code wiki / (root) / nx_swgpu.nx

nx_swgpu.nx

buildroot/runtime/nx_swgpu.nx

29145 B599 linesdepth 2pulls 3 transitivereach 11 importersview sourcekind librarytopic swgpu
docsdependenciesstructsconstsfunctions

about

nx_swgpu.nx -- the SOVEREIGN SOFTWARE GPU core (operator 2026-07-04: "build our OWN, beyond WebGL2/WebGPU, be FIRST ... nishi os + browser + game state of the art on our own"). A CPU that IS a GPU: a general MESH renderer -- arbitrary world verts + normals + triangles -> a TILED rasterizer (fast/SIMD/MT-ready, the llvmpipe/SwiftShader model, fully ours) with PER-PIXEL lighting (barycentric normals -> integer Blinn-Phong + rim + tonemap-ish). ALL INTEGER (nx_itrig) = deterministic + VM-vettable. Same pipeline Path B runs on the real GPU (NVIDIA/AMD/FPGA) via our driver. Primitives: sg_add_ellipsoid (sphere/limb/torso) -> compose any body. license_tier: ORIGINAL

dependencies 2 imports · 7 importers

nx_syscalls.nx nx_itrig.nx nx_swgpu.nx nx_d3d11_min.nx nx_game_world.nx nx_gx1c_canvas_gate.nx nx_gx5_nearclip_gate.nx nx_gx6_tonemap_gate.nx nx_gx8_ssao_gate.nx nx_swgpu_gate.nx

imports: nx_syscalls.nxnx_itrig.nx

imported by: nx_d3d11_min.nxnx_game_world.nxnx_gx1c_canvas_gate.nxnx_gx5_nearclip_gate.nxnx_gx6_tonemap_gate.nxnx_gx8_ssao_gate.nxnx_swgpu_gate.nx

structs

none

consts

10const O_MAGIC_4096: i64 = 4096
11const O_MAGIC_65536: i64 = 65536
12const O_MAGIC_4950: i64 = 4950
13const O_MAGIC_1080: i64 = 1080
14const O_MAGIC_3950: i64 = 3950
15const O_MAGIC_3050: i64 = 3050
16const O_MAGIC_1450: i64 = 1450
17const O_MAGIC_1250: i64 = 1250
18const O_MAGIC_2100: i64 = 2100
19const O_MAGIC_1300: i64 = 1300
20const O_MAGIC_1200: i64 = 1200
21const O_MAGIC_1400: i64 = 1400
22const O_MAGIC_1050: i64 = 1050
23const O_MAGIC_1550: i64 = 1550
24const O_MAGIC_2900: i64 = 2900
25const O_MAGIC_1780: i64 = 1780
26const O_MAGIC_1150: i64 = 1150
28const W: i64 = 512
29const H: i64 = 384
30const HW: i64 = 256
31const HH: i64 = 192
32const TILE: i64 = 64
33const NTX: i64 = 8
34const NTY: i64 = 6
35const FOCAL: i64 = 520
36const ZFAR: i64 = 1073741824
37const MAXV: i64 = 8192
38const MAXT: i64 = 16384
40const O_FB: i64 = 0
41const O_ZB: i64 = 1572864 // W*H*8
42const O_PX: i64 = 3145728 // world vert positions fx4096 (MAXV each)
43const O_PY: i64 = 3211264
44const O_PZ: i64 = 3276800
45const O_NX: i64 = 3342336 // vert normals (fx4096 unit, -> fx256 view at project)
46const O_NY: i64 = 3407872
47const O_NZ: i64 = 3473408
48const O_SX: i64 = 3538944 // screen x int
49const O_SY: i64 = 3604480
50const O_SZ: i64 = 3670016 // depth key
51const O_VIS: i64 = 3735552
52const O_TA: i64 = 3801088 // MAXT*3 i64 tri indices
53const O_TN: i64 = 4194304 // tri count
54const O_VC: i64 = 4194312 // vert count
56const O_VVX: i64 = 4194376 // view-space vert x fx4096 (MAXV) -- kept so we clip BEFORE projecting
57const O_VVY: i64 = 4259912
58const O_VVZ: i64 = 4325448
59const O_TA2: i64 = 4390984 // scratch tri list the clipper emits into (MAXT*3). In-place is UNSAFE:
61const O_CLIP: i64 = 4784200 // [0]=emitted tris [1]=verts the clip added [2]=envelope-hit flag
62const SG_NEAR: i64 = 2048 // near plane 0.5 world units in front of the eye (fx4096 view z)
78const SG_TM_EXPOSURE10: i64 = 12 // x1.2 midtone restore
79const SG_TM_WHITE10: i64 = 17 // 1.41 peak x 1.2 exposure ~= 1.7 -> nothing reaches the clamp
506const SG_AO_BIAS: i64 = 300 // below ~0.07 world units it is depth noise, not a cavity
507const SG_AO_FAR: i64 = 24576 // beyond 6 world units it is a DIFFERENT surface, not an occluder --

functions

63func swgpu_bytes() -> i64 { return O_CLIP + 64 }
65func sg_fb(base: i64) -> *i64 { return (base + O_FB) as *i64 }
66func sg_zb(base: i64) -> *i64 { return (base + O_ZB) as *i64 }
67func sg_isqrt(v: i64) -> i64 { if v <= 0 { return 0 } var x: i64 = v; var y: i64 = (x + 1) / 2; while y < x { x = y; y = (x + v / x) / 2 } return x }
68func sg_imin(a: i64, b: i64) -> i64 { if a < b { return a } return b }
called by 1: sg_raster
69func sg_imax(a: i64, b: i64) -> i64 { if a > b { return a } return b }
called by 1: sg_raster
87func sg_tonemap(v: i64) -> i64
called by 2: mainsg_raster
96func sg_reset(base: i64) -> i64
105func sg_add_ellipsoid(base: i64, cx: i64, cy: i64, cz: i64, rx: i64, ry: i64, rz: i64, seg: i64) -> i64
170func sg_sphere(base: i64, seg: i64) -> i64
called by 1: main calls 2: sg_resetsg_add_ellipsoid
178func sg_project(base: i64, yaw: i64, camz_units: i64) -> i64
222func sg_clip_vert(base: i64, ins: i64, outv: i64, k: i64) -> i64
250func sg_project_clip(base: i64, yaw: i64, camz_units: i64) -> i64
257func sg_project_clip_pitch(base: i64, yaw: i64, pitch: i64, camz_units: i64) -> i64
391func sg_raster(base: i64, skin_r: i64, skin_g: i64, skin_b: i64, clear: i64) -> i64
509func sg_ssao(base: i64, strength: i64) -> i64
565func sg_render(base: i64, skin_r: i64, skin_g: i64, skin_b: i64) -> i64 { return sg_raster(base, skin_r, skin_g, skin_b, 1) }
566func sg_render_pass(base: i64, skin_r: i64, skin_g: i64, skin_b: i64) -> i64 { return sg_raster(base, skin_r, skin_g, skin_b, 0) }
569func sg_humanoid(base: i64, seg: i64) -> i64
597func ww() -> i64 { return W }
598func hh() -> i64 { return H }
599func fb_off() -> i64 { return O_FB }
called by 1: main