Skip to content

Commit 4902e47

Browse files
Pipeline cache API and implementation for Vulkan (#5319)
Co-authored-by: Connor Fitzgerald <[email protected]>
1 parent eeb1a9d commit 4902e47

File tree

76 files changed

+1578
-19
lines changed

Some content is hidden

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

76 files changed

+1578
-19
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ By @stefnotch in [#5410](https://github.com/gfx-rs/wgpu/pull/5410)
7272

7373
### New features
7474

75+
#### Vulkan
76+
77+
- Added a `PipelineCache` resource to allow using Vulkan pipeline caches. By @DJMcNab in [#5319](https://github.com/gfx-rs/wgpu/pull/5319)
78+
7579
#### General
7680

7781
#### Naga

benches/benches/renderpass.rs

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ impl RenderpassState {
207207
compilation_options: wgpu::PipelineCompilationOptions::default(),
208208
}),
209209
multiview: None,
210+
cache: None,
210211
});
211212

212213
let render_target = device_state
@@ -304,6 +305,7 @@ impl RenderpassState {
304305
compilation_options: wgpu::PipelineCompilationOptions::default(),
305306
}),
306307
multiview: None,
308+
cache: None,
307309
},
308310
));
309311
}

deno_webgpu/pipeline.rs

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub fn op_webgpu_create_compute_pipeline(
115115
constants: Cow::Owned(compute.constants.unwrap_or_default()),
116116
zero_initialize_workgroup_memory: true,
117117
},
118+
cache: None,
118119
};
119120
let implicit_pipelines = match layout {
120121
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None,
@@ -395,6 +396,7 @@ pub fn op_webgpu_create_render_pipeline(
395396
multisample: args.multisample,
396397
fragment,
397398
multiview: None,
399+
cache: None,
398400
};
399401

400402
let implicit_pipelines = match args.layout {

examples/src/boids/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ impl crate::framework::Example for Example {
156156
depth_stencil: None,
157157
multisample: wgpu::MultisampleState::default(),
158158
multiview: None,
159+
cache: None,
159160
});
160161

161162
// create compute pipeline
@@ -166,6 +167,7 @@ impl crate::framework::Example for Example {
166167
module: &compute_shader,
167168
entry_point: "main",
168169
compilation_options: Default::default(),
170+
cache: None,
169171
});
170172

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

examples/src/bunnymark/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ impl crate::framework::Example for Example {
224224
depth_stencil: None,
225225
multisample: wgpu::MultisampleState::default(),
226226
multiview: None,
227+
cache: None,
227228
});
228229

229230
let texture = {

examples/src/conservative_raster/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ impl crate::framework::Example for Example {
113113
depth_stencil: None,
114114
multisample: wgpu::MultisampleState::default(),
115115
multiview: None,
116+
cache: None,
116117
});
117118

118119
let pipeline_triangle_regular =
@@ -135,6 +136,7 @@ impl crate::framework::Example for Example {
135136
depth_stencil: None,
136137
multisample: wgpu::MultisampleState::default(),
137138
multiview: None,
139+
cache: None,
138140
});
139141

140142
let pipeline_lines = if device
@@ -165,6 +167,7 @@ impl crate::framework::Example for Example {
165167
depth_stencil: None,
166168
multisample: wgpu::MultisampleState::default(),
167169
multiview: None,
170+
cache: None,
168171
}),
169172
)
170173
} else {
@@ -224,6 +227,7 @@ impl crate::framework::Example for Example {
224227
depth_stencil: None,
225228
multisample: wgpu::MultisampleState::default(),
226229
multiview: None,
230+
cache: None,
227231
}),
228232
bind_group_layout,
229233
)

examples/src/cube/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ impl crate::framework::Example for Example {
260260
depth_stencil: None,
261261
multisample: wgpu::MultisampleState::default(),
262262
multiview: None,
263+
cache: None,
263264
});
264265

265266
let pipeline_wire = if device
@@ -301,6 +302,7 @@ impl crate::framework::Example for Example {
301302
depth_stencil: None,
302303
multisample: wgpu::MultisampleState::default(),
303304
multiview: None,
305+
cache: None,
304306
});
305307
Some(pipeline_wire)
306308
} else {

examples/src/hello_compute/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ async fn execute_gpu_inner(
110110
module: &cs_module,
111111
entry_point: "main",
112112
compilation_options: Default::default(),
113+
cache: None,
113114
});
114115

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

examples/src/hello_synchronization/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ async fn execute(
104104
module: &shaders_module,
105105
entry_point: "patient_main",
106106
compilation_options: Default::default(),
107+
cache: None,
107108
});
108109
let hasty_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
109110
label: None,
110111
layout: Some(&pipeline_layout),
111112
module: &shaders_module,
112113
entry_point: "hasty_main",
113114
compilation_options: Default::default(),
115+
cache: None,
114116
});
115117

116118
//----------------------------------------------------------

examples/src/hello_triangle/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
7272
depth_stencil: None,
7373
multisample: wgpu::MultisampleState::default(),
7474
multiview: None,
75+
cache: None,
7576
});
7677

7778
let mut config = surface

examples/src/hello_workgroups/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ async fn run() {
111111
module: &shader,
112112
entry_point: "main",
113113
compilation_options: Default::default(),
114+
cache: None,
114115
});
115116

116117
//----------------------------------------------------------

examples/src/mipmap/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ impl Example {
109109
depth_stencil: None,
110110
multisample: wgpu::MultisampleState::default(),
111111
multiview: None,
112+
cache: None,
112113
});
113114

114115
let bind_group_layout = pipeline.get_bind_group_layout(0);
@@ -310,6 +311,7 @@ impl crate::framework::Example for Example {
310311
depth_stencil: None,
311312
multisample: wgpu::MultisampleState::default(),
312313
multiview: None,
314+
cache: None,
313315
});
314316

315317
// Create bind group

examples/src/msaa_line/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ impl Example {
7878
..Default::default()
7979
},
8080
multiview: None,
81+
cache: None,
8182
});
8283
let mut encoder =
8384
device.create_render_bundle_encoder(&wgpu::RenderBundleEncoderDescriptor {

examples/src/render_to_texture/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ async fn run(_path: Option<String>) {
7272
depth_stencil: None,
7373
multisample: wgpu::MultisampleState::default(),
7474
multiview: None,
75+
cache: None,
7576
});
7677

7778
log::info!("Wgpu context set up.");

examples/src/repeated_compute/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ impl WgpuContext {
246246
module: &shader,
247247
entry_point: "main",
248248
compilation_options: Default::default(),
249+
cache: None,
249250
});
250251

251252
WgpuContext {

examples/src/shadow/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ impl crate::framework::Example for Example {
526526
}),
527527
multisample: wgpu::MultisampleState::default(),
528528
multiview: None,
529+
cache: None,
529530
});
530531

531532
Pass {
@@ -660,6 +661,7 @@ impl crate::framework::Example for Example {
660661
}),
661662
multisample: wgpu::MultisampleState::default(),
662663
multiview: None,
664+
cache: None,
663665
});
664666

665667
Pass {

examples/src/skybox/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ impl crate::framework::Example for Example {
221221
}),
222222
multisample: wgpu::MultisampleState::default(),
223223
multiview: None,
224+
cache: None,
224225
});
225226
let entity_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
226227
label: Some("Entity"),
@@ -254,6 +255,7 @@ impl crate::framework::Example for Example {
254255
}),
255256
multisample: wgpu::MultisampleState::default(),
256257
multiview: None,
258+
cache: None,
257259
});
258260

259261
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {

examples/src/srgb_blend/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ impl<const SRGB: bool> crate::framework::Example for Example<SRGB> {
151151
depth_stencil: None,
152152
multisample: wgpu::MultisampleState::default(),
153153
multiview: None,
154+
cache: None,
154155
});
155156

156157
// Done

examples/src/stencil_triangles/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl crate::framework::Example for Example {
106106
}),
107107
multisample: wgpu::MultisampleState::default(),
108108
multiview: None,
109+
cache: None,
109110
});
110111

111112
let outer_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
@@ -141,6 +142,7 @@ impl crate::framework::Example for Example {
141142
}),
142143
multisample: wgpu::MultisampleState::default(),
143144
multiview: None,
145+
cache: None,
144146
});
145147

146148
let stencil_buffer = device.create_texture(&wgpu::TextureDescriptor {

examples/src/storage_texture/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ async fn run(_path: Option<String>) {
101101
module: &shader,
102102
entry_point: "main",
103103
compilation_options: Default::default(),
104+
cache: None,
104105
});
105106

106107
log::info!("Wgpu context set up.");

examples/src/texture_arrays/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ impl crate::framework::Example for Example {
341341
depth_stencil: None,
342342
multisample: wgpu::MultisampleState::default(),
343343
multiview: None,
344+
cache: None
344345
});
345346

346347
Self {

examples/src/timestamp_queries/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ fn compute_pass(
299299
module,
300300
entry_point: "main_cs",
301301
compilation_options: Default::default(),
302+
cache: None,
302303
});
303304
let bind_group_layout = compute_pipeline.get_bind_group_layout(0);
304305
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
@@ -366,8 +367,8 @@ fn render_pass(
366367
depth_stencil: None,
367368
multisample: wgpu::MultisampleState::default(),
368369
multiview: None,
370+
cache: None,
369371
});
370-
371372
let render_target = device.create_texture(&wgpu::TextureDescriptor {
372373
label: Some("rendertarget"),
373374
size: wgpu::Extent3d {

examples/src/uniform_values/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ impl WgpuContext {
192192
depth_stencil: None,
193193
multisample: wgpu::MultisampleState::default(),
194194
multiview: None,
195+
cache: None,
195196
});
196-
197197
let surface_config = surface
198198
.get_default_config(&adapter, size.width, size.height)
199199
.unwrap();

examples/src/water/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,8 @@ impl crate::framework::Example for Example {
574574
// No multisampling is used.
575575
multisample: wgpu::MultisampleState::default(),
576576
multiview: None,
577+
// No pipeline caching is used
578+
cache: None,
577579
});
578580

579581
// Same idea as the water pipeline.
@@ -610,6 +612,7 @@ impl crate::framework::Example for Example {
610612
}),
611613
multisample: wgpu::MultisampleState::default(),
612614
multiview: None,
615+
cache: None
613616
});
614617

615618
// A render bundle to draw the terrain.

player/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ impl GlobalPlay for wgc::global::Global {
302302
Action::DestroyRenderPipeline(id) => {
303303
self.render_pipeline_drop::<A>(id);
304304
}
305+
Action::CreatePipelineCache { id, desc } => {
306+
let _ = unsafe { self.device_create_pipeline_cache::<A>(device, &desc, Some(id)) };
307+
}
308+
Action::DestroyPipelineCache(id) => {
309+
self.pipeline_cache_drop::<A>(id);
310+
}
305311
Action::CreateRenderBundle { id, desc, base } => {
306312
let bundle =
307313
wgc::command::RenderBundleEncoder::new(&desc, device, Some(base)).unwrap();

tests/src/image.rs

+1
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ fn copy_via_compute(
370370
module: &sm,
371371
entry_point: "copy_texture_to_buffer",
372372
compilation_options: Default::default(),
373+
cache: None,
373374
});
374375

375376
{

tests/tests/bgra8unorm_storage.rs

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ static BGRA8_UNORM_STORAGE: GpuTestConfiguration = GpuTestConfiguration::new()
9898
entry_point: "main",
9999
compilation_options: Default::default(),
100100
module: &module,
101+
cache: None,
101102
});
102103

103104
let mut encoder =

tests/tests/bind_group_layout_dedup.rs

+5
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ async fn bgl_dedupe(ctx: TestingContext) {
9191
module: &module,
9292
entry_point: "no_resources",
9393
compilation_options: Default::default(),
94+
cache: None,
9495
};
9596

9697
let pipeline = ctx.device.create_compute_pipeline(&desc);
@@ -220,6 +221,7 @@ fn bgl_dedupe_with_dropped_user_handle(ctx: TestingContext) {
220221
module: &module,
221222
entry_point: "no_resources",
222223
compilation_options: Default::default(),
224+
cache: None,
223225
});
224226

225227
let mut encoder = ctx.device.create_command_encoder(&Default::default());
@@ -266,6 +268,7 @@ fn bgl_dedupe_derived(ctx: TestingContext) {
266268
module: &module,
267269
entry_point: "resources",
268270
compilation_options: Default::default(),
271+
cache: None,
269272
});
270273

271274
// We create two bind groups, pulling the bind_group_layout from the pipeline each time.
@@ -337,6 +340,7 @@ fn separate_programs_have_incompatible_derived_bgls(ctx: TestingContext) {
337340
module: &module,
338341
entry_point: "resources",
339342
compilation_options: Default::default(),
343+
cache: None,
340344
};
341345
// Create two pipelines, creating a BG from the second.
342346
let pipeline1 = ctx.device.create_compute_pipeline(&desc);
@@ -399,6 +403,7 @@ fn derived_bgls_incompatible_with_regular_bgls(ctx: TestingContext) {
399403
module: &module,
400404
entry_point: "resources",
401405
compilation_options: Default::default(),
406+
cache: None,
402407
});
403408

404409
// Create a matching BGL

tests/tests/buffer.rs

+2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_LAYOUT: GpuTestConfiguration = GpuTestConfigu
225225
module: &shader_module,
226226
entry_point: "main",
227227
compilation_options: Default::default(),
228+
cache: None,
228229
});
229230
});
230231
});
@@ -294,6 +295,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_DISPATCH: GpuTestConfiguration = GpuTestConfi
294295
module: &shader_module,
295296
entry_point: "main",
296297
compilation_options: Default::default(),
298+
cache: None,
297299
});
298300

299301
let buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {

0 commit comments

Comments
 (0)