SPV: Scalar smear operation should use type of the scalar to make the

expected vector type when the provided vector type is incompatible with
the scalar.
This commit is contained in:
Rex Xu 2015-12-07 19:07:17 +08:00
parent e00e72ded1
commit e723b45bca
4 changed files with 90 additions and 0 deletions

View File

@ -1190,6 +1190,10 @@ Id Builder::smearScalar(Decoration /*precision*/, Id scalar, Id vectorType)
if (numComponents == 1)
return scalar;
// Make new vector type if the provided one is incompatible with type of the scalar
if (getTypeId(scalar) != getScalarTypeId(vectorType))
vectorType = makeVectorType(getTypeId(scalar), numComponents);
Instruction* smear = new Instruction(getUniqueId(), vectorType, OpCompositeConstruct);
for (int c = 0; c < numComponents; ++c)
smear->addIdOperand(scalar);

View File

@ -0,0 +1,66 @@
spv.shiftOps.frag
Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.
Linked fragment stage:
// Module Version 10000
// Generated by (magic number): 80001
// Id's are bound by 38
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 9 25
ExecutionMode 4 OriginLowerLeft
Source GLSL 450
Name 4 "main"
Name 9 "icolor"
Name 11 "i3"
Name 15 "u1"
Name 25 "ucolor"
Name 27 "u3"
Name 30 "i1"
2: TypeVoid
3: TypeFunction 2
6: TypeInt 32 1
7: TypeVector 6(int) 3
8: TypePointer Output 7(ivec3)
9(icolor): 8(ptr) Variable Output
10: TypePointer UniformConstant 7(ivec3)
11(i3): 10(ptr) Variable UniformConstant
13: TypeInt 32 0
14: TypePointer UniformConstant 13(int)
15(u1): 14(ptr) Variable UniformConstant
17: TypeVector 13(int) 3
20: 13(int) Constant 4
24: TypePointer Output 17(ivec3)
25(ucolor): 24(ptr) Variable Output
26: TypePointer UniformConstant 17(ivec3)
27(u3): 26(ptr) Variable UniformConstant
29: TypePointer UniformConstant 6(int)
30(i1): 29(ptr) Variable UniformConstant
34: 6(int) Constant 5
4(main): 2 Function None 3
5: Label
12: 7(ivec3) Load 11(i3)
16: 13(int) Load 15(u1)
18: 17(ivec3) CompositeConstruct 16 16 16
19: 7(ivec3) ShiftLeftLogical 12 18
Store 9(icolor) 19
21: 7(ivec3) Load 9(icolor)
22: 17(ivec3) CompositeConstruct 20 20 20
23: 7(ivec3) ShiftLeftLogical 21 22
Store 9(icolor) 23
28: 17(ivec3) Load 27(u3)
31: 6(int) Load 30(i1)
32: 7(ivec3) CompositeConstruct 31 31 31
33: 17(ivec3) ShiftRightLogical 28 32
Store 25(ucolor) 33
35: 17(ivec3) Load 25(ucolor)
36: 7(ivec3) CompositeConstruct 34 34 34
37: 17(ivec3) ShiftRightLogical 35 36
Store 25(ucolor) 37
Return
FunctionEnd

19
Test/spv.ShiftOps.frag Normal file
View File

@ -0,0 +1,19 @@
#version 450
uniform int i1;
uniform uint u1;
uniform ivec3 i3;
uniform uvec3 u3;
out ivec3 icolor;
out uvec3 ucolor;
void main()
{
icolor = i3 << u1;
icolor <<= 4u;
ucolor = u3 >> i1;
ucolor >>= 5;
}

View File

@ -61,6 +61,7 @@ spv.intOps.vert
spv.precision.frag
spv.prepost.frag
spv.qualifiers.vert
spv.shiftOps.frag
spv.simpleFunctionCall.frag
spv.simpleMat.vert
spv.structAssignment.frag