Module: Mesa Branch: main Commit: 84cc494e51101ae71a407b137c6d611d3d9894db URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=84cc494e51101ae71a407b137c6d611d3d9894db
Author: Konstantin Seurer <konstantin.seu...@gmail.com> Date: Wed Dec 13 16:31:27 2023 +0100 radv/rmv: Fix tracing ray tracing pipelines Reviewed-by: Samuel Pitoiset <samuel.pitoi...@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26668> --- src/amd/vulkan/radv_pipeline_rt.c | 3 ++- src/amd/vulkan/radv_private.h | 2 ++ src/amd/vulkan/radv_rmv.c | 52 +++++++++++++++++++++++++++++++++++---- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/src/amd/vulkan/radv_pipeline_rt.c b/src/amd/vulkan/radv_pipeline_rt.c index 0023527d0e0..141ea1ea5d6 100644 --- a/src/amd/vulkan/radv_pipeline_rt.c +++ b/src/amd/vulkan/radv_pipeline_rt.c @@ -762,6 +762,7 @@ radv_rt_pipeline_create(VkDevice _device, VkPipelineCache _cache, const VkRayTra radv_pipeline_init(device, &pipeline->base.base, RADV_PIPELINE_RAY_TRACING); pipeline->base.base.create_flags = vk_rt_pipeline_create_flags(pCreateInfo); pipeline->stage_count = local_create_info.stageCount; + pipeline->non_imported_stage_count = pCreateInfo->stageCount; pipeline->group_count = local_create_info.groupCount; pipeline->stages = stages; pipeline->groups = groups; @@ -806,7 +807,7 @@ radv_rt_pipeline_create(VkDevice _device, VkPipelineCache _cache, const VkRayTra compile_rt_prolog(device, pipeline); radv_compute_pipeline_init(device, &pipeline->base, pipeline_layout, pipeline->prolog); - radv_rmv_log_compute_pipeline_create(device, &pipeline->base.base, false); + radv_rmv_log_rt_pipeline_create(device, pipeline); } if (!cache_hit) diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 6a7babef601..426593f8ac8 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -2149,6 +2149,7 @@ struct radv_ray_tracing_pipeline { struct radv_ray_tracing_stage *stages; struct radv_ray_tracing_group *groups; unsigned stage_count; + unsigned non_imported_stage_count; unsigned group_count; uint8_t sha1[SHA1_DIGEST_LENGTH]; @@ -2901,6 +2902,7 @@ void radv_rmv_log_descriptor_pool_create(struct radv_device *device, const VkDes void radv_rmv_log_graphics_pipeline_create(struct radv_device *device, struct radv_pipeline *pipeline, bool is_internal); void radv_rmv_log_compute_pipeline_create(struct radv_device *device, struct radv_pipeline *pipeline, bool is_internal); +void radv_rmv_log_rt_pipeline_create(struct radv_device *device, struct radv_ray_tracing_pipeline *pipeline); void radv_rmv_log_event_create(struct radv_device *device, VkEvent event, VkEventCreateFlags flags, bool is_internal); void radv_rmv_log_resource_destroy(struct radv_device *device, uint64_t handle); void radv_rmv_log_submit(struct radv_device *device, enum amd_ip_type type); diff --git a/src/amd/vulkan/radv_rmv.c b/src/amd/vulkan/radv_rmv.c index 6018a4482a1..ef715e0aa13 100644 --- a/src/amd/vulkan/radv_rmv.c +++ b/src/amd/vulkan/radv_rmv.c @@ -844,9 +844,6 @@ radv_rmv_log_compute_pipeline_create(struct radv_device *device, struct radv_pip VkPipeline _pipeline = radv_pipeline_to_handle(pipeline); - VkShaderStageFlagBits active_stages = - pipeline->type == RADV_PIPELINE_COMPUTE ? VK_SHADER_STAGE_COMPUTE_BIT : VK_SHADER_STAGE_RAYGEN_BIT_KHR; - simple_mtx_lock(&device->vk.memory_trace_data.token_mtx); struct vk_rmv_resource_create_token create_token = {0}; create_token.is_driver_internal = is_internal; @@ -855,14 +852,59 @@ radv_rmv_log_compute_pipeline_create(struct radv_device *device, struct radv_pip create_token.pipeline.is_internal = is_internal; create_token.pipeline.hash_lo = pipeline->pipeline_hash; create_token.pipeline.is_ngg = false; - create_token.pipeline.shader_stages = active_stages; + create_token.pipeline.shader_stages = VK_SHADER_STAGE_COMPUTE_BIT; vk_rmv_emit_token(&device->vk.memory_trace_data, VK_RMV_TOKEN_TYPE_RESOURCE_CREATE, &create_token); - struct radv_shader *shader = pipeline->shaders[vk_to_mesa_shader_stage(active_stages)]; + struct radv_shader *shader = pipeline->shaders[MESA_SHADER_COMPUTE]; log_resource_bind_locked(device, (uint64_t)_pipeline, shader->bo, shader->alloc->offset, shader->alloc->size); simple_mtx_unlock(&device->vk.memory_trace_data.token_mtx); } +void +radv_rmv_log_rt_pipeline_create(struct radv_device *device, struct radv_ray_tracing_pipeline *pipeline) +{ + if (!device->vk.memory_trace_data.is_enabled) + return; + + VkPipeline _pipeline = radv_pipeline_to_handle(&pipeline->base.base); + + struct radv_shader *prolog = pipeline->prolog; + struct radv_shader *traversal = pipeline->base.base.shaders[MESA_SHADER_INTERSECTION]; + + VkShaderStageFlagBits active_stages = traversal ? VK_SHADER_STAGE_INTERSECTION_BIT_KHR : 0; + if (prolog) + active_stages |= VK_SHADER_STAGE_COMPUTE_BIT; + + for (uint32_t i = 0; i < pipeline->stage_count; i++) { + if (pipeline->stages[i].shader) + active_stages |= mesa_to_vk_shader_stage(pipeline->stages[i].stage); + } + + simple_mtx_lock(&device->vk.memory_trace_data.token_mtx); + + struct vk_rmv_resource_create_token create_token = {0}; + create_token.resource_id = vk_rmv_get_resource_id_locked(&device->vk, (uint64_t)_pipeline); + create_token.type = VK_RMV_RESOURCE_TYPE_PIPELINE; + create_token.pipeline.hash_lo = pipeline->base.base.pipeline_hash; + create_token.pipeline.shader_stages = active_stages; + vk_rmv_emit_token(&device->vk.memory_trace_data, VK_RMV_TOKEN_TYPE_RESOURCE_CREATE, &create_token); + + if (prolog) + log_resource_bind_locked(device, (uint64_t)_pipeline, prolog->bo, prolog->alloc->offset, prolog->alloc->size); + + if (traversal) + log_resource_bind_locked(device, (uint64_t)_pipeline, traversal->bo, traversal->alloc->offset, + traversal->alloc->size); + + for (uint32_t i = 0; i < pipeline->non_imported_stage_count; i++) { + struct radv_shader *shader = pipeline->stages[i].shader; + if (shader) + log_resource_bind_locked(device, (uint64_t)_pipeline, shader->bo, shader->alloc->offset, shader->alloc->size); + } + + simple_mtx_unlock(&device->vk.memory_trace_data.token_mtx); +} + void radv_rmv_log_event_create(struct radv_device *device, VkEvent _event, VkEventCreateFlags flags, bool is_internal) {