From dbd68ff1396bf498eb97f095810b78d2bddd0011 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Mon, 13 Apr 2026 04:40:19 +0200 Subject: refactor: gpu webgl fallback and batched command encoding Made-with: Cursor --- rust/crates/effects/src/pipeline.rs | 42 +++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) (limited to 'rust/crates/effects') diff --git a/rust/crates/effects/src/pipeline.rs b/rust/crates/effects/src/pipeline.rs index 58692bde..1ea49053 100644 --- a/rust/crates/effects/src/pipeline.rs +++ b/rust/crates/effects/src/pipeline.rs @@ -1,7 +1,7 @@ use std::collections::HashMap; use bytemuck::{Pod, Zeroable}; -use gpu::{FULLSCREEN_SHADER_SOURCE, GPU_TEXTURE_FORMAT, GpuContext}; +use gpu::{FULLSCREEN_SHADER_SOURCE, GpuContext}; use thiserror::Error; use wgpu::util::DeviceExt; @@ -119,7 +119,7 @@ impl EffectPipeline { module: &gaussian_blur_shader_module, entry_point: Some("fragment_main"), targets: &[Some(wgpu::ColorTargetState { - format: GPU_TEXTURE_FORMAT, + format: context.texture_format(), blend: None, write_mask: wgpu::ColorWrites::ALL, })], @@ -149,6 +149,37 @@ impl EffectPipeline { height, passes, }: ApplyEffectsOptions<'_>, + ) -> Result { + let mut encoder = + context + .device() + .create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("effects-command-encoder"), + }); + let output = self.apply_with_encoder( + context, + &mut encoder, + ApplyEffectsOptions { + source, + width, + height, + passes, + }, + )?; + context.queue().submit([encoder.finish()]); + Ok(output) + } + + pub fn apply_with_encoder( + &self, + context: &GpuContext, + encoder: &mut wgpu::CommandEncoder, + ApplyEffectsOptions { + source, + width, + height, + passes, + }: ApplyEffectsOptions<'_>, ) -> Result { let mut current_texture: Option = None; @@ -199,12 +230,6 @@ impl EffectPipeline { shader: pass.shader.clone(), } })?; - let mut encoder = - context - .device() - .create_command_encoder(&wgpu::CommandEncoderDescriptor { - label: Some("effects-command-encoder"), - }); { let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { @@ -230,7 +255,6 @@ impl EffectPipeline { render_pass.draw(0..6, 0..1); } - context.queue().submit([encoder.finish()]); current_texture = Some(output_texture); } -- cgit v1.3.1