2014-10-29 12:42:54 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2014 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 "nir.h"
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Handles management of the metadata.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
void
|
2016-12-13 14:39:51 +11:00
|
|
|
nir_metadata_require(nir_function_impl *impl, nir_metadata required, ...)
|
2014-10-29 12:42:54 -07:00
|
|
|
{
|
|
|
|
|
#define NEEDS_UPDATE(X) ((required & ~impl->valid_metadata) & (X))
|
|
|
|
|
|
|
|
|
|
if (NEEDS_UPDATE(nir_metadata_block_index))
|
|
|
|
|
nir_index_blocks(impl);
|
2020-09-29 15:33:39 -07:00
|
|
|
if (NEEDS_UPDATE(nir_metadata_instr_index))
|
|
|
|
|
nir_index_instrs(impl);
|
2014-10-29 12:42:54 -07:00
|
|
|
if (NEEDS_UPDATE(nir_metadata_dominance))
|
|
|
|
|
nir_calc_dominance_impl(impl);
|
2023-08-15 10:11:43 -05:00
|
|
|
if (NEEDS_UPDATE(nir_metadata_live_defs))
|
|
|
|
|
nir_live_defs_impl(impl);
|
2024-08-23 11:42:37 +02:00
|
|
|
if (NEEDS_UPDATE(nir_metadata_divergence))
|
|
|
|
|
nir_divergence_analysis_impl(impl,
|
|
|
|
|
impl->function->shader->options->divergence_analysis_options);
|
2024-10-31 16:00:43 +00:00
|
|
|
if (required & nir_metadata_loop_analysis) {
|
2016-12-13 14:39:51 +11:00
|
|
|
va_list ap;
|
|
|
|
|
va_start(ap, required);
|
2022-05-11 20:12:56 +10:00
|
|
|
/* !! Warning !! Do not move these va_arg() call directly to
|
|
|
|
|
* nir_loop_analyze_impl() as parameters because the execution order will
|
|
|
|
|
* become undefined.
|
|
|
|
|
*/
|
2024-10-31 16:00:43 +00:00
|
|
|
nir_variable_mode indirect_mask = va_arg(ap, nir_variable_mode);
|
2022-05-11 20:12:56 +10:00
|
|
|
int force_unroll_sampler_indirect = va_arg(ap, int);
|
2016-12-13 14:39:51 +11:00
|
|
|
va_end(ap);
|
2024-10-31 16:00:43 +00:00
|
|
|
|
|
|
|
|
if (NEEDS_UPDATE(nir_metadata_loop_analysis) ||
|
|
|
|
|
indirect_mask != impl->loop_analysis_indirect_mask ||
|
|
|
|
|
force_unroll_sampler_indirect != impl->loop_analysis_force_unroll_sampler_indirect) {
|
|
|
|
|
nir_loop_analyze_impl(impl, indirect_mask, force_unroll_sampler_indirect);
|
|
|
|
|
}
|
2016-12-13 14:39:51 +11:00
|
|
|
}
|
2014-10-29 12:42:54 -07:00
|
|
|
|
|
|
|
|
#undef NEEDS_UPDATE
|
|
|
|
|
|
|
|
|
|
impl->valid_metadata |= required;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-24 15:25:10 -05:00
|
|
|
bool
|
|
|
|
|
nir_progress(bool progress, nir_function_impl *impl, nir_metadata preserved)
|
2014-10-29 12:42:54 -07:00
|
|
|
{
|
2025-02-24 15:25:10 -05:00
|
|
|
/* If we do not make progress, we preserve all metadata. */
|
|
|
|
|
if (!progress)
|
|
|
|
|
preserved = nir_metadata_all;
|
|
|
|
|
|
2024-06-05 10:44:51 +02:00
|
|
|
/* If we discard valid liveness information, immediately free the
|
|
|
|
|
* liveness information for each block. For large shaders, it can
|
|
|
|
|
* consume a huge amount of memory, and it's usually not immediately
|
|
|
|
|
* needed after dirtying.
|
|
|
|
|
*/
|
|
|
|
|
if ((impl->valid_metadata & ~preserved) & nir_metadata_live_defs) {
|
|
|
|
|
nir_foreach_block(block, impl) {
|
|
|
|
|
ralloc_free(block->live_in);
|
|
|
|
|
ralloc_free(block->live_out);
|
|
|
|
|
block->live_in = block->live_out = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-29 12:42:54 -07:00
|
|
|
impl->valid_metadata &= preserved;
|
2025-02-24 15:25:10 -05:00
|
|
|
return progress;
|
2014-10-29 12:42:54 -07:00
|
|
|
}
|
2015-11-03 00:31:22 -08:00
|
|
|
|
2020-05-21 21:37:33 -05:00
|
|
|
void
|
|
|
|
|
nir_shader_preserve_all_metadata(nir_shader *shader)
|
|
|
|
|
{
|
2023-06-22 13:27:59 -04:00
|
|
|
nir_foreach_function_impl(impl, shader) {
|
treewide: Switch to nir_progress
Via the Coccinelle patch at the end of the commit message, followed by
sed -ie 's/progress = progress | /progress |=/g' $(git grep -l 'progress = prog')
ninja -C ~/mesa/build clang-format
cd ~/mesa/src/compiler/nir && clang-format -i *.c
agxfmt
@@
identifier prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
-return prog;
+return nir_progress(prog, impl, metadata);
@@
expression prog_expr, impl, metadata;
@@
-if (prog_expr) {
-nir_metadata_preserve(impl, metadata);
-return true;
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-return false;
-}
+bool progress = prog_expr;
+return nir_progress(progress, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-nir_metadata_preserve(impl, prog ? (metadata) : nir_metadata_all);
-return prog;
+return nir_progress(prog, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-nir_metadata_preserve(impl, prog ? (metadata) : nir_metadata_all);
+nir_progress(prog, impl, metadata);
@@
expression impl, metadata;
@@
-nir_metadata_preserve(impl, metadata);
-return true;
+return nir_progress(true, impl, metadata);
@@
expression impl;
@@
-nir_metadata_preserve(impl, nir_metadata_all);
-return false;
+return nir_no_progress(impl);
@@
identifier other_prog, prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
-other_prog |= prog;
+other_prog = other_prog | nir_progress(prog, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+nir_progress(prog, impl, metadata);
@@
identifier other_prog, prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-other_prog = true;
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+other_prog = other_prog | nir_progress(prog, impl, metadata);
@@
expression prog_expr, impl, metadata;
identifier prog;
@@
-if (prog_expr) {
-nir_metadata_preserve(impl, metadata);
-prog = true;
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+bool impl_progress = prog_expr;
+prog = prog | nir_progress(impl_progress, impl, metadata);
@@
identifier other_prog, prog;
expression impl, metadata;
@@
-if (prog) {
-other_prog = true;
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+other_prog = other_prog | nir_progress(prog, impl, metadata);
@@
expression prog_expr, impl, metadata;
identifier prog;
@@
-if (prog_expr) {
-prog = true;
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+bool impl_progress = prog_expr;
+prog = prog | nir_progress(impl_progress, impl, metadata);
@@
expression prog_expr, impl, metadata;
@@
-if (prog_expr) {
-nir_metadata_preserve(impl, metadata);
-} else {
-nir_metadata_preserve(impl, nir_metadata_all);
-}
+bool impl_progress = prog_expr;
+nir_progress(impl_progress, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-nir_metadata_preserve(impl, metadata);
-prog = true;
+prog = nir_progress(true, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-}
-return prog;
+return nir_progress(prog, impl, metadata);
@@
identifier prog;
expression impl, metadata;
@@
-if (prog) {
-nir_metadata_preserve(impl, metadata);
-}
+nir_progress(prog, impl, metadata);
@@
expression impl;
@@
-nir_metadata_preserve(impl, nir_metadata_all);
+nir_no_progress(impl);
@@
expression impl, metadata;
@@
-nir_metadata_preserve(impl, metadata);
+nir_progress(true, impl, metadata);
squashme! sed -ie 's/progress = progress | /progress |=/g' $(git grep -l 'progress = prog')
Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Georg Lehmann <dadschoorse@gmail.com>
Acked-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33722>
2025-02-24 15:10:33 -05:00
|
|
|
nir_no_progress(impl);
|
2020-05-21 21:37:33 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-31 11:53:41 +00:00
|
|
|
void
|
|
|
|
|
nir_metadata_invalidate(nir_shader *shader)
|
|
|
|
|
{
|
|
|
|
|
nir_foreach_function_impl(impl, shader) {
|
|
|
|
|
unsigned instr_idx = UINT32_MAX;
|
|
|
|
|
unsigned block_idx = UINT32_MAX;
|
|
|
|
|
|
|
|
|
|
nir_foreach_block_unstructured(block, impl) {
|
|
|
|
|
/* This creates an index that is non-unique, backwards and very large. */
|
|
|
|
|
block->index = (block_idx-- & 0xf) + 0xfffffff0;
|
|
|
|
|
|
|
|
|
|
if (impl->valid_metadata & nir_metadata_live_defs) {
|
|
|
|
|
ralloc_free(block->live_in);
|
|
|
|
|
ralloc_free(block->live_out);
|
|
|
|
|
}
|
|
|
|
|
block->live_in = block->live_out = NULL;
|
|
|
|
|
|
2025-08-09 02:48:52 -04:00
|
|
|
if (impl->valid_metadata & nir_metadata_dominance &&
|
|
|
|
|
block->dom_children != block->_dom_children_storage)
|
2025-01-31 11:53:41 +00:00
|
|
|
ralloc_free(block->dom_children);
|
|
|
|
|
block->dom_children = NULL;
|
|
|
|
|
block->num_dom_children = 1;
|
|
|
|
|
block->dom_pre_index = block->dom_post_index = 0;
|
2025-08-09 16:52:18 -04:00
|
|
|
_mesa_set_clear(&block->dom_frontier, NULL);
|
2025-01-31 11:53:41 +00:00
|
|
|
|
|
|
|
|
if (block->cf_node.parent->type == nir_cf_node_loop &&
|
|
|
|
|
nir_cf_node_is_first(&block->cf_node)) {
|
|
|
|
|
nir_loop *loop = nir_cf_node_as_loop(block->cf_node.parent);
|
|
|
|
|
if (impl->valid_metadata & nir_metadata_loop_analysis)
|
|
|
|
|
ralloc_free(loop->info);
|
|
|
|
|
loop->info = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
block->start_ip = (instr_idx-- & 0xf) + 0xfffffff0;
|
|
|
|
|
nir_foreach_instr(instr, block)
|
|
|
|
|
instr->index = (instr_idx-- & 0xf) + 0xfffffff0;
|
|
|
|
|
block->end_ip = (instr_idx-- & 0xf) + 0xfffffff0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl->num_blocks = 0;
|
|
|
|
|
impl->end_block->index = 0xf;
|
|
|
|
|
|
|
|
|
|
impl->valid_metadata = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-23 13:16:43 +00:00
|
|
|
#ifndef NDEBUG
|
2015-11-03 00:31:22 -08:00
|
|
|
/**
|
|
|
|
|
* Make sure passes properly invalidate metadata (part 1).
|
|
|
|
|
*
|
|
|
|
|
* Call this before running a pass to set a bogus metadata flag, which will
|
2025-02-24 15:20:21 -05:00
|
|
|
* only be preserved if the pass forgets to call nir_progress().
|
2015-11-03 00:31:22 -08:00
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
nir_metadata_set_validation_flag(nir_shader *shader)
|
|
|
|
|
{
|
2023-06-22 13:27:59 -04:00
|
|
|
nir_foreach_function_impl(impl, shader) {
|
|
|
|
|
impl->valid_metadata |= nir_metadata_not_properly_reset;
|
2015-11-03 00:31:22 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Make sure passes properly invalidate metadata (part 2).
|
|
|
|
|
*
|
|
|
|
|
* Call this after a pass makes progress to verify that the bogus metadata set by
|
|
|
|
|
* the earlier function was properly thrown away. Note that passes may not call
|
2025-02-24 15:20:21 -05:00
|
|
|
* nir_progress() if they don't actually make any changes at all.
|
2015-11-03 00:31:22 -08:00
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
nir_metadata_check_validation_flag(nir_shader *shader)
|
|
|
|
|
{
|
2023-06-22 13:27:59 -04:00
|
|
|
nir_foreach_function_impl(impl, shader) {
|
|
|
|
|
assert(!(impl->valid_metadata & nir_metadata_not_properly_reset));
|
2015-11-03 00:31:22 -08:00
|
|
|
}
|
|
|
|
|
}
|
2025-01-10 16:25:11 +00:00
|
|
|
|
2025-02-24 15:09:24 -05:00
|
|
|
void
|
|
|
|
|
nir_metadata_require_all(nir_shader *shader)
|
2025-01-10 16:25:11 +00:00
|
|
|
{
|
|
|
|
|
bool force_unroll_sampler_indirect = shader->options->force_indirect_unrolling_sampler;
|
|
|
|
|
nir_variable_mode indirect_mask = shader->options->force_indirect_unrolling;
|
|
|
|
|
nir_foreach_function_impl(impl, shader) {
|
|
|
|
|
nir_metadata_require(impl, nir_metadata_all, indirect_mask,
|
|
|
|
|
(int)force_unroll_sampler_indirect);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-03 00:31:22 -08:00
|
|
|
#endif
|