From d39b8afc47a1f700b5670463c0d1068878acee6f Mon Sep 17 00:00:00 2001 From: alelenv <40001162+alelenv@users.noreply.github.com> Date: Thu, 28 May 2020 08:18:07 -0700 Subject: [PATCH] EXT_ray_tracing requires spv1.4 (#2237) * EXT_ray_tracing requires spv1.4 * Fix typo. * Add extension data table. * Updated feedback #2. --- .../spv.ext.AnyHitShader.rahit.out | 4 +- .../spv.ext.ClosestHitShader.rchit.out | 4 +- .../spv.ext.IntersectShader.rint.out | 4 +- Test/baseResults/spv.ext.MissShader.rmiss.out | 4 +- .../baseResults/spv.ext.RayCallable.rcall.out | 4 +- .../baseResults/spv.ext.RayConstants.rgen.out | 4 +- .../baseResults/spv.ext.RayGenShader.rgen.out | 6 +-- .../spv.ext.RayGenShader11.rgen.out | 6 +-- .../spv.ext.RayGenShaderArray.rgen.out | 6 +-- glslang/MachineIndependent/Versions.cpp | 50 ++++++++++++++++++- glslang/MachineIndependent/Versions.h | 1 + glslang/MachineIndependent/parseVersions.h | 4 ++ glslang/Public/ShaderLang.h | 1 + gtests/Spv.FromFile.cpp | 30 +++++------ 14 files changed, 91 insertions(+), 37 deletions(-) diff --git a/Test/baseResults/spv.ext.AnyHitShader.rahit.out b/Test/baseResults/spv.ext.AnyHitShader.rahit.out index 3cd60c78..7a501ddc 100644 --- a/Test/baseResults/spv.ext.AnyHitShader.rahit.out +++ b/Test/baseResults/spv.ext.AnyHitShader.rahit.out @@ -1,5 +1,5 @@ spv.ext.AnyHitShader.rahit -// Module Version 10000 +// Module Version 10400 // Generated by (magic number): 80008 // Id's are bound by 94 @@ -7,7 +7,7 @@ spv.ext.AnyHitShader.rahit Extension "SPV_KHR_ray_tracing" 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint AnyHitKHR 4 "main" 11 14 20 23 26 33 36 39 42 47 50 53 58 64 67 70 76 80 + EntryPoint AnyHitKHR 4 "main" 11 14 20 23 26 33 36 39 42 47 50 53 58 64 67 70 76 80 84 Source GLSL 460 SourceExtension "GL_EXT_ray_tracing" Name 4 "main" diff --git a/Test/baseResults/spv.ext.ClosestHitShader.rchit.out b/Test/baseResults/spv.ext.ClosestHitShader.rchit.out index 278b5c16..7bbf7107 100644 --- a/Test/baseResults/spv.ext.ClosestHitShader.rchit.out +++ b/Test/baseResults/spv.ext.ClosestHitShader.rchit.out @@ -1,5 +1,5 @@ spv.ext.ClosestHitShader.rchit -// Module Version 10000 +// Module Version 10400 // Generated by (magic number): 80008 // Id's are bound by 101 @@ -7,7 +7,7 @@ spv.ext.ClosestHitShader.rchit Extension "SPV_KHR_ray_tracing" 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint ClosestHitKHR 4 "main" 11 14 20 23 26 33 36 39 42 47 50 53 58 64 67 70 76 80 + EntryPoint ClosestHitKHR 4 "main" 11 14 20 23 26 33 36 39 42 47 50 53 58 64 67 70 76 80 85 98 100 Source GLSL 460 SourceExtension "GL_EXT_ray_tracing" Name 4 "main" diff --git a/Test/baseResults/spv.ext.IntersectShader.rint.out b/Test/baseResults/spv.ext.IntersectShader.rint.out index b8b8de22..f28b0546 100644 --- a/Test/baseResults/spv.ext.IntersectShader.rint.out +++ b/Test/baseResults/spv.ext.IntersectShader.rint.out @@ -1,5 +1,5 @@ spv.ext.IntersectShader.rint -// Module Version 10000 +// Module Version 10400 // Generated by (magic number): 80008 // Id's are bound by 81 @@ -7,7 +7,7 @@ spv.ext.IntersectShader.rint Extension "SPV_KHR_ray_tracing" 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint IntersectionKHR 4 "main" 11 14 20 23 26 33 36 39 42 47 50 56 59 65 69 + EntryPoint IntersectionKHR 4 "main" 11 14 20 23 26 33 36 39 42 47 50 56 59 65 69 73 Source GLSL 460 SourceExtension "GL_EXT_ray_tracing" Name 4 "main" diff --git a/Test/baseResults/spv.ext.MissShader.rmiss.out b/Test/baseResults/spv.ext.MissShader.rmiss.out index dd3f15f1..dbd6a2f1 100644 --- a/Test/baseResults/spv.ext.MissShader.rmiss.out +++ b/Test/baseResults/spv.ext.MissShader.rmiss.out @@ -1,5 +1,5 @@ spv.ext.MissShader.rmiss -// Module Version 10000 +// Module Version 10400 // Generated by (magic number): 80008 // Id's are bound by 54 @@ -7,7 +7,7 @@ spv.ext.MissShader.rmiss Extension "SPV_KHR_ray_tracing" 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint MissKHR 4 "main" 11 14 21 24 29 32 + EntryPoint MissKHR 4 "main" 11 14 21 24 29 32 36 51 53 Source GLSL 460 SourceExtension "GL_EXT_ray_tracing" Name 4 "main" diff --git a/Test/baseResults/spv.ext.RayCallable.rcall.out b/Test/baseResults/spv.ext.RayCallable.rcall.out index ac3b2b53..4d9aba71 100644 --- a/Test/baseResults/spv.ext.RayCallable.rcall.out +++ b/Test/baseResults/spv.ext.RayCallable.rcall.out @@ -1,5 +1,5 @@ spv.ext.RayCallable.rcall -// Module Version 10000 +// Module Version 10400 // Generated by (magic number): 80008 // Id's are bound by 30 @@ -7,7 +7,7 @@ spv.ext.RayCallable.rcall Extension "SPV_KHR_ray_tracing" 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint CallableKHR 4 "main" 11 14 + EntryPoint CallableKHR 4 "main" 11 14 18 29 Source GLSL 460 SourceExtension "GL_EXT_ray_tracing" Name 4 "main" diff --git a/Test/baseResults/spv.ext.RayConstants.rgen.out b/Test/baseResults/spv.ext.RayConstants.rgen.out index 5903ec93..5094823d 100644 --- a/Test/baseResults/spv.ext.RayConstants.rgen.out +++ b/Test/baseResults/spv.ext.RayConstants.rgen.out @@ -1,5 +1,5 @@ spv.ext.RayConstants.rgen -// Module Version 10000 +// Module Version 10400 // Generated by (magic number): 80008 // Id's are bound by 27 @@ -7,7 +7,7 @@ spv.ext.RayConstants.rgen Extension "SPV_KHR_ray_tracing" 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint RayGenerationKHR 4 "main" + EntryPoint RayGenerationKHR 4 "main" 8 26 Source GLSL 460 SourceExtension "GL_EXT_ray_tracing" Name 4 "main" diff --git a/Test/baseResults/spv.ext.RayGenShader.rgen.out b/Test/baseResults/spv.ext.RayGenShader.rgen.out index da16fa45..b2332009 100644 --- a/Test/baseResults/spv.ext.RayGenShader.rgen.out +++ b/Test/baseResults/spv.ext.RayGenShader.rgen.out @@ -1,5 +1,5 @@ spv.ext.RayGenShader.rgen -// Module Version 10000 +// Module Version 10400 // Generated by (magic number): 80008 // Id's are bound by 58 @@ -8,7 +8,7 @@ spv.ext.RayGenShader.rgen Extension "SPV_KHR_ray_tracing" 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint RayGenerationKHR 4 "main" 11 21 + EntryPoint RayGenerationKHR 4 "main" 11 21 29 40 51 54 57 Source GLSL 460 SourceExtension "GL_EXT_ray_flags_primitive_culling" SourceExtension "GL_EXT_ray_tracing" @@ -33,7 +33,7 @@ spv.ext.RayGenShader.rgen Decorate 29(accEXT0) Binding 0 MemberDecorate 38(block) 0 Offset 0 MemberDecorate 38(block) 1 Offset 16 - Decorate 38(block) BufferBlock + Decorate 38(block) Block Decorate 51(accEXT1) DescriptorSet 0 Decorate 51(accEXT1) Binding 1 Decorate 54(imageu) DescriptorSet 0 diff --git a/Test/baseResults/spv.ext.RayGenShader11.rgen.out b/Test/baseResults/spv.ext.RayGenShader11.rgen.out index 30ed902b..36c7215e 100644 --- a/Test/baseResults/spv.ext.RayGenShader11.rgen.out +++ b/Test/baseResults/spv.ext.RayGenShader11.rgen.out @@ -1,5 +1,5 @@ spv.ext.RayGenShader11.rgen -// Module Version 10000 +// Module Version 10400 // Generated by (magic number): 80008 // Id's are bound by 53 @@ -7,7 +7,7 @@ spv.ext.RayGenShader11.rgen Extension "SPV_KHR_ray_tracing" 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint RayGenerationKHR 4 "main" 11 21 + EntryPoint RayGenerationKHR 4 "main" 11 21 29 39 52 Source GLSL 460 SourceExtension "GL_EXT_ray_tracing" Name 4 "main" @@ -29,7 +29,7 @@ spv.ext.RayGenShader11.rgen Decorate 29(accEXT) Binding 0 MemberDecorate 37(block) 0 Offset 0 MemberDecorate 37(block) 1 Offset 16 - Decorate 37(block) BufferBlock + Decorate 37(block) Block Decorate 52(payload) Location 0 2: TypeVoid 3: TypeFunction 2 diff --git a/Test/baseResults/spv.ext.RayGenShaderArray.rgen.out b/Test/baseResults/spv.ext.RayGenShaderArray.rgen.out index 3962bcb8..8769fbdc 100644 --- a/Test/baseResults/spv.ext.RayGenShaderArray.rgen.out +++ b/Test/baseResults/spv.ext.RayGenShaderArray.rgen.out @@ -1,5 +1,5 @@ spv.ext.RayGenShaderArray.rgen -// Module Version 10000 +// Module Version 10400 // Generated by (magic number): 80008 // Id's are bound by 89 @@ -10,7 +10,7 @@ spv.ext.RayGenShaderArray.rgen Extension "SPV_KHR_ray_tracing" 1: ExtInstImport "GLSL.std.450" MemoryModel Logical GLSL450 - EntryPoint RayGenerationKHR 4 "main" 11 21 + EntryPoint RayGenerationKHR 4 "main" 11 21 30 36 60 88 Source GLSL 460 SourceExtension "GL_EXT_nonuniform_qualifier" SourceExtension "GL_EXT_ray_tracing" @@ -36,7 +36,7 @@ spv.ext.RayGenShaderArray.rgen MemberDecorate 34(block) 0 Offset 0 MemberDecorate 34(block) 1 Offset 16 MemberDecorate 34(block) 2 Offset 28 - Decorate 34(block) BufferBlock + Decorate 34(block) Block Decorate 60(accEXT1) DescriptorSet 0 Decorate 60(accEXT1) Binding 1 Decorate 75 DecorationNonUniformEXT diff --git a/glslang/MachineIndependent/Versions.cpp b/glslang/MachineIndependent/Versions.cpp index 143f2516..d4dad8ac 100644 --- a/glslang/MachineIndependent/Versions.cpp +++ b/glslang/MachineIndependent/Versions.cpp @@ -64,6 +64,7 @@ // checkDeprecated() // requireNotRemoved() // requireExtensions() +// extensionRequires() // // Typically, only the first two calls are needed. They go into a code path that // implements Feature F, and will log the proper error/warning messages. Parsing @@ -78,9 +79,11 @@ // const char* const XXX_extension_X = "XXX_extension_X"; // // 2) Add extension initialization to TParseVersions::initializeExtensionBehavior(), -// the first function below: +// the first function below and optionally a entry to extensionData for additional +// error checks: // // extensionBehavior[XXX_extension_X] = EBhDisable; +// (Optional) exts[] = {XXX_extension_X, EShTargetSpv_1_4} // // 3) Add any preprocessor directives etc. in the next function, TParseVersions::getPreamble(): // @@ -140,6 +143,8 @@ // set of extensions that both enable them and are necessary, given the version of the symbol // table. (There is a different symbol table for each version.) // +// 7) If the extension has additional requirements like minimum SPIR-V version required, add them +// to extensionRequires() #include "parseVersions.h" #include "localintermediate.h" @@ -155,6 +160,20 @@ namespace glslang { // void TParseVersions::initializeExtensionBehavior() { + typedef struct { + const char *const extensionName; + EShTargetLanguageVersion minSpvVersion; + } extensionData; + + const extensionData exts[] = { {E_GL_EXT_ray_tracing, EShTargetSpv_1_4} }; + + for (int ii = 0; ii < sizeof(exts) / sizeof(exts[0]); ii++) { + // Add only extensions which require > spv1.0 to save space in map + if (exts[ii].minSpvVersion > EShTargetSpv_1_0) { + extensionMinSpv[E_GL_EXT_ray_tracing] = exts[ii].minSpvVersion; + } + } + extensionBehavior[E_GL_OES_texture_3D] = EBhDisable; extensionBehavior[E_GL_OES_standard_derivatives] = EBhDisable; extensionBehavior[E_GL_EXT_frag_depth] = EBhDisable; @@ -329,6 +348,7 @@ void TParseVersions::initializeExtensionBehavior() extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_int64] = EBhDisable; extensionBehavior[E_GL_EXT_shader_subgroup_extended_types_float16] = EBhDisable; } + #endif // GLSLANG_WEB // Get code that is not part of a shared symbol table, is specific to this shader, @@ -828,6 +848,9 @@ void TParseVersions::updateExtensionBehavior(int line, const char* extension, co // check if extension is used with correct shader stage checkExtensionStage(getCurrentLoc(), extension); + // check if extension has additional requirements + extensionRequires(getCurrentLoc(), extension ,behaviorString); + // update the requested extension updateExtensionBehavior(extension, behavior); @@ -944,6 +967,24 @@ void TParseVersions::checkExtensionStage(const TSourceLoc& loc, const char * con } } +// Check if extension has additional requirements +void TParseVersions::extensionRequires(const TSourceLoc &loc, const char * const extension, const char *behaviorString) +{ + bool isEnabled = false; + if (!strcmp("require", behaviorString)) + isEnabled = true; + else if (!strcmp("enable", behaviorString)) + isEnabled = true; + + if (isEnabled) { + unsigned int minSpvVersion = 0; + auto iter = extensionMinSpv.find(TString(extension)); + if (iter != extensionMinSpv.end()) + minSpvVersion = iter->second; + requireSpv(loc, extension, minSpvVersion); + } +} + // Call for any operation needing full GLSL integer data-type support. void TParseVersions::fullIntegerCheck(const TSourceLoc& loc, const char* op) { @@ -1201,5 +1242,12 @@ void TParseVersions::requireSpv(const TSourceLoc& loc, const char* op) error(loc, "only allowed when generating SPIR-V", op, ""); #endif } +void TParseVersions::requireSpv(const TSourceLoc& loc, const char *op, unsigned int version) +{ +#ifndef GLSLANG_WEB + if (spvVersion.spv < version) + error(loc, "not supported for current targeted SPIR-V version", op, ""); +#endif +} } // end namespace glslang diff --git a/glslang/MachineIndependent/Versions.h b/glslang/MachineIndependent/Versions.h index c128d464..c90db966 100644 --- a/glslang/MachineIndependent/Versions.h +++ b/glslang/MachineIndependent/Versions.h @@ -36,6 +36,7 @@ // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. // + #ifndef _VERSIONS_INCLUDED_ #define _VERSIONS_INCLUDED_ diff --git a/glslang/MachineIndependent/parseVersions.h b/glslang/MachineIndependent/parseVersions.h index aa1964fc..0d006a71 100644 --- a/glslang/MachineIndependent/parseVersions.h +++ b/glslang/MachineIndependent/parseVersions.h @@ -101,6 +101,7 @@ public: void updateExtensionBehavior(int line, const char* const extension, const char* behavior) { } void updateExtensionBehavior(const char* const extension, TExtensionBehavior) { } void checkExtensionStage(const TSourceLoc&, const char* const extension) { } + void extensionRequires(const TSourceLoc&, const char* const extension, const char* behavior) { } void fullIntegerCheck(const TSourceLoc&, const char* op) { } void doubleCheck(const TSourceLoc&, const char* op) { } bool float16Arithmetic() { return false; } @@ -139,6 +140,7 @@ public: virtual bool checkExtensionsRequested(const TSourceLoc&, int numExtensions, const char* const extensions[], const char* featureDesc); virtual void checkExtensionStage(const TSourceLoc&, const char* const extension); + virtual void extensionRequires(const TSourceLoc&, const char* const extension, const char* behavior); virtual void fullIntegerCheck(const TSourceLoc&, const char* op); virtual void unimplemented(const TSourceLoc&, const char* featureDesc); @@ -170,6 +172,7 @@ public: virtual void vulkanRemoved(const TSourceLoc&, const char* op); virtual void requireVulkan(const TSourceLoc&, const char* op); virtual void requireSpv(const TSourceLoc&, const char* op); + virtual void requireSpv(const TSourceLoc&, const char *op, unsigned int version); #if defined(GLSLANG_WEB) && !defined(GLSLANG_WEB_DEVEL) @@ -222,6 +225,7 @@ public: protected: TMap extensionBehavior; // for each extension string, what its current behavior is set to + TMap extensionMinSpv; // for each extension string, store minimum spirv required EShMessages messages; // errors/warnings/rule-sets int numErrors; // number of compile-time errors encountered TInputScanner* currentScanner; diff --git a/glslang/Public/ShaderLang.h b/glslang/Public/ShaderLang.h index ee23556d..5b63ff7b 100644 --- a/glslang/Public/ShaderLang.h +++ b/glslang/Public/ShaderLang.h @@ -413,6 +413,7 @@ enum TResourceType { EResCount }; + // Make one TShader per shader that you will link into a program. Then // - provide the shader through setStrings() or setStringsWithLengths() // - optionally call setEnv*(), see below for more detail diff --git a/gtests/Spv.FromFile.cpp b/gtests/Spv.FromFile.cpp index 62941a47..bfab4026 100644 --- a/gtests/Spv.FromFile.cpp +++ b/gtests/Spv.FromFile.cpp @@ -329,21 +329,6 @@ INSTANTIATE_TEST_CASE_P( "spv.earlyReturnDiscard.frag", "spv.extPostDepthCoverage.frag", "spv.extPostDepthCoverage_Error.frag", - "spv.ext.AnyHitShader.rahit", - "spv.ext.AnyHitShader_Errors.rahit", - "spv.ext.ClosestHitShader.rchit", - "spv.ext.ClosestHitShader_Errors.rchit", - "spv.ext.IntersectShader.rint", - "spv.ext.IntersectShader_Errors.rint", - "spv.ext.MissShader.rmiss", - "spv.ext.MissShader_Errors.rmiss", - "spv.ext.RayPrimCull_Errors.rgen", - "spv.ext.RayCallable.rcall", - "spv.ext.RayCallable_Errors.rcall", - "spv.ext.RayConstants.rgen", - "spv.ext.RayGenShader.rgen", - "spv.ext.RayGenShader11.rgen", - "spv.ext.RayGenShaderArray.rgen", "spv.float16convertonlyarith.comp", "spv.float16convertonlystorage.comp", "spv.flowControl.frag", @@ -554,6 +539,21 @@ INSTANTIATE_TEST_CASE_P( "spv.1.4.sparseTexture.frag", "spv.1.4.texture.frag", "spv.1.4.constructComposite.comp", + "spv.ext.AnyHitShader.rahit", + "spv.ext.AnyHitShader_Errors.rahit", + "spv.ext.ClosestHitShader.rchit", + "spv.ext.ClosestHitShader_Errors.rchit", + "spv.ext.IntersectShader.rint", + "spv.ext.IntersectShader_Errors.rint", + "spv.ext.MissShader.rmiss", + "spv.ext.MissShader_Errors.rmiss", + "spv.ext.RayPrimCull_Errors.rgen", + "spv.ext.RayCallable.rcall", + "spv.ext.RayCallable_Errors.rcall", + "spv.ext.RayConstants.rgen", + "spv.ext.RayGenShader.rgen", + "spv.ext.RayGenShader11.rgen", + "spv.ext.RayGenShaderArray.rgen", })), FileNameAsCustomTestSuffix );