Skip to content

Commit

Permalink
Update wgpu to 0.13 (parasyte#300)
Browse files Browse the repository at this point in the history
* Intial work towards wgpu 0.13

* Increase MSRV for egui

* Add missing texture formats

* Update fermium

- Replaces beryllium with our own hand-rolled high-level abstraction
  layer for SDL2.

* Update dependencies

Co-authored-by: JMS55 <[email protected]>
  • Loading branch information
parasyte and JMS55 authored Aug 18, 2022
1 parent bcbe9d8 commit 051a523
Show file tree
Hide file tree
Showing 20 changed files with 242 additions and 110 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
rust:
- stable
- beta
- 1.60.0
- 1.61.0
steps:
- name: Checkout sources
uses: actions/checkout@v3
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
rust:
- stable
- beta
- 1.60.0
- 1.61.0
steps:
- name: Checkout sources
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ include = [
]

[dependencies]
bytemuck = "1.7"
bytemuck = "1.12"
raw-window-handle = "0.4"
thiserror = "1.0"
ultraviolet = "0.9"
wgpu = "0.12"
wgpu = "0.13"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
pollster = "0.2"
Expand Down
2 changes: 1 addition & 1 deletion MSRV.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

| `pixels` version | `rustc` version |
|------------------|-----------------|
| `0.10.0` | `1.60.0` |
| `0.10.0` | `1.61.0` |
| `0.9.0` | `1.57.0` |
| `0.8.0` | `1.52.0` |
| `0.7.0` | `1.52.0` |
Expand Down
2 changes: 1 addition & 1 deletion examples/conway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ optimize = ["log/release_max_level_warn"]
default = ["optimize"]

[dependencies]
byteorder = "1.3"
byteorder = "1.4"
env_logger = "0.9"
getrandom = "0.2"
line_drawing = "1.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-shader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ optimize = ["log/release_max_level_warn"]
default = ["optimize"]

[dependencies]
bytemuck = "1.7"
bytemuck = "1.10"
env_logger = "0.9"
log = "0.4"
pixels = { path = "../.." }
Expand Down
24 changes: 12 additions & 12 deletions examples/custom-shader/shaders/noise.wgsl
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Vertex shader bindings

struct VertexOutput {
[[location(0)]] tex_coord: vec2<f32>;
[[builtin(position)]] position: vec4<f32>;
};
@location(0) tex_coord: vec2<f32>,
@builtin(position) position: vec4<f32>,
}

[[stage(vertex)]]
@vertex
fn vs_main(
[[location(0)]] position: vec2<f32>,
@location(0) position: vec2<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.tex_coord = fma(position, vec2<f32>(0.5, -0.5), vec2<f32>(0.5, 0.5));
Expand All @@ -17,12 +17,12 @@ fn vs_main(

// Fragment shader bindings

[[group(0), binding(0)]] var r_tex_color: texture_2d<f32>;
[[group(0), binding(1)]] var r_tex_sampler: sampler;
@group(0) @binding(0) var r_tex_color: texture_2d<f32>;
@group(0) @binding(1) var r_tex_sampler: sampler;
struct Locals {
time: f32;
};
[[group(0), binding(2)]] var<uniform> r_locals: Locals;
time: f32,
}
@group(0) @binding(2) var<uniform> r_locals: Locals;

let tau: f32 = 6.283185307179586476925286766559;
let bias: f32 = 0.2376; // Offset the circular time input so it is never 0
Expand All @@ -40,8 +40,8 @@ fn random_vec2(st: vec2<f32>) -> f32 {
return random(dot(st, vec2<f32>(random_x, random_y)));
}

[[stage(fragment)]]
fn fs_main([[location(0)]] tex_coord: vec2<f32>) -> [[location(0)]] vec4<f32> {
@fragment
fn fs_main(@location(0) tex_coord: vec2<f32>) -> @location(0) vec4<f32> {
let sampled_color = textureSample(r_tex_color, r_tex_sampler, tex_coord);
let noise_color = vec3<f32>(random_vec2(tex_coord.xy * vec2<f32>(r_locals.time % tau + bias)));

Expand Down
10 changes: 5 additions & 5 deletions examples/custom-shader/src/renderers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl NoiseRenderer {
pub(crate) fn new(pixels: &pixels::Pixels, width: u32, height: u32) -> Self {
let device = pixels.device();
let shader = wgpu::include_wgsl!("../shaders/noise.wgsl");
let module = device.create_shader_module(&shader);
let module = device.create_shader_module(shader);

// Create a texture view that will be used as input
// This will be used as the render target for the default scaling renderer
Expand Down Expand Up @@ -127,14 +127,14 @@ impl NoiseRenderer {
fragment: Some(wgpu::FragmentState {
module: &module,
entry_point: "fs_main",
targets: &[wgpu::ColorTargetState {
targets: &[Some(wgpu::ColorTargetState {
format: pixels.render_texture_format(),
blend: Some(wgpu::BlendState {
color: wgpu::BlendComponent::REPLACE,
alpha: wgpu::BlendComponent::REPLACE,
}),
write_mask: wgpu::ColorWrites::ALL,
}],
})],
}),
multiview: None,
});
Expand Down Expand Up @@ -181,14 +181,14 @@ impl NoiseRenderer {
) {
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("NoiseRenderer render pass"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: render_target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: true,
},
}],
})],
depth_stencil_attachment: None,
});
rpass.set_pipeline(&self.render_pipeline);
Expand Down
2 changes: 1 addition & 1 deletion examples/imgui-winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ default = ["optimize"]
[dependencies]
env_logger = "0.9"
imgui = "0.8"
imgui-wgpu = "0.19"
imgui-wgpu = "0.20"
imgui-winit-support = { version = "0.8", default-features = false, features = ["winit-26"] }
log = "0.4"
pixels = { path = "../.." }
Expand Down
4 changes: 2 additions & 2 deletions examples/imgui-winit/src/gui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ impl Gui {
// Render Dear ImGui with WGPU
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("imgui"),
color_attachments: &[wgpu::RenderPassColorAttachment {
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: render_target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Load,
store: true,
},
}],
})],
depth_stencil_attachment: None,
});

Expand Down
6 changes: 3 additions & 3 deletions examples/minimal-egui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ optimize = ["log/release_max_level_warn"]
default = ["optimize"]

[dependencies]
egui = "0.18"
egui-wgpu = "0.18"
egui-winit = { version = "0.18", default-features = false, features = ["links"] }
egui = { git = "https://github.com/emilk/egui.git", rev = "38a67f86467f16084443258ae5e7761429c00db2" }
egui-wgpu = { git = "https://github.com/emilk/egui.git", rev = "38a67f86467f16084443258ae5e7761429c00db2" }
egui-winit = { git = "https://github.com/emilk/egui.git", rev = "38a67f86467f16084443258ae5e7761429c00db2", default-features = false, features = ["links"] }
env_logger = "0.9"
log = "0.4"
pixels = { path = "../.." }
Expand Down
13 changes: 11 additions & 2 deletions examples/minimal-egui/src/gui.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use egui::{ClippedPrimitive, Context, TexturesDelta};
use egui_wgpu::renderer::{RenderPass, ScreenDescriptor};
use pixels::{wgpu, PixelsContext};
use winit::event_loop::EventLoopWindowTarget;
use winit::window::Window;

/// Manages all state required for rendering egui over `Pixels`.
Expand All @@ -25,11 +26,19 @@ struct Gui {

impl Framework {
/// Create egui.
pub(crate) fn new(width: u32, height: u32, scale_factor: f32, pixels: &pixels::Pixels) -> Self {
pub(crate) fn new<T>(
event_loop: &EventLoopWindowTarget<T>,
width: u32,
height: u32,
scale_factor: f32,
pixels: &pixels::Pixels,
) -> Self {
let max_texture_size = pixels.device().limits().max_texture_dimension_2d as usize;

let egui_ctx = Context::default();
let egui_state = egui_winit::State::from_pixels_per_point(max_texture_size, scale_factor);
let mut egui_state = egui_winit::State::new(event_loop);
egui_state.set_max_texture_side(max_texture_size);
egui_state.set_pixels_per_point(scale_factor);
let screen_descriptor = ScreenDescriptor {
size_in_pixels: [width, height],
pixels_per_point: scale_factor,
Expand Down
9 changes: 7 additions & 2 deletions examples/minimal-egui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ fn main() -> Result<(), Error> {
let scale_factor = window.scale_factor() as f32;
let surface_texture = SurfaceTexture::new(window_size.width, window_size.height, &window);
let pixels = Pixels::new(WIDTH, HEIGHT, surface_texture)?;
let framework =
Framework::new(window_size.width, window_size.height, scale_factor, &pixels);
let framework = Framework::new(
&event_loop,
window_size.width,
window_size.height,
scale_factor,
&pixels,
);

(pixels, framework)
};
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal-fltk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ optimize = ["log/release_max_level_warn"]
default = ["optimize"]

[dependencies]
fltk = { version = "1.2", features = ["raw-window-handle", "no-images", "no-pango"] }
fltk = { version = "1.3", features = ["raw-window-handle", "no-images", "no-pango"] }
env_logger = "0.9"
log = "0.4"
pixels = { path = "../.." }
4 changes: 2 additions & 2 deletions examples/minimal-sdl2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ optimize = ["log/release_max_level_warn"]
default = ["optimize"]

[dependencies]
beryllium = { version = "0.7", features = ["use-raw-window-handle"] }
env_logger = "0.9"
fermium = { version = "20016.1.1", default-features = false }
fermium = { version = "20022.0.0", features = ["raw-window-handle"] }
log = "0.4"
pixels = { path = "../.." }
thiserror = "1.0"
zstring = "0.1"
28 changes: 8 additions & 20 deletions examples/minimal-sdl2/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#![deny(clippy::all)]
#![forbid(unsafe_code)]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

use beryllium::{
event::Event,
init::{InitFlags, Sdl},
window::WindowFlags,
};
use fermium::keycode;
use crate::sdl::{Event, Sdl};
use pixels::{Pixels, SurfaceTexture};
use zstring::zstr;

mod sdl;

const WIDTH: u32 = 320;
const HEIGHT: u32 = 240;
const BOX_SIZE: i16 = 64;
Expand All @@ -25,18 +21,12 @@ struct World {

fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
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 sdl = Sdl::new(zstr!("Hello Pixels"), WIDTH, HEIGHT)?;

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 (width, height) = sdl.drawable_size();
let surface_texture = SurfaceTexture::new(width, height, &sdl);
Pixels::new(WIDTH, HEIGHT, surface_texture)?
};
let mut world = World::new();
Expand All @@ -46,9 +36,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
match event {
// Close events
Event::Quit { .. } => break 'game_loop,
Event::Keyboard { keycode: key, .. } if key == keycode::SDLK_ESCAPE => {
break 'game_loop
}
Event::Keyboard(key) if key == fermium::keycode::SDLK_ESCAPE => break 'game_loop,

// Resize the window
Event::WindowResized { width, height, .. } => pixels.resize_surface(width, height),
Expand Down
Loading

0 comments on commit 051a523

Please sign in to comment.