Repository navigation
Shaders: translate 64-bit image atomics - #173
AlgoArtist06 wants to merge 1 commit into
Conversation
An image atomic with two data dwords per value (dmask 0x3, cmpswap 0xF)
is a 64-bit atomic on an R32G32 view. It stopped the translation ("a
64-bit image atomic"), which drops the pipeline's draws; a tester's run
in the world (Marvisak#97) hit it in five pixel programs.
It now lowers to DXIL's atomicBinOp.i64 and atomicCompareExchange.i64,
the dword pairs joined into i64 values and the returned value split back
into the pair with glc. The shader requires 64-bit integer ops and
64-bit atomics on typed and on heap resources. Flags, operations and
handle annotation match what DXC emits for InterlockedMax and
InterlockedCompareExchange on a RWTexture2D<uint64_t> taken from
ResourceDescriptorHeap, and the emitted containers pass dxv.
The descriptor load ahead of an image atomic annotated its handle as
four floats, and the atomic reused that handle, so the atomic's own
32-bit integer annotation never reached the DXIL. The load now
annotates an atomic's texture as the atomic does, for 32-bit atomics
too.
|
Tested
No game data used. |
|
Closing as a duplicate. #48 already translates 64-bit texture atomics and was opened first, and #177 fixes the reuse of a float-annotated handle by an image atomic. For whoever reviews #48: the shader flags ( |
|
Heads-up: #48 also translates 64-bit image atomics (SM 6.6, typed and heap capability bits), and the two conflict in Static review, not built or run. |
The node test's reference (bvh.rs) and its emitter (emit/intersect.rs) took a child whose pointer is 0xffff_ffff for a hit whenever the ray entered its box. Its result dword was "none" either way, but sorted it came with a finite distance, so it could stand before a child that is there; a traversal that stops at the first "none" would then miss that child. Both now test the pointer too: a child that is not there is a miss, as the reference's description of the result already said. The box test's emitted code grows by two integer instructions per child (a compare and an and): the parity tests' program (the 64-bit form) goes from 519 to 527 instructions. The reference's new test is the reproducer of Marvisak#173: a child that is not there whose box is entered first, one child behind it, and two that are not there with their boxes at the ray's origin, in both node widths. The card tests run the same node and ray. With the reference corrected and the emitter not, the four parity tests fail on the card; corrected, they pass on the card and on WARP. Not known: what the console returns for such a child, and whether the title's builder ever leaves a box under one. The cases of Marvisak#173 are synthetic. docs/fork-ray-tracing.md lists it with the other assumptions. Reproducer and patch: @Bennet0k, Marvisak#173. Co-Authored-By: GLM <noreply@z.ai>
… box The node test took a child whose pointer is "none" (0xffffffff) for a hit whenever the ray entered its box, in the reference (bvh.rs) and in the emitted DXIL. Its result dword was "none" either way, but sorted it came with a finite distance and could stand before a child that is there; a walk that stops at the first "none" then leaves that child out. Both now test the pointer too (one compare and one and per child). What the console returns for such a child is not documented; the title cannot rely on a "none" standing first, so this agrees with it wherever it can matter. The card tests compare the emitted code with the reference as before. Port of fxceless/victory-fork Marvisak#213 (Pablo-Barros; reproducer Bennet0k, Marvisak#173). Not taken: Marvisak#464 (boxes with min > max as misses), which assumes what the hardware does with such boxes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What is in it
64-bit image atomics no longer stop the translation.
In the world run in #97, "a 64-bit image atomic" stopped five pixel programs, and their draws were dropped.
0x3, cmpswap0xF) now lowers toatomicBinOp.i64oratomicCompareExchange.i64.The dword pairs become i64 values, and with
glcthe returned value is split back into the pair.subis the add of the i64 negation, as for 32-bit.ShaderFlagsbits 20, 27 and 32;SFI00x8000,0x40_0000and0x1000_0000).Every image handle comes from
ResourceDescriptorHeap, so both atomic bits are needed.descriptor_datacreates the handle when it lowers the descriptor load, and it annotated an atomic's texture as four floats (0x409).The atomic reused that cached handle, so its own one-channel 32-bit uint annotation (
0x105) never reached the DXIL.The load now picks
0x105when the use is an image atomic.This is what DXC emits for both
RWTexture2D<uint>andRWTexture2D<uint64_t>.join64, whichsrc64now uses too.emit/mod.rsname the host requirements.Refs #97.
Host requirements
The host view at the descriptor's index must be
R32G32_UINT, which is the format the title creates for a 64-bit atomic target.The device must also report
AtomicInt64OnTypedResourceSupportedandAtomicInt64OnDescriptorHeapResourceSupported.Without them the host refuses the pipeline, which drops the same draws as before.
I did not add a capability check to
victory-gpu.Tested
The tests ran on macOS, which builds the shader crate only.
No GPU and no game data were involved.
cargo test -p victory-shader: 58 passed, 0 failed, including the two new tests:a_64_bit_image_atomic_requires_64_bit_typed_atomicschecks theSFI0bits forimage_atomic_umax(32-bit and 64-bit) and the 64-bitimage_atomic_cmpswap. The programs are hand-written GFX10 words.an_image_atomic_on_part_of_a_pair_is_refusedchecks that dmask0x5fails with a reason.cargo clippy -p victory-shader --all-targets: no new warnings.constant_coloris unused off Windows, as onmain.cargo fmt -p victory-shader -- --check: passed.cargo xtask policy:asset policy: 151 files ok.umax, 64-bitumax, 64-bitcmpswapand 64-bitsubwithoutglcto files.dxvfrom DXC v1.9.2609 (Linux release) reports "Validation succeeded" for all four.InterlockedMaxandInterlockedCompareExchangeon aRWTexture2D<uint64_t>fromResourceDescriptorHeapwithdxc -T ps_6_6.Our 64-bit output matches it in the shader flags (
0x148100000), theSFI0bits (0x12408000), the operations and their operand order, and the handle annotation ({0x1002, 0x105}).Not tested: I could not create a pipeline or run the title on a GPU.
The
--validateand--pipelinespaths,diff_testsand the world itself still need a run on Windows.Hardware / OS
macOS (Apple silicon), with DXC in an x86-64 Linux container.
No Windows machine and no D3D12 device.
AI-assisted
Yes. Claude Code (Claude Opus 5.5) wrote the change and ran the checks above.
No game data was used.
🤖 Generated with Claude Code