freedreno/ir3: add generic get_barycentric()

This will be useful to support the missing barycentric sysvals.

Signed-off-by: Jonathan Marek <jonathan@marek.ca>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5582>
This commit is contained in:
Jonathan Marek 2020-06-21 16:31:10 -04:00 committed by Marge Bot
parent 75fef41f16
commit 33457fc705
3 changed files with 43 additions and 28 deletions

View file

@ -98,7 +98,7 @@ create_frag_input(struct ir3_context *ctx, bool use_ldlv, unsigned n)
instr->cat6.type = TYPE_U32;
instr->cat6.iim_val = 1;
} else {
instr = ir3_BARY_F(block, inloc, 0, ctx->ij_pixel, 0);
instr = ir3_BARY_F(block, inloc, 0, ctx->ij[IJ_PERSP_PIXEL], 0);
instr->regs[2]->wrmask = 0x3;
}
@ -1346,44 +1346,47 @@ create_sysval_input(struct ir3_context *ctx, gl_system_value slot,
}
static struct ir3_instruction *
get_barycentric_centroid(struct ir3_context *ctx)
get_barycentric(struct ir3_context *ctx, enum ir3_bary bary)
{
if (!ctx->ij_centroid) {
static const gl_system_value sysval_base = SYSTEM_VALUE_BARYCENTRIC_PERSP_PIXEL;
STATIC_ASSERT(sysval_base + IJ_PERSP_PIXEL == SYSTEM_VALUE_BARYCENTRIC_PERSP_PIXEL);
STATIC_ASSERT(sysval_base + IJ_PERSP_SAMPLE == SYSTEM_VALUE_BARYCENTRIC_PERSP_SAMPLE);
STATIC_ASSERT(sysval_base + IJ_PERSP_CENTROID == SYSTEM_VALUE_BARYCENTRIC_PERSP_CENTROID);
STATIC_ASSERT(sysval_base + IJ_PERSP_SIZE == SYSTEM_VALUE_BARYCENTRIC_PERSP_SIZE);
STATIC_ASSERT(sysval_base + IJ_LINEAR_PIXEL == SYSTEM_VALUE_BARYCENTRIC_LINEAR_PIXEL);
STATIC_ASSERT(sysval_base + IJ_LINEAR_CENTROID == SYSTEM_VALUE_BARYCENTRIC_LINEAR_CENTROID);
STATIC_ASSERT(sysval_base + IJ_LINEAR_SAMPLE == SYSTEM_VALUE_BARYCENTRIC_LINEAR_SAMPLE);
if (!ctx->ij[bary]) {
struct ir3_instruction *xy[2];
struct ir3_instruction *ij;
ij = create_sysval_input(ctx, SYSTEM_VALUE_BARYCENTRIC_PERSP_CENTROID, 0x3);
ij = create_sysval_input(ctx, sysval_base + bary, 0x3);
ir3_split_dest(ctx->block, xy, ij, 0, 2);
ctx->ij_centroid = ir3_create_collect(ctx, xy, 2);
ctx->ij[bary] = ir3_create_collect(ctx, xy, 2);
}
return ctx->ij_centroid;
return ctx->ij[bary];
}
static struct ir3_instruction *
get_barycentric_centroid(struct ir3_context *ctx)
{
return get_barycentric(ctx, IJ_PERSP_CENTROID);
}
static struct ir3_instruction *
get_barycentric_sample(struct ir3_context *ctx)
{
if (!ctx->ij_sample) {
struct ir3_instruction *xy[2];
struct ir3_instruction *ij;
ij = create_sysval_input(ctx, SYSTEM_VALUE_BARYCENTRIC_PERSP_SAMPLE, 0x3);
ir3_split_dest(ctx->block, xy, ij, 0, 2);
ctx->ij_sample = ir3_create_collect(ctx, xy, 2);
}
return ctx->ij_sample;
return get_barycentric(ctx, IJ_PERSP_SAMPLE);
}
static struct ir3_instruction *
get_barycentric_pixel(struct ir3_context *ctx)
{
/* TODO when tgsi_to_nir supports "new-style" FS inputs switch
* this to create ij_pixel only on demand:
*/
return ctx->ij_pixel;
return get_barycentric(ctx, IJ_PERSP_PIXEL);
}
static struct ir3_instruction *
@ -1594,11 +1597,11 @@ emit_intrinsic(struct ir3_context *ctx, nir_intrinsic_instr *intr)
break;
}
case nir_intrinsic_load_size_ir3:
if (!ctx->ij_size) {
ctx->ij_size =
if (!ctx->ij[IJ_PERSP_SIZE]) {
ctx->ij[IJ_PERSP_SIZE] =
create_sysval_input(ctx, SYSTEM_VALUE_BARYCENTRIC_PERSP_SIZE, 0x1);
}
dst[0] = ctx->ij_size;
dst[0] = ctx->ij[IJ_PERSP_SIZE];
break;
case nir_intrinsic_load_barycentric_centroid:
ir3_split_dest(b, dst, get_barycentric_centroid(ctx), 0, 2);
@ -3270,7 +3273,7 @@ emit_instructions(struct ir3_context *ctx)
* tgsi_to_nir)
*/
if (ctx->so->type == MESA_SHADER_FRAGMENT) {
ctx->ij_pixel = create_input(ctx, 0x3);
ctx->ij[IJ_PERSP_PIXEL] = create_input(ctx, 0x3);
}
/* Setup inputs: */
@ -3281,9 +3284,9 @@ emit_instructions(struct ir3_context *ctx)
/* Defer add_sysval_input() stuff until after setup_inputs(),
* because sysvals need to be appended after varyings:
*/
if (ctx->ij_pixel) {
if (ctx->ij[IJ_PERSP_PIXEL]) {
add_sysval_input_compmask(ctx, SYSTEM_VALUE_BARYCENTRIC_PERSP_PIXEL,
0x3, ctx->ij_pixel);
0x3, ctx->ij[IJ_PERSP_PIXEL]);
}

View file

@ -77,7 +77,7 @@ struct ir3_context {
* inputs. So we do all the input tracking normally and fix
* things up after compile_instructions()
*/
struct ir3_instruction *ij_pixel, *ij_sample, *ij_centroid, *ij_size;
struct ir3_instruction *ij[IJ_COUNT];
/* for fragment shaders, for gl_FrontFacing and gl_FragCoord: */
struct ir3_instruction *frag_face, *frag_coord;

View file

@ -74,6 +74,18 @@ enum ir3_driver_param {
#define IR3_MAX_SO_OUTPUTS 64
#define IR3_MAX_UBO_PUSH_RANGES 32
/* mirrors SYSTEM_VALUE_BARYCENTRIC_ but starting from 0 */
enum ir3_bary {
IJ_PERSP_PIXEL,
IJ_PERSP_SAMPLE,
IJ_PERSP_CENTROID,
IJ_PERSP_SIZE,
IJ_LINEAR_PIXEL,
IJ_LINEAR_CENTROID,
IJ_LINEAR_SAMPLE,
IJ_COUNT,
};
/**
* Description of a lowered UBO.
*/