Upgrade wgpu to v30

This commit is contained in:
meehl committed 2026-08-11 20:30:21 +02:00
1 parent cee6f848ea
commit a1cea10218
7 files changed
+298 -185

No files matched your search

-5
View File
@@ -246,11 +246,6 @@ impl ApplicationHandler<GraphicsContext> for App {
self.state.window.request_redraw();
}
}
// Reconfigure the surface if it's lost or outdated
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
self.needs_reconfigure = true;
self.state.window.request_redraw();
}
Err(err) => {
log::error!("Unable to render: {err}");
}
+25 -17
View File
@@ -31,9 +31,12 @@ impl GraphicsContext {
pub async fn new(window: Arc<Window>) -> anyhow::Result<Self> {
let size = window.inner_size();
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: wgpu::Backends::PRIMARY,
..Default::default()
flags: Default::default(),
memory_budget_thresholds: Default::default(),
backend_options: Default::default(),
display: None,
});
let surface = instance.create_surface(Arc::clone(&window)).unwrap();
@@ -43,6 +46,7 @@ impl GraphicsContext {
power_preference: wgpu::PowerPreference::default(),
compatible_surface: Some(&surface),
force_fallback_adapter: false,
apply_limit_buckets: true,
})
.await?;
@@ -104,11 +108,11 @@ impl GraphicsContext {
format: surface_format,
width: size.width,
height: size.height,
//present_mode: surface_caps.present_modes[0],
present_mode: wgpu::PresentMode::Fifo,
alpha_mode: surface_caps.alpha_modes[0],
view_formats: vec![],
desired_maximum_frame_latency: 2,
color_space: wgpu::SurfaceColorSpace::Auto,
};
let (blit_texture, blit_texture_view) =
@@ -144,19 +148,27 @@ impl GraphicsContext {
}
}
pub fn render(
&mut self,
render_job: RenderJob,
scale_factor: f32,
) -> Result<(), wgpu::SurfaceError> {
pub fn render(&mut self, render_job: RenderJob, scale_factor: f32) -> anyhow::Result<()> {
profiling::scope!("render");
if !self.is_surface_configured {
return Ok(());
}
let output = self.surface.get_current_texture()?;
let suboptimal = output.suboptimal;
let output = match self.surface.get_current_texture() {
wgpu::CurrentSurfaceTexture::Success(surface_tex) => surface_tex,
wgpu::CurrentSurfaceTexture::Suboptimal(surface_tex) => surface_tex,
wgpu::CurrentSurfaceTexture::Timeout
| wgpu::CurrentSurfaceTexture::Occluded
| wgpu::CurrentSurfaceTexture::Validation => {
// TODO: Skip this frame for now
return Ok(());
}
wgpu::CurrentSurfaceTexture::Outdated | wgpu::CurrentSurfaceTexture::Lost => {
self.surface.configure(&self.device, &self.config);
return Ok(());
}
};
let surface_view = output
.texture
@@ -209,6 +221,7 @@ impl GraphicsContext {
timestamp_writes: None,
label: Some("main render pass"),
occlusion_query_set: None,
multiview_mask: None,
});
self.renderer.render(
@@ -232,15 +245,10 @@ impl GraphicsContext {
}
self.queue.submit(std::iter::once(encoder.finish()));
self.window.pre_present_notify();
output.present();
self.queue.present(output);
if suboptimal {
Err(wgpu::SurfaceError::Outdated)
} else {
Ok(())
}
Ok(())
}
}
+14 -9
View File
@@ -117,14 +117,17 @@ impl Renderer {
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("pipeline_layout"),
bind_group_layouts: &[&globals_bind_group_layout, &texture_bind_group_layout],
push_constant_ranges: &[],
bind_group_layouts: &[
Some(&globals_bind_group_layout),
Some(&texture_bind_group_layout),
],
immediate_size: 0,
});
let depth_stencil = output_depth_format.map(|format| wgpu::DepthStencilState {
format,
depth_write_enabled: false,
depth_compare: wgpu::CompareFunction::Always,
depth_write_enabled: None,
depth_compare: None,
stencil: wgpu::StencilState::default(),
bias: wgpu::DepthBiasState::default(),
});
@@ -135,7 +138,7 @@ impl Renderer {
vertex: wgpu::VertexState {
entry_point: Some("vs_main"),
module: &shader_module,
buffers: &[wgpu::VertexBufferLayout {
buffers: &[Some(wgpu::VertexBufferLayout {
// 4x f32, 2x u32 -> 6 * 4 bytes
array_stride: 6 * 4,
step_mode: wgpu::VertexStepMode::Vertex,
@@ -144,7 +147,7 @@ impl Renderer {
// 2: uint color
// 3: uint layer_idx
attributes: &wgpu::vertex_attr_array![0 => Float32x2, 1 => Float32x2, 2 => Uint32, 3 => Uint32],
}],
})],
compilation_options: wgpu::PipelineCompilationOptions::default()
},
primitive: wgpu::PrimitiveState {
@@ -172,7 +175,7 @@ impl Renderer {
})],
compilation_options: wgpu::PipelineCompilationOptions::default()
}),
multiview: None,
multiview_mask: None,
cache: None,
});
@@ -442,7 +445,8 @@ impl Renderer {
{
let size = mesh.indices.len() * std::mem::size_of::<u32>();
let slice = index_offset..(index_offset + size);
staging_index_buffer[slice.clone()]
staging_index_buffer
.slice(slice.clone())
.copy_from_slice(bytemuck::cast_slice(&mesh.indices));
self.index_buffer.slices.push(slice);
index_offset += size;
@@ -450,7 +454,8 @@ impl Renderer {
{
let size = mesh.vertices.len() * std::mem::size_of::<Vertex>();
let slice = vertex_offset..(vertex_offset + size);
staging_vertex_buffer[slice.clone()]
staging_vertex_buffer
.slice(slice.clone())
.copy_from_slice(bytemuck::cast_slice(&mesh.vertices));
self.vertex_buffer.slices.push(slice);
vertex_offset += size;
+1 -1
View File
@@ -2,7 +2,7 @@
struct VertexOutput {
@location(0) tex_coord: vec2<f32>,
@location(1) color: vec4<f32>, // linear
@location(2) layer_idx: u32,
@location(2) @interpolate(flat) layer_idx: u32,
@builtin(position) position: vec4<f32>,
};
+3 -3
View File
@@ -291,7 +291,7 @@ pub struct TextureOptions {
pub magnification: wgpu::FilterMode,
pub minification: wgpu::FilterMode,
pub wrap_mode: wgpu::AddressMode,
pub mipmap_mode: wgpu::FilterMode,
pub mipmap_mode: wgpu::MipmapFilterMode,
pub generate_mipmaps: bool,
}
@@ -300,7 +300,7 @@ impl TextureOptions {
magnification: wgpu::FilterMode::Linear,
minification: wgpu::FilterMode::Linear,
wrap_mode: wgpu::AddressMode::Repeat,
mipmap_mode: wgpu::FilterMode::Linear,
mipmap_mode: wgpu::MipmapFilterMode::Linear,
generate_mipmaps: false,
};
@@ -308,7 +308,7 @@ impl TextureOptions {
magnification: wgpu::FilterMode::Linear,
minification: wgpu::FilterMode::Linear,
wrap_mode: wgpu::AddressMode::ClampToEdge,
mipmap_mode: wgpu::FilterMode::Linear,
mipmap_mode: wgpu::MipmapFilterMode::Linear,
generate_mipmaps: false,
};
}