i915: Fix for sampler view changes.
authormichal <michal@transistor.(none)>
Thu, 10 Dec 2009 06:52:45 +0000 (07:52 +0100)
committermichal <michal@transistor.(none)>
Thu, 10 Dec 2009 06:52:45 +0000 (07:52 +0100)
src/gallium/drivers/i915/i915_context.h
src/gallium/drivers/i915/i915_state.c
src/gallium/drivers/i915/i915_state_derived.c
src/gallium/drivers/i915/i915_state_emit.c
src/gallium/drivers/i915/i915_state_sampler.c

index da769e7b290a5453e201cef05829abcbb2312ec8..cd6dcd59a9f825305a4c334c9bb3c6af3fefcfe1 100644 (file)
@@ -239,14 +239,14 @@ struct i915_context
    struct pipe_framebuffer_state framebuffer;
    struct pipe_poly_stipple poly_stipple;
    struct pipe_scissor_state scissor;
-   struct i915_texture *texture[PIPE_MAX_SAMPLERS];
+   struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
    struct pipe_viewport_state viewport;
    struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
 
    unsigned dirty;
 
    unsigned num_samplers;
-   unsigned num_textures;
+   unsigned num_fragment_sampler_views;
    unsigned num_vertex_elements;
    unsigned num_vertex_buffers;
 
@@ -276,7 +276,7 @@ struct i915_context
 #define I915_NEW_ALPHA_TEST    0x100
 #define I915_NEW_DEPTH_STENCIL 0x200
 #define I915_NEW_SAMPLER       0x400
-#define I915_NEW_TEXTURE       0x800
+#define I915_NEW_SAMPLER_VIEW  0x800
 #define I915_NEW_CONSTANTS     0x1000
 #define I915_NEW_VBO           0x2000
 #define I915_NEW_VS            0x4000
index 62169918e2b715bedf8decb306ecde8ffaba4c20..b38d1b2404a027b11fda79f391530fc7e143e8be 100644 (file)
@@ -560,9 +560,9 @@ static void i915_set_constant_buffer(struct pipe_context *pipe,
 }
 
 
-static void i915_set_sampler_textures(struct pipe_context *pipe,
-                                      unsigned num,
-                                      struct pipe_texture **texture)
+static void i915_set_fragment_sampler_views(struct pipe_context *pipe,
+                                            unsigned num,
+                                            struct pipe_sampler_view **views)
 {
    struct i915_context *i915 = i915_context(pipe);
    uint i;
@@ -570,27 +570,53 @@ static void i915_set_sampler_textures(struct pipe_context *pipe,
    assert(num <= PIPE_MAX_SAMPLERS);
 
    /* Check for no-op */
-   if (num == i915->num_textures &&
-       !memcmp(i915->texture, texture, num * sizeof(struct pipe_texture *)))
+   if (num == i915->num_fragment_sampler_views &&
+       !memcmp(i915->fragment_sampler_views, views, num * sizeof(struct pipe_sampler_view *)))
       return;
 
    /* Fixes wrong texture in texobj with VBUF */
    draw_flush(i915->draw);
 
    for (i = 0; i < num; i++)
-      pipe_texture_reference((struct pipe_texture **) &i915->texture[i],
-                             texture[i]);
+      pipe_sampler_view_reference(&i915->fragment_sampler_views[i],
+                                  views[i]);
 
-   for (i = num; i < i915->num_textures; i++)
-      pipe_texture_reference((struct pipe_texture **) &i915->texture[i],
-                             NULL);
+   for (i = num; i < i915->num_fragment_sampler_views; i++)
+      pipe_sampler_view_reference(&i915->fragment_sampler_views[i],
+                                  NULL);
 
-   i915->num_textures = num;
+   i915->num_fragment_sampler_views = num;
 
-   i915->dirty |= I915_NEW_TEXTURE;
+   i915->dirty |= I915_NEW_SAMPLER_VIEW;
 }
 
 
+static struct pipe_sampler_view *
+i915_create_sampler_view(struct pipe_context *pipe,
+                         struct pipe_texture *texture,
+                         const struct pipe_sampler_view *templ)
+{
+   struct i915_context *i915 = i915_context(pipe);
+   struct pipe_sampler_view *view = CALLOC_STRUCT(pipe_sampler_view);
+
+   *view = *templ;
+   view->reference.count = 1;
+   view->texture = NULL;
+   pipe_texture_reference(&view->texture, texture);
+   view->context = pipe;
+
+   return view;
+}
+
+
+static void
+i915_sampler_view_destroy(struct pipe_context *pipe,
+                          struct pipe_sampler_view *view)
+{
+   pipe_texture_reference(&view->texture, NULL);
+   FREE(view);
+}
+
 
 static void i915_set_framebuffer_state(struct pipe_context *pipe,
                                       const struct pipe_framebuffer_state *fb)
@@ -791,7 +817,9 @@ i915_init_state_functions( struct i915_context *i915 )
 
    i915->base.set_polygon_stipple = i915_set_polygon_stipple;
    i915->base.set_scissor_state = i915_set_scissor_state;
-   i915->base.set_fragment_sampler_textures = i915_set_sampler_textures;
+   i915->base.set_fragment_sampler_views = i915_set_fragment_sampler_views;
+   i915->base.create_sampler_view = i915_create_sampler_view;
+   i915->base.sampler_view_destroy = i915_sampler_view_destroy;
    i915->base.set_viewport_state = i915_set_viewport_state;
    i915->base.set_vertex_buffers = i915_set_vertex_buffers;
    i915->base.set_vertex_elements = i915_set_vertex_elements;
index f5b0e9f011eb79d9dd8896ace3e38c5a0df2a8f1..0eb1e3f91a44fbc555aa4bc7ae36041d469bfe60 100644 (file)
@@ -157,10 +157,10 @@ void i915_update_derived( struct i915_context *i915 )
    if (i915->dirty & (I915_NEW_RASTERIZER | I915_NEW_FS | I915_NEW_VS))
       calculate_vertex_layout( i915 );
 
-   if (i915->dirty & (I915_NEW_SAMPLER | I915_NEW_TEXTURE))
+   if (i915->dirty & (I915_NEW_SAMPLER | I915_NEW_SAMPLER_VIEW))
       i915_update_samplers(i915);
 
-   if (i915->dirty & I915_NEW_TEXTURE)
+   if (i915->dirty & I915_NEW_SAMPLER_VIEW)
       i915_update_textures(i915);
 
    if (i915->dirty)
index a3d4e3b04e524ad55ff3aeda0a58df3fef31f83a..202607a656336f28806e3aacec2916349fca9662 100644 (file)
@@ -289,7 +289,8 @@ i915_emit_hardware_state(struct i915_context *i915 )
             OUT_BATCH(enabled);
             for (unit = 0; unit < I915_TEX_UNITS; unit++) {
                if (enabled & (1 << unit)) {
-                  struct intel_buffer *buf = i915->texture[unit]->buffer;
+                  struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture;
+                  struct intel_buffer *buf = texture->buffer;
                   uint offset = 0;
                   assert(buf);
 
index e5c6d87215bb57723434fd05c3389fc71a00e81c..483947ece7f159511099ef6f174592c36bd82ba4 100644 (file)
@@ -144,20 +144,22 @@ void i915_update_samplers( struct i915_context *i915 )
    i915->current.sampler_enable_nr = 0;
    i915->current.sampler_enable_flags = 0x0;
 
-   for (unit = 0; unit < i915->num_textures && unit < i915->num_samplers;
+   for (unit = 0; unit < i915->num_fragment_sampler_views && unit < i915->num_samplers;
         unit++) {
       /* determine unit enable/disable by looking for a bound texture */
       /* could also examine the fragment program? */
-      if (i915->texture[unit]) {
+      if (i915->fragment_sampler_views[unit]) {
+         struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture;
+
         update_sampler( i915,
                         unit,
                         i915->sampler[unit],       /* sampler state */
-                        i915->texture[unit],        /* texture */
+                        texture,                    /* texture */
                         i915->current.sampler[unit] /* the result */
                         );
         i915_update_texture( i915,
                              unit,
-                             i915->texture[unit],          /* texture */
+                             texture,                      /* texture */
                              i915->sampler[unit],          /* sampler state */
                              i915->current.texbuffer[unit] );
 
@@ -281,14 +283,16 @@ i915_update_textures(struct i915_context *i915)
 {
    uint unit;
 
-   for (unit = 0; unit < i915->num_textures && unit < i915->num_samplers;
+   for (unit = 0; unit < i915->num_fragment_sampler_views && unit < i915->num_samplers;
         unit++) {
       /* determine unit enable/disable by looking for a bound texture */
       /* could also examine the fragment program? */
-      if (i915->texture[unit]) {
+      if (i915->fragment_sampler_views[unit]) {
+         struct i915_texture *texture = (struct i915_texture *)i915->fragment_sampler_views[unit]->texture;
+
         i915_update_texture( i915,
                              unit,
-                             i915->texture[unit],          /* texture */
+                             texture,                      /* texture */
                              i915->sampler[unit],          /* sampler state */
                              i915->current.texbuffer[unit] );
       }