From 0badf7d6be6970786eb48333074b2bc427c9f183 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 27 Jul 2017 15:04:25 -0700 Subject: [PATCH] anv/formats: Nicely handle unknown VkFormat enums --- src/intel/vulkan/anv_formats.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c index 3535c09..bb8cc72 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -251,6 +251,15 @@ static const struct anv_format anv_formats[] = { #undef fmt +static bool +format_supported(VkFormat vk_format) +{ + if (vk_format > ARRAY_SIZE(anv_formats)) + return false; + + return anv_formats[vk_format].isl_format != ISL_FORMAT_UNSUPPORTED; +} + /** * Exactly one bit must be set in \a aspect. */ @@ -258,10 +267,10 @@ struct anv_format anv_get_format(const struct gen_device_info *devinfo, VkFormat vk_format, VkImageAspectFlags aspect, VkImageTiling tiling) { - struct anv_format format = anv_formats[vk_format]; + if (!format_supported(vk_format)) + return anv_formats[VK_FORMAT_UNDEFINED]; - if (format.isl_format == ISL_FORMAT_UNSUPPORTED) - return format; + struct anv_format format = anv_formats[vk_format]; if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT) { assert(vk_format_aspects(vk_format) & VK_IMAGE_ASPECT_STENCIL_BIT); @@ -392,7 +401,7 @@ anv_physical_device_get_format_properties(struct anv_physical_device *physical_d gen += 5; VkFormatFeatureFlags linear = 0, tiled = 0, buffer = 0; - if (anv_formats[format].isl_format == ISL_FORMAT_UNSUPPORTED) { + if (!format_supported(format)) { /* Nothing to do here */ } else if (vk_format_is_depth_or_stencil(format)) { tiled |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT; @@ -489,7 +498,7 @@ anv_get_image_format_properties( uint32_t maxArraySize; VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT; - if (anv_formats[info->format].isl_format == ISL_FORMAT_UNSUPPORTED) + if (!format_supported(info->format)) goto unsupported; anv_physical_device_get_format_properties(physical_device, info->format, -- 2.5.0.400.gff86faf