Log improper image format uses (#3105)

This commit is contained in:
Marcin Mikołajczyk 2025-06-19 23:36:50 +02:00 committed by GitHub
parent 6d65ea7314
commit 612f340292
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 52 additions and 9 deletions

View file

@ -324,6 +324,9 @@ public:
return driver_id != vk::DriverId::eMoltenvk;
}
/// Determines if a format is supported for a set of feature flags.
[[nodiscard]] bool IsFormatSupported(vk::Format format, vk::FormatFeatureFlags2 flags) const;
private:
/// Creates the logical device opportunistically enabling extensions
bool CreateDevice();
@ -338,9 +341,6 @@ private:
/// Gets the supported feature flags for a format.
[[nodiscard]] vk::FormatFeatureFlags2 GetFormatFeatureFlags(vk::Format format) const;
/// Determines if a format is supported for a set of feature flags.
[[nodiscard]] bool IsFormatSupported(vk::Format format, vk::FormatFeatureFlags2 flags) const;
private:
vk::UniqueInstance instance;
vk::PhysicalDevice physical_device;

View file

@ -346,8 +346,15 @@ bool PipelineCache::RefreshGraphicsKey() {
col_buf.GetDataFmt() == AmdGpu::DataFormat::Format8_8 ||
col_buf.GetDataFmt() == AmdGpu::DataFormat::Format8_8_8_8);
key.color_formats[remapped_cb] =
const auto format =
LiverpoolToVK::SurfaceFormat(col_buf.GetDataFmt(), col_buf.GetNumberFmt());
key.color_formats[remapped_cb] = format;
if (!instance.IsFormatSupported(format, vk::FormatFeatureFlagBits2::eColorAttachment)) {
LOG_WARNING(Render_Vulkan,
"color buffer format {} does not support COLOR_ATTACHMENT_BIT",
vk::to_string(format));
}
key.color_buffers[remapped_cb] = Shader::PsColorBuffer{
.num_format = col_buf.GetNumberFmt(),
.num_conversion = col_buf.GetNumberConversion(),

View file

@ -130,10 +130,23 @@ Image::Image(const Vulkan::Instance& instance_, Vulkan::Scheduler& scheduler_,
constexpr auto tiling = vk::ImageTiling::eOptimal;
const auto supported_format = instance->GetSupportedFormat(info.pixel_format, format_features);
const auto properties = instance->GetPhysicalDevice().getImageFormatProperties(
supported_format, info.type, tiling, usage_flags, flags);
const auto supported_samples = properties.result == vk::Result::eSuccess
? properties.value.sampleCounts
const vk::PhysicalDeviceImageFormatInfo2 format_info{
.format = supported_format,
.type = info.type,
.tiling = tiling,
.usage = usage_flags,
.flags = flags,
};
const auto image_format_properties =
instance->GetPhysicalDevice().getImageFormatProperties2(format_info);
if (image_format_properties.result == vk::Result::eErrorFormatNotSupported) {
LOG_ERROR(Render_Vulkan, "image format {} type {} is not supported (flags {}, usage {})",
vk::to_string(supported_format), vk::to_string(info.type),
vk::to_string(format_info.flags), vk::to_string(format_info.usage));
}
const auto supported_samples =
image_format_properties.result == vk::Result::eSuccess
? image_format_properties.value.imageFormatProperties.sampleCounts
: vk::SampleCountFlagBits::e1;
const vk::ImageCreateInfo image_ci = {

View file

@ -29,6 +29,24 @@ vk::ImageViewType ConvertImageViewType(AmdGpu::ImageType type) {
}
}
bool IsViewTypeCompatible(vk::ImageViewType view_type, vk::ImageType image_type) {
switch (view_type) {
case vk::ImageViewType::e1D:
case vk::ImageViewType::e1DArray:
return image_type == vk::ImageType::e1D;
case vk::ImageViewType::e2D:
case vk::ImageViewType::e2DArray:
return image_type == vk::ImageType::e2D || image_type == vk::ImageType::e3D;
case vk::ImageViewType::eCube:
case vk::ImageViewType::eCubeArray:
return image_type == vk::ImageType::e2D;
case vk::ImageViewType::e3D:
return image_type == vk::ImageType::e3D;
default:
UNREACHABLE();
}
}
ImageViewInfo::ImageViewInfo(const AmdGpu::Image& image, const Shader::ImageResource& desc) noexcept
: is_storage{desc.is_written} {
const auto dfmt = image.GetDataFmt();
@ -106,6 +124,11 @@ ImageView::ImageView(const Vulkan::Instance& instance, const ImageViewInfo& info
.layerCount = info.range.extent.layers,
},
};
if (!IsViewTypeCompatible(image_view_ci.viewType, image.info.type)) {
LOG_ERROR(Render_Vulkan, "image view type {} is incompatible with image type {}",
vk::to_string(image_view_ci.viewType), vk::to_string(image.info.type));
}
auto [view_result, view] = instance.GetDevice().createImageViewUnique(image_view_ci);
ASSERT_MSG(view_result == vk::Result::eSuccess, "Failed to create image view: {}",
vk::to_string(view_result));