From d3d422c27eb4366b66f698f4ee9348cef311301c Mon Sep 17 00:00:00 2001 From: firestar99 Date: Wed, 20 Aug 2025 17:18:03 +0200 Subject: [PATCH] shader-rt: manual pipeline layout, fixing errors when bindings got DCE'd --- .../src/shader_nodes/per_pixel_adjust.rs | 2 +- .../per_pixel_adjust_runtime.rs | 42 ++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/node-graph/node-macro/src/shader_nodes/per_pixel_adjust.rs b/node-graph/node-macro/src/shader_nodes/per_pixel_adjust.rs index 06a450801..3203e4328 100644 --- a/node-graph/node-macro/src/shader_nodes/per_pixel_adjust.rs +++ b/node-graph/node-macro/src/shader_nodes/per_pixel_adjust.rs @@ -190,7 +190,7 @@ impl PerPixelAdjust { #wgpu_executor.shader_runtime.run_per_pixel_adjust(&::wgpu_executor::shader_runtime::Shaders { wgsl_shader: crate::WGSL_SHADER, fragment_shader_name: super::#entry_point_name, - }, #gpu_image, &()).await + }, #gpu_image, &1u32).await } }; 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 352adb7e9..746e1a900 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 @@ -8,9 +8,9 @@ use std::borrow::Cow; use std::collections::HashMap; use wgpu::util::{BufferInitDescriptor, DeviceExt}; use wgpu::{ - BindGroupDescriptor, BindGroupEntry, BindingResource, Buffer, BufferBinding, BufferUsages, ColorTargetState, Face, FragmentState, FrontFace, LoadOp, Operations, PolygonMode, PrimitiveState, - PrimitiveTopology, RenderPassColorAttachment, RenderPassDescriptor, RenderPipelineDescriptor, ShaderModuleDescriptor, ShaderSource, StoreOp, TextureDescriptor, TextureDimension, TextureFormat, - TextureViewDescriptor, VertexState, + BindGroupDescriptor, BindGroupEntry, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingResource, BindingType, Buffer, BufferBinding, BufferBindingType, BufferUsages, ColorTargetState, Face, + FragmentState, FrontFace, LoadOp, Operations, PipelineLayoutDescriptor, PolygonMode, PrimitiveState, PrimitiveTopology, RenderPassColorAttachment, RenderPassDescriptor, RenderPipelineDescriptor, + ShaderModuleDescriptor, ShaderSource, ShaderStages, StoreOp, TextureDescriptor, TextureDimension, TextureFormat, TextureSampleType, TextureViewDescriptor, TextureViewDimension, VertexState, }; pub struct PerPixelAdjustShaderRuntime { @@ -53,18 +53,48 @@ impl PerPixelAdjustGraphicsPipeline { let device = &context.device; let name = info.fragment_shader_name.to_owned(); - // TODO workaround to naga removing `:` let fragment_name = &name; let fragment_name = &fragment_name[(fragment_name.find("::").unwrap() + 2)..]; + // TODO workaround to naga removing `:` let fragment_name = fragment_name.replace(":", ""); - let shader_module = device.create_shader_module(ShaderModuleDescriptor { label: Some(&format!("PerPixelAdjust {} wgsl shader", name)), source: ShaderSource::Wgsl(Cow::Borrowed(info.wgsl_shader)), }); + + let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor { + label: Some(&format!("PerPixelAdjust {} PipelineLayout", name)), + bind_group_layouts: &[&device.create_bind_group_layout(&BindGroupLayoutDescriptor { + label: Some(&format!("PerPixelAdjust {} BindGroupLayout 0", name)), + entries: &[ + BindGroupLayoutEntry { + binding: 0, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Buffer { + ty: BufferBindingType::Storage { read_only: true }, + has_dynamic_offset: false, + min_binding_size: None, + }, + count: None, + }, + BindGroupLayoutEntry { + binding: 1, + visibility: ShaderStages::FRAGMENT, + ty: BindingType::Texture { + sample_type: TextureSampleType::Float { filterable: false }, + view_dimension: TextureViewDimension::D2, + multisampled: false, + }, + count: None, + }, + ], + })], + push_constant_ranges: &[], + }); + let pipeline = device.create_render_pipeline(&RenderPipelineDescriptor { label: Some(&format!("PerPixelAdjust {} Pipeline", name)), - layout: None, + layout: Some(&pipeline_layout), vertex: VertexState { module: &shader_module, entry_point: Some(FULLSCREEN_VERTEX_SHADER_NAME),