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 spirv_capabilities; 36 37 struct nir_spirv_specialization { 38 uint32_t id; 39 nir_const_value value; 40 bool defined_on_module; 41 }; 42 43 enum nir_spirv_debug_level { 44 NIR_SPIRV_DEBUG_LEVEL_INVALID = -1, 45 NIR_SPIRV_DEBUG_LEVEL_INFO, 46 NIR_SPIRV_DEBUG_LEVEL_WARNING, 47 NIR_SPIRV_DEBUG_LEVEL_ERROR, 48 }; 49 50 enum nir_spirv_execution_environment { 51 NIR_SPIRV_VULKAN = 0, 52 NIR_SPIRV_OPENCL, 53 NIR_SPIRV_OPENGL, 54 }; 55 56 struct spirv_to_nir_options { 57 enum nir_spirv_execution_environment environment; 58 59 /* Whether to keep ViewIndex as an input instead of rewriting to a sysval. 60 */ 61 bool view_index_is_input; 62 63 /* Create a nir library. */ 64 bool create_library; 65 66 /* Initial value for shader_info::float_controls_execution_mode, 67 * indicates hardware requirements rather than shader author intent 68 */ 69 uint32_t float_controls_execution_mode; 70 71 /* Initial subgroup size. This may be overwritten for CL kernels */ 72 enum gl_subgroup_size subgroup_size; 73 74 /* True if RelaxedPrecision-decorated ALU result values should be performed 75 * with 16-bit math. 76 */ 77 bool mediump_16bit_alu; 78 79 /* When mediump_16bit_alu is set, determines whether ddx/ddy can be 80 * performed in 16-bit math. 81 */ 82 bool mediump_16bit_derivatives; 83 84 /* These really early AMD extensions don't have capabilities */ 85 bool amd_gcn_shader; 86 bool amd_shader_ballot; 87 bool amd_trinary_minmax; 88 bool amd_shader_explicit_vertex_parameter; 89 90 /* Whether or not printf is supported */ 91 bool printf; 92 93 /* Whether or not the driver wants consume debug information (Debugging purposes). */ 94 bool debug_info; 95 96 const struct spirv_capabilities *capabilities; 97 98 /* Address format for various kinds of pointers. */ 99 nir_address_format ubo_addr_format; 100 nir_address_format ssbo_addr_format; 101 nir_address_format phys_ssbo_addr_format; 102 nir_address_format push_const_addr_format; 103 nir_address_format shared_addr_format; 104 nir_address_format task_payload_addr_format; 105 nir_address_format global_addr_format; 106 nir_address_format temp_addr_format; 107 nir_address_format constant_addr_format; 108 109 /** Minimum UBO alignment. 110 * 111 * This should match VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment 112 */ 113 uint32_t min_ubo_alignment; 114 115 /** Minimum SSBO alignment. 116 * 117 * This should match VkPhysicalDeviceLimits::minStorageBufferOffsetAlignment 118 */ 119 uint32_t min_ssbo_alignment; 120 121 const nir_shader *clc_shader; 122 123 struct { 124 void (*func)(void *private_data, 125 enum nir_spirv_debug_level level, 126 size_t spirv_offset, 127 const char *message); 128 void *private_data; 129 } debug; 130 131 /* Whether debug_break instructions should be emitted. */ 132 bool emit_debug_break; 133 134 /* Force texture sampling to be non-uniform. */ 135 bool force_tex_non_uniform; 136 /* Force SSBO accesses to be non-uniform. */ 137 bool force_ssbo_non_uniform; 138 139 /* Whether OpTerminateInvocation should be lowered to OpKill to workaround 140 * game bugs. 141 */ 142 bool lower_terminate_to_discard; 143 144 /* In Debug Builds, instead of emitting an OS break on failure, just return NULL from 145 * spirv_to_nir(). This is useful for the unit tests that want to report a test failed 146 * but continue executing other tests. 147 */ 148 bool skip_os_break_in_debug_build; 149 150 /* Shader index provided by VkPipelineShaderStageNodeCreateInfoAMDX */ 151 uint32_t shader_index; 152 }; 153 154 enum spirv_verify_result { 155 SPIRV_VERIFY_OK = 0, 156 SPIRV_VERIFY_PARSER_ERROR = 1, 157 SPIRV_VERIFY_ENTRY_POINT_NOT_FOUND = 2, 158 SPIRV_VERIFY_UNKNOWN_SPEC_INDEX = 3, 159 }; 160 161 enum spirv_verify_result spirv_verify_gl_specialization_constants( 162 const uint32_t *words, size_t word_count, 163 struct nir_spirv_specialization *spec, unsigned num_spec, 164 gl_shader_stage stage, const char *entry_point_name); 165 166 nir_shader *spirv_to_nir(const uint32_t *words, size_t word_count, 167 struct nir_spirv_specialization *specializations, 168 unsigned num_specializations, 169 gl_shader_stage stage, const char *entry_point_name, 170 const struct spirv_to_nir_options *options, 171 const nir_shader_compiler_options *nir_options); 172 173 bool 174 spirv_library_to_nir_builder(FILE *fp, const uint32_t *words, size_t word_count, 175 const struct spirv_to_nir_options *options); 176 177 void spirv_print_asm(FILE *fp, const uint32_t *words, size_t word_count); 178 179 #ifdef __cplusplus 180 } 181 #endif 182 183 #endif /* _NIR_SPIRV_H_ */ 184