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 <jason@jlekstrand.net>
This commit is contained in:
Eric Anholt
2018-12-26 22:45:04 -08:00
parent 3fcec4a550
commit 6051c11d17
3 changed files with 28 additions and 0 deletions

View File

@@ -611,6 +611,8 @@ v3d_lower_nir(struct v3d_compile *c)
{ {
struct nir_lower_tex_options tex_options = { struct nir_lower_tex_options tex_options = {
.lower_txd = true, .lower_txd = true,
.lower_tg4_broadcom_swizzle = true,
.lower_rect = false, /* XXX: Use this on V3D 3.x */ .lower_rect = false, /* XXX: Use this on V3D 3.x */
.lower_txp = ~0, .lower_txp = ~0,
/* Apply swizzles to all samplers. */ /* Apply swizzles to all samplers. */

View File

@@ -3085,6 +3085,12 @@ typedef struct nir_lower_tex_options {
*/ */
bool lower_txd_offset_clamp; 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]; enum nir_lower_tex_packing lower_tex_packing[32];
} nir_lower_tex_options; } nir_lower_tex_options;

View File

@@ -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); 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 static void
swizzle_result(nir_builder *b, nir_tex_instr *tex, const uint8_t swizzle[4]) 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; 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) && if (((1 << tex->texture_index) & options->swizzle_result) &&
!nir_tex_instr_is_query(tex) && !nir_tex_instr_is_query(tex) &&
!(tex->is_shadow && tex->is_new_style_shadow)) { !(tex->is_shadow && tex->is_new_style_shadow)) {