From 3711964f33625add10b486cdfe8cb37d12e5c85e Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Fri, 1 Mar 2024 11:17:07 +0100 Subject: [PATCH] panvk: do not handle illegal null The Vulkan spec says that VkBindBufferMemoryInfo::memory must be a valid VkDeviceMemory handle, see https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkBindBufferMemoryInfo-memory-parameter So let's assert instead here. Part-of: --- src/panfrost/vulkan/panvk_device.c | 54 +++++++++++------------------- 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/src/panfrost/vulkan/panvk_device.c b/src/panfrost/vulkan/panvk_device.c index 92927cfe759..52f426bd23e 100644 --- a/src/panfrost/vulkan/panvk_device.c +++ b/src/panfrost/vulkan/panvk_device.c @@ -1459,43 +1459,29 @@ panvk_BindBufferMemory2(VkDevice device, uint32_t bindInfoCount, VK_FROM_HANDLE(panvk_buffer, buffer, pBindInfos[i].buffer); struct pan_kmod_bo *old_bo = buffer->bo; - if (mem) { - buffer->bo = pan_kmod_bo_get(mem->bo); - buffer->dev_addr = mem->addr.dev + pBindInfos[i].memoryOffset; + assert(mem != NULL); - /* FIXME: Only host map for index buffers so we can do the min/max - * index retrieval on the CPU. This is all broken anyway and the - * min/max search should be done with a compute shader that also - * patches the job descriptor accordingly (basically an indirect draw). - * - * Make sure this goes away as soon as we fixed indirect draws. - */ - if (buffer->vk.usage & VK_BUFFER_USAGE_INDEX_BUFFER_BIT) { - VkDeviceSize offset = pBindInfos[i].memoryOffset; - VkDeviceSize pgsize = getpagesize(); - off_t map_start = offset & ~(pgsize - 1); - off_t map_end = offset + buffer->vk.size; - void *map_addr = - pan_kmod_bo_mmap(mem->bo, map_start, map_end - map_start, - PROT_WRITE, MAP_SHARED, NULL); + buffer->bo = pan_kmod_bo_get(mem->bo); + buffer->dev_addr = mem->addr.dev + pBindInfos[i].memoryOffset; - assert(map_addr != MAP_FAILED); - buffer->host_ptr = map_addr + (offset & pgsize); - } - } else { - buffer->bo = NULL; - buffer->dev_addr = 0; - buffer->host_ptr = NULL; - if (buffer->host_ptr) { - VkDeviceSize pgsize = getpagesize(); - uintptr_t map_start = (uintptr_t)buffer->host_ptr & ~(pgsize - 1); - uintptr_t map_end = (uintptr_t)buffer->host_ptr + buffer->vk.size; - ASSERTED int ret = - os_munmap((void *)map_start, map_end - map_start); + /* FIXME: Only host map for index buffers so we can do the min/max + * index retrieval on the CPU. This is all broken anyway and the + * min/max search should be done with a compute shader that also + * patches the job descriptor accordingly (basically an indirect draw). + * + * Make sure this goes away as soon as we fixed indirect draws. + */ + if (buffer->vk.usage & VK_BUFFER_USAGE_INDEX_BUFFER_BIT) { + VkDeviceSize offset = pBindInfos[i].memoryOffset; + VkDeviceSize pgsize = getpagesize(); + off_t map_start = offset & ~(pgsize - 1); + off_t map_end = offset + buffer->vk.size; + void *map_addr = + pan_kmod_bo_mmap(mem->bo, map_start, map_end - map_start, + PROT_WRITE, MAP_SHARED, NULL); - assert(!ret); - buffer->host_ptr = NULL; - } + assert(map_addr != MAP_FAILED); + buffer->host_ptr = map_addr + (offset & pgsize); } pan_kmod_bo_put(old_bo);