shader: refuse view-address fields the table gives as 0; test a shader that needs both tables (follow-up to #311's merge) #311

Manually merged
github merged 4 commits from github-bot/gh-311 into main 2026-11-27 16:13:15 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-27 10:56 UTC · original
Olima34:fix/view-addresses → main · +331 −24 · 6 files · 4 commits · merged 2026-11-27 16:04 UTC

Current head (3cc078cf, rebased on main with #264 and #304): opens 44 programs (42 compute, 2 pixel), and refuses any read of a field the table gives as 0 (3fa85bb4). See the latest comment.

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:

  • One table per resource heap (NativeHeap::addresses), made by NativeHost::view_addresses the first time a shader needs it. It's filled from the heap's records with four dwords per entry:
    • a buffer view's title address;
    • a texture view's size fields, through descriptor::texture_words, moved out of the D3D12-only descriptor/host.rs so both paths share it;
    • zeros for anything else.
  • Kept up to date in NativeHost::mirror once 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_at is 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_address runs a compute that reads an SRV's address from t1, loads the word there (0x12345678) and stores it. It fails two ways without the full change:

  • without it at all, the shader is refused;
  • with the refusal lifted but no table, the converter refuses the pipeline ("SRV space 2 register 1 … not referenced by the root signature").

In the title. 7 compute shaders were refused for this reason alone in our boot dumps: 00bc6a9b, 0c748826, 48828947, 550d92da, a2d0209f, c3873dc0 and fcd8ef10. 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, and cargo xtask policy passes. docs/native-host.md has a new section, "View addresses on the native host (#306)".

**@⁠Olima34** on GitHub · 2026-11-27 10:56 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/311) `Olima34:fix/view-addresses` → `main` · +331 −24 · 6 files · 4 commits · merged 2026-11-27 16:04 UTC > **Current head (3cc078cf, rebased on main with #264 and #304):** opens 44 programs (42 compute, 2 pixel), and refuses any read of a field the table gives as 0 (3fa85bb4). See the latest comment. 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:** - **One table per resource heap** (`NativeHeap::addresses`), made by `NativeHost::view_addresses` the first time a shader needs it. It's filled from the heap's records with four dwords per entry: - a buffer view's title address; - a texture view's size fields, through `descriptor::texture_words`, moved out of the D3D12-only `descriptor/host.rs` so both paths share it; - zeros for anything else. - **Kept up to date** in `NativeHost::mirror` once 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_at`** is 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_address` runs a compute that reads an SRV's address from `t1`, loads the word there (0x12345678) and stores it. It fails two ways without the full change: - without it at all, the shader is refused; - with the refusal lifted but no table, the converter refuses the pipeline ("SRV space 2 register 1 … not referenced by the root signature"). **In the title.** 7 compute shaders were refused for this reason alone in our boot dumps: `00bc6a9b`, `0c748826`, `48828947`, `550d92da`, `a2d0209f`, `c3873dc0` and `fcd8ef10`. 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`, and `cargo xtask policy` passes. `docs/native-host.md` has a new section, "View addresses on the native host (#306)".
Refs #306

A shader that reads a buffer view's title address from its descriptor
(dwords 0-1, where a BVH walk starts), or a texture view's size fields,
gets them from the view addresses, the translator's root SRV t1 of the
memory space. The native host bound no such table and refused every such
program ("needs view addresses or write marks").

Each resource heap now has one (NativeHost::view_addresses,
NativeHeap::addresses): four dwords per title entry, a buffer view's
title address (dword 0, and the low 16 bits of dword 1), a texture
view's size fields (descriptor::texture_words, the D3D12 path's, moved
to be shared), zeros for anything else. It is made the first time a
shader reads it, from the heap's records as they are then, kept current
by every mirrored write, and follows the page table in the argument
buffer (Binding::view_addresses). Write marks stay refused ("needs write
marks").

Cost: 16 bytes an entry, for each resource heap a shader reads it
through (16 MiB for 2^20 entries), made only for those heaps.

Measured offline: the 7 compute programs of a boot-dumped corpus that
#304 lets translate but the host refused for view addresses now make
their Metal pipelines (not run).

Test: heap_tests::a_compute_shader_reads_title_memory_at_a_heap_views_
address: a raw SRV's address read from its descriptor, the word there
stored to the output. Refused before; with only the refusal lifted, the
converter refused the pipeline (SRV space 2 register 1 not in the root
signature).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 11:05:30 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 11:54 UTC · original

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.

  1. How many shaders in your dump have view_addresses set, 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.
  2. #264 adds the same write_at and edits mirror in 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.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 11:54 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/311#issuecomment-7217607278) 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. 1. How many shaders in your dump have `view_addresses` set, 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. 2. #264 adds the same `write_at` and edits `mirror` in 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.
github-bot force-pushed github-bot/gh-311 from c9ff744467 to 3cc078cf36 2026-11-27 13:08:36 +00:00 Compare
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 13:06 UTC · original

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:

  • 40 read a buffer's dword 1. 23 mask it to its low 16 bits with s_and_b32, 12 pack those bits with
    s_pack_ll_b32_b16, and 5 shift the address pair right with s_lshr_b64 and then mask the result.
  • None reads an image's dwords through the table.
  • 4 read only dword 0, or nothing the program uses.

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 its
table 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.

3fa85bb4 now refuses a program that can see any bit of a zero field.

  • Refused fields:
    • a buffer's dword 1 bits 16–31 and dwords 2–3;
    • an image's dword 0, dword 1 bits 0–29 (base address, minimum level, format), dword 2 bits 30–31,
      dword 3 bits 20–27 (tiling) and dwords 4–7.
  • Message: "a view address field the table gives as 0: " followed by the field.
  • Where: Lower::view_addresses and Lower::seen_bits.
  • How the visible bits are found: they're followed through the readers.
    • s_and_b32 with a constant keeps that constant's bits.
    • s_pack_ll_b32_b16 keeps the low half.
    • s_or_b32 with a constant, and s_lshr_b64 by a constant (with this dword as the high half),
      are followed into their results, four readers deep.
    • Any other reader, or a phi, sees every bit.
  • Test: gfx_refusal_tests::view_address_fields_the_table_gives_as_0_are_refused. It runs one
    refusal 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_b64 and masked) and of an image's size fields.
    Without the check, a read of a buffer's whole dword 1 translates.
  • Re-sweep of the 44:
    • all 44 still translate;
    • 40 have the same output;
    • 3 drop the load of a dword nothing lowered reads;
    • 1 changes only the wording of a refusal in its thread-count variant.
    • 11 programs that were already refused now name the field: 10 a buffer's stride or swizzle, 1 its
      record count or format.

descriptor_data, the path for a descriptor that's also used as a resource, doesn't use t1. It
refuses 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), and mirror updates both tables. A shader
that needs both tables gets its argument buffer in this order:

  1. the user-data block;
  2. the root views, the stride table among them (root SRV 255 of the root-view space);
  3. the page table (t0 of the memory space);
  4. the view addresses (t1).

Binding::layout declares that order to the converter, and translated_args, then memory_args,
then view_address_args fill 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 t1 after t0. I checked that the
test catches a wrong order: swapping t0 and t1, either in the layout or in the fill, makes it
read a decoy view's word instead (and the existing view-address test fails too).

**@⁠Olima34** on GitHub · 2026-11-27 13:06 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/311#issuecomment-7219055799) 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: - 40 read a buffer's dword 1. 23 mask it to its low 16 bits with `s_and_b32`, 12 pack those bits with `s_pack_ll_b32_b16`, and 5 shift the address pair right with `s_lshr_b64` and then mask the result. - None reads an image's dwords through the table. - 4 read only dword 0, or nothing the program uses. **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 its table 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. 3fa85bb4 now refuses a program that can see any bit of a zero field. - **Refused fields:** - a buffer's dword 1 bits 16–31 and dwords 2–3; - an image's dword 0, dword 1 bits 0–29 (base address, minimum level, format), dword 2 bits 30–31, dword 3 bits 20–27 (tiling) and dwords 4–7. - **Message:** "a view address field the table gives as 0: " followed by the field. - **Where:** `Lower::view_addresses` and `Lower::seen_bits`. - **How the visible bits are found:** they're followed through the readers. - `s_and_b32` with a constant keeps that constant's bits. - `s_pack_ll_b32_b16` keeps the low half. - `s_or_b32` with a constant, and `s_lshr_b64` by a constant (with this dword as the high half), are followed into their results, four readers deep. - Any other reader, or a phi, sees every bit. - **Test:** `gfx_refusal_tests::view_address_fields_the_table_gives_as_0_are_refused`. It runs one refusal 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_b64` and masked) and of an image's size fields. Without the check, a read of a buffer's whole dword 1 translates. - **Re-sweep of the 44:** - all 44 still translate; - 40 have the same output; - 3 drop the load of a dword nothing lowered reads; - 1 changes only the wording of a refusal in its thread-count variant. - 11 programs that were already refused now name the field: 10 a buffer's stride or swizzle, 1 its record count or format. `descriptor_data`, the path for a descriptor that's also used as a resource, doesn't use `t1`. It refuses 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), and `mirror` updates both tables. A shader that needs both tables gets its argument buffer in this order: 1. the user-data block; 2. the root views, the stride table among them (root SRV 255 of the root-view space); 3. the page table (`t0` of the memory space); 4. the view addresses (`t1`). `Binding::layout` declares that order to the converter, and `translated_args`, then `memory_args`, then `view_address_args` fill 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 `t1` after `t0`. I checked that the test catches a wrong order: swapping `t0` and `t1`, either in the layout or in the fill, makes it read a decoy view's word instead (and the existing view-address test fails too).
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 13:36 UTC · original

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 main 60baf130: 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.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 13:36 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/311#issuecomment-7219707179) 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 main 60baf130: 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.
github-bot changed title from native: bind the view-address table (t1) for shaders that read a view's address (#306) to shader: refuse view-address fields the table gives as 0; test a shader that needs both tables (follow-up to #311's merge) 2026-11-27 13:54:41 +00:00
github-bot force-pushed github-bot/gh-311 from 3cc078cf36 to 00853efa49 2026-11-27 13:54:45 +00:00 Compare
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 13:44 UTC · original

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 from t1, a field the table gives as 0 read as 0 instead of being refused:

    • a buffer's stride and swizzle;
    • an image's base address, format and tiling.

    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 policy passes. The first commit closes a wrong-accept gap that main has today, so it matters more than the test.

**@⁠Olima34** on GitHub · 2026-11-27 13:44 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/311#issuecomment-7219879244) 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 from `t1`, a field the table gives as 0 read as 0 instead of being refused: - a buffer's stride and swizzle; - an image's base address, format and tiling. 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 policy` passes. The first commit closes a wrong-accept gap that main has today, so it matters more than the test.
The zero-field refusal (c4faf9c4) refuses a program that can see a buffer
view's stride or swizzle bits through the view-address table. The
Windows-only memory test used the whole of dword 1 as the address's high
half; it now masks it to the low 16 bits first, as the title's BVH reads do.
The Windows-only memory test stored the whole of an image descriptor's
dwords 1-3 read through the view-address table; with the zero-field
refusal those dwords may only be seen in their size fields. It masks them
as a title does (the expected values were already within those fields).
github-bot referenced this pull request from a commit 2026-11-27 16:13:14 +00:00
github manually merged commit be7dc1b5cd into main 2026-11-27 16:13:15 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 16:05 UTC · original

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.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 16:05 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/311#issuecomment-7222841650) 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.