Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
- `wgpu` 0.12
- `raw-window-handle` 0.4

Closes #244
  • Loading branch information
parasyte committed Dec 30, 2021
1 parent 7d6446b commit 2090e65
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 72 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ 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"
Expand All @@ -38,3 +38,6 @@ members = [
"examples/*",
"internals/*",
]

[patch.crates-io]
egui_wgpu_backend = { git = "https://github.com/Jengamon/egui_wgpu_backend.git", branch = "egui-0.16" }
2 changes: 1 addition & 1 deletion examples/custom-shader/shaders/noise.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn vs_main(

[[group(0), binding(0)]] var r_tex_color: texture_2d<f32>;
[[group(0), binding(1)]] var r_tex_sampler: sampler;
[[block]] struct Locals {
struct Locals {
time: f32;
};
[[group(0), binding(2)]] var<uniform> r_locals: Locals;
Expand Down
6 changes: 2 additions & 4 deletions examples/custom-shader/src/renderers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -139,6 +136,7 @@ impl NoiseRenderer {
write_mask: wgpu::ColorWrites::ALL,
}],
}),
multiview: None,
});

Self {
Expand Down
8 changes: 4 additions & 4 deletions examples/imgui-winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,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"
10 changes: 5 additions & 5 deletions examples/minimal-egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,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"
17 changes: 8 additions & 9 deletions examples/minimal-egui/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(
Expand Down Expand Up @@ -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();
}
})
});
Expand Down
1 change: 0 additions & 1 deletion examples/minimal-fltk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
4 changes: 3 additions & 1 deletion examples/minimal-sdl2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,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"
48 changes: 28 additions & 20 deletions examples/minimal-sdl2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,34 +25,36 @@ struct World {

fn main() -> Result<(), Box<dyn std::error::Error>> {
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
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ default = ["optimize"]
[dependencies]
log = "0.4"
pixels = { path = "../.." }
wgpu = "0.11"
wgpu = "0.12"
winit = "0.26"
winit_input_helper = "0.11"

Expand Down
2 changes: 1 addition & 1 deletion internals/pixels-mocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2021"
publish = false

[dependencies]
raw-window-handle = "0.3"
raw-window-handle = "0.4"
12 changes: 4 additions & 8 deletions internals/pixels-mocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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());
}
}
2 changes: 1 addition & 1 deletion shaders/scale.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct VertexOutput {
[[builtin(position)]] position: vec4<f32>;
};

[[block]] struct Locals {
struct Locals {
transform: mat4x4<f32>;
};
[[group(0), binding(2)]] var<uniform> r_locals: Locals;
Expand Down
26 changes: 17 additions & 9 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 {
R16Uint
| R16Sint
| R16Float
| R16Unorm
| R16Snorm
| Rg8Unorm
| Rg8Snorm
| Rg8Uint
Expand All @@ -438,6 +440,8 @@ const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 {
| Rg16Uint
| Rg16Sint
| Rg16Float
| Rg16Unorm
| Rg16Snorm
| Rgba8Unorm
| Rgba8UnormSrgb
| Rgba8Snorm
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down
8 changes: 3 additions & 5 deletions src/renderers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
},
Expand Down Expand Up @@ -159,6 +156,7 @@ impl ScalingRenderer {
write_mask: wgpu::ColorWrites::ALL,
}],
}),
multiview: None,
});

// Create clipping rectangle
Expand Down

0 comments on commit 2090e65

Please sign in to comment.