Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions node-graph/gcore/src/raster_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<InnerTexture>,
}

impl Sealed for Raster<GPU> {}
Expand All @@ -150,13 +151,32 @@ mod gpu {

impl Raster<GPU> {
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 {
&self.texture
}
}

#[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.0.destroy();
}
}
}

#[cfg(not(feature = "wgpu"))]
Expand All @@ -174,6 +194,10 @@ mod gpu {
true
}
}

impl Drop for GPU {
fn drop(&mut self) {}
}
}

mod gpu_common {
Expand Down
4 changes: 2 additions & 2 deletions node-graph/gsvg-renderer/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Default for SvgRender {
#[derive(Clone, Debug, Default)]
pub struct RenderContext {
#[cfg(feature = "vello")]
pub resource_overrides: Vec<(peniko::Image, wgpu::Texture)>,
pub resource_overrides: Vec<(peniko::Image, Raster<GPU>)>,
}

/// Static state used whilst rendering
Expand Down Expand Up @@ -1326,7 +1326,7 @@ impl Render for Table<Raster<GPU>> {
.with_extend(peniko::Extend::Repeat);
let image_transform = transform * *row.transform * DAffine2::from_scale(1. / DVec2::new(image.width as f64, image.height as f64));
scene.draw_image(&image, kurbo::Affine::new(image_transform.to_cols_array()));
context.resource_overrides.push((image, row.element.data().clone()));
context.resource_overrides.push((image, row.element.clone()));

if layer {
scene.pop_layer()
Expand Down
2 changes: 1 addition & 1 deletion node-graph/wgpu-executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.clone(),
texture: wgpu::Texture::clone(&texture.texture),
mip_level: 0,
origin: Origin3d::ZERO,
aspect: TextureAspect::All,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down