diff options
author | Brian Paul <[email protected]> | 2012-08-04 08:46:41 -0600 |
---|---|---|
committer | Brian Paul <[email protected]> | 2012-08-06 08:33:17 -0600 |
commit | 0a14e9f09fc1cf9d5c277bb239f349203d3bed79 (patch) | |
tree | 96ce96ffcfc14a4d464bb369b4da084be2860ff7 | |
parent | 61b62c007a7941e9b45e83440e932160a597e0e1 (diff) |
softpipe: combine vert/frag/geom texture caches in an array
This lets us consolidate some code now, and more in subsequent patches.
Reviewed-by: José Fonseca <[email protected]>
-rw-r--r-- | src/gallium/drivers/softpipe/sp_context.c | 70 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_context.h | 10 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_flush.c | 7 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_state_derived.c | 52 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_state_sampler.c | 12 |
5 files changed, 60 insertions, 91 deletions
diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index a79a7a04fde..3d8a69a60ad 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -89,7 +89,7 @@ static void softpipe_destroy( struct pipe_context *pipe ) { struct softpipe_context *softpipe = softpipe_context( pipe ); - uint i; + uint i, sh; #if DO_PSTIPPLE_IN_HELPER_MODULE if (softpipe->pstipple.sampler) @@ -123,26 +123,31 @@ softpipe_destroy( struct pipe_context *pipe ) pipe_surface_reference(&softpipe->framebuffer.zsbuf, NULL); for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - sp_destroy_tex_tile_cache(softpipe->fragment_tex_cache[i]); + sp_destroy_tex_tile_cache(softpipe->tex_cache[PIPE_SHADER_FRAGMENT][i]); pipe_sampler_view_reference(&softpipe->fragment_sampler_views[i], NULL); } for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { - sp_destroy_tex_tile_cache(softpipe->vertex_tex_cache[i]); + sp_destroy_tex_tile_cache(softpipe->tex_cache[PIPE_SHADER_VERTEX][i]); pipe_sampler_view_reference(&softpipe->vertex_sampler_views[i], NULL); } for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) { - sp_destroy_tex_tile_cache(softpipe->geometry_tex_cache[i]); + sp_destroy_tex_tile_cache(softpipe->tex_cache[PIPE_SHADER_GEOMETRY][i]); pipe_sampler_view_reference(&softpipe->geometry_sampler_views[i], NULL); } - for (i = 0; i < PIPE_SHADER_TYPES; i++) { - uint j; + for (sh = 0; sh < Elements(softpipe->tex_cache); sh++) { + for (i = 0; i < Elements(softpipe->tex_cache[0]); i++) { + sp_destroy_tex_tile_cache(softpipe->tex_cache[sh][i]); + pipe_sampler_view_reference(&softpipe->sampler_views[sh][i], NULL); + } + } - for (j = 0; j < PIPE_MAX_CONSTANT_BUFFERS; j++) { - if (softpipe->constants[i][j]) { - pipe_resource_reference(&softpipe->constants[i][j], NULL); + for (sh = 0; sh < Elements(softpipe->constants); sh++) { + for (i = 0; i < Elements(softpipe->constants[0]); i++) { + if (softpipe->constants[sh][i]) { + pipe_resource_reference(&softpipe->constants[sh][i], NULL); } } } @@ -171,7 +176,7 @@ softpipe_is_resource_referenced( struct pipe_context *pipe, unsigned level, int layer) { struct softpipe_context *softpipe = softpipe_context( pipe ); - unsigned i; + unsigned i, sh; if (texture->target == PIPE_BUFFER) return SP_UNREFERENCED; @@ -191,20 +196,12 @@ softpipe_is_resource_referenced( struct pipe_context *pipe, } /* check if any of the tex_cache textures are this texture */ - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - if (softpipe->fragment_tex_cache[i] && - softpipe->fragment_tex_cache[i]->texture == texture) - return SP_REFERENCED_FOR_READ; - } - for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { - if (softpipe->vertex_tex_cache[i] && - softpipe->vertex_tex_cache[i]->texture == texture) - return SP_REFERENCED_FOR_READ; - } - for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) { - if (softpipe->geometry_tex_cache[i] && - softpipe->geometry_tex_cache[i]->texture == texture) - return SP_REFERENCED_FOR_READ; + for (sh = 0; sh < Elements(softpipe->tex_cache); sh++) { + for (i = 0; i < Elements(softpipe->tex_cache[0]); i++) { + if (softpipe->tex_cache[sh][i] && + softpipe->tex_cache[sh][i]->texture == texture) + return SP_REFERENCED_FOR_READ; + } } return SP_UNREFERENCED; @@ -232,7 +229,7 @@ softpipe_create_context( struct pipe_screen *screen, { struct softpipe_screen *sp_screen = softpipe_screen(screen); struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context); - uint i; + uint i, sh; util_init_math(); @@ -274,22 +271,13 @@ softpipe_create_context( struct pipe_screen *screen, softpipe->cbuf_cache[i] = sp_create_tile_cache( &softpipe->pipe ); softpipe->zsbuf_cache = sp_create_tile_cache( &softpipe->pipe ); - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - softpipe->fragment_tex_cache[i] = sp_create_tex_tile_cache( &softpipe->pipe ); - if (!softpipe->fragment_tex_cache[i]) - goto fail; - } - - for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { - softpipe->vertex_tex_cache[i] = sp_create_tex_tile_cache( &softpipe->pipe ); - if (!softpipe->vertex_tex_cache[i]) - goto fail; - } - - for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) { - softpipe->geometry_tex_cache[i] = sp_create_tex_tile_cache( &softpipe->pipe ); - if (!softpipe->geometry_tex_cache[i]) - goto fail; + /* Allocate texture caches */ + for (sh = 0; sh < Elements(softpipe->tex_cache); sh++) { + for (i = 0; i < Elements(softpipe->tex_cache[0]); i++) { + softpipe->tex_cache[sh][i] = sp_create_tex_tile_cache(&softpipe->pipe); + if (!softpipe->tex_cache[sh][i]) + goto fail; + } } softpipe->fs_machine = tgsi_exec_machine_create(); diff --git a/src/gallium/drivers/softpipe/sp_context.h b/src/gallium/drivers/softpipe/sp_context.h index 7634254104b..95f5b769a5a 100644 --- a/src/gallium/drivers/softpipe/sp_context.h +++ b/src/gallium/drivers/softpipe/sp_context.h @@ -184,9 +184,13 @@ struct softpipe_context { struct softpipe_tile_cache *zsbuf_cache; unsigned tex_timestamp; - struct softpipe_tex_tile_cache *fragment_tex_cache[PIPE_MAX_SAMPLERS]; - struct softpipe_tex_tile_cache *vertex_tex_cache[PIPE_MAX_VERTEX_SAMPLERS]; - struct softpipe_tex_tile_cache *geometry_tex_cache[PIPE_MAX_GEOMETRY_SAMPLERS]; + + /* + * Texture caches for vertex, fragment, geometry stages. + * Don't use PIPE_SHADER_TYPES here to avoid allocating unused memory + * for compute shaders. + */ + struct softpipe_tex_tile_cache *tex_cache[PIPE_SHADER_GEOMETRY+1][PIPE_MAX_SAMPLERS]; unsigned dump_fs : 1; unsigned dump_gs : 1; diff --git a/src/gallium/drivers/softpipe/sp_flush.c b/src/gallium/drivers/softpipe/sp_flush.c index a2733e95878..4651e8bb56b 100644 --- a/src/gallium/drivers/softpipe/sp_flush.c +++ b/src/gallium/drivers/softpipe/sp_flush.c @@ -38,6 +38,7 @@ #include "sp_state.h" #include "sp_tile_cache.h" #include "sp_tex_tile_cache.h" +#include "util/u_memory.h" void @@ -52,13 +53,13 @@ softpipe_flush( struct pipe_context *pipe, if (flags & SP_FLUSH_TEXTURE_CACHE) { for (i = 0; i < softpipe->num_fragment_sampler_views; i++) { - sp_flush_tex_tile_cache(softpipe->fragment_tex_cache[i]); + sp_flush_tex_tile_cache(softpipe->tex_cache[PIPE_SHADER_FRAGMENT][i]); } for (i = 0; i < softpipe->num_vertex_sampler_views; i++) { - sp_flush_tex_tile_cache(softpipe->vertex_tex_cache[i]); + sp_flush_tex_tile_cache(softpipe->tex_cache[PIPE_SHADER_VERTEX][i]); } for (i = 0; i < softpipe->num_geometry_sampler_views; i++) { - sp_flush_tex_tile_cache(softpipe->geometry_tex_cache[i]); + sp_flush_tex_tile_cache(softpipe->tex_cache[PIPE_SHADER_GEOMETRY][i]); } } diff --git a/src/gallium/drivers/softpipe/sp_state_derived.c b/src/gallium/drivers/softpipe/sp_state_derived.c index b9b0f94289f..7fbff73f27d 100644 --- a/src/gallium/drivers/softpipe/sp_state_derived.c +++ b/src/gallium/drivers/softpipe/sp_state_derived.c @@ -207,46 +207,22 @@ compute_cliprect(struct softpipe_context *sp) static void update_tgsi_samplers( struct softpipe_context *softpipe ) { - unsigned i; + unsigned i, sh; softpipe_reset_sampler_variants( softpipe ); - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - struct softpipe_tex_tile_cache *tc = softpipe->fragment_tex_cache[i]; - if (tc && tc->texture) { - struct softpipe_resource *spt = softpipe_resource(tc->texture); - if (spt->timestamp != tc->timestamp) { - sp_tex_tile_cache_validate_texture( tc ); - /* - _debug_printf("INV %d %d\n", tc->timestamp, spt->timestamp); - */ - tc->timestamp = spt->timestamp; - } - } - } - - for (i = 0; i < PIPE_MAX_VERTEX_SAMPLERS; i++) { - struct softpipe_tex_tile_cache *tc = softpipe->vertex_tex_cache[i]; - - if (tc && tc->texture) { - struct softpipe_resource *spt = softpipe_resource(tc->texture); - - if (spt->timestamp != tc->timestamp) { - sp_tex_tile_cache_validate_texture(tc); - tc->timestamp = spt->timestamp; - } - } - } - - for (i = 0; i < PIPE_MAX_GEOMETRY_SAMPLERS; i++) { - struct softpipe_tex_tile_cache *tc = softpipe->geometry_tex_cache[i]; - - if (tc && tc->texture) { - struct softpipe_resource *spt = softpipe_resource(tc->texture); - - if (spt->timestamp != tc->timestamp) { - sp_tex_tile_cache_validate_texture(tc); - tc->timestamp = spt->timestamp; + for (sh = 0; sh < Elements(softpipe->tex_cache); sh++) { + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + struct softpipe_tex_tile_cache *tc = softpipe->tex_cache[sh][i]; + if (tc && tc->texture) { + struct softpipe_resource *spt = softpipe_resource(tc->texture); + if (spt->timestamp != tc->timestamp) { + sp_tex_tile_cache_validate_texture( tc ); + /* + _debug_printf("INV %d %d\n", tc->timestamp, spt->timestamp); + */ + tc->timestamp = spt->timestamp; + } } } } @@ -338,7 +314,7 @@ update_polygon_stipple_enable(struct softpipe_context *softpipe, unsigned prim) pipe_sampler_view_reference(&softpipe->fragment_sampler_views[unit], softpipe->pstipple.sampler_view); - sp_tex_tile_cache_set_sampler_view(softpipe->fragment_tex_cache[unit], + sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[PIPE_SHADER_FRAGMENT][unit], softpipe->pstipple.sampler_view); softpipe->dirty |= SP_NEW_SAMPLER; diff --git a/src/gallium/drivers/softpipe/sp_state_sampler.c b/src/gallium/drivers/softpipe/sp_state_sampler.c index 16023c990a7..260295d1ae5 100644 --- a/src/gallium/drivers/softpipe/sp_state_sampler.c +++ b/src/gallium/drivers/softpipe/sp_state_sampler.c @@ -202,7 +202,7 @@ softpipe_set_fragment_sampler_views(struct pipe_context *pipe, struct pipe_sampler_view *view = i < num ? views[i] : NULL; pipe_sampler_view_reference(&softpipe->fragment_sampler_views[i], view); - sp_tex_tile_cache_set_sampler_view(softpipe->fragment_tex_cache[i], view); + sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[PIPE_SHADER_FRAGMENT][i], view); } softpipe->num_fragment_sampler_views = num; @@ -233,7 +233,7 @@ softpipe_set_vertex_sampler_views(struct pipe_context *pipe, struct pipe_sampler_view *view = i < num ? views[i] : NULL; pipe_sampler_view_reference(&softpipe->vertex_sampler_views[i], view); - sp_tex_tile_cache_set_sampler_view(softpipe->vertex_tex_cache[i], view); + sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[PIPE_SHADER_VERTEX][i], view); } softpipe->num_vertex_sampler_views = num; @@ -268,7 +268,7 @@ softpipe_set_geometry_sampler_views(struct pipe_context *pipe, struct pipe_sampler_view *view = i < num ? views[i] : NULL; pipe_sampler_view_reference(&softpipe->geometry_sampler_views[i], view); - sp_tex_tile_cache_set_sampler_view(softpipe->geometry_tex_cache[i], view); + sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[PIPE_SHADER_GEOMETRY][i], view); } softpipe->num_geometry_sampler_views = num; @@ -350,7 +350,7 @@ softpipe_reset_sampler_variants(struct softpipe_context *softpipe) TGSI_PROCESSOR_VERTEX ); sp_sampler_variant_bind_view( softpipe->tgsi.vert_samplers_list[i], - softpipe->vertex_tex_cache[i], + softpipe->tex_cache[PIPE_SHADER_VERTEX][i], softpipe->vertex_sampler_views[i] ); } } @@ -367,7 +367,7 @@ softpipe_reset_sampler_variants(struct softpipe_context *softpipe) sp_sampler_variant_bind_view( softpipe->tgsi.geom_samplers_list[i], - softpipe->geometry_tex_cache[i], + softpipe->tex_cache[PIPE_SHADER_GEOMETRY][i], softpipe->geometry_sampler_views[i] ); } } @@ -383,7 +383,7 @@ softpipe_reset_sampler_variants(struct softpipe_context *softpipe) TGSI_PROCESSOR_FRAGMENT ); sp_sampler_variant_bind_view( softpipe->tgsi.frag_samplers_list[i], - softpipe->fragment_tex_cache[i], + softpipe->tex_cache[PIPE_SHADER_FRAGMENT][i], softpipe->fragment_sampler_views[i] ); } } |