Unverified Commit 90ac5fcf by John Kessenich Committed by GitHub

Merge pull request #1253 from KhronosGroup/hlsl-ternary-select

HLSL: Fix #1249: Always execute both sides of ternary "?:".
parents a5cae082 4bee531f
......@@ -1973,18 +1973,29 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
// next layer copies r-values into memory to use the access-chain mechanism
bool TGlslangToSpvTraverser::visitSelection(glslang::TVisit /* visit */, glslang::TIntermSelection* node)
{
// See if it simple and safe to generate OpSelect instead of using control flow.
// Crucially, side effects must be avoided, and there are performance trade-offs.
// Return true if good idea (and safe) for OpSelect, false otherwise.
const auto selectPolicy = [&]() -> bool {
if ((!node->getType().isScalar() && !node->getType().isVector()) ||
node->getBasicType() == glslang::EbtVoid)
return false;
// See if it simple and safe, or required, to execute both sides.
// Crucially, side effects must be either semantically required or avoided,
// and there are performance trade-offs.
// Return true if required or a good idea (and safe) to execute both sides,
// false otherwise.
const auto bothSidesPolicy = [&]() -> bool {
// do we have both sides?
if (node->getTrueBlock() == nullptr ||
node->getFalseBlock() == nullptr)
return false;
// required? (unless we write additional code to look for side effects
// and make performance trade-offs if none are present)
if (!node->getShortCircuit())
return true;
// if not required to execute both, decide based on performance/practicality...
// see if OpSelect can handle it
if ((!node->getType().isScalar() && !node->getType().isVector()) ||
node->getBasicType() == glslang::EbtVoid)
return false;
assert(node->getType() == node->getTrueBlock() ->getAsTyped()->getType() &&
node->getType() == node->getFalseBlock()->getAsTyped()->getType());
......@@ -1997,10 +2008,14 @@ bool TGlslangToSpvTraverser::visitSelection(glslang::TVisit /* visit */, glslang
operandOkay(node->getFalseBlock()->getAsTyped());
};
// Emit OpSelect for this selection.
const auto handleAsOpSelect = [&]() {
node->getCondition()->traverse(this);
spv::Id condition = accessChainLoad(node->getCondition()->getType());
spv::Id result = spv::NoResult; // upcoming result selecting between trueValue and falseValue
// emit the condition before doing anything with selection
node->getCondition()->traverse(this);
spv::Id condition = accessChainLoad(node->getCondition()->getType());
// Find a way of executing both sides and selecting the right result.
const auto executeBothSides = [&]() -> void {
// execute both sides
node->getTrueBlock()->traverse(this);
spv::Id trueValue = accessChainLoad(node->getTrueBlock()->getAsTyped()->getType());
node->getFalseBlock()->traverse(this);
......@@ -2008,72 +2023,98 @@ bool TGlslangToSpvTraverser::visitSelection(glslang::TVisit /* visit */, glslang
builder.setLine(node->getLoc().line);
// smear condition to vector, if necessary (AST is always scalar)
if (builder.isVector(trueValue))
condition = builder.smearScalar(spv::NoPrecision, condition,
builder.makeVectorType(builder.makeBoolType(),
builder.getNumComponents(trueValue)));
// done if void
if (node->getBasicType() == glslang::EbtVoid)
return;
spv::Id select = builder.createTriOp(spv::OpSelect,
convertGlslangToSpvType(node->getType()), condition,
trueValue, falseValue);
builder.clearAccessChain();
builder.setAccessChainRValue(select);
};
// emit code to select between trueValue and falseValue
// Try for OpSelect
// see if OpSelect can handle it
if (node->getType().isScalar() || node->getType().isVector()) {
// Emit OpSelect for this selection.
if (selectPolicy()) {
SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
if (node->getType().getQualifier().isSpecConstant())
spec_constant_op_mode_setter.turnOnSpecConstantOpMode();
// smear condition to vector, if necessary (AST is always scalar)
if (builder.isVector(trueValue))
condition = builder.smearScalar(spv::NoPrecision, condition,
builder.makeVectorType(builder.makeBoolType(),
builder.getNumComponents(trueValue)));
handleAsOpSelect();
return false;
}
// OpSelect
result = builder.createTriOp(spv::OpSelect,
convertGlslangToSpvType(node->getType()), condition,
trueValue, falseValue);
// Instead, emit control flow...
// Don't handle results as temporaries, because there will be two names
// and better to leave SSA to later passes.
spv::Id result = (node->getBasicType() == glslang::EbtVoid)
? spv::NoResult
: builder.createVariable(spv::StorageClassFunction, convertGlslangToSpvType(node->getType()));
builder.clearAccessChain();
builder.setAccessChainRValue(result);
} else {
// We need control flow to select the result.
// TODO: Once SPIR-V OpSelect allows arbitrary types, eliminate this path.
result = builder.createVariable(spv::StorageClassFunction, convertGlslangToSpvType(node->getType()));
// emit the condition before doing anything with selection
node->getCondition()->traverse(this);
// Selection control:
const spv::SelectionControlMask control = TranslateSelectionControl(*node);
// Selection control:
const spv::SelectionControlMask control = TranslateSelectionControl(*node);
// make an "if" based on the value created by the condition
spv::Builder::If ifBuilder(condition, control, builder);
// make an "if" based on the value created by the condition
spv::Builder::If ifBuilder(accessChainLoad(node->getCondition()->getType()), control, builder);
// emit the "then" statement
builder.createStore(trueValue, result);
ifBuilder.makeBeginElse();
// emit the "else" statement
builder.createStore(falseValue, result);
// emit the "then" statement
if (node->getTrueBlock() != nullptr) {
node->getTrueBlock()->traverse(this);
if (result != spv::NoResult)
builder.createStore(accessChainLoad(node->getTrueBlock()->getAsTyped()->getType()), result);
}
// finish off the control flow
ifBuilder.makeEndIf();
if (node->getFalseBlock() != nullptr) {
ifBuilder.makeBeginElse();
// emit the "else" statement
node->getFalseBlock()->traverse(this);
if (result != spv::NoResult)
builder.createStore(accessChainLoad(node->getFalseBlock()->getAsTyped()->getType()), result);
}
builder.clearAccessChain();
builder.setAccessChainLValue(result);
}
};
// finish off the control flow
ifBuilder.makeEndIf();
// Execute the one side needed, as per the condition
const auto executeOneSide = [&]() {
// Always emit control flow.
if (node->getBasicType() != glslang::EbtVoid)
result = builder.createVariable(spv::StorageClassFunction, convertGlslangToSpvType(node->getType()));
if (result != spv::NoResult) {
// GLSL only has r-values as the result of a :?, but
// if we have an l-value, that can be more efficient if it will
// become the base of a complex r-value expression, because the
// next layer copies r-values into memory to use the access-chain mechanism
builder.clearAccessChain();
builder.setAccessChainLValue(result);
}
// Selection control:
const spv::SelectionControlMask control = TranslateSelectionControl(*node);
// make an "if" based on the value created by the condition
spv::Builder::If ifBuilder(condition, control, builder);
// emit the "then" statement
if (node->getTrueBlock() != nullptr) {
node->getTrueBlock()->traverse(this);
if (result != spv::NoResult)
builder.createStore(accessChainLoad(node->getTrueBlock()->getAsTyped()->getType()), result);
}
if (node->getFalseBlock() != nullptr) {
ifBuilder.makeBeginElse();
// emit the "else" statement
node->getFalseBlock()->traverse(this);
if (result != spv::NoResult)
builder.createStore(accessChainLoad(node->getFalseBlock()->getAsTyped()->getType()), result);
}
// finish off the control flow
ifBuilder.makeEndIf();
if (result != spv::NoResult) {
builder.clearAccessChain();
builder.setAccessChainLValue(result);
}
};
// Try for OpSelect (or a requirement to execute both sides)
if (bothSidesPolicy()) {
SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
if (node->getType().getQualifier().isSpecConstant())
spec_constant_op_mode_setter.turnOnSpecConstantOpMode();
executeBothSides();
} else
executeOneSide();
return false;
}
......
......@@ -133,7 +133,7 @@ gl_FragCoord origin is upper left
0:28 Sequence
0:28 move second child to first child ( temp float)
0:28 'g' ( temp float)
0:28 Test condition and select ( temp float)
0:28 Test condition and select ( temp float): no shortcircuit
0:28 Condition
0:28 Convert float to bool ( temp bool)
0:28 condf: direct index for structure ( uniform float)
......@@ -302,7 +302,7 @@ gl_FragCoord origin is upper left
0:28 Sequence
0:28 move second child to first child ( temp float)
0:28 'g' ( temp float)
0:28 Test condition and select ( temp float)
0:28 Test condition and select ( temp float): no shortcircuit
0:28 Condition
0:28 Convert float to bool ( temp bool)
0:28 condf: direct index for structure ( uniform float)
......
......@@ -18,7 +18,7 @@ gl_FragCoord origin is upper left
0:3 'n_dot_l' ( in float)
0:3 Constant:
0:3 0.000000
0:3 Test condition and select ( temp float)
0:3 Test condition and select ( temp float): no shortcircuit
0:3 Condition
0:3 Compare Less Than ( temp bool)
0:3 min ( temp float)
......@@ -79,7 +79,7 @@ gl_FragCoord origin is upper left
0:3 'n_dot_l' ( in float)
0:3 Constant:
0:3 0.000000
0:3 Test condition and select ( temp float)
0:3 Test condition and select ( temp float): no shortcircuit
0:3 Condition
0:3 Compare Less Than ( temp bool)
0:3 min ( temp float)
......@@ -119,12 +119,12 @@ gl_FragCoord origin is upper left
// Module Version 10000
// Generated by (magic number): 80004
// Id's are bound by 52
// Id's are bound by 48
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "PixelShaderFunction" 37 40 43
EntryPoint Fragment 4 "PixelShaderFunction" 33 36 39
ExecutionMode 4 OriginUpperLeft
Source HLSL 500
Name 4 "PixelShaderFunction"
......@@ -133,18 +133,18 @@ gl_FragCoord origin is upper left
Name 10 "n_dot_h"
Name 11 "m"
Name 16 "r0"
Name 35 "n_dot_l"
Name 37 "n_dot_l"
Name 39 "n_dot_h"
Name 40 "n_dot_h"
Name 42 "m"
Name 43 "m"
Name 31 "n_dot_l"
Name 33 "n_dot_l"
Name 35 "n_dot_h"
Name 36 "n_dot_h"
Name 38 "m"
Name 39 "m"
Name 41 "param"
Name 43 "param"
Name 45 "param"
Name 47 "param"
Name 49 "param"
Decorate 37(n_dot_l) Location 0
Decorate 40(n_dot_h) Location 1
Decorate 43(m) Location 2
Decorate 33(n_dot_l) Location 0
Decorate 36(n_dot_h) Location 1
Decorate 39(m) Location 2
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
......@@ -154,32 +154,32 @@ gl_FragCoord origin is upper left
15: TypePointer Function 14(fvec4)
17: 6(float) Constant 1065353216
19: 6(float) Constant 0
25: TypeBool
36: TypePointer Input 6(float)
37(n_dot_l): 36(ptr) Variable Input
40(n_dot_h): 36(ptr) Variable Input
43(m): 36(ptr) Variable Input
24: TypeBool
32: TypePointer Input 6(float)
33(n_dot_l): 32(ptr) Variable Input
36(n_dot_h): 32(ptr) Variable Input
39(m): 32(ptr) Variable Input
4(PixelShaderFunction): 2 Function None 3
5: Label
35(n_dot_l): 7(ptr) Variable Function
39(n_dot_h): 7(ptr) Variable Function
42(m): 7(ptr) Variable Function
31(n_dot_l): 7(ptr) Variable Function
35(n_dot_h): 7(ptr) Variable Function
38(m): 7(ptr) Variable Function
41(param): 7(ptr) Variable Function
43(param): 7(ptr) Variable Function
45(param): 7(ptr) Variable Function
47(param): 7(ptr) Variable Function
49(param): 7(ptr) Variable Function
38: 6(float) Load 37(n_dot_l)
Store 35(n_dot_l) 38
41: 6(float) Load 40(n_dot_h)
Store 39(n_dot_h) 41
44: 6(float) Load 43(m)
Store 42(m) 44
46: 6(float) Load 35(n_dot_l)
34: 6(float) Load 33(n_dot_l)
Store 31(n_dot_l) 34
37: 6(float) Load 36(n_dot_h)
Store 35(n_dot_h) 37
40: 6(float) Load 39(m)
Store 38(m) 40
42: 6(float) Load 31(n_dot_l)
Store 41(param) 42
44: 6(float) Load 35(n_dot_h)
Store 43(param) 44
46: 6(float) Load 38(m)
Store 45(param) 46
48: 6(float) Load 39(n_dot_h)
Store 47(param) 48
50: 6(float) Load 42(m)
Store 49(param) 50
51: 2 FunctionCall 12(@PixelShaderFunction(f1;f1;f1;) 45(param) 47(param) 49(param)
47: 2 FunctionCall 12(@PixelShaderFunction(f1;f1;f1;) 41(param) 43(param) 45(param)
Return
FunctionEnd
12(@PixelShaderFunction(f1;f1;f1;): 2 Function None 8
......@@ -188,27 +188,17 @@ gl_FragCoord origin is upper left
11(m): 7(ptr) FunctionParameter
13: Label
16(r0): 15(ptr) Variable Function
21: 7(ptr) Variable Function
18: 6(float) Load 9(n_dot_l)
20: 6(float) ExtInst 1(GLSL.std.450) 40(FMax) 18 19
22: 6(float) Load 9(n_dot_l)
23: 6(float) Load 10(n_dot_h)
24: 6(float) ExtInst 1(GLSL.std.450) 37(FMin) 22 23
26: 25(bool) FOrdLessThan 24 19
SelectionMerge 28 None
BranchConditional 26 27 29
27: Label
Store 21 19
Branch 28
29: Label
30: 6(float) Load 10(n_dot_h)
31: 6(float) Load 11(m)
32: 6(float) FMul 30 31
Store 21 32
Branch 28
28: Label
33: 6(float) Load 21
34: 14(fvec4) CompositeConstruct 17 20 33 17
Store 16(r0) 34
21: 6(float) Load 9(n_dot_l)
22: 6(float) Load 10(n_dot_h)
23: 6(float) ExtInst 1(GLSL.std.450) 37(FMin) 21 22
25: 24(bool) FOrdLessThan 23 19
26: 6(float) Load 10(n_dot_h)
27: 6(float) Load 11(m)
28: 6(float) FMul 26 27
29: 6(float) Select 25 19 28
30: 14(fvec4) CompositeConstruct 17 20 29 17
Store 16(r0) 30
Return
FunctionEnd
......@@ -86,7 +86,7 @@ gl_FragCoord origin is upper left
0:25 'uint' ( temp mediump uint)
0:25 'min16float' ( temp mediump float)
0:25 'min10float' ( temp mediump float)
0:25 Test condition and select ( temp mediump float)
0:25 Test condition and select ( temp mediump float): no shortcircuit
0:25 Condition
0:25 direct index ( temp bool)
0:25 'bool' ( temp 2-element array of bool)
......@@ -221,7 +221,7 @@ gl_FragCoord origin is upper left
0:25 'uint' ( temp mediump uint)
0:25 'min16float' ( temp mediump float)
0:25 'min10float' ( temp mediump float)
0:25 Test condition and select ( temp mediump float)
0:25 Test condition and select ( temp mediump float): no shortcircuit
0:25 Condition
0:25 direct index ( temp bool)
0:25 'bool' ( temp 2-element array of bool)
......@@ -267,12 +267,12 @@ gl_FragCoord origin is upper left
// Module Version 10000
// Generated by (magic number): 80004
// Id's are bound by 109
// Id's are bound by 105
Capability Shader
1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450
EntryPoint Fragment 4 "main" 107
EntryPoint Fragment 4 "main" 103
ExecutionMode 4 OriginUpperLeft
Source HLSL 500
Name 4 "main"
......@@ -289,9 +289,9 @@ gl_FragCoord origin is upper left
Name 56 "foo_t"
MemberName 56(foo_t) 0 "float"
Name 58 "float"
Name 86 "param"
Name 93 "half2x3"
Name 107 "@entryPointOutput"
Name 82 "param"
Name 89 "half2x3"
Name 103 "@entryPointOutput"
Decorate 49(min16float) RelaxedPrecision
Decorate 50 RelaxedPrecision
Decorate 51 RelaxedPrecision
......@@ -308,15 +308,14 @@ gl_FragCoord origin is upper left
Decorate 72 RelaxedPrecision
Decorate 73 RelaxedPrecision
Decorate 74 RelaxedPrecision
Decorate 80 RelaxedPrecision
Decorate 77 RelaxedPrecision
Decorate 78 RelaxedPrecision
Decorate 79 RelaxedPrecision
Decorate 81 RelaxedPrecision
Decorate 83 RelaxedPrecision
Decorate 84 RelaxedPrecision
Decorate 85 RelaxedPrecision
Decorate 87 RelaxedPrecision
Decorate 88 RelaxedPrecision
Decorate 89 RelaxedPrecision
Decorate 107(@entryPointOutput) Location 0
Decorate 103(@entryPointOutput) Location 0
2: TypeVoid
3: TypeFunction 2
6: TypeFloat 32
......@@ -341,16 +340,16 @@ gl_FragCoord origin is upper left
56(foo_t): TypeStruct 6(float)
57: TypePointer Function 56(foo_t)
59: 6(float) Constant 1109917696
90: TypeVector 6(float) 3
91: TypeMatrix 90(fvec3) 2
92: TypePointer Function 91
97: 22(int) Constant 0
106: TypePointer Output 12(fvec4)
107(@entryPointOutput): 106(ptr) Variable Output
86: TypeVector 6(float) 3
87: TypeMatrix 86(fvec3) 2
88: TypePointer Function 87
93: 22(int) Constant 0
102: TypePointer Output 12(fvec4)
103(@entryPointOutput): 102(ptr) Variable Output
4(main): 2 Function None 3
5: Label
108: 12(fvec4) FunctionCall 14(@main()
Store 107(@entryPointOutput) 108
104: 12(fvec4) FunctionCall 14(@main()
Store 103(@entryPointOutput) 104
Return
FunctionEnd
10(fn(f1;): 6(float) Function None 8
......@@ -369,9 +368,8 @@ gl_FragCoord origin is upper left
52(min10float): 7(ptr) Variable Function
54(half): 7(ptr) Variable Function
58(float): 57(ptr) Variable Function
75: 7(ptr) Variable Function
86(param): 7(ptr) Variable Function
93(half2x3): 92(ptr) Variable Function
82(param): 7(ptr) Variable Function
89(half2x3): 88(ptr) Variable Function
Store 19(float) 20
27: 6(float) Load 19(float)
29: 21(bool) FOrdNotEqual 27 28
......@@ -412,36 +410,27 @@ gl_FragCoord origin is upper left
72: 6(float) FAdd 70 71
73: 6(float) Load 52(min10float)
74: 6(float) FAdd 72 73
76: 37(ptr) AccessChain 26(bool) 40
77: 21(bool) Load 76
SelectionMerge 79 None
BranchConditional 77 78 82
78: Label
80: 33(int) Load 35(int)
81: 6(float) ConvertSToF 80
Store 75 81
Branch 79
82: Label
83: 6(float) Load 19(float)
Store 75 83
Branch 79
79: Label
84: 6(float) Load 75
85: 6(float) FAdd 74 84
87: 6(float) Load 19(float)
Store 86(param) 87
88: 6(float) FunctionCall 10(fn(f1;) 86(param)
89: 6(float) FAdd 85 88
Store 19(float) 89
94: 6(float) Load 19(float)
75: 37(ptr) AccessChain 26(bool) 40
76: 21(bool) Load 75
77: 33(int) Load 35(int)
78: 6(float) ConvertSToF 77
79: 6(float) Load 19(float)
80: 6(float) Select 76 78 79
81: 6(float) FAdd 74 80
83: 6(float) Load 19(float)
Store 82(param) 83
84: 6(float) FunctionCall 10(fn(f1;) 82(param)
85: 6(float) FAdd 81 84
Store 19(float) 85
90: 6(float) Load 19(float)
91: 6(float) Load 19(float)
92: 6(float) FMul 90 91
94: 7(ptr) AccessChain 89(half2x3) 40 93
Store 94 92
95: 6(float) Load 19(float)
96: 6(float) FMul 94 95
98: 7(ptr) AccessChain 93(half2x3) 40 97
Store 98 96
99: 6(float) Load 19(float)
100: 7(ptr) AccessChain 93(half2x3) 40 97
101: 6(float) Load 100
102: 6(float) FAdd 99 101
103: 12(fvec4) CompositeConstruct 102 102 102 102
ReturnValue 103
96: 7(ptr) AccessChain 89(half2x3) 40 93
97: 6(float) Load 96
98: 6(float) FAdd 95 97
99: 12(fvec4) CompositeConstruct 98 98 98 98
ReturnValue 99
FunctionEnd
......@@ -273,10 +273,10 @@ spv.400.frag
439(bvec2v): 438(ptr) Variable Function
448(bvec3v): 447(ptr) Variable Function
457(bvec4v): 456(ptr) Variable Function
556: 429(ptr) Variable Function
565: 438(ptr) Variable Function
574: 447(ptr) Variable Function
583: 456(ptr) Variable Function
557: 429(ptr) Variable Function
566: 438(ptr) Variable Function
575: 447(ptr) Variable Function
584: 456(ptr) Variable Function
739(dmat2v): 738(ptr) Variable Function
745(dmat3v): 744(ptr) Variable Function
751(dmat4v): 750(ptr) Variable Function
......@@ -875,61 +875,61 @@ spv.400.frag
554: 53(fvec4) Load 55(dvec4v)
555: 455(bvec4) IsNan 554
Store 457(bvec4v) 555
557: 428(bool) Load 430(boolv)
556: 428(bool) Load 430(boolv)
SelectionMerge 559 None
BranchConditional 557 558 562
BranchConditional 556 558 562
558: Label
560: 39(float) Load 41(doublev)
561: 428(bool) IsInf 560
Store 556 561
Store 557 561
Branch 559
562: Label
Store 556 563
Store 557 563
Branch 559
559: Label
564: 428(bool) Load 556
564: 428(bool) Load 557
Store 430(boolv) 564
566: 428(bool) Load 430(boolv)
565: 428(bool) Load 430(boolv)
SelectionMerge 568 None
BranchConditional 566 567 571
BranchConditional 565 567 571
567: Label
569: 43(fvec2) Load 45(dvec2v)
570: 437(bvec2) IsInf 569
Store 565 570
Store 566 570
Branch 568
571: Label
Store 565 572
Store 566 572
Branch 568
568: Label
573: 437(bvec2) Load 565
573: 437(bvec2) Load 566
Store 439(bvec2v) 573
575: 428(bool) Load 430(boolv)
574: 428(bool) Load 430(boolv)
SelectionMerge 577 None
BranchConditional 575 576 580
BranchConditional 574 576 580
576: Label
578: 48(fvec3) Load 50(dvec3v)
579: 446(bvec3) IsInf 578
Store 574 579
Store 575 579
Branch 577
580: Label
Store 574 581
Store 575 581
Branch 577
577: Label
582: 446(bvec3) Load 574
582: 446(bvec3) Load 575
Store 448(bvec3v) 582
584: 428(bool) Load 430(boolv)
583: 428(bool) Load 430(boolv)
SelectionMerge 586 None
BranchConditional 584 585 589
BranchConditional 583 585 589
585: Label
587: 53(fvec4) Load 55(dvec4v)
588: 455(bvec4) IsInf 587
Store 583 588
Store 584 588
Branch 586
589: Label
Store 583 590
Store 584 590
Branch 586
586: Label
591: 455(bvec4) Load 583
591: 455(bvec4) Load 584
Store 457(bvec4v) 591
592: 39(float) Load 41(doublev)
593: 39(float) ExtInst 1(GLSL.std.450) 66(Length) 592
......
......@@ -90,10 +90,10 @@ spv.Operations.frag
188(f): 143(ptr) Variable Function
285(u): 284(ptr) Variable Function
305(b): 304(ptr) Variable Function
486: 8(ptr) Variable Function
487: 8(ptr) Variable Function
503(m1): 502(ptr) Variable Function
510(m2): 502(ptr) Variable Function
513: 502(ptr) Variable Function
514: 502(ptr) Variable Function
12: 7(fvec4) Load 11(uv4)
13: 7(fvec4) ExtInst 1(GLSL.std.450) 11(Radians) 12
Store 9(v) 13
......@@ -658,9 +658,9 @@ spv.Operations.frag
482: 178(bool) Load 305(b)
483: 178(bool) LogicalNot 482
Store 305(b) 483
487: 178(bool) Load 305(b)
486: 178(bool) Load 305(b)
SelectionMerge 489 None
BranchConditional 487 488 498
BranchConditional 486 488 498
488: Label
490: 18(int) Load 20(i)
491: 6(float) ConvertSToF 490
......@@ -670,30 +670,30 @@ spv.Operations.frag
495: 7(fvec4) FAdd 492 494
496: 7(fvec4) Load 9(v)
497: 7(fvec4) FAdd 495 496
Store 486 497
Store 487 497
Branch 489
498: Label
499: 7(fvec4) Load 9(v)
Store 486 499
Store 487 499
Branch 489
489: Label
500: 7(fvec4) Load 486
500: 7(fvec4) Load 487
Store 485(FragColor) 500
Store 503(m1) 509
Store 510(m2) 512
514: 178(bool) Load 305(b)
513: 178(bool) Load 305(b)
SelectionMerge 516 None
BranchConditional 514 515 518
BranchConditional 513 515 518
515: Label
517: 501 Load 503(m1)
Store 513 517
Store 514 517
Branch 516
518: Label
519: 501 Load 510(m2)
Store 513 519
Store 514 519
Branch 516
516: Label
520: 8(ptr) AccessChain 513 405
520: 8(ptr) AccessChain 514 405
521: 7(fvec4) Load 520
522: 7(fvec4) Load 485(FragColor)
523: 7(fvec4) FAdd 522 521
......
......@@ -86,8 +86,8 @@ spv.bitCast.frag
148(u4): 147(ptr) Variable Input
153: TypePointer Output 46(fvec4)
154(fragColor): 153(ptr) Variable Output
159: TypeBool
160: TypeVector 159(bool) 4
158: TypeBool
159: TypeVector 158(bool) 4
168: 12(float) Constant 1045220557
169: 46(fvec4) ConstantComposite 168 168 168 168
4(main): 2 Function None 3
......@@ -95,7 +95,7 @@ spv.bitCast.frag
9(idata): 8(ptr) Variable Function
55(udata): 54(ptr) Variable Function
85(fdata): 84(ptr) Variable Function
155: 84(ptr) Variable Function
162: 84(ptr) Variable Function
Store 9(idata) 11
15: 12(float) Load 14(f1)
16: 6(int) Bitcast 15
......@@ -211,24 +211,24 @@ spv.bitCast.frag
151: 46(fvec4) Load 85(fdata)
152: 46(fvec4) FAdd 151 150
Store 85(fdata) 152
156: 7(ivec4) Load 9(idata)
157: 53(ivec4) Bitcast 156
158: 53(ivec4) Load 55(udata)
161: 160(bvec4) IEqual 157 158
162: 159(bool) All 161
155: 7(ivec4) Load 9(idata)
156: 53(ivec4) Bitcast 155
157: 53(ivec4) Load 55(udata)
160: 159(bvec4) IEqual 156 157
161: 158(bool) All 160
SelectionMerge 164 None
BranchConditional 162 163 166
BranchConditional 161 163 166
163: Label
165: 46(fvec4) Load 85(fdata)
Store 155 165
Store 162 165
Branch 164
166: Label
167: 46(fvec4) Load 85(fdata)
170: 46(fvec4) FAdd 167 169
Store 155 170
Store 162 170
Branch 164
164: Label
171: 46(fvec4) Load 155
171: 46(fvec4) Load 162
Store 154(fragColor) 171
Return
FunctionEnd
......@@ -119,8 +119,8 @@ spv.conversion.frag
315: 13(int) Constant 1
321: TypePointer Output 95(fvec4)
322(gl_FragColor): 321(ptr) Variable Output
337: 13(int) Constant 2
350: 13(int) Constant 3
336: 13(int) Constant 2
349: 13(int) Constant 3
427: TypePointer Private 6(bool)
428(u_b): 427(ptr) Variable Private
429: TypePointer Private 23(bvec2)
......@@ -163,9 +163,9 @@ spv.conversion.frag
110(f2): 109(ptr) Variable Function
114(f3): 113(ptr) Variable Function
118(f4): 117(ptr) Variable Function
297: 105(ptr) Variable Function
307: 105(ptr) Variable Function
323: 117(ptr) Variable Function
298: 105(ptr) Variable Function
309: 105(ptr) Variable Function
353: 117(ptr) Variable Function
417(cv2): 93(ptr) Variable Function
418(cv5): 44(ptr) Variable Function
12: 9(int) Load 11(u_i)
......@@ -425,72 +425,72 @@ spv.conversion.frag
SelectionMerge 296 None
BranchConditional 294 295 296
295: Label
298: 6(bool) Load 8(b)
297: 6(bool) Load 8(b)
SelectionMerge 300 None
BranchConditional 298 299 303
BranchConditional 297 299 303
299: Label
301: 9(int) Load 58(i)
302: 16(float) ConvertSToF 301
Store 297 302
Store 298 302
Branch 300
303: Label
304: 105(ptr) AccessChain 110(f2) 14
305: 16(float) Load 304
Store 297 305
Store 298 305
Branch 300
300: Label
306: 16(float) Load 297
308: 7(ptr) AccessChain 25(b2) 14
309: 6(bool) Load 308
306: 16(float) Load 298
307: 7(ptr) AccessChain 25(b2) 14
308: 6(bool) Load 307
SelectionMerge 311 None
BranchConditional 309 310 314
BranchConditional 308 310 314
310: Label
312: 105(ptr) AccessChain 114(f3) 14
313: 16(float) Load 312
Store 307 313
Store 309 313
Branch 311
314: Label
316: 57(ptr) AccessChain 68(i2) 315
317: 9(int) Load 316
318: 16(float) ConvertSToF 317
Store 307 318
Store 309 318
Branch 311
311: Label
319: 16(float) Load 307
319: 16(float) Load 309
320: 16(float) FAdd 306 319
Store 106(f) 320
Branch 296
296: Label
324: 6(bool) Load 8(b)
325: 7(ptr) AccessChain 25(b2) 14
326: 6(bool) Load 325
327: 6(bool) LogicalOr 324 326
328: 7(ptr) AccessChain 25(b2) 315
329: 6(bool) Load 328
330: 6(bool) LogicalOr 327 329
331: 7(ptr) AccessChain 33(b3) 14
332: 6(bool) Load 331
333: 6(bool) LogicalOr 330 332
334: 7(ptr) AccessChain 33(b3) 315
335: 6(bool) Load 334
336: 6(bool) LogicalOr 333 335
338: 7(ptr) AccessChain 33(b3) 337
339: 6(bool) Load 338
340: 6(bool) LogicalOr 336 339
341: 7(ptr) AccessChain 45(b4) 14
342: 6(bool) Load 341
343: 6(bool) LogicalOr 340 342
344: 7(ptr) AccessChain 45(b4) 315
345: 6(bool) Load 344
346: 6(bool) LogicalOr 343 345
347: 7(ptr) AccessChain 45(b4) 337
348: 6(bool) Load 347
349: 6(bool) LogicalOr 346 348
351: 7(ptr) AccessChain 45(b4) 350
352: 6(bool) Load 351
353: 6(bool) LogicalOr 349 352
323: 6(bool) Load 8(b)
324: 7(ptr) AccessChain 25(b2) 14
325: 6(bool) Load 324
326: 6(bool) LogicalOr 323 325
327: 7(ptr) AccessChain 25(b2) 315
328: 6(bool) Load 327
329: 6(bool) LogicalOr 326 328
330: 7(ptr) AccessChain 33(b3) 14
331: 6(bool) Load 330
332: 6(bool) LogicalOr 329 331
333: 7(ptr) AccessChain 33(b3) 315
334: 6(bool) Load 333
335: 6(bool) LogicalOr 332 334
337: 7(ptr) AccessChain 33(b3) 336
338: 6(bool) Load 337
339: 6(bool) LogicalOr 335 338
340: 7(ptr) AccessChain 45(b4) 14
341: 6(bool) Load 340
342: 6(bool) LogicalOr 339 341
343: 7(ptr) AccessChain 45(b4) 315
344: 6(bool) Load 343
345: 6(bool) LogicalOr 342 344
346: 7(ptr) AccessChain 45(b4) 336
347: 6(bool) Load 346
348: 6(bool) LogicalOr 345 347
350: 7(ptr) AccessChain 45(b4) 349
351: 6(bool) Load 350
352: 6(bool) LogicalOr 348 351
SelectionMerge 355 None
BranchConditional 353 354 415
BranchConditional 352 354 415
354: Label
356: 9(int) Load 58(i)
357: 57(ptr) AccessChain 68(i2) 14
......@@ -505,7 +505,7 @@ spv.conversion.frag
366: 57(ptr) AccessChain 81(i3) 315
367: 9(int) Load 366
368: 9(int) IAdd 365 367
369: 57(ptr) AccessChain 81(i3) 337
369: 57(ptr) AccessChain 81(i3) 336
370: 9(int) Load 369
371: 9(int) IAdd 368 370
372: 57(ptr) AccessChain 94(i4) 14
......@@ -514,10 +514,10 @@ spv.conversion.frag
375: 57(ptr) AccessChain 94(i4) 315
376: 9(int) Load 375
377: 9(int) IAdd 374 376
378: 57(ptr) AccessChain 94(i4) 337
378: 57(ptr) AccessChain 94(i4) 336
379: 9(int) Load 378
380: 9(int) IAdd 377 379
381: 57(ptr) AccessChain 94(i4) 350
381: 57(ptr) AccessChain 94(i4) 349
382: 9(int) Load 381
383: 9(int) IAdd 380 382
384: 16(float) ConvertSToF 383
......@@ -535,7 +535,7 @@ spv.conversion.frag
396: 105(ptr) AccessChain 114(f3) 315
397: 16(float) Load 396
398: 16(float) FAdd 395 397
399: 105(ptr) AccessChain 114(f3) 337
399: 105(ptr) AccessChain 114(f3) 336
400: 16(float) Load 399
401: 16(float) FAdd 398 400
402: 105(ptr) AccessChain 118(f4) 14
......@@ -544,20 +544,20 @@ spv.conversion.frag
405: 105(ptr) AccessChain 118(f4) 315
406: 16(float) Load 405
407: 16(float) FAdd 404 406
408: 105(ptr) AccessChain 118(f4) 337
408: 105(ptr) AccessChain 118(f4) 336
409: 16(float) Load 408
410: 16(float) FAdd 407 409
411: 105(ptr) AccessChain 118(f4) 350
411: 105(ptr) AccessChain 118(f4) 349
412: 16(float) Load 411
413: 16(float) FAdd 410 412
414: 95(fvec4) CompositeConstruct 413 413 413 413
Store 323 414
Store 353 414
Branch 355
415: Label
Store 323 151
Store 353 151
Branch 355
355: Label
416: 95(fvec4) Load 323
416: 95(fvec4) Load 353
Store 322(gl_FragColor) 416
Store 417(cv2) 102
419: 92(ivec4) Load 417(cv2)
......
......@@ -135,13 +135,13 @@ void main()
77: TypePointer Uniform 7(int)
106: 7(int) Constant 10
111: 7(int) Constant 1
114: TypePointer Output 10(float)
117: 10(float) Constant 1092616192
113: TypePointer Output 10(float)
116: 10(float) Constant 1092616192
5(main): 3 Function None 4
6: Label
59(param): 58(ptr) Variable Function
99(i): 19(ptr) Variable Function
113: 16(ptr) Variable Function
118: 16(ptr) Variable Function
Line 1 30 0
61: 60(ptr) AccessChain 56 18
62: 53(S) Load 61
......@@ -216,24 +216,24 @@ void main()
Branch 100
102: Label
Line 1 49 0
115: 114(ptr) AccessChain 52(outv) 32
116: 10(float) Load 115
118: 37(bool) FOrdLessThan 116 117
114: 113(ptr) AccessChain 52(outv) 32
115: 10(float) Load 114
117: 37(bool) FOrdLessThan 115 116
SelectionMerge 120 None
BranchConditional 118 119 123
BranchConditional 117 119 123
119: Label
Line 1 50 0
121: 11(fvec4) Load 52(outv)
122: 11(fvec4) ExtInst 2(GLSL.std.450) 13(Sin) 121
Store 52(outv) 122
Store 113 122
Store 118 122
Branch 120
123: Label
Line 1 51 0
124: 11(fvec4) Load 52(outv)
125: 11(fvec4) ExtInst 2(GLSL.std.450) 14(Cos) 124
Store 52(outv) 125
Store 113 125
Store 118 125
Branch 120
120: Label
Return
......
......@@ -182,14 +182,14 @@ spv.sparseTexture.frag
414(i2DMS): 413(ptr) Variable UniformConstant
422: TypePointer Output 11(fvec4)
423(outColor): 422(ptr) Variable Output
426: TypeBool
425: TypeBool
4(main): 2 Function None 3
5: Label
8(resident): 7(ptr) Variable Function
13(texel): 12(ptr) Variable Function
18(itexel): 17(ptr) Variable Function
23(utexel): 22(ptr) Variable Function
424: 12(ptr) Variable Function
427: 12(ptr) Variable Function
Store 8(resident) 9
Store 13(texel) 15
Store 18(itexel) 19
......@@ -565,13 +565,13 @@ spv.sparseTexture.frag
420: 6(int) Load 8(resident)
421: 6(int) BitwiseOr 420 419
Store 8(resident) 421
425: 6(int) Load 8(resident)
427: 426(bool) ImageSparseTexelsResident 425
424: 6(int) Load 8(resident)
426: 425(bool) ImageSparseTexelsResident 424
SelectionMerge 429 None
BranchConditional 427 428 431
BranchConditional 426 428 431
428: Label
430: 11(fvec4) Load 13(texel)
Store 424 430
Store 427 430
Branch 429
431: Label
432: 16(ivec4) Load 18(itexel)
......@@ -579,10 +579,10 @@ spv.sparseTexture.frag
434: 21(ivec4) Load 23(utexel)
435: 11(fvec4) ConvertUToF 434
436: 11(fvec4) FAdd 433 435
Store 424 436
Store 427 436
Branch 429
429: Label
437: 11(fvec4) Load 424
437: 11(fvec4) Load 427
Store 423(outColor) 437
Return
FunctionEnd
......@@ -145,14 +145,14 @@ spv.sparseTextureClamp.frag
310: 157(ivec2) ConstantComposite 143 143
344: TypePointer Output 11(fvec4)
345(outColor): 344(ptr) Variable Output
348: TypeBool
347: TypeBool
4(main): 2 Function None 3
5: Label
8(resident): 7(ptr) Variable Function
13(texel): 12(ptr) Variable Function
18(itexel): 17(ptr) Variable Function
23(utexel): 22(ptr) Variable Function
346: 12(ptr) Variable Function
349: 12(ptr) Variable Function
Store 8(resident) 9
Store 13(texel) 15
Store 18(itexel) 19
......@@ -442,13 +442,13 @@ spv.sparseTextureClamp.frag
342: 16(ivec4) Load 18(itexel)
343: 16(ivec4) IAdd 342 341
Store 18(itexel) 343
347: 6(int) Load 8(resident)
349: 348(bool) ImageSparseTexelsResident 347
346: 6(int) Load 8(resident)
348: 347(bool) ImageSparseTexelsResident 346
SelectionMerge 351 None
BranchConditional 349 350 353
BranchConditional 348 350 353
350: Label
352: 11(fvec4) Load 13(texel)
Store 346 352
Store 349 352
Branch 351
353: Label
354: 16(ivec4) Load 18(itexel)
......@@ -456,10 +456,10 @@ spv.sparseTextureClamp.frag
356: 21(ivec4) Load 23(utexel)
357: 11(fvec4) ConvertUToF 356
358: 11(fvec4) FAdd 355 357
Store 346 358
Store 349 358
Branch 351
351: Label
359: 11(fvec4) Load 346
359: 11(fvec4) Load 349
Store 345(outColor) 359
Return
FunctionEnd
......@@ -141,7 +141,7 @@ spv.types.frag
139(f2): 138(ptr) Variable Function
148(f3): 147(ptr) Variable Function
157(f4): 156(ptr) Variable Function
166: 156(ptr) Variable Function
194: 156(ptr) Variable Function
11: 6(bool) Load 10(u_b)
13: 6(bool) Load 12(i_b)
14: 6(bool) LogicalAnd 11 13
......@@ -235,36 +235,36 @@ spv.types.frag
162: 155(fvec4) Load 161(i_f4)
163: 155(fvec4) FAdd 160 162
Store 157(f4) 163
167: 6(bool) Load 8(b)
168: 7(ptr) AccessChain 17(b2) 21
169: 6(bool) Load 168
170: 6(bool) LogicalOr 167 169
171: 7(ptr) AccessChain 17(b2) 28
172: 6(bool) Load 171
173: 6(bool) LogicalOr 170 172
174: 7(ptr) AccessChain 38(b3) 21
175: 6(bool) Load 174
176: 6(bool) LogicalOr 173 175
177: 7(ptr) AccessChain 38(b3) 28
178: 6(bool) Load 177
179: 6(bool) LogicalOr 176 178
180: 7(ptr) AccessChain 38(b3) 53
181: 6(bool) Load 180
182: 6(bool) LogicalOr 179 181
183: 7(ptr) AccessChain 63(b4) 21
184: 6(bool) Load 183
185: 6(bool) LogicalOr 182 184
186: 7(ptr) AccessChain 63(b4) 28
187: 6(bool) Load 186
188: 6(bool) LogicalOr 185 187
189: 7(ptr) AccessChain 63(b4) 53
190: 6(bool) Load 189
191: 6(bool) LogicalOr 188 190
192: 7(ptr) AccessChain 63(b4) 84
193: 6(bool) Load 192
194: 6(bool) LogicalOr 191 193
166: 6(bool) Load 8(b)
167: 7(ptr) AccessChain 17(b2) 21
168: 6(bool) Load 167
169: 6(bool) LogicalOr 166 168
170: 7(ptr) AccessChain 17(b2) 28
171: 6(bool) Load 170
172: 6(bool) LogicalOr 169 171
173: 7(ptr) AccessChain 38(b3) 21
174: 6(bool) Load 173
175: 6(bool) LogicalOr 172 174
176: 7(ptr) AccessChain 38(b3) 28
177: 6(bool) Load 176
178: 6(bool) LogicalOr 175 177
179: 7(ptr) AccessChain 38(b3) 53
180: 6(bool) Load 179
181: 6(bool) LogicalOr 178 180
182: 7(ptr) AccessChain 63(b4) 21
183: 6(bool) Load 182
184: 6(bool) LogicalOr 181 183
185: 7(ptr) AccessChain 63(b4) 28
186: 6(bool) Load 185
187: 6(bool) LogicalOr 184 186
188: 7(ptr) AccessChain 63(b4) 53
189: 6(bool) Load 188
190: 6(bool) LogicalOr 187 189
191: 7(ptr) AccessChain 63(b4) 84
192: 6(bool) Load 191
193: 6(bool) LogicalOr 190 192
SelectionMerge 196 None
BranchConditional 194 195 256
BranchConditional 193 195 256
195: Label
197: 92(int) Load 94(i)
198: 93(ptr) AccessChain 103(i2) 21
......@@ -325,13 +325,13 @@ spv.types.frag
253: 128(float) Load 252
254: 128(float) FAdd 251 253
255: 155(fvec4) CompositeConstruct 254 254 254 254
Store 166 255
Store 194 255
Branch 196
256: Label
Store 166 258
Store 194 258
Branch 196
196: Label
259: 155(fvec4) Load 166
259: 155(fvec4) Load 194
Store 165(gl_FragColor) 259
Return
FunctionEnd
......@@ -1336,9 +1336,11 @@ class TIntermSelection : public TIntermTyped {
public:
TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB) :
TIntermTyped(EbtVoid), condition(cond), trueBlock(trueB), falseBlock(falseB),
shortCircuit(true),
flatten(false), dontFlatten(false) {}
TIntermSelection(TIntermTyped* cond, TIntermNode* trueB, TIntermNode* falseB, const TType& type) :
TIntermTyped(type), condition(cond), trueBlock(trueB), falseBlock(falseB),
shortCircuit(true),
flatten(false), dontFlatten(false) {}
virtual void traverse(TIntermTraverser*);
virtual TIntermTyped* getCondition() const { return condition; }
......@@ -1347,6 +1349,9 @@ public:
virtual TIntermSelection* getAsSelectionNode() { return this; }
virtual const TIntermSelection* getAsSelectionNode() const { return this; }
void setNoShortCircuit() { shortCircuit = false; }
bool getShortCircuit() const { return shortCircuit; }
void setFlatten() { flatten = true; }
void setDontFlatten() { dontFlatten = true; }
bool getFlatten() const { return flatten; }
......@@ -1356,8 +1361,9 @@ protected:
TIntermTyped* condition;
TIntermNode* trueBlock;
TIntermNode* falseBlock;
bool flatten; // true if flatten requested
bool dontFlatten; // true if requested to not flatten
bool shortCircuit; // normally all if-then-else and all GLSL ?: short-circuit, but HLSL ?: does not
bool flatten; // true if flatten requested
bool dontFlatten; // true if requested to not flatten
};
//
......
......@@ -1672,7 +1672,11 @@ TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* true
// If it's void, go to the if-then-else selection()
if (trueBlock->getBasicType() == EbtVoid && falseBlock->getBasicType() == EbtVoid) {
TIntermNodePair pair = { trueBlock, falseBlock };
return addSelection(cond, pair, loc);
TIntermSelection* selection = addSelection(cond, pair, loc);
if (getSource() == EShSourceHlsl)
selection->setNoShortCircuit();
return selection;
}
//
......@@ -1743,6 +1747,9 @@ TIntermTyped* TIntermediate::addSelection(TIntermTyped* cond, TIntermTyped* true
else
node->getQualifier().makeTemporary();
if (getSource() == EShSourceHlsl)
node->setNoShortCircuit();
return node;
}
......
......@@ -819,6 +819,8 @@ bool TOutputTraverser::visitSelection(TVisit /* visit */, TIntermSelection* node
out.debug << "Test condition and select";
out.debug << " (" << node->getCompleteString() << ")";
if (node->getShortCircuit() == false)
out.debug << ": no shortcircuit";
if (node->getFlatten())
out.debug << ": Flatten";
if (node->getDontFlatten())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment