From 2c3f9fabb74025b7ba35c32d6ff99eab2b2af418 Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Thu, 19 Jan 2023 08:20:15 -0500 Subject: [PATCH] Allow vulkan to change view formats (#3399) --- wgpu-core/src/device/mod.rs | 3 +++ wgpu-hal/examples/halmark/main.rs | 1 + wgpu-hal/src/lib.rs | 3 +++ wgpu-hal/src/vulkan/adapter.rs | 3 ++- wgpu-hal/src/vulkan/device.rs | 4 ++++ 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index a2cd64358..c913de6be 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -852,6 +852,7 @@ impl Device { )); } + let mut allow_different_view_format = false; for format in desc.view_formats.iter() { if desc.format == *format { continue; @@ -859,6 +860,7 @@ impl Device { if desc.format.remove_srgb_suffix() != format.remove_srgb_suffix() { return Err(CreateTextureError::InvalidViewFormat(*format, desc.format)); } + allow_different_view_format = true; } // Enforce having COPY_DST/DEPTH_STENCIL_WRIT/COLOR_TARGET otherwise we @@ -891,6 +893,7 @@ impl Device { format: desc.format, usage: hal_usage, memory_flags: hal::MemoryFlags::empty(), + allow_different_view_format, }; let raw_texture = unsafe { diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 849be37c6..6bcde926c 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -299,6 +299,7 @@ impl Example { format: wgt::TextureFormat::Rgba8UnormSrgb, usage: hal::TextureUses::COPY_DST | hal::TextureUses::RESOURCE, memory_flags: hal::MemoryFlags::empty(), + allow_different_view_format: false, }; let texture = unsafe { device.create_texture(&texture_desc).unwrap() }; diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 2654bddc0..6bb467fb2 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -848,6 +848,9 @@ pub struct TextureDescriptor<'a> { pub format: wgt::TextureFormat, pub usage: TextureUses, pub memory_flags: MemoryFlags, + /// Allows views of this texture to have a different format + /// than the this texture does. + pub allow_different_view_format: bool, } /// TextureView descriptor. diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 827f651c7..8d6f9f851 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -331,7 +331,8 @@ impl PhysicalDeviceFeatures { | Df::DEPTH_TEXTURE_AND_BUFFER_COPIES | Df::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED | Df::UNRESTRICTED_INDEX_BUFFER - | Df::INDIRECT_EXECUTION; + | Df::INDIRECT_EXECUTION + | Df::VIEW_FORMATS; dl_flags.set(Df::CUBE_ARRAY_TEXTURES, self.core.image_cube_array != 0); dl_flags.set(Df::ANISOTROPIC_FILTERING, self.core.sampler_anisotropy != 0); diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index dafd15f50..7627db919 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -895,6 +895,10 @@ impl crate::Device for super::Device { raw_flags |= vk::ImageCreateFlags::CUBE_COMPATIBLE; } + if desc.allow_different_view_format { + raw_flags |= vk::ImageCreateFlags::MUTABLE_FORMAT; + } + let vk_info = vk::ImageCreateInfo::builder() .flags(raw_flags) .image_type(conv::map_texture_dimension(desc.dimension))