llvmpipe: added scene functions for texture reference counting

When a texture is used in the scene we add it to a list of texture
references.  The lp_scene_is_textured_referenced() function tells
us if a texture is referenced by the scene.
This commit is contained in:
Brian Paul 2010-01-13 13:43:58 -07:00
parent 4769328fe1
commit 592e40aa7b
2 changed files with 64 additions and 0 deletions

View File

@ -27,6 +27,7 @@
#include "util/u_math.h"
#include "util/u_memory.h"
#include "util/u_simple_list.h"
#include "lp_scene.h"
@ -62,6 +63,8 @@ lp_scene_init(struct lp_scene *scene)
scene->data.head =
scene->data.tail = CALLOC_STRUCT(data_block);
make_empty_list(&scene->textures);
pipe_mutex_init(scene->mutex);
}
@ -140,6 +143,18 @@ lp_scene_reset(struct lp_scene *scene )
list->head = list->tail;
list->head->used = 0;
}
/* Release texture refs
*/
{
struct texture_ref *ref, *next, *ref_list = &scene->textures;
for (ref = ref_list->next; ref != ref_list; ref = next) {
next = next_elem(ref);
pipe_texture_reference(&ref->texture, NULL);
FREE(ref);
}
make_empty_list(ref_list);
}
}
@ -229,6 +244,39 @@ lp_scene_bin_size( const struct lp_scene *scene, unsigned x, unsigned y )
}
/**
* Add a reference to a texture by the scene.
*/
void
lp_scene_texture_reference( struct lp_scene *scene,
struct pipe_texture *texture )
{
struct texture_ref *ref = CALLOC_STRUCT(texture_ref);
if (ref) {
struct texture_ref *ref_list = &scene->textures;
pipe_texture_reference(&ref->texture, texture);
insert_at_tail(ref_list, ref);
}
}
/**
* Does this scene have a reference to the given texture?
*/
boolean
lp_scene_is_textured_referenced( const struct lp_scene *scene,
const struct pipe_texture *texture )
{
const struct texture_ref *ref_list = &scene->textures;
const struct texture_ref *ref;
foreach (ref, ref_list) {
if (ref->texture == texture)
return TRUE;
}
return FALSE;
}
/**
* Return last command in the bin
*/

View File

@ -97,6 +97,13 @@ struct data_block_list {
};
/** List of texture references */
struct texture_ref {
struct pipe_texture *texture;
struct texture_ref *prev, *next; /**< linked list w/ u_simple_list.h */
};
/**
* All bins and bin data are contained here.
* Per-bin data goes into the 'tile' bins.
@ -112,6 +119,9 @@ struct lp_scene {
/** the framebuffer to render the scene into */
struct pipe_framebuffer_state fb;
/** list of textures referenced by the scene commands */
struct texture_ref textures;
boolean write_depth;
/**
@ -150,6 +160,12 @@ unsigned lp_scene_data_size( const struct lp_scene *scene );
unsigned lp_scene_bin_size( const struct lp_scene *scene, unsigned x, unsigned y );
void lp_scene_texture_reference( struct lp_scene *scene,
struct pipe_texture *texture );
boolean lp_scene_is_textured_referenced( const struct lp_scene *scene,
const struct pipe_texture *texture );
/**
* Allocate space for a command/data in the bin's data buffer.