From: Chad Versace Date: Thu, 28 May 2015 14:40:22 +0000 (-0700) Subject: vk/image: Check extent does not exceed surface type limits X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fa352969a2ef1ebc65a29624aa0dde362c3b4367;p=mesa.git vk/image: Check extent does not exceed surface type limits --- diff --git a/src/vulkan/image.c b/src/vulkan/image.c index 2a441a47053..e2f8c4039b4 100644 --- a/src/vulkan/image.c +++ b/src/vulkan/image.c @@ -54,6 +54,19 @@ static const uint8_t anv_surf_type_from_image_view_type[] = { [VK_IMAGE_VIEW_TYPE_CUBE] = SURFTYPE_CUBE, }; +static const struct anv_surf_type_limits { + int32_t width; + int32_t height; + int32_t depth; +} anv_surf_type_limits[] = { + [SURFTYPE_1D] = {16384, 0, 2048}, + [SURFTYPE_2D] = {16384, 16384, 2048}, + [SURFTYPE_3D] = {2048, 2048, 2048}, + [SURFTYPE_CUBE] = {16384, 16384, 340}, + [SURFTYPE_BUFFER] = {128, 16384, 64}, + [SURFTYPE_STRBUF] = {128, 16384, 64}, +}; + static const struct anv_tile_info { uint32_t width; uint32_t height; @@ -132,6 +145,9 @@ VkResult anv_image_create( /* TODO(chadv): How should we validate inputs? */ image->surf_type = anv_surf_type_from_image_type[pCreateInfo->imageType]; + const struct anv_surf_type_limits *limits = + &anv_surf_type_limits[image->surf_type]; + assert(image->extent.width > 0); assert(image->extent.height > 0); assert(image->extent.depth > 0); @@ -139,6 +155,16 @@ VkResult anv_image_create( const struct anv_tile_info *tile_info = &anv_tile_info_table[image->tile_mode]; + if (image->extent.width > limits->width || + image->extent.height > limits->height || + image->extent.depth > limits->depth) { + anv_loge("image extent is too large"); + free(image); + + /* TODO(chadv): What is the correct error? */ + return vk_error(VK_ERROR_INVALID_MEMORY_SIZE); + } + image->alignment = tile_info->surface_alignment; /* FINISHME: Stop hardcoding miptree image alignment */