anv: move force shading rate writes checks

With variable fragment shading rate, the last pre-rasterization stage
is responsible to write the shading rate value.

The current checks is as follow :

   If the fragment shader can be dispatched at variable shading rate,
   look for the last pre-raster stage to force the write.

We change this to :

   If we're the last pre-raster stage, force the write.

That way this works for pre-rasterization shaders compiled without a
fragment shader.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15637>
This commit is contained in:
Lionel Landwerlin 2022-03-15 15:50:31 +02:00 committed by Marge Bot
parent b2d3d818d5
commit e82b05dc64

View file

@ -438,8 +438,7 @@ populate_gs_prog_key(const struct anv_device *device,
} }
static bool static bool
pipeline_has_coarse_pixel(const struct anv_graphics_base_pipeline *pipeline, pipeline_has_coarse_pixel(const BITSET_WORD *dynamic,
const BITSET_WORD *dynamic,
const struct vk_multisample_state *ms, const struct vk_multisample_state *ms,
const struct vk_fragment_shading_rate_state *fsr) const struct vk_fragment_shading_rate_state *fsr)
{ {
@ -569,7 +568,7 @@ populate_wm_prog_key(const struct anv_graphics_base_pipeline *pipeline,
key->coarse_pixel = key->coarse_pixel =
!key->persample_interp && !key->persample_interp &&
device->vk.enabled_extensions.KHR_fragment_shading_rate && device->vk.enabled_extensions.KHR_fragment_shading_rate &&
pipeline_has_coarse_pixel(pipeline, dynamic, ms, fsr); pipeline_has_coarse_pixel(dynamic, ms, fsr);
} }
static void static void
@ -1826,19 +1825,26 @@ anv_graphics_pipeline_compile(struct anv_graphics_base_pipeline *pipeline,
prev_stage = stage; prev_stage = stage;
} }
/* In the case the platform can write the primitive variable shading rate, /* In the case the platform can write the primitive variable shading rate
* and KHR_fragment_shading_rate is enabled :
* - there can be a fragment shader but we don't have it yet
* - the fragment shader needs fragment shading rate
*
* figure out the last geometry stage that should write the primitive * figure out the last geometry stage that should write the primitive
* shading rate, and ensure it is marked as used there. The backend will * shading rate, and ensure it is marked as used there. The backend will
* write a default value if the shader doesn't actually write it. * write a default value if the shader doesn't actually write it.
* *
* We iterate backwards in the stage and stop on the first shader that can * We iterate backwards in the stage and stop on the first shader that can
* set the value. * set the value.
*
* Don't apply this to MESH stages, as this is a per primitive thing.
*/ */
if (devinfo->has_coarse_pixel_primitive_and_cb && if (devinfo->has_coarse_pixel_primitive_and_cb &&
stages[MESA_SHADER_FRAGMENT].info && device->vk.enabled_extensions.KHR_fragment_shading_rate &&
stages[MESA_SHADER_FRAGMENT].key.wm.coarse_pixel && pipeline_has_coarse_pixel(state->dynamic, state->ms, state->fsr) &&
!stages[MESA_SHADER_FRAGMENT].nir->info.fs.uses_sample_shading && (!stages[MESA_SHADER_FRAGMENT].info ||
stages[MESA_SHADER_MESH].info == NULL) { stages[MESA_SHADER_FRAGMENT].key.wm.coarse_pixel) &&
stages[MESA_SHADER_MESH].nir == NULL) {
struct anv_pipeline_stage *last_psr = NULL; struct anv_pipeline_stage *last_psr = NULL;
for (unsigned i = 0; i < ARRAY_SIZE(graphics_shader_order); i++) { for (unsigned i = 0; i < ARRAY_SIZE(graphics_shader_order); i++) {
@ -1853,8 +1859,11 @@ anv_graphics_pipeline_compile(struct anv_graphics_base_pipeline *pipeline,
break; break;
} }
assert(last_psr); /* Only set primitive shading rate if there is a pre-rasterization
last_psr->nir->info.outputs_written |= VARYING_BIT_PRIMITIVE_SHADING_RATE; * shader in this pipeline/pipeline-library.
*/
if (last_psr)
last_psr->nir->info.outputs_written |= VARYING_BIT_PRIMITIVE_SHADING_RATE;
} }
prev_stage = NULL; prev_stage = NULL;