1*61046927SAndroid Build Coastguard Worker /* 2*61046927SAndroid Build Coastguard Worker * Copyright © 2015 Intel Corporation 3*61046927SAndroid Build Coastguard Worker * 4*61046927SAndroid Build Coastguard Worker * Permission is hereby granted, free of charge, to any person obtaining a 5*61046927SAndroid Build Coastguard Worker * copy of this software and associated documentation files (the "Software"), 6*61046927SAndroid Build Coastguard Worker * to deal in the Software without restriction, including without limitation 7*61046927SAndroid Build Coastguard Worker * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8*61046927SAndroid Build Coastguard Worker * and/or sell copies of the Software, and to permit persons to whom the 9*61046927SAndroid Build Coastguard Worker * Software is furnished to do so, subject to the following conditions: 10*61046927SAndroid Build Coastguard Worker * 11*61046927SAndroid Build Coastguard Worker * The above copyright notice and this permission notice (including the next 12*61046927SAndroid Build Coastguard Worker * paragraph) shall be included in all copies or substantial portions of the 13*61046927SAndroid Build Coastguard Worker * Software. 14*61046927SAndroid Build Coastguard Worker * 15*61046927SAndroid Build Coastguard Worker * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16*61046927SAndroid Build Coastguard Worker * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17*61046927SAndroid Build Coastguard Worker * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18*61046927SAndroid Build Coastguard Worker * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19*61046927SAndroid Build Coastguard Worker * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20*61046927SAndroid Build Coastguard Worker * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21*61046927SAndroid Build Coastguard Worker * IN THE SOFTWARE. 22*61046927SAndroid Build Coastguard Worker */ 23*61046927SAndroid Build Coastguard Worker 24*61046927SAndroid Build Coastguard Worker #ifndef _NIR_SPIRV_H_ 25*61046927SAndroid Build Coastguard Worker #define _NIR_SPIRV_H_ 26*61046927SAndroid Build Coastguard Worker 27*61046927SAndroid Build Coastguard Worker #include "util/disk_cache.h" 28*61046927SAndroid Build Coastguard Worker #include "compiler/nir/nir.h" 29*61046927SAndroid Build Coastguard Worker #include "compiler/shader_info.h" 30*61046927SAndroid Build Coastguard Worker 31*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus 32*61046927SAndroid Build Coastguard Worker extern "C" { 33*61046927SAndroid Build Coastguard Worker #endif 34*61046927SAndroid Build Coastguard Worker 35*61046927SAndroid Build Coastguard Worker struct spirv_capabilities; 36*61046927SAndroid Build Coastguard Worker 37*61046927SAndroid Build Coastguard Worker struct nir_spirv_specialization { 38*61046927SAndroid Build Coastguard Worker uint32_t id; 39*61046927SAndroid Build Coastguard Worker nir_const_value value; 40*61046927SAndroid Build Coastguard Worker bool defined_on_module; 41*61046927SAndroid Build Coastguard Worker }; 42*61046927SAndroid Build Coastguard Worker 43*61046927SAndroid Build Coastguard Worker enum nir_spirv_debug_level { 44*61046927SAndroid Build Coastguard Worker NIR_SPIRV_DEBUG_LEVEL_INVALID = -1, 45*61046927SAndroid Build Coastguard Worker NIR_SPIRV_DEBUG_LEVEL_INFO, 46*61046927SAndroid Build Coastguard Worker NIR_SPIRV_DEBUG_LEVEL_WARNING, 47*61046927SAndroid Build Coastguard Worker NIR_SPIRV_DEBUG_LEVEL_ERROR, 48*61046927SAndroid Build Coastguard Worker }; 49*61046927SAndroid Build Coastguard Worker 50*61046927SAndroid Build Coastguard Worker enum nir_spirv_execution_environment { 51*61046927SAndroid Build Coastguard Worker NIR_SPIRV_VULKAN = 0, 52*61046927SAndroid Build Coastguard Worker NIR_SPIRV_OPENCL, 53*61046927SAndroid Build Coastguard Worker NIR_SPIRV_OPENGL, 54*61046927SAndroid Build Coastguard Worker }; 55*61046927SAndroid Build Coastguard Worker 56*61046927SAndroid Build Coastguard Worker struct spirv_to_nir_options { 57*61046927SAndroid Build Coastguard Worker enum nir_spirv_execution_environment environment; 58*61046927SAndroid Build Coastguard Worker 59*61046927SAndroid Build Coastguard Worker /* Whether to keep ViewIndex as an input instead of rewriting to a sysval. 60*61046927SAndroid Build Coastguard Worker */ 61*61046927SAndroid Build Coastguard Worker bool view_index_is_input; 62*61046927SAndroid Build Coastguard Worker 63*61046927SAndroid Build Coastguard Worker /* Create a nir library. */ 64*61046927SAndroid Build Coastguard Worker bool create_library; 65*61046927SAndroid Build Coastguard Worker 66*61046927SAndroid Build Coastguard Worker /* Initial value for shader_info::float_controls_execution_mode, 67*61046927SAndroid Build Coastguard Worker * indicates hardware requirements rather than shader author intent 68*61046927SAndroid Build Coastguard Worker */ 69*61046927SAndroid Build Coastguard Worker uint32_t float_controls_execution_mode; 70*61046927SAndroid Build Coastguard Worker 71*61046927SAndroid Build Coastguard Worker /* Initial subgroup size. This may be overwritten for CL kernels */ 72*61046927SAndroid Build Coastguard Worker enum gl_subgroup_size subgroup_size; 73*61046927SAndroid Build Coastguard Worker 74*61046927SAndroid Build Coastguard Worker /* True if RelaxedPrecision-decorated ALU result values should be performed 75*61046927SAndroid Build Coastguard Worker * with 16-bit math. 76*61046927SAndroid Build Coastguard Worker */ 77*61046927SAndroid Build Coastguard Worker bool mediump_16bit_alu; 78*61046927SAndroid Build Coastguard Worker 79*61046927SAndroid Build Coastguard Worker /* When mediump_16bit_alu is set, determines whether nir_op_fddx/fddy can be 80*61046927SAndroid Build Coastguard Worker * performed in 16-bit math. 81*61046927SAndroid Build Coastguard Worker */ 82*61046927SAndroid Build Coastguard Worker bool mediump_16bit_derivatives; 83*61046927SAndroid Build Coastguard Worker 84*61046927SAndroid Build Coastguard Worker /* These really early AMD extensions don't have capabilities */ 85*61046927SAndroid Build Coastguard Worker bool amd_gcn_shader; 86*61046927SAndroid Build Coastguard Worker bool amd_shader_ballot; 87*61046927SAndroid Build Coastguard Worker bool amd_trinary_minmax; 88*61046927SAndroid Build Coastguard Worker bool amd_shader_explicit_vertex_parameter; 89*61046927SAndroid Build Coastguard Worker 90*61046927SAndroid Build Coastguard Worker /* Whether or not printf is supported */ 91*61046927SAndroid Build Coastguard Worker bool printf; 92*61046927SAndroid Build Coastguard Worker 93*61046927SAndroid Build Coastguard Worker /* Whether or not the driver wants consume debug information (Debugging purposes). */ 94*61046927SAndroid Build Coastguard Worker bool debug_info; 95*61046927SAndroid Build Coastguard Worker 96*61046927SAndroid Build Coastguard Worker const struct spirv_capabilities *capabilities; 97*61046927SAndroid Build Coastguard Worker 98*61046927SAndroid Build Coastguard Worker /* Address format for various kinds of pointers. */ 99*61046927SAndroid Build Coastguard Worker nir_address_format ubo_addr_format; 100*61046927SAndroid Build Coastguard Worker nir_address_format ssbo_addr_format; 101*61046927SAndroid Build Coastguard Worker nir_address_format phys_ssbo_addr_format; 102*61046927SAndroid Build Coastguard Worker nir_address_format push_const_addr_format; 103*61046927SAndroid Build Coastguard Worker nir_address_format shared_addr_format; 104*61046927SAndroid Build Coastguard Worker nir_address_format task_payload_addr_format; 105*61046927SAndroid Build Coastguard Worker nir_address_format global_addr_format; 106*61046927SAndroid Build Coastguard Worker nir_address_format temp_addr_format; 107*61046927SAndroid Build Coastguard Worker nir_address_format constant_addr_format; 108*61046927SAndroid Build Coastguard Worker 109*61046927SAndroid Build Coastguard Worker /** Minimum UBO alignment. 110*61046927SAndroid Build Coastguard Worker * 111*61046927SAndroid Build Coastguard Worker * This should match VkPhysicalDeviceLimits::minUniformBufferOffsetAlignment 112*61046927SAndroid Build Coastguard Worker */ 113*61046927SAndroid Build Coastguard Worker uint32_t min_ubo_alignment; 114*61046927SAndroid Build Coastguard Worker 115*61046927SAndroid Build Coastguard Worker /** Minimum SSBO alignment. 116*61046927SAndroid Build Coastguard Worker * 117*61046927SAndroid Build Coastguard Worker * This should match VkPhysicalDeviceLimits::minStorageBufferOffsetAlignment 118*61046927SAndroid Build Coastguard Worker */ 119*61046927SAndroid Build Coastguard Worker uint32_t min_ssbo_alignment; 120*61046927SAndroid Build Coastguard Worker 121*61046927SAndroid Build Coastguard Worker const nir_shader *clc_shader; 122*61046927SAndroid Build Coastguard Worker 123*61046927SAndroid Build Coastguard Worker struct { 124*61046927SAndroid Build Coastguard Worker void (*func)(void *private_data, 125*61046927SAndroid Build Coastguard Worker enum nir_spirv_debug_level level, 126*61046927SAndroid Build Coastguard Worker size_t spirv_offset, 127*61046927SAndroid Build Coastguard Worker const char *message); 128*61046927SAndroid Build Coastguard Worker void *private_data; 129*61046927SAndroid Build Coastguard Worker } debug; 130*61046927SAndroid Build Coastguard Worker 131*61046927SAndroid Build Coastguard Worker /* Force texture sampling to be non-uniform. */ 132*61046927SAndroid Build Coastguard Worker bool force_tex_non_uniform; 133*61046927SAndroid Build Coastguard Worker /* Force SSBO accesses to be non-uniform. */ 134*61046927SAndroid Build Coastguard Worker bool force_ssbo_non_uniform; 135*61046927SAndroid Build Coastguard Worker 136*61046927SAndroid Build Coastguard Worker /* In Debug Builds, instead of emitting an OS break on failure, just return NULL from 137*61046927SAndroid Build Coastguard Worker * spirv_to_nir(). This is useful for the unit tests that want to report a test failed 138*61046927SAndroid Build Coastguard Worker * but continue executing other tests. 139*61046927SAndroid Build Coastguard Worker */ 140*61046927SAndroid Build Coastguard Worker bool skip_os_break_in_debug_build; 141*61046927SAndroid Build Coastguard Worker 142*61046927SAndroid Build Coastguard Worker /* Shader index provided by VkPipelineShaderStageNodeCreateInfoAMDX */ 143*61046927SAndroid Build Coastguard Worker uint32_t shader_index; 144*61046927SAndroid Build Coastguard Worker }; 145*61046927SAndroid Build Coastguard Worker 146*61046927SAndroid Build Coastguard Worker enum spirv_verify_result { 147*61046927SAndroid Build Coastguard Worker SPIRV_VERIFY_OK = 0, 148*61046927SAndroid Build Coastguard Worker SPIRV_VERIFY_PARSER_ERROR = 1, 149*61046927SAndroid Build Coastguard Worker SPIRV_VERIFY_ENTRY_POINT_NOT_FOUND = 2, 150*61046927SAndroid Build Coastguard Worker SPIRV_VERIFY_UNKNOWN_SPEC_INDEX = 3, 151*61046927SAndroid Build Coastguard Worker }; 152*61046927SAndroid Build Coastguard Worker 153*61046927SAndroid Build Coastguard Worker enum spirv_verify_result spirv_verify_gl_specialization_constants( 154*61046927SAndroid Build Coastguard Worker const uint32_t *words, size_t word_count, 155*61046927SAndroid Build Coastguard Worker struct nir_spirv_specialization *spec, unsigned num_spec, 156*61046927SAndroid Build Coastguard Worker gl_shader_stage stage, const char *entry_point_name); 157*61046927SAndroid Build Coastguard Worker 158*61046927SAndroid Build Coastguard Worker nir_shader *spirv_to_nir(const uint32_t *words, size_t word_count, 159*61046927SAndroid Build Coastguard Worker struct nir_spirv_specialization *specializations, 160*61046927SAndroid Build Coastguard Worker unsigned num_specializations, 161*61046927SAndroid Build Coastguard Worker gl_shader_stage stage, const char *entry_point_name, 162*61046927SAndroid Build Coastguard Worker const struct spirv_to_nir_options *options, 163*61046927SAndroid Build Coastguard Worker const nir_shader_compiler_options *nir_options); 164*61046927SAndroid Build Coastguard Worker 165*61046927SAndroid Build Coastguard Worker bool 166*61046927SAndroid Build Coastguard Worker spirv_library_to_nir_builder(FILE *fp, const uint32_t *words, size_t word_count, 167*61046927SAndroid Build Coastguard Worker const struct spirv_to_nir_options *options); 168*61046927SAndroid Build Coastguard Worker 169*61046927SAndroid Build Coastguard Worker void spirv_print_asm(FILE *fp, const uint32_t *words, size_t word_count); 170*61046927SAndroid Build Coastguard Worker 171*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus 172*61046927SAndroid Build Coastguard Worker } 173*61046927SAndroid Build Coastguard Worker #endif 174*61046927SAndroid Build Coastguard Worker 175*61046927SAndroid Build Coastguard Worker #endif /* _NIR_SPIRV_H_ */ 176