nx_swgpu.nx
buildroot/runtime/nx_swgpu.nx
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
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
| 10 | const O_MAGIC_4096: i64 = 4096 |
| 11 | const O_MAGIC_65536: i64 = 65536 |
| 12 | const O_MAGIC_4950: i64 = 4950 |
| 13 | const O_MAGIC_1080: i64 = 1080 |
| 14 | const O_MAGIC_3950: i64 = 3950 |
| 15 | const O_MAGIC_3050: i64 = 3050 |
| 16 | const O_MAGIC_1450: i64 = 1450 |
| 17 | const O_MAGIC_1250: i64 = 1250 |
| 18 | const O_MAGIC_2100: i64 = 2100 |
| 19 | const O_MAGIC_1300: i64 = 1300 |
| 20 | const O_MAGIC_1200: i64 = 1200 |
| 21 | const O_MAGIC_1400: i64 = 1400 |
| 22 | const O_MAGIC_1050: i64 = 1050 |
| 23 | const O_MAGIC_1550: i64 = 1550 |
| 24 | const O_MAGIC_2900: i64 = 2900 |
| 25 | const O_MAGIC_1780: i64 = 1780 |
| 26 | const O_MAGIC_1150: i64 = 1150 |
| 28 | const W: i64 = 512 |
| 29 | const H: i64 = 384 |
| 30 | const HW: i64 = 256 |
| 31 | const HH: i64 = 192 |
| 32 | const TILE: i64 = 64 |
| 33 | const NTX: i64 = 8 |
| 34 | const NTY: i64 = 6 |
| 35 | const FOCAL: i64 = 520 |
| 36 | const ZFAR: i64 = 1073741824 |
| 37 | const MAXV: i64 = 8192 |
| 38 | const MAXT: i64 = 16384 |
| 40 | const O_FB: i64 = 0 |
| 41 | const O_ZB: i64 = 1572864 // W*H*8 |
| 42 | const O_PX: i64 = 3145728 // world vert positions fx4096 (MAXV each) |
| 43 | const O_PY: i64 = 3211264 |
| 44 | const O_PZ: i64 = 3276800 |
| 45 | const O_NX: i64 = 3342336 // vert normals (fx4096 unit, -> fx256 view at project) |
| 46 | const O_NY: i64 = 3407872 |
| 47 | const O_NZ: i64 = 3473408 |
| 48 | const O_SX: i64 = 3538944 // screen x int |
| 49 | const O_SY: i64 = 3604480 |
| 50 | const O_SZ: i64 = 3670016 // depth key |
| 51 | const O_VIS: i64 = 3735552 |
| 52 | const O_TA: i64 = 3801088 // MAXT*3 i64 tri indices |
| 53 | const O_TN: i64 = 4194304 // tri count |
| 54 | const O_VC: i64 = 4194312 // vert count |
| 56 | const O_VVX: i64 = 4194376 // view-space vert x fx4096 (MAXV) -- kept so we clip BEFORE projecting |
| 57 | const O_VVY: i64 = 4259912 |
| 58 | const O_VVZ: i64 = 4325448 |
| 59 | const O_TA2: i64 = 4390984 // scratch tri list the clipper emits into (MAXT*3). In-place is UNSAFE: |
| 61 | const O_CLIP: i64 = 4784200 // [0]=emitted tris [1]=verts the clip added [2]=envelope-hit flag |
| 62 | const SG_NEAR: i64 = 2048 // near plane 0.5 world units in front of the eye (fx4096 view z) |
| 78 | const SG_TM_EXPOSURE10: i64 = 12 // x1.2 midtone restore |
| 79 | const SG_TM_WHITE10: i64 = 17 // 1.41 peak x 1.2 exposure ~= 1.7 -> nothing reaches the clamp |
| 506 | const SG_AO_BIAS: i64 = 300 // below ~0.07 world units it is depth noise, not a cavity |
| 507 | const SG_AO_FAR: i64 = 24576 // beyond 6 world units it is a DIFFERENT surface, not an occluder -- |
functions
| 63 | func swgpu_bytes() -> i64 { return O_CLIP + 64 } |
| 65 | func sg_fb(base: i64) -> *i64 { return (base + O_FB) as *i64 } |
| 66 | func sg_zb(base: i64) -> *i64 { return (base + O_ZB) as *i64 } |
| 67 | func 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 } |
| 68 | func sg_imin(a: i64, b: i64) -> i64 { if a < b { return a } return b } called by 1: sg_raster |
| 69 | func sg_imax(a: i64, b: i64) -> i64 { if a > b { return a } return b } called by 1: sg_raster |
| 87 | func sg_tonemap(v: i64) -> i64 |
| 96 | func sg_reset(base: i64) -> i64 |
| 105 | func sg_add_ellipsoid(base: i64, cx: i64, cy: i64, cz: i64, rx: i64, ry: i64, rz: i64, seg: i64) -> i64 |
| 170 | func sg_sphere(base: i64, seg: i64) -> i64 |
| 178 | func sg_project(base: i64, yaw: i64, camz_units: i64) -> i64 |
| 222 | func sg_clip_vert(base: i64, ins: i64, outv: i64, k: i64) -> i64 called by 1: sg_project_clip_pitch |
| 250 | func sg_project_clip(base: i64, yaw: i64, camz_units: i64) -> i64 |
| 257 | func sg_project_clip_pitch(base: i64, yaw: i64, pitch: i64, camz_units: i64) -> i64 |
| 391 | func sg_raster(base: i64, skin_r: i64, skin_g: i64, skin_b: i64, clear: i64) -> i64 |
| 509 | func sg_ssao(base: i64, strength: i64) -> i64 |
| 565 | func 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) } |
| 566 | func 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) } |
| 569 | func sg_humanoid(base: i64, seg: i64) -> i64 |
| 597 | func ww() -> i64 { return W } |
| 598 | func hh() -> i64 { return H } |
| 599 | func fb_off() -> i64 { return O_FB } called by 1: main |