mesa: Move src/mesa/glapi/dispatch.h to mesa.
[mesa.git] / src / mesa / shader / prog_instruction.c
index f5c0a498fb05c2e15d291ae58f2e3aa98b3ed93d..81099cb99c5d939c6b9cd9faf2c5eb01d13ac55f 100644 (file)
@@ -1,8 +1,9 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.3
+ * Version:  7.3
  *
- * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2009  VMware, Inc.  All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -39,7 +40,7 @@ _mesa_init_instructions(struct prog_instruction *inst, GLuint count)
 {
    GLuint i;
 
-   _mesa_bzero(inst, count * sizeof(struct prog_instruction));
+   memset(inst, 0, count * sizeof(struct prog_instruction));
 
    for (i = 0; i < count; i++) {
       inst[i].SrcReg[0].File = PROGRAM_UNDEFINED;
@@ -69,7 +70,7 @@ struct prog_instruction *
 _mesa_alloc_instructions(GLuint numInst)
 {
    return (struct prog_instruction *)
-      _mesa_calloc(numInst * sizeof(struct prog_instruction));
+      calloc(1, numInst * sizeof(struct prog_instruction));
 }
 
 
@@ -109,7 +110,7 @@ _mesa_copy_instructions(struct prog_instruction *dest,
                         const struct prog_instruction *src, GLuint n)
 {
    GLuint i;
-   _mesa_memcpy(dest, src, n * sizeof(struct prog_instruction));
+   memcpy(dest, src, n * sizeof(struct prog_instruction));
    for (i = 0; i < n; i++) {
       if (src[i].Comment)
          dest[i].Comment = _mesa_strdup(src[i].Comment);
@@ -127,11 +128,11 @@ _mesa_free_instructions(struct prog_instruction *inst, GLuint count)
    GLuint i;
    for (i = 0; i < count; i++) {
       if (inst[i].Data)
-         _mesa_free(inst[i].Data);
+         free(inst[i].Data);
       if (inst[i].Comment)
-         _mesa_free((char *) inst[i].Comment);
+         free((char *) inst[i].Comment);
    }
-   _mesa_free(inst);
+   free(inst);
 }
 
 
@@ -157,7 +158,7 @@ static const struct instruction_info InstInfo[MAX_OPCODE] = {
    { OPCODE_AND,    "AND",     2, 1 },
    { OPCODE_ARA,    "ARA",     1, 1 },
    { OPCODE_ARL,    "ARL",     1, 1 },
-   { OPCODE_ARL_NV, "ARL",     1, 1 },
+   { OPCODE_ARL_NV, "ARL_NV",  1, 1 },
    { OPCODE_ARR,    "ARL",     1, 1 },
    { OPCODE_BGNLOOP,"BGNLOOP", 0, 0 },
    { OPCODE_BGNSUB, "BGNSUB",  0, 0 },
@@ -186,7 +187,7 @@ static const struct instruction_info InstInfo[MAX_OPCODE] = {
    { OPCODE_FRC,    "FRC",     1, 1 },
    { OPCODE_IF,     "IF",      1, 0 },
    { OPCODE_KIL,    "KIL",     1, 0 },
-   { OPCODE_KIL_NV, "KIL",     0, 0 },
+   { OPCODE_KIL_NV, "KIL_NV",  0, 0 },
    { OPCODE_LG2,    "LG2",     1, 1 },
    { OPCODE_LIT,    "LIT",     1, 1 },
    { OPCODE_LOG,    "LOG",     1, 1 },
@@ -235,7 +236,7 @@ static const struct instruction_info InstInfo[MAX_OPCODE] = {
    { OPCODE_TXD,    "TXD",     3, 1 },
    { OPCODE_TXL,    "TXL",     1, 1 },
    { OPCODE_TXP,    "TXP",     1, 1 },
-   { OPCODE_TXP_NV, "TXP",     1, 1 },
+   { OPCODE_TXP_NV, "TXP_NV",  1, 1 },
    { OPCODE_TRUNC,  "TRUNC",   1, 1 },
    { OPCODE_UP2H,   "UP2H",    1, 1 },
    { OPCODE_UP2US,  "UP2US",   1, 1 },
@@ -253,6 +254,7 @@ static const struct instruction_info InstInfo[MAX_OPCODE] = {
 GLuint
 _mesa_num_inst_src_regs(gl_inst_opcode opcode)
 {
+   ASSERT(opcode < MAX_OPCODE);
    ASSERT(opcode == InstInfo[opcode].Opcode);
    ASSERT(OPCODE_XPD == InstInfo[OPCODE_XPD].Opcode);
    return InstInfo[opcode].NumSrcRegs;
@@ -265,6 +267,7 @@ _mesa_num_inst_src_regs(gl_inst_opcode opcode)
 GLuint
 _mesa_num_inst_dst_regs(gl_inst_opcode opcode)
 {
+   ASSERT(opcode < MAX_OPCODE);
    ASSERT(opcode == InstInfo[opcode].Opcode);
    ASSERT(OPCODE_XPD == InstInfo[OPCODE_XPD].Opcode);
    return InstInfo[opcode].NumDstRegs;
@@ -282,13 +285,68 @@ _mesa_is_tex_instruction(gl_inst_opcode opcode)
 }
 
 
+/**
+ * Check if there's a potential src/dst register data dependency when
+ * using SOA execution.
+ * Example:
+ *   MOV T, T.yxwz;
+ * This would expand into:
+ *   MOV t0, t1;
+ *   MOV t1, t0;
+ *   MOV t2, t3;
+ *   MOV t3, t2;
+ * The second instruction will have the wrong value for t0 if executed as-is.
+ */
+GLboolean
+_mesa_check_soa_dependencies(const struct prog_instruction *inst)
+{
+   GLuint i, chan;
+
+   if (inst->DstReg.WriteMask == WRITEMASK_X ||
+       inst->DstReg.WriteMask == WRITEMASK_Y ||
+       inst->DstReg.WriteMask == WRITEMASK_Z ||
+       inst->DstReg.WriteMask == WRITEMASK_W ||
+       inst->DstReg.WriteMask == 0x0) {
+      /* no chance of data dependency */
+      return GL_FALSE;
+   }
+
+   /* loop over src regs */
+   for (i = 0; i < 3; i++) {
+      if (inst->SrcReg[i].File == inst->DstReg.File &&
+          inst->SrcReg[i].Index == inst->DstReg.Index) {
+         /* loop over dest channels */
+         GLuint channelsWritten = 0x0;
+         for (chan = 0; chan < 4; chan++) {
+            if (inst->DstReg.WriteMask & (1 << chan)) {
+               /* check if we're reading a channel that's been written */
+               GLuint swizzle = GET_SWZ(inst->SrcReg[i].Swizzle, chan);
+               if (swizzle <= SWIZZLE_W &&
+                   (channelsWritten & (1 << swizzle))) {
+                  return GL_TRUE;
+               }
+
+               channelsWritten |= (1 << chan);
+            }
+         }
+      }
+   }
+   return GL_FALSE;
+}
+
+
 /**
  * Return string name for given program opcode.
  */
 const char *
 _mesa_opcode_string(gl_inst_opcode opcode)
 {
-   ASSERT(opcode < MAX_OPCODE);
-   return InstInfo[opcode].Name;
+   if (opcode < MAX_OPCODE)
+      return InstInfo[opcode].Name;
+   else {
+      static char s[20];
+      _mesa_snprintf(s, sizeof(s), "OP%u", opcode);
+      return s;
+   }
 }