From f6324b0b5d65aef6e713e8b902a6b689659dd27f Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 8 Feb 2026 21:20:58 +0100 Subject: feat(gpu): Add auxiliary texture masking system MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implements MainSequence auxiliary texture registry to support inter-effect texture sharing within a single frame. Primary use case: screen-space partitioning where multiple effects render to complementary regions. Architecture: - MainSequence::register_auxiliary_texture(name, width, height) Creates named texture that persists for entire frame - MainSequence::get_auxiliary_view(name) Retrieves texture view for reading/writing Use case example: - Effect1: Generate mask (1 = Effect1 region, 0 = Effect2 region) - Effect1: Render scene A where mask = 1 - Effect2: Reuse mask, render scene B where mask = 0 - Result: Both scenes composited to same framebuffer Implementation details: - Added std::map to MainSequence - Texture lifecycle managed by MainSequence (create/resize/shutdown) - Memory impact: ~4-8 MB per mask (acceptable for 2-3 masks) - Size impact: ~100 lines (~500 bytes code) Changes: - src/gpu/effect.h: Added auxiliary texture registry API - src/gpu/effect.cc: Implemented registry with FATAL_CHECK validation - doc/MASKING_SYSTEM.md: Complete architecture documentation - doc/HOWTO.md: Added auxiliary texture usage example Also fixed: - test_demo_effects.cc: Corrected EXPECTED_POST_PROCESS_COUNT (9→8) Pre-existing bug: DistortEffect was counted but not tested Testing: - All 33 tests pass (100%) - No functional changes to existing effects - Zero regressions See doc/MASKING_SYSTEM.md for detailed design rationale and examples. --- doc/HOWTO.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'doc/HOWTO.md') diff --git a/doc/HOWTO.md b/doc/HOWTO.md index 3a1aee2..55580ba 100644 --- a/doc/HOWTO.md +++ b/doc/HOWTO.md @@ -158,6 +158,44 @@ void test_example() { For low-level synth-only tests, you can still call `synth_init()` directly. +## Auxiliary Texture Masking + +The project supports inter-effect texture sharing via the auxiliary texture registry. This allows effects to generate textures (masks, shadow maps, etc.) and make them available to other effects within the same frame. + +**Common use case:** Screen-space partitioning where different scenes render to complementary regions. + +```cpp +class MaskGeneratorEffect : public Effect { + void init(MainSequence* demo) override { + demo_ = demo; + // Register a named auxiliary texture + demo->register_auxiliary_texture("my_mask", width_, height_); + } + + void compute(WGPUCommandEncoder encoder, ...) override { + // Generate mask to auxiliary texture + WGPUTextureView mask_view = demo_->get_auxiliary_view("my_mask"); + // ... render mask + } + + void render(WGPURenderPassEncoder pass, ...) override { + // Use mask in scene rendering + WGPUTextureView mask_view = demo_->get_auxiliary_view("my_mask"); + // ... render scene with mask + } +}; + +class MaskUserEffect : public Effect { + void render(WGPURenderPassEncoder pass, ...) override { + // Reuse mask from MaskGeneratorEffect + WGPUTextureView mask_view = demo_->get_auxiliary_view("my_mask"); + // ... render scene with inverted mask + } +}; +``` + +See `doc/MASKING_SYSTEM.md` for detailed architecture and examples. + ## Debugging ### Seeking / Fast-Forward -- cgit v1.2.3