pan/va: Do not insert NOPs into empty shaders

It's unnecessary and breaks the empty shader optimizations. Noticed while
inspecting a trace from dEQP-GLES3.functional.color_clear.masked_scissored_rgb,
which does not produce any varyings other than gl_Position in its vertex shader
and hence should omit the varying shader.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16868>
This commit is contained in:
Alyssa Rosenzweig 2022-06-04 09:32:30 -04:00 committed by Marge Bot
parent e8da8fc5b7
commit e1fb182d90
2 changed files with 27 additions and 2 deletions

View file

@ -32,13 +32,13 @@
bi_builder *A = bit_builder(mem_ctx); \
bi_builder *B = bit_builder(mem_ctx); \
{ \
bi_builder *b = A; \
UNUSED bi_builder *b = A; \
A->shader->stage = MESA_SHADER_ ## shader_stage; \
test; \
} \
va_insert_flow_control_nops(A->shader); \
{ \
bi_builder *b = B; \
UNUSED bi_builder *b = B; \
B->shader->stage = MESA_SHADER_ ## shader_stage; \
expected; \
} \
@ -60,6 +60,10 @@ protected:
void *mem_ctx;
};
TEST_F(InsertFlow, PreserveEmptyShader) {
CASE(FRAGMENT, {}, {});
}
TEST_F(InsertFlow, TilebufferWait7) {
CASE(FRAGMENT, {
bi_fadd_f32_to(b, bi_register(0), bi_register(0), bi_register(0));

View file

@ -353,6 +353,19 @@ va_discard_before_block(bi_block *block)
return false;
}
/*
* Test if a program is empty, in the sense of having zero instructions. Empty
* shaders get special handling.
*/
static bool
bi_is_empty(bi_context *ctx)
{
bi_foreach_instr_global(ctx, _)
return false;
return true;
}
/*
* Given a program with no flow control modifiers, insert NOPs signaling the
* required flow control. Not much optimization happens here.
@ -360,6 +373,14 @@ va_discard_before_block(bi_block *block)
void
va_insert_flow_control_nops(bi_context *ctx)
{
/* Special case: if a program is empty, leave it empty. In particular, do not
* insert NOP.end. There is special handling in the driver for skipping empty
* shaders for shader stage. The .end is not necessary and disrupts
* optimizations.
*/
if (bi_is_empty(ctx))
return;
/* First do dataflow analysis for the scoreboard. This populates I->flow with
* a bitmap of slots to wait on.
*