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

add pipeline constants plumbing #4677

Merged
merged 5 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ For naga changelogs at or before v0.14.0. See [naga's changelog](naga/CHANGELOG.
#### General

- Log vulkan validation layer messages during instance creation and destruction: By @exrook in [#4586](https://github.com/gfx-rs/wgpu/pull/4586)
- `TextureFormat::block_size` is deprecated, use `TextureFormat::block_copy_size` instead: By @wumpf in [#4647](https://github.com/gfx-rs/wgpu/pull/4647)

#### Naga

- Introduce a new `Scalar` struct type for use in Naga's IR, and update all frontend, middle, and backend code appropriately. By @jimblandy in [#4673](https://github.com/gfx-rs/wgpu/pull/4673).

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ We have a [wiki](https://github.com/gfx-rs/wgpu/wiki) that serves as a knowledge

:white_check_mark: = First Class Support
:ok: = Downlevel/Best Effort Support
:triangular_ruler: = Requires the [ANGLE](#angle) translation layer (GL ES 3.0 only)
:triangular_ruler: = Requires the [ANGLE](#angle) translation layer (GL ES 3.0 only)
:volcano: = Requires the [MoltenVK](https://vulkan.lunarg.com/sdk/home#mac) translation layer
:hammer_and_wrench: = Unsupported, though open to contributions

Expand Down
16 changes: 10 additions & 6 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 @@ -78,7 +79,7 @@ pub enum GPUPipelineLayoutOrGPUAutoLayoutMode {
pub struct GpuProgrammableStage {
module: ResourceId,
entry_point: String,
// constants: HashMap<String, GPUPipelineConstantValue>
constants: HashMap<String, f64>,
}

#[op2]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -282,6 +283,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 @@ -309,7 +311,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 @@ -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
Expand All @@ -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),
},
Expand Down
3 changes: 3 additions & 0 deletions examples/boids/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(),
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions examples/bunnymark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 8 additions & 0 deletions examples/conservative-raster/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
Expand All @@ -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 {
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions examples/cube/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions examples/hello-compute/src/main.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/hello-synchronization/src/main.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/hello-triangle/src/main.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/hello-workgroups/src/main.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/mipmap/src/main.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 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 {
Expand Down
2 changes: 2 additions & 0 deletions examples/msaa-line/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions examples/render-to-texture/src/main.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/repeated-compute/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,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/shadow/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions examples/skybox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions examples/srgb-blend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ impl<const SRGB: bool> wgpu_example::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
Loading
Loading