Mesa (main): cso: disallow NULL sampler state templates in cso_single_sampler
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Jun 27 13:07:33 UTC 2021
Module: Mesa
Branch: main
Commit: 426dd55d6c1b5f652064300ad31703f7e0550ef0
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=426dd55d6c1b5f652064300ad31703f7e0550ef0
Author: Marek Olšák <marek.olsak at amd.com>
Date: Sun Jun 6 16:27:36 2021 -0400
cso: disallow NULL sampler state templates in cso_single_sampler
No code passes NULL into this except the single place that is updated.
Let's remove the if. The next commit depends on this.
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11428>
---
src/gallium/auxiliary/cso_cache/cso_context.c | 59 ++++++++++++++-------------
1 file changed, 30 insertions(+), 29 deletions(-)
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index cc5e7a29771..2b84cec2d78 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -1183,38 +1183,35 @@ void
cso_single_sampler(struct cso_context *ctx, enum pipe_shader_type shader_stage,
unsigned idx, const struct pipe_sampler_state *templ)
{
- if (templ) {
- unsigned key_size = sizeof(struct pipe_sampler_state);
- unsigned hash_key = cso_construct_key((void*)templ, key_size);
- struct cso_sampler *cso;
- struct cso_hash_iter iter =
- cso_find_state_template(&ctx->cache,
- hash_key, CSO_SAMPLER,
- (void *) templ, key_size);
+ unsigned key_size = sizeof(struct pipe_sampler_state);
+ unsigned hash_key = cso_construct_key((void*)templ, key_size);
+ struct cso_sampler *cso;
+ struct cso_hash_iter iter =
+ cso_find_state_template(&ctx->cache,
+ hash_key, CSO_SAMPLER,
+ (void *) templ, key_size);
+
+ if (cso_hash_iter_is_null(iter)) {
+ cso = MALLOC(sizeof(struct cso_sampler));
+ if (!cso)
+ return;
+
+ memcpy(&cso->state, templ, sizeof(*templ));
+ cso->data = ctx->pipe->create_sampler_state(ctx->pipe, &cso->state);
+ cso->hash_key = hash_key;
+ iter = cso_insert_state(&ctx->cache, hash_key, CSO_SAMPLER, cso);
if (cso_hash_iter_is_null(iter)) {
- cso = MALLOC(sizeof(struct cso_sampler));
- if (!cso)
- return;
-
- memcpy(&cso->state, templ, sizeof(*templ));
- cso->data = ctx->pipe->create_sampler_state(ctx->pipe, &cso->state);
- cso->hash_key = hash_key;
-
- iter = cso_insert_state(&ctx->cache, hash_key, CSO_SAMPLER, cso);
- if (cso_hash_iter_is_null(iter)) {
- FREE(cso);
- return;
- }
- }
- else {
- cso = cso_hash_iter_data(iter);
+ FREE(cso);
+ return;
}
-
- ctx->samplers[shader_stage].cso_samplers[idx] = cso;
- ctx->samplers[shader_stage].samplers[idx] = cso->data;
- ctx->max_sampler_seen = MAX2(ctx->max_sampler_seen, (int)idx);
+ } else {
+ cso = cso_hash_iter_data(iter);
}
+
+ ctx->samplers[shader_stage].cso_samplers[idx] = cso;
+ ctx->samplers[shader_stage].samplers[idx] = cso->data;
+ ctx->max_sampler_seen = MAX2(ctx->max_sampler_seen, (int)idx);
}
@@ -1248,8 +1245,12 @@ cso_set_samplers(struct cso_context *ctx,
unsigned nr,
const struct pipe_sampler_state **templates)
{
- for (unsigned i = 0; i < nr; i++)
+ for (unsigned i = 0; i < nr; i++) {
+ if (!templates[i])
+ continue;
+
cso_single_sampler(ctx, shader_stage, i, templates[i]);
+ }
cso_single_sampler_done(ctx, shader_stage);
}
More information about the mesa-commit
mailing list