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

Open
derz92 wants to merge 1 commit from upstream-pr/387 into main
derz92 commented 2026-11-27 16:09:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T16:09:14Z.


What this changes

Refs #386.

  • 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 (#386), 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 #407 (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 #383, 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)
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5529673041 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/387). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T16:09:14Z. --- ## What this changes Refs #386. - **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 (#386), 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 #407 (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 #383, 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)
LakshanSivakumar commented 2026-11-27 16:29:07 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:29:07Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223315223 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/387#issuecomment-7223315223). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T16:29:07Z. --- 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.
Sandile-0511 commented 2026-11-27 17:01:04 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sandile-0511 on 2026-11-27T17:01:04Z.


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 #407. 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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7223931300 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/387#issuecomment-7223931300). Originally posted by [Sandile-0511](https://github.com/Sandile-0511) on 2026-11-27T17:01:04Z. --- 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 #407. 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.*
derz92 commented 2026-11-27 19:45:32 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T19:45:32Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7226842605 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/387#issuecomment-7226842605). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T19:45:32Z. --- 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 commented 2026-11-27 19:52:41 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T19:52:41Z.


@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, #407)", so four-dword texture reads are left for #407;
  • 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 #407 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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7226957164 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/387#issuecomment-7226957164). Originally posted by [derz92](https://github.com/derz92) on 2026-11-27T19:52:41Z. --- @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, #407)", so four-dword texture reads are left for #407; - 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 #407 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.
AnastasisKon commented 2026-11-28 17:34:18 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T17:34:18Z.

Review: APPROVED


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, #386) 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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6099360984 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/387#pullrequestreview-6099360984). Originally posted by [AnastasisKon](https://github.com/AnastasisKon) on 2026-11-28T17:34:18Z. **Review:** APPROVED --- 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, #386) 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/387:upstream-pr/387'
git switch 'upstream-pr/387'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/387'
git switch 'upstream-pr/387'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/387'
git switch 'upstream-pr/387'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/387'
git switch 'main'
git merge --squash 'upstream-pr/387'
git switch 'main'
git merge --ff-only 'upstream-pr/387'
git switch 'main'
git merge 'upstream-pr/387'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!387
No description provided.