diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 0f045770a27..68cb3147172 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -19,7 +19,7 @@ env: # # This is the MSRV used by all repository infrastructure. - REPO_MSRV: "1.93" + REPO_MSRV: "nightly-2026-03-11" # # Environment variables diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c864629f005..8bd75da1505 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,12 +19,12 @@ env: # # This is the MSRV used by all repository infrastructure. - REPO_MSRV: "1.93" + REPO_MSRV: "nightly-2026-03-11" # This is the MSRV used by `wgpu` itself. - WGPU_MSRV: "1.87" + WGPU_MSRV: "nightly-2026-03-11" # This is the MSRV used by the `wgpu-core`, `wgpu-hal`, and `wgpu-types` crates, # to ensure that they can be used with firefox. - CORE_MSRV: "1.87" + CORE_MSRV: "nightly-2026-03-11" # # Environment variables diff --git a/.github/workflows/cts.yml b/.github/workflows/cts.yml index 90bb4cd5991..b828fbe411a 100644 --- a/.github/workflows/cts.yml +++ b/.github/workflows/cts.yml @@ -14,7 +14,7 @@ on: merge_group: env: - REPO_MSRV: "1.93" + REPO_MSRV: "nightly-2026-03-11" CARGO_INCREMENTAL: false CARGO_TERM_COLOR: always DENO_WEBGPU_DX12_COMPILER: dynamicdxc diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 4c14ea0b688..d955fdd8df0 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -15,7 +15,7 @@ on: env: # This is the MSRV used by all repository infrastructure. - REPO_MSRV: "1.93" + REPO_MSRV: "nightly-2026-03-11" CARGO_INCREMENTAL: false CARGO_TERM_COLOR: always diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml index 9fab5af87c2..f0dffb0ca77 100644 --- a/.github/workflows/generate.yml +++ b/.github/workflows/generate.yml @@ -19,7 +19,7 @@ env: # # This is the MSRV used by `wgpu` itself. - WGPU_MSRV: "1.87" + WGPU_MSRV: "nightly-2026-03-11" RUSTFLAGS: -D warnings # Every time a PR is pushed to, cancel any previous jobs. This diff --git a/Cargo.lock b/Cargo.lock index 9acfa798816..943206dc4e7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3900,9 +3900,8 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.117" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +version = "2.0.111" +source = "git+https://github.com/erichdongubler-contrib/syn?rev=146280b69756a0a8882d21ed061752214da94049#146280b69756a0a8882d21ed061752214da94049" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 7c8e42077f0..d50e58c0aff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -324,6 +324,8 @@ wgpu = { path = "./wgpu" } env_logger = { version = "0.11", git = "https://github.com/rust-cli/env_logger.git", rev = "d550741" } libtest-mimic = { version = "0.8", git = "https://github.com/cwfitzgerald/libtest-mimic.git", rev = "9979b3c" } +syn = { git = "https://github.com/erichdongubler-contrib/syn", rev = "146280b69756a0a8882d21ed061752214da94049" } + [profile.release] lto = "thin" debug = true diff --git a/examples/features/src/big_compute_buffers/mod.rs b/examples/features/src/big_compute_buffers/mod.rs index c7ef361da23..5a8d56237da 100644 --- a/examples/features/src/big_compute_buffers/mod.rs +++ b/examples/features/src/big_compute_buffers/mod.rs @@ -27,13 +27,12 @@ pub async fn execute_gpu(numbers: &[f32]) -> Vec { required_features: Features::BUFFER_BINDING_ARRAY | Features::STORAGE_RESOURCE_BINDING_ARRAY | Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, - memory_hints: wgpu::MemoryHints::Performance, required_limits: wgpu::Limits { max_buffer_size: MAX_BUFFER_SIZE, max_binding_array_elements_per_shader_stage: 8, ..Default::default() }, - ..Default::default() + .. }) .await .unwrap(); @@ -48,12 +47,11 @@ pub async fn execute_gpu_inner( ) -> Vec { let (staging_buffers, storage_buffers, bind_group, compute_pipeline) = setup(device, numbers); - let mut encoder = - device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); { let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { label: Some("compute pass descriptor"), - timestamp_writes: None, + .. }); cpass.set_pipeline(&compute_pipeline); cpass.set_bind_group(0, Some(&bind_group), &[]); @@ -127,7 +125,7 @@ fn setup_pipeline( let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: Some("Compute Pipeline Layout"), bind_group_layouts: &[Some(&bind_group_layout)], - immediate_size: 0, + .. }); device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { @@ -135,8 +133,7 @@ fn setup_pipeline( layout: Some(&pipeline_layout), module: &cs_module, entry_point: Some("main"), - compilation_options: Default::default(), - cache: None, + .. }) } @@ -159,8 +156,8 @@ fn setup_binds( visibility: wgpu::ShaderStages::COMPUTE, ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Storage { read_only: false }, - has_dynamic_offset: false, min_binding_size: Some(NonZeroU64::new(4).unwrap()), + .. }, count: Some(NonZeroU32::new(buffers.len() as u32).unwrap()), }; @@ -213,7 +210,7 @@ fn create_staging_buffers(device: &wgpu::Device, numbers: &[f32]) -> Vec wgpu::DownlevelCapabilities { wgpu::DownlevelCapabilities { flags: wgpu::DownlevelFlags::COMPUTE_SHADERS, - ..Default::default() + .. } } @@ -101,13 +101,13 @@ impl crate::framework::Example for Example { count: None, }, ], - label: None, + .. }); let compute_pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: Some("compute"), bind_group_layouts: &[Some(&compute_bind_group_layout)], - immediate_size: 0, + .. }); // create render pipeline with empty bind group layout @@ -116,16 +116,14 @@ impl crate::framework::Example for Example { device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: Some("render"), bind_group_layouts: &[], - immediate_size: 0, + .. }); 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: &[ wgpu::VertexBufferLayout { array_stride: 4 * 4, @@ -134,22 +132,19 @@ impl crate::framework::Example for Example { }, wgpu::VertexBufferLayout { array_stride: 2 * 4, - step_mode: wgpu::VertexStepMode::Vertex, attributes: &wgpu::vertex_attr_array![2 => Float32x2], + .. }, ], + .. }, fragment: Some(wgpu::FragmentState { module: &draw_shader, entry_point: Some("main_fs"), - compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], + .. }), - primitive: wgpu::PrimitiveState::default(), - depth_stencil: None, - multisample: wgpu::MultisampleState::default(), - multiview_mask: None, - cache: None, + .. }); // create compute pipeline @@ -159,8 +154,7 @@ impl crate::framework::Example for Example { layout: Some(&compute_pipeline_layout), module: &compute_shader, entry_point: Some("main"), - compilation_options: Default::default(), - cache: None, + .. }); // buffer for the three 2d triangle vertices of each instance @@ -221,7 +215,7 @@ impl crate::framework::Example for Example { resource: particle_buffers[(i + 1) % 2].as_entire_binding(), // bind to opposite buffer }, ], - label: None, + .. })); } @@ -270,12 +264,8 @@ impl crate::framework::Example for Example { }, })]; let render_pass_descriptor = wgpu::RenderPassDescriptor { - label: None, color_attachments: &color_attachments, - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, + .. }; // get command encoder @@ -285,10 +275,7 @@ impl crate::framework::Example for Example { command_encoder.push_debug_group("compute boid movement"); { // compute pass - let mut cpass = command_encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { - label: None, - timestamp_writes: None, - }); + let mut cpass = command_encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { .. }); cpass.set_pipeline(&self.compute_pipeline); cpass.set_bind_group(0, &self.particle_bind_groups[self.frame_num % 2], &[]); cpass.dispatch_workgroups(self.work_group_count, 1, 1); diff --git a/examples/features/src/cube/mod.rs b/examples/features/src/cube/mod.rs index 5b6c5c8fce1..a41d2f2e18e 100644 --- a/examples/features/src/cube/mod.rs +++ b/examples/features/src/cube/mod.rs @@ -131,15 +131,13 @@ impl crate::framework::Example for Example { // Create pipeline layout let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { - label: None, entries: &[ wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStages::VERTEX, ty: wgpu::BindingType::Buffer { - ty: wgpu::BufferBindingType::Uniform, - has_dynamic_offset: false, min_binding_size: wgpu::BufferSize::new(64), + .. }, count: None, }, @@ -147,18 +145,17 @@ impl crate::framework::Example for Example { binding: 1, visibility: wgpu::ShaderStages::FRAGMENT, ty: wgpu::BindingType::Texture { - multisampled: false, sample_type: wgpu::TextureSampleType::Uint, - view_dimension: wgpu::TextureViewDimension::D2, + .. }, count: None, }, ], + .. }); let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, bind_group_layouts: &[Some(&bind_group_layout)], - immediate_size: 0, + .. }); // Create the texture @@ -167,26 +164,23 @@ impl crate::framework::Example for Example { let texture_extent = wgpu::Extent3d { width: size, 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_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); queue.write_texture( texture.as_image_copy(), &texels, wgpu::TexelCopyBufferLayout { - offset: 0, bytes_per_row: Some(size), - rows_per_image: None, + .. }, texture_extent, ); @@ -220,7 +214,6 @@ impl crate::framework::Example for Example { let vertex_buffers = [wgpu::VertexBufferLayout { array_stride: vertex_size as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, attributes: &[ wgpu::VertexAttribute { format: wgpu::VertexFormat::Float32x4, @@ -233,31 +226,28 @@ impl crate::framework::Example for Example { shader_location: 1, }, ], + .. }]; 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, + .. }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), - compilation_options: Default::default(), targets: &[Some(config.view_formats[0].into())], + .. }), primitive: wgpu::PrimitiveState { cull_mode: Some(wgpu::Face::Back), - ..Default::default() + .. }, - depth_stencil: None, - multisample: wgpu::MultisampleState::default(), - multiview_mask: None, - cache: None, + .. }); let pipeline_wire = if device @@ -265,41 +255,36 @@ impl crate::framework::Example for Example { .contains(wgpu::Features::POLYGON_MODE_LINE) { 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, + .. }, fragment: Some(wgpu::FragmentState { 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 { - operation: wgpu::BlendOperation::Add, src_factor: wgpu::BlendFactor::SrcAlpha, dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha, + .. }, alpha: wgpu::BlendComponent::REPLACE, }), - 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() + .. }, - depth_stencil: None, - multisample: wgpu::MultisampleState::default(), - multiview_mask: None, - cache: None, + .. }); Some(pipeline_wire) } else { @@ -338,11 +323,8 @@ impl crate::framework::Example for Example { device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, color_attachments: &[Some(wgpu::RenderPassColorAttachment { view, - depth_slice: None, - resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color { r: 0.1, @@ -352,11 +334,9 @@ impl crate::framework::Example for Example { }), store: wgpu::StoreOp::Store, }, + .. })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, + .. }); rpass.push_debug_group("Prepare data for draw."); rpass.set_pipeline(&self.pipeline); diff --git a/examples/features/src/framework.rs b/examples/features/src/framework.rs index 0d0ba12d129..02626fc9cbf 100644 --- a/examples/features/src/framework.rs +++ b/examples/features/src/framework.rs @@ -495,8 +495,8 @@ pub struct ExampleTestParams { pub image_path: &'static str, pub width: u32, pub height: u32, - pub optional_features: wgpu::Features, - pub base_test_parameters: wgpu_test::TestParameters, + pub optional_features: wgpu::Features = wgpu::Features::empty(), + pub base_test_parameters: wgpu_test::TestParameters = wgpu_test::TestParameters { .. }, /// Comparisons against FLIP statistics that determine if the test passes or fails. pub comparisons: &'static [ComparisonType], pub _phantom: std::marker::PhantomData, @@ -533,12 +533,10 @@ impl From> 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_view = dst_texture.create_view(&wgpu::TextureViewDescriptor::default()); @@ -547,7 +545,7 @@ impl From> label: Some("image map buffer"), size: params.width as u64 * params.height as u64 * 4, usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ, - mapped_at_creation: false, + .. }); let mut example = E::init( @@ -575,16 +573,13 @@ impl From> cmd_buf.copy_texture_to_buffer( wgpu::TexelCopyTextureInfo { texture: &dst_texture, - mip_level: 0, - origin: wgpu::Origin3d::ZERO, - aspect: wgpu::TextureAspect::All, + .. }, wgpu::TexelCopyBufferInfo { buffer: &dst_buffer, layout: wgpu::TexelCopyBufferLayout { - offset: 0, bytes_per_row: Some(params.width * 4), - rows_per_image: None, + .. }, }, wgpu::Extent3d { diff --git a/examples/features/src/lib.rs b/examples/features/src/lib.rs index 6bf97458460..e0c5ba39746 100644 --- a/examples/features/src/lib.rs +++ b/examples/features/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(default_field_values)] #![allow(clippy::arc_with_non_send_sync)] // False positive on wasm #![warn(clippy::allow_attributes)] diff --git a/examples/features/src/mipmap/mod.rs b/examples/features/src/mipmap/mod.rs index 108413deded..99a0625d917 100644 --- a/examples/features/src/mipmap/mod.rs +++ b/examples/features/src/mipmap/mod.rs @@ -85,27 +85,18 @@ 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: &[], + .. }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), - compilation_options: Default::default(), targets: &[Some(TEXTURE_FORMAT.into())], + .. }), - primitive: wgpu::PrimitiveState { - topology: wgpu::PrimitiveTopology::TriangleList, - ..Default::default() - }, - depth_stencil: None, - multisample: wgpu::MultisampleState::default(), - multiview_mask: None, - cache: None, + .. }); let bind_group_layout = pipeline.get_bind_group_layout(0); @@ -125,14 +116,9 @@ impl Example { .map(|mip| { texture.create_view(&wgpu::TextureViewDescriptor { label: Some("mip"), - format: None, - dimension: None, - usage: None, - aspect: wgpu::TextureAspect::All, base_mip_level: mip, mip_level_count: Some(1), - base_array_layer: 0, - array_layer_count: None, + .. }) }) .collect::>(); @@ -160,17 +146,13 @@ impl Example { label: None, color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: &views[target_mip], - depth_slice: None, - resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::WHITE), store: wgpu::StoreOp::Store, }, + .. })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, + .. }); if let Some(ref query_sets) = query_sets { rpass.write_timestamp(&query_sets.timestamp, timestamp_query_index_base); @@ -226,19 +208,18 @@ impl crate::framework::Example for Example { let texture_extent = wgpu::Extent3d { width: size, 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_view = texture.create_view(&wgpu::TextureViewDescriptor::default()); //Note: we could use queue.write_texture instead, and this is what other @@ -252,9 +233,8 @@ impl crate::framework::Example for Example { wgpu::TexelCopyBufferInfo { buffer: &temp_buf, layout: wgpu::TexelCopyBufferLayout { - offset: 0, bytes_per_row: Some(4 * size), - rows_per_image: None, + .. }, }, texture.as_image_copy(), @@ -290,24 +270,21 @@ impl crate::framework::Example for Example { module: &shader, entry_point: Some("vs_main"), compilation_options: Default::default(), - buffers: &[], + .. }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), - 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() + .. }, - depth_stencil: None, - multisample: wgpu::MultisampleState::default(), - multiview_mask: None, - cache: None, + .. }); // Create bind group @@ -364,7 +341,7 @@ impl crate::framework::Example for Example { label: Some("query buffer"), size: buffer_size, usage: wgpu::BufferUsages::QUERY_RESOLVE | wgpu::BufferUsages::COPY_SRC, - mapped_at_creation: false, + .. }); // Mapping buffer @@ -372,7 +349,7 @@ impl crate::framework::Example for Example { label: Some("query buffer"), size: buffer_size, usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ, - mapped_at_creation: false, + .. }); Some(QuerySets { @@ -483,17 +460,13 @@ impl crate::framework::Example for Example { label: None, color_attachments: &[Some(wgpu::RenderPassColorAttachment { view, - depth_slice: None, - resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(clear_color), store: wgpu::StoreOp::Store, }, + .. })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, + .. }); rpass.set_pipeline(&self.draw_pipeline); rpass.set_bind_group(0, &self.bind_group, &[]); @@ -515,10 +488,9 @@ pub static TEST: crate::framework::ExampleTestParams = crate::framework::Example image_path: "/examples/features/src/mipmap/screenshot.png", width: 1024, height: 768, - optional_features: wgpu::Features::default(), - base_test_parameters: wgpu_test::TestParameters::default(), comparisons: &[wgpu_test::ComparisonType::Mean(0.02)], _phantom: std::marker::PhantomData::, + .. }; #[cfg(test)] @@ -529,7 +501,6 @@ pub static TEST_QUERY: crate::framework::ExampleTestParams = crate::framework::E width: 1024, height: 768, optional_features: QUERY_FEATURES, - base_test_parameters: wgpu_test::TestParameters::default(), // Somehow, this test on CI lavapipe reasonably often gets error of 0.025341, significantly higher // than the comparison we usually do with mean 0.005. This only happens when the query is used. comparisons: &[ @@ -540,4 +511,5 @@ pub static TEST_QUERY: crate::framework::ExampleTestParams = crate::framework::E }, ], _phantom: std::marker::PhantomData::, + .. }; diff --git a/examples/features/src/msaa_line/mod.rs b/examples/features/src/msaa_line/mod.rs index bcf931681ae..604ab889593 100644 --- a/examples/features/src/msaa_line/mod.rs +++ b/examples/features/src/msaa_line/mod.rs @@ -49,44 +49,38 @@ impl Example { ) -> wgpu::RenderBundle { log::info!("sample_count: {sample_count}"); 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 { array_stride: size_of::() as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x4], + .. }], + .. }, fragment: Some(wgpu::FragmentState { module: shader, entry_point: Some("fs_main"), - 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() + .. }, - depth_stencil: None, multisample: wgpu::MultisampleState { count: sample_count, - ..Default::default() + .. }, - multiview_mask: None, - cache: None, + .. }); let mut encoder = device.create_render_bundle_encoder(&wgpu::RenderBundleEncoderDescriptor { - label: None, color_formats: &[Some(config.view_formats[0])], - depth_stencil: None, sample_count, - multiview: None, + .. }); encoder.set_pipeline(&pipeline); encoder.set_vertex_buffer(0, vertex_buffer.slice(..)); @@ -104,17 +98,16 @@ impl Example { let multisampled_texture_extent = wgpu::Extent3d { width: config.width, 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 | wgpu::TextureUsages::TRANSIENT, label: None, view_formats: &[], + .. }; device @@ -158,11 +151,8 @@ 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: &[], - immediate_size: 0, - }); + let pipeline_layout = + device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor::default()); let multisampled_framebuffer = Example::create_multisampled_framebuffer(device, config, sample_count); @@ -279,17 +269,15 @@ impl crate::framework::Example for Example { let rpass_color_attachment = if self.sample_count == 1 { wgpu::RenderPassColorAttachment { view, - depth_slice: None, - resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), store: wgpu::StoreOp::Store, }, + .. } } else { wgpu::RenderPassColorAttachment { view: &self.multisampled_framebuffer, - depth_slice: None, resolve_target: Some(view), ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::BLACK), @@ -297,17 +285,14 @@ impl crate::framework::Example for Example { // On tile-based GPU, avoid store can reduce your app's memory footprint. store: wgpu::StoreOp::Discard, }, + .. } }; encoder .begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, color_attachments: &[Some(rpass_color_attachment)], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, + .. }) .execute_bundles(iter::once(&self.bundle)); } @@ -328,7 +313,6 @@ pub static TEST: crate::framework::ExampleTestParams = crate::framework::Example width: 1024, height: 768, optional_features: wgpu::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES, - base_test_parameters: wgpu_test::TestParameters::default(), // There's a lot of natural variance so we check the weighted median too to differentiate // real failures from variance. comparisons: &[ @@ -339,4 +323,5 @@ pub static TEST: crate::framework::ExampleTestParams = crate::framework::Example }, ], _phantom: std::marker::PhantomData::, + .. }; diff --git a/examples/features/src/multiple_render_targets/mod.rs b/examples/features/src/multiple_render_targets/mod.rs index 76a0643f6df..a9590bdba68 100644 --- a/examples/features/src/multiple_render_targets/mod.rs +++ b/examples/features/src/multiple_render_targets/mod.rs @@ -33,48 +33,37 @@ impl MultiTargetRenderer { let size = wgpu::Extent3d { width: WIDTH as u32, height: HEIGHT as u32, - depth_or_array_layers: 1, + .. }; let texture = device.create_texture(&wgpu::TextureDescriptor { label: Some("data texture"), size, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, format: wgpu::TextureFormat::R8Unorm, // we need only the red channel for black/white image, usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING, view_formats: &[], + .. }); let ball_texture_data = &create_ball_texture_data(WIDTH, HEIGHT); queue.write_texture( wgpu::TexelCopyTextureInfo { - aspect: wgpu::TextureAspect::All, texture: &texture, - mip_level: 0, - origin: wgpu::Origin3d::ZERO, + .. }, ball_texture_data, wgpu::TexelCopyBufferLayout { - offset: 0, bytes_per_row: Some(WIDTH as u32), rows_per_image: Some(HEIGHT as u32), + .. }, size, ); let view = texture.create_view(&wgpu::TextureViewDescriptor { label: Some("view"), - format: None, - dimension: Some(wgpu::TextureViewDimension::D2), - usage: None, - aspect: wgpu::TextureAspect::All, - base_mip_level: 0, - mip_level_count: None, - base_array_layer: 0, - array_layer_count: None, + .. }); (texture, view) @@ -92,36 +81,28 @@ impl MultiTargetRenderer { wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Texture { - multisampled: false, - sample_type: wgpu::TextureSampleType::Float { filterable: true }, - view_dimension: wgpu::TextureViewDimension::D2, - }, - count: None, + ty: wgpu::BindingType::Texture { .. }, + .. }, wgpu::BindGroupLayoutEntry { binding: 1, visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), - count: None, + ty: wgpu::BindingType::Sampler(Default::default()), + .. }, ], label: None, }); let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, bind_group_layouts: &[Some(&texture_bind_group_layout)], - immediate_size: 0, + .. }); let sampler = device.create_sampler(&wgpu::SamplerDescriptor { address_mode_u: wgpu::AddressMode::Repeat, address_mode_v: wgpu::AddressMode::Repeat, address_mode_w: wgpu::AddressMode::Repeat, - mag_filter: wgpu::FilterMode::Nearest, - min_filter: wgpu::FilterMode::Nearest, - mipmap_filter: wgpu::MipmapFilterMode::Nearest, ..Default::default() }); @@ -139,30 +120,24 @@ impl MultiTargetRenderer { resource: wgpu::BindingResource::Sampler(&sampler), }, ], - label: None, + .. }); 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: &[], + .. }, fragment: Some(wgpu::FragmentState { module: shader, entry_point: Some("fs_multi_main"), // IMPORTANT: specify the color states for the outputs: - compilation_options: Default::default(), targets: target_states, + .. }), - primitive: wgpu::PrimitiveState::default(), - depth_stencil: None, - multisample: wgpu::MultisampleState::default(), - multiview_mask: None, - cache: None, + .. }); Self { @@ -177,12 +152,8 @@ impl MultiTargetRenderer { targets: &[Option], ) { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, color_attachments: targets, - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, + .. }); rpass.set_pipeline(&self.pipeline); rpass.set_bind_group(0, &self.bindgroup, &[]); @@ -212,63 +183,45 @@ impl TargetRenderer { wgpu::BindGroupLayoutEntry { binding: 0, visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Texture { - multisampled: false, - sample_type: wgpu::TextureSampleType::Float { filterable: true }, - view_dimension: wgpu::TextureViewDimension::D2, - }, - count: None, + ty: wgpu::BindingType::Texture { .. }, + .. }, wgpu::BindGroupLayoutEntry { binding: 1, visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), - count: None, + ty: wgpu::BindingType::Sampler(Default::default()), + .. }, ], label: None, }); let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, bind_group_layouts: &[Some(&texture_bind_group_layout)], - immediate_size: 0, + .. }); let sampler = device.create_sampler(&wgpu::SamplerDescriptor { address_mode_u: wgpu::AddressMode::Repeat, address_mode_v: wgpu::AddressMode::Repeat, address_mode_w: wgpu::AddressMode::Repeat, - mag_filter: wgpu::FilterMode::Nearest, - min_filter: wgpu::FilterMode::Nearest, - mipmap_filter: wgpu::MipmapFilterMode::Nearest, ..Default::default() }); 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"), - compilation_options: Default::default(), - buffers: &[], + .. }, fragment: Some(wgpu::FragmentState { module: shader, entry_point: Some("fs_display_main"), - compilation_options: Default::default(), - targets: &[Some(wgpu::ColorTargetState { - format, - blend: None, - write_mask: Default::default(), - })], + targets: &[Some(wgpu::ColorTargetState { format, .. })], + .. }), - primitive: wgpu::PrimitiveState::default(), - depth_stencil: None, - multisample: wgpu::MultisampleState::default(), - multiview_mask: None, - cache: None, + .. }); let (bg_left, bg_right) = @@ -330,17 +283,13 @@ impl TargetRenderer { label: None, color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: surface_view, - depth_slice: None, - resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::GREEN), store: wgpu::StoreOp::Store, }, + .. })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, + .. }); rpass.set_pipeline(&self.pipeline); rpass.set_bind_group(0, &self.bindgroup_left, &[]); @@ -389,26 +338,22 @@ impl TextureTargets { let red_texture = device.create_texture(&wgpu::TextureDescriptor { label: None, size, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, format, usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::RENDER_ATTACHMENT, view_formats: &[format], + .. }); let green_texture = device.create_texture(&wgpu::TextureDescriptor { label: None, size, - mip_level_count: 1, - sample_count: 1, - dimension: wgpu::TextureDimension::D2, format, usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::RENDER_ATTACHMENT, view_formats: &[format], + .. }); let red_view = red_texture.create_view(&wgpu::TextureViewDescriptor { format: Some(format), @@ -443,10 +388,10 @@ impl crate::framework::Example for Example { queue: &wgpu::Queue, ) -> Self { let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { - label: None, source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!( "shader.wgsl" ))), + .. }); // Renderer that draws to 2 textures at the same time: let multi_target_renderer = MultiTargetRenderer::init( @@ -458,13 +403,11 @@ impl crate::framework::Example for Example { &[ Some(wgpu::ColorTargetState { format: config.view_formats[0], - blend: None, - write_mask: Default::default(), + .. }), Some(wgpu::ColorTargetState { format: config.view_formats[0], - blend: None, - write_mask: Default::default(), + .. }), ], ); @@ -511,15 +454,13 @@ impl crate::framework::Example for Example { &[ Some(wgpu::RenderPassColorAttachment { view: &self.texture_targets.red_view, - depth_slice: None, - resolve_target: None, ops: Default::default(), + .. }), Some(wgpu::RenderPassColorAttachment { view: &self.texture_targets.green_view, - depth_slice: None, - resolve_target: None, ops: Default::default(), + .. }), ], ); @@ -543,9 +484,8 @@ pub static TEST: crate::framework::ExampleTestParams = crate::framework::Example image_path: "/examples/features/src/multiple_render_targets/screenshot.png", width: 1024, height: 768, - optional_features: wgpu::Features::default(), - base_test_parameters: wgpu_test::TestParameters::default(), // Bounded by lavapipe comparisons: &[wgpu_test::ComparisonType::Mean(0.014)], // Bounded by Apple A9 _phantom: std::marker::PhantomData::, + .. }; diff --git a/examples/features/src/ray_cube_fragment/mod.rs b/examples/features/src/ray_cube_fragment/mod.rs index eb72b85846b..3ea671ce36d 100644 --- a/examples/features/src/ray_cube_fragment/mod.rs +++ b/examples/features/src/ray_cube_fragment/mod.rs @@ -91,7 +91,7 @@ impl crate::framework::Example for Example { fn required_downlevel_capabilities() -> wgpu::DownlevelCapabilities { wgpu::DownlevelCapabilities { flags: wgpu::DownlevelFlags::COMPUTE_SHADERS, - ..Default::default() + .. } } @@ -174,28 +174,18 @@ impl crate::framework::Example for Example { }); 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: &[], + .. }, fragment: Some(wgpu::FragmentState { module: &shader, entry_point: Some("fs_main"), - compilation_options: Default::default(), targets: &[Some(config.format.into())], + .. }), - primitive: wgpu::PrimitiveState { - topology: wgpu::PrimitiveTopology::TriangleList, - ..Default::default() - }, - depth_stencil: None, - multisample: wgpu::MultisampleState::default(), - multiview_mask: None, - cache: None, + .. }); let bind_group_layout = pipeline.get_bind_group_layout(0); @@ -318,20 +308,15 @@ impl crate::framework::Example for Example { { let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, color_attachments: &[Some(wgpu::RenderPassColorAttachment { view, - depth_slice: None, - resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::GREEN), store: wgpu::StoreOp::Store, }, + .. })], - depth_stencil_attachment: None, - timestamp_writes: None, - occlusion_query_set: None, - multiview_mask: None, + .. }); rpass.set_pipeline(&self.pipeline); diff --git a/examples/features/src/texture_arrays/mod.rs b/examples/features/src/texture_arrays/mod.rs index 082b09e7af9..59c546a39a2 100644 --- a/examples/features/src/texture_arrays/mod.rs +++ b/examples/features/src/texture_arrays/mod.rs @@ -328,7 +328,7 @@ impl crate::framework::Example for Example { let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { label: Some("main"), bind_group_layouts: &[Some(&bind_group_layout), Some(&uniform_bind_group_layout)], - immediate_size: 0, + .. }); let index_format = wgpu::IndexFormat::Uint16; diff --git a/examples/features/src/timestamp_queries/mod.rs b/examples/features/src/timestamp_queries/mod.rs index 38fffd8894f..cdd3f72bc94 100644 --- a/examples/features/src/timestamp_queries/mod.rs +++ b/examples/features/src/timestamp_queries/mod.rs @@ -127,13 +127,13 @@ impl Queries { label: Some("query resolve buffer"), size: size_of::() as u64 * num_queries, usage: wgpu::BufferUsages::COPY_SRC | wgpu::BufferUsages::QUERY_RESOLVE, - mapped_at_creation: false, + .. }), destination_buffer: device.create_buffer(&wgpu::BufferDescriptor { label: Some("query dest buffer"), size: size_of::() as u64 * num_queries, usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ, - mapped_at_creation: false, + .. }), num_queries, next_unused_query: 0, @@ -225,9 +225,8 @@ async fn run() { label: None, required_features: features, required_limits: wgpu::Limits::downlevel_defaults(), - experimental_features: wgpu::ExperimentalFeatures::disabled(), memory_hints: wgpu::MemoryHints::MemoryUsage, - trace: wgpu::Trace::Off, + .. }) .await .unwrap(); @@ -242,8 +241,7 @@ fn submit_render_and_compute_pass_with_queries( device: &wgpu::Device, queue: &wgpu::Queue, ) -> Queries { - let mut encoder = - device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); let mut queries = Queries::new(device, QueryResults::NUM_QUERIES); let shader = device.create_shader_module(wgpu::include_wgsl!("shader.wgsl")); @@ -310,21 +308,21 @@ fn compute_pass( }); let bind_group_layout = compute_pipeline.get_bind_group_layout(0); let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { - label: None, layout: &bind_group_layout, entries: &[wgpu::BindGroupEntry { binding: 0, resource: storage_buffer.as_entire_binding(), }], + .. }); let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { - label: None, timestamp_writes: Some(wgpu::ComputePassTimestampWrites { query_set, beginning_of_pass_write_index: Some(*next_unused_query), end_of_pass_write_index: Some(*next_unused_query + 1), }), + .. }); *next_unused_query += 2; cpass.set_pipeline(&compute_pipeline); @@ -349,68 +347,52 @@ fn render_pass( ) { let format = wgpu::TextureFormat::Rgba8Unorm; - let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, - bind_group_layouts: &[], - immediate_size: 0, - }); + let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor::default()); 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: &[], + .. }, fragment: Some(wgpu::FragmentState { module, entry_point: Some("fs_main"), - compilation_options: Default::default(), targets: &[Some(format.into())], + .. }), - primitive: wgpu::PrimitiveState::default(), - depth_stencil: None, - multisample: wgpu::MultisampleState::default(), - multiview_mask: 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_view = render_target.create_view(&wgpu::TextureViewDescriptor::default()); let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { - label: None, color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: &render_target_view, - depth_slice: None, - resolve_target: None, ops: wgpu::Operations { load: wgpu::LoadOp::Clear(wgpu::Color::GREEN), store: wgpu::StoreOp::Store, }, + .. })], - depth_stencil_attachment: None, timestamp_writes: Some(wgpu::RenderPassTimestampWrites { query_set, beginning_of_pass_write_index: Some(*next_unused_query), end_of_pass_write_index: Some(*next_unused_query + 1), }), - occlusion_query_set: None, - multiview_mask: None, + .. }); *next_unused_query += 2; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 70e56b6ba4e..1b1882e1569 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.93" +channel = "nightly-2026-03-11" components = ["cargo", "rustfmt", "clippy"] targets = ["wasm32-unknown-unknown"] diff --git a/tests/src/params.rs b/tests/src/params.rs index d7339225cb0..54d4a30988c 100644 --- a/tests/src/params.rs +++ b/tests/src/params.rs @@ -15,37 +15,29 @@ const LOWEST_DOWNLEVEL_PROPERTIES: wgpu::DownlevelCapabilities = DownlevelCapabi /// This information determines if a test should run. #[derive(Clone)] pub struct TestParameters { - pub required_features: Features, - pub required_downlevel_caps: DownlevelCapabilities, - pub required_limits: Limits, + pub required_features: Features = Features::empty(), + pub required_downlevel_caps: DownlevelCapabilities = LOWEST_DOWNLEVEL_PROPERTIES, + pub required_limits: Limits = Limits::downlevel_webgl2_defaults(), - pub required_instance_flags: InstanceFlags, + pub required_instance_flags: InstanceFlags = InstanceFlags::empty(), /// On Dx12, specifically test against the Fxc compiler. /// /// For testing workarounds to Fxc bugs. - pub force_fxc: bool, + pub force_fxc: bool = false, /// Conditions under which this test should be skipped. - pub skips: Vec, + // By default we skip the noop backend, and enable it if the test + // parameters ask us to remove it. + pub skips: Vec = vec![FailureCase::backend(wgpu::Backends::NOOP)], /// Conditions under which this test should be run, but is expected to fail. - pub failures: Vec, + pub failures: Vec = Vec::new(), } impl Default for TestParameters { fn default() -> Self { - Self { - required_features: Features::empty(), - required_downlevel_caps: LOWEST_DOWNLEVEL_PROPERTIES, - required_limits: Limits::downlevel_webgl2_defaults(), - required_instance_flags: InstanceFlags::empty(), - force_fxc: false, - // By default we skip the noop backend, and enable it if the test - // parameters ask us to remove it. - skips: vec![FailureCase::backend(wgpu::Backends::NOOP)], - failures: Vec::new(), - } + Self { .. } } } diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index cc01e0840ee..1c08f1b8d07 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -1,3 +1,5 @@ +#![feature(default_field_values)] + //! This library safely implements WebGPU on native platforms. //! It is designed for integration into browsers, as well as wrapping //! into other language-specific user-friendly libraries. diff --git a/wgpu-types/src/binding.rs b/wgpu-types/src/binding.rs index db7a15b3b7f..aa64937adf0 100644 --- a/wgpu-types/src/binding.rs +++ b/wgpu-types/src/binding.rs @@ -29,7 +29,7 @@ pub enum BindingType { /// https://gpuweb.github.io/gpuweb/#dictdef-gpubufferbindinglayout). Buffer { /// Sub-type of the buffer binding. - ty: BufferBindingType, + ty: BufferBindingType = BufferBindingType::Uniform, /// Indicates that the binding has a dynamic offset. /// @@ -38,7 +38,7 @@ pub enum BindingType { /// #[doc = link_to_wgpu_docs!(["RPsbg"]: "struct.RenderPass.html#method.set_bind_group")] #[cfg_attr(feature = "serde", serde(default))] - has_dynamic_offset: bool, + has_dynamic_offset: bool = false, /// The minimum size for a [`BufferBinding`] matching this entry, in bytes. /// @@ -66,7 +66,7 @@ pub enum BindingType { #[doc = link_to_wgpu_docs!(["`create_render_pipeline`"]: "struct.Device.html#method.create_render_pipeline")] #[doc = link_to_wgpu_docs!(["`create_compute_pipeline`"]: "struct.Device.html#method.create_compute_pipeline")] #[cfg_attr(feature = "serde", serde(default))] - min_binding_size: Option, + min_binding_size: Option = None, }, /// A sampler that can be used to sample a texture. /// @@ -84,6 +84,7 @@ pub enum BindingType { /// /// Corresponds to [WebGPU `GPUSamplerBindingLayout`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpusamplerbindinglayout). + // TODO: make optional to specify Sampler(SamplerBindingType), /// A texture binding. /// @@ -103,13 +104,13 @@ pub enum BindingType { /// https://gpuweb.github.io/gpuweb/#dictdef-gputexturebindinglayout). Texture { /// Sample type of the texture binding. - sample_type: crate::TextureSampleType, + sample_type: crate::TextureSampleType = crate::TextureSampleType::Float { filterable: true }, /// Dimension of the texture view that is going to be sampled. - view_dimension: crate::TextureViewDimension, + view_dimension: crate::TextureViewDimension = crate::TextureViewDimension::D2, /// True if the texture has a sample count greater than 1. If this is true, /// the texture must be declared as `texture_multisampled_2d` or /// `texture_depth_multisampled_2d` in the shader, and read using `textureLoad`. - multisampled: bool, + multisampled: bool = false, }, /// A storage texture. /// @@ -131,11 +132,11 @@ pub enum BindingType { /// https://gpuweb.github.io/gpuweb/#dictdef-gpustoragetexturebindinglayout). StorageTexture { /// Allowed access to this texture. - access: crate::StorageTextureAccess, + access: crate::StorageTextureAccess = crate::StorageTextureAccess::WriteOnly, /// Format of the texture. format: crate::TextureFormat, /// Dimension of the texture view that is going to be sampled. - view_dimension: crate::TextureViewDimension, + view_dimension: crate::TextureViewDimension = crate::TextureViewDimension::D2, }, /// A ray-tracing acceleration structure binding. @@ -162,7 +163,7 @@ pub enum BindingType { /// create a ray query that has flag vertex return in the shader /// /// If enabled requires [`Features::EXPERIMENTAL_RAY_HIT_VERTEX_RETURN`] - vertex_return: bool, + vertex_return: bool = false, }, /// An external texture binding. @@ -304,12 +305,13 @@ pub enum BufferBindingType { /// Corresponds to [WebGPU `GPUSamplerBindingType`]( /// https://gpuweb.github.io/gpuweb/#enumdef-gpusamplerbindingtype). #[repr(C)] -#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))] pub enum SamplerBindingType { /// The sampling result is produced based on more than a single color sample from a texture, /// e.g. when bilinear interpolation is enabled. + #[default] Filtering, /// The sampling result is produced based on a single color sample from a texture. NonFiltering, @@ -346,5 +348,5 @@ pub struct BindGroupLayoutEntry { /// - If [`Features::PARTIALLY_BOUND_BINDING_ARRAY`] is enabled, the specified count becomes the upper bound instead. /// #[cfg_attr(feature = "serde", serde(default))] - pub count: Option, + pub count: Option = None, } diff --git a/wgpu-types/src/buffer.rs b/wgpu-types/src/buffer.rs index 46d4c044c0e..a27bd5c626f 100644 --- a/wgpu-types/src/buffer.rs +++ b/wgpu-types/src/buffer.rs @@ -13,6 +13,7 @@ use crate::{DownlevelFlags, COPY_BUFFER_ALIGNMENT}; #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct BufferDescriptor { /// Debug label of a buffer. This will show up in graphics debuggers for easy identification. + // TODO: make optional to specify pub label: L, /// Size of a buffer, in bytes. pub size: crate::BufferAddress, @@ -28,7 +29,7 @@ pub struct BufferDescriptor { /// /// If this is `true`, [`size`](#structfield.size) must be a multiple of /// [`COPY_BUFFER_ALIGNMENT`]. - pub mapped_at_creation: bool, + pub mapped_at_creation: bool = false, } impl BufferDescriptor { diff --git a/wgpu-types/src/device.rs b/wgpu-types/src/device.rs index fe6c6fbd138..304cdbf2b51 100644 --- a/wgpu-types/src/device.rs +++ b/wgpu-types/src/device.rs @@ -11,27 +11,28 @@ use serde::{Deserialize, Serialize}; #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct DeviceDescriptor { /// Debug label for the device. + // TODO: make optional to specify pub label: L, /// Specifies the features that are required by the device request. /// The request will fail if the adapter cannot provide these features. /// /// Exactly the specified set of features, and no more or less, /// will be allowed in validation of API calls on the resulting device. - pub required_features: crate::Features, + pub required_features: crate::Features = crate::Features::empty(), /// Specifies the limits that are required by the device request. /// The request will fail if the adapter cannot provide these limits. /// /// Exactly the specified limits, and no better or worse, /// will be allowed in validation of API calls on the resulting device. - pub required_limits: crate::Limits, + pub required_limits: crate::Limits = crate::Limits::defaults(), /// Specifies whether `self.required_features` is allowed to contain experimental features. #[cfg_attr(feature = "serde", serde(skip))] - pub experimental_features: crate::ExperimentalFeatures, + pub experimental_features: crate::ExperimentalFeatures = crate::ExperimentalFeatures::disabled(), /// Hints for memory allocation strategies. - pub memory_hints: MemoryHints, + pub memory_hints: MemoryHints = MemoryHints::Performance, /// Whether API tracing for debugging is enabled, /// and where the trace is written if so. - pub trace: Trace, + pub trace: Trace = Trace::Off, } impl DeviceDescriptor { diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 7ea28ee1f44..e029b702ddc 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -1,6 +1,7 @@ //! This library describes the API surface of WebGPU that is agnostic of the backend. //! This API is used for targeting both Web and Native. +#![feature(default_field_values)] #![cfg_attr(docsrs, feature(doc_cfg))] #![allow( // We don't use syntax sugar where it's not necessary. @@ -466,6 +467,7 @@ impl CommandBufferDescriptor { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct QuerySetDescriptor { /// Debug label for the query set. + // TODO: make optional to specify pub label: L, /// Kind of query that this query set should contain. pub ty: QueryType, diff --git a/wgpu-types/src/limits.rs b/wgpu-types/src/limits.rs index 174bfd8b476..cc58f697b9a 100644 --- a/wgpu-types/src/limits.rs +++ b/wgpu-types/src/limits.rs @@ -776,37 +776,20 @@ impl Limits { /// Represents the sets of additional limits on an adapter, /// which take place when running on downlevel backends. -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct DownlevelLimits {} -#[allow(clippy::derivable_impls)] -impl Default for DownlevelLimits { - fn default() -> Self { - DownlevelLimits {} - } -} - /// Lists various ways the underlying platform does not conform to the WebGPU standard. -#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct DownlevelCapabilities { /// Combined boolean flags. - pub flags: DownlevelFlags, + pub flags: DownlevelFlags = DownlevelFlags::all(), /// Additional limits - pub limits: DownlevelLimits, + pub limits: DownlevelLimits = DownlevelLimits {}, /// Which collections of features shaders support. Defined in terms of D3D's shader models. - pub shader_model: ShaderModel, -} - -impl Default for DownlevelCapabilities { - fn default() -> Self { - Self { - flags: DownlevelFlags::all(), - limits: DownlevelLimits::default(), - shader_model: ShaderModel::Sm5, - } - } + pub shader_model: ShaderModel = ShaderModel::Sm5, } impl DownlevelCapabilities { diff --git a/wgpu-types/src/origin_extent.rs b/wgpu-types/src/origin_extent.rs index 5f871c3ab70..eec40324b61 100644 --- a/wgpu-types/src/origin_extent.rs +++ b/wgpu-types/src/origin_extent.rs @@ -13,14 +13,14 @@ use crate::TextureDimension; #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct Origin2d { #[allow(missing_docs)] - pub x: u32, + pub x: u32 = 0, #[allow(missing_docs)] - pub y: u32, + pub y: u32 = 0, } impl Origin2d { /// Zero origin. - pub const ZERO: Self = Self { x: 0, y: 0 }; + pub const ZERO: Self = Self { .. }; /// Adds the third dimension to this origin #[must_use] @@ -49,16 +49,16 @@ impl core::fmt::Debug for Origin2d { #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct Origin3d { /// X position of the origin - pub x: u32, + pub x: u32 = 0, /// Y position of the origin - pub y: u32, + pub y: u32 = 0, /// Z position of the origin - pub z: u32, + pub z: u32 = 0, } impl Origin3d { /// Zero origin. - pub const ZERO: Self = Self { x: 0, y: 0, z: 0 }; + pub const ZERO: Self = Self { .. }; /// Removes the third dimension from this origin #[must_use] @@ -94,10 +94,11 @@ pub struct Extent3d { /// Width of the extent pub width: u32, /// Height of the extent - pub height: u32, + #[cfg_attr(feature = "serde", serde(default = "default_depth"))] + pub height: u32 = 1, /// The depth of the extent or the number of array layers #[cfg_attr(feature = "serde", serde(default = "default_depth"))] - pub depth_or_array_layers: u32, + pub depth_or_array_layers: u32 = 1, } impl core::fmt::Debug for Extent3d { @@ -113,11 +114,7 @@ fn default_depth() -> u32 { impl Default for Extent3d { fn default() -> Self { - Self { - width: 1, - height: 1, - depth_or_array_layers: 1, - } + Self { width: 1, .. } } } diff --git a/wgpu-types/src/ray_tracing.rs b/wgpu-types/src/ray_tracing.rs index 82d7fe6d207..3b2d989d95c 100644 --- a/wgpu-types/src/ray_tracing.rs +++ b/wgpu-types/src/ray_tracing.rs @@ -57,6 +57,7 @@ pub enum AccelerationStructureUpdateMode { /// Descriptor for creating a bottom level acceleration structure. pub struct CreateBlasDescriptor { /// Label for the bottom level acceleration structure. + // TODO: make optional to specify pub label: L, /// Flags for the bottom level acceleration structure. pub flags: AccelerationStructureFlags, diff --git a/wgpu-types/src/render.rs b/wgpu-types/src/render.rs index 9256ea7cc24..691f3600229 100644 --- a/wgpu-types/src/render.rs +++ b/wgpu-types/src/render.rs @@ -106,26 +106,22 @@ pub enum BlendOperation { /// Corresponds to [WebGPU `GPUBlendComponent`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpublendcomponent). #[repr(C)] -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, Debug, Default, 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. - pub src_factor: BlendFactor, + pub src_factor: BlendFactor = BlendFactor::One, /// Multiplier for the destination, which is stored in the target. - pub dst_factor: BlendFactor, + pub dst_factor: BlendFactor = BlendFactor::Zero, /// The binary operation applied to the source and destination, /// multiplied by their respective factors. - pub operation: BlendOperation, + pub operation: BlendOperation = BlendOperation::Add, } impl BlendComponent { /// Default blending state that replaces destination with the source. - pub const REPLACE: Self = Self { - src_factor: BlendFactor::One, - dst_factor: BlendFactor::Zero, - operation: BlendOperation::Add, - }; + pub const REPLACE: Self = Self { .. }; /// Blend state of `(1 * src) + ((1 - src_alpha) * dst)`. pub const OVER: Self = Self { @@ -148,12 +144,6 @@ impl BlendComponent { } } -impl Default for BlendComponent { - fn default() -> Self { - Self::REPLACE - } -} - /// Describe the blend state of a render pipeline, /// within [`ColorTargetState`]. /// @@ -210,10 +200,10 @@ pub struct ColorTargetState { pub format: crate::TextureFormat, /// The blending that is used for this pipeline. #[cfg_attr(feature = "serde", serde(default))] - pub blend: Option, + pub blend: Option = None, /// Mask which enables/disables writes to different color/alpha channel. #[cfg_attr(feature = "serde", serde(default))] - pub write_mask: ColorWrites, + pub write_mask: ColorWrites = ColorWrites::all(), } impl From for ColorTargetState { @@ -370,7 +360,7 @@ pub enum PolygonMode { #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct PrimitiveState { /// The primitive topology used to interpret vertices. - pub topology: PrimitiveTopology, + pub topology: PrimitiveTopology = PrimitiveTopology::TriangleList, /// 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. /// @@ -378,30 +368,30 @@ pub struct PrimitiveState { /// in all backends and individual strips will be separated /// with the index value `0xFFFF` when using `Uint16`, or `0xFFFFFFFF` when using `Uint32`. #[cfg_attr(feature = "serde", serde(default))] - pub strip_index_format: Option, + pub strip_index_format: Option = None, /// The face to consider the front for the purpose of culling and stencil operations. #[cfg_attr(feature = "serde", serde(default))] - pub front_face: FrontFace, + pub front_face: FrontFace = FrontFace::Ccw, /// The face culling mode. #[cfg_attr(feature = "serde", serde(default))] - pub cull_mode: Option, + pub cull_mode: Option = None, /// If set to true, the polygon depth is not clipped to 0-1 before rasterization. /// /// Enabling this requires [`Features::DEPTH_CLIP_CONTROL`] to be enabled. #[cfg_attr(feature = "serde", serde(default))] - pub unclipped_depth: bool, + pub unclipped_depth: bool = false, /// Controls the way each polygon is rasterized. Can be either `Fill` (default), `Line` or `Point` /// /// Setting this to `Line` requires [`Features::POLYGON_MODE_LINE`] to be enabled. /// /// Setting this to `Point` requires [`Features::POLYGON_MODE_POINT`] to be enabled. #[cfg_attr(feature = "serde", serde(default))] - pub polygon_mode: PolygonMode, + pub polygon_mode: PolygonMode = PolygonMode::Fill, /// 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. - pub conservative: bool, + pub conservative: bool = false, } /// Describes the multi-sampling state of a render pipeline. @@ -409,33 +399,23 @@ pub struct PrimitiveState { /// Corresponds to [WebGPU `GPUMultisampleState`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpumultisamplestate). #[repr(C)] -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] pub struct MultisampleState { /// The number of samples calculated per pixel (for MSAA). For non-multisampled textures, /// this should be `1` - pub count: u32, + pub count: u32 = 1, /// Bitmask that restricts the samples of a pixel modified by this pipeline. All samples /// can be enabled using the value `!0` - pub mask: u64, + pub mask: u64 = !0, /// When enabled, produces another sample mask per pixel based on the alpha output value, that /// is ANDed with the sample mask and the primitive coverage to restrict the set of samples /// affected by a primitive. /// /// The implicit mask produced for alpha of zero is guaranteed to be zero, and for alpha of one /// is guaranteed to be all 1-s. - pub alpha_to_coverage_enabled: bool, -} - -impl Default for MultisampleState { - fn default() -> Self { - MultisampleState { - count: 1, - mask: !0, - alpha_to_coverage_enabled: false, - } - } + pub alpha_to_coverage_enabled: bool = false, } /// Format of indices used with pipeline. @@ -705,6 +685,7 @@ pub enum LoadOp { /// As a result, it is recommended to use "clear" rather than "load" in cases /// where the initial value doesn’t matter /// (e.g. the render target will be cleared using a skybox). + // TODO: make optional to specify, needs `Default` Clear(V) = 0, /// Loads the existing value for this attachment into the render pass. Load = 1, @@ -888,7 +869,7 @@ pub struct RenderBundleDepthStencil { /// If `depth_ops` is `Some(..)` this must be false. If it is `None` this must be true. /// #[doc = link_to_wgpu_docs!(["`RenderPassDepthStencilAttachment::depth_ops`"]: "struct.RenderPassDepthStencilAttachment.html#structfield.depth_ops")] - pub depth_read_only: bool, + pub depth_read_only: bool = false, /// If the stencil aspect of the depth stencil attachment is going to be written to. /// @@ -896,7 +877,7 @@ pub struct RenderBundleDepthStencil { /// If `depth_ops` is `Some(..)` this must be false. If it is `None` this must be true. /// #[doc = link_to_wgpu_docs!(["`RenderPassDepthStencilAttachment::stencil_ops`"]: "struct.RenderPassDepthStencilAttachment.html#structfield.stencil_ops")] - pub stencil_read_only: bool, + pub stencil_read_only: bool = false, } /// Describes a [`RenderBundle`](../wgpu/struct.RenderBundle.html). diff --git a/wgpu-types/src/surface.rs b/wgpu-types/src/surface.rs index a0f56b43ace..0370ac34f95 100644 --- a/wgpu-types/src/surface.rs +++ b/wgpu-types/src/surface.rs @@ -228,9 +228,9 @@ pub struct SurfaceConfiguration { #[doc = link_to_wgpu_docs!(["`Surface::get_current_texture`"]: "struct.Surface.html#method.get_current_texture")] #[doc = link_to_wgpu_docs!(["`Surface::get_default_config`"]: "struct.Surface.html#method.get_default_config")] /// [SMFL]: https://learn.microsoft.com/en-us/windows/win32/api/dxgi1_3/nf-dxgi1_3-idxgiswapchain2-setmaximumframelatency - pub desired_maximum_frame_latency: u32, + pub desired_maximum_frame_latency: u32 = 2, /// Specifies how the alpha channel of the textures should be handled during compositing. - pub alpha_mode: CompositeAlphaMode, + pub alpha_mode: CompositeAlphaMode = CompositeAlphaMode::Auto, /// Specifies what view formats will be allowed when calling `Texture::create_view` on the texture returned by `Surface::get_current_texture`. /// /// View formats of the same format as the texture are always allowed. diff --git a/wgpu-types/src/texture.rs b/wgpu-types/src/texture.rs index c9440c0619f..d2815c584f9 100644 --- a/wgpu-types/src/texture.rs +++ b/wgpu-types/src/texture.rs @@ -449,30 +449,31 @@ pub enum StorageTextureAccess { #[derive(Clone, Debug, Default, Eq, PartialEq)] pub struct TextureViewDescriptor { /// Debug label of the texture view. This will show up in graphics debuggers for easy identification. + // TODO: make optional to specify pub label: L, /// Format of the texture view. Either must be the same as the texture format or in the list /// of `view_formats` in the texture's descriptor. - pub format: Option, + pub format: Option = None, /// The dimension of the texture view. For 1D textures, this must be `D1`. For 2D textures it must be one of /// `D2`, `D2Array`, `Cube`, and `CubeArray`. For 3D textures it must be `D3` - pub dimension: Option, + pub dimension: Option = None, /// The allowed usage(s) for the texture view. Must be a subset of the usage flags of the texture. /// If not provided, defaults to the full set of usage flags of the texture. - pub usage: Option, + pub usage: Option = None, /// Aspect of the texture. Color textures must be [`TextureAspect::All`]. - pub aspect: TextureAspect, + pub aspect: TextureAspect = TextureAspect::All, /// Base mip level. - pub base_mip_level: u32, + pub base_mip_level: u32 = 0, /// Mip level count. /// If `Some(count)`, `base_mip_level + count` must be less or equal to underlying texture mip count. /// If `None`, considered to include the rest of the mipmap levels, but at least 1 in total. - pub mip_level_count: Option, + pub mip_level_count: Option = None, /// Base array layer. - pub base_array_layer: u32, + pub base_array_layer: u32 = 0, /// Layer count. /// If `Some(count)`, `base_array_layer + count` must be less or equal to the underlying array count. /// If `None`, considered to include the rest of the array layers, but at least 1 in total. - pub array_layer_count: Option, + pub array_layer_count: Option = None, } /// Describes a [`Texture`](../wgpu/struct.Texture.html). @@ -484,17 +485,18 @@ pub struct TextureViewDescriptor { #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct TextureDescriptor { /// Debug label of the texture. This will show up in graphics debuggers for easy identification. + // TODO: make optional to specify 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. - pub mip_level_count: u32, + pub mip_level_count: u32 = 1, /// Sample count of texture. If this is not 1, texture must have [`BindingType::Texture::multisampled`] set to true. - pub sample_count: u32, + pub sample_count: u32 = 1, /// Dimensions of the texture. - pub dimension: TextureDimension, + pub dimension: TextureDimension = TextureDimension::D2, /// Format of the texture. pub format: TextureFormat, /// Allowed usages of the texture. If used in other ways, the operation will panic. @@ -504,6 +506,7 @@ 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) + // TODO: make optional to specify pub view_formats: V, } @@ -641,44 +644,34 @@ pub struct SamplerDescriptor { /// Debug label of the sampler. This will show up in graphics debuggers for easy identification. pub label: L, /// How to deal with out of bounds accesses in the u (i.e. x) direction - pub address_mode_u: AddressMode, + pub address_mode_u: AddressMode = AddressMode::ClampToEdge, /// How to deal with out of bounds accesses in the v (i.e. y) direction - pub address_mode_v: AddressMode, + pub address_mode_v: AddressMode = AddressMode::ClampToEdge, /// How to deal with out of bounds accesses in the w (i.e. z) direction - pub address_mode_w: AddressMode, + pub address_mode_w: AddressMode = AddressMode::ClampToEdge, /// How to filter the texture when it needs to be magnified (made larger) - pub mag_filter: FilterMode, + pub mag_filter: FilterMode = FilterMode::Nearest, /// How to filter the texture when it needs to be minified (made smaller) - pub min_filter: FilterMode, + pub min_filter: FilterMode = FilterMode::Nearest, /// How to filter between mip map levels - pub mipmap_filter: MipmapFilterMode, + pub mipmap_filter: MipmapFilterMode = MipmapFilterMode::Nearest, /// Minimum level of detail (i.e. mip level) to use - pub lod_min_clamp: f32, + pub lod_min_clamp: f32 = 0.0, /// Maximum level of detail (i.e. mip level) to use - pub lod_max_clamp: f32, + pub lod_max_clamp: f32 = 32.0, /// If this is enabled, this is a comparison sampler using the given comparison function. - pub compare: Option, + pub compare: Option = None, /// Must be at least 1. If this is not 1, all filter modes must be linear. - pub anisotropy_clamp: u16, + pub anisotropy_clamp: u16 = 1, /// Border color to use when `address_mode` is [`AddressMode::ClampToBorder`] - pub border_color: Option, + pub border_color: Option = None, } impl Default for SamplerDescriptor { fn default() -> Self { Self { label: Default::default(), - address_mode_u: Default::default(), - address_mode_v: Default::default(), - address_mode_w: Default::default(), - mag_filter: Default::default(), - min_filter: Default::default(), - mipmap_filter: Default::default(), - lod_min_clamp: 0.0, - lod_max_clamp: 32.0, - compare: None, - anisotropy_clamp: 1, - border_color: None, + .. } } } @@ -795,7 +788,7 @@ pub enum SamplerBorderColor { pub struct TexelCopyBufferLayout { /// Offset into the buffer that is the start of the texture. Must be a multiple of texture block size. /// For non-compressed textures, this is 1. - pub offset: crate::BufferAddress, + pub offset: crate::BufferAddress = 0, /// Bytes per "row" in an image. /// /// A row is one row of pixels or of compressed blocks in the x direction. @@ -814,7 +807,7 @@ pub struct TexelCopyBufferLayout { #[doc = link_to_wgpu_docs!(["CEcbtt"]: "struct.CommandEncoder.html#method.copy_buffer_to_texture")] #[doc = link_to_wgpu_docs!(["CEcttb"]: "struct.CommandEncoder.html#method.copy_texture_to_buffer")] #[doc = link_to_wgpu_docs!(["Qwt"]: "struct.Queue.html#method.write_texture")] - pub bytes_per_row: Option, + pub bytes_per_row: Option = None, /// "Rows" that make up a single "image". /// /// A row is one row of pixels or of compressed blocks in the x direction. @@ -824,7 +817,7 @@ pub struct TexelCopyBufferLayout { /// The amount of rows per image may be larger than the actual amount of rows of data. /// /// Required if there are multiple images (i.e. the depth is more than one). - pub rows_per_image: Option, + pub rows_per_image: Option = None, } /// View of a buffer which can be used to copy to/from a texture. @@ -838,7 +831,7 @@ pub struct TexelCopyBufferInfo { /// The buffer to be copied to/from. pub buffer: B, /// The layout of the texture data in this buffer. - pub layout: TexelCopyBufferLayout, + pub layout: TexelCopyBufferLayout = TexelCopyBufferLayout { .. }, } /// View of a texture which can be used to copy to/from a buffer/texture. @@ -852,15 +845,15 @@ pub struct TexelCopyTextureInfo { /// The texture to be copied to/from. pub texture: T, /// The target mip level of the texture. - pub mip_level: u32, + pub mip_level: u32 = 0, /// The base texel of the texture in the selected `mip_level`. Together /// with the `copy_size` argument to copy functions, defines the /// sub-region of the texture to copy. #[cfg_attr(feature = "serde", serde(default))] - pub origin: Origin3d, + pub origin: Origin3d = Origin3d { .. }, /// The copy aspect. #[cfg_attr(feature = "serde", serde(default))] - pub aspect: TextureAspect, + pub aspect: TextureAspect = TextureAspect::All, } impl TexelCopyTextureInfo { diff --git a/wgpu-types/src/tokens.rs b/wgpu-types/src/tokens.rs index 9102d40b60f..19a6b718b97 100644 --- a/wgpu-types/src/tokens.rs +++ b/wgpu-types/src/tokens.rs @@ -3,7 +3,7 @@ use crate::link_to_wgpu_item; /// Token of the user agreeing to access experimental features. #[derive(Debug, Default, Copy, Clone)] pub struct ExperimentalFeatures { - enabled: bool, + enabled: bool = false, } impl ExperimentalFeatures { diff --git a/wgpu/src/api/bind_group.rs b/wgpu/src/api/bind_group.rs index 93e9a8f1bb6..63720082dd5 100644 --- a/wgpu/src/api/bind_group.rs +++ b/wgpu/src/api/bind_group.rs @@ -157,7 +157,7 @@ static_assertions::assert_impl_all!(BindGroupEntry<'_>: Send, Sync); #[derive(Clone, Debug)] pub struct BindGroupDescriptor<'a> { /// Debug label of the bind group. This will show up in graphics debuggers for easy identification. - pub label: Label<'a>, + pub label: Label<'a> = None, /// The [`BindGroupLayout`] that corresponds to this bind group. pub layout: &'a BindGroupLayout, /// The resources to bind to this bind group. diff --git a/wgpu/src/api/bind_group_layout.rs b/wgpu/src/api/bind_group_layout.rs index 62eb7dd4147..c10b59b4e4f 100644 --- a/wgpu/src/api/bind_group_layout.rs +++ b/wgpu/src/api/bind_group_layout.rs @@ -37,7 +37,7 @@ impl BindGroupLayout { #[derive(Clone, Debug)] pub struct BindGroupLayoutDescriptor<'a> { /// Debug label of the bind group layout. This will show up in graphics debuggers for easy identification. - pub label: Label<'a>, + pub label: Label<'a> = None, /// Array of entries in this BindGroupLayout pub entries: &'a [BindGroupLayoutEntry], diff --git a/wgpu/src/api/common_pipeline.rs b/wgpu/src/api/common_pipeline.rs index 79ac7121eca..6e0c8304a0d 100644 --- a/wgpu/src/api/common_pipeline.rs +++ b/wgpu/src/api/common_pipeline.rs @@ -1,6 +1,6 @@ use crate::*; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] /// Advanced options for use when a pipeline is compiled /// /// This implements `Default`, and for most users can be set to `Default::default()` @@ -14,21 +14,12 @@ pub struct PipelineCompilationOptions<'a> { /// If the given constant is specified more than once, the last value specified is used. /// /// The value may represent any of WGSL's concrete scalar types. - pub constants: &'a [(&'a str, f64)], + pub constants: &'a [(&'a str, f64)] = &[], /// Whether workgroup scoped memory will be initialized with zero values for this stage. /// /// This is required by the WebGPU spec, but may have overhead which can be avoided /// for cross-platform applications - pub zero_initialize_workgroup_memory: bool, -} - -impl Default for PipelineCompilationOptions<'_> { - fn default() -> Self { - Self { - constants: Default::default(), - zero_initialize_workgroup_memory: true, - } - } + pub zero_initialize_workgroup_memory: bool = false, } /// Describes a pipeline cache, which allows reusing compilation work diff --git a/wgpu/src/api/compute_pass.rs b/wgpu/src/api/compute_pass.rs index cbd970be922..642dad7167d 100644 --- a/wgpu/src/api/compute_pass.rs +++ b/wgpu/src/api/compute_pass.rs @@ -172,9 +172,9 @@ pub struct ComputePassTimestampWrites<'a> { /// The query set to write to. pub query_set: &'a QuerySet, /// The index of the query set at which a start timestamp of this pass is written, if any. - pub beginning_of_pass_write_index: Option, + pub beginning_of_pass_write_index: Option = None, /// The index of the query set at which an end timestamp of this pass is written, if any. - pub end_of_pass_write_index: Option, + pub end_of_pass_write_index: Option = None, } #[cfg(send_sync)] static_assertions::assert_impl_all!(ComputePassTimestampWrites<'_>: Send, Sync); @@ -188,11 +188,11 @@ static_assertions::assert_impl_all!(ComputePassTimestampWrites<'_>: Send, Sync); #[derive(Clone, Default, Debug)] pub struct ComputePassDescriptor<'a> { /// Debug label of the compute pass. This will show up in graphics debuggers for easy identification. - pub label: Label<'a>, + pub label: Label<'a> = None, /// Defines which timestamp values will be written for this pass, and where to write them to. /// /// Requires [`Features::TIMESTAMP_QUERY`] to be enabled. - pub timestamp_writes: Option>, + pub timestamp_writes: Option> = None, } #[cfg(send_sync)] static_assertions::assert_impl_all!(ComputePassDescriptor<'_>: Send, Sync); diff --git a/wgpu/src/api/compute_pipeline.rs b/wgpu/src/api/compute_pipeline.rs index 499f967b540..51902eaf51e 100644 --- a/wgpu/src/api/compute_pipeline.rs +++ b/wgpu/src/api/compute_pipeline.rs @@ -44,7 +44,7 @@ impl ComputePipeline { #[derive(Clone, Debug)] pub struct ComputePipelineDescriptor<'a> { /// Debug label of the pipeline. This will show up in graphics debuggers for easy identification. - pub label: Label<'a>, + pub label: Label<'a> = None, /// The layout of bind groups for this pipeline. /// /// If this is set, then [`Device::create_compute_pipeline`] will raise a validation error if @@ -65,7 +65,7 @@ pub struct ComputePipelineDescriptor<'a> { /// cases. /// /// [default layout]: https://www.w3.org/TR/webgpu/#default-pipeline-layout - pub layout: Option<&'a PipelineLayout>, + pub layout: Option<&'a PipelineLayout> = None, /// The compiled shader module for this stage. pub module: &'a ShaderModule, /// The name of the entry point in the compiled shader to use. @@ -75,13 +75,13 @@ pub struct ComputePipelineDescriptor<'a> { /// selected. // NOTE: keep phrasing in sync. with `FragmentState::entry_point` // NOTE: keep phrasing in sync. with `VertexState::entry_point` - pub entry_point: Option<&'a str>, + pub entry_point: Option<&'a str> = None, /// Advanced options for when this pipeline is compiled /// /// This implements `Default`, and for most users can be set to `Default::default()` - pub compilation_options: PipelineCompilationOptions<'a>, + pub compilation_options: PipelineCompilationOptions<'a> = PipelineCompilationOptions { .. }, /// The pipeline cache to use when creating this pipeline. - pub cache: Option<&'a PipelineCache>, + pub cache: Option<&'a PipelineCache> = None, } #[cfg(send_sync)] static_assertions::assert_impl_all!(ComputePipelineDescriptor<'_>: Send, Sync); diff --git a/wgpu/src/api/pipeline_layout.rs b/wgpu/src/api/pipeline_layout.rs index 7705ea75aa8..c4d2521e074 100644 --- a/wgpu/src/api/pipeline_layout.rs +++ b/wgpu/src/api/pipeline_layout.rs @@ -32,7 +32,7 @@ impl PipelineLayout { #[derive(Clone, Debug, Default)] pub struct PipelineLayoutDescriptor<'a> { /// Debug label of the pipeline layout. This will show up in graphics debuggers for easy identification. - pub label: Label<'a>, + pub label: Label<'a> = None, /// 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. pub bind_group_layouts: &'a [Option<&'a BindGroupLayout>], @@ -41,7 +41,7 @@ pub struct PipelineLayoutDescriptor<'a> { /// this pipeline must be equal or smaller than this size. /// /// If this value is non-zero, [`Features::IMMEDIATES`] must be enabled. - pub immediate_size: u32, + pub immediate_size: u32 = 0, } #[cfg(send_sync)] static_assertions::assert_impl_all!(PipelineLayoutDescriptor<'_>: Send, Sync); diff --git a/wgpu/src/api/render_bundle_encoder.rs b/wgpu/src/api/render_bundle_encoder.rs index cea7aa330c5..b15d839d201 100644 --- a/wgpu/src/api/render_bundle_encoder.rs +++ b/wgpu/src/api/render_bundle_encoder.rs @@ -34,18 +34,18 @@ crate::cmp::impl_eq_ord_hash_proxy!(RenderBundleEncoder<'_> => .inner); #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] pub struct RenderBundleEncoderDescriptor<'a> { /// Debug label of the render bundle encoder. This will show up in graphics debuggers for easy identification. - pub label: Label<'a>, + pub label: Label<'a> = None, /// The formats of the color attachments that this render bundle is capable to rendering to. This /// must match the formats of the color attachments in the render pass this render bundle is executed in. pub color_formats: &'a [Option], /// Information about the depth attachment that this render bundle is capable to rendering to. This /// must match the format of the depth attachments in the render pass this render bundle is executed in. - pub depth_stencil: Option, + pub depth_stencil: Option = None, /// Sample count this render bundle is capable of rendering to. This must match the pipelines and /// the render passes it is used in. - pub sample_count: u32, + pub sample_count: u32 = 1, /// If this render bundle will rendering to multiple array layers in the attachments at the same time. - pub multiview: Option, + pub multiview: Option = None, } static_assertions::assert_impl_all!(RenderBundleEncoderDescriptor<'_>: Send, Sync); diff --git a/wgpu/src/api/render_pass.rs b/wgpu/src/api/render_pass.rs index 3bd24d2c5f1..23e84de4d2c 100644 --- a/wgpu/src/api/render_pass.rs +++ b/wgpu/src/api/render_pass.rs @@ -604,11 +604,11 @@ pub struct RenderPassColorAttachment<'tex> { /// The view to use as an attachment. pub view: &'tex TextureView, /// The depth slice index of a 3D view. It must not be provided if the view is not 3D. - pub depth_slice: Option, + pub depth_slice: Option = None, /// The view that will receive the resolved output if multisampling is used. /// /// If set, it is always written to, regardless of how [`Self::ops`] is configured. - pub resolve_target: Option<&'tex TextureView>, + pub resolve_target: Option<&'tex TextureView> = None, /// What operations will be performed on this color attachment. pub ops: Operations, } @@ -642,17 +642,17 @@ static_assertions::assert_impl_all!(RenderPassDepthStencilAttachment<'_>: Send, #[derive(Clone, Debug, Default)] pub struct RenderPassDescriptor<'a> { /// Debug label of the render pass. This will show up in graphics debuggers for easy identification. - pub label: Label<'a>, + pub label: Label<'a> = None, /// The color attachments of the render pass. pub color_attachments: &'a [Option>], /// The depth and stencil attachment of the render pass, if any. - pub depth_stencil_attachment: Option>, + pub depth_stencil_attachment: Option> = None, /// Defines which timestamp values will be written for this pass, and where to write them to. /// /// Requires [`Features::TIMESTAMP_QUERY`] to be enabled. - pub timestamp_writes: Option>, + pub timestamp_writes: Option> = None, /// Defines where the occlusion query results will be stored for this pass. - pub occlusion_query_set: Option<&'a QuerySet>, + pub occlusion_query_set: Option<&'a QuerySet> = None, /// The mask of multiview image layers to use for this render pass. For example, if you wish /// to render to the first 2 layers, you would use 3=0b11. If you wanted ro render to only the /// 2nd layer, you would use 2=0b10. If you aren't using multiview this should be `None`. @@ -661,7 +661,7 @@ pub struct RenderPassDescriptor<'a> { /// /// This doesn't influence load/store/clear/etc operations, as those are defined for attachments, /// therefore affecting all attachments. Meaning, this affects only any shaders executed on the `RenderPass`. - pub multiview_mask: Option, + pub multiview_mask: Option = None, } #[cfg(send_sync)] static_assertions::assert_impl_all!(RenderPassDescriptor<'_>: Send, Sync); diff --git a/wgpu/src/api/render_pipeline.rs b/wgpu/src/api/render_pipeline.rs index ebc89633b3b..8449478bd0b 100644 --- a/wgpu/src/api/render_pipeline.rs +++ b/wgpu/src/api/render_pipeline.rs @@ -79,7 +79,7 @@ pub struct VertexBufferLayout<'a> { /// This must be a multiple of [`VERTEX_ALIGNMENT`]. pub array_stride: BufferAddress, /// How often this vertex buffer is "stepped" forward. - pub step_mode: VertexStepMode, + pub step_mode: VertexStepMode = VertexStepMode::Vertex, /// The list of attributes which comprise a single vertex. pub attributes: &'a [VertexAttribute], } @@ -102,17 +102,17 @@ pub struct VertexState<'a> { /// selected. // NOTE: keep phrasing in sync. with `ComputePipelineDescriptor::entry_point` // NOTE: keep phrasing in sync. with `FragmentState::entry_point` - pub entry_point: Option<&'a str>, + pub entry_point: Option<&'a str> = None, /// Advanced options for when this pipeline is compiled /// /// This implements `Default`, and for most users can be set to `Default::default()` - pub compilation_options: PipelineCompilationOptions<'a>, + pub compilation_options: PipelineCompilationOptions<'a> = PipelineCompilationOptions { .. }, /// The format of any vertex buffers used with this pipeline via /// [`RenderPass::set_vertex_buffer()`]. /// /// The attribute locations and types specified in this layout must match the /// locations and types of the inputs to the `entry_point` function. - pub buffers: &'a [VertexBufferLayout<'a>], + pub buffers: &'a [VertexBufferLayout<'a>] = &[], } #[cfg(send_sync)] static_assertions::assert_impl_all!(VertexState<'_>: Send, Sync); @@ -134,11 +134,11 @@ pub struct FragmentState<'a> { /// selected. // NOTE: keep phrasing in sync. with `ComputePipelineDescriptor::entry_point` // NOTE: keep phrasing in sync. with `VertexState::entry_point` - pub entry_point: Option<&'a str>, + pub entry_point: Option<&'a str> = None, /// Advanced options for when this pipeline is compiled /// /// This implements `Default`, and for most users can be set to `Default::default()` - pub compilation_options: PipelineCompilationOptions<'a>, + pub compilation_options: PipelineCompilationOptions<'a> = PipelineCompilationOptions { .. }, /// The color state of the render targets. pub targets: &'a [Option], } @@ -198,7 +198,7 @@ static_assertions::assert_impl_all!(MeshState<'_>: Send, Sync); #[derive(Clone, Debug)] pub struct RenderPipelineDescriptor<'a> { /// Debug label of the pipeline. This will show up in graphics debuggers for easy identification. - pub label: Label<'a>, + pub label: Label<'a> = None, /// The layout of bind groups for this pipeline. /// /// If this is set, then [`Device::create_render_pipeline`] will raise a validation error if @@ -218,26 +218,26 @@ pub struct RenderPipelineDescriptor<'a> { /// convenient for simple pipelines, but using an explicit layout is recommended in most cases. /// /// [default layout]: https://www.w3.org/TR/webgpu/#default-pipeline-layout - pub layout: Option<&'a PipelineLayout>, + pub layout: Option<&'a PipelineLayout> = None, /// 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. - pub primitive: PrimitiveState, + pub primitive: PrimitiveState = PrimitiveState { .. }, /// The effect of draw calls on the depth and stencil aspects of the output target, if any. - pub depth_stencil: Option, + pub depth_stencil: Option = None, /// The multi-sampling properties of the pipeline. - pub multisample: MultisampleState, + pub multisample: MultisampleState = MultisampleState { .. }, /// The compiled fragment stage, its entry point, and the color targets. - pub fragment: Option>, + pub fragment: Option> = None, /// If the pipeline will be used with a multiview render pass, this indicates what multiview /// mask the render pass will be used with. The masks must match exactly. /// /// For example, if you wish to render to the first 2 layers, you would use 3=0b11. If you /// wanted to render to only the 2nd layer, you would use 2=0b10. If you aren't using /// multiview this should be `None`. - pub multiview_mask: Option, + pub multiview_mask: Option = None, /// The pipeline cache to use when creating this pipeline. - pub cache: Option<&'a PipelineCache>, + pub cache: Option<&'a PipelineCache> = None, } #[cfg(send_sync)] static_assertions::assert_impl_all!(RenderPipelineDescriptor<'_>: Send, Sync); diff --git a/wgpu/src/api/shader_module.rs b/wgpu/src/api/shader_module.rs index b2aad03ab02..e648d5fb525 100644 --- a/wgpu/src/api/shader_module.rs +++ b/wgpu/src/api/shader_module.rs @@ -222,7 +222,7 @@ static_assertions::assert_impl_all!(ShaderSource<'_>: Send, Sync); #[derive(Clone, Debug)] pub struct ShaderModuleDescriptor<'a> { /// Debug label of the shader module. This will show up in graphics debuggers for easy identification. - pub label: Label<'a>, + pub label: Label<'a> = None, /// Source code for the shader. pub source: ShaderSource<'a>, } diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 5279e884e91..d383eceaf47 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -72,6 +72,7 @@ //! - **`naga`** --- Enabled when target `glsl` or `spirv` input is enabled, or when `wgpu_core` is enabled. //! +#![feature(default_field_values)] #![no_std] #![cfg_attr(docsrs, feature(doc_cfg))] #![doc(html_logo_url = "https://raw.githubusercontent.com/gfx-rs/wgpu/trunk/logo.png")] diff --git a/wgpu/src/util/device.rs b/wgpu/src/util/device.rs index 540607b8162..3f2064bc566 100644 --- a/wgpu/src/util/device.rs +++ b/wgpu/src/util/device.rs @@ -6,7 +6,7 @@ use wgt::TextureDataOrder; #[derive(Clone, Debug, PartialEq, Eq, Hash)] pub struct BufferInitDescriptor<'a> { /// Debug label of a buffer. This will show up in graphics debuggers for easy identification. - pub label: crate::Label<'a>, + pub label: crate::Label<'a> = None, /// Contents of a buffer on creation. pub contents: &'a [u8], /// Usages of a buffer. If the buffer is used in any way that isn't specified here, the operation