wgpu: fix format mismatch for copies

This commit is contained in:
chyyran 2024-03-07 19:55:34 -05:00 committed by Ronny Chan
parent 7593f9f9b5
commit 9c895caa51
7 changed files with 26 additions and 71 deletions

8
Cargo.lock generated
View file

@ -3255,9 +3255,9 @@ checksum = "53a85b86a771b1c87058196170769dd264f66c0782acf1ae6cc51bfd64b39082"
[[package]] [[package]]
name = "wgpu" name = "wgpu"
version = "0.19.1" version = "0.19.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0bfe9a310dcf2e6b85f00c46059aaeaf4184caa8e29a1ecd4b7a704c3482332d" checksum = "a4b1213b52478a7631d6e387543ed8f642bc02c578ef4e3b49aca2a29a7df0cb"
dependencies = [ dependencies = [
"arrayvec", "arrayvec",
"cfg-if", "cfg-if",
@ -3350,9 +3350,9 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-types" name = "wgpu-types"
version = "0.19.0" version = "0.19.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "895fcbeb772bfb049eb80b2d6e47f6c9af235284e9703c96fc0218a42ffd5af2" checksum = "b671ff9fb03f78b46ff176494ee1ebe7d603393f42664be55b64dc8d53969805"
dependencies = [ dependencies = [
"bitflags 2.4.2", "bitflags 2.4.2",
"js-sys", "js-sys",

View file

@ -24,7 +24,7 @@ metal = ["icrate"]
[dependencies] [dependencies]
gl = { version = "0.14.0", optional = true } gl = { version = "0.14.0", optional = true }
ash = { version = "0.37", 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" num-traits = "0.2.15"
rustc-hash = "1.1.0" rustc-hash = "1.1.0"
halfbrown = "0.2.4" halfbrown = "0.2.4"

View file

@ -94,58 +94,6 @@ impl From<wgpu_types::Extent3d> for Size<u32> {
} }
} }
//
// impl From<Size<u32>> for vk::Extent2D {
// fn from(value: Size<u32>) -> Self {
// vk::Extent2D {
// width: value.width,
// height: value.height,
// }
// }
// }
//
//
// impl From<vk::Extent2D> for Size<u32> {
// fn from(value: vk::Extent2D) -> Self {
// Size {
// width: value.width,
// height: value.height,
// }
// }
// }
//
// impl From<vk::Viewport> for Size<u32> {
// fn from(value: vk::Viewport) -> Self {
// Size {
// width: value.width as u32,
// height: value.height as u32,
// }
// }
// }
//
// impl From<&vk::Viewport> for Size<u32> {
// fn from(value: &vk::Viewport) -> Self {
// Size {
// width: value.width as u32,
// height: value.height as u32,
// }
// }
// }
//
// impl From<Size<u32>> for vk::Viewport {
// fn from(value: Size<u32>) -> 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<FilterMode> for wgpu_types::FilterMode { impl From<FilterMode> for wgpu_types::FilterMode {
fn from(value: FilterMode) -> Self { fn from(value: FilterMode) -> Self {
match value { match value {

View file

@ -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-reflect = { path = "../librashader-reflect", version = "0.2.6", features = ["wgsl"], default-features = false }
librashader-runtime = { path = "../librashader-runtime" , version = "0.2.6" } 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" image = "0.24.7"
thiserror = "1.0.50" thiserror = "1.0.50"
bytemuck = { version = "1.14.0", features = ["derive"] } bytemuck = { version = "1.14.0", features = ["derive"] }

View file

@ -20,7 +20,7 @@ use std::sync::Arc;
use crate::buffer::WgpuStagedBuffer; use crate::buffer::WgpuStagedBuffer;
use crate::draw_quad::DrawQuad; 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_reflect::reflect::naga::{Naga, NagaLoweringOptions};
use librashader_runtime::framebuffer::FramebufferInit; use librashader_runtime::framebuffer::FramebufferInit;
use librashader_runtime::render_target::RenderTarget; use librashader_runtime::render_target::RenderTarget;
@ -157,7 +157,7 @@ impl FilterChainWgpu {
Arc::clone(&device), Arc::clone(&device),
Size::new(1, 1), Size::new(1, 1),
1, 1,
ImageFormat::R8G8B8A8Unorm, TextureFormat::Bgra8Unorm,
)) ))
}; };
let input_gen = || None; let input_gen = || None;

View file

@ -4,6 +4,7 @@ use librashader_common::{FilterMode, ImageFormat, Size, WrapMode};
use librashader_presets::Scale2D; use librashader_presets::Scale2D;
use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer, ViewportSize}; use librashader_runtime::scaling::{MipmapSize, ScaleFramebuffer, ViewportSize};
use std::sync::Arc; use std::sync::Arc;
use wgpu::TextureFormat;
pub struct OwnedImage { pub struct OwnedImage {
device: Arc<wgpu::Device>, device: Arc<wgpu::Device>,
@ -35,11 +36,8 @@ impl OwnedImage {
device: Arc<wgpu::Device>, device: Arc<wgpu::Device>,
size: Size<u32>, size: Size<u32>,
max_miplevels: u32, max_miplevels: u32,
format: ImageFormat, format: TextureFormat,
) -> Self { ) -> Self {
let format: Option<wgpu::TextureFormat> = format.into();
let format = format.unwrap_or(wgpu::TextureFormat::Rgba8Unorm);
let texture = device.create_texture(&wgpu::TextureDescriptor { let texture = device.create_texture(&wgpu::TextureDescriptor {
label: None, label: None,
size: size.into(), size: size.into(),
@ -78,16 +76,13 @@ impl OwnedImage {
pub fn scale( pub fn scale(
&mut self, &mut self,
scaling: Scale2D, scaling: Scale2D,
format: ImageFormat, format: TextureFormat,
viewport_size: &Size<u32>, viewport_size: &Size<u32>,
source_size: &Size<u32>, source_size: &Size<u32>,
original_size: &Size<u32>, original_size: &Size<u32>,
mipmap: bool, mipmap: bool,
) -> Size<u32> { ) -> Size<u32> {
let size = source_size.scale_viewport(scaling, *viewport_size, *original_size); let size = source_size.scale_viewport(scaling, *viewport_size, *original_size);
let format: Option<wgpu::TextureFormat> = format.into();
let format = format.unwrap_or(wgpu::TextureFormat::Rgba8Unorm);
if self.size != size if self.size != size
|| (mipmap && self.max_miplevels == 1) || (mipmap && self.max_miplevels == 1)
|| (!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( cmd.copy_texture_to_texture(
source.as_image_copy(), source.as_image_copy(),
self.image.as_image_copy(), self.image.as_image_copy(),
@ -149,6 +155,8 @@ impl ScaleFramebuffer for OwnedImage {
should_mipmap: bool, should_mipmap: bool,
_context: &Self::Context, _context: &Self::Context,
) -> Result<Size<u32>, Self::Error> { ) -> Result<Size<u32>, Self::Error> {
let format: Option<wgpu::TextureFormat> = format.into();
let format = format.unwrap_or(TextureFormat::Bgra8Unorm);
Ok(self.scale( Ok(self.scale(
scaling, scaling,
format, format,

View file

@ -123,8 +123,7 @@ impl<'a> State<'a> {
// ) // )
// .unwrap(); // .unwrap();
// //
let preset = let preset = ShaderPreset::try_parse("../test/shaders_slang/test/history.slangp").unwrap();
ShaderPreset::try_parse("../test/shaders_slang/crt/crt-royale.slangp").unwrap();
// let preset = ShaderPreset::try_parse( // let preset = ShaderPreset::try_parse(
// "../test/shaders_slang/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp", // "../test/shaders_slang/bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp",