v3dv/pipeline: provide a shader_sha1 to private ShaderModules

So far for private pipelines we were creating dummy shader modules
where we directly provided the nir shader. But for the pipeline cache
we were using the SPIR-V to generate part of the cache key sha1.

The main use case for private pipelines are meta_copy/clear. Those nir
shaders depend on parameters like the format etc, so we use directly
the serialized form of the NIR shader to generate the sha1.

The other case are the no-op fragment shader that we need to provide
if no fragment shader is defined by the user. For that case we can
just use the default shader name, as the no-op shader is always the
same.

This is required as we plan to add a default pipeline cache, that
would include our private shaders too.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6766>
diff --git a/src/broadcom/vulkan/v3dv_meta_clear.c b/src/broadcom/vulkan/v3dv_meta_clear.c
index bd2e7d0..9a7020f 100644
--- a/src/broadcom/vulkan/v3dv_meta_clear.c
+++ b/src/broadcom/vulkan/v3dv_meta_clear.c
@@ -188,8 +188,11 @@
                 const VkPipelineLayout layout,
                 VkPipeline *pipeline)
 {
-   struct v3dv_shader_module vs_m = { .nir = vs_nir };
-   struct v3dv_shader_module fs_m = { .nir = fs_nir };
+   struct v3dv_shader_module vs_m;
+   struct v3dv_shader_module fs_m;
+
+   v3dv_shader_module_internal_init(&vs_m, vs_nir);
+   v3dv_shader_module_internal_init(&fs_m, fs_nir);
 
    VkPipelineShaderStageCreateInfo stages[2] = {
       {
diff --git a/src/broadcom/vulkan/v3dv_meta_copy.c b/src/broadcom/vulkan/v3dv_meta_copy.c
index f2dd235..3f1f15b 100644
--- a/src/broadcom/vulkan/v3dv_meta_copy.c
+++ b/src/broadcom/vulkan/v3dv_meta_copy.c
@@ -3219,8 +3219,11 @@
                 const VkPipelineLayout layout,
                 VkPipeline *pipeline)
 {
-   struct v3dv_shader_module vs_m = { .nir = vs_nir };
-   struct v3dv_shader_module fs_m = { .nir = fs_nir };
+   struct v3dv_shader_module vs_m;
+   struct v3dv_shader_module fs_m;
+
+   v3dv_shader_module_internal_init(&vs_m, vs_nir);
+   v3dv_shader_module_internal_init(&fs_m, fs_nir);
 
    VkPipelineShaderStageCreateInfo stages[2] = {
       {
diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c
index 0d4dacf..d5cba45 100644
--- a/src/broadcom/vulkan/v3dv_pipeline.c
+++ b/src/broadcom/vulkan/v3dv_pipeline.c
@@ -31,6 +31,7 @@
 #include "common/v3d_debug.h"
 
 #include "compiler/nir/nir_builder.h"
+#include "nir/nir_serialize.h"
 
 #include "util/u_atomic.h"
 
@@ -69,6 +70,25 @@
 }
 
 void
+v3dv_shader_module_internal_init(struct v3dv_shader_module *module,
+                                 nir_shader *nir)
+{
+   module->nir = nir;
+   module->size = 0;
+
+   if (nir != NULL) {
+      struct blob blob;
+      blob_init(&blob);
+
+      nir_serialize(&blob, nir, false);
+      if (!blob.out_of_memory)
+         _mesa_sha1_compute(blob.data, blob.size, module->sha1);
+
+      blob_finish(&blob);
+   }
+}
+
+void
 v3dv_DestroyShaderModule(VkDevice _device,
                          VkShaderModule _module,
                          const VkAllocationCallbacks *pAllocator)
@@ -1816,6 +1836,11 @@
       p_stage->entrypoint = "main";
       p_stage->module = 0;
       p_stage->nir = b.shader;
+      /* The no-op shader is always the same, so we can just create the sha1
+       * using the name
+       */
+      _mesa_sha1_compute(b.shader->info.name, strlen(b.shader->info.name),
+                         p_stage->shader_sha1);
 
       p_stage->program_id =
          p_atomic_inc_return(&physical_device->next_program_id);
diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h
index 115840a..341aa6b 100644
--- a/src/broadcom/vulkan/v3dv_private.h
+++ b/src/broadcom/vulkan/v3dv_private.h
@@ -1826,6 +1826,8 @@
                                    struct v3dv_pipeline_cache *cache,
                                    struct v3dv_shader_variant  *variant);
 
+void v3dv_shader_module_internal_init(struct v3dv_shader_module *module,
+                                      nir_shader *nir);
 
 #define V3DV_DEFINE_HANDLE_CASTS(__v3dv_type, __VkType)   \
                                                         \