SPV: Continue to fix the issue of bool -> uint32

For short-circuit operator (&& and ||), the conversion is missing.
This commit is contained in:
Rex Xu 2016-03-03 14:38:51 +08:00
parent 2725323bba
commit b4fd8d10f0
3 changed files with 54 additions and 4 deletions

View File

@ -3876,7 +3876,7 @@ spv::Id TGlslangToSpvTraverser::createShortCircuit(glslang::TOperator op, glslan
// emit left operand // emit left operand
builder.clearAccessChain(); builder.clearAccessChain();
left.traverse(this); left.traverse(this);
spv::Id leftId = builder.accessChainLoad(spv::NoPrecision, boolTypeId); spv::Id leftId = accessChainLoad(left.getType());
// Operands to accumulate OpPhi operands // Operands to accumulate OpPhi operands
std::vector<spv::Id> phiOperands; std::vector<spv::Id> phiOperands;
@ -3899,7 +3899,7 @@ spv::Id TGlslangToSpvTraverser::createShortCircuit(glslang::TOperator op, glslan
// emit right operand as the "then" part of the "if" // emit right operand as the "then" part of the "if"
builder.clearAccessChain(); builder.clearAccessChain();
right.traverse(this); right.traverse(this);
spv::Id rightId = builder.accessChainLoad(spv::NoPrecision, boolTypeId); spv::Id rightId = accessChainLoad(right.getType());
// accumulate left operand's phi information // accumulate left operand's phi information
phiOperands.push_back(rightId); phiOperands.push_back(rightId);

View File

@ -7,12 +7,12 @@ Linked fragment stage:
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 72 // Id's are bound by 107
Capability Shader Capability Shader
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" EntryPoint Fragment 4 "main" 75
ExecutionMode 4 OriginUpperLeft ExecutionMode 4 OriginUpperLeft
Source GLSL 450 Source GLSL 450
Name 4 "main" Name 4 "main"
@ -28,6 +28,7 @@ Linked fragment stage:
Name 41 "" Name 41 ""
Name 62 "param" Name 62 "param"
Name 67 "param" Name 67 "param"
Name 75 "fragColor"
MemberDecorate 24(Buffer) 0 Offset 0 MemberDecorate 24(Buffer) 0 Offset 0
Decorate 24(Buffer) BufferBlock Decorate 24(Buffer) BufferBlock
Decorate 26 DescriptorSet 0 Decorate 26 DescriptorSet 0
@ -36,6 +37,7 @@ Linked fragment stage:
Decorate 39(Uniform) Block Decorate 39(Uniform) Block
Decorate 41 DescriptorSet 0 Decorate 41 DescriptorSet 0
Decorate 41 Binding 0 Decorate 41 Binding 0
Decorate 75(fragColor) Location 0
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
6: TypeBool 6: TypeBool
@ -65,6 +67,12 @@ Linked fragment stage:
41: 40(ptr) Variable Uniform 41: 40(ptr) Variable Uniform
42: TypePointer Uniform 38(ivec4) 42: TypePointer Uniform 38(ivec4)
65: 38(ivec4) ConstantComposite 31 31 31 31 65: 38(ivec4) ConstantComposite 31 31 31 31
72: TypeFloat 32
73: TypeVector 72(float) 4
74: TypePointer Output 73(fvec4)
75(fragColor): 74(ptr) Variable Output
87: 72(float) Constant 0
88: 72(float) Constant 1065353216
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
62(param): 8(ptr) Variable Function 62(param): 8(ptr) Variable Function
@ -107,6 +115,43 @@ Linked fragment stage:
Store 71 70 Store 71 70
Branch 61 Branch 61
61: Label 61: Label
76: 42(ptr) AccessChain 41 28
77: 38(ivec4) Load 76
78: 22(int) CompositeExtract 77 0
79: 6(bool) INotEqual 78 31
SelectionMerge 81 None
BranchConditional 79 80 81
80: Label
82: 42(ptr) AccessChain 41 28
83: 38(ivec4) Load 82
84: 22(int) CompositeExtract 83 1
85: 6(bool) INotEqual 84 31
Branch 81
81: Label
86: 6(bool) Phi 79 61 85 80
89: 72(float) Select 86 88 87
90: 73(fvec4) CompositeConstruct 89 89 89 89
Store 75(fragColor) 90
91: 42(ptr) AccessChain 41 28
92: 38(ivec4) Load 91
93: 22(int) CompositeExtract 92 0
94: 6(bool) INotEqual 93 31
95: 6(bool) LogicalNot 94
SelectionMerge 97 None
BranchConditional 95 96 97
96: Label
98: 42(ptr) AccessChain 41 28
99: 38(ivec4) Load 98
100: 22(int) CompositeExtract 99 1
101: 6(bool) INotEqual 100 31
Branch 97
97: Label
102: 6(bool) Phi 94 81 101 96
103: 72(float) Select 102 88 87
104: 73(fvec4) CompositeConstruct 103 103 103 103
105: 73(fvec4) Load 75(fragColor)
106: 73(fvec4) FSub 105 104
Store 75(fragColor) 106
Return Return
FunctionEnd FunctionEnd
14(foo(vb4;vb2;): 2 Function None 11 14(foo(vb4;vb2;): 2 Function None 11

View File

@ -16,6 +16,8 @@ void foo(bvec4 paramb4, out bvec2 paramb2)
paramb2 = bvec2(b1); paramb2 = bvec2(b1);
} }
layout(location = 0) out vec4 fragColor;
void main() void main()
{ {
b2 = bvec2(0.0); b2 = bvec2(0.0);
@ -23,4 +25,7 @@ void main()
b2 = bvec2(b4.x); b2 = bvec2(b4.x);
if (b2.x) if (b2.x)
foo(b4, b2); foo(b4, b2);
fragColor = vec4(b4.x && b4.y);
fragColor -= vec4(b4.x || b4.y);
} }