From c1962ae35cd10ba6f79a1404a66c39145ccca798 Mon Sep 17 00:00:00 2001 From: Jay Oster Date: Fri, 31 Dec 2021 14:57:57 -0800 Subject: [PATCH] Update dependencies (#230) * Move to Edition 2021 * Update `wgpu`, `raw-window-handle`, and all dependencies for the examples * Update MSRV * Closes #244 --- .github/workflows/ci.yml | 4 +- Cargo.toml | 8 ++-- MSRV.md | 2 +- examples/conway/Cargo.toml | 7 ++-- examples/custom-shader/Cargo.toml | 7 ++-- examples/custom-shader/shaders/noise.wgsl | 2 +- examples/custom-shader/src/renderers.rs | 6 +-- examples/imgui-winit/Cargo.toml | 11 +++--- examples/invaders/Cargo.toml | 7 ++-- examples/minimal-egui/Cargo.toml | 13 +++--- examples/minimal-egui/src/gui.rs | 17 ++++---- examples/minimal-fltk/Cargo.toml | 3 +- examples/minimal-fltk/src/main.rs | 1 - examples/minimal-sdl2/Cargo.toml | 7 ++-- examples/minimal-sdl2/src/main.rs | 48 +++++++++++++---------- examples/minimal-web/Cargo.toml | 11 +++--- examples/minimal-winit/Cargo.toml | 7 ++-- examples/raqote-winit/Cargo.toml | 7 ++-- internals/pixels-mocks/Cargo.toml | 4 +- internals/pixels-mocks/src/lib.rs | 12 ++---- shaders/scale.wgsl | 2 +- src/builder.rs | 26 +++++++----- src/renderers.rs | 8 ++-- 23 files changed, 109 insertions(+), 111 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac993dc5..d669a2b8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: rust: - stable - beta - - 1.54.0 + - 1.57.0 steps: - name: Checkout sources uses: actions/checkout@v2 @@ -73,7 +73,7 @@ jobs: rust: - stable - beta - - 1.54.0 + - 1.57.0 steps: - name: Checkout sources uses: actions/checkout@v2 diff --git a/Cargo.toml b/Cargo.toml index f6729e60..b93fc743 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "pixels" description = "A tiny library providing a GPU-powered pixel frame buffer." version = "0.8.0" authors = ["Jay Oster "] -edition = "2018" +edition = "2021" repository = "https://github.com/parasyte/pixels" readme = "README.md" keywords = ["pixels", "2D", "GPU", "framebuffer"] @@ -20,17 +20,17 @@ include = [ [dependencies] bytemuck = "1.7" -raw-window-handle = "0.3" +raw-window-handle = "0.4" thiserror = "1.0" ultraviolet = "0.8" -wgpu = "0.11" +wgpu = "0.12" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] pollster = "0.2" [dev-dependencies] pixels-mocks = { path = "internals/pixels-mocks" } -winit = "0.25" +winit = "0.26" [workspace] resolver = "2" diff --git a/MSRV.md b/MSRV.md index 48b1952c..c21e3a67 100644 --- a/MSRV.md +++ b/MSRV.md @@ -2,7 +2,7 @@ | `pixels` version | `rustc` version | |------------------|-----------------| -| `0.9.0` | `1.54.0` | +| `0.9.0` | `1.57.0` | | `0.8.0` | `1.52.0` | | `0.7.0` | `1.52.0` | | `0.6.0` | `1.52.0` | diff --git a/examples/conway/Cargo.toml b/examples/conway/Cargo.toml index 42b2e0af..b348c08c 100644 --- a/examples/conway/Cargo.toml +++ b/examples/conway/Cargo.toml @@ -2,8 +2,7 @@ name = "conway" version = "0.1.0" authors = ["Jay Oster "] -edition = "2018" -resolver = "2" +edition = "2021" publish = false [features] @@ -18,5 +17,5 @@ line_drawing = "1.0" log = "0.4" pixels = { path = "../.." } randomize = "3.0" -winit = "0.25" -winit_input_helper = "0.10" +winit = "0.26" +winit_input_helper = "0.11" diff --git a/examples/custom-shader/Cargo.toml b/examples/custom-shader/Cargo.toml index 84b52752..880b5444 100644 --- a/examples/custom-shader/Cargo.toml +++ b/examples/custom-shader/Cargo.toml @@ -2,8 +2,7 @@ name = "custom-shader" version = "0.1.0" authors = ["Jay Oster "] -edition = "2018" -resolver = "2" +edition = "2021" publish = false [features] @@ -15,5 +14,5 @@ bytemuck = "1.7" env_logger = "0.9" log = "0.4" pixels = { path = "../.." } -winit = "0.25" -winit_input_helper = "0.10" +winit = "0.26" +winit_input_helper = "0.11" diff --git a/examples/custom-shader/shaders/noise.wgsl b/examples/custom-shader/shaders/noise.wgsl index 4ede4b41..2f60c146 100644 --- a/examples/custom-shader/shaders/noise.wgsl +++ b/examples/custom-shader/shaders/noise.wgsl @@ -19,7 +19,7 @@ fn vs_main( [[group(0), binding(0)]] var r_tex_color: texture_2d; [[group(0), binding(1)]] var r_tex_sampler: sampler; -[[block]] struct Locals { +struct Locals { time: f32; }; [[group(0), binding(2)]] var r_locals: Locals; diff --git a/examples/custom-shader/src/renderers.rs b/examples/custom-shader/src/renderers.rs index 58d6f402..f5e4806d 100644 --- a/examples/custom-shader/src/renderers.rs +++ b/examples/custom-shader/src/renderers.rs @@ -84,10 +84,7 @@ impl NoiseRenderer { wgpu::BindGroupLayoutEntry { binding: 1, visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Sampler { - filtering: true, - comparison: false, - }, + ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), count: None, }, wgpu::BindGroupLayoutEntry { @@ -139,6 +136,7 @@ impl NoiseRenderer { write_mask: wgpu::ColorWrites::ALL, }], }), + multiview: None, }); Self { diff --git a/examples/imgui-winit/Cargo.toml b/examples/imgui-winit/Cargo.toml index 8de5809e..56945c90 100644 --- a/examples/imgui-winit/Cargo.toml +++ b/examples/imgui-winit/Cargo.toml @@ -2,8 +2,7 @@ name = "imgui-winit" version = "0.1.0" authors = ["Jay Oster "] -edition = "2018" -resolver = "2" +edition = "2021" publish = false [features] @@ -13,9 +12,9 @@ default = ["optimize"] [dependencies] env_logger = "0.9" imgui = "0.8" -imgui-wgpu = "0.18" -imgui-winit-support = { version = "0.8", default-features = false, features = ["winit-25"] } +imgui-wgpu = "0.19" +imgui-winit-support = { version = "0.8", default-features = false, features = ["winit-26"] } log = "0.4" pixels = { path = "../.." } -winit = "0.25" -winit_input_helper = "0.10" +winit = "0.26" +winit_input_helper = "0.11" diff --git a/examples/invaders/Cargo.toml b/examples/invaders/Cargo.toml index c3b82a79..c8e3d0d9 100644 --- a/examples/invaders/Cargo.toml +++ b/examples/invaders/Cargo.toml @@ -2,8 +2,7 @@ name = "invaders" version = "0.1.0" authors = ["Jay Oster "] -edition = "2018" -resolver = "2" +edition = "2021" publish = false [features] @@ -19,5 +18,5 @@ log = "0.4" pixels = { path = "../.." } randomize = "3.0" simple-invaders = { path = "simple-invaders" } -winit = "0.25" -winit_input_helper = "0.10" +winit = "0.26" +winit_input_helper = "0.11" diff --git a/examples/minimal-egui/Cargo.toml b/examples/minimal-egui/Cargo.toml index 0bd58c8b..1268c6fa 100644 --- a/examples/minimal-egui/Cargo.toml +++ b/examples/minimal-egui/Cargo.toml @@ -2,8 +2,7 @@ name = "minimal-egui" version = "0.1.0" authors = ["Jay Oster "] -edition = "2018" -resolver = "2" +edition = "2021" publish = false [features] @@ -11,11 +10,11 @@ optimize = ["log/release_max_level_warn"] default = ["optimize"] [dependencies] -egui = "0.15" -egui_wgpu_backend = "0.14" -egui-winit = { version = "0.15", default-features = false, features = ["links"] } +egui = "0.16" +egui_wgpu_backend = "0.16" +egui-winit = { version = "0.16", default-features = false, features = ["links"] } env_logger = "0.9" log = "0.4" pixels = { path = "../.." } -winit = "0.25" -winit_input_helper = "0.10" +winit = "0.26" +winit_input_helper = "0.11" diff --git a/examples/minimal-egui/src/gui.rs b/examples/minimal-egui/src/gui.rs index 10439996..016bb7d7 100644 --- a/examples/minimal-egui/src/gui.rs +++ b/examples/minimal-egui/src/gui.rs @@ -65,15 +65,13 @@ impl Framework { /// Prepare egui. pub(crate) fn prepare(&mut self, window: &Window) { - // Begin the egui frame. + // Run the egui frame and create all paint jobs to prepare for rendering. let raw_input = self.egui_state.take_egui_input(window); - self.egui_ctx.begin_frame(raw_input); - - // Draw the demo application. - self.gui.ui(&self.egui_ctx); + let (output, paint_commands) = self.egui_ctx.run(raw_input, |egui_ctx| { + // Draw the demo application. + self.gui.ui(egui_ctx); + }); - // End the egui frame and create all paint jobs to prepare for rendering. - let (output, paint_commands) = self.egui_ctx.end_frame(); self.egui_state .handle_output(window, &self.egui_ctx, output); self.paint_jobs = self.egui_ctx.tessellate(paint_commands); @@ -88,7 +86,7 @@ impl Framework { ) -> Result<(), BackendError> { // Upload all resources to the GPU. self.rpass - .update_texture(&context.device, &context.queue, &self.egui_ctx.texture()); + .update_texture(&context.device, &context.queue, &self.egui_ctx.font_image()); self.rpass .update_user_textures(&context.device, &context.queue); self.rpass.update_buffers( @@ -119,9 +117,10 @@ impl Gui { fn ui(&mut self, ctx: &CtxRef) { egui::TopBottomPanel::top("menubar_container").show(ctx, |ui| { egui::menu::bar(ui, |ui| { - egui::menu::menu(ui, "File", |ui| { + ui.menu_button("File", |ui| { if ui.button("About...").clicked() { self.window_open = true; + ui.close_menu(); } }) }); diff --git a/examples/minimal-fltk/Cargo.toml b/examples/minimal-fltk/Cargo.toml index 5e617f18..ecef9b5c 100644 --- a/examples/minimal-fltk/Cargo.toml +++ b/examples/minimal-fltk/Cargo.toml @@ -2,8 +2,7 @@ name = "minimal-fltk" version = "0.1.0" authors = ["Jay Oster "] -edition = "2018" -resolver = "2" +edition = "2021" publish = false [features] diff --git a/examples/minimal-fltk/src/main.rs b/examples/minimal-fltk/src/main.rs index 128ba480..9f38bce1 100644 --- a/examples/minimal-fltk/src/main.rs +++ b/examples/minimal-fltk/src/main.rs @@ -26,7 +26,6 @@ fn main() -> Result<(), Error> { let mut win = Window::default() .with_size(WIDTH as i32, HEIGHT as i32) .with_label("Hello Pixels"); - win.make_resizable(true); win.end(); win.show(); diff --git a/examples/minimal-sdl2/Cargo.toml b/examples/minimal-sdl2/Cargo.toml index c5505d4b..a27fe6cf 100644 --- a/examples/minimal-sdl2/Cargo.toml +++ b/examples/minimal-sdl2/Cargo.toml @@ -2,8 +2,7 @@ name = "minimal-sdl2" version = "0.1.0" authors = ["Jay Oster "] -edition = "2018" -resolver = "2" +edition = "2021" publish = false [features] @@ -11,7 +10,9 @@ optimize = ["log/release_max_level_warn"] default = ["optimize"] [dependencies] -beryllium = { version = "0.3", features = ["extern_crate_raw_window_handle"] } +beryllium = { version = "0.7", features = ["use-raw-window-handle"] } env_logger = "0.9" +fermium = { version = "20016.1.1", default-features = false } log = "0.4" pixels = { path = "../.." } +zstring = "0.1" diff --git a/examples/minimal-sdl2/src/main.rs b/examples/minimal-sdl2/src/main.rs index e12716fc..c6718136 100644 --- a/examples/minimal-sdl2/src/main.rs +++ b/examples/minimal-sdl2/src/main.rs @@ -2,8 +2,14 @@ #![forbid(unsafe_code)] #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] -use beryllium::*; +use beryllium::{ + event::Event, + init::{InitFlags, Sdl}, + window::WindowFlags, +}; +use fermium::keycode; use pixels::{Pixels, SurfaceTexture}; +use zstring::zstr; const WIDTH: u32 = 320; const HEIGHT: u32 = 240; @@ -19,34 +25,36 @@ struct World { fn main() -> Result<(), Box> { env_logger::init(); - let sdl = SDL::init(InitFlags::default())?; - let window = - sdl.create_raw_window("Hello Pixels", WindowPosition::Centered, WIDTH, HEIGHT, 0)?; + let sdl = Sdl::init(InitFlags::EVERYTHING)?; + let window = sdl.create_vk_window( + zstr!("Hello Pixels"), + None, + (WIDTH as i32, HEIGHT as i32), + WindowFlags::ALLOW_HIGHDPI, + )?; let mut pixels = { // TODO: Beryllium does not expose the SDL2 `GetDrawableSize` APIs, so choosing the correct // surface texture size is not possible. - let surface_texture = SurfaceTexture::new(WIDTH, HEIGHT, &window); + let surface_texture = SurfaceTexture::new(WIDTH, HEIGHT, &*window); Pixels::new(WIDTH, HEIGHT, surface_texture)? }; let mut world = World::new(); 'game_loop: loop { - match sdl.poll_events().and_then(Result::ok) { - // Close events - Some(Event::Quit { .. }) => break 'game_loop, - Some(Event::Keyboard(KeyboardEvent { - key: KeyInfo { keycode: key, .. }, - .. - })) if key == Keycode::ESCAPE => break 'game_loop, - - // Resize the window - Some(Event::Window(WindowEvent { - event: WindowEventEnum::Resized { w, h }, - .. - })) => pixels.resize_surface(w as u32, h as u32), - - _ => (), + while let Some(event) = sdl.poll_event() { + match event { + // Close events + Event::Quit { .. } => break 'game_loop, + Event::Keyboard { keycode: key, .. } if key == keycode::SDLK_ESCAPE => { + break 'game_loop + } + + // Resize the window + Event::WindowResized { width, height, .. } => pixels.resize_surface(width, height), + + _ => (), + } } // Update internal state diff --git a/examples/minimal-web/Cargo.toml b/examples/minimal-web/Cargo.toml index 1b72dfb0..18945784 100644 --- a/examples/minimal-web/Cargo.toml +++ b/examples/minimal-web/Cargo.toml @@ -2,21 +2,20 @@ name = "minimal-web" version = "0.1.0" authors = ["Jay Oster "] -edition = "2018" -resolver = "2" +edition = "2021" publish = false [features] optimize = ["log/release_max_level_warn"] -web = ["wgpu/webgl", "winit/web-sys"] +web = ["wgpu/webgl"] default = ["optimize"] [dependencies] log = "0.4" pixels = { path = "../.." } -wgpu = "0.11" -winit = "0.25" -winit_input_helper = "0.10" +wgpu = "0.12" +winit = "0.26" +winit_input_helper = "0.11" [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = "0.1" diff --git a/examples/minimal-winit/Cargo.toml b/examples/minimal-winit/Cargo.toml index ac7f7512..8d2b6ce1 100644 --- a/examples/minimal-winit/Cargo.toml +++ b/examples/minimal-winit/Cargo.toml @@ -2,8 +2,7 @@ name = "minimal-winit" version = "0.1.0" authors = ["Jay Oster "] -edition = "2018" -resolver = "2" +edition = "2021" publish = false [features] @@ -14,5 +13,5 @@ default = ["optimize"] env_logger = "0.9" log = "0.4" pixels = { path = "../.." } -winit = "0.25" -winit_input_helper = "0.10" +winit = "0.26" +winit_input_helper = "0.11" diff --git a/examples/raqote-winit/Cargo.toml b/examples/raqote-winit/Cargo.toml index 5125120a..f1b66f74 100644 --- a/examples/raqote-winit/Cargo.toml +++ b/examples/raqote-winit/Cargo.toml @@ -2,8 +2,7 @@ name = "raqote-winit" version = "0.1.0" authors = ["Jay Oster "] -edition = "2018" -resolver = "2" +edition = "2021" publish = false [features] @@ -15,8 +14,8 @@ env_logger = "0.9" euclid = "0.22" log = "0.4" pixels = { path = "../.." } -winit = "0.25" -winit_input_helper = "0.10" +winit = "0.26" +winit_input_helper = "0.11" [dependencies.raqote] git = "https://github.com/jrmuizel/raqote.git" diff --git a/internals/pixels-mocks/Cargo.toml b/internals/pixels-mocks/Cargo.toml index 70bd4219..04e6c289 100644 --- a/internals/pixels-mocks/Cargo.toml +++ b/internals/pixels-mocks/Cargo.toml @@ -2,8 +2,8 @@ name = "pixels-mocks" version = "0.1.0" authors = ["Jay Oster "] -edition = "2018" +edition = "2021" publish = false [dependencies] -raw-window-handle = "0.3" +raw-window-handle = "0.4" diff --git a/internals/pixels-mocks/src/lib.rs b/internals/pixels-mocks/src/lib.rs index fef1b1bd..1d2c727f 100644 --- a/internals/pixels-mocks/src/lib.rs +++ b/internals/pixels-mocks/src/lib.rs @@ -5,9 +5,7 @@ pub struct Rwh; unsafe impl raw_window_handle::HasRawWindowHandle for Rwh { fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle { #[cfg(target_os = "macos")] - return raw_window_handle::RawWindowHandle::MacOS( - raw_window_handle::macos::MacOSHandle::empty(), - ); + return raw_window_handle::RawWindowHandle::AppKit(raw_window_handle::AppKitHandle::empty()); #[cfg(any( target_os = "linux", target_os = "dragonfly", @@ -16,13 +14,11 @@ unsafe impl raw_window_handle::HasRawWindowHandle for Rwh { target_os = "openbsd", ))] return raw_window_handle::RawWindowHandle::Wayland( - raw_window_handle::unix::WaylandHandle::empty(), + raw_window_handle::WaylandHandle::empty(), ); #[cfg(target_os = "windows")] - return raw_window_handle::RawWindowHandle::Windows( - raw_window_handle::windows::WindowsHandle::empty(), - ); + return raw_window_handle::RawWindowHandle::Win32(raw_window_handle::Win32Handle::empty()); #[cfg(target_os = "ios")] - return raw_window_handle::RawWindowHandle::IOS(raw_window_handle::ios::IOSHandle::empty()); + return raw_window_handle::RawWindowHandle::UiKit(raw_window_handle::UiKitHandle::empty()); } } diff --git a/shaders/scale.wgsl b/shaders/scale.wgsl index dc7bfce1..6d782e8f 100644 --- a/shaders/scale.wgsl +++ b/shaders/scale.wgsl @@ -5,7 +5,7 @@ struct VertexOutput { [[builtin(position)]] position: vec4; }; -[[block]] struct Locals { +struct Locals { transform: mat4x4; }; [[group(0), binding(2)]] var r_locals: Locals; diff --git a/src/builder.rs b/src/builder.rs index 34e6fcad..d4b322ef 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -425,6 +425,8 @@ const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 { R16Uint | R16Sint | R16Float + | R16Unorm + | R16Snorm | Rg8Unorm | Rg8Snorm | Rg8Uint @@ -438,6 +440,8 @@ const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 { | Rg16Uint | Rg16Sint | Rg16Float + | Rg16Unorm + | Rg16Snorm | Rgba8Unorm | Rgba8UnormSrgb | Rgba8Snorm @@ -457,7 +461,9 @@ const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 { | Rg32Float | Rgba16Uint | Rgba16Sint - | Rgba16Float => 8.0, // 64.0 / 8.0 + | Rgba16Float + | Rgba16Unorm + | Rgba16Snorm => 8.0, // 64.0 / 8.0 // 128-bit formats, 8 bits per component Rgba32Uint @@ -471,12 +477,12 @@ const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 { | Bc1RgbaUnormSrgb | Bc4RUnorm | Bc4RSnorm - | Etc2RgbUnorm - | Etc2RgbUnormSrgb - | Etc2RgbA1Unorm - | Etc2RgbA1UnormSrgb - | EacRUnorm - | EacRSnorm => 0.5, // 4.0 * 4.0 / 8.0 + | Etc2Rgb8Unorm + | Etc2Rgb8UnormSrgb + | Etc2Rgb8A1Unorm + | Etc2Rgb8A1UnormSrgb + | EacR11Unorm + | EacR11Snorm => 0.5, // 4.0 * 4.0 / 8.0 // 4x4 blocks, 16 bytes per block Bc2RgbaUnorm @@ -489,8 +495,10 @@ const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 { | Bc6hRgbSfloat | Bc7RgbaUnorm | Bc7RgbaUnormSrgb - | EacRgUnorm - | EacRgSnorm + | EacRg11Unorm + | EacRg11Snorm + | Etc2Rgba8Unorm + | Etc2Rgba8UnormSrgb | Astc4x4RgbaUnorm | Astc4x4RgbaUnormSrgb => 1.0, // 4.0 * 4.0 / 16.0 diff --git a/src/renderers.rs b/src/renderers.rs index 96926489..44cd70cc 100644 --- a/src/renderers.rs +++ b/src/renderers.rs @@ -96,10 +96,7 @@ impl ScalingRenderer { wgpu::BindGroupLayoutEntry { binding: 1, visibility: wgpu::ShaderStages::FRAGMENT, - ty: wgpu::BindingType::Sampler { - filtering: true, - comparison: false, - }, + ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering), count: None, }, wgpu::BindGroupLayoutEntry { @@ -108,7 +105,7 @@ impl ScalingRenderer { ty: wgpu::BindingType::Buffer { ty: wgpu::BufferBindingType::Uniform, has_dynamic_offset: false, - min_binding_size: None, // TODO: More efficent to specify this + min_binding_size: None, // TODO: More efficient to specify this }, count: None, }, @@ -159,6 +156,7 @@ impl ScalingRenderer { write_mask: wgpu::ColorWrites::ALL, }], }), + multiview: None, }); // Create clipping rectangle