From b96e0ef63a7b5db7c3cf7c40d0ac509b3ee01eed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Delgado=20Kr=C3=A4mer?= Date: Sat, 3 Aug 2024 19:30:10 +0200 Subject: [PATCH] gi: enable GLSL extensions using macros rather than generate new code --- src/gi/impl/Gi.cpp | 2 +- src/gi/impl/GlslShaderGen.cpp | 10 ++-------- src/gi/impl/GlslShaderGen.h | 2 +- src/gi/impl/GlslStitcher.cpp | 5 ----- src/gi/impl/GlslStitcher.h | 2 -- src/gi/shaders/rp_main.rgen | 9 +++++++++ 6 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/gi/impl/Gi.cpp b/src/gi/impl/Gi.cpp index 9d3f4874..06aafff3 100644 --- a/src/gi/impl/Gi.cpp +++ b/src/gi/impl/Gi.cpp @@ -1196,7 +1196,7 @@ namespace gtl .nextEventEstimation = nextEventEstimation, .progressiveAccumulation = params.progressiveAccumulation, .reorderInvocations = s_deviceFeatures.rayTracingInvocationReorder, - .shaderClockExts = clockCyclesAov + .shaderClockExt = clockCyclesAov }; std::vector spv; diff --git a/src/gi/impl/GlslShaderGen.cpp b/src/gi/impl/GlslShaderGen.cpp index 99bc070b..8d3341af 100644 --- a/src/gi/impl/GlslShaderGen.cpp +++ b/src/gi/impl/GlslShaderGen.cpp @@ -74,18 +74,12 @@ namespace gtl GiGlslStitcher stitcher; stitcher.appendVersion(); - if (params.shaderClockExts) + if (params.shaderClockExt) { - stitcher.appendRequiredExtension("GL_EXT_shader_explicit_arithmetic_types_int64"); - stitcher.appendRequiredExtension("GL_ARB_shader_clock"); + stitcher.appendDefine("REQUIRE_CLOCK"); } if (params.reorderInvocations) { - stitcher.appendRequiredExtension("GL_NV_shader_invocation_reorder"); - // For hit shader invocation reordering hint - stitcher.appendRequiredExtension("GL_EXT_buffer_reference"); - stitcher.appendRequiredExtension("GL_EXT_buffer_reference_uvec2"); - uint32_t reoderHintValueCount = params.materialCount + 1/* no hit */; int32_t reorderHintBitCount = 0; diff --git a/src/gi/impl/GlslShaderGen.h b/src/gi/impl/GlslShaderGen.h index 049a03d1..dcdfcae7 100644 --- a/src/gi/impl/GlslShaderGen.h +++ b/src/gi/impl/GlslShaderGen.h @@ -72,7 +72,7 @@ namespace gtl bool nextEventEstimation; bool progressiveAccumulation; bool reorderInvocations; - bool shaderClockExts; + bool shaderClockExt; }; struct MissShaderParams diff --git a/src/gi/impl/GlslStitcher.cpp b/src/gi/impl/GlslStitcher.cpp index a8789ffe..9ba53a91 100644 --- a/src/gi/impl/GlslStitcher.cpp +++ b/src/gi/impl/GlslStitcher.cpp @@ -67,11 +67,6 @@ namespace gtl m_source << "#define " << name << " " << value << "\n"; } - void GiGlslStitcher::appendRequiredExtension(std::string_view name) - { - m_source << "#extension " << name << ": require\n"; - } - void GiGlslStitcher::appendString(std::string_view value) { m_source << value; diff --git a/src/gi/impl/GlslStitcher.h b/src/gi/impl/GlslStitcher.h index 2a98c616..f2d0a9cc 100644 --- a/src/gi/impl/GlslStitcher.h +++ b/src/gi/impl/GlslStitcher.h @@ -37,8 +37,6 @@ namespace gtl void appendDefine(std::string_view name, int32_t value); void appendDefine(std::string_view name, float value); - void appendRequiredExtension(std::string_view name); - void appendString(std::string_view value); bool appendSourceFile(fs::path path); diff --git a/src/gi/shaders/rp_main.rgen b/src/gi/shaders/rp_main.rgen index 925e1ace..5de30725 100644 --- a/src/gi/shaders/rp_main.rgen +++ b/src/gi/shaders/rp_main.rgen @@ -6,8 +6,17 @@ #extension GL_EXT_shader_explicit_arithmetic_types_int16: require #extension GL_EXT_shader_explicit_arithmetic_types_int64: require #extension GL_EXT_buffer_reference: require + #ifdef REORDER_INVOCATIONS #extension GL_NV_shader_invocation_reorder: require +// For hit shader invocation reordering hint +#extension GL_EXT_buffer_reference: require +#extension GL_EXT_buffer_reference_uvec2: require +#endif + +#ifdef REQUIRE_CLOCK +#extension GL_EXT_shader_explicit_arithmetic_types_int64: require +#extension GL_ARB_shader_clock: require #endif #include "rp_main_payload.glsl"