diff options
Diffstat (limited to 'src/effects')
| -rw-r--r-- | src/effects/chroma_aberration_effect.cc | 2 | ||||
| -rw-r--r-- | src/effects/circle_mask_effect.cc | 6 | ||||
| -rw-r--r-- | src/effects/cnn_effect.cc | 65 | ||||
| -rw-r--r-- | src/effects/cnn_effect.h | 8 | ||||
| -rw-r--r-- | src/effects/cnn_v2_effect.cc | 190 | ||||
| -rw-r--r-- | src/effects/cnn_v2_effect.h | 17 | ||||
| -rw-r--r-- | src/effects/distort_effect.cc | 3 | ||||
| -rw-r--r-- | src/effects/fade_effect.cc | 3 | ||||
| -rw-r--r-- | src/effects/fade_effect.h | 2 | ||||
| -rw-r--r-- | src/effects/flash_effect.cc | 3 | ||||
| -rw-r--r-- | src/effects/gaussian_blur_effect.cc | 2 | ||||
| -rw-r--r-- | src/effects/heptagon_effect.cc | 3 | ||||
| -rw-r--r-- | src/effects/hybrid_3d_effect.cc | 2 | ||||
| -rw-r--r-- | src/effects/moving_ellipse_effect.cc | 5 | ||||
| -rw-r--r-- | src/effects/particle_spray_effect.cc | 2 | ||||
| -rw-r--r-- | src/effects/particles_effect.cc | 2 | ||||
| -rw-r--r-- | src/effects/rotating_cube_effect.cc | 12 | ||||
| -rw-r--r-- | src/effects/scene1_effect.cc | 3 | ||||
| -rw-r--r-- | src/effects/theme_modulation_effect.cc | 7 | ||||
| -rw-r--r-- | src/effects/vignette_effect.cc | 2 |
20 files changed, 195 insertions, 144 deletions
diff --git a/src/effects/chroma_aberration_effect.cc b/src/effects/chroma_aberration_effect.cc index a096f5b..2a92225 100644 --- a/src/effects/chroma_aberration_effect.cc +++ b/src/effects/chroma_aberration_effect.cc @@ -2,8 +2,8 @@ // It implements the ChromaAberrationEffect with parameterization. #include "gpu/demo_effects.h" -#include "gpu/post_process_helper.h" #include "gpu/gpu.h" +#include "gpu/post_process_helper.h" // --- ChromaAberrationEffect --- diff --git a/src/effects/circle_mask_effect.cc b/src/effects/circle_mask_effect.cc index 63c8f68..7a016d9 100644 --- a/src/effects/circle_mask_effect.cc +++ b/src/effects/circle_mask_effect.cc @@ -51,7 +51,8 @@ void CircleMaskEffect::init(MainSequence* demo) { AssetId::ASSET_CIRCLE_MASK_RENDER_SHADER, &render_size); // Compose shaders to resolve #include directives - std::string composed_compute = ShaderComposer::Get().Compose({}, compute_shader); + std::string composed_compute = + ShaderComposer::Get().Compose({}, compute_shader); WGPUShaderSourceWGSL compute_wgsl = {}; compute_wgsl.chain.sType = WGPUSType_ShaderSourceWGSL; @@ -93,7 +94,8 @@ void CircleMaskEffect::init(MainSequence* demo) { .build(ctx_.device, compute_layout); wgpuBindGroupLayoutRelease(compute_layout); - std::string composed_render = ShaderComposer::Get().Compose({}, render_shader); + std::string composed_render = + ShaderComposer::Get().Compose({}, render_shader); WGPUShaderSourceWGSL render_wgsl = {}; render_wgsl.chain.sType = WGPUSType_ShaderSourceWGSL; diff --git a/src/effects/cnn_effect.cc b/src/effects/cnn_effect.cc index 4475180..49c5239 100644 --- a/src/effects/cnn_effect.cc +++ b/src/effects/cnn_effect.cc @@ -2,31 +2,32 @@ // Neural network-based stylization with modular WGSL #include "effects/cnn_effect.h" -#include "gpu/post_process_helper.h" -#include "gpu/shaders.h" -#include "gpu/shader_composer.h" -#include "gpu/effect.h" #include "gpu/bind_group_builder.h" -#include "gpu/sampler_cache.h" +#include "gpu/effect.h" #include "gpu/pipeline_builder.h" +#include "gpu/post_process_helper.h" +#include "gpu/sampler_cache.h" +#include "gpu/shader_composer.h" +#include "gpu/shaders.h" // Create custom pipeline with 5 bindings (includes original texture) static WGPURenderPipeline create_cnn_pipeline(WGPUDevice device, - WGPUTextureFormat format, - const char* shader_code) { - WGPUBindGroupLayout bgl = BindGroupLayoutBuilder() - .sampler(0, WGPUShaderStage_Fragment) - .texture(1, WGPUShaderStage_Fragment) - .uniform(2, WGPUShaderStage_Vertex | WGPUShaderStage_Fragment) - .uniform(3, WGPUShaderStage_Fragment) - .texture(4, WGPUShaderStage_Fragment) - .build(device); + WGPUTextureFormat format, + const char* shader_code) { + WGPUBindGroupLayout bgl = + BindGroupLayoutBuilder() + .sampler(0, WGPUShaderStage_Fragment) + .texture(1, WGPUShaderStage_Fragment) + .uniform(2, WGPUShaderStage_Vertex | WGPUShaderStage_Fragment) + .uniform(3, WGPUShaderStage_Fragment) + .texture(4, WGPUShaderStage_Fragment) + .build(device); WGPURenderPipeline pipeline = RenderPipelineBuilder(device) - .shader(shader_code) - .bind_group_layout(bgl) - .format(format) - .build(); + .shader(shader_code) + .bind_group_layout(bgl) + .format(format) + .build(); wgpuBindGroupLayoutRelease(bgl); return pipeline; @@ -36,16 +37,16 @@ CNNEffect::CNNEffect(const GpuContext& ctx) : PostProcessEffect(ctx), layer_index_(0), total_layers_(1), blend_amount_(1.0f), input_view_(nullptr), original_view_(nullptr), bind_group_(nullptr) { - pipeline_ = create_cnn_pipeline(ctx_.device, ctx_.format, - cnn_layer_shader_wgsl); + pipeline_ = + create_cnn_pipeline(ctx_.device, ctx_.format, cnn_layer_shader_wgsl); } CNNEffect::CNNEffect(const GpuContext& ctx, const CNNEffectParams& params) : PostProcessEffect(ctx), layer_index_(params.layer_index), total_layers_(params.total_layers), blend_amount_(params.blend_amount), input_view_(nullptr), original_view_(nullptr), bind_group_(nullptr) { - pipeline_ = create_cnn_pipeline(ctx_.device, ctx_.format, - cnn_layer_shader_wgsl); + pipeline_ = + create_cnn_pipeline(ctx_.device, ctx_.format, cnn_layer_shader_wgsl); } void CNNEffect::init(MainSequence* demo) { @@ -78,7 +79,7 @@ void CNNEffect::resize(int width, int height) { } void CNNEffect::render(WGPURenderPassEncoder pass, - const CommonPostProcessUniforms& uniforms) { + const CommonPostProcessUniforms& uniforms) { if (!bind_group_) { fprintf(stderr, "CNN render: no bind_group\n"); return; @@ -114,13 +115,15 @@ void CNNEffect::update_bind_group(WGPUTextureView input_view) { WGPUBindGroupLayout bgl = wgpuRenderPipelineGetBindGroupLayout(pipeline_, 0); // Use clamp (not repeat) to match PyTorch Conv2d zero-padding behavior - WGPUSampler sampler = SamplerCache::Get().get_or_create(ctx_.device, SamplerCache::clamp()); + WGPUSampler sampler = + SamplerCache::Get().get_or_create(ctx_.device, SamplerCache::clamp()); - bind_group_ = BindGroupBuilder() - .sampler(0, sampler) - .texture(1, input_view_) - .buffer(2, uniforms_.get().buffer, uniforms_.get().size) - .buffer(3, params_buffer_.get().buffer, params_buffer_.get().size) - .texture(4, original_view_ ? original_view_ : input_view_) - .build(ctx_.device, bgl); + bind_group_ = + BindGroupBuilder() + .sampler(0, sampler) + .texture(1, input_view_) + .buffer(2, uniforms_.get().buffer, uniforms_.get().size) + .buffer(3, params_buffer_.get().buffer, params_buffer_.get().size) + .texture(4, original_view_ ? original_view_ : input_view_) + .build(ctx_.device, bgl); } diff --git a/src/effects/cnn_effect.h b/src/effects/cnn_effect.h index 3e2b7ca..cdcd656 100644 --- a/src/effects/cnn_effect.h +++ b/src/effects/cnn_effect.h @@ -7,15 +7,15 @@ struct CNNLayerParams { int layer_index; - float blend_amount; // Blend: mix(input, output, blend_amount) + float blend_amount; // Blend: mix(input, output, blend_amount) float _pad[2]; }; static_assert(sizeof(CNNLayerParams) == 16); struct CNNEffectParams { - int layer_index = 0; // Which layer to render (0-based) - int total_layers = 1; // Total number of layers in the CNN - float blend_amount = 1.0f; // Final blend with original input + int layer_index = 0; // Which layer to render (0-based) + int total_layers = 1; // Total number of layers in the CNN + float blend_amount = 1.0f; // Final blend with original input }; class CNNEffect : public PostProcessEffect { diff --git a/src/effects/cnn_v2_effect.cc b/src/effects/cnn_v2_effect.cc index 4c10ed1..7127aae 100644 --- a/src/effects/cnn_v2_effect.cc +++ b/src/effects/cnn_v2_effect.cc @@ -15,38 +15,24 @@ #include <cstring> CNNv2Effect::CNNv2Effect(const GpuContext& ctx) - : PostProcessEffect(ctx), - static_pipeline_(nullptr), - static_bind_group_(nullptr), - static_params_buffer_(nullptr), - static_features_tex_(nullptr), - static_features_view_(nullptr), - linear_sampler_(nullptr), - layer_pipeline_(nullptr), - weights_buffer_(nullptr), - input_mip_tex_(nullptr), - current_input_view_(nullptr), - blend_amount_(1.0f), - mip_level_(0), + : PostProcessEffect(ctx), static_pipeline_(nullptr), + static_bind_group_(nullptr), static_params_buffer_(nullptr), + static_features_tex_(nullptr), static_features_view_(nullptr), + linear_sampler_(nullptr), layer_pipeline_(nullptr), + weights_buffer_(nullptr), input_mip_tex_(nullptr), + current_input_view_(nullptr), blend_amount_(1.0f), mip_level_(0), initialized_(false) { std::memset(input_mip_view_, 0, sizeof(input_mip_view_)); } CNNv2Effect::CNNv2Effect(const GpuContext& ctx, const CNNv2EffectParams& params) - : PostProcessEffect(ctx), - static_pipeline_(nullptr), - static_bind_group_(nullptr), - static_params_buffer_(nullptr), - static_features_tex_(nullptr), - static_features_view_(nullptr), - linear_sampler_(nullptr), - layer_pipeline_(nullptr), - weights_buffer_(nullptr), - input_mip_tex_(nullptr), - current_input_view_(nullptr), - blend_amount_(params.blend_amount), - mip_level_(0), - initialized_(false) { + : PostProcessEffect(ctx), static_pipeline_(nullptr), + static_bind_group_(nullptr), static_params_buffer_(nullptr), + static_features_tex_(nullptr), static_features_view_(nullptr), + linear_sampler_(nullptr), layer_pipeline_(nullptr), + weights_buffer_(nullptr), input_mip_tex_(nullptr), + current_input_view_(nullptr), blend_amount_(params.blend_amount), + mip_level_(0), initialized_(false) { std::memset(input_mip_view_, 0, sizeof(input_mip_view_)); } @@ -56,7 +42,8 @@ CNNv2Effect::~CNNv2Effect() { void CNNv2Effect::init(MainSequence* demo) { (void)demo; - if (initialized_) return; + if (initialized_) + return; load_weights(); create_textures(); @@ -75,7 +62,8 @@ void CNNv2Effect::resize(int width, int height) { void CNNv2Effect::load_weights() { // Load binary weights asset size_t weights_size = 0; - const uint8_t* weights_data = (const uint8_t*)GetAsset(AssetId::ASSET_WEIGHTS_CNN_V2, &weights_size); + const uint8_t* weights_data = + (const uint8_t*)GetAsset(AssetId::ASSET_WEIGHTS_CNN_V2, &weights_size); if (!weights_data || weights_size < 20) { // Weights not available - effect will skip @@ -89,12 +77,14 @@ void CNNv2Effect::load_weights() { uint32_t num_layers = header[2]; uint32_t total_weights = header[3]; - FATAL_CHECK(magic != 0x324e4e43, "Invalid CNN v2 weights magic\n"); // 'CNN2' + FATAL_CHECK(magic != 0x324e4e43, "Invalid CNN v2 weights magic\n"); // 'CNN2' - // Support both version 1 (16-byte header) and version 2 (20-byte header with mip_level) - // TODO: Version 3 should include feature descriptor for arbitrary layout/ordering + // Support both version 1 (16-byte header) and version 2 (20-byte header with + // mip_level) + // TODO: Version 3 should include feature descriptor for arbitrary + // layout/ordering if (version == 1) { - mip_level_ = 0; // Default for v1 + mip_level_ = 0; // Default for v1 } else if (version == 2) { mip_level_ = header[4]; } else { @@ -115,9 +105,10 @@ void CNNv2Effect::load_weights() { layer_info_.push_back(info); } - // Create GPU storage buffer for weights (skip header + layer info, upload only weights) - size_t header_size = 20; // 5 u32 - size_t layer_info_size = 20 * num_layers; // 5 u32 per layer + // Create GPU storage buffer for weights (skip header + layer info, upload + // only weights) + size_t header_size = 20; // 5 u32 + size_t layer_info_size = 20 * num_layers; // 5 u32 per layer size_t weights_offset = header_size + layer_info_size; size_t weights_only_size = weights_size - weights_offset; @@ -129,7 +120,8 @@ void CNNv2Effect::load_weights() { weights_buffer_ = wgpuDeviceCreateBuffer(ctx_.device, &buffer_desc); // Upload only weights (skip header + layer info) - wgpuQueueWriteBuffer(ctx_.queue, weights_buffer_, 0, weights_data + weights_offset, weights_only_size); + wgpuQueueWriteBuffer(ctx_.queue, weights_buffer_, 0, + weights_data + weights_offset, weights_only_size); // Create uniform buffers for layer params (one per layer) for (uint32_t i = 0; i < num_layers; ++i) { @@ -153,7 +145,9 @@ void CNNv2Effect::create_textures() { // Input texture with mips (for multi-scale features) TextureWithView input_mip = gpu_create_texture_2d( ctx_.device, width_, height_, WGPUTextureFormat_RGBA8Unorm, - (WGPUTextureUsage)(WGPUTextureUsage_TextureBinding | WGPUTextureUsage_CopyDst), 3); + (WGPUTextureUsage)(WGPUTextureUsage_TextureBinding | + WGPUTextureUsage_CopyDst), + 3); input_mip_tex_ = input_mip.texture; for (int i = 0; i < 3; ++i) { @@ -195,7 +189,8 @@ void CNNv2Effect::create_pipelines() { // Static features compute pipeline size_t shader_size = 0; - const char* static_code = (const char*)GetAsset(AssetId::ASSET_SHADER_CNN_V2_STATIC, &shader_size); + const char* static_code = + (const char*)GetAsset(AssetId::ASSET_SHADER_CNN_V2_STATIC, &shader_size); if (!static_code || shader_size == 0) { // Shader not available (e.g., in test mode) - skip pipeline creation @@ -210,7 +205,8 @@ void CNNv2Effect::create_pipelines() { shader_desc.nextInChain = &wgsl_src.chain; // Create bind group layout for static features compute - // Bindings: 0=input_tex, 1=input_mip1, 2=input_mip2, 3=depth_tex, 4=output, 5=params, 6=linear_sampler + // Bindings: 0=input_tex, 1=input_mip1, 2=input_mip2, 3=depth_tex, 4=output, + // 5=params, 6=linear_sampler WGPUBindGroupLayout static_bgl = BindGroupLayoutBuilder() .texture(0, WGPUShaderStage_Compute) @@ -227,28 +223,35 @@ void CNNv2Effect::create_pipelines() { WGPUPipelineLayoutDescriptor pl_desc = {}; pl_desc.bindGroupLayoutCount = 1; pl_desc.bindGroupLayouts = &static_bgl; - WGPUPipelineLayout pipeline_layout = wgpuDeviceCreatePipelineLayout(ctx_.device, &pl_desc); + WGPUPipelineLayout pipeline_layout = + wgpuDeviceCreatePipelineLayout(ctx_.device, &pl_desc); // Recreate pipeline with proper layout WGPUComputePipelineDescriptor pipeline_desc2 = {}; - pipeline_desc2.compute.module = wgpuDeviceCreateShaderModule(ctx_.device, &shader_desc); + pipeline_desc2.compute.module = + wgpuDeviceCreateShaderModule(ctx_.device, &shader_desc); pipeline_desc2.compute.entryPoint = str_view("main"); pipeline_desc2.layout = pipeline_layout; - if (static_pipeline_) wgpuComputePipelineRelease(static_pipeline_); - static_pipeline_ = wgpuDeviceCreateComputePipeline(ctx_.device, &pipeline_desc2); + if (static_pipeline_) + wgpuComputePipelineRelease(static_pipeline_); + static_pipeline_ = + wgpuDeviceCreateComputePipeline(ctx_.device, &pipeline_desc2); wgpuShaderModuleRelease(pipeline_desc2.compute.module); wgpuPipelineLayoutRelease(pipeline_layout); wgpuBindGroupLayoutRelease(static_bgl); // CNN layer compute pipeline (storage buffer version) - if (layer_info_.empty()) return; // No weights loaded + if (layer_info_.empty()) + return; // No weights loaded size_t layer_shader_size = 0; - const char* layer_code = (const char*)GetAsset(AssetId::ASSET_SHADER_CNN_V2_COMPUTE, &layer_shader_size); + const char* layer_code = (const char*)GetAsset( + AssetId::ASSET_SHADER_CNN_V2_COMPUTE, &layer_shader_size); - if (!layer_code || layer_shader_size == 0) return; + if (!layer_code || layer_shader_size == 0) + return; WGPUShaderSourceWGSL layer_wgsl = {}; layer_wgsl.chain.sType = WGPUSType_ShaderSourceWGSL; @@ -257,11 +260,14 @@ void CNNv2Effect::create_pipelines() { WGPUShaderModuleDescriptor layer_shader_desc = {}; layer_shader_desc.nextInChain = &layer_wgsl.chain; - WGPUShaderModule layer_module = wgpuDeviceCreateShaderModule(ctx_.device, &layer_shader_desc); - if (!layer_module) return; + WGPUShaderModule layer_module = + wgpuDeviceCreateShaderModule(ctx_.device, &layer_shader_desc); + if (!layer_module) + return; // Create bind group layout for layer compute - // 0=static_features, 1=layer_input, 2=output, 3=weights, 4=params, 5=original_input + // 0=static_features, 1=layer_input, 2=output, 3=weights, 4=params, + // 5=original_input WGPUBindGroupLayout layer_bgl = BindGroupLayoutBuilder() .uint_texture(0, WGPUShaderStage_Compute) @@ -277,14 +283,16 @@ void CNNv2Effect::create_pipelines() { layer_pl_desc.bindGroupLayoutCount = 1; layer_pl_desc.bindGroupLayouts = &layer_bgl; - WGPUPipelineLayout layer_pipeline_layout = wgpuDeviceCreatePipelineLayout(ctx_.device, &layer_pl_desc); + WGPUPipelineLayout layer_pipeline_layout = + wgpuDeviceCreatePipelineLayout(ctx_.device, &layer_pl_desc); WGPUComputePipelineDescriptor layer_pipeline_desc = {}; layer_pipeline_desc.compute.module = layer_module; layer_pipeline_desc.compute.entryPoint = str_view("main"); layer_pipeline_desc.layout = layer_pipeline_layout; - layer_pipeline_ = wgpuDeviceCreateComputePipeline(ctx_.device, &layer_pipeline_desc); + layer_pipeline_ = + wgpuDeviceCreateComputePipeline(ctx_.device, &layer_pipeline_desc); wgpuShaderModuleRelease(layer_module); wgpuPipelineLayoutRelease(layer_pipeline_layout); @@ -292,7 +300,8 @@ void CNNv2Effect::create_pipelines() { } void CNNv2Effect::update_bind_group(WGPUTextureView input_view) { - if (!static_pipeline_) return; + if (!static_pipeline_) + return; // Cache input view current_input_view_ = input_view; @@ -303,7 +312,8 @@ void CNNv2Effect::update_bind_group(WGPUTextureView input_view) { static_bind_group_ = nullptr; } - // Create bind group for static features compute (manual for storage texture binding) + // Create bind group for static features compute (manual for storage texture + // binding) WGPUBindGroupEntry bg_entries[7] = {}; bg_entries[0].binding = 0; bg_entries[0].textureView = input_view; @@ -332,7 +342,8 @@ void CNNv2Effect::update_bind_group(WGPUTextureView input_view) { wgpuBindGroupLayoutRelease(layout); // Create layer bind groups - if (!layer_pipeline_ || layer_info_.empty()) return; + if (!layer_pipeline_ || layer_info_.empty()) + return; // Release old layer bind groups for (auto bg : layer_bind_groups_) { @@ -341,7 +352,8 @@ void CNNv2Effect::update_bind_group(WGPUTextureView input_view) { layer_bind_groups_.clear(); // Get bind group layout from layer pipeline - WGPUBindGroupLayout layer_bgl = wgpuComputePipelineGetBindGroupLayout(layer_pipeline_, 0); + WGPUBindGroupLayout layer_bgl = + wgpuComputePipelineGetBindGroupLayout(layer_pipeline_, 0); // Create bind group for each layer for (size_t i = 0; i < layer_info_.size(); ++i) { @@ -366,7 +378,8 @@ void CNNv2Effect::update_bind_group(WGPUTextureView input_view) { void CNNv2Effect::compute(WGPUCommandEncoder encoder, const CommonPostProcessUniforms& uniforms) { - if (!initialized_ || !static_pipeline_ || !static_bind_group_) return; + if (!initialized_ || !static_pipeline_ || !static_bind_group_) + return; float effective_blend = blend_amount_; if (beat_modulated_) { @@ -379,10 +392,12 @@ void CNNv2Effect::compute(WGPUCommandEncoder encoder, static_params.padding[0] = 0; static_params.padding[1] = 0; static_params.padding[2] = 0; - wgpuQueueWriteBuffer(ctx_.queue, static_params_buffer_, 0, &static_params, sizeof(static_params)); + wgpuQueueWriteBuffer(ctx_.queue, static_params_buffer_, 0, &static_params, + sizeof(static_params)); // Pass 1: Compute static features - WGPUComputePassEncoder pass = wgpuCommandEncoderBeginComputePass(encoder, nullptr); + WGPUComputePassEncoder pass = + wgpuCommandEncoderBeginComputePass(encoder, nullptr); wgpuComputePassEncoderSetPipeline(pass, static_pipeline_); wgpuComputePassEncoderSetBindGroup(pass, 0, static_bind_group_, 0, nullptr); @@ -396,7 +411,8 @@ void CNNv2Effect::compute(WGPUCommandEncoder encoder, wgpuComputePassEncoderRelease(pass); // Execute CNN layer passes - if (!layer_pipeline_ || layer_bind_groups_.empty()) return; + if (!layer_pipeline_ || layer_bind_groups_.empty()) + return; // Update layer params (each layer has own buffer) for (size_t i = 0; i < layer_info_.size(); ++i) { @@ -411,14 +427,18 @@ void CNNv2Effect::compute(WGPUCommandEncoder encoder, params.blend_amount = effective_blend; params.is_layer_0 = (i == 0) ? 1 : 0; - wgpuQueueWriteBuffer(ctx_.queue, layer_params_buffers_[i], 0, ¶ms, sizeof(params)); + wgpuQueueWriteBuffer(ctx_.queue, layer_params_buffers_[i], 0, ¶ms, + sizeof(params)); - WGPUComputePassEncoder layer_pass = wgpuCommandEncoderBeginComputePass(encoder, nullptr); + WGPUComputePassEncoder layer_pass = + wgpuCommandEncoderBeginComputePass(encoder, nullptr); wgpuComputePassEncoderSetPipeline(layer_pass, layer_pipeline_); - wgpuComputePassEncoderSetBindGroup(layer_pass, 0, layer_bind_groups_[i], 0, nullptr); + wgpuComputePassEncoderSetBindGroup(layer_pass, 0, layer_bind_groups_[i], 0, + nullptr); - wgpuComputePassEncoderDispatchWorkgroups(layer_pass, workgroups_x, workgroups_y, 1); + wgpuComputePassEncoderDispatchWorkgroups(layer_pass, workgroups_x, + workgroups_y, 1); wgpuComputePassEncoderEnd(layer_pass); wgpuComputePassEncoderRelease(layer_pass); @@ -433,26 +453,40 @@ void CNNv2Effect::render(WGPURenderPassEncoder pass, } void CNNv2Effect::cleanup() { - if (static_features_view_) wgpuTextureViewRelease(static_features_view_); - if (static_features_tex_) wgpuTextureRelease(static_features_tex_); - if (static_bind_group_) wgpuBindGroupRelease(static_bind_group_); - if (static_params_buffer_) wgpuBufferRelease(static_params_buffer_); - if (static_pipeline_) wgpuComputePipelineRelease(static_pipeline_); - if (linear_sampler_) wgpuSamplerRelease(linear_sampler_); + if (static_features_view_) + wgpuTextureViewRelease(static_features_view_); + if (static_features_tex_) + wgpuTextureRelease(static_features_tex_); + if (static_bind_group_) + wgpuBindGroupRelease(static_bind_group_); + if (static_params_buffer_) + wgpuBufferRelease(static_params_buffer_); + if (static_pipeline_) + wgpuComputePipelineRelease(static_pipeline_); + if (linear_sampler_) + wgpuSamplerRelease(linear_sampler_); - if (layer_pipeline_) wgpuComputePipelineRelease(layer_pipeline_); - if (weights_buffer_) wgpuBufferRelease(weights_buffer_); - for (auto buf : layer_params_buffers_) wgpuBufferRelease(buf); + if (layer_pipeline_) + wgpuComputePipelineRelease(layer_pipeline_); + if (weights_buffer_) + wgpuBufferRelease(weights_buffer_); + for (auto buf : layer_params_buffers_) + wgpuBufferRelease(buf); layer_params_buffers_.clear(); for (int i = 0; i < 3; ++i) { - if (input_mip_view_[i]) wgpuTextureViewRelease(input_mip_view_[i]); + if (input_mip_view_[i]) + wgpuTextureViewRelease(input_mip_view_[i]); } - if (input_mip_tex_) wgpuTextureRelease(input_mip_tex_); + if (input_mip_tex_) + wgpuTextureRelease(input_mip_tex_); - for (auto view : layer_views_) wgpuTextureViewRelease(view); - for (auto tex : layer_textures_) wgpuTextureRelease(tex); - for (auto bg : layer_bind_groups_) wgpuBindGroupRelease(bg); + for (auto view : layer_views_) + wgpuTextureViewRelease(view); + for (auto tex : layer_textures_) + wgpuTextureRelease(tex); + for (auto bg : layer_bind_groups_) + wgpuBindGroupRelease(bg); layer_views_.clear(); layer_textures_.clear(); diff --git a/src/effects/cnn_v2_effect.h b/src/effects/cnn_v2_effect.h index d530d3b..7960b4f 100644 --- a/src/effects/cnn_v2_effect.h +++ b/src/effects/cnn_v2_effect.h @@ -11,7 +11,7 @@ struct CNNv2EffectParams { }; class CNNv2Effect : public PostProcessEffect { -public: + public: explicit CNNv2Effect(const GpuContext& ctx); explicit CNNv2Effect(const GpuContext& ctx, const CNNv2EffectParams& params); ~CNNv2Effect(); @@ -29,7 +29,7 @@ public: beat_scale_ = scale; } -private: + private: struct LayerInfo { uint32_t kernel_size; uint32_t in_channels; @@ -67,12 +67,13 @@ private: WGPUSampler linear_sampler_; // CNN layers (storage buffer architecture) - WGPUComputePipeline layer_pipeline_; // Single pipeline for all layers - WGPUBuffer weights_buffer_; // Storage buffer for weights - std::vector<WGPUBuffer> layer_params_buffers_; // Uniform buffers (one per layer) - std::vector<LayerInfo> layer_info_; // Layer metadata - std::vector<WGPUBindGroup> layer_bind_groups_; // Per-layer bind groups - std::vector<WGPUTexture> layer_textures_; // Ping-pong buffers + WGPUComputePipeline layer_pipeline_; // Single pipeline for all layers + WGPUBuffer weights_buffer_; // Storage buffer for weights + std::vector<WGPUBuffer> + layer_params_buffers_; // Uniform buffers (one per layer) + std::vector<LayerInfo> layer_info_; // Layer metadata + std::vector<WGPUBindGroup> layer_bind_groups_; // Per-layer bind groups + std::vector<WGPUTexture> layer_textures_; // Ping-pong buffers std::vector<WGPUTextureView> layer_views_; // Input mips diff --git a/src/effects/distort_effect.cc b/src/effects/distort_effect.cc index 97622b2..f4e68d2 100644 --- a/src/effects/distort_effect.cc +++ b/src/effects/distort_effect.cc @@ -32,5 +32,6 @@ void DistortEffect::render(WGPURenderPassEncoder pass, } void DistortEffect::update_bind_group(WGPUTextureView v) { - pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, v, uniforms_.get(), params_buffer_); + pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, v, uniforms_.get(), + params_buffer_); }
\ No newline at end of file diff --git a/src/effects/fade_effect.cc b/src/effects/fade_effect.cc index fd2af69..1dff6bd 100644 --- a/src/effects/fade_effect.cc +++ b/src/effects/fade_effect.cc @@ -9,7 +9,8 @@ struct FadeParams { float fade_amount; float _pad[3]; }; -static_assert(sizeof(FadeParams) == 16, "FadeParams must be 16 bytes for WGSL alignment"); +static_assert(sizeof(FadeParams) == 16, + "FadeParams must be 16 bytes for WGSL alignment"); FadeEffect::FadeEffect(const GpuContext& ctx) : PostProcessEffect(ctx) { const char* shader_code = R"( diff --git a/src/effects/fade_effect.h b/src/effects/fade_effect.h index 8cd7006..6993152 100644 --- a/src/effects/fade_effect.h +++ b/src/effects/fade_effect.h @@ -4,8 +4,8 @@ #pragma once #include "gpu/effect.h" -#include "gpu/post_process_helper.h" #include "gpu/gpu.h" +#include "gpu/post_process_helper.h" #include "gpu/uniform_helper.h" class FadeEffect : public PostProcessEffect { diff --git a/src/effects/flash_effect.cc b/src/effects/flash_effect.cc index 235412d..00b5217 100644 --- a/src/effects/flash_effect.cc +++ b/src/effects/flash_effect.cc @@ -66,7 +66,8 @@ void FlashEffect::update_bind_group(WGPUTextureView input_view) { void FlashEffect::render(WGPURenderPassEncoder pass, const CommonPostProcessUniforms& uniforms) { // Trigger flash based on configured threshold - if (uniforms.audio_intensity > params_.trigger_threshold && flash_intensity_ < 0.2f) { + if (uniforms.audio_intensity > params_.trigger_threshold && + flash_intensity_ < 0.2f) { flash_intensity_ = 0.8f; // Trigger flash } diff --git a/src/effects/gaussian_blur_effect.cc b/src/effects/gaussian_blur_effect.cc index 0b4beae..6a0675d 100644 --- a/src/effects/gaussian_blur_effect.cc +++ b/src/effects/gaussian_blur_effect.cc @@ -2,8 +2,8 @@ // It implements the GaussianBlurEffect with parameterization. #include "gpu/demo_effects.h" -#include "gpu/post_process_helper.h" #include "gpu/gpu.h" +#include "gpu/post_process_helper.h" // --- GaussianBlurEffect --- diff --git a/src/effects/heptagon_effect.cc b/src/effects/heptagon_effect.cc index 724eabb..273adc2 100644 --- a/src/effects/heptagon_effect.cc +++ b/src/effects/heptagon_effect.cc @@ -8,7 +8,8 @@ // --- HeptagonEffect --- HeptagonEffect::HeptagonEffect(const GpuContext& ctx) : Effect(ctx) { // uniforms_ is initialized by Effect base class - ResourceBinding bindings[] = {{uniforms_.get(), WGPUBufferBindingType_Uniform}}; + ResourceBinding bindings[] = { + {uniforms_.get(), WGPUBufferBindingType_Uniform}}; pass_ = gpu_create_render_pass(ctx_.device, ctx_.format, main_shader_wgsl, bindings, 1); pass_.vertex_count = 21; diff --git a/src/effects/hybrid_3d_effect.cc b/src/effects/hybrid_3d_effect.cc index 1cd773d..61f3165 100644 --- a/src/effects/hybrid_3d_effect.cc +++ b/src/effects/hybrid_3d_effect.cc @@ -95,7 +95,7 @@ static float ease_in_out_cubic(float t) { } void Hybrid3DEffect::render(WGPURenderPassEncoder pass, - const CommonPostProcessUniforms& uniforms) { + const CommonPostProcessUniforms& uniforms) { // Animate Objects for (size_t i = 1; i < scene_.objects.size(); ++i) { diff --git a/src/effects/moving_ellipse_effect.cc b/src/effects/moving_ellipse_effect.cc index f595de9..e641927 100644 --- a/src/effects/moving_ellipse_effect.cc +++ b/src/effects/moving_ellipse_effect.cc @@ -2,13 +2,14 @@ // It implements the MovingEllipseEffect. #include "gpu/demo_effects.h" -#include "gpu/post_process_helper.h" #include "gpu/gpu.h" +#include "gpu/post_process_helper.h" // --- MovingEllipseEffect --- MovingEllipseEffect::MovingEllipseEffect(const GpuContext& ctx) : Effect(ctx) { // uniforms_ is initialized by Effect base class - ResourceBinding bindings[] = {{uniforms_.get(), WGPUBufferBindingType_Uniform}}; + ResourceBinding bindings[] = { + {uniforms_.get(), WGPUBufferBindingType_Uniform}}; pass_ = gpu_create_render_pass(ctx_.device, ctx_.format, ellipse_shader_wgsl, bindings, 1); pass_.vertex_count = 3; diff --git a/src/effects/particle_spray_effect.cc b/src/effects/particle_spray_effect.cc index e250f5a..0b0dba1 100644 --- a/src/effects/particle_spray_effect.cc +++ b/src/effects/particle_spray_effect.cc @@ -2,8 +2,8 @@ // It implements the ParticleSprayEffect. #include "gpu/demo_effects.h" -#include "gpu/post_process_helper.h" #include "gpu/gpu.h" +#include "gpu/post_process_helper.h" #include <vector> // --- ParticleSprayEffect --- diff --git a/src/effects/particles_effect.cc b/src/effects/particles_effect.cc index 5762637..b05aecd 100644 --- a/src/effects/particles_effect.cc +++ b/src/effects/particles_effect.cc @@ -2,8 +2,8 @@ // It implements the ParticlesEffect. #include "gpu/demo_effects.h" -#include "gpu/post_process_helper.h" #include "gpu/gpu.h" +#include "gpu/post_process_helper.h" #include <vector> // --- ParticlesEffect --- diff --git a/src/effects/rotating_cube_effect.cc b/src/effects/rotating_cube_effect.cc index a42feaa..c03eccb 100644 --- a/src/effects/rotating_cube_effect.cc +++ b/src/effects/rotating_cube_effect.cc @@ -5,9 +5,9 @@ #include "effects/rotating_cube_effect.h" #include "generated/assets.h" #include "gpu/bind_group_builder.h" -#include "gpu/shader_composer.h" #include "gpu/gpu.h" #include "gpu/sampler_cache.h" +#include "gpu/shader_composer.h" #include "util/asset_manager_utils.h" RotatingCubeEffect::RotatingCubeEffect(const GpuContext& ctx) : Effect(ctx) { @@ -39,12 +39,16 @@ void RotatingCubeEffect::init(MainSequence* demo) { TextureWithView noise = gpu_create_texture_2d( ctx_.device, 1, 1, WGPUTextureFormat_RGBA8Unorm, - (WGPUTextureUsage)(WGPUTextureUsage_TextureBinding | WGPUTextureUsage_RenderAttachment), 1); + (WGPUTextureUsage)(WGPUTextureUsage_TextureBinding | + WGPUTextureUsage_RenderAttachment), + 1); noise_texture_ = noise.texture; noise_view_ = noise.view; - noise_sampler_ = SamplerCache::Get().get_or_create(ctx_.device, SamplerCache::linear()); - mask_sampler_ = SamplerCache::Get().get_or_create(ctx_.device, SamplerCache::clamp()); + noise_sampler_ = + SamplerCache::Get().get_or_create(ctx_.device, SamplerCache::linear()); + mask_sampler_ = + SamplerCache::Get().get_or_create(ctx_.device, SamplerCache::clamp()); size_t shader_size; const char* shader_code = diff --git a/src/effects/scene1_effect.cc b/src/effects/scene1_effect.cc index c75e511..3d6df3b 100644 --- a/src/effects/scene1_effect.cc +++ b/src/effects/scene1_effect.cc @@ -5,7 +5,8 @@ #include "gpu/gpu.h" Scene1Effect::Scene1Effect(const GpuContext& ctx) : Effect(ctx) { - ResourceBinding bindings[] = {{uniforms_.get(), WGPUBufferBindingType_Uniform}}; + ResourceBinding bindings[] = { + {uniforms_.get(), WGPUBufferBindingType_Uniform}}; pass_ = gpu_create_render_pass(ctx_.device, ctx_.format, scene1_shader_wgsl, bindings, 1); pass_.vertex_count = 3; diff --git a/src/effects/theme_modulation_effect.cc b/src/effects/theme_modulation_effect.cc index 1c81d79..82bfeb8 100644 --- a/src/effects/theme_modulation_effect.cc +++ b/src/effects/theme_modulation_effect.cc @@ -10,7 +10,8 @@ struct ThemeModulationParams { float theme_brightness; float _pad[3]; }; -static_assert(sizeof(ThemeModulationParams) == 16, "ThemeModulationParams must be 16 bytes for WGSL alignment"); +static_assert(sizeof(ThemeModulationParams) == 16, + "ThemeModulationParams must be 16 bytes for WGSL alignment"); ThemeModulationEffect::ThemeModulationEffect(const GpuContext& ctx) : PostProcessEffect(ctx) { @@ -82,8 +83,8 @@ void ThemeModulationEffect::render(WGPURenderPassEncoder pass, // Alternate between bright and dark every 4 seconds (2 pattern changes) // Music patterns change every 2 seconds at 120 BPM - float cycle_time = fmodf(uniforms.time, 8.0f); // 8 second cycle (4 patterns) - bool is_dark_section = (cycle_time >= 4.0f); // Dark for second half + float cycle_time = fmodf(uniforms.time, 8.0f); // 8 second cycle (4 patterns) + bool is_dark_section = (cycle_time >= 4.0f); // Dark for second half // Smooth transition between themes using a sine wave float transition = diff --git a/src/effects/vignette_effect.cc b/src/effects/vignette_effect.cc index 0e5f68f..f5c3f05 100644 --- a/src/effects/vignette_effect.cc +++ b/src/effects/vignette_effect.cc @@ -2,8 +2,8 @@ // It implements the VignetteEffect. #include "gpu/demo_effects.h" -#include "gpu/post_process_helper.h" #include "gpu/gpu.h" +#include "gpu/post_process_helper.h" VignetteEffect::VignetteEffect(const GpuContext& ctx) : VignetteEffect(ctx, VignetteParams()) { |
