Shaders: test that an image read as float and used by an atomic is annotated twice #226

Closed
gingertonik wants to merge 2 commits from upstream-pr/226 into main
gingertonik commented 2026-11-24 01:37:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by gingertonik on 2026-11-24T01:37:08Z.


Stacked on #177 (its commit e55eb69 is the first commit here). This adds only the test that PR was noted to lack; once #177 merges, the diff is the test alone.

What

A synthetic compute program in emit::lower::tests, in the style of the existing ones: it loads a 2D image UAV from a descriptor table as four float channels (image_load) and then runs image_atomic_umin on the same image in the same block. The test asserts that the image is annotated twice: (0x1002, 0x409) for the load and (0x1002, 0x105) for the atomic.

To let the test read the annotations, test builds record each annotation's two property words in Shader and hand them out through Lowered (#[cfg(test)] fields; nothing changes in a normal build).

Why

#177 fixes the heap-handle cache handing an atomic the float handle of an earlier load. The expected values come from DXIL's resource properties, not from the code under test: word 0 is the resource kind (Texture2D = 2) with the UAV bit (0x1000); word 1 carries the component type in its low byte (U32 = 5, F32 = 9 in DxilConstants.h's ComponentType) and the component count above it. D3D12 allows the Interlocked operations on integer UAVs only, so the atomic's annotation has to be the one-u32 form.

Tested

Linux x86_64, pinned toolchain, from the repository root:

  • On d2a4bae (without #177) the test fails: the atomic's annotation: [(d, ffffffff), (1002, 409)]. The load's annotation is present and the atomic's is missing.
  • On #177's e55eb69 it passes. cargo test -p victory-shader: 57 passed, 0 failed.
  • With #177's key edited back to ignore the second word, it fails again with the same message.
  • cargo fmt --all -- --check: no differences in victory-shader. cargo clippy -p victory-shader --tests: only the existing constant_color dead-code warning on Linux.
  • cargo xtask policy: 151 files ok. Windows MSVC release cross-build (xwin SDK, lld-link): clean.

Synthetic words only; no game data.

AI-assisted (Hermes).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6572616646 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/226). Originally posted by [gingertonik](https://github.com/gingertonik) on 2026-11-24T01:37:08Z. --- Stacked on #177 (its commit `e55eb69` is the first commit here). This adds only the test that PR was noted to lack; once #177 merges, the diff is the test alone. ## What A synthetic compute program in `emit::lower::tests`, in the style of the existing ones: it loads a 2D image UAV from a descriptor table as four float channels (`image_load`) and then runs `image_atomic_umin` on the same image in the same block. The test asserts that the image is annotated twice: `(0x1002, 0x409)` for the load and `(0x1002, 0x105)` for the atomic. To let the test read the annotations, test builds record each annotation's two property words in `Shader` and hand them out through `Lowered` (`#[cfg(test)]` fields; nothing changes in a normal build). ## Why #177 fixes the heap-handle cache handing an atomic the float handle of an earlier load. The expected values come from DXIL's resource properties, not from the code under test: word 0 is the resource kind (Texture2D = 2) with the UAV bit (0x1000); word 1 carries the component type in its low byte (`U32` = 5, `F32` = 9 in `DxilConstants.h`'s `ComponentType`) and the component count above it. D3D12 allows the Interlocked operations on integer UAVs only, so the atomic's annotation has to be the one-`u32` form. ## Tested Linux x86_64, pinned toolchain, from the repository root: - On `d2a4bae` (without #177) the test fails: `the atomic's annotation: [(d, ffffffff), (1002, 409)]`. The load's annotation is present and the atomic's is missing. - On #177's `e55eb69` it passes. `cargo test -p victory-shader`: 57 passed, 0 failed. - With #177's key edited back to ignore the second word, it fails again with the same message. - `cargo fmt --all -- --check`: no differences in `victory-shader`. `cargo clippy -p victory-shader --tests`: only the existing `constant_color` dead-code warning on Linux. - `cargo xtask policy`: 151 files ok. Windows MSVC release cross-build (xwin SDK, `lld-link`): clean. Synthetic words only; no game data. AI-assisted (Hermes).
jeremygold02 commented 2026-11-24 06:56:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T05:24:24Z.


Thanks @gingertonik for adding a focused regression case for the two resource annotations emitted from one image.

I tested commit 6e01ea031553e1bd19b37ffae5cc2facaa18920b with:

cargo test --locked -p victory-shader --lib an_image_read_as_float_and_by_an_atomic_is_annotated_twice -- --test-threads=1

The targeted test passed (1 passed, 0 failed; 69 filtered). an_image_read_as_float_and_by_an_atomic_is_annotated_twice lowers a synthetic compute shader that loads four float channels from a 2D UAV and then performs an unsigned atomic minimum. It asserts both annotations are emitted: the four-component F32 resource for the load and a separate one-component U32 resource for the atomic.

This validates shader IR lowering and annotation generation; it does not compile or execute the shader on a GPU.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7122917190 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/226#issuecomment-7122917190). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T05:24:24Z. --- Thanks @gingertonik for adding a focused regression case for the two resource annotations emitted from one image. I tested commit `6e01ea031553e1bd19b37ffae5cc2facaa18920b` with: ``` cargo test --locked -p victory-shader --lib an_image_read_as_float_and_by_an_atomic_is_annotated_twice -- --test-threads=1 ``` The targeted test passed (1 passed, 0 failed; 69 filtered). [`an_image_read_as_float_and_by_an_atomic_is_annotated_twice`](https://github.com/Marvisak/VIctory/blob/6e01ea031553e1bd19b37ffae5cc2facaa18920b/crates/victory-shader/src/emit/lower.rs#L6671) lowers a synthetic compute shader that loads four float channels from a 2D UAV and then performs an unsigned atomic minimum. It asserts both annotations are emitted: the four-component F32 resource for the load and a separate one-component U32 resource for the atomic. This validates shader IR lowering and annotation generation; it does not compile or execute the shader on a GPU.
upstream-sync closed this pull request 2026-11-25 00:05:20 +00:00
Marvisak commented 2026-11-25 00:06:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:00:51Z.


Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #177.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148040365 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/226#issuecomment-7148040365). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:00:51Z. --- Automated triage for the maintainers. Closing because another open pull request covers the same change. See #177. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!226
No description provided.