gallivm: added lp_build_andc()
[mesa.git] / src / gallium / auxiliary / draw / draw_vs_exec.c
index cb80d008cd614b2c0aa937cd0d73124b08da038b..7deca2b69d946e9bcdbee454f64a084bbc75c950 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 "tgsi/util/tgsi_parse.h"
-#include "tgsi/util/tgsi_scan.h"
+#include "tgsi/tgsi_parse.h"
+#include "tgsi/tgsi_scan.h"
+#include "tgsi/tgsi_exec.h"
 
 
 struct exec_vertex_shader {
@@ -61,12 +63,15 @@ vs_exec_prepare( struct draw_vertex_shader *shader,
 {
    struct exec_vertex_shader *evs = exec_vertex_shader(shader);
 
-   /* specify the vertex program to interpret/execute */
-   tgsi_exec_machine_bind_shader(evs->machine,
-                                shader->state.tokens,
-                                PIPE_MAX_SAMPLERS,
-                                NULL /*samplers*/ );
-
+   /* Specify the vertex program to interpret/execute.
+    * Avoid rebinding when possible.
+    */
+   if (evs->machine->Tokens != shader->state.tokens) {
+      tgsi_exec_machine_bind_shader(evs->machine,
+                                    shader->state.tokens,
+                                    draw->vs.num_samplers,
+                                    draw->vs.samplers);
+   }
 }
 
 
@@ -80,7 +85,7 @@ static void
 vs_exec_run_linear( struct draw_vertex_shader *shader,
                    const float (*input)[4],
                    float (*output)[4],
-                   const float (*constants)[4],
+                   const void *constants[PIPE_MAX_CONSTANT_BUFFERS],
                    unsigned count,
                    unsigned input_stride,
                    unsigned output_stride )
@@ -90,7 +95,9 @@ vs_exec_run_linear( struct draw_vertex_shader *shader,
    unsigned int i, j;
    unsigned slot;
 
-   machine->Consts = constants;
+   for (i = 0; i < PIPE_MAX_CONSTANT_BUFFERS; i++) {
+      machine->Consts[i] = constants[i];
+   }
 
    for (i = 0; i < count; i += MAX_TGSI_VERTICES) {
       unsigned int max_vertices = MIN2(MAX_TGSI_VERTICES, count - i);
@@ -110,6 +117,12 @@ vs_exec_run_linear( struct draw_vertex_shader *shader,
 #endif
 
          for (slot = 0; slot < shader->info.num_inputs; slot++) {
+#if 0
+            assert(!util_is_inf_or_nan(input[slot][0]));
+            assert(!util_is_inf_or_nan(input[slot][1]));
+            assert(!util_is_inf_or_nan(input[slot][2]));
+            assert(!util_is_inf_or_nan(input[slot][3]));
+#endif
             machine->Inputs[slot].xyzw[0].f[j] = input[slot][0];
             machine->Inputs[slot].xyzw[1].f[j] = input[slot][1];
             machine->Inputs[slot].xyzw[2].f[j] = input[slot][2];
@@ -119,6 +132,12 @@ vs_exec_run_linear( struct draw_vertex_shader *shader,
         input = (const float (*)[4])((const char *)input + input_stride);
       } 
 
+      tgsi_set_exec_mask(machine,
+                         1,
+                         max_vertices > 1,
+                         max_vertices > 2,
+                         max_vertices > 3);
+
       /* run interpreter */
       tgsi_exec_machine_run( machine );
 
@@ -141,6 +160,7 @@ vs_exec_run_linear( struct draw_vertex_shader *shader,
                         output[slot][1],
                         output[slot][2],
                         output[slot][3]);
+            assert(!util_is_inf_or_nan(output[slot][0]));
          }
 #endif
 
@@ -179,10 +199,12 @@ draw_create_vs_exec(struct draw_context *draw,
 
    tgsi_scan_shader(state->tokens, &vs->base.info);
 
+   vs->base.draw = draw;
    vs->base.prepare = vs_exec_prepare;
    vs->base.run_linear = vs_exec_run_linear;
    vs->base.delete = vs_exec_delete;
-   vs->machine = &draw->vs.machine;
+   vs->base.create_varient = draw_vs_varient_generic;
+   vs->machine = draw->vs.machine;
 
    return &vs->base;
 }