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

Bump raw window handle to 0.6.0 #4202

Merged
merged 52 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
baf15b9
dep: bumping raw-window-handle to 0.6
TornaxO7 Oct 3, 2023
5f82c02
updating some casts
TornaxO7 Oct 3, 2023
0f161dd
fixing more casts
TornaxO7 Oct 3, 2023
4ba013a
removing deprecated traits of `raw-window-handle`
TornaxO7 Oct 3, 2023
6d72872
fixing `DynContext::instance_create_surface`
TornaxO7 Oct 3, 2023
b33e096
Merge branch 'trunk' of github.com:gfx-rs/wgpu into bump_raw_window_h…
TornaxO7 Oct 3, 2023
5eef0dc
Merge branch 'trunk' of github.com:gfx-rs/wgpu into bump_raw_window_h…
TornaxO7 Oct 12, 2023
9d200d8
Merge branch 'trunk' of github.com:gfx-rs/wgpu into bump_raw_window_h…
TornaxO7 Oct 21, 2023
b63ff42
dependencies: bumping `winit` up to `0.29.2`
TornaxO7 Oct 21, 2023
9b99e72
fix: `examples/common/src/framework.rs`
TornaxO7 Oct 23, 2023
a5b8244
fix: `examples/uniform-values/src/main.rs`
TornaxO7 Oct 23, 2023
5676afb
fix: `examples/hello-windows/src/main.rs`
TornaxO7 Oct 23, 2023
c2c2346
fix: `examples/hello-triangle/src/main.rs`
TornaxO7 Oct 23, 2023
b99cab0
Merge branch 'trunk' of github.com:gfx-rs/wgpu into bump_raw_window_h…
TornaxO7 Oct 23, 2023
ddbbcc2
make `cargo clippy` happy
TornaxO7 Oct 23, 2023
6105633
`cargo fmt`
TornaxO7 Oct 23, 2023
025b20b
updating `wgpu-hal/Cargo.toml`, fix `wgpu-hal/examples/halmark/main.rs`
TornaxO7 Oct 23, 2023
76d3175
fix `wgpu-hal/examples/halmark/main.rs`
TornaxO7 Oct 23, 2023
81084f3
make `cargo clippy --all-targets` happy
TornaxO7 Oct 23, 2023
b0c44f7
Get and cast value from HWND
junglie85 Oct 24, 2023
6d0fa16
Merge pull request #1 from junglie85/winit_raw_window_handle_windows
TornaxO7 Oct 24, 2023
55ae059
winit: fix tests
TornaxO7 Oct 25, 2023
b2c475d
examples: removing scale-factor-changed-event from framework
TornaxO7 Oct 25, 2023
298b7db
Merge branch 'bump_raw_window_handle_to_6_0_0' of github.com:TornaxO7…
TornaxO7 Oct 25, 2023
f8002f4
example-framework: removing `resize_window` function
TornaxO7 Oct 25, 2023
a645c71
examples/bunnymark, examples/common/src/framework: refactor code
TornaxO7 Oct 25, 2023
b338b24
`cargo fmt`
TornaxO7 Oct 25, 2023
b5d4984
Merge branch 'trunk' of github.com:gfx-rs/wgpu into bump_raw_window_h…
TornaxO7 Oct 25, 2023
f44074e
updating `Cargo.lock`
TornaxO7 Oct 25, 2023
ec16a2f
examples/common/src/framework.rs: removing unused function
TornaxO7 Oct 25, 2023
1a3388d
player/src/bin/play.rs: fix `winit` feature code
TornaxO7 Oct 25, 2023
62a6928
`cargo fmt`
TornaxO7 Oct 25, 2023
0e8afde
`cargo fmt` and fix `cargo clippy --all-targets`
TornaxO7 Oct 25, 2023
57d3555
`cargo clippy`: ignoring `window` argument
TornaxO7 Oct 25, 2023
352fca1
examples/common/src/framework.rs: removing unused attribute `window`
TornaxO7 Oct 25, 2023
f3b76dd
Merge branch 'trunk' of github.com:gfx-rs/wgpu into bump_raw_window_h…
TornaxO7 Oct 26, 2023
d1410e4
Merge branch 'trunk' of github.com:gfx-rs/wgpu into bump_raw_window_h…
TornaxO7 Oct 26, 2023
edd5de2
naga/tests/wgsl-errors.rs: reverting `cargo clippy` suggestion
TornaxO7 Oct 26, 2023
1bc4108
fixing types
TornaxO7 Oct 26, 2023
30bc824
metal: updating types
TornaxO7 Oct 26, 2023
efff848
`cargo fmt`
TornaxO7 Oct 26, 2023
64820fb
ios: fixing types
TornaxO7 Oct 26, 2023
5c49a77
examples/src/framework, webassembly: add `.expect` for getting canvas
TornaxO7 Oct 26, 2023
67bc63b
examples/common/src/framework: removing mut
TornaxO7 Oct 26, 2023
a1dbf5f
`cargo fmt`
TornaxO7 Oct 26, 2023
cfec502
adding missing `expect`
TornaxO7 Oct 26, 2023
5968aaf
`cargo fmt`
TornaxO7 Oct 26, 2023
be89abc
adding missing `.unwrap()`
TornaxO7 Oct 26, 2023
8e1e834
Merge branch 'trunk' into bump_raw_window_handle_to_6_0_0
cwfitzgerald Oct 26, 2023
a606b72
Merge remote-tracking branch 'upstream/trunk' into bump_raw_window_ha…
cwfitzgerald Oct 27, 2023
d404cda
Fix Clippy Warning
cwfitzgerald Oct 27, 2023
be75a66
Make coverage failure not fail the job
cwfitzgerald Oct 27, 2023
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
654 changes: 549 additions & 105 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pico-args = { version = "0.5.0", features = [
png = "0.17.10"
pollster = "0.3"
profiling = { version = "1", default-features = false }
raw-window-handle = "0.5"
raw-window-handle = "0.6"
renderdoc-sys = "1.0.0"
ron = "0.8"
serde = "1"
Expand All @@ -123,7 +123,7 @@ wgpu-example = { version = "0.18.0", path = "./examples/common" }
wgpu-macros = { version = "0.18.0", path = "./wgpu-macros" }
wgpu-test = { version = "0.18.0", path = "./tests" }
wgpu-types = { version = "0.18.0", path = "./wgpu-types" }
winit = { version = "0.28.7", features = ["android-native-activity"] }
winit = { version = "0.29.2", features = [ "android-native-activity" ] }

# Metal dependencies
block = "0.1"
Expand Down
186 changes: 107 additions & 79 deletions examples/bunnymark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use bytemuck::{Pod, Zeroable};
use nanorand::{Rng, WyRand};
use std::{borrow::Cow, mem};
use wgpu::util::DeviceExt;
use winit::{
event::{ElementState, KeyEvent},
keyboard::{Key, NamedKey},
};

const MAX_BUNNIES: usize = 1 << 20;
const BUNNY_SIZE: f32 = 0.15 * 256.0;
Expand All @@ -18,24 +22,115 @@ struct Globals {

#[repr(C, align(256))]
#[derive(Clone, Copy, Zeroable)]
struct Locals {
struct Bunny {
position: [f32; 2],
velocity: [f32; 2],
color: u32,
_pad: u32,
}

impl Bunny {
fn update_data(&mut self, delta: f32, extent: &[u32; 2]) {
self.position[0] += self.velocity[0] * delta;
self.position[1] += self.velocity[1] * delta;
self.velocity[1] += GRAVITY * delta;
if (self.velocity[0] > 0.0 && self.position[0] + 0.5 * BUNNY_SIZE > extent[0] as f32)
|| (self.velocity[0] < 0.0 && self.position[0] - 0.5 * BUNNY_SIZE < 0.0)
{
self.velocity[0] *= -1.0;
}
if self.velocity[1] < 0.0 && self.position[1] < 0.5 * BUNNY_SIZE {
self.velocity[1] *= -1.0;
}
}
}

/// Example struct holds references to wgpu resources and frame persistent data
struct Example {
global_group: wgpu::BindGroup,
local_group: wgpu::BindGroup,
pipeline: wgpu::RenderPipeline,
bunnies: Vec<Locals>,
bunnies: Vec<Bunny>,
local_buffer: wgpu::Buffer,
extent: [u32; 2],
rng: WyRand,
}

impl Example {
cwfitzgerald marked this conversation as resolved.
Show resolved Hide resolved
fn spawn_bunnies(&mut self) {
let spawn_count = 64 + self.bunnies.len() / 2;
let color = self.rng.generate::<u32>();
println!(
"Spawning {} bunnies, total at {}",
spawn_count,
self.bunnies.len() + spawn_count
);
for _ in 0..spawn_count {
let speed = self.rng.generate::<f32>() * MAX_VELOCITY - (MAX_VELOCITY * 0.5);
self.bunnies.push(Bunny {
position: [0.0, 0.5 * (self.extent[1] as f32)],
velocity: [speed, 0.0],
color,
_pad: 0,
});
}
}

fn render_inner(
&mut self,
view: &wgpu::TextureView,
device: &wgpu::Device,
queue: &wgpu::Queue,
) {
let delta = 0.01;
for bunny in self.bunnies.iter_mut() {
bunny.update_data(delta, &self.extent);
}

let uniform_alignment = device.limits().min_uniform_buffer_offset_alignment;
queue.write_buffer(&self.local_buffer, 0, unsafe {
std::slice::from_raw_parts(
self.bunnies.as_ptr() as *const u8,
self.bunnies.len() * uniform_alignment as usize,
)
});

let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());
{
let clear_color = wgpu::Color {
r: 0.1,
g: 0.2,
b: 0.3,
a: 1.0,
};
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(clear_color),
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
rpass.set_pipeline(&self.pipeline);
rpass.set_bind_group(0, &self.global_group, &[]);
for i in 0..self.bunnies.len() {
let offset =
(i as wgpu::DynamicOffset) * (uniform_alignment as wgpu::DynamicOffset);
rpass.set_bind_group(1, &self.local_group, &[offset]);
rpass.draw(0..4, 0..1);
}
}

queue.submit(Some(encoder.finish()));
}
}

impl wgpu_example::framework::Example for Example {
fn init(
config: &wgpu::SurfaceConfiguration,
Expand Down Expand Up @@ -90,7 +185,7 @@ impl wgpu_example::framework::Example for Example {
ty: wgpu::BindingType::Buffer {
ty: wgpu::BufferBindingType::Uniform,
has_dynamic_offset: true,
min_binding_size: wgpu::BufferSize::new(mem::size_of::<Locals>() as _),
min_binding_size: wgpu::BufferSize::new(mem::size_of::<Bunny>() as _),
},
count: None,
}],
Expand Down Expand Up @@ -228,7 +323,7 @@ impl wgpu_example::framework::Example for Example {
resource: wgpu::BindingResource::Buffer(wgpu::BufferBinding {
buffer: &local_buffer,
offset: 0,
size: wgpu::BufferSize::new(mem::size_of::<Locals>() as _),
size: wgpu::BufferSize::new(mem::size_of::<Bunny>() as _),
}),
}],
label: None,
Expand All @@ -249,31 +344,16 @@ impl wgpu_example::framework::Example for Example {

fn update(&mut self, event: winit::event::WindowEvent) {
if let winit::event::WindowEvent::KeyboardInput {
input:
winit::event::KeyboardInput {
virtual_keycode: Some(winit::event::VirtualKeyCode::Space),
state: winit::event::ElementState::Pressed,
event:
KeyEvent {
logical_key: Key::Named(NamedKey::Space),
state: ElementState::Pressed,
..
},
..
} = event
{
let spawn_count = 64 + self.bunnies.len() / 2;
let color = self.rng.generate::<u32>();
println!(
"Spawning {} bunnies, total at {}",
spawn_count,
self.bunnies.len() + spawn_count
);
for _ in 0..spawn_count {
let speed = self.rng.generate::<f32>() * MAX_VELOCITY - (MAX_VELOCITY * 0.5);
self.bunnies.push(Locals {
position: [0.0, 0.5 * (self.extent[1] as f32)],
velocity: [speed, 0.0],
color,
_pad: 0,
});
}
self.spawn_bunnies();
}
}

Expand All @@ -287,63 +367,11 @@ impl wgpu_example::framework::Example for Example {
}

fn render(&mut self, view: &wgpu::TextureView, device: &wgpu::Device, queue: &wgpu::Queue) {
let delta = 0.01;
for bunny in self.bunnies.iter_mut() {
bunny.position[0] += bunny.velocity[0] * delta;
bunny.position[1] += bunny.velocity[1] * delta;
bunny.velocity[1] += GRAVITY * delta;
if (bunny.velocity[0] > 0.0
&& bunny.position[0] + 0.5 * BUNNY_SIZE > self.extent[0] as f32)
|| (bunny.velocity[0] < 0.0 && bunny.position[0] - 0.5 * BUNNY_SIZE < 0.0)
{
bunny.velocity[0] *= -1.0;
}
if bunny.velocity[1] < 0.0 && bunny.position[1] < 0.5 * BUNNY_SIZE {
bunny.velocity[1] *= -1.0;
}
}
self.spawn_bunnies();

let uniform_alignment = device.limits().min_uniform_buffer_offset_alignment;
queue.write_buffer(&self.local_buffer, 0, unsafe {
std::slice::from_raw_parts(
self.bunnies.as_ptr() as *const u8,
self.bunnies.len() * uniform_alignment as usize,
)
});

let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default());
{
let clear_color = wgpu::Color {
r: 0.1,
g: 0.2,
b: 0.3,
a: 1.0,
};
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(clear_color),
store: wgpu::StoreOp::Store,
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
rpass.set_pipeline(&self.pipeline);
rpass.set_bind_group(0, &self.global_group, &[]);
for i in 0..self.bunnies.len() {
let offset =
(i as wgpu::DynamicOffset) * (uniform_alignment as wgpu::DynamicOffset);
rpass.set_bind_group(1, &self.local_group, &[offset]);
rpass.draw(0..4, 0..1);
}
for _frame_number in 0..3 {
self.render_inner(view, device, queue);
}

queue.submit(Some(encoder.finish()));
}
}

Expand Down
Loading
Loading