gallium/draw: initial code to properly support llvm in the draw module
[mesa.git] / src / mesa / drivers / dri / r600 / r700_vertprog.c
index d3d1da79592a52804df82ce0f80ad551fd19cc2d..07e0adc89056b498c3c2ed8f5396917c276b96e0 100644 (file)
@@ -188,7 +188,8 @@ GLboolean Process_Vertex_Program_Vfetch_Instructions2(
                                       context->stream_desc[i].size,
                                       context->stream_desc[i].element,
                                       context->stream_desc[i]._signed,
-                                      context->stream_desc[i].normalize,                                                           
+                                      context->stream_desc[i].normalize,
+                                      context->stream_desc[i].format,
                                      &vtxFetchMethod);
     }
 
@@ -306,8 +307,8 @@ struct r700_vertex_program* r700TranslateVertexShader(GLcontext *ctx,
        struct r700_vertex_program *vp;
        unsigned int i;
 
-       vp = _mesa_calloc(sizeof(*vp));
-       vp->mesa_program = (struct gl_vertex_program *)_mesa_clone_program(ctx, &mesa_vp->Base);
+       vp = calloc(1, sizeof(*vp));
+       vp->mesa_program = _mesa_clone_vertex_program(ctx, mesa_vp);
 
        if (mesa_vp->IsPositionInvariant)
        {
@@ -319,6 +320,7 @@ struct r700_vertex_program* r700TranslateVertexShader(GLcontext *ctx,
                vp->aos_desc[i].size   = context->stream_desc[i].size;
                vp->aos_desc[i].stride = context->stream_desc[i].stride;
                vp->aos_desc[i].type   = context->stream_desc[i].type;
+               vp->aos_desc[i].format = context->stream_desc[i].format;
        }
 
        if (context->radeon.radeonScreen->chip_family < CHIP_FAMILY_RV770)
@@ -337,7 +339,15 @@ struct r700_vertex_program* r700TranslateVertexShader(GLcontext *ctx,
 
     InitShaderProgram(&(vp->r700AsmCode));
 
+    for(i=0; i < MAX_SAMPLERS; i++)
+    {
+        vp->r700AsmCode.SamplerUnits[i] = vp->mesa_program->Base.SamplerUnits[i];
+    }
+
+    vp->r700AsmCode.unCurNumILInsts = vp->mesa_program->Base.NumInstructions;
+
        if(GL_FALSE == AssembleInstr(0,
+                                 0,
                                  vp->mesa_program->Base.NumInstructions,
                                  &(vp->mesa_program->Base.Instructions[0]),
                                  &(vp->r700AsmCode)) )
@@ -350,7 +360,7 @@ struct r700_vertex_program* r700TranslateVertexShader(GLcontext *ctx,
         return NULL;
     }
 
-    if( GL_FALSE == RelocProgram(&(vp->r700AsmCode)) )
+    if( GL_FALSE == RelocProgram(&(vp->r700AsmCode), &(vp->mesa_program->Base)) )
     {
         return GL_FALSE;
     }
@@ -387,7 +397,8 @@ void r700SelectVertexShader(GLcontext *ctx)
        match = GL_TRUE;
        for(i=0; i<context->nNumActiveAos; i++)
        {
-               if (vp->aos_desc[i].size != context->stream_desc[i].size)
+               if (vp->aos_desc[i].size != context->stream_desc[i].size ||
+                   vp->aos_desc[i].format != context->stream_desc[i].format)
                {
                        match = GL_FALSE;
                        break;
@@ -490,6 +501,7 @@ static void r700TranslateAttrib(GLcontext *ctx, GLuint unLoc, int count, const s
        pStreamDesc->size = input->Size;
        pStreamDesc->dst_loc = context->nNumActiveAos;
        pStreamDesc->element = unLoc;
+       pStreamDesc->format = input->Format;
 
        switch (pStreamDesc->type) 
        { //GetSurfaceFormat
@@ -635,7 +647,7 @@ GLboolean r700SetupVertexProgram(GLcontext * ctx)
         /* _mesa_reference_program has already checked glsl shProg is ok and set ctx->VertexProgem._Current */
         /* so, use ctx->VertexProgem._Current */       
         struct gl_program_parameter_list *paramListOrginal = 
-                         paramListOrginal = ctx->VertexProgram._Current->Base.Parameters;
+                         ctx->VertexProgram._Current->Base.Parameters;
          
            _mesa_load_state_parameters(ctx, paramList);
 
@@ -667,5 +679,24 @@ GLboolean r700SetupVertexProgram(GLcontext * ctx)
     } else
            r700->vs.num_consts = 0;
 
+    COMPILED_SUB * pCompiledSub;
+    GLuint uj;
+    GLuint unConstOffset = r700->vs.num_consts;
+    for(ui=0; ui<vp->r700AsmCode.unNumPresub; ui++)
+    {
+        pCompiledSub = vp->r700AsmCode.presubs[ui].pCompiledSub;
+
+        r700->vs.num_consts += pCompiledSub->NumParameters;
+
+        for(uj=0; uj<pCompiledSub->NumParameters; uj++)
+        {
+            r700->vs.consts[uj + unConstOffset][0].f32All = pCompiledSub->ParameterValues[uj][0];
+                   r700->vs.consts[uj + unConstOffset][1].f32All = pCompiledSub->ParameterValues[uj][1];
+                   r700->vs.consts[uj + unConstOffset][2].f32All = pCompiledSub->ParameterValues[uj][2];
+                   r700->vs.consts[uj + unConstOffset][3].f32All = pCompiledSub->ParameterValues[uj][3];
+        }
+        unConstOffset += pCompiledSub->NumParameters;
+    }
+
     return GL_TRUE;
 }