From: Jose Fonseca Date: Mon, 5 Dec 2022 10:28:15 +0000 (+0000) Subject: nir: Recognize empty shaders in nir_tgsi_scan_shader(). X-Git-Tag: upstream/23.3.3~15938 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=36a7d6788c92f69e7463fb7e3cd4f1154dea767d;p=platform%2Fupstream%2Fmesa.git nir: Recognize empty shaders in nir_tgsi_scan_shader(). 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 Reviewed-by: Roland Scheidegger Part-of: --- diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi_info.c b/src/gallium/auxiliary/nir/nir_to_tgsi_info.c index 0f043aa..1f7dcb9 100644 --- a/src/gallium/auxiliary/nir/nir_to_tgsi_info.c +++ b/src/gallium/auxiliary/nir/nir_to_tgsi_info.c @@ -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);