Merge branch 'mesa_7_5_branch'
[mesa.git] / src / gallium / auxiliary / draw / draw_vs.c
index a8b6d0c90d2500c3c8c0aecd9e980621ee374643..790e89ed820af7e7ab8d3c036b8f242a2c31931c 100644 (file)
   *   Brian Paul
   */
 
-#include "pipe/p_util.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+
 #include "pipe/p_shader_tokens.h"
+
 #include "draw_private.h"
 #include "draw_context.h"
 #include "draw_vs.h"
+
 #include "translate/translate.h"
 #include "translate/translate_cache.h"
 
+#include "tgsi/tgsi_exec.h"
+
 
 
 
 void draw_vs_set_constants( struct draw_context *draw,
-                            const float (*constants)[4] )
+                            const float (*constants)[4],
+                            unsigned size )
 {
+   if (((uintptr_t)constants) & 0xf) {
+      if (size > draw->vs.const_storage_size) {
+         if (draw->vs.aligned_constant_storage)
+            align_free((void *)draw->vs.aligned_constant_storage);
+         draw->vs.aligned_constant_storage = align_malloc( size, 16 );
+      }
+      memcpy( (void*)draw->vs.aligned_constant_storage,
+              constants, 
+              size );
+      constants = draw->vs.aligned_constant_storage;
+   }
+      
+   draw->vs.aligned_constants = constants;
    draw_vs_aos_machine_constants( draw->vs.aos_machine, constants );
 }
 
@@ -67,7 +87,20 @@ draw_create_vertex_shader(struct draw_context *draw,
    if (!vs) {
       vs = draw_create_vs_sse( draw, shader );
       if (!vs) {
-         vs = draw_create_vs_exec( draw, shader );
+         vs = draw_create_vs_ppc( draw, shader );
+         if (!vs) {
+            vs = draw_create_vs_exec( draw, shader );
+         }
+      }
+   }
+
+   if (vs)
+   {
+      uint i;
+      for (i = 0; i < vs->info.num_outputs; i++) {
+         if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_POSITION &&
+             vs->info.output_semantic_index[i] == 0)
+            vs->position_output = i;
       }
    }
 
@@ -86,6 +119,7 @@ draw_bind_vertex_shader(struct draw_context *draw,
    {
       draw->vs.vertex_shader = dvs;
       draw->vs.num_vs_outputs = dvs->info.num_outputs;
+      draw->vs.position_output = dvs->position_output;
       dvs->prepare( dvs, draw );
    }
    else {
@@ -114,16 +148,8 @@ draw_delete_vertex_shader(struct draw_context *draw,
 boolean 
 draw_vs_init( struct draw_context *draw )
 {
-   tgsi_exec_machine_init(&draw->vs.machine);
-
-   /* FIXME: give this machine thing a proper constructor:
-    */
-   draw->vs.machine.Inputs = align_malloc(PIPE_MAX_ATTRIBS * sizeof(struct tgsi_exec_vector), 16);
-   if (!draw->vs.machine.Inputs)
-      return FALSE;
-
-   draw->vs.machine.Outputs = align_malloc(PIPE_MAX_ATTRIBS * sizeof(struct tgsi_exec_vector), 16);
-   if (!draw->vs.machine.Outputs)
+   draw->vs.machine = tgsi_exec_machine_create();
+   if (!draw->vs.machine)
       return FALSE;
 
    draw->vs.emit_cache = translate_cache_create();
@@ -135,8 +161,10 @@ draw_vs_init( struct draw_context *draw )
       return FALSE;
 
    draw->vs.aos_machine = draw_vs_aos_machine();
+#ifdef PIPE_ARCH_X86
    if (!draw->vs.aos_machine)
       return FALSE;
+#endif
       
    return TRUE;
 }
@@ -144,12 +172,6 @@ draw_vs_init( struct draw_context *draw )
 void
 draw_vs_destroy( struct draw_context *draw )
 {
-   if (draw->vs.machine.Inputs)
-      align_free(draw->vs.machine.Inputs);
-
-   if (draw->vs.machine.Outputs)
-      align_free(draw->vs.machine.Outputs);
-
    if (draw->vs.fetch_cache)
       translate_cache_destroy(draw->vs.fetch_cache);
 
@@ -159,8 +181,10 @@ draw_vs_destroy( struct draw_context *draw )
    if (draw->vs.aos_machine)
       draw_vs_aos_machine_destroy(draw->vs.aos_machine);
 
-   tgsi_exec_machine_free_data(&draw->vs.machine);
+   if (draw->vs.aligned_constant_storage)
+      align_free((void*)draw->vs.aligned_constant_storage);
 
+   tgsi_exec_machine_destroy(draw->vs.machine);
 }