22
33// Tests InterlockedCompareExchangeFloatBitwise on groupshared destinations.
44// 256 threads run at the same time. Each test value is exact in float, thus
5- // the shader compares floats directly. There are four checks:
5+ // the shader compares floats directly. There are three checks:
66//
77// 1. Private slots. A compare that does not match must not store. A later
88// compare that matches must store. Both report the initial value.
1414// 3. Bit patterns. +0.0 against -0.0 must not store. A NaN against the
1515// same NaN bits must store. A buffer supplies the NaN, because HLSL
1616// has no NaN literal.
17- // 4. CounterZero. Thread `i` moves the counter from `i` to `i+1` only.
18- // The shader makes 256 attempts, with a barrier between them. Each
19- // thread wins one time, the counter stops at 256, and the counter must
20- // never decrease.
21-
22- RWStructuredBuffer<uint> OutMono : register(u0);
23- RWStructuredBuffer<uint> OutSlots : register(u1);
24- RWStructuredBuffer<uint> OutOrig : register(u2);
25- RWStructuredBuffer<uint> OutWins : register(u3);
26- RWStructuredBuffer<float> OutFinal : register(u4);
27- RWStructuredBuffer<float> NanIn : register(u5);
17+
18+ RWStructuredBuffer<uint> OutSlots : register(u0);
19+ RWStructuredBuffer<uint> OutOrig : register(u1);
20+ RWStructuredBuffer<float> OutFinal : register(u2);
21+ RWStructuredBuffer<float> NanIn : register(u3);
2822
2923groupshared float SlotsMinusTwoPointFive[256]; // per-thread slots, each -2.5
3024groupshared float MatchMinusFive; // contended, compare matches
3125groupshared float NoMatchSeventySeven; // contended, never matches
3226groupshared float ZeroPositive; // +0.0, compared against -0.0
3327groupshared float NanQuiet; // NaN, compared against NaN
34- groupshared float CounterZero; // stepped from 0.0 to 256.0
3528groupshared float ClaimZero; // 0.0, claimed by the winner
3629
3730[numthreads(256, 1, 1)]
@@ -42,7 +35,6 @@ void main(uint3 GTID : SV_GroupThreadID) {
4235 NoMatchSeventySeven = 77.0f;
4336 ZeroPositive = 0.0f;
4437 NanQuiet = NanIn[0];
45- CounterZero = 0.0f;
4638 ClaimZero = 0.0f;
4739 }
4840 GroupMemoryBarrierWithGroupSync();
@@ -84,36 +76,14 @@ void main(uint3 GTID : SV_GroupThreadID) {
8476 OrigNoMatch == 77.0f && OrigZero == 0.0f &&
8577 Claim == 0.0f) ? 1u : 0u;
8678
87- // Check 4.
88- float CompareValue = (float)GTID.x;
89- float NewValue = (float)GTID.x + 1.0f;
90- float Prev = 0.0f;
91- uint Mono = 1u;
92- uint Wins = 0u;
93- for (uint I = 0; I < 256; ++I) {
94- float Orig;
95- InterlockedCompareExchangeFloatBitwise(CounterZero, CompareValue, NewValue,
96- Orig);
97- if (Orig == CompareValue)
98- ++Wins;
99- GroupMemoryBarrierWithGroupSync();
100- float Cur = CounterZero;
101- if (Cur < Prev)
102- Mono = 0u;
103- Prev = Cur;
104- }
105- OutMono[GTID.x] = Mono;
106- OutWins[GTID.x] = Wins;
107-
10879 GroupMemoryBarrierWithGroupSync();
10980
11081 if (GTID.x == 0) {
111- OutFinal[0] = CounterZero; // 256.0
112- OutFinal[1] = MatchMinusFive; // 42.0
113- OutFinal[2] = NoMatchSeventySeven; // 77.0
114- OutFinal[3] = ZeroPositive; // +0.0, -0.0 must not have matched
115- OutFinal[4] = NanQuiet; // 7.0, the NaN must have matched
116- OutFinal[5] = ClaimZero; // 1.0, exactly one thread claimed
82+ OutFinal[0] = MatchMinusFive; // 42.0
83+ OutFinal[1] = NoMatchSeventySeven; // 77.0
84+ OutFinal[2] = ZeroPositive; // +0.0, -0.0 must not have matched
85+ OutFinal[3] = NanQuiet; // 7.0, the NaN must have matched
86+ OutFinal[4] = ClaimZero; // 1.0, exactly one thread claimed
11787 }
11888}
11989
@@ -124,10 +94,6 @@ Shaders:
12494 - Stage: Compute
12595 Entry: main
12696Buffers:
127- - Name: OutMono
128- Format: UInt32
129- Stride: 4
130- FillSize: 1024
13197 - Name: ExpectedOnes
13298 Format: UInt32
13399 Stride: 4
@@ -155,27 +121,19 @@ Buffers:
155121 Format: UInt32
156122 Stride: 4
157123 FillSize: 1024
158- - Name: OutWins
159- Format: UInt32
160- Stride: 4
161- FillSize: 1024
162124 - Name: OutFinal
163125 Format: Float32
164126 Stride: 4
165- FillSize: 24
127+ FillSize: 20
166128 - Name: ExpectedFinal
167129 Format: Float32
168130 Stride: 4
169- Data: [ 256.0, 42.0, 77.0, 0.0, 7.0, 1.0 ]
131+ Data: [ 42.0, 77.0, 0.0, 7.0, 1.0 ]
170132 - Name: NanIn
171133 Format: Float32
172134 Stride: 4
173135 Data: [ nan ]
174136Results:
175- - Result: TestMono
176- Rule: BufferExact
177- Actual: OutMono
178- Expected: ExpectedOnes
179137 - Result: TestSlots
180138 Rule: BufferExact
181139 Actual: OutSlots
@@ -184,58 +142,40 @@ Results:
184142 Rule: BufferExact
185143 Actual: OutOrig
186144 Expected: ExpectedOnes
187- - Result: TestWins
188- Rule: BufferExact
189- Actual: OutWins
190- Expected: ExpectedOnes
191145 - Result: TestFinal
192146 Rule: BufferExact
193147 Actual: OutFinal
194148 Expected: ExpectedFinal
195149DescriptorSets:
196150 - Resources:
197- - Name: OutMono
151+ - Name: OutSlots
198152 Kind: RWStructuredBuffer
199153 DirectXBinding:
200154 Register: 0
201155 Space: 0
202156 VulkanBinding:
203157 Binding: 0
204- - Name: OutSlots
158+ - Name: OutOrig
205159 Kind: RWStructuredBuffer
206160 DirectXBinding:
207161 Register: 1
208162 Space: 0
209163 VulkanBinding:
210164 Binding: 1
211- - Name: OutOrig
165+ - Name: OutFinal
212166 Kind: RWStructuredBuffer
213167 DirectXBinding:
214168 Register: 2
215169 Space: 0
216170 VulkanBinding:
217171 Binding: 2
218- - Name: OutWins
172+ - Name: NanIn
219173 Kind: RWStructuredBuffer
220174 DirectXBinding:
221175 Register: 3
222176 Space: 0
223177 VulkanBinding:
224178 Binding: 3
225- - Name: OutFinal
226- Kind: RWStructuredBuffer
227- DirectXBinding:
228- Register: 4
229- Space: 0
230- VulkanBinding:
231- Binding: 4
232- - Name: NanIn
233- Kind: RWStructuredBuffer
234- DirectXBinding:
235- Register: 5
236- Space: 0
237- VulkanBinding:
238- Binding: 5
239179...
240180#--- end
241181
0 commit comments