From 8fb8c382f67415be730891546f07645e332bc5b3 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 15:33:45 -0400 Subject: [PATCH 01/33] build: add `bon` 3.0.0 --- Cargo.lock | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + 2 files changed, 84 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 8ff6df69e71..b4f77265fb0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -362,6 +362,31 @@ dependencies = [ "objc2", ] +[[package]] +name = "bon" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32649b2d94d4dae1084cffd2ce1a778165e887497e4d1d55cd3976839f76194e" +dependencies = [ + "bon-macros", + "rustversion", +] + +[[package]] +name = "bon-macros" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13823053b3090fb2a35940608b0ff4c9254eb97651a971cf49fd84f8604c2591" +dependencies = [ + "darling", + "ident_case", + "prettyplease", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + [[package]] name = "bumpalo" version = "3.16.0" @@ -762,6 +787,41 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991" +[[package]] +name = "darling" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.20.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "data-encoding" version = "2.6.0" @@ -1099,6 +1159,12 @@ dependencies = [ "spin", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "foreign-types" version = "0.5.0" @@ -1534,6 +1600,12 @@ dependencies = [ "objc2", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "0.5.0" @@ -2364,6 +2436,16 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8cf8e6a8aa66ce33f63993ffc4ea4271eb5b0530a9002db8455ea6050c77bfa" +[[package]] +name = "prettyplease" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +dependencies = [ + "proc-macro2", + "syn", +] + [[package]] name = "proc-macro-crate" version = "3.2.0" @@ -3777,6 +3859,7 @@ name = "wgpu-types" version = "23.0.0" dependencies = [ "bitflags 2.6.0", + "bon", "js-sys", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 5e11425756f..1a2632b2594 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,6 +76,7 @@ arrayvec = "0.7" bincode = "1" bit-vec = "0.8" bitflags = "2.6" +bon = "3.0.0" bytemuck = { version = "1.19" } cfg_aliases = "0.1" cfg-if = "1" From f3512f93e59026746507a4a99183990c42997ffa Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 15:49:59 -0400 Subject: [PATCH 02/33] WIP: refactor!: give `BufferDescriptor` a builder API --- wgpu-types/src/lib.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 8053c57238c..c6362e22d26 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -5329,10 +5329,11 @@ impl_bitflags!(BufferUsages); /// Corresponds to [WebGPU `GPUBufferDescriptor`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpubufferdescriptor). #[repr(C)] -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(bon::Builder, Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct BufferDescriptor { +pub struct BufferDescriptor { /// Debug label of a buffer. This will show up in graphics debuggers for easy identification. + #[builder(default)] pub label: L, /// Size of a buffer, in bytes. pub size: BufferAddress, @@ -5344,13 +5345,14 @@ pub struct BufferDescriptor { /// /// If this is `true`, [`size`](#structfield.size) must be a multiple of /// [`COPY_BUFFER_ALIGNMENT`]. + #[builder(default)] pub mapped_at_creation: bool, } -impl BufferDescriptor { +impl BufferDescriptor { /// Takes a closure and maps the label of the buffer descriptor into another. #[must_use] - pub fn map_label(&self, fun: impl FnOnce(&L) -> K) -> BufferDescriptor { + pub fn map_label(&self, fun: impl FnOnce(&L) -> K) -> BufferDescriptor { BufferDescriptor { label: fun(&self.label), size: self.size, From 4bf1579c257863d25ae050d670e2b0821e71de40 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 16:16:06 -0400 Subject: [PATCH 03/33] WIP: refactor!: give `TextureViewDescriptor` a builder API From 77df9e29cb3608ef65d644e58dfb4c5642c862be Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 17:02:40 -0400 Subject: [PATCH 04/33] refactor: remove unnecessary `TextureDescriptor::view_formats` specs. --- examples/src/texture_arrays/mod.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index 00b90603fd7..c8275c9faa5 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -168,22 +168,18 @@ impl crate::framework::Example for Example { }; let red_texture = device.create_texture(&wgpu::TextureDescriptor { label: Some("red"), - view_formats: &[], ..texture_descriptor }); let green_texture = device.create_texture(&wgpu::TextureDescriptor { label: Some("green"), - view_formats: &[], ..texture_descriptor }); let blue_texture = device.create_texture(&wgpu::TextureDescriptor { label: Some("blue"), - view_formats: &[], ..texture_descriptor }); let white_texture = device.create_texture(&wgpu::TextureDescriptor { label: Some("white"), - view_formats: &[], ..texture_descriptor }); From 1fa77a9c8b69bead0e6d746874f6a731f77cb32d Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 17:03:45 -0400 Subject: [PATCH 05/33] refactor: replace manual `TextureViewDescriptor::default()` --- examples/src/texture_arrays/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index c8275c9faa5..da8b1be49dd 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -183,10 +183,10 @@ impl crate::framework::Example for Example { ..texture_descriptor }); - let red_texture_view = red_texture.create_view(&wgpu::TextureViewDescriptor::default()); - let green_texture_view = green_texture.create_view(&wgpu::TextureViewDescriptor::default()); - let blue_texture_view = blue_texture.create_view(&wgpu::TextureViewDescriptor::default()); - let white_texture_view = white_texture.create_view(&wgpu::TextureViewDescriptor::default()); + let red_texture_view = red_texture.create_view(&Default::default()); + let green_texture_view = green_texture.create_view(&Default::default()); + let blue_texture_view = blue_texture.create_view(&Default::default()); + let white_texture_view = white_texture.create_view(&Default::default()); queue.write_texture( red_texture.as_image_copy(), From 05e0b76f99795877362130240c6cf13116c38e04 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 16:04:44 -0400 Subject: [PATCH 06/33] refactor: replace manual `Extend3d::default()` --- benches/benches/computepass.rs | 12 ++---------- benches/benches/renderpass.rs | 12 ++---------- examples/src/texture_arrays/mod.rs | 2 +- tests/tests/encoder.rs | 6 +----- tests/tests/mem_leaks.rs | 6 +----- tests/tests/vertex_formats/mod.rs | 6 +----- tests/tests/vertex_indices/mod.rs | 6 +----- 7 files changed, 9 insertions(+), 41 deletions(-) diff --git a/benches/benches/computepass.rs b/benches/benches/computepass.rs index 2a5a9d3a04c..39a99cc2fff 100644 --- a/benches/benches/computepass.rs +++ b/benches/benches/computepass.rs @@ -130,11 +130,7 @@ impl ComputepassState { .device .create_texture(&wgpu::TextureDescriptor { label: Some(&format!("Texture {i}")), - size: wgpu::Extent3d { - width: 1, - height: 1, - depth_or_array_layers: 1, - }, + size: Default::default(), mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, @@ -156,11 +152,7 @@ impl ComputepassState { .device .create_texture(&wgpu::TextureDescriptor { label: Some(&format!("StorageTexture {i}")), - size: wgpu::Extent3d { - width: 1, - height: 1, - depth_or_array_layers: 1, - }, + size: Default::default(), mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index f8153df82b9..a22610e9f98 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -89,11 +89,7 @@ impl RenderpassState { .device .create_texture(&wgpu::TextureDescriptor { label: Some(&format!("Texture {i}")), - size: wgpu::Extent3d { - width: 1, - height: 1, - depth_or_array_layers: 1, - }, + size: Default::default(), mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, @@ -224,11 +220,7 @@ impl RenderpassState { .device .create_texture(&wgpu::TextureDescriptor { label: Some("Render Target"), - size: wgpu::Extent3d { - width: 1, - height: 1, - depth_or_array_layers: 1, - }, + size: Default::default(), mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index da8b1be49dd..0cb5d50f46d 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -157,7 +157,7 @@ impl crate::framework::Example for Example { let white_texture_data = create_texture_data(Color::White); let texture_descriptor = wgpu::TextureDescriptor { - size: wgpu::Extent3d::default(), + size: Default::default(), mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, diff --git a/tests/tests/encoder.rs b/tests/tests/encoder.rs index 0be5efb9010..6aa101ba74f 100644 --- a/tests/tests/encoder.rs +++ b/tests/tests/encoder.rs @@ -104,11 +104,7 @@ fn encoder_operations_fail_while_pass_alive(ctx: TestingContext) { let texture_desc = wgpu::TextureDescriptor { label: None, - size: wgpu::Extent3d { - width: 1, - height: 1, - depth_or_array_layers: 1, - }, + size: Default::default(), mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index 75de0776e87..eb81d285903 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -139,11 +139,7 @@ async fn draw_test_with_reports( &ctx.queue, &wgpu::TextureDescriptor { label: Some("dummy"), - size: wgpu::Extent3d { - width: 1, - height: 1, - depth_or_array_layers: 1, - }, + size: Default::default(), mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index e956455786a..6e6dd45215d 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -215,11 +215,7 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { &ctx.queue, &wgpu::TextureDescriptor { label: Some("dummy"), - size: wgpu::Extent3d { - width: 1, - height: 1, - depth_or_array_layers: 1, - }, + size: Default::default(), mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index 300a97eeb80..b0aae16ddd5 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -301,11 +301,7 @@ async fn vertex_index_common(ctx: TestingContext) { &ctx.queue, &wgpu::TextureDescriptor { label: Some("dummy"), - size: wgpu::Extent3d { - width: 1, - height: 1, - depth_or_array_layers: 1, - }, + size: Default::default(), mip_level_count: 1, sample_count: 1, dimension: wgpu::TextureDimension::D2, From 0bebbdfd3badd23f92f50aa669369ddd74ee98ef Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 15:33:45 -0400 Subject: [PATCH 07/33] WIP: refactor!: give `TextureDescriptor` a builder API TODO: unsquash removals of fields into next commit --- benches/benches/computepass.rs | 44 ++++--- benches/benches/renderpass.rs | 38 +++--- examples/src/bunnymark/mod.rs | 22 ++-- examples/src/conservative_raster/mod.rs | 34 +++--- examples/src/cube/mod.rs | 17 ++- examples/src/framework.rs | 32 ++--- examples/src/mipmap/mod.rs | 28 +++-- examples/src/msaa_line/mod.rs | 20 ++-- examples/src/render_to_texture/mod.rs | 30 ++--- examples/src/shadow/mod.rs | 44 ++++--- examples/src/skybox/mod.rs | 41 +++---- examples/src/stencil_triangles/mod.rs | 56 ++++----- examples/src/storage_texture/mod.rs | 30 ++--- examples/src/texture_arrays/mod.rs | 20 ++-- examples/src/timestamp_queries/mod.rs | 27 +++-- examples/src/water/mod.rs | 52 +++++---- tests/tests/bgra8unorm_storage.rs | 30 ++--- tests/tests/clear_texture.rs | 31 ++--- tests/tests/device.rs | 118 ++++++++++--------- tests/tests/encoder.rs | 50 ++++---- tests/tests/external_texture.rs | 36 +++--- tests/tests/float32_filterable.rs | 30 ++--- tests/tests/life_cycle.rs | 30 ++--- tests/tests/mem_leaks.rs | 20 ++-- tests/tests/nv12_texture/mod.rs | 122 ++++++++++---------- tests/tests/occlusion_query/mod.rs | 30 ++--- tests/tests/partially_bounded_arrays/mod.rs | 30 ++--- tests/tests/queue_transfer.rs | 30 ++--- tests/tests/regression/issue_3349.rs | 32 ++--- tests/tests/regression/issue_4485.rs | 30 ++--- tests/tests/regression/issue_4514.rs | 30 ++--- tests/tests/render_pass_ownership.rs | 21 ++-- tests/tests/resource_error.rs | 30 ++--- tests/tests/scissor_tests/mod.rs | 26 ++--- tests/tests/shader_primitive_index/mod.rs | 22 ++-- tests/tests/shader_view_format/mod.rs | 42 +++---- tests/tests/transfer.rs | 55 +++++---- tests/tests/vertex_formats/mod.rs | 20 ++-- tests/tests/vertex_indices/mod.rs | 20 ++-- tests/tests/write_texture.rs | 102 ++++++++-------- wgpu-types/Cargo.toml | 1 + wgpu-types/src/lib.rs | 15 ++- 42 files changed, 796 insertions(+), 742 deletions(-) diff --git a/benches/benches/computepass.rs b/benches/benches/computepass.rs index 39a99cc2fff..f93a6e80c95 100644 --- a/benches/benches/computepass.rs +++ b/benches/benches/computepass.rs @@ -126,18 +126,14 @@ impl ComputepassState { let mut texture_views = Vec::with_capacity(texture_count); for i in 0..texture_count { - let texture = device_state - .device - .create_texture(&wgpu::TextureDescriptor { - label: Some(&format!("Texture {i}")), - size: Default::default(), - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsages::TEXTURE_BINDING, - view_formats: &[], - }); + let texture = device_state.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(&*format!("Texture {i}")) + .size(Default::default()) + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .usage(wgpu::TextureUsages::TEXTURE_BINDING) + .build(), + ); texture_views.push(texture.create_view(&wgpu::TextureViewDescriptor { label: Some(&format!("Texture View {i}")), ..Default::default() @@ -148,18 +144,18 @@ impl ComputepassState { let mut storage_texture_views = Vec::with_capacity(storage_texture_count); for i in 0..storage_texture_count { - let texture = device_state - .device - .create_texture(&wgpu::TextureDescriptor { - label: Some(&format!("StorageTexture {i}")), - size: Default::default(), - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::R32Float, - usage: wgpu::TextureUsages::STORAGE_BINDING, - view_formats: &[], - }); + let texture = device_state.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(&*format!("StorageTexture {i}")) + .size(Default::default()) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::R32Float) + .usage(wgpu::TextureUsages::STORAGE_BINDING) + .view_formats(&[]) + .build(), + ); storage_texture_views.push(texture.create_view(&wgpu::TextureViewDescriptor { label: Some(&format!("StorageTexture View {i}")), ..Default::default() diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index a22610e9f98..f5bf54c0a59 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -85,18 +85,14 @@ impl RenderpassState { let mut texture_views = Vec::with_capacity(texture_count); for i in 0..texture_count { - let texture = device_state - .device - .create_texture(&wgpu::TextureDescriptor { - label: Some(&format!("Texture {i}")), - size: Default::default(), - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsages::TEXTURE_BINDING, - view_formats: &[], - }); + let texture = device_state.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(&*format!("Texture {i}")) + .size(Default::default()) + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .usage(wgpu::TextureUsages::TEXTURE_BINDING) + .build(), + ); texture_views.push(texture.create_view(&wgpu::TextureViewDescriptor { label: Some(&format!("Texture View {i}")), ..Default::default() @@ -218,16 +214,14 @@ impl RenderpassState { let render_target = device_state .device - .create_texture(&wgpu::TextureDescriptor { - label: Some("Render Target"), - size: Default::default(), - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }) + .create_texture( + &wgpu::TextureDescriptor::builder() + .label("Render Target") + .size(Default::default()) + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .build(), + ) .create_view(&wgpu::TextureViewDescriptor::default()); let mut bindless_bind_group = None; diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index a4ea8f5c6d0..ac36d818ad3 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -249,16 +249,18 @@ impl crate::framework::Example for Example { height: info.height, depth_or_array_layers: 1, }; - let texture = device.create_texture(&wgpu::TextureDescriptor { - label: None, - size, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING, - view_formats: &[], - }); + let texture = device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(size) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .usage(wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING) + .view_formats(&[]) + .build(), + ); queue.write_texture( texture.as_image_copy(), &buf, diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index ca0e9b7110a..589e67d778d 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -18,21 +18,25 @@ impl Example { bind_group_layout_upscale: &wgpu::BindGroupLayout, ) -> (wgpu::TextureView, wgpu::BindGroup) { let texture_view = device - .create_texture(&wgpu::TextureDescriptor { - label: Some("Low Resolution Target"), - size: wgpu::Extent3d { - width: (config.width / 16).max(1), - height: (config.height / 16).max(1), - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: RENDER_TARGET_FORMAT, - usage: wgpu::TextureUsages::TEXTURE_BINDING - | wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }) + .create_texture( + &wgpu::TextureDescriptor::builder() + .label("Low Resolution Target") + .size(wgpu::Extent3d { + width: (config.width / 16).max(1), + height: (config.height / 16).max(1), + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(RENDER_TARGET_FORMAT) + .usage( + wgpu::TextureUsages::TEXTURE_BINDING + | wgpu::TextureUsages::RENDER_ATTACHMENT, + ) + .view_formats(&[]) + .build(), + ) .create_view(&Default::default()); let sampler = device.create_sampler(&wgpu::SamplerDescriptor { diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index 13e050cdd08..4f46649f6e3 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -169,16 +169,13 @@ impl crate::framework::Example for Example { height: size, depth_or_array_layers: 1, }; - let texture = device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: texture_extent, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::R8Uint, - usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, - view_formats: &[], - }); + let texture = device.create_texture( + &wgpu::TextureDescriptor::builder() + .size(texture_extent) + .format(wgpu::TextureFormat::R8Uint) + .usage(wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST) + .build(), + ); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); queue.write_texture( texture.as_image_copy(), diff --git a/examples/src/framework.rs b/examples/src/framework.rs index ff86cc23570..c469eeed34d 100644 --- a/examples/src/framework.rs +++ b/examples/src/framework.rs @@ -548,20 +548,24 @@ impl From> } else { wgpu::TextureFormat::Rgba8Unorm }; - let dst_texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: Some("destination"), - size: wgpu::Extent3d { - width: params.width, - height: params.height, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC, - view_formats: &[], - }); + let dst_texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label("destination") + .size(wgpu::Extent3d { + width: params.width, + height: params.height, + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(format) + .usage( + wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC, + ) + .view_formats(&[]) + .build(), + ); let dst_view = dst_texture.create_view(&wgpu::TextureViewDescriptor::default()); diff --git a/examples/src/mipmap/mod.rs b/examples/src/mipmap/mod.rs index 817a6d62597..5493b7ad497 100644 --- a/examples/src/mipmap/mod.rs +++ b/examples/src/mipmap/mod.rs @@ -225,18 +225,22 @@ impl crate::framework::Example for Example { height: size, depth_or_array_layers: 1, }; - let texture = device.create_texture(&wgpu::TextureDescriptor { - size: texture_extent, - mip_level_count: MIP_LEVEL_COUNT, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: TEXTURE_FORMAT, - usage: wgpu::TextureUsages::TEXTURE_BINDING - | wgpu::TextureUsages::RENDER_ATTACHMENT - | wgpu::TextureUsages::COPY_DST, - label: None, - view_formats: &[], - }); + let texture = device.create_texture( + &wgpu::TextureDescriptor::builder() + .size(texture_extent) + .mip_level_count(MIP_LEVEL_COUNT) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(TEXTURE_FORMAT) + .usage( + wgpu::TextureUsages::TEXTURE_BINDING + | wgpu::TextureUsages::RENDER_ATTACHMENT + | wgpu::TextureUsages::COPY_DST, + ) + .label(None) + .view_formats(&[]) + .build(), + ); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); //Note: we could use queue.write_texture instead, and this is what other // examples do, but here we want to show another way to do this. diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index 1f49b90f4ac..7bbf2b56ef8 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -106,16 +106,16 @@ impl Example { height: config.height, depth_or_array_layers: 1, }; - let multisampled_frame_descriptor = &wgpu::TextureDescriptor { - size: multisampled_texture_extent, - mip_level_count: 1, - sample_count, - dimension: wgpu::TextureDimension::D2, - format: config.view_formats[0], - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - label: None, - view_formats: &[], - }; + let multisampled_frame_descriptor = &wgpu::TextureDescriptor::builder() + .size(multisampled_texture_extent) + .mip_level_count(1) + .sample_count(sample_count) + .dimension(wgpu::TextureDimension::D2) + .format(config.view_formats[0]) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .label(None) + .view_formats(&[]) + .build(); device .create_texture(multisampled_frame_descriptor) diff --git a/examples/src/render_to_texture/mod.rs b/examples/src/render_to_texture/mod.rs index 5295254986a..0a89c92025c 100644 --- a/examples/src/render_to_texture/mod.rs +++ b/examples/src/render_to_texture/mod.rs @@ -30,20 +30,22 @@ async fn run(_path: Option) { let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl")); - let render_target = device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: wgpu::Extent3d { - width: TEXTURE_DIMS.0 as u32, - height: TEXTURE_DIMS.1 as u32, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC, - view_formats: &[wgpu::TextureFormat::Rgba8UnormSrgb], - }); + let render_target = device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(wgpu::Extent3d { + width: TEXTURE_DIMS.0 as u32, + height: TEXTURE_DIMS.1 as u32, + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC) + .view_formats(&[wgpu::TextureFormat::Rgba8UnormSrgb]) + .build(), + ); let output_staging_buffer = device.create_buffer(&wgpu::BufferDescriptor { label: None, size: texture_data.capacity() as u64, diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index 44ad84a73ff..5da1379cbbf 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -182,20 +182,17 @@ impl Example { config: &wgpu::SurfaceConfiguration, device: &wgpu::Device, ) -> wgpu::TextureView { - let depth_texture = device.create_texture(&wgpu::TextureDescriptor { - size: wgpu::Extent3d { - width: config.width, - height: config.height, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: Self::DEPTH_FORMAT, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - label: None, - view_formats: &[], - }); + let depth_texture = device.create_texture( + &wgpu::TextureDescriptor::builder() + .size(wgpu::Extent3d { + width: config.width, + height: config.height, + depth_or_array_layers: 1, + }) + .format(Self::DEPTH_FORMAT) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .build(), + ); depth_texture.create_view(&wgpu::TextureViewDescriptor::default()) } @@ -375,16 +372,15 @@ impl crate::framework::Example for Example { ..Default::default() }); - let shadow_texture = device.create_texture(&wgpu::TextureDescriptor { - size: Self::SHADOW_SIZE, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: Self::SHADOW_FORMAT, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, - label: None, - view_formats: &[], - }); + let shadow_texture = device.create_texture( + &wgpu::TextureDescriptor::builder() + .size(Self::SHADOW_SIZE) + .format(Self::SHADOW_FORMAT) + .usage( + wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, + ) + .build(), + ); let shadow_view = shadow_texture.create_view(&wgpu::TextureViewDescriptor::default()); let mut shadow_target_views = (0..2) diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index 095a1e9fbb7..89e3a39803f 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -70,20 +70,17 @@ impl Example { config: &wgpu::SurfaceConfiguration, device: &wgpu::Device, ) -> wgpu::TextureView { - let depth_texture = device.create_texture(&wgpu::TextureDescriptor { - size: wgpu::Extent3d { - width: config.width, - height: config.height, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: Self::DEPTH_FORMAT, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - label: None, - view_formats: &[], - }); + let depth_texture = device.create_texture( + &wgpu::TextureDescriptor::builder() + .size(wgpu::Extent3d { + width: config.width, + height: config.height, + depth_or_array_layers: 1, + }) + .format(Self::DEPTH_FORMAT) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .build(), + ); depth_texture.create_view(&wgpu::TextureViewDescriptor::default()) } @@ -326,16 +323,12 @@ impl crate::framework::Example for Example { let texture = device.create_texture_with_data( queue, - &wgpu::TextureDescriptor { - size, - mip_level_count: header.level_count, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: skybox_format, - usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, - label: None, - view_formats: &[], - }, + &wgpu::TextureDescriptor::builder() + .size(size) + .mip_level_count(header.level_count) + .format(skybox_format) + .usage(wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST) + .build(), // KTX2 stores mip levels in mip major order. wgpu::util::TextureDataOrder::MipMajor, &image, diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index fcd37f813e8..34509a50bf2 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -141,20 +141,18 @@ impl crate::framework::Example for Example { cache: None, }); - let stencil_buffer = device.create_texture(&wgpu::TextureDescriptor { - label: Some("Stencil buffer"), - size: wgpu::Extent3d { - width: config.width, - height: config.height, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Stencil8, - view_formats: &[], - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - }); + let stencil_buffer = device.create_texture( + &wgpu::TextureDescriptor::builder() + .label("Stencil buffer") + .size(wgpu::Extent3d { + width: config.width, + height: config.height, + depth_or_array_layers: 1, + }) + .format(wgpu::TextureFormat::Stencil8) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .build(), + ); // Done Example { @@ -176,20 +174,22 @@ impl crate::framework::Example for Example { device: &wgpu::Device, _queue: &wgpu::Queue, ) { - self.stencil_buffer = device.create_texture(&wgpu::TextureDescriptor { - label: Some("Stencil buffer"), - size: wgpu::Extent3d { - width: config.width, - height: config.height, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Stencil8, - view_formats: &[], - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - }); + self.stencil_buffer = device.create_texture( + &wgpu::TextureDescriptor::builder() + .label("Stencil buffer") + .size(wgpu::Extent3d { + width: config.width, + height: config.height, + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Stencil8) + .view_formats(&[]) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .build(), + ); } fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) { diff --git a/examples/src/storage_texture/mod.rs b/examples/src/storage_texture/mod.rs index 56c8b2a6436..bea2c23bf0b 100644 --- a/examples/src/storage_texture/mod.rs +++ b/examples/src/storage_texture/mod.rs @@ -46,20 +46,22 @@ async fn run(_path: Option) { let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl")); - let storage_texture = device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: wgpu::Extent3d { - width: TEXTURE_DIMS.0 as u32, - height: TEXTURE_DIMS.1 as u32, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8Unorm, - usage: wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::COPY_SRC, - view_formats: &[], - }); + let storage_texture = device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(wgpu::Extent3d { + width: TEXTURE_DIMS.0 as u32, + height: TEXTURE_DIMS.1 as u32, + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8Unorm) + .usage(wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::COPY_SRC) + .view_formats(&[]) + .build(), + ); let storage_texture_view = storage_texture.create_view(&wgpu::TextureViewDescriptor::default()); let output_staging_buffer = device.create_buffer(&wgpu::BufferDescriptor { label: None, diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index 0cb5d50f46d..8f863b48fb4 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -156,16 +156,16 @@ impl crate::framework::Example for Example { let blue_texture_data = create_texture_data(Color::Blue); let white_texture_data = create_texture_data(Color::White); - let texture_descriptor = wgpu::TextureDescriptor { - size: Default::default(), - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, - label: None, - view_formats: &[], - }; + let texture_descriptor = wgpu::TextureDescriptor::builder() + .size(Default::default()) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .usage(wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST) + .label(None) + .view_formats(&[]) + .build(); let red_texture = device.create_texture(&wgpu::TextureDescriptor { label: Some("red"), ..texture_descriptor diff --git a/examples/src/timestamp_queries/mod.rs b/examples/src/timestamp_queries/mod.rs index 69f5c57dd63..cee4d5f9336 100644 --- a/examples/src/timestamp_queries/mod.rs +++ b/examples/src/timestamp_queries/mod.rs @@ -369,20 +369,19 @@ fn render_pass( multiview: None, cache: None, }); - let render_target = device.create_texture(&wgpu::TextureDescriptor { - label: Some("rendertarget"), - size: wgpu::Extent3d { - width: 512, - height: 512, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[format], - }); + let render_target = device.create_texture( + &wgpu::TextureDescriptor::builder() + .label("rendertarget") + .size(wgpu::Extent3d { + width: 512, + height: 512, + depth_or_array_layers: 1, + }) + .format(format) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .view_formats(&[format]) + .build(), + ); let render_target_view = render_target.create_view(&wgpu::TextureViewDescriptor::default()); let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index a60dc0279ea..dd20f665534 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -184,31 +184,35 @@ impl Example { depth_or_array_layers: 1, }; - let reflection_texture = device.create_texture(&wgpu::TextureDescriptor { - label: Some("Reflection Render Texture"), - size: texture_extent, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: config.view_formats[0], - usage: wgpu::TextureUsages::TEXTURE_BINDING - | wgpu::TextureUsages::COPY_DST - | wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }); + let reflection_texture = device.create_texture( + &wgpu::TextureDescriptor::builder() + .label("Reflection Render Texture") + .size(texture_extent) + .format(config.view_formats[0]) + .usage( + wgpu::TextureUsages::TEXTURE_BINDING + | wgpu::TextureUsages::COPY_DST + | wgpu::TextureUsages::RENDER_ATTACHMENT, + ) + .build(), + ); - let draw_depth_buffer = device.create_texture(&wgpu::TextureDescriptor { - label: Some("Depth Buffer"), - size: texture_extent, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Depth32Float, - usage: wgpu::TextureUsages::TEXTURE_BINDING - | wgpu::TextureUsages::COPY_DST - | wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }); + let draw_depth_buffer = device.create_texture( + &wgpu::TextureDescriptor::builder() + .label("Depth Buffer") + .size(texture_extent) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Depth32Float) + .usage( + wgpu::TextureUsages::TEXTURE_BINDING + | wgpu::TextureUsages::COPY_DST + | wgpu::TextureUsages::RENDER_ATTACHMENT, + ) + .view_formats(&[]) + .build(), + ); let color_sampler = device.create_sampler(&wgpu::SamplerDescriptor { label: Some("Color Sampler"), diff --git a/tests/tests/bgra8unorm_storage.rs b/tests/tests/bgra8unorm_storage.rs index 0859473b2f0..937d9360045 100644 --- a/tests/tests/bgra8unorm_storage.rs +++ b/tests/tests/bgra8unorm_storage.rs @@ -25,20 +25,22 @@ static BGRA8_UNORM_STORAGE: GpuTestConfiguration = GpuTestConfiguration::new() ) .run_async(|ctx| async move { let device = &ctx.device; - let texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: wgpu::Extent3d { - width: 256, - height: 256, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Bgra8Unorm, - usage: wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::COPY_SRC, - view_formats: &[], - }); + let texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(wgpu::Extent3d { + width: 256, + height: 256, + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Bgra8Unorm) + .usage(wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::COPY_SRC) + .view_formats(&[]) + .build(), + ); let view = texture.create_view(&wgpu::TextureViewDescriptor { label: None, diff --git a/tests/tests/clear_texture.rs b/tests/tests/clear_texture.rs index 484681130b4..bd981e3e5ad 100644 --- a/tests/tests/clear_texture.rs +++ b/tests/tests/clear_texture.rs @@ -223,21 +223,22 @@ async fn single_texture_clear_test( _ => wgpu::TextureUsages::empty(), }; - let texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: Some(&format!("texture {format:?}")), - size, - mip_level_count: if dimension == wgpu::TextureDimension::D1 { - 1 - } else { - // arbitrary value between 2 and max - 3 - }, - sample_count: 1, // multisampling is not supported for clear - dimension, - format, - usage: wgpu::TextureUsages::COPY_SRC | extra_usages, - view_formats: &[], - }); + let texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(&*format!("texture {format:?}")) + .size(size) + .mip_level_count(if dimension == wgpu::TextureDimension::D1 { + 1 + } else { + // arbitrary value between 2 and max + 3 + }) + .sample_count(1) // multisampling is not supported for clear + .dimension(dimension) + .format(format) + .usage(wgpu::TextureUsages::COPY_SRC | extra_usages) + .build(), + ); let mut encoder = ctx .device .create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 2774bfd524f..c6a8628d7c0 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -140,39 +140,45 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne height: 512, depth_or_array_layers: 1, }; - let texture_for_view = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: texture_extent, - mip_level_count: 2, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rg8Uint, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }); + let texture_for_view = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(texture_extent) + .mip_level_count(2) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rg8Uint) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .view_formats(&[]) + .build(), + ); let target_view = texture_for_view.create_view(&wgpu::TextureViewDescriptor::default()); - let texture_for_read = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: texture_extent, - mip_level_count: 2, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rg8Uint, - usage: wgpu::TextureUsages::COPY_SRC, - view_formats: &[], - }); + let texture_for_read = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(texture_extent) + .mip_level_count(2) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rg8Uint) + .usage(wgpu::TextureUsages::COPY_SRC) + .view_formats(&[]) + .build(), + ); - let texture_for_write = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: texture_extent, - mip_level_count: 2, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rg8Uint, - usage: wgpu::TextureUsages::COPY_DST, - view_formats: &[], - }); + let texture_for_write = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(texture_extent) + .mip_level_count(2) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rg8Uint) + .usage(wgpu::TextureUsages::COPY_DST) + .view_formats(&[]) + .build(), + ); // Create some buffers. let buffer_source = ctx.device.create_buffer(&wgpu::BufferDescriptor { @@ -298,20 +304,22 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne fail( &ctx.device, || { - let _ = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: wgpu::Extent3d { - width: 512, - height: 512, - depth_or_array_layers: 1, - }, - mip_level_count: 2, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rg8Uint, - usage: wgpu::TextureUsages::COPY_SRC, - view_formats: &[], - }); + let _ = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(wgpu::Extent3d { + width: 512, + height: 512, + depth_or_array_layers: 1, + }) + .mip_level_count(2) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rg8Uint) + .usage(wgpu::TextureUsages::COPY_SRC) + .view_formats(&[]) + .build(), + ); }, Some("device with '' label is invalid"), ); @@ -852,16 +860,18 @@ static DEVICE_DESTROY_THEN_BUFFER_CLEANUP: GpuTestConfiguration = GpuTestConfigu height: 512, depth_or_array_layers: 1, }; - let _texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: texture_extent, - mip_level_count: 2, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rg8Uint, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }); + let _texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(texture_extent) + .mip_level_count(2) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rg8Uint) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .view_formats(&[]) + .build(), + ); // Destroy the device. ctx.device.destroy(); diff --git a/tests/tests/encoder.rs b/tests/tests/encoder.rs index 6aa101ba74f..3f41b8060e5 100644 --- a/tests/tests/encoder.rs +++ b/tests/tests/encoder.rs @@ -33,20 +33,22 @@ static DROP_ENCODER_AFTER_ERROR: GpuTestConfiguration = GpuTestConfiguration::ne .device .create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); - let target_tex = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: wgpu::Extent3d { - width: 100, - height: 100, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::R8Unorm, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }); + let target_tex = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(wgpu::Extent3d { + width: 100, + height: 100, + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::R8Unorm) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .view_formats(&[]) + .build(), + ); let target_view = target_tex.create_view(&wgpu::TextureViewDescriptor::default()); let mut renderpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { @@ -102,16 +104,16 @@ fn encoder_operations_fail_while_pass_alive(ctx: TestingContext) { usage: wgpu::BufferUsages::COPY_DST, }); - let texture_desc = wgpu::TextureDescriptor { - label: None, - size: Default::default(), - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8Unorm, - usage: wgpu::TextureUsages::COPY_DST, - view_formats: &[], - }; + let texture_desc = wgpu::TextureDescriptor::builder() + .label(None) + .size(Default::default()) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8Unorm) + .usage(wgpu::TextureUsages::COPY_DST) + .view_formats(&[]) + .build(); let texture_dst = ctx.device.create_texture(&texture_desc); let texture_src = ctx.device.create_texture(&wgpu::TextureDescriptor { usage: wgpu::TextureUsages::COPY_SRC, diff --git a/tests/tests/external_texture.rs b/tests/tests/external_texture.rs index 6dba884a338..cf1f49ed53d 100644 --- a/tests/tests/external_texture.rs +++ b/tests/tests/external_texture.rs @@ -247,22 +247,26 @@ static IMAGE_BITMAP_IMPORT: GpuTestConfiguration = } } - let texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: Some("import dest"), - size: wgpu::Extent3d { - width: dest_width, - height: 3, - depth_or_array_layers: dest_layers, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT - | wgpu::TextureUsages::COPY_DST - | wgpu::TextureUsages::COPY_SRC, - view_formats: &[], - }); + let texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(Some("import dest")) + .size(wgpu::Extent3d { + width: dest_width, + height: 3, + depth_or_array_layers: dest_layers, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .usage( + wgpu::TextureUsages::RENDER_ATTACHMENT + | wgpu::TextureUsages::COPY_DST + | wgpu::TextureUsages::COPY_SRC, + ) + .view_formats(&[]) + .build(), + ); fail_if( &ctx.device, diff --git a/tests/tests/float32_filterable.rs b/tests/tests/float32_filterable.rs index 5376f924d17..acb5e989d85 100644 --- a/tests/tests/float32_filterable.rs +++ b/tests/tests/float32_filterable.rs @@ -3,20 +3,22 @@ use wgpu_test::{fail, gpu_test, GpuTestConfiguration, TestParameters}; fn create_texture_binding(device: &wgpu::Device, format: wgpu::TextureFormat, filterable: bool) { - let texture = device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: wgpu::Extent3d { - width: 256, - height: 256, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format, - usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, - view_formats: &[], - }); + let texture = device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(wgpu::Extent3d { + width: 256, + height: 256, + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(format) + .usage(wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST) + .view_formats(&[]) + .build(), + ); let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); diff --git a/tests/tests/life_cycle.rs b/tests/tests/life_cycle.rs index d8d21940c88..ea6b56533d6 100644 --- a/tests/tests/life_cycle.rs +++ b/tests/tests/life_cycle.rs @@ -80,20 +80,22 @@ static BUFFER_DESTROY: GpuTestConfiguration = #[gpu_test] static TEXTURE_DESTROY: GpuTestConfiguration = GpuTestConfiguration::new().run_async(|ctx| async move { - let texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: wgpu::Extent3d { - width: 128, - height: 128, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, // multisampling is not supported for clear - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8Snorm, - usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING, - view_formats: &[], - }); + let texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(wgpu::Extent3d { + width: 128, + height: 128, + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) // multisampling is not supported for clear + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8Snorm) + .usage(wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING) + .view_formats(&[]) + .build(), + ); texture.destroy(); diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index eb81d285903..c63882948cf 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -137,16 +137,16 @@ async fn draw_test_with_reports( let texture = ctx.device.create_texture_with_data( &ctx.queue, - &wgpu::TextureDescriptor { - label: Some("dummy"), - size: Default::default(), - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8Unorm, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST, - view_formats: &[], - }, + &wgpu::TextureDescriptor::builder() + .label("dummy") + .size(Default::default()) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8Unorm) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST) + .view_formats(&[]) + .build(), wgpu::util::TextureDataOrder::LayerMajor, &[0, 0, 0, 1], ); diff --git a/tests/tests/nv12_texture/mod.rs b/tests/tests/nv12_texture/mod.rs index 6ded163a3a4..d7677c4519b 100644 --- a/tests/tests/nv12_texture/mod.rs +++ b/tests/tests/nv12_texture/mod.rs @@ -44,16 +44,13 @@ static NV12_TEXTURE_CREATION_SAMPLING: GpuTestConfiguration = GpuTestConfigurati cache: None, }); - let tex = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - dimension: wgpu::TextureDimension::D2, - size, - format: wgpu::TextureFormat::NV12, - usage: wgpu::TextureUsages::TEXTURE_BINDING, - mip_level_count: 1, - sample_count: 1, - view_formats: &[], - }); + let tex = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .size(size) + .format(wgpu::TextureFormat::NV12) + .usage(wgpu::TextureUsages::TEXTURE_BINDING) + .build(), + ); let y_view = tex.create_view(&wgpu::TextureViewDescriptor { format: Some(wgpu::TextureFormat::R8Unorm), aspect: wgpu::TextureAspect::Plane0, @@ -88,16 +85,13 @@ static NV12_TEXTURE_CREATION_SAMPLING: GpuTestConfiguration = GpuTestConfigurati ], }); - let target_tex = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: target_format, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }); + let target_tex = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .size(size) + .format(target_format) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .build(), + ); let target_view = target_tex.create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = ctx @@ -131,16 +125,18 @@ static NV12_TEXTURE_VIEW_PLANE_ON_NON_PLANAR_FORMAT: GpuTestConfiguration = height: 256, depth_or_array_layers: 1, }; - let tex = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - dimension: wgpu::TextureDimension::D2, - size, - format: wgpu::TextureFormat::R8Unorm, - usage: wgpu::TextureUsages::TEXTURE_BINDING, - mip_level_count: 1, - sample_count: 1, - view_formats: &[], - }); + let tex = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .dimension(wgpu::TextureDimension::D2) + .size(size) + .format(wgpu::TextureFormat::R8Unorm) + .usage(wgpu::TextureUsages::TEXTURE_BINDING) + .mip_level_count(1) + .sample_count(1) + .view_formats(&[]) + .build(), + ); fail( &ctx.device, || { @@ -162,16 +158,18 @@ static NV12_TEXTURE_VIEW_PLANE_OUT_OF_BOUNDS: GpuTestConfiguration = GpuTestConf height: 256, depth_or_array_layers: 1, }; - let tex = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - dimension: wgpu::TextureDimension::D2, - size, - format: wgpu::TextureFormat::NV12, - usage: wgpu::TextureUsages::TEXTURE_BINDING, - mip_level_count: 1, - sample_count: 1, - view_formats: &[], - }); + let tex = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .dimension(wgpu::TextureDimension::D2) + .size(size) + .format(wgpu::TextureFormat::NV12) + .usage(wgpu::TextureUsages::TEXTURE_BINDING) + .mip_level_count(1) + .sample_count(1) + .view_formats(&[]) + .build(), + ); fail( &ctx.device, || { @@ -194,16 +192,18 @@ static NV12_TEXTURE_BAD_FORMAT_VIEW_PLANE: GpuTestConfiguration = GpuTestConfigu height: 256, depth_or_array_layers: 1, }; - let tex = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - dimension: wgpu::TextureDimension::D2, - size, - format: wgpu::TextureFormat::NV12, - usage: wgpu::TextureUsages::TEXTURE_BINDING, - mip_level_count: 1, - sample_count: 1, - view_formats: &[], - }); + let tex = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .dimension(wgpu::TextureDimension::D2) + .size(size) + .format(wgpu::TextureFormat::NV12) + .usage(wgpu::TextureUsages::TEXTURE_BINDING) + .mip_level_count(1) + .sample_count(1) + .view_formats(&[]) + .build(), + ); fail( &ctx.device, || { @@ -230,16 +230,18 @@ static NV12_TEXTURE_BAD_SIZE: GpuTestConfiguration = GpuTestConfiguration::new() fail( &ctx.device, || { - let _ = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - dimension: wgpu::TextureDimension::D2, - size, - format: wgpu::TextureFormat::NV12, - usage: wgpu::TextureUsages::TEXTURE_BINDING, - mip_level_count: 1, - sample_count: 1, - view_formats: &[], - }); + let _ = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .dimension(wgpu::TextureDimension::D2) + .size(size) + .format(wgpu::TextureFormat::NV12) + .usage(wgpu::TextureUsages::TEXTURE_BINDING) + .mip_level_count(1) + .sample_count(1) + .view_formats(&[]) + .build(), + ); }, Some("width 255 is not a multiple of nv12's width multiple requirement"), ); diff --git a/tests/tests/occlusion_query/mod.rs b/tests/tests/occlusion_query/mod.rs index 2cedab0299e..e3099da5f4d 100644 --- a/tests/tests/occlusion_query/mod.rs +++ b/tests/tests/occlusion_query/mod.rs @@ -6,20 +6,22 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new() .parameters(TestParameters::default().expect_fail(FailureCase::webgl2())) .run_async(|ctx| async move { // Create depth texture - let depth_texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: Some("Depth texture"), - size: wgpu::Extent3d { - width: 64, - height: 64, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Depth32Float, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }); + let depth_texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label("Depth texture") + .size(wgpu::Extent3d { + width: 64, + height: 64, + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Depth32Float) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .view_formats(&[]) + .build(), + ); let depth_texture_view = depth_texture.create_view(&wgpu::TextureViewDescriptor::default()); // Setup pipeline using a simple shader with hardcoded vertices diff --git a/tests/tests/partially_bounded_arrays/mod.rs b/tests/tests/partially_bounded_arrays/mod.rs index 669c13c5113..870bc0e902e 100644 --- a/tests/tests/partially_bounded_arrays/mod.rs +++ b/tests/tests/partially_bounded_arrays/mod.rs @@ -22,19 +22,23 @@ static PARTIALLY_BOUNDED_ARRAY: GpuTestConfiguration = GpuTestConfiguration::new height: 1, depth_or_array_layers: 1, }; - let storage_texture = device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: texture_extent, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba32Float, - usage: wgpu::TextureUsages::TEXTURE_BINDING - | wgpu::TextureUsages::COPY_DST - | wgpu::TextureUsages::STORAGE_BINDING - | wgpu::TextureUsages::COPY_SRC, - view_formats: &[], - }); + let storage_texture = device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(texture_extent) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba32Float) + .usage( + wgpu::TextureUsages::TEXTURE_BINDING + | wgpu::TextureUsages::COPY_DST + | wgpu::TextureUsages::STORAGE_BINDING + | wgpu::TextureUsages::COPY_SRC, + ) + .view_formats(&[]) + .build(), + ); let texture_view = storage_texture.create_view(&wgpu::TextureViewDescriptor::default()); diff --git a/tests/tests/queue_transfer.rs b/tests/tests/queue_transfer.rs index 6f816374cbc..99b72c250cf 100644 --- a/tests/tests/queue_transfer.rs +++ b/tests/tests/queue_transfer.rs @@ -5,20 +5,22 @@ use wgpu_test::{fail, gpu_test, GpuTestConfiguration}; #[gpu_test] static QUEUE_WRITE_TEXTURE_OVERFLOW: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(|ctx| { - let texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: wgpu::Extent3d { - width: 146, - height: 25, - depth_or_array_layers: 192, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba32Float, - usage: wgpu::TextureUsages::COPY_DST, - view_formats: &[], - }); + let texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(wgpu::Extent3d { + width: 146, + height: 25, + depth_or_array_layers: 192, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba32Float) + .usage(wgpu::TextureUsages::COPY_DST) + .view_formats(&[]) + .build(), + ); let data = vec![255; 128]; diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index 21929bd9b7a..040e9f3a378 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -122,21 +122,23 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { cache: None, }); - let texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: Some("texture"), - size: wgpu::Extent3d { - width: 2, - height: 2, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - // Important: NOT srgb. - format: wgpu::TextureFormat::Rgba8Unorm, - usage: wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }); + let texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(Some("texture")) + .size(wgpu::Extent3d { + width: 2, + height: 2, + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + // Important: NOT srgb. + .format(wgpu::TextureFormat::Rgba8Unorm) + .usage(wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT) + .view_formats(&[]) + .build(), + ); let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); diff --git a/tests/tests/regression/issue_4485.rs b/tests/tests/regression/issue_4485.rs index 4944afe49f0..c74c2e75ab2 100644 --- a/tests/tests/regression/issue_4485.rs +++ b/tests/tests/regression/issue_4485.rs @@ -18,20 +18,22 @@ async fn test_impl(ctx: &TestingContext) { const TEXTURE_WIDTH: u32 = 2; const BUFFER_SIZE: usize = (TEXTURE_WIDTH * TEXTURE_HEIGHT * 4) as usize; - let texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: Some("Offscreen texture"), - size: wgpu::Extent3d { - width: TEXTURE_WIDTH, - height: TEXTURE_HEIGHT, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8Unorm, - usage: wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }); + let texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(Some("Offscreen texture")) + .size(wgpu::Extent3d { + width: TEXTURE_WIDTH, + height: TEXTURE_HEIGHT, + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8Unorm) + .usage(wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT) + .view_formats(&[]) + .build(), + ); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); let shader = ctx diff --git a/tests/tests/regression/issue_4514.rs b/tests/tests/regression/issue_4514.rs index b3609ff9adb..71dc3b81370 100644 --- a/tests/tests/regression/issue_4514.rs +++ b/tests/tests/regression/issue_4514.rs @@ -18,20 +18,22 @@ async fn test_impl(ctx: &TestingContext) { const TEXTURE_WIDTH: u32 = 2; const BUFFER_SIZE: usize = (TEXTURE_WIDTH * TEXTURE_HEIGHT * 4) as usize; - let texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: Some("Offscreen texture"), - size: wgpu::Extent3d { - width: TEXTURE_WIDTH, - height: TEXTURE_HEIGHT, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8Unorm, - usage: wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }); + let texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(Some("Offscreen texture")) + .size(wgpu::Extent3d { + width: TEXTURE_WIDTH, + height: TEXTURE_HEIGHT, + depth_or_array_layers: 1, + }) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8Unorm) + .usage(wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT) + .view_formats(&[]) + .build(), + ); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); let shader = ctx diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index 7c41c859169..d06ee6f1c87 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -454,17 +454,16 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { }; let target_msaa = 4; let target_format = wgpu::TextureFormat::Bgra8UnormSrgb; - - let target_desc = wgpu::TextureDescriptor { - label: Some("target_tex"), - size: target_size, - mip_level_count: 1, - sample_count: target_msaa, - dimension: wgpu::TextureDimension::D2, - format: target_format, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[target_format], - }; + let target_formats = [target_format]; + + let target_desc = wgpu::TextureDescriptor::builder() + .label("target_tex") + .size(target_size) + .sample_count(target_msaa) + .format(target_format) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) + .view_formats(&target_formats) + .build(); let target_tex = ctx.device.create_texture(&target_desc); let target_tex_resolve = ctx.device.create_texture(&wgpu::TextureDescriptor { label: Some("target_resolve"), diff --git a/tests/tests/resource_error.rs b/tests/tests/resource_error.rs index d071053ebd1..884c240ea69 100644 --- a/tests/tests/resource_error.rs +++ b/tests/tests/resource_error.rs @@ -36,20 +36,22 @@ static BAD_TEXTURE: GpuTestConfiguration = GpuTestConfiguration::new().run_sync( let texture = fail( &ctx.device, || { - ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: wgpu::Extent3d { - width: 0, - height: 12345678, - depth_or_array_layers: 9001, - }, - mip_level_count: 2000, - sample_count: 27, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8UnormSrgb, - usage: wgpu::TextureUsages::all(), - view_formats: &[], - }) + ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(wgpu::Extent3d { + width: 0, + height: 12345678, + depth_or_array_layers: 9001, + }) + .mip_level_count(2000) + .sample_count(27) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .usage(wgpu::TextureUsages::all()) + .view_formats(&[]) + .build(), + ) }, Some("dimension x is zero"), ); diff --git a/tests/tests/scissor_tests/mod.rs b/tests/tests/scissor_tests/mod.rs index 583be021f30..e96e0da20ac 100644 --- a/tests/tests/scissor_tests/mod.rs +++ b/tests/tests/scissor_tests/mod.rs @@ -16,20 +16,18 @@ async fn scissor_test_impl( scissor_rect: Rect, expected_data: [u8; BUFFER_SIZE], ) { - let texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: Some("Offscreen texture"), - size: wgpu::Extent3d { - width: TEXTURE_WIDTH, - height: TEXTURE_HEIGHT, - depth_or_array_layers: 1, - }, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8Unorm, - usage: wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT, - view_formats: &[], - }); + let texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(Some("Offscreen texture")) + .size(wgpu::Extent3d { + width: TEXTURE_WIDTH, + height: TEXTURE_HEIGHT, + depth_or_array_layers: 1, + }) + .format(wgpu::TextureFormat::Rgba8Unorm) + .usage(wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT) + .build(), + ); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); let shader = ctx diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index 10708a24a20..66bee9cbbdf 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -157,16 +157,18 @@ async fn pulling_common( height, depth_or_array_layers: 1, }; - let color_texture = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size: texture_size, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8Unorm, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC, - view_formats: &[], - }); + let color_texture = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(texture_size) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8Unorm) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC) + .view_formats(&[]) + .build(), + ); let color_view = color_texture.create_view(&wgpu::TextureViewDescriptor::default()); let readback_buffer = wgpu_test::image::ReadbackBuffers::new(&ctx.device, &color_texture); diff --git a/tests/tests/shader_view_format/mod.rs b/tests/tests/shader_view_format/mod.rs index b2bc0426ebd..d197b7b9090 100644 --- a/tests/tests/shader_view_format/mod.rs +++ b/tests/tests/shader_view_format/mod.rs @@ -68,16 +68,16 @@ async fn reinterpret( ) { let tex = ctx.device.create_texture_with_data( &ctx.queue, - &wgpu::TextureDescriptor { - label: None, - dimension: wgpu::TextureDimension::D2, - size, - format: src_format, - usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING, - mip_level_count: 1, - sample_count: 1, - view_formats: &[reinterpret_to], - }, + &wgpu::TextureDescriptor::builder() + .label(None) + .dimension(wgpu::TextureDimension::D2) + .size(size) + .format(src_format) + .usage(wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING) + .mip_level_count(1) + .sample_count(1) + .view_formats(&[reinterpret_to]) + .build(), wgpu::util::TextureDataOrder::LayerMajor, bytemuck::cast_slice(src_data), ); @@ -121,16 +121,18 @@ async fn reinterpret( label: None, }); - let target_tex = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - size, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: src_format, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC, - view_formats: &[], - }); + let target_tex = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .size(size) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(src_format) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC) + .view_formats(&[]) + .build(), + ); let target_view = target_tex.create_view(&wgpu::TextureViewDescriptor::default()); let mut encoder = ctx diff --git a/tests/tests/transfer.rs b/tests/tests/transfer.rs index 3408fe2e833..582602c5656 100644 --- a/tests/tests/transfer.rs +++ b/tests/tests/transfer.rs @@ -6,34 +6,33 @@ static COPY_OVERFLOW_Z: GpuTestConfiguration = GpuTestConfiguration::new().run_s .device .create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); - let t1 = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - dimension: wgpu::TextureDimension::D2, - size: wgpu::Extent3d { - width: 256, - height: 256, - depth_or_array_layers: 1, - }, - format: wgpu::TextureFormat::Rgba8Uint, - usage: wgpu::TextureUsages::COPY_DST, - mip_level_count: 1, - sample_count: 1, - view_formats: &[], - }); - let t2 = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - dimension: wgpu::TextureDimension::D2, - size: wgpu::Extent3d { - width: 256, - height: 256, - depth_or_array_layers: 1, - }, - format: wgpu::TextureFormat::Rgba8Uint, - usage: wgpu::TextureUsages::COPY_DST, - mip_level_count: 1, - sample_count: 1, - view_formats: &[], - }); + let t1 = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .dimension(wgpu::TextureDimension::D2) + .size(wgpu::Extent3d { + width: 256, + height: 256, + depth_or_array_layers: 1, + }) + .format(wgpu::TextureFormat::Rgba8Uint) + .usage(wgpu::TextureUsages::COPY_DST) + .mip_level_count(1) + .sample_count(1) + .view_formats(&[]) + .build(), + ); + let t2 = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .size(wgpu::Extent3d { + width: 256, + height: 256, + depth_or_array_layers: 1, + }) + .format(wgpu::TextureFormat::Rgba8Uint) + .usage(wgpu::TextureUsages::COPY_DST) + .build(), + ); fail( &ctx.device, diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 6e6dd45215d..6e55340b38d 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -213,16 +213,16 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { .device .create_texture_with_data( &ctx.queue, - &wgpu::TextureDescriptor { - label: Some("dummy"), - size: Default::default(), - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8Unorm, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST, - view_formats: &[], - }, + &wgpu::TextureDescriptor::builder() + .label("dummy") + .size(Default::default()) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8Unorm) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST) + .view_formats(&[]) + .build(), wgpu::util::TextureDataOrder::LayerMajor, &[0, 0, 0, 1], ) diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index b0aae16ddd5..fa6aff78f63 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -299,16 +299,16 @@ async fn vertex_index_common(ctx: TestingContext) { .device .create_texture_with_data( &ctx.queue, - &wgpu::TextureDescriptor { - label: Some("dummy"), - size: Default::default(), - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, - format: wgpu::TextureFormat::Rgba8Unorm, - usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST, - view_formats: &[], - }, + &wgpu::TextureDescriptor::builder() + .label("dummy") + .size(Default::default()) + .mip_level_count(1) + .sample_count(1) + .dimension(wgpu::TextureDimension::D2) + .format(wgpu::TextureFormat::Rgba8Unorm) + .usage(wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST) + .view_formats(&[]) + .build(), wgpu::util::TextureDataOrder::LayerMajor, &[0, 0, 0, 1], ) diff --git a/tests/tests/write_texture.rs b/tests/tests/write_texture.rs index fbb0485918a..87f590b915e 100644 --- a/tests/tests/write_texture.rs +++ b/tests/tests/write_texture.rs @@ -7,22 +7,26 @@ static WRITE_TEXTURE_SUBSET_2D: GpuTestConfiguration = GpuTestConfiguration::new().run_async(|ctx| async move { let size = 256; - let tex = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - dimension: wgpu::TextureDimension::D2, - size: wgpu::Extent3d { - width: size, - height: size, - depth_or_array_layers: 1, - }, - format: wgpu::TextureFormat::R8Uint, - usage: wgpu::TextureUsages::COPY_DST - | wgpu::TextureUsages::COPY_SRC - | wgpu::TextureUsages::TEXTURE_BINDING, - mip_level_count: 1, - sample_count: 1, - view_formats: &[], - }); + let tex = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .dimension(wgpu::TextureDimension::D2) + .size(wgpu::Extent3d { + width: size, + height: size, + depth_or_array_layers: 1, + }) + .format(wgpu::TextureFormat::R8Uint) + .usage( + wgpu::TextureUsages::COPY_DST + | wgpu::TextureUsages::COPY_SRC + | wgpu::TextureUsages::TEXTURE_BINDING, + ) + .mip_level_count(1) + .sample_count(1) + .view_formats(&[]) + .build(), + ); let data = vec![1u8; size as usize * 2]; // Write the first two rows ctx.queue.write_texture( @@ -102,22 +106,26 @@ static WRITE_TEXTURE_SUBSET_3D: GpuTestConfiguration = GpuTestConfiguration::new().run_async(|ctx| async move { let size = 256; let depth = 4; - let tex = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - dimension: wgpu::TextureDimension::D3, - size: wgpu::Extent3d { - width: size, - height: size, - depth_or_array_layers: depth, - }, - format: wgpu::TextureFormat::R8Uint, - usage: wgpu::TextureUsages::COPY_DST - | wgpu::TextureUsages::COPY_SRC - | wgpu::TextureUsages::TEXTURE_BINDING, - mip_level_count: 1, - sample_count: 1, - view_formats: &[], - }); + let tex = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .dimension(wgpu::TextureDimension::D3) + .size(wgpu::Extent3d { + width: size, + height: size, + depth_or_array_layers: depth, + }) + .format(wgpu::TextureFormat::R8Uint) + .usage( + wgpu::TextureUsages::COPY_DST + | wgpu::TextureUsages::COPY_SRC + | wgpu::TextureUsages::TEXTURE_BINDING, + ) + .mip_level_count(1) + .sample_count(1) + .view_formats(&[]) + .build(), + ); let data = vec![1u8; (size * size) as usize * 2]; // Write the first two slices ctx.queue.write_texture( @@ -197,20 +205,22 @@ static WRITE_TEXTURE_NO_OOB: GpuTestConfiguration = GpuTestConfiguration::new().run_async(|ctx| async move { let size = 256; - let tex = ctx.device.create_texture(&wgpu::TextureDescriptor { - label: None, - dimension: wgpu::TextureDimension::D2, - size: wgpu::Extent3d { - width: size, - height: size, - depth_or_array_layers: 1, - }, - format: wgpu::TextureFormat::R8Uint, - usage: wgpu::TextureUsages::COPY_DST, - mip_level_count: 1, - sample_count: 1, - view_formats: &[], - }); + let tex = ctx.device.create_texture( + &wgpu::TextureDescriptor::builder() + .label(None) + .dimension(wgpu::TextureDimension::D2) + .size(wgpu::Extent3d { + width: size, + height: size, + depth_or_array_layers: 1, + }) + .format(wgpu::TextureFormat::R8Uint) + .usage(wgpu::TextureUsages::COPY_DST) + .mip_level_count(1) + .sample_count(1) + .view_formats(&[]) + .build(), + ); let data = vec![1u8; size as usize * 2 + 100]; // check that we don't attempt to copy OOB internally by adding 100 bytes here ctx.queue.write_texture( wgpu::ImageCopyTexture { diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml index e79ae330e55..beb42148feb 100644 --- a/wgpu-types/Cargo.toml +++ b/wgpu-types/Cargo.toml @@ -36,6 +36,7 @@ counters = [] [dependencies] bitflags.workspace = true +bon.workspace = true serde = { workspace = true, features = ["derive"], optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index c6362e22d26..c9376a06f4d 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -6059,20 +6059,24 @@ fn test_max_mips() { /// Corresponds to [WebGPU `GPUTextureDescriptor`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gputexturedescriptor). #[repr(C)] -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(bon::Builder, Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -pub struct TextureDescriptor { +pub struct TextureDescriptor { /// Debug label of the texture. This will show up in graphics debuggers for easy identification. + #[builder(default, into)] pub label: L, /// Size of the texture. All components must be greater than zero. For a /// regular 1D/2D texture, the unused sizes will be 1. For 2DArray textures, /// Z is the number of 2D textures in that array. pub size: Extent3d, /// Mip count of texture. For a texture with no extra mips, this must be 1. + #[builder(default = 1)] pub mip_level_count: u32, /// Sample count of texture. If this is not 1, texture must have [`BindingType::Texture::multisampled`] set to true. + #[builder(default = 1)] pub sample_count: u32, /// Dimensions of the texture. + #[builder(default = TextureDimension::D2)] pub dimension: TextureDimension, /// Format of the texture. pub format: TextureFormat, @@ -6083,13 +6087,14 @@ pub struct TextureDescriptor { /// View formats of the same format as the texture are always allowed. /// /// Note: currently, only the srgb-ness is allowed to change. (ex: Rgba8Unorm texture + Rgba8UnormSrgb view) + #[builder(default)] pub view_formats: V, } -impl TextureDescriptor { +impl TextureDescriptor { /// Takes a closure and maps the label of the texture descriptor into another. #[must_use] - pub fn map_label(&self, fun: impl FnOnce(&L) -> K) -> TextureDescriptor + pub fn map_label(&self, fun: impl FnOnce(&L) -> K) -> TextureDescriptor where V: Clone, { @@ -6107,7 +6112,7 @@ impl TextureDescriptor { /// Maps the label and view_formats of the texture descriptor into another. #[must_use] - pub fn map_label_and_view_formats( + pub fn map_label_and_view_formats( &self, l_fun: impl FnOnce(&L) -> K, v_fun: impl FnOnce(V) -> M, From 3435f9d65277e6e1b6be29675aec709889ac36f9 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 16:44:32 -0400 Subject: [PATCH 08/33] WIP: refactor!: remove unnecessary fields in `TextureDescriptor` builder usage --- benches/benches/computepass.rs | 4 ---- examples/src/bunnymark/mod.rs | 5 ----- examples/src/conservative_raster/mod.rs | 4 ---- examples/src/framework.rs | 4 ---- examples/src/mipmap/mod.rs | 4 ---- examples/src/msaa_line/mod.rs | 4 ---- examples/src/render_to_texture/mod.rs | 4 ---- examples/src/stencil_triangles/mod.rs | 4 ---- examples/src/storage_texture/mod.rs | 5 ----- examples/src/texture_arrays/mod.rs | 5 ----- tests/tests/bgra8unorm_storage.rs | 5 ----- tests/tests/device.rs | 20 -------------------- tests/tests/encoder.rs | 10 ---------- tests/tests/external_texture.rs | 4 ---- tests/tests/float32_filterable.rs | 5 ----- tests/tests/life_cycle.rs | 4 ---- tests/tests/mem_leaks.rs | 4 ---- tests/tests/nv12_texture/mod.rs | 20 -------------------- tests/tests/occlusion_query/mod.rs | 4 ---- tests/tests/partially_bounded_arrays/mod.rs | 5 ----- tests/tests/queue_transfer.rs | 5 ----- tests/tests/regression/issue_3349.rs | 4 ---- tests/tests/regression/issue_4485.rs | 4 ---- tests/tests/regression/issue_4514.rs | 4 ---- tests/tests/resource_error.rs | 2 -- tests/tests/shader_primitive_index/mod.rs | 5 ----- tests/tests/shader_view_format/mod.rs | 9 --------- tests/tests/transfer.rs | 5 ----- tests/tests/vertex_formats/mod.rs | 4 ---- tests/tests/vertex_indices/mod.rs | 4 ---- tests/tests/write_texture.rs | 14 -------------- 31 files changed, 184 deletions(-) diff --git a/benches/benches/computepass.rs b/benches/benches/computepass.rs index f93a6e80c95..58f1b2b0d76 100644 --- a/benches/benches/computepass.rs +++ b/benches/benches/computepass.rs @@ -148,12 +148,8 @@ impl ComputepassState { &wgpu::TextureDescriptor::builder() .label(&*format!("StorageTexture {i}")) .size(Default::default()) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::R32Float) .usage(wgpu::TextureUsages::STORAGE_BINDING) - .view_formats(&[]) .build(), ); storage_texture_views.push(texture.create_view(&wgpu::TextureViewDescriptor { diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index ac36d818ad3..4b631ad08d7 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -251,14 +251,9 @@ impl crate::framework::Example for Example { }; let texture = device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(size) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8UnormSrgb) .usage(wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING) - .view_formats(&[]) .build(), ); queue.write_texture( diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index 589e67d778d..1217c9bf10e 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -26,15 +26,11 @@ impl Example { height: (config.height / 16).max(1), depth_or_array_layers: 1, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(RENDER_TARGET_FORMAT) .usage( wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::RENDER_ATTACHMENT, ) - .view_formats(&[]) .build(), ) .create_view(&Default::default()); diff --git a/examples/src/framework.rs b/examples/src/framework.rs index c469eeed34d..f65b7aedce0 100644 --- a/examples/src/framework.rs +++ b/examples/src/framework.rs @@ -556,14 +556,10 @@ impl From> height: params.height, depth_or_array_layers: 1, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(format) .usage( wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC, ) - .view_formats(&[]) .build(), ); diff --git a/examples/src/mipmap/mod.rs b/examples/src/mipmap/mod.rs index 5493b7ad497..22e6e81bd92 100644 --- a/examples/src/mipmap/mod.rs +++ b/examples/src/mipmap/mod.rs @@ -229,16 +229,12 @@ impl crate::framework::Example for Example { &wgpu::TextureDescriptor::builder() .size(texture_extent) .mip_level_count(MIP_LEVEL_COUNT) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(TEXTURE_FORMAT) .usage( wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST, ) - .label(None) - .view_formats(&[]) .build(), ); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index 7bbf2b56ef8..0f6c342f820 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -108,13 +108,9 @@ impl Example { }; let multisampled_frame_descriptor = &wgpu::TextureDescriptor::builder() .size(multisampled_texture_extent) - .mip_level_count(1) .sample_count(sample_count) - .dimension(wgpu::TextureDimension::D2) .format(config.view_formats[0]) .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) - .label(None) - .view_formats(&[]) .build(); device diff --git a/examples/src/render_to_texture/mod.rs b/examples/src/render_to_texture/mod.rs index 0a89c92025c..2a0ff579fd3 100644 --- a/examples/src/render_to_texture/mod.rs +++ b/examples/src/render_to_texture/mod.rs @@ -32,15 +32,11 @@ async fn run(_path: Option) { let render_target = device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(wgpu::Extent3d { width: TEXTURE_DIMS.0 as u32, height: TEXTURE_DIMS.1 as u32, depth_or_array_layers: 1, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8UnormSrgb) .usage(wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC) .view_formats(&[wgpu::TextureFormat::Rgba8UnormSrgb]) diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index 34509a50bf2..87da97ab1a2 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -182,11 +182,7 @@ impl crate::framework::Example for Example { height: config.height, depth_or_array_layers: 1, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Stencil8) - .view_formats(&[]) .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) .build(), ); diff --git a/examples/src/storage_texture/mod.rs b/examples/src/storage_texture/mod.rs index bea2c23bf0b..fc3947bc37b 100644 --- a/examples/src/storage_texture/mod.rs +++ b/examples/src/storage_texture/mod.rs @@ -48,18 +48,13 @@ async fn run(_path: Option) { let storage_texture = device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(wgpu::Extent3d { width: TEXTURE_DIMS.0 as u32, height: TEXTURE_DIMS.1 as u32, depth_or_array_layers: 1, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8Unorm) .usage(wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::COPY_SRC) - .view_formats(&[]) .build(), ); let storage_texture_view = storage_texture.create_view(&wgpu::TextureViewDescriptor::default()); diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index 8f863b48fb4..9c3b5c87310 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -158,13 +158,8 @@ impl crate::framework::Example for Example { let texture_descriptor = wgpu::TextureDescriptor::builder() .size(Default::default()) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8UnormSrgb) .usage(wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST) - .label(None) - .view_formats(&[]) .build(); let red_texture = device.create_texture(&wgpu::TextureDescriptor { label: Some("red"), diff --git a/tests/tests/bgra8unorm_storage.rs b/tests/tests/bgra8unorm_storage.rs index 937d9360045..7cc267f4613 100644 --- a/tests/tests/bgra8unorm_storage.rs +++ b/tests/tests/bgra8unorm_storage.rs @@ -27,18 +27,13 @@ static BGRA8_UNORM_STORAGE: GpuTestConfiguration = GpuTestConfiguration::new() let device = &ctx.device; let texture = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(wgpu::Extent3d { width: 256, height: 256, depth_or_array_layers: 1, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Bgra8Unorm) .usage(wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::COPY_SRC) - .view_formats(&[]) .build(), ); diff --git a/tests/tests/device.rs b/tests/tests/device.rs index c6a8628d7c0..cebbd3ef6f3 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -142,41 +142,29 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne }; let texture_for_view = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(texture_extent) .mip_level_count(2) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rg8Uint) .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) - .view_formats(&[]) .build(), ); let target_view = texture_for_view.create_view(&wgpu::TextureViewDescriptor::default()); let texture_for_read = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(texture_extent) .mip_level_count(2) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rg8Uint) .usage(wgpu::TextureUsages::COPY_SRC) - .view_formats(&[]) .build(), ); let texture_for_write = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(texture_extent) .mip_level_count(2) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rg8Uint) .usage(wgpu::TextureUsages::COPY_DST) - .view_formats(&[]) .build(), ); @@ -306,18 +294,14 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne || { let _ = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(wgpu::Extent3d { width: 512, height: 512, depth_or_array_layers: 1, }) .mip_level_count(2) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rg8Uint) .usage(wgpu::TextureUsages::COPY_SRC) - .view_formats(&[]) .build(), ); }, @@ -862,14 +846,10 @@ static DEVICE_DESTROY_THEN_BUFFER_CLEANUP: GpuTestConfiguration = GpuTestConfigu }; let _texture = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(texture_extent) .mip_level_count(2) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rg8Uint) .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) - .view_formats(&[]) .build(), ); diff --git a/tests/tests/encoder.rs b/tests/tests/encoder.rs index 3f41b8060e5..8254a0de658 100644 --- a/tests/tests/encoder.rs +++ b/tests/tests/encoder.rs @@ -35,18 +35,13 @@ static DROP_ENCODER_AFTER_ERROR: GpuTestConfiguration = GpuTestConfiguration::ne let target_tex = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(wgpu::Extent3d { width: 100, height: 100, depth_or_array_layers: 1, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::R8Unorm) .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) - .view_formats(&[]) .build(), ); let target_view = target_tex.create_view(&wgpu::TextureViewDescriptor::default()); @@ -105,14 +100,9 @@ fn encoder_operations_fail_while_pass_alive(ctx: TestingContext) { }); let texture_desc = wgpu::TextureDescriptor::builder() - .label(None) .size(Default::default()) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8Unorm) .usage(wgpu::TextureUsages::COPY_DST) - .view_formats(&[]) .build(); let texture_dst = ctx.device.create_texture(&texture_desc); let texture_src = ctx.device.create_texture(&wgpu::TextureDescriptor { diff --git a/tests/tests/external_texture.rs b/tests/tests/external_texture.rs index cf1f49ed53d..589a8d1ef7a 100644 --- a/tests/tests/external_texture.rs +++ b/tests/tests/external_texture.rs @@ -255,16 +255,12 @@ static IMAGE_BITMAP_IMPORT: GpuTestConfiguration = height: 3, depth_or_array_layers: dest_layers, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8UnormSrgb) .usage( wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::COPY_SRC, ) - .view_formats(&[]) .build(), ); diff --git a/tests/tests/float32_filterable.rs b/tests/tests/float32_filterable.rs index acb5e989d85..39f22bc95de 100644 --- a/tests/tests/float32_filterable.rs +++ b/tests/tests/float32_filterable.rs @@ -5,18 +5,13 @@ use wgpu_test::{fail, gpu_test, GpuTestConfiguration, TestParameters}; fn create_texture_binding(device: &wgpu::Device, format: wgpu::TextureFormat, filterable: bool) { let texture = device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(wgpu::Extent3d { width: 256, height: 256, depth_or_array_layers: 1, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(format) .usage(wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST) - .view_formats(&[]) .build(), ); diff --git a/tests/tests/life_cycle.rs b/tests/tests/life_cycle.rs index ea6b56533d6..c449d99ba56 100644 --- a/tests/tests/life_cycle.rs +++ b/tests/tests/life_cycle.rs @@ -82,18 +82,14 @@ static TEXTURE_DESTROY: GpuTestConfiguration = GpuTestConfiguration::new().run_async(|ctx| async move { let texture = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(wgpu::Extent3d { width: 128, height: 128, depth_or_array_layers: 1, }) - .mip_level_count(1) .sample_count(1) // multisampling is not supported for clear - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8Snorm) .usage(wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING) - .view_formats(&[]) .build(), ); diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index c63882948cf..160a8a6653f 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -140,12 +140,8 @@ async fn draw_test_with_reports( &wgpu::TextureDescriptor::builder() .label("dummy") .size(Default::default()) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8Unorm) .usage(wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST) - .view_formats(&[]) .build(), wgpu::util::TextureDataOrder::LayerMajor, &[0, 0, 0, 1], diff --git a/tests/tests/nv12_texture/mod.rs b/tests/tests/nv12_texture/mod.rs index d7677c4519b..10c7fc7136e 100644 --- a/tests/tests/nv12_texture/mod.rs +++ b/tests/tests/nv12_texture/mod.rs @@ -127,14 +127,9 @@ static NV12_TEXTURE_VIEW_PLANE_ON_NON_PLANAR_FORMAT: GpuTestConfiguration = }; let tex = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) - .dimension(wgpu::TextureDimension::D2) .size(size) .format(wgpu::TextureFormat::R8Unorm) .usage(wgpu::TextureUsages::TEXTURE_BINDING) - .mip_level_count(1) - .sample_count(1) - .view_formats(&[]) .build(), ); fail( @@ -160,14 +155,9 @@ static NV12_TEXTURE_VIEW_PLANE_OUT_OF_BOUNDS: GpuTestConfiguration = GpuTestConf }; let tex = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) - .dimension(wgpu::TextureDimension::D2) .size(size) .format(wgpu::TextureFormat::NV12) .usage(wgpu::TextureUsages::TEXTURE_BINDING) - .mip_level_count(1) - .sample_count(1) - .view_formats(&[]) .build(), ); fail( @@ -194,14 +184,9 @@ static NV12_TEXTURE_BAD_FORMAT_VIEW_PLANE: GpuTestConfiguration = GpuTestConfigu }; let tex = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) - .dimension(wgpu::TextureDimension::D2) .size(size) .format(wgpu::TextureFormat::NV12) .usage(wgpu::TextureUsages::TEXTURE_BINDING) - .mip_level_count(1) - .sample_count(1) - .view_formats(&[]) .build(), ); fail( @@ -232,14 +217,9 @@ static NV12_TEXTURE_BAD_SIZE: GpuTestConfiguration = GpuTestConfiguration::new() || { let _ = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) - .dimension(wgpu::TextureDimension::D2) .size(size) .format(wgpu::TextureFormat::NV12) .usage(wgpu::TextureUsages::TEXTURE_BINDING) - .mip_level_count(1) - .sample_count(1) - .view_formats(&[]) .build(), ); }, diff --git a/tests/tests/occlusion_query/mod.rs b/tests/tests/occlusion_query/mod.rs index e3099da5f4d..6c3e1f25b04 100644 --- a/tests/tests/occlusion_query/mod.rs +++ b/tests/tests/occlusion_query/mod.rs @@ -14,12 +14,8 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new() height: 64, depth_or_array_layers: 1, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Depth32Float) .usage(wgpu::TextureUsages::RENDER_ATTACHMENT) - .view_formats(&[]) .build(), ); let depth_texture_view = depth_texture.create_view(&wgpu::TextureViewDescriptor::default()); diff --git a/tests/tests/partially_bounded_arrays/mod.rs b/tests/tests/partially_bounded_arrays/mod.rs index 870bc0e902e..2cc3abea498 100644 --- a/tests/tests/partially_bounded_arrays/mod.rs +++ b/tests/tests/partially_bounded_arrays/mod.rs @@ -24,11 +24,7 @@ static PARTIALLY_BOUNDED_ARRAY: GpuTestConfiguration = GpuTestConfiguration::new }; let storage_texture = device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(texture_extent) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba32Float) .usage( wgpu::TextureUsages::TEXTURE_BINDING @@ -36,7 +32,6 @@ static PARTIALLY_BOUNDED_ARRAY: GpuTestConfiguration = GpuTestConfiguration::new | wgpu::TextureUsages::STORAGE_BINDING | wgpu::TextureUsages::COPY_SRC, ) - .view_formats(&[]) .build(), ); diff --git a/tests/tests/queue_transfer.rs b/tests/tests/queue_transfer.rs index 99b72c250cf..451bbcee5a8 100644 --- a/tests/tests/queue_transfer.rs +++ b/tests/tests/queue_transfer.rs @@ -7,18 +7,13 @@ static QUEUE_WRITE_TEXTURE_OVERFLOW: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(|ctx| { let texture = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(wgpu::Extent3d { width: 146, height: 25, depth_or_array_layers: 192, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba32Float) .usage(wgpu::TextureUsages::COPY_DST) - .view_formats(&[]) .build(), ); diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index 040e9f3a378..6691e816110 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -130,13 +130,9 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { height: 2, depth_or_array_layers: 1, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) // Important: NOT srgb. .format(wgpu::TextureFormat::Rgba8Unorm) .usage(wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT) - .view_formats(&[]) .build(), ); diff --git a/tests/tests/regression/issue_4485.rs b/tests/tests/regression/issue_4485.rs index c74c2e75ab2..9e4fda8f865 100644 --- a/tests/tests/regression/issue_4485.rs +++ b/tests/tests/regression/issue_4485.rs @@ -26,12 +26,8 @@ async fn test_impl(ctx: &TestingContext) { height: TEXTURE_HEIGHT, depth_or_array_layers: 1, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8Unorm) .usage(wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT) - .view_formats(&[]) .build(), ); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); diff --git a/tests/tests/regression/issue_4514.rs b/tests/tests/regression/issue_4514.rs index 71dc3b81370..95a2bfb5fdd 100644 --- a/tests/tests/regression/issue_4514.rs +++ b/tests/tests/regression/issue_4514.rs @@ -26,12 +26,8 @@ async fn test_impl(ctx: &TestingContext) { height: TEXTURE_HEIGHT, depth_or_array_layers: 1, }) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8Unorm) .usage(wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::RENDER_ATTACHMENT) - .view_formats(&[]) .build(), ); let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); diff --git a/tests/tests/resource_error.rs b/tests/tests/resource_error.rs index 884c240ea69..8a817b8671f 100644 --- a/tests/tests/resource_error.rs +++ b/tests/tests/resource_error.rs @@ -38,7 +38,6 @@ static BAD_TEXTURE: GpuTestConfiguration = GpuTestConfiguration::new().run_sync( || { ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(wgpu::Extent3d { width: 0, height: 12345678, @@ -49,7 +48,6 @@ static BAD_TEXTURE: GpuTestConfiguration = GpuTestConfiguration::new().run_sync( .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8UnormSrgb) .usage(wgpu::TextureUsages::all()) - .view_formats(&[]) .build(), ) }, diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index 66bee9cbbdf..099878483b1 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -159,14 +159,9 @@ async fn pulling_common( }; let color_texture = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(texture_size) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8Unorm) .usage(wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC) - .view_formats(&[]) .build(), ); let color_view = color_texture.create_view(&wgpu::TextureViewDescriptor::default()); diff --git a/tests/tests/shader_view_format/mod.rs b/tests/tests/shader_view_format/mod.rs index d197b7b9090..047b216b639 100644 --- a/tests/tests/shader_view_format/mod.rs +++ b/tests/tests/shader_view_format/mod.rs @@ -69,13 +69,9 @@ async fn reinterpret( let tex = ctx.device.create_texture_with_data( &ctx.queue, &wgpu::TextureDescriptor::builder() - .label(None) - .dimension(wgpu::TextureDimension::D2) .size(size) .format(src_format) .usage(wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING) - .mip_level_count(1) - .sample_count(1) .view_formats(&[reinterpret_to]) .build(), wgpu::util::TextureDataOrder::LayerMajor, @@ -123,14 +119,9 @@ async fn reinterpret( let target_tex = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .size(size) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(src_format) .usage(wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_SRC) - .view_formats(&[]) .build(), ); let target_view = target_tex.create_view(&wgpu::TextureViewDescriptor::default()); diff --git a/tests/tests/transfer.rs b/tests/tests/transfer.rs index 582602c5656..c461371d31c 100644 --- a/tests/tests/transfer.rs +++ b/tests/tests/transfer.rs @@ -8,8 +8,6 @@ static COPY_OVERFLOW_Z: GpuTestConfiguration = GpuTestConfiguration::new().run_s let t1 = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) - .dimension(wgpu::TextureDimension::D2) .size(wgpu::Extent3d { width: 256, height: 256, @@ -17,9 +15,6 @@ static COPY_OVERFLOW_Z: GpuTestConfiguration = GpuTestConfiguration::new().run_s }) .format(wgpu::TextureFormat::Rgba8Uint) .usage(wgpu::TextureUsages::COPY_DST) - .mip_level_count(1) - .sample_count(1) - .view_formats(&[]) .build(), ); let t2 = ctx.device.create_texture( diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 6e55340b38d..64bfadc723b 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -216,12 +216,8 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { &wgpu::TextureDescriptor::builder() .label("dummy") .size(Default::default()) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8Unorm) .usage(wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST) - .view_formats(&[]) .build(), wgpu::util::TextureDataOrder::LayerMajor, &[0, 0, 0, 1], diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index fa6aff78f63..d6518c24cd7 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -302,12 +302,8 @@ async fn vertex_index_common(ctx: TestingContext) { &wgpu::TextureDescriptor::builder() .label("dummy") .size(Default::default()) - .mip_level_count(1) - .sample_count(1) - .dimension(wgpu::TextureDimension::D2) .format(wgpu::TextureFormat::Rgba8Unorm) .usage(wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::COPY_DST) - .view_formats(&[]) .build(), wgpu::util::TextureDataOrder::LayerMajor, &[0, 0, 0, 1], diff --git a/tests/tests/write_texture.rs b/tests/tests/write_texture.rs index 87f590b915e..1c7b55f0fb6 100644 --- a/tests/tests/write_texture.rs +++ b/tests/tests/write_texture.rs @@ -9,8 +9,6 @@ static WRITE_TEXTURE_SUBSET_2D: GpuTestConfiguration = let tex = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) - .dimension(wgpu::TextureDimension::D2) .size(wgpu::Extent3d { width: size, height: size, @@ -22,9 +20,6 @@ static WRITE_TEXTURE_SUBSET_2D: GpuTestConfiguration = | wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::TEXTURE_BINDING, ) - .mip_level_count(1) - .sample_count(1) - .view_formats(&[]) .build(), ); let data = vec![1u8; size as usize * 2]; @@ -108,7 +103,6 @@ static WRITE_TEXTURE_SUBSET_3D: GpuTestConfiguration = let depth = 4; let tex = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) .dimension(wgpu::TextureDimension::D3) .size(wgpu::Extent3d { width: size, @@ -121,9 +115,6 @@ static WRITE_TEXTURE_SUBSET_3D: GpuTestConfiguration = | wgpu::TextureUsages::COPY_SRC | wgpu::TextureUsages::TEXTURE_BINDING, ) - .mip_level_count(1) - .sample_count(1) - .view_formats(&[]) .build(), ); let data = vec![1u8; (size * size) as usize * 2]; @@ -207,8 +198,6 @@ static WRITE_TEXTURE_NO_OOB: GpuTestConfiguration = let tex = ctx.device.create_texture( &wgpu::TextureDescriptor::builder() - .label(None) - .dimension(wgpu::TextureDimension::D2) .size(wgpu::Extent3d { width: size, height: size, @@ -216,9 +205,6 @@ static WRITE_TEXTURE_NO_OOB: GpuTestConfiguration = }) .format(wgpu::TextureFormat::R8Uint) .usage(wgpu::TextureUsages::COPY_DST) - .mip_level_count(1) - .sample_count(1) - .view_formats(&[]) .build(), ); let data = vec![1u8; size as usize * 2 + 100]; // check that we don't attempt to copy OOB internally by adding 100 bytes here From 5e2e56c14a57344164169572079f80b7455aa928 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 17:33:40 -0400 Subject: [PATCH 09/33] WIP: refactor!: give `PipelineLayoutDescriptor` a builder API --- Cargo.lock | 2 ++ benches/benches/computepass.rs | 30 +++++++++---------- benches/benches/renderpass.rs | 30 +++++++++---------- deno_webgpu/binding.rs | 10 +++---- examples/src/boids/mod.rs | 26 ++++++++-------- examples/src/bunnymark/mod.rs | 12 ++++---- examples/src/conservative_raster/mod.rs | 25 +++++++++------- examples/src/cube/mod.rs | 12 ++++---- examples/src/hello_synchronization/mod.rs | 12 ++++---- examples/src/hello_triangle/mod.rs | 12 ++++---- examples/src/hello_workgroups/mod.rs | 12 ++++---- examples/src/msaa_line/mod.rs | 12 ++++---- examples/src/repeated_compute/mod.rs | 12 ++++---- examples/src/shadow/mod.rs | 24 ++++++++------- examples/src/skybox/mod.rs | 12 ++++---- examples/src/srgb_blend/mod.rs | 12 ++++---- examples/src/stencil_triangles/mod.rs | 12 ++++---- examples/src/storage_texture/mod.rs | 12 ++++---- examples/src/texture_arrays/mod.rs | 12 ++++---- examples/src/timestamp_queries/mod.rs | 12 ++++---- examples/src/uniform_values/mod.rs | 14 +++++---- examples/src/water/mod.rs | 26 ++++++++-------- tests/src/image.rs | 12 ++++---- tests/tests/bgra8unorm_storage.rs | 12 ++++---- tests/tests/bind_group_layout_dedup.rs | 28 ++++++++--------- tests/tests/buffer.rs | 22 +++++++------- tests/tests/compute_pass_ownership.rs | 14 ++++----- tests/tests/device.rs | 14 ++++----- tests/tests/mem_leaks.rs | 14 ++++----- tests/tests/partially_bounded_arrays/mod.rs | 12 ++++---- tests/tests/pipeline_cache.rs | 14 ++++----- tests/tests/push_constants.rs | 16 +++++----- tests/tests/regression/issue_3349.rs | 16 +++++----- tests/tests/regression/issue_3457.rs | 14 ++++----- tests/tests/regression/issue_5553.rs | 14 ++++----- tests/tests/render_pass_ownership.rs | 14 ++++----- tests/tests/shader/mod.rs | 16 +++++----- tests/tests/shader/zero_init_workgroup_mem.rs | 14 ++++----- tests/tests/subgroup_operations/mod.rs | 12 ++++---- tests/tests/vertex_formats/mod.rs | 14 ++++----- tests/tests/vertex_indices/mod.rs | 14 ++++----- wgpu-core/Cargo.toml | 1 + wgpu-core/src/binding_model.rs | 4 ++- wgpu/Cargo.toml | 1 + wgpu/src/api/pipeline_layout.rs | 4 ++- 45 files changed, 346 insertions(+), 293 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4f77265fb0..e892b61de2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3653,6 +3653,7 @@ name = "wgpu" version = "23.0.0" dependencies = [ "arrayvec", + "bon", "cfg_aliases", "document-features", "js-sys", @@ -3696,6 +3697,7 @@ dependencies = [ "arrayvec", "bit-vec", "bitflags 2.6.0", + "bon", "bytemuck", "cfg_aliases", "document-features", diff --git a/benches/benches/computepass.rs b/benches/benches/computepass.rs index 58f1b2b0d76..30f1421be42 100644 --- a/benches/benches/computepass.rs +++ b/benches/benches/computepass.rs @@ -222,14 +222,13 @@ impl ComputepassState { .device .create_shader_module(wgpu::include_wgsl!("computepass.wgsl")); - let pipeline_layout = - device_state - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device_state.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let pipeline = device_state @@ -317,14 +316,13 @@ impl ComputepassState { .device .create_shader_module(wgpu::include_wgsl!("computepass-bindless.wgsl")); - let bindless_pipeline_layout = - device_state - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bindless_bind_group_layout], - push_constant_ranges: &[], - }); + let bindless_pipeline_layout = device_state.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bindless_bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let bindless_pipeline = device_state diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index f5bf54c0a59..bd38ea0db3c 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -130,14 +130,13 @@ impl RenderpassState { .device .create_shader_module(wgpu::include_wgsl!("renderpass.wgsl")); - let pipeline_layout = - device_state - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device_state.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let mut vertex_buffers = Vec::with_capacity(vertex_buffer_count); for _ in 0..vertex_buffer_count { @@ -260,14 +259,13 @@ impl RenderpassState { .device .create_shader_module(wgpu::include_wgsl!("renderpass-bindless.wgsl")); - let bindless_pipeline_layout = - device_state - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bindless_bind_group_layout], - push_constant_ranges: &[], - }); + let bindless_pipeline_layout = device_state.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bindless_bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); bindless_pipeline = Some(device_state.device.create_render_pipeline( &wgpu::RenderPipelineDescriptor { diff --git a/deno_webgpu/binding.rs b/deno_webgpu/binding.rs index f1f3a80d359..2fd6cf0a79b 100644 --- a/deno_webgpu/binding.rs +++ b/deno_webgpu/binding.rs @@ -220,11 +220,11 @@ pub fn op_webgpu_create_pipeline_layout( }) .collect::, AnyError>>()?; - let descriptor = wgpu_core::binding_model::PipelineLayoutDescriptor { - label: Some(label), - bind_group_layouts: Cow::from(bind_group_layouts), - push_constant_ranges: Default::default(), - }; + let descriptor = wgpu_core::binding_model::PipelineLayoutDescriptor::builder() + .label(label) + .bind_group_layouts(Cow::from(bind_group_layouts)) + .push_constant_ranges(Default::default()) + .build(); gfx_put!(instance.device_create_pipeline_layout( device, diff --git a/examples/src/boids/mod.rs b/examples/src/boids/mod.rs index 53e4239f392..48281970ef5 100644 --- a/examples/src/boids/mod.rs +++ b/examples/src/boids/mod.rs @@ -104,21 +104,23 @@ impl crate::framework::Example for Example { ], label: None, }); - let compute_pipeline_layout = - device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("compute"), - bind_group_layouts: &[&compute_bind_group_layout], - push_constant_ranges: &[], - }); + let compute_pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("compute") + .bind_group_layouts(&[&compute_bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); // create render pipeline with empty bind group layout - let render_pipeline_layout = - device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("render"), - bind_group_layouts: &[], - push_constant_ranges: &[], - }); + let render_pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("render") + .bind_group_layouts(&[]) + .push_constant_ranges(&[]) + .build(), + ); let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index 4b631ad08d7..bcaf0f0f9ef 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -201,11 +201,13 @@ impl crate::framework::Example for Example { }], label: None, }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&global_bind_group_layout, &local_bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&global_bind_group_layout, &local_bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index 1217c9bf10e..2f98e9be1d9 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -74,12 +74,13 @@ impl crate::framework::Example for Example { device: &wgpu::Device, _queue: &wgpu::Queue, ) -> Self { - let pipeline_layout_empty = - device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[], - push_constant_ranges: &[], - }); + let pipeline_layout_empty = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[]) + .push_constant_ranges(&[]) + .build(), + ); let shader_triangle_and_lines = device.create_shader_module(wgpu::include_wgsl!("triangle_and_lines.wgsl")); @@ -192,11 +193,13 @@ impl crate::framework::Example for Example { ], }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let shader = device.create_shader_module(wgpu::include_wgsl!("upscale.wgsl")); ( device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index 4f46649f6e3..88749aadf32 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -155,11 +155,13 @@ impl crate::framework::Example for Example { }, ], }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); // Create the texture let size = 256u32; diff --git a/examples/src/hello_synchronization/mod.rs b/examples/src/hello_synchronization/mod.rs index 128609bb974..e2e0c24651b 100644 --- a/examples/src/hello_synchronization/mod.rs +++ b/examples/src/hello_synchronization/mod.rs @@ -93,11 +93,13 @@ async fn execute( }], }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let patient_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { label: None, layout: Some(&pipeline_layout), diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs index 7c82d49cf07..1592488c74c 100644 --- a/examples/src/hello_triangle/mod.rs +++ b/examples/src/hello_triangle/mod.rs @@ -45,11 +45,13 @@ async fn run(event_loop: EventLoop<()>, window: Window) { source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[]) + .push_constant_ranges(&[]) + .build(), + ); let swapchain_capabilities = surface.get_capabilities(&adapter); let swapchain_format = swapchain_capabilities.formats[0]; diff --git a/examples/src/hello_workgroups/mod.rs b/examples/src/hello_workgroups/mod.rs index 26b6cccfe56..870430ce39b 100644 --- a/examples/src/hello_workgroups/mod.rs +++ b/examples/src/hello_workgroups/mod.rs @@ -100,11 +100,13 @@ async fn run() { ], }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { label: None, layout: Some(&pipeline_layout), diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index 0f6c342f820..1db7e3ec2c2 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -154,11 +154,13 @@ impl crate::framework::Example for Example { let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl")); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[]) + .push_constant_ranges(&[]) + .build(), + ); let multisampled_framebuffer = Example::create_multisampled_framebuffer(device, config, sample_count); diff --git a/examples/src/repeated_compute/mod.rs b/examples/src/repeated_compute/mod.rs index a84ab4ed677..beae61f3369 100644 --- a/examples/src/repeated_compute/mod.rs +++ b/examples/src/repeated_compute/mod.rs @@ -231,11 +231,13 @@ impl WgpuContext { }], }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { label: None, layout: Some(&pipeline_layout), diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index 5da1379cbbf..4d42bcd65d0 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -462,11 +462,13 @@ impl crate::framework::Example for Example { count: None, }], }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("shadow"), - bind_group_layouts: &[&bind_group_layout, &local_bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("shadow") + .bind_group_layouts(&[&bind_group_layout, &local_bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor { label: None, @@ -578,11 +580,13 @@ impl crate::framework::Example for Example { ], label: None, }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("main"), - bind_group_layouts: &[&bind_group_layout, &local_bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("main") + .bind_group_layouts(&[&bind_group_layout, &local_bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let mx_total = Self::generate_matrix(config.width as f32 / config.height as f32); let forward_uniforms = GlobalUniforms { diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index 89e3a39803f..d148713f0f4 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -180,11 +180,13 @@ impl crate::framework::Example for Example { usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); // Create the render pipelines let sky_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index ac0343f690c..f5cbe98dd0c 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -90,11 +90,13 @@ impl crate::framework::Example for Example { label: None, entries: &[], }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); // Create bind group let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index 87da97ab1a2..fa297834a91 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -46,11 +46,13 @@ impl crate::framework::Example for Example { usage: wgpu::BufferUsages::VERTEX, }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[]) + .push_constant_ranges(&[]) + .build(), + ); let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl")); diff --git a/examples/src/storage_texture/mod.rs b/examples/src/storage_texture/mod.rs index fc3947bc37b..e1fee557d9e 100644 --- a/examples/src/storage_texture/mod.rs +++ b/examples/src/storage_texture/mod.rs @@ -87,11 +87,13 @@ async fn run(_path: Option) { }], }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { label: None, layout: Some(&pipeline_layout), diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index 9c3b5c87310..e9ef540c16b 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -301,11 +301,13 @@ impl crate::framework::Example for Example { label: Some("bind group"), }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("main"), - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("main") + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let index_format = wgpu::IndexFormat::Uint16; diff --git a/examples/src/timestamp_queries/mod.rs b/examples/src/timestamp_queries/mod.rs index cee4d5f9336..cbd5845448e 100644 --- a/examples/src/timestamp_queries/mod.rs +++ b/examples/src/timestamp_queries/mod.rs @@ -342,11 +342,13 @@ fn render_pass( ) { let format = wgpu::TextureFormat::Rgba8Unorm; - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[]) + .push_constant_ranges(&[]) + .build(), + ); let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, diff --git a/examples/src/uniform_values/mod.rs b/examples/src/uniform_values/mod.rs index a5c1e14c549..8be0757c98d 100644 --- a/examples/src/uniform_values/mod.rs +++ b/examples/src/uniform_values/mod.rs @@ -159,12 +159,14 @@ impl WgpuContext { }], }); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - // (4) - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + // (4) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let swapchain_capabilities = surface.get_capabilities(&adapter); let swapchain_format = swapchain_capabilities.formats[0]; diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index dd20f665534..3436ffb21a3 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -428,19 +428,21 @@ impl crate::framework::Example for Example { }); // Create our pipeline layouts. - let water_pipeline_layout = - device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("water"), - bind_group_layouts: &[&water_bind_group_layout], - push_constant_ranges: &[], - }); + let water_pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("water") + .bind_group_layouts(&[&water_bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); - let terrain_pipeline_layout = - device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("terrain"), - bind_group_layouts: &[&terrain_bind_group_layout], - push_constant_ranges: &[], - }); + let terrain_pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("terrain") + .bind_group_layouts(&[&terrain_bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let water_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor { label: Some("Water Uniforms"), diff --git a/tests/src/image.rs b/tests/src/image.rs index d990fdf9d90..ed5d819c75d 100644 --- a/tests/src/image.rs +++ b/tests/src/image.rs @@ -341,11 +341,13 @@ fn copy_via_compute( ], }); - let pll = device.create_pipeline_layout(&PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bgl], - push_constant_ranges: &[], - }); + let pll = device.create_pipeline_layout( + &PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bgl]) + .push_constant_ranges(&[]) + .build(), + ); let source = String::from(include_str!("copy_texture_to_buffer.wgsl")); diff --git a/tests/tests/bgra8unorm_storage.rs b/tests/tests/bgra8unorm_storage.rs index 7cc267f4613..df3da7c8a00 100644 --- a/tests/tests/bgra8unorm_storage.rs +++ b/tests/tests/bgra8unorm_storage.rs @@ -78,11 +78,13 @@ static BGRA8_UNORM_STORAGE: GpuTestConfiguration = GpuTestConfiguration::new() }], }); - let pl = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bgl], - push_constant_ranges: &[], - }); + let pl = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bgl]) + .push_constant_ranges(&[]) + .build(), + ); let module = device.create_shader_module(wgpu::ShaderModuleDescriptor { label: None, diff --git a/tests/tests/bind_group_layout_dedup.rs b/tests/tests/bind_group_layout_dedup.rs index b322b019b9b..4181f824c8a 100644 --- a/tests/tests/bind_group_layout_dedup.rs +++ b/tests/tests/bind_group_layout_dedup.rs @@ -59,13 +59,13 @@ async fn bgl_dedupe(ctx: TestingContext) { entries: &[], }); - let pipeline_layout = ctx - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bgl_1b], - push_constant_ranges: &[], - }); + let pipeline_layout = ctx.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bgl_1b]) + .push_constant_ranges(&[]) + .build(), + ); let module = ctx .device @@ -119,13 +119,13 @@ fn bgl_dedupe_with_dropped_user_handle(ctx: TestingContext) { entries: &[ENTRY], }); - let pipeline_layout = ctx - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bgl_1], - push_constant_ranges: &[], - }); + let pipeline_layout = ctx.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bgl_1]) + .push_constant_ranges(&[]) + .build(), + ); // We drop bgl_1 here. As bgl_1 is still alive, referenced by the pipeline layout, // the deduplication should work as expected. Previously this did not work. diff --git a/tests/tests/buffer.rs b/tests/tests/buffer.rs index b3a48f178ae..67aa68edcb6 100644 --- a/tests/tests/buffer.rs +++ b/tests/tests/buffer.rs @@ -211,11 +211,12 @@ static MINIMUM_BUFFER_BINDING_SIZE_LAYOUT: GpuTestConfiguration = GpuTestConfigu let pipeline_layout = ctx .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor ::builder() + .label(None) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build() + ); wgpu_test::fail( &ctx.device, @@ -285,11 +286,12 @@ static MINIMUM_BUFFER_BINDING_SIZE_DISPATCH: GpuTestConfiguration = GpuTestConfi let pipeline_layout = ctx .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor ::builder() + .label(None) + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build() + ); let pipeline = ctx .device diff --git a/tests/tests/compute_pass_ownership.rs b/tests/tests/compute_pass_ownership.rs index df50f51e058..ca3a8b4ce76 100644 --- a/tests/tests/compute_pass_ownership.rs +++ b/tests/tests/compute_pass_ownership.rs @@ -303,13 +303,13 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { }], }); - let pipeline_layout = ctx - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("pipeline_layout"), - bind_group_layouts: &[&bgl], - push_constant_ranges: &[], - }); + let pipeline_layout = ctx.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("pipeline_layout") + .bind_group_layouts(&[&bgl]) + .push_constant_ranges(&[]) + .build(), + ); let pipeline = ctx .device diff --git a/tests/tests/device.rs b/tests/tests/device.rs index cebbd3ef6f3..a401730707e 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -461,13 +461,13 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne fail( &ctx.device, || { - let _ = ctx - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[], - push_constant_ranges: &[], - }); + let _ = ctx.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[]) + .push_constant_ranges(&[]) + .build(), + ); }, Some("device with '' label is invalid"), ); diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index 160a8a6653f..662774697f3 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -73,13 +73,13 @@ async fn draw_test_with_reports( assert_eq!(report.bind_groups.num_allocated, 1); assert_eq!(report.bind_group_layouts.num_allocated, 1); - let ppl = ctx - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bgl], - push_constant_ranges: &[], - }); + let ppl = ctx.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bgl]) + .push_constant_ranges(&[]) + .build(), + ); let global_report = ctx.instance.generate_report().unwrap(); let report = global_report.hub_report(); diff --git a/tests/tests/partially_bounded_arrays/mod.rs b/tests/tests/partially_bounded_arrays/mod.rs index 2cc3abea498..80e43f7bb1e 100644 --- a/tests/tests/partially_bounded_arrays/mod.rs +++ b/tests/tests/partially_bounded_arrays/mod.rs @@ -54,11 +54,13 @@ static PARTIALLY_BOUNDED_ARRAY: GpuTestConfiguration = GpuTestConfiguration::new let cs_module = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl")); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("main"), - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("main") + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { label: None, diff --git a/tests/tests/pipeline_cache.rs b/tests/tests/pipeline_cache.rs index c88a871c753..2106d07d30f 100644 --- a/tests/tests/pipeline_cache.rs +++ b/tests/tests/pipeline_cache.rs @@ -89,13 +89,13 @@ async fn pipeline_cache_test(ctx: TestingContext) { }], }); - let pipeline_layout = ctx - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("pipeline_layout"), - bind_group_layouts: &[&bgl], - push_constant_ranges: &[], - }); + let pipeline_layout = ctx.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("pipeline_layout") + .bind_group_layouts(&[&bgl]) + .push_constant_ranges(&[]) + .build(), + ); let first_cache_data; { diff --git a/tests/tests/push_constants.rs b/tests/tests/push_constants.rs index 905578d5335..1dc9783d363 100644 --- a/tests/tests/push_constants.rs +++ b/tests/tests/push_constants.rs @@ -85,16 +85,16 @@ async fn partial_update_test(ctx: TestingContext) { }], }); - let pipeline_layout = ctx - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("pipeline_layout"), - bind_group_layouts: &[&bgl], - push_constant_ranges: &[wgpu::PushConstantRange { + let pipeline_layout = ctx.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("pipeline_layout") + .bind_group_layouts(&[&bgl]) + .push_constant_ranges(&[wgpu::PushConstantRange { stages: wgpu::ShaderStages::COMPUTE, range: 0..32, - }], - }); + }]) + .build(), + ); let pipeline = ctx .device diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index 6691e816110..5b3b36736ed 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -83,16 +83,16 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { }], }); - let pll = ctx - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("pll"), - bind_group_layouts: &[&bgl], - push_constant_ranges: &[wgpu::PushConstantRange { + let pll = ctx.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("pll") + .bind_group_layouts(&[&bgl]) + .push_constant_ranges(&[wgpu::PushConstantRange { stages: wgpu::ShaderStages::VERTEX_FRAGMENT, range: 0..16, - }], - }); + }]) + .build(), + ); let pipeline = ctx .device diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index 386b5c34bbe..780d512ddca 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -36,13 +36,13 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = mapped_at_creation: false, }); - let pipeline_layout = ctx - .device - .create_pipeline_layout(&PipelineLayoutDescriptor { - label: Some("Pipeline Layout"), - bind_group_layouts: &[], - push_constant_ranges: &[], - }); + let pipeline_layout = ctx.device.create_pipeline_layout( + &PipelineLayoutDescriptor::builder() + .label("Pipeline Layout") + .bind_group_layouts(&[]) + .push_constant_ranges(&[]) + .build(), + ); let double_pipeline = ctx .device diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index 01ffb59d1a2..dce80a74493 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -16,13 +16,13 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = .device .create_shader_module(include_wgsl!("issue_5553.wgsl")); - let pipeline_layout = ctx - .device - .create_pipeline_layout(&PipelineLayoutDescriptor { - label: Some("Pipeline Layout"), - bind_group_layouts: &[], - push_constant_ranges: &[], - }); + let pipeline_layout = ctx.device.create_pipeline_layout( + &PipelineLayoutDescriptor::builder() + .label("Pipeline Layout") + .bind_group_layouts(&[]) + .push_constant_ranges(&[]) + .build(), + ); let _ = ctx .device diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index d06ee6f1c87..33e17bd0cc5 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -439,13 +439,13 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { }], }); - let pipeline_layout = ctx - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("pipeline_layout"), - bind_group_layouts: &[&bgl], - push_constant_ranges: &[], - }); + let pipeline_layout = ctx.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("pipeline_layout") + .bind_group_layouts(&[&bgl]) + .push_constant_ranges(&[]) + .build(), + ); let target_size = wgpu::Extent3d { width: 4, diff --git a/tests/tests/shader/mod.rs b/tests/tests/shader/mod.rs index 7d6ed7aaaa5..446fae566df 100644 --- a/tests/tests/shader/mod.rs +++ b/tests/tests/shader/mod.rs @@ -263,19 +263,19 @@ async fn shader_input_output_test( ], }); - let pll = ctx - .device - .create_pipeline_layout(&PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bgl], - push_constant_ranges: match storage_type { + let pll = ctx.device.create_pipeline_layout( + &PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bgl]) + .push_constant_ranges(match storage_type { InputStorageType::PushConstant => &[PushConstantRange { stages: ShaderStages::COMPUTE, range: 0..MAX_BUFFER_SIZE as u32, }], _ => &[], - }, - }); + }) + .build(), + ); let mut fail = false; for test in tests { diff --git a/tests/tests/shader/zero_init_workgroup_mem.rs b/tests/tests/shader/zero_init_workgroup_mem.rs index beacb4fcc8c..62f589b94de 100644 --- a/tests/tests/shader/zero_init_workgroup_mem.rs +++ b/tests/tests/shader/zero_init_workgroup_mem.rs @@ -61,13 +61,13 @@ static ZERO_INIT_WORKGROUP_MEMORY: GpuTestConfiguration = GpuTestConfiguration:: }], }); - let pll = ctx - .device - .create_pipeline_layout(&PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bgl], - push_constant_ranges: &[], - }); + let pll = ctx.device.create_pipeline_layout( + &PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bgl]) + .push_constant_ranges(&[]) + .build(), + ); let sm = ctx .device diff --git a/tests/tests/subgroup_operations/mod.rs b/tests/tests/subgroup_operations/mod.rs index 84de70ee5ed..7a5b10929af 100644 --- a/tests/tests/subgroup_operations/mod.rs +++ b/tests/tests/subgroup_operations/mod.rs @@ -58,11 +58,13 @@ static SUBGROUP_OPERATIONS: GpuTestConfiguration = GpuTestConfiguration::new() let cs_module = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl")); - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: Some("main"), - bind_group_layouts: &[&bind_group_layout], - push_constant_ranges: &[], - }); + let pipeline_layout = device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label("main") + .bind_group_layouts(&[&bind_group_layout]) + .push_constant_ranges(&[]) + .build(), + ); let compute_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { label: None, diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 64bfadc723b..03d6e854ea7 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -201,13 +201,13 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { }], }); - let ppl = ctx - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bgl], - push_constant_ranges: &[], - }); + let ppl = ctx.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bgl]) + .push_constant_ranges(&[]) + .build(), + ); let dummy = ctx .device diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index d6518c24cd7..583b0d01bc3 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -245,13 +245,13 @@ async fn vertex_index_common(ctx: TestingContext) { }], }); - let ppl = ctx - .device - .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[&bgl], - push_constant_ranges: &[], - }); + let ppl = ctx.device.create_pipeline_layout( + &wgpu::PipelineLayoutDescriptor::builder() + .label(None) + .bind_group_layouts(&[&bgl]) + .push_constant_ranges(&[]) + .build(), + ); let mut pipeline_desc = wgpu::RenderPipelineDescriptor { label: None, diff --git a/wgpu-core/Cargo.toml b/wgpu-core/Cargo.toml index 5906aeb339b..0fe962eb8ad 100644 --- a/wgpu-core/Cargo.toml +++ b/wgpu-core/Cargo.toml @@ -113,6 +113,7 @@ dx12 = ["hal/dx12"] arrayvec.workspace = true bit-vec.workspace = true bitflags.workspace = true +bon.workspace = true bytemuck = { workspace = true, optional = true } document-features.workspace = true indexmap.workspace = true diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 30275f061df..e48af4cab15 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -606,12 +606,13 @@ pub enum PushConstantUploadError { /// Describes a pipeline layout. /// /// A `PipelineLayoutDescriptor` can be used to create a pipeline layout. -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(bon::Builder, Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct PipelineLayoutDescriptor<'a> { /// Debug label of the pipeline layout. /// /// This will show up in graphics debuggers for easy identification. + #[builder(default, into)] pub label: Label<'a>, /// Bind groups that this pipeline uses. The first entry will provide all the bindings for /// "set = 0", second entry will provide all the bindings for "set = 1" etc. @@ -623,6 +624,7 @@ pub struct PipelineLayoutDescriptor<'a> { /// If this array is non-empty, the /// [`Features::PUSH_CONSTANTS`](wgt::Features::PUSH_CONSTANTS) feature must /// be enabled. + #[builder(default)] pub push_constant_ranges: Cow<'a, [wgt::PushConstantRange]>, } diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index ed630133e23..055128cca6d 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -175,6 +175,7 @@ optional = true [dependencies] arrayvec.workspace = true +bon.workspace = true document-features.workspace = true log.workspace = true parking_lot.workspace = true diff --git a/wgpu/src/api/pipeline_layout.rs b/wgpu/src/api/pipeline_layout.rs index 20538dd9e74..ec66e073ad9 100644 --- a/wgpu/src/api/pipeline_layout.rs +++ b/wgpu/src/api/pipeline_layout.rs @@ -32,9 +32,10 @@ impl Drop for PipelineLayout { /// /// Corresponds to [WebGPU `GPUPipelineLayoutDescriptor`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpupipelinelayoutdescriptor). -#[derive(Clone, Debug, Default)] +#[derive(bon::Builder, Clone, Debug, Default)] pub struct PipelineLayoutDescriptor<'a> { /// Debug label of the pipeline layout. This will show up in graphics debuggers for easy identification. + #[builder(default, into)] pub label: Label<'a>, /// Bind groups that this pipeline uses. The first entry will provide all the bindings for /// "set = 0", second entry will provide all the bindings for "set = 1" etc. @@ -44,6 +45,7 @@ pub struct PipelineLayoutDescriptor<'a> { /// buffer. /// /// If this array is non-empty, the [`Features::PUSH_CONSTANTS`] must be enabled. + #[builder(default)] pub push_constant_ranges: &'a [PushConstantRange], } #[cfg(send_sync)] From 4fc865e63caa72a40a3588cd4491b962b47eb99d Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 9 Sep 2024 14:02:21 -0400 Subject: [PATCH 10/33] WIP: refactor!: remove unnecessary fields in `PipelineLayoutDescriptor` builder usage --- benches/benches/computepass.rs | 4 ---- benches/benches/renderpass.rs | 4 ---- deno_webgpu/binding.rs | 1 - examples/src/boids/mod.rs | 2 -- examples/src/bunnymark/mod.rs | 2 -- examples/src/conservative_raster/mod.rs | 4 ---- examples/src/cube/mod.rs | 2 -- examples/src/hello_synchronization/mod.rs | 2 -- examples/src/hello_triangle/mod.rs | 2 -- examples/src/hello_workgroups/mod.rs | 2 -- examples/src/msaa_line/mod.rs | 2 -- examples/src/repeated_compute/mod.rs | 2 -- examples/src/shadow/mod.rs | 2 -- examples/src/skybox/mod.rs | 2 -- examples/src/srgb_blend/mod.rs | 2 -- examples/src/stencil_triangles/mod.rs | 2 -- examples/src/storage_texture/mod.rs | 2 -- examples/src/texture_arrays/mod.rs | 1 - examples/src/timestamp_queries/mod.rs | 2 -- examples/src/uniform_values/mod.rs | 2 -- examples/src/water/mod.rs | 2 -- tests/src/image.rs | 2 -- tests/tests/bgra8unorm_storage.rs | 2 -- tests/tests/bind_group_layout_dedup.rs | 4 ---- tests/tests/buffer.rs | 4 ---- tests/tests/compute_pass_ownership.rs | 1 - tests/tests/device.rs | 2 -- tests/tests/mem_leaks.rs | 2 -- tests/tests/partially_bounded_arrays/mod.rs | 1 - tests/tests/pipeline_cache.rs | 1 - tests/tests/regression/issue_3457.rs | 1 - tests/tests/regression/issue_5553.rs | 1 - tests/tests/render_pass_ownership.rs | 1 - tests/tests/shader/mod.rs | 1 - tests/tests/shader/zero_init_workgroup_mem.rs | 2 -- tests/tests/subgroup_operations/mod.rs | 1 - tests/tests/vertex_formats/mod.rs | 2 -- tests/tests/vertex_indices/mod.rs | 2 -- 38 files changed, 76 deletions(-) diff --git a/benches/benches/computepass.rs b/benches/benches/computepass.rs index 30f1421be42..7e08f5214fa 100644 --- a/benches/benches/computepass.rs +++ b/benches/benches/computepass.rs @@ -224,9 +224,7 @@ impl ComputepassState { let pipeline_layout = device_state.device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); @@ -318,9 +316,7 @@ impl ComputepassState { let bindless_pipeline_layout = device_state.device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bindless_bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index bd38ea0db3c..bea79d45bef 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -132,9 +132,7 @@ impl RenderpassState { let pipeline_layout = device_state.device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); @@ -261,9 +259,7 @@ impl RenderpassState { let bindless_pipeline_layout = device_state.device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bindless_bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); diff --git a/deno_webgpu/binding.rs b/deno_webgpu/binding.rs index 2fd6cf0a79b..3b47cd60406 100644 --- a/deno_webgpu/binding.rs +++ b/deno_webgpu/binding.rs @@ -223,7 +223,6 @@ pub fn op_webgpu_create_pipeline_layout( let descriptor = wgpu_core::binding_model::PipelineLayoutDescriptor::builder() .label(label) .bind_group_layouts(Cow::from(bind_group_layouts)) - .push_constant_ranges(Default::default()) .build(); gfx_put!(instance.device_create_pipeline_layout( diff --git a/examples/src/boids/mod.rs b/examples/src/boids/mod.rs index 48281970ef5..8f78c4c39e4 100644 --- a/examples/src/boids/mod.rs +++ b/examples/src/boids/mod.rs @@ -108,7 +108,6 @@ impl crate::framework::Example for Example { &wgpu::PipelineLayoutDescriptor::builder() .label("compute") .bind_group_layouts(&[&compute_bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); @@ -118,7 +117,6 @@ impl crate::framework::Example for Example { &wgpu::PipelineLayoutDescriptor::builder() .label("render") .bind_group_layouts(&[]) - .push_constant_ranges(&[]) .build(), ); diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index bcaf0f0f9ef..b546f44efaa 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -203,9 +203,7 @@ impl crate::framework::Example for Example { }); let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&global_bind_group_layout, &local_bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index 2f98e9be1d9..4923ac4b2b9 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -76,9 +76,7 @@ impl crate::framework::Example for Example { ) -> Self { let pipeline_layout_empty = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[]) - .push_constant_ranges(&[]) .build(), ); @@ -195,9 +193,7 @@ impl crate::framework::Example for Example { let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); let shader = device.create_shader_module(wgpu::include_wgsl!("upscale.wgsl")); diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index 88749aadf32..aaaacd6d2fc 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -157,9 +157,7 @@ impl crate::framework::Example for Example { }); let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); diff --git a/examples/src/hello_synchronization/mod.rs b/examples/src/hello_synchronization/mod.rs index e2e0c24651b..f97a27aaf65 100644 --- a/examples/src/hello_synchronization/mod.rs +++ b/examples/src/hello_synchronization/mod.rs @@ -95,9 +95,7 @@ async fn execute( let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); let patient_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs index 1592488c74c..92028554a4f 100644 --- a/examples/src/hello_triangle/mod.rs +++ b/examples/src/hello_triangle/mod.rs @@ -47,9 +47,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) { let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[]) - .push_constant_ranges(&[]) .build(), ); diff --git a/examples/src/hello_workgroups/mod.rs b/examples/src/hello_workgroups/mod.rs index 870430ce39b..457154fee64 100644 --- a/examples/src/hello_workgroups/mod.rs +++ b/examples/src/hello_workgroups/mod.rs @@ -102,9 +102,7 @@ async fn run() { let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index 1db7e3ec2c2..bf11c44eaf6 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -156,9 +156,7 @@ impl crate::framework::Example for Example { let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[]) - .push_constant_ranges(&[]) .build(), ); diff --git a/examples/src/repeated_compute/mod.rs b/examples/src/repeated_compute/mod.rs index beae61f3369..8049f110aa0 100644 --- a/examples/src/repeated_compute/mod.rs +++ b/examples/src/repeated_compute/mod.rs @@ -233,9 +233,7 @@ impl WgpuContext { let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index 4d42bcd65d0..7a70c69309b 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -466,7 +466,6 @@ impl crate::framework::Example for Example { &wgpu::PipelineLayoutDescriptor::builder() .label("shadow") .bind_group_layouts(&[&bind_group_layout, &local_bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); @@ -584,7 +583,6 @@ impl crate::framework::Example for Example { &wgpu::PipelineLayoutDescriptor::builder() .label("main") .bind_group_layouts(&[&bind_group_layout, &local_bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index d148713f0f4..b11193833e1 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -182,9 +182,7 @@ impl crate::framework::Example for Example { let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index f5cbe98dd0c..3dc8678dad1 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -92,9 +92,7 @@ impl crate::framework::Example for Example { }); let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index fa297834a91..ab99c2f0531 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -48,9 +48,7 @@ impl crate::framework::Example for Example { let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[]) - .push_constant_ranges(&[]) .build(), ); diff --git a/examples/src/storage_texture/mod.rs b/examples/src/storage_texture/mod.rs index e1fee557d9e..b6ae6937217 100644 --- a/examples/src/storage_texture/mod.rs +++ b/examples/src/storage_texture/mod.rs @@ -89,9 +89,7 @@ async fn run(_path: Option) { let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index e9ef540c16b..deeece0cb11 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -305,7 +305,6 @@ impl crate::framework::Example for Example { &wgpu::PipelineLayoutDescriptor::builder() .label("main") .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); diff --git a/examples/src/timestamp_queries/mod.rs b/examples/src/timestamp_queries/mod.rs index cbd5845448e..ed5d2110550 100644 --- a/examples/src/timestamp_queries/mod.rs +++ b/examples/src/timestamp_queries/mod.rs @@ -344,9 +344,7 @@ fn render_pass( let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[]) - .push_constant_ranges(&[]) .build(), ); diff --git a/examples/src/uniform_values/mod.rs b/examples/src/uniform_values/mod.rs index 8be0757c98d..39002614f7c 100644 --- a/examples/src/uniform_values/mod.rs +++ b/examples/src/uniform_values/mod.rs @@ -161,10 +161,8 @@ impl WgpuContext { let pipeline_layout = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) // (4) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index 3436ffb21a3..68355b2fff5 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -432,7 +432,6 @@ impl crate::framework::Example for Example { &wgpu::PipelineLayoutDescriptor::builder() .label("water") .bind_group_layouts(&[&water_bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); @@ -440,7 +439,6 @@ impl crate::framework::Example for Example { &wgpu::PipelineLayoutDescriptor::builder() .label("terrain") .bind_group_layouts(&[&terrain_bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/src/image.rs b/tests/src/image.rs index ed5d819c75d..f3e47bb4f0c 100644 --- a/tests/src/image.rs +++ b/tests/src/image.rs @@ -343,9 +343,7 @@ fn copy_via_compute( let pll = device.create_pipeline_layout( &PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bgl]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/bgra8unorm_storage.rs b/tests/tests/bgra8unorm_storage.rs index df3da7c8a00..ed23ce91fa4 100644 --- a/tests/tests/bgra8unorm_storage.rs +++ b/tests/tests/bgra8unorm_storage.rs @@ -80,9 +80,7 @@ static BGRA8_UNORM_STORAGE: GpuTestConfiguration = GpuTestConfiguration::new() let pl = device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bgl]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/bind_group_layout_dedup.rs b/tests/tests/bind_group_layout_dedup.rs index 4181f824c8a..8354b2ba6ad 100644 --- a/tests/tests/bind_group_layout_dedup.rs +++ b/tests/tests/bind_group_layout_dedup.rs @@ -61,9 +61,7 @@ async fn bgl_dedupe(ctx: TestingContext) { let pipeline_layout = ctx.device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bgl_1b]) - .push_constant_ranges(&[]) .build(), ); @@ -121,9 +119,7 @@ fn bgl_dedupe_with_dropped_user_handle(ctx: TestingContext) { let pipeline_layout = ctx.device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bgl_1]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/buffer.rs b/tests/tests/buffer.rs index 67aa68edcb6..4cfc5609b34 100644 --- a/tests/tests/buffer.rs +++ b/tests/tests/buffer.rs @@ -212,9 +212,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_LAYOUT: GpuTestConfiguration = GpuTestConfigu let pipeline_layout = ctx .device .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor ::builder() - .label(None) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build() ); @@ -287,9 +285,7 @@ static MINIMUM_BUFFER_BINDING_SIZE_DISPATCH: GpuTestConfiguration = GpuTestConfi let pipeline_layout = ctx .device .create_pipeline_layout(&wgpu::PipelineLayoutDescriptor ::builder() - .label(None) .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build() ); diff --git a/tests/tests/compute_pass_ownership.rs b/tests/tests/compute_pass_ownership.rs index ca3a8b4ce76..0c4b71a0749 100644 --- a/tests/tests/compute_pass_ownership.rs +++ b/tests/tests/compute_pass_ownership.rs @@ -307,7 +307,6 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { &wgpu::PipelineLayoutDescriptor::builder() .label("pipeline_layout") .bind_group_layouts(&[&bgl]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/device.rs b/tests/tests/device.rs index a401730707e..3cdab648e26 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -463,9 +463,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne || { let _ = ctx.device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[]) - .push_constant_ranges(&[]) .build(), ); }, diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index 662774697f3..afcdd161535 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -75,9 +75,7 @@ async fn draw_test_with_reports( let ppl = ctx.device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bgl]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/partially_bounded_arrays/mod.rs b/tests/tests/partially_bounded_arrays/mod.rs index 80e43f7bb1e..d15451300d1 100644 --- a/tests/tests/partially_bounded_arrays/mod.rs +++ b/tests/tests/partially_bounded_arrays/mod.rs @@ -58,7 +58,6 @@ static PARTIALLY_BOUNDED_ARRAY: GpuTestConfiguration = GpuTestConfiguration::new &wgpu::PipelineLayoutDescriptor::builder() .label("main") .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/pipeline_cache.rs b/tests/tests/pipeline_cache.rs index 2106d07d30f..1d59c899c69 100644 --- a/tests/tests/pipeline_cache.rs +++ b/tests/tests/pipeline_cache.rs @@ -93,7 +93,6 @@ async fn pipeline_cache_test(ctx: TestingContext) { &wgpu::PipelineLayoutDescriptor::builder() .label("pipeline_layout") .bind_group_layouts(&[&bgl]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index 780d512ddca..4a3a17f9821 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -40,7 +40,6 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = &PipelineLayoutDescriptor::builder() .label("Pipeline Layout") .bind_group_layouts(&[]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index dce80a74493..716f4585fd7 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -20,7 +20,6 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = &PipelineLayoutDescriptor::builder() .label("Pipeline Layout") .bind_group_layouts(&[]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index 33e17bd0cc5..9cdf8b42594 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -443,7 +443,6 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { &wgpu::PipelineLayoutDescriptor::builder() .label("pipeline_layout") .bind_group_layouts(&[&bgl]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/shader/mod.rs b/tests/tests/shader/mod.rs index 446fae566df..7ae133c4e15 100644 --- a/tests/tests/shader/mod.rs +++ b/tests/tests/shader/mod.rs @@ -265,7 +265,6 @@ async fn shader_input_output_test( let pll = ctx.device.create_pipeline_layout( &PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bgl]) .push_constant_ranges(match storage_type { InputStorageType::PushConstant => &[PushConstantRange { diff --git a/tests/tests/shader/zero_init_workgroup_mem.rs b/tests/tests/shader/zero_init_workgroup_mem.rs index 62f589b94de..6fccfe1138a 100644 --- a/tests/tests/shader/zero_init_workgroup_mem.rs +++ b/tests/tests/shader/zero_init_workgroup_mem.rs @@ -63,9 +63,7 @@ static ZERO_INIT_WORKGROUP_MEMORY: GpuTestConfiguration = GpuTestConfiguration:: let pll = ctx.device.create_pipeline_layout( &PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bgl]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/subgroup_operations/mod.rs b/tests/tests/subgroup_operations/mod.rs index 7a5b10929af..106cd05ff94 100644 --- a/tests/tests/subgroup_operations/mod.rs +++ b/tests/tests/subgroup_operations/mod.rs @@ -62,7 +62,6 @@ static SUBGROUP_OPERATIONS: GpuTestConfiguration = GpuTestConfiguration::new() &wgpu::PipelineLayoutDescriptor::builder() .label("main") .bind_group_layouts(&[&bind_group_layout]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 03d6e854ea7..f3c4f423c4d 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -203,9 +203,7 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { let ppl = ctx.device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bgl]) - .push_constant_ranges(&[]) .build(), ); diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index 583b0d01bc3..df0947489ae 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -247,9 +247,7 @@ async fn vertex_index_common(ctx: TestingContext) { let ppl = ctx.device.create_pipeline_layout( &wgpu::PipelineLayoutDescriptor::builder() - .label(None) .bind_group_layouts(&[&bgl]) - .push_constant_ranges(&[]) .build(), ); From 5bea6ace3bf4bcb43e13264641a8f2b61ae9c276 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 20:47:12 -0400 Subject: [PATCH 11/33] refactor: replace manual `MultisampleState::default()` --- benches/benches/renderpass.rs | 4 ++-- examples/src/boids/mod.rs | 2 +- examples/src/bunnymark/mod.rs | 2 +- examples/src/conservative_raster/mod.rs | 8 ++++---- examples/src/cube/mod.rs | 4 ++-- examples/src/hello_triangle/mod.rs | 2 +- examples/src/mipmap/mod.rs | 4 ++-- examples/src/render_to_texture/mod.rs | 2 +- examples/src/shadow/mod.rs | 4 ++-- examples/src/skybox/mod.rs | 4 ++-- examples/src/srgb_blend/mod.rs | 2 +- examples/src/stencil_triangles/mod.rs | 4 ++-- examples/src/texture_arrays/mod.rs | 2 +- examples/src/timestamp_queries/mod.rs | 2 +- examples/src/uniform_values/mod.rs | 2 +- examples/src/water/mod.rs | 4 ++-- tests/tests/device.rs | 4 ++-- tests/tests/mem_leaks.rs | 2 +- tests/tests/nv12_texture/mod.rs | 2 +- tests/tests/occlusion_query/mod.rs | 2 +- tests/tests/regression/issue_3349.rs | 2 +- tests/tests/regression/issue_3457.rs | 4 ++-- tests/tests/regression/issue_4485.rs | 2 +- tests/tests/regression/issue_4514.rs | 2 +- tests/tests/regression/issue_5553.rs | 2 +- tests/tests/scissor_tests/mod.rs | 2 +- tests/tests/shader_primitive_index/mod.rs | 2 +- tests/tests/shader_view_format/mod.rs | 2 +- tests/tests/vertex_formats/mod.rs | 2 +- tests/tests/vertex_indices/mod.rs | 2 +- wgpu-hal/examples/halmark/main.rs | 2 +- 31 files changed, 43 insertions(+), 43 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index bea79d45bef..96335bff750 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -194,7 +194,7 @@ impl RenderpassState { conservative: false, }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), fragment: Some(wgpu::FragmentState { module: &sm, entry_point: Some("fs_main"), @@ -283,7 +283,7 @@ impl RenderpassState { conservative: false, }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), fragment: Some(wgpu::FragmentState { module: &bindless_shader_module, entry_point: Some("fs_main"), diff --git a/examples/src/boids/mod.rs b/examples/src/boids/mod.rs index 8f78c4c39e4..709eaa1c4fe 100644 --- a/examples/src/boids/mod.rs +++ b/examples/src/boids/mod.rs @@ -148,7 +148,7 @@ impl crate::framework::Example for Example { }), primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index b546f44efaa..70045df57e2 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -232,7 +232,7 @@ impl crate::framework::Example for Example { ..wgpu::PrimitiveState::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index 4923ac4b2b9..5259106f396 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -104,7 +104,7 @@ impl crate::framework::Example for Example { ..Default::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); @@ -127,7 +127,7 @@ impl crate::framework::Example for Example { }), primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); @@ -158,7 +158,7 @@ impl crate::framework::Example for Example { ..Default::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }), @@ -215,7 +215,7 @@ impl crate::framework::Example for Example { }), primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }), diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index aaaacd6d2fc..5ab5eb36468 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -252,7 +252,7 @@ impl crate::framework::Example for Example { ..Default::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); @@ -294,7 +294,7 @@ impl crate::framework::Example for Example { ..Default::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs index 92028554a4f..0daa2080e4c 100644 --- a/examples/src/hello_triangle/mod.rs +++ b/examples/src/hello_triangle/mod.rs @@ -71,7 +71,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) { }), primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/examples/src/mipmap/mod.rs b/examples/src/mipmap/mod.rs index 22e6e81bd92..a232498cf2b 100644 --- a/examples/src/mipmap/mod.rs +++ b/examples/src/mipmap/mod.rs @@ -103,7 +103,7 @@ impl Example { ..Default::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); @@ -302,7 +302,7 @@ impl crate::framework::Example for Example { ..Default::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/examples/src/render_to_texture/mod.rs b/examples/src/render_to_texture/mod.rs index 2a0ff579fd3..bb64208c5fe 100644 --- a/examples/src/render_to_texture/mod.rs +++ b/examples/src/render_to_texture/mod.rs @@ -66,7 +66,7 @@ async fn run(_path: Option) { }), primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index 7a70c69309b..bd849a337d0 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -517,7 +517,7 @@ impl crate::framework::Example for Example { clamp: 0.0, }, }), - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); @@ -653,7 +653,7 @@ impl crate::framework::Example for Example { stencil: wgpu::StencilState::default(), bias: wgpu::DepthBiasState::default(), }), - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index b11193833e1..fdeb5c857c4 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -213,7 +213,7 @@ impl crate::framework::Example for Example { stencil: wgpu::StencilState::default(), bias: wgpu::DepthBiasState::default(), }), - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); @@ -247,7 +247,7 @@ impl crate::framework::Example for Example { stencil: wgpu::StencilState::default(), bias: wgpu::DepthBiasState::default(), }), - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index 3dc8678dad1..9a6a5ae5a80 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -146,7 +146,7 @@ impl crate::framework::Example for Example { ..Default::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index ab99c2f0531..9bf0ba29d3c 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -100,7 +100,7 @@ impl crate::framework::Example for Example { }, bias: Default::default(), }), - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); @@ -136,7 +136,7 @@ impl crate::framework::Example for Example { }, bias: Default::default(), }), - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index deeece0cb11..9854b93e405 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -334,7 +334,7 @@ impl crate::framework::Example for Example { ..Default::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None }); diff --git a/examples/src/timestamp_queries/mod.rs b/examples/src/timestamp_queries/mod.rs index ed5d2110550..586cbf0c383 100644 --- a/examples/src/timestamp_queries/mod.rs +++ b/examples/src/timestamp_queries/mod.rs @@ -365,7 +365,7 @@ fn render_pass( }), primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/examples/src/uniform_values/mod.rs b/examples/src/uniform_values/mod.rs index 39002614f7c..f76e3932294 100644 --- a/examples/src/uniform_values/mod.rs +++ b/examples/src/uniform_values/mod.rs @@ -186,7 +186,7 @@ impl WgpuContext { }), primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index 68355b2fff5..4ee435621ce 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -570,7 +570,7 @@ impl crate::framework::Example for Example { bias: wgpu::DepthBiasState::default(), }), // No multisampling is used. - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, // No pipeline caching is used cache: None, @@ -608,7 +608,7 @@ impl crate::framework::Example for Example { stencil: wgpu::StencilState::default(), bias: wgpu::DepthBiasState::default(), }), - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None }); diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 3cdab648e26..0d79def5376 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -515,7 +515,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne }, primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), fragment: None, multiview: None, cache: None, @@ -794,7 +794,7 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf }, primitive: wgt::PrimitiveState::default(), depth_stencil: None, - multisample: wgt::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index afcdd161535..20ad1f4482c 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -99,7 +99,7 @@ async fn draw_test_with_reports( }, primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/tests/tests/nv12_texture/mod.rs b/tests/tests/nv12_texture/mod.rs index 10c7fc7136e..8f72cbda775 100644 --- a/tests/tests/nv12_texture/mod.rs +++ b/tests/tests/nv12_texture/mod.rs @@ -39,7 +39,7 @@ static NV12_TEXTURE_CREATION_SAMPLING: GpuTestConfiguration = GpuTestConfigurati ..Default::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/tests/tests/occlusion_query/mod.rs b/tests/tests/occlusion_query/mod.rs index 6c3e1f25b04..c95a0f3a29e 100644 --- a/tests/tests/occlusion_query/mod.rs +++ b/tests/tests/occlusion_query/mod.rs @@ -44,7 +44,7 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new() stencil: wgpu::StencilState::default(), bias: wgpu::DepthBiasState::default(), }), - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index 5b3b36736ed..035555ce38b 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -117,7 +117,7 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { }), primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index 4a3a17f9821..a8e791b3f47 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -67,7 +67,7 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = }, primitive: PrimitiveState::default(), depth_stencil: None, - multisample: MultisampleState::default(), + multisample: Default::default(), fragment: Some(FragmentState { module: &module, entry_point: Some("double_buffer_frag"), @@ -99,7 +99,7 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = }, primitive: PrimitiveState::default(), depth_stencil: None, - multisample: MultisampleState::default(), + multisample: Default::default(), fragment: Some(FragmentState { module: &module, entry_point: Some("single_buffer_frag"), diff --git a/tests/tests/regression/issue_4485.rs b/tests/tests/regression/issue_4485.rs index 9e4fda8f865..088c3cfd006 100644 --- a/tests/tests/regression/issue_4485.rs +++ b/tests/tests/regression/issue_4485.rs @@ -49,7 +49,7 @@ async fn test_impl(ctx: &TestingContext) { }, primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/tests/tests/regression/issue_4514.rs b/tests/tests/regression/issue_4514.rs index 95a2bfb5fdd..83df8fbfa4f 100644 --- a/tests/tests/regression/issue_4514.rs +++ b/tests/tests/regression/issue_4514.rs @@ -49,7 +49,7 @@ async fn test_impl(ctx: &TestingContext) { }, primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index 716f4585fd7..368c006972e 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -36,7 +36,7 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = }, primitive: PrimitiveState::default(), depth_stencil: None, - multisample: MultisampleState::default(), + multisample: Default::default(), fragment: Some(FragmentState { module: &module, entry_point: Some("fs_main"), diff --git a/tests/tests/scissor_tests/mod.rs b/tests/tests/scissor_tests/mod.rs index e96e0da20ac..902a0b02e0c 100644 --- a/tests/tests/scissor_tests/mod.rs +++ b/tests/tests/scissor_tests/mod.rs @@ -47,7 +47,7 @@ async fn scissor_test_impl( }, primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index 099878483b1..65b07f54754 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -135,7 +135,7 @@ async fn pulling_common( }, primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/tests/tests/shader_view_format/mod.rs b/tests/tests/shader_view_format/mod.rs index 047b216b639..9f2d83eb6e2 100644 --- a/tests/tests/shader_view_format/mod.rs +++ b/tests/tests/shader_view_format/mod.rs @@ -104,7 +104,7 @@ async fn reinterpret( ..Default::default() }, depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), multiview: None, cache: None, }); diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index f3c4f423c4d..32cd5e9229f 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -245,7 +245,7 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { }, primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fragment_main"), diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index df0947489ae..fe2ad6a512f 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -262,7 +262,7 @@ async fn vertex_index_common(ctx: TestingContext) { }, primitive: wgpu::PrimitiveState::default(), depth_stencil: None, - multisample: wgpu::MultisampleState::default(), + multisample: Default::default(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 8ab7f1cb470..42ad74cfdd1 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -272,7 +272,7 @@ impl Example { ..wgt::PrimitiveState::default() }, depth_stencil: None, - multisample: wgt::MultisampleState::default(), + multisample: Default::default(), color_targets: &[Some(wgt::ColorTargetState { format: surface_config.format, blend: Some(wgt::BlendState::ALPHA_BLENDING), From 9923d1ed8ca265ea8e0e8b25e289b7547d0723b4 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 9 Sep 2024 13:33:37 -0400 Subject: [PATCH 12/33] refactor: prefer default values for `MultisampleState` via `..Default::default()` --- tests/tests/render_pass_ownership.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index 9cdf8b42594..85fb34164a9 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -524,8 +524,7 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { }), multisample: wgpu::MultisampleState { count: target_msaa, - mask: !0, - alpha_to_coverage_enabled: false, + ..Default::default() }, multiview: None, cache: None, From 7cb3c16aeba477f7f03693b446c9642bbb1632d4 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 21:38:56 -0400 Subject: [PATCH 13/33] refactor!: replace manual `PrimitiveState::default()` --- examples/src/boids/mod.rs | 2 +- examples/src/conservative_raster/mod.rs | 4 ++-- examples/src/hello_triangle/mod.rs | 2 +- examples/src/mipmap/mod.rs | 5 +---- examples/src/render_to_texture/mod.rs | 2 +- examples/src/texture_arrays/mod.rs | 5 +---- examples/src/timestamp_queries/mod.rs | 2 +- examples/src/uniform_values/mod.rs | 2 +- tests/tests/device.rs | 4 ++-- tests/tests/mem_leaks.rs | 2 +- tests/tests/occlusion_query/mod.rs | 2 +- tests/tests/regression/issue_3349.rs | 2 +- tests/tests/regression/issue_3457.rs | 4 ++-- tests/tests/regression/issue_4485.rs | 2 +- tests/tests/regression/issue_4514.rs | 2 +- tests/tests/regression/issue_5553.rs | 2 +- tests/tests/scissor_tests/mod.rs | 2 +- tests/tests/shader_primitive_index/mod.rs | 2 +- tests/tests/vertex_formats/mod.rs | 2 +- tests/tests/vertex_indices/mod.rs | 2 +- wgpu-hal/src/gles/command.rs | 2 +- 21 files changed, 24 insertions(+), 30 deletions(-) diff --git a/examples/src/boids/mod.rs b/examples/src/boids/mod.rs index 709eaa1c4fe..970fcb32f60 100644 --- a/examples/src/boids/mod.rs +++ b/examples/src/boids/mod.rs @@ -146,7 +146,7 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], }), - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index 5259106f396..3c010dc9de3 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -125,7 +125,7 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), targets: &[Some(RENDER_TARGET_FORMAT.into())], }), - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), multiview: None, @@ -213,7 +213,7 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], }), - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs index 0daa2080e4c..eeb20a3ba0c 100644 --- a/examples/src/hello_triangle/mod.rs +++ b/examples/src/hello_triangle/mod.rs @@ -69,7 +69,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) { compilation_options: Default::default(), targets: &[Some(swapchain_format.into())], }), - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/examples/src/mipmap/mod.rs b/examples/src/mipmap/mod.rs index a232498cf2b..9356416e446 100644 --- a/examples/src/mipmap/mod.rs +++ b/examples/src/mipmap/mod.rs @@ -98,10 +98,7 @@ impl Example { compilation_options: Default::default(), targets: &[Some(TEXTURE_FORMAT.into())], }), - primitive: wgpu::PrimitiveState { - topology: wgpu::PrimitiveTopology::TriangleList, - ..Default::default() - }, + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/examples/src/render_to_texture/mod.rs b/examples/src/render_to_texture/mod.rs index bb64208c5fe..670c1afe973 100644 --- a/examples/src/render_to_texture/mod.rs +++ b/examples/src/render_to_texture/mod.rs @@ -64,7 +64,7 @@ async fn run(_path: Option) { compilation_options: Default::default(), targets: &[Some(wgpu::TextureFormat::Rgba8UnormSrgb.into())], }), - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index 9854b93e405..e03780ae348 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -329,10 +329,7 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], }), - primitive: wgpu::PrimitiveState { - front_face: wgpu::FrontFace::Ccw, - ..Default::default() - }, + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/examples/src/timestamp_queries/mod.rs b/examples/src/timestamp_queries/mod.rs index 586cbf0c383..8e440b2d24b 100644 --- a/examples/src/timestamp_queries/mod.rs +++ b/examples/src/timestamp_queries/mod.rs @@ -363,7 +363,7 @@ fn render_pass( compilation_options: Default::default(), targets: &[Some(format.into())], }), - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/examples/src/uniform_values/mod.rs b/examples/src/uniform_values/mod.rs index f76e3932294..c57e33d629f 100644 --- a/examples/src/uniform_values/mod.rs +++ b/examples/src/uniform_values/mod.rs @@ -184,7 +184,7 @@ impl WgpuContext { compilation_options: Default::default(), targets: &[Some(swapchain_format.into())], }), - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 0d79def5376..7539b6ccf5f 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -513,7 +513,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne compilation_options: Default::default(), buffers: &[], }, - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), fragment: None, @@ -792,7 +792,7 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf compilation_options: Default::default(), buffers: &[], }, - primitive: wgt::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index 20ad1f4482c..43823734653 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -97,7 +97,7 @@ async fn draw_test_with_reports( entry_point: Some("vs_main_builtin"), compilation_options: Default::default(), }, - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), fragment: Some(wgpu::FragmentState { diff --git a/tests/tests/occlusion_query/mod.rs b/tests/tests/occlusion_query/mod.rs index c95a0f3a29e..05df4b17542 100644 --- a/tests/tests/occlusion_query/mod.rs +++ b/tests/tests/occlusion_query/mod.rs @@ -36,7 +36,7 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new() buffers: &[], }, fragment: None, - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth32Float, depth_write_enabled: true, diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index 035555ce38b..ac9f9438f99 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -115,7 +115,7 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { write_mask: wgpu::ColorWrites::ALL, })], }), - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index a8e791b3f47..316466bedd8 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -65,7 +65,7 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = }, ], }, - primitive: PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), fragment: Some(FragmentState { @@ -97,7 +97,7 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = attributes: &vertex_attr_array![0 => Float32x4], }], }, - primitive: PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), fragment: Some(FragmentState { diff --git a/tests/tests/regression/issue_4485.rs b/tests/tests/regression/issue_4485.rs index 088c3cfd006..0f8803c7f54 100644 --- a/tests/tests/regression/issue_4485.rs +++ b/tests/tests/regression/issue_4485.rs @@ -47,7 +47,7 @@ async fn test_impl(ctx: &TestingContext) { compilation_options: Default::default(), buffers: &[], }, - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), fragment: Some(wgpu::FragmentState { diff --git a/tests/tests/regression/issue_4514.rs b/tests/tests/regression/issue_4514.rs index 83df8fbfa4f..6f07e41e18b 100644 --- a/tests/tests/regression/issue_4514.rs +++ b/tests/tests/regression/issue_4514.rs @@ -47,7 +47,7 @@ async fn test_impl(ctx: &TestingContext) { compilation_options: Default::default(), buffers: &[], }, - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), fragment: Some(wgpu::FragmentState { diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index 368c006972e..f76d81cf623 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -34,7 +34,7 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = compilation_options: Default::default(), buffers: &[], }, - primitive: PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), fragment: Some(FragmentState { diff --git a/tests/tests/scissor_tests/mod.rs b/tests/tests/scissor_tests/mod.rs index 902a0b02e0c..a61056bded4 100644 --- a/tests/tests/scissor_tests/mod.rs +++ b/tests/tests/scissor_tests/mod.rs @@ -45,7 +45,7 @@ async fn scissor_test_impl( compilation_options: Default::default(), buffers: &[], }, - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), fragment: Some(wgpu::FragmentState { diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index 65b07f54754..6aeec92afdf 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -133,7 +133,7 @@ async fn pulling_common( }], }], }, - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), fragment: Some(wgpu::FragmentState { diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 32cd5e9229f..3a60a02d9f3 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -243,7 +243,7 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { entry_point: Some(test.entry_point), compilation_options: Default::default(), }, - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), fragment: Some(wgpu::FragmentState { diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index fe2ad6a512f..f90c4560665 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -260,7 +260,7 @@ async fn vertex_index_common(ctx: TestingContext) { entry_point: Some("vs_main_builtin"), compilation_options: Default::default(), }, - primitive: wgpu::PrimitiveState::default(), + primitive: Default::default(), depth_stencil: None, multisample: Default::default(), fragment: Some(wgpu::FragmentState { diff --git a/wgpu-hal/src/gles/command.rs b/wgpu-hal/src/gles/command.rs index 2df3c1a991b..37832afde4b 100644 --- a/wgpu-hal/src/gles/command.rs +++ b/wgpu-hal/src/gles/command.rs @@ -698,7 +698,7 @@ impl crate::CommandEncoder for super::CommandEncoder { .push(C::UnsetVertexAttribute(vat.location)); } self.state.vertex_attributes.clear(); - self.state.primitive = super::PrimitiveState::default(); + self.state.primitive = Default::default(); if let Some(query) = self.state.end_of_pass_timestamp.take() { self.cmd_buffer.commands.push(C::TimestampQuery(query)); From 85683d0913927f7f3994ca14028e8ecfc768ada8 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 18:16:35 -0400 Subject: [PATCH 14/33] refactor!: give `PrimitiveState` a builder API --- benches/benches/renderpass.rs | 83 ++++++++++++------------- examples/src/bunnymark/mod.rs | 9 ++- examples/src/conservative_raster/mod.rs | 14 ++--- examples/src/cube/mod.rs | 18 +++--- examples/src/mipmap/mod.rs | 11 ++-- examples/src/msaa_line/mod.rs | 9 ++- examples/src/shadow/mod.rs | 28 ++++----- examples/src/skybox/mod.rs | 14 ++--- examples/src/srgb_blend/mod.rs | 7 +-- examples/src/water/mod.rs | 19 +++--- tests/tests/nv12_texture/mod.rs | 9 ++- tests/tests/render_pass_ownership.rs | 9 ++- tests/tests/shader_view_format/mod.rs | 7 +-- wgpu-hal/examples/halmark/main.rs | 7 +-- wgpu-types/src/lib.rs | 7 ++- 15 files changed, 118 insertions(+), 133 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index 96335bff750..fae51657685 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -184,15 +184,10 @@ impl RenderpassState { buffers: &vertex_buffer_layouts, compilation_options: wgpu::PipelineCompilationOptions::default(), }, - primitive: wgpu::PrimitiveState { - topology: wgpu::PrimitiveTopology::TriangleList, - strip_index_format: None, - front_face: wgpu::FrontFace::Cw, - cull_mode: Some(wgpu::Face::Back), - polygon_mode: wgpu::PolygonMode::Fill, - unclipped_depth: false, - conservative: false, - }, + primitive: wgpu::PrimitiveState::builder() + .front_face(wgpu::FrontFace::Cw) + .cull_mode(wgpu::Face::Back) + .build(), depth_stencil: None, multisample: Default::default(), fragment: Some(wgpu::FragmentState { @@ -263,41 +258,43 @@ impl RenderpassState { .build(), ); - bindless_pipeline = Some(device_state.device.create_render_pipeline( - &wgpu::RenderPipelineDescriptor { - label: None, - layout: Some(&bindless_pipeline_layout), - vertex: wgpu::VertexState { - module: &bindless_shader_module, - entry_point: Some("vs_main"), - buffers: &vertex_buffer_layouts, - compilation_options: wgpu::PipelineCompilationOptions::default(), - }, - primitive: wgpu::PrimitiveState { - topology: wgpu::PrimitiveTopology::TriangleList, - strip_index_format: None, - front_face: wgpu::FrontFace::Cw, - cull_mode: Some(wgpu::Face::Back), - polygon_mode: wgpu::PolygonMode::Fill, - unclipped_depth: false, - conservative: false, - }, - depth_stencil: None, - multisample: Default::default(), - fragment: Some(wgpu::FragmentState { - module: &bindless_shader_module, - entry_point: Some("fs_main"), - targets: &[Some(wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba8UnormSrgb, - blend: None, - write_mask: wgpu::ColorWrites::ALL, - })], - compilation_options: wgpu::PipelineCompilationOptions::default(), + bindless_pipeline = Some( + device_state + .device + .create_render_pipeline(&wgpu::RenderPipelineDescriptor { + label: None, + layout: Some(&bindless_pipeline_layout), + vertex: wgpu::VertexState { + module: &bindless_shader_module, + entry_point: Some("vs_main"), + buffers: &vertex_buffer_layouts, + compilation_options: wgpu::PipelineCompilationOptions::default(), + }, + primitive: wgpu::PrimitiveState::builder() + .topology(wgpu::PrimitiveTopology::TriangleList) + .maybe_strip_index_format(None) + .front_face(wgpu::FrontFace::Cw) + .cull_mode(wgpu::Face::Back) + .polygon_mode(wgpu::PolygonMode::Fill) + .unclipped_depth(false) + .conservative(false) + .build(), + depth_stencil: None, + multisample: Default::default(), + fragment: Some(wgpu::FragmentState { + module: &bindless_shader_module, + entry_point: Some("fs_main"), + targets: &[Some(wgpu::ColorTargetState { + format: wgpu::TextureFormat::Rgba8UnormSrgb, + blend: None, + write_mask: wgpu::ColorWrites::ALL, + })], + compilation_options: wgpu::PipelineCompilationOptions::default(), + }), + multiview: None, + cache: None, }), - multiview: None, - cache: None, - }, - )); + ); } Self { diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index 70045df57e2..13b0dc60dfb 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -226,11 +226,10 @@ impl crate::framework::Example for Example { write_mask: wgpu::ColorWrites::default(), })], }), - primitive: wgpu::PrimitiveState { - topology: wgpu::PrimitiveTopology::TriangleStrip, - strip_index_format: Some(wgpu::IndexFormat::Uint16), - ..wgpu::PrimitiveState::default() - }, + primitive: wgpu::PrimitiveState::builder() + .topology(wgpu::PrimitiveTopology::TriangleStrip) + .strip_index_format(wgpu::IndexFormat::Uint16) + .build(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index 3c010dc9de3..16e359b1e45 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -99,10 +99,7 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), targets: &[Some(RENDER_TARGET_FORMAT.into())], }), - primitive: wgpu::PrimitiveState { - conservative: true, - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder().conservative(true).build(), depth_stencil: None, multisample: Default::default(), multiview: None, @@ -152,11 +149,10 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], }), - primitive: wgpu::PrimitiveState { - polygon_mode: wgpu::PolygonMode::Line, - topology: wgpu::PrimitiveTopology::LineStrip, - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .polygon_mode(wgpu::PolygonMode::Line) + .topology(wgpu::PrimitiveTopology::LineStrip) + .build(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index 5ab5eb36468..f5b1b545271 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -247,10 +247,9 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], }), - primitive: wgpu::PrimitiveState { - cull_mode: Some(wgpu::Face::Back), - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .cull_mode(wgpu::Face::Back) + .build(), depth_stencil: None, multisample: Default::default(), multiview: None, @@ -287,12 +286,11 @@ impl crate::framework::Example for Example { write_mask: wgpu::ColorWrites::ALL, })], }), - primitive: wgpu::PrimitiveState { - front_face: wgpu::FrontFace::Ccw, - cull_mode: Some(wgpu::Face::Back), - polygon_mode: wgpu::PolygonMode::Line, - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .front_face(wgpu::FrontFace::Ccw) + .cull_mode(wgpu::Face::Back) + .polygon_mode(wgpu::PolygonMode::Line) + .build(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/examples/src/mipmap/mod.rs b/examples/src/mipmap/mod.rs index 9356416e446..6fb30999e28 100644 --- a/examples/src/mipmap/mod.rs +++ b/examples/src/mipmap/mod.rs @@ -292,12 +292,11 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], }), - primitive: wgpu::PrimitiveState { - topology: wgpu::PrimitiveTopology::TriangleStrip, - front_face: wgpu::FrontFace::Ccw, - cull_mode: Some(wgpu::Face::Back), - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .topology(wgpu::PrimitiveTopology::TriangleStrip) + .front_face(wgpu::FrontFace::Ccw) + .cull_mode(wgpu::Face::Back) + .build(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index bf11c44eaf6..b32d9d169b8 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -67,11 +67,10 @@ impl Example { compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], }), - primitive: wgpu::PrimitiveState { - topology: wgpu::PrimitiveTopology::LineList, - front_face: wgpu::FrontFace::Ccw, - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .topology(wgpu::PrimitiveTopology::LineList) + .front_face(wgpu::FrontFace::Ccw) + .build(), depth_stencil: None, multisample: wgpu::MultisampleState { count: sample_count, diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index bd849a337d0..a784e58926d 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -497,15 +497,16 @@ impl crate::framework::Example for Example { buffers: &[vb_desc.clone()], }, fragment: None, - primitive: wgpu::PrimitiveState { - topology: wgpu::PrimitiveTopology::TriangleList, - front_face: wgpu::FrontFace::Ccw, - cull_mode: Some(wgpu::Face::Back), - unclipped_depth: device - .features() - .contains(wgpu::Features::DEPTH_CLIP_CONTROL), - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .topology(wgpu::PrimitiveTopology::TriangleList) + .front_face(wgpu::FrontFace::Ccw) + .cull_mode(wgpu::Face::Back) + .unclipped_depth( + device + .features() + .contains(wgpu::Features::DEPTH_CLIP_CONTROL), + ) + .build(), depth_stencil: Some(wgpu::DepthStencilState { format: Self::SHADOW_FORMAT, depth_write_enabled: true, @@ -641,11 +642,10 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], }), - primitive: wgpu::PrimitiveState { - front_face: wgpu::FrontFace::Ccw, - cull_mode: Some(wgpu::Face::Back), - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .front_face(wgpu::FrontFace::Ccw) + .cull_mode(wgpu::Face::Back) + .build(), depth_stencil: Some(wgpu::DepthStencilState { format: Self::DEPTH_FORMAT, depth_write_enabled: true, diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index fdeb5c857c4..0c170821b54 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -202,10 +202,9 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], }), - primitive: wgpu::PrimitiveState { - front_face: wgpu::FrontFace::Cw, - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .front_face(wgpu::FrontFace::Cw) + .build(), depth_stencil: Some(wgpu::DepthStencilState { format: Self::DEPTH_FORMAT, depth_write_enabled: false, @@ -236,10 +235,9 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], }), - primitive: wgpu::PrimitiveState { - front_face: wgpu::FrontFace::Cw, - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .front_face(wgpu::FrontFace::Cw) + .build(), depth_stencil: Some(wgpu::DepthStencilState { format: Self::DEPTH_FORMAT, depth_write_enabled: true, diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index 9a6a5ae5a80..e9c5440d88e 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -141,10 +141,9 @@ impl crate::framework::Example for Example { write_mask: wgpu::ColorWrites::ALL, })], }), - primitive: wgpu::PrimitiveState { - cull_mode: Some(wgpu::Face::Back), - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .cull_mode(wgpu::Face::Back) + .build(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index 4ee435621ce..46366e36c3a 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -549,12 +549,11 @@ impl crate::framework::Example for Example { // How the triangles will be rasterized. This is more important // for the terrain because of the beneath-the water shot. // This is also dependent on how the triangles are being generated. - primitive: wgpu::PrimitiveState { + primitive: wgpu::PrimitiveState::builder() // What kind of data are we passing in? - topology: wgpu::PrimitiveTopology::TriangleList, - front_face: wgpu::FrontFace::Cw, - ..Default::default() - }, + .topology(wgpu::PrimitiveTopology::TriangleList) + .front_face(wgpu::FrontFace::Cw) + .build(), // Describes how us writing to the depth/stencil buffer // will work. Since this is water, we need to read from the // depth buffer both as a texture in the shader, and as an @@ -596,11 +595,11 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], }), - primitive: wgpu::PrimitiveState { - front_face: wgpu::FrontFace::Ccw, - cull_mode: Some(wgpu::Face::Front), - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .front_face(wgpu::FrontFace::Ccw) + .cull_mode(wgpu::Face::Front) + .build() + , depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth32Float, depth_write_enabled: true, diff --git a/tests/tests/nv12_texture/mod.rs b/tests/tests/nv12_texture/mod.rs index 8f72cbda775..436ad817f60 100644 --- a/tests/tests/nv12_texture/mod.rs +++ b/tests/tests/nv12_texture/mod.rs @@ -33,11 +33,10 @@ static NV12_TEXTURE_CREATION_SAMPLING: GpuTestConfiguration = GpuTestConfigurati compilation_options: Default::default(), targets: &[Some(target_format.into())], }), - primitive: wgpu::PrimitiveState { - topology: wgpu::PrimitiveTopology::TriangleStrip, - strip_index_format: Some(wgpu::IndexFormat::Uint32), - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .topology(wgpu::PrimitiveTopology::TriangleStrip) + .strip_index_format(wgpu::IndexFormat::Uint32) + .build(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index 85fb34164a9..79a16b8af56 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -510,11 +510,10 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { compilation_options: Default::default(), targets: &[Some(target_format.into())], }), - primitive: wgpu::PrimitiveState { - topology: wgpu::PrimitiveTopology::TriangleStrip, - strip_index_format: Some(wgpu::IndexFormat::Uint32), - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .topology(wgpu::PrimitiveTopology::TriangleStrip) + .strip_index_format(wgpu::IndexFormat::Uint32) + .build(), depth_stencil: Some(wgpu::DepthStencilState { format: depth_stencil_format, depth_write_enabled: true, diff --git a/tests/tests/shader_view_format/mod.rs b/tests/tests/shader_view_format/mod.rs index 9f2d83eb6e2..396b16d8103 100644 --- a/tests/tests/shader_view_format/mod.rs +++ b/tests/tests/shader_view_format/mod.rs @@ -99,10 +99,9 @@ async fn reinterpret( compilation_options: Default::default(), targets: &[Some(src_format.into())], }), - primitive: wgpu::PrimitiveState { - front_face: wgpu::FrontFace::Cw, - ..Default::default() - }, + primitive: wgpu::PrimitiveState::builder() + .front_face(wgpu::FrontFace::Cw) + .build(), depth_stencil: None, multisample: Default::default(), multiview: None, diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 42ad74cfdd1..21170c6229b 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -267,10 +267,9 @@ impl Example { constants: &constants, zero_initialize_workgroup_memory: true, }), - primitive: wgt::PrimitiveState { - topology: wgt::PrimitiveTopology::TriangleStrip, - ..wgt::PrimitiveState::default() - }, + primitive: wgt::PrimitiveState::builder() + .topology(wgt::PrimitiveTopology::TriangleStrip) + .build(), depth_stencil: None, multisample: Default::default(), color_targets: &[Some(wgt::ColorTargetState { diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index c9376a06f4d..94134f14d63 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2289,11 +2289,12 @@ pub enum PolygonMode { /// Corresponds to [WebGPU `GPUPrimitiveState`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpuprimitivestate). #[repr(C)] -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +#[derive(bon::Builder, Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct PrimitiveState { /// The primitive topology used to interpret vertices. + #[builder(default)] pub topology: PrimitiveTopology, /// When drawing strip topologies with indices, this is the required format for the index buffer. /// This has no effect on non-indexed or non-strip draws. @@ -2304,6 +2305,7 @@ pub struct PrimitiveState { pub strip_index_format: Option, /// The face to consider the front for the purpose of culling and stencil operations. #[cfg_attr(feature = "serde", serde(default))] + #[builder(default)] pub front_face: FrontFace, /// The face culling mode. #[cfg_attr(feature = "serde", serde(default))] @@ -2312,6 +2314,7 @@ pub struct PrimitiveState { /// /// Enabling this requires `Features::DEPTH_CLIP_CONTROL` to be enabled. #[cfg_attr(feature = "serde", serde(default))] + #[builder(default)] pub unclipped_depth: bool, /// Controls the way each polygon is rasterized. Can be either `Fill` (default), `Line` or `Point` /// @@ -2319,11 +2322,13 @@ pub struct PrimitiveState { /// /// Setting this to `Point` requires `Features::POLYGON_MODE_POINT` to be enabled. #[cfg_attr(feature = "serde", serde(default))] + #[builder(default)] pub polygon_mode: PolygonMode, /// If set to true, the primitives are rendered with conservative overestimation. I.e. any rastered pixel touched by it is filled. /// Only valid for PolygonMode::Fill! /// /// Enabling this requires `Features::CONSERVATIVE_RASTERIZATION` to be enabled. + #[builder(default)] pub conservative: bool, } From db7b54b36e5d27d221f88b214beb4868378da5cb Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 20:49:27 -0400 Subject: [PATCH 15/33] WIP: refactor!: remove unnecessary fields in `PrimitiveState` builder usage --- benches/benches/renderpass.rs | 5 ----- examples/src/cube/mod.rs | 1 - examples/src/mipmap/mod.rs | 1 - examples/src/shadow/mod.rs | 3 --- examples/src/water/mod.rs | 1 - 5 files changed, 11 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index fae51657685..cba03294353 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -271,13 +271,8 @@ impl RenderpassState { compilation_options: wgpu::PipelineCompilationOptions::default(), }, primitive: wgpu::PrimitiveState::builder() - .topology(wgpu::PrimitiveTopology::TriangleList) - .maybe_strip_index_format(None) .front_face(wgpu::FrontFace::Cw) .cull_mode(wgpu::Face::Back) - .polygon_mode(wgpu::PolygonMode::Fill) - .unclipped_depth(false) - .conservative(false) .build(), depth_stencil: None, multisample: Default::default(), diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index f5b1b545271..335e4eca868 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -287,7 +287,6 @@ impl crate::framework::Example for Example { })], }), primitive: wgpu::PrimitiveState::builder() - .front_face(wgpu::FrontFace::Ccw) .cull_mode(wgpu::Face::Back) .polygon_mode(wgpu::PolygonMode::Line) .build(), diff --git a/examples/src/mipmap/mod.rs b/examples/src/mipmap/mod.rs index 6fb30999e28..1ca126a5c73 100644 --- a/examples/src/mipmap/mod.rs +++ b/examples/src/mipmap/mod.rs @@ -294,7 +294,6 @@ impl crate::framework::Example for Example { }), primitive: wgpu::PrimitiveState::builder() .topology(wgpu::PrimitiveTopology::TriangleStrip) - .front_face(wgpu::FrontFace::Ccw) .cull_mode(wgpu::Face::Back) .build(), depth_stencil: None, diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index a784e58926d..dc617d5402e 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -498,8 +498,6 @@ impl crate::framework::Example for Example { }, fragment: None, primitive: wgpu::PrimitiveState::builder() - .topology(wgpu::PrimitiveTopology::TriangleList) - .front_face(wgpu::FrontFace::Ccw) .cull_mode(wgpu::Face::Back) .unclipped_depth( device @@ -643,7 +641,6 @@ impl crate::framework::Example for Example { targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState::builder() - .front_face(wgpu::FrontFace::Ccw) .cull_mode(wgpu::Face::Back) .build(), depth_stencil: Some(wgpu::DepthStencilState { diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index 46366e36c3a..4383126f491 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -596,7 +596,6 @@ impl crate::framework::Example for Example { targets: &[Some(config.view_formats[0].into())], }), primitive: wgpu::PrimitiveState::builder() - .front_face(wgpu::FrontFace::Ccw) .cull_mode(wgpu::Face::Front) .build() , From 09e894e5d56fdf4ce0d75c704de9c8ba2ef76483 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 22:02:01 -0400 Subject: [PATCH 16/33] refactor!: give `VertexBufferLayout` a builder API --- examples/src/boids/mod.rs | 20 +++++++-------- examples/src/cube/mod.rs | 12 ++++----- examples/src/msaa_line/mod.rs | 10 ++++---- examples/src/skybox/mod.rs | 10 ++++---- examples/src/srgb_blend/mod.rs | 12 ++++----- examples/src/stencil_triangles/mod.rs | 12 ++++----- examples/src/texture_arrays/mod.rs | 14 ++++++----- examples/src/water/mod.rs | 26 ++++++++++---------- tests/tests/regression/issue_3457.rs | 30 +++++++++++------------ tests/tests/shader_primitive_index/mod.rs | 12 ++++----- tests/tests/vertex_formats/mod.rs | 10 ++++---- wgpu/src/api/render_pipeline.rs | 3 ++- 12 files changed, 87 insertions(+), 84 deletions(-) diff --git a/examples/src/boids/mod.rs b/examples/src/boids/mod.rs index 970fcb32f60..cc3f5aed353 100644 --- a/examples/src/boids/mod.rs +++ b/examples/src/boids/mod.rs @@ -128,16 +128,16 @@ impl crate::framework::Example for Example { entry_point: Some("main_vs"), compilation_options: Default::default(), buffers: &[ - wgpu::VertexBufferLayout { - array_stride: 4 * 4, - step_mode: wgpu::VertexStepMode::Instance, - attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2], - }, - wgpu::VertexBufferLayout { - array_stride: 2 * 4, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &wgpu::vertex_attr_array![2 => Float32x2], - }, + wgpu::VertexBufferLayout::builder() + .array_stride(4 * 4) + .step_mode(wgpu::VertexStepMode::Instance) + .attributes(&wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2]) + .build(), + wgpu::VertexBufferLayout::builder() + .array_stride(2 * 4) + .step_mode(wgpu::VertexStepMode::Vertex) + .attributes(&wgpu::vertex_attr_array![2 => Float32x2]) + .build(), ], }, fragment: Some(wgpu::FragmentState { diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index 335e4eca868..63e8b2c74e1 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -215,10 +215,10 @@ impl crate::framework::Example for Example { let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl")); - let vertex_buffers = [wgpu::VertexBufferLayout { - array_stride: vertex_size as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &[ + let vertex_buffers = [wgpu::VertexBufferLayout::builder() + .array_stride(vertex_size as wgpu::BufferAddress) + .step_mode(wgpu::VertexStepMode::Vertex) + .attributes(&[ wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x4, offset: 0, @@ -229,8 +229,8 @@ impl crate::framework::Example for Example { offset: 4 * 4, shader_location: 1, }, - ], - }]; + ]) + .build()]; let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index b32d9d169b8..095771eeda2 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -55,11 +55,11 @@ impl Example { module: shader, entry_point: Some("vs_main"), compilation_options: Default::default(), - buffers: &[wgpu::VertexBufferLayout { - array_stride: size_of::() as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4], - }], + buffers: &[wgpu::VertexBufferLayout::builder() + .array_stride(size_of::() as wgpu::BufferAddress) + .step_mode(wgpu::VertexStepMode::Vertex) + .attributes(&wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4]) + .build()], }, fragment: Some(wgpu::FragmentState { module: shader, diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index 0c170821b54..7dcf155aa45 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -223,11 +223,11 @@ impl crate::framework::Example for Example { module: &shader, entry_point: Some("vs_entity"), compilation_options: Default::default(), - buffers: &[wgpu::VertexBufferLayout { - array_stride: size_of::() as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3], - }], + buffers: &[wgpu::VertexBufferLayout::builder() + .array_stride(size_of::() as wgpu::BufferAddress) + .step_mode(wgpu::VertexStepMode::Vertex) + .attributes(&wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3]) + .build()], }, fragment: Some(wgpu::FragmentState { module: &shader, diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index e9c5440d88e..42d776d692a 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -105,10 +105,10 @@ impl crate::framework::Example for Example { let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl")); - let vertex_buffers = [wgpu::VertexBufferLayout { - array_stride: vertex_size as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &[ + let vertex_buffers = [wgpu::VertexBufferLayout::builder() + .array_stride(vertex_size as wgpu::BufferAddress) + .step_mode(wgpu::VertexStepMode::Vertex) + .attributes(&[ wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x4, offset: 0, @@ -119,8 +119,8 @@ impl crate::framework::Example for Example { offset: 4 * 4, shader_location: 1, }, - ], - }]; + ]) + .build()]; let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index 9bf0ba29d3c..1f24105aa7f 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -54,15 +54,15 @@ impl crate::framework::Example for Example { let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl")); - let vertex_buffers = [wgpu::VertexBufferLayout { - array_stride: vertex_size as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &[wgpu::VertexAttribute { + let vertex_buffers = [wgpu::VertexBufferLayout::builder() + .array_stride(vertex_size as wgpu::BufferAddress) + .step_mode(wgpu::VertexStepMode::Vertex) + .attributes(&[wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x4, offset: 0, shader_location: 0, - }], - }]; + }]) + .build()]; let mask_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index e03780ae348..1f40fcfc395 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -317,11 +317,13 @@ impl crate::framework::Example for Example { module: &base_shader_module, entry_point: Some("vert_main"), compilation_options: Default::default(), - buffers: &[wgpu::VertexBufferLayout { - array_stride: vertex_size as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2, 2 => Sint32], - }], + buffers: &[wgpu::VertexBufferLayout::builder() + .array_stride(vertex_size as wgpu::BufferAddress) + .step_mode(wgpu::VertexStepMode::Vertex) + .attributes( + &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2, 2 => Sint32], + ) + .build()], }, fragment: Some(wgpu::FragmentState { module: fragment_shader_module, @@ -333,7 +335,7 @@ impl crate::framework::Example for Example { depth_stencil: None, multisample: Default::default(), multiview: None, - cache: None + cache: None, }); Self { diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index 4383126f491..1c574863deb 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -516,11 +516,11 @@ impl crate::framework::Example for Example { // ensured by tagging on either a `#[repr(C)]` onto a // struct, or a `#[repr(transparent)]` if it only contains // one item, which is itself `repr(C)`. - buffers: &[wgpu::VertexBufferLayout { - array_stride: water_vertex_size as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &wgpu::vertex_attr_array![0 => Sint16x2, 1 => Sint8x4], - }], + buffers: &[wgpu::VertexBufferLayout::builder() + .array_stride(water_vertex_size as wgpu::BufferAddress) + .step_mode(wgpu::VertexStepMode::Vertex) + .attributes(&wgpu::vertex_attr_array![0 => Sint16x2, 1 => Sint8x4]) + .build()], }, // Fragment shader and output targets fragment: Some(wgpu::FragmentState { @@ -583,11 +583,12 @@ impl crate::framework::Example for Example { module: &terrain_module, entry_point: Some("vs_main"), compilation_options: Default::default(), - buffers: &[wgpu::VertexBufferLayout { - array_stride: terrain_vertex_size as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3, 2 => Unorm8x4], - }], + buffers: &[wgpu::VertexBufferLayout::builder() + .array_stride(terrain_vertex_size as wgpu::BufferAddress) + .attributes( + &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3, 2 => Unorm8x4], + ) + .build()], }, fragment: Some(wgpu::FragmentState { module: &terrain_module, @@ -597,8 +598,7 @@ impl crate::framework::Example for Example { }), primitive: wgpu::PrimitiveState::builder() .cull_mode(wgpu::Face::Front) - .build() - , + .build(), depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Depth32Float, depth_write_enabled: true, @@ -608,7 +608,7 @@ impl crate::framework::Example for Example { }), multisample: Default::default(), multiview: None, - cache: None + cache: None, }); // A render bundle to draw the terrain. diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index 316466bedd8..d8667469a59 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -53,16 +53,16 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = entry_point: Some("double_buffer_vert"), compilation_options: Default::default(), buffers: &[ - VertexBufferLayout { - array_stride: 16, - step_mode: VertexStepMode::Vertex, - attributes: &vertex_attr_array![0 => Float32x4], - }, - VertexBufferLayout { - array_stride: 4, - step_mode: VertexStepMode::Vertex, - attributes: &vertex_attr_array![5 => Float32], - }, + VertexBufferLayout::builder() + .array_stride(16) + .step_mode(VertexStepMode::Vertex) + .attributes(&vertex_attr_array![0 => Float32x4]) + .build(), + VertexBufferLayout::builder() + .array_stride(4) + .step_mode(VertexStepMode::Vertex) + .attributes(&vertex_attr_array![5 => Float32]) + .build(), ], }, primitive: Default::default(), @@ -91,11 +91,11 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = module: &module, entry_point: Some("single_buffer_vert"), compilation_options: Default::default(), - buffers: &[VertexBufferLayout { - array_stride: 16, - step_mode: VertexStepMode::Vertex, - attributes: &vertex_attr_array![0 => Float32x4], - }], + buffers: &[VertexBufferLayout::builder() + .array_stride(16) + .step_mode(VertexStepMode::Vertex) + .attributes(&vertex_attr_array![0 => Float32x4]) + .build()], }, primitive: Default::default(), depth_stencil: None, diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index 6aeec92afdf..6024526b0bd 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -123,15 +123,15 @@ async fn pulling_common( module: &shader, entry_point: Some("vs_main"), compilation_options: Default::default(), - buffers: &[wgpu::VertexBufferLayout { - array_stride: 8, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &[wgpu::VertexAttribute { + buffers: &[wgpu::VertexBufferLayout::builder() + .array_stride(8) + .step_mode(wgpu::VertexStepMode::Vertex) + .attributes(&[wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x2, offset: 0, shader_location: 0, - }], - }], + }]) + .build()], }, primitive: Default::default(), depth_stencil: None, diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 3a60a02d9f3..558c2b8232c 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -234,11 +234,11 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { label: None, layout: Some(&ppl), vertex: wgpu::VertexState { - buffers: &[wgpu::VertexBufferLayout { - array_stride: 0, // Calculate, please! - step_mode: wgpu::VertexStepMode::Vertex, - attributes: test.attributes, - }], + buffers: &[wgpu::VertexBufferLayout::builder() + .array_stride(0) // Calculate, please! + .step_mode(wgpu::VertexStepMode::Vertex) + .attributes(test.attributes) + .build()], module: &shader, entry_point: Some(test.entry_point), compilation_options: Default::default(), diff --git a/wgpu/src/api/render_pipeline.rs b/wgpu/src/api/render_pipeline.rs index dd1c1cefe87..593806dab91 100644 --- a/wgpu/src/api/render_pipeline.rs +++ b/wgpu/src/api/render_pipeline.rs @@ -48,11 +48,12 @@ impl RenderPipeline { /// /// Corresponds to [WebGPU `GPUVertexBufferLayout`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpuvertexbufferlayout). -#[derive(Clone, Debug, Hash, Eq, PartialEq)] +#[derive(bon::Builder, Clone, Debug, Hash, Eq, PartialEq)] pub struct VertexBufferLayout<'a> { /// The stride, in bytes, between elements of this buffer. pub array_stride: BufferAddress, /// How often this vertex buffer is "stepped" forward. + #[builder(default)] pub step_mode: VertexStepMode, /// The list of attributes which comprise a single vertex. pub attributes: &'a [VertexAttribute], From d906df960c912bbfb98c70c067d77e2672dac017 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 22:03:36 -0400 Subject: [PATCH 17/33] WIP: refactor!: remove unnecessary fields in `VertexBufferLayout` builder usage --- examples/src/boids/mod.rs | 1 - examples/src/cube/mod.rs | 1 - examples/src/msaa_line/mod.rs | 1 - examples/src/srgb_blend/mod.rs | 1 - examples/src/stencil_triangles/mod.rs | 1 - examples/src/texture_arrays/mod.rs | 1 - examples/src/water/mod.rs | 1 - tests/tests/regression/issue_3457.rs | 3 --- tests/tests/shader_primitive_index/mod.rs | 1 - tests/tests/vertex_formats/mod.rs | 1 - 10 files changed, 12 deletions(-) diff --git a/examples/src/boids/mod.rs b/examples/src/boids/mod.rs index cc3f5aed353..f40c280b28a 100644 --- a/examples/src/boids/mod.rs +++ b/examples/src/boids/mod.rs @@ -135,7 +135,6 @@ impl crate::framework::Example for Example { .build(), wgpu::VertexBufferLayout::builder() .array_stride(2 * 4) - .step_mode(wgpu::VertexStepMode::Vertex) .attributes(&wgpu::vertex_attr_array![2 => Float32x2]) .build(), ], diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index 63e8b2c74e1..55572fbdf5d 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -217,7 +217,6 @@ impl crate::framework::Example for Example { let vertex_buffers = [wgpu::VertexBufferLayout::builder() .array_stride(vertex_size as wgpu::BufferAddress) - .step_mode(wgpu::VertexStepMode::Vertex) .attributes(&[ wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x4, diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index 095771eeda2..2c758e08875 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -57,7 +57,6 @@ impl Example { compilation_options: Default::default(), buffers: &[wgpu::VertexBufferLayout::builder() .array_stride(size_of::() as wgpu::BufferAddress) - .step_mode(wgpu::VertexStepMode::Vertex) .attributes(&wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4]) .build()], }, diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index 42d776d692a..accf4c8de77 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -107,7 +107,6 @@ impl crate::framework::Example for Example { let vertex_buffers = [wgpu::VertexBufferLayout::builder() .array_stride(vertex_size as wgpu::BufferAddress) - .step_mode(wgpu::VertexStepMode::Vertex) .attributes(&[ wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x4, diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index 1f24105aa7f..1d8640531fa 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -56,7 +56,6 @@ impl crate::framework::Example for Example { let vertex_buffers = [wgpu::VertexBufferLayout::builder() .array_stride(vertex_size as wgpu::BufferAddress) - .step_mode(wgpu::VertexStepMode::Vertex) .attributes(&[wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x4, offset: 0, diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index 1f40fcfc395..20be42626f4 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -319,7 +319,6 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), buffers: &[wgpu::VertexBufferLayout::builder() .array_stride(vertex_size as wgpu::BufferAddress) - .step_mode(wgpu::VertexStepMode::Vertex) .attributes( &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2, 2 => Sint32], ) diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index 1c574863deb..eb237103a27 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -518,7 +518,6 @@ impl crate::framework::Example for Example { // one item, which is itself `repr(C)`. buffers: &[wgpu::VertexBufferLayout::builder() .array_stride(water_vertex_size as wgpu::BufferAddress) - .step_mode(wgpu::VertexStepMode::Vertex) .attributes(&wgpu::vertex_attr_array![0 => Sint16x2, 1 => Sint8x4]) .build()], }, diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index d8667469a59..56ab7372ddd 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -55,12 +55,10 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = buffers: &[ VertexBufferLayout::builder() .array_stride(16) - .step_mode(VertexStepMode::Vertex) .attributes(&vertex_attr_array![0 => Float32x4]) .build(), VertexBufferLayout::builder() .array_stride(4) - .step_mode(VertexStepMode::Vertex) .attributes(&vertex_attr_array![5 => Float32]) .build(), ], @@ -93,7 +91,6 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = compilation_options: Default::default(), buffers: &[VertexBufferLayout::builder() .array_stride(16) - .step_mode(VertexStepMode::Vertex) .attributes(&vertex_attr_array![0 => Float32x4]) .build()], }, diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index 6024526b0bd..949b8be7141 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -125,7 +125,6 @@ async fn pulling_common( compilation_options: Default::default(), buffers: &[wgpu::VertexBufferLayout::builder() .array_stride(8) - .step_mode(wgpu::VertexStepMode::Vertex) .attributes(&[wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x2, offset: 0, diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 558c2b8232c..9d90fefc43d 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -236,7 +236,6 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { vertex: wgpu::VertexState { buffers: &[wgpu::VertexBufferLayout::builder() .array_stride(0) // Calculate, please! - .step_mode(wgpu::VertexStepMode::Vertex) .attributes(test.attributes) .build()], module: &shader, From 975bcf242a6b454b96324df3d230833043250f88 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 20:41:32 -0400 Subject: [PATCH 18/33] refactor!: give `VertexState` a builder API --- benches/benches/renderpass.rs | 24 ++++++------ examples/src/boids/mod.rs | 14 +++---- examples/src/bunnymark/mod.rs | 12 +++--- examples/src/conservative_raster/mod.rs | 48 +++++++++++------------ examples/src/cube/mod.rs | 24 ++++++------ examples/src/hello_triangle/mod.rs | 12 +++--- examples/src/mipmap/mod.rs | 24 ++++++------ examples/src/msaa_line/mod.rs | 14 +++---- examples/src/render_to_texture/mod.rs | 12 +++--- examples/src/shadow/mod.rs | 24 ++++++------ examples/src/skybox/mod.rs | 26 ++++++------ examples/src/srgb_blend/mod.rs | 12 +++--- examples/src/stencil_triangles/mod.rs | 24 ++++++------ examples/src/texture_arrays/mod.rs | 14 +++---- examples/src/timestamp_queries/mod.rs | 12 +++--- examples/src/uniform_values/mod.rs | 12 +++--- examples/src/water/mod.rs | 28 ++++++------- tests/tests/device.rs | 24 ++++++------ tests/tests/mem_leaks.rs | 12 +++--- tests/tests/nv12_texture/mod.rs | 12 +++--- tests/tests/occlusion_query/mod.rs | 12 +++--- tests/tests/pipeline.rs | 16 ++++---- tests/tests/regression/issue_3349.rs | 12 +++--- tests/tests/regression/issue_3457.rs | 28 ++++++------- tests/tests/regression/issue_4485.rs | 12 +++--- tests/tests/regression/issue_4514.rs | 12 +++--- tests/tests/regression/issue_5553.rs | 12 +++--- tests/tests/render_pass_ownership.rs | 14 +++---- tests/tests/scissor_tests/mod.rs | 12 +++--- tests/tests/shader_primitive_index/mod.rs | 14 +++---- tests/tests/shader_view_format/mod.rs | 13 +++--- tests/tests/vertex_formats/mod.rs | 19 ++++----- tests/tests/vertex_indices/mod.rs | 12 +++--- wgpu/src/api/render_pipeline.rs | 4 +- 34 files changed, 289 insertions(+), 287 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index cba03294353..1ee92b133b3 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -178,12 +178,12 @@ impl RenderpassState { .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &sm, - entry_point: Some("vs_main"), - buffers: &vertex_buffer_layouts, - compilation_options: wgpu::PipelineCompilationOptions::default(), - }, + vertex: wgpu::VertexState::builder() + .module(&sm) + .entry_point("vs_main") + .buffers(&vertex_buffer_layouts) + .compilation_options(wgpu::PipelineCompilationOptions::default()) + .build(), primitive: wgpu::PrimitiveState::builder() .front_face(wgpu::FrontFace::Cw) .cull_mode(wgpu::Face::Back) @@ -264,12 +264,12 @@ impl RenderpassState { .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&bindless_pipeline_layout), - vertex: wgpu::VertexState { - module: &bindless_shader_module, - entry_point: Some("vs_main"), - buffers: &vertex_buffer_layouts, - compilation_options: wgpu::PipelineCompilationOptions::default(), - }, + vertex: wgpu::VertexState::builder() + .module(&bindless_shader_module) + .entry_point("vs_main") + .buffers(&vertex_buffer_layouts) + .compilation_options(wgpu::PipelineCompilationOptions::default()) + .build(), primitive: wgpu::PrimitiveState::builder() .front_face(wgpu::FrontFace::Cw) .cull_mode(wgpu::Face::Back) diff --git a/examples/src/boids/mod.rs b/examples/src/boids/mod.rs index f40c280b28a..4d95bbae392 100644 --- a/examples/src/boids/mod.rs +++ b/examples/src/boids/mod.rs @@ -123,11 +123,11 @@ impl crate::framework::Example for Example { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&render_pipeline_layout), - vertex: wgpu::VertexState { - module: &draw_shader, - entry_point: Some("main_vs"), - compilation_options: Default::default(), - buffers: &[ + vertex: wgpu::VertexState::builder() + .module(&draw_shader) + .entry_point("main_vs") + .compilation_options(Default::default()) + .buffers(&[ wgpu::VertexBufferLayout::builder() .array_stride(4 * 4) .step_mode(wgpu::VertexStepMode::Instance) @@ -137,8 +137,8 @@ impl crate::framework::Example for Example { .array_stride(2 * 4) .attributes(&wgpu::vertex_attr_array![2 => Float32x2]) .build(), - ], - }, + ]) + .build(), fragment: Some(wgpu::FragmentState { module: &draw_shader, entry_point: Some("main_fs"), diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index 13b0dc60dfb..2ae413017ce 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -210,12 +210,12 @@ impl crate::framework::Example for Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index 16e359b1e45..9b99804bb0a 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -87,12 +87,12 @@ impl crate::framework::Example for Example { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Conservative Rasterization"), layout: Some(&pipeline_layout_empty), - vertex: wgpu::VertexState { - module: &shader_triangle_and_lines, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader_triangle_and_lines) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader_triangle_and_lines, entry_point: Some("fs_main_red"), @@ -110,12 +110,12 @@ impl crate::framework::Example for Example { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Regular Rasterization"), layout: Some(&pipeline_layout_empty), - vertex: wgpu::VertexState { - module: &shader_triangle_and_lines, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader_triangle_and_lines) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader_triangle_and_lines, entry_point: Some("fs_main_blue"), @@ -137,12 +137,12 @@ impl crate::framework::Example for Example { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Lines"), layout: Some(&pipeline_layout_empty), - vertex: wgpu::VertexState { - module: &shader_triangle_and_lines, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader_triangle_and_lines) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader_triangle_and_lines, entry_point: Some("fs_main_white"), @@ -197,12 +197,12 @@ impl crate::framework::Example for Example { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Upscale"), layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index 55572fbdf5d..82d3efb44c4 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -234,12 +234,12 @@ impl crate::framework::Example for Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &vertex_buffers, - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&vertex_buffers) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), @@ -262,12 +262,12 @@ impl crate::framework::Example for Example { let pipeline_wire = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &vertex_buffers, - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&vertex_buffers) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_wire"), diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs index eeb20a3ba0c..bc657dc4da7 100644 --- a/examples/src/hello_triangle/mod.rs +++ b/examples/src/hello_triangle/mod.rs @@ -57,12 +57,12 @@ async fn run(event_loop: EventLoop<()>, window: Window) { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - buffers: &[], - compilation_options: Default::default(), - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .buffers(&[]) + .compilation_options(Default::default()) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/examples/src/mipmap/mod.rs b/examples/src/mipmap/mod.rs index 1ca126a5c73..88920af55e0 100644 --- a/examples/src/mipmap/mod.rs +++ b/examples/src/mipmap/mod.rs @@ -86,12 +86,12 @@ impl Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("blit"), layout: None, - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), @@ -280,12 +280,12 @@ impl crate::framework::Example for Example { let draw_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("draw"), layout: None, - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index 2c758e08875..a6e4b5355db 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -51,15 +51,15 @@ impl Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(pipeline_layout), - vertex: wgpu::VertexState { - module: shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[wgpu::VertexBufferLayout::builder() + vertex: wgpu::VertexState::builder() + .module(shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(size_of::() as wgpu::BufferAddress) .attributes(&wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4]) - .build()], - }, + .build()]) + .build(), fragment: Some(wgpu::FragmentState { module: shader, entry_point: Some("fs_main"), diff --git a/examples/src/render_to_texture/mod.rs b/examples/src/render_to_texture/mod.rs index 670c1afe973..9073b55fb85 100644 --- a/examples/src/render_to_texture/mod.rs +++ b/examples/src/render_to_texture/mod.rs @@ -52,12 +52,12 @@ async fn run(_path: Option) { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: None, - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index dc617d5402e..3b7131cf024 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -490,12 +490,12 @@ impl crate::framework::Example for Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("shadow"), layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_bake"), - compilation_options: Default::default(), - buffers: &[vb_desc.clone()], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_bake") + .compilation_options(Default::default()) + .buffers(&[vb_desc.clone()]) + .build(), fragment: None, primitive: wgpu::PrimitiveState::builder() .cull_mode(wgpu::Face::Back) @@ -624,12 +624,12 @@ impl crate::framework::Example for Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("main"), layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[vb_desc], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[vb_desc]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some(if supports_storage_resources { diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index 7dcf155aa45..bf4e646b041 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -190,12 +190,12 @@ impl crate::framework::Example for Example { let sky_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Sky"), layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_sky"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_sky") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_sky"), @@ -219,16 +219,16 @@ impl crate::framework::Example for Example { let entity_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Entity"), layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_entity"), - compilation_options: Default::default(), - buffers: &[wgpu::VertexBufferLayout::builder() + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_entity") + .compilation_options(Default::default()) + .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(size_of::() as wgpu::BufferAddress) .step_mode(wgpu::VertexStepMode::Vertex) .attributes(&wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3]) - .build()], - }, + .build()]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_entity"), diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index accf4c8de77..0c04e42d8b5 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -124,12 +124,12 @@ impl crate::framework::Example for Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &vertex_buffers, - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&vertex_buffers) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index 1d8640531fa..b0fcf701d02 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -66,12 +66,12 @@ impl crate::framework::Example for Example { let mask_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &vertex_buffers, - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&vertex_buffers) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), @@ -107,12 +107,12 @@ impl crate::framework::Example for Example { let outer_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &vertex_buffers, - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&vertex_buffers) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index 20be42626f4..5606f475726 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -313,17 +313,17 @@ impl crate::framework::Example for Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &base_shader_module, - entry_point: Some("vert_main"), - compilation_options: Default::default(), - buffers: &[wgpu::VertexBufferLayout::builder() + vertex: wgpu::VertexState::builder() + .module(&base_shader_module) + .entry_point("vert_main") + .compilation_options(Default::default()) + .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(vertex_size as wgpu::BufferAddress) .attributes( &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2, 2 => Sint32], ) - .build()], - }, + .build()]) + .build(), fragment: Some(wgpu::FragmentState { module: fragment_shader_module, entry_point: Some(fragment_entry_point), diff --git a/examples/src/timestamp_queries/mod.rs b/examples/src/timestamp_queries/mod.rs index 8e440b2d24b..97a2e9f241a 100644 --- a/examples/src/timestamp_queries/mod.rs +++ b/examples/src/timestamp_queries/mod.rs @@ -351,12 +351,12 @@ fn render_pass( let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(module) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module, entry_point: Some("fs_main"), diff --git a/examples/src/uniform_values/mod.rs b/examples/src/uniform_values/mod.rs index c57e33d629f..b6db33c6a92 100644 --- a/examples/src/uniform_values/mod.rs +++ b/examples/src/uniform_values/mod.rs @@ -172,12 +172,12 @@ impl WgpuContext { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index eb237103a27..bec9a1a9cef 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -507,20 +507,20 @@ impl crate::framework::Example for Example { // The "layout" is what uniforms will be needed. layout: Some(&water_pipeline_layout), // Vertex shader and input buffers - vertex: wgpu::VertexState { - module: &water_module, - entry_point: Some("vs_main"), - compilation_options: Default::default(), + vertex: wgpu::VertexState::builder() + .module(&water_module) + .entry_point("vs_main") + .compilation_options(Default::default()) // Layout of our vertices. This should match the structs // which are uploaded to the GPU. This should also be // ensured by tagging on either a `#[repr(C)]` onto a // struct, or a `#[repr(transparent)]` if it only contains // one item, which is itself `repr(C)`. - buffers: &[wgpu::VertexBufferLayout::builder() + .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(water_vertex_size as wgpu::BufferAddress) .attributes(&wgpu::vertex_attr_array![0 => Sint16x2, 1 => Sint8x4]) - .build()], - }, + .build()]) + .build(), // Fragment shader and output targets fragment: Some(wgpu::FragmentState { module: &water_module, @@ -578,17 +578,17 @@ impl crate::framework::Example for Example { let terrain_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("terrain"), layout: Some(&terrain_pipeline_layout), - vertex: wgpu::VertexState { - module: &terrain_module, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[wgpu::VertexBufferLayout::builder() + vertex: wgpu::VertexState::builder() + .module(&terrain_module) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(terrain_vertex_size as wgpu::BufferAddress) .attributes( &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3, 2 => Unorm8x4], ) - .build()], - }, + .build()]) + .build(), fragment: Some(wgpu::FragmentState { module: &terrain_module, entry_point: Some("fs_main"), diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 7539b6ccf5f..16e8d9f2732 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -507,12 +507,12 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: None, - vertex: wgpu::VertexState { - module: &shader_module, - entry_point: Some(""), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader_module) + .entry_point("") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), @@ -786,12 +786,12 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf // Other fields below aren't interesting for this text. label: None, - vertex: wgpu::VertexState { - module: &trivial_shaders_with_some_reversed_bindings, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&trivial_shaders_with_some_reversed_bindings) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index 43823734653..8a5344bab39 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -91,12 +91,12 @@ async fn draw_test_with_reports( .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&ppl), - vertex: wgpu::VertexState { - buffers: &[], - module: &shader, - entry_point: Some("vs_main_builtin"), - compilation_options: Default::default(), - }, + vertex: wgpu::VertexState::builder() + .buffers(&[]) + .module(&shader) + .entry_point("vs_main_builtin") + .compilation_options(Default::default()) + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/tests/tests/nv12_texture/mod.rs b/tests/tests/nv12_texture/mod.rs index 436ad817f60..148a833d4c1 100644 --- a/tests/tests/nv12_texture/mod.rs +++ b/tests/tests/nv12_texture/mod.rs @@ -21,12 +21,12 @@ static NV12_TEXTURE_CREATION_SAMPLING: GpuTestConfiguration = GpuTestConfigurati .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("nv12 pipeline"), layout: None, - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), diff --git a/tests/tests/occlusion_query/mod.rs b/tests/tests/occlusion_query/mod.rs index 05df4b17542..cc8d4a0573e 100644 --- a/tests/tests/occlusion_query/mod.rs +++ b/tests/tests/occlusion_query/mod.rs @@ -29,12 +29,12 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new() .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Pipeline"), layout: None, - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: None, primitive: Default::default(), depth_stencil: Some(wgpu::DepthStencilState { diff --git a/tests/tests/pipeline.rs b/tests/tests/pipeline.rs index 8e9c91e5273..2142faa6c37 100644 --- a/tests/tests/pipeline.rs +++ b/tests/tests/pipeline.rs @@ -190,14 +190,14 @@ static NO_TARGETLESS_RENDER: GpuTestConfiguration = GpuTestConfiguration::new() .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: None, - vertex: wgpu::VertexState { - module: &ctx - .device - .create_shader_module(TRIVIAL_VERTEX_SHADER_DESC), - entry_point: Some("main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module( + &ctx.device.create_shader_module(TRIVIAL_VERTEX_SHADER_DESC), + ) + .entry_point("main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), primitive: Default::default(), depth_stencil: None, multisample: wgpu::MultisampleState { diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index ac9f9438f99..62dc46e769c 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -99,12 +99,12 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("pipeline"), layout: Some(&pll), - vertex: wgpu::VertexState { - module: &vs_sm, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&vs_sm) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: &fs_sm, entry_point: Some("fs_main"), diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index 56ab7372ddd..507ed09e618 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -48,11 +48,11 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = .create_render_pipeline(&RenderPipelineDescriptor { label: Some("Double Pipeline"), layout: Some(&pipeline_layout), - vertex: VertexState { - module: &module, - entry_point: Some("double_buffer_vert"), - compilation_options: Default::default(), - buffers: &[ + vertex: VertexState::builder() + .module(&module) + .entry_point("double_buffer_vert") + .compilation_options(Default::default()) + .buffers(&[ VertexBufferLayout::builder() .array_stride(16) .attributes(&vertex_attr_array![0 => Float32x4]) @@ -61,8 +61,8 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = .array_stride(4) .attributes(&vertex_attr_array![5 => Float32]) .build(), - ], - }, + ]) + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), @@ -85,15 +85,15 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = .create_render_pipeline(&RenderPipelineDescriptor { label: Some("Single Pipeline"), layout: Some(&pipeline_layout), - vertex: VertexState { - module: &module, - entry_point: Some("single_buffer_vert"), - compilation_options: Default::default(), - buffers: &[VertexBufferLayout::builder() + vertex: VertexState::builder() + .module(&module) + .entry_point("single_buffer_vert") + .compilation_options(Default::default()) + .buffers(&[VertexBufferLayout::builder() .array_stride(16) .attributes(&vertex_attr_array![0 => Float32x4]) - .build()], - }, + .build()]) + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/tests/tests/regression/issue_4485.rs b/tests/tests/regression/issue_4485.rs index 0f8803c7f54..68ebcd455fe 100644 --- a/tests/tests/regression/issue_4485.rs +++ b/tests/tests/regression/issue_4485.rs @@ -41,12 +41,12 @@ async fn test_impl(ctx: &TestingContext) { .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Pipeline"), layout: None, - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/tests/tests/regression/issue_4514.rs b/tests/tests/regression/issue_4514.rs index 6f07e41e18b..c487ad3e0da 100644 --- a/tests/tests/regression/issue_4514.rs +++ b/tests/tests/regression/issue_4514.rs @@ -41,12 +41,12 @@ async fn test_impl(ctx: &TestingContext) { .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Pipeline"), layout: None, - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index f76d81cf623..001884843ff 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -28,12 +28,12 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = .create_render_pipeline(&RenderPipelineDescriptor { label: Some("Pipeline"), layout: Some(&pipeline_layout), - vertex: VertexState { - module: &module, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: VertexState::builder() + .module(&module) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index 79a16b8af56..cd47a7c73f8 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -494,16 +494,16 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("pipeline"), layout: Some(&pipeline_layout), - vertex: wgpu::VertexState { - module: &sm, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[wgpu::VertexBufferLayout { + vertex: wgpu::VertexState::builder() + .module(&sm) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[wgpu::VertexBufferLayout { array_stride: 4, step_mode: wgpu::VertexStepMode::Vertex, attributes: &wgpu::vertex_attr_array![0 => Uint32], - }], - }, + }]) + .build(), fragment: Some(wgpu::FragmentState { module: &sm, entry_point: Some("fs_main"), diff --git a/tests/tests/scissor_tests/mod.rs b/tests/tests/scissor_tests/mod.rs index a61056bded4..f8b7b130cfb 100644 --- a/tests/tests/scissor_tests/mod.rs +++ b/tests/tests/scissor_tests/mod.rs @@ -39,12 +39,12 @@ async fn scissor_test_impl( .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Pipeline"), layout: None, - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index 949b8be7141..7c4fcf52aef 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -119,19 +119,19 @@ async fn pulling_common( .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: None, - vertex: wgpu::VertexState { - module: &shader, - entry_point: Some("vs_main"), - compilation_options: Default::default(), - buffers: &[wgpu::VertexBufferLayout::builder() + vertex: wgpu::VertexState::builder() + .module(&shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(8) .attributes(&[wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x2, offset: 0, shader_location: 0, }]) - .build()], - }, + .build()]) + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/tests/tests/shader_view_format/mod.rs b/tests/tests/shader_view_format/mod.rs index 396b16d8103..db31022c158 100644 --- a/tests/tests/shader_view_format/mod.rs +++ b/tests/tests/shader_view_format/mod.rs @@ -86,13 +86,12 @@ async fn reinterpret( .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("reinterpret pipeline"), layout: None, - vertex: wgpu::VertexState { - module: shader, - entry_point: Some("vs_main"), - - compilation_options: Default::default(), - buffers: &[], - }, + vertex: wgpu::VertexState::builder() + .module(shader) + .entry_point("vs_main") + .compilation_options(Default::default()) + .buffers(&[]) + .build(), fragment: Some(wgpu::FragmentState { module: shader, entry_point: Some("fs_main"), diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 9d90fefc43d..830313d4578 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -230,18 +230,19 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { usage: wgpu::BufferUsages::VERTEX, }); + let buffers = &[wgpu::VertexBufferLayout::builder() + .array_stride(0) // Calculate, please! + .attributes(test.attributes) + .build()]; let pipeline_desc = wgpu::RenderPipelineDescriptor { label: None, layout: Some(&ppl), - vertex: wgpu::VertexState { - buffers: &[wgpu::VertexBufferLayout::builder() - .array_stride(0) // Calculate, please! - .attributes(test.attributes) - .build()], - module: &shader, - entry_point: Some(test.entry_point), - compilation_options: Default::default(), - }, + vertex: wgpu::VertexState::builder() + .buffers(buffers) + .module(&shader) + .entry_point(test.entry_point) + .compilation_options(Default::default()) + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index f90c4560665..217d70b5816 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -254,12 +254,12 @@ async fn vertex_index_common(ctx: TestingContext) { let mut pipeline_desc = wgpu::RenderPipelineDescriptor { label: None, layout: Some(&ppl), - vertex: wgpu::VertexState { - buffers: &[], - module: &shader, - entry_point: Some("vs_main_builtin"), - compilation_options: Default::default(), - }, + vertex: wgpu::VertexState::builder() + .buffers(&[]) + .module(&shader) + .entry_point("vs_main_builtin") + .compilation_options(Default::default()) + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/wgpu/src/api/render_pipeline.rs b/wgpu/src/api/render_pipeline.rs index 593806dab91..c03a53f79e8 100644 --- a/wgpu/src/api/render_pipeline.rs +++ b/wgpu/src/api/render_pipeline.rs @@ -66,7 +66,7 @@ static_assertions::assert_impl_all!(VertexBufferLayout<'_>: Send, Sync); /// /// Corresponds to [WebGPU `GPUVertexState`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpuvertexstate). -#[derive(Clone, Debug)] +#[derive(bon::Builder, Clone, Debug)] pub struct VertexState<'a> { /// The compiled shader module for this stage. pub module: &'a ShaderModule, @@ -81,8 +81,10 @@ pub struct VertexState<'a> { /// Advanced options for when this pipeline is compiled /// /// This implements `Default`, and for most users can be set to `Default::default()` + #[builder(default)] pub compilation_options: PipelineCompilationOptions<'a>, /// The format of any vertex buffers used with this pipeline. + #[builder(default)] pub buffers: &'a [VertexBufferLayout<'a>], } #[cfg(send_sync)] From da7b491b7a8bf9c956cf1afbff68d2abaaa65f49 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 20:49:50 -0400 Subject: [PATCH 19/33] WIP: refactor!: remove unnecessary fields in `VertexState` builder usage --- benches/benches/renderpass.rs | 2 -- examples/src/boids/mod.rs | 1 - examples/src/bunnymark/mod.rs | 2 -- examples/src/conservative_raster/mod.rs | 8 -------- examples/src/cube/mod.rs | 2 -- examples/src/hello_triangle/mod.rs | 2 -- examples/src/mipmap/mod.rs | 4 ---- examples/src/msaa_line/mod.rs | 1 - examples/src/render_to_texture/mod.rs | 2 -- examples/src/shadow/mod.rs | 3 --- examples/src/skybox/mod.rs | 3 --- examples/src/srgb_blend/mod.rs | 1 - examples/src/stencil_triangles/mod.rs | 2 -- examples/src/texture_arrays/mod.rs | 1 - examples/src/timestamp_queries/mod.rs | 2 -- examples/src/uniform_values/mod.rs | 2 -- examples/src/water/mod.rs | 2 -- tests/tests/device.rs | 4 ---- tests/tests/mem_leaks.rs | 2 -- tests/tests/nv12_texture/mod.rs | 2 -- tests/tests/occlusion_query/mod.rs | 2 -- tests/tests/pipeline.rs | 2 -- tests/tests/regression/issue_3349.rs | 2 -- tests/tests/regression/issue_3457.rs | 2 -- tests/tests/regression/issue_4485.rs | 2 -- tests/tests/regression/issue_4514.rs | 2 -- tests/tests/regression/issue_5553.rs | 2 -- tests/tests/render_pass_ownership.rs | 1 - tests/tests/scissor_tests/mod.rs | 2 -- tests/tests/shader_primitive_index/mod.rs | 1 - tests/tests/shader_view_format/mod.rs | 2 -- tests/tests/vertex_formats/mod.rs | 1 - tests/tests/vertex_indices/mod.rs | 2 -- 33 files changed, 71 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index 1ee92b133b3..ba74bf5c6df 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -182,7 +182,6 @@ impl RenderpassState { .module(&sm) .entry_point("vs_main") .buffers(&vertex_buffer_layouts) - .compilation_options(wgpu::PipelineCompilationOptions::default()) .build(), primitive: wgpu::PrimitiveState::builder() .front_face(wgpu::FrontFace::Cw) @@ -268,7 +267,6 @@ impl RenderpassState { .module(&bindless_shader_module) .entry_point("vs_main") .buffers(&vertex_buffer_layouts) - .compilation_options(wgpu::PipelineCompilationOptions::default()) .build(), primitive: wgpu::PrimitiveState::builder() .front_face(wgpu::FrontFace::Cw) diff --git a/examples/src/boids/mod.rs b/examples/src/boids/mod.rs index 4d95bbae392..ae15a57d8fb 100644 --- a/examples/src/boids/mod.rs +++ b/examples/src/boids/mod.rs @@ -126,7 +126,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&draw_shader) .entry_point("main_vs") - .compilation_options(Default::default()) .buffers(&[ wgpu::VertexBufferLayout::builder() .array_stride(4 * 4) diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index 2ae413017ce..a041abbba6b 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -213,8 +213,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: &shader, diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index 9b99804bb0a..5bb80c8cc3c 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -90,8 +90,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader_triangle_and_lines) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: &shader_triangle_and_lines, @@ -113,8 +111,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader_triangle_and_lines) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: &shader_triangle_and_lines, @@ -140,8 +136,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader_triangle_and_lines) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: &shader_triangle_and_lines, @@ -200,8 +194,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: &shader, diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index 82d3efb44c4..cc787dea092 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -237,7 +237,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) .buffers(&vertex_buffers) .build(), fragment: Some(wgpu::FragmentState { @@ -265,7 +264,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) .buffers(&vertex_buffers) .build(), fragment: Some(wgpu::FragmentState { diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs index bc657dc4da7..128411c83fe 100644 --- a/examples/src/hello_triangle/mod.rs +++ b/examples/src/hello_triangle/mod.rs @@ -60,8 +60,6 @@ async fn run(event_loop: EventLoop<()>, window: Window) { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .buffers(&[]) - .compilation_options(Default::default()) .build(), fragment: Some(wgpu::FragmentState { module: &shader, diff --git a/examples/src/mipmap/mod.rs b/examples/src/mipmap/mod.rs index 88920af55e0..ae80fb5622e 100644 --- a/examples/src/mipmap/mod.rs +++ b/examples/src/mipmap/mod.rs @@ -89,8 +89,6 @@ impl Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: &shader, @@ -283,8 +281,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: &shader, diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index a6e4b5355db..1ccd7357240 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -54,7 +54,6 @@ impl Example { vertex: wgpu::VertexState::builder() .module(shader) .entry_point("vs_main") - .compilation_options(Default::default()) .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(size_of::() as wgpu::BufferAddress) .attributes(&wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4]) diff --git a/examples/src/render_to_texture/mod.rs b/examples/src/render_to_texture/mod.rs index 9073b55fb85..3cbe07ad71e 100644 --- a/examples/src/render_to_texture/mod.rs +++ b/examples/src/render_to_texture/mod.rs @@ -55,8 +55,6 @@ async fn run(_path: Option) { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: &shader, diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index 3b7131cf024..57640e057d3 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -493,8 +493,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_bake") - .compilation_options(Default::default()) - .buffers(&[vb_desc.clone()]) .build(), fragment: None, primitive: wgpu::PrimitiveState::builder() @@ -627,7 +625,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) .buffers(&[vb_desc]) .build(), fragment: Some(wgpu::FragmentState { diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index bf4e646b041..4d62d8cbd61 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -193,8 +193,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_sky") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: &shader, @@ -222,7 +220,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_entity") - .compilation_options(Default::default()) .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(size_of::() as wgpu::BufferAddress) .step_mode(wgpu::VertexStepMode::Vertex) diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index 0c04e42d8b5..ee53f222a29 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -127,7 +127,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) .buffers(&vertex_buffers) .build(), fragment: Some(wgpu::FragmentState { diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index b0fcf701d02..6597501b0e9 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -69,7 +69,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) .buffers(&vertex_buffers) .build(), fragment: Some(wgpu::FragmentState { @@ -110,7 +109,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) .buffers(&vertex_buffers) .build(), fragment: Some(wgpu::FragmentState { diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index 5606f475726..4f76df06dd2 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -316,7 +316,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&base_shader_module) .entry_point("vert_main") - .compilation_options(Default::default()) .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(vertex_size as wgpu::BufferAddress) .attributes( diff --git a/examples/src/timestamp_queries/mod.rs b/examples/src/timestamp_queries/mod.rs index 97a2e9f241a..60d696f3274 100644 --- a/examples/src/timestamp_queries/mod.rs +++ b/examples/src/timestamp_queries/mod.rs @@ -354,8 +354,6 @@ fn render_pass( vertex: wgpu::VertexState::builder() .module(module) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module, diff --git a/examples/src/uniform_values/mod.rs b/examples/src/uniform_values/mod.rs index b6db33c6a92..0df3e9604c2 100644 --- a/examples/src/uniform_values/mod.rs +++ b/examples/src/uniform_values/mod.rs @@ -175,8 +175,6 @@ impl WgpuContext { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: &shader, diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index bec9a1a9cef..c4f34a56211 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -510,7 +510,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&water_module) .entry_point("vs_main") - .compilation_options(Default::default()) // Layout of our vertices. This should match the structs // which are uploaded to the GPU. This should also be // ensured by tagging on either a `#[repr(C)]` onto a @@ -581,7 +580,6 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::builder() .module(&terrain_module) .entry_point("vs_main") - .compilation_options(Default::default()) .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(terrain_vertex_size as wgpu::BufferAddress) .attributes( diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 16e8d9f2732..4ea3afa7ef9 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -510,8 +510,6 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne vertex: wgpu::VertexState::builder() .module(&shader_module) .entry_point("") - .compilation_options(Default::default()) - .buffers(&[]) .build(), primitive: Default::default(), depth_stencil: None, @@ -789,8 +787,6 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf vertex: wgpu::VertexState::builder() .module(&trivial_shaders_with_some_reversed_bindings) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), primitive: Default::default(), depth_stencil: None, diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index 8a5344bab39..6bceb508275 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -92,10 +92,8 @@ async fn draw_test_with_reports( label: None, layout: Some(&ppl), vertex: wgpu::VertexState::builder() - .buffers(&[]) .module(&shader) .entry_point("vs_main_builtin") - .compilation_options(Default::default()) .build(), primitive: Default::default(), depth_stencil: None, diff --git a/tests/tests/nv12_texture/mod.rs b/tests/tests/nv12_texture/mod.rs index 148a833d4c1..3acb20ceec7 100644 --- a/tests/tests/nv12_texture/mod.rs +++ b/tests/tests/nv12_texture/mod.rs @@ -24,8 +24,6 @@ static NV12_TEXTURE_CREATION_SAMPLING: GpuTestConfiguration = GpuTestConfigurati vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: &shader, diff --git a/tests/tests/occlusion_query/mod.rs b/tests/tests/occlusion_query/mod.rs index cc8d4a0573e..3bfcafc69d6 100644 --- a/tests/tests/occlusion_query/mod.rs +++ b/tests/tests/occlusion_query/mod.rs @@ -32,8 +32,6 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new() vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: None, primitive: Default::default(), diff --git a/tests/tests/pipeline.rs b/tests/tests/pipeline.rs index 2142faa6c37..846deb9f757 100644 --- a/tests/tests/pipeline.rs +++ b/tests/tests/pipeline.rs @@ -195,8 +195,6 @@ static NO_TARGETLESS_RENDER: GpuTestConfiguration = GpuTestConfiguration::new() &ctx.device.create_shader_module(TRIVIAL_VERTEX_SHADER_DESC), ) .entry_point("main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), primitive: Default::default(), depth_stencil: None, diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index 62dc46e769c..d47a108f48d 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -102,8 +102,6 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { vertex: wgpu::VertexState::builder() .module(&vs_sm) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: &fs_sm, diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index 507ed09e618..b07c66d6f2f 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -51,7 +51,6 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = vertex: VertexState::builder() .module(&module) .entry_point("double_buffer_vert") - .compilation_options(Default::default()) .buffers(&[ VertexBufferLayout::builder() .array_stride(16) @@ -88,7 +87,6 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = vertex: VertexState::builder() .module(&module) .entry_point("single_buffer_vert") - .compilation_options(Default::default()) .buffers(&[VertexBufferLayout::builder() .array_stride(16) .attributes(&vertex_attr_array![0 => Float32x4]) diff --git a/tests/tests/regression/issue_4485.rs b/tests/tests/regression/issue_4485.rs index 68ebcd455fe..77f310a879c 100644 --- a/tests/tests/regression/issue_4485.rs +++ b/tests/tests/regression/issue_4485.rs @@ -44,8 +44,6 @@ async fn test_impl(ctx: &TestingContext) { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), primitive: Default::default(), depth_stencil: None, diff --git a/tests/tests/regression/issue_4514.rs b/tests/tests/regression/issue_4514.rs index c487ad3e0da..8b39250d909 100644 --- a/tests/tests/regression/issue_4514.rs +++ b/tests/tests/regression/issue_4514.rs @@ -44,8 +44,6 @@ async fn test_impl(ctx: &TestingContext) { vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), primitive: Default::default(), depth_stencil: None, diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index 001884843ff..0530dee1d1f 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -31,8 +31,6 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = vertex: VertexState::builder() .module(&module) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), primitive: Default::default(), depth_stencil: None, diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index cd47a7c73f8..c503543769d 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -497,7 +497,6 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { vertex: wgpu::VertexState::builder() .module(&sm) .entry_point("vs_main") - .compilation_options(Default::default()) .buffers(&[wgpu::VertexBufferLayout { array_stride: 4, step_mode: wgpu::VertexStepMode::Vertex, diff --git a/tests/tests/scissor_tests/mod.rs b/tests/tests/scissor_tests/mod.rs index f8b7b130cfb..f7872a9a597 100644 --- a/tests/tests/scissor_tests/mod.rs +++ b/tests/tests/scissor_tests/mod.rs @@ -42,8 +42,6 @@ async fn scissor_test_impl( vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), primitive: Default::default(), depth_stencil: None, diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index 7c4fcf52aef..136c5654134 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -122,7 +122,6 @@ async fn pulling_common( vertex: wgpu::VertexState::builder() .module(&shader) .entry_point("vs_main") - .compilation_options(Default::default()) .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(8) .attributes(&[wgpu::VertexAttribute { diff --git a/tests/tests/shader_view_format/mod.rs b/tests/tests/shader_view_format/mod.rs index db31022c158..76a61f2f464 100644 --- a/tests/tests/shader_view_format/mod.rs +++ b/tests/tests/shader_view_format/mod.rs @@ -89,8 +89,6 @@ async fn reinterpret( vertex: wgpu::VertexState::builder() .module(shader) .entry_point("vs_main") - .compilation_options(Default::default()) - .buffers(&[]) .build(), fragment: Some(wgpu::FragmentState { module: shader, diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 830313d4578..a24ab81be92 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -241,7 +241,6 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { .buffers(buffers) .module(&shader) .entry_point(test.entry_point) - .compilation_options(Default::default()) .build(), primitive: Default::default(), depth_stencil: None, diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index 217d70b5816..c93e9cc8bc9 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -255,10 +255,8 @@ async fn vertex_index_common(ctx: TestingContext) { label: None, layout: Some(&ppl), vertex: wgpu::VertexState::builder() - .buffers(&[]) .module(&shader) .entry_point("vs_main_builtin") - .compilation_options(Default::default()) .build(), primitive: Default::default(), depth_stencil: None, From 43eecd22e850667e42a8765993a09e7c2aad9700 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 9 Sep 2024 07:49:15 -0400 Subject: [PATCH 20/33] refactor: add `VertexState::from_module` builder entrypoint --- benches/benches/renderpass.rs | 6 ++---- examples/src/boids/mod.rs | 3 +-- examples/src/bunnymark/mod.rs | 3 +-- examples/src/conservative_raster/mod.rs | 12 ++++-------- examples/src/cube/mod.rs | 6 ++---- examples/src/hello_triangle/mod.rs | 3 +-- examples/src/mipmap/mod.rs | 6 ++---- examples/src/msaa_line/mod.rs | 3 +-- examples/src/render_to_texture/mod.rs | 3 +-- examples/src/shadow/mod.rs | 6 ++---- examples/src/skybox/mod.rs | 6 ++---- examples/src/srgb_blend/mod.rs | 3 +-- examples/src/stencil_triangles/mod.rs | 6 ++---- examples/src/texture_arrays/mod.rs | 3 +-- examples/src/timestamp_queries/mod.rs | 3 +-- examples/src/uniform_values/mod.rs | 3 +-- examples/src/water/mod.rs | 6 ++---- tests/tests/device.rs | 12 ++++++------ tests/tests/mem_leaks.rs | 3 +-- tests/tests/nv12_texture/mod.rs | 3 +-- tests/tests/occlusion_query/mod.rs | 3 +-- tests/tests/pipeline.rs | 3 +-- tests/tests/regression/issue_3349.rs | 3 +-- tests/tests/regression/issue_3457.rs | 6 ++---- tests/tests/regression/issue_4485.rs | 3 +-- tests/tests/regression/issue_4514.rs | 3 +-- tests/tests/regression/issue_5553.rs | 3 +-- tests/tests/render_pass_ownership.rs | 3 +-- tests/tests/scissor_tests/mod.rs | 3 +-- tests/tests/shader_primitive_index/mod.rs | 3 +-- tests/tests/shader_view_format/mod.rs | 3 +-- tests/tests/vertex_formats/mod.rs | 3 +-- tests/tests/vertex_indices/mod.rs | 3 +-- wgpu/src/api/render_pipeline.rs | 2 ++ 34 files changed, 51 insertions(+), 92 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index ba74bf5c6df..fbdd635ad6f 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -178,8 +178,7 @@ impl RenderpassState { .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&sm) + vertex: wgpu::VertexState::from_module(&sm) .entry_point("vs_main") .buffers(&vertex_buffer_layouts) .build(), @@ -263,8 +262,7 @@ impl RenderpassState { .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&bindless_pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&bindless_shader_module) + vertex: wgpu::VertexState::from_module(&bindless_shader_module) .entry_point("vs_main") .buffers(&vertex_buffer_layouts) .build(), diff --git a/examples/src/boids/mod.rs b/examples/src/boids/mod.rs index ae15a57d8fb..dd90d5201c1 100644 --- a/examples/src/boids/mod.rs +++ b/examples/src/boids/mod.rs @@ -123,8 +123,7 @@ impl crate::framework::Example for Example { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&render_pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&draw_shader) + vertex: wgpu::VertexState::from_module(&draw_shader) .entry_point("main_vs") .buffers(&[ wgpu::VertexBufferLayout::builder() diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index a041abbba6b..83fc76c766d 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -210,8 +210,7 @@ impl crate::framework::Example for Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index 5bb80c8cc3c..37db9273085 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -87,8 +87,7 @@ impl crate::framework::Example for Example { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Conservative Rasterization"), layout: Some(&pipeline_layout_empty), - vertex: wgpu::VertexState::builder() - .module(&shader_triangle_and_lines) + vertex: wgpu::VertexState::from_module(&shader_triangle_and_lines) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { @@ -108,8 +107,7 @@ impl crate::framework::Example for Example { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Regular Rasterization"), layout: Some(&pipeline_layout_empty), - vertex: wgpu::VertexState::builder() - .module(&shader_triangle_and_lines) + vertex: wgpu::VertexState::from_module(&shader_triangle_and_lines) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { @@ -133,8 +131,7 @@ impl crate::framework::Example for Example { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Lines"), layout: Some(&pipeline_layout_empty), - vertex: wgpu::VertexState::builder() - .module(&shader_triangle_and_lines) + vertex: wgpu::VertexState::from_module(&shader_triangle_and_lines) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { @@ -191,8 +188,7 @@ impl crate::framework::Example for Example { device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Upscale"), layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index cc787dea092..ec1dd8b53a4 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -234,8 +234,7 @@ impl crate::framework::Example for Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .buffers(&vertex_buffers) .build(), @@ -261,8 +260,7 @@ impl crate::framework::Example for Example { let pipeline_wire = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .buffers(&vertex_buffers) .build(), diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs index 128411c83fe..85a2b496858 100644 --- a/examples/src/hello_triangle/mod.rs +++ b/examples/src/hello_triangle/mod.rs @@ -57,8 +57,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) { let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { diff --git a/examples/src/mipmap/mod.rs b/examples/src/mipmap/mod.rs index ae80fb5622e..abc786fd24e 100644 --- a/examples/src/mipmap/mod.rs +++ b/examples/src/mipmap/mod.rs @@ -86,8 +86,7 @@ impl Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("blit"), layout: None, - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { @@ -278,8 +277,7 @@ impl crate::framework::Example for Example { let draw_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("draw"), layout: None, - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index 1ccd7357240..d92f8d92d0c 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -51,8 +51,7 @@ impl Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(shader) + vertex: wgpu::VertexState::from_module(shader) .entry_point("vs_main") .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(size_of::() as wgpu::BufferAddress) diff --git a/examples/src/render_to_texture/mod.rs b/examples/src/render_to_texture/mod.rs index 3cbe07ad71e..9ca0e156276 100644 --- a/examples/src/render_to_texture/mod.rs +++ b/examples/src/render_to_texture/mod.rs @@ -52,8 +52,7 @@ async fn run(_path: Option) { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: None, - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index 57640e057d3..74819e12bbc 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -490,8 +490,7 @@ impl crate::framework::Example for Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("shadow"), layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_bake") .build(), fragment: None, @@ -622,8 +621,7 @@ impl crate::framework::Example for Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("main"), layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .buffers(&[vb_desc]) .build(), diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index 4d62d8cbd61..24ceb572f56 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -190,8 +190,7 @@ impl crate::framework::Example for Example { let sky_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Sky"), layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_sky") .build(), fragment: Some(wgpu::FragmentState { @@ -217,8 +216,7 @@ impl crate::framework::Example for Example { let entity_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Entity"), layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_entity") .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(size_of::() as wgpu::BufferAddress) diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index ee53f222a29..58534cab1ef 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -124,8 +124,7 @@ impl crate::framework::Example for Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .buffers(&vertex_buffers) .build(), diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index 6597501b0e9..760d49a7ccc 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -66,8 +66,7 @@ impl crate::framework::Example for Example { let mask_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .buffers(&vertex_buffers) .build(), @@ -106,8 +105,7 @@ impl crate::framework::Example for Example { let outer_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .buffers(&vertex_buffers) .build(), diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index 4f76df06dd2..be72462a703 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -313,8 +313,7 @@ impl crate::framework::Example for Example { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&base_shader_module) + vertex: wgpu::VertexState::from_module(&base_shader_module) .entry_point("vert_main") .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(vertex_size as wgpu::BufferAddress) diff --git a/examples/src/timestamp_queries/mod.rs b/examples/src/timestamp_queries/mod.rs index 60d696f3274..54a39bce2b5 100644 --- a/examples/src/timestamp_queries/mod.rs +++ b/examples/src/timestamp_queries/mod.rs @@ -351,8 +351,7 @@ fn render_pass( let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(module) + vertex: wgpu::VertexState::from_module(module) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { diff --git a/examples/src/uniform_values/mod.rs b/examples/src/uniform_values/mod.rs index 0df3e9604c2..084a1d3bd13 100644 --- a/examples/src/uniform_values/mod.rs +++ b/examples/src/uniform_values/mod.rs @@ -172,8 +172,7 @@ impl WgpuContext { let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index c4f34a56211..e4c6b7edc15 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -507,8 +507,7 @@ impl crate::framework::Example for Example { // The "layout" is what uniforms will be needed. layout: Some(&water_pipeline_layout), // Vertex shader and input buffers - vertex: wgpu::VertexState::builder() - .module(&water_module) + vertex: wgpu::VertexState::from_module(&water_module) .entry_point("vs_main") // Layout of our vertices. This should match the structs // which are uploaded to the GPU. This should also be @@ -577,8 +576,7 @@ impl crate::framework::Example for Example { let terrain_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("terrain"), layout: Some(&terrain_pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&terrain_module) + vertex: wgpu::VertexState::from_module(&terrain_module) .entry_point("vs_main") .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(terrain_vertex_size as wgpu::BufferAddress) diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 4ea3afa7ef9..2232397e56b 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -507,8 +507,7 @@ static DEVICE_DESTROY_THEN_MORE: GpuTestConfiguration = GpuTestConfiguration::ne .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: None, - vertex: wgpu::VertexState::builder() - .module(&shader_module) + vertex: wgpu::VertexState::from_module(&shader_module) .entry_point("") .build(), primitive: Default::default(), @@ -784,10 +783,11 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf // Other fields below aren't interesting for this text. label: None, - vertex: wgpu::VertexState::builder() - .module(&trivial_shaders_with_some_reversed_bindings) - .entry_point("vs_main") - .build(), + vertex: wgpu::VertexState::from_module( + &trivial_shaders_with_some_reversed_bindings, + ) + .entry_point("vs_main") + .build(), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index 6bceb508275..d7ab75c67b9 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -91,8 +91,7 @@ async fn draw_test_with_reports( .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: Some(&ppl), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main_builtin") .build(), primitive: Default::default(), diff --git a/tests/tests/nv12_texture/mod.rs b/tests/tests/nv12_texture/mod.rs index 3acb20ceec7..733fa197890 100644 --- a/tests/tests/nv12_texture/mod.rs +++ b/tests/tests/nv12_texture/mod.rs @@ -21,8 +21,7 @@ static NV12_TEXTURE_CREATION_SAMPLING: GpuTestConfiguration = GpuTestConfigurati .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("nv12 pipeline"), layout: None, - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { diff --git a/tests/tests/occlusion_query/mod.rs b/tests/tests/occlusion_query/mod.rs index 3bfcafc69d6..43f92d9a37e 100644 --- a/tests/tests/occlusion_query/mod.rs +++ b/tests/tests/occlusion_query/mod.rs @@ -29,8 +29,7 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new() .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Pipeline"), layout: None, - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), fragment: None, diff --git a/tests/tests/pipeline.rs b/tests/tests/pipeline.rs index 846deb9f757..93f0a62a840 100644 --- a/tests/tests/pipeline.rs +++ b/tests/tests/pipeline.rs @@ -190,8 +190,7 @@ static NO_TARGETLESS_RENDER: GpuTestConfiguration = GpuTestConfiguration::new() .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: None, - vertex: wgpu::VertexState::builder() - .module( + vertex: wgpu::VertexState::from_module( &ctx.device.create_shader_module(TRIVIAL_VERTEX_SHADER_DESC), ) .entry_point("main") diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index d47a108f48d..f9e4e469a99 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -99,8 +99,7 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("pipeline"), layout: Some(&pll), - vertex: wgpu::VertexState::builder() - .module(&vs_sm) + vertex: wgpu::VertexState::from_module(&vs_sm) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index b07c66d6f2f..34c8eed19a6 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -48,8 +48,7 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = .create_render_pipeline(&RenderPipelineDescriptor { label: Some("Double Pipeline"), layout: Some(&pipeline_layout), - vertex: VertexState::builder() - .module(&module) + vertex: VertexState::from_module(&module) .entry_point("double_buffer_vert") .buffers(&[ VertexBufferLayout::builder() @@ -84,8 +83,7 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = .create_render_pipeline(&RenderPipelineDescriptor { label: Some("Single Pipeline"), layout: Some(&pipeline_layout), - vertex: VertexState::builder() - .module(&module) + vertex: VertexState::from_module(&module) .entry_point("single_buffer_vert") .buffers(&[VertexBufferLayout::builder() .array_stride(16) diff --git a/tests/tests/regression/issue_4485.rs b/tests/tests/regression/issue_4485.rs index 77f310a879c..75c67e38e8c 100644 --- a/tests/tests/regression/issue_4485.rs +++ b/tests/tests/regression/issue_4485.rs @@ -41,8 +41,7 @@ async fn test_impl(ctx: &TestingContext) { .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Pipeline"), layout: None, - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), primitive: Default::default(), diff --git a/tests/tests/regression/issue_4514.rs b/tests/tests/regression/issue_4514.rs index 8b39250d909..a9ae13b6b17 100644 --- a/tests/tests/regression/issue_4514.rs +++ b/tests/tests/regression/issue_4514.rs @@ -41,8 +41,7 @@ async fn test_impl(ctx: &TestingContext) { .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Pipeline"), layout: None, - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), primitive: Default::default(), diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index 0530dee1d1f..a0d61423425 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -28,8 +28,7 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = .create_render_pipeline(&RenderPipelineDescriptor { label: Some("Pipeline"), layout: Some(&pipeline_layout), - vertex: VertexState::builder() - .module(&module) + vertex: VertexState::from_module(&module) .entry_point("vs_main") .build(), primitive: Default::default(), diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index c503543769d..06944ac2df0 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -494,8 +494,7 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("pipeline"), layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::builder() - .module(&sm) + vertex: wgpu::VertexState::from_module(&sm) .entry_point("vs_main") .buffers(&[wgpu::VertexBufferLayout { array_stride: 4, diff --git a/tests/tests/scissor_tests/mod.rs b/tests/tests/scissor_tests/mod.rs index f7872a9a597..3f6f6e3b926 100644 --- a/tests/tests/scissor_tests/mod.rs +++ b/tests/tests/scissor_tests/mod.rs @@ -39,8 +39,7 @@ async fn scissor_test_impl( .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("Pipeline"), layout: None, - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), primitive: Default::default(), diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index 136c5654134..fcbb4a9bd10 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -119,8 +119,7 @@ async fn pulling_common( .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: None, layout: None, - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(8) diff --git a/tests/tests/shader_view_format/mod.rs b/tests/tests/shader_view_format/mod.rs index 76a61f2f464..55047e53b82 100644 --- a/tests/tests/shader_view_format/mod.rs +++ b/tests/tests/shader_view_format/mod.rs @@ -86,8 +86,7 @@ async fn reinterpret( .create_render_pipeline(&wgpu::RenderPipelineDescriptor { label: Some("reinterpret pipeline"), layout: None, - vertex: wgpu::VertexState::builder() - .module(shader) + vertex: wgpu::VertexState::from_module(shader) .entry_point("vs_main") .build(), fragment: Some(wgpu::FragmentState { diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index a24ab81be92..1c19064c4e8 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -237,9 +237,8 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { let pipeline_desc = wgpu::RenderPipelineDescriptor { label: None, layout: Some(&ppl), - vertex: wgpu::VertexState::builder() + vertex: wgpu::VertexState::from_module(&shader) .buffers(buffers) - .module(&shader) .entry_point(test.entry_point) .build(), primitive: Default::default(), diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index c93e9cc8bc9..373ebd727c3 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -254,8 +254,7 @@ async fn vertex_index_common(ctx: TestingContext) { let mut pipeline_desc = wgpu::RenderPipelineDescriptor { label: None, layout: Some(&ppl), - vertex: wgpu::VertexState::builder() - .module(&shader) + vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main_builtin") .build(), primitive: Default::default(), diff --git a/wgpu/src/api/render_pipeline.rs b/wgpu/src/api/render_pipeline.rs index c03a53f79e8..ce443c57628 100644 --- a/wgpu/src/api/render_pipeline.rs +++ b/wgpu/src/api/render_pipeline.rs @@ -67,8 +67,10 @@ static_assertions::assert_impl_all!(VertexBufferLayout<'_>: Send, Sync); /// Corresponds to [WebGPU `GPUVertexState`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpuvertexstate). #[derive(bon::Builder, Clone, Debug)] +#[builder(start_fn = from_module)] pub struct VertexState<'a> { /// The compiled shader module for this stage. + #[builder(start_fn)] pub module: &'a ShaderModule, /// The name of the entry point in the compiled shader to use. /// From c5d208e0f4e28ce069be49b118ba9fdfb72c7cb4 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 22:55:38 -0400 Subject: [PATCH 21/33] refactor!: give `BlendComponent` a builder API --- examples/src/cube/mod.rs | 10 +++++----- examples/src/water/mod.rs | 20 ++++++++++---------- wgpu-types/src/lib.rs | 5 ++++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index ec1dd8b53a4..497f8e19bfb 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -271,11 +271,11 @@ impl crate::framework::Example for Example { targets: &[Some(wgpu::ColorTargetState { format: config.view_formats[0], blend: Some(wgpu::BlendState { - color: wgpu::BlendComponent { - operation: wgpu::BlendOperation::Add, - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - }, + color: wgpu::BlendComponent::builder() + .operation(wgpu::BlendOperation::Add) + .src_factor(wgpu::BlendFactor::SrcAlpha) + .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) + .build(), alpha: wgpu::BlendComponent::REPLACE, }), write_mask: wgpu::ColorWrites::ALL, diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index e4c6b7edc15..6b4d447f9f5 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -529,16 +529,16 @@ impl crate::framework::Example for Example { targets: &[Some(wgpu::ColorTargetState { format: config.view_formats[0], blend: Some(wgpu::BlendState { - color: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::SrcAlpha, - dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, - operation: wgpu::BlendOperation::Add, - }, - alpha: wgpu::BlendComponent { - src_factor: wgpu::BlendFactor::One, - dst_factor: wgpu::BlendFactor::One, - operation: wgpu::BlendOperation::Max, - }, + color: wgpu::BlendComponent::builder() + .src_factor(wgpu::BlendFactor::SrcAlpha) + .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) + .operation(wgpu::BlendOperation::Add) + .build(), + alpha: wgpu::BlendComponent::builder() + .src_factor(wgpu::BlendFactor::One) + .dst_factor(wgpu::BlendFactor::One) + .operation(wgpu::BlendOperation::Max) + .build(), }), write_mask: wgpu::ColorWrites::ALL, })], diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 94134f14d63..a8cbc5aaeeb 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2072,16 +2072,19 @@ pub enum BlendOperation { /// Corresponds to [WebGPU `GPUBlendComponent`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpublendcomponent). #[repr(C)] -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[derive(bon::Builder, Clone, Copy, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct BlendComponent { /// Multiplier for the source, which is produced by the fragment shader. + #[builder(default = BlendFactor::One)] pub src_factor: BlendFactor, /// Multiplier for the destination, which is stored in the target. + #[builder(default = BlendFactor::Zero)] pub dst_factor: BlendFactor, /// The binary operation applied to the source and destination, /// multiplied by their respective factors. + #[builder(default)] pub operation: BlendOperation, } From 127af088e0399579747ec17b630686cc4820a7c1 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 22:55:18 -0400 Subject: [PATCH 22/33] WIP: refactor!: remove unnecessary fields in `BlendComponent` builder usage --- examples/src/cube/mod.rs | 1 - examples/src/water/mod.rs | 1 - 2 files changed, 2 deletions(-) diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index 497f8e19bfb..26dc6ee8a41 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -272,7 +272,6 @@ impl crate::framework::Example for Example { format: config.view_formats[0], blend: Some(wgpu::BlendState { color: wgpu::BlendComponent::builder() - .operation(wgpu::BlendOperation::Add) .src_factor(wgpu::BlendFactor::SrcAlpha) .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) .build(), diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index 6b4d447f9f5..b3e7a61b95b 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -532,7 +532,6 @@ impl crate::framework::Example for Example { color: wgpu::BlendComponent::builder() .src_factor(wgpu::BlendFactor::SrcAlpha) .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) - .operation(wgpu::BlendOperation::Add) .build(), alpha: wgpu::BlendComponent::builder() .src_factor(wgpu::BlendFactor::One) From 07eae288d5af93113815ab8599fc774c7a778722 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 22:47:58 -0400 Subject: [PATCH 23/33] refactor!: give `ColorTargetState` a builder API --- benches/benches/renderpass.rs | 24 ++++++++++------- examples/src/bunnymark/mod.rs | 12 +++++---- examples/src/cube/mod.rs | 24 +++++++++-------- examples/src/srgb_blend/mod.rs | 12 +++++---- examples/src/stencil_triangles/mod.rs | 12 +++++---- examples/src/water/mod.rs | 32 ++++++++++++----------- tests/tests/device.rs | 12 +++++---- tests/tests/mem_leaks.rs | 12 +++++---- tests/tests/regression/issue_3349.rs | 12 +++++---- tests/tests/regression/issue_3457.rs | 24 ++++++++++------- tests/tests/regression/issue_4485.rs | 12 +++++---- tests/tests/regression/issue_4514.rs | 12 +++++---- tests/tests/regression/issue_5553.rs | 12 +++++---- tests/tests/scissor_tests/mod.rs | 12 +++++---- tests/tests/shader_primitive_index/mod.rs | 12 +++++---- tests/tests/vertex_formats/mod.rs | 12 +++++---- tests/tests/vertex_indices/mod.rs | 12 +++++---- wgpu-hal/examples/halmark/main.rs | 12 +++++---- wgpu-types/src/lib.rs | 3 ++- 19 files changed, 158 insertions(+), 117 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index fbdd635ad6f..521d3437264 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -191,11 +191,13 @@ impl RenderpassState { fragment: Some(wgpu::FragmentState { module: &sm, entry_point: Some("fs_main"), - targets: &[Some(wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba8UnormSrgb, - blend: None, - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .blend(None) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], compilation_options: wgpu::PipelineCompilationOptions::default(), }), multiview: None, @@ -275,11 +277,13 @@ impl RenderpassState { fragment: Some(wgpu::FragmentState { module: &bindless_shader_module, entry_point: Some("fs_main"), - targets: &[Some(wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba8UnormSrgb, - blend: None, - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .blend(None) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], compilation_options: wgpu::PipelineCompilationOptions::default(), }), multiview: None, diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index 83fc76c766d..4e50bc847cb 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -217,11 +217,13 @@ impl crate::framework::Example for Example { module: &shader, entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format: config.view_formats[0], - blend: Some(wgpu::BlendState::ALPHA_BLENDING), - write_mask: wgpu::ColorWrites::default(), - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(config.view_formats[0]) + .blend(wgpu::BlendState::ALPHA_BLENDING) + .write_mask(wgpu::ColorWrites::default()) + .build(), + )], }), primitive: wgpu::PrimitiveState::builder() .topology(wgpu::PrimitiveTopology::TriangleStrip) diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index 26dc6ee8a41..e807928fe92 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -268,17 +268,19 @@ impl crate::framework::Example for Example { module: &shader, entry_point: Some("fs_wire"), compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format: config.view_formats[0], - blend: Some(wgpu::BlendState { - color: wgpu::BlendComponent::builder() - .src_factor(wgpu::BlendFactor::SrcAlpha) - .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) - .build(), - alpha: wgpu::BlendComponent::REPLACE, - }), - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(config.view_formats[0]) + .blend(wgpu::BlendState { + color: wgpu::BlendComponent::builder() + .src_factor(wgpu::BlendFactor::SrcAlpha) + .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) + .build(), + alpha: wgpu::BlendComponent::REPLACE, + }) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], }), primitive: wgpu::PrimitiveState::builder() .cull_mode(wgpu::Face::Back) diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index 58534cab1ef..358f032df3a 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -132,11 +132,13 @@ impl crate::framework::Example for Example { module: &shader, entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format: config.view_formats[0], - blend: Some(wgpu::BlendState::ALPHA_BLENDING), - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(config.view_formats[0]) + .blend(wgpu::BlendState::ALPHA_BLENDING) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], }), primitive: wgpu::PrimitiveState::builder() .cull_mode(wgpu::Face::Back) diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index 760d49a7ccc..c577841824b 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -74,11 +74,13 @@ impl crate::framework::Example for Example { module: &shader, entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format: config.view_formats[0], - blend: None, - write_mask: wgpu::ColorWrites::empty(), - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(config.view_formats[0]) + .maybe_blend(None) + .write_mask(wgpu::ColorWrites::empty()) + .build(), + )], }), primitive: Default::default(), depth_stencil: Some(wgpu::DepthStencilState { diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index b3e7a61b95b..5006a34b3e3 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -526,21 +526,23 @@ impl crate::framework::Example for Example { compilation_options: Default::default(), // Describes how the colour will be interpolated // and assigned to the output attachment. - targets: &[Some(wgpu::ColorTargetState { - format: config.view_formats[0], - blend: Some(wgpu::BlendState { - color: wgpu::BlendComponent::builder() - .src_factor(wgpu::BlendFactor::SrcAlpha) - .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) - .build(), - alpha: wgpu::BlendComponent::builder() - .src_factor(wgpu::BlendFactor::One) - .dst_factor(wgpu::BlendFactor::One) - .operation(wgpu::BlendOperation::Max) - .build(), - }), - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(config.view_formats[0]) + .blend(wgpu::BlendState { + color: wgpu::BlendComponent::builder() + .src_factor(wgpu::BlendFactor::SrcAlpha) + .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) + .build(), + alpha: wgpu::BlendComponent::builder() + .src_factor(wgpu::BlendFactor::One) + .dst_factor(wgpu::BlendFactor::One) + .operation(wgpu::BlendOperation::Max) + .build(), + }) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], }), // How the triangles will be rasterized. This is more important // for the terrain because of the beneath-the water shot. diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 2232397e56b..78dbcaa557f 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -773,11 +773,13 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf module: &trivial_shaders_with_some_reversed_bindings, entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(wgt::ColorTargetState { - format: wgt::TextureFormat::Bgra8Unorm, - blend: None, - write_mask: wgt::ColorWrites::ALL, - })], + targets: &[Some( + wgt::ColorTargetState::builder() + .format(wgt::TextureFormat::Bgra8Unorm) + .blend(None) + .write_mask(wgt::ColorWrites::ALL) + .build(), + )], }), layout: None, diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index d7ab75c67b9..32a7b5a6b71 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -101,11 +101,13 @@ async fn draw_test_with_reports( module: &shader, entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba8Unorm, - blend: None, - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .blend(None) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], }), multiview: None, cache: None, diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index f9e4e469a99..fe7cc599de8 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -106,11 +106,13 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { module: &fs_sm, entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba8Unorm, - blend: None, - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .blend(None) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], }), primitive: Default::default(), depth_stencil: None, diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index 34c8eed19a6..aac9d8862e4 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -68,11 +68,13 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = module: &module, entry_point: Some("double_buffer_frag"), compilation_options: Default::default(), - targets: &[Some(ColorTargetState { - format: TextureFormat::Rgba8Unorm, - blend: None, - write_mask: ColorWrites::all(), - })], + targets: &[Some( + ColorTargetState::builder() + .format(TextureFormat::Rgba8Unorm) + .blend(None) + .write_mask(ColorWrites::all()) + .build(), + )], }), multiview: None, cache: None, @@ -97,11 +99,13 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = module: &module, entry_point: Some("single_buffer_frag"), compilation_options: Default::default(), - targets: &[Some(ColorTargetState { - format: TextureFormat::Rgba8Unorm, - blend: None, - write_mask: ColorWrites::all(), - })], + targets: &[Some( + ColorTargetState::builder() + .format(TextureFormat::Rgba8Unorm) + .blend(None) + .write_mask(ColorWrites::all()) + .build(), + )], }), multiview: None, cache: None, diff --git a/tests/tests/regression/issue_4485.rs b/tests/tests/regression/issue_4485.rs index 75c67e38e8c..9ec1888e538 100644 --- a/tests/tests/regression/issue_4485.rs +++ b/tests/tests/regression/issue_4485.rs @@ -51,11 +51,13 @@ async fn test_impl(ctx: &TestingContext) { module: &shader, entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba8Unorm, - blend: None, - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .blend(None) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], }), multiview: None, cache: None, diff --git a/tests/tests/regression/issue_4514.rs b/tests/tests/regression/issue_4514.rs index a9ae13b6b17..e0574133749 100644 --- a/tests/tests/regression/issue_4514.rs +++ b/tests/tests/regression/issue_4514.rs @@ -51,11 +51,13 @@ async fn test_impl(ctx: &TestingContext) { module: &shader, entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba8Unorm, - blend: None, - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .blend(None) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], }), multiview: None, cache: None, diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index a0d61423425..e08aa71502f 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -38,11 +38,13 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = module: &module, entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(ColorTargetState { - format: TextureFormat::Rgba8Unorm, - blend: None, - write_mask: ColorWrites::all(), - })], + targets: &[Some( + ColorTargetState::builder() + .format(TextureFormat::Rgba8Unorm) + .blend(None) + .write_mask(ColorWrites::all()) + .build(), + )], }), multiview: None, cache: None, diff --git a/tests/tests/scissor_tests/mod.rs b/tests/tests/scissor_tests/mod.rs index 3f6f6e3b926..e37c968daa9 100644 --- a/tests/tests/scissor_tests/mod.rs +++ b/tests/tests/scissor_tests/mod.rs @@ -49,11 +49,13 @@ async fn scissor_test_impl( module: &shader, entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba8Unorm, - blend: None, - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .blend(None) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], }), multiview: None, cache: None, diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index fcbb4a9bd10..07235efe16d 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -137,11 +137,13 @@ async fn pulling_common( module: &shader, entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba8Unorm, - blend: None, - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .blend(None) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], }), multiview: None, cache: None, diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 1c19064c4e8..59ec9f9fa16 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -248,11 +248,13 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { module: &shader, entry_point: Some("fragment_main"), compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba8Unorm, - blend: None, - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .blend(None) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], }), multiview: None, cache: None, diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index 373ebd727c3..a5dd4459461 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -264,11 +264,13 @@ async fn vertex_index_common(ctx: TestingContext) { module: &shader, entry_point: Some("fs_main"), compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format: wgpu::TextureFormat::Rgba8Unorm, - blend: None, - write_mask: wgpu::ColorWrites::ALL, - })], + targets: &[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .blend(None) + .write_mask(wgpu::ColorWrites::ALL) + .build(), + )], }), multiview: None, cache: None, diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 21170c6229b..160d854e757 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -272,11 +272,13 @@ impl Example { .build(), depth_stencil: None, multisample: Default::default(), - color_targets: &[Some(wgt::ColorTargetState { - format: surface_config.format, - blend: Some(wgt::BlendState::ALPHA_BLENDING), - write_mask: wgt::ColorWrites::default(), - })], + color_targets: &[Some( + wgt::ColorTargetState::builder() + .format(surface_config.format) + .blend(wgt::BlendState::ALPHA_BLENDING) + .write_mask(wgt::ColorWrites::default()) + .build(), + )], multiview: None, cache: None, }; diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index a8cbc5aaeeb..f852d2a1af3 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2168,7 +2168,7 @@ impl BlendState { /// Corresponds to [WebGPU `GPUColorTargetState`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpucolortargetstate). #[repr(C)] -#[derive(Clone, Debug, PartialEq, Eq, Hash)] +#[derive(bon::Builder, Clone, Debug, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct ColorTargetState { @@ -2182,6 +2182,7 @@ pub struct ColorTargetState { pub blend: Option, /// Mask which enables/disables writes to different color/alpha channel. #[cfg_attr(feature = "serde", serde(default))] + #[builder(default)] pub write_mask: ColorWrites, } From 62141b062835cb08fb86365245055fb3aa82223d Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 22:48:17 -0400 Subject: [PATCH 24/33] WIP: refactor!: remove unnecessary fields in `ColorTargetState` builder usage --- benches/benches/renderpass.rs | 4 ---- examples/src/bunnymark/mod.rs | 1 - examples/src/cube/mod.rs | 1 - examples/src/srgb_blend/mod.rs | 1 - examples/src/stencil_triangles/mod.rs | 1 - examples/src/water/mod.rs | 1 - tests/tests/device.rs | 2 -- tests/tests/mem_leaks.rs | 2 -- tests/tests/regression/issue_3349.rs | 2 -- tests/tests/regression/issue_3457.rs | 4 ---- tests/tests/regression/issue_4485.rs | 2 -- tests/tests/regression/issue_4514.rs | 2 -- tests/tests/regression/issue_5553.rs | 2 -- tests/tests/scissor_tests/mod.rs | 2 -- tests/tests/shader_primitive_index/mod.rs | 2 -- tests/tests/vertex_formats/mod.rs | 2 -- tests/tests/vertex_indices/mod.rs | 2 -- wgpu-hal/examples/halmark/main.rs | 1 - 18 files changed, 34 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index 521d3437264..42e8b5f5cf7 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -194,8 +194,6 @@ impl RenderpassState { targets: &[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8UnormSrgb) - .blend(None) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], compilation_options: wgpu::PipelineCompilationOptions::default(), @@ -280,8 +278,6 @@ impl RenderpassState { targets: &[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8UnormSrgb) - .blend(None) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], compilation_options: wgpu::PipelineCompilationOptions::default(), diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index 4e50bc847cb..8b863546299 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -221,7 +221,6 @@ impl crate::framework::Example for Example { wgpu::ColorTargetState::builder() .format(config.view_formats[0]) .blend(wgpu::BlendState::ALPHA_BLENDING) - .write_mask(wgpu::ColorWrites::default()) .build(), )], }), diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index e807928fe92..e09dfaa370e 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -278,7 +278,6 @@ impl crate::framework::Example for Example { .build(), alpha: wgpu::BlendComponent::REPLACE, }) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], }), diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index 358f032df3a..51a238ad645 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -136,7 +136,6 @@ impl crate::framework::Example for Example { wgpu::ColorTargetState::builder() .format(config.view_formats[0]) .blend(wgpu::BlendState::ALPHA_BLENDING) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], }), diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index c577841824b..1db6f86c86d 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -77,7 +77,6 @@ impl crate::framework::Example for Example { targets: &[Some( wgpu::ColorTargetState::builder() .format(config.view_formats[0]) - .maybe_blend(None) .write_mask(wgpu::ColorWrites::empty()) .build(), )], diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index 5006a34b3e3..fcc52b31592 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -540,7 +540,6 @@ impl crate::framework::Example for Example { .operation(wgpu::BlendOperation::Max) .build(), }) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], }), diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 78dbcaa557f..b6d45b30f33 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -776,8 +776,6 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf targets: &[Some( wgt::ColorTargetState::builder() .format(wgt::TextureFormat::Bgra8Unorm) - .blend(None) - .write_mask(wgt::ColorWrites::ALL) .build(), )], }), diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index 32a7b5a6b71..4f94294d564 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -104,8 +104,6 @@ async fn draw_test_with_reports( targets: &[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) - .blend(None) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], }), diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index fe7cc599de8..250e38b806e 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -109,8 +109,6 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { targets: &[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) - .blend(None) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], }), diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index aac9d8862e4..28afbaa934e 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -71,8 +71,6 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = targets: &[Some( ColorTargetState::builder() .format(TextureFormat::Rgba8Unorm) - .blend(None) - .write_mask(ColorWrites::all()) .build(), )], }), @@ -102,8 +100,6 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = targets: &[Some( ColorTargetState::builder() .format(TextureFormat::Rgba8Unorm) - .blend(None) - .write_mask(ColorWrites::all()) .build(), )], }), diff --git a/tests/tests/regression/issue_4485.rs b/tests/tests/regression/issue_4485.rs index 9ec1888e538..b22718b9d7e 100644 --- a/tests/tests/regression/issue_4485.rs +++ b/tests/tests/regression/issue_4485.rs @@ -54,8 +54,6 @@ async fn test_impl(ctx: &TestingContext) { targets: &[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) - .blend(None) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], }), diff --git a/tests/tests/regression/issue_4514.rs b/tests/tests/regression/issue_4514.rs index e0574133749..4dc395b846d 100644 --- a/tests/tests/regression/issue_4514.rs +++ b/tests/tests/regression/issue_4514.rs @@ -54,8 +54,6 @@ async fn test_impl(ctx: &TestingContext) { targets: &[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) - .blend(None) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], }), diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index e08aa71502f..46b0d7b6109 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -41,8 +41,6 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = targets: &[Some( ColorTargetState::builder() .format(TextureFormat::Rgba8Unorm) - .blend(None) - .write_mask(ColorWrites::all()) .build(), )], }), diff --git a/tests/tests/scissor_tests/mod.rs b/tests/tests/scissor_tests/mod.rs index e37c968daa9..f790a15bef2 100644 --- a/tests/tests/scissor_tests/mod.rs +++ b/tests/tests/scissor_tests/mod.rs @@ -52,8 +52,6 @@ async fn scissor_test_impl( targets: &[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) - .blend(None) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], }), diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index 07235efe16d..e9bdcca7776 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -140,8 +140,6 @@ async fn pulling_common( targets: &[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) - .blend(None) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], }), diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 59ec9f9fa16..410b06ed8e9 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -251,8 +251,6 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { targets: &[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) - .blend(None) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], }), diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index a5dd4459461..de8e94138fc 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -267,8 +267,6 @@ async fn vertex_index_common(ctx: TestingContext) { targets: &[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) - .blend(None) - .write_mask(wgpu::ColorWrites::ALL) .build(), )], }), diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 160d854e757..ce85ffad2c4 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -276,7 +276,6 @@ impl Example { wgt::ColorTargetState::builder() .format(surface_config.format) .blend(wgt::BlendState::ALPHA_BLENDING) - .write_mask(wgt::ColorWrites::default()) .build(), )], multiview: None, From 860342c13a45d3b508da44a6804057d8ef0e96ae Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 22:43:34 -0400 Subject: [PATCH 25/33] refactor!: give `FragmentState` a builder API --- benches/benches/renderpass.rs | 44 ++++++++-------- examples/src/boids/mod.rs | 14 ++--- examples/src/bunnymark/mod.rs | 23 +++++---- examples/src/conservative_raster/mod.rs | 56 +++++++++++--------- examples/src/cube/mod.rs | 50 +++++++++--------- examples/src/hello_triangle/mod.rs | 14 ++--- examples/src/mipmap/mod.rs | 28 +++++----- examples/src/msaa_line/mod.rs | 14 ++--- examples/src/render_to_texture/mod.rs | 14 ++--- examples/src/shadow/mod.rs | 22 ++++---- examples/src/skybox/mod.rs | 28 +++++----- examples/src/srgb_blend/mod.rs | 23 +++++---- examples/src/stencil_triangles/mod.rs | 38 +++++++------- examples/src/texture_arrays/mod.rs | 14 ++--- examples/src/timestamp_queries/mod.rs | 14 ++--- examples/src/uniform_values/mod.rs | 14 ++--- examples/src/water/mod.rs | 62 ++++++++++++----------- tests/tests/device.rs | 22 ++++---- tests/tests/mem_leaks.rs | 21 ++++---- tests/tests/nv12_texture/mod.rs | 14 ++--- tests/tests/pipeline.rs | 8 +-- tests/tests/regression/issue_3349.rs | 22 ++++---- tests/tests/regression/issue_3457.rs | 44 ++++++++-------- tests/tests/regression/issue_4485.rs | 22 ++++---- tests/tests/regression/issue_4514.rs | 22 ++++---- tests/tests/regression/issue_5553.rs | 23 +++++---- tests/tests/render_pass_ownership.rs | 14 ++--- tests/tests/scissor_tests/mod.rs | 22 ++++---- tests/tests/shader_primitive_index/mod.rs | 22 ++++---- tests/tests/shader_view_format/mod.rs | 14 ++--- tests/tests/vertex_formats/mod.rs | 29 ++++++----- tests/tests/vertex_indices/mod.rs | 23 +++++---- wgpu/src/api/render_pipeline.rs | 3 +- 33 files changed, 440 insertions(+), 357 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index 42e8b5f5cf7..8356a007b67 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -188,16 +188,18 @@ impl RenderpassState { .build(), depth_stencil: None, multisample: Default::default(), - fragment: Some(wgpu::FragmentState { - module: &sm, - entry_point: Some("fs_main"), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(wgpu::TextureFormat::Rgba8UnormSrgb) - .build(), - )], - compilation_options: wgpu::PipelineCompilationOptions::default(), - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&sm) + .entry_point("fs_main") + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .build(), + )]) + .compilation_options(wgpu::PipelineCompilationOptions::default()) + .build(), + ), multiview: None, cache: None, }); @@ -272,16 +274,18 @@ impl RenderpassState { .build(), depth_stencil: None, multisample: Default::default(), - fragment: Some(wgpu::FragmentState { - module: &bindless_shader_module, - entry_point: Some("fs_main"), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(wgpu::TextureFormat::Rgba8UnormSrgb) - .build(), - )], - compilation_options: wgpu::PipelineCompilationOptions::default(), - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&bindless_shader_module) + .entry_point("fs_main") + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .build(), + )]) + .compilation_options(wgpu::PipelineCompilationOptions::default()) + .build(), + ), multiview: None, cache: None, }), diff --git a/examples/src/boids/mod.rs b/examples/src/boids/mod.rs index dd90d5201c1..c4ae43aa025 100644 --- a/examples/src/boids/mod.rs +++ b/examples/src/boids/mod.rs @@ -137,12 +137,14 @@ impl crate::framework::Example for Example { .build(), ]) .build(), - fragment: Some(wgpu::FragmentState { - module: &draw_shader, - entry_point: Some("main_fs"), - compilation_options: Default::default(), - targets: &[Some(config.view_formats[0].into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&draw_shader) + .entry_point("main_fs") + .compilation_options(Default::default()) + .targets(&[Some(config.view_formats[0].into())]) + .build(), + ), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index 8b863546299..e997d733e9f 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -213,17 +213,18 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(config.view_formats[0]) - .blend(wgpu::BlendState::ALPHA_BLENDING) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(config.view_formats[0]) + .blend(wgpu::BlendState::ALPHA_BLENDING) + .build(), + )]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .topology(wgpu::PrimitiveTopology::TriangleStrip) .strip_index_format(wgpu::IndexFormat::Uint16) diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index 37db9273085..5581d34a903 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -90,12 +90,14 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::from_module(&shader_triangle_and_lines) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: &shader_triangle_and_lines, - entry_point: Some("fs_main_red"), - compilation_options: Default::default(), - targets: &[Some(RENDER_TARGET_FORMAT.into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader_triangle_and_lines) + .entry_point("fs_main_red") + .compilation_options(Default::default()) + .targets(&[Some(RENDER_TARGET_FORMAT.into())]) + .build(), + ), primitive: wgpu::PrimitiveState::builder().conservative(true).build(), depth_stencil: None, multisample: Default::default(), @@ -110,12 +112,14 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::from_module(&shader_triangle_and_lines) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: &shader_triangle_and_lines, - entry_point: Some("fs_main_blue"), - compilation_options: Default::default(), - targets: &[Some(RENDER_TARGET_FORMAT.into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader_triangle_and_lines) + .entry_point("fs_main_blue") + .compilation_options(Default::default()) + .targets(&[Some(RENDER_TARGET_FORMAT.into())]) + .build(), + ), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), @@ -134,12 +138,14 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::from_module(&shader_triangle_and_lines) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: &shader_triangle_and_lines, - entry_point: Some("fs_main_white"), - compilation_options: Default::default(), - targets: &[Some(config.view_formats[0].into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader_triangle_and_lines) + .entry_point("fs_main_white") + .compilation_options(Default::default()) + .targets(&[Some(config.view_formats[0].into())]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .polygon_mode(wgpu::PolygonMode::Line) .topology(wgpu::PrimitiveTopology::LineStrip) @@ -191,12 +197,14 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(config.view_formats[0].into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(config.view_formats[0].into())]) + .build(), + ), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index e09dfaa370e..4bb89a12c23 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -238,12 +238,14 @@ impl crate::framework::Example for Example { .entry_point("vs_main") .buffers(&vertex_buffers) .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(config.view_formats[0].into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(config.view_formats[0].into())]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .cull_mode(wgpu::Face::Back) .build(), @@ -264,23 +266,25 @@ impl crate::framework::Example for Example { .entry_point("vs_main") .buffers(&vertex_buffers) .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_wire"), - compilation_options: Default::default(), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(config.view_formats[0]) - .blend(wgpu::BlendState { - color: wgpu::BlendComponent::builder() - .src_factor(wgpu::BlendFactor::SrcAlpha) - .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) - .build(), - alpha: wgpu::BlendComponent::REPLACE, - }) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_wire") + .compilation_options(Default::default()) + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(config.view_formats[0]) + .blend(wgpu::BlendState { + color: wgpu::BlendComponent::builder() + .src_factor(wgpu::BlendFactor::SrcAlpha) + .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) + .build(), + alpha: wgpu::BlendComponent::REPLACE, + }) + .build(), + )]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .cull_mode(wgpu::Face::Back) .polygon_mode(wgpu::PolygonMode::Line) diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs index 85a2b496858..4aaed1f156e 100644 --- a/examples/src/hello_triangle/mod.rs +++ b/examples/src/hello_triangle/mod.rs @@ -60,12 +60,14 @@ async fn run(event_loop: EventLoop<()>, window: Window) { vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(swapchain_format.into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(swapchain_format.into())]) + .build(), + ), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/examples/src/mipmap/mod.rs b/examples/src/mipmap/mod.rs index abc786fd24e..d45b03b6765 100644 --- a/examples/src/mipmap/mod.rs +++ b/examples/src/mipmap/mod.rs @@ -89,12 +89,14 @@ impl Example { vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(TEXTURE_FORMAT.into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(TEXTURE_FORMAT.into())]) + .build(), + ), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), @@ -280,12 +282,14 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(config.view_formats[0].into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(config.view_formats[0].into())]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .topology(wgpu::PrimitiveTopology::TriangleStrip) .cull_mode(wgpu::Face::Back) diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index d92f8d92d0c..fbc54b7efc4 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -58,12 +58,14 @@ impl Example { .attributes(&wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4]) .build()]) .build(), - fragment: Some(wgpu::FragmentState { - module: shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(config.view_formats[0].into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(config.view_formats[0].into())]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .topology(wgpu::PrimitiveTopology::LineList) .front_face(wgpu::FrontFace::Ccw) diff --git a/examples/src/render_to_texture/mod.rs b/examples/src/render_to_texture/mod.rs index 9ca0e156276..4c58e425c7c 100644 --- a/examples/src/render_to_texture/mod.rs +++ b/examples/src/render_to_texture/mod.rs @@ -55,12 +55,14 @@ async fn run(_path: Option) { vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(wgpu::TextureFormat::Rgba8UnormSrgb.into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(wgpu::TextureFormat::Rgba8UnormSrgb.into())]) + .build(), + ), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index 74819e12bbc..b1e8d172bdf 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -625,16 +625,18 @@ impl crate::framework::Example for Example { .entry_point("vs_main") .buffers(&[vb_desc]) .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some(if supports_storage_resources { - "fs_main" - } else { - "fs_main_without_storage" - }), - compilation_options: Default::default(), - targets: &[Some(config.view_formats[0].into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point(if supports_storage_resources { + "fs_main" + } else { + "fs_main_without_storage" + }) + .compilation_options(Default::default()) + .targets(&[Some(config.view_formats[0].into())]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .cull_mode(wgpu::Face::Back) .build(), diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index 24ceb572f56..30afb772eaf 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -193,12 +193,14 @@ impl crate::framework::Example for Example { vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_sky") .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_sky"), - compilation_options: Default::default(), - targets: &[Some(config.view_formats[0].into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_sky") + .compilation_options(Default::default()) + .targets(&[Some(config.view_formats[0].into())]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .front_face(wgpu::FrontFace::Cw) .build(), @@ -224,12 +226,14 @@ impl crate::framework::Example for Example { .attributes(&wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3]) .build()]) .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_entity"), - compilation_options: Default::default(), - targets: &[Some(config.view_formats[0].into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_entity") + .compilation_options(Default::default()) + .targets(&[Some(config.view_formats[0].into())]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .front_face(wgpu::FrontFace::Cw) .build(), diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index 51a238ad645..f763c6100e7 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -128,17 +128,18 @@ impl crate::framework::Example for Example { .entry_point("vs_main") .buffers(&vertex_buffers) .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(config.view_formats[0]) - .blend(wgpu::BlendState::ALPHA_BLENDING) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(config.view_formats[0]) + .blend(wgpu::BlendState::ALPHA_BLENDING) + .build(), + )]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .cull_mode(wgpu::Face::Back) .build(), diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index 1db6f86c86d..e1814c9d00a 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -70,17 +70,19 @@ impl crate::framework::Example for Example { .entry_point("vs_main") .buffers(&vertex_buffers) .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(config.view_formats[0]) - .write_mask(wgpu::ColorWrites::empty()) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(config.view_formats[0]) + .write_mask(wgpu::ColorWrites::empty()) + .build(), + )]) + .build(), + ), primitive: Default::default(), depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Stencil8, @@ -110,12 +112,14 @@ impl crate::framework::Example for Example { .entry_point("vs_main") .buffers(&vertex_buffers) .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(config.view_formats[0].into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(config.view_formats[0].into())]) + .build(), + ), primitive: Default::default(), depth_stencil: Some(wgpu::DepthStencilState { format: wgpu::TextureFormat::Stencil8, diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index be72462a703..2bc2c7ce05d 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -322,12 +322,14 @@ impl crate::framework::Example for Example { ) .build()]) .build(), - fragment: Some(wgpu::FragmentState { - module: fragment_shader_module, - entry_point: Some(fragment_entry_point), - compilation_options: Default::default(), - targets: &[Some(config.view_formats[0].into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(fragment_shader_module) + .entry_point(fragment_entry_point) + .compilation_options(Default::default()) + .targets(&[Some(config.view_formats[0].into())]) + .build(), + ), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/examples/src/timestamp_queries/mod.rs b/examples/src/timestamp_queries/mod.rs index 54a39bce2b5..58e279a0aa9 100644 --- a/examples/src/timestamp_queries/mod.rs +++ b/examples/src/timestamp_queries/mod.rs @@ -354,12 +354,14 @@ fn render_pass( vertex: wgpu::VertexState::from_module(module) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(format.into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(module) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(format.into())]) + .build(), + ), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/examples/src/uniform_values/mod.rs b/examples/src/uniform_values/mod.rs index 084a1d3bd13..857a67184c3 100644 --- a/examples/src/uniform_values/mod.rs +++ b/examples/src/uniform_values/mod.rs @@ -175,12 +175,14 @@ impl WgpuContext { vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(swapchain_format.into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(swapchain_format.into())]) + .build(), + ), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index fcc52b31592..c444bce80c3 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -520,29 +520,31 @@ impl crate::framework::Example for Example { .build()]) .build(), // Fragment shader and output targets - fragment: Some(wgpu::FragmentState { - module: &water_module, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - // Describes how the colour will be interpolated - // and assigned to the output attachment. - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(config.view_formats[0]) - .blend(wgpu::BlendState { - color: wgpu::BlendComponent::builder() - .src_factor(wgpu::BlendFactor::SrcAlpha) - .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) - .build(), - alpha: wgpu::BlendComponent::builder() - .src_factor(wgpu::BlendFactor::One) - .dst_factor(wgpu::BlendFactor::One) - .operation(wgpu::BlendOperation::Max) - .build(), - }) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&water_module) + .entry_point("fs_main") + .compilation_options(Default::default()) + // Describes how the colour will be interpolated + // and assigned to the output attachment. + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(config.view_formats[0]) + .blend(wgpu::BlendState { + color: wgpu::BlendComponent::builder() + .src_factor(wgpu::BlendFactor::SrcAlpha) + .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) + .build(), + alpha: wgpu::BlendComponent::builder() + .src_factor(wgpu::BlendFactor::One) + .dst_factor(wgpu::BlendFactor::One) + .operation(wgpu::BlendOperation::Max) + .build(), + }) + .build(), + )]) + .build(), + ), // How the triangles will be rasterized. This is more important // for the terrain because of the beneath-the water shot. // This is also dependent on how the triangles are being generated. @@ -585,12 +587,14 @@ impl crate::framework::Example for Example { ) .build()]) .build(), - fragment: Some(wgpu::FragmentState { - module: &terrain_module, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(config.view_formats[0].into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&terrain_module) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(config.view_formats[0].into())]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .cull_mode(wgpu::Face::Front) .build(), diff --git a/tests/tests/device.rs b/tests/tests/device.rs index b6d45b30f33..3e46267867e 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -769,16 +769,18 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf let render_pipeline = ctx .device .create_render_pipeline(&wgpu::RenderPipelineDescriptor { - fragment: Some(wgpu::FragmentState { - module: &trivial_shaders_with_some_reversed_bindings, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some( - wgt::ColorTargetState::builder() - .format(wgt::TextureFormat::Bgra8Unorm) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&trivial_shaders_with_some_reversed_bindings) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some( + wgt::ColorTargetState::builder() + .format(wgt::TextureFormat::Bgra8Unorm) + .build(), + )]) + .build(), + ), layout: None, // Other fields below aren't interesting for this text. diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index 4f94294d564..5cf9b1af84f 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -97,16 +97,17 @@ async fn draw_test_with_reports( primitive: Default::default(), depth_stencil: None, multisample: Default::default(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(wgpu::TextureFormat::Rgba8Unorm) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .build(), + )]) + .build(), + ), multiview: None, cache: None, }); diff --git a/tests/tests/nv12_texture/mod.rs b/tests/tests/nv12_texture/mod.rs index 733fa197890..e70db06441d 100644 --- a/tests/tests/nv12_texture/mod.rs +++ b/tests/tests/nv12_texture/mod.rs @@ -24,12 +24,14 @@ static NV12_TEXTURE_CREATION_SAMPLING: GpuTestConfiguration = GpuTestConfigurati vertex: wgpu::VertexState::from_module(&shader) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(target_format.into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(target_format.into())]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .topology(wgpu::PrimitiveTopology::TriangleStrip) .strip_index_format(wgpu::IndexFormat::Uint32) diff --git a/tests/tests/pipeline.rs b/tests/tests/pipeline.rs index 93f0a62a840..028bfd20f58 100644 --- a/tests/tests/pipeline.rs +++ b/tests/tests/pipeline.rs @@ -191,10 +191,10 @@ static NO_TARGETLESS_RENDER: GpuTestConfiguration = GpuTestConfiguration::new() label: None, layout: None, vertex: wgpu::VertexState::from_module( - &ctx.device.create_shader_module(TRIVIAL_VERTEX_SHADER_DESC), - ) - .entry_point("main") - .build(), + &ctx.device.create_shader_module(TRIVIAL_VERTEX_SHADER_DESC), + ) + .entry_point("main") + .build(), primitive: Default::default(), depth_stencil: None, multisample: wgpu::MultisampleState { diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index 250e38b806e..7bf941896d5 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -102,16 +102,18 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { vertex: wgpu::VertexState::from_module(&vs_sm) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: &fs_sm, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(wgpu::TextureFormat::Rgba8Unorm) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&fs_sm) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .build(), + )]) + .build(), + ), primitive: Default::default(), depth_stencil: None, multisample: Default::default(), diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index 28afbaa934e..1a33f2a1271 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -64,16 +64,18 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = primitive: Default::default(), depth_stencil: None, multisample: Default::default(), - fragment: Some(FragmentState { - module: &module, - entry_point: Some("double_buffer_frag"), - compilation_options: Default::default(), - targets: &[Some( - ColorTargetState::builder() - .format(TextureFormat::Rgba8Unorm) - .build(), - )], - }), + fragment: Some( + FragmentState::builder() + .module(&module) + .entry_point("double_buffer_frag") + .compilation_options(Default::default()) + .targets(&[Some( + ColorTargetState::builder() + .format(TextureFormat::Rgba8Unorm) + .build(), + )]) + .build(), + ), multiview: None, cache: None, }); @@ -93,16 +95,18 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = primitive: Default::default(), depth_stencil: None, multisample: Default::default(), - fragment: Some(FragmentState { - module: &module, - entry_point: Some("single_buffer_frag"), - compilation_options: Default::default(), - targets: &[Some( - ColorTargetState::builder() - .format(TextureFormat::Rgba8Unorm) - .build(), - )], - }), + fragment: Some( + FragmentState::builder() + .module(&module) + .entry_point("single_buffer_frag") + .compilation_options(Default::default()) + .targets(&[Some( + ColorTargetState::builder() + .format(TextureFormat::Rgba8Unorm) + .build(), + )]) + .build(), + ), multiview: None, cache: None, }); diff --git a/tests/tests/regression/issue_4485.rs b/tests/tests/regression/issue_4485.rs index b22718b9d7e..616119b1b5e 100644 --- a/tests/tests/regression/issue_4485.rs +++ b/tests/tests/regression/issue_4485.rs @@ -47,16 +47,18 @@ async fn test_impl(ctx: &TestingContext) { primitive: Default::default(), depth_stencil: None, multisample: Default::default(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(wgpu::TextureFormat::Rgba8Unorm) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .build(), + )]) + .build(), + ), multiview: None, cache: None, }); diff --git a/tests/tests/regression/issue_4514.rs b/tests/tests/regression/issue_4514.rs index 4dc395b846d..a4f444e9b09 100644 --- a/tests/tests/regression/issue_4514.rs +++ b/tests/tests/regression/issue_4514.rs @@ -47,16 +47,18 @@ async fn test_impl(ctx: &TestingContext) { primitive: Default::default(), depth_stencil: None, multisample: Default::default(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(wgpu::TextureFormat::Rgba8Unorm) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .build(), + )]) + .build(), + ), multiview: None, cache: None, }); diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index 46b0d7b6109..76c15500c3a 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -23,6 +23,11 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = .build(), ); + let targets = &[Some( + ColorTargetState::builder() + .format(TextureFormat::Rgba8Unorm) + .build(), + )]; let _ = ctx .device .create_render_pipeline(&RenderPipelineDescriptor { @@ -34,16 +39,14 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = primitive: Default::default(), depth_stencil: None, multisample: Default::default(), - fragment: Some(FragmentState { - module: &module, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some( - ColorTargetState::builder() - .format(TextureFormat::Rgba8Unorm) - .build(), - )], - }), + fragment: Some( + FragmentState::builder() + .module(&module) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(targets) + .build(), + ), multiview: None, cache: None, }); diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index 06944ac2df0..f33697f2e93 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -502,12 +502,14 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { attributes: &wgpu::vertex_attr_array![0 => Uint32], }]) .build(), - fragment: Some(wgpu::FragmentState { - module: &sm, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(target_format.into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&sm) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(target_format.into())]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .topology(wgpu::PrimitiveTopology::TriangleStrip) .strip_index_format(wgpu::IndexFormat::Uint32) diff --git a/tests/tests/scissor_tests/mod.rs b/tests/tests/scissor_tests/mod.rs index f790a15bef2..cc15334395f 100644 --- a/tests/tests/scissor_tests/mod.rs +++ b/tests/tests/scissor_tests/mod.rs @@ -45,16 +45,18 @@ async fn scissor_test_impl( primitive: Default::default(), depth_stencil: None, multisample: Default::default(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(wgpu::TextureFormat::Rgba8Unorm) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .build(), + )]) + .build(), + ), multiview: None, cache: None, }); diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index e9bdcca7776..ace9d13001d 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -133,16 +133,18 @@ async fn pulling_common( primitive: Default::default(), depth_stencil: None, multisample: Default::default(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(wgpu::TextureFormat::Rgba8Unorm) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .build(), + )]) + .build(), + ), multiview: None, cache: None, }); diff --git a/tests/tests/shader_view_format/mod.rs b/tests/tests/shader_view_format/mod.rs index 55047e53b82..037417ff8d1 100644 --- a/tests/tests/shader_view_format/mod.rs +++ b/tests/tests/shader_view_format/mod.rs @@ -89,12 +89,14 @@ async fn reinterpret( vertex: wgpu::VertexState::from_module(shader) .entry_point("vs_main") .build(), - fragment: Some(wgpu::FragmentState { - module: shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some(src_format.into())], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(&[Some(src_format.into())]) + .build(), + ), primitive: wgpu::PrimitiveState::builder() .front_face(wgpu::FrontFace::Cw) .build(), diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 410b06ed8e9..007cb7bb1e5 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -231,9 +231,14 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { }); let buffers = &[wgpu::VertexBufferLayout::builder() - .array_stride(0) // Calculate, please! - .attributes(test.attributes) - .build()]; + .array_stride(0) // Calculate, please! + .attributes(test.attributes) + .build()]; + let targets = &[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .build(), + )]; let pipeline_desc = wgpu::RenderPipelineDescriptor { label: None, layout: Some(&ppl), @@ -244,16 +249,14 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { primitive: Default::default(), depth_stencil: None, multisample: Default::default(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fragment_main"), - compilation_options: Default::default(), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(wgpu::TextureFormat::Rgba8Unorm) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fragment_main") + .compilation_options(Default::default()) + .targets(targets) + .build(), + ), multiview: None, cache: None, }; diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index de8e94138fc..cf78a1920f8 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -251,6 +251,11 @@ async fn vertex_index_common(ctx: TestingContext) { .build(), ); + let targets = &[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8Unorm) + .build(), + )]; let mut pipeline_desc = wgpu::RenderPipelineDescriptor { label: None, layout: Some(&ppl), @@ -260,16 +265,14 @@ async fn vertex_index_common(ctx: TestingContext) { primitive: Default::default(), depth_stencil: None, multisample: Default::default(), - fragment: Some(wgpu::FragmentState { - module: &shader, - entry_point: Some("fs_main"), - compilation_options: Default::default(), - targets: &[Some( - wgpu::ColorTargetState::builder() - .format(wgpu::TextureFormat::Rgba8Unorm) - .build(), - )], - }), + fragment: Some( + wgpu::FragmentState::builder() + .module(&shader) + .entry_point("fs_main") + .compilation_options(Default::default()) + .targets(targets) + .build(), + ), multiview: None, cache: None, }; diff --git a/wgpu/src/api/render_pipeline.rs b/wgpu/src/api/render_pipeline.rs index ce443c57628..beb98d77dd2 100644 --- a/wgpu/src/api/render_pipeline.rs +++ b/wgpu/src/api/render_pipeline.rs @@ -98,7 +98,7 @@ static_assertions::assert_impl_all!(VertexState<'_>: Send, Sync); /// /// Corresponds to [WebGPU `GPUFragmentState`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpufragmentstate). -#[derive(Clone, Debug)] +#[derive(bon::Builder, Clone, Debug)] pub struct FragmentState<'a> { /// The compiled shader module for this stage. pub module: &'a ShaderModule, @@ -113,6 +113,7 @@ pub struct FragmentState<'a> { /// Advanced options for when this pipeline is compiled /// /// This implements `Default`, and for most users can be set to `Default::default()` + #[builder(default)] pub compilation_options: PipelineCompilationOptions<'a>, /// The color state of the render targets. pub targets: &'a [Option], From 51884e50dcb7b06da61aecd7497fc6432a9b742e Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 22:44:24 -0400 Subject: [PATCH 26/33] WIP: refactor!: remove unnecessary fields in `FragmentState` builder usage --- benches/benches/renderpass.rs | 2 -- examples/src/boids/mod.rs | 1 - examples/src/conservative_raster/mod.rs | 2 -- examples/src/cube/mod.rs | 2 -- examples/src/hello_triangle/mod.rs | 1 - examples/src/mipmap/mod.rs | 2 -- examples/src/msaa_line/mod.rs | 1 - examples/src/render_to_texture/mod.rs | 1 - examples/src/shadow/mod.rs | 1 - examples/src/skybox/mod.rs | 2 -- examples/src/stencil_triangles/mod.rs | 2 -- examples/src/texture_arrays/mod.rs | 1 - examples/src/timestamp_queries/mod.rs | 1 - examples/src/uniform_values/mod.rs | 1 - examples/src/water/mod.rs | 2 -- tests/tests/device.rs | 1 - tests/tests/nv12_texture/mod.rs | 1 - tests/tests/regression/issue_3349.rs | 1 - tests/tests/regression/issue_3457.rs | 2 -- tests/tests/regression/issue_4485.rs | 1 - tests/tests/regression/issue_4514.rs | 1 - tests/tests/regression/issue_5553.rs | 1 - tests/tests/render_pass_ownership.rs | 1 - tests/tests/scissor_tests/mod.rs | 1 - tests/tests/shader_primitive_index/mod.rs | 1 - tests/tests/shader_view_format/mod.rs | 1 - tests/tests/vertex_formats/mod.rs | 1 - tests/tests/vertex_indices/mod.rs | 1 - 28 files changed, 36 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index 8356a007b67..cf63d0f790c 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -197,7 +197,6 @@ impl RenderpassState { .format(wgpu::TextureFormat::Rgba8UnormSrgb) .build(), )]) - .compilation_options(wgpu::PipelineCompilationOptions::default()) .build(), ), multiview: None, @@ -283,7 +282,6 @@ impl RenderpassState { .format(wgpu::TextureFormat::Rgba8UnormSrgb) .build(), )]) - .compilation_options(wgpu::PipelineCompilationOptions::default()) .build(), ), multiview: None, diff --git a/examples/src/boids/mod.rs b/examples/src/boids/mod.rs index c4ae43aa025..c86c5eac8e8 100644 --- a/examples/src/boids/mod.rs +++ b/examples/src/boids/mod.rs @@ -141,7 +141,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(&draw_shader) .entry_point("main_fs") - .compilation_options(Default::default()) .targets(&[Some(config.view_formats[0].into())]) .build(), ), diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index 5581d34a903..76dbdbaa191 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -94,7 +94,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(&shader_triangle_and_lines) .entry_point("fs_main_red") - .compilation_options(Default::default()) .targets(&[Some(RENDER_TARGET_FORMAT.into())]) .build(), ), @@ -116,7 +115,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(&shader_triangle_and_lines) .entry_point("fs_main_blue") - .compilation_options(Default::default()) .targets(&[Some(RENDER_TARGET_FORMAT.into())]) .build(), ), diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index 4bb89a12c23..ccec26b761f 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -242,7 +242,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(config.view_formats[0].into())]) .build(), ), @@ -270,7 +269,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_wire") - .compilation_options(Default::default()) .targets(&[Some( wgpu::ColorTargetState::builder() .format(config.view_formats[0]) diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs index 4aaed1f156e..d544a353cb1 100644 --- a/examples/src/hello_triangle/mod.rs +++ b/examples/src/hello_triangle/mod.rs @@ -64,7 +64,6 @@ async fn run(event_loop: EventLoop<()>, window: Window) { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(swapchain_format.into())]) .build(), ), diff --git a/examples/src/mipmap/mod.rs b/examples/src/mipmap/mod.rs index d45b03b6765..dd88f7c5184 100644 --- a/examples/src/mipmap/mod.rs +++ b/examples/src/mipmap/mod.rs @@ -93,7 +93,6 @@ impl Example { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(TEXTURE_FORMAT.into())]) .build(), ), @@ -286,7 +285,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(config.view_formats[0].into())]) .build(), ), diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index fbc54b7efc4..461f7f24725 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -62,7 +62,6 @@ impl Example { wgpu::FragmentState::builder() .module(shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(config.view_formats[0].into())]) .build(), ), diff --git a/examples/src/render_to_texture/mod.rs b/examples/src/render_to_texture/mod.rs index 4c58e425c7c..a09ad6379e3 100644 --- a/examples/src/render_to_texture/mod.rs +++ b/examples/src/render_to_texture/mod.rs @@ -59,7 +59,6 @@ async fn run(_path: Option) { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(wgpu::TextureFormat::Rgba8UnormSrgb.into())]) .build(), ), diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index b1e8d172bdf..bf9a27c847f 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -633,7 +633,6 @@ impl crate::framework::Example for Example { } else { "fs_main_without_storage" }) - .compilation_options(Default::default()) .targets(&[Some(config.view_formats[0].into())]) .build(), ), diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index 30afb772eaf..7106c185e79 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -197,7 +197,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_sky") - .compilation_options(Default::default()) .targets(&[Some(config.view_formats[0].into())]) .build(), ), @@ -230,7 +229,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_entity") - .compilation_options(Default::default()) .targets(&[Some(config.view_formats[0].into())]) .build(), ), diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index e1814c9d00a..25c2a9ae787 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -74,7 +74,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some( wgpu::ColorTargetState::builder() .format(config.view_formats[0]) @@ -116,7 +115,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(config.view_formats[0].into())]) .build(), ), diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index 2bc2c7ce05d..0391984d5e6 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -326,7 +326,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(fragment_shader_module) .entry_point(fragment_entry_point) - .compilation_options(Default::default()) .targets(&[Some(config.view_formats[0].into())]) .build(), ), diff --git a/examples/src/timestamp_queries/mod.rs b/examples/src/timestamp_queries/mod.rs index 58e279a0aa9..85bf6f994ba 100644 --- a/examples/src/timestamp_queries/mod.rs +++ b/examples/src/timestamp_queries/mod.rs @@ -358,7 +358,6 @@ fn render_pass( wgpu::FragmentState::builder() .module(module) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(format.into())]) .build(), ), diff --git a/examples/src/uniform_values/mod.rs b/examples/src/uniform_values/mod.rs index 857a67184c3..b1bd0c4badc 100644 --- a/examples/src/uniform_values/mod.rs +++ b/examples/src/uniform_values/mod.rs @@ -179,7 +179,6 @@ impl WgpuContext { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(swapchain_format.into())]) .build(), ), diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index c444bce80c3..1b6381e947b 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -524,7 +524,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(&water_module) .entry_point("fs_main") - .compilation_options(Default::default()) // Describes how the colour will be interpolated // and assigned to the output attachment. .targets(&[Some( @@ -591,7 +590,6 @@ impl crate::framework::Example for Example { wgpu::FragmentState::builder() .module(&terrain_module) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(config.view_formats[0].into())]) .build(), ), diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 3e46267867e..55d5f8ba8ab 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -773,7 +773,6 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf wgpu::FragmentState::builder() .module(&trivial_shaders_with_some_reversed_bindings) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some( wgt::ColorTargetState::builder() .format(wgt::TextureFormat::Bgra8Unorm) diff --git a/tests/tests/nv12_texture/mod.rs b/tests/tests/nv12_texture/mod.rs index e70db06441d..2f4e1004f8b 100644 --- a/tests/tests/nv12_texture/mod.rs +++ b/tests/tests/nv12_texture/mod.rs @@ -28,7 +28,6 @@ static NV12_TEXTURE_CREATION_SAMPLING: GpuTestConfiguration = GpuTestConfigurati wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(target_format.into())]) .build(), ), diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index 7bf941896d5..5571f7ef99e 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -106,7 +106,6 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { wgpu::FragmentState::builder() .module(&fs_sm) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index 1a33f2a1271..225a3a2f2c0 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -68,7 +68,6 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = FragmentState::builder() .module(&module) .entry_point("double_buffer_frag") - .compilation_options(Default::default()) .targets(&[Some( ColorTargetState::builder() .format(TextureFormat::Rgba8Unorm) @@ -99,7 +98,6 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = FragmentState::builder() .module(&module) .entry_point("single_buffer_frag") - .compilation_options(Default::default()) .targets(&[Some( ColorTargetState::builder() .format(TextureFormat::Rgba8Unorm) diff --git a/tests/tests/regression/issue_4485.rs b/tests/tests/regression/issue_4485.rs index 616119b1b5e..579480cfb59 100644 --- a/tests/tests/regression/issue_4485.rs +++ b/tests/tests/regression/issue_4485.rs @@ -51,7 +51,6 @@ async fn test_impl(ctx: &TestingContext) { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) diff --git a/tests/tests/regression/issue_4514.rs b/tests/tests/regression/issue_4514.rs index a4f444e9b09..a1b9eb938a2 100644 --- a/tests/tests/regression/issue_4514.rs +++ b/tests/tests/regression/issue_4514.rs @@ -51,7 +51,6 @@ async fn test_impl(ctx: &TestingContext) { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index 76c15500c3a..53ae7b7dafd 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -43,7 +43,6 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = FragmentState::builder() .module(&module) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(targets) .build(), ), diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index f33697f2e93..47e2d456506 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -506,7 +506,6 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { wgpu::FragmentState::builder() .module(&sm) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(target_format.into())]) .build(), ), diff --git a/tests/tests/scissor_tests/mod.rs b/tests/tests/scissor_tests/mod.rs index cc15334395f..beab8d23c25 100644 --- a/tests/tests/scissor_tests/mod.rs +++ b/tests/tests/scissor_tests/mod.rs @@ -49,7 +49,6 @@ async fn scissor_test_impl( wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index ace9d13001d..6750df01dca 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -137,7 +137,6 @@ async fn pulling_common( wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some( wgpu::ColorTargetState::builder() .format(wgpu::TextureFormat::Rgba8Unorm) diff --git a/tests/tests/shader_view_format/mod.rs b/tests/tests/shader_view_format/mod.rs index 037417ff8d1..bf80a7154a9 100644 --- a/tests/tests/shader_view_format/mod.rs +++ b/tests/tests/shader_view_format/mod.rs @@ -93,7 +93,6 @@ async fn reinterpret( wgpu::FragmentState::builder() .module(shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(&[Some(src_format.into())]) .build(), ), diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 007cb7bb1e5..5679c4f2715 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -253,7 +253,6 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { wgpu::FragmentState::builder() .module(&shader) .entry_point("fragment_main") - .compilation_options(Default::default()) .targets(targets) .build(), ), diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index cf78a1920f8..994a7e5dd2c 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -269,7 +269,6 @@ async fn vertex_index_common(ctx: TestingContext) { wgpu::FragmentState::builder() .module(&shader) .entry_point("fs_main") - .compilation_options(Default::default()) .targets(targets) .build(), ), From 023378f3d14cd93a53b2647a891098897ab733f5 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 9 Sep 2024 13:39:30 -0400 Subject: [PATCH 27/33] refactor: add `FragmentState::from_module` builder entrypoint --- benches/benches/renderpass.rs | 6 ++---- examples/src/boids/mod.rs | 3 +-- examples/src/bunnymark/mod.rs | 3 +-- examples/src/conservative_raster/mod.rs | 12 ++++-------- examples/src/cube/mod.rs | 6 ++---- examples/src/hello_triangle/mod.rs | 3 +-- examples/src/mipmap/mod.rs | 6 ++---- examples/src/msaa_line/mod.rs | 3 +-- examples/src/render_to_texture/mod.rs | 3 +-- examples/src/shadow/mod.rs | 3 +-- examples/src/skybox/mod.rs | 6 ++---- examples/src/srgb_blend/mod.rs | 3 +-- examples/src/stencil_triangles/mod.rs | 6 ++---- examples/src/texture_arrays/mod.rs | 3 +-- examples/src/timestamp_queries/mod.rs | 3 +-- examples/src/uniform_values/mod.rs | 3 +-- examples/src/water/mod.rs | 6 ++---- tests/tests/device.rs | 3 +-- tests/tests/mem_leaks.rs | 3 +-- tests/tests/nv12_texture/mod.rs | 3 +-- tests/tests/regression/issue_3349.rs | 3 +-- tests/tests/regression/issue_3457.rs | 6 ++---- tests/tests/regression/issue_4485.rs | 3 +-- tests/tests/regression/issue_4514.rs | 3 +-- tests/tests/regression/issue_5553.rs | 3 +-- tests/tests/render_pass_ownership.rs | 3 +-- tests/tests/scissor_tests/mod.rs | 3 +-- tests/tests/shader_primitive_index/mod.rs | 3 +-- tests/tests/shader_view_format/mod.rs | 3 +-- tests/tests/vertex_formats/mod.rs | 3 +-- tests/tests/vertex_indices/mod.rs | 3 +-- wgpu/src/api/render_pipeline.rs | 2 ++ 32 files changed, 43 insertions(+), 82 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index cf63d0f790c..0f5929f8fa1 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -189,8 +189,7 @@ impl RenderpassState { depth_stencil: None, multisample: Default::default(), fragment: Some( - wgpu::FragmentState::builder() - .module(&sm) + wgpu::FragmentState::from_module(&sm) .entry_point("fs_main") .targets(&[Some( wgpu::ColorTargetState::builder() @@ -274,8 +273,7 @@ impl RenderpassState { depth_stencil: None, multisample: Default::default(), fragment: Some( - wgpu::FragmentState::builder() - .module(&bindless_shader_module) + wgpu::FragmentState::from_module(&bindless_shader_module) .entry_point("fs_main") .targets(&[Some( wgpu::ColorTargetState::builder() diff --git a/examples/src/boids/mod.rs b/examples/src/boids/mod.rs index c86c5eac8e8..39b09f649e5 100644 --- a/examples/src/boids/mod.rs +++ b/examples/src/boids/mod.rs @@ -138,8 +138,7 @@ impl crate::framework::Example for Example { ]) .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&draw_shader) + wgpu::FragmentState::from_module(&draw_shader) .entry_point("main_fs") .targets(&[Some(config.view_formats[0].into())]) .build(), diff --git a/examples/src/bunnymark/mod.rs b/examples/src/bunnymark/mod.rs index e997d733e9f..4ad3ec7d3fa 100644 --- a/examples/src/bunnymark/mod.rs +++ b/examples/src/bunnymark/mod.rs @@ -214,8 +214,7 @@ impl crate::framework::Example for Example { .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some( wgpu::ColorTargetState::builder() diff --git a/examples/src/conservative_raster/mod.rs b/examples/src/conservative_raster/mod.rs index 76dbdbaa191..9b0758f47e8 100644 --- a/examples/src/conservative_raster/mod.rs +++ b/examples/src/conservative_raster/mod.rs @@ -91,8 +91,7 @@ impl crate::framework::Example for Example { .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader_triangle_and_lines) + wgpu::FragmentState::from_module(&shader_triangle_and_lines) .entry_point("fs_main_red") .targets(&[Some(RENDER_TARGET_FORMAT.into())]) .build(), @@ -112,8 +111,7 @@ impl crate::framework::Example for Example { .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader_triangle_and_lines) + wgpu::FragmentState::from_module(&shader_triangle_and_lines) .entry_point("fs_main_blue") .targets(&[Some(RENDER_TARGET_FORMAT.into())]) .build(), @@ -137,8 +135,7 @@ impl crate::framework::Example for Example { .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader_triangle_and_lines) + wgpu::FragmentState::from_module(&shader_triangle_and_lines) .entry_point("fs_main_white") .compilation_options(Default::default()) .targets(&[Some(config.view_formats[0].into())]) @@ -196,8 +193,7 @@ impl crate::framework::Example for Example { .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .compilation_options(Default::default()) .targets(&[Some(config.view_formats[0].into())]) diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index ccec26b761f..fb51734995f 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -239,8 +239,7 @@ impl crate::framework::Example for Example { .buffers(&vertex_buffers) .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some(config.view_formats[0].into())]) .build(), @@ -266,8 +265,7 @@ impl crate::framework::Example for Example { .buffers(&vertex_buffers) .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_wire") .targets(&[Some( wgpu::ColorTargetState::builder() diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs index d544a353cb1..2e2b2e9697e 100644 --- a/examples/src/hello_triangle/mod.rs +++ b/examples/src/hello_triangle/mod.rs @@ -61,8 +61,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) { .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some(swapchain_format.into())]) .build(), diff --git a/examples/src/mipmap/mod.rs b/examples/src/mipmap/mod.rs index dd88f7c5184..6d2118a7886 100644 --- a/examples/src/mipmap/mod.rs +++ b/examples/src/mipmap/mod.rs @@ -90,8 +90,7 @@ impl Example { .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some(TEXTURE_FORMAT.into())]) .build(), @@ -282,8 +281,7 @@ impl crate::framework::Example for Example { .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some(config.view_formats[0].into())]) .build(), diff --git a/examples/src/msaa_line/mod.rs b/examples/src/msaa_line/mod.rs index 461f7f24725..058ba5a4269 100644 --- a/examples/src/msaa_line/mod.rs +++ b/examples/src/msaa_line/mod.rs @@ -59,8 +59,7 @@ impl Example { .build()]) .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(shader) + wgpu::FragmentState::from_module(shader) .entry_point("fs_main") .targets(&[Some(config.view_formats[0].into())]) .build(), diff --git a/examples/src/render_to_texture/mod.rs b/examples/src/render_to_texture/mod.rs index a09ad6379e3..b80d38c8b98 100644 --- a/examples/src/render_to_texture/mod.rs +++ b/examples/src/render_to_texture/mod.rs @@ -56,8 +56,7 @@ async fn run(_path: Option) { .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some(wgpu::TextureFormat::Rgba8UnormSrgb.into())]) .build(), diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index bf9a27c847f..3477cdf0e91 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -626,8 +626,7 @@ impl crate::framework::Example for Example { .buffers(&[vb_desc]) .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point(if supports_storage_resources { "fs_main" } else { diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index 7106c185e79..ef491ecc411 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -194,8 +194,7 @@ impl crate::framework::Example for Example { .entry_point("vs_sky") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_sky") .targets(&[Some(config.view_formats[0].into())]) .build(), @@ -226,8 +225,7 @@ impl crate::framework::Example for Example { .build()]) .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_entity") .targets(&[Some(config.view_formats[0].into())]) .build(), diff --git a/examples/src/srgb_blend/mod.rs b/examples/src/srgb_blend/mod.rs index f763c6100e7..1c0c325ba8e 100644 --- a/examples/src/srgb_blend/mod.rs +++ b/examples/src/srgb_blend/mod.rs @@ -129,8 +129,7 @@ impl crate::framework::Example for Example { .buffers(&vertex_buffers) .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some( wgpu::ColorTargetState::builder() diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index 25c2a9ae787..2190d763cad 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -71,8 +71,7 @@ impl crate::framework::Example for Example { .buffers(&vertex_buffers) .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some( wgpu::ColorTargetState::builder() @@ -112,8 +111,7 @@ impl crate::framework::Example for Example { .buffers(&vertex_buffers) .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some(config.view_formats[0].into())]) .build(), diff --git a/examples/src/texture_arrays/mod.rs b/examples/src/texture_arrays/mod.rs index 0391984d5e6..d0e2b61d0e3 100644 --- a/examples/src/texture_arrays/mod.rs +++ b/examples/src/texture_arrays/mod.rs @@ -323,8 +323,7 @@ impl crate::framework::Example for Example { .build()]) .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(fragment_shader_module) + wgpu::FragmentState::from_module(fragment_shader_module) .entry_point(fragment_entry_point) .targets(&[Some(config.view_formats[0].into())]) .build(), diff --git a/examples/src/timestamp_queries/mod.rs b/examples/src/timestamp_queries/mod.rs index 85bf6f994ba..0a6762f19f9 100644 --- a/examples/src/timestamp_queries/mod.rs +++ b/examples/src/timestamp_queries/mod.rs @@ -355,8 +355,7 @@ fn render_pass( .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(module) + wgpu::FragmentState::from_module(module) .entry_point("fs_main") .targets(&[Some(format.into())]) .build(), diff --git a/examples/src/uniform_values/mod.rs b/examples/src/uniform_values/mod.rs index b1bd0c4badc..dcd6782ffe7 100644 --- a/examples/src/uniform_values/mod.rs +++ b/examples/src/uniform_values/mod.rs @@ -176,8 +176,7 @@ impl WgpuContext { .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some(swapchain_format.into())]) .build(), diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index 1b6381e947b..a05e392be94 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -521,8 +521,7 @@ impl crate::framework::Example for Example { .build(), // Fragment shader and output targets fragment: Some( - wgpu::FragmentState::builder() - .module(&water_module) + wgpu::FragmentState::from_module(&water_module) .entry_point("fs_main") // Describes how the colour will be interpolated // and assigned to the output attachment. @@ -587,8 +586,7 @@ impl crate::framework::Example for Example { .build()]) .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&terrain_module) + wgpu::FragmentState::from_module(&terrain_module) .entry_point("fs_main") .targets(&[Some(config.view_formats[0].into())]) .build(), diff --git a/tests/tests/device.rs b/tests/tests/device.rs index 55d5f8ba8ab..ab41ea3aafc 100644 --- a/tests/tests/device.rs +++ b/tests/tests/device.rs @@ -770,8 +770,7 @@ static DIFFERENT_BGL_ORDER_BW_SHADER_AND_API: GpuTestConfiguration = GpuTestConf .device .create_render_pipeline(&wgpu::RenderPipelineDescriptor { fragment: Some( - wgpu::FragmentState::builder() - .module(&trivial_shaders_with_some_reversed_bindings) + wgpu::FragmentState::from_module(&trivial_shaders_with_some_reversed_bindings) .entry_point("fs_main") .targets(&[Some( wgt::ColorTargetState::builder() diff --git a/tests/tests/mem_leaks.rs b/tests/tests/mem_leaks.rs index 5cf9b1af84f..143082be575 100644 --- a/tests/tests/mem_leaks.rs +++ b/tests/tests/mem_leaks.rs @@ -98,8 +98,7 @@ async fn draw_test_with_reports( depth_stencil: None, multisample: Default::default(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some( wgpu::ColorTargetState::builder() diff --git a/tests/tests/nv12_texture/mod.rs b/tests/tests/nv12_texture/mod.rs index 2f4e1004f8b..67f886ac8e9 100644 --- a/tests/tests/nv12_texture/mod.rs +++ b/tests/tests/nv12_texture/mod.rs @@ -25,8 +25,7 @@ static NV12_TEXTURE_CREATION_SAMPLING: GpuTestConfiguration = GpuTestConfigurati .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some(target_format.into())]) .build(), diff --git a/tests/tests/regression/issue_3349.rs b/tests/tests/regression/issue_3349.rs index 5571f7ef99e..d7ed0da8dda 100644 --- a/tests/tests/regression/issue_3349.rs +++ b/tests/tests/regression/issue_3349.rs @@ -103,8 +103,7 @@ async fn multi_stage_data_binding_test(ctx: TestingContext) { .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&fs_sm) + wgpu::FragmentState::from_module(&fs_sm) .entry_point("fs_main") .targets(&[Some( wgpu::ColorTargetState::builder() diff --git a/tests/tests/regression/issue_3457.rs b/tests/tests/regression/issue_3457.rs index 225a3a2f2c0..63db96c34f3 100644 --- a/tests/tests/regression/issue_3457.rs +++ b/tests/tests/regression/issue_3457.rs @@ -65,8 +65,7 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = depth_stencil: None, multisample: Default::default(), fragment: Some( - FragmentState::builder() - .module(&module) + FragmentState::from_module(&module) .entry_point("double_buffer_frag") .targets(&[Some( ColorTargetState::builder() @@ -95,8 +94,7 @@ static PASS_RESET_VERTEX_BUFFER: GpuTestConfiguration = depth_stencil: None, multisample: Default::default(), fragment: Some( - FragmentState::builder() - .module(&module) + FragmentState::from_module(&module) .entry_point("single_buffer_frag") .targets(&[Some( ColorTargetState::builder() diff --git a/tests/tests/regression/issue_4485.rs b/tests/tests/regression/issue_4485.rs index 579480cfb59..084ec3bf4b1 100644 --- a/tests/tests/regression/issue_4485.rs +++ b/tests/tests/regression/issue_4485.rs @@ -48,8 +48,7 @@ async fn test_impl(ctx: &TestingContext) { depth_stencil: None, multisample: Default::default(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some( wgpu::ColorTargetState::builder() diff --git a/tests/tests/regression/issue_4514.rs b/tests/tests/regression/issue_4514.rs index a1b9eb938a2..49dc18941bf 100644 --- a/tests/tests/regression/issue_4514.rs +++ b/tests/tests/regression/issue_4514.rs @@ -48,8 +48,7 @@ async fn test_impl(ctx: &TestingContext) { depth_stencil: None, multisample: Default::default(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some( wgpu::ColorTargetState::builder() diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index 53ae7b7dafd..112456c2a12 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -40,8 +40,7 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = depth_stencil: None, multisample: Default::default(), fragment: Some( - FragmentState::builder() - .module(&module) + FragmentState::from_module(&module) .entry_point("fs_main") .targets(targets) .build(), diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index 47e2d456506..889ff5cbaa9 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -503,8 +503,7 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { }]) .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(&sm) + wgpu::FragmentState::from_module(&sm) .entry_point("fs_main") .targets(&[Some(target_format.into())]) .build(), diff --git a/tests/tests/scissor_tests/mod.rs b/tests/tests/scissor_tests/mod.rs index beab8d23c25..0c5c5783727 100644 --- a/tests/tests/scissor_tests/mod.rs +++ b/tests/tests/scissor_tests/mod.rs @@ -46,8 +46,7 @@ async fn scissor_test_impl( depth_stencil: None, multisample: Default::default(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some( wgpu::ColorTargetState::builder() diff --git a/tests/tests/shader_primitive_index/mod.rs b/tests/tests/shader_primitive_index/mod.rs index 6750df01dca..a544b4d4850 100644 --- a/tests/tests/shader_primitive_index/mod.rs +++ b/tests/tests/shader_primitive_index/mod.rs @@ -134,8 +134,7 @@ async fn pulling_common( depth_stencil: None, multisample: Default::default(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(&[Some( wgpu::ColorTargetState::builder() diff --git a/tests/tests/shader_view_format/mod.rs b/tests/tests/shader_view_format/mod.rs index bf80a7154a9..a3418219f5c 100644 --- a/tests/tests/shader_view_format/mod.rs +++ b/tests/tests/shader_view_format/mod.rs @@ -90,8 +90,7 @@ async fn reinterpret( .entry_point("vs_main") .build(), fragment: Some( - wgpu::FragmentState::builder() - .module(shader) + wgpu::FragmentState::from_module(shader) .entry_point("fs_main") .targets(&[Some(src_format.into())]) .build(), diff --git a/tests/tests/vertex_formats/mod.rs b/tests/tests/vertex_formats/mod.rs index 5679c4f2715..a0cac725aa8 100644 --- a/tests/tests/vertex_formats/mod.rs +++ b/tests/tests/vertex_formats/mod.rs @@ -250,8 +250,7 @@ async fn vertex_formats_common(ctx: TestingContext, tests: &[Test<'_>]) { depth_stencil: None, multisample: Default::default(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fragment_main") .targets(targets) .build(), diff --git a/tests/tests/vertex_indices/mod.rs b/tests/tests/vertex_indices/mod.rs index 994a7e5dd2c..00faa6ffdb2 100644 --- a/tests/tests/vertex_indices/mod.rs +++ b/tests/tests/vertex_indices/mod.rs @@ -266,8 +266,7 @@ async fn vertex_index_common(ctx: TestingContext) { depth_stencil: None, multisample: Default::default(), fragment: Some( - wgpu::FragmentState::builder() - .module(&shader) + wgpu::FragmentState::from_module(&shader) .entry_point("fs_main") .targets(targets) .build(), diff --git a/wgpu/src/api/render_pipeline.rs b/wgpu/src/api/render_pipeline.rs index beb98d77dd2..923eccf19a4 100644 --- a/wgpu/src/api/render_pipeline.rs +++ b/wgpu/src/api/render_pipeline.rs @@ -99,8 +99,10 @@ static_assertions::assert_impl_all!(VertexState<'_>: Send, Sync); /// Corresponds to [WebGPU `GPUFragmentState`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpufragmentstate). #[derive(bon::Builder, Clone, Debug)] +#[builder(start_fn = from_module)] pub struct FragmentState<'a> { /// The compiled shader module for this stage. + #[builder(start_fn)] pub module: &'a ShaderModule, /// The name of the entry point in the compiled shader to use. /// From 771e861d4cb7ac9ef785382fecd2a7f81bcdc420 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 9 Sep 2024 13:29:14 -0400 Subject: [PATCH 28/33] refactor: prefer default values for `DepthStencilState` via `..Default::default()` --- examples/src/stencil_triangles/mod.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index 2190d763cad..404cef87484 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -93,8 +93,7 @@ impl crate::framework::Example for Example { ..Default::default() }, back: wgpu::StencilFaceState::IGNORE, - read_mask: !0, - write_mask: !0, + ..Default::default() }, bias: Default::default(), }), @@ -127,8 +126,7 @@ impl crate::framework::Example for Example { ..Default::default() }, back: wgpu::StencilFaceState::IGNORE, - read_mask: !0, - write_mask: !0, + ..Default::default() }, bias: Default::default(), }), From f420dbb215ba2ca3dbd78c849d91a13b73057f53 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 9 Sep 2024 07:45:02 -0400 Subject: [PATCH 29/33] refactor!: give `DepthStencilState` a builder API --- examples/src/shadow/mod.rs | 40 +++++++++--------- examples/src/skybox/mod.rs | 32 ++++++++------- examples/src/stencil_triangles/mod.rs | 58 ++++++++++++++------------- examples/src/water/mod.rs | 34 +++++++++------- tests/tests/occlusion_query/mod.rs | 16 ++++---- tests/tests/render_pass_ownership.rs | 16 ++++---- wgpu-types/src/lib.rs | 5 ++- 7 files changed, 112 insertions(+), 89 deletions(-) diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index 3477cdf0e91..36cfb30b559 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -502,17 +502,19 @@ impl crate::framework::Example for Example { .contains(wgpu::Features::DEPTH_CLIP_CONTROL), ) .build(), - depth_stencil: Some(wgpu::DepthStencilState { - format: Self::SHADOW_FORMAT, - depth_write_enabled: true, - depth_compare: wgpu::CompareFunction::LessEqual, - stencil: wgpu::StencilState::default(), - bias: wgpu::DepthBiasState { - constant: 2, // corresponds to bilinear filtering - slope_scale: 2.0, - clamp: 0.0, - }, - }), + depth_stencil: Some( + wgpu::DepthStencilState::builder() + .format(Self::SHADOW_FORMAT) + .depth_write_enabled(true) + .depth_compare(wgpu::CompareFunction::LessEqual) + .stencil(wgpu::StencilState::default()) + .bias(wgpu::DepthBiasState { + constant: 2, // corresponds to bilinear filtering + slope_scale: 2.0, + clamp: 0.0, + }) + .build(), + ), multisample: Default::default(), multiview: None, cache: None, @@ -638,13 +640,15 @@ impl crate::framework::Example for Example { primitive: wgpu::PrimitiveState::builder() .cull_mode(wgpu::Face::Back) .build(), - depth_stencil: Some(wgpu::DepthStencilState { - format: Self::DEPTH_FORMAT, - depth_write_enabled: true, - depth_compare: wgpu::CompareFunction::Less, - stencil: wgpu::StencilState::default(), - bias: wgpu::DepthBiasState::default(), - }), + depth_stencil: Some( + wgpu::DepthStencilState::builder() + .format(Self::DEPTH_FORMAT) + .depth_write_enabled(true) + .depth_compare(wgpu::CompareFunction::Less) + .stencil(wgpu::StencilState::default()) + .bias(wgpu::DepthBiasState::default()) + .build(), + ), multisample: Default::default(), multiview: None, cache: None, diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index ef491ecc411..508d7ef485a 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -202,13 +202,15 @@ impl crate::framework::Example for Example { primitive: wgpu::PrimitiveState::builder() .front_face(wgpu::FrontFace::Cw) .build(), - depth_stencil: Some(wgpu::DepthStencilState { - format: Self::DEPTH_FORMAT, - depth_write_enabled: false, - depth_compare: wgpu::CompareFunction::LessEqual, - stencil: wgpu::StencilState::default(), - bias: wgpu::DepthBiasState::default(), - }), + depth_stencil: Some( + wgpu::DepthStencilState::builder() + .format(Self::DEPTH_FORMAT) + .depth_write_enabled(false) + .depth_compare(wgpu::CompareFunction::LessEqual) + .stencil(wgpu::StencilState::default()) + .bias(wgpu::DepthBiasState::default()) + .build(), + ), multisample: Default::default(), multiview: None, cache: None, @@ -233,13 +235,15 @@ impl crate::framework::Example for Example { primitive: wgpu::PrimitiveState::builder() .front_face(wgpu::FrontFace::Cw) .build(), - depth_stencil: Some(wgpu::DepthStencilState { - format: Self::DEPTH_FORMAT, - depth_write_enabled: true, - depth_compare: wgpu::CompareFunction::LessEqual, - stencil: wgpu::StencilState::default(), - bias: wgpu::DepthBiasState::default(), - }), + depth_stencil: Some( + wgpu::DepthStencilState::builder() + .format(Self::DEPTH_FORMAT) + .depth_write_enabled(true) + .depth_compare(wgpu::CompareFunction::LessEqual) + .stencil(wgpu::StencilState::default()) + .bias(wgpu::DepthBiasState::default()) + .build(), + ), multisample: Default::default(), multiview: None, cache: None, diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index 404cef87484..91c231f5922 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -82,21 +82,23 @@ impl crate::framework::Example for Example { .build(), ), primitive: Default::default(), - depth_stencil: Some(wgpu::DepthStencilState { - format: wgpu::TextureFormat::Stencil8, - depth_write_enabled: false, - depth_compare: wgpu::CompareFunction::Always, - stencil: wgpu::StencilState { - front: wgpu::StencilFaceState { - compare: wgpu::CompareFunction::Always, - pass_op: wgpu::StencilOperation::Replace, + depth_stencil: Some( + wgpu::DepthStencilState::builder() + .format(wgpu::TextureFormat::Stencil8) + .depth_write_enabled(false) + .depth_compare(wgpu::CompareFunction::Always) + .stencil(wgpu::StencilState { + front: wgpu::StencilFaceState { + compare: wgpu::CompareFunction::Always, + pass_op: wgpu::StencilOperation::Replace, + ..Default::default() + }, + back: wgpu::StencilFaceState::IGNORE, ..Default::default() - }, - back: wgpu::StencilFaceState::IGNORE, - ..Default::default() - }, - bias: Default::default(), - }), + }) + .bias(Default::default()) + .build(), + ), multisample: Default::default(), multiview: None, cache: None, @@ -116,20 +118,22 @@ impl crate::framework::Example for Example { .build(), ), primitive: Default::default(), - depth_stencil: Some(wgpu::DepthStencilState { - format: wgpu::TextureFormat::Stencil8, - depth_write_enabled: false, - depth_compare: wgpu::CompareFunction::Always, - stencil: wgpu::StencilState { - front: wgpu::StencilFaceState { - compare: wgpu::CompareFunction::Greater, + depth_stencil: Some( + wgpu::DepthStencilState::builder() + .format(wgpu::TextureFormat::Stencil8) + .depth_write_enabled(false) + .depth_compare(wgpu::CompareFunction::Always) + .stencil(wgpu::StencilState { + front: wgpu::StencilFaceState { + compare: wgpu::CompareFunction::Greater, + ..Default::default() + }, + back: wgpu::StencilFaceState::IGNORE, ..Default::default() - }, - back: wgpu::StencilFaceState::IGNORE, - ..Default::default() - }, - bias: Default::default(), - }), + }) + .bias(Default::default()) + .build(), + ), multisample: Default::default(), multiview: None, cache: None, diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index a05e392be94..cadea0ec00d 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -557,14 +557,16 @@ impl crate::framework::Example for Example { // input attachment to do depth-testing. We don't write, so // depth_write_enabled is set to false. This is called // RODS or read-only depth stencil. - depth_stencil: Some(wgpu::DepthStencilState { - // We don't use stencil. - format: wgpu::TextureFormat::Depth32Float, - depth_write_enabled: false, - depth_compare: wgpu::CompareFunction::Less, - stencil: wgpu::StencilState::default(), - bias: wgpu::DepthBiasState::default(), - }), + depth_stencil: Some( + wgpu::DepthStencilState::builder() + // We don't use stencil. + .format(wgpu::TextureFormat::Depth32Float) + .depth_write_enabled(false) + .depth_compare(wgpu::CompareFunction::Less) + .stencil(wgpu::StencilState::default()) + .bias(wgpu::DepthBiasState::default()) + .build(), + ), // No multisampling is used. multisample: Default::default(), multiview: None, @@ -594,13 +596,15 @@ impl crate::framework::Example for Example { primitive: wgpu::PrimitiveState::builder() .cull_mode(wgpu::Face::Front) .build(), - depth_stencil: Some(wgpu::DepthStencilState { - format: wgpu::TextureFormat::Depth32Float, - depth_write_enabled: true, - depth_compare: wgpu::CompareFunction::Less, - stencil: wgpu::StencilState::default(), - bias: wgpu::DepthBiasState::default(), - }), + depth_stencil: Some( + wgpu::DepthStencilState::builder() + .format(wgpu::TextureFormat::Depth32Float) + .depth_write_enabled(true) + .depth_compare(wgpu::CompareFunction::Less) + .stencil(wgpu::StencilState::default()) + .bias(wgpu::DepthBiasState::default()) + .build(), + ), multisample: Default::default(), multiview: None, cache: None, diff --git a/tests/tests/occlusion_query/mod.rs b/tests/tests/occlusion_query/mod.rs index 43f92d9a37e..835f168e60b 100644 --- a/tests/tests/occlusion_query/mod.rs +++ b/tests/tests/occlusion_query/mod.rs @@ -34,13 +34,15 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new() .build(), fragment: None, primitive: Default::default(), - depth_stencil: Some(wgpu::DepthStencilState { - format: wgpu::TextureFormat::Depth32Float, - depth_write_enabled: true, - depth_compare: wgpu::CompareFunction::Less, - stencil: wgpu::StencilState::default(), - bias: wgpu::DepthBiasState::default(), - }), + depth_stencil: Some( + wgpu::DepthStencilState::builder() + .format(wgpu::TextureFormat::Depth32Float) + .depth_write_enabled(true) + .depth_compare(wgpu::CompareFunction::Less) + .stencil(wgpu::StencilState::default()) + .bias(wgpu::DepthBiasState::default()) + .build(), + ), multisample: Default::default(), multiview: None, cache: None, diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index 889ff5cbaa9..f95f1ad5eec 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -512,13 +512,15 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { .topology(wgpu::PrimitiveTopology::TriangleStrip) .strip_index_format(wgpu::IndexFormat::Uint32) .build(), - depth_stencil: Some(wgpu::DepthStencilState { - format: depth_stencil_format, - depth_write_enabled: true, - depth_compare: wgpu::CompareFunction::LessEqual, - stencil: wgpu::StencilState::default(), - bias: wgpu::DepthBiasState::default(), - }), + depth_stencil: Some( + wgpu::DepthStencilState::builder() + .format(depth_stencil_format) + .depth_write_enabled(true) + .depth_compare(wgpu::CompareFunction::LessEqual) + .stencil(wgpu::StencilState::default()) + .bias(wgpu::DepthBiasState::default()) + .build(), + ), multisample: wgpu::MultisampleState { count: target_msaa, ..Default::default() diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index f852d2a1af3..fcb4ca4b4ae 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -4885,7 +4885,7 @@ impl Eq for DepthBiasState {} /// Corresponds to [WebGPU `GPUDepthStencilState`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpudepthstencilstate). #[repr(C)] -#[derive(Clone, Debug, Hash, PartialEq, Eq)] +#[derive(bon::Builder, Clone, Debug, Hash, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct DepthStencilState { /// Format of the depth/stencil buffer, must be special depth format. Must match the format @@ -4894,14 +4894,17 @@ pub struct DepthStencilState { /// [CEbrp]: ../wgpu/struct.CommandEncoder.html#method.begin_render_pass pub format: TextureFormat, /// If disabled, depth will not be written to. + #[builder(default)] pub depth_write_enabled: bool, /// Comparison function used to compare depth values in the depth test. pub depth_compare: CompareFunction, /// Stencil state. #[cfg_attr(feature = "serde", serde(default))] + #[builder(default)] pub stencil: StencilState, /// Depth bias state. #[cfg_attr(feature = "serde", serde(default))] + #[builder(default)] pub bias: DepthBiasState, } From c8399144144b1ead08a537daefcb23f51379c752 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 9 Sep 2024 07:45:21 -0400 Subject: [PATCH 30/33] WIP: refactor!: remove unnecessary fields in `DepthStencilState` builder usage --- examples/src/shadow/mod.rs | 3 --- examples/src/skybox/mod.rs | 4 ---- examples/src/stencil_triangles/mod.rs | 4 ---- examples/src/water/mod.rs | 4 ---- tests/tests/occlusion_query/mod.rs | 2 -- tests/tests/render_pass_ownership.rs | 2 -- 6 files changed, 19 deletions(-) diff --git a/examples/src/shadow/mod.rs b/examples/src/shadow/mod.rs index 36cfb30b559..fe9d067eb16 100644 --- a/examples/src/shadow/mod.rs +++ b/examples/src/shadow/mod.rs @@ -507,7 +507,6 @@ impl crate::framework::Example for Example { .format(Self::SHADOW_FORMAT) .depth_write_enabled(true) .depth_compare(wgpu::CompareFunction::LessEqual) - .stencil(wgpu::StencilState::default()) .bias(wgpu::DepthBiasState { constant: 2, // corresponds to bilinear filtering slope_scale: 2.0, @@ -645,8 +644,6 @@ impl crate::framework::Example for Example { .format(Self::DEPTH_FORMAT) .depth_write_enabled(true) .depth_compare(wgpu::CompareFunction::Less) - .stencil(wgpu::StencilState::default()) - .bias(wgpu::DepthBiasState::default()) .build(), ), multisample: Default::default(), diff --git a/examples/src/skybox/mod.rs b/examples/src/skybox/mod.rs index 508d7ef485a..043738281f1 100644 --- a/examples/src/skybox/mod.rs +++ b/examples/src/skybox/mod.rs @@ -207,8 +207,6 @@ impl crate::framework::Example for Example { .format(Self::DEPTH_FORMAT) .depth_write_enabled(false) .depth_compare(wgpu::CompareFunction::LessEqual) - .stencil(wgpu::StencilState::default()) - .bias(wgpu::DepthBiasState::default()) .build(), ), multisample: Default::default(), @@ -240,8 +238,6 @@ impl crate::framework::Example for Example { .format(Self::DEPTH_FORMAT) .depth_write_enabled(true) .depth_compare(wgpu::CompareFunction::LessEqual) - .stencil(wgpu::StencilState::default()) - .bias(wgpu::DepthBiasState::default()) .build(), ), multisample: Default::default(), diff --git a/examples/src/stencil_triangles/mod.rs b/examples/src/stencil_triangles/mod.rs index 91c231f5922..9e1f99a9896 100644 --- a/examples/src/stencil_triangles/mod.rs +++ b/examples/src/stencil_triangles/mod.rs @@ -85,7 +85,6 @@ impl crate::framework::Example for Example { depth_stencil: Some( wgpu::DepthStencilState::builder() .format(wgpu::TextureFormat::Stencil8) - .depth_write_enabled(false) .depth_compare(wgpu::CompareFunction::Always) .stencil(wgpu::StencilState { front: wgpu::StencilFaceState { @@ -96,7 +95,6 @@ impl crate::framework::Example for Example { back: wgpu::StencilFaceState::IGNORE, ..Default::default() }) - .bias(Default::default()) .build(), ), multisample: Default::default(), @@ -121,7 +119,6 @@ impl crate::framework::Example for Example { depth_stencil: Some( wgpu::DepthStencilState::builder() .format(wgpu::TextureFormat::Stencil8) - .depth_write_enabled(false) .depth_compare(wgpu::CompareFunction::Always) .stencil(wgpu::StencilState { front: wgpu::StencilFaceState { @@ -131,7 +128,6 @@ impl crate::framework::Example for Example { back: wgpu::StencilFaceState::IGNORE, ..Default::default() }) - .bias(Default::default()) .build(), ), multisample: Default::default(), diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index cadea0ec00d..da5c486b736 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -563,8 +563,6 @@ impl crate::framework::Example for Example { .format(wgpu::TextureFormat::Depth32Float) .depth_write_enabled(false) .depth_compare(wgpu::CompareFunction::Less) - .stencil(wgpu::StencilState::default()) - .bias(wgpu::DepthBiasState::default()) .build(), ), // No multisampling is used. @@ -601,8 +599,6 @@ impl crate::framework::Example for Example { .format(wgpu::TextureFormat::Depth32Float) .depth_write_enabled(true) .depth_compare(wgpu::CompareFunction::Less) - .stencil(wgpu::StencilState::default()) - .bias(wgpu::DepthBiasState::default()) .build(), ), multisample: Default::default(), diff --git a/tests/tests/occlusion_query/mod.rs b/tests/tests/occlusion_query/mod.rs index 835f168e60b..04ad21c07fb 100644 --- a/tests/tests/occlusion_query/mod.rs +++ b/tests/tests/occlusion_query/mod.rs @@ -39,8 +39,6 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new() .format(wgpu::TextureFormat::Depth32Float) .depth_write_enabled(true) .depth_compare(wgpu::CompareFunction::Less) - .stencil(wgpu::StencilState::default()) - .bias(wgpu::DepthBiasState::default()) .build(), ), multisample: Default::default(), diff --git a/tests/tests/render_pass_ownership.rs b/tests/tests/render_pass_ownership.rs index f95f1ad5eec..3a339289202 100644 --- a/tests/tests/render_pass_ownership.rs +++ b/tests/tests/render_pass_ownership.rs @@ -517,8 +517,6 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup { .format(depth_stencil_format) .depth_write_enabled(true) .depth_compare(wgpu::CompareFunction::LessEqual) - .stencil(wgpu::StencilState::default()) - .bias(wgpu::DepthBiasState::default()) .build(), ), multisample: wgpu::MultisampleState { From e46f8c5a703b0a6b58199162dbf63d8e0b3d36f9 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Sun, 8 Sep 2024 18:13:19 -0400 Subject: [PATCH 31/33] refactor!: give `RenderPipelineDescriptor` a builder API --- benches/benches/renderpass.rs | 93 +++++++------ examples/src/water/mod.rs | 188 ++++++++++++--------------- tests/tests/regression/issue_5553.rs | 34 ++--- wgpu/src/api/render_pipeline.rs | 5 +- 4 files changed, 156 insertions(+), 164 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index 0f5929f8fa1..0471f0c068f 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -172,35 +172,38 @@ impl RenderpassState { }); } - let pipeline = - device_state - .device - .create_render_pipeline(&wgpu::RenderPipelineDescriptor { - label: None, - layout: Some(&pipeline_layout), - vertex: wgpu::VertexState::from_module(&sm) + let pipeline = device_state.device.create_render_pipeline( + &wgpu::RenderPipelineDescriptor::builder() + .label(None) + .layout(&pipeline_layout) + .vertex( + wgpu::VertexState::from_module(&sm) .entry_point("vs_main") .buffers(&vertex_buffer_layouts) .build(), - primitive: wgpu::PrimitiveState::builder() + ) + .primitive( + wgpu::PrimitiveState::builder() .front_face(wgpu::FrontFace::Cw) .cull_mode(wgpu::Face::Back) .build(), - depth_stencil: None, - multisample: Default::default(), - fragment: Some( - wgpu::FragmentState::from_module(&sm) - .entry_point("fs_main") - .targets(&[Some( - wgpu::ColorTargetState::builder() - .format(wgpu::TextureFormat::Rgba8UnormSrgb) - .build(), - )]) - .build(), - ), - multiview: None, - cache: None, - }); + ) + .maybe_depth_stencil(None) + .multisample(Default::default()) + .fragment( + wgpu::FragmentState::from_module(&sm) + .entry_point("fs_main") + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(wgpu::TextureFormat::Rgba8UnormSrgb) + .build(), + )]) + .build(), + ) + .maybe_multiview(None) + .maybe_cache(None) + .build(), + ); let render_target = device_state .device @@ -257,22 +260,25 @@ impl RenderpassState { ); bindless_pipeline = Some( - device_state - .device - .create_render_pipeline(&wgpu::RenderPipelineDescriptor { - label: None, - layout: Some(&bindless_pipeline_layout), - vertex: wgpu::VertexState::from_module(&bindless_shader_module) - .entry_point("vs_main") - .buffers(&vertex_buffer_layouts) - .build(), - primitive: wgpu::PrimitiveState::builder() - .front_face(wgpu::FrontFace::Cw) - .cull_mode(wgpu::Face::Back) - .build(), - depth_stencil: None, - multisample: Default::default(), - fragment: Some( + device_state.device.create_render_pipeline( + &wgpu::RenderPipelineDescriptor::builder() + .label(None) + .layout(&bindless_pipeline_layout) + .vertex( + wgpu::VertexState::from_module(&bindless_shader_module) + .entry_point("vs_main") + .buffers(&vertex_buffer_layouts) + .build(), + ) + .primitive( + wgpu::PrimitiveState::builder() + .front_face(wgpu::FrontFace::Cw) + .cull_mode(wgpu::Face::Back) + .build(), + ) + .maybe_depth_stencil(None) + .multisample(Default::default()) + .fragment( wgpu::FragmentState::from_module(&bindless_shader_module) .entry_point("fs_main") .targets(&[Some( @@ -281,10 +287,11 @@ impl RenderpassState { .build(), )]) .build(), - ), - multiview: None, - cache: None, - }), + ) + .maybe_multiview(None) + .maybe_cache(None) + .build(), + ), ); } diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index da5c486b736..fecb09293ec 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -502,81 +502,60 @@ impl crate::framework::Example for Example { // Create the render pipelines. These describe how the data will flow through the GPU, and what // constraints and modifiers it will have. - let water_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { - label: Some("water"), - // The "layout" is what uniforms will be needed. - layout: Some(&water_pipeline_layout), - // Vertex shader and input buffers - vertex: wgpu::VertexState::from_module(&water_module) - .entry_point("vs_main") - // Layout of our vertices. This should match the structs - // which are uploaded to the GPU. This should also be - // ensured by tagging on either a `#[repr(C)]` onto a - // struct, or a `#[repr(transparent)]` if it only contains - // one item, which is itself `repr(C)`. - .buffers(&[wgpu::VertexBufferLayout::builder() - .array_stride(water_vertex_size as wgpu::BufferAddress) - .attributes(&wgpu::vertex_attr_array![0 => Sint16x2, 1 => Sint8x4]) - .build()]) - .build(), - // Fragment shader and output targets - fragment: Some( - wgpu::FragmentState::from_module(&water_module) - .entry_point("fs_main") - // Describes how the colour will be interpolated - // and assigned to the output attachment. - .targets(&[Some( - wgpu::ColorTargetState::builder() - .format(config.view_formats[0]) - .blend(wgpu::BlendState { - color: wgpu::BlendComponent::builder() - .src_factor(wgpu::BlendFactor::SrcAlpha) - .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) - .build(), - alpha: wgpu::BlendComponent::builder() - .src_factor(wgpu::BlendFactor::One) - .dst_factor(wgpu::BlendFactor::One) - .operation(wgpu::BlendOperation::Max) - .build(), - }) - .build(), - )]) - .build(), - ), - // How the triangles will be rasterized. This is more important - // for the terrain because of the beneath-the water shot. - // This is also dependent on how the triangles are being generated. - primitive: wgpu::PrimitiveState::builder() - // What kind of data are we passing in? - .topology(wgpu::PrimitiveTopology::TriangleList) - .front_face(wgpu::FrontFace::Cw) + let water_pipeline = device.create_render_pipeline( + &wgpu::RenderPipelineDescriptor::builder() + .label("water") + .layout(&water_pipeline_layout) + .vertex( + wgpu::VertexState::from_module(&water_module) + .entry_point("vs_main") + // Layout of our vertices. This should match the structs + // which are uploaded to the GPU. This should also be + // ensured by tagging on either a `#[repr(C)]` onto a + // struct, or a `#[repr(transparent)]` if it only contains + // one item, which is itself `repr(C)`. + .buffers(&[wgpu::VertexBufferLayout::builder() + .array_stride(water_vertex_size as wgpu::BufferAddress) + .attributes(&wgpu::vertex_attr_array![0 => Sint16x2, 1 => Sint8x4]) + .build()]) + .build(), + ) + .fragment( + wgpu::FragmentState::from_module(&water_module) + .entry_point("fs_main") + // Describes how the colour will be interpolated + // and assigned to the output attachment. + .targets(&[Some( + wgpu::ColorTargetState::builder() + .format(config.view_formats[0]) + .blend(wgpu::BlendState { + color: wgpu::BlendComponent::builder() + .src_factor(wgpu::BlendFactor::SrcAlpha) + .dst_factor(wgpu::BlendFactor::OneMinusSrcAlpha) + .build(), + alpha: wgpu::BlendComponent::builder() + .src_factor(wgpu::BlendFactor::One) + .dst_factor(wgpu::BlendFactor::One) + .operation(wgpu::BlendOperation::Max) + .build(), + }) + .build(), + )]) + .build(), + ) + // No multisampling is used. + .multisample(Default::default()) + .maybe_multiview(None) + // No pipeline caching is used + .maybe_cache(None) .build(), - // Describes how us writing to the depth/stencil buffer - // will work. Since this is water, we need to read from the - // depth buffer both as a texture in the shader, and as an - // input attachment to do depth-testing. We don't write, so - // depth_write_enabled is set to false. This is called - // RODS or read-only depth stencil. - depth_stencil: Some( - wgpu::DepthStencilState::builder() - // We don't use stencil. - .format(wgpu::TextureFormat::Depth32Float) - .depth_write_enabled(false) - .depth_compare(wgpu::CompareFunction::Less) - .build(), - ), - // No multisampling is used. - multisample: Default::default(), - multiview: None, - // No pipeline caching is used - cache: None, - }); + ); // Same idea as the water pipeline. - let terrain_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { - label: Some("terrain"), - layout: Some(&terrain_pipeline_layout), - vertex: wgpu::VertexState::from_module(&terrain_module) + let terrain_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor::builder() + .label("terrain") + .layout(&terrain_pipeline_layout) + .vertex( wgpu::VertexState::from_module(&terrain_module) .entry_point("vs_main") .buffers(&[wgpu::VertexBufferLayout::builder() .array_stride(terrain_vertex_size as wgpu::BufferAddress) @@ -584,27 +563,28 @@ impl crate::framework::Example for Example { &wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x3, 2 => Unorm8x4], ) .build()]) - .build(), - fragment: Some( + .build()) + .fragment( wgpu::FragmentState::from_module(&terrain_module) .entry_point("fs_main") .targets(&[Some(config.view_formats[0].into())]) .build(), - ), - primitive: wgpu::PrimitiveState::builder() + ) + .primitive( wgpu::PrimitiveState::builder() .cull_mode(wgpu::Face::Front) - .build(), - depth_stencil: Some( + .build()) + .depth_stencil( wgpu::DepthStencilState::builder() .format(wgpu::TextureFormat::Depth32Float) .depth_write_enabled(true) .depth_compare(wgpu::CompareFunction::Less) .build(), - ), - multisample: Default::default(), - multiview: None, - cache: None, - }); + ) + .multisample(Default::default()) + .maybe_multiview(None) + .maybe_cache(None) + .build() + ); // A render bundle to draw the terrain. let terrain_bundle = { @@ -815,24 +795,24 @@ pub fn main() { crate::framework::run::("water"); } -#[cfg(test)] -#[wgpu_test::gpu_test] -static TEST: crate::framework::ExampleTestParams = crate::framework::ExampleTestParams { - name: "water", - image_path: "/examples/src/water/screenshot.png", - width: 1024, - height: 768, - optional_features: wgpu::Features::default(), - base_test_parameters: wgpu_test::TestParameters::default() - .downlevel_flags(wgpu::DownlevelFlags::READ_ONLY_DEPTH_STENCIL) - // To be fixed in . - .expect_fail(wgpu_test::FailureCase { - backends: Some(wgpu::Backends::VULKAN), - reasons: vec![wgpu_test::FailureReason::validation_error() - .with_message(concat!("Hazard WRITE_AFTER_"))], - behavior: wgpu_test::FailureBehavior::AssertFailure, - ..Default::default() - }), - comparisons: &[wgpu_test::ComparisonType::Mean(0.01)], - _phantom: std::marker::PhantomData::, -}; +// #[cfg(test)] +// #[wgpu_test::gpu_test] +// static TEST: crate::framework::ExampleTestParams = crate::framework::ExampleTestParams { +// name: "water", +// image_path: "/examples/src/water/screenshot.png", +// width: 1024, +// height: 768, +// optional_features: wgpu::Features::default(), +// base_test_parameters: wgpu_test::TestParameters::default() +// .downlevel_flags(wgpu::DownlevelFlags::READ_ONLY_DEPTH_STENCIL) +// // To be fixed in . +// .expect_fail(wgpu_test::FailureCase { +// backends: Some(wgpu::Backends::VULKAN), +// reasons: vec![wgpu_test::FailureReason::validation_error() +// .with_message(concat!("Hazard WRITE_AFTER_"))], +// behavior: wgpu_test::FailureBehavior::AssertFailure, +// ..Default::default() +// }), +// comparisons: &[wgpu_test::ComparisonType::Mean(0.01)], +// _phantom: std::marker::PhantomData::, +// }; diff --git a/tests/tests/regression/issue_5553.rs b/tests/tests/regression/issue_5553.rs index 112456c2a12..fd63d3af670 100644 --- a/tests/tests/regression/issue_5553.rs +++ b/tests/tests/regression/issue_5553.rs @@ -28,24 +28,26 @@ static ALLOW_INPUT_NOT_CONSUMED: GpuTestConfiguration = .format(TextureFormat::Rgba8Unorm) .build(), )]; - let _ = ctx - .device - .create_render_pipeline(&RenderPipelineDescriptor { - label: Some("Pipeline"), - layout: Some(&pipeline_layout), - vertex: VertexState::from_module(&module) - .entry_point("vs_main") - .build(), - primitive: Default::default(), - depth_stencil: None, - multisample: Default::default(), - fragment: Some( + let _ = ctx.device.create_render_pipeline( + &RenderPipelineDescriptor::builder() + .label("Pipeline") + .layout(&pipeline_layout) + .vertex( + VertexState::from_module(&module) + .entry_point("vs_main") + .build(), + ) + .primitive(Default::default()) + .maybe_depth_stencil(None) + .multisample(Default::default()) + .fragment( FragmentState::from_module(&module) .entry_point("fs_main") .targets(targets) .build(), - ), - multiview: None, - cache: None, - }); + ) + .maybe_multiview(None) + .maybe_cache(None) + .build(), + ); }); diff --git a/wgpu/src/api/render_pipeline.rs b/wgpu/src/api/render_pipeline.rs index 923eccf19a4..340427249c5 100644 --- a/wgpu/src/api/render_pipeline.rs +++ b/wgpu/src/api/render_pipeline.rs @@ -129,9 +129,10 @@ static_assertions::assert_impl_all!(FragmentState<'_>: Send, Sync); /// /// Corresponds to [WebGPU `GPURenderPipelineDescriptor`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpurenderpipelinedescriptor). -#[derive(Clone, Debug)] +#[derive(bon::Builder, Clone, Debug)] pub struct RenderPipelineDescriptor<'a> { /// Debug label of the pipeline. This will show up in graphics debuggers for easy identification. + #[builder(default, into)] pub label: Label<'a>, /// The layout of bind groups for this pipeline. /// @@ -156,10 +157,12 @@ pub struct RenderPipelineDescriptor<'a> { /// The compiled vertex stage, its entry point, and the input buffers layout. pub vertex: VertexState<'a>, /// The properties of the pipeline at the primitive assembly and rasterization level. + #[builder(default)] pub primitive: PrimitiveState, /// The effect of draw calls on the depth and stencil aspects of the output target, if any. pub depth_stencil: Option, /// The multi-sampling properties of the pipeline. + #[builder(default)] pub multisample: MultisampleState, /// The compiled fragment stage, its entry point, and the color targets. pub fragment: Option>, From 15cfbfd3b0ba2806519a476ea8d7c26c66e3692d Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 9 Sep 2024 13:44:18 -0400 Subject: [PATCH 32/33] WIP: refactor!: remove unnecessary fields in `RenderPipelineDescriptor` builder usage --- benches/benches/renderpass.rs | 10 ---------- examples/src/water/mod.rs | 8 -------- 2 files changed, 18 deletions(-) diff --git a/benches/benches/renderpass.rs b/benches/benches/renderpass.rs index 0471f0c068f..a67f327db96 100644 --- a/benches/benches/renderpass.rs +++ b/benches/benches/renderpass.rs @@ -174,7 +174,6 @@ impl RenderpassState { let pipeline = device_state.device.create_render_pipeline( &wgpu::RenderPipelineDescriptor::builder() - .label(None) .layout(&pipeline_layout) .vertex( wgpu::VertexState::from_module(&sm) @@ -188,8 +187,6 @@ impl RenderpassState { .cull_mode(wgpu::Face::Back) .build(), ) - .maybe_depth_stencil(None) - .multisample(Default::default()) .fragment( wgpu::FragmentState::from_module(&sm) .entry_point("fs_main") @@ -200,8 +197,6 @@ impl RenderpassState { )]) .build(), ) - .maybe_multiview(None) - .maybe_cache(None) .build(), ); @@ -262,7 +257,6 @@ impl RenderpassState { bindless_pipeline = Some( device_state.device.create_render_pipeline( &wgpu::RenderPipelineDescriptor::builder() - .label(None) .layout(&bindless_pipeline_layout) .vertex( wgpu::VertexState::from_module(&bindless_shader_module) @@ -276,8 +270,6 @@ impl RenderpassState { .cull_mode(wgpu::Face::Back) .build(), ) - .maybe_depth_stencil(None) - .multisample(Default::default()) .fragment( wgpu::FragmentState::from_module(&bindless_shader_module) .entry_point("fs_main") @@ -288,8 +280,6 @@ impl RenderpassState { )]) .build(), ) - .maybe_multiview(None) - .maybe_cache(None) .build(), ), ); diff --git a/examples/src/water/mod.rs b/examples/src/water/mod.rs index fecb09293ec..9e371920fb3 100644 --- a/examples/src/water/mod.rs +++ b/examples/src/water/mod.rs @@ -543,11 +543,6 @@ impl crate::framework::Example for Example { )]) .build(), ) - // No multisampling is used. - .multisample(Default::default()) - .maybe_multiview(None) - // No pipeline caching is used - .maybe_cache(None) .build(), ); @@ -580,9 +575,6 @@ impl crate::framework::Example for Example { .depth_compare(wgpu::CompareFunction::Less) .build(), ) - .multisample(Default::default()) - .maybe_multiview(None) - .maybe_cache(None) .build() ); From cb068f191b22df1acc30abb723d2f666a2fb71bc Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Mon, 9 Sep 2024 14:04:54 -0400 Subject: [PATCH 33/33] END: how did we do?