From e9a8d4fa8453d45d3fc297b49089be651e7139df Mon Sep 17 00:00:00 2001 From: firestar99 Date: Sun, 7 Sep 2025 20:29:44 +0200 Subject: [PATCH] WIP shaders: wrap Texture in Arc within `Raster` --- node-graph/gcore/src/raster_types.rs | 22 +++++++++++++++---- node-graph/wgpu-executor/src/lib.rs | 2 +- .../per_pixel_adjust_runtime.rs | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/node-graph/gcore/src/raster_types.rs b/node-graph/gcore/src/raster_types.rs index 583de0a3d1..75aed1b145 100644 --- a/node-graph/gcore/src/raster_types.rs +++ b/node-graph/gcore/src/raster_types.rs @@ -134,10 +134,11 @@ pub use gpu::GPU; mod gpu { use super::*; use crate::raster_types::__private::Sealed; + use std::sync::Arc; #[derive(Clone, Debug, PartialEq, Hash)] pub struct GPU { - pub texture: wgpu::Texture, + pub texture: Arc, } impl Sealed for Raster {} @@ -150,7 +151,9 @@ mod gpu { impl Raster { pub fn new_gpu(texture: wgpu::Texture) -> Self { - Self::new(GPU { texture }) + Self::new(GPU { + texture: Arc::new(InnerTexture(texture)), + }) } pub fn data(&self) -> &wgpu::Texture { @@ -158,9 +161,20 @@ mod gpu { } } - impl Drop for GPU { + #[derive(Debug, PartialEq, Hash)] + pub struct InnerTexture(wgpu::Texture); + + impl Deref for InnerTexture { + type Target = wgpu::Texture; + + fn deref(&self) -> &Self::Target { + &self.0 + } + } + + impl Drop for InnerTexture { fn drop(&mut self) { - self.texture.destroy(); + self.0.destroy(); } } } diff --git a/node-graph/wgpu-executor/src/lib.rs b/node-graph/wgpu-executor/src/lib.rs index 8351d6cb54..34ffc5a3aa 100644 --- a/node-graph/wgpu-executor/src/lib.rs +++ b/node-graph/wgpu-executor/src/lib.rs @@ -140,7 +140,7 @@ impl WgpuExecutor { let mut renderer = self.vello_renderer.lock().await; for (image, texture) in context.resource_overrides.iter() { let texture_view = wgpu::TexelCopyTextureInfoBase { - texture: texture.texture.clone(), + texture: wgpu::Texture::clone(&texture.texture), mip_level: 0, origin: Origin3d::ZERO, aspect: TextureAspect::All, diff --git a/node-graph/wgpu-executor/src/shader_runtime/per_pixel_adjust_runtime.rs b/node-graph/wgpu-executor/src/shader_runtime/per_pixel_adjust_runtime.rs index aa567a5b93..7ed4bb65cf 100644 --- a/node-graph/wgpu-executor/src/shader_runtime/per_pixel_adjust_runtime.rs +++ b/node-graph/wgpu-executor/src/shader_runtime/per_pixel_adjust_runtime.rs @@ -230,7 +230,7 @@ impl PerPixelAdjustGraphicsPipeline { rp.draw(0..3, 0..1); TableRow { - element: Raster::new(GPU { texture: tex_out }), + element: Raster::new_gpu(tex_out), transform: *instance.transform, alpha_blending: *instance.alpha_blending, source_node_id: *instance.source_node_id,