From cccd3aa45ccf83d1c6eaea5d265bf122552e099c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timur=20Krist=C3=B3f?= Date: Mon, 3 Feb 2025 09:22:28 +0100 Subject: [PATCH] nir: Move nir_tcs_info to separate file. The nir_tcs_info struct is like nir_xfb_info in the sense that it's very specialized and not often used, so it deserves its own header too. Reviewed-by: Faith Ekstrand Reviewed-by: Alyssa Rosenzweig Acked-By: Mike Blumenkrantz Part-of: --- .../common/nir/ac_nir_lower_tess_io_to_mem.c | 1 + src/amd/vulkan/radv_shader_info.h | 1 + src/compiler/nir/meson.build | 1 + src/compiler/nir/nir.h | 38 --------- src/compiler/nir/nir_gather_tcs_info.c | 1 + src/compiler/nir/nir_tcs_info.h | 80 +++++++++++++++++++ src/gallium/drivers/radeonsi/si_shader.c | 1 + src/gallium/drivers/radeonsi/si_shader_info.c | 1 + 8 files changed, 86 insertions(+), 38 deletions(-) create mode 100644 src/compiler/nir/nir_tcs_info.h diff --git a/src/amd/common/nir/ac_nir_lower_tess_io_to_mem.c b/src/amd/common/nir/ac_nir_lower_tess_io_to_mem.c index 1694345f99d..7fb27184d13 100644 --- a/src/amd/common/nir/ac_nir_lower_tess_io_to_mem.c +++ b/src/amd/common/nir/ac_nir_lower_tess_io_to_mem.c @@ -8,6 +8,7 @@ #include "ac_nir.h" #include "ac_nir_helpers.h" #include "nir_builder.h" +#include "nir_tcs_info.h" #include "util/u_math.h" /* diff --git a/src/amd/vulkan/radv_shader_info.h b/src/amd/vulkan/radv_shader_info.h index eebe53485e1..8f416b4936e 100644 --- a/src/amd/vulkan/radv_shader_info.h +++ b/src/amd/vulkan/radv_shader_info.h @@ -15,6 +15,7 @@ #include #include "nir.h" +#include "nir_tcs_info.h" #include "radv_constants.h" #include "radv_shader_args.h" diff --git a/src/compiler/nir/meson.build b/src/compiler/nir/meson.build index 674bf011158..2b1f9ebcc0a 100644 --- a/src/compiler/nir/meson.build +++ b/src/compiler/nir/meson.build @@ -295,6 +295,7 @@ files_libnir = files( 'nir_split_vars.c', 'nir_sweep.c', 'nir_to_lcssa.c', + 'nir_tcs_info.h', 'nir_trivialize_registers.c', 'nir_use_dominance.c', 'nir_validate.c', diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 3722a1df14b..c5afa2b7174 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -5621,44 +5621,6 @@ void nir_gather_types(nir_function_impl *impl, BITSET_WORD *float_types, BITSET_WORD *int_types); -typedef struct nir_tcs_info { - /* Whether all invocations write tess level outputs. - * - * This is useful when a pass wants to read tess level values at the end - * of the shader. If this is true, the pass doesn't have to insert a barrier - * and use output loads, it can just use the SSA defs that are being stored - * (or phis thereof) to get the tess level output values. - */ - bool all_invocations_define_tess_levels; - - /* Whether any of the outer tess level components is effectively 0, meaning - * that the shader discards the patch. NaNs and negative values are included - * in this. If the patch is discarded, inner tess levels have no effect. - */ - bool all_tess_levels_are_effectively_zero; - - /* Whether all tess levels are effectively 1, meaning that the tessellator - * behaves as if they were 1. There is a range of values that lead to that - * behavior depending on the tessellation spacing. - */ - bool all_tess_levels_are_effectively_one; - - /* Whether the shader uses a barrier synchronizing TCS output stores. - * For example, passes that write an output at the beginning of the shader - * and load it at the end can use this to determine whether they have to - * insert a barrier or whether the shader already contains a barrier. - */ - bool always_executes_barrier; - - /* Whether outer tess levels <= 0 are written anywhere in the shader. */ - bool discards_patches; -} nir_tcs_info; - -void -nir_gather_tcs_info(const nir_shader *nir, nir_tcs_info *info, - enum tess_primitive_mode prim, - enum gl_tess_spacing spacing); - void nir_assign_var_locations(nir_shader *shader, nir_variable_mode mode, unsigned *size, int (*type_size)(const struct glsl_type *, bool)); diff --git a/src/compiler/nir/nir_gather_tcs_info.c b/src/compiler/nir/nir_gather_tcs_info.c index 0d3e5c9575c..4e8fc575fc7 100644 --- a/src/compiler/nir/nir_gather_tcs_info.c +++ b/src/compiler/nir/nir_gather_tcs_info.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: MIT */ +#include "nir_tcs_info.h" #include "nir.h" #include diff --git a/src/compiler/nir/nir_tcs_info.h b/src/compiler/nir/nir_tcs_info.h new file mode 100644 index 00000000000..1056c127d58 --- /dev/null +++ b/src/compiler/nir/nir_tcs_info.h @@ -0,0 +1,80 @@ +/* + * Copyright © 2024 Advanced Micro Devices, Inc. + * + * 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. + * + * Authors: + * Marek Olšák + * + */ + +#ifndef NIR_TCS_INFO_H +#define NIR_TCS_INFO_H + +#include "compiler/shader_enums.h" +#include "nir_defines.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct nir_tcs_info { + /* Whether all invocations write tess level outputs. + * + * This is useful when a pass wants to read tess level values at the end + * of the shader. If this is true, the pass doesn't have to insert a barrier + * and use output loads, it can just use the SSA defs that are being stored + * (or phis thereof) to get the tess level output values. + */ + bool all_invocations_define_tess_levels; + + /* Whether any of the outer tess level components is effectively 0, meaning + * that the shader discards the patch. NaNs and negative values are included + * in this. If the patch is discarded, inner tess levels have no effect. + */ + bool all_tess_levels_are_effectively_zero; + + /* Whether all tess levels are effectively 1, meaning that the tessellator + * behaves as if they were 1. There is a range of values that lead to that + * behavior depending on the tessellation spacing. + */ + bool all_tess_levels_are_effectively_one; + + /* Whether the shader uses a barrier synchronizing TCS output stores. + * For example, passes that write an output at the beginning of the shader + * and load it at the end can use this to determine whether they have to + * insert a barrier or whether the shader already contains a barrier. + */ + bool always_executes_barrier; + + /* Whether outer tess levels <= 0 are written anywhere in the shader. */ + bool discards_patches; +} nir_tcs_info; + +void +nir_gather_tcs_info(const nir_shader *nir, nir_tcs_info *info, + enum tess_primitive_mode prim, + enum gl_tess_spacing spacing); + +#ifdef __cplusplus +} +#endif + +#endif /* NIR_TCS_INFO_H */ diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index 7a9274ff3b0..a1a5057514d 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -10,6 +10,7 @@ #include "nir.h" #include "nir_builder.h" #include "nir_serialize.h" +#include "nir_tcs_info.h" #include "nir_xfb_info.h" #include "si_pipe.h" #include "si_shader_internal.h" diff --git a/src/gallium/drivers/radeonsi/si_shader_info.c b/src/gallium/drivers/radeonsi/si_shader_info.c index 770d4aeb713..5eac1f2c620 100644 --- a/src/gallium/drivers/radeonsi/si_shader_info.c +++ b/src/gallium/drivers/radeonsi/si_shader_info.c @@ -9,6 +9,7 @@ #include "util/mesa-sha1.h" #include "sid.h" #include "nir.h" +#include "nir_tcs_info.h" #include "nir_xfb_info.h" #include "aco_interface.h" #include "ac_nir.h"