From fb18b6df287a092cf8d0f26600f000b7d37df8b6 Mon Sep 17 00:00:00 2001 From: Rex Xu Date: Sat, 22 Feb 2020 22:04:31 +0800 Subject: [PATCH] Fix an issue of SPV generation for imageAtomicStore. For GLSL function imageAtomicStore, it will be translated to OpImageTexelPointer + OpAtomicStore. The result type of OpImageTexelPointer must be the same as the sampled type of OpTypeImage. On translation, the result type is mistakenly fetched from operand list operands[2] while operands[2] corresponds to sampleNum whose type is always uint. This leads to an error if the image type is iimageXXX that is int image. --- SPIRV/GlslangToSpv.cpp | 2 +- Test/baseResults/spv.memoryScopeSemantics.comp.out | 5 ++++- Test/spv.memoryScopeSemantics.comp | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 0c8a87e..0d4f2c6 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -4731,7 +4731,7 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO // imageAtomicStore has a void return type so base the pointer type on // the type of the value operand. if (node->getOp() == glslang::EOpImageAtomicStore) { - resultTypeId = builder.makePointer(spv::StorageClassImage, builder.getTypeId(operands[2].word)); + resultTypeId = builder.makePointer(spv::StorageClassImage, builder.getTypeId(*opIt)); } else { resultTypeId = builder.makePointer(spv::StorageClassImage, resultType()); } diff --git a/Test/baseResults/spv.memoryScopeSemantics.comp.out b/Test/baseResults/spv.memoryScopeSemantics.comp.out index cd99ec3..b8721f2 100644 --- a/Test/baseResults/spv.memoryScopeSemantics.comp.out +++ b/Test/baseResults/spv.memoryScopeSemantics.comp.out @@ -1,7 +1,7 @@ spv.memoryScopeSemantics.comp // Module Version 10300 // Generated by (magic number): 80008 -// Id's are bound by 167 +// Id's are bound by 169 Capability Shader Capability Int64 @@ -181,6 +181,7 @@ spv.memoryScopeSemantics.comp 163: TypeImage 6(int) 2D multi-sampled nonsampled format:R32i 164: TypePointer UniformConstant 163 165(imageMS): 164(ptr) Variable UniformConstant + 167: 6(int) Constant 4294967289 4(main): 2 Function None 3 5: Label 8(origi): 7(ptr) Variable Function @@ -280,5 +281,7 @@ spv.memoryScopeSemantics.comp 162: 15(int) AtomicIAdd 160 12 42 16 166: 40(ptr) ImageTexelPointer 165(imageMS) 39 12 AtomicStore 166 12 33 14 + 168: 40(ptr) ImageTexelPointer 36(imagei) 39 17 + AtomicStore 168 12 33 167 Return FunctionEnd diff --git a/Test/spv.memoryScopeSemantics.comp b/Test/spv.memoryScopeSemantics.comp index cb8545b..528a639 100644 --- a/Test/spv.memoryScopeSemantics.comp +++ b/Test/spv.memoryScopeSemantics.comp @@ -69,5 +69,6 @@ void main() atomicAdd(bufferu.x, 5u, gl_ScopeDevice, 0, gl_SemanticsVolatile); imageAtomicStore(imageMS, ivec2(0,0), 1, 4, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelease); + imageAtomicStore(imagei, ivec2(0,0), -7, gl_ScopeDevice, gl_StorageSemanticsBuffer, gl_SemanticsRelease); } -- 2.7.4