1 /*
2  * Copyright © 2022 Collabora, LTD
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_PIPELINE_H
25 #define VK_PIPELINE_H
26 
27 #include "vulkan/vulkan_core.h"
28 
29 #include <stdbool.h>
30 
31 struct nir_shader;
32 struct nir_shader_compiler_options;
33 struct spirv_to_nir_options;
34 struct vk_device;
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #define VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_NIR_CREATE_INFO_MESA \
41    (VkStructureType)1000290001
42 
43 #define VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_NIR_CREATE_INFO_MESA_cast \
44    VkPipelineShaderStageNirCreateInfoMESA
45 
46 typedef struct VkPipelineShaderStageNirCreateInfoMESA {
47    VkStructureType sType;
48    const void *pNext;
49    struct nir_shader *nir;
50 } VkPipelineShaderStageNirCreateInfoMESA;
51 
52 bool
53 vk_pipeline_shader_stage_is_null(const VkPipelineShaderStageCreateInfo *info);
54 
55 VkResult
56 vk_pipeline_shader_stage_to_nir(struct vk_device *device,
57                                 const VkPipelineShaderStageCreateInfo *info,
58                                 const struct spirv_to_nir_options *spirv_options,
59                                 const struct nir_shader_compiler_options *nir_options,
60                                 void *mem_ctx, struct nir_shader **nir_out);
61 
62 struct vk_pipeline_robustness_state {
63    VkPipelineRobustnessBufferBehaviorEXT storage_buffers;
64    VkPipelineRobustnessBufferBehaviorEXT uniform_buffers;
65    VkPipelineRobustnessBufferBehaviorEXT vertex_inputs;
66    VkPipelineRobustnessImageBehaviorEXT images;
67 };
68 
69 /** Hash VkPipelineShaderStageCreateInfo info
70  *
71  * Returns the hash of a VkPipelineShaderStageCreateInfo:
72  *    SHA1(info->module->sha1,
73  *         info->pName,
74  *         vk_stage_to_mesa_stage(info->stage),
75  *         info->pSpecializationInfo)
76  *
77  * Can only be used if VkPipelineShaderStageCreateInfo::module is a
78  * vk_shader_module object.
79  */
80 void
81 vk_pipeline_hash_shader_stage(const VkPipelineShaderStageCreateInfo *info,
82                               const struct vk_pipeline_robustness_state *rstate,
83                               unsigned char *stage_sha1);
84 
85 void
86 vk_pipeline_robustness_state_fill(const struct vk_device *device,
87                                   struct vk_pipeline_robustness_state *rs,
88                                   const void *pipeline_pNext,
89                                   const void *shader_stage_pNext);
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 #endif /* VK_PIPELINE_H */
96