Repository navigation
fix(shader): skip unused image atomic descriptor reconstruction - #589
jeremygold02 wants to merge 1 commit into
Conversation
A direct eight-word scalar load can supply the resource of an image atomic without exposing any descriptor words as values. Avoid emitting a float-annotated dimension query in that case while retaining reconstruction for scalar reads, PHIs, and other consumers. Refs: Marvisak#48, Marvisak#177, Marvisak#259
|
Measured on the full retail shader pack (26,503 containers) with
|
catminou4
left a comment
There was a problem hiding this comment.
Sound and conservative. atomic_descriptor_loads only marks an s_load_dwordx8 when all 8 written SGPRs are consumed by exactly one image_atomic_*'s rsrc (checked via atomic.read(reg) == Some(v)), the SGPR window stays below VCC (code > VCC - 8 rejected), and — critically — any other reader (phi args or any other instruction's reads, excluding the atomic itself) disqualifies the load. So the skip can never hide a descriptor word that real code observes.
descriptor_data early-returning Ok(()) for those sites removes the reconstruction DXIL for loads whose words are provably unused, and the new native.rs test pins the behavior: x8 load yields smaller DXIL than x16 when only the atomic consumes it, a data read of a descriptor dword forces the reconstruction path (x8 == x16 output), and the phi-joined branch case stays conservative. The #[cfg(windows)] validator block is properly gated.
Verified locally: test-merge with current main (ffe310e) clean; cargo test -p victory-shader --locked (macOS arm64, rustc 1.98.1) → 97 passed / 0 failed / 1 ignored, including the new test (it runs on macOS; only the DXIL validator is Windows-gated).
mercuryVM
left a comment
There was a problem hiding this comment.
Tested ab2e7cc on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 70 passed, including reconstructs_an_atomic_descriptor_only_when_its_words_are_read, which validates through dxil.dll here. cargo clippy -p victory-shader --all-targets is clean. victory translate --validate --pipelines on the local title executable still reports 12 of 12 emitted, validated and built into pipelines.
- The skip applies only when all eight written SGPR values flow straight into the one
image_atomic_*rsrc operand, with no phi use and no other reader. Any scalar data use keeps the reconstruction, so a program that reads a descriptor field still gets it. code > VCC - 8keeps the range inside the SGPR file. The x16 contrast case in the test is a good guard that the skip doesn't widen by accident.
AI-assisted (Claude Code).
… descriptor reconstruction Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…reconstruction
|
Automated triage for the maintainers. Proposed close: a narrower duplicate of #1756, which is still open. The bug is a float4-annotated handle reused by an unsigned image atomic. It comes from the handle cache in On your reply: thank you for checking this against #1756. It confirms #1756 covers every correctness case you could find. The remaining difference is code size in a synthetic fixture (1,968 vs 2,160 bytes), and the retail-pack comparison found no extra validated shaders or pipelines, so that gain does not justify a second path. This pull request will be closed in 48 hours unless the author pushes a change or a maintainer removes the Generated by Claude Code |
|
@Marvisak I checked the overlap with #1756 on This PR does have a separate code-size effect. With #589 alone on the same base, the original regression passed and the atomic-only x8 case produced 1,968 bytes versus 2,160 for x16. That measures the optimization in the fixture; the retail-pack comparison above found no increase in validated shaders or created pipelines. I agree with using #1756 for the correctness fix. I’ve left this branch as-is for the proposed-close decision. |
… hold The once-per-signature line gave the command signature's descriptor as `args=[[1, 28671, ...]]` and no reason, so a dropped indirect execution read as garbage title memory in an unwritten argument buffer: the descriptor's fields past the type are the union the title leaves alone, not the records, and the drop is the pipeline's (a shader with no host pipeline, `Marvisak#589`). - `State::execute_indirect` sets the reason at every branch that drops it (skipped shader, arguments/count outside title buffers, no host signature, not bounded, prepare/bind failed, rectangle path), and the not-ran branch now names the drops in the frame's reason table as `indirect kind N: <shader hash or being made>`, where before they were counted as unlabelled shader drops. - The once-per-signature log says `reason=`, keeps the descriptor as `signature=` (not `args=`), adds `records=` read from the host copy of the buffer the GPU would have read, and logs again when a signature starts failing for a new reason. - `Shadow::bytes` reads a range of the host copy for the log, bounded by the buffer; covered by `bytes_reads_the_copy_inside_the_buffer_only`. Diagnostics and counting labels only: no draw, dispatch or clamp behaviour changes, nothing vendor- or wave-specific, shader translation untouched.
…reconstruction
A scalar load of eight image-descriptor words currently reconstructs descriptor fields with a float-annotated
GetDimensions. When those SGPRs feed only an image atomic, the atomic builds its heap index directly from the load address. The extra query also lets the cached float4 annotation reach an unsigned atomic on current main.Track this single-consumer case during lowering and omit the field reconstruction. The check requires the same eight SGPR definitions to reach the image resource operand directly. A scalar data use, a PHI edge or another instruction reading any of those values keeps the existing path.
Verification
atomicBinOp.i32UMax on aRWTexture2D<U32>handle and zero dimension queries. The scalar and PHI controls still feed the queried dimension into the atomic.d2a4baeand this change. All 21,971 previously SDK-valid inputs passed. 21,931 outputs were byte-identical. The 40 changed shaders (27 pixel and 13 compute) retained all 167 atomic sites and dropped 83 redundant dimension queries. Exactly 78 atomic handle annotations changed from float4 to U32. All 3,538 translator refusals and 185 SDK rejections retained their previous diagnostic.R32_UINTUAV returned the expected unsigned maxima across the sign bit and within the high unsigned range. All three fences completed, and the adjacent texel and control descriptor retained their initial values. This check used the standalone change on main.Related work includes #177 distinguishes cached handle annotations, #259 checks use of the reconstructed mip-count field, and #48 adds 64-bit image atomics. In a separate comparison stacked on #48, all 14 unsigned 64-bit maximum sites in seven SDK-valid pixel shaders lost their redundant float query. Five bounded synthetic comparisons on a physical RTX 5070 produced the expected unsigned 64-bit maxima with fence-complete readbacks.