From 32d9afdf734ee776012c1565d9683ab1a4142877 Mon Sep 17 00:00:00 2001 From: Ella Stanforth Date: Mon, 28 Apr 2025 17:55:29 +0100 Subject: [PATCH] nir/printf: add new helper to printf at a specific pixel. Debugging with nir_printf_fmt can result in overwhelming information. This allows us to filter for a pixel we care about. Reviewed-by: Alyssa Rosenzweig Reviewed-by: Lionel Landwerlin Part-of: --- src/compiler/nir/nir_builder.h | 2 ++ src/compiler/nir/nir_lower_printf.c | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h index 37044143937..9e8e5bd7858 100644 --- a/src/compiler/nir/nir_builder.h +++ b/src/compiler/nir/nir_builder.h @@ -2404,6 +2404,8 @@ nir_gen_rect_vertices(nir_builder *b, nir_def *z, nir_def *w); */ void nir_printf_fmt(nir_builder *b, unsigned ptr_bit_size, const char *fmt, ...); +void nir_printf_fmt_at_px(nir_builder *b, unsigned ptr_bit_size, + unsigned x, unsigned y, const char *fmt, ...); /* Call a serialized function. This is used internally by vtn_bindgen, it is not * intended for end-users of NIR. diff --git a/src/compiler/nir/nir_lower_printf.c b/src/compiler/nir/nir_lower_printf.c index 204fd575511..6030a12dbed 100644 --- a/src/compiler/nir/nir_lower_printf.c +++ b/src/compiler/nir/nir_lower_printf.c @@ -329,3 +329,18 @@ nir_printf_fmt(nir_builder *b, unsigned ptr_bit_size, const char *fmt, ...) nir_vprintf_fmt(b, ptr_bit_size, fmt, ap); va_end(ap); } + +/* Debug helper to allow us to printf at a single pixel */ +void nir_printf_fmt_at_px(nir_builder *b, unsigned ptr_bit_size, unsigned x_px, unsigned y_px, const char *fmt, ...) +{ + va_list ap; + + nir_def *xy_px = nir_f2u32(b,nir_load_frag_coord(b)); + nir_def *is_at_px = nir_ball_iequal(b, nir_imm_ivec2(b, x_px, y_px), xy_px); + + nir_push_if(b, is_at_px); + va_start(ap, fmt); + nir_vprintf_fmt(b, ptr_bit_size, fmt, ap); + va_end(ap); + nir_pop_if(b, NULL); +}