From b4bab3ce0113ee030cdbcce00f2d2ca2f45eda79 Mon Sep 17 00:00:00 2001 From: Rex Xu Date: Thu, 6 Feb 2020 16:51:10 +0800 Subject: [PATCH] Fix a parser error of GL_KHR_memory_scope_semantics When 2DMS or 2DMSArray is used, IMAGE_PARAMS will take an additional paramter to represent sample number. The semantics check should get the correct semantics values, taking this case into account. --- .../spv.memoryScopeSemantics.comp.out | 11 ++++++++++- Test/spv.memoryScopeSemantics.comp | 3 +++ glslang/MachineIndependent/ParseHelper.cpp | 19 +++++++++++-------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Test/baseResults/spv.memoryScopeSemantics.comp.out b/Test/baseResults/spv.memoryScopeSemantics.comp.out index 29675915..cd99ec3e 100644 --- a/Test/baseResults/spv.memoryScopeSemantics.comp.out +++ b/Test/baseResults/spv.memoryScopeSemantics.comp.out @@ -1,11 +1,12 @@ spv.memoryScopeSemantics.comp // Module Version 10300 // Generated by (magic number): 80008 -// Id's are bound by 163 +// Id's are bound by 167 Capability Shader Capability Int64 Capability Int64Atomics + Capability StorageImageMultisample Capability VulkanMemoryModelKHR Capability VulkanMemoryModelDeviceScopeKHR Extension "SPV_KHR_vulkan_memory_model" @@ -49,6 +50,7 @@ spv.memoryScopeSemantics.comp Name 151 "BufferM" MemberName 151(BufferM) 0 "x" Name 153 "bufferm" + Name 165 "imageMS" Decorate 36(imagei) DescriptorSet 0 Decorate 36(imagei) Binding 1 Decorate 46(imageu) DescriptorSet 0 @@ -83,6 +85,8 @@ spv.memoryScopeSemantics.comp Decorate 151(BufferM) Block Decorate 153(bufferm) DescriptorSet 0 Decorate 153(bufferm) Binding 9 + Decorate 165(imageMS) DescriptorSet 0 + Decorate 165(imageMS) Binding 10 2: TypeVoid 3: TypeFunction 2 6: TypeInt 32 1 @@ -174,6 +178,9 @@ spv.memoryScopeSemantics.comp 152: TypePointer StorageBuffer 151(BufferM) 153(bufferm): 152(ptr) Variable StorageBuffer 161: 6(int) Constant 32768 + 163: TypeImage 6(int) 2D multi-sampled nonsampled format:R32i + 164: TypePointer UniformConstant 163 + 165(imageMS): 164(ptr) Variable UniformConstant 4(main): 2 Function None 3 5: Label 8(origi): 7(ptr) Variable Function @@ -271,5 +278,7 @@ spv.memoryScopeSemantics.comp 159: 15(int) AtomicIAdd 158 12 17 51 160: 69(ptr) AccessChain 68(bufferu) 38 162: 15(int) AtomicIAdd 160 12 42 16 + 166: 40(ptr) ImageTexelPointer 165(imageMS) 39 12 + AtomicStore 166 12 33 14 Return FunctionEnd diff --git a/Test/spv.memoryScopeSemantics.comp b/Test/spv.memoryScopeSemantics.comp index 037e6d7b..cb8545b6 100644 --- a/Test/spv.memoryScopeSemantics.comp +++ b/Test/spv.memoryScopeSemantics.comp @@ -20,6 +20,7 @@ shared uint64_t atomu64; shared int64_t atomi64; layout (binding = 8) volatile buffer BufferL { uint x; } bufferl; layout (binding = 9) buffer BufferM { volatile uint x; } bufferm; +layout(binding = 10, r32i) volatile coherent uniform iimage2DMS imageMS; void main() @@ -66,5 +67,7 @@ void main() imageAtomicAdd(imagei, ivec2(0,0), 3); atomicAdd(bufferu.x, 4u, gl_ScopeDevice, 0, 0); atomicAdd(bufferu.x, 5u, gl_ScopeDevice, 0, gl_SemanticsVolatile); + + imageAtomicStore(imageMS, ivec2(0,0), 1, 4, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelease); } diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index a2224e16..6f41adb0 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -1672,6 +1672,9 @@ void TParseContext::memorySemanticsCheck(const TSourceLoc& loc, const TFunction& unsigned int semantics = 0, storageClassSemantics = 0; unsigned int semantics2 = 0, storageClassSemantics2 = 0; + const TIntermTyped* arg0 = (*argp)[0]->getAsTyped(); + const bool isMS = arg0->getBasicType() == EbtSampler && arg0->getType().getSampler().isMultiSample(); + // Grab the semantics and storage class semantics from the operands, based on opcode switch (callNode.getOp()) { case EOpAtomicAdd: @@ -1704,18 +1707,18 @@ void TParseContext::memorySemanticsCheck(const TSourceLoc& loc, const TFunction& case EOpImageAtomicXor: case EOpImageAtomicExchange: case EOpImageAtomicStore: - storageClassSemantics = (*argp)[4]->getAsConstantUnion()->getConstArray()[0].getIConst(); - semantics = (*argp)[5]->getAsConstantUnion()->getConstArray()[0].getIConst(); + storageClassSemantics = (*argp)[isMS ? 5 : 4]->getAsConstantUnion()->getConstArray()[0].getIConst(); + semantics = (*argp)[isMS ? 6 : 5]->getAsConstantUnion()->getConstArray()[0].getIConst(); break; case EOpImageAtomicLoad: - storageClassSemantics = (*argp)[3]->getAsConstantUnion()->getConstArray()[0].getIConst(); - semantics = (*argp)[4]->getAsConstantUnion()->getConstArray()[0].getIConst(); + storageClassSemantics = (*argp)[isMS ? 4 : 3]->getAsConstantUnion()->getConstArray()[0].getIConst(); + semantics = (*argp)[isMS ? 5 : 4]->getAsConstantUnion()->getConstArray()[0].getIConst(); break; case EOpImageAtomicCompSwap: - storageClassSemantics = (*argp)[5]->getAsConstantUnion()->getConstArray()[0].getIConst(); - semantics = (*argp)[6]->getAsConstantUnion()->getConstArray()[0].getIConst(); - storageClassSemantics2 = (*argp)[7]->getAsConstantUnion()->getConstArray()[0].getIConst(); - semantics2 = (*argp)[8]->getAsConstantUnion()->getConstArray()[0].getIConst(); + storageClassSemantics = (*argp)[isMS ? 6 : 5]->getAsConstantUnion()->getConstArray()[0].getIConst(); + semantics = (*argp)[isMS ? 7 : 6]->getAsConstantUnion()->getConstArray()[0].getIConst(); + storageClassSemantics2 = (*argp)[isMS ? 8 : 7]->getAsConstantUnion()->getConstArray()[0].getIConst(); + semantics2 = (*argp)[isMS ? 9 : 8]->getAsConstantUnion()->getConstArray()[0].getIConst(); break; case EOpBarrier: