summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-03-10 09:28:08 +0100
committerskal <pascal.massimino@gmail.com>2026-03-10 09:28:08 +0100
commitef205b6eda78f1dcf65aa696dedf1f8c0707ff30 (patch)
tree4e8512b0e9eb34aa56c01dfa667fd68e07050e93
parente10eea9d89440c9494c86433c15baaca58705ffd (diff)
fix: use ShaderComposer in RotatingCube; add rule to CODING_STYLE
rotating_cube_effect.cc was bypassing ShaderComposer, causing #include directives in rotating_cube.wgsl to fail at runtime. handoff(Claude): ShaderComposer rule documented and enforced in rotating_cube. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
-rw-r--r--doc/CODING_STYLE.md18
-rw-r--r--src/effects/rotating_cube_effect.cc4
2 files changed, 21 insertions, 1 deletions
diff --git a/doc/CODING_STYLE.md b/doc/CODING_STYLE.md
index 7d45027..6ef7326 100644
--- a/doc/CODING_STYLE.md
+++ b/doc/CODING_STYLE.md
@@ -166,6 +166,24 @@ Three-line header for all source files.
## WGSL Shader Style
+### Always Use ShaderComposer (Required)
+
+**Rule:** Always load `.wgsl` shaders via `ShaderComposer::Get().Compose(...)`, even if the shader has no `#include` directives. Never pass the raw shader string directly to `wgpuDeviceCreateShaderModule`.
+
+```cpp
+// Correct
+const std::string src = ShaderComposer::Get().Compose({}, my_shader_wgsl);
+WGPUShaderSourceWGSL wgsl_src = {};
+wgsl_src.code = str_view(src);
+
+// Wrong - bypasses #include resolution
+wgsl_src.code = str_view(my_shader_wgsl);
+```
+
+**Rationale:** Shaders may gain `#include` directives later; bypassing `ShaderComposer` silently breaks them at runtime with no compile error.
+
+---
+
### File Header (Required)
Every `.wgsl` file must start with a 2-line comment header:
diff --git a/src/effects/rotating_cube_effect.cc b/src/effects/rotating_cube_effect.cc
index 197bc26..6ee3e85 100644
--- a/src/effects/rotating_cube_effect.cc
+++ b/src/effects/rotating_cube_effect.cc
@@ -6,6 +6,7 @@
#include "gpu/bind_group_builder.h"
#include "gpu/gpu.h"
#include "gpu/post_process_helper.h"
+#include "gpu/shader_composer.h"
#include "util/fatal_error.h"
RotatingCube::RotatingCube(const GpuContext& ctx,
@@ -43,9 +44,10 @@ RotatingCube::RotatingCube(const GpuContext& ctx,
wgpuDeviceCreatePipelineLayout(ctx_.device, &pl_desc);
// Load shader
+ const std::string composed = ShaderComposer::Get().Compose({}, rotating_cube_wgsl);
WGPUShaderSourceWGSL wgsl_src = {};
wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL;
- wgsl_src.code = str_view(rotating_cube_wgsl);
+ wgsl_src.code = str_view(composed.c_str());
WGPUShaderModuleDescriptor shader_desc = {};
shader_desc.nextInChain = &wgsl_src.chain;