Mesa (main): vulkan: Add a shader module clone helper

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Apr 26 18:57:08 UTC 2022


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

Author: Konstantin Seurer <konstantin.seurer at gmail.com>
Date:   Tue Apr 26 09:36:29 2022 +0200

vulkan: Add a shader module clone helper

Signed-off-by: Konstantin Seurer <konstantin.seurer at gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16027>

---

 src/vulkan/runtime/vk_shader_module.c | 18 ++++++++++++++++++
 src/vulkan/runtime/vk_shader_module.h |  3 +++
 2 files changed, 21 insertions(+)

diff --git a/src/vulkan/runtime/vk_shader_module.c b/src/vulkan/runtime/vk_shader_module.c
index 3b523e368e6..de896229b96 100644
--- a/src/vulkan/runtime/vk_shader_module.c
+++ b/src/vulkan/runtime/vk_shader_module.c
@@ -131,3 +131,21 @@ vk_shader_module_to_nir(struct vk_device *device,
       return VK_SUCCESS;
    }
 }
+
+struct vk_shader_module *
+vk_shader_module_clone(void *mem_ctx, const struct vk_shader_module *src)
+{
+   struct vk_shader_module *dst =
+      ralloc_size(mem_ctx, sizeof(struct vk_shader_module) + src->size);
+
+   vk_object_base_init(src->base.device, &dst->base, VK_OBJECT_TYPE_SHADER_MODULE);
+
+   dst->nir = NULL;
+
+   memcpy(dst->sha1, src->sha1, sizeof(src->sha1));
+
+   dst->size = src->size;
+   memcpy(dst->data, src->data, src->size);
+
+   return dst;
+}
diff --git a/src/vulkan/runtime/vk_shader_module.h b/src/vulkan/runtime/vk_shader_module.h
index f909a082c4e..fbd584d19d7 100644
--- a/src/vulkan/runtime/vk_shader_module.h
+++ b/src/vulkan/runtime/vk_shader_module.h
@@ -60,6 +60,9 @@ vk_shader_module_to_nir(struct vk_device *device,
                         const struct nir_shader_compiler_options *nir_options,
                         void *mem_ctx, struct nir_shader **nir_out);
 
+struct vk_shader_module *vk_shader_module_clone(void *mem_ctx,
+                                                const struct vk_shader_module *src);
+
 /* this should only be used for stack-allocated, temporary objects */
 #define vk_shader_module_handle_from_nir(_nir) \
    ((VkShaderModule)(uintptr_t)&(struct vk_shader_module) { \



More information about the mesa-commit mailing list