diff --git a/deno_webgpu/pipeline.rs b/deno_webgpu/pipeline.rs index e0555b9d1e3..e8a6fe8e258 100644 --- a/deno_webgpu/pipeline.rs +++ b/deno_webgpu/pipeline.rs @@ -8,6 +8,7 @@ use deno_core::ResourceId; use serde::Deserialize; use serde::Serialize; use std::borrow::Cow; +use std::collections::HashMap; use std::rc::Rc; use super::error::WebGpuError; @@ -78,7 +79,7 @@ pub enum GPUPipelineLayoutOrGPUAutoLayoutMode { pub struct GpuProgrammableStage { module: ResourceId, entry_point: String, - // constants: HashMap + constants: HashMap, } #[op2] @@ -113,8 +114,8 @@ pub fn op_webgpu_create_compute_pipeline( layout: pipeline_layout, stage: wgpu_core::pipeline::ProgrammableStageDescriptor { module: compute_shader_module_resource.1, - entry_point: Cow::from(compute.entry_point), - // TODO(lucacasonato): support args.compute.constants + entry_point: Cow::Owned(compute.entry_point), + constants: Cow::Owned(compute.constants), }, }; let implicit_pipelines = match layout { @@ -282,6 +283,7 @@ impl<'a> From for wgpu_core::pipeline::VertexBufferLayout struct GpuVertexState { module: ResourceId, entry_point: String, + constants: HashMap, buffers: Vec>, } @@ -309,7 +311,7 @@ struct GpuFragmentState { targets: Vec>, module: u32, entry_point: String, - // TODO(lucacasonato): constants + constants: HashMap, } #[derive(Deserialize)] @@ -358,9 +360,10 @@ pub fn op_webgpu_create_render_pipeline( Some(wgpu_core::pipeline::FragmentState { stage: wgpu_core::pipeline::ProgrammableStageDescriptor { module: fragment_shader_module_resource.1, - entry_point: Cow::from(fragment.entry_point), + entry_point: Cow::Owned(fragment.entry_point), + constants: Cow::Owned(fragment.constants), }, - targets: Cow::from(fragment.targets), + targets: Cow::Owned(fragment.targets), }) } else { None @@ -381,6 +384,7 @@ pub fn op_webgpu_create_render_pipeline( stage: wgpu_core::pipeline::ProgrammableStageDescriptor { module: vertex_shader_module_resource.1, entry_point: Cow::Owned(args.vertex.entry_point), + constants: Cow::Owned(args.vertex.constants), }, buffers: Cow::Owned(vertex_buffers), }, diff --git a/examples/boids/src/main.rs b/examples/boids/src/main.rs index f81eadd4265..433737694b8 100644 --- a/examples/boids/src/main.rs +++ b/examples/boids/src/main.rs @@ -132,6 +132,7 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &draw_shader, entry_point: "main_vs", + constants: &Default::default(), buffers: &[ wgpu::VertexBufferLayout { array_stride: 4 * 4, @@ -148,6 +149,7 @@ impl wgpu_example::framework::Example for Example { fragment: Some(wgpu::FragmentState { module: &draw_shader, entry_point: "main_fs", + constants: &Default::default(), targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState::default(), @@ -163,6 +165,7 @@ impl wgpu_example::framework::Example for Example { layout: Some(&compute_pipeline_layout), module: &compute_shader, entry_point: "main", + constants: &Default::default(), }); // buffer for the three 2d triangle vertices of each instance diff --git a/examples/bunnymark/src/main.rs b/examples/bunnymark/src/main.rs index fc6d4414c95..a99063a19fa 100644 --- a/examples/bunnymark/src/main.rs +++ b/examples/bunnymark/src/main.rs @@ -203,11 +203,13 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(wgpu::ColorTargetState { format: config.view_formats[0], blend: Some(wgpu::BlendState::ALPHA_BLENDING), diff --git a/examples/conservative-raster/src/main.rs b/examples/conservative-raster/src/main.rs index 580c6781b93..bfcc8e8aed2 100644 --- a/examples/conservative-raster/src/main.rs +++ b/examples/conservative-raster/src/main.rs @@ -97,11 +97,13 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader_triangle_and_lines, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &shader_triangle_and_lines, entry_point: "fs_main_red", + constants: &Default::default(), targets: &[Some(RENDER_TARGET_FORMAT.into())], }), primitive: wgpu::PrimitiveState { @@ -120,11 +122,13 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader_triangle_and_lines, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &shader_triangle_and_lines, entry_point: "fs_main_blue", + constants: &Default::default(), targets: &[Some(RENDER_TARGET_FORMAT.into())], }), primitive: wgpu::PrimitiveState::default(), @@ -144,11 +148,13 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader_triangle_and_lines, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &shader_triangle_and_lines, entry_point: "fs_main_white", + constants: &Default::default(), targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState { @@ -205,11 +211,13 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState::default(), diff --git a/examples/cube/src/main.rs b/examples/cube/src/main.rs index badeae8e5c2..efa498b27db 100644 --- a/examples/cube/src/main.rs +++ b/examples/cube/src/main.rs @@ -244,11 +244,13 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &vertex_buffers, }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState { @@ -270,11 +272,13 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &vertex_buffers, }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_wire", + constants: &Default::default(), targets: &[Some(wgpu::ColorTargetState { format: config.view_formats[0], blend: Some(wgpu::BlendState { diff --git a/examples/hello-compute/src/main.rs b/examples/hello-compute/src/main.rs index c7d09c6a4ae..b3d1efd6d42 100644 --- a/examples/hello-compute/src/main.rs +++ b/examples/hello-compute/src/main.rs @@ -109,6 +109,7 @@ async fn execute_gpu_inner( layout: None, module: &cs_module, entry_point: "main", + constants: &Default::default(), }); // Instantiates the bind group, once again specifying the binding of buffers. diff --git a/examples/hello-synchronization/src/main.rs b/examples/hello-synchronization/src/main.rs index bcf360d577f..729c89a1c7d 100644 --- a/examples/hello-synchronization/src/main.rs +++ b/examples/hello-synchronization/src/main.rs @@ -103,12 +103,14 @@ async fn execute( layout: Some(&pipeline_layout), module: &shaders_module, entry_point: "patient_main", + constants: &Default::default(), }); let hasty_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { label: None, layout: Some(&pipeline_layout), module: &shaders_module, entry_point: "hasty_main", + constants: &Default::default(), }); //---------------------------------------------------------- diff --git a/examples/hello-triangle/src/main.rs b/examples/hello-triangle/src/main.rs index 6a9d1414d06..9fced78ae99 100644 --- a/examples/hello-triangle/src/main.rs +++ b/examples/hello-triangle/src/main.rs @@ -60,10 +60,12 @@ async fn run(event_loop: EventLoop<()>, window: Window) { module: &shader, entry_point: "vs_main", buffers: &[], + constants: &Default::default(), }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(swapchain_format.into())], }), primitive: wgpu::PrimitiveState::default(), diff --git a/examples/hello-workgroups/src/main.rs b/examples/hello-workgroups/src/main.rs index 53e8b2adca3..55b9a1244bf 100644 --- a/examples/hello-workgroups/src/main.rs +++ b/examples/hello-workgroups/src/main.rs @@ -110,6 +110,7 @@ async fn run() { layout: Some(&pipeline_layout), module: &shader, entry_point: "main", + constants: &Default::default(), }); //---------------------------------------------------------- diff --git a/examples/mipmap/src/main.rs b/examples/mipmap/src/main.rs index 44de83560d2..a4f231bf9f8 100644 --- a/examples/mipmap/src/main.rs +++ b/examples/mipmap/src/main.rs @@ -93,11 +93,13 @@ impl Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(TEXTURE_FORMAT.into())], }), primitive: wgpu::PrimitiveState { @@ -290,11 +292,13 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState { diff --git a/examples/msaa-line/src/main.rs b/examples/msaa-line/src/main.rs index 9c6dddcfd92..09cd73d6960 100644 --- a/examples/msaa-line/src/main.rs +++ b/examples/msaa-line/src/main.rs @@ -56,6 +56,7 @@ impl Example { vertex: wgpu::VertexState { module: shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &[wgpu::VertexBufferLayout { array_stride: std::mem::size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, @@ -65,6 +66,7 @@ impl Example { fragment: Some(wgpu::FragmentState { module: shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState { diff --git a/examples/render-to-texture/src/main.rs b/examples/render-to-texture/src/main.rs index cc0a191132a..ca9a1189648 100644 --- a/examples/render-to-texture/src/main.rs +++ b/examples/render-to-texture/src/main.rs @@ -59,11 +59,13 @@ async fn run(_path: Option) { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(wgpu::TextureFormat::Rgba8UnormSrgb.into())], }), primitive: wgpu::PrimitiveState::default(), diff --git a/examples/repeated-compute/src/main.rs b/examples/repeated-compute/src/main.rs index 4795756e932..3fc9f873693 100644 --- a/examples/repeated-compute/src/main.rs +++ b/examples/repeated-compute/src/main.rs @@ -242,6 +242,7 @@ impl WgpuContext { layout: Some(&pipeline_layout), module: &shader, entry_point: "main", + constants: &Default::default(), }); WgpuContext { diff --git a/examples/shadow/src/main.rs b/examples/shadow/src/main.rs index 401860781c4..827d96d226b 100644 --- a/examples/shadow/src/main.rs +++ b/examples/shadow/src/main.rs @@ -500,6 +500,7 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_bake", + constants: &Default::default(), buffers: &[vb_desc.clone()], }, fragment: None, @@ -632,6 +633,7 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &[vb_desc], }, fragment: Some(wgpu::FragmentState { @@ -641,6 +643,7 @@ impl wgpu_example::framework::Example for Example { } else { "fs_main_without_storage" }, + constants: &Default::default(), targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState { diff --git a/examples/skybox/src/main.rs b/examples/skybox/src/main.rs index b74b24ce519..6ceb04ddcda 100644 --- a/examples/skybox/src/main.rs +++ b/examples/skybox/src/main.rs @@ -199,11 +199,13 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_sky", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_sky", + constants: &Default::default(), targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState { @@ -226,6 +228,7 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_entity", + constants: &Default::default(), buffers: &[wgpu::VertexBufferLayout { array_stride: std::mem::size_of::() as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, @@ -235,6 +238,7 @@ impl wgpu_example::framework::Example for Example { fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_entity", + constants: &Default::default(), targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState { diff --git a/examples/srgb-blend/src/main.rs b/examples/srgb-blend/src/main.rs index 4c328facc19..6b1ae16fe55 100644 --- a/examples/srgb-blend/src/main.rs +++ b/examples/srgb-blend/src/main.rs @@ -131,11 +131,13 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &vertex_buffers, }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(wgpu::ColorTargetState { format: config.view_formats[0], blend: Some(wgpu::BlendState::ALPHA_BLENDING), diff --git a/examples/stencil-triangles/src/main.rs b/examples/stencil-triangles/src/main.rs index 554c60812e0..90d93c953e3 100644 --- a/examples/stencil-triangles/src/main.rs +++ b/examples/stencil-triangles/src/main.rs @@ -74,11 +74,13 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &vertex_buffers, }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(wgpu::ColorTargetState { format: config.view_formats[0], blend: None, @@ -112,11 +114,13 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &vertex_buffers, }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(config.view_formats[0].into())], }), primitive: Default::default(), diff --git a/examples/storage-texture/src/main.rs b/examples/storage-texture/src/main.rs index 2e35970123c..1acd1d2e0b6 100644 --- a/examples/storage-texture/src/main.rs +++ b/examples/storage-texture/src/main.rs @@ -100,6 +100,7 @@ async fn run(_path: Option) { layout: Some(&pipeline_layout), module: &shader, entry_point: "main", + constants: &Default::default(), }); log::info!("Wgpu context set up."); diff --git a/examples/texture-arrays/src/main.rs b/examples/texture-arrays/src/main.rs index 634f7d96058..2021249b1c8 100644 --- a/examples/texture-arrays/src/main.rs +++ b/examples/texture-arrays/src/main.rs @@ -321,6 +321,7 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &base_shader_module, entry_point: "vert_main", + constants: &Default::default(), buffers: &[wgpu::VertexBufferLayout { array_stride: vertex_size as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, @@ -330,6 +331,7 @@ impl wgpu_example::framework::Example for Example { fragment: Some(wgpu::FragmentState { module: fragment_shader_module, entry_point: fragment_entry_point, + constants: &Default::default(), targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState { diff --git a/examples/timestamp-queries/src/main.rs b/examples/timestamp-queries/src/main.rs index b10d54cc700..e94ff8046cc 100644 --- a/examples/timestamp-queries/src/main.rs +++ b/examples/timestamp-queries/src/main.rs @@ -288,6 +288,7 @@ fn compute_pass( layout: None, module, entry_point: "main_cs", + constants: &Default::default(), }); let bind_group_layout = compute_pipeline.get_bind_group_layout(0); let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { @@ -342,11 +343,13 @@ fn render_pass( vertex: wgpu::VertexState { module, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(format.into())], }), primitive: wgpu::PrimitiveState::default(), diff --git a/examples/uniform-values/src/main.rs b/examples/uniform-values/src/main.rs index 48faf857c56..6e999eda5fb 100644 --- a/examples/uniform-values/src/main.rs +++ b/examples/uniform-values/src/main.rs @@ -178,11 +178,13 @@ impl WgpuContext { vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(swapchain_format.into())], }), primitive: wgpu::PrimitiveState::default(), diff --git a/examples/water/src/main.rs b/examples/water/src/main.rs index 2b254159118..38affa1746f 100644 --- a/examples/water/src/main.rs +++ b/examples/water/src/main.rs @@ -512,6 +512,7 @@ impl wgpu_example::framework::Example for Example { vertex: wgpu::VertexState { module: &water_module, entry_point: "vs_main", + constants: &Default::default(), // Layout of our vertices. This should match the structs // which are uploaded to the GPU. This should also be // ensured by tagging on either a `#[repr(C)]` onto a @@ -527,6 +528,7 @@ impl wgpu_example::framework::Example for Example { fragment: Some(wgpu::FragmentState { module: &water_module, entry_point: "fs_main", + constants: &Default::default(), // Describes how the colour will be interpolated // and assigned to the output attachment. targets: &[Some(wgpu::ColorTargetState { @@ -580,7 +582,7 @@ impl wgpu_example::framework::Example for Example { layout: Some(&terrain_pipeline_layout), vertex: wgpu::VertexState { module: &terrain_module, - entry_point: "vs_main", + entry_point: "vs_main",constants: &Default::default(), buffers: &[wgpu::VertexBufferLayout { array_stride: terrain_vertex_size as wgpu::BufferAddress, step_mode: wgpu::VertexStepMode::Vertex, @@ -589,7 +591,7 @@ impl wgpu_example::framework::Example for Example { }, fragment: Some(wgpu::FragmentState { module: &terrain_module, - entry_point: "fs_main", + entry_point: "fs_main",constants: &Default::default(), targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState { diff --git a/naga-cli/src/bin/naga.rs b/naga-cli/src/bin/naga.rs index 3b0873a376f..6e587177978 100644 --- a/naga-cli/src/bin/naga.rs +++ b/naga-cli/src/bin/naga.rs @@ -529,6 +529,7 @@ fn write_output( pipeline_options_owned = spv::PipelineOptions { entry_point: name.clone(), shader_stage: module.entry_points[ep_index].stage, + constants: naga::back::PipelineConstants::default(), }; Some(&pipeline_options_owned) } @@ -569,6 +570,7 @@ fn write_output( _ => unreachable!(), }, multiview: None, + constants: naga::back::PipelineConstants::default(), }; let mut buffer = String::new(); @@ -604,6 +606,7 @@ fn write_output( "Generating hlsl output requires validation to \ succeed, and it failed in a previous step", ))?, + &hlsl::PipelineOptions::default(), ) .unwrap_pretty(); fs::write(output_path, buffer)?; diff --git a/naga/src/back/glsl/mod.rs b/naga/src/back/glsl/mod.rs index b33c904f305..f0dd6322607 100644 --- a/naga/src/back/glsl/mod.rs +++ b/naga/src/back/glsl/mod.rs @@ -276,7 +276,7 @@ impl Default for Options { } /// A subset of options meant to be changed per pipeline. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct PipelineOptions { @@ -288,6 +288,8 @@ pub struct PipelineOptions { pub entry_point: String, /// How many views to render to, if doing multiview rendering. pub multiview: Option, + /// Pipeline constants. + pub constants: back::PipelineConstants, } #[derive(Debug)] diff --git a/naga/src/back/hlsl/mod.rs b/naga/src/back/hlsl/mod.rs index f3a6f9106c2..83bbb6a899b 100644 --- a/naga/src/back/hlsl/mod.rs +++ b/naga/src/back/hlsl/mod.rs @@ -195,6 +195,14 @@ pub struct Options { pub zero_initialize_workgroup_memory: bool, } +#[derive(Clone, Debug, Default)] +#[cfg_attr(feature = "serialize", derive(serde::Serialize))] +#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] +pub struct PipelineOptions { + /// Pipeline constants. + pub constants: back::PipelineConstants, +} + impl Default for Options { fn default() -> Self { Options { diff --git a/naga/src/back/hlsl/writer.rs b/naga/src/back/hlsl/writer.rs index f26604476a7..0b684cec97c 100644 --- a/naga/src/back/hlsl/writer.rs +++ b/naga/src/back/hlsl/writer.rs @@ -1,7 +1,7 @@ use super::{ help::{WrappedArrayLength, WrappedConstructor, WrappedImageQuery, WrappedStructMatrixAccess}, storage::StoreValue, - BackendResult, Error, Options, + BackendResult, Error, Options, PipelineOptions, }; use crate::{ back, @@ -183,6 +183,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { &mut self, module: &Module, module_info: &valid::ModuleInfo, + _pipeline_options: &PipelineOptions, ) -> Result { self.reset(module); diff --git a/naga/src/back/mod.rs b/naga/src/back/mod.rs index 8100b930e91..55f7fb436fb 100644 --- a/naga/src/back/mod.rs +++ b/naga/src/back/mod.rs @@ -22,6 +22,13 @@ const BAKE_PREFIX: &str = "_e"; type NeedBakeExpressions = crate::FastHashSet>; +/// Specifies the values of pipeline-overridable constants in the shader module module. +/// +/// The key represents the numeric ID of the constant, if one is specified, and otherwise the constant's identifier name. +/// +/// The value may represent any of WGSL's concrete scalar types. +pub type PipelineConstants = std::collections::HashMap; + #[derive(Clone, Copy)] struct Level(usize); diff --git a/naga/src/back/msl/mod.rs b/naga/src/back/msl/mod.rs index 5ef18730c92..efdba2e6bd3 100644 --- a/naga/src/back/msl/mod.rs +++ b/naga/src/back/msl/mod.rs @@ -221,7 +221,7 @@ impl Default for Options { } /// A subset of options that are meant to be changed per pipeline. -#[derive(Debug, Default, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Default, Clone)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct PipelineOptions { @@ -232,6 +232,8 @@ pub struct PipelineOptions { /// /// Enable this for vertex shaders with point primitive topologies. pub allow_and_force_point_size: bool, + /// Pipeline constants. + pub constants: crate::back::PipelineConstants, } impl Options { diff --git a/naga/src/back/spv/mod.rs b/naga/src/back/spv/mod.rs index ac7281fc6b4..09bd8cdd6d9 100644 --- a/naga/src/back/spv/mod.rs +++ b/naga/src/back/spv/mod.rs @@ -723,7 +723,7 @@ impl<'a> Default for Options<'a> { } // A subset of options meant to be changed per pipeline. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] +#[derive(Debug, Clone)] #[cfg_attr(feature = "serialize", derive(serde::Serialize))] #[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] pub struct PipelineOptions { @@ -733,6 +733,8 @@ pub struct PipelineOptions { /// /// If no entry point that matches is found while creating a [`Writer`], a error will be thrown. pub entry_point: String, + /// Pipeline constants. + pub constants: crate::back::PipelineConstants, } pub fn write_vec( diff --git a/naga/tests/in/interface.param.ron b/naga/tests/in/interface.param.ron index 4d85661767b..19ed5e464c0 100644 --- a/naga/tests/in/interface.param.ron +++ b/naga/tests/in/interface.param.ron @@ -27,5 +27,6 @@ ), msl_pipeline: ( allow_and_force_point_size: true, + constants: {}, ), ) diff --git a/naga/tests/snapshots.rs b/naga/tests/snapshots.rs index ed75805ae0c..4cd20dae42c 100644 --- a/naga/tests/snapshots.rs +++ b/naga/tests/snapshots.rs @@ -425,6 +425,7 @@ fn write_output_spv( let pipeline_options = spv::PipelineOptions { entry_point: ep.name.clone(), shader_stage: ep.stage, + constants: naga::back::PipelineConstants::default(), }; write_output_spv_inner( input, @@ -513,6 +514,7 @@ fn write_output_glsl( shader_stage: stage, entry_point: ep_name.to_string(), multiview, + constants: naga::back::PipelineConstants::default(), }; let mut buffer = String::new(); @@ -545,7 +547,9 @@ fn write_output_hlsl( let mut buffer = String::new(); let mut writer = hlsl::Writer::new(&mut buffer, options); - let reflection_info = writer.write(module, info).expect("HLSL write failed"); + let reflection_info = writer + .write(module, info, &hlsl::PipelineOptions::default()) + .expect("HLSL write failed"); input.write_output_file("hlsl", "hlsl", buffer); diff --git a/player/tests/data/bind-group.ron b/player/tests/data/bind-group.ron index 00ecf0b20cb..0ded312e137 100644 --- a/player/tests/data/bind-group.ron +++ b/player/tests/data/bind-group.ron @@ -23,6 +23,7 @@ stage: ( module: Id(0, 1, Empty), entry_point: "main", + constants: {}, ), ), ), diff --git a/player/tests/data/pipeline-statistics-query.ron b/player/tests/data/pipeline-statistics-query.ron index 999c333a302..58ab9658d67 100644 --- a/player/tests/data/pipeline-statistics-query.ron +++ b/player/tests/data/pipeline-statistics-query.ron @@ -30,6 +30,7 @@ stage: ( module: Id(0, 1, Empty), entry_point: "main", + constants: {}, ), ), ), diff --git a/player/tests/data/quad.ron b/player/tests/data/quad.ron index 563ba24b846..4fa3498cdb9 100644 --- a/player/tests/data/quad.ron +++ b/player/tests/data/quad.ron @@ -58,6 +58,7 @@ stage: ( module: Id(0, 1, Empty), entry_point: "vs_main", + constants: {}, ), buffers: [], ), @@ -65,6 +66,7 @@ stage: ( module: Id(0, 1, Empty), entry_point: "fs_main", + constants: {}, ), targets: [ Some(( diff --git a/player/tests/data/zero-init-buffer.ron b/player/tests/data/zero-init-buffer.ron index b93f65c736f..a05e9a8d7a3 100644 --- a/player/tests/data/zero-init-buffer.ron +++ b/player/tests/data/zero-init-buffer.ron @@ -134,6 +134,7 @@ stage: ( module: Id(0, 1, Empty), entry_point: "main", + constants: {}, ), ), ), diff --git a/player/tests/data/zero-init-texture-binding.ron b/player/tests/data/zero-init-texture-binding.ron index e94255cfc3a..60c1f897986 100644 --- a/player/tests/data/zero-init-texture-binding.ron +++ b/player/tests/data/zero-init-texture-binding.ron @@ -135,6 +135,7 @@ stage: ( module: Id(0, 1, Empty), entry_point: "main", + constants: {}, ), ), ), diff --git a/tests/src/image.rs b/tests/src/image.rs index 66f6abf16a1..a3c7e3921a6 100644 --- a/tests/src/image.rs +++ b/tests/src/image.rs @@ -367,6 +367,7 @@ fn copy_via_compute( layout: Some(&pll), module: &sm, entry_point: "copy_texture_to_buffer", + constants: &Default::default(), }); { diff --git a/tests/tests/bgra8unorm_storage.rs b/tests/tests/bgra8unorm_storage.rs index 5cfcb27a29c..a0b585d98e9 100644 --- a/tests/tests/bgra8unorm_storage.rs +++ b/tests/tests/bgra8unorm_storage.rs @@ -96,6 +96,7 @@ static BGRA8_UNORM_STORAGE: GpuTestConfiguration = GpuTestConfiguration::new() label: None, layout: Some(&pl), entry_point: "main", + constants: &Default::default(), module: &module, }); diff --git a/tests/tests/bind_group_layout_dedup.rs b/tests/tests/bind_group_layout_dedup.rs index 3f2e6fe17a2..e6125a6d1fb 100644 --- a/tests/tests/bind_group_layout_dedup.rs +++ b/tests/tests/bind_group_layout_dedup.rs @@ -70,17 +70,20 @@ static BIND_GROUP_LAYOUT_DEDUPLICATION: GpuTestConfiguration = GpuTestConfigurat write_mask: Default::default(), })]; + let constants = std::collections::HashMap::default(); let desc = wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), vertex: wgpu::VertexState { module: &module, entry_point: "vs_main", + constants: &constants, buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &module, entry_point: "fs_main", + constants: &constants, targets, }), primitive: wgpu::PrimitiveState::default(), diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 2288fd0cb65..5c0a53f98d2 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -415,6 +415,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne vertex: wgpu::VertexState { module: &shader_module, entry_point: "", + constants: &Default::default(), buffers: &[], }, primitive: wgpu::PrimitiveState::default(), @@ -433,6 +434,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne layout: None, module: &shader_module, entry_point: "", + constants: &Default::default(), }); }); diff --git a/tests/tests/occlusion_query/mod.rs b/tests/tests/occlusion_query/mod.rs index 7a7f3fa9a23..30962d12e4a 100644 --- a/tests/tests/occlusion_query/mod.rs +++ b/tests/tests/occlusion_query/mod.rs @@ -37,6 +37,7 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new() vertex: wgpu::VertexState { module: &shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: None, diff --git a/tests/tests/partially_bounded_arrays/mod.rs b/tests/tests/partially_bounded_arrays/mod.rs index 5a41ae8f29c..d9d1d2b3f4a 100644 --- a/tests/tests/partially_bounded_arrays/mod.rs +++ b/tests/tests/partially_bounded_arrays/mod.rs @@ -69,6 +69,7 @@ static PARTIALLY_BOUNDED_ARRAY: GpuTestConfiguration = GpuTestConfiguration::new layout: Some(&pipeline_layout), module: &cs_module, entry_point: "main", + constants: &Default::default(), }); let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { diff --git a/tests/tests/pipeline.rs b/tests/tests/pipeline.rs index 2733bf2f817..1cefedac06d 100644 --- a/tests/tests/pipeline.rs +++ b/tests/tests/pipeline.rs @@ -28,6 +28,7 @@ static PIPELINE_DEFAULT_LAYOUT_BAD_MODULE: GpuTestConfiguration = GpuTestConfigu layout: None, module: &module, entry_point: "doesn't exist", + constants: &Default::default(), }); pipeline.get_bind_group_layout(0); diff --git a/tests/tests/push_constants.rs b/tests/tests/push_constants.rs index e39000173c4..966a218cc7c 100644 --- a/tests/tests/push_constants.rs +++ b/tests/tests/push_constants.rs @@ -103,6 +103,7 @@ fn partial_update_test(ctx: TestingContext) { layout: Some(&pipeline_layout), module: &sm, entry_point: "main", + constants: &Default::default(), }); let mut encoder = ctx diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index 5db5575ddf1..54241dcd6d6 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -102,11 +102,13 @@ fn multi_stage_data_binding_test(ctx: TestingContext) { vertex: wgpu::VertexState { module: &vs_sm, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module: &fs_sm, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(wgpu::ColorTargetState { format: wgpu::TextureFormat::Rgba8Unorm, blend: None, diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index d7ea0e5bb99..84f41022663 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -52,6 +52,7 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = vertex: VertexState { module: &module, entry_point: "double_buffer_vert", + constants: &Default::default(), buffers: &[ VertexBufferLayout { array_stride: 16, @@ -71,6 +72,7 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = fragment: Some(FragmentState { module: &module, entry_point: "double_buffer_frag", + constants: &Default::default(), targets: &[Some(ColorTargetState { format: TextureFormat::Rgba8Unorm, blend: None, @@ -88,6 +90,7 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = vertex: VertexState { module: &module, entry_point: "single_buffer_vert", + constants: &Default::default(), buffers: &[VertexBufferLayout { array_stride: 16, step_mode: VertexStepMode::Vertex, @@ -100,6 +103,7 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = fragment: Some(FragmentState { module: &module, entry_point: "single_buffer_frag", + constants: &Default::default(), targets: &[Some(ColorTargetState { format: TextureFormat::Rgba8Unorm, blend: None, diff --git a/tests/tests/scissor_tests/mod.rs b/tests/tests/scissor_tests/mod.rs index 40801a343ad..7bb24ab138e 100644 --- a/tests/tests/scissor_tests/mod.rs +++ b/tests/tests/scissor_tests/mod.rs @@ -38,16 +38,18 @@ fn scissor_test_impl(ctx: &TestingContext, scissor_rect: Rect, expected_data: [u label: Some("Pipeline"), layout: None, vertex: wgpu::VertexState { - entry_point: "vs_main", module: &shader, + entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, primitive: wgpu::PrimitiveState::default(), depth_stencil: None, multisample: wgpu::MultisampleState::default(), fragment: Some(wgpu::FragmentState { - entry_point: "fs_main", module: &shader, + entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(wgpu::ColorTargetState { format: wgpu::TextureFormat::Rgba8Unorm, blend: None, diff --git a/tests/tests/shader/mod.rs b/tests/tests/shader/mod.rs index 48800bfb356..8876f32035d 100644 --- a/tests/tests/shader/mod.rs +++ b/tests/tests/shader/mod.rs @@ -307,6 +307,7 @@ fn shader_input_output_test( layout: Some(&pll), module: &sm, entry_point: "cs_main", + constants: &Default::default(), }); // -- Initializing data -- diff --git a/tests/tests/shader/zero_init_workgroup_mem.rs b/tests/tests/shader/zero_init_workgroup_mem.rs index e5a30c3b14f..dcba1543e52 100644 --- a/tests/tests/shader/zero_init_workgroup_mem.rs +++ b/tests/tests/shader/zero_init_workgroup_mem.rs @@ -88,6 +88,7 @@ static ZERO_INIT_WORKGROUP_MEMORY: GpuTestConfiguration = GpuTestConfiguration:: layout: Some(&pll), module: &sm, entry_point: "read", + constants: &Default::default(), }); let pipeline_write = ctx @@ -97,6 +98,7 @@ static ZERO_INIT_WORKGROUP_MEMORY: GpuTestConfiguration = GpuTestConfiguration:: layout: None, module: &sm, entry_point: "write", + constants: &Default::default(), }); // -- Initializing data -- diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index 13ba76a3288..80a5b0b85e3 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -118,6 +118,9 @@ fn pulling_common( label: None, layout: None, vertex: wgpu::VertexState { + module: &shader, + entry_point: "vs_main", + constants: &Default::default(), buffers: &[wgpu::VertexBufferLayout { array_stride: 8, step_mode: wgpu::VertexStepMode::Vertex, @@ -127,15 +130,14 @@ fn pulling_common( shader_location: 0, }], }], - entry_point: "vs_main", - module: &shader, }, primitive: wgpu::PrimitiveState::default(), depth_stencil: None, multisample: wgpu::MultisampleState::default(), fragment: Some(wgpu::FragmentState { - entry_point: "fs_main", module: &shader, + entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(wgpu::ColorTargetState { format: wgpu::TextureFormat::Rgba8Unorm, blend: None, diff --git a/tests/tests/shader_view_format/mod.rs b/tests/tests/shader_view_format/mod.rs index 5e7bed9b085..2f783ea3b2e 100644 --- a/tests/tests/shader_view_format/mod.rs +++ b/tests/tests/shader_view_format/mod.rs @@ -90,11 +90,13 @@ fn reinterpret( vertex: wgpu::VertexState { module: shader, entry_point: "vs_main", + constants: &Default::default(), buffers: &[], }, fragment: Some(wgpu::FragmentState { module: shader, entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(src_format.into())], }), primitive: wgpu::PrimitiveState { diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index 4fe8395eaa0..ec33d90461b 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -67,16 +67,18 @@ fn pulling_common( label: None, layout: Some(&ppl), vertex: wgpu::VertexState { - buffers: &[], - entry_point: "vs_main", module: &shader, + entry_point: "vs_main", + constants: &Default::default(), + buffers: &[], }, primitive: wgpu::PrimitiveState::default(), depth_stencil: None, multisample: wgpu::MultisampleState::default(), fragment: Some(wgpu::FragmentState { - entry_point: "fs_main", module: &shader, + entry_point: "fs_main", + constants: &Default::default(), targets: &[Some(wgpu::ColorTargetState { format: wgpu::TextureFormat::Rgba8Unorm, blend: None, diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 3d422a8e285..124511e508e 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -2601,8 +2601,9 @@ impl Device { label: desc.label.to_hal(self.instance_flags), layout: &layout.raw, stage: hal::ProgrammableStage { - entry_point: desc.stage.entry_point.as_ref(), module: &shader_module.raw, + entry_point: desc.stage.entry_point.as_ref(), + constants: desc.stage.constants.as_ref(), }, }; @@ -3000,6 +3001,7 @@ impl Device { hal::ProgrammableStage { module: &shader_module.raw, entry_point: stage.entry_point.as_ref(), + constants: stage.constants.as_ref(), } }; @@ -3057,6 +3059,7 @@ impl Device { Some(hal::ProgrammableStage { module: &shader_module.raw, entry_point: fragment.stage.entry_point.as_ref(), + constants: fragment.stage.constants.as_ref(), }) } None => None, diff --git a/wgpu-core/src/pipeline.rs b/wgpu-core/src/pipeline.rs index bfab15b2f5e..5e7cc724f7f 100644 --- a/wgpu-core/src/pipeline.rs +++ b/wgpu-core/src/pipeline.rs @@ -164,6 +164,12 @@ pub struct ProgrammableStageDescriptor<'a> { /// The name of the entry point in the compiled shader. There must be a function with this name /// in the shader. pub entry_point: Cow<'a, str>, + /// Specifies the values of pipeline-overridable constants in the shader module module. + /// + /// The key represents the numeric ID of the constant, if one is specified, and otherwise the constant's identifier name. + /// + /// The value may represent any of WGSL's concrete scalar types. + pub constants: Cow<'a, naga::back::PipelineConstants>, } /// Number of implicit bind groups derived at pipeline creation. diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 471b0c48906..a4f9aa8092e 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -244,17 +244,20 @@ impl Example { .unwrap() }; + let constants = naga::back::PipelineConstants::default(); let pipeline_desc = hal::RenderPipelineDescriptor { label: None, layout: &pipeline_layout, vertex_stage: hal::ProgrammableStage { module: &shader, entry_point: "vs_main", + constants: &constants, }, vertex_buffers: &[], fragment_stage: Some(hal::ProgrammableStage { module: &shader, entry_point: "fs_main", + constants: &constants, }), primitive: wgt::PrimitiveState { topology: wgt::PrimitiveTopology::TriangleStrip, diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 84146a006b2..bf1182f55d7 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -210,10 +210,13 @@ impl super::Device { //TODO: reuse the writer let mut source = String::new(); let mut writer = hlsl::Writer::new(&mut source, &layout.naga_options); + let pipeline_options = hlsl::PipelineOptions { + constants: stage.constants.to_owned(), + }; let reflection_info = { profiling::scope!("naga::back::hlsl::write"); writer - .write(module, &stage.module.naga.info) + .write(module, &stage.module.naga.info, &pipeline_options) .map_err(|e| crate::PipelineError::Linkage(stage_bit, format!("HLSL: {e:?}")))? }; diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index 7934c4be01a..a3c0c67dfea 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -218,6 +218,7 @@ impl super::Device { shader_stage: naga_stage, entry_point: stage.entry_point.to_string(), multiview: context.multiview, + constants: stage.constants.to_owned(), }; let shader = &stage.module.naga; diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 6c8e36ab7ce..4bd3f1d0ecd 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -1146,6 +1146,8 @@ pub struct ProgrammableStage<'a, A: Api> { /// The name of the entry point in the compiled shader. There must be a function with this name /// in the shader. pub entry_point: &'a str, + /// Pipeline constants + pub constants: &'a naga::back::PipelineConstants, } // Rust gets confused about the impl requirements for `A` @@ -1154,6 +1156,7 @@ impl Clone for ProgrammableStage<'_, A> { Self { module: self.module, entry_point: self.entry_point, + constants: self.constants, } } } diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index 475332b76d5..fd20a828a96 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -112,6 +112,7 @@ impl super::Device { metal::MTLPrimitiveTopologyClass::Point => true, _ => false, }, + constants: stage.constants.to_owned(), }; let (source, info) = naga::back::msl::write_string( diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index 8eb2935a32b..4c11a9759f2 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -722,6 +722,7 @@ impl super::Device { let pipeline_options = naga::back::spv::PipelineOptions { entry_point: stage.entry_point.to_string(), shader_stage: naga_stage, + constants: stage.constants.to_owned(), }; let needs_temp_options = !runtime_checks || !binding_map.is_empty() @@ -1516,6 +1517,7 @@ impl crate::Device for super::Device { .shared .workarounds .contains(super::Workarounds::SEPARATE_ENTRY_POINTS) + // or if it has any overrides { return Ok(super::ShaderModule::Intermediate { naga_shader, diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 1a12a5601ed..b44852c7018 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -1192,6 +1192,7 @@ impl crate::Context for Context { stage: pipe::ProgrammableStageDescriptor { module: desc.vertex.module.id.into(), entry_point: Borrowed(desc.vertex.entry_point), + constants: Borrowed(desc.vertex.constants), }, buffers: Borrowed(&vertex_buffers), }, @@ -1202,6 +1203,7 @@ impl crate::Context for Context { stage: pipe::ProgrammableStageDescriptor { module: frag.module.id.into(), entry_point: Borrowed(frag.entry_point), + constants: Borrowed(frag.constants), }, targets: Borrowed(frag.targets), }), @@ -1251,6 +1253,7 @@ impl crate::Context for Context { stage: pipe::ProgrammableStageDescriptor { module: desc.module.id.into(), entry_point: Borrowed(desc.entry_point), + constants: Borrowed(desc.constants), }, }; diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 914e234f1da..5c498eb937e 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -15,6 +15,7 @@ mod macros; use std::{ any::Any, borrow::Cow, + collections::HashMap, error, fmt, future::Future, marker::PhantomData, @@ -1465,6 +1466,12 @@ pub struct VertexState<'a> { /// The name of the entry point in the compiled shader. There must be a function with this name /// in the shader. pub entry_point: &'a str, + /// Specifies the values of pipeline-overridable constants in the shader module module. + /// + /// The key represents the numeric ID of the constant, if one is specified, and otherwise the constant's identifier name. + /// + /// The value may represent any of WGSL's concrete scalar types. + pub constants: &'a HashMap, /// The format of any vertex buffers used with this pipeline. pub buffers: &'a [VertexBufferLayout<'a>], } @@ -1490,6 +1497,12 @@ pub struct FragmentState<'a> { /// The name of the entry point in the compiled shader. There must be a function with this name /// in the shader. pub entry_point: &'a str, + /// Specifies the values of pipeline-overridable constants in the shader module module. + /// + /// The key represents the numeric ID of the constant, if one is specified, and otherwise the constant's identifier name. + /// + /// The value may represent any of WGSL's concrete scalar types. + pub constants: &'a HashMap, /// The color state of the render targets. pub targets: &'a [Option], } @@ -1603,6 +1616,12 @@ pub struct ComputePipelineDescriptor<'a> { /// The name of the entry point in the compiled shader. There must be a function with this name /// and no return value in the shader. pub entry_point: &'a str, + /// Specifies the values of pipeline-overridable constants in the shader module module. + /// + /// The key represents the numeric ID of the constant, if one is specified, and otherwise the constant's identifier name. + /// + /// The value may represent any of WGSL's concrete scalar types. + pub constants: &'a HashMap, } #[cfg(any( not(target_arch = "wasm32"),