pan/midgard: Use shader stage in mir_op_computes_derivative
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 18 Nov 2019 13:02:58 +0000 (08:02 -0500)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 18 Nov 2019 13:48:54 +0000 (08:48 -0500)
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 <alyssa.rosenzweig@collabora.com>
src/panfrost/midgard/compiler.h
src/panfrost/midgard/midgard_derivatives.c
src/panfrost/midgard/midgard_emit.c

index 7e3f998ab4f88a292a13e6f67d7d1b3031283dec..b308552e7c9c227630b2d148d4cdc7cdd538657a 100644 (file)
@@ -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 */
 
index ad12293dd339352224d364dbbdf76245279fd939..ceb3bb96166286ace63dd92a15388256a66745e7 100644 (file)
@@ -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;
index 7559a34dcfb08bd40d795dab00d5fe676c697dce..63dcb41ad4141ca94b899dbb2fcf89fbb345e5e2 100644 (file)
@@ -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