Fix #2178: Allow specialization constants for texel offsets.

This commit is contained in:
John Kessenich 2020-04-12 22:56:17 -06:00
parent fd593d5f08
commit 4657244018
4 changed files with 60 additions and 4 deletions

View File

@ -0,0 +1,43 @@
spv.specTexture.frag
// Module Version 10000
// Generated by (magic number): 80008
// Id's are bound by 23
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 9
ExecutionMode 4 OriginLowerLeft
Source GLSL 450
Name 4 "main"
Name 9 "color_out"
Name 13 "tex"
Name 19 "offs"
Decorate 9(color_out) Location 0
Decorate 13(tex) DescriptorSet 0
Decorate 13(tex) Binding 0
Decorate 19(offs) SpecId 1
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
7: TypeVector 6(float) 4
8: TypePointer Output 7(fvec4)
9(color_out): 8(ptr) Variable Output
10: TypeImage 6(float) 2D sampled format:Unknown
11: TypeSampledImage 10
12: TypePointer UniformConstant 11
13(tex): 12(ptr) Variable UniformConstant
15: TypeVector 6(float) 2
16: 6(float) Constant 0
17: 15(fvec2) ConstantComposite 16 16
18: TypeInt 32 1
19(offs): 18(int) SpecConstant 0
20: TypeVector 18(int) 2
21: 20(ivec2) SpecConstantComposite 19(offs) 19(offs)
4(main): 2 Function None 3
5: Label
14: 11 Load 13(tex)
22: 7(fvec4) ImageSampleExplicitLod 14 17 Lod ConstOffset 16 21
Store 9(color_out) 22
Return
FunctionEnd

10
Test/spv.specTexture.frag Normal file
View File

@ -0,0 +1,10 @@
#version 450
layout(constant_id = 1) const int offs = 0;
layout(binding = 0) uniform sampler2D tex;
layout(location = 0) out vec4 color_out;
void main(void)
{
color_out = textureLodOffset(tex, vec2(0.0, 0.0), 0.0, ivec2(offs, offs));
}

View File

@ -2013,18 +2013,20 @@ void TParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCan
if (arg > 0) {
#ifndef GLSLANG_WEB
bool f16ShadowCompare = (*argp)[1]->getAsTyped()->getBasicType() == EbtFloat16 && arg0->getType().getSampler().shadow;
bool f16ShadowCompare = (*argp)[1]->getAsTyped()->getBasicType() == EbtFloat16 &&
arg0->getType().getSampler().shadow;
if (f16ShadowCompare)
++arg;
#endif
if (! (*argp)[arg]->getAsConstantUnion())
if (! (*argp)[arg]->getAsTyped()->getQualifier().isConstant())
error(loc, "argument must be compile-time constant", "texel offset", "");
else {
else if ((*argp)[arg]->getAsConstantUnion()) {
const TType& type = (*argp)[arg]->getAsTyped()->getType();
for (int c = 0; c < type.getVectorSize(); ++c) {
int offset = (*argp)[arg]->getAsConstantUnion()->getConstArray()[c].getIConst();
if (offset > resources.maxProgramTexelOffset || offset < resources.minProgramTexelOffset)
error(loc, "value is out of range:", "texel offset", "[gl_MinProgramTexelOffset, gl_MaxProgramTexelOffset]");
error(loc, "value is out of range:", "texel offset",
"[gl_MinProgramTexelOffset, gl_MaxProgramTexelOffset]");
}
}
}

View File

@ -598,6 +598,7 @@ INSTANTIATE_TEST_CASE_P(
"spv.glFragColor.frag",
"spv.rankShift.comp",
"spv.specConst.vert",
"spv.specTexture.frag",
"spv.OVR_multiview.vert",
"spv.xfbOffsetOnBlockMembersAssignment.vert",
"spv.xfbOffsetOnStructMembersAssignment.vert",