Only print legalization warning if optimizer disabled
This commit is contained in:
		
							parent
							
								
									7be36647fc
								
							
						
					
					
						commit
						fb03a55e0f
					
				| @ -94,9 +94,10 @@ endif() | |||||||
| 
 | 
 | ||||||
| if(ENABLE_OPT) | if(ENABLE_OPT) | ||||||
|     message(STATUS "optimizer enabled") |     message(STATUS "optimizer enabled") | ||||||
|     add_definitions(-DENABLE_OPT) |     add_definitions(-DENABLE_OPT=1) | ||||||
| elseif(ENABLE_HLSL) | elseif(ENABLE_HLSL) | ||||||
|     message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL") |     message(STATUS "spirv-tools not linked - illegal SPIRV may be generated for HLSL") | ||||||
|  |     add_definitions(-DENABLE_OPT=0) | ||||||
| endif() | endif() | ||||||
| 
 | 
 | ||||||
| add_subdirectory(glslang) | add_subdirectory(glslang) | ||||||
|  | |||||||
| @ -54,12 +54,12 @@ namespace spv { | |||||||
| #endif | #endif | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #ifdef ENABLE_OPT | #if ENABLE_OPT | ||||||
|     #include "spirv-tools/optimizer.hpp" |     #include "spirv-tools/optimizer.hpp" | ||||||
|     #include "message.h" |     #include "message.h" | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| #ifdef ENABLE_OPT | #if ENABLE_OPT | ||||||
| using namespace spvtools; | using namespace spvtools; | ||||||
| #endif | #endif | ||||||
| 
 | 
 | ||||||
| @ -6757,7 +6757,7 @@ void GlslangToSpv(const glslang::TIntermediate& intermediate, std::vector<unsign | |||||||
|     it.finishSpv(); |     it.finishSpv(); | ||||||
|     it.dumpSpv(spirv); |     it.dumpSpv(spirv); | ||||||
| 
 | 
 | ||||||
| #ifdef ENABLE_OPT | #if ENABLE_OPT | ||||||
|     // If from HLSL, run spirv-opt to "legalize" the SPIR-V for Vulkan
 |     // If from HLSL, run spirv-opt to "legalize" the SPIR-V for Vulkan
 | ||||||
|     // eg. forward and remove memory writes of opaque types.
 |     // eg. forward and remove memory writes of opaque types.
 | ||||||
|     if ((intermediate.getSource() == EShSourceHlsl || |     if ((intermediate.getSource() == EShSourceHlsl || | ||||||
|  | |||||||
| @ -574,7 +574,7 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem | |||||||
|                 if (argv[0][2] == 'd') |                 if (argv[0][2] == 'd') | ||||||
|                     Options |= EOptionOptimizeDisable; |                     Options |= EOptionOptimizeDisable; | ||||||
|                 else if (argv[0][2] == 's') |                 else if (argv[0][2] == 's') | ||||||
| #ifdef ENABLE_OPT | #if ENABLE_OPT | ||||||
|                     Options |= EOptionOptimizeSize; |                     Options |= EOptionOptimizeSize; | ||||||
| #else | #else | ||||||
|                     Error("-Os not available; optimizer not linked"); |                     Error("-Os not available; optimizer not linked"); | ||||||
| @ -720,6 +720,8 @@ void SetMessageOptions(EShMessages& messages) | |||||||
|         messages = (EShMessages)(messages | EShMsgDebugInfo); |         messages = (EShMessages)(messages | EShMsgDebugInfo); | ||||||
|     if (HlslEnable16BitTypes) |     if (HlslEnable16BitTypes) | ||||||
|         messages = (EShMessages)(messages | EShMsgHlslEnable16BitTypes); |         messages = (EShMessages)(messages | EShMsgHlslEnable16BitTypes); | ||||||
|  |     if ((Options & EOptionOptimizeDisable) || !ENABLE_OPT) | ||||||
|  |         messages = (EShMessages)(messages | EShMsgHlslLegalization); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| //
 | //
 | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| hlsl.aliasOpaque.frag | hlsl.aliasOpaque.frag | ||||||
| WARNING: AST will form illegal SPIR-V; need to transform to legalize |  | ||||||
| // Module Version 10000 | // Module Version 10000 | ||||||
| // Generated by (magic number): 80006 | // Generated by (magic number): 80006 | ||||||
| // Id's are bound by 87 | // Id's are bound by 87 | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| hlsl.flattenOpaque.frag | hlsl.flattenOpaque.frag | ||||||
| WARNING: AST will form illegal SPIR-V; need to transform to legalize |  | ||||||
| // Module Version 10000 | // Module Version 10000 | ||||||
| // Generated by (magic number): 80006 | // Generated by (magic number): 80006 | ||||||
| // Id's are bound by 185 | // Id's are bound by 185 | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| hlsl.flattenOpaqueInit.vert | hlsl.flattenOpaqueInit.vert | ||||||
| WARNING: AST will form illegal SPIR-V; need to transform to legalize |  | ||||||
| // Module Version 10000 | // Module Version 10000 | ||||||
| // Generated by (magic number): 80006 | // Generated by (magic number): 80006 | ||||||
| // Id's are bound by 134 | // Id's are bound by 134 | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| hlsl.flattenOpaqueInitMix.vert | hlsl.flattenOpaqueInitMix.vert | ||||||
| WARNING: AST will form illegal SPIR-V; need to transform to legalize |  | ||||||
| // Module Version 10000 | // Module Version 10000 | ||||||
| // Generated by (magic number): 80006 | // Generated by (magic number): 80006 | ||||||
| // Id's are bound by 97 | // Id's are bound by 97 | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| hlsl.flattenSubset.frag | hlsl.flattenSubset.frag | ||||||
| WARNING: AST will form illegal SPIR-V; need to transform to legalize |  | ||||||
| // Module Version 10000 | // Module Version 10000 | ||||||
| // Generated by (magic number): 80006 | // Generated by (magic number): 80006 | ||||||
| // Id's are bound by 66 | // Id's are bound by 66 | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| hlsl.flattenSubset2.frag | hlsl.flattenSubset2.frag | ||||||
| WARNING: AST will form illegal SPIR-V; need to transform to legalize |  | ||||||
| // Module Version 10000 | // Module Version 10000 | ||||||
| // Generated by (magic number): 80006 | // Generated by (magic number): 80006 | ||||||
| // Id's are bound by 53 | // Id's are bound by 53 | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| hlsl.partialFlattenLocal.vert | hlsl.partialFlattenLocal.vert | ||||||
| WARNING: AST will form illegal SPIR-V; need to transform to legalize |  | ||||||
| // Module Version 10000 | // Module Version 10000 | ||||||
| // Generated by (magic number): 80006 | // Generated by (magic number): 80006 | ||||||
| // Id's are bound by 169 | // Id's are bound by 169 | ||||||
|  | |||||||
| @ -1,5 +1,4 @@ | |||||||
| hlsl.partialFlattenMixed.vert | hlsl.partialFlattenMixed.vert | ||||||
| WARNING: AST will form illegal SPIR-V; need to transform to legalize |  | ||||||
| // Module Version 10000 | // Module Version 10000 | ||||||
| // Generated by (magic number): 80006 | // Generated by (magic number): 80006 | ||||||
| // Id's are bound by 36 | // Id's are bound by 36 | ||||||
|  | |||||||
| @ -215,6 +215,7 @@ enum EShMessages { | |||||||
|     EShMsgHlslOffsets      = (1 << 9),  // allow block offsets to follow HLSL rules instead of GLSL rules
 |     EShMsgHlslOffsets      = (1 << 9),  // allow block offsets to follow HLSL rules instead of GLSL rules
 | ||||||
|     EShMsgDebugInfo        = (1 << 10), // save debug information
 |     EShMsgDebugInfo        = (1 << 10), // save debug information
 | ||||||
|     EShMsgHlslEnable16BitTypes  = (1 << 11), // enable use of 16-bit types in SPIR-V for HLSL
 |     EShMsgHlslEnable16BitTypes  = (1 << 11), // enable use of 16-bit types in SPIR-V for HLSL
 | ||||||
|  |     EShMsgHlslLegalization  = (1 << 12), // enable HLSL Legalization messages
 | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| //
 | //
 | ||||||
|  | |||||||
| @ -92,7 +92,7 @@ TEST_P(HlslLegalizeTest, FromFile) | |||||||
|     loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam().fileName, |     loadFileCompileAndCheck(GlobalTestSettings.testRoot, GetParam().fileName, | ||||||
|                             Source::HLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0, |                             Source::HLSL, Semantics::Vulkan, glslang::EShTargetVulkan_1_0, | ||||||
|                             Target::Spv, true, GetParam().entryPoint, |                             Target::Spv, true, GetParam().entryPoint, | ||||||
|                             "/baseLegalResults/", false); |                             "/baseLegalResults/", true); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // clang-format off
 | // clang-format off
 | ||||||
| @ -410,7 +410,7 @@ INSTANTIATE_TEST_CASE_P( | |||||||
| ); | ); | ||||||
| // clang-format on
 | // clang-format on
 | ||||||
| 
 | 
 | ||||||
| #ifdef ENABLE_OPT | #if ENABLE_OPT | ||||||
| // clang-format off
 | // clang-format off
 | ||||||
| INSTANTIATE_TEST_CASE_P( | INSTANTIATE_TEST_CASE_P( | ||||||
|     ToSpirv, HlslLegalizeTest, |     ToSpirv, HlslLegalizeTest, | ||||||
|  | |||||||
| @ -100,6 +100,8 @@ EShMessages DeriveOptions(Source source, Semantics semantics, Target target) | |||||||
|             break; |             break; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     result = static_cast<EShMessages>(result | EShMsgHlslLegalization); | ||||||
|  | 
 | ||||||
|     return result; |     return result; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -200,7 +200,7 @@ public: | |||||||
|             glslang::EShTargetClientVersion clientTargetVersion, |             glslang::EShTargetClientVersion clientTargetVersion, | ||||||
|             bool flattenUniformArrays = false, |             bool flattenUniformArrays = false, | ||||||
|             EShTextureSamplerTransformMode texSampTransMode = EShTexSampTransKeep, |             EShTextureSamplerTransformMode texSampTransMode = EShTexSampTransKeep, | ||||||
|             bool disableOptimizer = true, |             bool enableOptimizer = false, | ||||||
|             bool automap = true) |             bool automap = true) | ||||||
|     { |     { | ||||||
|         const EShLanguage stage = GetShaderStage(GetSuffix(shaderName)); |         const EShLanguage stage = GetShaderStage(GetSuffix(shaderName)); | ||||||
| @ -242,7 +242,7 @@ public: | |||||||
|         if (success && (controls & EShMsgSpvRules)) { |         if (success && (controls & EShMsgSpvRules)) { | ||||||
|             std::vector<uint32_t> spirv_binary; |             std::vector<uint32_t> spirv_binary; | ||||||
|             glslang::SpvOptions options; |             glslang::SpvOptions options; | ||||||
|             options.disableOptimizer = disableOptimizer; |             options.disableOptimizer = !enableOptimizer; | ||||||
|             glslang::GlslangToSpv(*program.getIntermediate(stage), |             glslang::GlslangToSpv(*program.getIntermediate(stage), | ||||||
|                                   spirv_binary, &logger, &options); |                                   spirv_binary, &logger, &options); | ||||||
| 
 | 
 | ||||||
| @ -412,7 +412,7 @@ public: | |||||||
|                                  bool automap = true, |                                  bool automap = true, | ||||||
|                                  const std::string& entryPointName="", |                                  const std::string& entryPointName="", | ||||||
|                                  const std::string& baseDir="/baseResults/", |                                  const std::string& baseDir="/baseResults/", | ||||||
|                                  const bool disableOptimizer = true) |                                  const bool enableOptimizer = false) | ||||||
|     { |     { | ||||||
|         const std::string inputFname = testDir + "/" + testName; |         const std::string inputFname = testDir + "/" + testName; | ||||||
|         const std::string expectedOutputFname = |         const std::string expectedOutputFname = | ||||||
| @ -422,9 +422,11 @@ public: | |||||||
|         tryLoadFile(inputFname, "input", &input); |         tryLoadFile(inputFname, "input", &input); | ||||||
|         tryLoadFile(expectedOutputFname, "expected output", &expectedOutput); |         tryLoadFile(expectedOutputFname, "expected output", &expectedOutput); | ||||||
| 
 | 
 | ||||||
|         const EShMessages controls = DeriveOptions(source, semantics, target); |         EShMessages controls = DeriveOptions(source, semantics, target); | ||||||
|  |         if (enableOptimizer) | ||||||
|  |             controls = static_cast<EShMessages>(controls & ~EShMsgHlslLegalization); | ||||||
|         GlslangResult result = compileAndLink(testName, input, entryPointName, controls, clientTargetVersion, false, |         GlslangResult result = compileAndLink(testName, input, entryPointName, controls, clientTargetVersion, false, | ||||||
|                                               EShTexSampTransKeep, disableOptimizer, automap); |                                               EShTexSampTransKeep, enableOptimizer, automap); | ||||||
| 
 | 
 | ||||||
|         // Generate the hybrid output in the way of glslangValidator.
 |         // Generate the hybrid output in the way of glslangValidator.
 | ||||||
|         std::ostringstream stream; |         std::ostringstream stream; | ||||||
|  | |||||||
| @ -9924,7 +9924,7 @@ void HlslParseContext::finish() | |||||||
| 
 | 
 | ||||||
|     // Communicate out (esp. for command line) that we formed AST that will make
 |     // Communicate out (esp. for command line) that we formed AST that will make
 | ||||||
|     // illegal AST SPIR-V and it needs transforms to legalize it.
 |     // 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"; |         infoSink.info << "WARNING: AST will form illegal SPIR-V; need to transform to legalize"; | ||||||
| 
 | 
 | ||||||
|     TParseContextBase::finish(); |     TParseContextBase::finish(); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 GregF
						GregF