1a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand/* 2a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * Copyright © 2015 Intel Corporation 3a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * 4a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * Permission is hereby granted, free of charge, to any person obtaining a 5a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * copy of this software and associated documentation files (the "Software"), 6a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * to deal in the Software without restriction, including without limitation 7a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * and/or sell copies of the Software, and to permit persons to whom the 9a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * Software is furnished to do so, subject to the following conditions: 10a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * 11a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * The above copyright notice and this permission notice (including the next 12a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * paragraph) shall be included in all copies or substantial portions of the 13a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * Software. 14a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * 15a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * IN THE SOFTWARE. 22a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand */ 23a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand 24a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand#pragma once 25a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand 2697e205fd35bf77fd761caf24c611ff72cc0d85e2Eduardo Lima Mitev#include "brw_reg.h" 27a39a8fbbaa129f4e52f2a3ad2747182e9a74d910Emil Velikov#include "compiler/nir/nir.h" 28555b22a446362a2b0f9bae3c57cdaa330be89edbJason Ekstrand#include "brw_compiler.h" 29a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand 30a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand#ifdef __cplusplus 31a55af2699feb8f64d6f480b223204da071606721Jason Ekstrandextern "C" { 32a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand#endif 33a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand 34555b22a446362a2b0f9bae3c57cdaa330be89edbJason Ekstrandint type_size_scalar(const struct glsl_type *type); 35555b22a446362a2b0f9bae3c57cdaa330be89edbJason Ekstrandint type_size_vec4(const struct glsl_type *type); 36555b22a446362a2b0f9bae3c57cdaa330be89edbJason Ekstrandint type_size_dvec4(const struct glsl_type *type); 37555b22a446362a2b0f9bae3c57cdaa330be89edbJason Ekstrand 3886a2447eec7e87e46e842ca7a3ad5cd9fadb1ca5Jason Ekstrandstatic inline int 3986a2447eec7e87e46e842ca7a3ad5cd9fadb1ca5Jason Ekstrandtype_size_scalar_bytes(const struct glsl_type *type) 4086a2447eec7e87e46e842ca7a3ad5cd9fadb1ca5Jason Ekstrand{ 4186a2447eec7e87e46e842ca7a3ad5cd9fadb1ca5Jason Ekstrand return type_size_scalar(type) * 4; 4286a2447eec7e87e46e842ca7a3ad5cd9fadb1ca5Jason Ekstrand} 4386a2447eec7e87e46e842ca7a3ad5cd9fadb1ca5Jason Ekstrand 4486a2447eec7e87e46e842ca7a3ad5cd9fadb1ca5Jason Ekstrandstatic inline int 4586a2447eec7e87e46e842ca7a3ad5cd9fadb1ca5Jason Ekstrandtype_size_vec4_bytes(const struct glsl_type *type) 4686a2447eec7e87e46e842ca7a3ad5cd9fadb1ca5Jason Ekstrand{ 4786a2447eec7e87e46e842ca7a3ad5cd9fadb1ca5Jason Ekstrand return type_size_vec4(type) * 16; 4886a2447eec7e87e46e842ca7a3ad5cd9fadb1ca5Jason Ekstrand} 4986a2447eec7e87e46e842ca7a3ad5cd9fadb1ca5Jason Ekstrand 50a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand/* Flags set in the instr->pass_flags field by i965 analysis passes */ 51a55af2699feb8f64d6f480b223204da071606721Jason Ekstrandenum { 52a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand BRW_NIR_NON_BOOLEAN = 0x0, 53a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand 54a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand /* Indicates that the given instruction's destination is a boolean 55a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * value but that it needs to be resolved before it can be used. 56a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * On Gen <= 5, CMP instructions return a 32-bit value where the bottom 57a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * bit represents the actual true/false value of the compare and the top 58a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * 31 bits are undefined. In order to use this value, we have to do a 59a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * "resolve" operation by replacing the value of the CMP with -(x & 1) 60a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * to sign-extend the bottom bit to 0/~0. 61a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand */ 62a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand BRW_NIR_BOOLEAN_NEEDS_RESOLVE = 0x1, 63a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand 64a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand /* Indicates that the given instruction's destination is a boolean 65a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * value that has intentionally been left unresolved. Not all boolean 66a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * values need to be resolved immediately. For instance, if we have 67a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * 68a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * CMP r1 r2 r3 69a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * CMP r4 r5 r6 70a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * AND r7 r1 r4 71a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * 72a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * We don't have to resolve the result of the two CMP instructions 73a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * immediately because the AND still does an AND of the bottom bits. 74a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * Instead, we can save ourselves instructions by delaying the resolve 75a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * until after the AND. The result of the two CMP instructions is left 76a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * as BRW_NIR_BOOLEAN_UNRESOLVED. 77a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand */ 78a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand BRW_NIR_BOOLEAN_UNRESOLVED = 0x2, 79a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand 80a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand /* Indicates a that the given instruction's destination is a boolean 81a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * value that does not need a resolve. For instance, if you AND two 82a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * values that are BRW_NIR_BOOLEAN_NEEDS_RESOLVE then we know that both 83a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * values will be 0/~0 before we get them and the result of the AND is 84a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand * also guaranteed to be 0/~0 and does not need a resolve. 85a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand */ 86a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand BRW_NIR_BOOLEAN_NO_RESOLVE = 0x3, 87a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand 88a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand /* A mask to mask the boolean status values off of instr->pass_flags */ 89a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand BRW_NIR_BOOLEAN_MASK = 0x3, 90a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand}; 91a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand 92a55af2699feb8f64d6f480b223204da071606721Jason Ekstrandvoid brw_nir_analyze_boolean_resolves(nir_shader *nir); 93a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand 94b0dffdc616801a1fd8534502e11ac840369041abKenneth Graunkenir_shader *brw_preprocess_nir(const struct brw_compiler *compiler, 95b0dffdc616801a1fd8534502e11ac840369041abKenneth Graunke nir_shader *nir); 96cfbd9831f89ef165e7998d0b8524a1aefedec404Kenneth Graunke 973ef0957dac11edee7babc9746ec766dcb055d909Jordan Justenbool brw_nir_lower_intrinsics(nir_shader *nir, 983ef0957dac11edee7babc9746ec766dcb055d909Jordan Justen struct brw_stage_prog_data *prog_data); 99cfbd9831f89ef165e7998d0b8524a1aefedec404Kenneth Graunkevoid brw_nir_lower_vs_inputs(nir_shader *nir, 100cfbd9831f89ef165e7998d0b8524a1aefedec404Kenneth Graunke bool is_scalar, 101cfbd9831f89ef165e7998d0b8524a1aefedec404Kenneth Graunke bool use_legacy_snorm_formula, 102cfbd9831f89ef165e7998d0b8524a1aefedec404Kenneth Graunke const uint8_t *vs_attrib_wa_flags); 1038151003ade952c3e9d8284fada9237e1311cf173Kenneth Graunkevoid brw_nir_lower_vue_inputs(nir_shader *nir, bool is_scalar, 1048151003ade952c3e9d8284fada9237e1311cf173Kenneth Graunke const struct brw_vue_map *vue_map); 10515b3639bf1b0676e74b107d74653185eedbc6688Kenneth Graunkevoid brw_nir_lower_tes_inputs(nir_shader *nir, const struct brw_vue_map *vue); 1060d5071db5e50629a63490639a3c86dfc65bf27abKenneth Graunkevoid brw_nir_lower_fs_inputs(nir_shader *nir, 107111f6b250d01fa1937103f24b5cb54b15dd77fbfJason Ekstrand const struct gen_device_info *devinfo, 108246db0063eb6e01aad961b1c73d32fca911ae1dfJason Ekstrand const struct brw_wm_prog_key *key); 109cfbd9831f89ef165e7998d0b8524a1aefedec404Kenneth Graunkevoid brw_nir_lower_vue_outputs(nir_shader *nir, bool is_scalar); 110e6ae19944d977dc91bc45adff679337182c20683Kenneth Graunkevoid brw_nir_lower_tcs_outputs(nir_shader *nir, const struct brw_vue_map *vue, 111e6ae19944d977dc91bc45adff679337182c20683Kenneth Graunke GLenum tes_primitive_mode); 112cfbd9831f89ef165e7998d0b8524a1aefedec404Kenneth Graunkevoid brw_nir_lower_fs_outputs(nir_shader *nir); 1137d021cb15e6d67ecef8b020fd36c4a680bcc9c39Jordan Justenvoid brw_nir_lower_cs_shared(nir_shader *nir); 114cfbd9831f89ef165e7998d0b8524a1aefedec404Kenneth Graunke 1159cf108193b61c342c94c4cd980c4b403638e1051Jason Ekstrandnir_shader *brw_postprocess_nir(nir_shader *nir, 116e729504fb1799c3ae31cea76d73946530ef9806fTimothy Arceri const struct brw_compiler *compiler, 1179cf108193b61c342c94c4cd980c4b403638e1051Jason Ekstrand bool is_scalar); 1189cf108193b61c342c94c4cd980c4b403638e1051Jason Ekstrand 119d56ae2d1605fc1b5a3fdf5aba9aefc3c7692a4baKenneth Graunkebool brw_nir_apply_attribute_workarounds(nir_shader *nir, 120d56ae2d1605fc1b5a3fdf5aba9aefc3c7692a4baKenneth Graunke bool use_legacy_snorm_formula, 121d56ae2d1605fc1b5a3fdf5aba9aefc3c7692a4baKenneth Graunke const uint8_t *attrib_wa_flags); 1226c8ba59cff14a1a86273f4008ff2a8e68335ab25Jason Ekstrand 123bfd17c76c1267756ea16051cbe174cb23ff49f44Kenneth Graunkebool brw_nir_apply_trig_workarounds(nir_shader *nir); 124bfd17c76c1267756ea16051cbe174cb23ff49f44Kenneth Graunke 1259e778837ff9abba0bed963d003297e3333cc7f1fKenneth Graunkevoid brw_nir_apply_tcs_quads_workaround(nir_shader *nir); 1269e778837ff9abba0bed963d003297e3333cc7f1fKenneth Graunke 1276c8ba59cff14a1a86273f4008ff2a8e68335ab25Jason Ekstrandnir_shader *brw_nir_apply_sampler_key(nir_shader *nir, 128e729504fb1799c3ae31cea76d73946530ef9806fTimothy Arceri const struct brw_compiler *compiler, 1296c8ba59cff14a1a86273f4008ff2a8e68335ab25Jason Ekstrand const struct brw_sampler_prog_key_data *key, 1306c8ba59cff14a1a86273f4008ff2a8e68335ab25Jason Ekstrand bool is_scalar); 1316c8ba59cff14a1a86273f4008ff2a8e68335ab25Jason Ekstrand 13297e205fd35bf77fd761caf24c611ff72cc0d85e2Eduardo Lima Mitevenum brw_reg_type brw_type_for_nir_type(nir_alu_type type); 13397e205fd35bf77fd761caf24c611ff72cc0d85e2Eduardo Lima Mitev 134db8a6de571bb72ef43209a415e5492001a87b1d8Eduardo Lima Mitevenum glsl_base_type brw_glsl_base_type_for_nir_type(nir_alu_type type); 135db8a6de571bb72ef43209a415e5492001a87b1d8Eduardo Lima Mitev 1367fee8b6f055831bc070bb36d02a8b1c4d601652aJason Ekstrandvoid brw_nir_setup_glsl_uniforms(nir_shader *shader, 1377fee8b6f055831bc070bb36d02a8b1c4d601652aJason Ekstrand const struct gl_program *prog, 1387fee8b6f055831bc070bb36d02a8b1c4d601652aJason Ekstrand struct brw_stage_prog_data *stage_prog_data, 1397fee8b6f055831bc070bb36d02a8b1c4d601652aJason Ekstrand bool is_scalar); 1407fee8b6f055831bc070bb36d02a8b1c4d601652aJason Ekstrand 14103c4171b577b06b1d8dde50b6eb9507d8ef4c1ceJason Ekstrandvoid brw_nir_setup_arb_uniforms(nir_shader *shader, struct gl_program *prog, 14203c4171b577b06b1d8dde50b6eb9507d8ef4c1ceJason Ekstrand struct brw_stage_prog_data *stage_prog_data); 14303c4171b577b06b1d8dde50b6eb9507d8ef4c1ceJason Ekstrand 14494ff35204dba0ddbd7f5c4342206c8acba22d32fEduardo Lima Mitevbool brw_nir_opt_peephole_ffma(nir_shader *shader); 14594ff35204dba0ddbd7f5c4342206c8acba22d32fEduardo Lima Mitev 1467dac8820730777756c00d7024330517848dc3b9fFrancisco Jerez#define BRW_NIR_FRAG_OUTPUT_INDEX_SHIFT 0 1477dac8820730777756c00d7024330517848dc3b9fFrancisco Jerez#define BRW_NIR_FRAG_OUTPUT_INDEX_MASK INTEL_MASK(0, 0) 1487dac8820730777756c00d7024330517848dc3b9fFrancisco Jerez#define BRW_NIR_FRAG_OUTPUT_LOCATION_SHIFT 1 1497dac8820730777756c00d7024330517848dc3b9fFrancisco Jerez#define BRW_NIR_FRAG_OUTPUT_LOCATION_MASK INTEL_MASK(31, 1) 1507dac8820730777756c00d7024330517848dc3b9fFrancisco Jerez 151a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand#ifdef __cplusplus 152a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand} 153a55af2699feb8f64d6f480b223204da071606721Jason Ekstrand#endif 154