2016-01-21 09:19:53 -08:00
|
|
|
/*
|
|
|
|
* Copyright © 2015-2016 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "brw_compiler.h"
|
2017-02-28 16:12:22 -08:00
|
|
|
#include "brw_shader.h"
|
2017-03-09 16:01:30 -08:00
|
|
|
#include "brw_eu.h"
|
2021-04-05 10:44:41 -07:00
|
|
|
#include "dev/intel_debug.h"
|
2016-01-21 09:19:53 -08:00
|
|
|
#include "compiler/nir/nir.h"
|
|
|
|
#include "main/errors.h"
|
2022-09-13 12:49:56 +03:00
|
|
|
#include "util/u_debug.h"
|
2016-01-21 09:19:53 -08:00
|
|
|
|
2016-01-21 09:30:05 -08:00
|
|
|
#define COMMON_OPTIONS \
|
|
|
|
.lower_fdiv = true, \
|
|
|
|
.lower_scmp = true, \
|
2018-04-18 11:02:51 +02:00
|
|
|
.lower_flrp16 = true, \
|
2019-06-03 13:18:55 -07:00
|
|
|
.lower_fmod = true, \
|
2022-10-10 13:21:52 -07:00
|
|
|
.lower_ufind_msb_to_uclz = true, \
|
2016-01-21 09:30:05 -08:00
|
|
|
.lower_uadd_carry = true, \
|
|
|
|
.lower_usub_borrow = true, \
|
2016-01-19 08:19:20 +01:00
|
|
|
.lower_flrp64 = true, \
|
2022-04-15 15:24:11 -05:00
|
|
|
.lower_fisnormal = true, \
|
2019-02-06 13:26:17 -08:00
|
|
|
.lower_isign = true, \
|
2018-02-27 19:19:21 +11:00
|
|
|
.lower_ldexp = true, \
|
2017-09-21 13:54:55 -07:00
|
|
|
.lower_device_index_to_zero = true, \
|
2019-05-21 15:18:25 -07:00
|
|
|
.vectorize_io = true, \
|
intel/compiler: Vectorize gl_TessLevelInner/Outer[] writes [v2]
Setting the NIR options takes care of iris thanks to the common st/mesa
linking code, and updating brw_nir_link_shaders should handle anv.
The main effort here is updating remap_tess_levels, which needs to
handle vector stores, writemasking, and swizzling. Unfortunately,
we also need to continue handling the existing single-component
access because it's used for TES inputs, which we don't vectorize.
We could try to vectorize TES inputs too, but they're all pushed
anyway, so it wouldn't buy us much other than deleting this code.
Also, we do have opt_combine_stores, but not one for loads.
One limitation of using nir_vectorize_tess_levels is that it works
on variables, and so isn't able to combine outer/inner writes that
happen to live in the same vec4 slot (for triangle domains). That
said, it's still better than before.
For writes, we allow the intrinsics to supply up to the full size
of the variable (vec4 for outer, vec2 for inner) even if the domain
only requires a subset of those components (i.e. triangles needs 3).
shader-db results on Icelake:
total instructions in shared programs: 19600314 -> 19597528 (-0.01%)
instructions in affected programs: 65338 -> 62552 (-4.26%)
helped: 271 / HURT: 0
helped stats (abs) min: 6 max: 24 x̄: 10.28 x̃: 12
helped stats (rel) min: 1.30% max: 18.18% x̄: 5.80% x̃: 7.59%
95% mean confidence interval for instructions value: -10.71 -9.85
95% mean confidence interval for instructions %-change: -6.17% -5.43%
Instructions are helped.
total cycles in shared programs: 851842332 -> 851808165 (<.01%)
cycles in affected programs: 618577 -> 584410 (-5.52%)
helped: 271 / HURT: 0
helped stats (abs) min: 64 max: 540 x̄: 126.08 x̃: 111
helped stats (rel) min: 2.57% max: 37.97% x̄: 6.12% x̃: 5.06%
95% mean confidence interval for cycles value: -135.35 -116.80
95% mean confidence interval for cycles %-change: -6.67% -5.57%
Cycles are helped.
total sends in shared programs: 1025238 -> 1024308 (-0.09%)
sends in affected programs: 6454 -> 5524 (-14.41%)
helped: 271 / HURT: 0
helped stats (abs) min: 2 max: 8 x̄: 3.43 x̃: 4
helped stats (rel) min: 5.71% max: 25.00% x̄: 14.98% x̃: 17.39%
95% mean confidence interval for sends value: -3.57 -3.29
95% mean confidence interval for sends %-change: -15.42% -14.54%
Sends are helped.
According to Felix DeGrood, this results in a 10% improvement in
the draw call time for certain draw calls from Strange Brigade.
v2: Fix assertions about number of components and add more of them.
Combine the quads and triangles handling as it's nearly identical.
Reviewed-by: Caio Oliveira <caio.oliveira@intel.com> [v1]
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19061>
2022-08-04 02:06:52 -07:00
|
|
|
.vectorize_tess_levels = true, \
|
2016-07-12 03:57:25 -07:00
|
|
|
.use_interpolated_input_intrinsics = true, \
|
2020-03-25 15:38:06 +00:00
|
|
|
.lower_insert_byte = true, \
|
|
|
|
.lower_insert_word = true, \
|
2018-04-28 14:09:22 +02:00
|
|
|
.vertex_id_zero_based = true, \
|
2020-01-10 16:25:02 -08:00
|
|
|
.lower_base_vertex = true, \
|
2020-05-05 09:13:20 +02:00
|
|
|
.use_scoped_barrier = true, \
|
2020-09-13 21:28:02 +02:00
|
|
|
.support_16bit_alu = true, \
|
2021-02-01 11:05:48 +01:00
|
|
|
.lower_uniforms_to_ubo = true, \
|
|
|
|
.has_txs = true
|
2016-01-21 09:30:05 -08:00
|
|
|
|
2017-06-14 16:20:41 -07:00
|
|
|
#define COMMON_SCALAR_OPTIONS \
|
2019-10-07 22:46:00 -04:00
|
|
|
.lower_to_scalar = true, \
|
2017-06-14 16:20:41 -07:00
|
|
|
.lower_pack_half_2x16 = true, \
|
|
|
|
.lower_pack_snorm_2x16 = true, \
|
|
|
|
.lower_pack_snorm_4x8 = true, \
|
|
|
|
.lower_pack_unorm_2x16 = true, \
|
|
|
|
.lower_pack_unorm_4x8 = true, \
|
|
|
|
.lower_unpack_half_2x16 = true, \
|
|
|
|
.lower_unpack_snorm_2x16 = true, \
|
|
|
|
.lower_unpack_snorm_4x8 = true, \
|
|
|
|
.lower_unpack_unorm_2x16 = true, \
|
|
|
|
.lower_unpack_unorm_4x8 = true, \
|
2018-09-11 16:50:06 -07:00
|
|
|
.lower_hadd64 = true, \
|
2021-06-02 15:14:41 +01:00
|
|
|
.avoid_ternary_with_two_constants = true, \
|
2021-01-25 16:31:17 -08:00
|
|
|
.has_pack_32_4x8 = true, \
|
2021-07-29 19:34:26 +10:00
|
|
|
.max_unroll_iterations = 32, \
|
2020-10-16 16:05:52 -07:00
|
|
|
.force_indirect_unrolling = nir_var_function_temp, \
|
|
|
|
.divergence_analysis_options = \
|
|
|
|
(nir_divergence_single_prim_per_subgroup | \
|
|
|
|
nir_divergence_single_patch_per_tcs_subgroup | \
|
2022-12-22 09:35:19 +02:00
|
|
|
nir_divergence_single_patch_per_tes_subgroup | \
|
|
|
|
nir_divergence_shader_record_ptr_uniform)
|
2017-06-14 16:20:41 -07:00
|
|
|
|
2016-01-21 09:30:05 -08:00
|
|
|
static const struct nir_shader_compiler_options scalar_nir_options = {
|
|
|
|
COMMON_OPTIONS,
|
2017-06-14 16:20:41 -07:00
|
|
|
COMMON_SCALAR_OPTIONS,
|
|
|
|
};
|
|
|
|
|
2016-01-21 09:30:05 -08:00
|
|
|
static const struct nir_shader_compiler_options vector_nir_options = {
|
|
|
|
COMMON_OPTIONS,
|
|
|
|
|
|
|
|
/* In the vec4 backend, our dpN instruction replicates its result to all the
|
|
|
|
* components of a vec4. We would like NIR to give us replicated fdot
|
|
|
|
* instructions because it can optimize better for us.
|
|
|
|
*/
|
|
|
|
.fdot_replicates = true,
|
2016-01-25 11:07:28 -08:00
|
|
|
|
2022-07-20 13:01:44 -07:00
|
|
|
.lower_usub_sat = true,
|
2016-01-25 11:07:28 -08:00
|
|
|
.lower_pack_snorm_2x16 = true,
|
|
|
|
.lower_pack_unorm_2x16 = true,
|
|
|
|
.lower_unpack_snorm_2x16 = true,
|
|
|
|
.lower_unpack_unorm_2x16 = true,
|
|
|
|
.lower_extract_byte = true,
|
|
|
|
.lower_extract_word = true,
|
2019-06-03 15:22:15 -07:00
|
|
|
.intel_vec4 = true,
|
2016-12-13 11:36:51 +11:00
|
|
|
.max_unroll_iterations = 32,
|
2016-01-21 09:30:05 -08:00
|
|
|
};
|
|
|
|
|
2016-01-21 09:19:53 -08:00
|
|
|
struct brw_compiler *
|
2021-04-05 13:19:39 -07:00
|
|
|
brw_compiler_create(void *mem_ctx, const struct intel_device_info *devinfo)
|
2016-01-21 09:19:53 -08:00
|
|
|
{
|
|
|
|
struct brw_compiler *compiler = rzalloc(mem_ctx, struct brw_compiler);
|
|
|
|
|
|
|
|
compiler->devinfo = devinfo;
|
|
|
|
|
2022-06-29 14:13:31 -07:00
|
|
|
brw_init_isa_info(&compiler->isa, devinfo);
|
|
|
|
|
2016-01-21 09:19:53 -08:00
|
|
|
brw_fs_alloc_reg_sets(compiler);
|
2022-07-08 11:27:13 -07:00
|
|
|
if (devinfo->ver < 8)
|
|
|
|
brw_vec4_alloc_reg_set(compiler);
|
2016-01-21 09:19:53 -08:00
|
|
|
|
2022-09-13 12:49:56 +03:00
|
|
|
compiler->precise_trig = debug_get_bool_option("INTEL_PRECISE_TRIG", false);
|
2016-06-11 13:17:27 -07:00
|
|
|
|
2022-08-16 11:02:20 -07:00
|
|
|
compiler->use_tcs_multi_patch = devinfo->ver >= 12;
|
intel/compiler: Implement TCS 8_PATCH mode and INTEL_DEBUG=tcs8
Our tessellation control shaders can be dispatched in several modes.
- SINGLE_PATCH (Gen7+) processes a single patch per thread, with each
channel corresponding to a different patch vertex. PATCHLIST_N will
launch (N / 8) threads. If N is less than 8, some channels will be
disabled, leaving some untapped hardware capabilities. Conditionals
based on gl_InvocationID are non-uniform, which means that they'll
often have to execute both paths. However, if there are fewer than
8 vertices, all invocations will happen within a single thread, so
barriers can become no-ops, which is nice. We also burn a maximum
of 4 registers for ICP handles, so we can compile without regard for
the value of N. It also works in all cases.
- DUAL_PATCH mode processes up to two patches at a time, where the first
four channels come from patch 1, and the second group of four come
from patch 2. This tries to provide better EU utilization for small
patches (N <= 4). It cannot be used in all cases.
- 8_PATCH mode processes 8 patches at a time, with a thread launched per
vertex in the patch. Each channel corresponds to the same vertex, but
in each of the 8 patches. This utilizes all channels even for small
patches. It also makes conditions on gl_InvocationID uniform, leading
to proper jumps. Barriers, unfortunately, become real. Worse, for
PATCHLIST_N, the thread payload burns N registers for ICP handles.
This can burn up to 32 registers, or 1/4 of our register file, for
URB handles. For Vulkan (and DX), we know the number of vertices at
compile time, so we can limit the amount of waste. In GL, the patch
dimension is dynamic state, so we either would have to waste all 32
(not reasonable) or guess (badly) and recompile. This is unfortunate.
Because we can only spawn 16 thread instances, we can only use this
mode for PATCHLIST_16 and smaller. The rest must use SINGLE_PATCH.
This patch implements the new 8_PATCH TCS mode, but leaves us using
SINGLE_PATCH by default. A new INTEL_DEBUG=tcs8 flag will switch to
using 8_PATCH mode for testing and benchmarking purposes. We may
want to consider using 8_PATCH mode in Vulkan in some cases.
The data I've seen shows that 8_PATCH mode can be more efficient in
some cases, but SINGLE_PATCH mode (the one we use today) is faster
in other cases. Ultimately, the TES matters much more than the TCS
for performance, so the decision may not matter much.
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2019-05-03 14:57:54 -07:00
|
|
|
|
2020-02-21 11:29:06 -06:00
|
|
|
/* Default to the sampler since that's what we've done since forever */
|
|
|
|
compiler->indirect_ubos_use_sampler = true;
|
|
|
|
|
2021-03-29 15:46:12 -07:00
|
|
|
/* There is no vec4 mode on Gfx10+, and we don't use it at all on Gfx8+. */
|
2020-09-22 11:47:38 -07:00
|
|
|
for (int i = MESA_SHADER_VERTEX; i < MESA_ALL_SHADER_STAGES; i++) {
|
2021-03-29 14:41:58 -07:00
|
|
|
compiler->scalar_stage[i] = devinfo->ver >= 8 ||
|
2020-09-22 11:47:38 -07:00
|
|
|
i == MESA_SHADER_FRAGMENT || i == MESA_SHADER_COMPUTE;
|
2017-05-13 12:11:40 -07:00
|
|
|
}
|
2016-01-21 09:19:53 -08:00
|
|
|
|
2020-10-21 14:46:50 -05:00
|
|
|
for (int i = MESA_SHADER_TASK; i < MESA_VULKAN_SHADER_STAGES; i++)
|
|
|
|
compiler->scalar_stage[i] = true;
|
|
|
|
|
2019-02-25 17:17:29 -08:00
|
|
|
nir_lower_int64_options int64_options =
|
|
|
|
nir_lower_imul64 |
|
|
|
|
nir_lower_isign64 |
|
|
|
|
nir_lower_divmod64 |
|
intel/compiler: Fix 64-bit ufind_msb, find_lsb, and bit_count
We only support 32-bit versions of ufind_msb, find_lsb, and bit_count,
so we need to lower them via nir_lower_int64.
Previously, we were failing to do so on platforms older than Icelake
and let those operations fall through to nir_lower_bit_size, which
used a callback to determine it should lower them for bit_size != 32.
However, that pass only emulates small bit-size operations by promoting
them to supported, larger bit-sizes (i.e. 16-bit using 32-bit). It
doesn't support emulating larger operations (i.e. 64-bit using 32-bit).
So nir_lower_bit_size would just u2u32 the 64-bit source, causing us to
flat ignore half of the bits.
Commit 78a195f252d (intel/compiler: Postpone most int64 lowering to
brw_postprocess_nir) provoked this bug on Icelake and later as well,
by moving the nir_lower_int64 handling for ufind_msb until late in
compilation, allowing it to reach nir_lower_bit_size which broke it.
To fix this, we always set int64 lowering for these opcodes, and also
correct the nir_lower_bit_size callback to ignore 64-bit operations.
Cc: mesa-stable
Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23123>
2023-05-18 17:19:42 -07:00
|
|
|
nir_lower_imul_high64 |
|
|
|
|
nir_lower_find_lsb64 |
|
|
|
|
nir_lower_ufind_msb64 |
|
|
|
|
nir_lower_bit_count64;
|
2019-02-25 17:17:29 -08:00
|
|
|
nir_lower_doubles_options fp64_options =
|
|
|
|
nir_lower_drcp |
|
|
|
|
nir_lower_dsqrt |
|
|
|
|
nir_lower_drsq |
|
|
|
|
nir_lower_dtrunc |
|
|
|
|
nir_lower_dfloor |
|
|
|
|
nir_lower_dceil |
|
|
|
|
nir_lower_dfract |
|
|
|
|
nir_lower_dround_even |
|
2019-07-11 16:59:31 -05:00
|
|
|
nir_lower_dmod |
|
|
|
|
nir_lower_dsub |
|
|
|
|
nir_lower_ddiv;
|
2019-02-25 17:17:29 -08:00
|
|
|
|
2022-03-09 16:56:08 -08:00
|
|
|
if (!devinfo->has_64bit_float || INTEL_DEBUG(DEBUG_SOFT64))
|
2019-02-25 17:17:29 -08:00
|
|
|
fp64_options |= nir_lower_fp64_full_software;
|
2022-03-09 16:56:08 -08:00
|
|
|
if (!devinfo->has_64bit_int)
|
|
|
|
int64_options |= (nir_lower_int64_options)~0;
|
2019-02-25 17:17:29 -08:00
|
|
|
|
2022-06-22 18:31:08 +02:00
|
|
|
/* The Bspec's section titled "Instruction_multiply[DevBDW+]" claims that
|
2021-03-29 15:46:12 -07:00
|
|
|
* destination type can be Quadword and source type Doubleword for Gfx8 and
|
|
|
|
* Gfx9. So, lower 64 bit multiply instruction on rest of the platforms.
|
2019-02-14 23:08:39 -08:00
|
|
|
*/
|
2021-03-29 14:41:58 -07:00
|
|
|
if (devinfo->ver < 8 || devinfo->ver > 9)
|
2019-02-14 23:08:39 -08:00
|
|
|
int64_options |= nir_lower_imul_2x32_64;
|
|
|
|
|
2016-01-21 09:19:53 -08:00
|
|
|
/* We want the GLSL compiler to emit code that uses condition codes */
|
2019-02-03 19:46:16 -06:00
|
|
|
for (int i = 0; i < MESA_ALL_SHADER_STAGES; i++) {
|
2019-02-25 17:17:29 -08:00
|
|
|
struct nir_shader_compiler_options *nir_options =
|
|
|
|
rzalloc(compiler, struct nir_shader_compiler_options);
|
2021-12-07 15:53:49 +10:00
|
|
|
bool is_scalar = compiler->scalar_stage[i];
|
2016-03-07 10:55:21 -08:00
|
|
|
if (is_scalar) {
|
2019-04-19 13:11:34 -07:00
|
|
|
*nir_options = scalar_nir_options;
|
2022-01-17 18:11:27 +01:00
|
|
|
int64_options |= nir_lower_usub_sat64;
|
2016-03-07 10:55:21 -08:00
|
|
|
} else {
|
2019-04-19 13:11:34 -07:00
|
|
|
*nir_options = vector_nir_options;
|
2016-03-07 10:55:21 -08:00
|
|
|
}
|
2019-04-18 17:48:15 -07:00
|
|
|
|
2021-03-29 15:46:12 -07:00
|
|
|
/* Prior to Gfx6, there are no three source operations, and Gfx11 loses
|
2018-08-18 16:42:04 -07:00
|
|
|
* LRP.
|
|
|
|
*/
|
2021-03-29 14:41:58 -07:00
|
|
|
nir_options->lower_ffma16 = devinfo->ver < 6;
|
|
|
|
nir_options->lower_ffma32 = devinfo->ver < 6;
|
|
|
|
nir_options->lower_ffma64 = devinfo->ver < 6;
|
|
|
|
nir_options->lower_flrp32 = devinfo->ver < 6 || devinfo->ver >= 11;
|
|
|
|
nir_options->lower_fpow = devinfo->ver >= 12;
|
2019-04-18 17:48:15 -07:00
|
|
|
|
2022-12-13 09:43:39 -08:00
|
|
|
nir_options->lower_bitfield_extract = devinfo->ver >= 7;
|
|
|
|
nir_options->lower_bitfield_extract_to_shifts = devinfo->ver < 7;
|
|
|
|
nir_options->lower_bitfield_insert = devinfo->ver >= 7;
|
|
|
|
nir_options->lower_bitfield_insert_to_shifts = devinfo->ver < 7;
|
|
|
|
|
2021-03-29 14:41:58 -07:00
|
|
|
nir_options->lower_rotate = devinfo->ver < 11;
|
|
|
|
nir_options->lower_bitfield_reverse = devinfo->ver < 7;
|
2022-10-10 13:41:59 -07:00
|
|
|
nir_options->lower_find_lsb = devinfo->ver < 7;
|
2022-10-10 13:35:01 -07:00
|
|
|
nir_options->lower_ifind_msb_to_uclz = devinfo->ver < 7;
|
2021-06-28 17:49:01 -07:00
|
|
|
nir_options->has_iadd3 = devinfo->verx10 >= 125;
|
2019-05-30 14:14:52 -07:00
|
|
|
|
2021-11-26 19:27:03 +02:00
|
|
|
nir_options->has_sdot_4x8 = devinfo->ver >= 12;
|
|
|
|
nir_options->has_udot_4x8 = devinfo->ver >= 12;
|
2021-02-23 18:46:53 -08:00
|
|
|
nir_options->has_sudot_4x8 = devinfo->ver >= 12;
|
|
|
|
|
2019-02-25 17:17:29 -08:00
|
|
|
nir_options->lower_int64_options = int64_options;
|
|
|
|
nir_options->lower_doubles_options = fp64_options;
|
2019-06-17 17:12:25 -05:00
|
|
|
|
|
|
|
nir_options->unify_interfaces = i < MESA_SHADER_FRAGMENT;
|
|
|
|
|
2021-07-29 19:34:26 +10:00
|
|
|
nir_options->force_indirect_unrolling |=
|
|
|
|
brw_nir_no_indirect_mask(compiler, i);
|
2022-05-11 22:44:44 +10:00
|
|
|
nir_options->force_indirect_unrolling_sampler = devinfo->ver < 7;
|
2021-07-29 19:34:26 +10:00
|
|
|
|
2022-08-16 11:02:20 -07:00
|
|
|
if (compiler->use_tcs_multi_patch) {
|
|
|
|
/* TCS MULTI_PATCH mode has multiple patches per subgroup */
|
2020-10-16 16:05:52 -07:00
|
|
|
nir_options->divergence_analysis_options &=
|
|
|
|
~nir_divergence_single_patch_per_tcs_subgroup;
|
|
|
|
}
|
|
|
|
|
2021-12-07 15:53:49 +10:00
|
|
|
compiler->nir_options[i] = nir_options;
|
2016-01-21 09:19:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return compiler;
|
|
|
|
}
|
2017-10-21 01:30:13 -07:00
|
|
|
|
2018-07-25 14:31:05 -07:00
|
|
|
static void
|
|
|
|
insert_u64_bit(uint64_t *val, bool add)
|
|
|
|
{
|
|
|
|
*val = (*val << 1) | !!add;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
brw_get_compiler_config_value(const struct brw_compiler *compiler)
|
|
|
|
{
|
|
|
|
uint64_t config = 0;
|
2023-01-21 12:49:44 +01:00
|
|
|
unsigned bits = 0;
|
|
|
|
|
2018-07-25 14:31:05 -07:00
|
|
|
insert_u64_bit(&config, compiler->precise_trig);
|
2023-01-21 12:49:44 +01:00
|
|
|
bits++;
|
2021-10-08 12:09:04 -07:00
|
|
|
|
2018-07-25 14:31:05 -07:00
|
|
|
uint64_t mask = DEBUG_DISK_CACHE_MASK;
|
2023-01-21 12:49:44 +01:00
|
|
|
bits += util_bitcount64(mask);
|
2018-07-25 14:31:05 -07:00
|
|
|
while (mask != 0) {
|
|
|
|
const uint64_t bit = 1ULL << (ffsll(mask) - 1);
|
2021-10-13 11:21:41 +02:00
|
|
|
insert_u64_bit(&config, INTEL_DEBUG(bit));
|
2018-07-25 14:31:05 -07:00
|
|
|
mask &= ~bit;
|
|
|
|
}
|
2023-01-21 12:49:44 +01:00
|
|
|
|
|
|
|
mask = SIMD_DISK_CACHE_MASK;
|
|
|
|
bits += util_bitcount64(mask);
|
|
|
|
while (mask != 0) {
|
|
|
|
const uint64_t bit = 1ULL << (ffsll(mask) - 1);
|
|
|
|
insert_u64_bit(&config, (intel_simd & bit) != 0);
|
|
|
|
mask &= ~bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(bits <= util_bitcount64(UINT64_MAX));
|
|
|
|
|
2018-07-25 14:31:05 -07:00
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
2017-10-21 01:30:13 -07:00
|
|
|
unsigned
|
|
|
|
brw_prog_data_size(gl_shader_stage stage)
|
|
|
|
{
|
|
|
|
static const size_t stage_sizes[] = {
|
2020-10-21 14:46:50 -05:00
|
|
|
[MESA_SHADER_VERTEX] = sizeof(struct brw_vs_prog_data),
|
|
|
|
[MESA_SHADER_TESS_CTRL] = sizeof(struct brw_tcs_prog_data),
|
|
|
|
[MESA_SHADER_TESS_EVAL] = sizeof(struct brw_tes_prog_data),
|
|
|
|
[MESA_SHADER_GEOMETRY] = sizeof(struct brw_gs_prog_data),
|
|
|
|
[MESA_SHADER_FRAGMENT] = sizeof(struct brw_wm_prog_data),
|
|
|
|
[MESA_SHADER_COMPUTE] = sizeof(struct brw_cs_prog_data),
|
2021-10-29 12:27:45 -07:00
|
|
|
[MESA_SHADER_TASK] = sizeof(struct brw_task_prog_data),
|
|
|
|
[MESA_SHADER_MESH] = sizeof(struct brw_mesh_prog_data),
|
2020-10-21 14:46:50 -05:00
|
|
|
[MESA_SHADER_RAYGEN] = sizeof(struct brw_bs_prog_data),
|
|
|
|
[MESA_SHADER_ANY_HIT] = sizeof(struct brw_bs_prog_data),
|
|
|
|
[MESA_SHADER_CLOSEST_HIT] = sizeof(struct brw_bs_prog_data),
|
|
|
|
[MESA_SHADER_MISS] = sizeof(struct brw_bs_prog_data),
|
|
|
|
[MESA_SHADER_INTERSECTION] = sizeof(struct brw_bs_prog_data),
|
|
|
|
[MESA_SHADER_CALLABLE] = sizeof(struct brw_bs_prog_data),
|
|
|
|
[MESA_SHADER_KERNEL] = sizeof(struct brw_cs_prog_data),
|
2017-10-21 01:30:13 -07:00
|
|
|
};
|
|
|
|
assert((int)stage >= 0 && stage < ARRAY_SIZE(stage_sizes));
|
|
|
|
return stage_sizes[stage];
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned
|
|
|
|
brw_prog_key_size(gl_shader_stage stage)
|
|
|
|
{
|
|
|
|
static const size_t stage_sizes[] = {
|
2020-10-21 14:46:50 -05:00
|
|
|
[MESA_SHADER_VERTEX] = sizeof(struct brw_vs_prog_key),
|
|
|
|
[MESA_SHADER_TESS_CTRL] = sizeof(struct brw_tcs_prog_key),
|
|
|
|
[MESA_SHADER_TESS_EVAL] = sizeof(struct brw_tes_prog_key),
|
|
|
|
[MESA_SHADER_GEOMETRY] = sizeof(struct brw_gs_prog_key),
|
|
|
|
[MESA_SHADER_FRAGMENT] = sizeof(struct brw_wm_prog_key),
|
|
|
|
[MESA_SHADER_COMPUTE] = sizeof(struct brw_cs_prog_key),
|
2021-10-29 12:27:45 -07:00
|
|
|
[MESA_SHADER_TASK] = sizeof(struct brw_task_prog_key),
|
|
|
|
[MESA_SHADER_MESH] = sizeof(struct brw_mesh_prog_key),
|
2020-10-21 14:46:50 -05:00
|
|
|
[MESA_SHADER_RAYGEN] = sizeof(struct brw_bs_prog_key),
|
|
|
|
[MESA_SHADER_ANY_HIT] = sizeof(struct brw_bs_prog_key),
|
|
|
|
[MESA_SHADER_CLOSEST_HIT] = sizeof(struct brw_bs_prog_key),
|
|
|
|
[MESA_SHADER_MISS] = sizeof(struct brw_bs_prog_key),
|
|
|
|
[MESA_SHADER_INTERSECTION] = sizeof(struct brw_bs_prog_key),
|
|
|
|
[MESA_SHADER_CALLABLE] = sizeof(struct brw_bs_prog_key),
|
|
|
|
[MESA_SHADER_KERNEL] = sizeof(struct brw_cs_prog_key),
|
2017-10-21 01:30:13 -07:00
|
|
|
};
|
|
|
|
assert((int)stage >= 0 && stage < ARRAY_SIZE(stage_sizes));
|
|
|
|
return stage_sizes[stage];
|
|
|
|
}
|
2020-08-08 12:55:29 -05:00
|
|
|
|
|
|
|
void
|
2022-06-29 14:13:31 -07:00
|
|
|
brw_write_shader_relocs(const struct brw_isa_info *isa,
|
2020-08-08 12:55:29 -05:00
|
|
|
void *program,
|
|
|
|
const struct brw_stage_prog_data *prog_data,
|
|
|
|
struct brw_shader_reloc_value *values,
|
|
|
|
unsigned num_values)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < prog_data->num_relocs; i++) {
|
|
|
|
assert(prog_data->relocs[i].offset % 8 == 0);
|
2020-09-04 12:09:11 -05:00
|
|
|
void *dst = program + prog_data->relocs[i].offset;
|
2020-08-08 12:55:29 -05:00
|
|
|
for (unsigned j = 0; j < num_values; j++) {
|
|
|
|
if (prog_data->relocs[i].id == values[j].id) {
|
2020-09-04 12:09:11 -05:00
|
|
|
uint32_t value = values[j].value + prog_data->relocs[i].delta;
|
|
|
|
switch (prog_data->relocs[i].type) {
|
2020-09-04 12:23:35 -05:00
|
|
|
case BRW_SHADER_RELOC_TYPE_U32:
|
|
|
|
*(uint32_t *)dst = value;
|
|
|
|
break;
|
2020-09-04 12:09:11 -05:00
|
|
|
case BRW_SHADER_RELOC_TYPE_MOV_IMM:
|
2022-06-29 14:13:31 -07:00
|
|
|
brw_update_reloc_imm(isa, dst, value);
|
2020-09-04 12:09:11 -05:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
unreachable("Invalid relocation type");
|
|
|
|
}
|
2020-08-08 12:55:29 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|