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();
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.setAccessChainRValue(length);