SPV: For GLSL only, bitcast OpArrayLength result back to int.

This makes the rest of the AST consuming the result match GLSL
semantics and hence get complete type matching.
This commit is contained in:
John Kessenich 2018-11-28 07:01:37 -07:00
parent e045c23a34
commit 8c869679f2
2 changed files with 25 additions and 22 deletions

View File

@ -1825,6 +1825,12 @@ bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TI
unsigned int member = node->getOperand()->getAsBinaryNode()->getRight()->getAsConstantUnion()->getConstArray()[0].getUConst(); unsigned int member = node->getOperand()->getAsBinaryNode()->getRight()->getAsConstantUnion()->getConstArray()[0].getUConst();
spv::Id length = builder.createArrayLength(builder.accessChainGetLValue(), member); spv::Id length = builder.createArrayLength(builder.accessChainGetLValue(), member);
// GLSL semantics say the result of .length() is an int, while SPIR-V says
// signedness must be 0. So, convert from SPIR-V unsigned back to GLSL's
// AST expectation of a signed result.
if (glslangIntermediate->getSource() == glslang::EShSourceGlsl)
length = builder.createUnaryOp(spv::OpBitcast, builder.makeIntType(32), length);
builder.clearAccessChain(); builder.clearAccessChain();
builder.setAccessChainRValue(length); builder.setAccessChainRValue(length);

View File

@ -1,18 +1,14 @@
spv.310.comp spv.310.comp
error: SPIRV-Tools Validation Errors
error: OpStore Pointer <id> '62's type does not match Object <id> '60's type.
OpStore %62 %60
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80007 // Generated by (magic number): 80007
// Id's are bound by 71 // Id's are bound by 72
Capability Shader Capability Shader
Capability DeviceGroup Capability DeviceGroup
Extension "SPV_KHR_device_group" Extension "SPV_KHR_device_group"
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint GLCompute 4 "main" 53 64 EntryPoint GLCompute 4 "main" 53 65
ExecutionMode 4 LocalSize 16 32 4 ExecutionMode 4 LocalSize 16 32 4
Source ESSL 310 Source ESSL 310
SourceExtension "GL_EXT_device_group" SourceExtension "GL_EXT_device_group"
@ -34,7 +30,7 @@ error: OpStore Pointer <id> '62's type does not match Object <id> '60's type.
MemberName 48(outs) 1 "va" MemberName 48(outs) 1 "va"
Name 50 "outnames" Name 50 "outnames"
Name 53 "gl_LocalInvocationID" Name 53 "gl_LocalInvocationID"
Name 64 "gl_DeviceIndex" Name 65 "gl_DeviceIndex"
Decorate 11 ArrayStride 16 Decorate 11 ArrayStride 16
MemberDecorate 12(outb) 0 Offset 0 MemberDecorate 12(outb) 0 Offset 0
MemberDecorate 12(outb) 1 Offset 4 MemberDecorate 12(outb) 1 Offset 4
@ -52,8 +48,8 @@ error: OpStore Pointer <id> '62's type does not match Object <id> '60's type.
Decorate 48(outs) BufferBlock Decorate 48(outs) BufferBlock
Decorate 50(outnames) DescriptorSet 0 Decorate 50(outnames) DescriptorSet 0
Decorate 53(gl_LocalInvocationID) BuiltIn LocalInvocationId Decorate 53(gl_LocalInvocationID) BuiltIn LocalInvocationId
Decorate 64(gl_DeviceIndex) BuiltIn DeviceIndex Decorate 65(gl_DeviceIndex) BuiltIn DeviceIndex
Decorate 70 BuiltIn WorkgroupSize Decorate 71 BuiltIn WorkgroupSize
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeInt 32 0 6: TypeInt 32 0
@ -93,15 +89,15 @@ error: OpStore Pointer <id> '62's type does not match Object <id> '60's type.
52: TypePointer Input 51(ivec3) 52: TypePointer Input 51(ivec3)
53(gl_LocalInvocationID): 52(ptr) Variable Input 53(gl_LocalInvocationID): 52(ptr) Variable Input
54: TypePointer Input 6(int) 54: TypePointer Input 6(int)
61: TypePointer Uniform 15(int) 62: TypePointer Uniform 15(int)
63: TypePointer Input 15(int) 64: TypePointer Input 15(int)
64(gl_DeviceIndex): 63(ptr) Variable Input 65(gl_DeviceIndex): 64(ptr) Variable Input
65: 6(int) Constant 1 66: 6(int) Constant 1
66: 6(int) Constant 3400 67: 6(int) Constant 3400
67: 6(int) Constant 16 68: 6(int) Constant 16
68: 6(int) Constant 32 69: 6(int) Constant 32
69: 6(int) Constant 4 70: 6(int) Constant 4
70: 51(ivec3) ConstantComposite 67 68 69 71: 51(ivec3) ConstantComposite 68 69 70
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
ControlBarrier 7 7 8 ControlBarrier 7 7 8
@ -129,9 +125,10 @@ error: OpStore Pointer <id> '62's type does not match Object <id> '60's type.
59: 29(ptr) AccessChain 50(outnames) 26 56 59: 29(ptr) AccessChain 50(outnames) 26 56
Store 59 58 Store 59 58
60: 6(int) ArrayLength 14(outbname) 3 60: 6(int) ArrayLength 14(outbname) 3
62: 61(ptr) AccessChain 50(outnames) 16 61: 15(int) Bitcast 60
Store 62 60 63: 62(ptr) AccessChain 50(outnames) 16
MemoryBarrier 65 8 Store 63 61
MemoryBarrier 7 66 MemoryBarrier 66 8
MemoryBarrier 7 67
Return Return
FunctionEnd FunctionEnd