r600: code cleanup
authorAlex Deucher <alexdeucher@gmail.com>
Mon, 24 Aug 2009 21:41:01 +0000 (17:41 -0400)
committerAlex Deucher <alexdeucher@gmail.com>
Mon, 24 Aug 2009 21:51:00 +0000 (17:51 -0400)
src/mesa/drivers/dri/r600/r700_fragprog.c
src/mesa/drivers/dri/r600/r700_fragprog.h
src/mesa/drivers/dri/r600/r700_state.c
src/mesa/drivers/dri/r600/r700_vertprog.c
src/mesa/drivers/dri/r600/r700_vertprog.h

index 098b420dfccd8f3bd0509defa6cc47987ed78689..e4a6d4cedf860ef539300e1686a9cb0711ded61f 100644 (file)
@@ -121,13 +121,13 @@ void Map_Fragment_Program(r700_AssemblerBase         *pAsm,
                pAsm->pR700Shader->depthIsExported = 1;
        }
 
-    pAsm->pucOutMask = (unsigned char*) MALLOC(pAsm->number_of_exports);    
+    pAsm->pucOutMask = (unsigned char*) MALLOC(pAsm->number_of_exports);
     for(ui=0; ui<pAsm->number_of_exports; ui++)
     {
         pAsm->pucOutMask[ui] = 0x0;
     }
-       
-       pAsm->uFirstHelpReg = pAsm->number_used_registers;
+
+    pAsm->uFirstHelpReg = pAsm->number_used_registers;
 }
 
 GLboolean Find_Instruction_Dependencies_fp(struct r700_fragment_program *fp,
@@ -258,6 +258,19 @@ GLboolean r700TranslateFragmentShader(struct r700_fragment_program *fp,
        return GL_TRUE;
 }
 
+void r700SelectFragmentShader(GLcontext *ctx)
+{
+    context_t *context = R700_CONTEXT(ctx);
+    struct r700_fragment_program *fp = (struct r700_fragment_program *)
+           (ctx->FragmentProgram._Current);
+    if (context->radeon.radeonScreen->chip_family < CHIP_FAMILY_RV770)
+    {
+           fp->r700AsmCode.bR6xx = 1;
+    }
+
+    r700TranslateFragmentShader(fp, &(fp->mesa_program));
+}
+
 void * r700GetActiveFpShaderBo(GLcontext * ctx)
 {
     struct r700_fragment_program *fp = (struct r700_fragment_program *)
@@ -283,7 +296,7 @@ GLboolean r700SetupFragmentProgram(GLcontext * ctx)
 
     if(GL_FALSE == fp->loaded)
     {
-        if(fp->r700Shader.bNeedsAssembly == GL_TRUE)
+           if(fp->r700Shader.bNeedsAssembly == GL_TRUE)
            {
                    Assemble( &(fp->r700Shader) );
            }
index 9c7813e90845a22d31874acca6584d94be304fcd..cbb108d21280556ac722e05ac54456e672bc05d8 100644 (file)
@@ -49,13 +49,16 @@ struct r700_fragment_program
 
 /* Internal */
 void Map_Fragment_Program(r700_AssemblerBase         *pAsm,
-                                                 struct gl_fragment_program *mesa_fp);
+                         struct gl_fragment_program *mesa_fp);
 GLboolean Find_Instruction_Dependencies_fp(struct r700_fragment_program *fp,
-                                                                  struct gl_fragment_program   *mesa_fp);
+                                          struct gl_fragment_program   *mesa_fp);
+
+GLboolean r700TranslateFragmentShader(struct r700_fragment_program *fp,
+                                     struct gl_fragment_program   *mesa_vp);
 
 /* Interface */
-extern GLboolean r700TranslateFragmentShader(struct r700_fragment_program *fp,
-                                                                        struct gl_fragment_program   *mesa_vp);
+extern void r700SelectFragmentShader(GLcontext *ctx);
+
 extern GLboolean r700SetupFragmentProgram(GLcontext * ctx);
 
 extern void *    r700GetActiveFpShaderBo(GLcontext * ctx);
index 15f40b2771ebca0a5aab649e6505e8127603d46e..efa1daf2d3c049a70b727a17064d720c2bb5c3b6 100644 (file)
@@ -71,65 +71,37 @@ void r700SetDefaultStates(context_t *context) //--------------------
 void r700UpdateShaders (GLcontext * ctx)  //----------------------------------
 {
     context_t *context = R700_CONTEXT(ctx);
-
     GLvector4f dummy_attrib[_TNL_ATTRIB_MAX];
     GLvector4f *temp_attrib[_TNL_ATTRIB_MAX];
     int i;
 
-    if (ctx->FragmentProgram._Current) {
-           struct r700_fragment_program *fp = (struct r700_fragment_program *)
-                   (ctx->FragmentProgram._Current);
-           if (context->radeon.radeonScreen->chip_family < CHIP_FAMILY_RV770)
-           {
-                   fp->r700AsmCode.bR6xx = 1;
-           }
-
-           if(GL_FALSE == fp->translated)
-           {
-                   if( GL_FALSE == r700TranslateFragmentShader(fp, &(fp->mesa_program)) )
-                   {
-                           //return GL_TRUE;
-                   }
-           }
+    /* should only happenen once, just after context is created */
+    /* TODO: shouldn't we fallback to sw here? */
+    if (!ctx->FragmentProgram._Current) {
+           _mesa_fprintf(stderr, "No ctx->FragmentProgram._Current!!\n");
+           return;
     }
 
-    if (context->radeon.NewGLState) 
-    {
-       struct r700_vertex_program *vp;
-        context->radeon.NewGLState = 0;
-
-        for (i = _TNL_FIRST_MAT; i <= _TNL_LAST_MAT; i++) 
-        {
-            /* mat states from state var not array for sw */
-            dummy_attrib[i].stride = 0;
+    r700SelectFragmentShader(ctx);
 
-            temp_attrib[i] = TNL_CONTEXT(ctx)->vb.AttribPtr[i];
-            TNL_CONTEXT(ctx)->vb.AttribPtr[i] = &(dummy_attrib[i]);
-        }
-
-        _tnl_UpdateFixedFunctionProgram(ctx);
-
-        for (i = _TNL_FIRST_MAT; i <= _TNL_LAST_MAT; i++) 
-        {
-            TNL_CONTEXT(ctx)->vb.AttribPtr[i] = temp_attrib[i];
-        }
+    if (context->radeon.NewGLState) {
+           for (i = _TNL_FIRST_MAT; i <= _TNL_LAST_MAT; i++) {
+                   /* mat states from state var not array for sw */
+                   dummy_attrib[i].stride = 0;
+                   temp_attrib[i] = TNL_CONTEXT(ctx)->vb.AttribPtr[i];
+                   TNL_CONTEXT(ctx)->vb.AttribPtr[i] = &(dummy_attrib[i]);
+           }
 
-        r700SelectVertexShader(ctx);
-        vp = (struct r700_vertex_program *)ctx->VertexProgram._Current;
+           _tnl_UpdateFixedFunctionProgram(ctx);
 
-        if (vp->translated == GL_FALSE) 
-        {
-            // TODO
-            //fprintf(stderr, "Failing back to sw-tcl\n");
-            //hw_tcl_on = future_hw_tcl_on = 0;
-            //r300ResetHwState(rmesa);
-            //
-            r700UpdateStateParameters(ctx, _NEW_PROGRAM);
-            return;
-        }
+           for (i = _TNL_FIRST_MAT; i <= _TNL_LAST_MAT; i++) {
+                   TNL_CONTEXT(ctx)->vb.AttribPtr[i] = temp_attrib[i];
+           }
     }
 
-    r700UpdateStateParameters(ctx, _NEW_PROGRAM);
+    r700SelectVertexShader(ctx);
+    r700UpdateStateParameters(ctx, _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS);
+    context->radeon.NewGLState = 0;
 }
 
 /*
@@ -176,45 +148,25 @@ void r700UpdateDrawBuffer(GLcontext * ctx) /* TODO */ //---------------------
        r700SetDepthTarget(context);
 }
 
-static void r700FetchStateParameter(GLcontext * ctx,
-                                               const gl_state_index state[STATE_LENGTH],
-                                               GLfloat * value)
-{
-    /* TODO */
-}
-
 void r700UpdateStateParameters(GLcontext * ctx, GLuint new_state) //--------------------
 {
-       struct r700_fragment_program *fp;
+       struct r700_fragment_program *fp =
+               (struct r700_fragment_program *)ctx->FragmentProgram._Current;
        struct gl_program_parameter_list *paramList;
-       GLuint i;
 
-       if (!(new_state & (_NEW_BUFFERS | _NEW_PROGRAM)))
+       if (!(new_state & (_NEW_BUFFERS | _NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS)))
                return;
 
-       fp = (struct r700_fragment_program *)ctx->FragmentProgram._Current;
-       if (!fp)
-    {
+       if (!ctx->FragmentProgram._Current || !fp)
                return;
-    }
 
-       paramList = fp->mesa_program.Base.Parameters;
+       paramList = ctx->FragmentProgram._Current->Base.Parameters;
 
        if (!paramList)
-    {
                return;
-    }
 
-       for (i = 0; i < paramList->NumParameters; i++) 
-    {
-               if (paramList->Parameters[i].Type == PROGRAM_STATE_VAR) 
-        {
-                       r700FetchStateParameter(ctx,
-                                               paramList->Parameters[i].
-                                               StateIndexes,
-                                               paramList->ParameterValues[i]);
-               }
-       }
+       _mesa_load_state_parameters(ctx, paramList);
+
 }
 
 /**
index 550594e9df8ff4abca6b549412eabea89184e0cb..f8f862b33aa7d16974e0e65634e723e9015853f5 100644 (file)
@@ -296,16 +296,16 @@ void r700SelectVertexShader(GLcontext *ctx)
     context_t *context = R700_CONTEXT(ctx);
     struct r700_vertex_program *vpc
              = (struct r700_vertex_program *)ctx->VertexProgram._Current;
+    TNLcontext *tnl = TNL_CONTEXT(ctx);
+    struct vertex_buffer *vb = &tnl->vb;
+    unsigned int unBit;
+    unsigned int i;
+
     if (context->radeon.radeonScreen->chip_family < CHIP_FAMILY_RV770)
     {
         vpc->r700AsmCode.bR6xx = 1;
     }
-    
-    TNLcontext *tnl = TNL_CONTEXT(ctx);
-       struct vertex_buffer *vb = &tnl->vb;
 
-    unsigned int unBit;
-    unsigned int i;
        for(i=0; i<VERT_ATTRIB_MAX; i++)
        {
                unBit = 1 << i;
@@ -317,11 +317,9 @@ void r700SelectVertexShader(GLcontext *ctx)
                }
        }
 
-    if(GL_FALSE == vpc->translated)
-    {
-        r700TranslateVertexShader(vpc,
-                                                         &(vpc->mesa_program) );
-    }
+       if(GL_FALSE == vpc->translated) {
+               r700TranslateVertexShader(vpc, &(vpc->mesa_program) );
+       }
 }
 
 void * r700GetActiveVpShaderBo(GLcontext * ctx)
@@ -345,17 +343,17 @@ GLboolean r700SetupVertexProgram(GLcontext * ctx)
 
     if(GL_FALSE == vp->loaded)
     {
-        if(vp->r700Shader.bNeedsAssembly == GL_TRUE)
+           if(vp->r700Shader.bNeedsAssembly == GL_TRUE)
            {
                    Assemble( &(vp->r700Shader) );
            }
 
         /* Load vp to gpu */
-        r600EmitShader(ctx, 
-                       &(vp->shaderbo), 
+        r600EmitShader(ctx,
+                       &(vp->shaderbo),
                        (GLvoid *)(vp->r700Shader.pProgram),
                        vp->r700Shader.uShaderBinaryDWORDSize,
-                       "VS"); 
+                       "VS");
 
         vp->loaded = GL_TRUE;
     }
index 6a9726a3d0f5e59985abf335414b3b10b533bd9b..4c3b7ee453d326079a48ca873fbda640a7797c56 100644 (file)
@@ -62,23 +62,23 @@ struct r700_vertex_program
 
 //Internal
 unsigned int Map_Vertex_Output(r700_AssemblerBase       *pAsm, 
-                                                  struct gl_vertex_program *mesa_vp,
-                                                  unsigned int unStart);
+                              struct gl_vertex_program *mesa_vp,
+                              unsigned int unStart);
 unsigned int Map_Vertex_Input(r700_AssemblerBase       *pAsm, 
-                                                 struct gl_vertex_program *mesa_vp,
-                                                 unsigned int unStart);
+                             struct gl_vertex_program *mesa_vp,
+                             unsigned int unStart);
 GLboolean Process_Vertex_Program_Vfetch_Instructions(
-                                               struct r700_vertex_program *vp,
-                                               struct gl_vertex_program   *mesa_vp);
+       struct r700_vertex_program *vp,
+       struct gl_vertex_program   *mesa_vp);
 void Map_Vertex_Program(struct r700_vertex_program *vp,
-                                               struct gl_vertex_program   *mesa_vp);
+                       struct gl_vertex_program   *mesa_vp);
 GLboolean Find_Instruction_Dependencies_vp(struct r700_vertex_program *vp,
-                                                                  struct gl_vertex_program   *mesa_vp);
+                                          struct gl_vertex_program   *mesa_vp);
 
-/* Interface */
-extern GLboolean r700TranslateVertexShader(struct r700_vertex_program *vp,
-                                                          struct gl_vertex_program   *mesa_vp);
+GLboolean r700TranslateVertexShader(struct r700_vertex_program *vp,
+                                   struct gl_vertex_program   *mesa_vp);
 
+/* Interface */
 extern void r700SelectVertexShader(GLcontext *ctx);
 
 extern GLboolean r700SetupVertexProgram(GLcontext * ctx);