radv/rt: unify radv_ray_tracing_lib_pipeline and radv_ray_tracing_pipeline
authorDaniel Schürmann <daniel@schuermann.dev>
Fri, 14 Apr 2023 12:53:02 +0000 (14:53 +0200)
committerMarge Bot <emma+marge@anholt.net>
Wed, 10 May 2023 07:02:13 +0000 (07:02 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22503>

src/amd/vulkan/radv_pipeline.c
src/amd/vulkan/radv_pipeline_cache.c
src/amd/vulkan/radv_pipeline_rt.c
src/amd/vulkan/radv_private.h

index 70d9fad..a73dd88 100644 (file)
@@ -98,9 +98,6 @@ radv_pipeline_destroy(struct radv_device *device, struct radv_pipeline *pipeline
    case RADV_PIPELINE_COMPUTE:
       radv_destroy_compute_pipeline(device, radv_pipeline_to_compute(pipeline));
       break;
-   case RADV_PIPELINE_RAY_TRACING_LIB:
-      radv_destroy_ray_tracing_lib_pipeline(device, radv_pipeline_to_ray_tracing_lib(pipeline));
-      break;
    case RADV_PIPELINE_RAY_TRACING:
       radv_destroy_ray_tracing_pipeline(device, radv_pipeline_to_ray_tracing(pipeline));
       break;
index 73e2596..07486a5 100644 (file)
@@ -111,7 +111,7 @@ radv_hash_rt_shaders(unsigned char *hash, const VkRayTracingPipelineCreateInfoKH
    if (pCreateInfo->pLibraryInfo) {
       for (uint32_t i = 0; i < pCreateInfo->pLibraryInfo->libraryCount; ++i) {
          RADV_FROM_HANDLE(radv_pipeline, lib_pipeline, pCreateInfo->pLibraryInfo->pLibraries[i]);
-         struct radv_ray_tracing_lib_pipeline *lib = radv_pipeline_to_ray_tracing_lib(lib_pipeline);
+         struct radv_ray_tracing_pipeline *lib = radv_pipeline_to_ray_tracing(lib_pipeline);
          _mesa_sha1_update(&ctx, lib->sha1, SHA1_DIGEST_LENGTH);
       }
    }
@@ -122,7 +122,8 @@ radv_hash_rt_shaders(unsigned char *hash, const VkRayTracingPipelineCreateInfoKH
                             VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_ANY_HIT_SHADERS_BIT_KHR |
                             VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_CLOSEST_HIT_SHADERS_BIT_KHR |
                             VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_MISS_SHADERS_BIT_KHR |
-                            VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_INTERSECTION_SHADERS_BIT_KHR);
+                            VK_PIPELINE_CREATE_RAY_TRACING_NO_NULL_INTERSECTION_SHADERS_BIT_KHR |
+                            VK_PIPELINE_CREATE_LIBRARY_BIT_KHR);
    _mesa_sha1_update(&ctx, &pipeline_flags, 4);
 
    _mesa_sha1_update(&ctx, &flags, 4);
index 3604396..c9294de 100644 (file)
@@ -155,8 +155,8 @@ radv_rt_fill_group_info(struct radv_device *device,
       unsigned stage_count = pCreateInfo->stageCount;
       for (unsigned i = 0; i < pCreateInfo->pLibraryInfo->libraryCount; ++i) {
          RADV_FROM_HANDLE(radv_pipeline, pipeline, pCreateInfo->pLibraryInfo->pLibraries[i]);
-         struct radv_ray_tracing_lib_pipeline *library_pipeline =
-            radv_pipeline_to_ray_tracing_lib(pipeline);
+         struct radv_ray_tracing_pipeline *library_pipeline =
+            radv_pipeline_to_ray_tracing(pipeline);
 
          for (unsigned j = 0; j < library_pipeline->group_count; ++j) {
             struct radv_ray_tracing_group *dst = &groups[idx + j];
@@ -187,8 +187,8 @@ radv_rt_fill_stage_info(const VkRayTracingPipelineCreateInfoKHR *pCreateInfo,
    if (pCreateInfo->pLibraryInfo) {
       for (unsigned i = 0; i < pCreateInfo->pLibraryInfo->libraryCount; ++i) {
          RADV_FROM_HANDLE(radv_pipeline, pipeline, pCreateInfo->pLibraryInfo->pLibraries[i]);
-         struct radv_ray_tracing_lib_pipeline *library_pipeline =
-            radv_pipeline_to_ray_tracing_lib(pipeline);
+         struct radv_ray_tracing_pipeline *library_pipeline =
+            radv_pipeline_to_ray_tracing(pipeline);
          for (unsigned j = 0; j < library_pipeline->stage_count; ++j)
             stages[idx++].stage = library_pipeline->stages[j].stage;
       }
@@ -205,8 +205,8 @@ radv_create_merged_rt_create_info(const VkRayTracingPipelineCreateInfoKHR *pCrea
    if (pCreateInfo->pLibraryInfo) {
       for (unsigned i = 0; i < pCreateInfo->pLibraryInfo->libraryCount; ++i) {
          RADV_FROM_HANDLE(radv_pipeline, pipeline, pCreateInfo->pLibraryInfo->pLibraries[i]);
-         struct radv_ray_tracing_lib_pipeline *library_pipeline =
-            radv_pipeline_to_ray_tracing_lib(pipeline);
+         struct radv_ray_tracing_pipeline *library_pipeline =
+            radv_pipeline_to_ray_tracing(pipeline);
 
          total_stages += library_pipeline->stage_count;
          total_groups += library_pipeline->group_count;
@@ -271,7 +271,7 @@ radv_rt_precompile_shaders(struct radv_device *device, struct vk_pipeline_cache
    if (pCreateInfo->pLibraryInfo) {
       for (unsigned i = 0; i < pCreateInfo->pLibraryInfo->libraryCount; ++i) {
          RADV_FROM_HANDLE(radv_pipeline, pipeline, pCreateInfo->pLibraryInfo->pLibraries[i]);
-         struct radv_ray_tracing_lib_pipeline *library = radv_pipeline_to_ray_tracing_lib(pipeline);
+         struct radv_ray_tracing_pipeline *library = radv_pipeline_to_ray_tracing(pipeline);
 
          for (unsigned j = 0; j < library->stage_count; ++j)
             stages[idx++].shader = vk_pipeline_cache_object_ref(library->stages[j].shader);
@@ -404,7 +404,7 @@ radv_rt_pipeline_library_create(VkDevice _device, VkPipelineCache _cache,
 {
    RADV_FROM_HANDLE(radv_device, device, _device);
    VK_FROM_HANDLE(vk_pipeline_cache, cache, _cache);
-   struct radv_ray_tracing_lib_pipeline *pipeline;
+   struct radv_ray_tracing_pipeline *pipeline;
    VkResult result = VK_SUCCESS;
    bool keep_statistic_info = radv_pipeline_capture_shader_stats(device, pCreateInfo->flags);
    const VkPipelineCreationFeedbackCreateInfo *creation_feedback =
@@ -424,7 +424,7 @@ radv_rt_pipeline_library_create(VkDevice _device, VkPipelineCache _cache,
    if (!pipeline)
       return VK_ERROR_OUT_OF_HOST_MEMORY;
 
-   radv_pipeline_init(device, &pipeline->base.base, RADV_PIPELINE_RAY_TRACING_LIB);
+   radv_pipeline_init(device, &pipeline->base.base, RADV_PIPELINE_RAY_TRACING);
 
    struct radv_pipeline_key key =
       radv_generate_pipeline_key(device, &pipeline->base.base, pCreateInfo->flags);
@@ -467,20 +467,6 @@ pipeline_fail:
    return result;
 }
 
-void
-radv_destroy_ray_tracing_lib_pipeline(struct radv_device *device,
-                                      struct radv_ray_tracing_lib_pipeline *pipeline)
-{
-   if (pipeline->stages) {
-      for (unsigned i = 0; i < pipeline->stage_count; i++) {
-         if (pipeline->stages[i].shader)
-            vk_pipeline_cache_object_unref(&device->vk, pipeline->stages[i].shader);
-      }
-   }
-
-   ralloc_free(pipeline->ctx);
-}
-
 static bool
 radv_rt_pipeline_has_dynamic_stack_size(const VkRayTracingPipelineCreateInfoKHR *pCreateInfo)
 {
@@ -707,10 +693,19 @@ void
 radv_destroy_ray_tracing_pipeline(struct radv_device *device,
                                   struct radv_ray_tracing_pipeline *pipeline)
 {
+   if (pipeline->stages) {
+      for (unsigned i = 0; i < pipeline->stage_count; i++) {
+         if (pipeline->stages[i].shader)
+            vk_pipeline_cache_object_unref(&device->vk, pipeline->stages[i].shader);
+      }
+   }
+
    if (pipeline->base.base.shaders[MESA_SHADER_COMPUTE])
       radv_shader_unref(device, pipeline->base.base.shaders[MESA_SHADER_COMPUTE]);
    if (pipeline->base.base.shaders[MESA_SHADER_RAYGEN])
       radv_shader_unref(device, pipeline->base.base.shaders[MESA_SHADER_RAYGEN]);
+
+   ralloc_free(pipeline->ctx);
 }
 
 VKAPI_ATTR VkResult VKAPI_CALL
@@ -753,12 +748,7 @@ radv_GetRayTracingShaderGroupHandlesKHR(VkDevice device, VkPipeline _pipeline, u
                                         uint32_t groupCount, size_t dataSize, void *pData)
 {
    RADV_FROM_HANDLE(radv_pipeline, pipeline, _pipeline);
-   struct radv_ray_tracing_group *groups;
-   if (pipeline->type == RADV_PIPELINE_RAY_TRACING_LIB) {
-      groups = radv_pipeline_to_ray_tracing_lib(pipeline)->groups;
-   } else {
-      groups = radv_pipeline_to_ray_tracing(pipeline)->groups;
-   }
+   struct radv_ray_tracing_group *groups = radv_pipeline_to_ray_tracing(pipeline)->groups;
    char *data = pData;
 
    STATIC_ASSERT(sizeof(struct radv_pipeline_group_handle) <= RADV_RT_HANDLE_SIZE);
index b80d717..e060a6b 100644 (file)
@@ -2175,7 +2175,6 @@ enum radv_pipeline_type {
    RADV_PIPELINE_GRAPHICS_LIB,
    /* Compute pipeline */
    RADV_PIPELINE_COMPUTE,
-   RADV_PIPELINE_RAY_TRACING_LIB,
    /* Raytracing pipeline */
    RADV_PIPELINE_RAY_TRACING,
 };
@@ -2324,7 +2323,7 @@ struct radv_ray_tracing_stage {
    gl_shader_stage stage;
 };
 
-struct radv_ray_tracing_lib_pipeline {
+struct radv_ray_tracing_pipeline {
    struct radv_compute_pipeline base;
 
    /* ralloc context used for allocating pipeline library resources. */
@@ -2334,6 +2333,7 @@ struct radv_ray_tracing_lib_pipeline {
    unsigned group_count;
    struct radv_ray_tracing_stage *stages;
    uint8_t sha1[SHA1_DIGEST_LENGTH];
+   uint32_t stack_size;
    struct radv_ray_tracing_group groups[];
 };
 
@@ -2358,14 +2358,6 @@ struct radv_graphics_lib_pipeline {
    VkPipelineShaderStageCreateInfo *stages;
 };
 
-struct radv_ray_tracing_pipeline {
-   struct radv_compute_pipeline base;
-
-   uint32_t group_count;
-   uint32_t stack_size;
-   struct radv_ray_tracing_group groups[];
-};
-
 #define RADV_DECL_PIPELINE_DOWNCAST(pipe_type, pipe_enum)            \
    static inline struct radv_##pipe_type##_pipeline *                \
    radv_pipeline_to_##pipe_type(struct radv_pipeline *pipeline)      \
@@ -2377,7 +2369,6 @@ struct radv_ray_tracing_pipeline {
 RADV_DECL_PIPELINE_DOWNCAST(graphics, RADV_PIPELINE_GRAPHICS)
 RADV_DECL_PIPELINE_DOWNCAST(graphics_lib, RADV_PIPELINE_GRAPHICS_LIB)
 RADV_DECL_PIPELINE_DOWNCAST(compute, RADV_PIPELINE_COMPUTE)
-RADV_DECL_PIPELINE_DOWNCAST(ray_tracing_lib, RADV_PIPELINE_RAY_TRACING_LIB)
 RADV_DECL_PIPELINE_DOWNCAST(ray_tracing, RADV_PIPELINE_RAY_TRACING)
 
 struct radv_pipeline_stage {
@@ -3683,8 +3674,6 @@ void radv_destroy_graphics_lib_pipeline(struct radv_device *device,
                                         struct radv_graphics_lib_pipeline *pipeline);
 void radv_destroy_compute_pipeline(struct radv_device *device,
                                    struct radv_compute_pipeline *pipeline);
-void radv_destroy_ray_tracing_lib_pipeline(struct radv_device *device,
-                                           struct radv_ray_tracing_lib_pipeline *pipeline);
 void radv_destroy_ray_tracing_pipeline(struct radv_device *device,
                                        struct radv_ray_tracing_pipeline *pipeline);