Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipeline constants #5500

Merged
merged 30 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5ec78ab
add pipeline constants plumbing
teoxoy Nov 13, 2023
747fb30
[naga] Delete `Constant::override` and `Override`.
jimblandy Dec 7, 2023
e5b7df3
[wgsl-in] add support for override declarations (#4793)
teoxoy Dec 7, 2023
da0a6c9
remove naga's clone feature
teoxoy Jan 5, 2024
1a3c47b
[spv/msl/hlsl-out] support pipeline constant value replacements
teoxoy Jan 5, 2024
d340f9f
validate that override ids are unique
teoxoy Jan 9, 2024
120d0a0
[const-eval] refactor logic around `try_eval_and_append`
teoxoy Jan 16, 2024
e9775c8
[const-eval] fix evaluation of bool constuctors
teoxoy Feb 13, 2024
c48f01b
implement override-expression evaluation for initializers of override…
teoxoy Feb 14, 2024
98f4ca0
rename `ExpressionConstnessTracker` to `ExpressionKindTracker`
teoxoy Feb 14, 2024
29abd93
rename `const_expressions` to `global_expressions`
teoxoy Feb 14, 2024
bb999fc
[valid] error on non fully evaluated const-expressions
teoxoy Mar 7, 2024
7d79d71
[valid] make sure overrides are not present after evaluation
teoxoy Mar 7, 2024
f3ff6b3
[naga] Add some documentation to process_overrides and subroutines.
jimblandy Mar 13, 2024
0c4b2d7
refactor `try_eval_and_append` body
teoxoy Mar 14, 2024
e2ff98b
evaluate override-expressions in functions
teoxoy Mar 6, 2024
e2fcc26
allow private variables to have an override-expression initializer
teoxoy Mar 6, 2024
dcef6c6
[naga] Doc tweaks for `back::pipeline_constants`.
jimblandy Mar 23, 2024
df8c8cb
[naga] Simplify uses of `replace` in `back::pipeline_constants`.
jimblandy Mar 23, 2024
106f56a
[naga] Hoist `ConstantEvaluator` construction in `process_function`.
jimblandy Mar 23, 2024
ce77287
[naga] Let `filter_emits_with_block` operate on a `&mut Block`.
jimblandy Mar 23, 2024
2c29ecb
[naga] Tweak comments in `ConstantEvaluator::try_eval_and_append`.
jimblandy Mar 24, 2024
e62621b
[naga] Add missing newline to test input file.
jimblandy Mar 25, 2024
ddd1222
[naga] Handle comparison operands in pipeline constant evaluation.
jimblandy Mar 26, 2024
f015fb1
[naga] Spell out members in adjust_expr.
jimblandy Mar 26, 2024
de50eb0
[naga] Adjust RayQuery statements in override processing.
jimblandy Mar 26, 2024
b9403c1
[naga-cli] Add `--override` option.
jimblandy Mar 20, 2024
9c3fc6c
move the burden of evaluating override-expressions to users of naga's…
teoxoy Apr 4, 2024
c104f08
[naga wgsl-in] Allow override expressions as local var initializers.
jimblandy Mar 26, 2024
6d89548
add changelog entry
teoxoy Apr 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ Bottom level categories:
- Added `wgpu::TextureView::as_hal`
- `wgpu::Texture::as_hal` now returns a user-defined type to match the other as_hal functions

- Added support for pipeline-overridable constants. By @teoxoy & @jimblandy in [#5500](https://github.com/gfx-rs/wgpu/pull/5500)

#### GLES

- Log an error when GLES texture format heuristics fail. By @PolyMeilex in [#5266](https://github.com/gfx-rs/wgpu/issues/5266)
Expand Down
12 changes: 8 additions & 4 deletions deno_webgpu/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,7 +76,7 @@ pub enum GPUPipelineLayoutOrGPUAutoLayoutMode {
pub struct GpuProgrammableStage {
module: ResourceId,
entry_point: Option<String>,
// constants: HashMap<String, GPUPipelineConstantValue>
constants: HashMap<String, f64>,
}

#[op2]
Expand Down Expand Up @@ -111,7 +112,7 @@ pub fn op_webgpu_create_compute_pipeline(
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
module: compute_shader_module_resource.1,
entry_point: compute.entry_point.map(Cow::from),
// TODO(lucacasonato): support args.compute.constants
constants: Cow::Owned(compute.constants),
},
};
let implicit_pipelines = match layout {
Expand Down Expand Up @@ -279,6 +280,7 @@ impl<'a> From<GpuVertexBufferLayout> for wgpu_core::pipeline::VertexBufferLayout
struct GpuVertexState {
module: ResourceId,
entry_point: String,
constants: HashMap<String, f64>,
buffers: Vec<Option<GpuVertexBufferLayout>>,
}

Expand Down Expand Up @@ -306,7 +308,7 @@ struct GpuFragmentState {
targets: Vec<Option<wgpu_types::ColorTargetState>>,
module: u32,
entry_point: String,
// TODO(lucacasonato): constants
constants: HashMap<String, f64>,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -356,8 +358,9 @@ pub fn op_webgpu_create_render_pipeline(
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
module: fragment_shader_module_resource.1,
entry_point: Some(Cow::from(fragment.entry_point)),
constants: Cow::Owned(fragment.constants),
},
targets: Cow::from(fragment.targets),
targets: Cow::Owned(fragment.targets),
})
} else {
None
Expand All @@ -378,6 +381,7 @@ pub fn op_webgpu_create_render_pipeline(
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
module: vertex_shader_module_resource.1,
entry_point: Some(Cow::Owned(args.vertex.entry_point)),
constants: Cow::Owned(args.vertex.constants),
},
buffers: Cow::Owned(vertex_buffers),
},
Expand Down
3 changes: 3 additions & 0 deletions examples/src/boids/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ impl crate::framework::Example for Example {
vertex: wgpu::VertexState {
module: &draw_shader,
entry_point: "main_vs",
constants: &Default::default(),
buffers: &[
wgpu::VertexBufferLayout {
array_stride: 4 * 4,
Expand All @@ -148,6 +149,7 @@ impl crate::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(),
Expand All @@ -163,6 +165,7 @@ impl crate::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
Expand Down
2 changes: 2 additions & 0 deletions examples/src/bunnymark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,13 @@ impl crate::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),
Expand Down
8 changes: 8 additions & 0 deletions examples/src/conservative_raster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ impl crate::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 {
Expand All @@ -120,11 +122,13 @@ impl crate::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(),
Expand All @@ -144,11 +148,13 @@ impl crate::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 {
Expand Down Expand Up @@ -205,11 +211,13 @@ impl crate::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(),
Expand Down
4 changes: 4 additions & 0 deletions examples/src/cube/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,13 @@ impl crate::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 {
Expand All @@ -270,11 +272,13 @@ impl crate::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 {
Expand Down
1 change: 1 addition & 0 deletions examples/src/hello_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions examples/src/hello_synchronization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});

//----------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions examples/src/hello_triangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions examples/src/hello_workgroups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ async fn run() {
layout: Some(&pipeline_layout),
module: &shader,
entry_point: "main",
constants: &Default::default(),
});

//----------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions examples/src/mipmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -290,11 +292,13 @@ impl crate::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 {
Expand Down
2 changes: 2 additions & 0 deletions examples/src/msaa_line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl Example {
vertex: wgpu::VertexState {
module: shader,
entry_point: "vs_main",
constants: &Default::default(),
buffers: &[wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
Expand All @@ -63,6 +64,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 {
Expand Down
2 changes: 2 additions & 0 deletions examples/src/render_to_texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,13 @@ async fn run(_path: Option<String>) {
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(),
Expand Down
1 change: 1 addition & 0 deletions examples/src/repeated_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ impl WgpuContext {
layout: Some(&pipeline_layout),
module: &shader,
entry_point: "main",
constants: &Default::default(),
});

WgpuContext {
Expand Down
3 changes: 3 additions & 0 deletions examples/src/shadow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ impl crate::framework::Example for Example {
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_bake",
constants: &Default::default(),
buffers: &[vb_desc.clone()],
},
fragment: None,
Expand Down Expand Up @@ -632,6 +633,7 @@ impl crate::framework::Example for Example {
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
constants: &Default::default(),
buffers: &[vb_desc],
},
fragment: Some(wgpu::FragmentState {
Expand All @@ -641,6 +643,7 @@ impl crate::framework::Example for Example {
} else {
"fs_main_without_storage"
},
constants: &Default::default(),
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
Expand Down
4 changes: 4 additions & 0 deletions examples/src/skybox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,13 @@ impl crate::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 {
Expand All @@ -226,6 +228,7 @@ impl crate::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::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
Expand All @@ -235,6 +238,7 @@ impl crate::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 {
Expand Down
2 changes: 2 additions & 0 deletions examples/src/srgb_blend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ impl<const SRGB: bool> crate::framework::Example for Example<SRGB> {
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),
Expand Down
4 changes: 4 additions & 0 deletions examples/src/stencil_triangles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,13 @@ impl crate::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,
Expand Down Expand Up @@ -112,11 +114,13 @@ impl crate::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(),
Expand Down
Loading
Loading