nir: Recognize empty shaders in nir_tgsi_scan_shader().
authorJose Fonseca <jfonseca@vmware.com>
Mon, 5 Dec 2022 10:28:15 +0000 (10:28 +0000)
committerMarge Bot <emma+marge@anholt.net>
Tue, 6 Dec 2022 11:44:11 +0000 (11:44 +0000)
When a null PS is bound, the
pipe_query_data_pipeline_statistics::ps_invocations counter should not
be incremented.

However llvmpipe can't cope with a null PS bound, requiring the state
tracker to bind an empty pixel shader instead.  llvmpipe infers empty
TGSI pixel shaders by looking tgsi_shader_info::num_instructions, as an
empty shader should have a single END instruction, but this logic wasn't
working for NIR shaders.

I mulled over the possibility of making llvmpipe handle null pixel
shaders.  Spreading null checks everywhere would be invasive and error
prone, but it would be quite simple if llvmpipe simply created a dummy
PS internally, to be used as a replacement whenever a null PS was bound.
That said, I'm not sure if other gallium drivers can cope with a null PS
neither, and if nought, might as well keep using an empty PS in lavapipe
state tracker.  An any rate, this change makes sense on its own.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/20155>

src/gallium/auxiliary/nir/nir_to_tgsi_info.c

index 0f043aa..1f7dcb9 100644 (file)
@@ -172,6 +172,9 @@ static void scan_instruction(const struct nir_shader *nir,
                              struct tgsi_shader_info *info,
                              const nir_instr *instr)
 {
+   info->num_tokens = 2; /* indicate that the shader is non-empty */
+   info->num_instructions = 2;
+
    if (instr->type == nir_instr_type_alu) {
       const nir_alu_instr *alu = nir_instr_as_alu(instr);
 
@@ -422,8 +425,8 @@ void nir_tgsi_scan_shader(const struct nir_shader *nir,
    unsigned i;
 
    info->processor = pipe_shader_type_from_mesa(nir->info.stage);
-   info->num_tokens = 2; /* indicate that the shader is non-empty */
-   info->num_instructions = 2;
+   info->num_tokens = 1; /* Presume empty */
+   info->num_instructions = 1;
 
    info->properties[TGSI_PROPERTY_NEXT_SHADER] =
       pipe_shader_type_from_mesa(nir->info.next_stage);