From 0479437a5c5d1d727f72ff769f198b95a9650103 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Wed, 1 Mar 2017 13:49:11 -0700 Subject: [PATCH] SPV: Fix #739: OpSelect can only operate on scalars and vectors. --- SPIRV/GlslangToSpv.cpp | 3 +- Test/baseResults/spv.Operations.frag.out | 64 ++++++++++++++++++------ Test/spv.Operations.frag | 3 ++ glslang/Include/revision.h | 2 +- 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 925b8590..5385eeef 100755 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -1789,7 +1789,8 @@ bool TGlslangToSpvTraverser::visitSelection(glslang::TVisit /* visit */, glslang // 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->getBasicType() == glslang::EbtVoid) + if ((!node->getType().isScalar() && !node->getType().isVector()) || + node->getBasicType() == glslang::EbtVoid) return false; if (node->getTrueBlock() == nullptr || diff --git a/Test/baseResults/spv.Operations.frag.out b/Test/baseResults/spv.Operations.frag.out index 1a74192e..aeee253b 100755 --- a/Test/baseResults/spv.Operations.frag.out +++ b/Test/baseResults/spv.Operations.frag.out @@ -3,12 +3,12 @@ Warning, version 450 is not yet complete; most version-specific features are pre // Module Version 10000 // Generated by (magic number): 80001 -// Id's are bound by 509 +// Id's are bound by 532 Capability Shader 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint Fragment 4 "main" 11 22 212 288 485 503 508 + EntryPoint Fragment 4 "main" 11 22 212 288 485 526 531 ExecutionMode 4 OriginUpperLeft Source GLSL 450 Name 4 "main" @@ -24,13 +24,15 @@ Warning, version 450 is not yet complete; most version-specific features are pre Name 305 "b" Name 342 "ub42" Name 485 "FragColor" - Name 503 "uiv4" - Name 505 "ub" - Name 508 "uuv4" + Name 503 "m1" + Name 510 "m2" + Name 526 "uiv4" + Name 528 "ub" + Name 531 "uuv4" Decorate 22(ui) Flat Decorate 288(uui) Flat - Decorate 503(uiv4) Flat - Decorate 508(uuv4) Flat + Decorate 526(uiv4) Flat + Decorate 531(uuv4) Flat 2: TypeVoid 3: TypeFunction 2 6: TypeFloat 32 @@ -65,14 +67,24 @@ Warning, version 450 is not yet complete; most version-specific features are pre 472: 18(int) Constant 17 484: TypePointer Output 7(fvec4) 485(FragColor): 484(ptr) Variable Output - 501: TypeVector 18(int) 4 - 502: TypePointer Input 501(ivec4) - 503(uiv4): 502(ptr) Variable Input - 504: TypePointer Private 178(bool) - 505(ub): 504(ptr) Variable Private - 506: TypeVector 141(int) 4 - 507: TypePointer Input 506(ivec4) - 508(uuv4): 507(ptr) Variable Input + 501: TypeMatrix 7(fvec4) 4 + 502: TypePointer Function 501 + 504: 6(float) Constant 0 + 505: 7(fvec4) ConstantComposite 461 504 504 504 + 506: 7(fvec4) ConstantComposite 504 461 504 504 + 507: 7(fvec4) ConstantComposite 504 504 461 504 + 508: 7(fvec4) ConstantComposite 504 504 504 461 + 509: 501 ConstantComposite 505 506 507 508 + 511: 7(fvec4) ConstantComposite 504 504 504 504 + 512: 501 ConstantComposite 511 511 511 511 + 524: TypeVector 18(int) 4 + 525: TypePointer Input 524(ivec4) + 526(uiv4): 525(ptr) Variable Input + 527: TypePointer Private 178(bool) + 528(ub): 527(ptr) Variable Private + 529: TypeVector 141(int) 4 + 530: TypePointer Input 529(ivec4) + 531(uuv4): 530(ptr) Variable Input 4(main): 2 Function None 3 5: Label 9(v): 8(ptr) Variable Function @@ -81,6 +93,9 @@ Warning, version 450 is not yet complete; most version-specific features are pre 285(u): 284(ptr) Variable Function 305(b): 304(ptr) Variable Function 486: 8(ptr) Variable Function + 503(m1): 502(ptr) Variable Function + 510(m2): 502(ptr) Variable Function + 513: 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 @@ -666,5 +681,24 @@ Warning, version 450 is not yet complete; most version-specific features are pre 489: Label 500: 7(fvec4) Load 486 Store 485(FragColor) 500 + Store 503(m1) 509 + Store 510(m2) 512 + 514: 178(bool) Load 305(b) + SelectionMerge 516 None + BranchConditional 514 515 518 + 515: Label + 517: 501 Load 503(m1) + Store 513 517 + Branch 516 + 518: Label + 519: 501 Load 510(m2) + Store 513 519 + Branch 516 + 516: Label + 520: 8(ptr) AccessChain 513 405 + 521: 7(fvec4) Load 520 + 522: 7(fvec4) Load 485(FragColor) + 523: 7(fvec4) FAdd 522 521 + Store 485(FragColor) 523 Return FunctionEnd diff --git a/Test/spv.Operations.frag b/Test/spv.Operations.frag index 5c8c8af0..52f0a30f 100644 --- a/Test/spv.Operations.frag +++ b/Test/spv.Operations.frag @@ -135,4 +135,7 @@ void main() b = !b; FragColor = b ? vec4(i) + vec4(f) + v : v; + + mat4 m1 = mat4(1.0), m2 = mat4(0.0); + FragColor += (b ? m1 : m2)[1]; } diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h index 3bd52078..7359459e 100644 --- a/glslang/Include/revision.h +++ b/glslang/Include/revision.h @@ -2,5 +2,5 @@ // For the version, it uses the latest git tag followed by the number of commits. // For the date, it uses the current date (when then script is run). -#define GLSLANG_REVISION "Overload400-PrecQual.1865" +#define GLSLANG_REVISION "Overload400-PrecQual.1870" #define GLSLANG_DATE "01-Mar-2017"