This lets us consolidate some code now, and more in subsequent patches.
Reviewed-by: José Fonseca <jfonseca@vmware.com>
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)
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);
}
}
}
unsigned level, int layer)
{
struct softpipe_context *softpipe = softpipe_context( pipe );
- unsigned i;
+ unsigned i, sh;
if (texture->target == PIPE_BUFFER)
return SP_UNREFERENCED;
}
/* 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;
{
struct softpipe_screen *sp_screen = softpipe_screen(screen);
struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);
- uint i;
+ uint i, sh;
util_init_math();
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();
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;
#include "sp_state.h"
#include "sp_tile_cache.h"
#include "sp_tex_tile_cache.h"
+#include "util/u_memory.h"
void
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]);
}
}
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;
+ }
}
}
}
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;
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;
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;
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;
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] );
}
}
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] );
}
}
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] );
}
}