2 * Copyright © 2015 Intel Corporation
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:
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
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
26 #include "brw_context.h"
28 #include "compiler/nir/nir.h"
34 /* Flags set in the instr->pass_flags field by i965 analysis passes */
36 BRW_NIR_NON_BOOLEAN = 0x0,
38 /* Indicates that the given instruction's destination is a boolean
39 * value but that it needs to be resolved before it can be used.
40 * On Gen <= 5, CMP instructions return a 32-bit value where the bottom
41 * bit represents the actual true/false value of the compare and the top
42 * 31 bits are undefined. In order to use this value, we have to do a
43 * "resolve" operation by replacing the value of the CMP with -(x & 1)
44 * to sign-extend the bottom bit to 0/~0.
46 BRW_NIR_BOOLEAN_NEEDS_RESOLVE = 0x1,
48 /* Indicates that the given instruction's destination is a boolean
49 * value that has intentionally been left unresolved. Not all boolean
50 * values need to be resolved immediately. For instance, if we have
56 * We don't have to resolve the result of the two CMP instructions
57 * immediately because the AND still does an AND of the bottom bits.
58 * Instead, we can save ourselves instructions by delaying the resolve
59 * until after the AND. The result of the two CMP instructions is left
60 * as BRW_NIR_BOOLEAN_UNRESOLVED.
62 BRW_NIR_BOOLEAN_UNRESOLVED = 0x2,
64 /* Indicates a that the given instruction's destination is a boolean
65 * value that does not need a resolve. For instance, if you AND two
66 * values that are BRW_NIR_BOOLEAN_NEEDS_RESOLVE then we know that both
67 * values will be 0/~0 before we get them and the result of the AND is
68 * also guaranteed to be 0/~0 and does not need a resolve.
70 BRW_NIR_BOOLEAN_NO_RESOLVE = 0x3,
72 /* A mask to mask the boolean status values off of instr->pass_flags */
73 BRW_NIR_BOOLEAN_MASK = 0x3,
76 void brw_nir_analyze_boolean_resolves(nir_shader *nir);
78 nir_shader *brw_create_nir(struct brw_context *brw,
79 const struct gl_shader_program *shader_prog,
80 const struct gl_program *prog,
81 gl_shader_stage stage,
84 nir_shader *brw_preprocess_nir(nir_shader *nir, bool is_scalar);
86 void brw_nir_lower_vs_inputs(nir_shader *nir,
87 const struct brw_device_info *devinfo,
89 bool use_legacy_snorm_formula,
90 const uint8_t *vs_attrib_wa_flags);
91 void brw_nir_lower_vue_inputs(nir_shader *nir, bool is_scalar,
92 const struct brw_vue_map *vue_map);
93 void brw_nir_lower_tes_inputs(nir_shader *nir, const struct brw_vue_map *vue);
94 void brw_nir_lower_fs_inputs(nir_shader *nir);
95 void brw_nir_lower_vue_outputs(nir_shader *nir, bool is_scalar);
96 void brw_nir_lower_tcs_outputs(nir_shader *nir, const struct brw_vue_map *vue);
97 void brw_nir_lower_fs_outputs(nir_shader *nir);
99 nir_shader *brw_postprocess_nir(nir_shader *nir,
100 const struct brw_device_info *devinfo,
103 bool brw_nir_apply_attribute_workarounds(nir_shader *nir,
104 bool use_legacy_snorm_formula,
105 const uint8_t *attrib_wa_flags);
107 nir_shader *brw_nir_apply_sampler_key(nir_shader *nir,
108 const struct brw_device_info *devinfo,
109 const struct brw_sampler_prog_key_data *key,
112 enum brw_reg_type brw_type_for_nir_type(nir_alu_type type);
114 enum glsl_base_type brw_glsl_base_type_for_nir_type(nir_alu_type type);
116 void brw_nir_setup_glsl_uniforms(nir_shader *shader,
117 struct gl_shader_program *shader_prog,
118 const struct gl_program *prog,
119 struct brw_stage_prog_data *stage_prog_data,
122 void brw_nir_setup_arb_uniforms(nir_shader *shader, struct gl_program *prog,
123 struct brw_stage_prog_data *stage_prog_data);
125 bool brw_nir_opt_peephole_ffma(nir_shader *shader);