Preserve signedness in SPV image query ops
The AST->SPIRV translation of image queries was dropping signedness,
causing some validation troubles.
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index 5385eee..276899c 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -2922,6 +2922,10 @@
glslang::TCrackedTextureOp cracked;
node->crackTexture(sampler, cracked);
+ const bool isUnsignedResult =
+ node->getType().getBasicType() == glslang::EbtUint64 ||
+ node->getType().getBasicType() == glslang::EbtUint;
+
// Check for queries
if (cracked.query) {
// OpImageQueryLod works on a sampled image, for other queries the image has to be extracted first
@@ -2933,17 +2937,17 @@
case glslang::EOpTextureQuerySize:
if (arguments.size() > 1) {
params.lod = arguments[1];
- return builder.createTextureQueryCall(spv::OpImageQuerySizeLod, params);
+ return builder.createTextureQueryCall(spv::OpImageQuerySizeLod, params, isUnsignedResult);
} else
- return builder.createTextureQueryCall(spv::OpImageQuerySize, params);
+ return builder.createTextureQueryCall(spv::OpImageQuerySize, params, isUnsignedResult);
case glslang::EOpImageQuerySamples:
case glslang::EOpTextureQuerySamples:
- return builder.createTextureQueryCall(spv::OpImageQuerySamples, params);
+ return builder.createTextureQueryCall(spv::OpImageQuerySamples, params, isUnsignedResult);
case glslang::EOpTextureQueryLod:
params.coords = arguments[1];
- return builder.createTextureQueryCall(spv::OpImageQueryLod, params);
+ return builder.createTextureQueryCall(spv::OpImageQueryLod, params, isUnsignedResult);
case glslang::EOpTextureQueryLevels:
- return builder.createTextureQueryCall(spv::OpImageQueryLevels, params);
+ return builder.createTextureQueryCall(spv::OpImageQueryLevels, params, isUnsignedResult);
case glslang::EOpSparseTexelsResident:
return builder.createUnaryOp(spv::OpImageSparseTexelsResident, builder.makeBoolType(), arguments[0]);
default:
diff --git a/SPIRV/SpvBuilder.cpp b/SPIRV/SpvBuilder.cpp
index f6b0b86..0add1db 100644
--- a/SPIRV/SpvBuilder.cpp
+++ b/SPIRV/SpvBuilder.cpp
@@ -1662,7 +1662,7 @@
}
// Comments in header
-Id Builder::createTextureQueryCall(Op opCode, const TextureParameters& parameters)
+Id Builder::createTextureQueryCall(Op opCode, const TextureParameters& parameters, bool isUnsignedResult)
{
// All these need a capability
addCapability(CapabilityImageQuery);
@@ -1695,10 +1695,12 @@
}
if (isArrayedImageType(getImageType(parameters.sampler)))
++numComponents;
+
+ Id intType = isUnsignedResult ? makeUintType(32) : makeIntType(32);
if (numComponents == 1)
- resultType = makeIntType(32);
+ resultType = intType;
else
- resultType = makeVectorType(makeIntType(32), numComponents);
+ resultType = makeVectorType(intType, numComponents);
break;
}
@@ -1707,7 +1709,7 @@
break;
case OpImageQueryLevels:
case OpImageQuerySamples:
- resultType = makeIntType(32);
+ resultType = isUnsignedResult ? makeUintType(32) : makeIntType(32);
break;
default:
assert(0);
diff --git a/SPIRV/SpvBuilder.h b/SPIRV/SpvBuilder.h
index fe83ac1..204d3e7 100755
--- a/SPIRV/SpvBuilder.h
+++ b/SPIRV/SpvBuilder.h
@@ -335,7 +335,7 @@
// Emit the OpTextureQuery* instruction that was passed in.
// Figure out the right return value and type, and return it.
- Id createTextureQueryCall(Op, const TextureParameters&);
+ Id createTextureQueryCall(Op, const TextureParameters&, bool isUnsignedResult);
Id createSamplePositionCall(Decoration precision, Id, Id);