Shaders: coalesce aligned constant-buffer loads #511
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!511
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-511"
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?
@aycow on GitHub · 2026-11-24 04:20 UTC · original
aycow:shaders/coalesce-aligned-cbv-loads→main· +231 −19 · 2 files · 5 commits · openChange
When the per-lane MUBUF CBV path proves a vector read stays within one 16-byte DXIL row, issue one
cbufferLoadLegacy.i32and extract the required dwords. Unaligned offsets, row crossings, variable byte offsets and unproven built bases keep the existing lowering.Current upstream integration
Head
02dc7b2merges cleanly with upstream42363ab. Coalescing applies to the native root CBV lowering. Main routes table CBVs through raw SRVs, and this PR preserves the table lowering. A built root view falls back to scalar loads when an index can shift the address within a 16-byte row, as with a stride of four bytes.The regression runs 176 synthetic dispatches per adapter across raw tables and native root views, including strides of 4, 16, and 32 bytes. AMD Radeon Graphics, GeForce RTX 5070 Laptop GPU, and WARP passed with the D3D12 debug layer and full GPU-based validation. The explicit-adapter run used Agility SDK 1.620.2 and a local startup sampler-heap workaround outside the PR. The unmodified PR head also passed the normal matrix and strict shader Clippy.
The current DXIL dump shows one native row load for the aligned four-dword case and four for the stride-four or dynamic-offset cases. A two-dword row crossing still uses two loads. Current-head GPU timing and title performance have yet to be measured.
Synthetic reproduction and validation
On Windows with Shader Model 6.6, run
cargo test -p victory-shader indexed_cbv_loads_match_their_byte_addresses -- --nocapture. The synthetic GFX10 fixture compares dword, dwordx2, dwordx3 and dwordx4 loads against the CPU reference at every aligned immediate byte offset from 0 to 28, plus dynamic byte offsets 0, 4, 12 and 16 for each width. The regular test runs on the available default hardware adapter and WARP. An explicit-adapter Agility SDK 1.620.2 run of the expanded matrix at0b3c1fdpassed all 48 cases per adapter on AMD Radeon Graphics, NVIDIA RTX 5070 Laptop GPU and WARP with the debug layer and full GPU-based validation. A mutation using the row’s first dword instead of the requested in-row dword failed at byte offset 4, group 0, lane 0. fromthemoonx identified the gap, provided the mutation, and independently validated the preceding lowering on desktop RTX 3060 and WARP. Independent review · Expanded regressionA separate earlier explicit-adapter harness compared baseline and candidate on six offset cases. The aligned module’s input-row loads fell from four to one and channel selects from 12 to zero. Dynamic and row-crossing modules were byte-identical.
Earlier synthetic GPU timing
One dispatch of 4,096 groups × 32 threads wrote a 2 MiB UAV. Both PSOs were created outside the timing brackets. Four warm-up pairs were discarded and 32 measured pairs alternated variants with debug and GPU-based validation off.
NVIDIA improved in all 32 pairs. AMD variation was larger than the median difference. The figures apply to this workload. Title shader frequency and frame impact remain unmeasured.
This PR contains only the shader lowering and its regression. AI-assisted with OpenAI Codex.
Current main validation
Rebased onto
ffe310eafter #566. The per-lane constant-buffer lowering and the expanded 48-case matrix are intact. Seven focused tests passed, including the expanded CBV matrix, the upstream FP16 class case, and all five waterfall tests. A test-only adapter-selection run verified all CBV cases on AMD Radeon Graphics, RTX 5070 Laptop GPU, and WARP with Agility 1.620 and full GPU-based validation.ccfb02996e' into maintenance/pr511-ccfb029 3f9c70ca0ff3578e3' into maintenance/78ed-r511 d320fabee1@fromthemoonx on GitHub · 2026-11-24 05:11 UTC · original
Tested
7beab43(onmaind2a4bae) on desktop NVIDIA, with DXIL validation on (Windows SDK 10.0.26100dxil.dll, found by default).Environment: Windows 11 Pro build 26300, AMD Ryzen 7 5700X, 16 GB, NVIDIA GeForce RTX 3060 12 GB (driver 610.88), Rust 1.98.1
x86_64-pc-windows-msvc, debug.Tested
indexed_cbv_loads_match_their_byte_addresses: passes on the hardware adapter and WARP, 20 of 20 repeated runscargo test --locked -p victory-shader: 70 passed, 0 failedcargo test --locked --workspace: 265 passed, 0 failed, 4 ignoredcargo clippy -p victory-shader --all-targets: no warnings;cargo fmt --check,git diff --check: clean;cargo xtask policy: 151 files okA gap in the regression test. It only uses
buffer_load_dwordx4, which can coalesce only atfirst == 0, so the in-row dword index is never exercised: withextract(c, row, first + k)changed toextract(c, row, k), the test still passes.I added a local variant (below, not pushed). It reuses
build_indexed_cbv_cswithbuffer_load_dword/dwordx2/dwordx3/dwordx4at every immediate offset 0–28 and checks each lane'scountdwords on both backends:first1–3) and row-crossing fallbacks alikefirst != 0So the lowering is right; the test just doesn't pin that part down yet. Adding a narrower load at a non-zero in-row offset (e.g.
dwordx2at offset 8) to the test would cover it.Local variant (throwaway: patches the load opcode through a static)
Not tested: the timing (the harness isn't in the PR); no game data used.
AI-assisted (Claude Code) ran the checks and drafted this comment.
@aycow on GitHub · 2026-11-24 06:45 UTC · original
@fromthemoonx Thanks for spotting the coverage gap and proposing the expanded matrix. I credited the contribution in
0b3c1fd, now on this PR. The test checks dword, dwordx2, dwordx3 and dwordx4 at every aligned byte offset from 0 to 28, plus dynamic offsets for each width.The final regression passed 48 cases per adapter on AMD, NVIDIA and WARP with full GPU-based validation. With your mutation changing
first + ktok, it failed at the first nonzero in-row case: one dword at byte offset 4, group 0, lane 0. The lowering and the previously reported synthetic timing numbers are unchanged.@aycow on GitHub · 2026-11-24 16:26 UTC · original
@catminou4 The #566 conflict is resolved in
ff96ffe, based onffe310e. GitHub reports the branch merges cleanly. The expanded 48-case matrix passed on AMD Radeon Graphics, RTX 5070 Laptop GPU, and WARP with full GPU-based validation using a test-only adapter selector. The five upstream waterfall fixtures and the preserved FP16 class test passed as well.@aycow on GitHub · 2026-11-24 21:37 UTC · original · edited 2026-11-24 21:47 UTC
@catminou4 Update to the re-review request: main advanced after the clean
ffe310echeck. GitHub now shows a conflict with70564ae. I resolved the test-file conflict locally, and full GPU-based validation exposed a material change in683ad7a: table constant buffers now bind as raw SRVs, while #511's historical regression binds CBVs. The 48-case AMD/NVIDIA/WARP results apply toff96ffeonffe310e. I'm checking the remaining native-CBV path before asking for review against the new main.AI-assisted using Codex.
@aycow on GitHub · 2026-11-24 22:17 UTC · original
The current-main table-constant binding has now been tested separately. On
70564aeit is a raw SRV path. A local same-row vector experiment passed 240 cases each on AMD and WARP with full validation. The old CBV regression remains useful historical evidence. A mechanical port also needs a new alignment proof for indexed built root descriptors: current lowering folds the descriptor stride into the address before the old row proof. I'm coordinating the raw case with #1393 and recommend superseding this PR's table-CBV approach once that direction is agreed.AI-assisted using Codex.
@Marvisak on GitHub · 2026-11-25 00:23 UTC · original · edited 2026-11-26 01:23 UTC
Automated triage for the maintainers.
Merge candidate. The new head
d320fabonly merges currentmaininto the branch (conflict resolved invalu_tests.rs); the PR's own change is the same as at the last triage, and it merges cleanly withmain.I re-read the native CBV path of the MUBUF lowering in
crates/victory-shader/src/emit/lower.rsagainst the merged code: coalescing into onecbufferLoadLegacyrow still requires an immediate-only offset (nooffen, no scalar offset, no built base or extra term), a row-aligned index (built root view stride a multiple of 16) andfirst + count <= 4, so the extracted dwords match whatcbuffer_dwordwould read. The raw-SRV table path is untouched.indexed_cbv_loads_match_their_byte_addressesinvalu_tests.rsstill covers every width and aligned offset, tables and strides 4/16/32.CI: passing (
check). Recommending a look, not approving.Generated by Claude Code
@aycow on GitHub · 2026-11-25 01:05 UTC · original
@catminou4 The branch now merges cleanly with main at
02dc7b2. The change keeps native CBV coalescing and adds a stride guard for indexed root views. The 176-dispatch matrix passed on AMD, NVIDIA, and WARP with full GPU-based validation. I updated the description with the scope and the validation setup.@fuzeofficlal on GitHub · 2026-11-26 01:21 UTC · original
Code review and RTX 5090 + WARP + DXIL verification at head
d320fabee173merged cleanly ontomain(63bcca43c6a0;emit/lower.rs=521,706B,2,582B under the 512 KiB cap):crates/victory-shader/src/emit/lower.rs:4881-4890, 9527-9540):cbufferLoadLegacy.i32(h, byte >> 4)only whenimmediate(!*offen && !scalar_offset && base == 0 && extra.is_none()),row_aligned_index(stride.is_multiple_of(16)forSource::Built),offset.is_multiple_of(4), andfirst + count <= 4(guaranteeing no 16-byte row crossing even under 32-bit address wrap). Table CBVs keep theirrawBufferLoadpath untouched.dxil.dll10.0.26100.0,VICTORY_D3D12_DEBUG=1, Rust 1.98.1):cargo xtask policy:191 files ok;cargo clippy -p victory-shader --all-targets -- -D warnings(default +--features diagnostics): 0 warningsemit::lower::tests(33/33),indexed_cbv_loads_match_their_byte_addresses(RTX 5090 + WARP), andemit::semantics_tests(34/34 on both RTX 5090 and WARP, 1 ignored) all passed.LGTM.
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.