• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2015 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 _NIR_SPIRV_H_
25 #define _NIR_SPIRV_H_
26 
27 #include "util/disk_cache.h"
28 #include "compiler/nir/nir.h"
29 #include "compiler/shader_info.h"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 struct nir_spirv_specialization {
36    uint32_t id;
37    nir_const_value value;
38    bool defined_on_module;
39 };
40 
41 enum nir_spirv_debug_level {
42    NIR_SPIRV_DEBUG_LEVEL_INVALID = -1,
43    NIR_SPIRV_DEBUG_LEVEL_INFO,
44    NIR_SPIRV_DEBUG_LEVEL_WARNING,
45    NIR_SPIRV_DEBUG_LEVEL_ERROR,
46 };
47 
48 enum nir_spirv_execution_environment {
49    NIR_SPIRV_VULKAN = 0,
50    NIR_SPIRV_OPENCL,
51    NIR_SPIRV_OPENGL,
52 };
53 
54 struct spirv_to_nir_options {
55    enum nir_spirv_execution_environment environment;
56 
57    /* Whether to keep ViewIndex as an input instead of rewriting to a sysval.
58     */
59    bool view_index_is_input;
60 
61    /* Create a nir library. */
62    bool create_library;
63 
64    /* Initial value for shader_info::float_controls_execution_mode,
65     * indicates hardware requirements rather than shader author intent
66     */
67    uint32_t float_controls_execution_mode;
68 
69    /* Initial subgroup size.  This may be overwritten for CL kernels */
70    enum gl_subgroup_size subgroup_size;
71 
72    /* True if RelaxedPrecision-decorated ALU result values should be performed
73     * with 16-bit math.
74     */
75    bool mediump_16bit_alu;
76 
77    /* When mediump_16bit_alu is set, determines whether nir_op_fddx/fddy can be
78     * performed in 16-bit math.
79     */
80    bool mediump_16bit_derivatives;
81 
82    struct spirv_supported_capabilities caps;
83 
84    /* Address format for various kinds of pointers. */
85    nir_address_format ubo_addr_format;
86    nir_address_format ssbo_addr_format;
87    nir_address_format phys_ssbo_addr_format;
88    nir_address_format push_const_addr_format;
89    nir_address_format shared_addr_format;
90    nir_address_format task_payload_addr_format;
91    nir_address_format global_addr_format;
92    nir_address_format temp_addr_format;
93    nir_address_format constant_addr_format;
94 
95    /** Minimum UBO alignment.
96     *
97     * This should match VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment
98     */
99    uint32_t min_ubo_alignment;
100 
101    /** Minimum SSBO alignment.
102     *
103     * This should match VkPhysicalDeviceLimits::minStorageBufferOffsetAlignment
104     */
105    uint32_t min_ssbo_alignment;
106 
107    const nir_shader *clc_shader;
108 
109    struct {
110       void (*func)(void *private_data,
111                    enum nir_spirv_debug_level level,
112                    size_t spirv_offset,
113                    const char *message);
114       void *private_data;
115    } debug;
116 
117    /* Force texture sampling to be non-uniform. */
118    bool force_tex_non_uniform;
119    /* Force SSBO accesses to be non-uniform. */
120    bool force_ssbo_non_uniform;
121 
122    /* In Debug Builds, instead of emitting an OS break on failure, just return NULL from
123     * spirv_to_nir().  This is useful for the unit tests that want to report a test failed
124     * but continue executing other tests.
125     */
126    bool skip_os_break_in_debug_build;
127 
128    /* Shader index provided by VkPipelineShaderStageNodeCreateInfoAMDX */
129    uint32_t shader_index;
130 };
131 
132 enum spirv_verify_result {
133    SPIRV_VERIFY_OK = 0,
134    SPIRV_VERIFY_PARSER_ERROR = 1,
135    SPIRV_VERIFY_ENTRY_POINT_NOT_FOUND = 2,
136    SPIRV_VERIFY_UNKNOWN_SPEC_INDEX = 3,
137 };
138 
139 enum spirv_verify_result spirv_verify_gl_specialization_constants(
140    const uint32_t *words, size_t word_count,
141    struct nir_spirv_specialization *spec, unsigned num_spec,
142    gl_shader_stage stage, const char *entry_point_name);
143 
144 nir_shader *spirv_to_nir(const uint32_t *words, size_t word_count,
145                          struct nir_spirv_specialization *specializations,
146                          unsigned num_specializations,
147                          gl_shader_stage stage, const char *entry_point_name,
148                          const struct spirv_to_nir_options *options,
149                          const nir_shader_compiler_options *nir_options);
150 
151 bool
152 spirv_library_to_nir_builder(FILE *fp, const uint32_t *words, size_t word_count,
153                              const struct spirv_to_nir_options *options);
154 
155 #ifdef __cplusplus
156 }
157 #endif
158 
159 #endif /* _NIR_SPIRV_H_ */
160