Preserve signedness in SPV image query ops

The AST->SPIRV translation of image queries was dropping signedness,
causing some validation troubles.
This commit is contained in:
steve-lunarg
2017-03-10 12:45:50 -07:00
parent 757bc87445
commit 0b5c2ae70e
8 changed files with 1025 additions and 1021 deletions

View File

@@ -2922,6 +2922,10 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
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 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
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:

View File

@@ -1662,7 +1662,7 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool sparse,
}
// 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 @@ Id Builder::createTextureQueryCall(Op opCode, const TextureParameters& parameter
}
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 @@ Id Builder::createTextureQueryCall(Op opCode, const TextureParameters& parameter
break;
case OpImageQueryLevels:
case OpImageQuerySamples:
resultType = makeIntType(32);
resultType = isUnsignedResult ? makeUintType(32) : makeIntType(32);
break;
default:
assert(0);

View File

@@ -335,7 +335,7 @@ public:
// 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);