gpu, shader: give a buffer descriptor's stride, record count and type word to programs that read them (53 shaders) #390

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

@⁠derz92 on GitHub · 2026-11-27 16:09 UTC · original
derz92:fix/buffer-descriptor-words → main · +196 −20 · 5 files · 1 commits · open

What this changes

Refs #389.

  • Host (victory-gpu/src/native/descriptors.rs, host.rs): buffer_words builds the console's buffer descriptor words for a buffer view. NativeHost::address_words writes them into the view addresses (t1) in place of [address, 0, 0]:

    • dword 0, and dword 1 bits 0-15: base address;
    • dword 1 bits 16-29: stride (the element size, 0 for a raw view);
    • dword 2: NUM_RECORDS (elements, or bytes for a raw view);
    • dword 3: a nominal type word (identity channel selects, a 32-bit float format, RESOURCE_LEVEL 1, OOB_SELECT 3 for a raw view or 0).

    Constant buffers and whole-buffer views are raw.

  • Translator (lower.rs, view_addresses): a buffer descriptor's dwords 0-3, not 0-1, are read from the view addresses.

  • Guesses, marked in the code and in docs/native-host.md ("View addresses on the native host"):

    • the console's driver writes a structured view's stride and element count, a typed view's element size and count, and a raw view's stride 0 and size in bytes;
    • dword 3's format field isn't the view's own. The programs here read it to rebuild a descriptor (#389), not to choose a format.

How it was tested

  • Corpus: examples/sweep on the 19,173 shaders one run registered (Series S, through the story load), main 728845d1 vs this branch, tools/corpus/compare.sh:
    • Updated after the rebase onto #311 (b998bb65): 53 newly translated (52 vertex, 1 compute: record-count reads), 0 regressions, 54 outputs changed. The first version's +419 also counted four-dword texture reads; those stay refused here and are left to #411 (see the comments).
    • 0 regressions;
    • 269 now stop at a later refusal (mostly lane-mask reads);
    • 55 output changed: shaders that load a buffer descriptor's dwords 2-3 and never use them, which now read them from the view addresses.
  • Game run: Apple M5 Max, 36 GB, macOS 26.5, --console series-s, heap residency. With this plus our other open PRs and #386, the world ran with no GPU errors, and distinct refused shaders in the run went from 434 to 286. The scene's G-buffer shows the prologue's interior. The window is still grey for the reasons on #258.
  • cargo test -p victory-shader: 373 passed. New: gfx_refusal_tests::a_buffer_descriptors_record_count_and_type_word_read_as_numbers_translate. A program reads dwords 2 and 3 of a table SRV as numbers and stores them. It failed on main with Unsupported { what: "a descriptor read only as data" }, which I checked by putting the old limit back.
  • cargo test -p victory-gpu --lib (arm64): 361 passed. New: descriptors::tests::buffer_views_give_the_console_descriptor_words, covering structured, raw, typed, whole-buffer and constant-buffer views.
  • cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory: all pass except host_posix::ucrt::tests::dlls_that_are_not_the_c_runtime_are_left_alone, which fails the same way on main.
  • cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings
  • cargo xtask policy

Checklist

  • No game files, game code, disassembly listings or SDK files are included (counts, hashes and refusal messages only)
  • 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 (no new diagnostics)
**@⁠derz92** on GitHub · 2026-11-27 16:09 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/387) `derz92:fix/buffer-descriptor-words` → `main` · +196 −20 · 5 files · 1 commits · open ## What this changes Refs #389. - **Host** (`victory-gpu/src/native/descriptors.rs`, `host.rs`): `buffer_words` builds the console's buffer descriptor words for a buffer view. `NativeHost::address_words` writes them into the view addresses (`t1`) in place of `[address, 0, 0]`: - dword 0, and dword 1 bits 0-15: base address; - dword 1 bits 16-29: stride (the element size, 0 for a raw view); - dword 2: `NUM_RECORDS` (elements, or bytes for a raw view); - dword 3: a nominal type word (identity channel selects, a 32-bit float format, RESOURCE_LEVEL 1, OOB_SELECT 3 for a raw view or 0). Constant buffers and whole-buffer views are raw. - **Translator** (`lower.rs`, `view_addresses`): a buffer descriptor's dwords 0-3, not 0-1, are read from the view addresses. - **Guesses**, marked in the code and in docs/native-host.md ("View addresses on the native host"): - the console's driver writes a structured view's stride and element count, a typed view's element size and count, and a raw view's stride 0 and size in bytes; - dword 3's format field isn't the view's own. The programs here read it to rebuild a descriptor (#389), not to choose a format. ## How it was tested - **Corpus:** `examples/sweep` on the 19,173 shaders one run registered (Series S, through the story load), main 728845d1 vs this branch, `tools/corpus/compare.sh`: - **Updated after the rebase onto #311 (b998bb65):** 53 newly translated (52 vertex, 1 compute: record-count reads), 0 regressions, 54 outputs changed. The first version's +419 also counted four-dword texture reads; those stay refused here and are left to #411 (see the comments). - **0 regressions**; - 269 now stop at a later refusal (mostly lane-mask reads); - **55 output changed:** shaders that load a buffer descriptor's dwords 2-3 and never use them, which now read them from the view addresses. - **Game run:** Apple M5 Max, 36 GB, macOS 26.5, `--console series-s`, heap residency. With this plus our other open PRs and #386, the world ran with no GPU errors, and **distinct refused shaders in the run went from 434 to 286**. The scene's G-buffer shows the prologue's interior. The window is still grey for the reasons on #258. - [x] `cargo test -p victory-shader`: 373 passed. New: `gfx_refusal_tests::a_buffer_descriptors_record_count_and_type_word_read_as_numbers_translate`. A program reads dwords 2 and 3 of a table SRV as numbers and stores them. It failed on main with `Unsupported { what: "a descriptor read only as data" }`, which I checked by putting the old limit back. - [x] `cargo test -p victory-gpu --lib` (arm64): 361 passed. New: `descriptors::tests::buffer_views_give_the_console_descriptor_words`, covering structured, raw, typed, whole-buffer and constant-buffer views. - [x] `cargo test --target x86_64-apple-darwin -p victory-hle -p victory-loader -p victory`: all pass except `host_posix::ucrt::tests::dlls_that_are_not_the_c_runtime_are_left_alone`, which fails the same way on main. - [x] `cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings` - [x] `cargo xtask policy` ## Checklist - [x] No game files, game code, disassembly listings or SDK files are included (counts, hashes and refusal messages only) - [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 (no new diagnostics)
The console compiler reads a buffer descriptor's dwords as numbers to
size a loop (GetDimensions: the record count in dword 2) or to make a raw
view of a structured one (clear dword 1's stride, multiply the record
count by it, set dword 3's OOB_SELECT to raw). The view addresses held
only the base address, so those programs were refused ("a descriptor
read only as data").

The host's view addresses now hold the console's dwords 0-2 of a buffer
view (address, stride, record count) and a nominal dword 3, and the
translator reads dwords 0-3 of a buffer descriptor from them.

On a corpus of the 19,173 shaders one run registered: 419 more translate,
0 regress, 55 that translated before change output (they load dwords 2-3
and leave them unused). In a world run the distinct refused shaders went
from 434 to 286.

Refs #386
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 16:13:17 +00:00
github-bot referenced this pull request from a commit 2026-11-27 16:29:45 +00:00
Author
Owner

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

Leaving this open for now: it conflicts with main in emit/lower.rs and docs/native-host.md since #311 landed (b998bb65 is the current head). #311 refuses view-address fields the table gives as 0, and this PR is what fills some of those fields, so the two need to be put together on purpose rather than merged mechanically. Could you rebase it on main? I'll sweep it once it is.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 16:29 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/387#issuecomment-7223315223) Leaving this open for now: it conflicts with main in emit/lower.rs and docs/native-host.md since #311 landed (b998bb65 is the current head). #311 refuses view-address fields the table gives as 0, and this PR is what fills some of those fields, so the two need to be put together on purpose rather than merged mechanically. Could you rebase it on main? I'll sweep it once it is.
Author
Owner

@⁠Sandile-0511 on GitHub · 2026-11-27 17:01 UTC · original

A sweep of this head on a second corpus, with one thing for the rebase onto #311.

c091cbda against its base 728845d1, 21,608 shaders (every shader the title registered in a run that reached the world), by output: 421 newly translated (353 compute, 14 pixel, 54 vertex), 0 regressions, 55 changed.

53 of the 421 (52 vertex, 1 compute) are reads of a buffer's record count. The other 368 (352 compute, 14 pixel, 2 vertex), which are all 69 of the gains bound in the world here, read a texture: s_load_dwordx4 of the first four dwords of the descriptor at a per-lane heap index, then the width's low 2 bits from dword 1 (s_bfe_u32), the rest of the width and the height from dword 2, the base level from dword 3, and a test of dword 1 against 0 for a null view. They translate with known = 4 because a texture view's entry already holds texture_words. The size fields are the ones the table holds. The test is not: the table holds dword 1 as the width's low 2 bits only, so a texture of width 1, 5, 9 and so on reads as a null view. docs/native-host.md ("Descriptor dwords read as data") keeps the shape refused for that reason, and on main these are the 723 shaders refused as "a buffer's stride or swizzle".

Details, counts and a plan for the texture half are in #411. I suggest this PR keeps the buffer fields and leaves four-dword texture reads refused, as seen_bits does on main. Say if you would rather fold it in here.

AI-assisted: sweeps and summary done with Claude Code on my own machine; I reviewed the text.

**@⁠Sandile-0511** on GitHub · 2026-11-27 17:01 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/387#issuecomment-7223931300) A sweep of this head on a second corpus, with one thing for the rebase onto #311. `c091cbda` against its base `728845d1`, 21,608 shaders (every shader the title registered in a run that reached the world), by output: 421 newly translated (353 compute, 14 pixel, 54 vertex), 0 regressions, 55 changed. 53 of the 421 (52 vertex, 1 compute) are reads of a buffer's record count. The other 368 (352 compute, 14 pixel, 2 vertex), which are all 69 of the gains bound in the world here, read a texture: `s_load_dwordx4` of the first four dwords of the descriptor at a per-lane heap index, then the width's low 2 bits from dword 1 (`s_bfe_u32`), the rest of the width and the height from dword 2, the base level from dword 3, and a test of dword 1 against 0 for a null view. They translate with `known = 4` because a texture view's entry already holds `texture_words`. The size fields are the ones the table holds. The test is not: the table holds dword 1 as the width's low 2 bits only, so a texture of width 1, 5, 9 and so on reads as a null view. `docs/native-host.md` ("Descriptor dwords read as data") keeps the shape refused for that reason, and on main these are the 723 shaders refused as "a buffer's stride or swizzle". Details, counts and a plan for the texture half are in #411. I suggest this PR keeps the buffer fields and leaves four-dword texture reads refused, as `seen_bits` does on main. Say if you would rather fold it in here. *AI-assisted: sweeps and summary done with Claude Code on my own machine; I reviewed the text.*
Author
Owner

@⁠derz92 on GitHub · 2026-11-27 19:45 UTC · original

Rebased onto main be7dc1b5, which reworked view_addresses to per-dword masks of what the table holds (seen_bits). This PR now fits into that:

  • the BUFFER masks take a buffer's dwords 0-3 as held, since the host writes them (descriptors::buffer_words);
  • main's view_address_fields_the_table_gives_as_0_are_refused is updated: a buffer's stride, record count, type word and whole dword 1 are now accepted cases, and the image cases are unchanged.

One more guess (marked in the code and docs): dword 1's swizzle bits (30-31) read 0, taking SWIZZLE_ENABLE off for the views a title makes. Without it, 612 programs that make a raw view of a structured one (and dword1, 0xc000ffff) stopped at "a buffer's swizzle" instead.

Corpus against the new main (same 19,173 shaders):

  • 420 newly translated (353 compute, 14 pixel, 53 vertex);
  • 0 regressions;
  • 268 now stop at a later refusal (mostly lane-mask reads);
  • 55 outputs changed: they load dwords 2-3 and leave them unused.

Checks rerun: victory-shader 382 passed, victory-gpu --lib 373 passed, Windows clippy clean, xtask policy ok.

**@⁠derz92** on GitHub · 2026-11-27 19:45 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/387#issuecomment-7226842605) Rebased onto main be7dc1b5, which reworked `view_addresses` to per-dword masks of what the table holds (`seen_bits`). This PR now fits into that: - the `BUFFER` masks take a buffer's **dwords 0-3 as held**, since the host writes them (`descriptors::buffer_words`); - main's `view_address_fields_the_table_gives_as_0_are_refused` is updated: a buffer's stride, record count, type word and whole dword 1 are now accepted cases, and the image cases are unchanged. **One more guess (marked in the code and docs):** dword 1's swizzle bits (30-31) read 0, taking SWIZZLE_ENABLE off for the views a title makes. Without it, 612 programs that make a raw view of a structured one (`and dword1, 0xc000ffff`) stopped at "a buffer's swizzle" instead. **Corpus against the new main** (same 19,173 shaders): - **420 newly translated** (353 compute, 14 pixel, 53 vertex); - **0 regressions**; - 268 now stop at a later refusal (mostly lane-mask reads); - 55 outputs changed: they load dwords 2-3 and leave them unused. Checks rerun: `victory-shader` 382 passed, `victory-gpu --lib` 373 passed, Windows clippy clean, `xtask policy` ok.
github-bot force-pushed github-bot/gh-387 from c091cbdaa0 to c8f6870e27 2026-11-27 19:51:47 +00:00 Compare
github-bot changed title from gpu, shader: give a buffer descriptor's stride, record count and type word to programs that read them (419 shaders) to gpu, shader: give a buffer descriptor's stride, record count and type word to programs that read them (53 shaders) 2026-11-27 19:57:16 +00:00
github-bot force-pushed github-bot/gh-387 from c8f6870e27 to 724f81e6bc 2026-11-27 19:57:17 +00:00 Compare
Author
Owner

@⁠derz92 on GitHub · 2026-11-27 19:52 UTC · original

@⁠Sandile-0511 thanks, agreed. I've rebased onto b998bb65 and kept the buffer fields only:

  • BUFFER now takes a buffer's dword 1 bits 0-29 (address high bits and stride) and dwords 2-3 as held;
  • the top two bits of dword 1 stay refused, now as "a buffer's swizzle (or a texture's dword 1, #411)", so four-dword texture reads are left for #411;
  • the earlier note about the swizzle reading 0 is dropped.

Against main b998bb65 on my corpus (19,173 shaders):

  • 53 newly translated (52 vertex, 1 compute: record-count reads);
  • 0 regressions;
  • 54 outputs changed (they load dwords 2-3 and leave them unused);
  • the 721 that main refuses as "a buffer's stride or swizzle" now name the swizzle and #411 instead.

The PR description's +419 counted the texture-shaped reads, which are now excluded; I'll update it.

Checks: victory-shader 403 passed, victory-gpu --lib 413 passed, Windows clippy clean, policy ok.

**@⁠derz92** on GitHub · 2026-11-27 19:52 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/387#issuecomment-7226957164) @⁠Sandile-0511 thanks, agreed. I've rebased onto b998bb65 and kept the buffer fields only: - `BUFFER` now takes a buffer's dword 1 bits 0-29 (address high bits and stride) and dwords 2-3 as held; - the top two bits of dword 1 stay refused, now as "a buffer's swizzle (or a texture's dword 1, #411)", so four-dword texture reads are left for #411; - the earlier note about the swizzle reading 0 is dropped. Against main b998bb65 on my corpus (19,173 shaders): - **53 newly translated** (52 vertex, 1 compute: record-count reads); - **0 regressions**; - 54 outputs changed (they load dwords 2-3 and leave them unused); - the 721 that main refuses as "a buffer's stride or swizzle" now name the swizzle and #411 instead. The PR description's +419 counted the texture-shaped reads, which are now excluded; I'll update it. Checks: victory-shader 403 passed, victory-gpu --lib 413 passed, Windows clippy clean, policy ok.
Author
Owner

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

Read the diff: buffer_words in descriptors.rs builds the console buffer-descriptor words (base address, stride in dword 1 bits 16-29, NUM_RECORDS in dword 2, nominal type word in dword 3) and NativeHost::address_words writes them into the view addresses, so programs reading a descriptor's own fields (53 shaders, #389) get real values instead of [address, 0, 0]; lower.rs reads them back for descriptor_data. Tests updated in gfx_refusal_tests, docs paragraph added. Verified on the head 724f81e6: darwin victory-gpu descriptor tests 33/33, host victory-shader gfx_refusal tests 68/68, workspace windows clippy -D warnings clean. Approving.

**@⁠AnastasisKon** on GitHub · 2026-11-28 17:34 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/387#pullrequestreview-6099360984) · **approved these changes** Read the diff: `buffer_words` in `descriptors.rs` builds the console buffer-descriptor words (base address, stride in dword 1 bits 16-29, NUM_RECORDS in dword 2, nominal type word in dword 3) and `NativeHost::address_words` writes them into the view addresses, so programs reading a descriptor's own fields (53 shaders, #389) get real values instead of `[address, 0, 0]`; `lower.rs` reads them back for `descriptor_data`. Tests updated in `gfx_refusal_tests`, docs paragraph added. Verified on the head 724f81e6: darwin `victory-gpu` descriptor tests 33/33, host `victory-shader` gfx_refusal tests 68/68, workspace windows clippy `-D warnings` clean. 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/390/head:github-bot/gh-387'
git switch 'github-bot/gh-387'

Merge

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