Fixes dEQP-GLES3.functional.shaders.texture_functions.textureoffset.sampler2d_fixed_fragment.
Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3169>
* emitted before the register allocation pass.
*/
-#define MIR_SRC_COUNT 3
+#define MIR_SRC_COUNT 4
#define MIR_VEC_COMPONENTS 16
typedef struct midgard_instruction {
/* Instruction arguments represented as block-local SSA
* indices, rather than registers. ~0 means unused. */
- unsigned src[3];
+ unsigned src[MIR_SRC_COUNT];
unsigned dest;
/* vec16 swizzle, unpacked, per source */
midgard_instruction ins = {
.type = TAG_ALU_4,
.mask = 0xF,
- .src = { SSA_UNUSED, src, SSA_UNUSED },
+ .src = { ~0, src, ~0, ~0 },
.swizzle = SWIZZLE_IDENTITY,
.dest = dest,
.alu = {
.type = TAG_LOAD_STORE_4,
.mask = mask,
.dest = ~0,
- .src = { ~0, ~0, ~0 },
+ .src = { ~0, ~0, ~0, ~0 },
.swizzle = SWIZZLE_IDENTITY_4,
.load_store = {
.op = is_store ? midgard_op_st_int4 : midgard_op_ld_int4,
/* SSA helper aliases to mimic the registers. */
-#define SSA_UNUSED ~0
#define SSA_FIXED_SHIFT 24
#define SSA_FIXED_REGISTER(reg) (((1 + (reg)) << SSA_FIXED_SHIFT) | 1)
#define SSA_REG_FROM_FIXED(reg) ((((reg) & ~1) >> SSA_FIXED_SHIFT) - 1)
#define COMPONENT_W 0x3
#define SWIZZLE_IDENTITY { \
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, \
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, \
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }, \
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } \
{ 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, \
{ 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, \
{ 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, \
+ { 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, \
}
static inline unsigned
.type = TAG_LOAD_STORE_4, \
.mask = 0xF, \
.dest = ~0, \
- .src = { ~0, ~0, ~0 }, \
+ .src = { ~0, ~0, ~0, ~0 }, \
.swizzle = SWIZZLE_IDENTITY_4, \
.load_store = { \
.op = midgard_op_##name, \
.compact_branch = true,
.br_compact = compact,
.dest = ~0,
- .src = { ~0, ~0, ~0 },
+ .src = { ~0, ~0, ~0, ~0 },
};
if (op == midgard_jmp_writeout_op_writeout)
.invert_conditional = invert
},
.dest = ~0,
- .src = { ~0, ~0, ~0 },
+ .src = { ~0, ~0, ~0, ~0 },
};
return ins;
quirk_flipped_r24 ? ~0 : src0,
quirk_flipped_r24 ? src0 : src1,
src2,
+ ~0
},
.dest = dest,
};
.type = TAG_TEXTURE_4,
.mask = 0xF,
.dest = nir_dest_index(ctx, &instr->dest),
- .src = { ~0, ~0, ~0 },
+ .src = { ~0, ~0, ~0, ~0 },
.swizzle = SWIZZLE_IDENTITY_4,
.texture = {
.op = midgard_texop,
break;
};
+ case nir_tex_src_offset: {
+ ins.texture.offset_register = true;
+ ins.src[3] = index;
+
+ for (unsigned c = 0; c < MIR_VEC_COMPONENTS; ++c)
+ ins.swizzle[3][c] = (c > COMPONENT_Z) ? 0 : c;
+
+ emit_explicit_constant(ctx, index, index);
+ };
+
case nir_tex_src_comparator: {
/* TODO: generalize */
unsigned comp = COMPONENT_Z;
.type = TAG_TEXTURE_4,
.mask = mask_of(nr_components),
.dest = nir_dest_index(ctx, &instr->dest.dest),
- .src = { nir_alu_src_index(ctx, &instr->src[0]), ~0, ~0 },
+ .src = { nir_alu_src_index(ctx, &instr->src[0]), ~0, ~0, ~0 },
.texture = {
.op = mir_derivative_op(instr->op),
.format = MALI_TEX_2D,
midgard_instruction not = {
.type = TAG_ALU_4,
.mask = ins->mask,
- .src = { temp, ~0, ~0 },
+ .src = { temp, ~0, ~0, ~0 },
.swizzle = SWIZZLE_IDENTITY,
.dest = ins->dest,
.has_inline_constant = true,
.type = TAG_LOAD_STORE_4,
.mask = ins->mask,
.dest = to,
- .src = { frcp_from, ~0, ~0 },
+ .src = { frcp_from, ~0, ~0, ~0 },
.swizzle = SWIZZLE_IDENTITY_4,
.load_store = {
.op = frcp_component == COMPONENT_W ?
mir_print_index(ins->src[2]);
mir_print_swizzle(ins->swizzle[2]);
+ printf(", ");
+ mir_print_index(ins->src[3]);
+ mir_print_swizzle(ins->swizzle[3]);
+
if (ins->has_constants) {
uint32_t *uc = ins->constants;
float *fc = (float *) uc;
set_class(l->class, ins->src[0], REG_CLASS_TEXR);
set_class(l->class, ins->src[1], REG_CLASS_TEXR);
set_class(l->class, ins->src[2], REG_CLASS_TEXR);
+ set_class(l->class, ins->src[3], REG_CLASS_TEXR);
}
}
return l;
}
+/* Reverses 2 bits, used to pack swizzles of offsets for some reason */
+
+static unsigned
+mir_reverse2(unsigned in)
+{
+ return (in >> 1) | ((in & 1) << 1);
+}
+
/* Once registers have been decided via register allocation
* (allocate_registers), we need to rewrite the MIR to use registers instead of
* indices */
struct phys_reg dest = index_to_reg(ctx, l, ins->dest, mir_typesize(ins));
struct phys_reg coord = index_to_reg(ctx, l, ins->src[1], mir_srcsize(ins, 1));
struct phys_reg lod = index_to_reg(ctx, l, ins->src[2], mir_srcsize(ins, 2));
+ struct phys_reg offset = index_to_reg(ctx, l, ins->src[3], mir_srcsize(ins, 2));
/* First, install the texture coordinate */
ins->texture.in_reg_full = 1;
if (ins->src[2] != ~0) {
assert(!(lod.offset & 3));
midgard_tex_register_select sel = {
- .select = lod.reg,
+ .select = lod.reg & 1,
.full = 1,
.component = lod.offset / 4
};
ins->texture.bias = packed;
}
+ /* If there is an offset register, install it */
+ if (ins->src[3] != ~0) {
+ ins->texture.offset_x =
+ (1) | /* full */
+ (offset.reg & 1) << 1 | /* select */
+ 0 << 2; /* upper */
+
+ unsigned x = offset.offset / 4;
+ unsigned y = x + 1;
+ unsigned z = x + 2;
+
+ ins->texture.offset_y =
+ mir_reverse2(y) | (mir_reverse2(x) << 2);
+
+ ins->texture.offset_z =
+ mir_reverse2(z);
+ }
+
break;
}
if (i >= 2) {
/* TODO: 16-bit conditions, ffma */
- assert(i == 2);
return midgard_reg_mode_32;
}