Skip to content

Commit 7c0df7c

Browse files
committed
add pipeline constants plumbing
1 parent 59e79c0 commit 7c0df7c

File tree

66 files changed

+212
-23
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+212
-23
lines changed

deno_webgpu/pipeline.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use deno_core::ResourceId;
88
use serde::Deserialize;
99
use serde::Serialize;
1010
use std::borrow::Cow;
11+
use std::collections::HashMap;
1112
use std::rc::Rc;
1213

1314
use super::error::WebGpuError;
@@ -75,7 +76,7 @@ pub enum GPUPipelineLayoutOrGPUAutoLayoutMode {
7576
pub struct GpuProgrammableStage {
7677
module: ResourceId,
7778
entry_point: String,
78-
// constants: HashMap<String, GPUPipelineConstantValue>
79+
constants: HashMap<String, f64>,
7980
}
8081

8182
#[op2]
@@ -110,8 +111,8 @@ pub fn op_webgpu_create_compute_pipeline(
110111
layout: pipeline_layout,
111112
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
112113
module: compute_shader_module_resource.1,
113-
entry_point: Cow::from(compute.entry_point),
114-
// TODO(lucacasonato): support args.compute.constants
114+
entry_point: Cow::Owned(compute.entry_point),
115+
constants: Cow::Owned(compute.constants),
115116
},
116117
};
117118
let implicit_pipelines = match layout {
@@ -279,6 +280,7 @@ impl<'a> From<GpuVertexBufferLayout> for wgpu_core::pipeline::VertexBufferLayout
279280
struct GpuVertexState {
280281
module: ResourceId,
281282
entry_point: String,
283+
constants: HashMap<String, f64>,
282284
buffers: Vec<Option<GpuVertexBufferLayout>>,
283285
}
284286

@@ -306,7 +308,7 @@ struct GpuFragmentState {
306308
targets: Vec<Option<wgpu_types::ColorTargetState>>,
307309
module: u32,
308310
entry_point: String,
309-
// TODO(lucacasonato): constants
311+
constants: HashMap<String, f64>,
310312
}
311313

312314
#[derive(Deserialize)]
@@ -355,9 +357,10 @@ pub fn op_webgpu_create_render_pipeline(
355357
Some(wgpu_core::pipeline::FragmentState {
356358
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
357359
module: fragment_shader_module_resource.1,
358-
entry_point: Cow::from(fragment.entry_point),
360+
entry_point: Cow::Owned(fragment.entry_point),
361+
constants: Cow::Owned(fragment.constants),
359362
},
360-
targets: Cow::from(fragment.targets),
363+
targets: Cow::Owned(fragment.targets),
361364
})
362365
} else {
363366
None
@@ -378,6 +381,7 @@ pub fn op_webgpu_create_render_pipeline(
378381
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
379382
module: vertex_shader_module_resource.1,
380383
entry_point: Cow::Owned(args.vertex.entry_point),
384+
constants: Cow::Owned(args.vertex.constants),
381385
},
382386
buffers: Cow::Owned(vertex_buffers),
383387
},

examples/src/boids/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl crate::framework::Example for Example {
132132
vertex: wgpu::VertexState {
133133
module: &draw_shader,
134134
entry_point: "main_vs",
135+
constants: &Default::default(),
135136
buffers: &[
136137
wgpu::VertexBufferLayout {
137138
array_stride: 4 * 4,
@@ -148,6 +149,7 @@ impl crate::framework::Example for Example {
148149
fragment: Some(wgpu::FragmentState {
149150
module: &draw_shader,
150151
entry_point: "main_fs",
152+
constants: &Default::default(),
151153
targets: &[Some(config.view_formats[0].into())],
152154
}),
153155
primitive: wgpu::PrimitiveState::default(),
@@ -163,6 +165,7 @@ impl crate::framework::Example for Example {
163165
layout: Some(&compute_pipeline_layout),
164166
module: &compute_shader,
165167
entry_point: "main",
168+
constants: &Default::default(),
166169
});
167170

168171
// buffer for the three 2d triangle vertices of each instance

examples/src/bunnymark/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,13 @@ impl crate::framework::Example for Example {
203203
vertex: wgpu::VertexState {
204204
module: &shader,
205205
entry_point: "vs_main",
206+
constants: &Default::default(),
206207
buffers: &[],
207208
},
208209
fragment: Some(wgpu::FragmentState {
209210
module: &shader,
210211
entry_point: "fs_main",
212+
constants: &Default::default(),
211213
targets: &[Some(wgpu::ColorTargetState {
212214
format: config.view_formats[0],
213215
blend: Some(wgpu::BlendState::ALPHA_BLENDING),

examples/src/conservative_raster/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ impl crate::framework::Example for Example {
9797
vertex: wgpu::VertexState {
9898
module: &shader_triangle_and_lines,
9999
entry_point: "vs_main",
100+
constants: &Default::default(),
100101
buffers: &[],
101102
},
102103
fragment: Some(wgpu::FragmentState {
103104
module: &shader_triangle_and_lines,
104105
entry_point: "fs_main_red",
106+
constants: &Default::default(),
105107
targets: &[Some(RENDER_TARGET_FORMAT.into())],
106108
}),
107109
primitive: wgpu::PrimitiveState {
@@ -120,11 +122,13 @@ impl crate::framework::Example for Example {
120122
vertex: wgpu::VertexState {
121123
module: &shader_triangle_and_lines,
122124
entry_point: "vs_main",
125+
constants: &Default::default(),
123126
buffers: &[],
124127
},
125128
fragment: Some(wgpu::FragmentState {
126129
module: &shader_triangle_and_lines,
127130
entry_point: "fs_main_blue",
131+
constants: &Default::default(),
128132
targets: &[Some(RENDER_TARGET_FORMAT.into())],
129133
}),
130134
primitive: wgpu::PrimitiveState::default(),
@@ -144,11 +148,13 @@ impl crate::framework::Example for Example {
144148
vertex: wgpu::VertexState {
145149
module: &shader_triangle_and_lines,
146150
entry_point: "vs_main",
151+
constants: &Default::default(),
147152
buffers: &[],
148153
},
149154
fragment: Some(wgpu::FragmentState {
150155
module: &shader_triangle_and_lines,
151156
entry_point: "fs_main_white",
157+
constants: &Default::default(),
152158
targets: &[Some(config.view_formats[0].into())],
153159
}),
154160
primitive: wgpu::PrimitiveState {
@@ -205,11 +211,13 @@ impl crate::framework::Example for Example {
205211
vertex: wgpu::VertexState {
206212
module: &shader,
207213
entry_point: "vs_main",
214+
constants: &Default::default(),
208215
buffers: &[],
209216
},
210217
fragment: Some(wgpu::FragmentState {
211218
module: &shader,
212219
entry_point: "fs_main",
220+
constants: &Default::default(),
213221
targets: &[Some(config.view_formats[0].into())],
214222
}),
215223
primitive: wgpu::PrimitiveState::default(),

examples/src/cube/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,13 @@ impl crate::framework::Example for Example {
244244
vertex: wgpu::VertexState {
245245
module: &shader,
246246
entry_point: "vs_main",
247+
constants: &Default::default(),
247248
buffers: &vertex_buffers,
248249
},
249250
fragment: Some(wgpu::FragmentState {
250251
module: &shader,
251252
entry_point: "fs_main",
253+
constants: &Default::default(),
252254
targets: &[Some(config.view_formats[0].into())],
253255
}),
254256
primitive: wgpu::PrimitiveState {
@@ -270,11 +272,13 @@ impl crate::framework::Example for Example {
270272
vertex: wgpu::VertexState {
271273
module: &shader,
272274
entry_point: "vs_main",
275+
constants: &Default::default(),
273276
buffers: &vertex_buffers,
274277
},
275278
fragment: Some(wgpu::FragmentState {
276279
module: &shader,
277280
entry_point: "fs_wire",
281+
constants: &Default::default(),
278282
targets: &[Some(wgpu::ColorTargetState {
279283
format: config.view_formats[0],
280284
blend: Some(wgpu::BlendState {

examples/src/hello_compute/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ async fn execute_gpu_inner(
109109
layout: None,
110110
module: &cs_module,
111111
entry_point: "main",
112+
constants: &Default::default(),
112113
});
113114

114115
// Instantiates the bind group, once again specifying the binding of buffers.

examples/src/hello_synchronization/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ async fn execute(
103103
layout: Some(&pipeline_layout),
104104
module: &shaders_module,
105105
entry_point: "patient_main",
106+
constants: &Default::default(),
106107
});
107108
let hasty_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
108109
label: None,
109110
layout: Some(&pipeline_layout),
110111
module: &shaders_module,
111112
entry_point: "hasty_main",
113+
constants: &Default::default(),
112114
});
113115

114116
//----------------------------------------------------------

examples/src/hello_triangle/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
6060
module: &shader,
6161
entry_point: "vs_main",
6262
buffers: &[],
63+
constants: &Default::default(),
6364
},
6465
fragment: Some(wgpu::FragmentState {
6566
module: &shader,
6667
entry_point: "fs_main",
68+
constants: &Default::default(),
6769
targets: &[Some(swapchain_format.into())],
6870
}),
6971
primitive: wgpu::PrimitiveState::default(),

examples/src/hello_workgroups/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ async fn run() {
110110
layout: Some(&pipeline_layout),
111111
module: &shader,
112112
entry_point: "main",
113+
constants: &Default::default(),
113114
});
114115

115116
//----------------------------------------------------------

examples/src/mipmap/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,13 @@ impl Example {
9393
vertex: wgpu::VertexState {
9494
module: &shader,
9595
entry_point: "vs_main",
96+
constants: &Default::default(),
9697
buffers: &[],
9798
},
9899
fragment: Some(wgpu::FragmentState {
99100
module: &shader,
100101
entry_point: "fs_main",
102+
constants: &Default::default(),
101103
targets: &[Some(TEXTURE_FORMAT.into())],
102104
}),
103105
primitive: wgpu::PrimitiveState {
@@ -290,11 +292,13 @@ impl crate::framework::Example for Example {
290292
vertex: wgpu::VertexState {
291293
module: &shader,
292294
entry_point: "vs_main",
295+
constants: &Default::default(),
293296
buffers: &[],
294297
},
295298
fragment: Some(wgpu::FragmentState {
296299
module: &shader,
297300
entry_point: "fs_main",
301+
constants: &Default::default(),
298302
targets: &[Some(config.view_formats[0].into())],
299303
}),
300304
primitive: wgpu::PrimitiveState {

examples/src/msaa_line/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ impl Example {
5454
vertex: wgpu::VertexState {
5555
module: shader,
5656
entry_point: "vs_main",
57+
constants: &Default::default(),
5758
buffers: &[wgpu::VertexBufferLayout {
5859
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
5960
step_mode: wgpu::VertexStepMode::Vertex,
@@ -63,6 +64,7 @@ impl Example {
6364
fragment: Some(wgpu::FragmentState {
6465
module: shader,
6566
entry_point: "fs_main",
67+
constants: &Default::default(),
6668
targets: &[Some(config.view_formats[0].into())],
6769
}),
6870
primitive: wgpu::PrimitiveState {

examples/src/render_to_texture/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ async fn run(_path: Option<String>) {
5959
vertex: wgpu::VertexState {
6060
module: &shader,
6161
entry_point: "vs_main",
62+
constants: &Default::default(),
6263
buffers: &[],
6364
},
6465
fragment: Some(wgpu::FragmentState {
6566
module: &shader,
6667
entry_point: "fs_main",
68+
constants: &Default::default(),
6769
targets: &[Some(wgpu::TextureFormat::Rgba8UnormSrgb.into())],
6870
}),
6971
primitive: wgpu::PrimitiveState::default(),

examples/src/repeated_compute/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ impl WgpuContext {
245245
layout: Some(&pipeline_layout),
246246
module: &shader,
247247
entry_point: "main",
248+
constants: &Default::default(),
248249
});
249250

250251
WgpuContext {

examples/src/shadow/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ impl crate::framework::Example for Example {
500500
vertex: wgpu::VertexState {
501501
module: &shader,
502502
entry_point: "vs_bake",
503+
constants: &Default::default(),
503504
buffers: &[vb_desc.clone()],
504505
},
505506
fragment: None,
@@ -632,6 +633,7 @@ impl crate::framework::Example for Example {
632633
vertex: wgpu::VertexState {
633634
module: &shader,
634635
entry_point: "vs_main",
636+
constants: &Default::default(),
635637
buffers: &[vb_desc],
636638
},
637639
fragment: Some(wgpu::FragmentState {
@@ -641,6 +643,7 @@ impl crate::framework::Example for Example {
641643
} else {
642644
"fs_main_without_storage"
643645
},
646+
constants: &Default::default(),
644647
targets: &[Some(config.view_formats[0].into())],
645648
}),
646649
primitive: wgpu::PrimitiveState {

examples/src/skybox/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,13 @@ impl crate::framework::Example for Example {
199199
vertex: wgpu::VertexState {
200200
module: &shader,
201201
entry_point: "vs_sky",
202+
constants: &Default::default(),
202203
buffers: &[],
203204
},
204205
fragment: Some(wgpu::FragmentState {
205206
module: &shader,
206207
entry_point: "fs_sky",
208+
constants: &Default::default(),
207209
targets: &[Some(config.view_formats[0].into())],
208210
}),
209211
primitive: wgpu::PrimitiveState {
@@ -226,6 +228,7 @@ impl crate::framework::Example for Example {
226228
vertex: wgpu::VertexState {
227229
module: &shader,
228230
entry_point: "vs_entity",
231+
constants: &Default::default(),
229232
buffers: &[wgpu::VertexBufferLayout {
230233
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
231234
step_mode: wgpu::VertexStepMode::Vertex,
@@ -235,6 +238,7 @@ impl crate::framework::Example for Example {
235238
fragment: Some(wgpu::FragmentState {
236239
module: &shader,
237240
entry_point: "fs_entity",
241+
constants: &Default::default(),
238242
targets: &[Some(config.view_formats[0].into())],
239243
}),
240244
primitive: wgpu::PrimitiveState {

examples/src/srgb_blend/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ impl<const SRGB: bool> crate::framework::Example for Example<SRGB> {
131131
vertex: wgpu::VertexState {
132132
module: &shader,
133133
entry_point: "vs_main",
134+
constants: &Default::default(),
134135
buffers: &vertex_buffers,
135136
},
136137
fragment: Some(wgpu::FragmentState {
137138
module: &shader,
138139
entry_point: "fs_main",
140+
constants: &Default::default(),
139141
targets: &[Some(wgpu::ColorTargetState {
140142
format: config.view_formats[0],
141143
blend: Some(wgpu::BlendState::ALPHA_BLENDING),

examples/src/stencil_triangles/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ impl crate::framework::Example for Example {
7474
vertex: wgpu::VertexState {
7575
module: &shader,
7676
entry_point: "vs_main",
77+
constants: &Default::default(),
7778
buffers: &vertex_buffers,
7879
},
7980
fragment: Some(wgpu::FragmentState {
8081
module: &shader,
8182
entry_point: "fs_main",
83+
constants: &Default::default(),
8284
targets: &[Some(wgpu::ColorTargetState {
8385
format: config.view_formats[0],
8486
blend: None,
@@ -112,11 +114,13 @@ impl crate::framework::Example for Example {
112114
vertex: wgpu::VertexState {
113115
module: &shader,
114116
entry_point: "vs_main",
117+
constants: &Default::default(),
115118
buffers: &vertex_buffers,
116119
},
117120
fragment: Some(wgpu::FragmentState {
118121
module: &shader,
119122
entry_point: "fs_main",
123+
constants: &Default::default(),
120124
targets: &[Some(config.view_formats[0].into())],
121125
}),
122126
primitive: Default::default(),

0 commit comments

Comments
 (0)