Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / gallium / drivers / softpipe / sp_fs_sse.c
index 8095d662ee6a88bbaab0045284a5101d89796350..31908a517b7f9daf7beb0ca073f3a14860d2e3dc 100644 (file)
 
 #include "pipe/p_state.h"
 #include "pipe/p_defines.h"
-#include "pipe/p_util.h"
+#include "util/u_memory.h"
 #include "pipe/p_inlines.h"
-#include "tgsi/exec/tgsi_exec.h"
-#include "tgsi/exec/tgsi_sse2.h"
+#include "tgsi/tgsi_exec.h"
+#include "tgsi/tgsi_sse2.h"
 
 
-#if defined(__i386__) || defined(__386__)
+#if defined(PIPE_ARCH_X86)
 
 #include "rtasm/rtasm_x86sse.h"
 
 /* Surely this should be defined somewhere in a tgsi header:
  */
-typedef void (XSTDCALL *codegen_function)(
+typedef void (PIPE_CDECL *codegen_function)(
    const struct tgsi_exec_vector *input,
    struct tgsi_exec_vector *output,
-   float (*constant)[4],
+   const float (*constant)[4],
    struct tgsi_exec_vector *temporary,
-   const struct tgsi_interp_coef *coef
+   const struct tgsi_interp_coef *coef,
+   float (*immediates)[4]
    //, const struct tgsi_exec_vector *quadPos
  );
 
@@ -60,14 +61,15 @@ struct sp_sse_fragment_shader {
    struct sp_fragment_shader base;
    struct x86_function             sse2_program;
    codegen_function func;
+   float immediates[TGSI_EXEC_NUM_IMMEDIATES][4];
 };
 
 
 
 static void
-fs_sse_prepare( struct sp_fragment_shader *base,
-             struct tgsi_exec_machine *machine,
-             struct tgsi_sampler *samplers )
+fs_sse_prepare( const struct sp_fragment_shader *base,
+               struct tgsi_exec_machine *machine,
+               struct tgsi_sampler *samplers )
 {
 }
 
@@ -78,25 +80,27 @@ fs_sse_prepare( struct sp_fragment_shader *base,
  * TODO: process >1 quad at a time
  */
 static unsigned 
-fs_sse_run( struct sp_fragment_shader *base,
-        struct tgsi_exec_machine *machine,
-        struct quad_header *quad )
+fs_sse_run( const struct sp_fragment_shader *base,
+           struct tgsi_exec_machine *machine,
+           struct quad_header *quad )
 {
    struct sp_sse_fragment_shader *shader = (struct sp_sse_fragment_shader *) base;
 
    /* Compute X, Y, Z, W vals for this quad -- place in temp[0] for now */
    sp_setup_pos_vector(quad->posCoef, 
-                      (float)quad->x0, (float)quad->y0, 
+                      (float)quad->input.x0, (float)quad->input.y0, 
                       machine->Temps);
 
    /* init kill mask */
-   machine->Temps[TGSI_EXEC_TEMP_KILMASK_I].xyzw[TGSI_EXEC_TEMP_KILMASK_C].u[0] = 0x0;
+   tgsi_set_kill_mask(machine, 0x0);
+   tgsi_set_exec_mask(machine, 1, 1, 1, 1);
 
    shader->func( machine->Inputs,
                 machine->Outputs,
                 machine->Consts,
                 machine->Temps,
-                machine->InterpCoefs
+                machine->InterpCoefs,
+                 shader->immediates
                 //      , &machine->QuadPos
       );
 
@@ -129,13 +133,18 @@ softpipe_create_fs_sse(struct softpipe_context *softpipe,
 
    x86_init_func( &shader->sse2_program );
    
-   if (!tgsi_emit_sse2_fs( templ->tokens, &shader->sse2_program )) {
+   if (!tgsi_emit_sse2( templ->tokens, &shader->sse2_program,
+                        shader->immediates, FALSE )) {
       FREE(shader);
       return NULL;
    }
 
    shader->func = (codegen_function) x86_get_func( &shader->sse2_program );
-   assert(shader->func);
+   if (!shader->func) {
+      x86_release_func( &shader->sse2_program );
+      FREE(shader);
+      return NULL;
+   }
 
    shader->base.shader = *templ;
    shader->base.prepare = fs_sse_prepare;