diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-11 11:58:24 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-11 11:58:24 +0100 |
| commit | 5ceb0256792053ee80841f2b5ac0dfae1fd4c6f8 (patch) | |
| tree | e24dafeca0d270437a39c8d91c7f5c037cf0d2f4 /src | |
| parent | 58c595810d0346f0c2b32dbc70b7385aee545e11 (diff) | |
fix: Complete auxiliary texture initialization fix
Root cause: After swapping init/resize order, effects with Renderer3D crashed
because resize() called before init() tried to use uninitialized GPU resources.
Changes:
- Add guards in FlashCubeEffect::resize() and Hybrid3DEffect::resize() to
check ctx_.device before calling renderer_.resize()
- Remove lazy initialization remnants from CircleMaskEffect and CNNEffect
- Register auxiliary textures directly in init() (width_/height_ already set)
- Remove ensure_texture() methods and texture_initialized_ flags
All 36 tests passing. Demo runs without crashes.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/gpu/effects/circle_mask_effect.cc | 14 | ||||
| -rw-r--r-- | src/gpu/effects/circle_mask_effect.h | 3 | ||||
| -rw-r--r-- | src/gpu/effects/cnn_effect.cc | 16 | ||||
| -rw-r--r-- | src/gpu/effects/cnn_effect.h | 3 | ||||
| -rw-r--r-- | src/gpu/effects/flash_cube_effect.cc | 10 | ||||
| -rw-r--r-- | src/gpu/effects/hybrid_3d_effect.cc | 10 |
6 files changed, 26 insertions, 30 deletions
diff --git a/src/gpu/effects/circle_mask_effect.cc b/src/gpu/effects/circle_mask_effect.cc index 08a9e33..f34ffb7 100644 --- a/src/gpu/effects/circle_mask_effect.cc +++ b/src/gpu/effects/circle_mask_effect.cc @@ -26,6 +26,9 @@ CircleMaskEffect::~CircleMaskEffect() { void CircleMaskEffect::init(MainSequence* demo) { demo_ = demo; + // Register auxiliary texture (width_/height_ set by resize() before init()) + demo_->register_auxiliary_texture("circle_mask", width_, height_); + compute_params_.init(ctx_.device); // Initialize uniforms BEFORE bind group creation @@ -152,20 +155,13 @@ void CircleMaskEffect::init(MainSequence* demo) { render_bind_group_ = wgpuDeviceCreateBindGroup(ctx_.device, &render_bg_desc); } -void CircleMaskEffect::ensure_texture() { - if (!texture_initialized_ && demo_) { - demo_->register_auxiliary_texture("circle_mask", width_, height_); - texture_initialized_ = true; - } -} - void CircleMaskEffect::resize(int width, int height) { if (width == width_ && height == height_) return; Effect::resize(width, height); - if (!demo_ || !texture_initialized_) + if (!demo_) return; // Resize auxiliary texture @@ -193,8 +189,6 @@ void CircleMaskEffect::resize(int width, int height) { void CircleMaskEffect::compute(WGPUCommandEncoder encoder, const CommonPostProcessUniforms& uniforms) { - ensure_texture(); - uniforms_.update(ctx_.queue, uniforms); const CircleMaskParams params = { diff --git a/src/gpu/effects/circle_mask_effect.h b/src/gpu/effects/circle_mask_effect.h index 91443d8..6ebaca1 100644 --- a/src/gpu/effects/circle_mask_effect.h +++ b/src/gpu/effects/circle_mask_effect.h @@ -29,11 +29,8 @@ class CircleMaskEffect : public Effect { static_assert(sizeof(CircleMaskParams) == 16, "CircleMaskParams must be 16 bytes for WGSL alignment"); - void ensure_texture(); - MainSequence* demo_ = nullptr; float radius_; - bool texture_initialized_ = false; WGPURenderPipeline compute_pipeline_ = nullptr; WGPUBindGroup compute_bind_group_ = nullptr; diff --git a/src/gpu/effects/cnn_effect.cc b/src/gpu/effects/cnn_effect.cc index 8673127..b2305b2 100644 --- a/src/gpu/effects/cnn_effect.cc +++ b/src/gpu/effects/cnn_effect.cc @@ -53,6 +53,11 @@ void CNNEffect::init(MainSequence* demo) { demo_ = demo; params_buffer_.init(ctx_.device); + // Register auxiliary texture for layer 0 (width_/height_ set by resize()) + if (layer_index_ == 0) { + demo_->register_auxiliary_texture("captured_frame", width_, height_); + } + // Initialize uniforms BEFORE any bind group creation uniforms_.update(ctx_.queue, get_common_uniforms()); @@ -60,13 +65,6 @@ void CNNEffect::init(MainSequence* demo) { params_buffer_.update(ctx_.queue, params); } -void CNNEffect::ensure_texture() { - if (!texture_initialized_ && layer_index_ == 0 && demo_) { - demo_->register_auxiliary_texture("captured_frame", width_, height_); - texture_initialized_ = true; - } -} - void CNNEffect::resize(int width, int height) { if (width == width_ && height == height_) return; @@ -74,7 +72,7 @@ void CNNEffect::resize(int width, int height) { PostProcessEffect::resize(width, height); // Only layer 0 owns the captured_frame texture - if (layer_index_ == 0 && demo_ && texture_initialized_) { + if (layer_index_ == 0 && demo_) { demo_->resize_auxiliary_texture("captured_frame", width, height); } } @@ -93,8 +91,6 @@ void CNNEffect::render(WGPURenderPassEncoder pass, } void CNNEffect::update_bind_group(WGPUTextureView input_view) { - ensure_texture(); - input_view_ = input_view; // Update common uniforms (CRITICAL for UV calculation!) diff --git a/src/gpu/effects/cnn_effect.h b/src/gpu/effects/cnn_effect.h index f79fac7..1c9f0f3 100644 --- a/src/gpu/effects/cnn_effect.h +++ b/src/gpu/effects/cnn_effect.h @@ -35,12 +35,9 @@ class CNNEffect : public PostProcessEffect { } private: - void ensure_texture(); - int layer_index_; int total_layers_; float blend_amount_; - bool texture_initialized_ = false; WGPUTextureView input_view_; WGPUTextureView original_view_; UniformBuffer<CNNLayerParams> params_buffer_; diff --git a/src/gpu/effects/flash_cube_effect.cc b/src/gpu/effects/flash_cube_effect.cc index ee25408..fe6b2a7 100644 --- a/src/gpu/effects/flash_cube_effect.cc +++ b/src/gpu/effects/flash_cube_effect.cc @@ -12,8 +12,14 @@ FlashCubeEffect::FlashCubeEffect(const GpuContext& ctx) : Effect(ctx) { } void FlashCubeEffect::resize(int width, int height) { - width_ = width; - height_ = height; + if (width == width_ && height == height_) + return; + + Effect::resize(width, height); + + if (!ctx_.device) + return; + renderer_.resize(width_, height_); } diff --git a/src/gpu/effects/hybrid_3d_effect.cc b/src/gpu/effects/hybrid_3d_effect.cc index d580471..61b3734 100644 --- a/src/gpu/effects/hybrid_3d_effect.cc +++ b/src/gpu/effects/hybrid_3d_effect.cc @@ -12,8 +12,14 @@ Hybrid3DEffect::Hybrid3DEffect(const GpuContext& ctx) : Effect(ctx) { } void Hybrid3DEffect::resize(int width, int height) { - width_ = width; - height_ = height; + if (width == width_ && height == height_) + return; + + Effect::resize(width, height); + + if (!ctx_.device) + return; + renderer_.resize(width_, height_); } |
