Skip to content

Commit 85ffa8d

Browse files
authored
29.0 (#667)
* update code to 29.0 and started news/29.0/readme.md * wrote news article for 29.0
1 parent d6e84dc commit 85ffa8d

76 files changed

Lines changed: 1333 additions & 543 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 184 additions & 136 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ exclude = [
2828
]
2929

3030
[workspace.dependencies]
31-
wgpu = "28.0"
31+
wgpu = "29.0"
3232
anyhow = "1"
3333
glam = { version = "0.30.9", features = ["bytemuck"] }
3434
bytemuck = { version = "1.13.1", features = ["derive"] }

code/beginner/tutorial1-window/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ anyhow = "1.0"
1616
winit = { version = "0.30" }
1717
env_logger = "0.10"
1818
log = "0.4"
19-
wgpu = "28.0"
19+
wgpu = "29.0"
2020
pollster = "0.3"
2121

2222
[target.'cfg(target_arch = "wasm32")'.dependencies]
2323
console_error_panic_hook = "0.1.6"
2424
console_log = "1.0"
25-
wgpu = { version = "28.0", features = ["webgl"]}
25+
wgpu = { version = "29.0", features = ["webgl"]}
2626
wasm-bindgen = "0.2"
2727
wasm-bindgen-futures = "0.4.30"
2828
web-sys = { version = "0.3.69", features = [

code/beginner/tutorial2-surface/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ anyhow = "1.0"
1212
winit = { version = "0.30", features = ["android-native-activity"] }
1313
env_logger = "0.10"
1414
log = "0.4"
15-
wgpu = "28.0"
15+
wgpu = "29.0"
1616
pollster = "0.3"
1717

1818
[target.'cfg(target_arch = "wasm32")'.dependencies]
1919
console_error_panic_hook = "0.1.6"
2020
console_log = "1.0"
21-
wgpu = { version = "28.0", features = ["webgl"]}
21+
wgpu = { version = "29.0", features = ["webgl"]}
2222
wasm-bindgen = "0.2"
2323
wasm-bindgen-futures = "0.4"
2424
web-sys = { version = "0.3", features = [

code/beginner/tutorial2-surface/src/challenge.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ impl State {
2828

2929
// The instance is a handle to our GPU
3030
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
31-
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
31+
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
3232
#[cfg(not(target_arch = "wasm32"))]
3333
backends: wgpu::Backends::PRIMARY,
3434
#[cfg(target_arch = "wasm32")]
3535
backends: wgpu::Backends::GL,
36-
..Default::default()
36+
flags: Default::default(),
37+
memory_budget_thresholds: Default::default(),
38+
backend_options: Default::default(),
39+
display: None,
3740
});
3841

3942
let surface = instance.create_surface(window.clone()).unwrap();
@@ -111,10 +114,31 @@ impl State {
111114
#[allow(unused)]
112115
fn update(&mut self) {}
113116

114-
fn render(&mut self) -> Result<(), wgpu::SurfaceError> {
117+
fn render(&mut self) -> anyhow::Result<()> {
115118
self.window.request_redraw();
116119

117-
let output = self.surface.get_current_texture()?;
120+
let output = match self.surface.get_current_texture() {
121+
wgpu::CurrentSurfaceTexture::Success(surface_texture) => surface_texture,
122+
wgpu::CurrentSurfaceTexture::Suboptimal(surface_texture) => {
123+
self.surface.configure(&self.device, &self.config);
124+
surface_texture
125+
}
126+
wgpu::CurrentSurfaceTexture::Timeout
127+
| wgpu::CurrentSurfaceTexture::Occluded
128+
| wgpu::CurrentSurfaceTexture::Validation => {
129+
// Skip this frame
130+
return Ok(());
131+
}
132+
wgpu::CurrentSurfaceTexture::Outdated => {
133+
self.surface.configure(&self.device, &self.config);
134+
return Ok(());
135+
}
136+
wgpu::CurrentSurfaceTexture::Lost => {
137+
// You could recreate the devices and all resources
138+
// created with it here, but we'll just bail
139+
anyhow::bail!("Lost device");
140+
}
141+
};
118142
let view = output
119143
.texture
120144
.create_view(&wgpu::TextureViewDescriptor::default());
@@ -255,13 +279,10 @@ impl ApplicationHandler<State> for App {
255279
WindowEvent::RedrawRequested => {
256280
match state.render() {
257281
Ok(_) => {}
258-
// Reconfigure the surface if it's lost or outdated
259-
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
260-
let size = state.window.inner_size();
261-
state.resize(size.width, size.height);
262-
}
263282
Err(e) => {
264-
log::error!("Unable to render {}", e);
283+
// Log the error and exit gracefully
284+
log::error!("{e}");
285+
event_loop.exit();
265286
}
266287
}
267288
}

code/beginner/tutorial2-surface/src/lib.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,15 @@ impl State {
2828

2929
// The instance is a handle to our GPU
3030
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
31-
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
31+
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
3232
#[cfg(not(target_arch = "wasm32"))]
3333
backends: wgpu::Backends::PRIMARY,
3434
#[cfg(target_arch = "wasm32")]
3535
backends: wgpu::Backends::GL,
36-
..Default::default()
36+
flags: Default::default(),
37+
memory_budget_thresholds: Default::default(),
38+
backend_options: Default::default(),
39+
display: None,
3740
});
3841

3942
let surface = instance.create_surface(window.clone()).unwrap();
@@ -106,15 +109,36 @@ impl State {
106109

107110
fn update(&mut self) {}
108111

109-
fn render(&mut self) -> Result<(), wgpu::SurfaceError> {
112+
fn render(&mut self) -> anyhow::Result<()> {
110113
self.window.request_redraw();
111114

112115
// We can't render unless the surface is configured
113116
if !self.is_surface_configured {
114117
return Ok(());
115118
}
116119

117-
let output = self.surface.get_current_texture()?;
120+
let output = match self.surface.get_current_texture() {
121+
wgpu::CurrentSurfaceTexture::Success(surface_texture) => surface_texture,
122+
wgpu::CurrentSurfaceTexture::Suboptimal(surface_texture) => {
123+
self.surface.configure(&self.device, &self.config);
124+
surface_texture
125+
}
126+
wgpu::CurrentSurfaceTexture::Timeout
127+
| wgpu::CurrentSurfaceTexture::Occluded
128+
| wgpu::CurrentSurfaceTexture::Validation => {
129+
// Skip this frame
130+
return Ok(());
131+
}
132+
wgpu::CurrentSurfaceTexture::Outdated => {
133+
self.surface.configure(&self.device, &self.config);
134+
return Ok(());
135+
}
136+
wgpu::CurrentSurfaceTexture::Lost => {
137+
// You could recreate the devices and all resources
138+
// created with it here, but we'll just bail
139+
anyhow::bail!("Lost device");
140+
}
141+
};
118142
let view = output
119143
.texture
120144
.create_view(&wgpu::TextureViewDescriptor::default());
@@ -256,13 +280,10 @@ impl ApplicationHandler<State> for App {
256280
state.update();
257281
match state.render() {
258282
Ok(_) => {}
259-
// Reconfigure the surface if it's lost or outdated
260-
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
261-
let size = state.window.inner_size();
262-
state.resize(size.width, size.height);
263-
}
264283
Err(e) => {
265-
log::error!("Unable to render {}", e);
284+
// Log the error and exit gracefully
285+
log::error!("{e}");
286+
event_loop.exit();
266287
}
267288
}
268289
}

code/beginner/tutorial3-pipeline/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ anyhow = "1.0"
1212
winit = { version = "0.30", features = ["android-native-activity"] }
1313
env_logger = "0.10"
1414
log = "0.4"
15-
wgpu = "28.0"
15+
wgpu = "29.0"
1616
pollster = "0.3"
1717

1818
[target.'cfg(target_arch = "wasm32")'.dependencies]
1919
console_error_panic_hook = "0.1.6"
2020
console_log = "1.0"
21-
wgpu = { version = "28.0", features = ["webgl"]}
21+
wgpu = { version = "29.0", features = ["webgl"]}
2222
wasm-bindgen = "0.2"
2323
wasm-bindgen-futures = "0.4"
2424
web-sys = { version = "0.3", features = [

code/beginner/tutorial3-pipeline/src/challenge.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ impl State {
3131

3232
// The instance is a handle to our GPU
3333
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
34-
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
34+
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
3535
#[cfg(not(target_arch = "wasm32"))]
3636
backends: wgpu::Backends::PRIMARY,
3737
#[cfg(target_arch = "wasm32")]
3838
backends: wgpu::Backends::GL,
39-
..Default::default()
39+
flags: Default::default(),
40+
memory_budget_thresholds: Default::default(),
41+
backend_options: Default::default(),
42+
display: None,
4043
});
4144

4245
let surface = instance.create_surface(window.clone()).unwrap();
@@ -232,15 +235,36 @@ impl State {
232235
#[allow(dead_code)]
233236
fn update(&mut self) {}
234237

235-
fn render(&mut self) -> Result<(), wgpu::SurfaceError> {
238+
fn render(&mut self) -> anyhow::Result<()> {
236239
self.window.request_redraw();
237240

238241
// We can't render unless the surface is configured
239242
if !self.is_surface_configured {
240243
return Ok(());
241244
}
242245

243-
let output = self.surface.get_current_texture()?;
246+
let output = match self.surface.get_current_texture() {
247+
wgpu::CurrentSurfaceTexture::Success(surface_texture) => surface_texture,
248+
wgpu::CurrentSurfaceTexture::Suboptimal(surface_texture) => {
249+
self.surface.configure(&self.device, &self.config);
250+
surface_texture
251+
}
252+
wgpu::CurrentSurfaceTexture::Timeout
253+
| wgpu::CurrentSurfaceTexture::Occluded
254+
| wgpu::CurrentSurfaceTexture::Validation => {
255+
// Skip this frame
256+
return Ok(());
257+
}
258+
wgpu::CurrentSurfaceTexture::Outdated => {
259+
self.surface.configure(&self.device, &self.config);
260+
return Ok(());
261+
}
262+
wgpu::CurrentSurfaceTexture::Lost => {
263+
// You could recreate the devices and all resources
264+
// created with it here, but we'll just bail
265+
anyhow::bail!("Lost device");
266+
}
267+
};
244268
let view = output
245269
.texture
246270
.create_view(&wgpu::TextureViewDescriptor::default());
@@ -385,13 +409,10 @@ impl ApplicationHandler<State> for App {
385409
WindowEvent::RedrawRequested => {
386410
match state.render() {
387411
Ok(_) => {}
388-
// Reconfigure the surface if it's lost or outdated
389-
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
390-
let size = state.window.inner_size();
391-
state.resize(size.width, size.height);
392-
}
393412
Err(e) => {
394-
log::error!("Unable to render {}", e);
413+
// Log the error and exit gracefully
414+
log::error!("{e}");
415+
event_loop.exit();
395416
}
396417
}
397418
}

code/beginner/tutorial3-pipeline/src/lib.rs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ impl State {
3030

3131
// The instance is a handle to our GPU
3232
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
33-
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
33+
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
3434
#[cfg(not(target_arch = "wasm32"))]
3535
backends: wgpu::Backends::PRIMARY,
3636
#[cfg(target_arch = "wasm32")]
3737
backends: wgpu::Backends::GL,
38-
..Default::default()
38+
flags: Default::default(),
39+
memory_budget_thresholds: Default::default(),
40+
backend_options: Default::default(),
41+
display: None,
3942
});
4043

4144
let surface = instance.create_surface(window.clone()).unwrap();
@@ -177,15 +180,36 @@ impl State {
177180

178181
fn update(&mut self) {}
179182

180-
fn render(&mut self) -> Result<(), wgpu::SurfaceError> {
183+
fn render(&mut self) -> anyhow::Result<()> {
181184
self.window.request_redraw();
182185

183186
// We can't render unless the surface is configured
184187
if !self.is_surface_configured {
185188
return Ok(());
186189
}
187190

188-
let output = self.surface.get_current_texture()?;
191+
let output = match self.surface.get_current_texture() {
192+
wgpu::CurrentSurfaceTexture::Success(surface_texture) => surface_texture,
193+
wgpu::CurrentSurfaceTexture::Suboptimal(surface_texture) => {
194+
self.surface.configure(&self.device, &self.config);
195+
surface_texture
196+
}
197+
wgpu::CurrentSurfaceTexture::Timeout
198+
| wgpu::CurrentSurfaceTexture::Occluded
199+
| wgpu::CurrentSurfaceTexture::Validation => {
200+
// Skip this frame
201+
return Ok(());
202+
}
203+
wgpu::CurrentSurfaceTexture::Outdated => {
204+
self.surface.configure(&self.device, &self.config);
205+
return Ok(());
206+
}
207+
wgpu::CurrentSurfaceTexture::Lost => {
208+
// You could recreate the devices and all resources
209+
// created with it here, but we'll just bail
210+
anyhow::bail!("Lost device");
211+
}
212+
};
189213
let view = output
190214
.texture
191215
.create_view(&wgpu::TextureViewDescriptor::default());
@@ -323,13 +347,10 @@ impl ApplicationHandler<State> for App {
323347
state.update();
324348
match state.render() {
325349
Ok(_) => {}
326-
// Reconfigure the surface if it's lost or outdated
327-
Err(wgpu::SurfaceError::Lost | wgpu::SurfaceError::Outdated) => {
328-
let size = state.window.inner_size();
329-
state.resize(size.width, size.height);
330-
}
331350
Err(e) => {
332-
log::error!("Unable to render {}", e);
351+
// Log the error and exit gracefully
352+
log::error!("{e}");
353+
event_loop.exit();
333354
}
334355
}
335356
}

code/beginner/tutorial4-buffer/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate-type = ["cdylib", "rlib"]
1111
[dependencies]
1212
anyhow = "1.0"
1313
winit = { version = "0.30", features = ["android-native-activity"] }
14-
wgpu = "28.0"
14+
wgpu = "29.0"
1515
env_logger = "0.10"
1616
log = "0.4"
1717
pollster = "0.3"
@@ -21,7 +21,7 @@ bytemuck = { version = "1.24", features = [ "derive" ] }
2121
[target.'cfg(target_arch = "wasm32")'.dependencies]
2222
console_error_panic_hook = "0.1"
2323
console_log = "1.0"
24-
wgpu = { version = "28.0", features = ["webgl"]}
24+
wgpu = { version = "29.0", features = ["webgl"]}
2525
wasm-bindgen = "0.2"
2626
wasm-bindgen-futures = "0.4"
2727
web-sys = { version = "0.3", features = [

0 commit comments

Comments
 (0)