Skip to content

Commit f46258e

Browse files
committed
add pipeline constants plumbing
1 parent 16ec5b0 commit f46258e

File tree

64 files changed

+207
-24
lines changed

Some content is hidden

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

64 files changed

+207
-24
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;
@@ -78,7 +79,7 @@ pub enum GPUPipelineLayoutOrGPUAutoLayoutMode {
7879
pub struct GpuProgrammableStage {
7980
module: ResourceId,
8081
entry_point: String,
81-
// constants: HashMap<String, GPUPipelineConstantValue>
82+
constants: HashMap<String, f64>,
8283
}
8384

8485
#[op2]
@@ -113,8 +114,8 @@ pub fn op_webgpu_create_compute_pipeline(
113114
layout: pipeline_layout,
114115
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
115116
module: compute_shader_module_resource.1,
116-
entry_point: Cow::from(compute.entry_point),
117-
// TODO(lucacasonato): support args.compute.constants
117+
entry_point: Cow::Owned(compute.entry_point),
118+
constants: Cow::Owned(compute.constants),
118119
},
119120
};
120121
let implicit_pipelines = match layout {
@@ -282,6 +283,7 @@ impl<'a> From<GpuVertexBufferLayout> for wgpu_core::pipeline::VertexBufferLayout
282283
struct GpuVertexState {
283284
module: ResourceId,
284285
entry_point: String,
286+
constants: HashMap<String, f64>,
285287
buffers: Vec<Option<GpuVertexBufferLayout>>,
286288
}
287289

@@ -309,7 +311,7 @@ struct GpuFragmentState {
309311
targets: Vec<Option<wgpu_types::ColorTargetState>>,
310312
module: u32,
311313
entry_point: String,
312-
// TODO(lucacasonato): constants
314+
constants: HashMap<String, f64>,
313315
}
314316

315317
#[derive(Deserialize)]
@@ -358,9 +360,10 @@ pub fn op_webgpu_create_render_pipeline(
358360
Some(wgpu_core::pipeline::FragmentState {
359361
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
360362
module: fragment_shader_module_resource.1,
361-
entry_point: Cow::from(fragment.entry_point),
363+
entry_point: Cow::Owned(fragment.entry_point),
364+
constants: Cow::Owned(fragment.constants),
362365
},
363-
targets: Cow::from(fragment.targets),
366+
targets: Cow::Owned(fragment.targets),
364367
})
365368
} else {
366369
None
@@ -381,6 +384,7 @@ pub fn op_webgpu_create_render_pipeline(
381384
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
382385
module: vertex_shader_module_resource.1,
383386
entry_point: Cow::Owned(args.vertex.entry_point),
387+
constants: Cow::Owned(args.vertex.constants),
384388
},
385389
buffers: Cow::Owned(vertex_buffers),
386390
},

examples/boids/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ impl wgpu_example::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 wgpu_example::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 wgpu_example::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/bunnymark/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,13 @@ impl wgpu_example::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/conservative-raster/src/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ impl wgpu_example::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 wgpu_example::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 wgpu_example::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 wgpu_example::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/cube/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,13 @@ impl wgpu_example::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 wgpu_example::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/hello-compute/src/main.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/hello-synchronization/src/main.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/hello-triangle/src/main.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/hello-workgroups/src/main.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/mipmap/src/main.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 wgpu_example::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/msaa-line/src/main.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/render-to-texture/src/main.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/repeated-compute/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ impl WgpuContext {
242242
layout: Some(&pipeline_layout),
243243
module: &shader,
244244
entry_point: "main",
245+
constants: &Default::default(),
245246
});
246247

247248
WgpuContext {

examples/shadow/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ impl wgpu_example::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 wgpu_example::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 wgpu_example::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/skybox/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,13 @@ impl wgpu_example::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 wgpu_example::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 wgpu_example::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/srgb-blend/src/main.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ impl<const SRGB: bool> wgpu_example::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/stencil-triangles/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,13 @@ impl wgpu_example::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 wgpu_example::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)