OSDN Git Service

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 e1b9107..0edefa5 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 294e6fa..e055eed 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 b235fae..1b415a9 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 f746d1c..f269b28 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 043a2ff..86ce3d0 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 b70d4fe..a50cee7 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 cf1b1ef..2f40e09 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 9246915..18669a1 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 295704c..6ba0f09 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 b86f416..ad28417 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;
 }