diff --git a/src/gallium/drivers/panfrost/pan_nir_lower_res_indices.c b/src/gallium/drivers/panfrost/pan_nir_lower_res_indices.c index 591c3c6ce0e..bbcab2494ab 100644 --- a/src/gallium/drivers/panfrost/pan_nir_lower_res_indices.c +++ b/src/gallium/drivers/panfrost/pan_nir_lower_res_indices.c @@ -27,13 +27,8 @@ #include "pan_shader.h" static bool -lower_instr(nir_builder *b, nir_instr *instr, void *data) +lower_tex(nir_builder *b, nir_tex_instr *tex) { - if (instr->type != nir_instr_type_tex) - return false; - - nir_tex_instr *tex = nir_instr_as_tex(instr); - b->cursor = nir_before_instr(&tex->instr); nir_def *tex_offset = nir_steal_tex_src(tex, nir_tex_src_texture_offset); @@ -65,6 +60,45 @@ lower_instr(nir_builder *b, nir_instr *instr, void *data) return true; } +static bool +lower_image_intrin(nir_builder *b, nir_intrinsic_instr *intrin) +{ + b->cursor = nir_before_instr(&intrin->instr); + + nir_src *tex_handle = &intrin->src[0]; + nir_def *new_handle = + nir_ior_imm(b, tex_handle->ssa, pan_res_handle(PAN_TABLE_IMAGE, 0)); + nir_src_rewrite(tex_handle, new_handle); + + return true; +} + +static bool +lower_intrinsic(nir_builder *b, nir_intrinsic_instr *intrin) +{ + switch (intrin->intrinsic) { + case nir_intrinsic_image_load: + case nir_intrinsic_image_store: + case nir_intrinsic_image_texel_address: + return lower_image_intrin(b, intrin); + default: + return false; + } +} + +static bool +lower_instr(nir_builder *b, nir_instr *instr, void *data) +{ + switch (instr->type) { + case nir_instr_type_tex: + return lower_tex(b, nir_instr_as_tex(instr)); + case nir_instr_type_intrinsic: + return lower_intrinsic(b, nir_instr_as_intrinsic(instr)); + default: + return false; + } +} + bool panfrost_nir_lower_res_indices(nir_shader *shader, struct panfrost_compile_inputs *inputs) diff --git a/src/panfrost/compiler/bifrost_compile.c b/src/panfrost/compiler/bifrost_compile.c index d74a7c67729..6eacf49433c 100644 --- a/src/panfrost/compiler/bifrost_compile.c +++ b/src/panfrost/compiler/bifrost_compile.c @@ -25,8 +25,8 @@ * Alyssa Rosenzweig */ -#include "compiler/glsl_types.h" #include "compiler/glsl/glsl_to_nir.h" +#include "compiler/glsl_types.h" #include "compiler/nir/nir_builder.h" #include "util/u_debug.h" @@ -1355,12 +1355,21 @@ bi_emit_image_load(bi_builder *b, nir_intrinsic_instr *instr) assert(dim != GLSL_SAMPLER_DIM_MS && "MSAA'd image not lowered"); if (b->shader->arch >= 9 && nir_src_is_const(instr->src[0])) { - bi_instr *I = bi_ld_tex_imm_to(b, dest, xy, zw, regfmt, vecsize, - nir_src_as_uint(instr->src[0])); + const unsigned raw_value = nir_src_as_uint(instr->src[0]); + const unsigned table_index = pan_res_handle_get_table(raw_value); + const unsigned texture_index = pan_res_handle_get_index(raw_value); - I->table = PAN_TABLE_IMAGE; + if (texture_index < 16 && va_is_valid_const_table(table_index)) { + bi_instr *I = + bi_ld_tex_imm_to(b, dest, xy, zw, regfmt, vecsize, texture_index); + I->table = va_res_fold_table_idx(table_index); + } else { + bi_ld_tex_to(b, dest, xy, zw, bi_src_index(&instr->src[0]), regfmt, + vecsize); + } } else if (b->shader->arch >= 9) { - unreachable("Indirect images on Valhall not yet supported"); + bi_ld_tex_to(b, dest, xy, zw, bi_src_index(&instr->src[0]), regfmt, + vecsize); } else { bi_ld_attr_tex_to(b, dest, xy, zw, bi_emit_image_index(b, instr), regfmt, vecsize); @@ -1388,12 +1397,18 @@ bi_emit_lea_image_to(bi_builder *b, bi_index dest, nir_intrinsic_instr *instr) bi_index zw = bi_emit_image_coord(b, coords, 1, coord_comps, array); if (b->shader->arch >= 9 && nir_src_is_const(instr->src[0])) { - bi_instr *I = bi_lea_tex_imm_to(b, dest, xy, zw, false, - nir_src_as_uint(instr->src[0])); + const unsigned raw_value = nir_src_as_uint(instr->src[0]); + unsigned table_index = pan_res_handle_get_table(raw_value); + unsigned texture_index = pan_res_handle_get_index(raw_value); - I->table = PAN_TABLE_IMAGE; + if (texture_index < 16 && va_is_valid_const_table(table_index)) { + bi_instr *I = bi_lea_tex_imm_to(b, dest, xy, zw, false, texture_index); + I->table = va_res_fold_table_idx(table_index); + } else { + bi_lea_tex_to(b, dest, xy, zw, bi_src_index(&instr->src[0]), false); + } } else if (b->shader->arch >= 9) { - unreachable("Indirect images on Valhall not yet supported"); + bi_lea_tex_to(b, dest, xy, zw, bi_src_index(&instr->src[0]), false); } else { bi_instr *I = bi_lea_attr_tex_to(b, dest, xy, zw, bi_emit_image_index(b, instr), type);