gpu, shader: give a buffer descriptor's stride, record count and type word to programs that read them (53 shaders) #387
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
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_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 #407 (see the comments).--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 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)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 (
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.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.
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 #407. 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.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T19:45:32Z.
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.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by derz92 on 2026-11-27T19:52:41Z.
@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.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T17:34:18Z.
Review: APPROVED
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, #386) 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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.