From e10618f6f5c6fa30e10be5a92fc8f92c4a897289 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Fri, 7 May 2021 13:34:52 +0200 Subject: [PATCH] lavapipe: report out-of-memory when binding This isn't the perfect error-code, but we don't really have anything better, it seems. The ideal fix here would be to fix LLVMpipe to support larger textures, but this is probably as far as I'm interested in chasing down this path for now. Reviewed-by: Adam Jackson Reviewed-by: Dave Airlie Part-of: --- src/gallium/drivers/llvmpipe/lp_texture.c | 6 ++++-- src/gallium/frontends/lavapipe/lvp_device.c | 14 ++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index c65a4bc5fae..1335b1ed9c4 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -852,10 +852,12 @@ static bool llvmpipe_resource_bind_backing(struct pipe_screen *screen, if (!lpr->backable) return FALSE; + if (llvmpipe_resource_is_texture(&lpr->base)) { + if (lpr->size_required > LP_MAX_TEXTURE_SIZE) + return FALSE; - if (llvmpipe_resource_is_texture(&lpr->base)) lpr->tex_data = (char *)pmem + offset; - else + } else lpr->data = (char *)pmem + offset; lpr->backing_offset = offset; diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index a153c190ad8..846abcd110d 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -1629,12 +1629,18 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_BindImageMemory2(VkDevice _device, } if (!did_bind) { + if (!device->pscreen->resource_bind_backing(device->pscreen, + image->bo, + mem->pmem, + bind_info->memoryOffset)) { + /* This is probably caused by the texture being too large, so let's + * report this as the *closest* allowed error-code. It's not ideal, + * but it's unlikely that anyone will care too much. + */ + return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY); + } image->pmem = mem->pmem; image->memory_offset = bind_info->memoryOffset; - device->pscreen->resource_bind_backing(device->pscreen, - image->bo, - mem->pmem, - bind_info->memoryOffset); } } return VK_SUCCESS;