radv: fix race condition when getting the blit queue

Cc: mesa-stable
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/14439
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
(cherry picked from commit a89118c5b0)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39003>
This commit is contained in:
Samuel Pitoiset 2025-12-10 09:44:42 +01:00 committed by Dylan Baker
parent cb7143572e
commit a6f2db03cd
4 changed files with 13 additions and 2 deletions

View file

@ -1394,7 +1394,7 @@
"description": "radv: fix race condition when getting the blit queue",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -1137,6 +1137,7 @@ radv_destroy_device(struct radv_device *device, const VkAllocationCallbacks *pAl
simple_mtx_destroy(&device->trace_mtx);
simple_mtx_destroy(&device->rt_handles_mtx);
simple_mtx_destroy(&device->pso_cache_stats_mtx);
simple_mtx_destroy(&device->blit_queue_mtx);
radv_destroy_shader_arenas(device);
if (device->capture_replay_arena_vas)
@ -1192,6 +1193,7 @@ radv_CreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCr
simple_mtx_init(&device->pstate_mtx, mtx_plain);
simple_mtx_init(&device->rt_handles_mtx, mtx_plain);
simple_mtx_init(&device->pso_cache_stats_mtx, mtx_plain);
simple_mtx_init(&device->blit_queue_mtx, mtx_plain);
device->rt_handles = _mesa_hash_table_create(NULL, _mesa_hash_u32, _mesa_key_u32_equal);

View file

@ -317,6 +317,8 @@ struct radv_device {
simple_mtx_t pso_cache_stats_mtx;
struct radv_pso_cache_stats pso_cache_stats[RADV_PIPELINE_TYPE_COUNT];
simple_mtx_t blit_queue_mtx;
struct radv_address_binding_tracker *addr_binding_tracker;
};

View file

@ -41,8 +41,12 @@ radv_wsi_get_prime_blit_queue(VkDevice _device)
struct radv_physical_device *pdev = radv_device_physical(device);
const struct radv_instance *instance = radv_physical_device_instance(pdev);
if (device->private_sdma_queue != VK_NULL_HANDLE)
simple_mtx_lock(&device->blit_queue_mtx);
if (device->private_sdma_queue != VK_NULL_HANDLE) {
simple_mtx_unlock(&device->blit_queue_mtx);
return &device->private_sdma_queue->vk;
}
if (pdev->info.gfx_level >= GFX9 && !(instance->debug_flags & RADV_DEBUG_NO_DMA_BLIT)) {
@ -58,12 +62,15 @@ radv_wsi_get_prime_blit_queue(VkDevice _device)
VkResult result = radv_queue_init(device, device->private_sdma_queue, 0, &queue_create, NULL);
if (result == VK_SUCCESS) {
simple_mtx_unlock(&device->blit_queue_mtx);
return &device->private_sdma_queue->vk;
} else {
vk_free(&device->vk.alloc, device->private_sdma_queue);
device->private_sdma_queue = VK_NULL_HANDLE;
}
}
simple_mtx_unlock(&device->blit_queue_mtx);
return NULL;
}