cso: only allow saving and restoring fragment sampler views

Not needed for other shader stages.
This commit is contained in:
Marek Olšák
2015-07-05 15:53:10 +02:00
parent 2d8213bfa9
commit 3639d66a47
7 changed files with 63 additions and 64 deletions

View File

@@ -66,12 +66,6 @@ struct sampler_info
void *samplers_saved[PIPE_MAX_SAMPLERS];
unsigned nr_samplers_saved;
struct pipe_sampler_view *views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
unsigned nr_views;
struct pipe_sampler_view *views_saved[PIPE_MAX_SHADER_SAMPLER_VIEWS];
unsigned nr_views_saved;
};
@@ -85,6 +79,12 @@ struct cso_context {
boolean has_tessellation;
boolean has_streamout;
struct pipe_sampler_view *fragment_views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
unsigned nr_fragment_views;
struct pipe_sampler_view *fragment_views_saved[PIPE_MAX_SHADER_SAMPLER_VIEWS];
unsigned nr_fragment_views_saved;
struct sampler_info samplers[PIPE_SHADER_TYPES];
struct pipe_vertex_buffer aux_vertex_buffer_current;
@@ -297,7 +297,7 @@ out:
*/
void cso_destroy_context( struct cso_context *ctx )
{
unsigned i, shader;
unsigned i;
if (ctx->pipe) {
ctx->pipe->set_index_buffer(ctx->pipe, NULL);
@@ -347,13 +347,9 @@ void cso_destroy_context( struct cso_context *ctx )
ctx->pipe->set_stream_output_targets(ctx->pipe, 0, NULL, NULL);
}
/* free sampler views for each shader stage */
for (shader = 0; shader < Elements(ctx->samplers); shader++) {
struct sampler_info *info = &ctx->samplers[shader];
for (i = 0; i < PIPE_MAX_SHADER_SAMPLER_VIEWS; i++) {
pipe_sampler_view_reference(&info->views[i], NULL);
pipe_sampler_view_reference(&info->views_saved[i], NULL);
}
pipe_sampler_view_reference(&ctx->fragment_views[i], NULL);
pipe_sampler_view_reference(&ctx->fragment_views_saved[i], NULL);
}
util_unreference_framebuffer_state(&ctx->fb);
@@ -1281,71 +1277,74 @@ cso_set_sampler_views(struct cso_context *ctx,
unsigned count,
struct pipe_sampler_view **views)
{
struct sampler_info *info = &ctx->samplers[shader_stage];
if (shader_stage == PIPE_SHADER_FRAGMENT) {
unsigned i;
boolean any_change = FALSE;
/* reference new views */
for (i = 0; i < count; i++) {
any_change |= info->views[i] != views[i];
pipe_sampler_view_reference(&info->views[i], views[i]);
any_change |= ctx->fragment_views[i] != views[i];
pipe_sampler_view_reference(&ctx->fragment_views[i], views[i]);
}
/* unref extra old views, if any */
for (; i < info->nr_views; i++) {
any_change |= info->views[i] != NULL;
pipe_sampler_view_reference(&info->views[i], NULL);
for (; i < ctx->nr_fragment_views; i++) {
any_change |= ctx->fragment_views[i] != NULL;
pipe_sampler_view_reference(&ctx->fragment_views[i], NULL);
}
/* bind the new sampler views */
if (any_change) {
ctx->pipe->set_sampler_views(ctx->pipe, shader_stage, 0,
MAX2(info->nr_views, count),
info->views);
MAX2(ctx->nr_fragment_views, count),
ctx->fragment_views);
}
info->nr_views = count;
ctx->nr_fragment_views = count;
}
else
ctx->pipe->set_sampler_views(ctx->pipe, shader_stage, 0, count, views);
}
void
cso_save_sampler_views(struct cso_context *ctx, unsigned shader_stage)
cso_save_fragment_sampler_views(struct cso_context *ctx)
{
struct sampler_info *info = &ctx->samplers[shader_stage];
unsigned i;
info->nr_views_saved = info->nr_views;
ctx->nr_fragment_views_saved = ctx->nr_fragment_views;
for (i = 0; i < info->nr_views; i++) {
assert(!info->views_saved[i]);
pipe_sampler_view_reference(&info->views_saved[i], info->views[i]);
for (i = 0; i < ctx->nr_fragment_views; i++) {
assert(!ctx->fragment_views_saved[i]);
pipe_sampler_view_reference(&ctx->fragment_views_saved[i],
ctx->fragment_views[i]);
}
}
void
cso_restore_sampler_views(struct cso_context *ctx, unsigned shader_stage)
cso_restore_fragment_sampler_views(struct cso_context *ctx)
{
struct sampler_info *info = &ctx->samplers[shader_stage];
unsigned i, nr_saved = info->nr_views_saved;
unsigned i, nr_saved = ctx->nr_fragment_views_saved;
unsigned num;
for (i = 0; i < nr_saved; i++) {
pipe_sampler_view_reference(&info->views[i], NULL);
pipe_sampler_view_reference(&ctx->fragment_views[i], NULL);
/* move the reference from one pointer to another */
info->views[i] = info->views_saved[i];
info->views_saved[i] = NULL;
ctx->fragment_views[i] = ctx->fragment_views_saved[i];
ctx->fragment_views_saved[i] = NULL;
}
for (; i < info->nr_views; i++) {
pipe_sampler_view_reference(&info->views[i], NULL);
for (; i < ctx->nr_fragment_views; i++) {
pipe_sampler_view_reference(&ctx->fragment_views[i], NULL);
}
num = MAX2(info->nr_views, nr_saved);
num = MAX2(ctx->nr_fragment_views, nr_saved);
/* bind the old/saved sampler views */
ctx->pipe->set_sampler_views(ctx->pipe, shader_stage, 0, num, info->views);
ctx->pipe->set_sampler_views(ctx->pipe, PIPE_SHADER_FRAGMENT, 0, num,
ctx->fragment_views);
info->nr_views = nr_saved;
info->nr_views_saved = 0;
ctx->nr_fragment_views = nr_saved;
ctx->nr_fragment_views_saved = 0;
}

View File

@@ -210,10 +210,10 @@ cso_set_sampler_views(struct cso_context *cso,
struct pipe_sampler_view **views);
void
cso_save_sampler_views(struct cso_context *cso, unsigned shader_stage);
cso_save_fragment_sampler_views(struct cso_context *ctx);
void
cso_restore_sampler_views(struct cso_context *cso, unsigned shader_stage);
cso_restore_fragment_sampler_views(struct cso_context *ctx);
/* constant buffers */

View File

@@ -437,7 +437,7 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
cso_save_blend(cso);
cso_save_depth_stencil_alpha(cso);
cso_save_fragment_shader(cso);
cso_save_sampler_views(cso, PIPE_SHADER_FRAGMENT);
cso_save_fragment_sampler_views(cso);
cso_save_samplers(cso, PIPE_SHADER_FRAGMENT);
cso_save_rasterizer(cso);
cso_save_viewport(cso);
@@ -567,7 +567,7 @@ hud_draw(struct hud_context *hud, struct pipe_resource *tex)
cso_restore_blend(cso);
cso_restore_depth_stencil_alpha(cso);
cso_restore_fragment_shader(cso);
cso_restore_sampler_views(cso, PIPE_SHADER_FRAGMENT);
cso_restore_fragment_sampler_views(cso);
cso_restore_samplers(cso, PIPE_SHADER_FRAGMENT);
cso_restore_rasterizer(cso);
cso_restore_viewport(cso);

View File

@@ -126,7 +126,7 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
cso_save_sample_mask(cso);
cso_save_min_samples(cso);
cso_save_samplers(cso, PIPE_SHADER_FRAGMENT);
cso_save_sampler_views(cso, PIPE_SHADER_FRAGMENT);
cso_save_fragment_sampler_views(cso);
cso_save_stencil_ref(cso);
cso_save_stream_outputs(cso);
cso_save_vertex_elements(cso);
@@ -197,7 +197,7 @@ pp_run(struct pp_queue_t *ppq, struct pipe_resource *in,
cso_restore_sample_mask(cso);
cso_restore_min_samples(cso);
cso_restore_samplers(cso, PIPE_SHADER_FRAGMENT);
cso_restore_sampler_views(cso, PIPE_SHADER_FRAGMENT);
cso_restore_fragment_sampler_views(cso);
cso_restore_stencil_ref(cso);
cso_restore_stream_outputs(cso);
cso_restore_vertex_elements(cso);

View File

@@ -547,7 +547,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
cso_save_sample_mask(ctx->cso);
cso_save_min_samples(ctx->cso);
cso_save_samplers(ctx->cso, PIPE_SHADER_FRAGMENT);
cso_save_sampler_views(ctx->cso, PIPE_SHADER_FRAGMENT);
cso_save_fragment_sampler_views(ctx->cso);
cso_save_stream_outputs(ctx->cso);
cso_save_viewport(ctx->cso);
cso_save_framebuffer(ctx->cso);
@@ -629,7 +629,7 @@ util_blit_pixels_tex(struct blit_state *ctx,
cso_restore_sample_mask(ctx->cso);
cso_restore_min_samples(ctx->cso);
cso_restore_samplers(ctx->cso, PIPE_SHADER_FRAGMENT);
cso_restore_sampler_views(ctx->cso, PIPE_SHADER_FRAGMENT);
cso_restore_fragment_sampler_views(ctx->cso);
cso_restore_viewport(ctx->cso);
cso_restore_framebuffer(ctx->cso);
cso_restore_fragment_shader(ctx->cso);

View File

@@ -447,7 +447,7 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
cso_save_rasterizer(cso);
cso_save_samplers(cso, PIPE_SHADER_FRAGMENT);
cso_save_sampler_views(cso, PIPE_SHADER_FRAGMENT);
cso_save_fragment_sampler_views(cso);
cso_save_viewport(cso);
cso_save_fragment_shader(cso);
cso_save_stream_outputs(cso);
@@ -536,7 +536,7 @@ draw_bitmap_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
/* restore state */
cso_restore_rasterizer(cso);
cso_restore_samplers(cso, PIPE_SHADER_FRAGMENT);
cso_restore_sampler_views(cso, PIPE_SHADER_FRAGMENT);
cso_restore_fragment_sampler_views(cso);
cso_restore_viewport(cso);
cso_restore_fragment_shader(cso);
cso_restore_vertex_shader(cso);

View File

@@ -690,7 +690,7 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
cso_save_rasterizer(cso);
cso_save_viewport(cso);
cso_save_samplers(cso, PIPE_SHADER_FRAGMENT);
cso_save_sampler_views(cso, PIPE_SHADER_FRAGMENT);
cso_save_fragment_sampler_views(cso);
cso_save_fragment_shader(cso);
cso_save_stream_outputs(cso);
cso_save_vertex_shader(cso);
@@ -818,7 +818,7 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
cso_restore_rasterizer(cso);
cso_restore_viewport(cso);
cso_restore_samplers(cso, PIPE_SHADER_FRAGMENT);
cso_restore_sampler_views(cso, PIPE_SHADER_FRAGMENT);
cso_restore_fragment_sampler_views(cso);
cso_restore_fragment_shader(cso);
cso_restore_vertex_shader(cso);
cso_restore_tessctrl_shader(cso);