From fb03a55e0f89f0863623bbdced93cd0e3231beca Mon Sep 17 00:00:00 2001 From: GregF Date: Thu, 29 Mar 2018 11:49:14 -0600 Subject: [PATCH] Only print legalization warning if optimizer disabled --- CMakeLists.txt | 3 ++- SPIRV/GlslangToSpv.cpp | 6 +++--- StandAlone/StandAlone.cpp | 4 +++- Test/baseLegalResults/hlsl.aliasOpaque.frag.out | 1 - Test/baseLegalResults/hlsl.flattenOpaque.frag.out | 1 - .../baseLegalResults/hlsl.flattenOpaqueInit.vert.out | 1 - .../hlsl.flattenOpaqueInitMix.vert.out | 1 - Test/baseLegalResults/hlsl.flattenSubset.frag.out | 1 - Test/baseLegalResults/hlsl.flattenSubset2.frag.out | 1 - .../hlsl.partialFlattenLocal.vert.out | 1 - .../hlsl.partialFlattenMixed.vert.out | 1 - glslang/Public/ShaderLang.h | 1 + gtests/Hlsl.FromFile.cpp | 4 ++-- gtests/TestFixture.cpp | 2 ++ gtests/TestFixture.h | 12 +++++++----- hlsl/hlslParseHelper.cpp | 2 +- 16 files changed, 21 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d453cc6..d54ff9bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,9 +94,10 @@ endif() if(ENABLE_OPT) message(STATUS "optimizer enabled") - add_definitions(-DENABLE_OPT) + add_definitions(-DENABLE_OPT=1) elseif(ENABLE_HLSL) message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL") + add_definitions(-DENABLE_OPT=0) endif() add_subdirectory(glslang) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 56bc4cf7..d39c2609 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -54,12 +54,12 @@ namespace spv { #endif } -#ifdef ENABLE_OPT +#if ENABLE_OPT #include "spirv-tools/optimizer.hpp" #include "message.h" #endif -#ifdef ENABLE_OPT +#if ENABLE_OPT using namespace spvtools; #endif @@ -6757,7 +6757,7 @@ void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector>& workItem if (argv[0][2] == 'd') Options |= EOptionOptimizeDisable; else if (argv[0][2] == 's') -#ifdef ENABLE_OPT +#if ENABLE_OPT Options |= EOptionOptimizeSize; #else Error("-Os not available; optimizer not linked"); @@ -720,6 +720,8 @@ void SetMessageOptions(EShMessages& messages) messages = (EShMessages)(messages | EShMsgDebugInfo); if (HlslEnable16BitTypes) messages = (EShMessages)(messages | EShMsgHlslEnable16BitTypes); + if ((Options & EOptionOptimizeDisable) || !ENABLE_OPT) + messages = (EShMessages)(messages | EShMsgHlslLegalization); } // diff --git a/Test/baseLegalResults/hlsl.aliasOpaque.frag.out b/Test/baseLegalResults/hlsl.aliasOpaque.frag.out index 895b3373..f877db67 100644 --- a/Test/baseLegalResults/hlsl.aliasOpaque.frag.out +++ b/Test/baseLegalResults/hlsl.aliasOpaque.frag.out @@ -1,5 +1,4 @@ hlsl.aliasOpaque.frag -WARNING: AST will form illegal SPIR-V; need to transform to legalize // Module Version 10000 // Generated by (magic number): 80006 // Id's are bound by 87 diff --git a/Test/baseLegalResults/hlsl.flattenOpaque.frag.out b/Test/baseLegalResults/hlsl.flattenOpaque.frag.out index 3ad7f1dd..ab9237b1 100644 --- a/Test/baseLegalResults/hlsl.flattenOpaque.frag.out +++ b/Test/baseLegalResults/hlsl.flattenOpaque.frag.out @@ -1,5 +1,4 @@ hlsl.flattenOpaque.frag -WARNING: AST will form illegal SPIR-V; need to transform to legalize // Module Version 10000 // Generated by (magic number): 80006 // Id's are bound by 185 diff --git a/Test/baseLegalResults/hlsl.flattenOpaqueInit.vert.out b/Test/baseLegalResults/hlsl.flattenOpaqueInit.vert.out index d4a985de..3d0a0bd0 100644 --- a/Test/baseLegalResults/hlsl.flattenOpaqueInit.vert.out +++ b/Test/baseLegalResults/hlsl.flattenOpaqueInit.vert.out @@ -1,5 +1,4 @@ hlsl.flattenOpaqueInit.vert -WARNING: AST will form illegal SPIR-V; need to transform to legalize // Module Version 10000 // Generated by (magic number): 80006 // Id's are bound by 134 diff --git a/Test/baseLegalResults/hlsl.flattenOpaqueInitMix.vert.out b/Test/baseLegalResults/hlsl.flattenOpaqueInitMix.vert.out index e3568e5a..9793d575 100644 --- a/Test/baseLegalResults/hlsl.flattenOpaqueInitMix.vert.out +++ b/Test/baseLegalResults/hlsl.flattenOpaqueInitMix.vert.out @@ -1,5 +1,4 @@ hlsl.flattenOpaqueInitMix.vert -WARNING: AST will form illegal SPIR-V; need to transform to legalize // Module Version 10000 // Generated by (magic number): 80006 // Id's are bound by 97 diff --git a/Test/baseLegalResults/hlsl.flattenSubset.frag.out b/Test/baseLegalResults/hlsl.flattenSubset.frag.out index 3d2bee34..617c719e 100755 --- a/Test/baseLegalResults/hlsl.flattenSubset.frag.out +++ b/Test/baseLegalResults/hlsl.flattenSubset.frag.out @@ -1,5 +1,4 @@ hlsl.flattenSubset.frag -WARNING: AST will form illegal SPIR-V; need to transform to legalize // Module Version 10000 // Generated by (magic number): 80006 // Id's are bound by 66 diff --git a/Test/baseLegalResults/hlsl.flattenSubset2.frag.out b/Test/baseLegalResults/hlsl.flattenSubset2.frag.out index 5823bc5c..ef661ba6 100755 --- a/Test/baseLegalResults/hlsl.flattenSubset2.frag.out +++ b/Test/baseLegalResults/hlsl.flattenSubset2.frag.out @@ -1,5 +1,4 @@ hlsl.flattenSubset2.frag -WARNING: AST will form illegal SPIR-V; need to transform to legalize // Module Version 10000 // Generated by (magic number): 80006 // Id's are bound by 53 diff --git a/Test/baseLegalResults/hlsl.partialFlattenLocal.vert.out b/Test/baseLegalResults/hlsl.partialFlattenLocal.vert.out index cae5d073..8bf9614d 100755 --- a/Test/baseLegalResults/hlsl.partialFlattenLocal.vert.out +++ b/Test/baseLegalResults/hlsl.partialFlattenLocal.vert.out @@ -1,5 +1,4 @@ hlsl.partialFlattenLocal.vert -WARNING: AST will form illegal SPIR-V; need to transform to legalize // Module Version 10000 // Generated by (magic number): 80006 // Id's are bound by 169 diff --git a/Test/baseLegalResults/hlsl.partialFlattenMixed.vert.out b/Test/baseLegalResults/hlsl.partialFlattenMixed.vert.out index 1662eca3..7e36eb9c 100755 --- a/Test/baseLegalResults/hlsl.partialFlattenMixed.vert.out +++ b/Test/baseLegalResults/hlsl.partialFlattenMixed.vert.out @@ -1,5 +1,4 @@ hlsl.partialFlattenMixed.vert -WARNING: AST will form illegal SPIR-V; need to transform to legalize // Module Version 10000 // Generated by (magic number): 80006 // Id's are bound by 36 diff --git a/glslang/Public/ShaderLang.h b/glslang/Public/ShaderLang.h index ef6c0745..732c17ad 100644 --- a/glslang/Public/ShaderLang.h +++ b/glslang/Public/ShaderLang.h @@ -215,6 +215,7 @@ enum EShMessages { EShMsgHlslOffsets = (1 << 9), // allow block offsets to follow HLSL rules instead of GLSL rules EShMsgDebugInfo = (1 << 10), // save debug information EShMsgHlslEnable16BitTypes = (1 << 11), // enable use of 16-bit types in SPIR-V for HLSL + EShMsgHlslLegalization = (1 << 12), // enable HLSL Legalization messages }; // diff --git a/gtests/Hlsl.FromFile.cpp b/gtests/Hlsl.FromFile.cpp index 068338ae..79e9592c 100644 --- a/gtests/Hlsl.FromFile.cpp +++ b/gtests/Hlsl.FromFile.cpp @@ -92,7 +92,7 @@ TEST_P(HlslLegalizeTest, FromFile) loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam().fileName, Source::HLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0, Target::Spv, true, GetParam().entryPoint, - "/baseLegalResults/", false); + "/baseLegalResults/", true); } // clang-format off @@ -410,7 +410,7 @@ INSTANTIATE_TEST_CASE_P( ); // clang-format on -#ifdef ENABLE_OPT +#if ENABLE_OPT // clang-format off INSTANTIATE_TEST_CASE_P( ToSpirv, HlslLegalizeTest, diff --git a/gtests/TestFixture.cpp b/gtests/TestFixture.cpp index db2b81d1..77bada5f 100644 --- a/gtests/TestFixture.cpp +++ b/gtests/TestFixture.cpp @@ -100,6 +100,8 @@ EShMessages DeriveOptions(Source source, Semantics semantics, Target target) break; } + result = static_cast(result | EShMsgHlslLegalization); + return result; } diff --git a/gtests/TestFixture.h b/gtests/TestFixture.h index 0e984d4e..a58978d3 100644 --- a/gtests/TestFixture.h +++ b/gtests/TestFixture.h @@ -200,7 +200,7 @@ public: glslang::EShTargetClientVersion clientTargetVersion, bool flattenUniformArrays = false, EShTextureSamplerTransformMode texSampTransMode = EShTexSampTransKeep, - bool disableOptimizer = true, + bool enableOptimizer = false, bool automap = true) { const EShLanguage stage = GetShaderStage(GetSuffix(shaderName)); @@ -242,7 +242,7 @@ public: if (success && (controls & EShMsgSpvRules)) { std::vector spirv_binary; glslang::SpvOptions options; - options.disableOptimizer = disableOptimizer; + options.disableOptimizer = !enableOptimizer; glslang::GlslangToSpv(*program.getIntermediate(stage), spirv_binary, &logger, &options); @@ -412,7 +412,7 @@ public: bool automap = true, const std::string& entryPointName="", const std::string& baseDir="/baseResults/", - const bool disableOptimizer = true) + const bool enableOptimizer = false) { const std::string inputFname = testDir + "/" + testName; const std::string expectedOutputFname = @@ -422,9 +422,11 @@ public: tryLoadFile(inputFname, "input", &input); tryLoadFile(expectedOutputFname, "expected output", &expectedOutput); - const EShMessages controls = DeriveOptions(source, semantics, target); + EShMessages controls = DeriveOptions(source, semantics, target); + if (enableOptimizer) + controls = static_cast(controls & ~EShMsgHlslLegalization); GlslangResult result = compileAndLink(testName, input, entryPointName, controls, clientTargetVersion, false, - EShTexSampTransKeep, disableOptimizer, automap); + EShTexSampTransKeep, enableOptimizer, automap); // Generate the hybrid output in the way of glslangValidator. std::ostringstream stream; diff --git a/hlsl/hlslParseHelper.cpp b/hlsl/hlslParseHelper.cpp index 1b9cc538..5738321a 100755 --- a/hlsl/hlslParseHelper.cpp +++ b/hlsl/hlslParseHelper.cpp @@ -9924,7 +9924,7 @@ void HlslParseContext::finish() // Communicate out (esp. for command line) that we formed AST that will make // illegal AST SPIR-V and it needs transforms to legalize it. - if (intermediate.needsLegalization()) + if (intermediate.needsLegalization() && (messages & EShMsgHlslLegalization)) infoSink.info << "WARNING: AST will form illegal SPIR-V; need to transform to legalize"; TParseContextBase::finish();