2015-03-17 11:29:01 -07:00
|
|
|
/*
|
|
|
|
* Copyright © 2015 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2017-03-20 16:04:38 +00:00
|
|
|
#ifndef BRW_NIR_H
|
|
|
|
#define BRW_NIR_H
|
2015-03-17 11:29:01 -07:00
|
|
|
|
2015-04-17 18:10:50 +02:00
|
|
|
#include "brw_reg.h"
|
2016-01-18 12:54:03 +02:00
|
|
|
#include "compiler/nir/nir.h"
|
2016-08-19 04:28:31 -07:00
|
|
|
#include "brw_compiler.h"
|
2021-07-12 13:20:22 +02:00
|
|
|
#include "nir_builder.h"
|
2015-03-17 11:29:01 -07:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2019-03-29 12:39:48 +11:00
|
|
|
int type_size_vec4(const struct glsl_type *type, bool bindless);
|
|
|
|
int type_size_dvec4(const struct glsl_type *type, bool bindless);
|
2016-08-19 04:28:31 -07:00
|
|
|
|
2016-05-25 17:26:42 -07:00
|
|
|
static inline int
|
2019-03-29 12:39:48 +11:00
|
|
|
type_size_scalar_bytes(const struct glsl_type *type, bool bindless)
|
2016-05-25 17:26:42 -07:00
|
|
|
{
|
2020-01-06 13:09:25 -08:00
|
|
|
return glsl_count_dword_slots(type, bindless) * 4;
|
2016-05-25 17:26:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
2019-03-29 12:39:48 +11:00
|
|
|
type_size_vec4_bytes(const struct glsl_type *type, bool bindless)
|
2016-05-25 17:26:42 -07:00
|
|
|
{
|
2019-03-29 12:39:48 +11:00
|
|
|
return type_size_vec4(type, bindless) * 16;
|
2016-05-25 17:26:42 -07:00
|
|
|
}
|
|
|
|
|
2015-03-17 11:29:01 -07:00
|
|
|
/* Flags set in the instr->pass_flags field by i965 analysis passes */
|
|
|
|
enum {
|
|
|
|
BRW_NIR_NON_BOOLEAN = 0x0,
|
|
|
|
|
|
|
|
/* Indicates that the given instruction's destination is a boolean
|
|
|
|
* value but that it needs to be resolved before it can be used.
|
|
|
|
* On Gen <= 5, CMP instructions return a 32-bit value where the bottom
|
|
|
|
* bit represents the actual true/false value of the compare and the top
|
|
|
|
* 31 bits are undefined. In order to use this value, we have to do a
|
|
|
|
* "resolve" operation by replacing the value of the CMP with -(x & 1)
|
|
|
|
* to sign-extend the bottom bit to 0/~0.
|
|
|
|
*/
|
|
|
|
BRW_NIR_BOOLEAN_NEEDS_RESOLVE = 0x1,
|
|
|
|
|
|
|
|
/* Indicates that the given instruction's destination is a boolean
|
|
|
|
* value that has intentionally been left unresolved. Not all boolean
|
|
|
|
* values need to be resolved immediately. For instance, if we have
|
|
|
|
*
|
|
|
|
* CMP r1 r2 r3
|
|
|
|
* CMP r4 r5 r6
|
|
|
|
* AND r7 r1 r4
|
|
|
|
*
|
|
|
|
* We don't have to resolve the result of the two CMP instructions
|
|
|
|
* immediately because the AND still does an AND of the bottom bits.
|
|
|
|
* Instead, we can save ourselves instructions by delaying the resolve
|
|
|
|
* until after the AND. The result of the two CMP instructions is left
|
|
|
|
* as BRW_NIR_BOOLEAN_UNRESOLVED.
|
|
|
|
*/
|
|
|
|
BRW_NIR_BOOLEAN_UNRESOLVED = 0x2,
|
|
|
|
|
|
|
|
/* Indicates a that the given instruction's destination is a boolean
|
|
|
|
* value that does not need a resolve. For instance, if you AND two
|
|
|
|
* values that are BRW_NIR_BOOLEAN_NEEDS_RESOLVE then we know that both
|
|
|
|
* values will be 0/~0 before we get them and the result of the AND is
|
|
|
|
* also guaranteed to be 0/~0 and does not need a resolve.
|
|
|
|
*/
|
|
|
|
BRW_NIR_BOOLEAN_NO_RESOLVE = 0x3,
|
|
|
|
|
|
|
|
/* A mask to mask the boolean status values off of instr->pass_flags */
|
|
|
|
BRW_NIR_BOOLEAN_MASK = 0x3,
|
|
|
|
};
|
|
|
|
|
|
|
|
void brw_nir_analyze_boolean_resolves(nir_shader *nir);
|
|
|
|
|
2019-06-04 18:19:06 -05:00
|
|
|
void brw_preprocess_nir(const struct brw_compiler *compiler,
|
|
|
|
nir_shader *nir,
|
|
|
|
const nir_shader *softfp64);
|
2016-02-24 22:11:35 -08:00
|
|
|
|
2017-10-28 08:57:23 -07:00
|
|
|
void
|
|
|
|
brw_nir_link_shaders(const struct brw_compiler *compiler,
|
2019-06-04 18:23:17 -05:00
|
|
|
nir_shader *producer, nir_shader *consumer);
|
2017-10-28 08:57:23 -07:00
|
|
|
|
2020-04-28 13:09:27 -07:00
|
|
|
bool brw_nir_lower_cs_intrinsics(nir_shader *nir);
|
2020-08-07 11:25:54 -05:00
|
|
|
bool brw_nir_lower_alpha_to_coverage(nir_shader *shader);
|
2016-02-24 22:11:35 -08:00
|
|
|
void brw_nir_lower_vs_inputs(nir_shader *nir,
|
2021-06-08 15:04:42 +10:00
|
|
|
bool edgeflag_is_last,
|
2016-02-24 22:11:35 -08:00
|
|
|
const uint8_t *vs_attrib_wa_flags);
|
2017-05-04 16:36:26 -07:00
|
|
|
void brw_nir_lower_vue_inputs(nir_shader *nir,
|
2016-02-24 23:43:17 -08:00
|
|
|
const struct brw_vue_map *vue_map);
|
2016-02-24 22:34:51 -08:00
|
|
|
void brw_nir_lower_tes_inputs(nir_shader *nir, const struct brw_vue_map *vue);
|
i965: Move Gen4-5 interpolation stuff to brw_wm_prog_data.
This fixes glxgears rendering, which had surprisingly been broken since
late October! Specifically, commit 91d61fbf7cb61a44adcaae51ee08ad0dd6b.
glxgears uses glShadeModel(GL_FLAT) when drawing the main portion of the
gears, then uses glShadeModel(GL_SMOOTH) for drawing the Gouraud-shaded
inner portion of the gears. This results in the same fragment program
having two different state-dependent interpolation maps: one where
gl_Color is flat, and another where it's smooth.
The problem is that there's only one gen4_fragment_program, so it can't
store both. Each FS compile would trash the last one. But, the FS
compiles are cached, so the first one would store FLAT, and the second
would see a matching program in the cache and never bother to compile
one with SMOOTH. (Clearing the program cache on every draw made it
render correctly.)
Instead, move it to brw_wm_prog_data, where we can keep a copy for
every specialization of the program. The only downside is bloating
the structure a bit, but we can tighten that up a bit if we need to.
This also lets us kill gen4_fragment_program entirely!
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Timothy Arceri <timothy.arceri@collabora.com>
2017-01-13 14:29:52 -08:00
|
|
|
void brw_nir_lower_fs_inputs(nir_shader *nir,
|
2021-04-05 13:19:39 -07:00
|
|
|
const struct intel_device_info *devinfo,
|
2016-09-14 10:39:52 -07:00
|
|
|
const struct brw_wm_prog_key *key);
|
2018-05-23 11:33:51 -07:00
|
|
|
void brw_nir_lower_vue_outputs(nir_shader *nir);
|
2016-11-24 01:50:10 -08:00
|
|
|
void brw_nir_lower_tcs_outputs(nir_shader *nir, const struct brw_vue_map *vue,
|
2022-01-19 11:43:15 +10:00
|
|
|
enum tess_primitive_mode tes_primitive_mode);
|
2016-02-24 22:11:35 -08:00
|
|
|
void brw_nir_lower_fs_outputs(nir_shader *nir);
|
|
|
|
|
2018-12-17 09:17:06 +01:00
|
|
|
bool brw_nir_lower_conversions(nir_shader *nir);
|
|
|
|
|
2020-05-05 10:18:29 +02:00
|
|
|
bool brw_nir_lower_scoped_barriers(nir_shader *nir);
|
|
|
|
|
2021-02-17 13:47:36 +02:00
|
|
|
bool brw_nir_lower_shading_rate_output(nir_shader *nir);
|
|
|
|
|
2021-02-03 11:34:46 -08:00
|
|
|
bool brw_nir_lower_storage_image(nir_shader *nir,
|
2021-08-10 17:30:13 -07:00
|
|
|
const struct intel_device_info *devinfo);
|
2018-01-27 13:19:57 -08:00
|
|
|
|
2019-02-28 10:02:03 -06:00
|
|
|
bool brw_nir_lower_mem_access_bit_sizes(nir_shader *shader,
|
2021-04-12 20:17:16 -07:00
|
|
|
const struct
|
|
|
|
intel_device_info *devinfo);
|
2018-11-12 18:48:10 -06:00
|
|
|
|
2019-06-04 18:19:06 -05:00
|
|
|
void brw_postprocess_nir(nir_shader *nir,
|
|
|
|
const struct brw_compiler *compiler,
|
2021-03-23 11:08:32 -07:00
|
|
|
bool is_scalar,
|
2021-04-09 14:42:53 -07:00
|
|
|
bool debug_enabled,
|
|
|
|
bool robust_buffer_access);
|
2015-11-11 09:40:51 -08:00
|
|
|
|
2020-01-13 15:11:25 +02:00
|
|
|
bool brw_nir_clamp_image_1d_2d_array_sizes(nir_shader *shader);
|
|
|
|
|
2016-01-13 20:33:15 -08:00
|
|
|
bool brw_nir_apply_attribute_workarounds(nir_shader *nir,
|
|
|
|
const uint8_t *attrib_wa_flags);
|
2015-11-11 11:01:59 -08:00
|
|
|
|
2016-04-07 15:04:35 -07:00
|
|
|
bool brw_nir_apply_trig_workarounds(nir_shader *nir);
|
|
|
|
|
2022-05-06 18:52:47 +03:00
|
|
|
bool brw_nir_limit_trig_input_range_workaround(nir_shader *nir);
|
|
|
|
|
2016-06-07 18:18:49 -07:00
|
|
|
void brw_nir_apply_tcs_quads_workaround(nir_shader *nir);
|
|
|
|
|
2019-02-22 11:15:21 -06:00
|
|
|
void brw_nir_apply_key(nir_shader *nir,
|
|
|
|
const struct brw_compiler *compiler,
|
|
|
|
const struct brw_base_prog_key *key,
|
2019-02-22 10:48:39 -06:00
|
|
|
unsigned max_subgroup_size,
|
2019-02-22 11:15:21 -06:00
|
|
|
bool is_scalar);
|
2015-11-11 11:01:59 -08:00
|
|
|
|
2019-08-02 15:19:16 -05:00
|
|
|
enum brw_conditional_mod brw_cmod_for_nir_comparison(nir_op op);
|
2019-08-20 23:10:50 -05:00
|
|
|
uint32_t brw_aop_for_nir_intrinsic(const nir_intrinsic_instr *atomic);
|
2021-04-05 13:19:39 -07:00
|
|
|
enum brw_reg_type brw_type_for_nir_type(const struct intel_device_info *devinfo,
|
2017-01-20 19:03:21 -08:00
|
|
|
nir_alu_type type);
|
2015-04-17 18:10:50 +02:00
|
|
|
|
2017-09-28 21:45:41 -07:00
|
|
|
void brw_nir_setup_glsl_uniforms(void *mem_ctx, nir_shader *shader,
|
2015-10-02 10:45:53 -07:00
|
|
|
const struct gl_program *prog,
|
|
|
|
struct brw_stage_prog_data *stage_prog_data,
|
|
|
|
bool is_scalar);
|
|
|
|
|
2017-09-28 21:45:41 -07:00
|
|
|
void brw_nir_setup_arb_uniforms(void *mem_ctx, nir_shader *shader,
|
|
|
|
struct gl_program *prog,
|
2015-09-29 14:07:20 -07:00
|
|
|
struct brw_stage_prog_data *stage_prog_data);
|
|
|
|
|
2018-09-05 12:34:47 +02:00
|
|
|
void brw_nir_lower_gl_images(nir_shader *shader,
|
|
|
|
const struct gl_program *prog);
|
2018-08-16 16:23:10 -05:00
|
|
|
|
2016-01-02 03:21:28 -08:00
|
|
|
void brw_nir_analyze_ubo_ranges(const struct brw_compiler *compiler,
|
|
|
|
nir_shader *nir,
|
2018-07-23 09:41:26 -07:00
|
|
|
const struct brw_vs_prog_key *vs_key,
|
2016-01-02 03:21:28 -08:00
|
|
|
struct brw_ubo_range out_ranges[4]);
|
|
|
|
|
2015-10-22 15:25:23 +02:00
|
|
|
bool brw_nir_opt_peephole_ffma(nir_shader *shader);
|
|
|
|
|
2022-02-02 18:49:25 -08:00
|
|
|
bool brw_nir_opt_peephole_imul32x16(nir_shader *shader);
|
|
|
|
|
2019-06-04 18:19:06 -05:00
|
|
|
void brw_nir_optimize(nir_shader *nir,
|
|
|
|
const struct brw_compiler *compiler,
|
|
|
|
bool is_scalar,
|
|
|
|
bool allow_copies);
|
2017-09-07 13:42:17 +10:00
|
|
|
|
2018-09-21 13:26:03 -07:00
|
|
|
nir_shader *brw_nir_create_passthrough_tcs(void *mem_ctx,
|
|
|
|
const struct brw_compiler *compiler,
|
|
|
|
const struct brw_tcs_prog_key *key);
|
|
|
|
|
2016-07-21 21:26:20 -07:00
|
|
|
#define BRW_NIR_FRAG_OUTPUT_INDEX_SHIFT 0
|
|
|
|
#define BRW_NIR_FRAG_OUTPUT_INDEX_MASK INTEL_MASK(0, 0)
|
|
|
|
#define BRW_NIR_FRAG_OUTPUT_LOCATION_SHIFT 1
|
|
|
|
#define BRW_NIR_FRAG_OUTPUT_LOCATION_MASK INTEL_MASK(31, 1)
|
|
|
|
|
2019-07-18 09:23:23 -05:00
|
|
|
bool brw_nir_move_interpolation_to_top(nir_shader *nir);
|
|
|
|
bool brw_nir_demote_sample_qualifiers(nir_shader *nir);
|
2021-07-12 13:20:22 +02:00
|
|
|
nir_ssa_def *brw_nir_load_global_const(nir_builder *b,
|
|
|
|
nir_intrinsic_instr *load_uniform,
|
|
|
|
nir_ssa_def *base_addr,
|
|
|
|
unsigned off);
|
2019-07-18 09:23:23 -05:00
|
|
|
|
2015-03-17 11:29:01 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2017-03-20 16:04:38 +00:00
|
|
|
|
|
|
|
#endif /* BRW_NIR_H */
|