gpu, shader: give a buffer descriptor's stride, record count and type word to programs that read them (53 shaders) #390
No reviewers
Labels
No labels
accessibility
bug
claimed
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
tester report
urgent
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LakshanSivakumar--Native-Victory-macOS!390
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-387"
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?
@derz92 on GitHub · 2026-11-27 16:09 UTC · original
derz92:fix/buffer-descriptor-words→main· +196 −20 · 5 files · 1 commits · openWhat this changes
Refs #389.
Host (
victory-gpu/src/native/descriptors.rs,host.rs):buffer_wordsbuilds the console's buffer descriptor words for a buffer view.NativeHost::address_wordswrites them into the view addresses (t1) in place of[address, 0, 0]:NUM_RECORDS(elements, or bytes for a raw view);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"):
How it was tested
examples/sweepon the 19,173 shaders one run registered (Series S, through the story load), main728845d1vs this branch,tools/corpus/compare.sh: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).--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 withUnsupported { 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 excepthost_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 warningscargo xtask policyChecklist
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@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 (
b998bb65is 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 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.
c091cbdaagainst its base728845d1, 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_dwordx4of 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 withknown = 4because a texture view's entry already holdstexture_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_bitsdoes 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 on GitHub · 2026-11-27 19:45 UTC · original
Rebased onto main
be7dc1b5, which reworkedview_addressesto per-dword masks of what the table holds (seen_bits). This PR now fits into that:BUFFERmasks take a buffer's dwords 0-3 as held, since the host writes them (descriptors::buffer_words);view_address_fields_the_table_gives_as_0_are_refusedis 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):
Checks rerun:
victory-shader382 passed,victory-gpu --lib373 passed, Windows clippy clean,xtask policyok.c091cbdaa0toc8f6870e27gpu, 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)c8f6870e27to724f81e6bc@derz92 on GitHub · 2026-11-27 19:52 UTC · original
@Sandile-0511 thanks, agreed. I've rebased onto
b998bb65and kept the buffer fields only:BUFFERnow takes a buffer's dword 1 bits 0-29 (address high bits and stride) and dwords 2-3 as held;Against main
b998bb65on my corpus (19,173 shaders):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 on GitHub · 2026-11-28 17:34 UTC · original · approved these changes
Read the diff:
buffer_wordsindescriptors.rsbuilds 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) andNativeHost::address_wordswrites 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.rsreads them back fordescriptor_data. Tests updated ingfx_refusal_tests, docs paragraph added. Verified on the head724f81e6: darwinvictory-gpudescriptor tests 33/33, hostvictory-shadergfx_refusal tests 68/68, workspace windows clippy-D warningsclean. Approving.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.