Skip to content

Commit

Permalink
Allow vulkan to change view formats
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Jan 18, 2023
1 parent cecf063 commit b420759
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 1 deletion.
3 changes: 3 additions & 0 deletions wgpu-core/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,13 +852,15 @@ impl<A: HalApi> Device<A> {
));
}

let mut allow_different_view_format = false;
for format in desc.view_formats.iter() {
if desc.format == *format {
continue;
}
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
Expand Down Expand Up @@ -891,6 +893,7 @@ impl<A: HalApi> Device<A> {
format: desc.format,
usage: hal_usage,
memory_flags: hal::MemoryFlags::empty(),
allow_different_view_format,
};

let raw_texture = unsafe {
Expand Down
1 change: 1 addition & 0 deletions wgpu-hal/examples/halmark/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ impl<A: hal::Api> Example<A> {
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() };

Expand Down
3 changes: 3 additions & 0 deletions wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions wgpu-hal/src/vulkan/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,10 @@ impl crate::Device<super::Api> 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))
Expand Down

0 comments on commit b420759

Please sign in to comment.