About Social Code
aboutsummaryrefslogtreecommitdiff
path: root/src/compiler/nir/nir_inline_sysval.c
blob: 349f3af8d506b5bad3344fc826b25684c771e6d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);
}