summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/broadcom/compiler/vir.c2
-rw-r--r--src/compiler/nir/nir.h6
-rw-r--r--src/compiler/nir/nir_lower_tex.c20
3 files changed, 28 insertions, 0 deletions
diff --git a/src/broadcom/compiler/vir.c b/src/broadcom/compiler/vir.c
index 01e18ffd074..4e6149d11aa 100644
--- a/src/broadcom/compiler/vir.c
+++ b/src/broadcom/compiler/vir.c
@@ -611,6 +611,8 @@ v3d_lower_nir(struct v3d_compile *c)
{
struct nir_lower_tex_options tex_options = {
.lower_txd = true,
+ .lower_tg4_broadcom_swizzle = true,
+
.lower_rect = false, /* XXX: Use this on V3D 3.x */
.lower_txp = ~0,
/* Apply swizzles to all samplers. */
diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h
index 76c09069985..318ffb33cef 100644
--- a/src/compiler/nir/nir.h
+++ b/src/compiler/nir/nir.h
@@ -3085,6 +3085,12 @@ typedef struct nir_lower_tex_options {
*/
bool lower_txd_offset_clamp;
+ /**
+ * If true, apply a .bagr swizzle on tg4 results to handle Broadcom's
+ * mixed-up tg4 locations.
+ */
+ bool lower_tg4_broadcom_swizzle;
+
enum nir_lower_tex_packing lower_tex_packing[32];
} nir_lower_tex_options;
diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c
index 001c525e666..a618b86b34c 100644
--- a/src/compiler/nir/nir_lower_tex.c
+++ b/src/compiler/nir/nir_lower_tex.c
@@ -739,6 +739,21 @@ get_zero_or_one(nir_builder *b, nir_alu_type type, uint8_t swizzle_val)
}
static void
+swizzle_tg4_broadcom(nir_builder *b, nir_tex_instr *tex)
+{
+ assert(tex->dest.is_ssa);
+
+ b->cursor = nir_after_instr(&tex->instr);
+
+ assert(nir_tex_instr_dest_size(tex) == 4);
+ unsigned swiz[4] = { 2, 3, 1, 0 };
+ nir_ssa_def *swizzled = nir_swizzle(b, &tex->dest.ssa, swiz, 4, false);
+
+ nir_ssa_def_rewrite_uses_after(&tex->dest.ssa, nir_src_for_ssa(swizzled),
+ swizzled->parent_instr);
+}
+
+static void
swizzle_result(nir_builder *b, nir_tex_instr *tex, const uint8_t swizzle[4])
{
assert(tex->dest.is_ssa);
@@ -937,6 +952,11 @@ nir_lower_tex_block(nir_block *block, nir_builder *b,
progress = true;
}
+ if (tex->op == nir_texop_tg4 && options->lower_tg4_broadcom_swizzle) {
+ swizzle_tg4_broadcom(b, tex);
+ progress = true;
+ }
+
if (((1 << tex->texture_index) & options->swizzle_result) &&
!nir_tex_instr_is_query(tex) &&
!(tex->is_shadow && tex->is_new_style_shadow)) {