101e04c3fSmrg/* 201e04c3fSmrg * Copyright © 2015 Intel Corporation 301e04c3fSmrg * 401e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 501e04c3fSmrg * copy of this software and associated documentation files (the "Software"), 601e04c3fSmrg * to deal in the Software without restriction, including without limitation 701e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 801e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the 901e04c3fSmrg * Software is furnished to do so, subject to the following conditions: 1001e04c3fSmrg * 1101e04c3fSmrg * The above copyright notice and this permission notice (including the next 1201e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the 1301e04c3fSmrg * Software. 1401e04c3fSmrg * 1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1601e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1801e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1901e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2001e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 2101e04c3fSmrg * IN THE SOFTWARE. 2201e04c3fSmrg */ 2301e04c3fSmrg 2401e04c3fSmrg#ifndef BRW_NIR_H 2501e04c3fSmrg#define BRW_NIR_H 2601e04c3fSmrg 2701e04c3fSmrg#include "brw_reg.h" 2801e04c3fSmrg#include "compiler/nir/nir.h" 2901e04c3fSmrg#include "brw_compiler.h" 3001e04c3fSmrg 3101e04c3fSmrg#ifdef __cplusplus 3201e04c3fSmrgextern "C" { 3301e04c3fSmrg#endif 3401e04c3fSmrg 359f464c52Smayaint type_size_vec4(const struct glsl_type *type, bool bindless); 369f464c52Smayaint type_size_dvec4(const struct glsl_type *type, bool bindless); 3701e04c3fSmrg 3801e04c3fSmrgstatic inline int 399f464c52Smayatype_size_scalar_bytes(const struct glsl_type *type, bool bindless) 4001e04c3fSmrg{ 417ec681f3Smrg return glsl_count_dword_slots(type, bindless) * 4; 4201e04c3fSmrg} 4301e04c3fSmrg 4401e04c3fSmrgstatic inline int 459f464c52Smayatype_size_vec4_bytes(const struct glsl_type *type, bool bindless) 4601e04c3fSmrg{ 479f464c52Smaya return type_size_vec4(type, bindless) * 16; 4801e04c3fSmrg} 4901e04c3fSmrg 5001e04c3fSmrg/* Flags set in the instr->pass_flags field by i965 analysis passes */ 5101e04c3fSmrgenum { 5201e04c3fSmrg BRW_NIR_NON_BOOLEAN = 0x0, 5301e04c3fSmrg 5401e04c3fSmrg /* Indicates that the given instruction's destination is a boolean 5501e04c3fSmrg * value but that it needs to be resolved before it can be used. 5601e04c3fSmrg * On Gen <= 5, CMP instructions return a 32-bit value where the bottom 5701e04c3fSmrg * bit represents the actual true/false value of the compare and the top 5801e04c3fSmrg * 31 bits are undefined. In order to use this value, we have to do a 5901e04c3fSmrg * "resolve" operation by replacing the value of the CMP with -(x & 1) 6001e04c3fSmrg * to sign-extend the bottom bit to 0/~0. 6101e04c3fSmrg */ 6201e04c3fSmrg BRW_NIR_BOOLEAN_NEEDS_RESOLVE = 0x1, 6301e04c3fSmrg 6401e04c3fSmrg /* Indicates that the given instruction's destination is a boolean 6501e04c3fSmrg * value that has intentionally been left unresolved. Not all boolean 6601e04c3fSmrg * values need to be resolved immediately. For instance, if we have 6701e04c3fSmrg * 6801e04c3fSmrg * CMP r1 r2 r3 6901e04c3fSmrg * CMP r4 r5 r6 7001e04c3fSmrg * AND r7 r1 r4 7101e04c3fSmrg * 7201e04c3fSmrg * We don't have to resolve the result of the two CMP instructions 7301e04c3fSmrg * immediately because the AND still does an AND of the bottom bits. 7401e04c3fSmrg * Instead, we can save ourselves instructions by delaying the resolve 7501e04c3fSmrg * until after the AND. The result of the two CMP instructions is left 7601e04c3fSmrg * as BRW_NIR_BOOLEAN_UNRESOLVED. 7701e04c3fSmrg */ 7801e04c3fSmrg BRW_NIR_BOOLEAN_UNRESOLVED = 0x2, 7901e04c3fSmrg 8001e04c3fSmrg /* Indicates a that the given instruction's destination is a boolean 8101e04c3fSmrg * value that does not need a resolve. For instance, if you AND two 8201e04c3fSmrg * values that are BRW_NIR_BOOLEAN_NEEDS_RESOLVE then we know that both 8301e04c3fSmrg * values will be 0/~0 before we get them and the result of the AND is 8401e04c3fSmrg * also guaranteed to be 0/~0 and does not need a resolve. 8501e04c3fSmrg */ 8601e04c3fSmrg BRW_NIR_BOOLEAN_NO_RESOLVE = 0x3, 8701e04c3fSmrg 8801e04c3fSmrg /* A mask to mask the boolean status values off of instr->pass_flags */ 8901e04c3fSmrg BRW_NIR_BOOLEAN_MASK = 0x3, 9001e04c3fSmrg}; 9101e04c3fSmrg 9201e04c3fSmrgvoid brw_nir_analyze_boolean_resolves(nir_shader *nir); 9301e04c3fSmrg 947ec681f3Smrgvoid brw_preprocess_nir(const struct brw_compiler *compiler, 957ec681f3Smrg nir_shader *nir, 967ec681f3Smrg const nir_shader *softfp64); 9701e04c3fSmrg 9801e04c3fSmrgvoid 9901e04c3fSmrgbrw_nir_link_shaders(const struct brw_compiler *compiler, 1007ec681f3Smrg nir_shader *producer, nir_shader *consumer); 10101e04c3fSmrg 1027ec681f3Smrgbool brw_nir_lower_cs_intrinsics(nir_shader *nir); 1037ec681f3Smrgbool brw_nir_lower_alpha_to_coverage(nir_shader *shader); 1047ec681f3Smrgvoid brw_nir_lower_legacy_clipping(nir_shader *nir, 1057ec681f3Smrg int nr_userclip_plane_consts, 1067ec681f3Smrg struct brw_stage_prog_data *prog_data); 10701e04c3fSmrgvoid brw_nir_lower_vs_inputs(nir_shader *nir, 1087ec681f3Smrg bool edgeflag_is_last, 10901e04c3fSmrg const uint8_t *vs_attrib_wa_flags); 11001e04c3fSmrgvoid brw_nir_lower_vue_inputs(nir_shader *nir, 11101e04c3fSmrg const struct brw_vue_map *vue_map); 11201e04c3fSmrgvoid brw_nir_lower_tes_inputs(nir_shader *nir, const struct brw_vue_map *vue); 11301e04c3fSmrgvoid brw_nir_lower_fs_inputs(nir_shader *nir, 1147ec681f3Smrg const struct intel_device_info *devinfo, 11501e04c3fSmrg const struct brw_wm_prog_key *key); 11601e04c3fSmrgvoid brw_nir_lower_vue_outputs(nir_shader *nir); 11701e04c3fSmrgvoid brw_nir_lower_tcs_outputs(nir_shader *nir, const struct brw_vue_map *vue, 11801e04c3fSmrg GLenum tes_primitive_mode); 11901e04c3fSmrgvoid brw_nir_lower_fs_outputs(nir_shader *nir); 12001e04c3fSmrg 1219f464c52Smayabool brw_nir_lower_conversions(nir_shader *nir); 1229f464c52Smaya 1237ec681f3Smrgbool brw_nir_lower_scoped_barriers(nir_shader *nir); 1247ec681f3Smrg 1257ec681f3Smrgbool brw_nir_lower_storage_image(nir_shader *nir, 1267ec681f3Smrg const struct intel_device_info *devinfo); 12701e04c3fSmrgvoid brw_nir_rewrite_image_intrinsic(nir_intrinsic_instr *intrin, 12801e04c3fSmrg nir_ssa_def *index); 1299f464c52Smayavoid brw_nir_rewrite_bindless_image_intrinsic(nir_intrinsic_instr *intrin, 1309f464c52Smaya nir_ssa_def *handle); 1319f464c52Smaya 1327ec681f3Smrgbool brw_nir_lower_mem_access_bit_sizes(nir_shader *shader, 1337ec681f3Smrg const struct 1347ec681f3Smrg intel_device_info *devinfo); 1357ec681f3Smrg 1367ec681f3Smrgvoid brw_postprocess_nir(nir_shader *nir, 1377ec681f3Smrg const struct brw_compiler *compiler, 1387ec681f3Smrg bool is_scalar, 1397ec681f3Smrg bool debug_enabled, 1407ec681f3Smrg bool robust_buffer_access); 14101e04c3fSmrg 1427ec681f3Smrgbool brw_nir_clamp_image_1d_2d_array_sizes(nir_shader *shader); 14301e04c3fSmrg 14401e04c3fSmrgbool brw_nir_apply_attribute_workarounds(nir_shader *nir, 14501e04c3fSmrg const uint8_t *attrib_wa_flags); 14601e04c3fSmrg 14701e04c3fSmrgbool brw_nir_apply_trig_workarounds(nir_shader *nir); 14801e04c3fSmrg 14901e04c3fSmrgvoid brw_nir_apply_tcs_quads_workaround(nir_shader *nir); 15001e04c3fSmrg 1517ec681f3Smrgvoid brw_nir_apply_key(nir_shader *nir, 1527ec681f3Smrg const struct brw_compiler *compiler, 1537ec681f3Smrg const struct brw_base_prog_key *key, 1547ec681f3Smrg unsigned max_subgroup_size, 1557ec681f3Smrg bool is_scalar); 15601e04c3fSmrg 1577ec681f3Smrgenum brw_conditional_mod brw_cmod_for_nir_comparison(nir_op op); 1587ec681f3Smrguint32_t brw_aop_for_nir_intrinsic(const nir_intrinsic_instr *atomic); 1597ec681f3Smrgenum brw_reg_type brw_type_for_nir_type(const struct intel_device_info *devinfo, 16001e04c3fSmrg nir_alu_type type); 16101e04c3fSmrg 16201e04c3fSmrgvoid brw_nir_setup_glsl_uniforms(void *mem_ctx, nir_shader *shader, 16301e04c3fSmrg const struct gl_program *prog, 16401e04c3fSmrg struct brw_stage_prog_data *stage_prog_data, 16501e04c3fSmrg bool is_scalar); 16601e04c3fSmrg 16701e04c3fSmrgvoid brw_nir_setup_arb_uniforms(void *mem_ctx, nir_shader *shader, 16801e04c3fSmrg struct gl_program *prog, 16901e04c3fSmrg struct brw_stage_prog_data *stage_prog_data); 17001e04c3fSmrg 17101e04c3fSmrgvoid brw_nir_lower_gl_images(nir_shader *shader, 17201e04c3fSmrg const struct gl_program *prog); 17301e04c3fSmrg 17401e04c3fSmrgvoid brw_nir_analyze_ubo_ranges(const struct brw_compiler *compiler, 17501e04c3fSmrg nir_shader *nir, 17601e04c3fSmrg const struct brw_vs_prog_key *vs_key, 17701e04c3fSmrg struct brw_ubo_range out_ranges[4]); 17801e04c3fSmrg 17901e04c3fSmrgbool brw_nir_opt_peephole_ffma(nir_shader *shader); 18001e04c3fSmrg 1817ec681f3Smrgvoid brw_nir_optimize(nir_shader *nir, 1827ec681f3Smrg const struct brw_compiler *compiler, 1837ec681f3Smrg bool is_scalar, 1847ec681f3Smrg bool allow_copies); 18501e04c3fSmrg 18601e04c3fSmrgnir_shader *brw_nir_create_passthrough_tcs(void *mem_ctx, 18701e04c3fSmrg const struct brw_compiler *compiler, 18801e04c3fSmrg const nir_shader_compiler_options *options, 18901e04c3fSmrg const struct brw_tcs_prog_key *key); 19001e04c3fSmrg 19101e04c3fSmrg#define BRW_NIR_FRAG_OUTPUT_INDEX_SHIFT 0 19201e04c3fSmrg#define BRW_NIR_FRAG_OUTPUT_INDEX_MASK INTEL_MASK(0, 0) 19301e04c3fSmrg#define BRW_NIR_FRAG_OUTPUT_LOCATION_SHIFT 1 19401e04c3fSmrg#define BRW_NIR_FRAG_OUTPUT_LOCATION_MASK INTEL_MASK(31, 1) 19501e04c3fSmrg 1967ec681f3Smrgbool brw_nir_move_interpolation_to_top(nir_shader *nir); 1977ec681f3Smrgbool brw_nir_demote_sample_qualifiers(nir_shader *nir); 1987ec681f3Smrgvoid brw_nir_populate_wm_prog_data(const nir_shader *shader, 1997ec681f3Smrg const struct intel_device_info *devinfo, 2007ec681f3Smrg const struct brw_wm_prog_key *key, 2017ec681f3Smrg struct brw_wm_prog_data *prog_data); 2027ec681f3Smrg 20301e04c3fSmrg#ifdef __cplusplus 20401e04c3fSmrg} 20501e04c3fSmrg#endif 20601e04c3fSmrg 20701e04c3fSmrg#endif /* BRW_NIR_H */ 208