Skip to content

Commit

Permalink
wgpu 0.19
Browse files Browse the repository at this point in the history
  • Loading branch information
pema99 committed Jan 24, 2024
1 parent dd1fe79 commit 95d8be1
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bytemuck = "1.7"
cfg-if = "1.0"
futures = { version = "0.3", default-features = false, features = ["executor"] }
image = { version = "0.24.6", default-features = false, optional = true }
wgpu = { version = "0.14", features = ["spirv"] }
wgpu = { version = "0.19.1", features = ["spirv"] }
ndarray = { version = "0.15", default-features = false, features = [
"std",
], optional = true }
Expand Down
2 changes: 1 addition & 1 deletion examples/image-compatibility/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
let pixel = textureLoad(input, coord, 0);

let dims = textureDimensions(input);
let mirror_coord = vec2<i32>(dims.x - coord.x, coord.y);
let mirror_coord = vec2<i32>(i32(dims.x) - coord.x, coord.y);

textureStore(output, mirror_coord, pixel);
}
2 changes: 1 addition & 1 deletion examples/mirror-image/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
let pixel = textureLoad(input, coord, 0);

let dims = textureDimensions(input);
let mirror_coord = vec2<i32>(dims.x - coord.x, coord.y);
let mirror_coord = vec2<i32>(i32(dims.x) - coord.x, coord.y);

textureStore(output, mirror_coord, pixel);
}
4 changes: 2 additions & 2 deletions examples/webcam/shader.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ struct Time {
@group(0) @binding(1) var output: texture_storage_2d<rgba8unorm, write>;
@group(0) @binding(2) var<uniform> time: Time;

let pi: f32 = 3.14159;
const pi: f32 = 3.14159;

@compute @workgroup_size(32, 32, 1)
fn main(@builtin(global_invocation_id) global_id: vec3<u32>) {
let coord = vec2<i32>(global_id.xy);
let pixel = textureLoad(input, coord, 0);

let dims = textureDimensions(input);
let mirror_coord = vec2<i32>(dims.x - coord.x, coord.y);
let mirror_coord = vec2<i32>(i32(dims.x) - coord.x, coord.y);

let t = pi * time.time;
let colour = vec4<f32>(sin(t), sin(0.25 * t), sin(0.5 * t), 1.0);
Expand Down
2 changes: 1 addition & 1 deletion src/features/integrate_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ where
GpuConstImage::from_bytes(
fw,
bytemuck::cast_slice(img),
width * Pixel::GpgpuPixel::byte_size() as u32,
width,
height,
)
}
Expand Down
13 changes: 7 additions & 6 deletions src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use crate::Framework;

impl Default for Framework {
fn default() -> Self {
let backend = wgpu::util::backend_bits_from_env().unwrap_or(wgpu::Backends::PRIMARY);
let power_preference = wgpu::util::power_preference_from_env()
.unwrap_or(wgpu::PowerPreference::HighPerformance);
let instance = wgpu::Instance::new(backend);
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
backends: wgpu::Backends::PRIMARY,
..Default::default()
});

log::debug!(
"Requesting device with {:#?} and {:#?}",
backend,
"Requesting device with {:#?}",
power_preference
);

Expand All @@ -38,8 +39,8 @@ impl Framework {
.request_device(
&wgpu::DeviceDescriptor {
label: None,
features: adapter.features(), // Change this to allow proper WebGL2 support (in the future™️).
limits: adapter.limits(), // Bye WebGL2 support :(
required_features: adapter.features(), // Change this to allow proper WebGL2 support (in the future™️).
required_limits: adapter.limits(), // Bye WebGL2 support :(
},
None,
)
Expand Down
1 change: 1 addition & 0 deletions src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ impl<'fw> Kernel<'fw> {
{
let mut cpass = encoder.begin_compute_pass(&wgpu::ComputePassDescriptor {
label: Some("Kernel::enqueue"),
timestamp_writes: None,
});

cpass.set_pipeline(&self.pipeline);
Expand Down
20 changes: 9 additions & 11 deletions src/primitives/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ where
sample_count: 1,
format,
usage: GPU_IMAGE_USAGES,
view_formats: &[format],
});

let full_view = texture.create_view(&wgpu::TextureViewDescriptor::default());
Expand Down Expand Up @@ -104,7 +105,9 @@ where
sample_count: 1,
format,
usage: GPU_IMAGE_USAGES,
view_formats: &[format],
},
wgpu::util::TextureDataOrder::LayerMajor,
data,
);

Expand Down Expand Up @@ -155,8 +158,6 @@ where
{
/// Pulls some elements from the [`GpuImage`] into `buf`, returning how many pixels were read.
pub async fn read(&self, buf: &mut [u8]) -> Result<usize, ImageOutputError> {
use std::num::NonZeroU32;

let (width, height) = self.dimensions();

let img_bytes = (width * height) as usize * P::byte_size();
Expand Down Expand Up @@ -201,7 +202,7 @@ where
buffer: &staging,
layout: wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: NonZeroU32::new(padded_bytes_per_row),
bytes_per_row: Option::Some(padded_bytes_per_row),
rows_per_image: None,
},
};
Expand Down Expand Up @@ -260,8 +261,6 @@ where
/// This function will attempt to write the entire contents of `buf`, unless its capacity
/// exceeds the one of the image, in which case the first `width * height` pixels are written.
pub fn write(&self, buf: &[u8]) -> Result<usize, ImageInputError> {
use std::num::NonZeroU32;

if buf.len() % P::byte_size() != 0 {
return Err(ImageInputError::NotIntegerPixelNumber);
}
Expand Down Expand Up @@ -290,8 +289,7 @@ where
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: Some(
NonZeroU32::new(P::byte_size() as u32 * self.size.width)
.expect("Could not create a NonZeroU32."),
P::byte_size() as u32 * self.size.width,
),
rows_per_image: None,
},
Expand Down Expand Up @@ -348,6 +346,7 @@ where
sample_count: 1,
format,
usage: GPU_CONST_IMAGE_USAGES,
view_formats: &[format],
});

let full_view = texture.create_view(&wgpu::TextureViewDescriptor::default());
Expand Down Expand Up @@ -380,7 +379,9 @@ where
sample_count: 1,
format,
usage: GPU_CONST_IMAGE_USAGES,
view_formats: &[format],
},
wgpu::util::TextureDataOrder::LayerMajor,
data,
);

Expand Down Expand Up @@ -433,8 +434,6 @@ where
/// This function will attempt to write the entire contents of `buf`, unless its capacity
/// exceeds the one of the image, in which case the first `width * height` pixels are written.
pub fn write(&self, buf: &[u8]) -> Result<usize, ImageInputError> {
use std::num::NonZeroU32;

if buf.len() % P::byte_size() != 0 {
return Err(ImageInputError::NotIntegerPixelNumber);
}
Expand Down Expand Up @@ -463,8 +462,7 @@ where
wgpu::ImageDataLayout {
offset: 0,
bytes_per_row: Some(
NonZeroU32::new(P::byte_size() as u32 * self.size.width)
.expect("Could not create a NonZeroU32."),
P::byte_size() as u32 * self.size.width,
),
rows_per_image: None,
},
Expand Down
2 changes: 1 addition & 1 deletion src/primitives/samplers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl Sampler {
lod_min_clamp: 0.0,
lod_max_clamp: std::f32::MAX,
compare: None,
anisotropy_clamp: None,
anisotropy_clamp: 1,
border_color: None,
});
Self {
Expand Down

0 comments on commit 95d8be1

Please sign in to comment.