code wiki / (root) / nx_layout_metadata_gate_t220.nx

nx_layout_metadata_gate_t220.nx source

↩ module page · 84 lines · 9855 B

1// nx_layout_metadata_gate_t220.nx -- Validates and retains metadata for layout objects in the Nishi sovereign ecosystem. 2import "nx_game_page_metadata_candidate_t220.nx" 3import "nx_gate_verdict.nx" 4func lmg_bad(s:*u8,label:*u8,out:*u8,c:*i64)->i64{ 5 gsb_failed=0;let n:i64=rk_layout_obj(out,0,s,rk_slen(s),"layout_rc=","struct_size=","T") 6 gv_check(label,gsb_failed==1&&rk_find(out,n,0,"T_META=null;")>=0,c);return 0 7} 8// Immutable private evidence; a rerun succeeds only if retained bytes are identical. 9func lmg_retain(path:*u8,b:*u8,n:i64)->i64{ 10 if n<=0{return 0} 11 let rc:i64=fxc_create(path,b,n) 12 if rc!=n&&rc!=FXC_EXISTS{return 0} 13 let check:*u8=sys_mmap_try(n+1);if (check as i64)<=0{return 0} 14 let got:i64=vw_read(path,check,n+1);let same:i64=gpa_same(b,n,check,got) 15 sys_munmap_direct(check,n+1);return same 16} 17func lmg_export_old(owned:*NxBufOwned,out:*u8,n:i64,c:*i64)->i64{ 18 gv_check("old fragment layout evidence retained and read back",lmg_retain("knowledge/gates/old-cast-layout-t220.js",out,n)==1,c) 19 let span:*i64=sys_mmap_try(2*__size_of(i64)) as *i64 20 if (span as i64)<=0{gv_check("old fragment WGSL evidence retained and read back",0,c);return 0} 21 let ok:i64=rk_world_span(owned.buf,owned.len,RK_CAST_FS_BEGIN,RK_CAST_FS_END,span) 22 var kept:i64=0 23 if ok==1{kept=lmg_retain("knowledge/gates/old-cast-fragment-t220.wgsl",(owned.buf as i64+span[0]) as *u8,span[1]-span[0])} 24 gv_check("old fragment WGSL evidence retained and read back",kept==1,c) 25 sys_munmap_direct(span as *u8,2*__size_of(i64));return kept 26} 27func main(argc:i64,argv:*i64)->i64{ 28 if argc!=7{return 2};let c:*i64=gv_ctr();let out:*u8=sys_mmap_try(GPE_OUT_CAP) 29 if (out as i64)<=0{return 3} 30 let good:*u8="layout_rc=32 rows:\nuniform|v|offset=0|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n" 31 gsb_failed=0;let n:i64=rk_layout_obj(out,0,good,rk_slen(good),"layout_rc=","struct_size=","T") 32 gv_check("valid vec3 scalar and array metadata retained",gsb_failed==0&&rk_find(out,n,0,"T_META={[\"v\"]:{offset:0,size:12,align:16},[\"f\"]:{offset:12,size:4,align:4},[\"a\"]:{offset:16,size:16,align:16},}")>=0,c) 33 gv_check("existing offsets and total size retained",rk_find(out,n,0,"T={[\"v\"]:0,[\"f\"]:12,[\"a\"]:16,}")>=0&&rk_find(out,n,0,"T_SIZE=32;")>=0,c) 34 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","missing size",out,c) 35 lmg_bad("layout_rc=32 rows:\nuniform|v|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","missing offset",out,c) 36 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=12|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","missing alignment",out,c) 37 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|offset=4|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","duplicate offset property",out,c) 38 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=9223372036854775808|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","overflow decimal",out,c) 39 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=12|align=16|stride=0|count=0\nuniform|f|offset=8|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","overlap",out,c) 40 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=17|size=16|align=16|stride=16|count=1\nstruct_size=32\n","misaligned offset",out,c) 41 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=32|align=16|stride=16|count=1\nstruct_size=32\n","out of range",out,c) 42 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|v|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","duplicate name",out,c) 43 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a-b|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","invalid name",out,c) 44 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=0|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","zero size",out,c) 45 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=12|align=3|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","non power of two alignment",out,c) 46 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=-12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","negative metadata",out,c) 47 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=12x|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","partial decimal",out,c) 48 lmg_bad("layout_rc=16 rows:\nuniform|v|offset=0|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","mismatched header size",out,c) 49 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\nlayout_rc=32 rows:\nuniform|v|offset=0|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\nstruct_size=32\n","duplicate section",out,c) 50 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1\n","missing footer",out,c) 51 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=12|align=16|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=16|stride=16|count=1struct_size=32\n","unterminated uniform row",out,c) 52 lmg_bad("layout_rc=32 rows:\nuniform|v|offset=0|size=12|align=64|stride=0|count=0\nuniform|f|offset=12|size=4|align=4|stride=0|count=0\nuniform|a|offset=16|size=16|align=64|stride=16|count=1\nstruct_size=32\n","oversized alignment",out,c) 53 lmg_bad("layout_rc=16 rows:\nstruct_size=16\n","empty rows",out,c) 54 gsb_failed=0 55 let proto:*u8="layout_rc=4 rows:\nuniform|__proto__|offset=0|size=4|align=4\nstruct_size=4\n" 56 let pn:i64=rk_layout_obj(out,0,proto,rk_slen(proto),"layout_rc=","struct_size=","T") 57 gv_check("computed key preserves prototype-like field as own data",gsb_failed==0&&rk_find(out,pn,0,"[\"__proto__\"]:{offset:0,size:4,align:4}")>=0,c) 58 gv_check("prototype fixture retained and read back",lmg_retain("knowledge/gates/layout-prototype-t220.js",out,pn)==1,c) 59 gsb_failed=0;rk_layout_obj(out,0,0 as *u8,1,"layout_rc=","struct_size=","T");gv_check("null capture refused",gsb_failed==1,c) 60 gsb_failed=0 61 let boundary:*u8="layout_rc=9007199254740991 rows:\nuniform|v|offset=0|size=9007199254740991|align=1\nstruct_size=9007199254740991\n" 62 let bn:i64=rk_layout_obj(out,0,boundary,rk_slen(boundary),"layout_rc=","struct_size=","T") 63 gv_check("JavaScript exact integer boundary retained",gsb_failed==0&&rk_find(out,bn,0,"T_SIZE=9007199254740991;")>=0&&rk_find(out,bn,0,"size:9007199254740991,align:1}")>=0,c) 64 lmg_bad("layout_rc=9007199254740992 rows:\nuniform|v|offset=0|size=9007199254740992|align=1\nstruct_size=9007199254740992\n","above JavaScript safe integer refused",out,c) 65 lmg_bad("layout_rc=9007199254740993 rows:\nuniform|v|offset=0|size=9007199254740993|align=1\nstruct_size=9007199254740993\n","rounded JavaScript integer refused",out,c) 66 var run:i64=0 67 while run<2{ 68 let at:i64=1+run*3;let owned:*NxBufOwned=rk_owned_new();if (owned as i64)<=0{return 3} 69 gsb_failed=0 70 let bytes:i64=rk_lm_decimal(argv[at+2] as *u8,0,rk_slen(argv[at+2] as *u8)) 71 let rc:i64=gsb_capture_selected_owned(argv[at] as *u8,argv[at+1] as *u8,bytes,"cast",owned,RK_WGSL_TMO_MS,0) 72 gv_check("retained producer captured with exact identity",rc==0&&owned.len>0,c) 73 if rc!=0{rk_owned_close(owned);return 3} 74 gsb_failed=0;let vn:i64=rk_layout_obj(out,0,owned.buf,owned.len,"castv_layout_rc=","castv_struct_size=","NXCV") 75 gv_check("actual vertex metadata accepted",gsb_failed==0&&rk_find(out,vn,0,"NXCV_META={")>=0,c) 76 let fn:i64=rk_layout_obj(out,0,owned.buf,owned.len,"castf_layout_rc=","castf_struct_size=","NXCF") 77 gv_check("actual fragment metadata accepted",gsb_failed==0&&rk_find(out,fn,0,"NXCF_META={")>=0,c) 78 if run==0{gv_check("stable lit metadata present",rk_find(out,fn,0,"[\"uEmissiveFactor\"]:{offset:1680,size:12,align:16}")>=0,c)} 79 else{gv_check("old albedo metadata does not invent lit capability",rk_find(out,fn,0,"uMaterialMode")>=0&&rk_find(out,fn,0,"uEmissiveFactor")<0,c);lmg_export_old(owned,out,fn,c)} 80 rk_owned_close(owned);run=run+1 81 } 82 sys_munmap_direct(out,GPE_OUT_CAP) 83 return gv_verdict("producer-layout-metadata",c,"Actual producer metadata and refusal fixtures; browser consumer compatibility remains separate") 84}