Update wgpu to 0.15 (#332)
* Update wgpu to 0.15 * Fix the panic described in #330 * Specify `min_binding_size` since we know what it is.
This commit is contained in:
parent
bf296a455e
commit
332a02f12d
580
Cargo.lock
generated
580
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -24,10 +24,10 @@ bytemuck = "1.12"
|
|||
raw-window-handle = "0.5"
|
||||
thiserror = "1.0"
|
||||
ultraviolet = "0.9"
|
||||
wgpu = "0.14"
|
||||
wgpu = "0.15"
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
wgpu = { version = "0.14", features = ["webgl"] }
|
||||
wgpu = { version = "0.15", features = ["webgl"] }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
pollster = "0.2"
|
||||
|
|
|
@ -24,13 +24,13 @@ struct Locals {
|
|||
}
|
||||
@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
|
||||
const tau: f32 = 6.283185307179586476925286766559;
|
||||
const bias: f32 = 0.2376; // Offset the circular time input so it is never 0
|
||||
|
||||
// Random functions based on https://thebookofshaders.com/10/
|
||||
let random_scale: f32 = 43758.5453123;
|
||||
let random_x: f32 = 12.9898;
|
||||
let random_y: f32 = 78.233;
|
||||
const random_scale: f32 = 43758.5453123;
|
||||
const random_x: f32 = 12.9898;
|
||||
const random_y: f32 = 78.233;
|
||||
|
||||
fn random(x: f32) -> f32 {
|
||||
return fract(sin(x) * random_scale);
|
||||
|
|
|
@ -101,7 +101,7 @@ impl NoiseRenderer {
|
|||
ty: wgpu::BindingType::Buffer {
|
||||
ty: wgpu::BufferBindingType::Uniform,
|
||||
has_dynamic_offset: false,
|
||||
min_binding_size: None,
|
||||
min_binding_size: wgpu::BufferSize::new(std::mem::size_of::<f32>() as u64),
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
|
@ -229,6 +229,10 @@ fn create_texture_view(
|
|||
dimension: wgpu::TextureDimension::D2,
|
||||
format: pixels.render_texture_format(),
|
||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||
view_formats: &[
|
||||
pixels.render_texture_format().add_srgb_suffix(),
|
||||
pixels.render_texture_format().remove_srgb_suffix(),
|
||||
],
|
||||
};
|
||||
|
||||
Ok(device
|
||||
|
|
|
@ -11,10 +11,14 @@ default = ["optimize"]
|
|||
|
||||
[dependencies]
|
||||
env_logger = "0.10"
|
||||
imgui = "0.9"
|
||||
imgui-wgpu = "0.21"
|
||||
imgui-winit-support = "0.9"
|
||||
imgui = "0.10"
|
||||
# imgui-wgpu = "0.21"
|
||||
imgui-winit-support = "0.10"
|
||||
log = "0.4"
|
||||
pixels = { path = "../.." }
|
||||
winit = "0.27"
|
||||
winit_input_helper = "0.13"
|
||||
|
||||
[dependencies.imgui-wgpu]
|
||||
git = "https://github.com/Yatekii/imgui-wgpu-rs.git"
|
||||
rev = "1355ebf8181bc51aea4dbd2009ea124f5da90542"
|
||||
|
|
|
@ -10,11 +10,23 @@ optimize = ["log/release_max_level_warn"]
|
|||
default = ["optimize"]
|
||||
|
||||
[dependencies]
|
||||
egui = "0.20"
|
||||
egui-wgpu = "0.20"
|
||||
egui-winit = { version = "0.20", default-features = false, features = ["links"] }
|
||||
# egui = "0.20"
|
||||
# egui-wgpu = "0.20"
|
||||
# egui-winit = { version = "0.20", default-features = false, features = ["links"] }
|
||||
env_logger = "0.10"
|
||||
log = "0.4"
|
||||
pixels = { path = "../.." }
|
||||
winit = "0.27"
|
||||
winit_input_helper = "0.13"
|
||||
|
||||
[dependencies.egui]
|
||||
git = "https://github.com/emilk/egui.git"
|
||||
rev = "f222ee044edf8beebfaf5dd7be15c9f318f20886"
|
||||
|
||||
[dependencies.egui-wgpu]
|
||||
git = "https://github.com/emilk/egui.git"
|
||||
rev = "f222ee044edf8beebfaf5dd7be15c9f318f20886"
|
||||
|
||||
[dependencies.egui-winit]
|
||||
git = "https://github.com/emilk/egui.git"
|
||||
rev = "f222ee044edf8beebfaf5dd7be15c9f318f20886"
|
||||
|
|
|
@ -13,4 +13,4 @@ default = ["optimize"]
|
|||
env_logger = "0.10"
|
||||
log = "0.4"
|
||||
pixels = { path = "../.." }
|
||||
tao = "0.15"
|
||||
tao = "0.17"
|
||||
|
|
|
@ -254,10 +254,13 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle>
|
|||
///
|
||||
/// Returns an error when a [`wgpu::Adapter`] cannot be found.
|
||||
async fn build_impl(self) -> Result<Pixels, Error> {
|
||||
let instance = wgpu::Instance::new(self.backend);
|
||||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||
backends: self.backend,
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
// TODO: Use `options.pixel_aspect_ratio` to stretch the scaled texture
|
||||
let surface = unsafe { instance.create_surface(self.surface_texture.window) };
|
||||
let surface = unsafe { instance.create_surface(self.surface_texture.window) }?;
|
||||
let compatible_surface = Some(&surface);
|
||||
let request_adapter_options = &self.request_adapter_options;
|
||||
let adapter = match wgpu::util::initialize_adapter_from_env(&instance, self.backend) {
|
||||
|
@ -290,16 +293,15 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle>
|
|||
..wgpu::DeviceDescriptor::default()
|
||||
});
|
||||
|
||||
let (device, queue) = adapter
|
||||
.request_device(&device_descriptor, None)
|
||||
.await
|
||||
.map_err(Error::DeviceNotFound)?;
|
||||
let (device, queue) = adapter.request_device(&device_descriptor, None).await?;
|
||||
|
||||
let surface_capabilities = surface.get_capabilities(&adapter);
|
||||
let present_mode = self.present_mode;
|
||||
let surface_texture_format = self.surface_texture_format.unwrap_or_else(|| {
|
||||
*surface
|
||||
.get_supported_formats(&adapter)
|
||||
.first()
|
||||
*surface_capabilities
|
||||
.formats
|
||||
.iter()
|
||||
.find(|format| texture_format_is_srgb(**format))
|
||||
.unwrap_or(&wgpu::TextureFormat::Bgra8UnormSrgb)
|
||||
});
|
||||
let render_texture_format = self.render_texture_format.unwrap_or(surface_texture_format);
|
||||
|
@ -318,6 +320,7 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle>
|
|||
// Render texture values
|
||||
&surface_size,
|
||||
render_texture_format,
|
||||
// Clear color and blending values
|
||||
clear_color,
|
||||
blend_state,
|
||||
)?;
|
||||
|
@ -326,7 +329,7 @@ impl<'req, 'dev, 'win, W: HasRawWindowHandle + HasRawDisplayHandle>
|
|||
let mut pixels = Vec::with_capacity(pixels_buffer_size);
|
||||
pixels.resize_with(pixels_buffer_size, Default::default);
|
||||
|
||||
let alpha_mode = surface.get_supported_alpha_modes(&adapter)[0];
|
||||
let alpha_mode = surface_capabilities.alpha_modes[0];
|
||||
|
||||
// Instantiate the Pixels struct
|
||||
let context = PixelsContext {
|
||||
|
@ -461,6 +464,10 @@ pub(crate) fn create_backing_texture(
|
|||
dimension: wgpu::TextureDimension::D2,
|
||||
format: backing_texture_format,
|
||||
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
|
||||
view_formats: &[
|
||||
backing_texture_format.add_srgb_suffix(),
|
||||
backing_texture_format.remove_srgb_suffix(),
|
||||
],
|
||||
});
|
||||
let texture_view = texture.create_view(&wgpu::TextureViewDescriptor::default());
|
||||
|
||||
|
@ -486,6 +493,24 @@ pub(crate) fn create_backing_texture(
|
|||
))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
const fn texture_format_is_srgb(texture_format: wgpu::TextureFormat) -> bool {
|
||||
use wgpu::TextureFormat::*;
|
||||
|
||||
matches!(
|
||||
texture_format,
|
||||
Rgba8UnormSrgb
|
||||
| Bgra8UnormSrgb
|
||||
| Bc1RgbaUnormSrgb
|
||||
| Etc2Rgb8UnormSrgb
|
||||
| Etc2Rgb8A1UnormSrgb
|
||||
| Bc2RgbaUnormSrgb
|
||||
| Bc3RgbaUnormSrgb
|
||||
| Bc7RgbaUnormSrgb
|
||||
| Etc2Rgba8UnormSrgb
|
||||
)
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[inline]
|
||||
const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 {
|
||||
|
@ -507,7 +532,8 @@ const fn get_texture_format_size(texture_format: wgpu::TextureFormat) -> f32 {
|
|||
R8Unorm
|
||||
| R8Snorm
|
||||
| R8Uint
|
||||
| R8Sint => 1.0, // 8.0 / 8.0
|
||||
| R8Sint
|
||||
| Stencil8 => 1.0, // 8.0 / 8.0
|
||||
|
||||
// 16-bit formats, 8 bits per component
|
||||
R16Uint
|
||||
|
|
14
src/lib.rs
14
src/lib.rs
|
@ -118,10 +118,13 @@ pub enum Error {
|
|||
AdapterNotFound,
|
||||
/// Equivalent to [`wgpu::RequestDeviceError`]
|
||||
#[error("No wgpu::Device found.")]
|
||||
DeviceNotFound(wgpu::RequestDeviceError),
|
||||
DeviceNotFound(#[from] wgpu::RequestDeviceError),
|
||||
/// Equivalent to [`wgpu::SurfaceError`]
|
||||
#[error("The GPU failed to acquire a surface frame.")]
|
||||
Surface(wgpu::SurfaceError),
|
||||
Surface(#[from] wgpu::SurfaceError),
|
||||
/// Equivalent to [`wgpu::CreateSurfaceError`]
|
||||
#[error("Unable to create a surface.")]
|
||||
CreateSurface(#[from] wgpu::CreateSurfaceError),
|
||||
/// Equivalent to [`TextureError`]
|
||||
#[error("Texture creation failed: {0}")]
|
||||
InvalidTexture(#[from] TextureError),
|
||||
|
@ -457,8 +460,7 @@ impl Pixels {
|
|||
self.context.surface.get_current_texture()
|
||||
}
|
||||
err => Err(err),
|
||||
})
|
||||
.map_err(Error::Surface)?;
|
||||
})?;
|
||||
let mut encoder =
|
||||
self.context
|
||||
.device
|
||||
|
@ -510,6 +512,10 @@ impl Pixels {
|
|||
height: self.surface_size.height,
|
||||
present_mode: self.present_mode,
|
||||
alpha_mode: self.alpha_mode,
|
||||
view_formats: vec![
|
||||
self.surface_texture_format.add_srgb_suffix(),
|
||||
self.surface_texture_format.remove_srgb_suffix(),
|
||||
],
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ impl ScalingRenderer {
|
|||
ty: wgpu::BindingType::Buffer {
|
||||
ty: wgpu::BufferBindingType::Uniform,
|
||||
has_dynamic_offset: false,
|
||||
min_binding_size: None, // TODO: More efficient to specify this
|
||||
min_binding_size: wgpu::BufferSize::new(transform_bytes.len() as u64),
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
|
@ -230,10 +230,11 @@ impl ScalingMatrix {
|
|||
let (texture_width, texture_height) = texture_size;
|
||||
let (screen_width, screen_height) = screen_size;
|
||||
|
||||
let width_ratio = (screen_width / texture_width).max(1.0);
|
||||
let height_ratio = (screen_height / texture_height).max(1.0);
|
||||
|
||||
// Get smallest scale size
|
||||
let scale = (screen_width / texture_width)
|
||||
.clamp(1.0, screen_height / texture_height)
|
||||
.floor();
|
||||
let scale = width_ratio.clamp(1.0, height_ratio).floor();
|
||||
|
||||
let scaled_width = texture_width * scale;
|
||||
let scaled_height = texture_height * scale;
|
||||
|
|
Loading…
Reference in a new issue