Shaders: lower partial-channel and dmask=0 image_store #3403
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!3403
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3403"
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?
@Texbirds on GitHub · 2026-11-26 22:29 UTC · original
Texbirds:feat/shader-partial-image-stores→main· +606 −69 · 6 files · 2 commits · openProblem
In
crates/victory-shader/src/emit/lower.rs(Lower::image),image_storecurrently refuses any instruction withdmask != 0xF("an image store of some channels"), preventing translation of compute and pixel shaders that write 1-, 2-, or 3-channelRWTextureUAVs (R32_FLOAT,R32_UINT,R16_FLOAT,R16G16_FLOAT,R32G32_FLOAT, etc.). In addition,dmask == 0was normalized todmask = 1before checkingstore, even though RDNA2IMAGE_STOREwithdmask = 0is a no-op.Root cause
Lower::imageassumed everyimage_storesupplied all four channels (dmask == 0xF) and indexedvdataby output channelk(0..4) rather than by the packed index of enableddmaskbits.Solution
Lower::image(crates/victory-shader/src/emit/lower.rs):raw_dmaskbefore the load/sample0 -> 1adjustment, and treatimage_storewithraw_dmask == 0as a no-op (Ok(())) while continuing to refuseimage_store_mip/_pck.raw_dmask-enabled channels fromvdatain ascending bit order (withd16reading two 16-bit halves per VGPR, low half first, indmaskbit order), fill disabled channels with0.0f, and emitdx.op.textureStore.f32with write mask0xF.crates/victory-shader/src/emit/host.rs:#[cfg(test)] View::TypedTextureUav(DXGI_FORMAT, u32, u32, u32)and passr.GetDesc().Formattofootprint_assoCopyTextureRegionzeroing and readback match the texture's DXGI format.Correctness
WRITEMASKFORTYPEDUAVSTORE(write mask0xF) andWRITEMASKMATCHVALUEFORUAVSTORE(non-undef0.0fvalues for disabled channels).IMAGE_STOREis a whole-texel store (not a partial-channel RMW); D3D12 hardware drops channels past the bound UAV format's channel count, anddmask = 0leaves memory untouched.begin_guarded(guard)EXEC/helper-lane guarding and supports all existing UAV dimensions (1D,2D,3D,1DArray,2DArray).Testing
All synthetic GFX10 compute shaders (no game data):
emit::lower::image_store_tests::partial_dmask_and_d16_image_stores_lower_and_validate: lowers and validates (dxil.dll) all 15 non-zerodmaskvalues in 32-bit andd16modes on 2D UAVs, plus 1D, 3D, 1DArray, and 2DArray dimensions.emit::lower::image_store_tests::image_store_with_zero_dmask_is_noop: verifiesdmask = 0lowers and validates cleanly.emit::lower::image_store_tests::image_store_mip_is_still_refused: verifiesimage_store_mipremains refused.emit::stride_tests::partial_dmask_image_stores_write_typed_texture_uavs: hardware GPU + WARP execution readback coveringR32_FLOAT(0x1),R32_UINT(0x1),R32G32_FLOAT(0x3),R16G16_FLOAT(0x3d16),R16G16B16A16_FLOAT(sparse0x5d16), andR32_FLOAT(0x0no-op).Verification status: Not run locally (no Rust toolchain on this machine); intended for verification via CI (
cargo clippy --workspace --all-targets --locked -- -D warnings,--all-features,cargo test --workspace --locked, andxtaskpolicy check) and hardware/WARP runs.Limitations
d16stores to integer texture UAVs (R16_UINT,R16G16_UINT) still widen vialegacyF16ToF32(same as existingdmask = 0xFd16image_store), pending texture integer-format metadata inVIEW_STRIDES(#2125).image_store_mipand_pckvariants remain refused.Prior work
Follows the same DXIL typed-UAV write-mask and test pattern as #3377 (partial-channel typed buffer stores). AI-assisted.
@Dukestar69 on GitHub · 2026-11-26 22:49 UTC · original · approved these changes
LGTM — verified on RTX 5090 and
VICTORY_WARP=1(Windows / D3D12) againstorigin/main(63bcca4).dmask=0image_store(includingd16variants while continuing to rejectimage_store_mip) validates cleanly and executes accurately on both RTX 5090 and WARP.cargo test -p victory-shader --lib image_store_tests:: -- --test-threads=1: 3 passed, 0 failed.cargo test -p victory-shader --lib emit::stride_tests::image_store -- --test-threads=1: passed on RTX 5090 andVICTORY_WARP=1.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).
@fuzeofficlal on GitHub · 2026-11-26 23:03 UTC · original · requested changes
Unpacking packed
VDATAslots (includingd16half-word unpacking) in ascendingdmaskbit order with0.0for missing channels matches RDNA2IMAGE_STOREfloat-UAV semantics,lower.rsstays under 512 KiB (521,053bytes),policyandclippypass, and all newimage_store_testsandstride_teststests pass on RTX 5090 and WARP.Two blocking items need fixing before merge:
rustfmt --edition 2024 --checkfails on PR-modified lines:crates/victory-shader/src/emit/host.rs:1693andcrates/victory-shader/src/emit/stride_tests.rs(814, 863, 943) failrustfmtcheck.d16integer texture stores runlegacyF16ToF32unconditionally (crates/victory-shader/src/emit/lower.rs:8618-8626, 8641):While 32-bit
R32_UINTstores instride_tests.rswork by raw bit-copy throughfloat_of+textureStore.f32, thed16branch unconditionally converts every 16-bit halfword withlegacyF16ToF32and emits anF32(0x409) handle +textureStore.f32. On 16-bit integer UAVs (R16_UINT,R16G16_UINT, etc.), this silently corrupts integer payloads (e.g.,0x3C00/15360becomes1.0finstead of15360).Non-blocking P2 notes:
image_store_pckcurrently falls into the"an image store to a mip level"error message atlower.rs:8590-8592.image_store_tests.rsleaveUNRM(bit 12) clear in the MIMG encoding.@Jackster on GitHub · 2026-11-26 23:08 UTC · original
Windows 11,
63bcca4+ this PR, Radeon RX 7900 XTX:cargo test -p victory-shader --lib --features host emit::: 208 passed / 0 failed / 2 ignored (143 s).cargo clippy -p victory-shader --all-targets -- -D warnings: clean.The new tests are in that run:
emit::lower::image_store_tests::partial_dmask_and_d16_image_stores_lower_and_validate,image_store_with_zero_dmask_is_noop,image_store_mip_is_still_refusedandpartial_dmask_image_stores_write_typed_texture_uavs, plus the twotable_image_uav_*ones. Synthetic only. AI-assisted.@Texbirds on GitHub · 2026-11-26 23:25 UTC · original
Thanks @Dukestar69, @Jackster, and @fuzeofficlal for the RTX 5090, RX 7900 XTX, and WARP testing and review!
Pushed
7652064addressing both blocking items and both P2 notes (lower.rsis 523,845 bytes, andCI / checkis green):d16integer texture stores (shader.rs,lower.rs,stride_tests.rs):Shader::texture_uav_index(separate fromview_indexbuffer write marks andtexture_indexSRV read marks) and updatedLower::integer_viewto check it.Lower::image,d16stores now branch onVIEW_INTEGERfrom the view-stride table: integer texture UAVs emitdx.op.textureStore.i32through an integer-typed handle(kind | 0x1000, 0x405)with zero-/sign-extended 16-bit integer channels, while float/normalized texture UAVs emitdx.op.textureStore.f32through(kind | 0x1000, 0x409)withlegacyF16ToF32.DXGI_FORMAT_R16G16_UINT(including0x3C00=15360) withVIEW_INTEGERtopartial_dmask_image_stores_write_typed_texture_uavs.rustfmt --edition 2024: Fixed formatting instride_tests.rs.image_store_pckerror message: Split"an image store to a mip level"(_mip) from"a packed image store"(image_store_pck) and pinned both inimage_store_mip_and_pck_are_still_refused.UNRMbit: SetUNRM(bit 12) on the syntheticimage_storeencodings inimage_store_tests.rsandstride_tests.rs.Ready for re-review!
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 23:33 UTC · original
I reproduced the original Windows CI failure on
04fc2d0: all 32R16G16_UINTtexels read back0xffffffffon app-local WARP. I verified that the updated7652064passes the existing WARP readback and validator tests.The shader now consults the format-kind bits, which the test supplies in its root table. The production heap still supplies those bits only for typed buffers. Follow-up
188df5badds the bits for explicit typed texture UAV descriptions, including placed textures, while keeping their buffer stride at zero.The expanded test passed three WARP runs. All 32 texels matched in each signed and unsigned 16-bit case. A seeded
dmask=0x9store also replaced every RGBA32F texel with[16, 0, 0, 32], and every RG32F texel with[16, 0]. This follows the RDNA 2 whole-texel store rule. The affected shader tests passed 45/45, the four GPU integer tests passed, and strict Clippy in both configurations and asset policy passed.@Texbirds, could you take the production format metadata change and repeat the two integer formats on your card? If you fold in the changes, please retain the Git author or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.@Texbirds on GitHub · 2026-11-26 23:38 UTC · original
Thanks @andrewpozdnakov7-jpg! That cleanly closes the production
VIEW_STRIDESmetadata gap for texture UAVs and adds great coverage forR16G16_SINTand seededdmask=0x9whole-texel writes.Cherry-picked
188df5bonto this branch as1ac4502with your original Git authorship preserved, and CI (check) is running now. (I don't have a local Rust toolchain on this machine to run hardware tests directly, so if anyone on NVIDIA/AMD can re-runpartial_dmask_image_stores_write_typed_texture_uavson1ac4502to confirm theR16G16_UINT/R16G16_SINTcases on physical hardware, that would be huge!)@Texbirds on GitHub · 2026-11-26 23:45 UTC · original
Verified
1ac4502locally on NVIDIA GeForce RTX 3080 Ti (driver32.0.16.1088, Windows 11, Rust 1.98.1) and WARP:cargo test -p victory-shader --lib --locked -- --test-threads=1 partial_dmask_image_stores_write_typed_texture_uavs image_store_tests::: 4 passed, 0 failed (both hardware RTX 3080 Ti and WARP — includingR16G16_UINT,R16G16_SINT, and seededdmask=0x9whole-texel writes).cargo test -p victory-gpu --lib --locked explicit_integer_texture_uavs_have_kind_bits_without_a_buffer_stride: 1 passed, 0 failed.Synthetic tests only (no game files).
@fuzeofficlal on GitHub · 2026-11-27 00:16 UTC · original · requested changes
Tested
1ac4502b2db0da7815f6e675b370392171e949aawithcargo xtask policy,cargo clippy --tests(default and--features diagnostics),dxil.dllvalidation,dxc.exe -dumpbin, and live D3D12 runs on both RTX 5090 and WARP (VICTORY_D3D12_DEBUG=1).The new tests pass (
image_store_tests3/3,stride_tests::partial_dmask_image_stores_write_typed_texture_uavson both hardware and WARP,descriptor::host::tests16/16 on WARP and 15/15 on RTX 5090, andlower.rsstays under the 512 KiB limit at 523,845 bytes). However, two functional issues remain before this is ready to merge:Handle caches still drop
props.1, sotextureStore.i32still receives theF32-annotated handle (crates/victory-shader/src/emit/lower.rs:219, 224, 227, 5377, 5390, 5499, 8658)lower.rs:8612requestsprops = (kind | 0x1000, 0x409)(RWTexture2D<4xF32>), andlower.rs:8658requests(kind | 0x1000, 0x405)(RWTexture2D<4xI32>).handles(line 219 / 5390),entry_handles(line 224 / 5377), andjoin_handles(line 227 / 5499) still key only onprops.0, the secondself.handle(...)call hits the cache and returns the exact sameF32-annotated handle forSource::LoadedandSource::Phi.d162Dimage_storeDXIL withdxc.exe -dumpbinconfirms no0x405(4xI32) annotation is emitted at all:props: (u32, u32)tuple inhandles,entry_handles, andjoin_handleskeys fixes all three caches cleanly.view_kindmisses default (desc = None) and format-inheriting (Format = DXGI_FORMAT_UNKNOWN) integer texture UAVs (crates/victory-gpu/src/descriptor/host.rs:1013-1045)descriptor/host.rs:1547-1556and1642-1658explicitly supports bothView::Unordered(resource, _, None)(default UAV inheriting the texture's format) anddesc.Format == 0(DXGI_FORMAT_UNKNOWN, resolved viacrate::resource::view_format(resource)forView::Unorderedand the resource's format for placed textures).view_kind(),View::Unordered(_, _, None)falls through to_ => return 0(line 1022), andwords[0] == 0maps throughinteger_format(pc_format(0))to0(line 1040) for bothView::Unordered(r, _, Some([0, dim, ...]))andView::Placed(true, resource, [0, dim, ...]).VIEW_INTEGERnorVIEW_SIGNED, causingd16image_storeto take the float branch (legacyF16ToF32+textureStore.f32) and silently corrupt the stored integer texels.descisNone(on texture resources) orwords[0] == 0(for bothView::Unorderedand placed texture UAVs).Minor note: a few newly added lines in
crates/victory-shader/src/emit/stride_tests.rs(lines 785–989) still have formatting diffs underrustfmt --edition 2024 --check(max_width = 100).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.