From 23b0798551bc32f2885ac5016b7ba8584c8c6a2e Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Fri, 12 Jul 2024 23:36:49 -0700 Subject: [PATCH] intel/brw: Move interp_reg and per_primitive_reg out of fs_visitor Reviewed-by: Ian Romanick Part-of: --- src/intel/compiler/brw_fs.h | 5 -- src/intel/compiler/brw_fs_nir.cpp | 101 +++++++++++++++++++++++--- src/intel/compiler/brw_fs_visitor.cpp | 79 -------------------- 3 files changed, 91 insertions(+), 94 deletions(-) diff --git a/src/intel/compiler/brw_fs.h b/src/intel/compiler/brw_fs.h index f0a61977fd3..9cb77b7c5cc 100644 --- a/src/intel/compiler/brw_fs.h +++ b/src/intel/compiler/brw_fs.h @@ -312,11 +312,6 @@ public: bool mark_last_urb_write_with_eot(); void emit_cs_terminate(); - brw_reg interp_reg(const brw::fs_builder &bld, unsigned location, - unsigned channel, unsigned comp); - brw_reg per_primitive_reg(const brw::fs_builder &bld, - int location, unsigned comp); - const struct brw_compiler *compiler; void *log_data; /* Passed to compiler->*_log functions */ diff --git a/src/intel/compiler/brw_fs_nir.cpp b/src/intel/compiler/brw_fs_nir.cpp index 7a61cb5c3fc..b45260f4f4d 100644 --- a/src/intel/compiler/brw_fs_nir.cpp +++ b/src/intel/compiler/brw_fs_nir.cpp @@ -4045,6 +4045,87 @@ emit_shading_rate_setup(nir_to_brw_state &ntb) return rate; } +/* Input data is organized with first the per-primitive values, followed + * by per-vertex values. The per-vertex will have interpolation information + * associated, so use 4 components for each value. + */ + +/* The register location here is relative to the start of the URB + * data. It will get adjusted to be a real location before + * generate_code() time. + */ +static brw_reg +brw_interp_reg(const fs_builder &bld, unsigned location, + unsigned channel, unsigned comp) +{ + fs_visitor &s = *bld.shader; + assert(s.stage == MESA_SHADER_FRAGMENT); + assert(BITFIELD64_BIT(location) & ~s.nir->info.per_primitive_inputs); + + const struct brw_wm_prog_data *prog_data = brw_wm_prog_data(s.prog_data); + + assert(prog_data->urb_setup[location] >= 0); + unsigned nr = prog_data->urb_setup[location]; + channel += prog_data->urb_setup_channel[location]; + + /* Adjust so we start counting from the first per_vertex input. */ + assert(nr >= prog_data->num_per_primitive_inputs); + nr -= prog_data->num_per_primitive_inputs; + + const unsigned per_vertex_start = prog_data->num_per_primitive_inputs; + const unsigned regnr = per_vertex_start + (nr * 4) + channel; + + if (s.max_polygons > 1) { + /* In multipolygon dispatch each plane parameter is a + * dispatch_width-wide SIMD vector (see comment in + * assign_urb_setup()), so we need to use offset() instead of + * component() to select the specified parameter. + */ + const brw_reg tmp = bld.vgrf(BRW_TYPE_UD); + bld.MOV(tmp, offset(brw_attr_reg(regnr, BRW_TYPE_UD), + s.dispatch_width, comp)); + return retype(tmp, BRW_TYPE_F); + } else { + return component(brw_attr_reg(regnr, BRW_TYPE_F), comp); + } +} + +/* The register location here is relative to the start of the URB + * data. It will get adjusted to be a real location before + * generate_code() time. + */ +static brw_reg +brw_per_primitive_reg(const fs_builder &bld, int location, unsigned comp) +{ + fs_visitor &s = *bld.shader; + assert(s.stage == MESA_SHADER_FRAGMENT); + assert(BITFIELD64_BIT(location) & s.nir->info.per_primitive_inputs); + + const struct brw_wm_prog_data *prog_data = brw_wm_prog_data(s.prog_data); + + comp += prog_data->urb_setup_channel[location]; + + assert(prog_data->urb_setup[location] >= 0); + + const unsigned regnr = prog_data->urb_setup[location] + comp / 4; + + assert(regnr < prog_data->num_per_primitive_inputs); + + if (s.max_polygons > 1) { + /* In multipolygon dispatch each primitive constant is a + * dispatch_width-wide SIMD vector (see comment in + * assign_urb_setup()), so we need to use offset() instead of + * component() to select the specified parameter. + */ + const brw_reg tmp = bld.vgrf(BRW_TYPE_UD); + bld.MOV(tmp, offset(brw_attr_reg(regnr, BRW_TYPE_UD), + s.dispatch_width, comp % 4)); + return retype(tmp, BRW_TYPE_F); + } else { + return component(brw_attr_reg(regnr, BRW_TYPE_F), comp % 4); + } +} + static void fs_nir_emit_fs_intrinsic(nir_to_brw_state &ntb, nir_intrinsic_instr *instr) @@ -4235,7 +4316,7 @@ fs_nir_emit_fs_intrinsic(nir_to_brw_state &ntb, assert(base != VARYING_SLOT_PRIMITIVE_INDICES); for (unsigned int i = 0; i < num_components; i++) { bld.MOV(offset(dest, bld, i), - retype(s.per_primitive_reg(bld, base, comp + i), dest.type)); + retype(brw_per_primitive_reg(bld, base, comp + i), dest.type)); } } else { /* Gfx20+ packs the plane parameters of a single logical @@ -4245,7 +4326,7 @@ fs_nir_emit_fs_intrinsic(nir_to_brw_state &ntb, const unsigned k = devinfo->ver >= 20 ? 0 : 3; for (unsigned int i = 0; i < num_components; i++) { bld.MOV(offset(dest, bld, i), - retype(s.interp_reg(bld, base, comp + i, k), dest.type)); + retype(brw_interp_reg(bld, base, comp + i, k), dest.type)); } } break; @@ -4263,13 +4344,13 @@ fs_nir_emit_fs_intrinsic(nir_to_brw_state &ntb, * format. */ if (devinfo->ver >= 20) { - bld.MOV(offset(dest, bld, 0), s.interp_reg(bld, base, comp, 0)); - bld.MOV(offset(dest, bld, 1), s.interp_reg(bld, base, comp, 2)); - bld.MOV(offset(dest, bld, 2), s.interp_reg(bld, base, comp, 1)); + bld.MOV(offset(dest, bld, 0), brw_interp_reg(bld, base, comp, 0)); + bld.MOV(offset(dest, bld, 1), brw_interp_reg(bld, base, comp, 2)); + bld.MOV(offset(dest, bld, 2), brw_interp_reg(bld, base, comp, 1)); } else { - bld.MOV(offset(dest, bld, 0), s.interp_reg(bld, base, comp, 3)); - bld.MOV(offset(dest, bld, 1), s.interp_reg(bld, base, comp, 1)); - bld.MOV(offset(dest, bld, 2), s.interp_reg(bld, base, comp, 0)); + bld.MOV(offset(dest, bld, 0), brw_interp_reg(bld, base, comp, 3)); + bld.MOV(offset(dest, bld, 1), brw_interp_reg(bld, base, comp, 1)); + bld.MOV(offset(dest, bld, 2), brw_interp_reg(bld, base, comp, 0)); } break; @@ -4394,8 +4475,8 @@ fs_nir_emit_fs_intrinsic(nir_to_brw_state &ntb, for (unsigned int i = 0; i < instr->num_components; i++) { brw_reg interp = - s.interp_reg(bld, nir_intrinsic_base(instr), - nir_intrinsic_component(instr) + i, 0); + brw_interp_reg(bld, nir_intrinsic_base(instr), + nir_intrinsic_component(instr) + i, 0); interp.type = BRW_TYPE_F; dest.type = BRW_TYPE_F; diff --git a/src/intel/compiler/brw_fs_visitor.cpp b/src/intel/compiler/brw_fs_visitor.cpp index 627ce41b2e5..666f106d9bc 100644 --- a/src/intel/compiler/brw_fs_visitor.cpp +++ b/src/intel/compiler/brw_fs_visitor.cpp @@ -36,85 +36,6 @@ using namespace brw; -/* Input data is organized with first the per-primitive values, followed - * by per-vertex values. The per-vertex will have interpolation information - * associated, so use 4 components for each value. - */ - -/* The register location here is relative to the start of the URB - * data. It will get adjusted to be a real location before - * generate_code() time. - */ -brw_reg -fs_visitor::interp_reg(const fs_builder &bld, unsigned location, - unsigned channel, unsigned comp) -{ - assert(stage == MESA_SHADER_FRAGMENT); - assert(BITFIELD64_BIT(location) & ~nir->info.per_primitive_inputs); - - const struct brw_wm_prog_data *prog_data = brw_wm_prog_data(this->prog_data); - - assert(prog_data->urb_setup[location] >= 0); - unsigned nr = prog_data->urb_setup[location]; - channel += prog_data->urb_setup_channel[location]; - - /* Adjust so we start counting from the first per_vertex input. */ - assert(nr >= prog_data->num_per_primitive_inputs); - nr -= prog_data->num_per_primitive_inputs; - - const unsigned per_vertex_start = prog_data->num_per_primitive_inputs; - const unsigned regnr = per_vertex_start + (nr * 4) + channel; - - if (max_polygons > 1) { - /* In multipolygon dispatch each plane parameter is a - * dispatch_width-wide SIMD vector (see comment in - * assign_urb_setup()), so we need to use offset() instead of - * component() to select the specified parameter. - */ - const brw_reg tmp = bld.vgrf(BRW_TYPE_UD); - bld.MOV(tmp, offset(brw_attr_reg(regnr, BRW_TYPE_UD), - dispatch_width, comp)); - return retype(tmp, BRW_TYPE_F); - } else { - return component(brw_attr_reg(regnr, BRW_TYPE_F), comp); - } -} - -/* The register location here is relative to the start of the URB - * data. It will get adjusted to be a real location before - * generate_code() time. - */ -brw_reg -fs_visitor::per_primitive_reg(const fs_builder &bld, int location, unsigned comp) -{ - assert(stage == MESA_SHADER_FRAGMENT); - assert(BITFIELD64_BIT(location) & nir->info.per_primitive_inputs); - - const struct brw_wm_prog_data *prog_data = brw_wm_prog_data(this->prog_data); - - comp += prog_data->urb_setup_channel[location]; - - assert(prog_data->urb_setup[location] >= 0); - - const unsigned regnr = prog_data->urb_setup[location] + comp / 4; - - assert(regnr < prog_data->num_per_primitive_inputs); - - if (max_polygons > 1) { - /* In multipolygon dispatch each primitive constant is a - * dispatch_width-wide SIMD vector (see comment in - * assign_urb_setup()), so we need to use offset() instead of - * component() to select the specified parameter. - */ - const brw_reg tmp = bld.vgrf(BRW_TYPE_UD); - bld.MOV(tmp, offset(brw_attr_reg(regnr, BRW_TYPE_UD), - dispatch_width, comp % 4)); - return retype(tmp, BRW_TYPE_F); - } else { - return component(brw_attr_reg(regnr, BRW_TYPE_F), comp % 4); - } -} - void fs_visitor::emit_urb_writes(const brw_reg &gs_vertex_count) {