diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c index eaf94918b9a..90be3bdecb2 100644 --- a/src/gallium/frontends/lavapipe/lvp_device.c +++ b/src/gallium/frontends/lavapipe/lvp_device.c @@ -1527,6 +1527,8 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDevice( shstate.type = PIPE_SHADER_IR_NIR; shstate.ir.nir = b.shader; device->noop_fs = device->queue.ctx->create_fs_state(device->queue.ctx, &shstate); + _mesa_hash_table_init(&device->bda, NULL, _mesa_hash_pointer, _mesa_key_pointer_equal); + simple_mtx_init(&device->bda_lock, mtx_plain); *pDevice = lvp_device_to_handle(device); @@ -1544,6 +1546,9 @@ VKAPI_ATTR void VKAPI_CALL lvp_DestroyDevice( if (device->queue.last_fence) device->pscreen->fence_reference(device->pscreen, &device->queue.last_fence, NULL); + ralloc_free(device->bda.table); + simple_mtx_destroy(&device->bda_lock); + lvp_queue_finish(&device->queue); vk_device_finish(&device->vk); vk_free(&device->vk.alloc, device); diff --git a/src/gallium/frontends/lavapipe/lvp_image.c b/src/gallium/frontends/lavapipe/lvp_image.c index d796dca439f..41cf8651248 100644 --- a/src/gallium/frontends/lavapipe/lvp_image.c +++ b/src/gallium/frontends/lavapipe/lvp_image.c @@ -436,18 +436,31 @@ VKAPI_ATTR void VKAPI_CALL lvp_DestroyBuffer( if (!_buffer) return; + char *ptr = (char*)buffer->pmem + buffer->offset; + if (ptr) { + simple_mtx_lock(&device->bda_lock); + struct hash_entry *he = _mesa_hash_table_search(&device->bda, ptr); + if (he) + _mesa_hash_table_remove(&device->bda, he); + simple_mtx_unlock(&device->bda_lock); + } pipe_resource_reference(&buffer->bo, NULL); vk_object_base_finish(&buffer->base); vk_free2(&device->vk.alloc, pAllocator, buffer); } VKAPI_ATTR VkDeviceAddress VKAPI_CALL lvp_GetBufferDeviceAddress( - VkDevice device, + VkDevice _device, const VkBufferDeviceAddressInfo* pInfo) { + LVP_FROM_HANDLE(lvp_device, device, _device); LVP_FROM_HANDLE(lvp_buffer, buffer, pInfo->buffer); + char *ptr = (char*)buffer->pmem + buffer->offset; + simple_mtx_lock(&device->bda_lock); + _mesa_hash_table_insert(&device->bda, ptr, buffer); + simple_mtx_unlock(&device->bda_lock); - return (VkDeviceAddress)(uintptr_t)((char*)buffer->pmem + buffer->offset); + return (VkDeviceAddress)(uintptr_t)ptr; } VKAPI_ATTR uint64_t VKAPI_CALL lvp_GetBufferOpaqueCaptureAddress( diff --git a/src/gallium/frontends/lavapipe/lvp_private.h b/src/gallium/frontends/lavapipe/lvp_private.h index ca912ee0f69..97da27ba7e1 100644 --- a/src/gallium/frontends/lavapipe/lvp_private.h +++ b/src/gallium/frontends/lavapipe/lvp_private.h @@ -191,6 +191,8 @@ struct lvp_device { struct lvp_physical_device *physical_device; struct pipe_screen *pscreen; void *noop_fs; + simple_mtx_t bda_lock; + struct hash_table bda; bool poison_mem; bool print_cmds; };