shader-rt: connect shader runtime

This commit is contained in:
firestar99 2025-08-21 11:08:14 +02:00
parent c5af8260bd
commit 6847bf062b
6 changed files with 80 additions and 16 deletions

View file

@ -2,6 +2,7 @@ mod context;
pub mod shader_runtime;
pub mod texture_upload;
use crate::shader_runtime::ShaderRuntime;
use anyhow::Result;
pub use context::Context;
use dyn_any::StaticType;
@ -19,6 +20,7 @@ use wgpu::{Origin3d, SurfaceConfiguration, TextureAspect};
pub struct WgpuExecutor {
pub context: Context,
vello_renderer: Mutex<Renderer>,
pub shader_runtime: ShaderRuntime,
}
impl std::fmt::Debug for WgpuExecutor {
@ -196,6 +198,7 @@ impl WgpuExecutor {
.ok()?;
Some(Self {
shader_runtime: ShaderRuntime::new(&context),
context,
vello_renderer: vello_renderer.into(),
})

View file

@ -35,8 +35,8 @@ impl ShaderRuntime {
}
pub struct PerPixelAdjustInfo<'a> {
shader_wgsl: &'a str,
fragment_shader_name: &'a str,
pub wgsl_shader: &'a str,
pub fragment_shader_name: &'a str,
}
pub struct PerPixelAdjustGraphicsPipeline {
@ -48,9 +48,12 @@ impl PerPixelAdjustGraphicsPipeline {
pub fn new(context: &Context, info: &PerPixelAdjustInfo) -> Self {
let device = &context.device;
let name = info.fragment_shader_name.to_owned();
// TODO workaround to naga removing `:`
let fragment_name = name.replace(":", "");
let shader_module = device.create_shader_module(ShaderModuleDescriptor {
label: Some(&format!("PerPixelAdjust {} wgsl shader", name)),
source: ShaderSource::Wgsl(Cow::Borrowed(info.shader_wgsl)),
source: ShaderSource::Wgsl(Cow::Borrowed(info.wgsl_shader)),
});
let pipeline = device.create_render_pipeline(&RenderPipelineDescriptor {
label: Some(&format!("PerPixelAdjust {} Pipeline", name)),
@ -74,7 +77,7 @@ impl PerPixelAdjustGraphicsPipeline {
multisample: Default::default(),
fragment: Some(FragmentState {
module: &shader_module,
entry_point: Some(&name),
entry_point: Some(&fragment_name),
compilation_options: Default::default(),
targets: &[Some(ColorTargetState {
format: TextureFormat::Rgba32Float,