Path: blob/21.2-virgl/src/vulkan/util/vk_shader_module.c
7188 views
/*1* Copyright © 2017 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "vk_shader_module.h"24#include "util/mesa-sha1.h"25#include "vk_common_entrypoints.h"26#include "vk_device.h"2728VKAPI_ATTR VkResult VKAPI_CALL29vk_common_CreateShaderModule(VkDevice _device,30const VkShaderModuleCreateInfo *pCreateInfo,31const VkAllocationCallbacks *pAllocator,32VkShaderModule *pShaderModule)33{34VK_FROM_HANDLE(vk_device, device, _device);35struct vk_shader_module *module;3637assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO);38assert(pCreateInfo->flags == 0);3940module = vk_object_alloc(device, pAllocator,41sizeof(*module) + pCreateInfo->codeSize,42VK_OBJECT_TYPE_SHADER_MODULE);43if (module == NULL)44return VK_ERROR_OUT_OF_HOST_MEMORY;4546module->size = pCreateInfo->codeSize;47module->nir = NULL;48memcpy(module->data, pCreateInfo->pCode, module->size);4950_mesa_sha1_compute(module->data, module->size, module->sha1);5152*pShaderModule = vk_shader_module_to_handle(module);5354return VK_SUCCESS;55}5657VKAPI_ATTR void VKAPI_CALL58vk_common_DestroyShaderModule(VkDevice _device,59VkShaderModule _module,60const VkAllocationCallbacks *pAllocator)61{62VK_FROM_HANDLE(vk_device, device, _device);63VK_FROM_HANDLE(vk_shader_module, module, _module);6465if (!module)66return;6768/* NIR modules (which are only created internally by the driver) are not69* dynamically allocated so we should never call this for them.70* Instead the driver is responsible for freeing the NIR code when it is71* no longer needed.72*/73assert(module->nir == NULL);7475vk_object_free(device, pAllocator, module);76}777879