i965: Move load_interpolated_input/barycentric_* intrinsics to the top.
[mesa.git] / src / mesa / main / atifragshader.c
index 9fc35520a38f9d6d78dafd1c3fd15a3d26e98431..83a449a1b132e73036e22968b4c4974b799787ea 100644 (file)
@@ -30,6 +30,7 @@
 #include "main/mtypes.h"
 #include "main/dispatch.h"
 #include "main/atifragshader.h"
+#include "program/program.h"
 
 #define MESA_DEBUG_ATI_FS 0
 
@@ -63,6 +64,7 @@ _mesa_delete_ati_fragment_shader(struct gl_context *ctx, struct ati_fragment_sha
       free(s->Instructions[i]);
       free(s->SetupInst[i]);
    }
+   _mesa_reference_program(ctx, &s->Program, NULL);
    free(s);
 }
 
@@ -132,21 +134,21 @@ static void debug_op(GLint optype, GLuint arg_count, GLenum op, GLuint dst,
 
   op_name = atifs_ops[(arg_count-1)+(optype?3:0)];
   
-  fprintf(stderr, "%s(%s, %s", op_name, _mesa_lookup_enum_by_nr(op),
-             _mesa_lookup_enum_by_nr(dst));
+  fprintf(stderr, "%s(%s, %s", op_name, _mesa_enum_to_string(op),
+             _mesa_enum_to_string(dst));
   if (!optype)
     fprintf(stderr, ", %d", dstMask);
   
   fprintf(stderr, ", %s", create_dst_mod_str(dstMod));
   
-  fprintf(stderr, ", %s, %s, %d", _mesa_lookup_enum_by_nr(arg1),
-             _mesa_lookup_enum_by_nr(arg1Rep), arg1Mod);
+  fprintf(stderr, ", %s, %s, %d", _mesa_enum_to_string(arg1),
+             _mesa_enum_to_string(arg1Rep), arg1Mod);
   if (arg_count>1)
-    fprintf(stderr, ", %s, %s, %d", _mesa_lookup_enum_by_nr(arg2),
-             _mesa_lookup_enum_by_nr(arg2Rep), arg2Mod);
+    fprintf(stderr, ", %s, %s, %d", _mesa_enum_to_string(arg2),
+             _mesa_enum_to_string(arg2Rep), arg2Mod);
   if (arg_count>2)
-    fprintf(stderr, ", %s, %s, %d", _mesa_lookup_enum_by_nr(arg3),
-             _mesa_lookup_enum_by_nr(arg3Rep), arg3Mod);
+    fprintf(stderr, ", %s, %s, %d", _mesa_enum_to_string(arg3),
+             _mesa_enum_to_string(arg3Rep), arg3Mod);
 
   fprintf(stderr,")\n");
 
@@ -199,11 +201,15 @@ _mesa_GenFragmentShadersATI(GLuint range)
       return 0;
    }
 
+   _mesa_HashLockMutex(ctx->Shared->ATIShaders);
+
    first = _mesa_HashFindFreeKeyBlock(ctx->Shared->ATIShaders, range);
    for (i = 0; i < range; i++) {
-      _mesa_HashInsert(ctx->Shared->ATIShaders, first + i, &DummyShader);
+      _mesa_HashInsertLocked(ctx->Shared->ATIShaders, first + i, &DummyShader);
    }
 
+   _mesa_HashUnlockMutex(ctx->Shared->ATIShaders);
+
    return first;
 }
 
@@ -293,7 +299,7 @@ _mesa_DeleteFragmentShaderATI(GLuint id)
         prog->RefCount--;
         if (prog->RefCount <= 0) {
            assert(prog != &DummyShader);
-           free(prog);
+            _mesa_delete_ati_fragment_shader(ctx, prog);
         }
       }
    }
@@ -321,6 +327,8 @@ _mesa_BeginFragmentShaderATI(void)
          free(ctx->ATIFragmentShader.Current->SetupInst[i]);
    }
 
+   _mesa_reference_program(ctx, &ctx->ATIFragmentShader.Current->Program, NULL);
+
    /* malloc the instructions here - not sure if the best place but its
       a start */
    for (i = 0; i < MAX_NUM_PASSES_ATI; i++) {
@@ -345,6 +353,9 @@ _mesa_BeginFragmentShaderATI(void)
    ctx->ATIFragmentShader.Current->isValid = GL_FALSE;
    ctx->ATIFragmentShader.Current->swizzlerq = 0;
    ctx->ATIFragmentShader.Compiling = 1;
+#if MESA_DEBUG_ATI_FS
+   _mesa_debug(ctx, "%s %u\n", __func__, ctx->ATIFragmentShader.Current->Id);
+#endif
 }
 
 void GLAPIENTRY
@@ -383,7 +394,7 @@ _mesa_EndFragmentShaderATI(void)
    for (j = 0; j < MAX_NUM_PASSES_ATI; j++) {
       for (i = 0; i < MAX_NUM_FRAGMENT_REGISTERS_ATI; i++) {
         GLuint op = curProg->SetupInst[j][i].Opcode;
-        const char *op_enum = op > 5 ? _mesa_lookup_enum_by_nr(op) : "0";
+        const char *op_enum = op > 5 ? _mesa_enum_to_string(op) : "0";
         GLuint src = curProg->SetupInst[j][i].src;
         GLuint swizzle = curProg->SetupInst[j][i].swizzle;
         fprintf(stderr, "%2d %04X %s %d %04X\n", i, op, op_enum, src,
@@ -392,8 +403,8 @@ _mesa_EndFragmentShaderATI(void)
       for (i = 0; i < curProg->numArithInstr[j]; i++) {
         GLuint op0 = curProg->Instructions[j][i].Opcode[0];
         GLuint op1 = curProg->Instructions[j][i].Opcode[1];
-        const char *op0_enum = op0 > 5 ? _mesa_lookup_enum_by_nr(op0) : "0";
-        const char *op1_enum = op1 > 5 ? _mesa_lookup_enum_by_nr(op1) : "0";
+        const char *op0_enum = op0 > 5 ? _mesa_enum_to_string(op0) : "0";
+        const char *op1_enum = op1 > 5 ? _mesa_enum_to_string(op1) : "0";
         GLuint count0 = curProg->Instructions[j][i].ArgCount[0];
         GLuint count1 = curProg->Instructions[j][i].ArgCount[1];
         fprintf(stderr, "%2d %04X %s %d %04X %s %d\n", i, op0, op0_enum, count0,
@@ -402,7 +413,14 @@ _mesa_EndFragmentShaderATI(void)
    }
 #endif
 
-   if (!ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_SHADER_ATI, NULL)) {
+   if (ctx->Driver.NewATIfs) {
+      struct gl_program *prog = ctx->Driver.NewATIfs(ctx,
+                                                     ctx->ATIFragmentShader.Current);
+      _mesa_reference_program(ctx, &ctx->ATIFragmentShader.Current->Program, prog);
+   }
+
+   if (!ctx->Driver.ProgramStringNotify(ctx, GL_FRAGMENT_SHADER_ATI,
+                                        curProg->Program)) {
       ctx->ATIFragmentShader.Current->isValid = GL_FALSE;
       /* XXX is this the right error? */
       _mesa_error(ctx, GL_INVALID_OPERATION,
@@ -477,8 +495,8 @@ _mesa_PassTexCoordATI(GLuint dst, GLuint coord, GLenum swizzle)
 
 #if MESA_DEBUG_ATI_FS
    _mesa_debug(ctx, "%s(%s, %s, %s)\n", __func__,
-              _mesa_lookup_enum_by_nr(dst), _mesa_lookup_enum_by_nr(coord),
-              _mesa_lookup_enum_by_nr(swizzle));
+              _mesa_enum_to_string(dst), _mesa_enum_to_string(coord),
+              _mesa_enum_to_string(swizzle));
 #endif
 }
 
@@ -550,8 +568,8 @@ _mesa_SampleMapATI(GLuint dst, GLuint interp, GLenum swizzle)
 
 #if MESA_DEBUG_ATI_FS
    _mesa_debug(ctx, "%s(%s, %s, %s)\n", __func__,
-              _mesa_lookup_enum_by_nr(dst), _mesa_lookup_enum_by_nr(interp),
-              _mesa_lookup_enum_by_nr(swizzle));
+              _mesa_enum_to_string(dst), _mesa_enum_to_string(interp),
+              _mesa_enum_to_string(swizzle));
 #endif
 }