Skip to content

Commit

Permalink
update wgpu and adapt code
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsheldon committed Jan 18, 2024
1 parent fe28779 commit 5cef5e4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ winit = { version = "0.29", features = ["rwh_05"] }
cgmath = { version = "0.18", features = ["swizzle"] }
env_logger = "0.10"
log = "0.4"
wgpu = "0.18"
wgpu = "0.19"
crevice = { version = "0.14", features = ["cgmath"] }
futures = "0.3"
anyhow = "1.0"
Expand Down
21 changes: 9 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ use wenderer::rendering::{Camera, CanvasPass, D3Pass, RenderPass};
use wenderer::shading::Tex;
use wenderer::utils::{CameraController, load_volume_data};

struct State {
surface: wgpu::Surface,
struct State<'w> {
surface: wgpu::Surface<'w>,
surface_configs: SurfaceConfiguration,
surface_view_desc: TextureViewDescriptor<'static>,
device: wgpu::Device,
Expand All @@ -38,21 +38,17 @@ struct State {
canvas_pass: CanvasPass,
}

impl State {
impl<'w> State<'w> {
/// This is 1 because render buffer textures for front-face and back-face rendering is the resolved target
/// not the multisampled target
const FACE_RENDER_BUFFER_SAMPLE_COUNT: u32 = 1;
// need async because we need to await some struct creation here
async fn new(window: &Window, sample_count: NonZeroU32) -> Self {
async fn new(window: &'w Window, sample_count: NonZeroU32) -> Self {
let size = window.inner_size();
// The instance is a handle to our GPU
// BackendBit::PRIMARY => Vulkan + Metal + DX12 + Browser WebGPU
let instance = wgpu::Instance::default();
let surface = unsafe {
instance
.create_surface(window)
.expect("Surface creation failed")
};
let surface = instance.create_surface(window).expect("Failed to create surface");
// need adapter to create the device and queue
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
Expand All @@ -65,9 +61,9 @@ impl State {
let (device, queue) = adapter
.request_device(
&wgpu::DeviceDescriptor {
features: wgpu::Features::empty(), //The device you have limits the features you can use
limits: wgpu::Limits::default(), //The limits field describes the limit of certain types of resource we can create
label: None,
required_features: wgpu::Features::empty(), //The device you have limits the features you can use
required_limits: wgpu::Limits::default(), //The limits field describes the limit of certain types of resource we can create
},
None,
)
Expand All @@ -80,6 +76,7 @@ impl State {
width: size.width,
height: size.height,
present_mode: wgpu::PresentMode::Fifo,
desired_maximum_frame_latency: 2, // 2 is the default value
alpha_mode: CompositeAlphaMode::Auto,
view_formats: vec![preferred_format],
};
Expand Down Expand Up @@ -284,7 +281,7 @@ fn main() {
.unwrap();
let sample_count = 4;
let mut state = block_on(State::new(&window, NonZeroU32::new(sample_count).unwrap()));
event_loop.run(move |event, event_loop_window_target| match event {
event_loop.run(|event, event_loop_window_target| match event {
Event::WindowEvent {
ref event,
window_id,
Expand Down

0 comments on commit 5cef5e4

Please sign in to comment.