From 9b96ae69bc7f07d267e880fe77a389c2b944f019 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Thu, 6 Jun 2019 10:04:27 +0200 Subject: [PATCH 1/1] v3d: don't emit point coordinates varyings if the FS doesn't read them We still need to emit them in V3D 3.x since there there is no mechanism to disable them. Reviewed-by: Eric Anholt --- src/broadcom/compiler/nir_to_vir.c | 23 ++++++++++++++++++----- src/broadcom/compiler/v3d_compiler.h | 2 ++ src/broadcom/compiler/vir.c | 2 ++ src/gallium/drivers/v3d/v3dx_draw.c | 5 +++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/broadcom/compiler/nir_to_vir.c b/src/broadcom/compiler/nir_to_vir.c index 1e98e69efbc..702e4bf15f8 100644 --- a/src/broadcom/compiler/nir_to_vir.c +++ b/src/broadcom/compiler/nir_to_vir.c @@ -1462,6 +1462,17 @@ var_needs_point_coord(struct v3d_compile *c, nir_variable *var) (1 << (var->data.location - VARYING_SLOT_VAR0))))); } +static bool +program_reads_point_coord(struct v3d_compile *c) +{ + nir_foreach_variable(var, &c->s->inputs) { + if (var_needs_point_coord(c, var)) + return true; + } + + return false; +} + static void ntq_setup_fs_inputs(struct v3d_compile *c) { @@ -2300,15 +2311,17 @@ nir_to_vir(struct v3d_compile *c) c->payload_w_centroid = vir_MOV(c, vir_reg(QFILE_REG, 1)); c->payload_z = vir_MOV(c, vir_reg(QFILE_REG, 2)); - /* XXX perf: We could set the "disable implicit point/line - * varyings" field in the shader record and not emit these, if - * they're not going to be used. + /* V3D 4.x can disable implicit point coordinate varyings if + * they are not used. */ - if (c->fs_key->is_points) { + if (c->fs_key->is_points && + (c->devinfo->ver < 40 || program_reads_point_coord(c))) { c->point_x = emit_fragment_varying(c, NULL, 0, 0); c->point_y = emit_fragment_varying(c, NULL, 0, 0); - } else if (c->fs_key->is_lines) { + c->uses_implicit_point_line_varyings = true; + } else if (c->fs_key->is_lines && c->devinfo->ver < 40) { c->line_x = emit_fragment_varying(c, NULL, 0, 0); + c->uses_implicit_point_line_varyings = true; } break; case MESA_SHADER_COMPUTE: diff --git a/src/broadcom/compiler/v3d_compiler.h b/src/broadcom/compiler/v3d_compiler.h index 2bc07de7e1f..cb466c0c59f 100644 --- a/src/broadcom/compiler/v3d_compiler.h +++ b/src/broadcom/compiler/v3d_compiler.h @@ -513,6 +513,7 @@ struct v3d_compile { bool uses_center_w; bool writes_z; + bool uses_implicit_point_line_varyings; /* State for whether we're executing on each channel currently. 0 if * yes, otherwise a block number + 1 that the channel jumped to. @@ -689,6 +690,7 @@ struct v3d_fs_prog_data { bool writes_z; bool disable_ez; bool uses_center_w; + bool uses_implicit_point_line_varyings; }; struct v3d_compute_prog_data { diff --git a/src/broadcom/compiler/vir.c b/src/broadcom/compiler/vir.c index 5d4e5dd103a..45a6cc9ed2b 100644 --- a/src/broadcom/compiler/vir.c +++ b/src/broadcom/compiler/vir.c @@ -688,6 +688,8 @@ v3d_fs_set_prog_data(struct v3d_compile *c, prog_data->writes_z = c->writes_z; prog_data->disable_ez = !c->s->info.fs.early_fragment_tests; prog_data->uses_center_w = c->uses_center_w; + prog_data->uses_implicit_point_line_varyings = + c->uses_implicit_point_line_varyings; } static void diff --git a/src/gallium/drivers/v3d/v3dx_draw.c b/src/gallium/drivers/v3d/v3dx_draw.c index 7ddd1f92a2f..629f35a8d7f 100644 --- a/src/gallium/drivers/v3d/v3dx_draw.c +++ b/src/gallium/drivers/v3d/v3dx_draw.c @@ -236,6 +236,11 @@ v3d_emit_gl_shader_state(struct v3d_context *v3d, shader.fragment_shader_uses_real_pixel_centre_w_in_addition_to_centroid_w2 = v3d->prog.fs->prog_data.fs->uses_center_w; +#if V3D_VERSION >= 40 + shader.disable_implicit_point_line_varyings = + !v3d->prog.fs->prog_data.fs->uses_implicit_point_line_varyings; +#endif + shader.number_of_varyings_in_fragment_shader = v3d->prog.fs->prog_data.fs->num_inputs; -- 2.30.2