From bd939acdf750181ef0e1a612b445da4c15077c85 Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 7 Feb 2026 17:04:56 +0100 Subject: 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. --- src/gpu/gpu.cc | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/gpu/gpu.cc') diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc index 63a30ff..fe71d3e 100644 --- a/src/gpu/gpu.cc +++ b/src/gpu/gpu.cc @@ -21,12 +21,13 @@ static WGPUInstance g_instance = nullptr; static WGPUAdapter g_adapter = nullptr; -WGPUDevice g_device = nullptr; // Non-static for external access (debug builds) -WGPUQueue g_queue = nullptr; // Non-static for external access (debug builds) +static WGPUDevice g_device = nullptr; +static WGPUQueue g_queue = nullptr; static WGPUSurface g_surface = nullptr; static WGPUSurfaceConfiguration g_config = {}; -WGPUTextureFormat g_format = WGPUTextureFormat_BGRA8Unorm; // Exposed for custom effects +static WGPUTextureFormat g_format = WGPUTextureFormat_BGRA8Unorm; +static GpuContext g_gpu_context = {}; static MainSequence g_main_sequence; // --- Helper Functions --- @@ -355,7 +356,12 @@ void gpu_init(PlatformState* platform_state) { g_config.device = g_device; g_config.format = swap_chain_format; - g_format = swap_chain_format; // Update global format for external access + g_format = swap_chain_format; + + // Update GPU context for accessor + g_gpu_context.device = g_device; + g_gpu_context.queue = g_queue; + g_gpu_context.format = g_format; g_config.usage = WGPUTextureUsage_RenderAttachment; g_config.width = platform_state->width; g_config.height = platform_state->height; @@ -365,10 +371,9 @@ void gpu_init(PlatformState* platform_state) { InitShaderComposer(); - g_main_sequence.init(g_device, g_queue, g_config.format, - platform_state->width, platform_state->height); + g_main_sequence.init(g_gpu_context, platform_state->width, platform_state->height); - LoadTimeline(g_main_sequence, g_device, g_queue, g_config.format); + LoadTimeline(g_main_sequence, g_gpu_context); } void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat) { @@ -395,6 +400,10 @@ void gpu_add_custom_effect(Effect* effect, float start_time, float end_time, int seq->init(&g_main_sequence); g_main_sequence.add_sequence(seq, 0.0f, priority); } + +const GpuContext* gpu_get_context() { + return &g_gpu_context; +} #endif /* !defined(STRIP_ALL) */ void gpu_shutdown() { -- cgit v1.2.3