diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-14 15:14:25 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-14 15:14:25 +0100 |
| commit | 8ce27b7e15f0fc65c8ee78950c7501660b936178 (patch) | |
| tree | 391f32111b9a30a0156709b6c1ed2fae7b435d57 /src/gpu | |
| parent | e38be0dbf5816338ff97e2ee2f9adfff2902dc2b (diff) | |
style: Apply clang-format to codebase
Diffstat (limited to 'src/gpu')
| -rw-r--r-- | src/gpu/bind_group_builder.h | 22 | ||||
| -rw-r--r-- | src/gpu/demo_effects.h | 16 | ||||
| -rw-r--r-- | src/gpu/effect.cc | 19 | ||||
| -rw-r--r-- | src/gpu/effect.h | 17 | ||||
| -rw-r--r-- | src/gpu/gpu.cc | 16 | ||||
| -rw-r--r-- | src/gpu/gpu.h | 7 | ||||
| -rw-r--r-- | src/gpu/headless_gpu.cc | 4 | ||||
| -rw-r--r-- | src/gpu/pipeline_builder.h | 21 | ||||
| -rw-r--r-- | src/gpu/post_process_helper.cc | 50 | ||||
| -rw-r--r-- | src/gpu/post_process_helper.h | 14 | ||||
| -rw-r--r-- | src/gpu/sampler_cache.h | 17 | ||||
| -rw-r--r-- | src/gpu/shaders.cc | 6 | ||||
| -rw-r--r-- | src/gpu/stub_gpu.cc | 4 | ||||
| -rw-r--r-- | src/gpu/texture_manager.cc | 47 | ||||
| -rw-r--r-- | src/gpu/texture_manager.h | 38 | ||||
| -rw-r--r-- | src/gpu/texture_readback.cc | 31 | ||||
| -rw-r--r-- | src/gpu/texture_readback.h | 21 |
17 files changed, 186 insertions, 164 deletions
diff --git a/src/gpu/bind_group_builder.h b/src/gpu/bind_group_builder.h index abce9dc..55b7291 100644 --- a/src/gpu/bind_group_builder.h +++ b/src/gpu/bind_group_builder.h @@ -24,23 +24,27 @@ typedef uint32_t WGPUShaderStageFlags; class BindGroupLayoutBuilder { std::vector<WGPUBindGroupLayoutEntry> entries_; -public: - BindGroupLayoutBuilder& uniform(uint32_t binding, WGPUShaderStageFlags vis, size_t min_size = 0) { + public: + BindGroupLayoutBuilder& uniform(uint32_t binding, WGPUShaderStageFlags vis, + size_t min_size = 0) { WGPUBindGroupLayoutEntry e{}; e.binding = binding; e.visibility = vis; e.buffer.type = WGPUBufferBindingType_Uniform; - if (min_size) e.buffer.minBindingSize = min_size; + if (min_size) + e.buffer.minBindingSize = min_size; entries_.push_back(e); return *this; } - BindGroupLayoutBuilder& storage(uint32_t binding, WGPUShaderStageFlags vis, size_t min_size = 0) { + BindGroupLayoutBuilder& storage(uint32_t binding, WGPUShaderStageFlags vis, + size_t min_size = 0) { WGPUBindGroupLayoutEntry e{}; e.binding = binding; e.visibility = vis; e.buffer.type = WGPUBufferBindingType_ReadOnlyStorage; - if (min_size) e.buffer.minBindingSize = min_size; + if (min_size) + e.buffer.minBindingSize = min_size; entries_.push_back(e); return *this; } @@ -55,7 +59,8 @@ public: return *this; } - BindGroupLayoutBuilder& uint_texture(uint32_t binding, WGPUShaderStageFlags vis) { + BindGroupLayoutBuilder& uint_texture(uint32_t binding, + WGPUShaderStageFlags vis) { WGPUBindGroupLayoutEntry e{}; e.binding = binding; e.visibility = vis; @@ -65,7 +70,8 @@ public: return *this; } - BindGroupLayoutBuilder& storage_texture(uint32_t binding, WGPUShaderStageFlags vis, + BindGroupLayoutBuilder& storage_texture(uint32_t binding, + WGPUShaderStageFlags vis, WGPUTextureFormat format) { WGPUBindGroupLayoutEntry e{}; e.binding = binding; @@ -97,7 +103,7 @@ public: class BindGroupBuilder { std::vector<WGPUBindGroupEntry> entries_; -public: + public: BindGroupBuilder& buffer(uint32_t binding, WGPUBuffer buf, size_t size) { WGPUBindGroupEntry e{}; e.binding = binding; diff --git a/src/gpu/demo_effects.h b/src/gpu/demo_effects.h index beadafb..a9258af 100644 --- a/src/gpu/demo_effects.h +++ b/src/gpu/demo_effects.h @@ -7,16 +7,16 @@ #include "3d/scene.h" #include "effect.h" #include "effects/circle_mask_effect.h" -#include "effects/fade_effect.h" // FadeEffect with full definition +#include "effects/fade_effect.h" // FadeEffect with full definition +#include "effects/flash_cube_effect.h" #include "effects/flash_effect.h" // FlashEffect with params support -#include "gpu/post_process_helper.h" -#include "effects/rotating_cube_effect.h" -#include "gpu/shaders.h" -#include "effects/theme_modulation_effect.h" // ThemeModulationEffect with full definition #include "effects/hybrid_3d_effect.h" -#include "effects/flash_cube_effect.h" +#include "effects/rotating_cube_effect.h" #include "effects/scene1_effect.h" +#include "effects/theme_modulation_effect.h" // ThemeModulationEffect with full definition #include "gpu/gpu.h" +#include "gpu/post_process_helper.h" +#include "gpu/shaders.h" #include "gpu/texture_manager.h" #include "gpu/uniform_helper.h" #include <memory> @@ -165,7 +165,8 @@ struct DistortParams { float strength = 0.01f; // Default distortion strength float speed = 1.0f; // Default distortion speed }; -static_assert(sizeof(DistortParams) == 8, "DistortParams must be 8 bytes for WGSL alignment"); +static_assert(sizeof(DistortParams) == 8, + "DistortParams must be 8 bytes for WGSL alignment"); class DistortEffect : public PostProcessEffect { public: @@ -180,7 +181,6 @@ class DistortEffect : public PostProcessEffect { UniformBuffer<DistortParams> params_buffer_; }; - #include "effects/cnn_effect.h" #include "effects/cnn_v2_effect.h" diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc index 52128c4..ca98ebd 100644 --- a/src/gpu/effect.cc +++ b/src/gpu/effect.cc @@ -66,8 +66,8 @@ void Sequence::update_active_list(float seq_time) { #if !defined(STRIP_ALL) Effect* effect_ptr = item.effect.get(); const char* effect_name = typeid(*effect_ptr).name(); - printf(" [EFFECT START] <%s> (priority=%d, time=%.2f-%.2f)\n", effect_name, - item.priority, item.start_time, item.end_time); + printf(" [EFFECT START] <%s> (priority=%d, time=%.2f-%.2f)\n", + effect_name, item.priority, item.start_time, item.end_time); #endif item.effect->start(); item.active = true; @@ -173,8 +173,8 @@ void MainSequence::init(const GpuContext& ctx, int width, int height) { passthrough_effect_->resize(width, height); for (ActiveSequence& entry : sequences_) { - entry.seq->resize(width, height); // Set dimensions FIRST - entry.seq->init(this); // Then init with correct dimensions + entry.seq->resize(width, height); // Set dimensions FIRST + entry.seq->init(this); // Then init with correct dimensions } } @@ -183,8 +183,8 @@ void MainSequence::add_sequence(std::shared_ptr<Sequence> seq, float start_time, sequences_.push_back({seq, start_time, priority}); // If MainSequence is already initialized, init the new sequence immediately if (gpu_ctx.device) { - seq->resize(width_, height_); // Set dimensions FIRST - seq->init(this); // Then init with correct dimensions + seq->resize(width_, height_); // Set dimensions FIRST + seq->init(this); // Then init with correct dimensions } std::sort(sequences_.begin(), sequences_.end(), [](const ActiveSequence& a, const ActiveSequence& b) { @@ -329,8 +329,8 @@ void MainSequence::render_frame(float global_time, float beat_time, .colorAttachmentCount = 1, .colorAttachments = &capture_attachment}; WGPURenderPassEncoder capture_pass = wgpuCommandEncoderBeginRenderPass(encoder, &capture_desc); - wgpuRenderPassEncoderSetViewport(capture_pass, 0.0f, 0.0f, - (float)width_, (float)height_, 0.0f, 1.0f); + wgpuRenderPassEncoderSetViewport(capture_pass, 0.0f, 0.0f, (float)width_, + (float)height_, 0.0f, 1.0f); PostProcessEffect* passthrough = (PostProcessEffect*)passthrough_effect_.get(); @@ -555,7 +555,8 @@ void MainSequence::simulate_until(float target_time, float step_rate, } for (const SequenceItem* item : scene_effects) { CommonPostProcessUniforms test_uniforms = { - .resolution = {static_cast<float>(width_), static_cast<float>(height_)}, + .resolution = {static_cast<float>(width_), + static_cast<float>(height_)}, .aspect_ratio = aspect_ratio, .time = t - item->start_time, .beat_time = absolute_beat_time, diff --git a/src/gpu/effect.h b/src/gpu/effect.h index 5d835ad..30e43d1 100644 --- a/src/gpu/effect.h +++ b/src/gpu/effect.h @@ -47,16 +47,17 @@ class Effect { return false; } - // Helper: get initialized CommonPostProcessUniforms based on current dimensions - // If aspect_ratio < 0, computes from width_/height_ - CommonPostProcessUniforms get_common_uniforms(float time = 0.0f, - float beat_time = 0.0f, - float beat_phase = 0.0f, - float intensity = 0.0f, - float aspect_ratio = -1.0f) const { + // Helper: get initialized CommonPostProcessUniforms based on current + // dimensions If aspect_ratio < 0, computes from width_/height_ + CommonPostProcessUniforms + get_common_uniforms(float time = 0.0f, float beat_time = 0.0f, + float beat_phase = 0.0f, float intensity = 0.0f, + float aspect_ratio = -1.0f) const { return { .resolution = {static_cast<float>(width_), static_cast<float>(height_)}, - .aspect_ratio = aspect_ratio < 0.0f ? static_cast<float>(width_) / static_cast<float>(height_) : aspect_ratio, + .aspect_ratio = aspect_ratio < 0.0f ? static_cast<float>(width_) / + static_cast<float>(height_) + : aspect_ratio, .time = time, .beat_time = beat_time, .beat_phase = beat_phase, diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc index 929a063..6d2c7d5 100644 --- a/src/gpu/gpu.cc +++ b/src/gpu/gpu.cc @@ -4,8 +4,8 @@ #include "gpu.h" #include "effect.h" -#include "gpu/shaders.h" #include "gpu/shader_composer.h" +#include "gpu/shaders.h" #include "platform/platform.h" #include <cassert> @@ -81,7 +81,9 @@ TextureWithView gpu_create_storage_texture_2d(WGPUDevice device, uint32_t width, WGPUTextureFormat format) { return gpu_create_texture_2d( device, width, height, format, - (WGPUTextureUsage)(WGPUTextureUsage_StorageBinding | WGPUTextureUsage_TextureBinding), 1); + (WGPUTextureUsage)(WGPUTextureUsage_StorageBinding | + WGPUTextureUsage_TextureBinding), + 1); } TextureWithView gpu_create_post_process_texture(WGPUDevice device, @@ -89,7 +91,9 @@ TextureWithView gpu_create_post_process_texture(WGPUDevice device, WGPUTextureFormat format) { return gpu_create_texture_2d( device, width, height, format, - (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_TextureBinding | WGPUTextureUsage_CopySrc), + (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment | + WGPUTextureUsage_TextureBinding | + WGPUTextureUsage_CopySrc), 1); } @@ -451,10 +455,10 @@ void gpu_init(PlatformState* platform_state) { platform_state->height); } -void gpu_draw(float audio_peak, float aspect_ratio, float time, - float beat_time, float beat_phase) { +void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat_time, + float beat_phase) { g_main_sequence.render_frame(time, beat_time, beat_phase, audio_peak, - aspect_ratio, g_surface); + aspect_ratio, g_surface); } void gpu_resize(int width, int height) { diff --git a/src/gpu/gpu.h b/src/gpu/gpu.h index 0b0153b..3796517 100644 --- a/src/gpu/gpu.h +++ b/src/gpu/gpu.h @@ -42,8 +42,8 @@ struct RenderPass { class MainSequence; // Forward declaration void gpu_init(PlatformState* platform_state); -void gpu_draw(float audio_peak, float aspect_ratio, float time, - float beat_time, float beat_phase); +void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat_time, + float beat_phase); void gpu_resize(int width, int height); void gpu_shutdown(); @@ -101,7 +101,8 @@ TextureWithView gpu_create_post_process_texture(WGPUDevice device, uint32_t width, uint32_t height, WGPUTextureFormat format); WGPUTextureView gpu_create_mip_view(WGPUTexture texture, - WGPUTextureFormat format, uint32_t mip_level); + WGPUTextureFormat format, + uint32_t mip_level); WGPUTextureView gpu_create_texture_view_2d(WGPUTexture texture, WGPUTextureFormat format, uint32_t mip_levels = 1); diff --git a/src/gpu/headless_gpu.cc b/src/gpu/headless_gpu.cc index 1eedc66..f204a78 100644 --- a/src/gpu/headless_gpu.cc +++ b/src/gpu/headless_gpu.cc @@ -47,8 +47,8 @@ void gpu_init(PlatformState* platform_state) { } } -void gpu_draw(float audio_peak, float aspect_ratio, float time, - float beat_time, float beat_phase) { +void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat_time, + float beat_phase) { (void)audio_peak; (void)aspect_ratio; (void)time; diff --git a/src/gpu/pipeline_builder.h b/src/gpu/pipeline_builder.h index 68e34ea..87b9190 100644 --- a/src/gpu/pipeline_builder.h +++ b/src/gpu/pipeline_builder.h @@ -1,7 +1,7 @@ // WGPU render pipeline builder - reduces pipeline creation boilerplate #pragma once -#include <vector> #include <string> +#include <vector> // Forward declarations (users must include gpu.h and shader_composer.h) struct WGPUDeviceImpl; @@ -13,8 +13,8 @@ typedef struct WGPURenderPipelineImpl* WGPURenderPipeline; struct WGPUShaderModuleImpl; typedef struct WGPUShaderModuleImpl* WGPUShaderModule; -#include "platform/platform.h" #include "gpu/shader_composer.h" +#include "platform/platform.h" class RenderPipelineBuilder { WGPUDevice device_; @@ -28,7 +28,7 @@ class RenderPipelineBuilder { bool has_blend_ = false; bool has_depth_ = false; -public: + public: explicit RenderPipelineBuilder(WGPUDevice device) : device_(device) { desc_.primitive.topology = WGPUPrimitiveTopology_TriangleList; desc_.primitive.cullMode = WGPUCullMode_None; @@ -70,7 +70,8 @@ public: return *this; } - RenderPipelineBuilder& depth(WGPUTextureFormat depth_fmt = WGPUTextureFormat_Depth24Plus) { + RenderPipelineBuilder& + depth(WGPUTextureFormat depth_fmt = WGPUTextureFormat_Depth24Plus) { has_depth_ = true; depth_.format = depth_fmt; depth_.depthWriteEnabled = WGPUOptionalBool_True; @@ -85,7 +86,8 @@ public: WGPURenderPipeline build() { color_.writeMask = WGPUColorWriteMask_All; - if (has_blend_) color_.blend = &blend_; + if (has_blend_) + color_.blend = &blend_; WGPUFragmentState fragment{}; fragment.module = shader_module_; @@ -96,13 +98,16 @@ public: WGPUPipelineLayoutDescriptor pl_desc{}; pl_desc.bindGroupLayoutCount = layouts_.size(); pl_desc.bindGroupLayouts = layouts_.data(); - WGPUPipelineLayout layout = wgpuDeviceCreatePipelineLayout(device_, &pl_desc); + WGPUPipelineLayout layout = + wgpuDeviceCreatePipelineLayout(device_, &pl_desc); desc_.layout = layout; desc_.fragment = &fragment; - if (has_depth_) desc_.depthStencil = &depth_; + if (has_depth_) + desc_.depthStencil = &depth_; - WGPURenderPipeline pipeline = wgpuDeviceCreateRenderPipeline(device_, &desc_); + WGPURenderPipeline pipeline = + wgpuDeviceCreateRenderPipeline(device_, &desc_); wgpuPipelineLayoutRelease(layout); return pipeline; } diff --git a/src/gpu/post_process_helper.cc b/src/gpu/post_process_helper.cc index c5bef27..2e8f6ad 100644 --- a/src/gpu/post_process_helper.cc +++ b/src/gpu/post_process_helper.cc @@ -3,31 +3,34 @@ #include "post_process_helper.h" #include "demo_effects.h" -#include "gpu/gpu.h" -#include "gpu/shader_composer.h" #include "gpu/bind_group_builder.h" -#include "gpu/sampler_cache.h" +#include "gpu/gpu.h" #include "gpu/pipeline_builder.h" +#include "gpu/sampler_cache.h" +#include "gpu/shader_composer.h" #include <cstring> // Helper to create a standard post-processing pipeline WGPURenderPipeline create_post_process_pipeline(WGPUDevice device, WGPUTextureFormat format, const char* shader_code) { - WGPUBindGroupLayout bgl = BindGroupLayoutBuilder() - .sampler(PP_BINDING_SAMPLER, WGPUShaderStage_Fragment) - .texture(PP_BINDING_TEXTURE, WGPUShaderStage_Fragment) - .uniform(PP_BINDING_UNIFORMS, WGPUShaderStage_Vertex | WGPUShaderStage_Fragment) - .uniform(PP_BINDING_EFFECT_PARAMS, WGPUShaderStage_Fragment) - .build(device); + WGPUBindGroupLayout bgl = + BindGroupLayoutBuilder() + .sampler(PP_BINDING_SAMPLER, WGPUShaderStage_Fragment) + .texture(PP_BINDING_TEXTURE, WGPUShaderStage_Fragment) + .uniform(PP_BINDING_UNIFORMS, + WGPUShaderStage_Vertex | WGPUShaderStage_Fragment) + .uniform(PP_BINDING_EFFECT_PARAMS, WGPUShaderStage_Fragment) + .build(device); - const std::string composed_shader = ShaderComposer::Get().Compose({}, shader_code); + const std::string composed_shader = + ShaderComposer::Get().Compose({}, shader_code); WGPURenderPipeline pipeline = RenderPipelineBuilder(device) - .shader(composed_shader.c_str()) - .bind_group_layout(bgl) - .format(format) - .build(); + .shader(composed_shader.c_str()) + .bind_group_layout(bgl) + .format(format) + .build(); wgpuBindGroupLayoutRelease(bgl); return pipeline; @@ -47,14 +50,17 @@ void pp_update_bind_group(WGPUDevice device, WGPURenderPipeline pipeline, wgpuBindGroupRelease(*bind_group); WGPUBindGroupLayout bgl = wgpuRenderPipelineGetBindGroupLayout(pipeline, 0); - WGPUSampler sampler = SamplerCache::Get().get_or_create(device, SamplerCache::linear()); + WGPUSampler sampler = + SamplerCache::Get().get_or_create(device, SamplerCache::linear()); *bind_group = BindGroupBuilder() - .sampler(PP_BINDING_SAMPLER, sampler) - .texture(PP_BINDING_TEXTURE, input_view) - .buffer(PP_BINDING_UNIFORMS, uniforms.buffer, uniforms.size) - .buffer(PP_BINDING_EFFECT_PARAMS, - effect_params.buffer ? effect_params.buffer : g_dummy_buffer.buffer, - effect_params.buffer ? effect_params.size : g_dummy_buffer.size) - .build(device, bgl); + .sampler(PP_BINDING_SAMPLER, sampler) + .texture(PP_BINDING_TEXTURE, input_view) + .buffer(PP_BINDING_UNIFORMS, uniforms.buffer, uniforms.size) + .buffer(PP_BINDING_EFFECT_PARAMS, + effect_params.buffer ? effect_params.buffer + : g_dummy_buffer.buffer, + effect_params.buffer ? effect_params.size + : g_dummy_buffer.size) + .build(device, bgl); } diff --git a/src/gpu/post_process_helper.h b/src/gpu/post_process_helper.h index 1c649e7..5a7e9fd 100644 --- a/src/gpu/post_process_helper.h +++ b/src/gpu/post_process_helper.h @@ -8,13 +8,13 @@ // Uniform data common to all post-processing effects struct CommonPostProcessUniforms { - vec2 resolution; // Screen dimensions - float aspect_ratio; // Width/height ratio - float time; // Physical time in seconds (unaffected by tempo) - float beat_time; // Musical time in beats (absolute, tempo-scaled) - float beat_phase; // Fractional beat (0.0-1.0 within current beat) - float audio_intensity;// Audio peak for beat sync - float _pad; // Padding for 16-byte alignment + vec2 resolution; // Screen dimensions + float aspect_ratio; // Width/height ratio + float time; // Physical time in seconds (unaffected by tempo) + float beat_time; // Musical time in beats (absolute, tempo-scaled) + float beat_phase; // Fractional beat (0.0-1.0 within current beat) + float audio_intensity; // Audio peak for beat sync + float _pad; // Padding for 16-byte alignment }; static_assert(sizeof(CommonPostProcessUniforms) == 32, "CommonPostProcessUniforms must be 32 bytes for WGSL alignment"); diff --git a/src/gpu/sampler_cache.h b/src/gpu/sampler_cache.h index 5df3958..7149921 100644 --- a/src/gpu/sampler_cache.h +++ b/src/gpu/sampler_cache.h @@ -16,10 +16,14 @@ struct SamplerSpec { uint16_t anisotropy; bool operator<(const SamplerSpec& o) const { - if (u != o.u) return u < o.u; - if (v != o.v) return v < o.v; - if (mag != o.mag) return mag < o.mag; - if (min != o.min) return min < o.min; + if (u != o.u) + return u < o.u; + if (v != o.v) + return v < o.v; + if (mag != o.mag) + return mag < o.mag; + if (min != o.min) + return min < o.min; return anisotropy < o.anisotropy; } }; @@ -28,7 +32,7 @@ class SamplerCache { std::map<SamplerSpec, WGPUSampler> cache_; SamplerCache() = default; -public: + public: static SamplerCache& Get() { static SamplerCache instance; return instance; @@ -36,7 +40,8 @@ public: WGPUSampler get_or_create(WGPUDevice device, const SamplerSpec& spec) { auto it = cache_.find(spec); - if (it != cache_.end()) return it->second; + if (it != cache_.end()) + return it->second; WGPUSamplerDescriptor desc{}; desc.addressModeU = spec.u; diff --git a/src/gpu/shaders.cc b/src/gpu/shaders.cc index 1b50e8e..60db655 100644 --- a/src/gpu/shaders.cc +++ b/src/gpu/shaders.cc @@ -52,10 +52,12 @@ void InitShaderComposer() { register_if_exists("ray_box", AssetId::ASSET_SHADER_RAY_BOX); register_if_exists("ray_triangle", AssetId::ASSET_SHADER_RAY_TRIANGLE); - register_if_exists("render/fullscreen_vs", AssetId::ASSET_SHADER_RENDER_FULLSCREEN_VS); + register_if_exists("render/fullscreen_vs", + AssetId::ASSET_SHADER_RENDER_FULLSCREEN_VS); register_if_exists("math/color", AssetId::ASSET_SHADER_MATH_COLOR); register_if_exists("math/utils", AssetId::ASSET_SHADER_MATH_UTILS); - register_if_exists("render/raymarching", AssetId::ASSET_SHADER_RENDER_RAYMARCHING); + register_if_exists("render/raymarching", + AssetId::ASSET_SHADER_RENDER_RAYMARCHING); register_if_exists("cnn_activation", AssetId::ASSET_SHADER_CNN_ACTIVATION); register_if_exists("cnn_conv1x1", AssetId::ASSET_SHADER_CNN_CONV1X1); diff --git a/src/gpu/stub_gpu.cc b/src/gpu/stub_gpu.cc index 8d69996..95e647d 100644 --- a/src/gpu/stub_gpu.cc +++ b/src/gpu/stub_gpu.cc @@ -41,8 +41,8 @@ void gpu_init(PlatformState* platform_state) { (void)platform_state; } -void gpu_draw(float audio_peak, float aspect_ratio, float time, - float beat_time, float beat_phase) { +void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat_time, + float beat_phase) { (void)audio_peak; (void)aspect_ratio; (void)time; diff --git a/src/gpu/texture_manager.cc b/src/gpu/texture_manager.cc index 7889283..5bca95b 100644 --- a/src/gpu/texture_manager.cc +++ b/src/gpu/texture_manager.cc @@ -125,8 +125,8 @@ WGPUTextureView TextureManager::get_texture_view(const std::string& name) { } WGPUComputePipeline TextureManager::get_or_create_compute_pipeline( - const std::string& func_name, const char* shader_code, - size_t uniform_size, int num_input_textures) { + const std::string& func_name, const char* shader_code, size_t uniform_size, + int num_input_textures) { auto it = compute_pipelines_.find(func_name); if (it != compute_pipelines_.end()) { return it->second.pipeline; @@ -149,7 +149,8 @@ WGPUComputePipeline TextureManager::get_or_create_compute_pipeline( // Binding 1: uniform buffer // Binding 2 to (2 + num_input_textures - 1): input textures // Binding (2 + num_input_textures): sampler (if inputs > 0) - const int max_entries = 2 + num_input_textures + (num_input_textures > 0 ? 1 : 0); + const int max_entries = + 2 + num_input_textures + (num_input_textures > 0 ? 1 : 0); std::vector<WGPUBindGroupLayoutEntry> bgl_entries(max_entries); // Binding 0: Output storage texture @@ -177,7 +178,8 @@ WGPUComputePipeline TextureManager::get_or_create_compute_pipeline( if (num_input_textures > 0) { bgl_entries[2 + num_input_textures].binding = 2 + num_input_textures; bgl_entries[2 + num_input_textures].visibility = WGPUShaderStage_Compute; - bgl_entries[2 + num_input_textures].sampler.type = WGPUSamplerBindingType_Filtering; + bgl_entries[2 + num_input_textures].sampler.type = + WGPUSamplerBindingType_Filtering; } WGPUBindGroupLayoutDescriptor bgl_desc = {}; @@ -205,7 +207,8 @@ WGPUComputePipeline TextureManager::get_or_create_compute_pipeline( wgpuShaderModuleRelease(shader_module); // Cache pipeline - ComputePipelineInfo info = {pipeline, shader_code, uniform_size, num_input_textures}; + ComputePipelineInfo info = {pipeline, shader_code, uniform_size, + num_input_textures}; compute_pipelines_[func_name] = info; return pipeline; @@ -318,7 +321,8 @@ void TextureManager::create_gpu_noise_texture( }; NoiseParams uniforms = {(uint32_t)params.width, (uint32_t)params.height, params.params[0], params.params[1]}; - dispatch_compute("gen_noise", texture, params, &uniforms, sizeof(NoiseParams)); + dispatch_compute("gen_noise", texture, params, &uniforms, + sizeof(NoiseParams)); WGPUTextureView view = gpu_create_texture_view_2d(texture, WGPUTextureFormat_RGBA8Unorm); @@ -361,15 +365,15 @@ void TextureManager::create_gpu_perlin_texture( uint32_t octaves; float _pad0; }; - PerlinParams uniforms = { - (uint32_t)params.width, - (uint32_t)params.height, - params.params[0], - params.params[1], - params.num_params > 2 ? params.params[2] : 1.0f, - params.num_params > 3 ? params.params[3] : 0.5f, - params.num_params > 4 ? (uint32_t)params.params[4] : 4u, - 0.0f}; + PerlinParams uniforms = {(uint32_t)params.width, + (uint32_t)params.height, + params.params[0], + params.params[1], + params.num_params > 2 ? params.params[2] : 1.0f, + params.num_params > 3 ? params.params[3] : 0.5f, + params.num_params > 4 ? (uint32_t)params.params[4] + : 4u, + 0.0f}; dispatch_compute("gen_perlin", texture, params, &uniforms, sizeof(PerlinParams)); @@ -427,8 +431,8 @@ void TextureManager::create_gpu_grid_texture( textures_[name] = gpu_tex; #if !defined(STRIP_ALL) - printf("Generated GPU grid texture: %s (%dx%d)\n", name.c_str(), - params.width, params.height); + printf("Generated GPU grid texture: %s (%dx%d)\n", name.c_str(), params.width, + params.height); #endif } @@ -634,7 +638,7 @@ void TextureManager::create_gpu_composite_texture( // Dispatch composite shader GpuProceduralParams params = {width, height, nullptr, 0}; dispatch_composite(shader_func, texture, params, uniform_data, uniform_size, - input_views, sampler); + input_views, sampler); // Create view WGPUTextureView view = @@ -653,11 +657,12 @@ void TextureManager::create_gpu_composite_texture( name.c_str(), width, height, input_names.size()); #endif } -#endif // !defined(STRIP_GPU_COMPOSITE) +#endif // !defined(STRIP_GPU_COMPOSITE) #if !defined(STRIP_ALL) -WGPUTextureView TextureManager::get_or_generate_gpu_texture( - const std::string& name, const GpuProceduralParams& params) { +WGPUTextureView +TextureManager::get_or_generate_gpu_texture(const std::string& name, + const GpuProceduralParams& params) { auto it = textures_.find(name); if (it != textures_.end()) { return it->second.view; diff --git a/src/gpu/texture_manager.h b/src/gpu/texture_manager.h index 5a2b9f8..ec30c7b 100644 --- a/src/gpu/texture_manager.h +++ b/src/gpu/texture_manager.h @@ -60,20 +60,18 @@ class TextureManager { }; // GPU composite generation (multi-input textures) - void create_gpu_composite_texture(const std::string& name, - const std::string& shader_func, - const char* shader_code, - const void* uniform_data, - size_t uniform_size, - int width, int height, - const std::vector<std::string>& input_names, - SamplerType sampler = SamplerType::LinearClamp); + void create_gpu_composite_texture( + const std::string& name, const std::string& shader_func, + const char* shader_code, const void* uniform_data, size_t uniform_size, + int width, int height, const std::vector<std::string>& input_names, + SamplerType sampler = SamplerType::LinearClamp); #endif #if !defined(STRIP_ALL) // On-demand lazy generation (stripped in final builds) - WGPUTextureView get_or_generate_gpu_texture(const std::string& name, - const GpuProceduralParams& params); + WGPUTextureView + get_or_generate_gpu_texture(const std::string& name, + const GpuProceduralParams& params); #endif // Retrieves a texture view by name (returns nullptr if not found) @@ -87,20 +85,20 @@ class TextureManager { int num_input_textures; }; - WGPUComputePipeline get_or_create_compute_pipeline(const std::string& func_name, - const char* shader_code, - size_t uniform_size, - int num_input_textures = 0); + WGPUComputePipeline + get_or_create_compute_pipeline(const std::string& func_name, + const char* shader_code, size_t uniform_size, + int num_input_textures = 0); void dispatch_compute(const std::string& func_name, WGPUTexture target, - const GpuProceduralParams& params, const void* uniform_data, - size_t uniform_size); + const GpuProceduralParams& params, + const void* uniform_data, size_t uniform_size); #if !defined(STRIP_GPU_COMPOSITE) void dispatch_composite(const std::string& func_name, WGPUTexture target, - const GpuProceduralParams& params, - const void* uniform_data, size_t uniform_size, - const std::vector<WGPUTextureView>& input_views, - SamplerType sampler_type); + const GpuProceduralParams& params, + const void* uniform_data, size_t uniform_size, + const std::vector<WGPUTextureView>& input_views, + SamplerType sampler_type); #endif WGPUDevice device_; diff --git a/src/gpu/texture_readback.cc b/src/gpu/texture_readback.cc index e25da9e..bd3c79c 100644 --- a/src/gpu/texture_readback.cc +++ b/src/gpu/texture_readback.cc @@ -15,13 +15,9 @@ struct MapState { WGPUMapAsyncStatus status = WGPUMapAsyncStatus_Unknown; }; -std::vector<uint8_t> read_texture_pixels( - WGPUInstance instance, - WGPUDevice device, - WGPUTexture texture, - int width, - int height) { - +std::vector<uint8_t> read_texture_pixels(WGPUInstance instance, + WGPUDevice device, WGPUTexture texture, + int width, int height) { // Align bytes per row to 256 (COPY_BYTES_PER_ROW_ALIGNMENT) const uint32_t bytes_per_pixel = 4; // BGRA8 const uint32_t unaligned_bytes_per_row = width * bytes_per_pixel; @@ -99,7 +95,8 @@ std::vector<uint8_t> read_texture_pixels( state->done = true; }; WGPUBufferMapCallbackInfo map_info = {}; - map_info.mode = WGPUCallbackMode_AllowProcessEvents; // Fire during ProcessEvents + map_info.mode = + WGPUCallbackMode_AllowProcessEvents; // Fire during ProcessEvents map_info.callback = map_cb; map_info.userdata1 = &map_state; wgpuBufferMapAsync(staging, WGPUMapMode_Read, 0, buffer_size, map_info); @@ -178,13 +175,10 @@ static float fp16_to_float(uint16_t h) { return result; } -std::vector<uint8_t> texture_readback_fp16_to_u8( - WGPUDevice device, - WGPUQueue queue, - WGPUTexture texture, - int width, - int height) { - +std::vector<uint8_t> texture_readback_fp16_to_u8(WGPUDevice device, + WGPUQueue queue, + WGPUTexture texture, int width, + int height) { // Align bytes per row to 256 const uint32_t bytes_per_pixel = 8; // RGBA16Float = 4 × 2 bytes const uint32_t unaligned_bytes_per_row = width * bytes_per_pixel; @@ -271,10 +265,9 @@ std::vector<uint8_t> texture_readback_fp16_to_u8( std::vector<uint8_t> pixels(width * height * 4); if (mapped_data) { for (int y = 0; y < height; ++y) { - const uint16_t* src_row = - reinterpret_cast<const uint16_t*>( - reinterpret_cast<const uint8_t*>(mapped_data) + - y * aligned_bytes_per_row); + const uint16_t* src_row = reinterpret_cast<const uint16_t*>( + reinterpret_cast<const uint8_t*>(mapped_data) + + y * aligned_bytes_per_row); for (int x = 0; x < width; ++x) { float r = fp16_to_float(src_row[x * 4 + 0]); float g = fp16_to_float(src_row[x * 4 + 1]); diff --git a/src/gpu/texture_readback.h b/src/gpu/texture_readback.h index 8230e13..a99d572 100644 --- a/src/gpu/texture_readback.h +++ b/src/gpu/texture_readback.h @@ -7,27 +7,22 @@ #if !defined(STRIP_ALL) #include "platform/platform.h" -#include <vector> #include <cstdint> +#include <vector> // Read texture pixels to CPU memory (synchronous, blocking) // Format: BGRA8Unorm (4 bytes per pixel) // Returns: width * height * 4 bytes -std::vector<uint8_t> read_texture_pixels( - WGPUInstance instance, - WGPUDevice device, - WGPUTexture texture, - int width, - int height); +std::vector<uint8_t> read_texture_pixels(WGPUInstance instance, + WGPUDevice device, WGPUTexture texture, + int width, int height); // Read RGBA16Float texture and convert to BGRA8Unorm for saving // Converts [-1,1] float range to [0,255] uint8 range // Returns: width * height * 4 bytes (BGRA8) -std::vector<uint8_t> texture_readback_fp16_to_u8( - WGPUDevice device, - WGPUQueue queue, - WGPUTexture texture, - int width, - int height); +std::vector<uint8_t> texture_readback_fp16_to_u8(WGPUDevice device, + WGPUQueue queue, + WGPUTexture texture, int width, + int height); #endif // !defined(STRIP_ALL) |
