Skip to content

Commit c218541

Browse files
WIP: feat: use default_field_values for entire API
TODO: go through the rest of the examples TODO: write a `CHANGELOG` entry
2 parents 1bfddec + eee121b commit c218541

34 files changed

Lines changed: 284 additions & 517 deletions

File tree

examples/features/src/big_compute_buffers/mod.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ pub async fn execute_gpu(numbers: &[f32]) -> Vec<f32> {
2727
required_features: Features::BUFFER_BINDING_ARRAY
2828
| Features::STORAGE_RESOURCE_BINDING_ARRAY
2929
| Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING,
30-
memory_hints: wgpu::MemoryHints::Performance,
3130
required_limits: wgpu::Limits {
3231
max_buffer_size: MAX_BUFFER_SIZE,
3332
max_binding_array_elements_per_shader_stage: 8,
3433
..Default::default()
3534
},
36-
..Default::default()
35+
..
3736
})
3837
.await
3938
.unwrap();
@@ -48,12 +47,11 @@ pub async fn execute_gpu_inner(
4847
) -> Vec<f32> {
4948
let (staging_buffers, storage_buffers, bind_group, compute_pipeline) = setup(device, numbers);
5049

51-
let mut encoder =
52-
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
50+
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());
5351
{
5452
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
5553
label: Some("compute pass descriptor"),
56-
timestamp_writes: None,
54+
..
5755
});
5856
cpass.set_pipeline(&compute_pipeline);
5957
cpass.set_bind_group(0, Some(&bind_group), &[]);
@@ -127,16 +125,15 @@ fn setup_pipeline(
127125
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
128126
label: Some("Compute Pipeline Layout"),
129127
bind_group_layouts: &[Some(&bind_group_layout)],
130-
immediate_size: 0,
128+
..
131129
});
132130

133131
device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
134132
label: Some("Compute Pipeline"),
135133
layout: Some(&pipeline_layout),
136134
module: &cs_module,
137135
entry_point: Some("main"),
138-
compilation_options: Default::default(),
139-
cache: None,
136+
..
140137
})
141138
}
142139

@@ -159,8 +156,8 @@ fn setup_binds(
159156
visibility: wgpu::ShaderStages::COMPUTE,
160157
ty: wgpu::BindingType::Buffer {
161158
ty: wgpu::BufferBindingType::Storage { read_only: false },
162-
has_dynamic_offset: false,
163159
min_binding_size: Some(NonZeroU64::new(4).unwrap()),
160+
..
164161
},
165162
count: Some(NonZeroU32::new(buffers.len() as u32).unwrap()),
166163
};
@@ -213,7 +210,7 @@ fn create_staging_buffers(device: &wgpu::Device, numbers: &[f32]) -> Vec<wgpu::B
213210
label: Some(&format!("staging buffer-{e}")),
214211
size,
215212
usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
216-
mapped_at_creation: false,
213+
..
217214
})
218215
})
219216
.collect()

examples/features/src/boids/mod.rs

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl crate::framework::Example for Example {
3131
fn required_downlevel_capabilities() -> wgpu::DownlevelCapabilities {
3232
wgpu::DownlevelCapabilities {
3333
flags: wgpu::DownlevelFlags::COMPUTE_SHADERS,
34-
..Default::default()
34+
..
3535
}
3636
}
3737

@@ -101,13 +101,13 @@ impl crate::framework::Example for Example {
101101
count: None,
102102
},
103103
],
104-
label: None,
104+
..
105105
});
106106
let compute_pipeline_layout =
107107
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
108108
label: Some("compute"),
109109
bind_group_layouts: &[Some(&compute_bind_group_layout)],
110-
immediate_size: 0,
110+
..
111111
});
112112

113113
// create render pipeline with empty bind group layout
@@ -116,16 +116,14 @@ impl crate::framework::Example for Example {
116116
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
117117
label: Some("render"),
118118
bind_group_layouts: &[],
119-
immediate_size: 0,
119+
..
120120
});
121121

122122
let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
123-
label: None,
124123
layout: Some(&render_pipeline_layout),
125124
vertex: wgpu::VertexState {
126125
module: &draw_shader,
127126
entry_point: Some("main_vs"),
128-
compilation_options: Default::default(),
129127
buffers: &[
130128
wgpu::VertexBufferLayout {
131129
array_stride: 4 * 4,
@@ -134,22 +132,19 @@ impl crate::framework::Example for Example {
134132
},
135133
wgpu::VertexBufferLayout {
136134
array_stride: 2 * 4,
137-
step_mode: wgpu::VertexStepMode::Vertex,
138135
attributes: &wgpu::vertex_attr_array![2 => Float32x2],
136+
..
139137
},
140138
],
139+
..
141140
},
142141
fragment: Some(wgpu::FragmentState {
143142
module: &draw_shader,
144143
entry_point: Some("main_fs"),
145-
compilation_options: Default::default(),
146144
targets: &[Some(config.view_formats[0].into())],
145+
..
147146
}),
148-
primitive: wgpu::PrimitiveState::default(),
149-
depth_stencil: None,
150-
multisample: wgpu::MultisampleState::default(),
151-
multiview_mask: None,
152-
cache: None,
147+
..
153148
});
154149

155150
// create compute pipeline
@@ -159,8 +154,7 @@ impl crate::framework::Example for Example {
159154
layout: Some(&compute_pipeline_layout),
160155
module: &compute_shader,
161156
entry_point: Some("main"),
162-
compilation_options: Default::default(),
163-
cache: None,
157+
..
164158
});
165159

166160
// buffer for the three 2d triangle vertices of each instance
@@ -221,7 +215,7 @@ impl crate::framework::Example for Example {
221215
resource: particle_buffers[(i + 1) % 2].as_entire_binding(), // bind to opposite buffer
222216
},
223217
],
224-
label: None,
218+
..
225219
}));
226220
}
227221

@@ -270,12 +264,8 @@ impl crate::framework::Example for Example {
270264
},
271265
})];
272266
let render_pass_descriptor = wgpu::RenderPassDescriptor {
273-
label: None,
274267
color_attachments: &color_attachments,
275-
depth_stencil_attachment: None,
276-
timestamp_writes: None,
277-
occlusion_query_set: None,
278-
multiview_mask: None,
268+
..
279269
};
280270

281271
// get command encoder
@@ -285,10 +275,7 @@ impl crate::framework::Example for Example {
285275
command_encoder.push_debug_group("compute boid movement");
286276
{
287277
// compute pass
288-
let mut cpass = command_encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
289-
label: None,
290-
timestamp_writes: None,
291-
});
278+
let mut cpass = command_encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { .. });
292279
cpass.set_pipeline(&self.compute_pipeline);
293280
cpass.set_bind_group(0, &self.particle_bind_groups[self.frame_num % 2], &[]);
294281
cpass.dispatch_workgroups(self.work_group_count, 1, 1);

examples/features/src/cube/mod.rs

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -131,34 +131,31 @@ impl crate::framework::Example for Example {
131131

132132
// Create pipeline layout
133133
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
134-
label: None,
135134
entries: &[
136135
wgpu::BindGroupLayoutEntry {
137136
binding: 0,
138137
visibility: wgpu::ShaderStages::VERTEX,
139138
ty: wgpu::BindingType::Buffer {
140-
ty: wgpu::BufferBindingType::Uniform,
141-
has_dynamic_offset: false,
142139
min_binding_size: wgpu::BufferSize::new(64),
140+
..
143141
},
144142
count: None,
145143
},
146144
wgpu::BindGroupLayoutEntry {
147145
binding: 1,
148146
visibility: wgpu::ShaderStages::FRAGMENT,
149147
ty: wgpu::BindingType::Texture {
150-
multisampled: false,
151148
sample_type: wgpu::TextureSampleType::Uint,
152-
view_dimension: wgpu::TextureViewDimension::D2,
149+
..
153150
},
154151
count: None,
155152
},
156153
],
154+
..
157155
});
158156
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
159-
label: None,
160157
bind_group_layouts: &[Some(&bind_group_layout)],
161-
immediate_size: 0,
158+
..
162159
});
163160

164161
// Create the texture
@@ -167,26 +164,23 @@ impl crate::framework::Example for Example {
167164
let texture_extent = wgpu::Extent3d {
168165
width: size,
169166
height: size,
170-
depth_or_array_layers: 1,
167+
..
171168
};
172169
let texture = device.create_texture(&wgpu::TextureDescriptor {
173170
label: None,
174171
size: texture_extent,
175-
mip_level_count: 1,
176-
sample_count: 1,
177-
dimension: wgpu::TextureDimension::D2,
178172
format: wgpu::TextureFormat::R8Uint,
179173
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
180174
view_formats: &[],
175+
..
181176
});
182177
let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default());
183178
queue.write_texture(
184179
texture.as_image_copy(),
185180
&texels,
186181
wgpu::TexelCopyBufferLayout {
187-
offset: 0,
188182
bytes_per_row: Some(size),
189-
rows_per_image: None,
183+
..
190184
},
191185
texture_extent,
192186
);
@@ -220,7 +214,6 @@ impl crate::framework::Example for Example {
220214

221215
let vertex_buffers = [wgpu::VertexBufferLayout {
222216
array_stride: vertex_size as wgpu::BufferAddress,
223-
step_mode: wgpu::VertexStepMode::Vertex,
224217
attributes: &[
225218
wgpu::VertexAttribute {
226219
format: wgpu::VertexFormat::Float32x4,
@@ -233,73 +226,65 @@ impl crate::framework::Example for Example {
233226
shader_location: 1,
234227
},
235228
],
229+
..
236230
}];
237231

238232
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
239-
label: None,
240233
layout: Some(&pipeline_layout),
241234
vertex: wgpu::VertexState {
242235
module: &shader,
243236
entry_point: Some("vs_main"),
244-
compilation_options: Default::default(),
245237
buffers: &vertex_buffers,
238+
..
246239
},
247240
fragment: Some(wgpu::FragmentState {
248241
module: &shader,
249242
entry_point: Some("fs_main"),
250-
compilation_options: Default::default(),
251243
targets: &[Some(config.view_formats[0].into())],
244+
..
252245
}),
253246
primitive: wgpu::PrimitiveState {
254247
cull_mode: Some(wgpu::Face::Back),
255-
..Default::default()
248+
..
256249
},
257-
depth_stencil: None,
258-
multisample: wgpu::MultisampleState::default(),
259-
multiview_mask: None,
260-
cache: None,
250+
..
261251
});
262252

263253
let pipeline_wire = if device
264254
.features()
265255
.contains(wgpu::Features::POLYGON_MODE_LINE)
266256
{
267257
let pipeline_wire = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
268-
label: None,
269258
layout: Some(&pipeline_layout),
270259
vertex: wgpu::VertexState {
271260
module: &shader,
272261
entry_point: Some("vs_main"),
273-
compilation_options: Default::default(),
274262
buffers: &vertex_buffers,
263+
..
275264
},
276265
fragment: Some(wgpu::FragmentState {
277266
module: &shader,
278267
entry_point: Some("fs_wire"),
279-
compilation_options: Default::default(),
280268
targets: &[Some(wgpu::ColorTargetState {
281269
format: config.view_formats[0],
282270
blend: Some(wgpu::BlendState {
283271
color: wgpu::BlendComponent {
284-
operation: wgpu::BlendOperation::Add,
285272
src_factor: wgpu::BlendFactor::SrcAlpha,
286273
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
274+
..
287275
},
288276
alpha: wgpu::BlendComponent::REPLACE,
289277
}),
290-
write_mask: wgpu::ColorWrites::ALL,
278+
..
291279
})],
280+
..
292281
}),
293282
primitive: wgpu::PrimitiveState {
294-
front_face: wgpu::FrontFace::Ccw,
295283
cull_mode: Some(wgpu::Face::Back),
296284
polygon_mode: wgpu::PolygonMode::Line,
297-
..Default::default()
285+
..
298286
},
299-
depth_stencil: None,
300-
multisample: wgpu::MultisampleState::default(),
301-
multiview_mask: None,
302-
cache: None,
287+
..
303288
});
304289
Some(pipeline_wire)
305290
} else {
@@ -338,11 +323,8 @@ impl crate::framework::Example for Example {
338323
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
339324
{
340325
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
341-
label: None,
342326
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
343327
view,
344-
depth_slice: None,
345-
resolve_target: None,
346328
ops: wgpu::Operations {
347329
load: wgpu::LoadOp::Clear(wgpu::Color {
348330
r: 0.1,
@@ -352,11 +334,9 @@ impl crate::framework::Example for Example {
352334
}),
353335
store: wgpu::StoreOp::Store,
354336
},
337+
..
355338
})],
356-
depth_stencil_attachment: None,
357-
timestamp_writes: None,
358-
occlusion_query_set: None,
359-
multiview_mask: None,
339+
..
360340
});
361341
rpass.push_debug_group("Prepare data for draw.");
362342
rpass.set_pipeline(&self.pipeline);

0 commit comments

Comments
 (0)