diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/gpu/effect.cc | 66 | ||||
| -rw-r--r-- | src/gpu/effect.h | 14 | ||||
| -rw-r--r-- | src/tests/test_demo_effects.cc | 2 |
3 files changed, 81 insertions, 1 deletions
diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc index df8ef2d..c2c36b4 100644 --- a/src/gpu/effect.cc +++ b/src/gpu/effect.cc @@ -5,6 +5,7 @@ #include "audio/tracker.h" #include "gpu/demo_effects.h" #include "gpu/gpu.h" +#include "util/fatal_error.h" #include <algorithm> #include <cstdio> #include <typeinfo> @@ -378,11 +379,76 @@ void MainSequence::shutdown() { wgpuTextureViewRelease(depth_view_); if (depth_texture_) wgpuTextureRelease(depth_texture_); + for (auto& [name, aux] : auxiliary_textures_) { + if (aux.view) + wgpuTextureViewRelease(aux.view); + if (aux.texture) + wgpuTextureRelease(aux.texture); + } + auxiliary_textures_.clear(); for (ActiveSequence& entry : sequences_) { entry.seq->reset(); } } +// Register a named auxiliary texture for inter-effect sharing +void MainSequence::register_auxiliary_texture(const char* name, int width, + int height) { + const std::string key(name); + + // Check if already exists + auto it = auxiliary_textures_.find(key); + if (it != auxiliary_textures_.end()) { +#if !defined(STRIP_ALL) + fprintf(stderr, "Warning: Auxiliary texture '%s' already registered\n", + name); +#endif /* !defined(STRIP_ALL) */ + return; + } + + // Create texture + const WGPUTextureDescriptor desc = { + .usage = + WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_TextureBinding, + .dimension = WGPUTextureDimension_2D, + .size = {(uint32_t)width, (uint32_t)height, 1}, + .format = gpu_ctx.format, + .mipLevelCount = 1, + .sampleCount = 1, + }; + + WGPUTexture texture = wgpuDeviceCreateTexture(gpu_ctx.device, &desc); + FATAL_CHECK(!texture, "Failed to create auxiliary texture: %s\n", name); + + // Create view + const WGPUTextureViewDescriptor view_desc = { + .format = gpu_ctx.format, + .dimension = WGPUTextureViewDimension_2D, + .mipLevelCount = 1, + .arrayLayerCount = 1, + }; + + WGPUTextureView view = wgpuTextureCreateView(texture, &view_desc); + FATAL_CHECK(!view, "Failed to create auxiliary texture view: %s\n", name); + + // Store in registry + auxiliary_textures_[key] = {texture, view, width, height}; + +#if !defined(STRIP_ALL) + printf("[MainSequence] Registered auxiliary texture '%s' (%dx%d)\n", name, + width, height); +#endif /* !defined(STRIP_ALL) */ +} + +// Retrieve auxiliary texture view by name +WGPUTextureView MainSequence::get_auxiliary_view(const char* name) { + const std::string key(name); + auto it = auxiliary_textures_.find(key); + FATAL_CHECK(it == auxiliary_textures_.end(), + "Auxiliary texture not found: %s\n", name); + return it->second.view; +} + #if !defined(STRIP_ALL) void MainSequence::simulate_until(float target_time, float step_rate, float bpm) { diff --git a/src/gpu/effect.h b/src/gpu/effect.h index 6ed2c55..6fdb0f4 100644 --- a/src/gpu/effect.h +++ b/src/gpu/effect.h @@ -1,7 +1,9 @@ #pragma once #include "gpu/gpu.h" #include <algorithm> +#include <map> #include <memory> +#include <string> #include <vector> class MainSequence; @@ -112,6 +114,10 @@ class MainSequence { void resize(int width, int height); void shutdown(); + // Auxiliary texture registry for inter-effect texture sharing + void register_auxiliary_texture(const char* name, int width, int height); + WGPUTextureView get_auxiliary_view(const char* name); + #if !defined(STRIP_ALL) void simulate_until(float target_time, float step_rate, float bpm = 120.0f); #endif /* !defined(STRIP_ALL) */ @@ -139,5 +145,13 @@ class MainSequence { std::unique_ptr<Effect> passthrough_effect_; + struct AuxiliaryTexture { + WGPUTexture texture; + WGPUTextureView view; + int width; + int height; + }; + std::map<std::string, AuxiliaryTexture> auxiliary_textures_; + void create_framebuffers(int width, int height); }; diff --git a/src/tests/test_demo_effects.cc b/src/tests/test_demo_effects.cc index 7dbf700..cf77c13 100644 --- a/src/tests/test_demo_effects.cc +++ b/src/tests/test_demo_effects.cc @@ -13,7 +13,7 @@ // Expected effect counts - UPDATE THESE when adding new effects! static constexpr int EXPECTED_POST_PROCESS_COUNT = - 9; // FlashEffect, PassthroughEffect, GaussianBlurEffect, + 8; // FlashEffect, PassthroughEffect, GaussianBlurEffect, // ChromaAberrationEffect, SolarizeEffect, FadeEffect, // ThemeModulationEffect, VignetteEffect static constexpr int EXPECTED_SCENE_COUNT = |
