diff options
author | Lionel Landwerlin <[email protected]> | 2019-05-09 15:22:40 +0100 |
---|---|---|
committer | Juan A. Suarez Romero <[email protected]> | 2019-05-16 09:40:47 +0200 |
commit | d70d8b2ffa05e557470188573e7bb100cb148e78 (patch) | |
tree | b6f341d004264d294b8570eb24918958f48efd1b | |
parent | 558a067d1719c1a488d27fe6f0e22999575a5fe4 (diff) |
vulkan/overlay: fix truncating error on 32bit platforms
Non dispatchable handles can be uint64_t. When compiling the layer on
a 32bit platform, this will lead to casting uint64_t into (void *)
which is 32bit, leading to incorrect handles being mapped internally
in the layer.
v2: Use more HKEY() (Eric)
Signed-off-by: Lionel Landwerlin <[email protected]>
Reported-by: Józef Kucia <[email protected]>
Fixes: 2d2927938f074f ("vulkan/overlay-layer: fix cast errors")
Reviewed-by: Józef Kucia <[email protected]>
(cherry picked from commit 877b371cbb2c51cd569d8e5bb3f00ef6d9724336)
[Juan: resolve trivial conflicts]
Signed-off-by: Juan A. Suarez Romero <[email protected]>
Conflicts:
src/vulkan/overlay-layer/overlay.cpp
-rw-r--r-- | src/vulkan/overlay-layer/overlay.cpp | 76 |
1 files changed, 36 insertions, 40 deletions
diff --git a/src/vulkan/overlay-layer/overlay.cpp b/src/vulkan/overlay-layer/overlay.cpp index 4f9202eafe9..7d24c64886e 100644 --- a/src/vulkan/overlay-layer/overlay.cpp +++ b/src/vulkan/overlay-layer/overlay.cpp @@ -199,49 +199,45 @@ static const VkQueryPipelineStatisticFlags overlay_query_flags = VK_QUERY_PIPELINE_STATISTIC_COMPUTE_SHADER_INVOCATIONS_BIT; #define OVERLAY_QUERY_COUNT (11) -static struct hash_table *vk_object_to_data = NULL; +static struct hash_table_u64 *vk_object_to_data = NULL; static simple_mtx_t vk_object_to_data_mutex = _SIMPLE_MTX_INITIALIZER_NP; thread_local ImGuiContext* __MesaImGui; static inline void ensure_vk_object_map(void) { - if (!vk_object_to_data) { - vk_object_to_data = _mesa_hash_table_create(NULL, - _mesa_hash_pointer, - _mesa_key_pointer_equal); - } + if (!vk_object_to_data) + vk_object_to_data = _mesa_hash_table_u64_create(NULL); } -#define FIND_SWAPCHAIN_DATA(obj) ((struct swapchain_data *)find_object_data((void *) obj)) -#define FIND_CMD_BUFFER_DATA(obj) ((struct command_buffer_data *)find_object_data((void *) obj)) -#define FIND_DEVICE_DATA(obj) ((struct device_data *)find_object_data((void *) obj)) -#define FIND_QUEUE_DATA(obj) ((struct queue_data *)find_object_data((void *) obj)) -#define FIND_PHYSICAL_DEVICE_DATA(obj) ((struct instance_data *)find_object_data((void *) obj)) -#define FIND_INSTANCE_DATA(obj) ((struct instance_data *)find_object_data((void *) obj)) -static void *find_object_data(void *obj) +#define HKEY(obj) ((uint64_t)(obj)) +#define FIND_SWAPCHAIN_DATA(obj) ((struct swapchain_data *)find_object_data(HKEY(obj))) +#define FIND_CMD_BUFFER_DATA(obj) ((struct command_buffer_data *)find_object_data(HKEY(obj))) +#define FIND_DEVICE_DATA(obj) ((struct device_data *)find_object_data(HKEY(obj))) +#define FIND_QUEUE_DATA(obj) ((struct queue_data *)find_object_data(HKEY(obj))) +#define FIND_PHYSICAL_DEVICE_DATA(obj) ((struct instance_data *)find_object_data(HKEY(obj))) +#define FIND_INSTANCE_DATA(obj) ((struct instance_data *)find_object_data(HKEY(obj))) +static void *find_object_data(uint64_t obj) { simple_mtx_lock(&vk_object_to_data_mutex); ensure_vk_object_map(); - struct hash_entry *entry = _mesa_hash_table_search(vk_object_to_data, obj); - void *data = entry ? entry->data : NULL; + void *data = _mesa_hash_table_u64_search(vk_object_to_data, obj); simple_mtx_unlock(&vk_object_to_data_mutex); return data; } -static void map_object(void *obj, void *data) +static void map_object(uint64_t obj, void *data) { simple_mtx_lock(&vk_object_to_data_mutex); ensure_vk_object_map(); - _mesa_hash_table_insert(vk_object_to_data, obj, data); + _mesa_hash_table_u64_insert(vk_object_to_data, obj, data); simple_mtx_unlock(&vk_object_to_data_mutex); } -static void unmap_object(void *obj) +static void unmap_object(uint64_t obj) { simple_mtx_lock(&vk_object_to_data_mutex); - struct hash_entry *entry = _mesa_hash_table_search(vk_object_to_data, obj); - _mesa_hash_table_remove(vk_object_to_data, entry); + _mesa_hash_table_u64_remove(vk_object_to_data, obj); simple_mtx_unlock(&vk_object_to_data_mutex); } @@ -326,7 +322,7 @@ static struct instance_data *new_instance_data(VkInstance instance) { struct instance_data *data = rzalloc(NULL, struct instance_data); data->instance = instance; - map_object(data->instance, data); + map_object(HKEY(data->instance), data); return data; } @@ -334,7 +330,7 @@ static void destroy_instance_data(struct instance_data *data) { if (data->params.output_file) fclose(data->params.output_file); - unmap_object(data->instance); + unmap_object(HKEY(data->instance)); ralloc_free(data); } @@ -353,9 +349,9 @@ static void instance_data_map_physical_devices(struct instance_data *instance_da for (uint32_t i = 0; i < physicalDeviceCount; i++) { if (map) - map_object(physicalDevices[i], instance_data); + map_object(HKEY(physicalDevices[i]), instance_data); else - unmap_object(physicalDevices[i]); + unmap_object(HKEY(physicalDevices[i])); } free(physicalDevices); @@ -367,7 +363,7 @@ static struct device_data *new_device_data(VkDevice device, struct instance_data struct device_data *data = rzalloc(NULL, struct device_data); data->instance = instance; data->device = device; - map_object(data->device, data); + map_object(HKEY(data->device), data); return data; } @@ -383,7 +379,7 @@ static struct queue_data *new_queue_data(VkQueue queue, data->timestamp_mask = (1ull << family_props->timestampValidBits) - 1; data->family_index = family_index; LIST_INITHEAD(&data->running_command_buffer); - map_object(data->queue, data); + map_object(HKEY(data->queue), data); /* Fence synchronizing access to queries on that queue. */ VkFenceCreateInfo fence_info = {}; @@ -405,7 +401,7 @@ static void destroy_queue(struct queue_data *data) { struct device_data *device_data = data->device; device_data->vtable.DestroyFence(device_data->device, data->queries_fence, NULL); - unmap_object(data->queue); + unmap_object(HKEY(data->queue)); ralloc_free(data); } @@ -454,7 +450,7 @@ static void device_unmap_queues(struct device_data *data) static void destroy_device_data(struct device_data *data) { - unmap_object(data->device); + unmap_object(HKEY(data->device)); ralloc_free(data); } @@ -474,13 +470,13 @@ static struct command_buffer_data *new_command_buffer_data(VkCommandBuffer cmd_b data->timestamp_query_pool = timestamp_query_pool; data->query_index = query_index; list_inithead(&data->link); - map_object((void *) data->cmd_buffer, data); + map_object(HKEY(data->cmd_buffer), data); return data; } static void destroy_command_buffer_data(struct command_buffer_data *data) { - unmap_object((void *) data->cmd_buffer); + unmap_object(HKEY(data->cmd_buffer)); list_delinit(&data->link); ralloc_free(data); } @@ -495,13 +491,13 @@ static struct swapchain_data *new_swapchain_data(VkSwapchainKHR swapchain, data->swapchain = swapchain; data->window_size = ImVec2(instance_data->params.width, instance_data->params.height); list_inithead(&data->draws); - map_object((void *) data->swapchain, data); + map_object(HKEY(data->swapchain), data); return data; } static void destroy_swapchain_data(struct swapchain_data *data) { - unmap_object((void *) data->swapchain); + unmap_object(HKEY(data->swapchain)); ralloc_free(data); } @@ -2033,9 +2029,9 @@ static VkResult overlay_AllocateCommandBuffers( } if (pipeline_query_pool) - map_object((void *) pipeline_query_pool, (void *)(uintptr_t) pAllocateInfo->commandBufferCount); + map_object(HKEY(pipeline_query_pool), (void *)(uintptr_t) pAllocateInfo->commandBufferCount); if (timestamp_query_pool) - map_object((void *) timestamp_query_pool, (void *)(uintptr_t) pAllocateInfo->commandBufferCount); + map_object(HKEY(timestamp_query_pool), (void *)(uintptr_t) pAllocateInfo->commandBufferCount); return result; } @@ -2050,21 +2046,21 @@ static void overlay_FreeCommandBuffers( for (uint32_t i = 0; i < commandBufferCount; i++) { struct command_buffer_data *cmd_buffer_data = FIND_CMD_BUFFER_DATA(pCommandBuffers[i]); - uint64_t count = (uintptr_t)find_object_data((void *)cmd_buffer_data->pipeline_query_pool); + uint64_t count = (uintptr_t)find_object_data(HKEY(cmd_buffer_data->pipeline_query_pool)); if (count == 1) { - unmap_object((void *) cmd_buffer_data->pipeline_query_pool); + unmap_object(HKEY(cmd_buffer_data->pipeline_query_pool)); device_data->vtable.DestroyQueryPool(device_data->device, cmd_buffer_data->pipeline_query_pool, NULL); } else if (count != 0) { - map_object((void *) cmd_buffer_data->pipeline_query_pool, (void *)(uintptr_t)(count - 1)); + map_object(HKEY(cmd_buffer_data->pipeline_query_pool), (void *)(uintptr_t)(count - 1)); } - count = (uintptr_t)find_object_data((void *)cmd_buffer_data->timestamp_query_pool); + count = (uintptr_t)find_object_data(HKEY(cmd_buffer_data->timestamp_query_pool)); if (count == 1) { - unmap_object((void *) cmd_buffer_data->timestamp_query_pool); + unmap_object(HKEY(cmd_buffer_data->timestamp_query_pool)); device_data->vtable.DestroyQueryPool(device_data->device, cmd_buffer_data->timestamp_query_pool, NULL); } else if (count != 0) { - map_object((void *) cmd_buffer_data->timestamp_query_pool, (void *)(uintptr_t)(count - 1)); + map_object(HKEY(cmd_buffer_data->timestamp_query_pool), (void *)(uintptr_t)(count - 1)); } destroy_command_buffer_data(cmd_buffer_data); } |