code wiki / (root) / nx_gpu_geometry.nx

nx_gpu_geometry.nx

buildroot/runtime/nx_gpu_geometry.nx

9175 B124 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic gpu
docsdependenciesstructsconstsfunctions

about

nx_gpu_geometry.nx -- GOAL-GPU-NATIVE rung-3: the 3D GEOMETRY STAGE (transform + project + hidden-surface). Turns flat 2D triangles into real moving 3D -- the front of the graphics pipeline, the last pure-software rung before the silicon unlock. A unit cube (8 verts, 12 triangles, 6 coloured faces) is rotated (Y then X, integer fixed-point cos/sin x256), perspective-projected to screen space, and rasterized with the rung-1 Z-BUFFER doing HIDDEN-SURFACE REMOVAL -- so only the front faces show, back faces are occluded by depth. Two frames at different angles prove the rotation is real geometry, not a static picture. KAT: the cube renders; HIDDEN-SURFACE is correct (a cube shows at most 3 faces -> <=3 face colours visible, proving back faces were depth-occluded); rotating the angle changes the projection (frame0 != frame1); frames export to BMP. All integer, fully sovereign. Feeds the GPFIFO graphics path (rung-2) as draw cmds. (cube geometry packed into one `mesh` array: verts x@0..7 y@8..15 z@16..23; tris a@24 b@36 c@48 r@60 g@72 b@84.) HONEST SCOPE: flat per-triangle depth/shading + fixed angles; smooth animation + per-pixel depth + lighting are refinements; real-time perf needs the silicon last-mile. No hw writes (Rule 26). expect_exit: 0 tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_fb.nx nx_gpu_geometry.nx

imports: nx_fb.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main gm_puts setv settri render_cube gm_project gm_tri gm_edge gm_clamp gm_min3 gm_max3 fb_bmp_save sys_mmap fb_p32 fb_p16 sys_openat_wr sys_write sys_close sys_openat_wr ↻ gm_num

structs

none

consts

none

functions

15func gm_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main
16func gm_num(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
called by 1: main
17func gm_edge(ax: i64, ay: i64, bx: i64, by: i64, px: i64, py: i64) -> i64 { return (bx-ax)*(py-ay) - (by-ay)*(px-ax) }
called by 1: gm_tri
18func gm_min3(a: i64, b: i64, c: i64) -> i64 { var m: i64=a; if b<m {m=b} if c<m {m=c} return m }
called by 1: gm_tri
19func gm_max3(a: i64, b: i64, c: i64) -> i64 { var m: i64=a; if b>m {m=b} if c>m {m=c} return m }
called by 1: gm_tri
20func gm_clamp(v: i64, lo: i64, hi: i64) -> i64 { if v<lo {return lo} if v>hi {return hi} return v }
called by 1: gm_tri
22func gm_project(vx: i64, vy: i64, vz: i64, cy: i64, sy: i64, cx: i64, sx: i64, W: i64, H: i64, out: *i64) -> i64
called by 1: render_cube
34func gm_tri(fb: *u8, zbuf: *i64, W: i64, H: i64, x0: i64, y0: i64, x1: i64, y1: i64, x2: i64, y2: i64, z: i64, r: i64, g: i64, b: i64) -> i64
53func render_cube(fb: *u8, zbuf: *i64, W: i64, H: i64, cy: i64, sy: i64, cx: i64, sx: i64, mesh: *i64) -> i64
called by 1: main calls 2: gm_projectgm_tri
70func setv(mesh: *i64, v: i64, x: i64, y: i64, z: i64) -> i64 { mesh[v]=x; mesh[8+v]=y; mesh[16+v]=z; return 0 }
called by 1: main
71func settri(mesh: *i64, t: i64, a: i64, b: i64, c: i64, r: i64, g: i64, bl: i64) -> i64 { mesh[24+t]=a; mesh[36+t]=b; mesh[48+t]=c; mesh[60+t]=r; mesh[72+t]=g; mesh[84+t]=bl; return 0 }
called by 1: main
73func main() -> i64