Shaders: lower partial-channel and dmask=0 image_store #3403
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/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?
Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-26T22:29:35Z.
Problem
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.
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T22:49:44Z.
Review: APPROVED
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).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T23:03:54Z.
Review: CHANGES_REQUESTED
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.Imported from Marvisak/VIctory. Originally posted by Jackster on 2026-11-26T23:08:08Z.
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.Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-26T23:25:58Z.
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!
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T23:33:23Z.
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]>.Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-26T23:38:28Z.
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!)Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-26T23:45:07Z.
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).
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T00:16:01Z.
Review: CHANGES_REQUESTED
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).Imported from Marvisak/VIctory. Originally posted by zzm1234560621-prog on 2026-11-27T04:01:16Z.
Verification on Intel (Arc, Xe-LPG, driver 32.0.101.6127),
1ac4502on top of63bcca4:The seven failures are this adapter's standing set on unmodified
63bcca4(#3196): three BVH tests one ULP off from this driver's reassociation,arithmetic_matches_the_hardwareand the MAD signed zero (fixed by #3212),image_atomics_of_64_bits(gated by #3203) and the view-heap test (#3191/#3178), andfspx_…dot_products. So no new failure here, and the 299 over the 295 baseline is your fourimage_storetests.cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.One note for whoever runs this next: I built the head from a zip (git fetch to github is being reset on this network today), so the run was a cold build — 72 minutes for the suite. Nothing about the code, just why the timings in this comment are not comparable with the others I have posted.
No game files. AI-assisted (Claude).
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T07:13:39Z.
@Texbirds 1c0acc5 is a follow-up on
1ac4502for the two format observations.The three handle caches now keep both resource-property words. Before the fix, the DXIL test found the float annotation but no integer annotation for the d16 case. Both annotations are present after the fix and the four image-store tests passed.
The stride table now uses the texture UAV format actually chosen at host view creation. This covers a default UAV and an explicit texture descriptor with
DXGI_FORMAT_UNKNOWN. The placed-resource description supplies the format for an inherited placed texture before the host view is made. The added format test and the full descriptor host group passed on app-local WARP (17/17), and a separate native WARP fixture checked an actual default and an inheriting UAV. Strict all-features GPU and shader Clippy passed.If you take the patch, please retain Git authorship when cherry-picking or rebasing. If folded into another commit, please add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.AI-assisted with Codex. Synthetic tests only.
Imported from Marvisak/VIctory. Originally posted by Texbirds on 2026-11-27T07:31:03Z.
Thanks @fuzeofficlal for the
dxc -dumpbinaudit, @zzm1234560621-prog for the Intel Arc verification, and @andrewpozdnakov7-jpg for the1c0acc5follow-up!Cherry-picked
1c0acc5onto this branch as8531c85(preserving @andrewpozdnakov7-jpg's Git authorship) and pushedb0a959efixing the remainingrustfmt --edition 2024diffs instride_tests.rs:lower.rs):handles,entry_handles, andjoin_handlesnow key on the fullprops: (u32, u32)tuple sod16image_storeemits both the0x409(4xF32) and0x405(4xU32) handle annotations (verified inimage_store_tests).DXGI_FORMAT_UNKNOWNtexture UAV format metadata (victory-gpu/src/descriptor/host.rs):view_kindnow resolves inherited texture UAV formats for bothView::Unordered(..., None)/Format == 0and placed texture UAVs (inherited_integer_texture_uavs_have_kind_bits).stride_tests.rs):rustfmt --edition 2024 --checkis clean across all PR-added lines.Local verification on
b0a959e(NVIDIA GeForce RTX 3080 Ti32.0.16.1088+ WARP, Windows 11, Rust 1.98.1, synthetic tests only):cargo clippy -p victory-shader -p victory-gpu --all-targets --locked -- -D warnings(default &--all-features): cleancargo xtask policy:192 files ok(lower.rs= 524,074 bytes)cargo test -p victory-shader --lib --locked -- --test-threads=1 image_store_tests:: partial_dmask_image_stores_write_typed_texture_uavs: 4 passed, 0 failed (2.52s)cargo test -p victory-gpu --lib --locked descriptor::host::tests::: 16/17 passed (both new integer texture UAV tests pass; only the pre-existing NVIDIA 1M view-heap cap failure indynamic_slots_are_held_until_released)Ready for re-review!
Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-27T09:36:32Z.
I verified
b0a959edd8d40f8be181164307cdc0c898f2f54don a GeForce RTX 4090 Laptop GPU (621.14) and Microsoft WARP. The unmodified head passed all four selectedimage_storetests. I then used three matched synthetic dispatches per adapter to read back the result of ad16store on a pre-filledR16G16B16A16_FLOATtexture. All 32 texels per dispatch were checked.3c003800 44004000dmask=0, with new values in the source register3c003800 44004000dmask=5, packed R=5 and B=1200004500 00004a00Both adapters matched all 96 texels each. The zero mask preserved the nonzero green and alpha channels, whereas the sparse whole-texel store cleared them and placed the upper source half in blue. This is a Windows D3D12 host readback. Synthetic fixture. AI-assisted with Codex.
Imported from Marvisak/VIctory. Originally posted by pablogonz12 on 2026-11-27T17:05:32Z.
I tested the current head
b0a959edd8d40f8be181164307cdc0c898f2f54don RX 9070 XT (RDNA4), RADV, Mesa 26.3.1-arch3.5, GE-Proton11-14 (Wine 11.0), Rust/Cargo 1.100.0. This was one run per tree.I built the Windows test binary with
cargo xwin test --no-run -p victory-shader --lib --target x86_64-pc-windows-msvc, then ran it under Wine with--test-threads=1 image_store, using the hardware adapter rather than WARP.63bcca43c6a00a758510398fa43096ce7e4f7df0b0a959edd8d40f8be181164307cdc0c898f2f54dpartial_dmask_image_stores_write_typed_texture_uavshardware readbackThe main tree does not contain these new tests, so its zero-test result is not a readback control. Unit tests only, not a game run. Not tested on NVIDIA hardware.
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.