Skip to content

Commit

Permalink
Pipeline cache API and implementation for Vulkan (#5319)
Browse files Browse the repository at this point in the history
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
  • Loading branch information
DJMcNab and cwfitzgerald committed May 16, 2024
1 parent eeb1a9d commit 4902e47
Show file tree
Hide file tree
Showing 76 changed files with 1,578 additions and 19 deletions.
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 benches/benches/renderpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ impl RenderpassState {
compilation_options: wgpu::PipelineCompilationOptions::default(),
}),
multiview: None,
cache: None,
});

let render_target = device_state
Expand Down Expand Up @@ -304,6 +305,7 @@ impl RenderpassState {
compilation_options: wgpu::PipelineCompilationOptions::default(),
}),
multiview: None,
cache: None,
},
));
}
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

0 comments on commit 4902e47

Please sign in to comment.