lavapipe: add a mapping for BDA

when passing around BDA, it's important to be able to link the pointer
back to the pipe_resource since BDA doesn't have an explicit lifetime

this mapping enables cmds to receive a BDA pointer and then map it back
to a pipe_resource in order to avoid gymnastics with dynamically creating
pipe_resource objects which may or may not be able to be freed

Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23394>
This commit is contained in:
Mike Blumenkrantz
2023-05-31 11:59:25 -04:00
committed by Marge Bot
parent 2ac8ca7d72
commit ea9ded410a
3 changed files with 22 additions and 2 deletions
@@ -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);
+15 -2
View File
@@ -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(
@@ -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;
};