Mesa (main): radv: upload shader binaries after they are all compiled

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Dec 2 07:39:17 UTC 2021


Module: Mesa
Branch: main
Commit: 13143b3c1149ce6857c0357bb6b467b6cd6d5dc9
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=13143b3c1149ce6857c0357bb6b467b6cd6d5dc9

Author: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Date:   Fri Nov  5 13:30:28 2021 +0100

radv: upload shader binaries after they are all compiled

Instead of mixing compilation and upload. This will allow us to
upload all shader binaries contiguously in memory and also for future
pipeline libraries work.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas at basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/13690>

---

 src/amd/vulkan/radv_pipeline.c       | 15 +++++++++++++++
 src/amd/vulkan/radv_pipeline_cache.c |  7 +++++++
 src/amd/vulkan/radv_shader.c         |  5 +----
 src/amd/vulkan/radv_shader.h         |  3 +++
 4 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/amd/vulkan/radv_pipeline.c b/src/amd/vulkan/radv_pipeline.c
index 0baa908684f..909d92adda1 100644
--- a/src/amd/vulkan/radv_pipeline.c
+++ b/src/amd/vulkan/radv_pipeline.c
@@ -3691,6 +3691,21 @@ radv_create_shaders(struct radv_pipeline *pipeline, struct radv_pipeline_layout
       }
    }
 
+   /* Upload shader binaries. */
+   for (int i = 0; i < MESA_VULKAN_SHADER_STAGES; ++i) {
+      struct radv_shader *shader = pipeline->shaders[i];
+      if (!shader)
+         continue;
+
+      if (!radv_shader_binary_upload(device, binaries[i], shader))
+         return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+
+      if (i == MESA_SHADER_GEOMETRY && pipeline->gs_copy_shader) {
+         if (!radv_shader_binary_upload(device, gs_copy_binary, pipeline->gs_copy_shader))
+            return VK_ERROR_OUT_OF_DEVICE_MEMORY;
+      }
+   }
+
    if (!keep_executable_info) {
       if (pipeline->gs_copy_shader) {
          assert(!binaries[MESA_SHADER_COMPUTE] && !pipeline->shaders[MESA_SHADER_COMPUTE]);
diff --git a/src/amd/vulkan/radv_pipeline_cache.c b/src/amd/vulkan/radv_pipeline_cache.c
index dfba72b8d47..34d74f81307 100644
--- a/src/amd/vulkan/radv_pipeline_cache.c
+++ b/src/amd/vulkan/radv_pipeline_cache.c
@@ -355,6 +355,13 @@ radv_create_shaders_from_pipeline_cache(
          p += entry->binary_sizes[i];
 
          entry->shaders[i] = radv_shader_create(device, binary, false, true, NULL);
+
+         if (!radv_shader_binary_upload(device, binary, entry->shaders[i])) {
+            free(binary);
+            radv_pipeline_cache_unlock(cache);
+            return false;
+         }
+
          free(binary);
       } else if (entry->binary_sizes[i]) {
          p += entry->binary_sizes[i];
diff --git a/src/amd/vulkan/radv_shader.c b/src/amd/vulkan/radv_shader.c
index 68b6497f3e6..61ed8cfd8c4 100644
--- a/src/amd/vulkan/radv_shader.c
+++ b/src/amd/vulkan/radv_shader.c
@@ -1606,7 +1606,7 @@ radv_open_rtld_binary(struct radv_device *device, const struct radv_shader *shad
    return ac_rtld_open(rtld_binary, open_info);
 }
 
-static bool
+bool
 radv_shader_binary_upload(struct radv_device *device, const struct radv_shader_binary *binary,
                           struct radv_shader *shader)
 {
@@ -1710,9 +1710,6 @@ radv_shader_create(struct radv_device *device, const struct radv_shader_binary *
       radv_postprocess_config(device, &config, &binary->info, binary->stage, args, &shader->config);
    }
 
-   if (!radv_shader_binary_upload(device, binary, shader))
-      return NULL;
-
    if (binary->type == RADV_BINARY_TYPE_RTLD) {
       struct radv_shader_binary_rtld *bin = (struct radv_shader_binary_rtld *)binary;
       struct ac_rtld_binary rtld_binary = {0};
diff --git a/src/amd/vulkan/radv_shader.h b/src/amd/vulkan/radv_shader.h
index 52a5b06ab7c..a09afe900c2 100644
--- a/src/amd/vulkan/radv_shader.h
+++ b/src/amd/vulkan/radv_shader.h
@@ -514,6 +514,9 @@ struct radv_shader *radv_shader_compile(
    struct radv_shader_info *info, bool keep_shader_info, bool keep_statistic_info,
    struct radv_shader_binary **binary_out);
 
+bool radv_shader_binary_upload(struct radv_device *device, const struct radv_shader_binary *binary,
+                               struct radv_shader *shader);
+
 struct radv_shader *
 radv_create_gs_copy_shader(struct radv_device *device, struct nir_shader *nir,
                            struct radv_shader_info *info, struct radv_shader_binary **binary_out,



More information about the mesa-commit mailing list