diff --git a/Cargo.lock b/Cargo.lock index 26193bd..e8fe12e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3255,9 +3255,9 @@ checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082" [[package]] name = "wgpu" -version = "0.19.1" +version = "0.19.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bfe9a310dcf2e6b85f00c46059aaeaf4184caa8e29a1ecd4b7a704c3482332d" +checksum = "a4b1213b52478a7631d6e387543ed8f642bc02c578ef4e3b49aca2a29a7df0cb" dependencies = [ "arrayvec", "cfg-if", @@ -3350,9 +3350,9 @@ dependencies = [ [[package]] name = "wgpu-types" -version = "0.19.0" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "895fcbeb772bfb049eb80b2d6e47f6c9af235284e9703c96fc0218a42ffd5af2" +checksum = "b671ff9fb03f78b46ff176494ee1ebe7d603393f42664be55b64dc8d53969805" dependencies = [ "bitflags 2.4.2", "js-sys", diff --git a/librashader-common/Cargo.toml b/librashader-common/Cargo.toml index b0a6ad9..d2eada6 100644 --- a/librashader-common/Cargo.toml +++ b/librashader-common/Cargo.toml @@ -24,7 +24,7 @@ metal = ["icrate"] [dependencies] gl = { version = "0.14.0", optional = true } ash = { version = "0.37", optional = true } -wgpu-types = { version = "0.19.0", optional = true } +wgpu-types = { version = "0.19.2", optional = true } num-traits = "0.2.15" rustc-hash = "1.1.0" halfbrown = "0.2.4" diff --git a/librashader-common/src/wgpu.rs b/librashader-common/src/wgpu.rs index 3a7398e..a8f1cb2 100644 --- a/librashader-common/src/wgpu.rs +++ b/librashader-common/src/wgpu.rs @@ -94,58 +94,6 @@ impl From for Size { } } -// -// impl From> for vk::Extent2D { -// fn from(value: Size) -> Self { -// vk::Extent2D { -// width: value.width, -// height: value.height, -// } -// } -// } -// - -// -// impl From for Size { -// fn from(value: vk::Extent2D) -> Self { -// Size { -// width: value.width, -// height: value.height, -// } -// } -// } -// -// impl From for Size { -// fn from(value: vk::Viewport) -> Self { -// Size { -// width: value.width as u32, -// height: value.height as u32, -// } -// } -// } -// -// impl From<&vk::Viewport> for Size { -// fn from(value: &vk::Viewport) -> Self { -// Size { -// width: value.width as u32, -// height: value.height as u32, -// } -// } -// } -// -// impl From> for vk::Viewport { -// fn from(value: Size) -> Self { -// vk::Viewport { -// x: 0.0, -// y: 0.0, -// width: value.width as f32, -// height: value.height as f32, -// min_depth: 0.0, -// max_depth: 1.0, -// } -// } -// } - impl From for wgpu_types::FilterMode { fn from(value: FilterMode) -> Self { match value { diff --git a/librashader-runtime-wgpu/Cargo.toml b/librashader-runtime-wgpu/Cargo.toml index 8cbc326..9a2ca2f 100644 --- a/librashader-runtime-wgpu/Cargo.toml +++ b/librashader-runtime-wgpu/Cargo.toml @@ -20,7 +20,7 @@ librashader-preprocess = { path = "../librashader-preprocess", version = "0.2.6" librashader-reflect = { path = "../librashader-reflect", version = "0.2.6", features = ["wgsl"], default-features = false } librashader-runtime = { path = "../librashader-runtime" , version = "0.2.6" } -wgpu = { version = "0.19.0", default-features = false, features = ["wgsl"] } +wgpu = { version = "0.19.3", default-features = false, features = ["wgsl"] } image = "0.24.7" thiserror = "1.0.50" bytemuck = { version = "1.14.0", features = ["derive"] } diff --git a/librashader-runtime-wgpu/src/filter_chain.rs b/librashader-runtime-wgpu/src/filter_chain.rs index a6c4614..0e36cb8 100644 --- a/librashader-runtime-wgpu/src/filter_chain.rs +++ b/librashader-runtime-wgpu/src/filter_chain.rs @@ -20,7 +20,7 @@ use std::sync::Arc; use crate::buffer::WgpuStagedBuffer; use crate::draw_quad::DrawQuad; -use librashader_common::{FilterMode, ImageFormat, Size, Viewport, WrapMode}; +use librashader_common::{FilterMode, Size, Viewport, WrapMode}; use librashader_reflect::reflect::naga::{Naga, NagaLoweringOptions}; use librashader_runtime::framebuffer::FramebufferInit; use librashader_runtime::render_target::RenderTarget; @@ -157,7 +157,7 @@ impl FilterChainWgpu { Arc::clone(&device), Size::new(1, 1), 1, - ImageFormat::R8G8B8A8Unorm, + TextureFormat::Bgra8Unorm, )) }; let input_gen = || None; diff --git a/librashader-runtime-wgpu/src/texture.rs b/librashader-runtime-wgpu/src/texture.rs index d90b2ea..c820c44 100644 --- a/librashader-runtime-wgpu/src/texture.rs +++ b/librashader-runtime-wgpu/src/texture.rs @@ -4,6 +4,7 @@ use librashader_common::{FilterMode, ImageFormat, Size, WrapMode}; use librashader_presets::Scale2D; use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer, ViewportSize}; use std::sync::Arc; +use wgpu::TextureFormat; pub struct OwnedImage { device: Arc, @@ -35,11 +36,8 @@ impl OwnedImage { device: Arc, size: Size, max_miplevels: u32, - format: ImageFormat, + format: TextureFormat, ) -> Self { - let format: Option = format.into(); - let format = format.unwrap_or(wgpu::TextureFormat::Rgba8Unorm); - let texture = device.create_texture(&wgpu::TextureDescriptor { label: None, size: size.into(), @@ -78,16 +76,13 @@ impl OwnedImage { pub fn scale( &mut self, scaling: Scale2D, - format: ImageFormat, + format: TextureFormat, viewport_size: &Size, source_size: &Size, original_size: &Size, mipmap: bool, ) -> Size { let size = source_size.scale_viewport(scaling, *viewport_size, *original_size); - let format: Option = format.into(); - let format = format.unwrap_or(wgpu::TextureFormat::Rgba8Unorm); - if self.size != size || (mipmap && self.max_miplevels == 1) || (!mipmap && self.max_miplevels != 1) @@ -114,7 +109,18 @@ impl OwnedImage { } } - pub fn copy_from(&self, cmd: &mut wgpu::CommandEncoder, source: &wgpu::Texture) { + pub fn copy_from(&mut self, cmd: &mut wgpu::CommandEncoder, source: &wgpu::Texture) { + let source_size = source.size().into(); + if source.format() != self.image.format() || self.size != source_size { + let mut new = OwnedImage::new( + Arc::clone(&self.device), + source_size, + self.max_miplevels, + source.format(), + ); + std::mem::swap(self, &mut new); + } + cmd.copy_texture_to_texture( source.as_image_copy(), self.image.as_image_copy(), @@ -149,6 +155,8 @@ impl ScaleFramebuffer for OwnedImage { should_mipmap: bool, _context: &Self::Context, ) -> Result, Self::Error> { + let format: Option = format.into(); + let format = format.unwrap_or(TextureFormat::Bgra8Unorm); Ok(self.scale( scaling, format, diff --git a/librashader-runtime-wgpu/tests/hello_triangle.rs b/librashader-runtime-wgpu/tests/hello_triangle.rs index 7579c93..979b559 100644 --- a/librashader-runtime-wgpu/tests/hello_triangle.rs +++ b/librashader-runtime-wgpu/tests/hello_triangle.rs @@ -123,8 +123,7 @@ impl<'a> State<'a> { // ) // .unwrap(); // - let preset = - ShaderPreset::try_parse("../test/shaders_slang/crt/crt-royale.slangp").unwrap(); + let preset = ShaderPreset::try_parse("../test/shaders_slang/test/history.slangp").unwrap(); // let preset = ShaderPreset::try_parse( // "../test/shaders_slang/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp",