Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions layers/gpuav/spirv/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ Module::Module(vvl::span<const uint32_t> words, DebugReport* debug_report, const
function_end_found = true;
} else if (opcode == spv::OpAssumeTrueKHR) {
has_assume_true_ = true;
} else if (opcode == spv::OpControlBarrier && !has_subgroup_shared_memory_barrier_) {
const Constant* scope = type_manager_.FindConstantById(new_inst->Word(1));
const Constant* semantics = type_manager_.FindConstantById(new_inst->Word(3));
if (scope && semantics && scope->GetValueUint32() == spv::ScopeSubgroup &&
(semantics->GetValueUint32() & spv::MemorySemanticsWorkgroupMemoryMask) != 0) {
has_subgroup_shared_memory_barrier_ = true;
}
}

if (opcode == spv::OpLoopMerge) {
Expand Down
2 changes: 2 additions & 0 deletions layers/gpuav/spirv/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ class Module {

// Lets ExpectAssumePass be skipped for the (majority of) shaders without an OpAssumeTrueKHR
bool has_assume_true_ = false;
// Lets SharedMemoryDataRacePass skip shaders with a Subgroup scope barrier on Workgroup memory
bool has_subgroup_shared_memory_barrier_ = false;

// Used when UseErrorPayloadVariable is set. Needs to be same for all passes.
// Will be set in the LogErrorPass
Expand Down
7 changes: 7 additions & 0 deletions layers/gpuav/spirv/shared_memory_data_race_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,13 @@ bool SharedMemoryDataRacePass::Instrument() {
return false;
}

// Only a Workgroup scope barrier resets the shadow memory,
// so accesses ordered by a Subgroup scope barrier would be reported as races
// https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/12813
if (module_.has_subgroup_shared_memory_barrier_) {
return false;
}

const std::vector<const Variable*>& shmem_vars = type_manager_.GetSharedMemoryVariables();

// Since we don't support WorkgroupMemoryExplicitLayoutKHR, we don't need to worry about Aliased blocks
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/gpu_av_shared_memory_data_race_positive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,46 @@ TEST_F(PositiveGpuAVSharedMemoryDataRace, SlangBasic) {
TestHelper(shader_source, SPV_SOURCE_SLANG);
}

TEST_F(PositiveGpuAVSharedMemoryDataRace, SubgroupBarrier) {
TEST_DESCRIPTION("https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/12813");
const char* shader_source = R"glsl(
#version 450
#extension GL_KHR_memory_scope_semantics : enable
#extension GL_KHR_shader_subgroup_basic : enable

layout(local_size_x = 64) in;
shared uint bins[64];
void main() {
bins[gl_LocalInvocationIndex] = 0;
controlBarrier(gl_ScopeSubgroup, gl_ScopeWorkgroup, gl_StorageSemanticsShared, gl_SemanticsAcquireRelease);
// Another invocation's slot, but always in the same subgroup
uint other = gl_SubgroupID * gl_SubgroupSize + (gl_SubgroupInvocationID ^ 1);
atomicAdd(bins[other], 1);
}
)glsl";

TestHelper(shader_source, SPV_SOURCE_GLSL);
}

TEST_F(PositiveGpuAVSharedMemoryDataRace, SubgroupBarrierSlang) {
TEST_DESCRIPTION("https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/12813");
const char* shader_source = R"slang(
groupshared uint sharedBins[64];

[numthreads(64, 1, 1)]
void main()
{
uint waveBinsIndex = WaveGetWaveIndex() * WaveGetLaneCount();
sharedBins[waveBinsIndex + WaveGetLaneIndex()] = 0;
GroupMemoryBarrierWithWaveSync();

InterlockedAdd(sharedBins[waveBinsIndex + (WaveGetLaneIndex() ^ 1)], 1);
}
)slang";

TestHelper(shader_source, SPV_SOURCE_SLANG);
}

TEST_F(PositiveGpuAVSharedMemoryDataRace, SlangIssue12415) {
TEST_DESCRIPTION(
"Regression test for https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/12415. A first load from a "
Expand Down
Loading