Skip to content

Commit

Permalink
update wgpu to v0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Jul 7, 2022
1 parent 71955be commit cac9fe7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static-rc = { version = "0.5", features = ["alloc"], default-features = false, o
criterion = { version = "0.3", features = ["cargo_bench_support", "html_reports"], default-features = false }
rand = { version = "0.8", features = ["std_rng"], default-features = false }
mimalloc = { version = "0.1", default-features = false }
wgpu = { version = "0.12", default-features = false }
wgpu = { version = "0.13", default-features = false }
futures = { version = "0.3", features = ["executor"], default-features = false }
pprof = { version = "0.8", features = ["criterion", "flamegraph"], default-features = false }
trybuild = { version = "1", default-features = false }
18 changes: 9 additions & 9 deletions tests/shaders/array_length.wgsl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
struct A {
array_length: u32;
array_length_call_ret_val: u32;
a: vec3<u32>;
[[align(16)]]
arr: array<u32>;
};
array_length: u32,
array_length_call_ret_val: u32,
a: vec3<u32>,
@align(16)
arr: array<u32>,
}

[[group(0), binding(0)]]
@group(0) @binding(0)
var<storage> in: A;

[[group(0), binding(1)]]
@group(0) @binding(1)
var<storage, read_write> out: A;

[[stage(compute), workgroup_size(1, 1, 1)]]
@compute @workgroup_size(1, 1, 1)
fn main() {
out.array_length = in.array_length;
out.a = in.a;
Expand Down
44 changes: 22 additions & 22 deletions tests/shaders/general.wgsl
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
struct A {
u: u32;
v: u32;
w: vec2<u32>;
[[size(16), align(8)]]
x: u32;
xx: u32;
};
u: u32,
v: u32,
w: vec2<u32>,
@size(16) @align(8)
x: u32,
xx: u32,
}

struct B {
a: vec2<u32>;
b: vec3<u32>;
c: u32;
d: u32;
[[align(16)]]
e: A;
f: vec3<u32>;
g: array<A, 3>;
h: i32;
[[align(32)]]
i: array<A>;
};
a: vec2<u32>,
b: vec3<u32>,
c: u32,
d: u32,
@align(16)
e: A,
f: vec3<u32>,
g: array<A, 3>,
h: i32,
@align(32)
i: array<A>,
}

[[group(0), binding(0)]]
@group(0) @binding(0)
var<storage> in: B;

[[group(0), binding(1)]]
@group(0) @binding(1)
var<storage, read_write> out: B;

[[stage(compute), workgroup_size(1, 1, 1)]]
@compute @workgroup_size(1, 1, 1)
fn main() {
out.a = in.a;
out.b = in.b;
Expand Down
11 changes: 5 additions & 6 deletions tests/wgpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn test_wgpu() {
assert_eq!(in_byte_buffer.len(), b.size().get() as _);

let shader = include_wgsl!("./shaders/general.wgsl");
let out_byte_buffer = in_out::<B, B>(&shader, &in_byte_buffer, false);
let out_byte_buffer = in_out::<B, B>(shader, &in_byte_buffer, false);

assert_eq!(in_byte_buffer, out_byte_buffer);

Expand Down Expand Up @@ -140,7 +140,7 @@ fn array_length() {
assert_eq!(in_byte_buffer.len(), in_value.size().get() as _);

let shader = include_wgsl!("./shaders/array_length.wgsl");
let out_byte_buffer = in_out::<A, A>(&shader, &in_byte_buffer, false);
let out_byte_buffer = in_out::<A, A>(shader, &in_byte_buffer, false);

assert_eq!(in_byte_buffer, out_byte_buffer);

Expand All @@ -151,7 +151,7 @@ fn array_length() {
}

fn in_out<IN: encase::ShaderType, OUT: encase::ShaderType>(
shader: &wgpu::ShaderModuleDescriptor,
shader: wgpu::ShaderModuleDescriptor,
data: &[u8],
is_uniform: bool,
) -> Vec<u8> {
Expand Down Expand Up @@ -246,16 +246,15 @@ fn in_out<IN: encase::ShaderType, OUT: encase::ShaderType>(
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor::default());
cpass.set_pipeline(&compute_pipeline);
cpass.set_bind_group(0, &bind_group, &[]);
cpass.dispatch(1, 1, 1);
cpass.dispatch_workgroups(1, 1, 1);
}

queue.submit(core::iter::once(encoder.finish()));

let output_slice = output_gpu_buffer.slice(..);
let output_future = output_slice.map_async(wgpu::MapMode::Read);
output_slice.map_async(wgpu::MapMode::Read, |_| {});

device.poll(wgpu::Maintain::Wait);
block_on(output_future).unwrap();

let output = output_slice.get_mapped_range().to_vec();
output_gpu_buffer.unmap();
Expand Down

0 comments on commit cac9fe7

Please sign in to comment.