This commit is contained in:
Timon
2026-06-17 10:31:23 +00:00
parent c5bd8acce9
commit b01c6ea3ab
4 changed files with 25 additions and 21 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ pub fn wrap_network_in_scope(network: NodeNetwork, editor_api: Arc<PlatformEdito
DocumentNode { DocumentNode {
call_argument: concrete!(Context), call_argument: concrete!(Context),
inputs: vec![ inputs: vec![
NodeInput::scope(graphene_std::render_background::background_compositor_pipeline::IDENTIFIER), NodeInput::scope(graphene_std::render_background::composit_background_pipeline::IDENTIFIER),
NodeInput::node(NodeId(3), 0), NodeInput::node(NodeId(3), 0),
], ],
implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_background::render_background::IDENTIFIER), implementation: DocumentNodeImplementation::ProtoNode(graphene_std::render_background::render_background::IDENTIFIER),
@@ -267,7 +267,7 @@ pub async fn editor_api<'a: 'n>(_: impl Ctx, #[scope("editor-api")] editor_api:
} }
#[node_macro::node(category(""))] #[node_macro::node(category(""))]
pub async fn resource<'a: 'n>(_: impl Ctx, hash: ResourceHash, #[editor_api::IDENTIFIER] editor_api: &'a PlatformEditorApi) -> Resource { pub async fn resource<'a: 'n>(_: impl Ctx, hash: ResourceHash, #[scope(editor_api::IDENTIFIER)] editor_api: &'a PlatformEditorApi) -> Resource {
let application_io = editor_api.application_io.as_ref().expect("ApplicationIo must be available when using resources"); let application_io = editor_api.application_io.as_ref().expect("ApplicationIo must be available when using resources");
application_io.load_resource(hash).await.unwrap_or_else(|| { application_io.load_resource(hash).await.unwrap_or_else(|| {
panic!("Resource {hash} not found"); panic!("Resource {hash} not found");
@@ -275,11 +275,11 @@ pub async fn resource<'a: 'n>(_: impl Ctx, hash: ResourceHash, #[editor_api::IDE
} }
#[node_macro::node(category(""), inject_scope)] #[node_macro::node(category(""), inject_scope)]
pub async fn wgpu_executor<'a: 'n>(_: impl Ctx, #[editor_api::IDENTIFIER] editor_api: &'a PlatformEditorApi) -> &'a ::wgpu_executor::WgpuExecutor { pub async fn wgpu_executor<'a: 'n>(_: impl Ctx, #[scope(editor_api::IDENTIFIER)] editor_api: &'a PlatformEditorApi) -> &'a ::wgpu_executor::WgpuExecutor {
editor_api.application_io.as_ref().unwrap().gpu_executor().expect("GPU executor not available") editor_api.application_io.as_ref().unwrap().gpu_executor().expect("GPU executor not available")
} }
#[node_macro::node(category(""), inject_scope)] #[node_macro::node(category(""), inject_scope)]
pub async fn try_wgpu_executor<'a: 'n>(_: impl Ctx, #[editor_api::IDENTIFIER] editor_api: &'a PlatformEditorApi) -> Option<&'a ::wgpu_executor::WgpuExecutor> { pub async fn try_wgpu_executor<'a: 'n>(_: impl Ctx, #[scope(editor_api::IDENTIFIER)] editor_api: &'a PlatformEditorApi) -> Option<&'a ::wgpu_executor::WgpuExecutor> {
editor_api.application_io.as_ref().unwrap().gpu_executor() editor_api.application_io.as_ref().unwrap().gpu_executor()
} }
+13 -11
View File
@@ -14,7 +14,7 @@ use wgpu_executor::{AsyncWgpuPipeline, WgpuExecutor, WgpuPipelineCache};
#[node_macro::node(category(""))] #[node_macro::node(category(""))]
async fn render_background<'a: 'n>( async fn render_background<'a: 'n>(
ctx: impl Ctx + ExtractFootprint + ExtractVarArgs, ctx: impl Ctx + ExtractFootprint + ExtractVarArgs,
#[scope(background_compositor_pipeline::IDENTIFIER)] pipeline: WgpuPipelineCache, #[scope(composit_background_pipeline::IDENTIFIER)] pipeline: WgpuPipelineCache,
data: RenderOutput, data: RenderOutput,
) -> RenderOutput { ) -> RenderOutput {
let footprint = ctx.footprint(); let footprint = ctx.footprint();
@@ -36,7 +36,7 @@ async fn render_background<'a: 'n>(
RenderOutputType::Texture(foreground_texture) => { RenderOutputType::Texture(foreground_texture) => {
let doc_to_screen = (glam::DAffine2::from_scale(glam::DVec2::splat(render_params.scale)) * render_params.footprint.transform).as_affine2(); let doc_to_screen = (glam::DAffine2::from_scale(glam::DVec2::splat(render_params.scale)) * render_params.footprint.transform).as_affine2();
let blended = pipeline let blended = pipeline
.run::<BackgroundCompositor>(&BackgroundCompositorArgs { .run::<CompositBackground>(&CompositBackgroundArgs {
foreground: foreground_texture.as_ref(), foreground: foreground_texture.as_ref(),
backgrounds: &metadata.backgrounds, backgrounds: &metadata.backgrounds,
document_to_screen: doc_to_screen, document_to_screen: doc_to_screen,
@@ -118,16 +118,18 @@ async fn render_background<'a: 'n>(
} }
#[node_macro::node(category(""), inject_scope)] #[node_macro::node(category(""), inject_scope)]
async fn background_compositor_pipeline<'a: 'n>( async fn composit_background_pipeline<'a: 'n>(
_ctx: impl Ctx, _ctx: impl Ctx,
#[scope(crate::platform_application_io::wgpu_executor::IDENTIFIER)] executor: &'a WgpuExecutor, #[scope(crate::platform_application_io::try_wgpu_executor::IDENTIFIER)] executor: Option<&'a WgpuExecutor>,
#[data] pipeline: WgpuPipelineCache, #[data] pipeline: WgpuPipelineCache,
) -> WgpuPipelineCache { ) -> WgpuPipelineCache {
executor.pipeline_init::<BackgroundCompositor>(pipeline); if let Some(executor) = executor {
executor.pipeline_init::<CompositBackground>(pipeline);
}
pipeline.clone() pipeline.clone()
} }
pub struct BackgroundCompositor { pub struct CompositBackground {
checker_rect_pipeline: wgpu::RenderPipeline, checker_rect_pipeline: wgpu::RenderPipeline,
checker_viewport_pipeline: wgpu::RenderPipeline, checker_viewport_pipeline: wgpu::RenderPipeline,
fullscreen_pipeline: wgpu::RenderPipeline, fullscreen_pipeline: wgpu::RenderPipeline,
@@ -136,15 +138,15 @@ pub struct BackgroundCompositor {
sampler: wgpu::Sampler, sampler: wgpu::Sampler,
} }
pub struct BackgroundCompositorArgs<'a> { pub struct CompositBackgroundArgs<'a> {
foreground: &'a wgpu::Texture, foreground: &'a wgpu::Texture,
backgrounds: &'a [rendering::Background], backgrounds: &'a [rendering::Background],
document_to_screen: Affine2, document_to_screen: Affine2,
zoom: f32, zoom: f32,
} }
impl AsyncWgpuPipeline for BackgroundCompositor { impl AsyncWgpuPipeline for CompositBackground {
type Args<'a> = BackgroundCompositorArgs<'a>; type Args<'a> = CompositBackgroundArgs<'a>;
type Out = Arc<wgpu::Texture>; type Out = Arc<wgpu::Texture>;
fn create(executor: &WgpuExecutor) -> Self { fn create(executor: &WgpuExecutor) -> Self {
@@ -327,7 +329,7 @@ impl AsyncWgpuPipeline for BackgroundCompositor {
} }
async fn run<'a>(&'a self, executor: &'a WgpuExecutor, args: &'a Self::Args<'_>) -> Self::Out { async fn run<'a>(&'a self, executor: &'a WgpuExecutor, args: &'a Self::Args<'_>) -> Self::Out {
let &BackgroundCompositorArgs { let &CompositBackgroundArgs {
foreground, foreground,
backgrounds, backgrounds,
document_to_screen, document_to_screen,
@@ -437,7 +439,7 @@ impl AsyncWgpuPipeline for BackgroundCompositor {
} }
} }
impl BackgroundCompositor { impl CompositBackground {
fn create_checker_bind_group(&self, device: &wgpu::Device, uniforms: CompositeUniforms) -> wgpu::BindGroup { fn create_checker_bind_group(&self, device: &wgpu::Device, uniforms: CompositeUniforms) -> wgpu::BindGroup {
let buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { let buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some("background_checker_uniforms"), label: Some("background_checker_uniforms"),
@@ -58,7 +58,7 @@ pub async fn render_pixel_preview<'a: 'n>(
let transform = DAffine2::from_translation(-upstream_min) * footprint.transform.inverse() * DAffine2::from_scale(logical_resolution); let transform = DAffine2::from_translation(-upstream_min) * footprint.transform.inverse() * DAffine2::from_scale(logical_resolution);
let resampled = pipeline let resampled = pipeline
.run::<PixelPreview>(&ResamplerArgs { .run::<PixelPreview>(&PixelPreviewArgs {
source: source_texture.as_ref(), source: source_texture.as_ref(),
transform: &transform, transform: &transform,
size: physical_resolution, size: physical_resolution,
@@ -77,10 +77,12 @@ pub async fn render_pixel_preview<'a: 'n>(
#[node_macro::node(category(""), inject_scope)] #[node_macro::node(category(""), inject_scope)]
async fn pixel_preview_pipeline<'a: 'n>( async fn pixel_preview_pipeline<'a: 'n>(
_ctx: impl Ctx, _ctx: impl Ctx,
#[scope(crate::platform_application_io::wgpu_executor::IDENTIFIER)] executor: &'a WgpuExecutor, #[scope(crate::platform_application_io::try_wgpu_executor::IDENTIFIER)] executor: Option<&'a WgpuExecutor>,
#[data] pipeline: WgpuPipelineCache, #[data] pipeline: WgpuPipelineCache,
) -> WgpuPipelineCache { ) -> WgpuPipelineCache {
executor.pipeline_init::<PixelPreview>(pipeline); if let Some(executor) = executor {
executor.pipeline_init::<PixelPreview>(pipeline);
}
pipeline.clone() pipeline.clone()
} }
@@ -89,14 +91,14 @@ pub struct PixelPreview {
bind_group_layout: wgpu::BindGroupLayout, bind_group_layout: wgpu::BindGroupLayout,
} }
pub struct ResamplerArgs<'a> { pub struct PixelPreviewArgs<'a> {
source: &'a wgpu::Texture, source: &'a wgpu::Texture,
transform: &'a DAffine2, transform: &'a DAffine2,
size: UVec2, size: UVec2,
} }
impl AsyncWgpuPipeline for PixelPreview { impl AsyncWgpuPipeline for PixelPreview {
type Args<'a> = ResamplerArgs<'a>; type Args<'a> = PixelPreviewArgs<'a>;
type Out = Arc<wgpu::Texture>; type Out = Arc<wgpu::Texture>;
fn create(executor: &WgpuExecutor) -> Self { fn create(executor: &WgpuExecutor) -> Self {
@@ -169,7 +171,7 @@ impl AsyncWgpuPipeline for PixelPreview {
async fn run<'a>(&'a self, executor: &'a WgpuExecutor, args: &'a Self::Args<'_>) -> Self::Out { async fn run<'a>(&'a self, executor: &'a WgpuExecutor, args: &'a Self::Args<'_>) -> Self::Out {
let context = &executor.context(); let context = &executor.context();
let &ResamplerArgs { source, transform, size } = args; let &PixelPreviewArgs { source, transform, size } = args;
let output = executor.request_texture(size).await; let output = executor.request_texture(size).await;