Repository navigation
Shaders: use declared structured SRVs for scalar loads and record counts - #995
jeremygold02 wants to merge 2 commits into
Conversation
Use the original PSV binding and the exact native table slot to recover the record count and split scalar byte offsets within structured records. Preserve existing handling of ambiguous, mixed-consumer, and raw views. Refs: Marvisak#136, Marvisak#329, Marvisak#437
Merge upstream main, retain both shader regression tests, and pass absent PSV metadata in the three synthetic fixtures that construct lowering inputs directly. Refs: Marvisak#136, Marvisak#329, Marvisak#437
…ueries smem() splits scalar loads of a structured table SRV into record and offset (Marvisak#984 port), but descriptor_data() made the size query's handle for the same slot a raw view: two kinds for one descriptor, and word 2 reported bytes where the record count was read. Use the structured stride there too. Idea from upstream PR Marvisak#995 (89b6c67, Jeremy Goldberg); its PSV declaration check is not ported (our structured choice follows the table binding as in Marvisak#984). Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
catminou4
left a comment
There was a problem hiding this comment.
Using the declared structured SRV for scalar loads is implemented as a proof, not a heuristic: scalar_structured_stride requires the PSV bindings, an exact single table slot with no other consumers, exactly one matching used-resource entry (kind SRV, 4 dwords, stride 4..=2048 multiple of 4), and singleton_structured_srv on the lower bound — any doubt falls back to the old raw path. The raw-buffer side correctly splits the byte address into record index + within-record offset so wide loads crossing record boundaries land right. record_count_word conservatively bails on mixed consumers and phi-selected descriptors. The +251 lines of native tests plus the emit-side proof test back the guards.
Verified locally: test-merge with main (ffe310e) clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 101 passed / 0 failed / 1 ignored. Scope note: host-execution coverage of the new structured path is Windows-gated; macOS covers compilation and all unit tests. Approving.
|
I compared the same two mission vertex shaders on Windows 11 with Windows SDK 10.0.26100.0. The draw-entry observations for the affected slot are in the earlier verification on #136.
I also ran #984’s separate one-thread buffer-read regression on a physical RTX 5070. I restricted the test adapter loop to hardware and checked the device LUID’s adapter description before dispatch. Both scalar and flat vector reads returned the expected word at all nine offsets across three 56-byte records. That fixture covers a distinct case worth retaining alongside the count-consuming shaders here. The mission shaders were translated offline. |
|
Validated this exact change (78c8078) locally on RX 7900 XT / RADV under Wine 11.18 and vkd3d-proton 3.2.0. The test base also contains the mapped-copy fix and #1056; no title-derived fixtures were used. A synthetic scalar-buffer fixture passed 12 hardware dispatches with exact eight-word readbacks: stride 80, x2/x4 loads across record boundaries at byte offsets 76 and 156, a count-derived last-record address, both count-guard outcomes, and raw-buffer controls with the same native stride. Canary words remain intact. The raw count remains refused rather than being inferred from stride. Microsoft DXIL validator release 1.7.2308 was required and passed. The identical declaration/count fixture on the test-only parent reproduces the original scalar-memory-read refusal; the patched candidate passes. This establishes those scalar cases, not full game correctness or performance. |
|
Independent verification at
AI-assisted verification on local RTX 5070 Ti + WARP; no game data. |
Offline measurement on a retail dump, and the shader tests on AdaResult: +15 programs over Offline. I merged head 78c8078 onto
All 15 are among the programs that #1319 gains. Another 114 programs move from "a scalar memory read as data" on to "a descriptor's address or format read as data". That is the reason #1597 targets, and I'm measuring this PR stacked on #1597. Tests: with the same merge, No shader names or data are included, per the asset policy. AI-assisted (Claude Code). |
|
Hardware note from testing on AMD Radeon RX 6900 XT (RDNA2), Adrenalin driver While verifying structured SRVs on hardware in a local integration build ( This directly supports #995's motivation on AMD RDNA2 hardware. (No game assets or dumps attached; tested with AI assistance.) |
|
Automated triage for the maintainers. Closing because this change is already in Structured addressing for scalar loads chosen from PSV0, and record counts: main settled this the other way (scalar loads read raw views by byte address, emit/mod.rs notes) and reads record counts through getDimensions (75677cb). If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution. |
… too A structured view's dword 1 holds the stride in its high half, which GetDimensions reads, and the address in its low half. descriptor_data gives the word no value, so a direct read is refused either way; at a join with data it is now the undefined path, as for a raw view. Without this, a PR that turns raw views into structured ones (Marvisak#995) loses programs that the raw-view rule covered. On a retail dump: 1 more program validates, none lost.
Stacked results
The merge with #1402 conflicts in 4 hunks (
This PR's test Method: |
Scalar
s_buffer_load_dword*instructions use byte addresses. Onffe310e, a descriptor-table SRV takes the raw-buffer path even when the original shader declares a structured SRV. Reading descriptor word 2 (NUM_RECORDS) as ordinary data can also stop translation. Native stride alone cannot identify the view because a raw SRV can carry the same stride metadata.This change checks the original
PSV0declaration and the exact, statically addressed native table slot. A unique, single-register structured SRV with a matching native binding uses structured addressing. Each dword of a wide load gets its own record index and byte offset, including when the load crosses a record boundary. A use of the record count as ordinary data or through a phi obtains it fromGetDimensions. Loads that only need the descriptor handle omit that query. Raw, ambiguous, dynamically selected and mixed-consumer bindings keep their existing behavior.Relationship to other PRs
#984, opened while this branch was being verified, also splits each scalar dword address and covers flat vector loads, stores and atomics. It selects the structured path from table binding and aligned stride. The scalar address arithmetic overlaps. This patch adds the declaration and slot check and recovers the consumed record count for that same structured SRV.
#136 demonstrated the structured scalar case using native stride. #329 recovers counts for descriptors with no tracked resource consumer. #437 preserves raw scalar loads, and #953 uses a raw view to query size for a scalar consumer. The case here reads an element count from a declared structured view and addresses each scalar dword within that view.
Verification
ffe310e, all five new regression tests and the upstream stencil-export test passed with Windows SDK 10.0.26100.0dxil.dll. The broadervictory-shaderlibrary run passed 103 tests, with one benchmark ignored and 22 GPU or differential cases filtered.cargo clippy --locked -p victory-shader --all-targets --all-features -- -D warningspassed.c2e7254, two vertex shaders failed on the scalar descriptor-data read. Both translated and passed SDK validation on89b6c67. Each emitted one live count query and 21 dword loads split into record index and byte offset.89b6c67reproduced the three hardware-tested DXIL containers byte for byte.d2a4baecovered 25,694 inputs. Fifteen additional shaders passed SDK validation and all 21,971 previously valid shaders still passed. The emitted code changed for 18,136 of those previously valid shaders.Gameplay impact remains unverified.