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 cache API and implementation for Vulkan #5319

Merged
merged 33 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
7a52266
Implement resource management of pipeline caches
DJMcNab Feb 27, 2024
ef88b7c
Introduce the cache API to the frontend
DJMcNab Feb 27, 2024
7edb08b
Support using a pipeline cache when creating a pipeline
DJMcNab Feb 27, 2024
fb56d8c
Finish implementing the anemic version of pipeline caching
DJMcNab Feb 28, 2024
1b53496
Actually pass the cache to the data
DJMcNab Feb 28, 2024
2e0e614
Move `pipeline_cache_key` to `wgpu::util`
DJMcNab Feb 29, 2024
f488e81
Fix solveable CI errors
DJMcNab Feb 29, 2024
eb17331
Add a CHANGELOG entry
DJMcNab Mar 1, 2024
f7d4516
Add more comprehensive documentation
DJMcNab Mar 1, 2024
40f2a85
Update documentation and caching use
DJMcNab Mar 4, 2024
66f9d54
Add a feature for pipeline caching
DJMcNab Mar 5, 2024
ceb70a0
Address (most) review comments
DJMcNab Mar 14, 2024
026edf5
Sketch out some API for validation
DJMcNab Mar 14, 2024
7969387
Sketch out the cache header API fully
DJMcNab Mar 15, 2024
824feab
Integrate cache validation
DJMcNab Mar 18, 2024
fea8a79
📎
DJMcNab Mar 18, 2024
7ac7010
Fix enforced truncation
DJMcNab Mar 18, 2024
ca65d7e
Punt the hash validation
DJMcNab Apr 5, 2024
c6f1669
Move the cache to PipelineCompilationOptions
DJMcNab Apr 19, 2024
d46ccd3
Address some review comments
DJMcNab Apr 19, 2024
e046f9b
Combine the init and non-init paths
DJMcNab Apr 19, 2024
b470541
Fix more review comments and add a test
DJMcNab Apr 19, 2024
3daf8eb
Fix incorrect intra-doc-link
DJMcNab Apr 19, 2024
130cb0a
📎
DJMcNab Apr 19, 2024
20906e9
Fix webgpu compile
DJMcNab Apr 19, 2024
bddbe63
Fix changelog again
DJMcNab May 9, 2024
e957a85
Update wgpu-types/src/lib.rs
DJMcNab May 9, 2024
1f11a64
Address review comments
DJMcNab May 9, 2024
f292531
Move the cache back to the root :(
DJMcNab May 16, 2024
5ecb734
Merge branch 'trunk' into pipeline-cache-api-vulkan
DJMcNab May 16, 2024
96da24a
Fix ash upgrade issue
DJMcNab May 16, 2024
56bb2ea
Fix new test
DJMcNab May 16, 2024
1d8f2af
Merge remote-tracking branch 'upstream/trunk' into pipeline-cache-api…
cwfitzgerald May 16, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ By @stefnotch in [#5410](https://github.com/gfx-rs/wgpu/pull/5410)

### New features

#### Vulkan

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

#### General

#### Naga
Expand Down
2 changes: 2 additions & 0 deletions deno_webgpu/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub fn op_webgpu_create_compute_pipeline(
constants: Cow::Owned(compute.constants.unwrap_or_default()),
zero_initialize_workgroup_memory: true,
},
cache: None,
};
let implicit_pipelines = match layout {
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None,
Expand Down Expand Up @@ -395,6 +396,7 @@ pub fn op_webgpu_create_render_pipeline(
multisample: args.multisample,
fragment,
multiview: None,
cache: None,
};

let implicit_pipelines = match args.layout {
Expand Down
2 changes: 2 additions & 0 deletions examples/src/boids/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ impl crate::framework::Example for Example {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

// create compute pipeline
Expand All @@ -166,6 +167,7 @@ impl crate::framework::Example for Example {
module: &compute_shader,
entry_point: "main",
compilation_options: Default::default(),
cache: None,
});

// buffer for the three 2d triangle vertices of each instance
Expand Down
1 change: 1 addition & 0 deletions examples/src/bunnymark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ impl crate::framework::Example for Example {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

let texture = {
Expand Down
4 changes: 4 additions & 0 deletions examples/src/conservative_raster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl crate::framework::Example for Example {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

let pipeline_triangle_regular =
Expand All @@ -135,6 +136,7 @@ impl crate::framework::Example for Example {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

let pipeline_lines = if device
Expand Down Expand Up @@ -165,6 +167,7 @@ impl crate::framework::Example for Example {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
}),
)
} else {
Expand Down Expand Up @@ -224,6 +227,7 @@ impl crate::framework::Example for Example {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
}),
bind_group_layout,
)
Expand Down
2 changes: 2 additions & 0 deletions examples/src/cube/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ impl crate::framework::Example for Example {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

let pipeline_wire = if device
Expand Down Expand Up @@ -301,6 +302,7 @@ impl crate::framework::Example for Example {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});
Some(pipeline_wire)
} else {
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 @@ -110,6 +110,7 @@ async fn execute_gpu_inner(
module: &cs_module,
entry_point: "main",
compilation_options: Default::default(),
cache: None,
});

// 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 @@ -104,13 +104,15 @@ async fn execute(
module: &shaders_module,
entry_point: "patient_main",
compilation_options: Default::default(),
cache: None,
});
let hasty_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: None,
layout: Some(&pipeline_layout),
module: &shaders_module,
entry_point: "hasty_main",
compilation_options: Default::default(),
cache: None,
});

//----------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions examples/src/hello_triangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

let mut config = surface
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 @@ -111,6 +111,7 @@ async fn run() {
module: &shader,
entry_point: "main",
compilation_options: Default::default(),
cache: None,
});

//----------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions examples/src/mipmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ impl Example {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

let bind_group_layout = pipeline.get_bind_group_layout(0);
Expand Down Expand Up @@ -310,6 +311,7 @@ impl crate::framework::Example for Example {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

// Create bind group
Expand Down
1 change: 1 addition & 0 deletions examples/src/msaa_line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl Example {
..Default::default()
},
multiview: None,
cache: None,
});
let mut encoder =
device.create_render_bundle_encoder(&wgpu::RenderBundleEncoderDescriptor {
Expand Down
1 change: 1 addition & 0 deletions examples/src/render_to_texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ async fn run(_path: Option<String>) {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

log::info!("Wgpu context set up.");
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 @@ -246,6 +246,7 @@ impl WgpuContext {
module: &shader,
entry_point: "main",
compilation_options: Default::default(),
cache: None,
});

WgpuContext {
Expand Down
2 changes: 2 additions & 0 deletions examples/src/shadow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ impl crate::framework::Example for Example {
}),
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

Pass {
Expand Down Expand Up @@ -660,6 +661,7 @@ impl crate::framework::Example for Example {
}),
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

Pass {
Expand Down
2 changes: 2 additions & 0 deletions examples/src/skybox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ impl crate::framework::Example for Example {
}),
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});
let entity_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: Some("Entity"),
Expand Down Expand Up @@ -254,6 +255,7 @@ impl crate::framework::Example for Example {
}),
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
Expand Down
1 change: 1 addition & 0 deletions examples/src/srgb_blend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl<const SRGB: bool> crate::framework::Example for Example<SRGB> {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

// Done
Expand Down
2 changes: 2 additions & 0 deletions examples/src/stencil_triangles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl crate::framework::Example for Example {
}),
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

let outer_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
Expand Down Expand Up @@ -141,6 +142,7 @@ impl crate::framework::Example for Example {
}),
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

let stencil_buffer = device.create_texture(&wgpu::TextureDescriptor {
Expand Down
1 change: 1 addition & 0 deletions examples/src/storage_texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ async fn run(_path: Option<String>) {
module: &shader,
entry_point: "main",
compilation_options: Default::default(),
cache: None,
});

log::info!("Wgpu context set up.");
Expand Down
1 change: 1 addition & 0 deletions examples/src/texture_arrays/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ impl crate::framework::Example for Example {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None
});

Self {
Expand Down
3 changes: 2 additions & 1 deletion examples/src/timestamp_queries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ fn compute_pass(
module,
entry_point: "main_cs",
compilation_options: Default::default(),
cache: None,
});
let bind_group_layout = compute_pipeline.get_bind_group_layout(0);
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
Expand Down Expand Up @@ -366,8 +367,8 @@ fn render_pass(
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

let render_target = device.create_texture(&wgpu::TextureDescriptor {
label: Some("rendertarget"),
size: wgpu::Extent3d {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/uniform_values/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ impl WgpuContext {
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None,
});

let surface_config = surface
.get_default_config(&adapter, size.width, size.height)
.unwrap();
Expand Down
3 changes: 3 additions & 0 deletions examples/src/water/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ impl crate::framework::Example for Example {
// No multisampling is used.
multisample: wgpu::MultisampleState::default(),
multiview: None,
// No pipeline caching is used
cache: None,
});

// Same idea as the water pipeline.
Expand Down Expand Up @@ -610,6 +612,7 @@ impl crate::framework::Example for Example {
}),
multisample: wgpu::MultisampleState::default(),
multiview: None,
cache: None
});

// A render bundle to draw the terrain.
Expand Down
6 changes: 6 additions & 0 deletions player/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,12 @@ impl GlobalPlay for wgc::global::Global {
Action::DestroyRenderPipeline(id) => {
self.render_pipeline_drop::<A>(id);
}
Action::CreatePipelineCache { id, desc } => {
let _ = unsafe { self.device_create_pipeline_cache::<A>(device, &desc, Some(id)) };
}
Action::DestroyPipelineCache(id) => {
self.pipeline_cache_drop::<A>(id);
}
Action::CreateRenderBundle { id, desc, base } => {
let bundle =
wgc::command::RenderBundleEncoder::new(&desc, device, Some(base)).unwrap();
Expand Down
1 change: 1 addition & 0 deletions tests/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ fn copy_via_compute(
module: &sm,
entry_point: "copy_texture_to_buffer",
compilation_options: Default::default(),
cache: None,
});

{
Expand Down
1 change: 1 addition & 0 deletions tests/tests/bgra8unorm_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static BGRA8_UNORM_STORAGE: GpuTestConfiguration = GpuTestConfiguration::new()
entry_point: "main",
compilation_options: Default::default(),
module: &module,
cache: None,
});

let mut encoder =
Expand Down
5 changes: 5 additions & 0 deletions tests/tests/bind_group_layout_dedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ async fn bgl_dedupe(ctx: TestingContext) {
module: &module,
entry_point: "no_resources",
compilation_options: Default::default(),
cache: None,
};

let pipeline = ctx.device.create_compute_pipeline(&desc);
Expand Down Expand Up @@ -220,6 +221,7 @@ fn bgl_dedupe_with_dropped_user_handle(ctx: TestingContext) {
module: &module,
entry_point: "no_resources",
compilation_options: Default::default(),
cache: None,
});

let mut encoder = ctx.device.create_command_encoder(&Default::default());
Expand Down Expand Up @@ -266,6 +268,7 @@ fn bgl_dedupe_derived(ctx: TestingContext) {
module: &module,
entry_point: "resources",
compilation_options: Default::default(),
cache: None,
});

// We create two bind groups, pulling the bind_group_layout from the pipeline each time.
Expand Down Expand Up @@ -337,6 +340,7 @@ fn separate_programs_have_incompatible_derived_bgls(ctx: TestingContext) {
module: &module,
entry_point: "resources",
compilation_options: Default::default(),
cache: None,
};
// Create two pipelines, creating a BG from the second.
let pipeline1 = ctx.device.create_compute_pipeline(&desc);
Expand Down Expand Up @@ -399,6 +403,7 @@ fn derived_bgls_incompatible_with_regular_bgls(ctx: TestingContext) {
module: &module,
entry_point: "resources",
compilation_options: Default::default(),
cache: None,
});

// Create a matching BGL
Expand Down
2 changes: 2 additions & 0 deletions tests/tests/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_LAYOUT: GpuTestConfiguration = GpuTestConfigu
module: &shader_module,
entry_point: "main",
compilation_options: Default::default(),
cache: None,
});
});
});
Expand Down Expand Up @@ -294,6 +295,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_DISPATCH: GpuTestConfiguration = GpuTestConfi
module: &shader_module,
entry_point: "main",
compilation_options: Default::default(),
cache: None,
});

let buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
Expand Down
Loading
Loading