From 75bdd2f8c17169422d175ed2d9dfceb9acb0fe77 Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 6 Feb 2026 02:14:30 +0100 Subject: refactor(gpu): Implement compile-time BVH toggle via shader composition Completed Task #18-B optimization and refactoring. - Replaced runtime branching in shader with compile-time snippet substitution in ShaderComposer. - Added 'scene_query_bvh.wgsl' and 'scene_query_linear.wgsl' as distinct snippets. - Refactored Renderer3D to manage two separate pipelines (with and without BVH). - Updated ShaderComposer to support snippet substitution during composition. - Verified both paths with test_3d_render (default and --no-bvh). - Removed temporary shader hacks and cleaned up renderer_3d.wgsl. --- src/gpu/effects/shader_composer.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/gpu/effects/shader_composer.h') diff --git a/src/gpu/effects/shader_composer.h b/src/gpu/effects/shader_composer.h index a63a6a4..9eb43f4 100644 --- a/src/gpu/effects/shader_composer.h +++ b/src/gpu/effects/shader_composer.h @@ -15,16 +15,21 @@ class ShaderComposer { // Register a snippet (e.g. "common_math", "sdf_primitives") void RegisterSnippet(const std::string& name, const std::string& code); + using CompositionMap = std::map; + // Assemble a final shader string by prepending required snippets // and recursively resolving #include "snippet_name" directives. + // Optional substitutions: map "placeholder_name" -> "actual_snippet_name" std::string Compose(const std::vector& dependencies, - const std::string& main_code); + const std::string& main_code, + const CompositionMap& substitutions = {}); private: ShaderComposer() = default; void ResolveRecursive(const std::string& source, std::stringstream& ss, - std::set& included); + std::set& included, + const CompositionMap& substitutions); std::map snippets_; }; -- cgit v1.2.3