|
| 1 | +#--- source.hlsl |
| 2 | + |
| 3 | +// This test exercises InterlockedAnd against non-resource (groupshared) |
| 4 | +// destinations using 64-bit integer types. A single threadgroup of 64 |
| 5 | +// threads concurrently updates shared counters, so the test actually |
| 6 | +// exercises atomic behavior. |
| 7 | +// |
| 8 | +// Both the 2-argument and 3-argument overloads are covered for int64_t |
| 9 | +// and uint64_t. |
| 10 | +// |
| 11 | +// Atomicity is verified by starting a counter at 0xFFFFFFFFFFFFFFFF and |
| 12 | +// having each of 64 threads atomically clear its own unique bit |
| 13 | +// (AND with ~(1ull << tid)). If any read-modify-write were non-atomic, |
| 14 | +// some thread's bit clear would be lost and the final value would be |
| 15 | +// non-zero. With true atomicity, the counter must end at exactly 0. |
| 16 | +// |
| 17 | +// For the 3-argument form we additionally verify, per-thread, that the |
| 18 | +// returned "original value" still had this thread's bit set when the AND |
| 19 | +// was performed -- this must always be true under atomic semantics, since |
| 20 | +// no other thread ever clears that bit. |
| 21 | + |
| 22 | +RWStructuredBuffer<uint> OutOrigBitSet : register(u0); |
| 23 | +RWStructuredBuffer<uint64_t> OutFinal : register(u1); |
| 24 | + |
| 25 | +groupshared uint64_t CounterU; // 3-arg form, unsigned: bit-clear test |
| 26 | +groupshared uint64_t CounterUNoOrig; // 2-arg form, unsigned: bit-clear test |
| 27 | +groupshared int64_t CounterI; // 3-arg form, signed: bit-clear test on -1 |
| 28 | +groupshared uint64_t MaskedU; // deterministic mask test (all threads |
| 29 | + // AND with the same constant) |
| 30 | + |
| 31 | +groupshared uint OrigBitSet[64]; // per-thread: was my bit set in the |
| 32 | + // original value I observed? |
| 33 | + |
| 34 | +[numthreads(64, 1, 1)] |
| 35 | +void main(uint3 GTID : SV_GroupThreadID) { |
| 36 | + if (GTID.x == 0) { |
| 37 | + CounterU = 0xFFFFFFFFFFFFFFFFull; |
| 38 | + CounterUNoOrig = 0xFFFFFFFFFFFFFFFFull; |
| 39 | + CounterI = (int64_t)-1; // all bits set |
| 40 | + MaskedU = 0xAAAAAAAAAAAAAAAAull; |
| 41 | + } |
| 42 | + OrigBitSet[GTID.x] = 0; |
| 43 | + GroupMemoryBarrierWithGroupSync(); |
| 44 | + |
| 45 | + uint64_t ThreadBit = 1ull << GTID.x; |
| 46 | + uint64_t ThreadMask = ~ThreadBit; |
| 47 | + |
| 48 | + // 3-argument form: capture original, then check our bit was set in it. |
| 49 | + uint64_t OrigU; |
| 50 | + InterlockedAnd(CounterU, ThreadMask, OrigU); |
| 51 | + OrigBitSet[GTID.x] = ((OrigU & ThreadBit) != 0ull) ? 1u : 0u; |
| 52 | + |
| 53 | + // 3-argument form, signed. |
| 54 | + int64_t OrigI; |
| 55 | + InterlockedAnd(CounterI, (int64_t)ThreadMask, OrigI); |
| 56 | + |
| 57 | + // 2-argument form: no original captured. |
| 58 | + InterlockedAnd(CounterUNoOrig, ThreadMask); |
| 59 | + |
| 60 | + // 2-argument form: every thread ANDs with the same constant. Result |
| 61 | + // is deterministic regardless of ordering. The mask exercises both the |
| 62 | + // low and high 32-bit halves. |
| 63 | + InterlockedAnd(MaskedU, 0x0F0F0F0F0F0F0F0Full); |
| 64 | + |
| 65 | + GroupMemoryBarrierWithGroupSync(); |
| 66 | + |
| 67 | + OutOrigBitSet[GTID.x] = OrigBitSet[GTID.x]; |
| 68 | + |
| 69 | + if (GTID.x == 0) { |
| 70 | + OutFinal[0] = CounterU; // 0 |
| 71 | + OutFinal[1] = (uint64_t)CounterI; // 0 |
| 72 | + OutFinal[2] = CounterUNoOrig; // 0 |
| 73 | + OutFinal[3] = MaskedU; // 0x0A0A0A0A0A0A0A0A |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +//--- pipeline.yaml |
| 78 | + |
| 79 | +--- |
| 80 | +Shaders: |
| 81 | + - Stage: Compute |
| 82 | + Entry: main |
| 83 | +Buffers: |
| 84 | + - Name: OutOrigBitSet |
| 85 | + Format: UInt32 |
| 86 | + Stride: 4 |
| 87 | + FillSize: 256 |
| 88 | + - Name: ExpectedOrigBitSet |
| 89 | + Format: UInt32 |
| 90 | + Stride: 4 |
| 91 | + Data: [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 92 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 93 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 94 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] |
| 95 | + - Name: OutFinal |
| 96 | + Format: UInt64 |
| 97 | + Stride: 8 |
| 98 | + FillSize: 32 |
| 99 | + - Name: ExpectedFinal |
| 100 | + Format: UInt64 |
| 101 | + Stride: 8 |
| 102 | + Data: [ 0, 0, 0, 0x0A0A0A0A0A0A0A0A ] |
| 103 | +Results: |
| 104 | + - Result: TestOrigBitSet |
| 105 | + Rule: BufferExact |
| 106 | + Actual: OutOrigBitSet |
| 107 | + Expected: ExpectedOrigBitSet |
| 108 | + - Result: TestFinal |
| 109 | + Rule: BufferExact |
| 110 | + Actual: OutFinal |
| 111 | + Expected: ExpectedFinal |
| 112 | +DescriptorSets: |
| 113 | + - Resources: |
| 114 | + - Name: OutOrigBitSet |
| 115 | + Kind: RWStructuredBuffer |
| 116 | + DirectXBinding: |
| 117 | + Register: 0 |
| 118 | + Space: 0 |
| 119 | + VulkanBinding: |
| 120 | + Binding: 0 |
| 121 | + - Name: OutFinal |
| 122 | + Kind: RWStructuredBuffer |
| 123 | + DirectXBinding: |
| 124 | + Register: 1 |
| 125 | + Space: 0 |
| 126 | + VulkanBinding: |
| 127 | + Binding: 1 |
| 128 | +... |
| 129 | +#--- end |
| 130 | + |
| 131 | +# Unimplemented: https://github.com/llvm/llvm-project/issues/99125 |
| 132 | +# XFAIL: Clang |
| 133 | + |
| 134 | +# Bug: https://github.com/llvm/offload-test-suite/issues/1164 |
| 135 | +# XFAIL: Metal && DXC |
| 136 | + |
| 137 | +# REQUIRES: Int64 && Int64GroupSharedAtomics && SM_6_6 |
| 138 | +# RUN: split-file %s %t |
| 139 | +# RUN: %dxc_target -HV 202x -T cs_6_6 -Fo %t.o %t/source.hlsl |
| 140 | +# RUN: %offloader %t/pipeline.yaml %t.o |
0 commit comments