diff --git a/src/broadcom/vulkan/common.h b/src/broadcom/vulkan/common.h index d34016f76b..e463a936ba 100644 --- a/src/broadcom/vulkan/common.h +++ b/src/broadcom/vulkan/common.h @@ -85,5 +85,6 @@ V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_query_pool, VkQueryPool) V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_render_pass, VkRenderPass) V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_sampler, VkSampler) V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_semaphore, VkSemaphore) +V3DVK_DEFINE_NONDISP_HANDLE_CASTS(v3dvk_shader_module, VkShaderModule) #endif // V3DVK_COMMON_H diff --git a/src/broadcom/vulkan/meson.build b/src/broadcom/vulkan/meson.build index fcf17025bb..5a350a6bd5 100644 --- a/src/broadcom/vulkan/meson.build +++ b/src/broadcom/vulkan/meson.build @@ -106,6 +106,7 @@ libv3dvk_files = files( 'v3dvk_macro.h', 'v3dvk_sampler.c', 'v3dvk_semaphore.c', + 'v3dvk_shader.c', 'v3dvk_util.c', 'wsi.c', ) diff --git a/src/broadcom/vulkan/v3dvk_shader.c b/src/broadcom/vulkan/v3dvk_shader.c new file mode 100644 index 0000000000..ab4df80f96 --- /dev/null +++ b/src/broadcom/vulkan/v3dvk_shader.c @@ -0,0 +1,50 @@ + +#include "common.h" +#include "device.h" +#include "vk_alloc.h" +#include "v3dvk_error.h" +#include "v3dvk_shader.h" +#include "util/mesa-sha1.h" + +VkResult +v3dvk_CreateShaderModule(VkDevice _device, + const VkShaderModuleCreateInfo *pCreateInfo, + const VkAllocationCallbacks *pAllocator, + VkShaderModule *pShaderModule) +{ + V3DVK_FROM_HANDLE(v3dvk_device, device, _device); + struct v3dvk_shader_module *module; + + assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO); + assert(pCreateInfo->flags == 0); + assert(pCreateInfo->codeSize % 4 == 0); + + module = vk_alloc2(&device->alloc, pAllocator, + sizeof(*module) + pCreateInfo->codeSize, 8, + VK_SYSTEM_ALLOCATION_SCOPE_OBJECT); + if (module == NULL) + return v3dvk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY); + + module->code_size = pCreateInfo->codeSize; + memcpy(module->code, pCreateInfo->pCode, pCreateInfo->codeSize); + + _mesa_sha1_compute(module->code, module->code_size, module->sha1); + + *pShaderModule = v3dvk_shader_module_to_handle(module); + + return VK_SUCCESS; +} + +void +v3dvk_DestroyShaderModule(VkDevice _device, + VkShaderModule _module, + const VkAllocationCallbacks *pAllocator) +{ + V3DVK_FROM_HANDLE(v3dvk_device, device, _device); + V3DVK_FROM_HANDLE(v3dvk_shader_module, module, _module); + + if (!module) + return; + + vk_free2(&device->alloc, pAllocator, module); +} diff --git a/src/broadcom/vulkan/v3dvk_shader.h b/src/broadcom/vulkan/v3dvk_shader.h new file mode 100644 index 0000000000..1902b983af --- /dev/null +++ b/src/broadcom/vulkan/v3dvk_shader.h @@ -0,0 +1,15 @@ + +#ifndef V3DVK_SHADER_H +#define V3DVK_SHADER_H + +#include + +struct v3dvk_shader_module +{ + unsigned char sha1[20]; + + uint32_t code_size; + const uint32_t *code[0]; +}; + +#endif