Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wgpu to 0.12 and fix raw-window-handle-with-wgpu example program. #1225

Merged
merged 3 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ optional = true

[dev-dependencies]
rand = "0.7"
wgpu = { version = "0.10", features = ["spirv"] }
wgpu = { version = "0.12", features = ["spirv"] }
pollster = "0.2.4"
env_logger = "0.9.0"

Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
In this file will be listed the changes, especially the breaking ones that one should be careful of
when upgrading from a version of rust-sdl2 to another.

### Unreleased

[PR #1225](https://github.com/Rust-SDL2/rust-sdl2/pull/1225) Update wgpu to 0.12 and fix raw-window-handle-with-wgpu example

### v0.35.2

[PR #1173](https://github.com/Rust-SDL2/rust-sdl2/pull/1173) Fix segfault when using timer callbacks
Expand Down
41 changes: 18 additions & 23 deletions examples/raw-window-handle-with-wgpu/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern crate sdl2;
extern crate wgpu;

use std::borrow::Cow;
use wgpu::{SurfaceError, SurfaceTexture};

use sdl2::event::{Event, WindowEvent};
use sdl2::keyboard::Keycode;
Expand All @@ -26,6 +27,7 @@ fn main() -> Result<(), String> {
let surface = unsafe { instance.create_surface(&window) };
let adapter_opt = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::HighPerformance,
force_fallback_adapter: false,
compatible_surface: Some(&surface),
}));
let adapter = match adapter_opt {
Expand Down Expand Up @@ -81,37 +83,23 @@ fn main() -> Result<(), String> {
module: &shader,
entry_point: "fs_main",
}),
//rasterization_state: Some(wgpu::RasterizationStateDescriptor {
// depth_bias: 0,
// depth_bias_slope_scale: 0.0,
// depth_bias_clamp: 0.0,
//}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
strip_index_format: None,
front_face: wgpu::FrontFace::Ccw,
cull_mode: Some(wgpu::Face::Front),
clamp_depth: false,
unclipped_depth: false,
polygon_mode: wgpu::PolygonMode::Fill,
conservative: false,
},
//color_states: &[wgpu::ColorStateDescriptor {
// format: wgpu::TextureFormat::Bgra8UnormSrgb,
// color_blend: wgpu::BlendDescriptor::REPLACE,
// alpha_blend: wgpu::BlendDescriptor::REPLACE,
// write_mask: wgpu::ColorWrite::ALL,
//}],
//vertex_state: wgpu::VertexStateDescriptor {
// index_format: wgpu::IndexFormat::Uint16,
// vertex_buffers: &[],
//},
depth_stencil: None,
label: None,
multisample: wgpu::MultisampleState {
count: 1,
mask: !0,
alpha_to_coverage_enabled: false,
},
multiview: None
});

let mut config = wgpu::SurfaceConfiguration {
Expand Down Expand Up @@ -149,13 +137,20 @@ fn main() -> Result<(), String> {
}
}

let frame_res = surface.get_current_frame();
let frame = match frame_res {
Ok(a) => a,
Err(e) => return Err(format!("Timeout getting next texture: {}", e)),
};
let mut frame = match surface.get_current_texture() {
Ok(frame) => {frame},
Err(err) => {
let reason = match (err) {
SurfaceError::Timeout => { "Timeout" }
SurfaceError::Outdated => { "Outdated" }
SurfaceError::Lost => { "Lost" }
SurfaceError::OutOfMemory => { "OutOfMemory" }
};
panic!("Failed to get current surface texture! Reason: {}", reason)
}
};

let output = frame
.output
.texture
.create_view(&wgpu::TextureViewDescriptor::default());
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
Expand All @@ -179,8 +174,8 @@ fn main() -> Result<(), String> {
rpass.set_bind_group(0, &bind_group, &[]);
rpass.draw(0..3, 0..1);
}

queue.submit([encoder.finish()]);
frame.present();
}

Ok(())
Expand Down