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);
}
}

View File

@ -0,0 +1,43 @@
spv.1.6.samplerBuffer.frag
// Module Version 10600
// Generated by (magic number): 8000a
// Id's are bound by 23
Capability Shader
Capability SampledBuffer
Capability ImageQuery
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 9 13
ExecutionMode 4 OriginUpperLeft
Source GLSL 140
Name 4 "main"
Name 9 "o"
Name 13 "sampB"
Decorate 9(o) Location 0
Decorate 13(sampB) DescriptorSet 0
Decorate 13(sampB) Binding 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Output 7(fvec4)
9(o): 8(ptr) Variable Output
10: TypeInt 32 1
11: TypeImage 10(int) Buffer sampled format:Unknown
12: TypePointer UniformConstant 11
13(sampB): 12(ptr) Variable UniformConstant
17: 6(float) Constant 1120403456
19: TypeInt 32 0
20: 19(int) Constant 3
21: TypePointer Output 6(float)
4(main): 2 Function None 3
5: Label
14: 11 Load 13(sampB)
15: 10(int) ImageQuerySize 14
16: 6(float) ConvertSToF 15
18: 6(float) FDiv 16 17
22: 21(ptr) AccessChain 9(o) 20
Store 22 18
Return
FunctionEnd

View File

@ -0,0 +1,52 @@
spv.1.6.separate.frag
// Module Version 10600
// Generated by (magic number): 8000a
// Id's are bound by 27
Capability Shader
Capability SampledBuffer
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 9 13 18 24
ExecutionMode 4 OriginUpperLeft
Source GLSL 400
Name 4 "main"
Name 9 "texBuffer"
Name 13 "s"
Name 18 "itexBuffer"
Name 24 "utexBuffer"
Decorate 9(texBuffer) DescriptorSet 0
Decorate 9(texBuffer) Binding 1
Decorate 13(s) DescriptorSet 0
Decorate 13(s) Binding 0
Decorate 18(itexBuffer) DescriptorSet 0
Decorate 18(itexBuffer) Binding 2
Decorate 24(utexBuffer) DescriptorSet 0
Decorate 24(utexBuffer) Binding 3
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeImage 6(float) Buffer sampled format:Unknown
8: TypePointer UniformConstant 7
9(texBuffer): 8(ptr) Variable UniformConstant
11: TypeSampler
12: TypePointer UniformConstant 11
13(s): 12(ptr) Variable UniformConstant
15: TypeInt 32 1
16: TypeImage 15(int) Buffer sampled format:Unknown
17: TypePointer UniformConstant 16
18(itexBuffer): 17(ptr) Variable UniformConstant
21: TypeInt 32 0
22: TypeImage 21(int) Buffer sampled format:Unknown
23: TypePointer UniformConstant 22
24(utexBuffer): 23(ptr) Variable UniformConstant
4(main): 2 Function None 3
5: Label
10: 7 Load 9(texBuffer)
14: 11 Load 13(s)
19: 16 Load 18(itexBuffer)
20: 11 Load 13(s)
25: 22 Load 24(utexBuffer)
26: 11 Load 13(s)
Return
FunctionEnd

View File

@ -0,0 +1,11 @@
#version 140
out vec4 o;
uniform isamplerBuffer sampB;
void main()
{
o.w = float(textureSize(sampB)) / 100.0;
}

View File

@ -0,0 +1,14 @@
#version 400
uniform sampler s;
uniform textureBuffer texBuffer;
uniform itextureBuffer itexBuffer;
uniform utextureBuffer utexBuffer;
void main()
{
samplerBuffer (texBuffer, s);
isamplerBuffer (itexBuffer, s);
usamplerBuffer (utexBuffer, s);
}

View File

@ -639,6 +639,8 @@ INSTANTIATE_TEST_SUITE_P(
"spv.1.6.conditionalDiscard.frag",
"spv.1.6.helperInvocation.frag",
"spv.1.6.specConstant.comp",
"spv.1.6.samplerBuffer.frag",
"spv.1.6.separate.frag",
})),
FileNameAsCustomTestSuffix
);