From ef5cba56a0871c9767a3165728e6ba69d6c29b57 Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Sat, 4 Mar 2023 17:17:13 +0100 Subject: [PATCH] vulkan: Add vk_shader_module_init This will be used for allocating shader modules using ralloc by RADV. Reviewed-by: Samuel Pitoiset Part-of: --- src/vulkan/runtime/vk_shader_module.c | 27 +++++++++++++++++++-------- src/vulkan/runtime/vk_shader_module.h | 4 ++++ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/vulkan/runtime/vk_shader_module.c b/src/vulkan/runtime/vk_shader_module.c index b9ca8a9..6f838ed 100644 --- a/src/vulkan/runtime/vk_shader_module.c +++ b/src/vulkan/runtime/vk_shader_module.c @@ -24,6 +24,7 @@ #include "vk_shader_module.h" #include "util/mesa-sha1.h" +#include "vk_alloc.h" #include "vk_common_entrypoints.h" #include "vk_device.h" #include "vk_log.h" @@ -31,6 +32,20 @@ #include "vk_pipeline.h" #include "vk_util.h" +void vk_shader_module_init(struct vk_device *device, + struct vk_shader_module *module, + const VkShaderModuleCreateInfo *create_info) +{ + vk_object_base_init(device, &module->base, VK_OBJECT_TYPE_SHADER_MODULE); + + module->nir = NULL; + + module->size = create_info->codeSize; + memcpy(module->data, create_info->pCode, module->size); + + _mesa_sha1_compute(module->data, module->size, module->sha1); +} + VKAPI_ATTR VkResult VKAPI_CALL vk_common_CreateShaderModule(VkDevice _device, const VkShaderModuleCreateInfo *pCreateInfo, @@ -43,17 +58,13 @@ vk_common_CreateShaderModule(VkDevice _device, assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO); assert(pCreateInfo->flags == 0); - module = vk_object_alloc(device, pAllocator, - sizeof(*module) + pCreateInfo->codeSize, - VK_OBJECT_TYPE_SHADER_MODULE); + module = vk_alloc2(&device->alloc, pAllocator, + sizeof(*module) + pCreateInfo->codeSize, 8, + VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); if (module == NULL) return VK_ERROR_OUT_OF_HOST_MEMORY; - module->size = pCreateInfo->codeSize; - module->nir = NULL; - memcpy(module->data, pCreateInfo->pCode, module->size); - - _mesa_sha1_compute(module->data, module->size, module->sha1); + vk_shader_module_init(device, module, pCreateInfo); *pShaderModule = vk_shader_module_to_handle(module); diff --git a/src/vulkan/runtime/vk_shader_module.h b/src/vulkan/runtime/vk_shader_module.h index 317a7b4..efb1d8c 100644 --- a/src/vulkan/runtime/vk_shader_module.h +++ b/src/vulkan/runtime/vk_shader_module.h @@ -50,6 +50,10 @@ extern const uint8_t vk_shaderModuleIdentifierAlgorithmUUID[VK_UUID_SIZE]; VK_DEFINE_NONDISP_HANDLE_CASTS(vk_shader_module, base, VkShaderModule, VK_OBJECT_TYPE_SHADER_MODULE) +void vk_shader_module_init(struct vk_device *device, + struct vk_shader_module *module, + const VkShaderModuleCreateInfo *create_info); + uint32_t vk_shader_module_spirv_version(const struct vk_shader_module *mod); VkResult -- 2.7.4