From 6051c11d17645b973f975b25cfdebc027dc36be7 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 26 Dec 2018 22:45:04 -0800 Subject: [PATCH] nir: Add nir_lower_tex support for Broadcom's swizzled TG4 results. V3D returns the texels in a different order in the resulting vec4 from what GLSL wants, so we need to put in a swizzle. Fixes dEQP-GLES31.functional.texture.gather.basic.2d.rgba8.base_level.level_1 Reviewed-by: Jason Ekstrand --- src/broadcom/compiler/vir.c | 2 ++ src/compiler/nir/nir.h | 6 ++++++ src/compiler/nir/nir_lower_tex.c | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+) 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 @@ -738,6 +738,21 @@ get_zero_or_one(nir_builder *b, nir_alu_type type, uint8_t swizzle_val) return nir_build_imm(b, 4, 32, v); } +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]) { @@ -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)) { -- 2.30.2