aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/cso_cache
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2011-02-03 11:59:59 -0700
committerBrian Paul <[email protected]>2011-02-03 13:47:11 -0700
commitc5fb2c60bfe114d993da6c416a39c7873ab9cb3d (patch)
tree8ead79684b7545564e4e6c6d85b427b6523851a8 /src/gallium/auxiliary/cso_cache
parenta6a710cbe7425819e1cd5ad5f2085311c092f2e7 (diff)
cso: don't tell drivers to bind null samplers, sampler views
Before, the set_sampler_views() and restore_sampler_views() functions used MAX2(old,new) to tell the driver how many samplers or sampler views to set. This could result in cases such as: pipe->set_fragment_sampler_views(pipe, 4, views={foo, bar, NULL, NULL}) Many/most gallium drivers would take this as-is and set ctx->num_sampler_views=4 and ctx->sampler_views={foo, bar, NULL, NULL, ...}. Later, loops over ctx->num_sampler_views would have to check for null pointers. Worse, the number of sampler views and number of sampler CSOs could get out of sync: ctx->num_samplers = 2 ctx->samplers = {foo, bar, ...} ctx->num_sampler_views = 4 ctx->sampler_views={Foo, Bar, NULL, NULL, ...} So loops over the num_samplers could run into null sampler_views pointers or vice versa. This fixes a failed assertion in the SVGA driver when running the Mesa engine demo in AA line mode (and possibly other cases). It looks like all gallium drivers are careful to unreference views and null-out sampler CSO pointers for the units beyond what's set with the pipe::bind_x_sampler_states() and pipe::set_x_sampler_views() functions. I'll update the gallium docs to explain this as well.
Diffstat (limited to 'src/gallium/auxiliary/cso_cache')
-rw-r--r--src/gallium/auxiliary/cso_cache/cso_context.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index 195f6c7cdfe..9b148b2bdfd 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -1146,18 +1146,19 @@ set_sampler_views(struct cso_context *ctx,
{
uint i;
+ /* reference new views */
for (i = 0; i < count; i++) {
pipe_sampler_view_reference(&info->views[i], views[i]);
}
+ /* unref extra old views, if any */
for (; i < info->nr_views; i++) {
pipe_sampler_view_reference(&info->views[i], NULL);
}
- set_views(ctx->pipe,
- MAX2(count, info->nr_views),
- info->views);
-
info->nr_views = count;
+
+ /* bind the new sampler views */
+ set_views(ctx->pipe, count, info->views);
}
void
@@ -1226,9 +1227,8 @@ restore_sampler_views(struct cso_context *ctx,
pipe_sampler_view_reference(&info->views[i], NULL);
}
- set_views(ctx->pipe,
- MAX2(info->nr_views, info->nr_views_saved),
- info->views);
+ /* bind the old/saved sampler views */
+ set_views(ctx->pipe, info->nr_views_saved, info->views);
info->nr_views = info->nr_views_saved;
info->nr_views_saved = 0;