Skip to content

Commit bd81157

Browse files
committed
wgpu template: update wgpu 27 -> 29, generated
1 parent ac02f25 commit bd81157

10 files changed

Lines changed: 112 additions & 102 deletions

File tree

generated/graphics/wgpu/cargo-gpu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spir
1717

1818
[workspace.dependencies]
1919
# API
20-
wgpu = { version = "27.0.1", default-features = false, features = ["std", "parking_lot", "vulkan", "vulkan-portability", "spirv", "wgsl"] }
20+
wgpu = { version = "29.0.1", default-features = false, features = ["std", "parking_lot", "vulkan", "vulkan-portability", "spirv", "wgsl"] }
2121
pollster = "0.4.0"
2222

2323
# rust-gpu

generated/graphics/wgpu/cargo-gpu/mygraphics/src/wgpu_renderer/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ pub async fn main_inner() -> anyhow::Result<()> {
3131
)?,
3232
);
3333

34-
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::from_env_or_default());
34+
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::new_with_display_handle_from_env(
35+
Box::new(event_loop.owned_display_handle()),
36+
));
3537
let surface = instance.create_surface(window.clone())?;
3638
let adapter =
3739
wgpu::util::initialize_adapter_from_env_or_default(&instance, Some(&surface)).await?;
3840

39-
let required_features = wgpu::Features::PUSH_CONSTANTS;
41+
let required_features = wgpu::Features::IMMEDIATES;
4042
let required_limits = wgpu::Limits {
41-
max_push_constant_size: 128,
43+
max_immediate_size: 128,
4244
..Default::default()
4345
};
4446
let (device, queue) = adapter
@@ -53,7 +55,13 @@ pub async fn main_inner() -> anyhow::Result<()> {
5355
.await
5456
.context("Failed to create device")?;
5557

56-
let mut swapchain = MySwapchainManager::new(adapter.clone(), device.clone(), window, surface);
58+
let mut swapchain = MySwapchainManager::new(
59+
instance.clone(),
60+
adapter.clone(),
61+
device.clone(),
62+
window,
63+
surface,
64+
);
5765
let renderer = renderer::MyRenderer::new(device, queue, swapchain.format())?;
5866

5967
let start = std::time::Instant::now();
@@ -67,7 +75,7 @@ pub async fn main_inner() -> anyhow::Result<()> {
6775
height: render_target.texture().height(),
6876
},
6977
render_target,
70-
);
78+
)
7179
}),
7280
Event::WindowEvent { event, .. } => {
7381
match event {

generated/graphics/wgpu/cargo-gpu/mygraphics/src/wgpu_renderer/render_pipeline.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use crate::wgpu_renderer::renderer::{GlobalBindGroup, GlobalBindGroupLayout};
22
use mygraphics_shaders::ShaderConstants;
33
use wgpu::{
44
ColorTargetState, ColorWrites, Device, FragmentState, FrontFace, MultisampleState,
5-
PipelineLayoutDescriptor, PolygonMode, PrimitiveState, PrimitiveTopology, PushConstantRange,
6-
RenderPass, RenderPipeline, RenderPipelineDescriptor, ShaderStages, TextureFormat, VertexState,
7-
include_spirv,
5+
PipelineLayoutDescriptor, PolygonMode, PrimitiveState, PrimitiveTopology, RenderPass,
6+
RenderPipeline, RenderPipelineDescriptor, TextureFormat, VertexState, include_spirv,
87
};
98

109
#[derive(Debug, Clone)]
@@ -22,11 +21,8 @@ impl MyRenderPipeline {
2221

2322
let layout = device.create_pipeline_layout(&PipelineLayoutDescriptor {
2423
label: Some("MyRenderPipeline layout"),
25-
bind_group_layouts: &[&global_bind_group_layout.0],
26-
push_constant_ranges: &[PushConstantRange {
27-
stages: ShaderStages::VERTEX_FRAGMENT,
28-
range: 0..size_of::<ShaderConstants>() as u32,
29-
}],
24+
bind_group_layouts: &[Some(&global_bind_group_layout.0)],
25+
immediate_size: size_of::<ShaderConstants>() as u32,
3026
});
3127

3228
Ok(Self {
@@ -60,7 +56,7 @@ impl MyRenderPipeline {
6056
write_mask: ColorWrites::ALL,
6157
})],
6258
}),
63-
multiview: None,
59+
multiview_mask: None,
6460
cache: None,
6561
}),
6662
})

generated/graphics/wgpu/cargo-gpu/mygraphics/src/wgpu_renderer/renderer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl MyRenderer {
2828
})
2929
}
3030

31-
pub fn render(&self, shader_constants: &ShaderConstants, output: TextureView) {
31+
pub fn render(&self, shader_constants: &ShaderConstants, output: TextureView) -> anyhow::Result<()> {
3232
let global_bind_group = self
3333
.global_bind_group_layout
3434
.create(&self.device, shader_constants);
@@ -53,11 +53,13 @@ impl MyRenderer {
5353
depth_stencil_attachment: None,
5454
timestamp_writes: None,
5555
occlusion_query_set: None,
56+
multiview_mask: None,
5657
});
5758
self.pipeline.draw(&mut rpass, &global_bind_group);
5859
drop(rpass);
5960

6061
self.queue.submit(std::iter::once(cmd.finish()));
62+
Ok(())
6163
}
6264
}
6365

generated/graphics/wgpu/cargo-gpu/mygraphics/src/wgpu_renderer/swapchain.rs

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use anyhow::Context;
22
use std::sync::Arc;
3-
use wgpu::{Adapter, Device, Surface, SurfaceError, TextureFormat, TextureView};
3+
use wgpu::{Adapter, CurrentSurfaceTexture, Device, Instance, Surface, TextureFormat, TextureView};
44
use winit::dpi::PhysicalSize;
55
use winit::window::Window;
66

77
pub struct MySwapchainManager<'a> {
8+
instance: Instance,
89
adapter: Adapter,
910
device: Device,
1011
window: Arc<Window>,
@@ -22,13 +23,15 @@ pub struct ActiveConfiguration {
2223

2324
impl<'a> MySwapchainManager<'a> {
2425
pub fn new(
26+
instance: Instance,
2527
adapter: Adapter,
2628
device: Device,
2729
window: Arc<Window>,
2830
surface: Surface<'a>,
2931
) -> Self {
3032
let caps = surface.get_capabilities(&adapter);
3133
Self {
34+
instance,
3235
adapter,
3336
device,
3437
window,
@@ -48,7 +51,7 @@ impl<'a> MySwapchainManager<'a> {
4851
self.format
4952
}
5053

51-
pub fn render<R>(&mut self, f: impl FnOnce(TextureView) -> R) -> anyhow::Result<R> {
54+
pub fn render(&mut self, f: impl FnOnce(TextureView) -> anyhow::Result<()>) -> anyhow::Result<()> {
5255
let size = self.window.inner_size();
5356
if let Some(active) = &self.active {
5457
if active.size != size {
@@ -58,40 +61,36 @@ impl<'a> MySwapchainManager<'a> {
5861
self.should_recreate();
5962
}
6063

61-
const RECREATE_ATTEMPTS: u32 = 10;
62-
for _ in 0..RECREATE_ATTEMPTS {
63-
if self.should_recreate {
64-
self.should_recreate = false;
65-
self.configure_surface(size)?;
66-
}
67-
68-
match self.surface.get_current_texture() {
69-
Ok(surface_texture) => {
70-
if surface_texture.suboptimal {
71-
self.should_recreate = true;
72-
}
73-
let output_view =
74-
surface_texture
75-
.texture
76-
.create_view(&wgpu::TextureViewDescriptor {
77-
format: Some(self.format),
78-
..wgpu::TextureViewDescriptor::default()
79-
});
80-
let r = f(output_view);
81-
surface_texture.present();
82-
return Ok(r);
83-
}
84-
Err(SurfaceError::Outdated | SurfaceError::Lost) => {
85-
self.should_recreate = true;
86-
}
87-
Err(e) => {
88-
anyhow::bail!("get_current_texture() failed: {e}")
89-
}
90-
};
64+
if self.should_recreate {
65+
self.should_recreate = false;
66+
self.configure_surface(size)?;
9167
}
92-
anyhow::bail!(
93-
"looped {RECREATE_ATTEMPTS} times trying to acquire swapchain image and failed repeatedly!"
94-
);
68+
69+
match self.surface.get_current_texture() {
70+
CurrentSurfaceTexture::Success(surface_texture) => {
71+
let output_view =
72+
surface_texture
73+
.texture
74+
.create_view(&wgpu::TextureViewDescriptor {
75+
format: Some(self.format),
76+
..wgpu::TextureViewDescriptor::default()
77+
});
78+
f(output_view)?;
79+
surface_texture.present();
80+
}
81+
CurrentSurfaceTexture::Occluded | CurrentSurfaceTexture::Timeout => (),
82+
CurrentSurfaceTexture::Suboptimal(_) | CurrentSurfaceTexture::Outdated => {
83+
self.should_recreate();
84+
}
85+
CurrentSurfaceTexture::Validation => {
86+
anyhow::bail!("Validation error during surface texture acquisition")
87+
}
88+
CurrentSurfaceTexture::Lost => {
89+
self.surface = self.instance.create_surface(self.window.clone())?;
90+
self.should_recreate();
91+
}
92+
};
93+
Ok(())
9594
}
9695

9796
fn configure_surface(&mut self, size: PhysicalSize<u32>) -> anyhow::Result<()> {

generated/graphics/wgpu/spirv-builder/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ unexpected_cfgs = { level = "allow", check-cfg = ['cfg(target_arch, values("spir
1717

1818
[workspace.dependencies]
1919
# API
20-
wgpu = { version = "27.0.1", default-features = false, features = ["std", "parking_lot", "vulkan", "vulkan-portability", "spirv", "wgsl"] }
20+
wgpu = { version = "29.0.1", default-features = false, features = ["std", "parking_lot", "vulkan", "vulkan-portability", "spirv", "wgsl"] }
2121
pollster = "0.4.0"
2222

2323
# rust-gpu

generated/graphics/wgpu/spirv-builder/mygraphics/src/wgpu_renderer/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,16 @@ pub async fn main_inner() -> anyhow::Result<()> {
3131
)?,
3232
);
3333

34-
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor::from_env_or_default());
34+
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::new_with_display_handle_from_env(
35+
Box::new(event_loop.owned_display_handle()),
36+
));
3537
let surface = instance.create_surface(window.clone())?;
3638
let adapter =
3739
wgpu::util::initialize_adapter_from_env_or_default(&instance, Some(&surface)).await?;
3840

39-
let required_features = wgpu::Features::PUSH_CONSTANTS;
41+
let required_features = wgpu::Features::IMMEDIATES;
4042
let required_limits = wgpu::Limits {
41-
max_push_constant_size: 128,
43+
max_immediate_size: 128,
4244
..Default::default()
4345
};
4446
let (device, queue) = adapter
@@ -53,7 +55,13 @@ pub async fn main_inner() -> anyhow::Result<()> {
5355
.await
5456
.context("Failed to create device")?;
5557

56-
let mut swapchain = MySwapchainManager::new(adapter.clone(), device.clone(), window, surface);
58+
let mut swapchain = MySwapchainManager::new(
59+
instance.clone(),
60+
adapter.clone(),
61+
device.clone(),
62+
window,
63+
surface,
64+
);
5765
let renderer = renderer::MyRenderer::new(device, queue, swapchain.format())?;
5866

5967
let start = std::time::Instant::now();
@@ -67,7 +75,7 @@ pub async fn main_inner() -> anyhow::Result<()> {
6775
height: render_target.texture().height(),
6876
},
6977
render_target,
70-
);
78+
)
7179
}),
7280
Event::WindowEvent { event, .. } => {
7381
match event {

generated/graphics/wgpu/spirv-builder/mygraphics/src/wgpu_renderer/render_pipeline.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ use crate::wgpu_renderer::renderer::{GlobalBindGroup, GlobalBindGroupLayout};
22
use mygraphics_shaders::ShaderConstants;
33
use wgpu::{
44
ColorTargetState, ColorWrites, Device, FragmentState, FrontFace, MultisampleState,
5-
PipelineLayoutDescriptor, PolygonMode, PrimitiveState, PrimitiveTopology, PushConstantRange,
6-
RenderPass, RenderPipeline, RenderPipelineDescriptor, ShaderStages, TextureFormat, VertexState,
7-
include_spirv,
5+
PipelineLayoutDescriptor, PolygonMode, PrimitiveState, PrimitiveTopology, RenderPass,
6+
RenderPipeline, RenderPipelineDescriptor, TextureFormat, VertexState, include_spirv,
87
};
98

109
#[derive(Debug, Clone)]
@@ -22,11 +21,8 @@ impl MyRenderPipeline {
2221

2322
let layout = device.create_pipeline_layout(&PipelineLayoutDescriptor {
2423
label: Some("MyRenderPipeline layout"),
25-
bind_group_layouts: &[&global_bind_group_layout.0],
26-
push_constant_ranges: &[PushConstantRange {
27-
stages: ShaderStages::VERTEX_FRAGMENT,
28-
range: 0..size_of::<ShaderConstants>() as u32,
29-
}],
24+
bind_group_layouts: &[Some(&global_bind_group_layout.0)],
25+
immediate_size: size_of::<ShaderConstants>() as u32,
3026
});
3127

3228
Ok(Self {
@@ -60,7 +56,7 @@ impl MyRenderPipeline {
6056
write_mask: ColorWrites::ALL,
6157
})],
6258
}),
63-
multiview: None,
59+
multiview_mask: None,
6460
cache: None,
6561
}),
6662
})

generated/graphics/wgpu/spirv-builder/mygraphics/src/wgpu_renderer/renderer.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl MyRenderer {
2828
})
2929
}
3030

31-
pub fn render(&self, shader_constants: &ShaderConstants, output: TextureView) {
31+
pub fn render(&self, shader_constants: &ShaderConstants, output: TextureView) -> anyhow::Result<()> {
3232
let global_bind_group = self
3333
.global_bind_group_layout
3434
.create(&self.device, shader_constants);
@@ -53,11 +53,13 @@ impl MyRenderer {
5353
depth_stencil_attachment: None,
5454
timestamp_writes: None,
5555
occlusion_query_set: None,
56+
multiview_mask: None,
5657
});
5758
self.pipeline.draw(&mut rpass, &global_bind_group);
5859
drop(rpass);
5960

6061
self.queue.submit(std::iter::once(cmd.finish()));
62+
Ok(())
6163
}
6264
}
6365

0 commit comments

Comments
 (0)