diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-09 15:25:57 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-09 15:25:57 +0100 |
| commit | c784f8e1472991b8f4c35136b3468f3bfc6c37a7 (patch) | |
| tree | 24cb5564eec22ccacc3b46f741f2e915086b757f | |
| parent | 1fa811727d674d2ebcd8d46661642e2c4b4c0a34 (diff) | |
docs: Add sub-task for type-safe shader composition
Low priority task to prevent recurrent error of forgetting to call
ShaderComposer::Compose() by using strong typing (ComposedShader class).
Would make it a compile-time error instead of runtime crash.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
| -rw-r--r-- | TODO.md | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -93,6 +93,34 @@ This file tracks prioritized tasks with detailed attack plans. - **Impact**: Minimal (most shaders only use CommonUniforms anyway) - **Priority**: Low (nice-to-have for code organization) +### Sub-task: Type-safe shader composition (Low Priority) +- **Problem**: Recurrent error of forgetting `ShaderComposer::Get().Compose({}, code)` and using raw `code` directly + - Happened in: `create_post_process_pipeline`, `gpu_create_render_pass`, `gpu_create_compute_pass`, `CircleMaskEffect` + - Runtime error only (crashes demo, but tests may pass) +- **Solution**: Use strong typing to make it a compile-time error + ```cpp + class ComposedShader { + private: + std::string code_; + friend class ShaderComposer; + explicit ComposedShader(std::string code) : code_(std::move(code)) {} + public: + const char* c_str() const { return code_.c_str(); } + }; + ``` +- **Changes needed**: + - `ShaderComposer::Compose()` returns `ComposedShader` instead of `std::string` + - All shader creation functions take `const ComposedShader&` instead of `const char*` + - Cannot pass raw string to shader functions (compile error) +- **Benefits**: + - Impossible to forget composition (type mismatch) + - Self-documenting API (signature shows shader must be composed) + - Catches errors at compile-time instead of runtime +- **Trade-offs**: + - More verbose code (`auto shader = ShaderComposer::Get().Compose(...)`) + - Small overhead (extra std::string copy, but negligible) +- **Priority**: Low (recurrent but rare, easy to catch in testing) + ## Phase 2: Size Optimization (Final Goal) - [ ] **Task #34: Full STL Removal**: Replace all remaining `std::vector`, `std::map`, and `std::string` usage with custom minimal containers or C-style arrays to allow for CRT replacement. (Minimal Priority - deferred to end). |
