radv: Use multiple dispatch tables for layers

Every layer has its own dispatch table that it can use to call down the
layer stack. This allows us to use RRA and RGP tracing simultaneously.
Using application layers with tracing should work as well.

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20439>
This commit is contained in:
Konstantin Seurer
2022-12-27 16:25:12 +01:00
committed by Marge Bot
parent 0821f76fd7
commit 124a405f6f
5 changed files with 82 additions and 38 deletions

View File

@@ -33,5 +33,6 @@ metro_exodus_GetSemaphoreCounterValue(VkDevice _device, VkSemaphore _semaphore,
return VK_SUCCESS;
}
return vk_common_GetSemaphoreCounterValue(_device, _semaphore, pValue);
RADV_FROM_HANDLE(radv_device, device, _device);
return device->layer_dispatch.app.GetSemaphoreCounterValue(_device, _semaphore, pValue);
}

View File

@@ -91,13 +91,13 @@ radv_rra_handle_trace(VkQueue _queue)
VKAPI_ATTR VkResult VKAPI_CALL
rra_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo)
{
VkResult result = wsi_QueuePresentKHR(_queue, pPresentInfo);
RADV_FROM_HANDLE(radv_queue, queue, _queue);
VkResult result = queue->device->layer_dispatch.rra.QueuePresentKHR(_queue, pPresentInfo);
if (result != VK_SUCCESS)
return result;
radv_rra_handle_trace(_queue);
RADV_FROM_HANDLE(radv_queue, queue, _queue);
struct hash_table *accel_structs = queue->device->rra_trace.accel_structs;
hash_table_foreach (accel_structs, entry) {
@@ -175,13 +175,13 @@ rra_CreateAccelerationStructureKHR(VkDevice _device,
const VkAllocationCallbacks *pAllocator,
VkAccelerationStructureKHR *pAccelerationStructure)
{
VkResult result =
radv_CreateAccelerationStructureKHR(_device, pCreateInfo, pAllocator, pAccelerationStructure);
RADV_FROM_HANDLE(radv_device, device, _device);
VkResult result = device->layer_dispatch.rra.CreateAccelerationStructureKHR(
_device, pCreateInfo, pAllocator, pAccelerationStructure);
if (result != VK_SUCCESS)
return result;
RADV_FROM_HANDLE(radv_device, device, _device);
RADV_FROM_HANDLE(radv_acceleration_structure, structure, *pAccelerationStructure);
simple_mtx_lock(&device->rra_trace.data_mtx);
@@ -218,7 +218,8 @@ fail_event:
fail_data:
free(data);
fail_as:
radv_DestroyAccelerationStructureKHR(_device, *pAccelerationStructure, pAllocator);
device->layer_dispatch.rra.DestroyAccelerationStructureKHR(_device, *pAccelerationStructure,
pAllocator);
*pAccelerationStructure = VK_NULL_HANDLE;
exit:
simple_mtx_unlock(&device->rra_trace.data_mtx);
@@ -279,8 +280,9 @@ rra_CmdBuildAccelerationStructuresKHR(
const VkAccelerationStructureBuildRangeInfoKHR *const *ppBuildRangeInfos)
{
RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer, commandBuffer);
cmd_buffer->device->layer_dispatch.rra.CmdBuildAccelerationStructuresKHR(
commandBuffer, infoCount, pInfos, ppBuildRangeInfos);
radv_CmdBuildAccelerationStructuresKHR(commandBuffer, infoCount, pInfos, ppBuildRangeInfos);
simple_mtx_lock(&cmd_buffer->device->rra_trace.data_mtx);
for (uint32_t i = 0; i < infoCount; ++i) {
RADV_FROM_HANDLE(radv_acceleration_structure, structure, pInfos[i].dstAccelerationStructure);
@@ -299,8 +301,8 @@ VKAPI_ATTR void VKAPI_CALL
rra_CmdCopyAccelerationStructureKHR(VkCommandBuffer commandBuffer,
const VkCopyAccelerationStructureInfoKHR *pInfo)
{
radv_CmdCopyAccelerationStructureKHR(commandBuffer, pInfo);
RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer, commandBuffer);
cmd_buffer->device->layer_dispatch.rra.CmdCopyAccelerationStructureKHR(commandBuffer, pInfo);
simple_mtx_lock(&cmd_buffer->device->rra_trace.data_mtx);
@@ -320,8 +322,9 @@ VKAPI_ATTR void VKAPI_CALL
rra_CmdCopyMemoryToAccelerationStructureKHR(VkCommandBuffer commandBuffer,
const VkCopyMemoryToAccelerationStructureInfoKHR *pInfo)
{
radv_CmdCopyMemoryToAccelerationStructureKHR(commandBuffer, pInfo);
RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer, commandBuffer);
cmd_buffer->device->layer_dispatch.rra.CmdCopyMemoryToAccelerationStructureKHR(commandBuffer,
pInfo);
simple_mtx_lock(&cmd_buffer->device->rra_trace.data_mtx);
@@ -358,5 +361,5 @@ rra_DestroyAccelerationStructureKHR(VkDevice _device, VkAccelerationStructureKHR
simple_mtx_unlock(&device->rra_trace.data_mtx);
radv_DestroyAccelerationStructureKHR(_device, _structure, pAllocator);
device->layer_dispatch.rra.DestroyAccelerationStructureKHR(_device, _structure, pAllocator);
}

View File

@@ -408,9 +408,10 @@ radv_handle_thread_trace(VkQueue _queue)
VKAPI_ATTR VkResult VKAPI_CALL
sqtt_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo)
{
RADV_FROM_HANDLE(radv_queue, queue, _queue);
VkResult result;
result = wsi_QueuePresentKHR(_queue, pPresentInfo);
result = queue->device->layer_dispatch.rgp.QueuePresentKHR(_queue, pPresentInfo);
if (result != VK_SUCCESS)
return result;
@@ -423,7 +424,7 @@ sqtt_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo)
RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer, commandBuffer); \
radv_write_begin_general_api_marker(cmd_buffer, ApiCmd##api_name); \
cmd_buffer->state.current_event_type = EventCmd##event_name; \
radv_Cmd##cmd_name(__VA_ARGS__); \
cmd_buffer->device->layer_dispatch.rgp.Cmd##cmd_name(__VA_ARGS__); \
cmd_buffer->state.current_event_type = EventInternalUnknown; \
radv_write_end_general_api_marker(cmd_buffer, ApiCmd##api_name);
@@ -683,7 +684,7 @@ sqtt_CmdCopyMemoryToAccelerationStructureKHR(VkCommandBuffer commandBuffer,
#define API_MARKER_ALIAS(cmd_name, api_name, ...) \
RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer, commandBuffer); \
radv_write_begin_general_api_marker(cmd_buffer, ApiCmd##api_name); \
radv_Cmd##cmd_name(__VA_ARGS__); \
cmd_buffer->device->layer_dispatch.rgp.Cmd##cmd_name(__VA_ARGS__); \
radv_write_end_general_api_marker(cmd_buffer, ApiCmd##api_name);
#define API_MARKER(cmd_name, ...) API_MARKER_ALIAS(cmd_name, cmd_name, __VA_ARGS__);
@@ -887,7 +888,7 @@ sqtt_CmdBeginDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer, commandBuffer);
radv_write_user_event_marker(cmd_buffer, UserEventPush, pLabelInfo->pLabelName);
vk_common_CmdBeginDebugUtilsLabelEXT(commandBuffer, pLabelInfo);
cmd_buffer->device->layer_dispatch.rgp.CmdBeginDebugUtilsLabelEXT(commandBuffer, pLabelInfo);
}
VKAPI_ATTR void VKAPI_CALL
@@ -896,7 +897,7 @@ sqtt_CmdEndDebugUtilsLabelEXT(VkCommandBuffer commandBuffer)
RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer, commandBuffer);
radv_write_user_event_marker(cmd_buffer, UserEventPop, NULL);
vk_common_CmdEndDebugUtilsLabelEXT(commandBuffer);
cmd_buffer->device->layer_dispatch.rgp.CmdEndDebugUtilsLabelEXT(commandBuffer);
}
VKAPI_ATTR void VKAPI_CALL
@@ -906,7 +907,7 @@ sqtt_CmdInsertDebugUtilsLabelEXT(VkCommandBuffer commandBuffer,
RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer, commandBuffer);
radv_write_user_event_marker(cmd_buffer, UserEventTrigger, pLabelInfo->pLabelName);
vk_common_CmdInsertDebugUtilsLabelEXT(commandBuffer, pLabelInfo);
cmd_buffer->device->layer_dispatch.rgp.CmdInsertDebugUtilsLabelEXT(commandBuffer, pLabelInfo);
}
/* Pipelines */
@@ -1103,8 +1104,8 @@ sqtt_CreateGraphicsPipelines(VkDevice _device, VkPipelineCache pipelineCache, ui
RADV_FROM_HANDLE(radv_device, device, _device);
VkResult result;
result = radv_CreateGraphicsPipelines(_device, pipelineCache, count, pCreateInfos, pAllocator,
pPipelines);
result = device->layer_dispatch.rgp.CreateGraphicsPipelines(
_device, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
if (result != VK_SUCCESS)
return result;
@@ -1137,8 +1138,8 @@ sqtt_CreateComputePipelines(VkDevice _device, VkPipelineCache pipelineCache, uin
RADV_FROM_HANDLE(radv_device, device, _device);
VkResult result;
result = radv_CreateComputePipelines(_device, pipelineCache, count, pCreateInfos, pAllocator,
pPipelines);
result = device->layer_dispatch.rgp.CreateComputePipelines(_device, pipelineCache, count,
pCreateInfos, pAllocator, pPipelines);
if (result != VK_SUCCESS)
return result;
@@ -1172,8 +1173,8 @@ sqtt_CreateRayTracingPipelinesKHR(VkDevice _device, VkDeferredOperationKHR defer
RADV_FROM_HANDLE(radv_device, device, _device);
VkResult result;
result = radv_CreateRayTracingPipelinesKHR(_device, deferredOperation, pipelineCache, count,
pCreateInfos, pAllocator, pPipelines);
result = device->layer_dispatch.rgp.CreateRayTracingPipelinesKHR(
_device, deferredOperation, pipelineCache, count, pCreateInfos, pAllocator, pPipelines);
if (result != VK_SUCCESS)
return result;
@@ -1210,7 +1211,7 @@ sqtt_DestroyPipeline(VkDevice _device, VkPipeline _pipeline,
radv_unregister_pipeline(device, pipeline);
radv_DestroyPipeline(_device, _pipeline, pAllocator);
device->layer_dispatch.rgp.DestroyPipeline(_device, _pipeline, pAllocator);
}
#undef API_MARKER

View File

@@ -3576,10 +3576,36 @@ radv_device_finish_perf_counter_lock_cs(struct radv_device *device)
free(device->perf_counter_lock_cs);
}
struct dispatch_table_builder {
struct vk_device_dispatch_table *tables[RADV_DISPATCH_TABLE_COUNT];
bool used[RADV_DISPATCH_TABLE_COUNT];
bool initialized[RADV_DISPATCH_TABLE_COUNT];
};
static void
add_entrypoints(struct dispatch_table_builder *b,
const struct vk_device_entrypoint_table *entrypoints,
enum radv_dispatch_table table)
{
for (int32_t i = table - 1; i >= RADV_DEVICE_DISPATCH_TABLE; i--) {
if (i == RADV_DEVICE_DISPATCH_TABLE || b->used[i]) {
vk_device_dispatch_table_from_entrypoints(b->tables[i], entrypoints, !b->initialized[i]);
b->initialized[i] = true;
}
}
if (table < RADV_DISPATCH_TABLE_COUNT)
b->used[table] = true;
}
static void
init_dispatch_tables(struct radv_device *device, struct radv_physical_device *physical_device)
{
struct vk_device_dispatch_table *dispatch_table = &device->vk.dispatch_table;
struct dispatch_table_builder b = {0};
b.tables[RADV_DEVICE_DISPATCH_TABLE] = &device->vk.dispatch_table;
b.tables[RADV_APP_DISPATCH_TABLE] = &device->layer_dispatch.app;
b.tables[RADV_RGP_DISPATCH_TABLE] = &device->layer_dispatch.rgp;
b.tables[RADV_RRA_DISPATCH_TABLE] = &device->layer_dispatch.rra;
if (physical_device->instance->vk.app_info.app_name &&
!strcmp(physical_device->instance->vk.app_info.app_name, "metroexodus")) {
@@ -3587,21 +3613,18 @@ init_dispatch_tables(struct radv_device *device, struct radv_physical_device *ph
* crashes sometimes. Workaround this game bug by enabling an internal layer. Remove this
* when the game is fixed.
*/
vk_device_dispatch_table_from_entrypoints(dispatch_table, &metro_exodus_device_entrypoints,
true);
vk_device_dispatch_table_from_entrypoints(dispatch_table, &radv_device_entrypoints, false);
} else if (radv_thread_trace_enabled()) {
vk_device_dispatch_table_from_entrypoints(dispatch_table, &sqtt_device_entrypoints, true);
vk_device_dispatch_table_from_entrypoints(dispatch_table, &radv_device_entrypoints, false);
} else if (radv_rra_trace_enabled() && radv_enable_rt(physical_device, false)) {
vk_device_dispatch_table_from_entrypoints(dispatch_table, &rra_device_entrypoints, true);
vk_device_dispatch_table_from_entrypoints(dispatch_table, &radv_device_entrypoints, false);
} else {
vk_device_dispatch_table_from_entrypoints(dispatch_table, &radv_device_entrypoints, true);
add_entrypoints(&b, &metro_exodus_device_entrypoints, RADV_APP_DISPATCH_TABLE);
}
vk_device_dispatch_table_from_entrypoints(dispatch_table, &wsi_device_entrypoints, false);
vk_device_dispatch_table_from_entrypoints(dispatch_table, &vk_common_device_entrypoints, false);
if (radv_thread_trace_enabled())
add_entrypoints(&b, &sqtt_device_entrypoints, RADV_RGP_DISPATCH_TABLE);
if (radv_rra_trace_enabled() && radv_enable_rt(physical_device, false))
add_entrypoints(&b, &rra_device_entrypoints, RADV_RRA_DISPATCH_TABLE);
add_entrypoints(&b, &radv_device_entrypoints, RADV_DISPATCH_TABLE_COUNT);
add_entrypoints(&b, &wsi_device_entrypoints, RADV_DISPATCH_TABLE_COUNT);
add_entrypoints(&b, &vk_common_device_entrypoints, RADV_DISPATCH_TABLE_COUNT);
}
VKAPI_ATTR VkResult VKAPI_CALL

View File

@@ -825,12 +825,28 @@ struct radv_rra_trace_data {
bool validate_as;
};
enum radv_dispatch_table {
RADV_DEVICE_DISPATCH_TABLE,
RADV_APP_DISPATCH_TABLE,
RADV_RGP_DISPATCH_TABLE,
RADV_RRA_DISPATCH_TABLE,
RADV_DISPATCH_TABLE_COUNT,
};
struct radv_layer_dispatch_tables {
struct vk_device_dispatch_table app;
struct vk_device_dispatch_table rgp;
struct vk_device_dispatch_table rra;
};
struct radv_device {
struct vk_device vk;
struct radv_instance *instance;
struct radeon_winsys *ws;
struct radv_layer_dispatch_tables layer_dispatch;
struct radeon_winsys_ctx *hw_ctx[RADV_NUM_HW_CTX];
struct radv_meta_state meta_state;