vulkan: Improve format support info for vertex buffer formats. (#753)

This commit is contained in:
squidbus 2024-09-03 11:08:29 -07:00 committed by GitHub
parent cfe49fbfba
commit 6012e3cc86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 9 deletions

View file

@ -118,11 +118,15 @@ Instance::Instance(Frontend::WindowSDL& window, s32 physical_device_index,
// Check and log format support details.
for (const auto& key : format_properties | std::views::keys) {
const auto format = key;
if (!IsFormatSupported(format)) {
if (!IsImageFormatSupported(format)) {
const auto alternative = GetAlternativeFormat(format);
if (IsFormatSupported(alternative)) {
LOG_WARNING(Render_Vulkan, "Format {} is not supported, falling back to {}",
if (IsImageFormatSupported(alternative)) {
LOG_WARNING(Render_Vulkan,
"Format {} is not supported for images, falling back to {}.",
vk::to_string(format), vk::to_string(alternative));
} else if (IsVertexFormatSupported(format)) {
LOG_WARNING(Render_Vulkan, "Format {} is only supported for vertex buffers.",
vk::to_string(format));
} else {
LOG_ERROR(Render_Vulkan,
"Format {} is not supported and no suitable alternative is supported.",
@ -479,7 +483,7 @@ void Instance::CollectToolingInfo() {
}
}
bool Instance::IsFormatSupported(const vk::Format format) const {
bool Instance::IsImageFormatSupported(const vk::Format format) const {
if (format == vk::Format::eUndefined) [[unlikely]] {
return true;
}
@ -495,6 +499,20 @@ bool Instance::IsFormatSupported(const vk::Format format) const {
return (it->second.optimalTilingFeatures & optimal_flags) == optimal_flags;
}
bool Instance::IsVertexFormatSupported(const vk::Format format) const {
if (format == vk::Format::eUndefined) [[unlikely]] {
return true;
}
const auto it = format_properties.find(format);
if (it == format_properties.end()) {
UNIMPLEMENTED_MSG("Properties of format {} have not been queried.", vk::to_string(format));
}
constexpr vk::FormatFeatureFlags optimal_flags = vk::FormatFeatureFlagBits::eVertexBuffer;
return (it->second.bufferFeatures & optimal_flags) == optimal_flags;
}
vk::Format Instance::GetAlternativeFormat(const vk::Format format) const {
if (format == vk::Format::eB5G6R5UnormPack16) {
return vk::Format::eR5G6B5UnormPack16;
@ -505,11 +523,11 @@ vk::Format Instance::GetAlternativeFormat(const vk::Format format) const {
}
vk::Format Instance::GetSupportedFormat(const vk::Format format) const {
if (IsFormatSupported(format)) [[likely]] {
if (IsImageFormatSupported(format)) [[likely]] {
return format;
}
const vk::Format alternative = GetAlternativeFormat(format);
if (IsFormatSupported(alternative)) [[likely]] {
if (IsImageFormatSupported(alternative)) [[likely]] {
return alternative;
}
return format;
@ -517,7 +535,7 @@ vk::Format Instance::GetSupportedFormat(const vk::Format format) const {
vk::ComponentMapping Instance::GetSupportedComponentSwizzle(vk::Format format,
vk::ComponentMapping swizzle) const {
if (IsFormatSupported(format)) [[likely]] {
if (IsImageFormatSupported(format)) [[likely]] {
return swizzle;
}

View file

@ -227,8 +227,11 @@ private:
void CollectDeviceParameters();
void CollectToolingInfo();
/// Determines if a format is supported.
[[nodiscard]] bool IsFormatSupported(vk::Format format) const;
/// Determines if a format is supported for images.
[[nodiscard]] bool IsImageFormatSupported(vk::Format format) const;
/// Determines if a format is supported for vertex buffers.
[[nodiscard]] bool IsVertexFormatSupported(vk::Format format) const;
/// Gets a commonly available alternative for an unsupported pixel format.
vk::Format GetAlternativeFormat(const vk::Format format) const;