diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index 3741711fb91..8aba1fd7154 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -3890,6 +3890,22 @@ agx_preprocess_nir(nir_shader *nir) NIR_PASS(_, nir, agx_nir_lower_shared_bitsize); } +static bool +lower_printf_buffer(nir_builder *b, nir_intrinsic_instr *intr, UNUSED void *_) +{ + uint64_t value = 0; + if (intr->intrinsic == nir_intrinsic_load_printf_buffer_address) + value = LIBAGX_PRINTF_BUFFER_ADDRESS; + else if (intr->intrinsic == nir_intrinsic_load_printf_buffer_size) + value = LIBAGX_PRINTF_BUFFER_SIZE; + else + return false; + + b->cursor = nir_before_instr(&intr->instr); + nir_def_replace(&intr->def, nir_imm_intN_t(b, value, intr->def.bit_size)); + return true; +} + void agx_compile_shader_nir(nir_shader *nir, struct agx_shader_key *key, struct agx_shader_part *out) @@ -3910,8 +3926,8 @@ agx_compile_shader_nir(nir_shader *nir, struct agx_shader_key *key, if (nir->info.stage == MESA_SHADER_FRAGMENT) info->tag_write_disable = !nir->info.writes_memory; - NIR_PASS(_, nir, nir_lower_printf_buffer, LIBAGX_PRINTF_BUFFER_ADDRESS, - LIBAGX_PRINTF_BUFFER_SIZE - 8); + NIR_PASS(_, nir, nir_shader_intrinsics_pass, lower_printf_buffer, + nir_metadata_control_flow, NULL); NIR_PASS(_, nir, nir_lower_frag_coord_to_pixel_coord); NIR_PASS(_, nir, nir_lower_vars_to_ssa); diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index cc50581ca9f..53dc11fc424 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -6138,7 +6138,6 @@ typedef struct nir_lower_printf_options { } nir_lower_printf_options; bool nir_lower_printf(nir_shader *nir, const nir_lower_printf_options *options); -bool nir_lower_printf_buffer(nir_shader *nir, uint64_t address, uint32_t size); /* This is here for unit tests. */ bool nir_opt_comparison_pre_impl(nir_function_impl *impl); diff --git a/src/compiler/nir/nir_lower_printf.c b/src/compiler/nir/nir_lower_printf.c index e2580500109..881a73e9b48 100644 --- a/src/compiler/nir/nir_lower_printf.c +++ b/src/compiler/nir/nir_lower_printf.c @@ -166,39 +166,6 @@ nir_lower_printf(nir_shader *nir, const nir_lower_printf_options *options) (void *)options); } -struct buffer_opts { - uint64_t address; - uint32_t size; -}; - -static bool -lower_printf_buffer(nir_builder *b, nir_intrinsic_instr *intr, void *_options) -{ - const struct buffer_opts *options = _options; - - uint64_t value = 0; - if (intr->intrinsic == nir_intrinsic_load_printf_buffer_address) - value = options->address; - else if (intr->intrinsic == nir_intrinsic_load_printf_buffer_size) - value = options->size; - - if (value == 0) - return false; - - b->cursor = nir_before_instr(&intr->instr); - nir_def_replace(&intr->def, nir_imm_intN_t(b, value, intr->def.bit_size)); - return true; -} - -bool -nir_lower_printf_buffer(nir_shader *nir, uint64_t address, uint32_t size) -{ - struct buffer_opts opts = { .address = address, .size = size }; - - return nir_shader_intrinsics_pass(nir, lower_printf_buffer, - nir_metadata_control_flow, &opts); -} - static void nir_vprintf_fmt(nir_builder *b, unsigned ptr_bit_size, const char *fmt, va_list aq) {