code wiki / (root) / nx_swgpu.nx

nx_swgpu.nx

buildroot/runtime/nx_swgpu.nx

29070 B600 linesdepth 2pulls 4 transitivereach 8 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 3 imports · 6 importers

nx_syscalls.nx nx_itrig.nx nx_vecmath.nx nx_swgpu.nx nx_d3d11_min.nx nx_game_world.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.nxnx_vecmath.nx

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

structs

none

consts

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

functions

64func swgpu_bytes() -> i64 { return O_CLIP + 64 }
66func sg_fb(base: i64) -> *i64 { return (base + O_FB) as *i64 }
67func sg_zb(base: i64) -> *i64 { return (base + O_ZB) as *i64 }
68func sg_isqrt(v: i64) -> i64 { return vm_isqrt(v) }
69func sg_imin(a: i64, b: i64) -> i64 { if a < b { return a } return b }
called by 1: sg_raster
70func sg_imax(a: i64, b: i64) -> i64 { if a > b { return a } return b }
called by 1: sg_raster
88func sg_tonemap(v: i64) -> i64
called by 2: mainsg_raster
97func sg_reset(base: i64) -> i64
106func sg_add_ellipsoid(base: i64, cx: i64, cy: i64, cz: i64, rx: i64, ry: i64, rz: i64, seg: i64) -> i64
171func sg_sphere(base: i64, seg: i64) -> i64
called by 1: main calls 2: sg_resetsg_add_ellipsoid
179func sg_project(base: i64, yaw: i64, camz_units: i64) -> i64
223func sg_clip_vert(base: i64, ins: i64, outv: i64, k: i64) -> i64
251func sg_project_clip(base: i64, yaw: i64, camz_units: i64) -> i64
called by 1: main calls 1: sg_project_clip_pitch
258func sg_project_clip_pitch(base: i64, yaw: i64, pitch: i64, camz_units: i64) -> i64
392func sg_raster(base: i64, skin_r: i64, skin_g: i64, skin_b: i64, clear: i64) -> i64
510func sg_ssao(base: i64, strength: i64) -> i64
called by 2: mainsl_render calls 3: sg_fbsg_zbsys_mmap
566func 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) }
called by 4: mainmainmainmain calls 1: sg_raster
567func 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) }
called by 1: sl_render calls 1: sg_raster
570func sg_humanoid(base: i64, seg: i64) -> i64
598func ww() -> i64 { return W }
599func hh() -> i64 { return H }
600func fb_off() -> i64 { return O_FB }
called by 1: main