summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/cso_cache
diff options
context:
space:
mode:
authorJosé Fonseca <[email protected]>2008-04-20 14:41:02 +0900
committerJosé Fonseca <[email protected]>2008-04-20 14:41:29 +0900
commit29858e1b553cee1fd7e3380ea62c69d2a6b91b95 (patch)
tree484296c302e2a5371dd77743b700f4c3955f67fd /src/gallium/auxiliary/cso_cache
parent68a7cb21fa14eac9e38bf398623739a892cc0d52 (diff)
gallium: Refcount textures.
Pipe driver does refcount textures. If cso_context does not, dangling pointers appear.
Diffstat (limited to 'src/gallium/auxiliary/cso_cache')
-rw-r--r--src/gallium/auxiliary/cso_cache/cso_context.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index 4a1a6cb79c2..746b1761850 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -25,16 +25,19 @@
*
**************************************************************************/
- /* Wrap the cso cache & hash mechanisms in a simplified
+ /**
+ * @file
+ *
+ * Wrap the cso cache & hash mechanisms in a simplified
* pipe-driver-specific interface.
*
- * Authors:
- * Zack Rusin <[email protected]>
- * Keith Whitwell <[email protected]>
+ * @author Zack Rusin <[email protected]>
+ * @author Keith Whitwell <[email protected]>
*/
#include "pipe/p_state.h"
#include "pipe/p_util.h"
+#include "pipe/p_inlines.h"
#include "cso_cache/cso_context.h"
#include "cso_cache/cso_cache.h"
@@ -277,23 +280,39 @@ void cso_set_sampler_textures( struct cso_context *ctx,
ctx->nr_textures = count;
for (i = 0; i < count; i++)
- ctx->textures[i] = textures[i];
+ pipe_texture_reference(&ctx->textures[i], textures[i]);
for ( ; i < PIPE_MAX_SAMPLERS; i++)
- ctx->textures[i] = NULL;
+ pipe_texture_reference(&ctx->textures[i], NULL);
ctx->pipe->set_sampler_textures(ctx->pipe, count, textures);
}
void cso_save_sampler_textures( struct cso_context *ctx )
{
+ uint i;
+
ctx->nr_textures_saved = ctx->nr_textures;
- memcpy(ctx->textures_saved, ctx->textures, sizeof(ctx->textures));
+ for (i = 0; i < ctx->nr_textures; i++) {
+ assert(!ctx->textures_saved[i]);
+ pipe_texture_reference(&ctx->textures_saved[i], ctx->textures[i]);
+ }
}
void cso_restore_sampler_textures( struct cso_context *ctx )
{
- cso_set_sampler_textures(ctx, ctx->nr_textures_saved, ctx->textures_saved);
- ctx->nr_textures_saved = 0;
+ uint i;
+
+ ctx->nr_textures = ctx->nr_textures_saved;
+
+ for (i = 0; i < ctx->nr_textures; i++) {
+ pipe_texture_reference(&ctx->textures[i], NULL);
+ ctx->textures[i] = ctx->textures_saved[i];
+ ctx->textures_saved[i] = NULL;
+ }
+ for ( ; i < PIPE_MAX_SAMPLERS; i++)
+ pipe_texture_reference(&ctx->textures[i], NULL);
+
+ ctx->pipe->set_sampler_textures(ctx->pipe, ctx->nr_textures, ctx->textures);
}