From 016ddee83a5418aaacb5c397d044438d4781bb46 Mon Sep 17 00:00:00 2001 From: Jeff Bolz Date: Thu, 17 Oct 2019 11:22:57 -0500 Subject: [PATCH] Only apply volatile semantics to atomics when using Vulkan Memory Model --- SPIRV/GlslangToSpv.cpp | 2 +- Test/baseResults/spv.volatileAtomic.comp.out | 40 ++++++++++++++++++++ Test/spv.volatileAtomic.comp | 8 ++++ gtests/Spv.FromFile.cpp | 1 + 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 Test/baseResults/spv.volatileAtomic.comp.out create mode 100644 Test/spv.volatileAtomic.comp diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index f4e0fdbcf..ae5f24d30 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -6401,7 +6401,7 @@ spv::Id TGlslangToSpvTraverser::createAtomicOperation(glslang::TOperator op, spv scopeId = builder.makeUintConstant(spv::ScopeDevice); } // semantics default to relaxed - spv::Id semanticsId = builder.makeUintConstant(lvalueCoherentFlags.isVolatile() ? + spv::Id semanticsId = builder.makeUintConstant(lvalueCoherentFlags.isVolatile() && glslangIntermediate->usingVulkanMemoryModel() ? spv::MemorySemanticsVolatileMask : spv::MemorySemanticsMaskNone); spv::Id semanticsId2 = semanticsId; diff --git a/Test/baseResults/spv.volatileAtomic.comp.out b/Test/baseResults/spv.volatileAtomic.comp.out new file mode 100644 index 000000000..aa2d211a2 --- /dev/null +++ b/Test/baseResults/spv.volatileAtomic.comp.out @@ -0,0 +1,40 @@ +spv.volatileAtomic.comp +// Module Version 10000 +// Generated by (magic number): 80007 +// Id's are bound by 18 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint GLCompute 4 "main" + ExecutionMode 4 LocalSize 1 1 1 + Source GLSL 450 + Name 4 "main" + Name 8 "D" + MemberName 8(D) 0 "d" + Name 10 "d" + Decorate 7 ArrayStride 4 + MemberDecorate 8(D) 0 Volatile + MemberDecorate 8(D) 0 Coherent + MemberDecorate 8(D) 0 Offset 0 + Decorate 8(D) BufferBlock + Decorate 10(d) DescriptorSet 0 + Decorate 10(d) Binding 3 + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeInt 32 0 + 7: TypeRuntimeArray 6(int) + 8(D): TypeStruct 7 + 9: TypePointer Uniform 8(D) + 10(d): 9(ptr) Variable Uniform + 11: TypeInt 32 1 + 12: 11(int) Constant 0 + 13: TypePointer Uniform 6(int) + 15: 6(int) Constant 0 + 16: 6(int) Constant 1 + 4(main): 2 Function None 3 + 5: Label + 14: 13(ptr) AccessChain 10(d) 12 12 + 17: 6(int) AtomicExchange 14 16 15 15 + Return + FunctionEnd diff --git a/Test/spv.volatileAtomic.comp b/Test/spv.volatileAtomic.comp new file mode 100644 index 000000000..2b7e6c62c --- /dev/null +++ b/Test/spv.volatileAtomic.comp @@ -0,0 +1,8 @@ +#version 450 core + +layout(set=0, binding=3) volatile buffer D { uint d[]; } d; + +void main() +{ + atomicExchange(d.d[0], 0); +} diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index d0c075156..962034168 100644 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -404,6 +404,7 @@ INSTANTIATE_TEST_CASE_P( "spv.storageBuffer.vert", "spv.precise.tese", "spv.precise.tesc", + "spv.volatileAtomic.comp", "spv.vulkan100.subgroupArithmetic.comp", "spv.vulkan100.subgroupPartitioned.comp", "spv.xfb.vert",