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.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-12-06 14:25:29 -08:00
|
|
|
#pragma once
|
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
|
|
|
|
|
|
2023-11-06 12:52:50 +02:00
|
|
|
extern const struct nir_shader_compiler_options brw_scalar_nir_options;
|
|
|
|
|
|
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
|
|
|
|
2025-03-24 18:17:47 -07:00
|
|
|
struct brw_mem_access_cb_data {
|
|
|
|
|
const struct intel_device_info *devinfo;
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2022-12-12 15:31:41 +02:00
|
|
|
struct brw_nir_compiler_opts {
|
|
|
|
|
/* Soft floating point implementation shader */
|
|
|
|
|
const nir_shader *softfp64;
|
|
|
|
|
|
|
|
|
|
/* Whether robust image access is enabled */
|
|
|
|
|
bool robust_image_access;
|
2023-04-08 21:34:35 +03:00
|
|
|
|
|
|
|
|
/* Input vertices for TCS stage (0 means dynamic) */
|
|
|
|
|
unsigned input_vertices;
|
2022-12-12 15:31:41 +02:00
|
|
|
};
|
|
|
|
|
|
2022-12-27 11:26:02 +02:00
|
|
|
/* UBO surface index can come in 2 flavors :
|
|
|
|
|
* - nir_intrinsic_resource_intel
|
|
|
|
|
* - anything else
|
|
|
|
|
*
|
|
|
|
|
* In the first case, checking that the surface index is const requires
|
|
|
|
|
* checking resource_intel::src[1]. In any other case it's a simple
|
|
|
|
|
* nir_src_is_const().
|
|
|
|
|
*
|
|
|
|
|
* This function should only be called on src[0] of load_ubo intrinsics.
|
|
|
|
|
*/
|
|
|
|
|
static inline bool
|
|
|
|
|
brw_nir_ubo_surface_index_is_pushable(nir_src src)
|
|
|
|
|
{
|
2023-08-01 12:24:31 -04:00
|
|
|
nir_intrinsic_instr *intrin =
|
2022-12-27 11:26:02 +02:00
|
|
|
src.ssa->parent_instr->type == nir_instr_type_intrinsic ?
|
|
|
|
|
nir_instr_as_intrinsic(src.ssa->parent_instr) : NULL;
|
|
|
|
|
|
|
|
|
|
if (intrin && intrin->intrinsic == nir_intrinsic_resource_intel) {
|
|
|
|
|
return (nir_intrinsic_resource_access_intel(intrin) &
|
2024-02-07 10:16:57 +02:00
|
|
|
nir_resource_intel_pushable);
|
2022-12-27 11:26:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nir_src_is_const(src);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline unsigned
|
|
|
|
|
brw_nir_ubo_surface_index_get_push_block(nir_src src)
|
|
|
|
|
{
|
|
|
|
|
if (nir_src_is_const(src))
|
|
|
|
|
return nir_src_as_uint(src);
|
|
|
|
|
|
|
|
|
|
if (!brw_nir_ubo_surface_index_is_pushable(src))
|
|
|
|
|
return UINT32_MAX;
|
|
|
|
|
|
|
|
|
|
assert(src.ssa->parent_instr->type == nir_instr_type_intrinsic);
|
|
|
|
|
|
|
|
|
|
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(src.ssa->parent_instr);
|
|
|
|
|
assert(intrin->intrinsic == nir_intrinsic_resource_intel);
|
|
|
|
|
|
|
|
|
|
return nir_intrinsic_resource_block_intel(intrin);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-07 10:16:57 +02:00
|
|
|
/* This helper return the binding table index of a surface access (any
|
|
|
|
|
* buffer/image/etc...). It works off the source of one of the intrinsics
|
|
|
|
|
* (load_ubo, load_ssbo, store_ssbo, load_image, store_image, etc...).
|
|
|
|
|
*
|
|
|
|
|
* If the source is constant, then this is the binding table index. If we're
|
|
|
|
|
* going through a resource_intel intel intrinsic, then we need to check
|
|
|
|
|
* src[1] of that intrinsic.
|
|
|
|
|
*/
|
2022-12-27 11:26:02 +02:00
|
|
|
static inline unsigned
|
|
|
|
|
brw_nir_ubo_surface_index_get_bti(nir_src src)
|
|
|
|
|
{
|
|
|
|
|
if (nir_src_is_const(src))
|
|
|
|
|
return nir_src_as_uint(src);
|
|
|
|
|
|
|
|
|
|
assert(src.ssa->parent_instr->type == nir_instr_type_intrinsic);
|
|
|
|
|
|
|
|
|
|
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(src.ssa->parent_instr);
|
2024-02-07 10:16:57 +02:00
|
|
|
if (!intrin || intrin->intrinsic != nir_intrinsic_resource_intel)
|
|
|
|
|
return UINT32_MAX;
|
|
|
|
|
|
|
|
|
|
/* In practice we could even drop this intrinsic because the bindless
|
|
|
|
|
* access always operate from a base offset coming from a push constant, so
|
|
|
|
|
* they can never be constant.
|
|
|
|
|
*/
|
|
|
|
|
if (nir_intrinsic_resource_access_intel(intrin) &
|
|
|
|
|
nir_resource_intel_bindless)
|
|
|
|
|
return UINT32_MAX;
|
|
|
|
|
|
|
|
|
|
if (!nir_src_is_const(intrin->src[1]))
|
|
|
|
|
return UINT32_MAX;
|
2022-12-27 11:26:02 +02:00
|
|
|
|
|
|
|
|
return nir_src_as_uint(intrin->src[1]);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-19 15:01:54 +03:00
|
|
|
/* Returns true if a fragment shader needs at least one render target */
|
|
|
|
|
static inline bool
|
|
|
|
|
brw_nir_fs_needs_null_rt(const struct intel_device_info *devinfo,
|
2025-06-03 15:41:50 +03:00
|
|
|
nir_shader *nir, bool alpha_to_coverage)
|
2024-09-19 15:01:54 +03:00
|
|
|
{
|
|
|
|
|
assert(nir->info.stage == MESA_SHADER_FRAGMENT);
|
|
|
|
|
|
|
|
|
|
/* Null-RT bit in the render target write extended descriptor is only
|
|
|
|
|
* available on Gfx11+.
|
|
|
|
|
*/
|
|
|
|
|
if (devinfo->ver < 11)
|
|
|
|
|
return true;
|
|
|
|
|
|
2025-04-18 12:06:25 +03:00
|
|
|
/* Depth/Stencil needs a valid render target even if there is no color
|
|
|
|
|
* output.
|
|
|
|
|
*/
|
|
|
|
|
if (nir->info.outputs_written & (BITFIELD_BIT(FRAG_RESULT_DEPTH) |
|
2025-06-03 15:41:50 +03:00
|
|
|
BITFIELD_BIT(FRAG_RESULT_STENCIL) |
|
|
|
|
|
BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)))
|
2025-04-18 12:06:25 +03:00
|
|
|
return true;
|
|
|
|
|
|
2025-06-03 15:41:50 +03:00
|
|
|
return alpha_to_coverage;
|
2024-09-19 15:01:54 +03:00
|
|
|
}
|
|
|
|
|
|
2019-06-04 18:19:06 -05:00
|
|
|
void brw_preprocess_nir(const struct brw_compiler *compiler,
|
|
|
|
|
nir_shader *nir,
|
2022-12-12 15:31:41 +02:00
|
|
|
const struct brw_nir_compiler_opts *opts);
|
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
|
|
|
|
2023-11-28 02:05:33 -08:00
|
|
|
bool brw_nir_lower_cs_intrinsics(nir_shader *nir,
|
|
|
|
|
const struct intel_device_info *devinfo,
|
|
|
|
|
struct brw_cs_prog_data *prog_data);
|
2024-05-12 14:39:14 +03:00
|
|
|
bool brw_nir_lower_alpha_to_coverage(nir_shader *shader);
|
2025-04-07 11:36:57 -07:00
|
|
|
bool brw_needs_vertex_attributes_bypass(const nir_shader *shader);
|
2025-03-11 15:47:40 -07:00
|
|
|
void brw_nir_lower_fs_barycentrics(nir_shader *shader);
|
2024-05-12 14:39:14 +03:00
|
|
|
bool brw_nir_lower_fs_msaa(nir_shader *shader,
|
|
|
|
|
const struct brw_wm_prog_key *key);
|
|
|
|
|
|
2024-02-26 21:33:05 -08:00
|
|
|
void brw_nir_lower_vs_inputs(nir_shader *nir);
|
2017-05-04 16:36:26 -07:00
|
|
|
void brw_nir_lower_vue_inputs(nir_shader *nir,
|
2024-02-01 15:39:52 -08:00
|
|
|
const struct intel_vue_map *vue_map);
|
|
|
|
|
void brw_nir_lower_tes_inputs(nir_shader *nir, const struct intel_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);
|
2024-02-01 15:39:52 -08:00
|
|
|
void brw_nir_lower_tcs_outputs(nir_shader *nir, const struct intel_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);
|
|
|
|
|
|
2023-06-13 19:45:49 -07:00
|
|
|
bool brw_nir_lower_cmat(nir_shader *nir, unsigned subgroup_size);
|
|
|
|
|
|
2023-04-04 20:42:39 +03:00
|
|
|
struct brw_nir_lower_storage_image_opts {
|
|
|
|
|
bool lower_loads;
|
|
|
|
|
bool lower_stores;
|
2024-12-14 02:11:37 +02:00
|
|
|
bool lower_stores_64bit;
|
2023-04-10 13:28:48 +03:00
|
|
|
bool lower_loads_without_formats;
|
2023-04-04 20:42:39 +03:00
|
|
|
};
|
|
|
|
|
|
2021-02-03 11:34:46 -08:00
|
|
|
bool brw_nir_lower_storage_image(nir_shader *nir,
|
2023-04-10 13:28:48 +03:00
|
|
|
const struct brw_compiler *compiler,
|
2023-04-04 20:42:39 +03:00
|
|
|
const struct brw_nir_lower_storage_image_opts *opts);
|
2018-01-27 13:19:57 -08:00
|
|
|
|
2024-12-07 03:56:38 +08:00
|
|
|
bool brw_nir_lower_texel_address(nir_shader *shader,
|
|
|
|
|
const struct intel_device_info *devinfo,
|
|
|
|
|
enum isl_tiling tiling);
|
|
|
|
|
|
2025-03-26 10:48:51 +02:00
|
|
|
bool brw_nir_lower_texture(nir_shader *nir,
|
2025-01-21 14:17:11 +02:00
|
|
|
const struct intel_device_info *devinfo);
|
2025-03-26 10:48:51 +02:00
|
|
|
|
2023-10-04 15:39:48 -07:00
|
|
|
bool brw_nir_lower_sample_index_in_coord(nir_shader *nir);
|
|
|
|
|
|
brw: run the nir_opt_offsets pass and set the maximum offset size
Perf A/B testing on DG2: no changes
Perf A/B testing on BMG: +2.1% Blackops3, +1.5% Cyberpunk
DG2 stats (mostly insignificant):
Assassins Creed Valhalla:
Totals from 1169 (55.67% of 2100) affected shaders:
Instrs: 509237 -> 509215 (-0.00%)
Cycle count: 30614325 -> 30607419 (-0.02%); split: -0.03%, +0.00%
Non SSA regs after NIR: 83434 -> 85909 (+2.97%)
Blackops 3:
Totals from 1045 (64.63% of 1617) affected shaders:
Instrs: 527312 -> 527310 (-0.00%)
Cycle count: 496912222 -> 496902846 (-0.00%); split: -0.00%, +0.00%
Non SSA regs after NIR: 106883 -> 109095 (+2.07%)
Cyberpunk:
Totals from 706 (56.03% of 1260) affected shaders:
Instrs: 345976 -> 345974 (-0.00%); split: -0.00%, +0.00%
Cycle count: 9775138 -> 9775472 (+0.00%); split: -0.00%, +0.00%
Max live registers: 40295 -> 40297 (+0.00%)
Non SSA regs after NIR: 93245 -> 94718 (+1.58%)
Fortnite:
Totals from 4210 (55.98% of 7521) affected shaders:
Instrs: 2205471 -> 2205469 (-0.00%)
Cycle count: 91451040 -> 91450956 (-0.00%); split: -0.00%, +0.00%
Non SSA regs after NIR: 952354 -> 961664 (+0.98%)
LNL stats (notable changes):
Assassins Creed Valhalla:
Totals from 1684 (83.57% of 2015) affected shaders:
Instrs: 774305 -> 764501 (-1.27%); split: -1.27%, +0.01%
Cycle count: 58845842 -> 58699250 (-0.25%); split: -0.98%, +0.73%
Spill count: 625 -> 638 (+2.08%)
Fill count: 1490 -> 1503 (+0.87%)
Scratch Memory Size: 41984 -> 44032 (+4.88%)
Max live registers: 196424 -> 197561 (+0.58%); split: -0.10%, +0.68%
Blackops 3:
Totals from 1125 (76.53% of 1470) affected shaders:
Instrs: 781749 -> 773275 (-1.08%); split: -1.08%, +0.00%
Subgroup size: 22896 -> 22912 (+0.07%)
Cycle count: 659864454 -> 654641032 (-0.79%); split: -1.10%, +0.31%
Max live registers: 116772 -> 116854 (+0.07%); split: -0.01%, +0.08%
Non SSA regs after NIR: 172648 -> 168260 (-2.54%); split: -2.55%, +0.01%
Control:
Totals from 378 (51.50% of 734) affected shaders:
Instrs: 148184 -> 147544 (-0.43%)
Cycle count: 6905200 -> 6913366 (+0.12%); split: -0.30%, +0.42%
Max live registers: 41271 -> 41281 (+0.02%)
Non SSA regs after NIR: 44964 -> 43868 (-2.44%); split: -2.45%, +0.01%
Cyberpunk:
Totals from 1141 (92.46% of 1234) affected shaders:
Instrs: 636744 -> 629333 (-1.16%)
Subgroup size: 24256 -> 24272 (+0.07%)
Cycle count: 24952258 -> 24801298 (-0.60%); split: -1.39%, +0.78%
Max live registers: 125848 -> 126855 (+0.80%); split: -0.00%, +0.80%
Non SSA regs after NIR: 127399 -> 119837 (-5.94%); split: -5.95%, +0.02%
Fortnite:
Totals from 5497 (83.52% of 6582) affected shaders:
Instrs: 4072831 -> 4041852 (-0.76%); split: -0.77%, +0.01%
Subgroup size: 103296 -> 103312 (+0.02%)
Cycle count: 133046874 -> 132789242 (-0.19%); split: -0.67%, +0.48%
Spill count: 7218 -> 7254 (+0.50%); split: -0.33%, +0.83%
Fill count: 11724 -> 11749 (+0.21%); split: -0.34%, +0.55%
Scratch Memory Size: 591872 -> 599040 (+1.21%)
Max live registers: 816530 -> 818522 (+0.24%); split: -0.01%, +0.26%
Non SSA regs after NIR: 1610296 -> 1560284 (-3.11%); split: -3.11%, +0.00%
Hitman3:
Totals from 4713 (92.39% of 5101) affected shaders:
Instrs: 2731598 -> 2698224 (-1.22%)
Cycle count: 186422098 -> 185472640 (-0.51%); split: -1.12%, +0.61%
Spill count: 3244 -> 3242 (-0.06%)
Fill count: 9937 -> 9933 (-0.04%)
Max live registers: 585035 -> 589801 (+0.81%); split: -0.00%, +0.82%
Non SSA regs after NIR: 347681 -> 324314 (-6.72%); split: -6.73%, +0.01%
Hogwarts Legacy:
Totals from 930 (59.81% of 1555) affected shaders:
Instrs: 464146 -> 459526 (-1.00%); split: -1.00%, +0.01%
Subgroup size: 19104 -> 19120 (+0.08%)
Cycle count: 24062460 -> 24078964 (+0.07%); split: -0.49%, +0.56%
Spill count: 2068 -> 1964 (-5.03%); split: -5.22%, +0.19%
Fill count: 2342 -> 2205 (-5.85%); split: -6.40%, +0.56%
Scratch Memory Size: 147456 -> 141312 (-4.17%)
Max live registers: 112384 -> 112787 (+0.36%); split: -0.08%, +0.44%
Non SSA regs after NIR: 80293 -> 79161 (-1.41%); split: -1.72%, +0.32%
Metro Exodus:
Totals from 29755 (78.62% of 37846) affected shaders:
Instrs: 11495578 -> 11492951 (-0.02%); split: -0.02%, +0.00%
Subgroup size: 644688 -> 644704 (+0.00%)
Cycle count: 301572068 -> 301548054 (-0.01%); split: -0.03%, +0.02%
Max live registers: 3369504 -> 3370454 (+0.03%); split: -0.00%, +0.03%
Non SSA regs after NIR: 2476561 -> 2396090 (-3.25%); split: -3.27%, +0.02%
Red Dead Redemption 2:
Totals from 4161 (78.61% of 5293) affected shaders:
Instrs: 2428782 -> 2409032 (-0.81%); split: -0.82%, +0.00%
Subgroup size: 85344 -> 85360 (+0.02%)
Cycle count: 8514984142 -> 8533415324 (+0.22%); split: -0.02%, +0.23%
Spill count: 4659 -> 4674 (+0.32%); split: -0.02%, +0.34%
Fill count: 11236 -> 11231 (-0.04%); split: -0.19%, +0.14%
Scratch Memory Size: 398336 -> 397312 (-0.26%)
Max live registers: 473946 -> 475798 (+0.39%); split: -0.08%, +0.47%
Non SSA regs after NIR: 616820 -> 567706 (-7.96%); split: -8.09%, +0.12%
Rise Of The Tomb Raider:
Totals from 68 (46.58% of 146) affected shaders:
Instrs: 28209 -> 27801 (-1.45%)
Subgroup size: 1584 -> 1600 (+1.01%)
Cycle count: 16182992 -> 16249364 (+0.41%); split: -0.97%, +1.38%
Max live registers: 7320 -> 7296 (-0.33%); split: -0.38%, +0.05%
Non SSA regs after NIR: 8438 -> 8207 (-2.74%); split: -2.82%, +0.08%
Spiderman Remastered:
Totals from 6403 (93.87% of 6821) affected shaders:
Instrs: 5662713 -> 5597949 (-1.14%); split: -1.28%, +0.14%
Cycle count: 282861519016 -> 279806958122 (-1.08%); split: -1.26%, +0.18%
Spill count: 61150 -> 60754 (-0.65%); split: -1.13%, +0.48%
Fill count: 162597 -> 163190 (+0.36%); split: -0.84%, +1.21%
Scratch Memory Size: 5834752 -> 5804032 (-0.53%); split: -0.70%, +0.18%
Max live registers: 901926 -> 903820 (+0.21%); split: -0.01%, +0.22%
Non SSA regs after NIR: 555053 -> 521016 (-6.13%); split: -6.14%, +0.01%
Signed-off-by: Rohan Garg <rohan.garg@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35252>
2024-05-22 12:22:47 +02:00
|
|
|
bool brw_nir_lower_immediate_offsets(nir_shader *shader);
|
|
|
|
|
|
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
|
|
|
|
2024-12-06 23:39:55 -08:00
|
|
|
bool brw_nir_lower_simd(nir_shader *nir, unsigned dispatch_width);
|
|
|
|
|
|
2019-06-04 18:19:06 -05:00
|
|
|
void brw_postprocess_nir(nir_shader *nir,
|
|
|
|
|
const struct brw_compiler *compiler,
|
2021-04-09 14:42:53 -07:00
|
|
|
bool debug_enabled,
|
2022-06-21 18:06:04 -07:00
|
|
|
enum brw_robustness_flags robust_flags);
|
2015-11-11 09:40:51 -08:00
|
|
|
|
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);
|
|
|
|
|
|
intel/brw: Handle fsign optimization in a NIR algebraic pass
This is a lot less code, and it makes it easier to experiment with other
pattern-based optimizations in the future.
The results here are nearly identical to the results I got from Ken's
"intel/brw: Make fsign (for 16/32-bit) in SSA form"... which are not
particularly good.
In this commit and in Ken's, all of the shader-db shaders hurt for
spills and fills are from Deus Ex Mankind Divided. Each shader has a
bunch of texture instructions with a single fsign between the
blocks. With the dependency on the flag removed, the scheduler puts all
of the texture instructions at the start... and there are a LOT of them.
shader-db:
All Intel platforms had similar results. (Meteor Lake shown)
total instructions in shared programs: 19647060 -> 19650207 (0.02%)
instructions in affected programs: 734718 -> 737865 (0.43%)
helped: 382 / HURT: 1984
total cycles in shared programs: 823238442 -> 822785913 (-0.05%)
cycles in affected programs: 426901157 -> 426448628 (-0.11%)
helped: 3408 / HURT: 3671
total spills in shared programs: 3887 -> 3891 (0.10%)
spills in affected programs: 256 -> 260 (1.56%)
helped: 0 / HURT: 4
total fills in shared programs: 3236 -> 3306 (2.16%)
fills in affected programs: 882 -> 952 (7.94%)
helped: 0 / HURT: 12
LOST: 37
GAINED: 34
fossil-db:
DG2 and Meteor Lake had similar results. (Meteor Lake shown)
Totals:
Instrs: 154005469 -> 154008294 (+0.00%); split: -0.00%, +0.00%
Cycle count: 17551859277 -> 17554293955 (+0.01%); split: -0.02%, +0.04%
Spill count: 142078 -> 142090 (+0.01%)
Fill count: 266761 -> 266729 (-0.01%); split: -0.02%, +0.01%
Max live registers: 32593578 -> 32593858 (+0.00%)
Max dispatch width: 5535944 -> 5536816 (+0.02%); split: +0.02%, -0.01%
Totals from 5867 (0.93% of 631350) affected shaders:
Instrs: 5475544 -> 5478369 (+0.05%); split: -0.04%, +0.09%
Cycle count: 1649032029 -> 1651466707 (+0.15%); split: -0.24%, +0.39%
Spill count: 26411 -> 26423 (+0.05%)
Fill count: 57364 -> 57332 (-0.06%); split: -0.10%, +0.04%
Max live registers: 431561 -> 431841 (+0.06%)
Max dispatch width: 49784 -> 50656 (+1.75%); split: +2.38%, -0.63%
Tiger Lake
Totals:
Instrs: 149530671 -> 149533588 (+0.00%); split: -0.00%, +0.00%
Cycle count: 15261418953 -> 15264764921 (+0.02%); split: -0.00%, +0.03%
Spill count: 60317 -> 60316 (-0.00%); split: -0.02%, +0.01%
Max live registers: 32249201 -> 32249464 (+0.00%)
Max dispatch width: 5540608 -> 5540584 (-0.00%)
Totals from 5862 (0.93% of 630309) affected shaders:
Instrs: 4740800 -> 4743717 (+0.06%); split: -0.04%, +0.10%
Cycle count: 566531248 -> 569877216 (+0.59%); split: -0.13%, +0.72%
Spill count: 11709 -> 11708 (-0.01%); split: -0.09%, +0.08%
Max live registers: 424560 -> 424823 (+0.06%)
Max dispatch width: 50304 -> 50280 (-0.05%)
Ice Lake
Totals:
Instrs: 150499705 -> 150502608 (+0.00%); split: -0.00%, +0.00%
Cycle count: 15105629116 -> 15105425880 (-0.00%); split: -0.00%, +0.00%
Spill count: 60087 -> 60090 (+0.00%)
Fill count: 100542 -> 100541 (-0.00%); split: -0.00%, +0.00%
Max live registers: 32605215 -> 32605495 (+0.00%)
Max dispatch width: 5617752 -> 5617792 (+0.00%); split: +0.00%, -0.00%
Totals from 5882 (0.93% of 634934) affected shaders:
Instrs: 4737206 -> 4740109 (+0.06%); split: -0.04%, +0.10%
Cycle count: 598882104 -> 598678868 (-0.03%); split: -0.08%, +0.05%
Spill count: 10278 -> 10281 (+0.03%)
Fill count: 22504 -> 22503 (-0.00%); split: -0.01%, +0.01%
Max live registers: 424184 -> 424464 (+0.07%)
Max dispatch width: 50216 -> 50256 (+0.08%); split: +0.25%, -0.18%
Skylake
Totals:
Instrs: 139092612 -> 139095257 (+0.00%); split: -0.00%, +0.00%
Cycle count: 14533550285 -> 14533544716 (-0.00%); split: -0.00%, +0.00%
Spill count: 58176 -> 58172 (-0.01%)
Fill count: 95877 -> 95796 (-0.08%)
Max live registers: 31924594 -> 31924874 (+0.00%)
Max dispatch width: 5484568 -> 5484552 (-0.00%); split: +0.00%, -0.00%
Totals from 5789 (0.93% of 625512) affected shaders:
Instrs: 4481987 -> 4484632 (+0.06%); split: -0.04%, +0.10%
Cycle count: 578310124 -> 578304555 (-0.00%); split: -0.05%, +0.05%
Spill count: 9248 -> 9244 (-0.04%)
Fill count: 19677 -> 19596 (-0.41%)
Max live registers: 415340 -> 415620 (+0.07%)
Max dispatch width: 49720 -> 49704 (-0.03%); split: +0.10%, -0.13%
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29095>
2024-05-01 21:02:13 -07:00
|
|
|
bool brw_nir_lower_fsign(nir_shader *nir);
|
|
|
|
|
|
intel/brw: Move fsat instructions closer to the source
Intel GPUs have a saturate destination modifier, and
brw_fs_opt_saturate_propagation tries to replace explicit saturate
operations with this destination modifier. That pass is limited in
several ways. If the source of the explicit saturate is in a different
block or if the source of the explicit saturate is live after the
explicit saturate, brw_fs_opt_saturate_propagation will be unable to
make progress.
This optimization exists to help brw_fs_opt_saturate_propagation make
more progress. It tries to move NIR fsat instructions to the same block
that contains the definition of its source. It does this only in cases
where it will not create additional live values. It also attempts to do
this only in cases where the explicit saturate will ultimiately be
converted to a destination modifier.
v2: Fix metadata_preserve when theres no progress and use
nir_metadata_control_flow when there is progress. All suggested by
Alyssa.
v3: Fix a typo in the file header comment. Noticed by Ken. Don't
require nir_metadata_instr_index. Use nir_def_rewrite_uses_after instead
of open-coding something slightly more specific. Both suggested by Ken.
shader-db:
All Intel platforms had similar results. (Meteor Lake shown)
total instructions in shared programs: 19733645 -> 19733028 (<.01%)
instructions in affected programs: 193300 -> 192683 (-0.32%)
helped: 246
HURT: 1
helped stats (abs) min: 2 max: 48 x̄: 2.51 x̃: 2
helped stats (rel) min: 0.18% max: 0.39% x̄: 0.33% x̃: 0.34%
HURT stats (abs) min: 1 max: 1 x̄: 1.00 x̃: 1
HURT stats (rel) min: 0.31% max: 0.31% x̄: 0.31% x̃: 0.31%
95% mean confidence interval for instructions value: -2.87 -2.13
95% mean confidence interval for instructions %-change: -0.34% -0.32%
Instructions are helped.
total cycles in shared programs: 916180971 -> 916264656 (<.01%)
cycles in affected programs: 30197180 -> 30280865 (0.28%)
helped: 194
HURT: 142
helped stats (abs) min: 1 max: 21251 x̄: 872.75 x̃: 19
helped stats (rel) min: <.01% max: 23.17% x̄: 2.59% x̃: 0.23%
HURT stats (abs) min: 1 max: 28058 x̄: 1781.68 x̃: 399
HURT stats (rel) min: <.01% max: 37.21% x̄: 4.85% x̃: 1.63%
95% mean confidence interval for cycles value: -196.84 694.97
95% mean confidence interval for cycles %-change: -0.17% 1.27%
Inconclusive result (value mean confidence interval includes 0).
fossil-db:
Meteor Lake, DG2, and Tiger Lake had similar results. (Meteor Lake shown)
Totals:
Instrs: 151512021 -> 151511351 (-0.00%); split: -0.00%, +0.00%
Cycle count: 17209013596 -> 17209840995 (+0.00%); split: -0.02%, +0.02%
Max live registers: 32013312 -> 32013549 (+0.00%)
Max dispatch width: 5512304 -> 5512136 (-0.00%)
Totals from 774 (0.12% of 630172) affected shaders:
Instrs: 1559285 -> 1558615 (-0.04%); split: -0.05%, +0.01%
Cycle count: 1312656268 -> 1313483667 (+0.06%); split: -0.24%, +0.30%
Max live registers: 82195 -> 82432 (+0.29%)
Max dispatch width: 6664 -> 6496 (-2.52%)
Ice Lake
Totals:
Instrs: 151416791 -> 151416137 (-0.00%); split: -0.00%, +0.00%
Cycle count: 15162468885 -> 15163298824 (+0.01%); split: -0.00%, +0.01%
Max live registers: 32471367 -> 32471603 (+0.00%)
Max dispatch width: 5623752 -> 5623712 (-0.00%)
Totals from 733 (0.12% of 635598) affected shaders:
Instrs: 877965 -> 877311 (-0.07%); split: -0.09%, +0.01%
Cycle count: 190763628 -> 191593567 (+0.44%); split: -0.21%, +0.64%
Max live registers: 72067 -> 72303 (+0.33%)
Max dispatch width: 6216 -> 6176 (-0.64%)
Skylake
Totals:
Instrs: 140794845 -> 140794075 (-0.00%); split: -0.00%, +0.00%
Cycle count: 14665159301 -> 14665320514 (+0.00%); split: -0.00%, +0.01%
Max live registers: 31783341 -> 31783662 (+0.00%); split: -0.00%, +0.00%
Totals from 659 (0.11% of 625670) affected shaders:
Instrs: 829061 -> 828291 (-0.09%); split: -0.09%, +0.00%
Cycle count: 185478478 -> 185639691 (+0.09%); split: -0.33%, +0.41%
Max live registers: 67491 -> 67812 (+0.48%); split: -0.01%, +0.48%
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29774>
2024-06-07 13:08:06 -07:00
|
|
|
bool brw_nir_opt_fsat(nir_shader *);
|
|
|
|
|
|
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,
|
2023-05-17 17:09:06 +02:00
|
|
|
unsigned max_subgroup_size);
|
2015-11-11 11:01:59 -08:00
|
|
|
|
2023-03-10 22:57:36 +02:00
|
|
|
unsigned brw_nir_api_subgroup_size(const nir_shader *nir,
|
|
|
|
|
unsigned hw_subgroup_size);
|
|
|
|
|
|
2019-08-02 15:19:16 -05:00
|
|
|
enum brw_conditional_mod brw_cmod_for_nir_comparison(nir_op op);
|
2024-08-05 19:36:02 -07:00
|
|
|
enum lsc_opcode lsc_op_for_nir_intrinsic(const nir_intrinsic_instr *intrin);
|
2025-03-14 13:29:59 -07:00
|
|
|
enum brw_reg_type brw_type_for_base_type(enum glsl_base_type base_type);
|
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
|
|
|
|
2022-11-29 13:42:12 +02:00
|
|
|
bool brw_nir_should_vectorize_mem(unsigned align_mul, unsigned align_offset,
|
|
|
|
|
unsigned bit_size,
|
|
|
|
|
unsigned num_components,
|
2024-12-18 05:11:33 -05:00
|
|
|
int64_t hole_size,
|
2022-11-29 13:42:12 +02:00
|
|
|
nir_intrinsic_instr *low,
|
|
|
|
|
nir_intrinsic_instr *high,
|
|
|
|
|
void *data);
|
|
|
|
|
|
2016-01-02 03:21:28 -08:00
|
|
|
void brw_nir_analyze_ubo_ranges(const struct brw_compiler *compiler,
|
|
|
|
|
nir_shader *nir,
|
|
|
|
|
struct brw_ubo_range out_ranges[4]);
|
|
|
|
|
|
2024-02-14 22:41:17 -08:00
|
|
|
void brw_nir_optimize(nir_shader *nir,
|
2023-10-31 23:37:20 -07:00
|
|
|
const struct intel_device_info *devinfo);
|
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);
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_def *brw_nir_load_global_const(nir_builder *b,
|
2021-07-12 13:20:22 +02:00
|
|
|
nir_intrinsic_instr *load_uniform,
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_def *base_addr,
|
2021-07-12 13:20:22 +02:00
|
|
|
unsigned off);
|
2019-07-18 09:23:23 -05:00
|
|
|
|
2022-12-21 15:40:07 +01:00
|
|
|
const struct glsl_type *brw_nir_get_var_type(const struct nir_shader *nir,
|
|
|
|
|
nir_variable *var);
|
|
|
|
|
|
2023-10-31 23:22:32 -07:00
|
|
|
void brw_nir_adjust_payload(nir_shader *shader);
|
2023-07-24 16:38:18 -07:00
|
|
|
|
2024-02-28 13:59:35 -08:00
|
|
|
static inline nir_variable_mode
|
|
|
|
|
brw_nir_no_indirect_mask(const struct brw_compiler *compiler,
|
|
|
|
|
gl_shader_stage stage)
|
|
|
|
|
{
|
|
|
|
|
nir_variable_mode indirect_mask = (nir_variable_mode) 0;
|
|
|
|
|
|
|
|
|
|
switch (stage) {
|
|
|
|
|
case MESA_SHADER_VERTEX:
|
|
|
|
|
case MESA_SHADER_FRAGMENT:
|
|
|
|
|
indirect_mask |= nir_var_shader_in;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
/* Everything else can handle indirect inputs */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (stage != MESA_SHADER_TESS_CTRL &&
|
|
|
|
|
stage != MESA_SHADER_TASK &&
|
|
|
|
|
stage != MESA_SHADER_MESH)
|
|
|
|
|
indirect_mask |= nir_var_shader_out;
|
|
|
|
|
|
|
|
|
|
return indirect_mask;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-30 08:45:21 +03:00
|
|
|
bool brw_nir_uses_inline_data(nir_shader *shader);
|
|
|
|
|
|
2025-01-14 15:23:18 +02:00
|
|
|
nir_shader *
|
2025-01-14 17:20:59 +02:00
|
|
|
brw_nir_from_spirv(void *mem_ctx, const uint32_t *spirv, size_t spirv_size);
|
2025-01-14 15:23:18 +02:00
|
|
|
|
2025-03-14 22:42:24 +02:00
|
|
|
nir_variable *
|
|
|
|
|
brw_nir_find_complete_variable_with_location(nir_shader *shader,
|
|
|
|
|
nir_variable_mode mode,
|
|
|
|
|
int location);
|
2025-05-16 11:46:33 +03:00
|
|
|
|
2025-05-21 14:56:35 +03:00
|
|
|
nir_def *
|
|
|
|
|
brw_nir_vertex_attribute_offset(nir_builder *b,
|
|
|
|
|
nir_def *attr_idx,
|
|
|
|
|
const struct intel_device_info *devinfo);
|
|
|
|
|
|
2025-05-16 11:46:33 +03:00
|
|
|
static inline bool
|
|
|
|
|
brw_nir_mesh_shader_needs_wa_18019110168(const struct intel_device_info *devinfo,
|
|
|
|
|
nir_shader *shader)
|
|
|
|
|
{
|
|
|
|
|
return intel_needs_workaround(devinfo, 18019110168) &&
|
|
|
|
|
(shader->info.outputs_written & (VARYING_BIT_CLIP_DIST0 |
|
|
|
|
|
VARYING_BIT_CLIP_DIST1)) &&
|
|
|
|
|
(shader->info.per_primitive_outputs & ~(VARYING_BIT_PRIMITIVE_INDICES |
|
|
|
|
|
VARYING_BIT_PRIMITIVE_COUNT));
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-19 17:05:15 +03:00
|
|
|
static inline bool
|
|
|
|
|
brw_nir_fragment_shader_needs_wa_18019110168(const struct intel_device_info *devinfo,
|
|
|
|
|
enum intel_sometimes mesh_input,
|
|
|
|
|
nir_shader *shader)
|
|
|
|
|
{
|
|
|
|
|
return intel_needs_workaround(devinfo, 18019110168) &&
|
|
|
|
|
mesh_input != INTEL_NEVER &&
|
|
|
|
|
(shader->info.per_primitive_inputs != 0 ||
|
|
|
|
|
(shader->info.inputs_read & VARYING_BIT_PRIMITIVE_ID));
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-16 11:46:33 +03:00
|
|
|
void
|
|
|
|
|
brw_nir_mesh_convert_attrs_prim_to_vert(struct nir_shader *nir,
|
|
|
|
|
struct brw_compile_mesh_params *params,
|
|
|
|
|
int *wa_mapping);
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
brw_nir_frag_convert_attrs_prim_to_vert(struct nir_shader *nir,
|
|
|
|
|
const int *wa_mapping);
|
|
|
|
|
|
2025-05-19 17:05:15 +03:00
|
|
|
bool
|
|
|
|
|
brw_nir_frag_convert_attrs_prim_to_vert_indirect(struct nir_shader *nir,
|
|
|
|
|
const struct intel_device_info *devinfo,
|
|
|
|
|
struct brw_compile_fs_params *params);
|
|
|
|
|
|
2015-03-17 11:29:01 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|