shader: refuse view-address fields the table gives as 0; test a shader that needs both tables (follow-up to #311's merge) #311
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/311"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T10:56:21Z.
Refs #306.
The native host refused every shader that needs the view-address table (root SRV
t1, space 2), which the D3D12 path builds and binds. This adds it to the native host.What changes:
NativeHeap::addresses), made byNativeHost::view_addressesthe first time a shader needs it. It's filled from the heap's records with four dwords per entry:descriptor::texture_words, moved out of the D3D12-onlydescriptor/host.rsso both paths share it;NativeHost::mirroronce made, and bound after the page table, for compute and for vertex/pixel programs.unsupported()now refuses only write marks ("needs write marks").Pages::write_atis the same helper #264 adds, so the two should merge cleanly there.Test.
heap_tests::a_compute_shader_reads_title_memory_at_a_heap_views_addressruns a compute that reads an SRV's address fromt1, loads the word there (0x12345678) and stores it. It fails two ways without the full change:In the title. 7 compute shaders were refused for this reason alone in our boot dumps:
00bc6a9b,0c748826,48828947,550d92da,a2d0209f,c3873dc0andfcd8ef10. Six of them read a buffer view's address and walk title memory through the page table, which looks like BVH traversal. On main + this + #304, all 7 now make their Metal pipelines (pipeline creation only, nothing run). We haven't measured them in game: game runs are paused on our Mac for now (#79).Memory: 16 bytes per entry, only for resource heaps that such a shader reads through. That's 16 MiB per 2^20 entries. Our world heap reaches at least index 505,076, so at least 7.7 MiB.
Checks: victory-gpu 320, victory-shader 332 and victory-hle 141 tests pass, and victory and xtask pass. Windows clippy is clean with
-D warnings, andcargo xtask policypasses.docs/native-host.mdhas a new section, "View addresses on the native host (#306)".Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T11:54:11Z.
Thank you. The test with real values (the word read at a view's address) is what I wanted.
Two things before I merge it.
view_addressesset, by stage (compute, vertex, pixel)? Your change opens all of them on the native host, not only the seven compute ones. A shader that reads a field this table gives as 0 (format, tiling, base address) would now draw something wrong instead of being refused. Please say how the translator refuses those reads, and point to the test.write_atand editsmirrorin the same lines, and it conflicts with main today. I will take #264 first. Please rebase on it when it is in, and check the order of the arguments in the argument buffer when a shader needs both tables.I have not run this in the game. It needs a run with a world frame before I merge it.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T13:06:01Z.
Thanks. Both answers below were measured offline on a boot set of every shader the prewarm
translated: 4,921 containers, main
465db23b+ #304.1. Shaders with
view_addresses, by stage. 44 translated programs read the table: 42 compute,2 pixel, 0 vertex. On main alone it is 35 compute and 2 pixel; the 7 named above need #304 to
translate. So this PR opens 44 programs, not 7. What they read:
s_and_b32, 12 pack those bits withs_pack_ll_b32_b16, and 5 shift the address pair right withs_lshr_b64and then mask the result.2. Fields the table gives as 0. Before this push, the translator didn't refuse them. Inside the
dwords it fetched from
t1(0–1 of a buffer, 0–3 of an image loaded whole), every field read as itstable value. That includes the 0s: a buffer's stride and swizzle, and an image's base address,
format and tiling. Only dwords outside those (a buffer's 2–3, an image's 4–7) were refused.
3fa85bb4now refuses a program that can see any bit of a zero field.dword 3 bits 20–27 (tiling) and dwords 4–7.
Lower::view_addressesandLower::seen_bits.s_and_b32with a constant keeps that constant's bits.s_pack_ll_b32_b16keeps the low half.s_or_b32with a constant, ands_lshr_b64by a constant (with this dword as the high half),are followed into their results, four readers deep.
gfx_refusal_tests::view_address_fields_the_table_gives_as_0_are_refused. It runs onerefusal per field class. It also checks accepted reads of a buffer's address (dword 0; dword 1
masked to 16 bits; the pair shifted by
s_lshr_b64and masked) and of an image's size fields.Without the check, a read of a buffer's whole dword 1 translates.
record count or format.
descriptor_data, the path for a descriptor that's also used as a resource, doesn't uset1. Itrefuses by dword (
gfx_refusal_tests::descriptor_dwords_read_as_data_say_which).Two limits remain, and they're marked in the code. The kind of view comes from the load (eight dwords
at a whole descriptor means an image). The swizzle reads as the identity.
Rebased on main with #264, and the argument order. The PR is now rebased on main, which has
#264 and #304. There is one
Pages::write_at(#264's), andmirrorupdates both tables. A shaderthat needs both tables gets its argument buffer in this order:
t0of the memory space);t1).Binding::layoutdeclares that order to the converter, andtranslated_args, thenmemory_args,then
view_address_argsfill it in the same order.New Metal test:
heap_tests::a_compute_shader_reads_both_the_view_strides_and_the_view_addresses.Its compute program stores through a buffer it takes from the heap itself, which uses the stride
table, and loads the word at an SRV's title address, which uses
t1aftert0. I checked that thetest catches a wrong order: swapping
t0andt1, either in the layout or in the fill, makes itread a decoy view's word instead (and the existing view-address test fails too).
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T13:36:26Z.
This is on main as of
b639c175, merged from the head before your latest push, so GitHub still shows the PR open. Your commits are in the history under your name. Checked as part of a batch of nine PRs on main60baf130: tests, Windows clippy, policy, a full-corpus comparison and one world run (240 s, no crash, no GPU errors, scene colour lit).If your new head has changes beyond a rebase, please rebase it onto main so only those remain; otherwise please close this. Thank you.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T13:44:09Z.
Rebased onto main
b639c175. Only the two commits that came after the head you merged remain:c4faf9c4: shader: refuse view-address fields the table gives as 0. Inside the dwords fetched fromt1, a field the table gives as 0 read as 0 instead of being refused:Now a program that can see any bit of such a field is refused, with the visible bits followed through the program's instructions (
Lower::seen_bits). Test:gfx_refusal_tests::view_address_fields_the_table_gives_as_0_are_refused, with 10 refusals and 6 accepted reads. On our boot set, all 44 view-address programs still translate. 40 have the same output, 3 drop a load nothing reads, and 1 changes only a refusal message.00853efa: a Metal test,heap_tests::a_compute_shader_reads_both_the_view_strides_and_the_view_addresses. It checks the argument order when one shader needs both tables, and swapping them makes it fail.Checks on this head: victory-shader 371 and victory-gpu 358 tests pass, Windows clippy is clean, and
cargo xtask policypasses. The first commit closes a wrong-accept gap that main has today, so it matters more than the test.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:05:20Z.
Merged in
be7dc1b5. Ran the tests, Windows clippy, the policy check and a release build, and swept my full corpus (21,600 shaders): nothing lost; 690 refusals now name the zero field instead of "a descriptor read only as data", and 33 outputs change (5 compute, 28 pixel), which matches your note about loads nothing reads being dropped (I did not diff each one). Not run in the game yet. Thanks.