From 36633400499d109865eefd0e226fcd78cf33e02f Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Mon, 18 Nov 2019 08:02:58 -0500 Subject: [PATCH] pan/midgard: Use shader stage in mir_op_computes_derivative A 'normal' texture op may be emitted in a vertex shader on T720 but it still doesn't take any derivatives. Signed-off-by: Alyssa Rosenzweig --- src/panfrost/midgard/compiler.h | 2 +- src/panfrost/midgard/midgard_derivatives.c | 9 ++++++++- src/panfrost/midgard/midgard_emit.c | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/panfrost/midgard/compiler.h b/src/panfrost/midgard/compiler.h index 7e3f998ab4f..b308552e7c9 100644 --- a/src/panfrost/midgard/compiler.h +++ b/src/panfrost/midgard/compiler.h @@ -621,7 +621,7 @@ midgard_emit_derivatives(compiler_context *ctx, nir_alu_instr *instr); void midgard_lower_derivatives(compiler_context *ctx, midgard_block *block); -bool mir_op_computes_derivatives(unsigned op); +bool mir_op_computes_derivatives(gl_shader_stage stage, unsigned op); /* Final emission */ diff --git a/src/panfrost/midgard/midgard_derivatives.c b/src/panfrost/midgard/midgard_derivatives.c index ad12293dd33..ceb3bb96166 100644 --- a/src/panfrost/midgard/midgard_derivatives.c +++ b/src/panfrost/midgard/midgard_derivatives.c @@ -72,12 +72,19 @@ mir_derivative_op(nir_op op) * implicitly */ bool -mir_op_computes_derivatives(unsigned op) +mir_op_computes_derivatives(gl_shader_stage stage, unsigned op) { + /* Only fragment shaders may compute derivatives, but the sense of + * "normal" changes in vertex shaders on certain GPUs */ + + if (op == TEXTURE_OP_NORMAL && stage != MESA_SHADER_FRAGMENT) + return false; + switch (op) { case TEXTURE_OP_NORMAL: case TEXTURE_OP_DFDX: case TEXTURE_OP_DFDY: + assert(stage == MESA_SHADER_FRAGMENT); return true; default: return false; diff --git a/src/panfrost/midgard/midgard_emit.c b/src/panfrost/midgard/midgard_emit.c index 7559a34dcfb..63dcb41ad41 100644 --- a/src/panfrost/midgard/midgard_emit.c +++ b/src/panfrost/midgard/midgard_emit.c @@ -430,7 +430,7 @@ emit_binary_bundle(compiler_context *ctx, ctx->texture_op_count--; - if (mir_op_computes_derivatives(ins->texture.op)) { + if (mir_op_computes_derivatives(ctx->stage, ins->texture.op)) { bool continues = ctx->texture_op_count > 0; /* Control flow complicates helper invocation -- 2.30.2