summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2017-07-27 15:04:25 -0700
committerAndres Gomez <[email protected]>2017-09-06 18:05:10 +0300
commitf4266d73b54d821a63c97a94d7494e7689e5dc5a (patch)
tree2e0f7850bc636bf3ef6670524f816915a1b00805 /src
parent018e602dc629dfbda52b5c7711b5867d72ce33c8 (diff)
anv/formats: Nicely handle unknown VkFormat enums
This fixes some crashes in the dEQP-VK.memory.requirements.core.* tests. I'm not sure whether or not passing out-of-bound formats into the query is supposed to be allowed but there's no harm in protecting ourselves from it. Reviewed-by: Lionel Landwerlin <[email protected]> Bugzilla: https://bugs.freedesktop.org/101956 Cc: [email protected] (cherry picked from commit 242211933a06826961709c2689a1d30f735ab7b9) Squashed with: anv: fix off by one in array check `anv_formats[ARRAY_SIZE(anv_formats)]` is already one too far. Spotted by Coverity. CovID: 1417259 Fixes: 242211933a0682696170 "anv/formats: Nicely handle unknown VkFormat enums" Cc: Jason Ekstrand <[email protected]> Signed-off-by: Eric Engestrom <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]> Reviewed-by: Samuel Iglesias Gonsálvez <[email protected]> (cherry picked from commit 0c7272a66c633b0b11c0b81c0f3552201d083b3a)
Diffstat (limited to 'src')
-rw-r--r--src/intel/vulkan/anv_formats.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c
index b38fb35817c..659a6ba1b11 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);
@@ -397,7 +406,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;
@@ -495,7 +504,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,