Skip to content

Commit 2c3f9fa

Browse files
authored
Allow vulkan to change view formats (#3399)
1 parent e3ebb03 commit 2c3f9fa

File tree

5 files changed

+13
-1
lines changed

5 files changed

+13
-1
lines changed

wgpu-core/src/device/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,15 @@ impl<A: HalApi> Device<A> {
852852
));
853853
}
854854

855+
let mut allow_different_view_format = false;
855856
for format in desc.view_formats.iter() {
856857
if desc.format == *format {
857858
continue;
858859
}
859860
if desc.format.remove_srgb_suffix() != format.remove_srgb_suffix() {
860861
return Err(CreateTextureError::InvalidViewFormat(*format, desc.format));
861862
}
863+
allow_different_view_format = true;
862864
}
863865

864866
// Enforce having COPY_DST/DEPTH_STENCIL_WRIT/COLOR_TARGET otherwise we
@@ -891,6 +893,7 @@ impl<A: HalApi> Device<A> {
891893
format: desc.format,
892894
usage: hal_usage,
893895
memory_flags: hal::MemoryFlags::empty(),
896+
allow_different_view_format,
894897
};
895898

896899
let raw_texture = unsafe {

wgpu-hal/examples/halmark/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ impl<A: hal::Api> Example<A> {
299299
format: wgt::TextureFormat::Rgba8UnormSrgb,
300300
usage: hal::TextureUses::COPY_DST | hal::TextureUses::RESOURCE,
301301
memory_flags: hal::MemoryFlags::empty(),
302+
allow_different_view_format: false,
302303
};
303304
let texture = unsafe { device.create_texture(&texture_desc).unwrap() };
304305

wgpu-hal/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,9 @@ pub struct TextureDescriptor<'a> {
848848
pub format: wgt::TextureFormat,
849849
pub usage: TextureUses,
850850
pub memory_flags: MemoryFlags,
851+
/// Allows views of this texture to have a different format
852+
/// than the this texture does.
853+
pub allow_different_view_format: bool,
851854
}
852855

853856
/// TextureView descriptor.

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ impl PhysicalDeviceFeatures {
331331
| Df::DEPTH_TEXTURE_AND_BUFFER_COPIES
332332
| Df::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED
333333
| Df::UNRESTRICTED_INDEX_BUFFER
334-
| Df::INDIRECT_EXECUTION;
334+
| Df::INDIRECT_EXECUTION
335+
| Df::VIEW_FORMATS;
335336

336337
dl_flags.set(Df::CUBE_ARRAY_TEXTURES, self.core.image_cube_array != 0);
337338
dl_flags.set(Df::ANISOTROPIC_FILTERING, self.core.sampler_anisotropy != 0);

wgpu-hal/src/vulkan/device.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,10 @@ impl crate::Device<super::Api> for super::Device {
895895
raw_flags |= vk::ImageCreateFlags::CUBE_COMPATIBLE;
896896
}
897897

898+
if desc.allow_different_view_format {
899+
raw_flags |= vk::ImageCreateFlags::MUTABLE_FORMAT;
900+
}
901+
898902
let vk_info = vk::ImageCreateInfo::builder()
899903
.flags(raw_flags)
900904
.image_type(conv::map_texture_dimension(desc.dimension))

0 commit comments

Comments
 (0)