radv: rely on non-NULL binaries when inserting shaders to the cache
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 6 Jan 2023 08:27:30 +0000 (09:27 +0100)
committerMarge Bot <emma+marge@anholt.net>
Tue, 4 Apr 2023 14:47:39 +0000 (14:47 +0000)
With GPL, a stage can be imported from a library which means that the
binary is NULL (it's freed right after compilation) but the shader is
non-NULL. To avoid crashing, rely on non-NULL binaries because this
implies that the shader is non-NULL as well.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22264>

src/amd/vulkan/radv_pipeline_cache.c

index 9980a4b..48802dc 100644 (file)
@@ -482,7 +482,7 @@ radv_pipeline_cache_insert_shaders(struct radv_device *device, struct radv_pipel
 
    size_t size = sizeof(*entry) + sizeof(struct radv_pipeline_shader_stack_size) * num_rt_groups;
    for (int i = 0; i < MESA_VULKAN_SHADER_STAGES; ++i)
-      if (pipeline->shaders[i])
+      if (binaries[i])
          size += binaries[i]->total_size;
    if (ps_epilog_binary)
       size += ps_epilog_binary->total_size;
@@ -501,7 +501,7 @@ radv_pipeline_cache_insert_shaders(struct radv_device *device, struct radv_pipel
    char *p = entry->code;
 
    for (int i = 0; i < MESA_VULKAN_SHADER_STAGES; ++i) {
-      if (!pipeline->shaders[i])
+      if (!binaries[i])
          continue;
 
       entry->binary_sizes[i] = binaries[i]->total_size;
@@ -551,8 +551,9 @@ radv_pipeline_cache_insert_shaders(struct radv_device *device, struct radv_pipel
     * items.
     */
    for (int i = 0; i < MESA_VULKAN_SHADER_STAGES; ++i) {
-      if (!pipeline->shaders[i])
+      if (!binaries[i])
          continue;
+      assert(pipeline->shaders[i]);
 
       entry->shaders[i] = pipeline->shaders[i];
       radv_shader_ref(pipeline->shaders[i]);