• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.h>
28 
29 #include "compiler/shader_enums.h"
30 #include "vk_object.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 struct nir_shader;
37 struct nir_shader_compiler_options;
38 struct spirv_to_nir_options;
39 
40 struct vk_shader_module {
41    struct vk_object_base base;
42    struct nir_shader *nir;
43    unsigned char sha1[20];
44    uint32_t size;
45    char data[0];
46 };
47 
48 extern const uint8_t vk_shaderModuleIdentifierAlgorithmUUID[VK_UUID_SIZE];
49 
50 VK_DEFINE_NONDISP_HANDLE_CASTS(vk_shader_module, base, VkShaderModule,
51                                VK_OBJECT_TYPE_SHADER_MODULE)
52 
53 uint32_t vk_shader_module_spirv_version(const struct vk_shader_module *mod);
54 
55 VkResult
56 vk_shader_module_to_nir(struct vk_device *device,
57                         const struct vk_shader_module *mod,
58                         gl_shader_stage stage,
59                         const char *entrypoint_name,
60                         const VkSpecializationInfo *spec_info,
61                         const struct spirv_to_nir_options *spirv_options,
62                         const struct nir_shader_compiler_options *nir_options,
63                         void *mem_ctx, struct nir_shader **nir_out);
64 
65 struct vk_shader_module *vk_shader_module_clone(void *mem_ctx,
66                                                 const struct vk_shader_module *src);
67 
68 /* this should only be used for stack-allocated, temporary objects */
69 #define vk_shader_module_handle_from_nir(_nir) \
70    ((VkShaderModule)(uintptr_t)&(struct vk_shader_module) { \
71       .base.type = VK_OBJECT_TYPE_SHADER_MODULE, \
72       .nir = _nir, \
73    })
74 #define vk_shader_module_from_nir(_nir) \
75    (struct vk_shader_module) { \
76       .base.type = VK_OBJECT_TYPE_SHADER_MODULE, \
77       .nir = _nir, \
78    }
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif /* VK_SHADER_MODULE_H */
85