Do not generate samplerBuffer for spirv1.6 and beyond

This type was removed from spirv1.6. If samplerBuffer is specified in
GLSL, generate textureBuffer. If samplerBuffer type is constructed,
just return the buffer.

Fixes #2956
This commit is contained in:
Greg Fischer
2022-06-21 17:33:57 -06:00
parent bffcf209cb
commit c1ae2f33b5
6 changed files with 137 additions and 5 deletions

View File

@@ -2936,9 +2936,17 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
std::vector<spv::Id> arguments;
translateArguments(*node, arguments, lvalueCoherentFlags);
spv::Id constructed;
if (node->getOp() == glslang::EOpConstructTextureSampler)
constructed = builder.createOp(spv::OpSampledImage, resultType(), arguments);
else if (node->getOp() == glslang::EOpConstructStruct ||
if (node->getOp() == glslang::EOpConstructTextureSampler) {
const glslang::TType& texType = node->getSequence()[0]->getAsTyped()->getType();
if (glslangIntermediate->getSpv().spv >= glslang::EShTargetSpv_1_6 &&
texType.getSampler().isBuffer()) {
// SamplerBuffer is not supported in spirv1.6 so
// `samplerBuffer(textureBuffer, sampler)` is a no-op
// and textureBuffer is the result going forward
constructed = arguments[0];
} else
constructed = builder.createOp(spv::OpSampledImage, resultType(), arguments);
} else if (node->getOp() == glslang::EOpConstructStruct ||
node->getOp() == glslang::EOpConstructCooperativeMatrix ||
node->getType().isArray()) {
std::vector<spv::Id> constituents;
@@ -4173,8 +4181,10 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty
spvType = builder.makeImageType(getSampledType(sampler), TranslateDimensionality(sampler),
sampler.isShadow(), sampler.isArrayed(), sampler.isMultiSample(),
sampler.isImageClass() ? 2 : 1, TranslateImageFormat(type));
if (sampler.isCombined()) {
// already has both image and sampler, make the combined type
if (sampler.isCombined() &&
(!sampler.isBuffer() || glslangIntermediate->getSpv().spv < glslang::EShTargetSpv_1_6)) {
// Already has both image and sampler, make the combined type. Only combine sampler to
// buffer if before SPIR-V 1.6.
spvType = builder.makeSampledImageType(spvType);
}
}