llvmpipe: Pass state to setup.
authorJosé Fonseca <jfonseca@vmware.com>
Fri, 9 Oct 2009 12:41:33 +0000 (13:41 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Fri, 9 Oct 2009 12:41:33 +0000 (13:41 +0100)
src/gallium/drivers/llvmpipe/lp_context.h
src/gallium/drivers/llvmpipe/lp_setup.c
src/gallium/drivers/llvmpipe/lp_setup.h
src/gallium/drivers/llvmpipe/lp_setup_context.h
src/gallium/drivers/llvmpipe/lp_state.h
src/gallium/drivers/llvmpipe/lp_state_blend.c
src/gallium/drivers/llvmpipe/lp_state_derived.c
src/gallium/drivers/llvmpipe/lp_state_fs.c
src/gallium/drivers/llvmpipe/lp_state_sampler.c

index e34385bbae0f0b4d116a01e2cf8a5e9a26497ffc..17c6939ff5b8a3ef1fd9180094bc813d5943754a 100644 (file)
@@ -59,7 +59,7 @@ struct llvmpipe_context {
    const struct lp_vertex_shader *vs;
 
    /** Other rendering state */
-   struct pipe_blend_color blend_color[4][16];
+   struct pipe_blend_color blend_color;
    struct pipe_clip_state clip;
    struct pipe_constant_buffer constants[PIPE_SHADER_TYPES];
    struct pipe_framebuffer_state framebuffer;
@@ -120,7 +120,6 @@ struct llvmpipe_context {
    unsigned tex_timestamp;
    boolean no_rast;
 
-   struct lp_jit_context jit_context;
 };
 
 
index 56bbee1f7cbb9804992ac415b319d80ea337af46..f999004a6696acf97f0665377d2b58bf2f68c8be 100644 (file)
  * lp_setup_flush().
  */
 
-#include "lp_setup_context.h"
+#include "pipe/p_defines.h"
+#include "pipe/p_inlines.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "util/u_pack_color.h"
-#include "pipe/p_defines.h"
+#include "lp_state.h"
+#include "lp_buffer.h"
+#include "lp_texture.h"
+#include "lp_setup_context.h"
 
 static void set_state( struct setup_context *, unsigned );
 
@@ -394,14 +398,99 @@ lp_setup_set_fs_inputs( struct setup_context *setup,
 }
 
 void
-lp_setup_set_shader_state( struct setup_context *setup,
-                           const struct lp_jit_context *jc )
+lp_setup_set_fs( struct setup_context *setup,
+                 struct lp_fragment_shader *fs )
 {
-   
+   /* FIXME: reference count */
+
+   setup->fs.jit_function = fs->current->jit_function;
 }
 
+void
+lp_setup_set_fs_constants(struct setup_context *setup,
+                          struct pipe_buffer *buffer)
+{
+   const void *data = buffer ? llvmpipe_buffer(buffer)->data : NULL;
+   struct pipe_buffer *dummy;
 
+   /* FIXME: hold on to the reference */
+   dummy = NULL;
+   pipe_buffer_reference(&dummy, buffer);
 
+   setup->fs.jit_context.constants = data;
+
+   setup->fs.jit_context_dirty = TRUE;
+}
+
+
+void
+lp_setup_set_alpha_ref_value( struct setup_context *setup,
+                              float alpha_ref_value )
+{
+   if(setup->fs.jit_context.alpha_ref_value != alpha_ref_value) {
+      setup->fs.jit_context.alpha_ref_value = alpha_ref_value;
+      setup->fs.jit_context_dirty = TRUE;
+   }
+}
+
+void
+lp_setup_set_blend_color( struct setup_context *setup,
+                          const struct pipe_blend_color *blend_color )
+{
+   unsigned i, j;
+
+   if(!setup->fs.jit_context.blend_color)
+      setup->fs.jit_context.blend_color = align_malloc(4 * 16, 16);
+
+   for (i = 0; i < 4; ++i) {
+      uint8_t c = float_to_ubyte(blend_color->color[i]);
+      for (j = 0; j < 16; ++j)
+         setup->fs.jit_context.blend_color[i*4 + j] = c;
+   }
+
+   setup->fs.jit_context_dirty = TRUE;
+}
+
+void
+lp_setup_set_sampler_textures( struct setup_context *setup,
+                               unsigned num, struct pipe_texture **texture)
+{
+   struct pipe_texture *dummy;
+   unsigned i;
+
+   assert(num <= PIPE_MAX_SAMPLERS);
+
+   for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
+      struct pipe_texture *tex = i < num ? texture[i] : NULL;
+
+      /* FIXME: hold on to the reference */
+      dummy = NULL;
+      pipe_texture_reference(&dummy, tex);
+
+      if(tex) {
+         struct llvmpipe_texture *lp_tex = llvmpipe_texture(tex);
+         struct lp_jit_texture *jit_tex = &setup->fs.jit_context.textures[i];
+         jit_tex->width = tex->width[0];
+         jit_tex->height = tex->height[0];
+         jit_tex->stride = lp_tex->stride[0];
+         if(!lp_tex->dt)
+            jit_tex->data = lp_tex->data;
+         else
+            /* FIXME: map the rendertarget */
+            assert(0);
+      }
+   }
+
+   setup->fs.jit_context_dirty = TRUE;
+}
+
+static void
+lp_setup_set_shader_state( struct setup_context *setup,
+                           const struct lp_jit_context *jc )
+{
+
+
+}
 
 
 /* Stubs for lines & points for now:
index bd439fa8578bbfdf03fb8cb6295938eed1c4cc83..ac9c3cc0ee96ccfcb0402e2e3616e88ebbdb0bec 100644 (file)
@@ -50,7 +50,9 @@ struct lp_shader_input {
 
 struct pipe_texture;
 struct pipe_surface;
+struct pipe_blend_color;
 struct setup_context;
+struct lp_fragment_shader;
 struct lp_jit_context;
 
 struct setup_context *
@@ -100,8 +102,25 @@ lp_setup_set_fs_inputs( struct setup_context *setup,
                         unsigned nr );
 
 void
-lp_setup_set_shader_state( struct setup_context *setup,
-                           const struct lp_jit_context *jc );
+lp_setup_set_fs( struct setup_context *setup,
+                 struct lp_fragment_shader *fs );
+
+void
+lp_setup_set_fs_constants(struct setup_context *setup,
+                          struct pipe_buffer *buffer);
+
+
+void
+lp_setup_set_alpha_ref_value( struct setup_context *setup,
+                              float alpha_ref_value );
+
+void
+lp_setup_set_blend_color( struct setup_context *setup,
+                          const struct pipe_blend_color *blend_color );
+
+void
+lp_setup_set_sampler_textures( struct setup_context *setup,
+                               unsigned num, struct pipe_texture **texture);
 
 boolean
 lp_setup_is_texture_referenced( struct setup_context *setup,
index b29fec8ef059811337c5658864fee1cc8ea8c432..2e2380dd8065978ca51b2bc70e2ec233839d6b1a 100644 (file)
@@ -109,6 +109,11 @@ struct setup_context {
    struct {
       struct lp_shader_input input[PIPE_MAX_ATTRIBS];
       unsigned nr_inputs;
+
+      struct lp_jit_context jit_context;
+      lp_jit_frag_func jit_function;
+
+      boolean jit_context_dirty;
    } fs;
 
    void (*point)( struct setup_context *,
index a9980d6f14a40ff8ff91a67a238c86b5fb0e63f2..64fe3600f5eff2c5325483667a6d0006527c1d84 100644 (file)
@@ -54,6 +54,7 @@
 #define LP_NEW_VERTEX        0x1000
 #define LP_NEW_VS            0x2000
 #define LP_NEW_QUERY         0x4000
+#define LP_NEW_BLEND_COLOR   0x8000
 
 
 struct tgsi_sampler;
index 3f03bd00571637d69b39230d9b53165155924703..48afe5f524224e84f7d2618c53b53c97afd25b0f 100644 (file)
@@ -67,17 +67,16 @@ void llvmpipe_set_blend_color( struct pipe_context *pipe,
                             const struct pipe_blend_color *blend_color )
 {
    struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
-   unsigned i, j;
+
+   if(!blend_color)
+      return;
+
+   if(memcmp(&llvmpipe->blend_color, blend_color, sizeof *blend_color) == 0)
+      return;
 
    memcpy(&llvmpipe->blend_color, blend_color, sizeof *blend_color);
 
-   if(!llvmpipe->jit_context.blend_color)
-      llvmpipe->jit_context.blend_color = align_malloc(4 * 16, 16);
-   for (i = 0; i < 4; ++i) {
-      uint8_t c = float_to_ubyte(blend_color->color[i]);
-      for (j = 0; j < 16; ++j)
-         llvmpipe->jit_context.blend_color[i*4 + j] = c;
-   }
+   llvmpipe->dirty |= LP_NEW_BLEND_COLOR;
 }
 
 
@@ -101,9 +100,6 @@ llvmpipe_bind_depth_stencil_state(struct pipe_context *pipe,
 
    llvmpipe->depth_stencil = (const struct pipe_depth_stencil_alpha_state *)depth_stencil;
 
-   if(llvmpipe->depth_stencil)
-      llvmpipe->jit_context.alpha_ref_value = llvmpipe->depth_stencil->alpha.ref_value;
-
    llvmpipe->dirty |= LP_NEW_DEPTH_STENCIL_ALPHA;
 }
 
index b801f054a2fe85fca0e5de7f55e5412917186796..00903c8ef449035a78c281513ea3b8f4a369111a 100644 (file)
@@ -33,6 +33,7 @@
 #include "draw/draw_private.h"
 #include "lp_context.h"
 #include "lp_screen.h"
+#include "lp_setup.h"
 #include "lp_state.h"
 
 
@@ -256,6 +257,23 @@ void llvmpipe_update_derived( struct llvmpipe_context *llvmpipe )
                           LP_NEW_TEXTURE))
       llvmpipe_update_fs( llvmpipe );
 
+   if (llvmpipe->dirty & (LP_NEW_BLEND |
+                          LP_NEW_DEPTH_STENCIL_ALPHA |
+                          LP_NEW_SAMPLER |
+                          LP_NEW_TEXTURE))
+      llvmpipe_update_fs( llvmpipe );
+
+   if (llvmpipe->dirty & LP_NEW_BLEND_COLOR)
+      lp_setup_set_blend_color(llvmpipe->setup, &llvmpipe->blend_color);
+
+   if (llvmpipe->dirty & LP_NEW_DEPTH_STENCIL_ALPHA)
+      lp_setup_set_alpha_ref_value(llvmpipe->setup, llvmpipe->depth_stencil->alpha.ref_value);
+
+   if (llvmpipe->dirty & LP_NEW_CONSTANTS)
+      lp_setup_set_fs_constants(llvmpipe->setup, llvmpipe->constants[PIPE_SHADER_FRAGMENT].buffer);
+
+   if (llvmpipe->dirty & LP_NEW_TEXTURE)
+      lp_setup_set_sampler_textures(llvmpipe->setup, llvmpipe->num_textures, llvmpipe->texture);
 
    llvmpipe->dirty = 0;
 }
index 59c7afc6f78eceb14286046092098ffb007eebbe..63e675e5848a542534d068a2cbc627a3a0fa7449 100644 (file)
@@ -681,16 +681,15 @@ llvmpipe_set_constant_buffer(struct pipe_context *pipe,
    assert(shader < PIPE_SHADER_TYPES);
    assert(index == 0);
 
+   if(llvmpipe->constants[shader].buffer == buffer)
+      return;
+
    if(shader == PIPE_SHADER_VERTEX)
       draw_flush(llvmpipe->draw);
 
    /* note: reference counting */
    pipe_buffer_reference(&llvmpipe->constants[shader].buffer, buffer);
 
-   if(shader == PIPE_SHADER_FRAGMENT) {
-      llvmpipe->jit_context.constants = data;
-   }
-
    if(shader == PIPE_SHADER_VERTEX) {
       draw_set_mapped_constant_buffer(llvmpipe->draw, data, size);
    }
index ae787801eb64ce6a859b554140180974ba936b39..e19394a4c92007623ebfd67236f2c4f9aef52b16 100644 (file)
@@ -96,16 +96,6 @@ llvmpipe_set_sampler_textures(struct pipe_context *pipe,
       struct pipe_texture *tex = i < num ? texture[i] : NULL;
 
       pipe_texture_reference(&llvmpipe->texture[i], tex);
-
-      if(tex) {
-         struct llvmpipe_texture *lp_tex = llvmpipe_texture(tex);
-         struct lp_jit_texture *jit_tex = &llvmpipe->jit_context.textures[i];
-         jit_tex->width = tex->width[0];
-         jit_tex->height = tex->height[0];
-         jit_tex->stride = lp_tex->stride[0];
-         if(!lp_tex->dt)
-            jit_tex->data = lp_tex->data;
-      }
    }
 
    llvmpipe->num_textures = num;