From f3342fa680dc2d209f25ffc5995ed62c7cd37ff7 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Thu, 7 Nov 2024 10:29:40 +0100 Subject: [PATCH] Fix #129708: Vulkan: Add limit checks when creating images Drivers should perform a limit check when creating images and return `VK_ERROR_OUT_OF_DEVICE_MEMORY`. However there are drivers where this check is a pass-through and leads to `VK_ERROR_DEVICE_LOST`. This issue was introduced !128877 and only shows up on official NVIDIA drivers. Pull Request: https://projects.blender.org/blender/blender/pulls/129939 --- source/blender/gpu/vulkan/vk_texture.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/source/blender/gpu/vulkan/vk_texture.cc b/source/blender/gpu/vulkan/vk_texture.cc index 4fa4003a4f9..636a07f0d10 100644 --- a/source/blender/gpu/vulkan/vk_texture.cc +++ b/source/blender/gpu/vulkan/vk_texture.cc @@ -6,6 +6,8 @@ * \ingroup gpu */ +#include "GPU_capabilities.hh" + #include "vk_texture.hh" #include "vk_buffer.hh" @@ -450,12 +452,19 @@ bool VKTexture::allocate() BLI_assert(vk_image_ == VK_NULL_HANDLE); BLI_assert(!is_texture_view()); + VkExtent3D vk_extent = vk_extent_3d(0); + const uint32_t limit = (type_ == GPU_TEXTURE_3D) ? GPU_max_texture_3d_size() : + GPU_max_texture_size(); + if (vk_extent.depth > limit || vk_extent.height > limit || vk_extent.depth > limit) { + return false; + } + VKDevice &device = VKBackend::get().device; VkImageCreateInfo image_info = {}; image_info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; image_info.flags = to_vk_image_create(type_, format_flag_, usage_get()); image_info.imageType = to_vk_image_type(type_); - image_info.extent = vk_extent_3d(0); + image_info.extent = vk_extent; image_info.mipLevels = max_ii(mipmaps_, 1); image_info.arrayLayers = vk_layer_count(1); image_info.format = to_vk_format(device_format_);