mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-19 11:28:15 +02:00
Makes it possible to use printf statements inside glsl meta shaders. Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34208>
52 lines
No EOL
1.2 KiB
C
52 lines
No EOL
1.2 KiB
C
/*
|
|
* Copyright © 2025 Valve Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include "radv_nir.h"
|
|
#include "radv_printf.h"
|
|
|
|
#include "util/u_printf.h"
|
|
|
|
#include "nir.h"
|
|
#include "nir_builder.h"
|
|
|
|
static bool
|
|
pass(nir_builder *b, nir_intrinsic_instr *instr, void *state)
|
|
{
|
|
if (instr->intrinsic != nir_intrinsic_printf)
|
|
return false;
|
|
|
|
u_printf_info *info = &b->shader->printf_info[nir_intrinsic_fmt_idx(instr)];
|
|
|
|
nir_def **args = malloc(info->num_args * sizeof(nir_def *));
|
|
|
|
b->cursor = nir_after_instr(&instr->instr);
|
|
|
|
nir_deref_instr *packed_args = nir_src_as_deref(instr->src[0]);
|
|
for (uint32_t i = 0; i < info->num_args; i++)
|
|
args[i] = nir_load_deref(b, nir_build_deref_struct(b, packed_args, i));
|
|
|
|
radv_build_printf_args(b, NULL, info->strings, info->num_args, args);
|
|
|
|
nir_instr_remove(&instr->instr);
|
|
|
|
free(args);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
radv_nir_lower_printf(nir_shader *shader)
|
|
{
|
|
bool progress = nir_shader_intrinsics_pass(shader, pass, nir_metadata_none, NULL);
|
|
|
|
/* cleanup */
|
|
if (progress) {
|
|
nir_split_struct_vars(shader, nir_var_function_temp);
|
|
nir_lower_vars_to_ssa(shader);
|
|
}
|
|
|
|
return progress;
|
|
} |