From 2cb2dd31fc3bede56c042d4dfe128dfc03a6fa46 Mon Sep 17 00:00:00 2001 From: Timon Date: Thu, 3 Dec 2026 23:22:55 +0000 Subject: [PATCH] Take effect row textures and Mandelbrot reference orbits from the texture pool (fixup #5010) --- .../wgpu-executor/src/vello_effects.rs | 22 +++----- .../wgpu-executor/src/vello_effects/masks.rs | 2 +- .../wgpu-executor/src/vello_effects/styles.rs | 2 +- .../wgpu-executor/src/vello_generators.rs | 51 +++++++++++-------- .../wgpu-executor/src/vello_render.rs | 3 +- .../wgpu-executor/src/vello_render/tests.rs | 4 +- 6 files changed, 43 insertions(+), 41 deletions(-) diff --git a/node-graph/libraries/wgpu-executor/src/vello_effects.rs b/node-graph/libraries/wgpu-executor/src/vello_effects.rs index c8eb12f199..35e4fba52f 100644 --- a/node-graph/libraries/wgpu-executor/src/vello_effects.rs +++ b/node-graph/libraries/wgpu-executor/src/vello_effects.rs @@ -1603,7 +1603,7 @@ impl PassRecorder<'_> { fn gradient_glow_tint(&mut self, paint: &GlowFill, strength: &wgpu::Texture, content: &wgpu::Texture, fades: bool, grain: Option<&styles::GlowGrain>) -> Option { let (samples, opacity) = paint.gradient_samples(GRADIENT_SAMPLES as usize)?; let samples: Vec = samples.into_iter().flatten().map(half::f16::from_f32).collect(); - let samples = self.row_texture("vello_effects_gradient", wgpu::TextureFormat::Rgba16Float, GRADIENT_SAMPLES, bytemuck::cast_slice(&samples)); + let samples = self.row_texture(wgpu::TextureFormat::Rgba16Float, GRADIENT_SAMPLES, bytemuck::cast_slice(&samples)); let parameters = Parameters { values: [if fades { 1. } else { 0. }, GRADIENT_GLOW_FADE as f32, opacity, grain.map_or(0., |grain| grain.amounts[0] as f32)], @@ -1658,27 +1658,17 @@ impl PassRecorder<'_> { let samples: Vec = (0..CONTOUR_SAMPLES) .map(|index| half::f16::from_f64(contour.evaluate(index as f64 / (CONTOUR_SAMPLES - 1) as f64).clamp(0., 1.))) .collect(); - self.row_texture("vello_effects_contour", COVERAGE_FORMAT, CONTOUR_SAMPLES, bytemuck::cast_slice(&samples)) + self.row_texture(COVERAGE_FORMAT, CONTOUR_SAMPLES, bytemuck::cast_slice(&samples)) } /// A texture one row of `width` texels tall holding `data` in the `format`, for shaders to interpolate between its samples. - /// It's made fresh rather than pooled, since its upload runs ahead of the passes recorded before it that a pooled texture may still serve. - fn row_texture(&mut self, label: &str, format: wgpu::TextureFormat, width: u32, data: &[u8]) -> wgpu::Texture { + fn row_texture(&mut self, format: wgpu::TextureFormat, width: u32, data: &[u8]) -> wgpu::Texture { let extent = wgpu::Extent3d { width, height: 1, depth_or_array_layers: 1, }; - let texture = self.device.create_texture(&wgpu::TextureDescriptor { - label: Some(label), - size: extent, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format, - usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, - view_formats: &[], - }); + let texture = self.executor.request_texture_with_format(UVec2::new(width, 1), format); self.queue.write_texture( wgpu::TexelCopyTextureInfo { texture: &texture, @@ -1694,7 +1684,9 @@ impl PassRecorder<'_> { }, extent, ); - texture + let row = (*texture).clone(); + self.textures.held.push(texture); + row } /// The coverage (or tinted image) of what lies beneath, hidden behind the full-strength content where a `fill` below 1 (times the Blend If weight if any) fades the content that shows over it. diff --git a/node-graph/libraries/wgpu-executor/src/vello_effects/masks.rs b/node-graph/libraries/wgpu-executor/src/vello_effects/masks.rs index 4bbfc81c0a..2cf3aac04a 100644 --- a/node-graph/libraries/wgpu-executor/src/vello_effects/masks.rs +++ b/node-graph/libraries/wgpu-executor/src/vello_effects/masks.rs @@ -86,7 +86,7 @@ impl PassRecorder<'_> { }) .map(half::f16::from_f32) .collect(); - let table = self.row_texture("vello_effects_masked_radius_blur", wgpu::TextureFormat::Rgba16Float, 256, bytemuck::cast_slice(&blends)); + let table = self.row_texture(wgpu::TextureFormat::Rgba16Float, 256, bytemuck::cast_slice(&blends)); let interpolation = self.run("masked_radius_blur_interpolation", WORKING_FORMAT, self.size, luminance, Some(&table), None, Parameters::default()); if full_is_read && let Some(blurred) = self.masked_radius_blur_image(full.as_ref().unwrap_or(content), &interpolation, levels, linear) { diff --git a/node-graph/libraries/wgpu-executor/src/vello_effects/styles.rs b/node-graph/libraries/wgpu-executor/src/vello_effects/styles.rs index e6672f77bf..6c11ee38ce 100644 --- a/node-graph/libraries/wgpu-executor/src/vello_effects/styles.rs +++ b/node-graph/libraries/wgpu-executor/src/vello_effects/styles.rs @@ -74,7 +74,7 @@ impl PassRecorder<'_> { return band; }; let samples: Vec = samples.into_iter().flatten().map(half::f16::from_f32).collect(); - let samples = self.row_texture("vello_effects_gradient", wgpu::TextureFormat::Rgba16Float, GRADIENT_SAMPLES, bytemuck::cast_slice(&samples)); + let samples = self.row_texture(wgpu::TextureFormat::Rgba16Float, GRADIENT_SAMPLES, bytemuck::cast_slice(&samples)); let parameters = Parameters { amount: opacity, diff --git a/node-graph/libraries/wgpu-executor/src/vello_generators.rs b/node-graph/libraries/wgpu-executor/src/vello_generators.rs index 948ecd2f11..0e2a66e2d2 100644 --- a/node-graph/libraries/wgpu-executor/src/vello_generators.rs +++ b/node-graph/libraries/wgpu-executor/src/vello_generators.rs @@ -272,7 +272,7 @@ impl Tile { } /// The texture holding a reference orbit's values and their raisings for the Mandelbrot shader, in rows of `REFERENCE_ROW_LENGTH`, or one empty texel without one. -fn reference_texture(device: &wgpu::Device, queue: &wgpu::Queue, reference: Option<&ReferenceOrbit>) -> wgpu::Texture { +fn reference_texture(executor: &WgpuExecutor, queue: &wgpu::Queue, reference: Option<&ReferenceOrbit>) -> Texture { let (values, raised_values) = reference.map_or((&[][..], &[][..]), |reference| (&reference.values[..], &reference.raised_values[..])); let (width, height) = (values.len().clamp(1, REFERENCE_ROW_LENGTH), values.len().div_ceil(REFERENCE_ROW_LENGTH).max(1)); @@ -281,25 +281,18 @@ fn reference_texture(device: &wgpu::Device, queue: &wgpu::Queue, reference: Opti *texel = [value.x, value.y, raised.x, raised.y]; } - device.create_texture_with_data( - queue, - &wgpu::TextureDescriptor { - label: Some("vello_generator_reference_orbit"), - size: wgpu::Extent3d { - width: width as u32, - height: height as u32, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba32Float, - usage: wgpu::TextureUsages::TEXTURE_BINDING, - view_formats: &[], - }, - wgpu::util::TextureDataOrder::LayerMajor, + let texture = executor.request_texture_with_format(UVec2::new(width as u32, height as u32), wgpu::TextureFormat::Rgba32Float); + queue.write_texture( + texture.as_image_copy(), bytemuck::cast_slice(&texels), - ) + wgpu::TexelCopyBufferLayout { + offset: 0, + bytes_per_row: Some(width as u32 * size_of::<[f32; 4]>() as u32), + rows_per_image: Some(height as u32), + }, + texture.size(), + ); + texture } /// The pipelines of the pass, one for each shader. @@ -394,7 +387,18 @@ impl GeneratorPasses { /// Records the rendering of a square tile of `pattern` into the top mip level of `texture`, with its top left corner at `corner` of the pattern's space and pixels `texel` units across. #[allow(clippy::too_many_arguments)] - pub(crate) fn render_tile(&self, device: &wgpu::Device, queue: &wgpu::Queue, encoder: &mut wgpu::CommandEncoder, texture: &wgpu::Texture, pattern: &GeneratorPattern, corner: DVec2, texel: f64) { + pub(crate) fn render_tile( + &self, + executor: &WgpuExecutor, + queue: &wgpu::Queue, + encoder: &mut wgpu::CommandEncoder, + held: &mut Vec, + texture: &wgpu::Texture, + pattern: &GeneratorPattern, + corner: DVec2, + texel: f64, + ) { + let device = &executor.context().device; let tile = Tile::new(pattern, corner, texel, texture.width()); let (pipeline, bind_group_layout) = self.pipeline(device, tile.shader); @@ -403,7 +407,12 @@ impl GeneratorPasses { contents: &tile.parameters, usage: wgpu::BufferUsages::UNIFORM, }); - let reference_view = (tile.shader == Shader::Mandelbrot).then(|| reference_texture(device, queue, tile.reference.as_ref()).create_view(&wgpu::TextureViewDescriptor::default())); + let reference_view = (tile.shader == Shader::Mandelbrot).then(|| { + let reference = reference_texture(executor, queue, tile.reference.as_ref()); + let view = reference.create_view(&wgpu::TextureViewDescriptor::default()); + held.push(reference); + view + }); let mut entries = vec![wgpu::BindGroupEntry { binding: 0, resource: buffer.as_entire_binding(), diff --git a/node-graph/libraries/wgpu-executor/src/vello_render.rs b/node-graph/libraries/wgpu-executor/src/vello_render.rs index 994e51cc53..2a799783f7 100644 --- a/node-graph/libraries/wgpu-executor/src/vello_render.rs +++ b/node-graph/libraries/wgpu-executor/src/vello_render.rs @@ -542,7 +542,6 @@ impl ImageTextures { max_texture_size: u32, held: &mut Vec, ) -> Option { - let device = &executor.context().device; let key = match image { SceneImage::Pixels(data) => ImageKey::Blob(data.data.id()), SceneImage::Raster { raster, .. } => ImageKey::Raster(raster.buffer_id()), @@ -552,7 +551,7 @@ impl ImageTextures { None => { let texture = GeneratorPasses::tile_texture(executor, GeneratorTile::SAMPLES); let (corner, texel) = tile.corner_and_texel(); - renderer.generator_passes.render_tile(device, queue, encoder, &texture, pattern, corner, texel); + renderer.generator_passes.render_tile(executor, queue, encoder, held, &texture, pattern, corner, texel); renderer.effect_passes.record_mipmaps(executor, encoder, effect_textures, &texture); self.generator_tiles.insert(*tile, texture.downgrade()); texture diff --git a/node-graph/libraries/wgpu-executor/src/vello_render/tests.rs b/node-graph/libraries/wgpu-executor/src/vello_render/tests.rs index 4c62c4b355..33044d25e6 100644 --- a/node-graph/libraries/wgpu-executor/src/vello_render/tests.rs +++ b/node-graph/libraries/wgpu-executor/src/vello_render/tests.rs @@ -6326,8 +6326,10 @@ fn generator_tile_pixels(pattern: &graphic_types::generator::GeneratorPattern, c let queue = executor.context().queue.lock(); let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("generator_tile_test") }); - (executor.inner.vello_renderer.generator_passes).render_tile(device, &queue, &mut encoder, &texture, pattern, corner, texel); + let mut held = Vec::new(); + (executor.inner.vello_renderer.generator_passes).render_tile(executor, &queue, &mut encoder, &mut held, &texture, pattern, corner, texel); queue.submit([encoder.finish()]); + drop(held); drop(queue); let bytes = executor.read_texture_pixels(&texture).expect("Failed to read back the tile");