diff options
Diffstat (limited to 'src/gallium/auxiliary/cso_cache')
-rw-r--r-- | src/gallium/auxiliary/cso_cache/cso_context.c | 241 | ||||
-rw-r--r-- | src/gallium/auxiliary/cso_cache/cso_context.h | 79 |
2 files changed, 108 insertions, 212 deletions
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c index 7f2dc431ae5..c9a9fef737f 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.c +++ b/src/gallium/auxiliary/cso_cache/cso_context.c @@ -84,8 +84,7 @@ struct cso_context { boolean has_geometry_shader; boolean has_streamout; - struct sampler_info fragment_samplers; - struct sampler_info vertex_samplers; + struct sampler_info samplers[PIPE_SHADER_TYPES]; uint nr_vertex_buffers; struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; @@ -296,8 +295,7 @@ out: */ void cso_release_all( struct cso_context *ctx ) { - unsigned i; - struct sampler_info *info; + unsigned i, shader; if (ctx->pipe) { ctx->pipe->bind_blend_state( ctx->pipe, NULL ); @@ -317,17 +315,12 @@ void cso_release_all( struct cso_context *ctx ) } /* free fragment samplers, views */ - info = &ctx->fragment_samplers; - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - pipe_sampler_view_reference(&info->views[i], NULL); - pipe_sampler_view_reference(&info->views_saved[i], NULL); - } - - /* free vertex samplers, views */ - info = &ctx->vertex_samplers; - for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { - pipe_sampler_view_reference(&info->views[i], NULL); - pipe_sampler_view_reference(&info->views_saved[i], NULL); + for (shader = 0; shader < Elements(ctx->samplers); shader++) { + struct sampler_info *info = &ctx->samplers[shader]; + for (i = 0; i < PIPE_MAX_SAMPLERS; i++) { + pipe_sampler_view_reference(&info->views[i], NULL); + pipe_sampler_view_reference(&info->views_saved[i], NULL); + } } util_unreference_framebuffer_state(&ctx->fb); @@ -993,26 +986,19 @@ single_sampler(struct cso_context *ctx, enum pipe_error cso_single_sampler(struct cso_context *ctx, + unsigned shader_stage, unsigned idx, const struct pipe_sampler_state *templ) { - return single_sampler(ctx, &ctx->fragment_samplers, idx, templ); -} - -enum pipe_error -cso_single_vertex_sampler(struct cso_context *ctx, - unsigned idx, - const struct pipe_sampler_state *templ) -{ - return single_sampler(ctx, &ctx->vertex_samplers, idx, templ); + return single_sampler(ctx, &ctx->samplers[shader_stage], idx, templ); } static void -single_sampler_done(struct cso_context *ctx, - struct sampler_info *info) +single_sampler_done(struct cso_context *ctx, unsigned shader_stage) { + struct sampler_info *info = &ctx->samplers[shader_stage]; unsigned i; /* find highest non-null sampler */ @@ -1033,32 +1019,32 @@ single_sampler_done(struct cso_context *ctx, info->nr_samplers * sizeof(void *)); info->hw.nr_samplers = info->nr_samplers; - if (info == &ctx->fragment_samplers) { + switch (shader_stage) { + case PIPE_SHADER_FRAGMENT: ctx->pipe->bind_fragment_sampler_states(ctx->pipe, info->nr_samplers, info->samplers); - } - else if (info == &ctx->vertex_samplers) { + break; + case PIPE_SHADER_VERTEX: ctx->pipe->bind_vertex_sampler_states(ctx->pipe, info->nr_samplers, info->samplers); - } - else { - assert(0); + break; + case PIPE_SHADER_GEOMETRY: + ctx->pipe->bind_geometry_sampler_states(ctx->pipe, + info->nr_samplers, + info->samplers); + break; + default: + assert(!"bad shader type in single_sampler_done()"); } } } void -cso_single_sampler_done( struct cso_context *ctx ) -{ - single_sampler_done(ctx, &ctx->fragment_samplers); -} - -void -cso_single_vertex_sampler_done(struct cso_context *ctx) +cso_single_sampler_done(struct cso_context *ctx, unsigned shader_stage) { - single_sampler_done(ctx, &ctx->vertex_samplers); + single_sampler_done(ctx, shader_stage); } @@ -1067,12 +1053,13 @@ cso_single_vertex_sampler_done(struct cso_context *ctx) * last one. Done to always try to set as many samplers * as possible. */ -static enum pipe_error -set_samplers(struct cso_context *ctx, - struct sampler_info *info, - unsigned nr, - const struct pipe_sampler_state **templates) +enum pipe_error +cso_set_samplers(struct cso_context *ctx, + unsigned shader_stage, + unsigned nr, + const struct pipe_sampler_state **templates) { + struct sampler_info *info = &ctx->samplers[shader_stage]; unsigned i; enum pipe_error temp, error = PIPE_OK; @@ -1091,82 +1078,38 @@ set_samplers(struct cso_context *ctx, error = temp; } - single_sampler_done(ctx, info); + single_sampler_done(ctx, shader_stage); return error; } -enum pipe_error -cso_set_samplers(struct cso_context *ctx, - unsigned nr, - const struct pipe_sampler_state **templates) -{ - return set_samplers(ctx, &ctx->fragment_samplers, nr, templates); -} - -enum pipe_error -cso_set_vertex_samplers(struct cso_context *ctx, - unsigned nr, - const struct pipe_sampler_state **templates) -{ - return set_samplers(ctx, &ctx->vertex_samplers, nr, templates); -} - - - -static void -save_samplers(struct cso_context *ctx, struct sampler_info *info) +void +cso_save_samplers(struct cso_context *ctx, unsigned shader_stage) { + struct sampler_info *info = &ctx->samplers[shader_stage]; info->nr_samplers_saved = info->nr_samplers; memcpy(info->samplers_saved, info->samplers, sizeof(info->samplers)); } -void -cso_save_samplers(struct cso_context *ctx) -{ - save_samplers(ctx, &ctx->fragment_samplers); -} void -cso_save_vertex_samplers(struct cso_context *ctx) -{ - save_samplers(ctx, &ctx->vertex_samplers); -} - - - -static void -restore_samplers(struct cso_context *ctx, struct sampler_info *info) +cso_restore_samplers(struct cso_context *ctx, unsigned shader_stage) { + struct sampler_info *info = &ctx->samplers[shader_stage]; info->nr_samplers = info->nr_samplers_saved; memcpy(info->samplers, info->samplers_saved, sizeof(info->samplers)); - single_sampler_done(ctx, info); + single_sampler_done(ctx, shader_stage); } -void -cso_restore_samplers(struct cso_context *ctx) -{ - restore_samplers(ctx, &ctx->fragment_samplers); -} void -cso_restore_vertex_samplers(struct cso_context *ctx) +cso_set_sampler_views(struct cso_context *ctx, + unsigned shader_stage, + unsigned count, + struct pipe_sampler_view **views) { - restore_samplers(ctx, &ctx->vertex_samplers); -} - - - -static void -set_sampler_views(struct cso_context *ctx, - struct sampler_info *info, - void (*set_views)(struct pipe_context *, - unsigned num_views, - struct pipe_sampler_view **), - uint count, - struct pipe_sampler_view **views) -{ - uint i; + struct sampler_info *info = &ctx->samplers[shader_stage]; + unsigned i; /* reference new views */ for (i = 0; i < count; i++) { @@ -1180,36 +1123,27 @@ set_sampler_views(struct cso_context *ctx, info->nr_views = count; /* bind the new sampler views */ - set_views(ctx->pipe, count, info->views); + switch (shader_stage) { + case PIPE_SHADER_FRAGMENT: + ctx->pipe->set_fragment_sampler_views(ctx->pipe, count, info->views); + break; + case PIPE_SHADER_VERTEX: + ctx->pipe->set_vertex_sampler_views(ctx->pipe, count, info->views); + break; + case PIPE_SHADER_GEOMETRY: + ctx->pipe->set_geometry_sampler_views(ctx->pipe, count, info->views); + break; + default: + assert(!"bad shader type in cso_set_sampler_views()"); + } } -void -cso_set_fragment_sampler_views(struct cso_context *ctx, - uint count, - struct pipe_sampler_view **views) -{ - set_sampler_views(ctx, &ctx->fragment_samplers, - ctx->pipe->set_fragment_sampler_views, - count, views); -} void -cso_set_vertex_sampler_views(struct cso_context *ctx, - uint count, - struct pipe_sampler_view **views) -{ - set_sampler_views(ctx, &ctx->vertex_samplers, - ctx->pipe->set_vertex_sampler_views, - count, views); -} - - - -static void -save_sampler_views(struct cso_context *ctx, - struct sampler_info *info) +cso_save_sampler_views(struct cso_context *ctx, unsigned shader_stage) { - uint i; + struct sampler_info *info = &ctx->samplers[shader_stage]; + unsigned i; info->nr_views_saved = info->nr_views; @@ -1219,29 +1153,14 @@ save_sampler_views(struct cso_context *ctx, } } -void -cso_save_fragment_sampler_views(struct cso_context *ctx) -{ - save_sampler_views(ctx, &ctx->fragment_samplers); -} void -cso_save_vertex_sampler_views(struct cso_context *ctx) +cso_restore_sampler_views(struct cso_context *ctx, unsigned shader_stage) { - save_sampler_views(ctx, &ctx->vertex_samplers); -} + struct sampler_info *info = &ctx->samplers[shader_stage]; + unsigned i, nr_saved = info->nr_views_saved; - -static void -restore_sampler_views(struct cso_context *ctx, - struct sampler_info *info, - void (*set_views)(struct pipe_context *, - unsigned num_views, - struct pipe_sampler_view **)) -{ - uint i; - - for (i = 0; i < info->nr_views_saved; i++) { + for (i = 0; i < nr_saved; i++) { pipe_sampler_view_reference(&info->views[i], NULL); /* move the reference from one pointer to another */ info->views[i] = info->views_saved[i]; @@ -1252,26 +1171,24 @@ restore_sampler_views(struct cso_context *ctx, } /* bind the old/saved sampler views */ - set_views(ctx->pipe, info->nr_views_saved, info->views); + switch (shader_stage) { + case PIPE_SHADER_FRAGMENT: + ctx->pipe->set_fragment_sampler_views(ctx->pipe, nr_saved, info->views); + break; + case PIPE_SHADER_VERTEX: + ctx->pipe->set_vertex_sampler_views(ctx->pipe, nr_saved, info->views); + break; + case PIPE_SHADER_GEOMETRY: + ctx->pipe->set_geometry_sampler_views(ctx->pipe, nr_saved, info->views); + break; + default: + assert(!"bad shader type in cso_restore_sampler_views()"); + } - info->nr_views = info->nr_views_saved; + info->nr_views = nr_saved; info->nr_views_saved = 0; } -void -cso_restore_fragment_sampler_views(struct cso_context *ctx) -{ - restore_sampler_views(ctx, &ctx->fragment_samplers, - ctx->pipe->set_fragment_sampler_views); -} - -void -cso_restore_vertex_sampler_views(struct cso_context *ctx) -{ - restore_sampler_views(ctx, &ctx->vertex_samplers, - ctx->pipe->set_vertex_sampler_views); -} - void cso_set_stream_outputs(struct cso_context *ctx, diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h index 4de08a8364c..f01a0f20c62 100644 --- a/src/gallium/auxiliary/cso_cache/cso_context.h +++ b/src/gallium/auxiliary/cso_cache/cso_context.h @@ -69,39 +69,29 @@ void cso_save_rasterizer(struct cso_context *cso); void cso_restore_rasterizer(struct cso_context *cso); - -enum pipe_error cso_set_samplers( struct cso_context *cso, - unsigned count, - const struct pipe_sampler_state **states ); -void cso_save_samplers(struct cso_context *cso); -void cso_restore_samplers(struct cso_context *cso); - -/* Alternate interface to support state trackers that like to modify - * samplers one at a time: - */ -enum pipe_error cso_single_sampler( struct cso_context *cso, - unsigned nr, - const struct pipe_sampler_state *states ); - -void cso_single_sampler_done( struct cso_context *cso ); - -enum pipe_error cso_set_vertex_samplers(struct cso_context *cso, - unsigned count, - const struct pipe_sampler_state **states); +enum pipe_error +cso_set_samplers(struct cso_context *cso, + unsigned shader_stage, + unsigned count, + const struct pipe_sampler_state **states); void -cso_save_vertex_samplers(struct cso_context *cso); +cso_save_samplers(struct cso_context *cso, unsigned shader_stage); void -cso_restore_vertex_samplers(struct cso_context *cso); +cso_restore_samplers(struct cso_context *cso, unsigned shader_stage); +/* Alternate interface to support state trackers that like to modify + * samplers one at a time: + */ enum pipe_error -cso_single_vertex_sampler(struct cso_context *cso, - unsigned nr, - const struct pipe_sampler_state *states); +cso_single_sampler(struct cso_context *cso, + unsigned shader_stage, + unsigned count, + const struct pipe_sampler_state *states); void -cso_single_vertex_sampler_done(struct cso_context *cso); +cso_single_sampler_done(struct cso_context *cso, unsigned shader_stage); enum pipe_error cso_set_vertex_elements(struct cso_context *ctx, @@ -126,6 +116,13 @@ void cso_save_stream_outputs(struct cso_context *ctx); void cso_restore_stream_outputs(struct cso_context *ctx); +/* + * We don't provide shader caching in CSO. Most of the time the api provides + * object semantics for shaders anyway, and the cases where it doesn't + * (eg mesa's internally-generated texenv programs), it will be up to + * the state tracker to implement their own specialized caching. + */ + enum pipe_error cso_set_fragment_shader_handle(struct cso_context *ctx, void *handle ); void cso_delete_fragment_shader(struct cso_context *ctx, void *handle ); @@ -184,39 +181,21 @@ void cso_restore_clip(struct cso_context *cso); -/* fragment sampler view state */ - -/* - * We don't provide shader caching in CSO. Most of the time the api provides - * object semantics for shaders anyway, and the cases where it doesn't - * (eg mesa's internally-generated texenv programs), it will be up to - * the state tracker to implement their own specialized caching. - */ - -void -cso_set_fragment_sampler_views(struct cso_context *cso, - uint count, - struct pipe_sampler_view **views); +/* sampler view state */ void -cso_save_fragment_sampler_views(struct cso_context *cso); +cso_set_sampler_views(struct cso_context *cso, + unsigned shader_stage, + unsigned count, + struct pipe_sampler_view **views); void -cso_restore_fragment_sampler_views(struct cso_context *cso); - - -/* vertex sampler view state */ +cso_save_sampler_views(struct cso_context *cso, unsigned shader_stage); void -cso_set_vertex_sampler_views(struct cso_context *cso, - uint count, - struct pipe_sampler_view **views); +cso_restore_sampler_views(struct cso_context *cso, unsigned shader_stage); -void -cso_save_vertex_sampler_views(struct cso_context *cso); -void -cso_restore_vertex_sampler_views(struct cso_context *cso); /* drawing */ |