diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-04 11:56:03 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-04 11:56:03 +0100 |
| commit | 2e34965e5e48175c5ee6016af1a858f7f3f02c1d (patch) | |
| tree | a41ea2fdc50a18183742bffaf0705b394f2be69f /src/3d/renderer.cc | |
| parent | 0d29f340b9de8f6a14baa0a2c6f3c57b8d1458a5 (diff) | |
feat(gpu): Implement recursive WGSL composition and modularize shaders (Task #50)
- Updated ShaderComposer to support recursive #include "snippet_name" with cycle detection.
- Extracted granular WGSL snippets: math/sdf_shapes, math/sdf_utils, render/shadows, render/scene_query, render/lighting_utils.
- Refactored Renderer3D to use #include in shaders, simplifying C++ dependency lists.
- Fixed WGPUShaderSourceWGSL usage on macOS to correctly handle composed shader strings.
- Added comprehensive unit tests for recursive composition in test_shader_composer.
- Verified system stability with test_3d_render and full test suite.
- Marked Task #50 as recurrent for future code hygiene.
Diffstat (limited to 'src/3d/renderer.cc')
| -rw-r--r-- | src/3d/renderer.cc | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/3d/renderer.cc b/src/3d/renderer.cc index 778509f..e4320f4 100644 --- a/src/3d/renderer.cc +++ b/src/3d/renderer.cc @@ -66,8 +66,8 @@ void Renderer3D::create_skybox_pipeline() { const uint8_t* shader_code_asset = GetAsset(AssetId::ASSET_SHADER_SKYBOX, nullptr); - std::string shader_source = ShaderComposer::Get().Compose( - {"common_uniforms"}, (const char*)shader_code_asset); + std::string shader_source = + ShaderComposer::Get().Compose({}, (const char*)shader_code_asset); #if defined(DEMO_CROSS_COMPILE_WIN32) WGPUShaderModuleWGSLDescriptor wgsl_desc = {}; @@ -78,7 +78,7 @@ void Renderer3D::create_skybox_pipeline() { #else WGPUShaderSourceWGSL wgsl_desc = {}; wgsl_desc.chain.sType = WGPUSType_ShaderSourceWGSL; - wgsl_desc.code = {shader_source.c_str(), shader_source.length()}; + wgsl_desc.code = str_view(shader_source.c_str()); WGPUShaderModuleDescriptor shader_desc = {}; shader_desc.nextInChain = (const WGPUChainedStruct*)&wgsl_desc.chain; #endif @@ -236,10 +236,9 @@ void Renderer3D::create_pipeline() { WGPUPipelineLayout pipeline_layout = wgpuDeviceCreatePipelineLayout(device_, &pl_desc); - std::string main_code = - (const char*)GetAsset(AssetId::ASSET_SHADER_RENDERER_3D); - std::string shader_source = ShaderComposer::Get().Compose( - {"common_uniforms", "sdf_primitives", "lighting", "ray_box"}, main_code); + const char* asset_data = (const char*)GetAsset(AssetId::ASSET_SHADER_RENDERER_3D); + std::string main_code = asset_data; + std::string shader_source = ShaderComposer::Get().Compose({}, main_code); #if defined(DEMO_CROSS_COMPILE_WIN32) WGPUShaderModuleWGSLDescriptor wgsl_desc = {}; @@ -250,7 +249,7 @@ void Renderer3D::create_pipeline() { #else WGPUShaderSourceWGSL wgsl_desc = {}; wgsl_desc.chain.sType = WGPUSType_ShaderSourceWGSL; - wgsl_desc.code = {shader_source.c_str(), shader_source.length()}; + wgsl_desc.code = str_view(shader_source.c_str()); WGPUShaderModuleDescriptor shader_desc = {}; shader_desc.nextInChain = (const WGPUChainedStruct*)&wgsl_desc.chain; #endif |
