GLSL->SPIR-V: Put precision decorations on imageLoad().

This commit is contained in:
John Kessenich 2017-10-19 02:07:30 -06:00
parent f0e35bf0ef
commit fe4e572c53
3 changed files with 77 additions and 11 deletions

View File

@ -3281,7 +3281,9 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
operands.push_back(spv::ImageOperandsSampleMask);
operands.push_back(*(opIt++));
}
return builder.createOp(spv::OpImageRead, resultType(), operands);
spv::Id result = builder.createOp(spv::OpImageRead, resultType(), operands);
builder.setPrecision(result, precision);
return result;
}
operands.push_back(*(opIt++));
@ -3304,7 +3306,10 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
}
if (builder.getImageTypeFormat(builder.getImageType(operands.front())) == spv::ImageFormatUnknown)
builder.addCapability(spv::CapabilityStorageImageReadWithoutFormat);
return builder.createOp(spv::OpImageRead, resultType(), operands);
spv::Id result = builder.createOp(spv::OpImageRead, resultType(), operands);
builder.setPrecision(result, precision);
return result;
#ifdef AMD_EXTENSIONS
} else if (node->getOp() == glslang::EOpImageStore || node->getOp() == glslang::EOpImageStoreLod) {
#else

View File

@ -1,27 +1,50 @@
spv.precisionNonESSamp.frag
// Module Version 10000
// Generated by (magic number): 80002
// Id's are bound by 20
// Id's are bound by 47
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 9 17
EntryPoint Fragment 4 "main" 9 17 27 39
ExecutionMode 4 OriginUpperLeft
Source GLSL 450
Name 4 "main"
Name 9 "color"
Name 13 "s"
Name 17 "v"
Name 17 "v2"
Name 23 "t"
Name 27 "v3"
Name 31 "vi1"
Name 34 "i1"
Name 39 "iv2"
Name 42 "vi2"
Name 43 "i2"
Decorate 9(color) RelaxedPrecision
Decorate 9(color) Location 0
Decorate 13(s) RelaxedPrecision
Decorate 13(s) DescriptorSet 0
Decorate 14 RelaxedPrecision
Decorate 17(v) RelaxedPrecision
Decorate 17(v) Location 0
Decorate 17(v2) RelaxedPrecision
Decorate 17(v2) Location 0
Decorate 18 RelaxedPrecision
Decorate 19 RelaxedPrecision
Decorate 23(t) DescriptorSet 0
Decorate 27(v3) RelaxedPrecision
Decorate 27(v3) Location 1
Decorate 28 RelaxedPrecision
Decorate 31(vi1) RelaxedPrecision
Decorate 34(i1) RelaxedPrecision
Decorate 34(i1) DescriptorSet 0
Decorate 35 RelaxedPrecision
Decorate 39(iv2) RelaxedPrecision
Decorate 39(iv2) Flat
Decorate 39(iv2) Location 3
Decorate 40 RelaxedPrecision
Decorate 41 RelaxedPrecision
Decorate 42(vi2) RelaxedPrecision
Decorate 43(i2) DescriptorSet 0
Decorate 45 RelaxedPrecision
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
@ -34,12 +57,42 @@ spv.precisionNonESSamp.frag
13(s): 12(ptr) Variable UniformConstant
15: TypeVector 6(float) 2
16: TypePointer Input 15(fvec2)
17(v): 16(ptr) Variable Input
17(v2): 16(ptr) Variable Input
20: TypeImage 6(float) 3D sampled format:Unknown
21: TypeSampledImage 20
22: TypePointer UniformConstant 21
23(t): 22(ptr) Variable UniformConstant
25: TypeVector 6(float) 3
26: TypePointer Input 25(fvec3)
27(v3): 26(ptr) Variable Input
30: TypePointer Function 7(fvec4)
32: TypeImage 6(float) 2D nonsampled format:Rgba32f
33: TypePointer UniformConstant 32
34(i1): 33(ptr) Variable UniformConstant
36: TypeInt 32 1
37: TypeVector 36(int) 2
38: TypePointer Input 37(ivec2)
39(iv2): 38(ptr) Variable Input
43(i2): 33(ptr) Variable UniformConstant
4(main): 2 Function None 3
5: Label
31(vi1): 30(ptr) Variable Function
42(vi2): 30(ptr) Variable Function
14: 11 Load 13(s)
18: 15(fvec2) Load 17(v)
18: 15(fvec2) Load 17(v2)
19: 7(fvec4) ImageSampleImplicitLod 14 18
Store 9(color) 19
24: 21 Load 23(t)
28: 25(fvec3) Load 27(v3)
29: 7(fvec4) ImageSampleImplicitLod 24 28
Store 9(color) 29
35: 32 Load 34(i1)
40: 37(ivec2) Load 39(iv2)
41: 7(fvec4) ImageRead 35 40
Store 31(vi1) 41
44: 32 Load 43(i2)
45: 37(ivec2) Load 39(iv2)
46: 7(fvec4) ImageRead 44 45
Store 42(vi2) 46
Return
FunctionEnd

View File

@ -5,12 +5,20 @@ precision lowp int;
precision lowp float;
uniform lowp sampler2D s;
uniform highp sampler3D t;
layout(rgba32f) uniform lowp image2D i1;
layout(rgba32f) uniform highp image2D i2;
layout(location = 0) in lowp vec2 v;
layout(location = 0) in lowp vec2 v2;
layout(location = 1) in lowp vec3 v3;
layout(location = 3) flat in lowp ivec2 iv2;
layout(location = 0) out lowp vec4 color;
void main()
{
color = texture(s, v);
color = texture(s, v2);
color = texture(t, v3);
lowp vec4 vi1 = imageLoad(i1, iv2);
lowp vec4 vi2 = imageLoad(i2, iv2);
}