Shaders/Lower: align and extract sub-dword buffer_load_{ubyte,sbyte,ushort,sshort} on CBVs #3006
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3008"
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 Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T03:19:27Z.
Lower::buffer's early-return path forResourceType::Cbv(crates/victory-shader/src/emit/lower.rs:9481-9523) previously ignoredsub = Some((8 | 16, signed)):RootType::Table): passed unaligned byte offsets directly torawBufferLoad.f32withalign = 4and returned the full unshifted 32-bit dword.RootType::Descriptor): calledcbuffer_dword()and returned all 32 bits of the containing dword without shifting right by(byte & 3) * 8or zero-/sign-extending the 8- or 16-bit lane.Fix:
Lower::extract_sub(w, byte, width, signed)shared with the SRV/UAV sub-dword path (keepinglower.rsat521,524 B, well under the 512 KiB asset-policy limit).byte & !3), refreshlet c = self.curafterraw_view, and applyextract_subon both table and root CBVs.&& !store && atomic.is_none().Verification
cbv_subdword_dxil_distinguishes_width_and_signednessfailed (table_cbv: ubyte and sbyte must differ) —ubyte,sbyte,ushort,sshortemitted identical DXIL on CBVs.buffer_load_{ubyte,sbyte,ushort,sshort}) across both table CBV and root CBV passdxil.dllvalidation and execute bit-exact zero-/sign-extended byte & short reads on WARP SM 6.6 inemit/lower/cbv_subdword_tests.rs.--tests+--features diagnosticsclippy,xtask policy, full workspace tests): RVZO6/VIctory CI run #45747688145 (green, combined Wave 9 check on63bcca4).AI-assisted: T3 Code (Antigravity, gemini-4-neon).
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T03:32:29Z.
Review: APPROVED
Tested merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP,dxil.dllvalidator active):cargo test -p victory-shader --lib cbv_subdword_tests: 2 passed, 0 failed (cbv_subdword_dxil_distinguishes_width_and_signednessandcbv_subdword_loads_extract_and_extend_bytes_and_shortspass on RTX 5090 hardware and WARP).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T03:38:41Z.
Review: CHANGES_REQUESTED
Code review on
0f35c0b9(static source inspection; no runtime GPU/DXIL validation executed):crates/victory-shader/src/emit/lower.rs:9495, 9536-9588,crates/victory-gpu/src/descriptor/host.rs:1471):&& !store && atomic.is_none()to theResourceType::Cbvcheck atlower.rs:9495lets any store or atomic referencing a tracked table CBV fall through tolet uav = store || atomic.is_some() || ...(:9536), emitting a UAV write/atomic against a descriptor that the host binds as a raw SRV. Returning an explicitErr(...)for writes/atomics onResourceType::Cbvbefore falling through avoids emitting an invalid D3D12 binding.extract_subsilently truncates 16-bit loads straddling a 4-byte boundary (crates/victory-shader/src/emit/lower.rs:4907-4922, 9542, 9554):(w >> ((byte & 3) * 8))without checking alignment. Forushort/sshort(width == 16) atbyte % 4 == 3, the high byte lies in the next dword and is silently dropped/zeroed. Suggest either checking/rejecting unaligned halfword offsets or combining the adjacent dword if RDNA2 allows unalignedbuffer_load_ushort/sshort.emit/lower.rsis521,524 B(within the 512 KiB limit).Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T04:41:31Z.
Review: APPROVED
LGTM — extract_sub does the textbook align-down + shift + sign/zero extension; the CBV gate correctly excludes stores and atomics now, and the align-down applies only when a sub-dword load exists. Test file covers the store/load matrix.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T06:16:48Z.
Automated triage for the maintainers.
The main fix looks right. In
main, the CBV early return inLower::buffer(emit/lower.rs) ignoressub, sobuffer_load_{ubyte,sbyte,ushort,sshort}on a constant buffer returns the whole containing dword. The PR fixes both paths:cbuffer_dwordalready selects the dword from an unaligned address, and the PR adds the shift and extend.The new shared
extract_subhelper is the same code the SRV/UAV path used.What it needs: the PR also changes the early-return guard to
&& !store && atomic.is_none(). That sends stores and atomics on a descriptor used as a CBV into the general UAV path (uav = store || …), which asks for a writable handle on a resource the root signature binds as a constant buffer. Nothing tests that path or explains what it lowers to. A store to a CBV is clearly wrong today, since it is lowered as a load. Either have it return an explicitErr("a store or atomic on a constant buffer"), or drop the guard from this PR. Then this would be a good candidate.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by RVZO6 on 2026-11-26T08:26:47Z.
Addressed the review comment in
2829f99:if used.is_some_and(|u| u.kind == ResourceType::Cbv) && !typed {entry condition incrates/victory-shader/src/emit/lower.rsand explicitly refusedstore || atomic.is_some()on a CBV (return Err("a store or atomic to a constant buffer")) sobuffer_store_*/buffer_atomic_*against a CBV descriptor can never fall through into the raw-buffer/UAV write path.cbv_store_and_atomic_are_refusedincrates/victory-shader/src/emit/lower/cbv_subdword_tests.rs(confirmed failing before the fix and passing after).windows-latestMSVC + WARP SM 6.6 CI (policy, clippy default +--all-features, full workspace tests): https://github.com/RVZO6/VIctory/actions/runs/45782627843.Not run: the title; any hardware GPU.
AI-assisted: T3 Code (Antigravity, gemini-4-neon).
Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-26T08:48:49Z.
I checked the halfword-at-offset-3 question from the review on
2829f99a. The RTX 4090 Laptop and Microsoft WARP returned the same values through both a root CBV and a table CBV. All reads were inside a live 256-byte buffer.With bytes 2–5 set to
34 81 92 5e,buffer_load_ushortat offsets 2, 3, 4 returned00008134,00000081,00005e92. The signed variant returnedffff8134,00000081,00005e92. Changing only byte 4 from92to16changed offset 4 to00005e16in every variant. Offset 3 remained00000081. The output guard held through all 16 dispatches. The byte in the next dword reaches the GPU and contributes to the aligned read at offset 4, but does not contribute to the halfword at offset 3 on this revision.The RDNA 2 ISA, §8.1.7 specifies several alignment modes. On the first input, an unaligned unsigned halfword would be
9281, while automatic natural alignment would select8134. The two strict modes require halfword alignment. I have no measurement of the console setting for this path. The opt-in readback asserts the aligned controls and guard and reports the crossing value for comparison. From the evidence revision, runcargo test --locked -p victory-shader --features host --lib emit::lower::cbv_subdword_tests::observe_interior_halfword_offsets -- --exact --ignored --nocapture --test-threads=1.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T09:17:43Z.
Review: COMMENTED
Verified
2829f99alocally on Windows 11 x64 (dxil.dll10.0.26100.0):cargo clippy -p victory-shader --all-targets --locked -- -D warnings(default and--all-features): clean (2.67s/2.03s).cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed, 0 failed (0.35s).cargo test -p victory-shader --lib --locked cbv_subdword_tests -- --test-threads=1: 3 passed, 0 failed on both RTX 5090 + WARP (0.73s) andVICTORY_WARP=1(0.07s).cargo test -p victory-shader --lib --locked emit::lower::tests: 33 passed, 0 failed (0.02s).emit/lower.rsis521,613bytes (2,675bytes under the 524,288-byte policy cap).The explicit
"a store or atomic on a constant buffer"rejection atlower.rs:9499-9501resolves the raw CBV write fallthrough, andextract_sub/byte & !3/raw_viewcursor refresh are sound for in-dword reads. Three minor notes:&& !typed, a formattedbuffer_store_format_*on a tracked table CBV can still reach the typed UAV path; moving thestore || atomic.is_some()guard ahead of!typedwould close that too.byte % 4 == 3, 16-bit loads still return only the top byte of that dword (matching the existing SRV/UAV path at:9785-9806and the reported RTX/WARP readback); documenting that assumption and adding an odd-offset control incbv_subdword_tests.rswould be helpful.rustfmt --edition 2024 --checkflags two small formatting lines incbv_subdword_tests.rs(:174and:278).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.