Merge commit 'origin/master' into gallium-0.2
[mesa.git] / src / gallium / drivers / softpipe / sp_state_fs.c
index 0b814fc2847f049ccf301965eb8c322503d7dc8a..e5b609cf6c98b83231207e31b353ec36beab12a1 100644 (file)
 
 #include "sp_context.h"
 #include "sp_state.h"
+#include "sp_fs.h"
 
 #include "pipe/p_defines.h"
-#include "pipe/p_util.h"
+#include "util/u_memory.h"
 #include "pipe/p_inlines.h"
 #include "pipe/p_winsys.h"
-#include "pipe/draw/draw_context.h"
 #include "pipe/p_shader_tokens.h"
-#include "pipe/llvm/gallivm.h"
-#include "pipe/tgsi/util/tgsi_dump.h"
-#include "pipe/tgsi/exec/tgsi_sse2.h"
+#include "draw/draw_context.h"
+#include "tgsi/tgsi_dump.h"
+#include "tgsi/tgsi_scan.h"
 
 
 void *
@@ -44,39 +44,25 @@ softpipe_create_fs_state(struct pipe_context *pipe,
                          const struct pipe_shader_state *templ)
 {
    struct softpipe_context *softpipe = softpipe_context(pipe);
-   struct sp_fragment_shader_state *state;
-
-   /* Decide whether we'll be codegenerating this shader and if so do
-    * that now.
-    */
-
-   state = CALLOC_STRUCT(sp_fragment_shader_state);
-   if (!state)
-      return NULL;
-
-   state->shader = *templ;
-
-   if (softpipe->dump_fs) {
-      tgsi_dump(state->shader.tokens, 0);
+   struct sp_fragment_shader *state;
+
+   /* debug */
+   if (softpipe->dump_fs) 
+      tgsi_dump(templ->tokens, 0);
+
+   /* codegen */
+   state = softpipe_create_fs_llvm( softpipe, templ );
+   if (!state) {
+      state = softpipe_create_fs_sse( softpipe, templ );
+      if (!state) {
+         state = softpipe_create_fs_exec( softpipe, templ );
+      }
    }
 
-#ifdef MESA_LLVM
-   state->llvm_prog = 0;
+   assert(state);
 
-#if 0
-   if (!gallivm_global_cpu_engine()) {
-      gallivm_cpu_engine_create(state->llvm_prog);
-   }
-   else
-      gallivm_cpu_jit_compile(gallivm_global_cpu_engine(), state->llvm_prog);
-#endif
-
-#elif defined(__i386__) || defined(__386__)
-   if (softpipe->use_sse) {
-      x86_init_func( &state->sse2_program );
-      tgsi_emit_sse2_fs( state->shader.tokens, &state->sse2_program );
-   }
-#endif
+   /* get/save the summary info for this shader */
+   tgsi_scan_shader(templ->tokens, &state->info);
 
    return state;
 }
@@ -87,7 +73,7 @@ softpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
 {
    struct softpipe_context *softpipe = softpipe_context(pipe);
 
-   softpipe->fs = (struct sp_fragment_shader_state *) fs;
+   softpipe->fs = (struct sp_fragment_shader *) fs;
 
    softpipe->dirty |= SP_NEW_FS;
 }
@@ -96,13 +82,11 @@ softpipe_bind_fs_state(struct pipe_context *pipe, void *fs)
 void
 softpipe_delete_fs_state(struct pipe_context *pipe, void *fs)
 {
-   struct sp_fragment_shader_state *state = fs;
-
-#if defined(__i386__) || defined(__386__)
-   x86_release_func( &state->sse2_program );
-#endif
+   struct sp_fragment_shader *state = fs;
 
-   FREE( state );
+   assert(fs != softpipe_context(pipe)->fs);
+   
+   state->delete( state );
 }
 
 
@@ -111,17 +95,14 @@ softpipe_create_vs_state(struct pipe_context *pipe,
                          const struct pipe_shader_state *templ)
 {
    struct softpipe_context *softpipe = softpipe_context(pipe);
-   struct sp_vertex_shader_state *state;
+   struct sp_vertex_shader *state;
 
-   state = CALLOC_STRUCT(sp_vertex_shader_state);
+   state = CALLOC_STRUCT(sp_vertex_shader);
    if (state == NULL ) {
       return NULL;
    }
 
-   state->shader = *templ;
-
-   state->draw_data = draw_create_vertex_shader(softpipe->draw,
-                                                &state->shader);
+   state->draw_data = draw_create_vertex_shader(softpipe->draw, templ);
    if (state->draw_data == NULL) {
       FREE( state );
       return NULL;
@@ -136,9 +117,10 @@ softpipe_bind_vs_state(struct pipe_context *pipe, void *vs)
 {
    struct softpipe_context *softpipe = softpipe_context(pipe);
 
-   softpipe->vs = (const struct sp_vertex_shader_state *)vs;
+   softpipe->vs = (const struct sp_vertex_shader *)vs;
 
-   draw_bind_vertex_shader(softpipe->draw, softpipe->vs->draw_data);
+   draw_bind_vertex_shader(softpipe->draw,
+                           (softpipe->vs ? softpipe->vs->draw_data : NULL));
 
    softpipe->dirty |= SP_NEW_VS;
 }
@@ -149,8 +131,8 @@ softpipe_delete_vs_state(struct pipe_context *pipe, void *vs)
 {
    struct softpipe_context *softpipe = softpipe_context(pipe);
 
-   struct sp_vertex_shader_state *state =
-      (struct sp_vertex_shader_state *)vs;
+   struct sp_vertex_shader *state =
+      (struct sp_vertex_shader *)vs;
 
    draw_delete_vertex_shader(softpipe->draw, state->draw_data);
    FREE( state );
@@ -170,10 +152,10 @@ softpipe_set_constant_buffer(struct pipe_context *pipe,
    assert(index == 0);
 
    /* note: reference counting */
-   pipe_buffer_reference(ws,
+   winsys_buffer_reference(ws,
                         &softpipe->constants[shader].buffer,
-                        buf->buffer);
-   softpipe->constants[shader].size = buf->size;
+                        buf ? buf->buffer : NULL);
+   softpipe->constants[shader].size = buf ? buf->size : 0;
 
    softpipe->dirty |= SP_NEW_CONSTANTS;
 }