gallium: replace some ordinary assignments with pipe_reference_texture()
authorBrian <brian.paul@tungstengraphics.com>
Wed, 20 Feb 2008 22:09:27 +0000 (15:09 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Wed, 20 Feb 2008 22:09:44 +0000 (15:09 -0700)
This fixes at least one instance of dereferencing an invalid texture pointer.

src/gallium/drivers/cell/ppu/cell_texture.c
src/gallium/drivers/i915simple/i915_state.c
src/gallium/drivers/i915simple/i915_texture.c
src/gallium/drivers/i965simple/brw_state.c
src/gallium/drivers/i965simple/brw_tex_layout.c
src/gallium/drivers/softpipe/sp_context.h
src/gallium/drivers/softpipe/sp_quad_fs.c
src/gallium/drivers/softpipe/sp_state_sampler.c
src/gallium/drivers/softpipe/sp_texture.c
src/mesa/state_tracker/st_texture.c

index e1b91075b2ce8af9eb74c8baa7e12ee5ae51ce1b..0edefa5f0561bffacf7e345864031ec68c743806 100644 (file)
@@ -88,6 +88,7 @@ cell_texture_create(struct pipe_context *pipe,
       return NULL;
 
    spt->base = *templat;
+   spt->base.refcount = 1;
 
    cell_texture_layout(spt);
 
index 294e6fad0355fdfee64023be7a973b6b9dd5038c..e055eed7e025a16bacfa952ecfefdb71ff1d87b9 100644 (file)
@@ -32,6 +32,7 @@
 #include "draw/draw_context.h"
 #include "pipe/p_winsys.h"
 #include "pipe/p_util.h"
+#include "pipe/p_inlines.h"
 
 #include "i915_context.h"
 #include "i915_reg.h"
@@ -505,7 +506,9 @@ static void i915_set_sampler_texture(struct pipe_context *pipe,
 {
    struct i915_context *i915 = i915_context(pipe);
 
-   i915->texture[sampler] = (struct i915_texture*)texture;  /* ptr, not struct */
+   pipe_texture_reference(pipe,
+                          (struct pipe_texture **) &i915->texture[sampler],
+                          texture);
 
    i915->dirty |= I915_NEW_TEXTURE;
 }
index b235fae96d91e3e88bc24956d3d24dc26d1ae63a..1b415a94d4094a30b2ba14a8105381753c96b49a 100644 (file)
@@ -488,6 +488,7 @@ i915_texture_create(struct pipe_context *pipe,
       struct i915_context *i915 = i915_context(pipe);
 
       tex->base = *templat;
+      tex->base.refcount = 1;
 
       if (i915->flags.is_i945 ? i945_miptree_layout(pipe, tex) :
          i915_miptree_layout(pipe, tex))
index f746d1cc57c42d0123fd7a89b4c25dc6a77e316d..f269b2882cabe911eb73d4fbcf8d44b1e8a1bf48 100644 (file)
@@ -327,7 +327,9 @@ static void brw_set_sampler_texture(struct pipe_context *pipe,
 {
    struct brw_context *brw = brw_context(pipe);
 
-   brw->attribs.Texture[unit] = (struct brw_texture*)texture;  /* ptr, not struct */
+   pipe_reference_texture(pipe,
+                          (struct pipe_texture **) &brw->attribs.Texture[unit],
+                          texture);
 
    brw->state.dirty.brw |= BRW_NEW_TEXTURE;
 }
index 043a2ff9a45f9e9e45c6030bb8fcd98d7d8a1d19..86ce3d0cc38da6cd5f842e183eecc26c99da8440 100644 (file)
@@ -308,6 +308,7 @@ brw_texture_create(struct pipe_context *pipe,
 
    if (tex) {
       tex->base = *templat;
+      tex->base.refcount = 1;
 
       if (brw_miptree_layout(pipe, tex))
         tex->buffer = pipe->winsys->buffer_create(pipe->winsys, 64,
index b70d4fea85a8cc3dc5d4de6e6333b147bd9fee30..a50cee764869da1a0bbf3b17d2f2c60eeb5cff6c 100644 (file)
@@ -68,7 +68,7 @@ struct softpipe_context {
    struct pipe_framebuffer_state framebuffer;
    struct pipe_poly_stipple poly_stipple;
    struct pipe_scissor_state scissor;
-   struct softpipe_texture *texture[PIPE_MAX_SAMPLERS];
+   struct pipe_texture *texture[PIPE_MAX_SAMPLERS];
    struct pipe_viewport_state viewport;
    struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX];
    struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX];
index cf1b1eff75c66918d82ee48016affbf90d492c1f..2f40e09d5c202d82e90fec6dc6295c240370a892 100644 (file)
@@ -142,7 +142,7 @@ static void shade_begin(struct quad_stage *qs)
    /* set TGSI sampler state that varies */
    for (i = 0; i < PIPE_MAX_SAMPLERS; i++) {
       qss->samplers[i].state = softpipe->sampler[i];
-      qss->samplers[i].texture = &softpipe->texture[i]->base;
+      qss->samplers[i].texture = softpipe->texture[i];
    }
 
    /* find output slots for depth, color */
index 9246915e19e4bfa357249eea6e081a3a8f61c21a..18669a1c6ef9445417f2ff5c7ee4015e69574d75 100644 (file)
@@ -30,6 +30,7 @@
  */
 
 #include "pipe/p_util.h"
+#include "pipe/p_inlines.h"
 
 #include "draw/draw_context.h"
 
@@ -82,7 +83,7 @@ softpipe_set_sampler_texture(struct pipe_context *pipe,
    draw_flush(softpipe->draw);
 
    assert(unit < PIPE_MAX_SAMPLERS);
-   softpipe->texture[unit] = softpipe_texture(texture);  /* ptr, not struct */
+   pipe_texture_reference(pipe, &softpipe->texture[unit], texture);
 
    sp_tile_cache_set_texture(pipe, softpipe->tex_cache[unit], texture);
 
index 295704c05f86198f5cf82b4153b9e8723dc345c5..6ba0f09e0a1269b00b7bec6eb52b6a2aa58d1a26 100644 (file)
@@ -89,6 +89,7 @@ softpipe_texture_create(struct pipe_context *pipe,
       return NULL;
 
    spt->base = *templat;
+   spt->base.refcount = 1;
 
    softpipe_texture_layout(spt);
 
@@ -100,6 +101,8 @@ softpipe_texture_create(struct pipe_context *pipe,
       return NULL;
    }
 
+   assert(spt->base.refcount == 1);
+
    return &spt->base;
 }
 
@@ -136,7 +139,7 @@ softpipe_texture_update(struct pipe_context *pipe,
    struct softpipe_context *softpipe = softpipe_context(pipe);
    uint unit;
    for (unit = 0; unit < PIPE_MAX_SAMPLERS; unit++) {
-      if (softpipe->texture[unit] == softpipe_texture(texture)) {
+      if (softpipe->texture[unit] == texture) {
          sp_flush_tile_cache(softpipe, softpipe->tex_cache[unit]);
       }
    }
index b86f416c9b435d88c3c9b749bda3c443ea2f29c0..ad284170e44593c022fb2ab229f9f0eefc20d269 100644 (file)
@@ -76,7 +76,7 @@ st_texture_create(struct st_context *st,
                  GLuint depth0,
                  GLuint compress_byte)
 {
-   struct pipe_texture pt;
+   struct pipe_texture pt, *newtex;
 
    assert(target <= PIPE_TEXTURE_CUBE);
 
@@ -95,9 +95,12 @@ st_texture_create(struct st_context *st,
    pt.depth[0] = depth0;
    pt.compressed = compress_byte ? 1 : 0;
    pt.cpp = pt.compressed ? compress_byte : st_sizeof_format(format);
-   pt.refcount = 1; 
 
-   return st->pipe->texture_create(st->pipe, &pt);
+   newtex = st->pipe->texture_create(st->pipe, &pt);
+
+   assert(!newtex || newtex->refcount == 1);
+
+   return newtex;
 }