mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 17:30:12 +01:00
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>
31 lines
718 B
C
31 lines
718 B
C
/*
|
|
* 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);
|
|
}
|