1 /* 2 * Copyright © 2017 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 */ 23 24 #ifndef VK_SHADER_MODULE_H 25 #define VK_SHADER_MODULE_H 26 27 #include <vulkan/vulkan_core.h> 28 29 #include "util/mesa-blake3.h" 30 #include "compiler/shader_enums.h" 31 #include "vk_object.h" 32 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 37 struct nir_shader; 38 struct nir_shader_compiler_options; 39 struct spirv_to_nir_options; 40 41 struct vk_shader_module { 42 struct vk_object_base base; 43 struct nir_shader *nir; 44 blake3_hash hash; 45 uint32_t size; 46 char data[0]; 47 }; 48 49 extern const uint8_t vk_shaderModuleIdentifierAlgorithmUUID[VK_UUID_SIZE]; 50 51 VK_DEFINE_NONDISP_HANDLE_CASTS(vk_shader_module, base, VkShaderModule, 52 VK_OBJECT_TYPE_SHADER_MODULE) 53 54 void vk_shader_module_init(struct vk_device *device, 55 struct vk_shader_module *module, 56 const VkShaderModuleCreateInfo *create_info); 57 58 uint32_t vk_shader_module_spirv_version(const struct vk_shader_module *mod); 59 60 VkResult 61 vk_shader_module_to_nir(struct vk_device *device, 62 const struct vk_shader_module *mod, 63 gl_shader_stage stage, 64 const char *entrypoint_name, 65 const VkSpecializationInfo *spec_info, 66 const struct spirv_to_nir_options *spirv_options, 67 const struct nir_shader_compiler_options *nir_options, 68 void *mem_ctx, struct nir_shader **nir_out); 69 70 /* this should only be used for stack-allocated, temporary objects */ 71 #define vk_shader_module_handle_from_nir(_nir) \ 72 ((VkShaderModule)(uintptr_t)&(struct vk_shader_module) { \ 73 .base.type = VK_OBJECT_TYPE_SHADER_MODULE, \ 74 .nir = _nir, \ 75 }) 76 #define vk_shader_module_from_nir(_nir) \ 77 (struct vk_shader_module) { \ 78 .base.type = VK_OBJECT_TYPE_SHADER_MODULE, \ 79 .nir = _nir, \ 80 } 81 82 #ifdef __cplusplus 83 } 84 #endif 85 86 #endif /* VK_SHADER_MODULE_H */ 87