Shaders: runtime and shader node codegen (#2985)

* shader-rt: initial

* shader-rt: fix recursion when generating shader node

* shader-rt: replace gpu node's args and ret types with `Raster<GPU>`

* shader-rt: properly cfg out the gpu node

* shader-rt: fix `impl Context` in the wrong places

* shader-rt: disable gpu blend node, needs two images

* shader-rt: connect shader runtime

* shader-rt: pass WgpuExecutor by reference

* shader-rt: correct bindings with derpy arg buffer

* shader-rt: manual pipeline layout, fixing errors when bindings got DCE'd

* shader-rt: correct RT format, working invert gpu node

* shader-rt: cleanup codegen with common sym struct

* shader-rt: correct arg buffer handling

* shader-nodes feature: put shader nodes behind feature gate

* shader-nodes feature: rename any `gpu_node` to `shader-node`

* shaders-rt: fix wgpu label name

* shaders-rt: explain fullscreen_vertex coordinates with a drawing
This commit is contained in:
Firestar99
2025-09-05 08:33:53 +02:00
committed by GitHub
parent 7dc86b36ca
commit 5d441c2e18
15 changed files with 619 additions and 63 deletions

View File

@@ -30,7 +30,7 @@ use num_traits::float::Float;
// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=%27clrL%27%20%3D%20Color%20Lookup
// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=Color%20Lookup%20(Photoshop%20CS6
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, node_macro::ChoiceType)]
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash, node_macro::ChoiceType, bytemuck::NoUninit)]
#[cfg_attr(feature = "std", derive(dyn_any::DynAny, specta::Type, serde::Serialize, serde::Deserialize))]
#[widget(Dropdown)]
#[repr(u32)]
@@ -560,7 +560,7 @@ pub enum RedGreenBlue {
}
/// Color Channel
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, node_macro::ChoiceType)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, node_macro::ChoiceType, bytemuck::NoUninit)]
#[cfg_attr(feature = "std", derive(dyn_any::DynAny, specta::Type, serde::Serialize, serde::Deserialize))]
#[widget(Radio)]
#[repr(u32)]

View File

@@ -132,7 +132,7 @@ pub fn apply_blend_mode(foreground: Color, background: Color, blend_mode: BlendM
}
}
#[node_macro::node(category("Raster"), shader_node(PerPixelAdjust))]
#[node_macro::node(category("Raster"), cfg(feature = "std"))]
fn blend<T: Blend<Color> + Send>(
_: impl Ctx,
#[implementations(

View File

@@ -0,0 +1,29 @@
use glam::{Vec2, Vec4};
use spirv_std::spirv;
/// webgpu NDC is like OpenGL: (-1.0 .. 1.0, -1.0 .. 1.0, 0.0 .. 1.0)
/// https://www.w3.org/TR/webgpu/#coordinate-systems
///
/// So to make a fullscreen triangle around a box at (-1..1):
///
/// ```norun
/// 3 +
/// |\
/// 2 | \
/// | \
/// 1 +-----+
/// | |\
/// 0 | 0 | \
/// | | \
/// -1 +-----+-----+
/// -1 0 1 2 3
/// ```
const FULLSCREEN_VERTICES: [Vec2; 3] = [Vec2::new(-1., -1.), Vec2::new(-1., 3.), Vec2::new(3., -1.)];
#[spirv(vertex)]
pub fn fullscreen_vertex(#[spirv(vertex_index)] vertex_index: u32, #[spirv(position)] gl_position: &mut Vec4) {
// broken on edition 2024 branch
// let vertex = unsafe { *FULLSCREEN_VERTICES.index_unchecked(vertex_index as usize) };
let vertex = FULLSCREEN_VERTICES[vertex_index as usize];
*gl_position = Vec4::from((vertex, 0., 1.));
}

View File

@@ -4,6 +4,11 @@ pub mod adjust;
pub mod adjustments;
pub mod blending_nodes;
pub mod cubic_spline;
pub mod fullscreen_vertex;
/// required by shader macro
#[cfg(feature = "shader-nodes")]
pub use graphene_raster_nodes_shaders::WGSL_SHADER;
#[cfg(feature = "std")]
pub mod curve;