Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow vulkan to change view formats #3399

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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