KhronosGroup / KhronosGroup/Vulkan-ValidationLayers
Unexpected SharedMemoryDataRace-RaceOnLoadStoreVsAtomic
- Dominant language
- C++
- Stars
- 1k
- Forks
- 504
- Avg merge
- 11h 35m
- Merged PRs (30d)
- 224
Description
**Environment:**
- OS: Ubuntu 24.04
- GPU and driver version: RTX 3090 , Driver: 595.84
- SDK or header version if building from repo: 1.4.350
- Options enabled (synchronization, best practices, etc.):
**Describe the Issue**
Shader:
```slang
groupshared uint s_min[3];
groupshared uint s_max[3];
[ForceInline]
uint float_to_sortable_uint(float val) {
uint temp = asuint(val);
uint mask = uint(-int(temp >> 31)) | 0x80000000;
return temp ^ mask;
}
[ForceInline]
float sortable_uint_to_float(uint val) {
uint mask = ((val >> 31) - 1) | 0x80000000;
return asfloat(val ^ mask);
}
[shader("compute")]
[numthreads(256, 1, 1)]
void compute_float3_minmax(float *points, uniform uint num_points,
uniform uint start_point_idx, uint *out_minmax,
uint gid: SV_DispatchThreadID,
uint tid: SV_GroupThreadID) {
const uint global_idx = start_point_idx + gid;
if (global_idx >= num_points)
return;
if (tid < 3) {
s_min[tid] = 0xFFFFFFFFu;
s_max[tid] = 0u;
}
GroupMemoryBarrierWithGroupSync();
for (int d = 0; d < 3; ++d) {
uint val = float_to_sortable_uint(points[global_idx * 3 + d]);
// Wave min/max
uint wave_min = WaveActiveMin(val);
uint wave_max = WaveActiveMax(val);
// Atomic min/max on shared memory
if (WaveIsFirstLane()) {
InterlockedMin(s_min[d], wave_min);
InterlockedMax(s_max[d], wave_max);
}
GroupMemoryBarrierWithGroupSync();
// Atomic min/max on global memory
if (tid == 0) {
InterlockedMin(out_minmax[d], s_min[d]);
InterlockedMax(out_minmax[3 + d], s_max[d]);
}
}
}
```
Throws a validation error:
```
Validation Error: [ SharedMemoryDataRace-RaceOnLoadStoreVsAtomic ] | MessageID = 0x7600531a
vkCmdDispatch(): A data race was detected on the shared memory variable "s_max" in local invocation index 0 while performing a load or store operation. (Likely against unknown invocation)
The other access in this race was at:
Shader validation error occurred at gpu/seed_morton_sort.slang:53:13
53: InterlockedMax(s_max[d], wave_max);
^
Stage = Compute. Global invocation ID (x, y, z) = (0, 0, 0)
Command buffer (0xc0)
Compute Dispatch Index 0
Shader Module (gpu/seed_morton_sort.spv)(0x55cc943a3cd0) (internal ID 22)
Shader validation error occurred at gpu/seed_morton_sort.slang:59:13
59: InterlockedMax(out_minmax[3 + d], s_max[d]);
^
Objects: 3
[0] VkQueue 0x55cc90229b30
[1] VkCommandBuffer 0x55cc906dcbb0[stream_0]
[2] VkPipeline 0x55cc93ba3ea0[compute_float3_minmax]
2026-07-30 12:56:04.566 [Error] (Vulkan) vkCmdDispatch(): A data race was detected on the shared memory variable "s_max" in local invocation index 0 while performing a load or store operation. (Likely against unknown invocation)
The other access in this race was at:
Shader validation error occurred at gpu/seed_morton_sort.slang:53:13
53: InterlockedMax(s_max[d], wave_max);
^
Stage = Compute. Global invocation ID (x, y, z) = (0, 0, 0)
Command buffer (0xc0)
Compute Dispatch Index 0
Shader Module (gpu/seed_morton_sort.spv)(0x55cc943a3cd0) (internal ID 22)
Shader validation error occurred at gpu/seed_morton_sort.slang:59:13
59: InterlockedMax(out_minmax[3 + d], s_max[d]);
^
```
But I can't see any data-race there. Could anyone explain? Is this validation error correct?
**Expected behavior**
No validation error...
**Valid Usage ID**
**Additional context**
Contributor guide
Research direction
Start with the provided compute shader and reproduce the validation report using the shared-memory accesses at lines 53 and 59. Compare the reported atomic and load/store accesses with the validator's expected synchronization rules; done means establishing whether the diagnostic is correct and documenting or correcting the validation behavior accordingly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100