code wiki / _hdl_build / nx_raster3d_bilinear.nx
nx_raster3d_bilinear.nx
buildroot/runtime/_hdl_build/nx_raster3d_bilinear.nx
about
nx_raster3d_bilinear.nx -- GATE: BILINEAR TEXTURE FILTERING, the SOTA texture-quality upgrade (smooth sampling vs
blocky nearest-neighbor). Blends the 4 nearest texels by the fractional (u,v) position, per color channel, all in
integer fixed-point (FBITS=8) => BIT-EXACT on any CPU, no GPU. Combined with the perspective-correct mapping
(nx_raster3d_tex) this is what real GPUs do. Nearest-neighbor is the low-quality baseline; bilinear is SOTA.
T1 bilinear KAT: sampling EXACTLY between a black and a white texel yields gray (~127) -- a blend nearest cannot make.
T2 weighting KAT: sampling 1/4 of the way yields ~64 (25% of 255) -- proves fractional weighting, not rounding.
T3 a bilinear-filtered textured quad produces INTERMEDIATE colors (smooth) that nearest-neighbor would never emit.
T4 (EXCEED) determinism -- bit-identical across runs.
expect_exit: 0 Sovereign: nx_syscalls. NEVER-BRICK: software render, writes 0 GPU firmware.
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 11 | const INVZ_MAGIC_5381: i64 = 5381 |
| 17 | const W: i64 = 64 |
| 18 | const H: i64 = 64 |
| 19 | const ZINF: i64 = 1000000000 |
| 20 | const INVZ_Q: i64 = 1048576 // 2^20 inverse-depth scale (perspective) |
| 21 | const FBITS: i64 = 8 // texture-coord fractional bits |
| 22 | const FONE: i64 = 256 // 1.0 in FBITS |
functions
| 13 | func g_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 14 | func g_pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var x: i64=v; if x<0{b[0]=45;sys_write(1,b,1);x=0-x} if x==0{b[0]=48;sys_write(1,b,1);return 0} var d: i64=0; var y: i64=x; while y>0{d=d+1;y=y/10} var i: i64=d-1; y=x; while i>=0{b[i]=(48+(y%10)) as u8;y=y/10;i=i-1} sys_write(1,b,d); return 0 } |
| 15 | func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c } |
| 24 | func fb_clear(fb: *i64, zb: *i64) -> i64 { var i: i64=0; while i<W*H { fb[i]=0; zb[i]=ZINF; i=i+1 } return 0 } called by 1: main |
| 25 | func cksum(fb: *i64) -> i64 { var h: i64=INVZ_MAGIC_5381; var i: i64=0; while i<W*H { h=((h<<5)+h)+fb[i]; i=i+1 } return h } called by 1: main |
| 26 | func 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: draw_tri_bl |
| 27 | func chan(c: i64, sh: i64) -> i64 { return (c>>sh)&255 } called by 1: bilinear_sample |
| 30 | func bilinear_sample(tex: *i64, tw: i64, th: i64, ufp: i64, vfp: i64) -> i64 |
| 51 | func draw_tri_bl(fb: *i64, zb: *i64, x0: i64, y0: i64, z0: i64, u0: i64, v0: i64, x1: i64, y1: i64, z1: i64, u1: i64, v1: i64, x2: i64, y2: i64, z2: i64, u2: i64, v2: i64, tex: *i64, texw: i64, texh: i64) -> i64 |
| 88 | func main() -> i64 |