Skip to content

Commit 6195894

Browse files
authored
Merge pull request #1225 from kaphula/master
Update wgpu to 0.12 and fix raw-window-handle-with-wgpu example program.
2 parents 6552107 + 3739159 commit 6195894

File tree

3 files changed

+23
-24
lines changed

3 files changed

+23
-24
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ optional = true
3131

3232
[dev-dependencies]
3333
rand = "0.7"
34-
wgpu = { version = "0.10", features = ["spirv"] }
34+
wgpu = { version = "0.12", features = ["spirv"] }
3535
pollster = "0.2.4"
3636
env_logger = "0.9.0"
3737

changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
In this file will be listed the changes, especially the breaking ones that one should be careful of
22
when upgrading from a version of rust-sdl2 to another.
33

4+
### Unreleased
5+
6+
[PR #1225](https://github.com/Rust-SDL2/rust-sdl2/pull/1225) Update wgpu to 0.12 and fix raw-window-handle-with-wgpu example
7+
48
### v0.35.2
59

610
[PR #1173](https://github.com/Rust-SDL2/rust-sdl2/pull/1173) Fix segfault when using timer callbacks

examples/raw-window-handle-with-wgpu/main.rs

+18-23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern crate sdl2;
44
extern crate wgpu;
55

66
use std::borrow::Cow;
7+
use wgpu::{SurfaceError, SurfaceTexture};
78

89
use sdl2::event::{Event, WindowEvent};
910
use sdl2::keyboard::Keycode;
@@ -26,6 +27,7 @@ fn main() -> Result<(), String> {
2627
let surface = unsafe { instance.create_surface(&window) };
2728
let adapter_opt = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
2829
power_preference: wgpu::PowerPreference::HighPerformance,
30+
force_fallback_adapter: false,
2931
compatible_surface: Some(&surface),
3032
}));
3133
let adapter = match adapter_opt {
@@ -81,37 +83,23 @@ fn main() -> Result<(), String> {
8183
module: &shader,
8284
entry_point: "fs_main",
8385
}),
84-
//rasterization_state: Some(wgpu::RasterizationStateDescriptor {
85-
// depth_bias: 0,
86-
// depth_bias_slope_scale: 0.0,
87-
// depth_bias_clamp: 0.0,
88-
//}),
8986
primitive: wgpu::PrimitiveState {
9087
topology: wgpu::PrimitiveTopology::TriangleList,
9188
strip_index_format: None,
9289
front_face: wgpu::FrontFace::Ccw,
9390
cull_mode: Some(wgpu::Face::Front),
94-
clamp_depth: false,
91+
unclipped_depth: false,
9592
polygon_mode: wgpu::PolygonMode::Fill,
9693
conservative: false,
9794
},
98-
//color_states: &[wgpu::ColorStateDescriptor {
99-
// format: wgpu::TextureFormat::Bgra8UnormSrgb,
100-
// color_blend: wgpu::BlendDescriptor::REPLACE,
101-
// alpha_blend: wgpu::BlendDescriptor::REPLACE,
102-
// write_mask: wgpu::ColorWrite::ALL,
103-
//}],
104-
//vertex_state: wgpu::VertexStateDescriptor {
105-
// index_format: wgpu::IndexFormat::Uint16,
106-
// vertex_buffers: &[],
107-
//},
10895
depth_stencil: None,
10996
label: None,
11097
multisample: wgpu::MultisampleState {
11198
count: 1,
11299
mask: !0,
113100
alpha_to_coverage_enabled: false,
114101
},
102+
multiview: None
115103
});
116104

117105
let mut config = wgpu::SurfaceConfiguration {
@@ -149,13 +137,20 @@ fn main() -> Result<(), String> {
149137
}
150138
}
151139

152-
let frame_res = surface.get_current_frame();
153-
let frame = match frame_res {
154-
Ok(a) => a,
155-
Err(e) => return Err(format!("Timeout getting next texture: {}", e)),
156-
};
140+
let mut frame = match surface.get_current_texture() {
141+
Ok(frame) => {frame},
142+
Err(err) => {
143+
let reason = match (err) {
144+
SurfaceError::Timeout => { "Timeout" }
145+
SurfaceError::Outdated => { "Outdated" }
146+
SurfaceError::Lost => { "Lost" }
147+
SurfaceError::OutOfMemory => { "OutOfMemory" }
148+
};
149+
panic!("Failed to get current surface texture! Reason: {}", reason)
150+
}
151+
};
152+
157153
let output = frame
158-
.output
159154
.texture
160155
.create_view(&wgpu::TextureViewDescriptor::default());
161156
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
@@ -179,8 +174,8 @@ fn main() -> Result<(), String> {
179174
rpass.set_bind_group(0, &bind_group, &[]);
180175
rpass.draw(0..3, 0..1);
181176
}
182-
183177
queue.submit([encoder.finish()]);
178+
frame.present();
184179
}
185180

186181
Ok(())

0 commit comments

Comments
 (0)