From 1c4c7d95f7105c3a552a271fccb9ece69884b091 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Tue, 4 Aug 2020 08:37:07 +0200 Subject: [PATCH] broadcom/compiler: track if the fragment shader forces per-sample MSAA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For example, regarding gl_SampleID, the GLSL spec states: "Any static use of this variable in a fragment shader causes the entire shader to be evaluated per-sample." So we need to track if the fragment shader does anything that implicitly enables per-sample shading in the compiler for the driver to auto-enable sample rate shading if needed. v2: - Instead of tracking reads of gl_SampleID, check SYSTEM_BIT_SAMPLE_ID and SYSTEM_BIT_SAMPLE_POS as well as the sample layout qualifier like other drivers are doing to activate this behavior (Eric). Reviewed-by: Alejandro PiƱeiro (v1) Reviewed-by: Eric Anholt Part-of: --- src/broadcom/compiler/nir_to_vir.c | 5 +++++ src/broadcom/compiler/v3d_compiler.h | 6 ++++++ src/broadcom/compiler/vir.c | 1 + 3 files changed, 12 insertions(+) diff --git a/src/broadcom/compiler/nir_to_vir.c b/src/broadcom/compiler/nir_to_vir.c index c03afcb2a69..a89dac44c90 100644 --- a/src/broadcom/compiler/nir_to_vir.c +++ b/src/broadcom/compiler/nir_to_vir.c @@ -2827,6 +2827,11 @@ nir_to_vir(struct v3d_compile *c) c->line_x = emit_fragment_varying(c, NULL, 0, 0); c->uses_implicit_point_line_varyings = true; } + + c->force_per_sample_msaa = + c->s->info.fs.uses_sample_qualifier || + (c->s->info.system_values_read & (SYSTEM_BIT_SAMPLE_ID | + SYSTEM_BIT_SAMPLE_POS)); break; case MESA_SHADER_COMPUTE: /* Set up the TSO for barriers, assuming we do some. */ diff --git a/src/broadcom/compiler/v3d_compiler.h b/src/broadcom/compiler/v3d_compiler.h index 5f0e83ca4d9..2aef79213aa 100644 --- a/src/broadcom/compiler/v3d_compiler.h +++ b/src/broadcom/compiler/v3d_compiler.h @@ -571,6 +571,11 @@ struct v3d_compile { bool writes_z; bool uses_implicit_point_line_varyings; + /* If the fragment shader does anything that requires to force + * per-sample MSAA, such as reading gl_SampleID. + */ + bool force_per_sample_msaa; + /* Whether we are using the fallback scheduler. This will be set after * register allocation has failed once. */ @@ -798,6 +803,7 @@ struct v3d_fs_prog_data { bool uses_center_w; bool uses_implicit_point_line_varyings; bool lock_scoreboard_on_first_thrsw; + bool force_per_sample_msaa; }; struct v3d_compute_prog_data { diff --git a/src/broadcom/compiler/vir.c b/src/broadcom/compiler/vir.c index 39cae231ba7..8f07ad4a822 100644 --- a/src/broadcom/compiler/vir.c +++ b/src/broadcom/compiler/vir.c @@ -760,6 +760,7 @@ v3d_fs_set_prog_data(struct v3d_compile *c, c->uses_implicit_point_line_varyings; prog_data->lock_scoreboard_on_first_thrsw = c->lock_scoreboard_on_first_thrsw; + prog_data->force_per_sample_msaa = c->force_per_sample_msaa; } static void