mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 11:00:11 +01:00
nir: add nir_inline_sysval pass
a bunch of drivers have versions of this, might as well make a common one. Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Marek Olšák <maraeo@gmail.com> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: Mary Guillemard <mary.guillemard@collabora.com> Reviewed-by: John Anthony <john.anthony@arm.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36516>
This commit is contained in:
parent
3c9471c8d7
commit
1c28fc0a86
3 changed files with 34 additions and 0 deletions
|
|
@ -126,6 +126,7 @@ else
|
|||
'nir_gather_xfb_info.c',
|
||||
'nir_opt_group_loads.c',
|
||||
'nir_gs_count_vertices.c',
|
||||
'nir_inline_sysval.c',
|
||||
'nir_inline_uniforms.c',
|
||||
'nir_instr_set.c',
|
||||
'nir_instr_set.h',
|
||||
|
|
|
|||
|
|
@ -4945,6 +4945,8 @@ void nir_add_inlinable_uniforms(const nir_src *cond, nir_loop_info *info,
|
|||
uint32_t *uni_offsets, uint8_t *num_offsets,
|
||||
unsigned max_num_bo, unsigned max_offset);
|
||||
|
||||
bool nir_inline_sysval(nir_shader *shader, nir_intrinsic_op op, uint64_t imm);
|
||||
|
||||
bool nir_propagate_invariant(nir_shader *shader, bool invariant_prim);
|
||||
|
||||
void nir_lower_var_copy_instr(nir_intrinsic_instr *copy, nir_shader *shader);
|
||||
|
|
|
|||
31
src/compiler/nir/nir_inline_sysval.c
Normal file
31
src/compiler/nir/nir_inline_sysval.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (C) 2025 Valve Corporation
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include "nir_builder.h"
|
||||
|
||||
struct ctx {
|
||||
nir_intrinsic_op op;
|
||||
uint64_t imm;
|
||||
};
|
||||
|
||||
static bool
|
||||
pass(nir_builder *b, nir_intrinsic_instr *intr, void *data)
|
||||
{
|
||||
struct ctx *ctx = data;
|
||||
if (intr->intrinsic != ctx->op)
|
||||
return false;
|
||||
|
||||
b->cursor = nir_before_instr(&intr->instr);
|
||||
nir_def_replace(&intr->def, nir_imm_intN_t(b, ctx->imm, intr->def.bit_size));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
nir_inline_sysval(nir_shader *shader, nir_intrinsic_op op, uint64_t imm)
|
||||
{
|
||||
struct ctx ctx = { .op = op, .imm = imm };
|
||||
return nir_shader_intrinsics_pass(shader, pass, nir_metadata_control_flow,
|
||||
&ctx);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue