diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-07 17:04:56 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-07 17:04:56 +0100 |
| commit | bd939acdf750181ef0e1a612b445da4c15077c85 (patch) | |
| tree | 028401c762b0436d9a5de1aa656ab35ba6445674 /src/gpu/effect.cc | |
| parent | f2963ac821a3af1c54002ba13944552166956d04 (diff) | |
refactor: Bundle GPU context into GpuContext struct
- Created GpuContext struct {device, queue, format}
- Updated Effect/PostProcessEffect to take const GpuContext&
- Updated all 19 effect implementations
- Updated MainSequence.init() and LoadTimeline() signatures
- Updated generated timeline files
- Updated all test files
- Added gpu_get_context() accessor and fixture.ctx() helper
Fixes test_mesh.cc compilation error from g_device/g_queue/g_format conflicts.
All targets build successfully.
Diffstat (limited to 'src/gpu/effect.cc')
| -rw-r--r-- | src/gpu/effect.cc | 35 |
1 files changed, 15 insertions, 20 deletions
diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc index b95c4ce..ea5230d 100644 --- a/src/gpu/effect.cc +++ b/src/gpu/effect.cc @@ -117,16 +117,16 @@ void MainSequence::create_framebuffers(int width, int height) { WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_TextureBinding; desc.dimension = WGPUTextureDimension_2D; desc.size = {(uint32_t)width, (uint32_t)height, 1}; - desc.format = format; + desc.format = gpu_ctx.format; desc.mipLevelCount = 1; desc.sampleCount = 1; - framebuffer_a_ = wgpuDeviceCreateTexture(device, &desc); - framebuffer_b_ = wgpuDeviceCreateTexture(device, &desc); + framebuffer_a_ = wgpuDeviceCreateTexture(gpu_ctx.device, &desc); + framebuffer_b_ = wgpuDeviceCreateTexture(gpu_ctx.device, &desc); WGPUTextureViewDescriptor view_desc = {}; view_desc.dimension = WGPUTextureViewDimension_2D; - view_desc.format = format; + view_desc.format = gpu_ctx.format; view_desc.mipLevelCount = 1; view_desc.arrayLayerCount = 1; @@ -141,7 +141,7 @@ void MainSequence::create_framebuffers(int width, int height) { depth_desc.format = WGPUTextureFormat_Depth24Plus; depth_desc.mipLevelCount = 1; depth_desc.sampleCount = 1; - depth_texture_ = wgpuDeviceCreateTexture(device, &depth_desc); + depth_texture_ = wgpuDeviceCreateTexture(gpu_ctx.device, &depth_desc); WGPUTextureViewDescriptor depth_view_desc = {}; depth_view_desc.format = WGPUTextureFormat_Depth24Plus; @@ -152,25 +152,20 @@ void MainSequence::create_framebuffers(int width, int height) { depth_view_ = wgpuTextureCreateView(depth_texture_, &depth_view_desc); } -void MainSequence::init_test(WGPUDevice d, WGPUQueue q, WGPUTextureFormat f) { - device = d; - queue = q; - format = f; +void MainSequence::init_test(const GpuContext& ctx) { + gpu_ctx = ctx; // No framebuffers or passthrough effect created in test mode. // Test effects should not rely on these being real. } -void MainSequence::init(WGPUDevice d, WGPUQueue q, WGPUTextureFormat f, - int width, int height) { - device = d; - queue = q; - format = f; +void MainSequence::init(const GpuContext& ctx, int width, int height) { + gpu_ctx = ctx; width_ = width; height_ = height; create_framebuffers(width, height); passthrough_effect_ = - std::make_unique<PassthroughEffect>(device, queue, format); + std::make_unique<PassthroughEffect>(gpu_ctx); passthrough_effect_->resize(width, height); for (ActiveSequence& entry : sequences_) { @@ -183,7 +178,7 @@ void MainSequence::add_sequence(std::shared_ptr<Sequence> seq, float start_time, int priority) { sequences_.push_back({seq, start_time, priority}); // If MainSequence is already initialized, init the new sequence immediately - if (device) { + if (gpu_ctx.device) { seq->init(this); seq->resize(width_, height_); } @@ -225,7 +220,7 @@ void MainSequence::resize(int width, int height) { void MainSequence::render_frame(float global_time, float beat, float peak, float aspect_ratio, WGPUSurface surface) { - WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(device, nullptr); + WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(gpu_ctx.device, nullptr); std::vector<SequenceItem*> scene_effects; std::vector<SequenceItem*> post_effects; @@ -360,7 +355,7 @@ void MainSequence::render_frame(float global_time, float beat, float peak, } WGPUCommandBuffer commands = wgpuCommandEncoderFinish(encoder, nullptr); - wgpuQueueSubmit(queue, 1, &commands); + wgpuQueueSubmit(gpu_ctx.queue, 1, &commands); if (st.texture) { wgpuTextureViewRelease(final_view); @@ -393,7 +388,7 @@ void MainSequence::simulate_until(float target_time, float step_rate) { const float aspect_ratio = 16.0f / 9.0f; for (float t = 0.0f; t < target_time; t += step_rate) { WGPUCommandEncoder encoder = - wgpuDeviceCreateCommandEncoder(device, nullptr); + wgpuDeviceCreateCommandEncoder(gpu_ctx.device, nullptr); float beat = fmodf(t * bpm / 60.0f, 1.0f); std::vector<SequenceItem*> scene_effects, post_effects; for (ActiveSequence& entry : sequences_) { @@ -407,7 +402,7 @@ void MainSequence::simulate_until(float target_time, float step_rate) { aspect_ratio); } WGPUCommandBuffer commands = wgpuCommandEncoderFinish(encoder, nullptr); - wgpuQueueSubmit(queue, 1, &commands); + wgpuQueueSubmit(gpu_ctx.queue, 1, &commands); } } #endif /* !defined(STRIP_ALL) */ |
