tgsi: fix tgsi transform's epilog callback
authorBrian Paul <brianp@vmware.com>
Fri, 19 Sep 2014 19:11:58 +0000 (13:11 -0600)
committerBrian Paul <brianp@vmware.com>
Mon, 22 Sep 2014 22:56:23 +0000 (16:56 -0600)
We want to call the caller's epilog callback when we find the TGSI
END instruction, not after it.

Reviewed-by: Charmaine Lee <charmainel@vmware.com>
src/gallium/auxiliary/tgsi/tgsi_transform.c

index 93e5b98c915c3d0f036b9fbd5b12b46ab15e9595..9d316ccb9e39d5ad89f33a96c1ebe87789a8f81c 100644 (file)
@@ -171,10 +171,22 @@ tgsi_transform_shader(const struct tgsi_token *tokens_in,
                ctx->prolog(ctx);
             }
 
-            if (ctx->transform_instruction)
-               ctx->transform_instruction(ctx, fullinst);
-            else
+            /* XXX Note: we may also want to look for a main/top-level
+             * TGSI_OPCODE_RET instruction in the future.
+             */
+            if (fullinst->Instruction.Opcode == TGSI_OPCODE_END
+                && ctx->epilog) {
+               /* Emit caller's epilog */
+               ctx->epilog(ctx);
+               /* Emit END */
                ctx->emit_instruction(ctx, fullinst);
+            }
+            else {
+               if (ctx->transform_instruction)
+                  ctx->transform_instruction(ctx, fullinst);
+               else
+                  ctx->emit_instruction(ctx, fullinst);
+            }
 
             first_instruction = FALSE;
          }
@@ -220,10 +232,6 @@ tgsi_transform_shader(const struct tgsi_token *tokens_in,
       }
    }
 
-   if (ctx->epilog) {
-      ctx->epilog(ctx);
-   }
-
    tgsi_parse_free (&parse);
 
    return ctx->ti;