1 /*
2 * Copyright 2018 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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24 #ifndef NIR_TO_SPIRV_H
25 #define NIR_TO_SPIRV_H
26
27 #include <stdlib.h>
28 #include <stdint.h>
29 #include <vulkan/vulkan.h>
30
31 #include "compiler/nir/nir.h"
32 #include "compiler/shader_enums.h"
33 #include "pipe/p_state.h"
34
35 #include "zink_compiler.h"
36
37 #define SPIRV_VERSION(major, minor) (((major) << 16) | ((minor) << 8))
38
39 struct spirv_shader {
40 uint32_t *words;
41 size_t num_words;
42 };
43
44 struct nir_shader;
45 struct pipe_stream_output_info;
46
47 struct spirv_shader *
48 nir_to_spirv(struct nir_shader *s, const struct zink_so_info *so_info,
49 uint32_t spirv_version);
50
51 void
52 spirv_shader_delete(struct spirv_shader *s);
53
54 static inline bool
type_is_counter(const struct glsl_type * type)55 type_is_counter(const struct glsl_type *type)
56 {
57 return glsl_get_base_type(glsl_without_array(type)) == GLSL_TYPE_ATOMIC_UINT;
58 }
59
60 static inline VkDescriptorType
zink_sampler_type(const struct glsl_type * type)61 zink_sampler_type(const struct glsl_type *type)
62 {
63 assert(glsl_type_is_sampler(type));
64 switch (glsl_get_sampler_dim(type)) {
65 case GLSL_SAMPLER_DIM_1D:
66 case GLSL_SAMPLER_DIM_2D:
67 case GLSL_SAMPLER_DIM_3D:
68 case GLSL_SAMPLER_DIM_CUBE:
69 case GLSL_SAMPLER_DIM_RECT:
70 case GLSL_SAMPLER_DIM_MS:
71 case GLSL_SAMPLER_DIM_EXTERNAL:
72 return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
73 case GLSL_SAMPLER_DIM_BUF:
74 return VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER;
75 default:
76 unreachable("unimplemented");
77 }
78 return 0;
79 }
80
81 static inline VkDescriptorType
zink_image_type(const struct glsl_type * type)82 zink_image_type(const struct glsl_type *type)
83 {
84 assert(glsl_type_is_image(type));
85 switch (glsl_get_sampler_dim(type)) {
86 case GLSL_SAMPLER_DIM_1D:
87 case GLSL_SAMPLER_DIM_2D:
88 case GLSL_SAMPLER_DIM_3D:
89 case GLSL_SAMPLER_DIM_CUBE:
90 case GLSL_SAMPLER_DIM_RECT:
91 case GLSL_SAMPLER_DIM_MS:
92 case GLSL_SAMPLER_DIM_EXTERNAL:
93 return VK_DESCRIPTOR_TYPE_STORAGE_IMAGE;
94 case GLSL_SAMPLER_DIM_BUF:
95 return VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER;
96 default:
97 unreachable("unimplemented");
98 }
99 return 0;
100 }
101
102 struct nir_shader;
103
104 bool
105 zink_nir_lower_b2b(struct nir_shader *shader);
106
107 #endif
108