feat(shader): translate texture size queries through four descriptor dwords #567

Open
github-bot wants to merge 1 commit from github-bot/gh-563 into main AGit
Owner

@⁠Sandile-0511 on GitHub · 2026-11-28 05:13 UTC · original
Sandile-0511:shader/size-query-four-dwords → main · +515 −25 · 5 files · 1 commits · open

What this changes

Refs #411

Main took most of #411 while this was being written: since 5cb68393 and 3a435b56 a sizing load takes its kind and its sizes from the view the program also samples, which covers 708 of the 723 programs that b998bb65 refused for "a view address field the table gives as 0: a buffer's stride or swizzle". This is the rest: size queries of a view the program does not use, which still fall to the view addresses. On main 2f4d81e0 that is 43 of my 21,608 shaders (41 pixel, 2 vertex): 15 are refused, 28 translate with the size missing.

  • Lower::image_half (crates/victory-shader/src/emit/lower.rs) takes a four-dword load as an image's first half when it is at a whole descriptor (the computed part an index shifted left by 5 as the offset register, or none), every reader keeps only bits the view addresses hold of an image or tests dword 1 against 0, and together they read a size from dword 2 and the view's first level from dword 3. Any other load stays a buffer's and keeps the refusal it has on main.
  • Lower::seen_bits follows s_bfe_u32 of a constant field, and for an image's dword 1 counts s_cmp_eq_i32 / s_cmp_lg_i32 with 0 as seeing no bit.
  • The table's dword 1 holds the width's two low bits only, so it is 0 for a texture of width 4k + 1 as well as for no view. Where a program tests it against 0, the translator sets format bit 20 (the bit descriptor_data sets since 5cb68393), which no other reader sees, when the entry's dword 3 is not 0 (a texture view's never is). This is the case docs/native-host.md names as "still refused, rightly for now".
  • No host change: the view addresses already hold these fields (#306).

Things to know before reviewing:

  • Two guesses, marked in the code and in the docs: the console's dword 1 is 0 for a null view and never for an image (its format field is not 0), as main's own null test takes it; and an entry read this way holds an image view or nothing. The kind of view is decided by the readers, not proved.
  • Why "a size and the first level": the corpus has 815 such loads in 757 shaders, in three forms (the width alone 705, the width and height 101, the height alone 9), and every one reads the first level and tests dword 1 against 0. A buffer has part of its format where that level is, so a buffer's record count read under a mask does not pass as an image.
  • A zero entry reads as a null view (size 0). That is wrong for a texture view the title copied as bytes outside a bound table until it is mirrored: #306's own shortcut.
  • #549 (draft) covers these loads too, with a change to the table's layout. I have not run it. This one changes no host code.

How it was tested

  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • Ran the game: not run. Everything here is offline (tests, Metal tests, the sweep). One of the newly translated shaders and two of the changed ones are bound in the world.

Also:

  • cargo test -p victory-shader -p victory-hle: 424 library tests pass. Four are new (gfx_refusal_tests): the three forms and the eight-dword form translate; one refusal per field class, a join, and tests that are not of dword 1 against 0; a size without the level, the level without a size, the last level for the first; the waterfall loop, with a shift by 4 and an index added into the base refused. All are hand-written programs.
  • cargo test -p victory-gpu --lib (Metal, M5): 450 pass. New: heap_tests::a_compute_shader_sizes_textures_from_the_first_half_of_their_descriptors reads, per lane, the widths of textures 5 and 1 wide, of a view from level 1 of one 24 wide and of an empty entry: 5, 1, 12, 0. Without the mark the first two read 0.
  • Each condition of the rule was removed in turn (11 mutations) and a test failed for it.
  • cargo xtask policy: 404 files ok.
  • Whole corpus by output (21,608 shaders, every one the title registered in a run that reached the world, -j 4, against main 2f4d81e0): 14 newly translated (12 pixel, 2 vertex), one of them bound from the first world frame on; 0 regressions; 28 changed; 1 stops at a later refusal ("a lane mask holding lanes elsewhere read as data: a program input"). The 43 lines that differ are exactly the programs in which the rule accepts a load, and nothing is refused for "a buffer's stride or swizzle" any more.
    • The 28 changed already translate on main. There the size has no DXIL form and reaches only a join that the lanes outside a guarded write keep, which write_placed does not count as a read, so that edge gets 0 (the shape of #256). Those lanes now keep the size. Checked with a throwaway print on clean main: in all 28 a join edge carrying the refused size gets 0, and that join is the kept old value of a guarded write.
    • For anyone with a dump of their own: newly translated and bound in the world, bf6031225eee4640; changed and bound in the world, 0149c1fd291ed305 and 15133db0bc1b8b1f.
  • Not from this change: victory-hle's modules::dsp::tests::dump_captures_the_titles_ir_blocks_and_output failed in 4 of 7 runs of the x86_64 suite here, and in 2 of 8 on clean main (it shares VICTORY_DUMP_DSP with tests running beside it). host_posix::sync::tests::wait_on_address_handles_sizes_timeouts_and_isolated_wakes failed twice while other builds were running. The suite passes on re-run.

Checklist

  • No game files, game code, disassembly listings or SDK files are included
  • Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md
  • New diagnostics are behind a VICTORY_* variable and documented (none added)
**@⁠Sandile-0511** on GitHub · 2026-11-28 05:13 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/563) `Sandile-0511:shader/size-query-four-dwords` → `main` · +515 −25 · 5 files · 1 commits · open ## What this changes Refs #411 Main took most of #411 while this was being written: since `5cb68393` and `3a435b56` a sizing load takes its kind and its sizes from the view the program also samples, which covers 708 of the 723 programs that `b998bb65` refused for "a view address field the table gives as 0: a buffer's stride or swizzle". This is the rest: size queries of a view the program does not use, which still fall to the view addresses. On main `2f4d81e0` that is 43 of my 21,608 shaders (41 pixel, 2 vertex): 15 are refused, 28 translate with the size missing. - `Lower::image_half` (`crates/victory-shader/src/emit/lower.rs`) takes a four-dword load as an image's first half when it is at a whole descriptor (the computed part an index shifted left by 5 as the offset register, or none), every reader keeps only bits the view addresses hold of an image or tests dword 1 against 0, and together they read a size from dword 2 and the view's first level from dword 3. Any other load stays a buffer's and keeps the refusal it has on main. - `Lower::seen_bits` follows `s_bfe_u32` of a constant field, and for an image's dword 1 counts `s_cmp_eq_i32` / `s_cmp_lg_i32` with 0 as seeing no bit. - The table's dword 1 holds the width's two low bits only, so it is 0 for a texture of width 4k + 1 as well as for no view. Where a program tests it against 0, the translator sets format bit 20 (the bit `descriptor_data` sets since `5cb68393`), which no other reader sees, when the entry's dword 3 is not 0 (a texture view's never is). This is the case `docs/native-host.md` names as "still refused, rightly for now". - No host change: the view addresses already hold these fields (#306). Things to know before reviewing: - Two guesses, marked in the code and in the docs: the console's dword 1 is 0 for a null view and never for an image (its format field is not 0), as main's own null test takes it; and an entry read this way holds an image view or nothing. The kind of view is decided by the readers, not proved. - Why "a size and the first level": the corpus has 815 such loads in 757 shaders, in three forms (the width alone 705, the width and height 101, the height alone 9), and every one reads the first level and tests dword 1 against 0. A buffer has part of its format where that level is, so a buffer's record count read under a mask does not pass as an image. - A zero entry reads as a null view (size 0). That is wrong for a texture view the title copied as bytes outside a bound table until it is mirrored: #306's own shortcut. - #549 (draft) covers these loads too, with a change to the table's layout. I have not run it. This one changes no host code. ## How it was tested - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory` - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - [ ] Ran the game: not run. Everything here is offline (tests, Metal tests, the sweep). One of the newly translated shaders and two of the changed ones are bound in the world. Also: - `cargo test -p victory-shader -p victory-hle`: 424 library tests pass. Four are new (`gfx_refusal_tests`): the three forms and the eight-dword form translate; one refusal per field class, a join, and tests that are not of dword 1 against 0; a size without the level, the level without a size, the last level for the first; the waterfall loop, with a shift by 4 and an index added into the base refused. All are hand-written programs. - `cargo test -p victory-gpu --lib` (Metal, M5): 450 pass. New: `heap_tests::a_compute_shader_sizes_textures_from_the_first_half_of_their_descriptors` reads, per lane, the widths of textures 5 and 1 wide, of a view from level 1 of one 24 wide and of an empty entry: 5, 1, 12, 0. Without the mark the first two read 0. - Each condition of the rule was removed in turn (11 mutations) and a test failed for it. - `cargo xtask policy`: 404 files ok. - Whole corpus by output (21,608 shaders, every one the title registered in a run that reached the world, `-j 4`, against main `2f4d81e0`): 14 newly translated (12 pixel, 2 vertex), one of them bound from the first world frame on; 0 regressions; 28 changed; 1 stops at a later refusal ("a lane mask holding lanes elsewhere read as data: a program input"). The 43 lines that differ are exactly the programs in which the rule accepts a load, and nothing is refused for "a buffer's stride or swizzle" any more. - The 28 changed already translate on main. There the size has no DXIL form and reaches only a join that the lanes outside a guarded write keep, which `write_placed` does not count as a read, so that edge gets 0 (the shape of #256). Those lanes now keep the size. Checked with a throwaway print on clean main: in all 28 a join edge carrying the refused size gets 0, and that join is the kept old value of a guarded write. - For anyone with a dump of their own: newly translated and bound in the world, `bf6031225eee4640`; changed and bound in the world, `0149c1fd291ed305` and `15133db0bc1b8b1f`. - Not from this change: `victory-hle`'s `modules::dsp::tests::dump_captures_the_titles_ir_blocks_and_output` failed in 4 of 7 runs of the x86_64 suite here, and in 2 of 8 on clean main (it shares `VICTORY_DUMP_DSP` with tests running beside it). `host_posix::sync::tests::wait_on_address_handles_sizes_timeouts_and_isolated_wakes` failed twice while other builds were running. The suite passes on re-run. ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included - [x] Guesses about undocumented console behaviour are marked in the code and in docs/native-host.md - [x] New diagnostics are behind a `VICTORY_*` variable and documented (none added)
A size query loads only the first four dwords of an image descriptor.
Where the program does not use the view, the load falls to the view
addresses, and was a buffer's there by its size: refused for "a
buffer's stride or swizzle", or translated with the size missing.

Lower::image_half takes such a load as an image's first half when it
is at a whole descriptor, every reader keeps only bits the table holds
of an image or tests dword 1 against 0, and together they read a size
from dword 2 and the view's first level from dword 3. The test of
dword 1 against 0 is made exact: format bit 20 is set where the entry
holds a view.

Corpus (21,608 shaders, by output, against main 2f4d81e0): 14 newly
translated (12 pixel, 2 vertex), 0 regressed, 28 outputs changed
(lanes outside a guarded write kept 0 for the size), 1 refused for
another reason.

Refs #407
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 05:17:38 +00:00
Author
Owner

@⁠AnastasisKon on GitHub · 2026-11-28 18:04 UTC · original · approved these changes

Reviewed and verified locally on head fc52e3bb (worktree /private/tmp/review-563):

  • cargo test -p victory-shader -p victory-gpu: 424+5 passed, 0 failed; the new pins run green: a_texture_size_query_through_four_dwords_translates, a_four_dword_load_read_beyond_an_images_size_fields_stays_refused, a_compute_shader_sizes_textures_from_the_first_half_of_their_descriptors.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: clean (exit 0).
  • cargo xtask policy: 404 files ok (exit 0).

The reader-based image_half detection is conservative (whole-descriptor offset via s_lshl_b32-by-5, size fields plus first level read, dword-1 null test), the refused-case pins cover dword 0 / format / tiling / 32-bit fields / joins / wrong compares, and the docs record both guesses (null-view semantics, image-or-nothing entry) and the 4k+1-width shortcut explicitly, which is what AGENTS.md asks for. The null-test format-bit trick (bit 20 set when entry dword 3 != 0) is documented in both mod.rs and native-host.md.

Note: the branch is behind upstream/main by two README-only commits (bf9cdf17, 26817285); no code conflict, mergeable as-is. Approving.

**@⁠AnastasisKon** on GitHub · 2026-11-28 18:04 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/563#pullrequestreview-6099470989) · **approved these changes** Reviewed and verified locally on head fc52e3bb (worktree /private/tmp/review-563): - cargo test -p victory-shader -p victory-gpu: 424+5 passed, 0 failed; the new pins run green: a_texture_size_query_through_four_dwords_translates, a_four_dword_load_read_beyond_an_images_size_fields_stays_refused, a_compute_shader_sizes_textures_from_the_first_half_of_their_descriptors. - cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings: clean (exit 0). - cargo xtask policy: 404 files ok (exit 0). The reader-based image_half detection is conservative (whole-descriptor offset via s_lshl_b32-by-5, size fields plus first level read, dword-1 null test), the refused-case pins cover dword 0 / format / tiling / 32-bit fields / joins / wrong compares, and the docs record both guesses (null-view semantics, image-or-nothing entry) and the 4k+1-width shortcut explicitly, which is what AGENTS.md asks for. The null-test format-bit trick (bit 20 set when entry dword 3 != 0) is documented in both mod.rs and native-host.md. Note: the branch is behind upstream/main by two README-only commits (bf9cdf17, 26817285); no code conflict, mergeable as-is. Approving.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/567/head:github-bot/gh-563'
git switch 'github-bot/gh-563'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-563'
git switch 'github-bot/gh-563'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-563'
git switch 'github-bot/gh-563'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-563'
git switch 'main'
git merge --squash 'github-bot/gh-563'
git switch 'main'
git merge --ff-only 'github-bot/gh-563'
git switch 'main'
git merge 'github-bot/gh-563'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.