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

Dependency updates (wgpu 0.13) #289

Closed
wants to merge 11 commits into from
Closed
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
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.57.0
- 1.60.0
steps:
- name: Checkout sources
uses: actions/checkout@v2
Expand Down Expand Up @@ -73,7 +73,7 @@ jobs:
rust:
- stable
- beta
- 1.57.0
- 1.60.0
steps:
- name: Checkout sources
uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ include = [
]

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

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

| `pixels` version | `rustc` version |
|------------------|-----------------|
| `0.10.0` | `1.60.0` |
| `0.9.0` | `1.57.0` |
| `0.8.0` | `1.52.0` |
| `0.7.0` | `1.52.0` |
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ $ RUST_LOG=trace cargo run --package minimal-winit --release --no-default-featur
## Comparison with `minifb`

The [`minifb`](https://crates.io/crates/minifb) crate shares some similarities with `pixels`; it also allows rapid prototyping of 2D games and emulators. But it requires the use of its own window/GUI management, event loop, and input handling. One of the disadvantages with the `minifb` approach is the lack of hardware acceleration (except on macOS, which uses Metal but is not configurable). An advantage is that it relies on fewer dependencies.

## Comparison with `softbuffer`

There is a more recent project called [`softbuffer`](https://github.com/john01dav/softbuffer). It provides similar capabilities to what `pixels` offers, but is intentionally limited to software-only (not hardware-accelerated) rasterization.
4 changes: 2 additions & 2 deletions examples/conway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ 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"
log = "0.4"
pixels = { path = "../.." }
randomize = "3.0"
winit = "0.26"
winit_input_helper = "0.11"
winit_input_helper = "0.12"
4 changes: 2 additions & 2 deletions examples/conway/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn main() -> Result<(), Error> {
if input.key_pressed(VirtualKeyCode::P) {
paused = !paused;
}
if input.key_pressed(VirtualKeyCode::Space) {
if input.key_pressed_os(VirtualKeyCode::Space) {
// Space is frame-step, so ensure we're paused
paused = true;
}
Expand Down Expand Up @@ -127,7 +127,7 @@ fn main() -> Result<(), Error> {
if let Some(size) = input.window_resized() {
pixels.resize_surface(size.width, size.height);
}
if !paused || input.key_pressed(VirtualKeyCode::Space) {
if !paused || input.key_pressed_os(VirtualKeyCode::Space) {
life.update();
}
window.request_redraw();
Expand Down
4 changes: 2 additions & 2 deletions examples/custom-shader/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]
bytemuck = "1.7"
bytemuck = "1.10"
env_logger = "0.9"
log = "0.4"
pixels = { path = "../.." }
winit = "0.26"
winit_input_helper = "0.11"
winit_input_helper = "0.12"
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
4 changes: 2 additions & 2 deletions examples/custom-shader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ fn main() -> Result<(), Error> {
.unwrap()
};

let window_size = window.inner_size();
let mut pixels = {
let window_size = window.inner_size();
let surface_texture = SurfaceTexture::new(window_size.width, window_size.height, &window);
Pixels::new(WIDTH, HEIGHT, surface_texture)?
};
let mut world = World::new();
let mut time = 0.0;
let mut noise_renderer = NoiseRenderer::new(&pixels, WIDTH, HEIGHT);
let mut noise_renderer = NoiseRenderer::new(&pixels, window_size.width, window_size.height);

event_loop.run(move |event, _, control_flow| {
// Draw the current frame
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 @@ -177,14 +177,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
4 changes: 2 additions & 2 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.19"
imgui-wgpu = "0.20"
imgui-winit-support = { version = "0.8", default-features = false, features = ["winit-26"] }
log = "0.4"
pixels = { path = "../.." }
winit = "0.26"
winit_input_helper = "0.11"
winit_input_helper = "0.12"
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/invaders/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ default = ["optimize"]
[dependencies]
byteorder = "1.3"
env_logger = "0.9"
game-loop = { version = "0.8", features = ["window"] }
game-loop = { version = "0.9", features = ["window"] }
getrandom = "0.2"
gilrs = "0.8"
gilrs = "0.9"
log = "0.4"
pixels = { path = "../.." }
randomize = "3.0"
simple-invaders = { path = "simple-invaders" }
winit = "0.26"
winit_input_helper = "0.11"
winit_input_helper = "0.12"
2 changes: 1 addition & 1 deletion examples/invaders/simple-invaders/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ fn make_invader_grid(assets: &Assets) -> Vec<Vec<Option<Invader>>> {
}

fn next_invader<'a>(
invaders: &'a mut Vec<Vec<Option<Invader>>>,
invaders: &'a mut [Vec<Option<Invader>>],
stepper: &mut Point,
) -> (&'a mut Invader, bool) {
let mut is_leader = false;
Expand Down
56 changes: 23 additions & 33 deletions examples/invaders/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use pixels::{Error, Pixels, SurfaceTexture};
use simple_invaders::{Controls, Direction, World, FPS, HEIGHT, TIME_STEP, WIDTH};
use std::{env, time::Duration};
use winit::{
dpi::LogicalSize,
event::{Event, VirtualKeyCode},
event_loop::EventLoop,
window::WindowBuilder,
dpi::LogicalSize, event::VirtualKeyCode, event_loop::EventLoop, window::WindowBuilder,
};
use winit_input_helper::WinitInputHelper;

Expand All @@ -31,8 +28,6 @@ struct Game {
gamepad: Option<GamepadId>,
/// Game pause state.
paused: bool,
/// State for key edge detection.
held: [bool; 2],
}

impl Game {
Expand All @@ -45,14 +40,10 @@ impl Game {
gilrs: Gilrs::new().unwrap(), // XXX: Don't unwrap.
gamepad: None,
paused: false,
held: [false; 2],
}
}

fn update_controls(&mut self, event: &Event<()>) {
// Let winit_input_helper collect events to build its state.
self.input.update(event);

fn update_controls(&mut self) {
// Pump the gilrs event loop and find an active gamepad
while let Some(gilrs::Event { id, event, .. }) = self.gilrs.next_event() {
let pad = self.gilrs.gamepad(id);
Expand All @@ -67,25 +58,21 @@ impl Game {

self.controls = {
// Keyboard controls
let held = [
self.input.key_held(VirtualKeyCode::Pause),
self.input.key_held(VirtualKeyCode::P),
];

let mut left = self.input.key_held(VirtualKeyCode::Left);
let mut right = self.input.key_held(VirtualKeyCode::Right);
let mut fire = self.input.key_held(VirtualKeyCode::Space);
let mut pause = (held[0] ^ self.held[0] & held[0]) | (held[1] ^ self.held[1] & held[1]);

self.held = held;
let mut fire = self.input.key_pressed(VirtualKeyCode::Space);
let mut pause = self.input.key_pressed(VirtualKeyCode::Pause)
| self.input.key_pressed(VirtualKeyCode::P);

// GamePad controls
if let Some(id) = self.gamepad {
let gamepad = self.gilrs.gamepad(id);

left |= gamepad.is_pressed(Button::DPadLeft);
right |= gamepad.is_pressed(Button::DPadRight);
fire |= gamepad.is_pressed(Button::South);
fire |= gamepad.button_data(Button::South).map_or(false, |button| {
button.is_pressed() && button.counter() == self.gilrs.counter()
});
pause |= gamepad.button_data(Button::Start).map_or(false, |button| {
button.is_pressed() && button.counter() == self.gilrs.counter()
});
Expand Down Expand Up @@ -166,18 +153,21 @@ fn main() -> Result<(), Error> {
}
},
|g, event| {
// Update controls
g.game.update_controls(&event);

// Close events
if g.game.input.key_pressed(VirtualKeyCode::Escape) || g.game.input.quit() {
g.exit();
return;
}

// Resize the window
if let Some(size) = g.game.input.window_resized() {
g.game.pixels.resize_surface(size.width, size.height);
// Let winit_input_helper collect events to build its state.
if g.game.input.update(event) {
// Update controls
g.game.update_controls();

// Close events
if g.game.input.key_pressed(VirtualKeyCode::Escape) || g.game.input.quit() {
g.exit();
return;
}

// Resize the window
if let Some(size) = g.game.input.window_resized() {
g.game.pixels.resize_surface(size.width, size.height);
}
}
},
);
Expand Down
8 changes: 4 additions & 4 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.16"
egui_wgpu_backend = "0.16"
egui-winit = { version = "0.16", default-features = false, features = ["links"] }
egui = "0.18"
egui_wgpu_backend = "0.18"
egui-winit = { version = "0.18", default-features = false, features = ["links"] }
env_logger = "0.9"
log = "0.4"
pixels = { path = "../.." }
winit = "0.26"
winit_input_helper = "0.11"
winit_input_helper = "0.12"
Loading