cso: inline struct cso_cache to remove dereferences
Reviewed-by: Eric Anholt <eric@anholt.net> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7901>
This commit is contained in:
parent
8904fcca6d
commit
d23f45577e
|
@ -36,14 +36,6 @@
|
||||||
#include "cso_hash.h"
|
#include "cso_hash.h"
|
||||||
|
|
||||||
|
|
||||||
struct cso_cache {
|
|
||||||
struct cso_hash hashes[CSO_CACHE_MAX];
|
|
||||||
int max_size;
|
|
||||||
|
|
||||||
cso_sanitize_callback sanitize_cb;
|
|
||||||
void *sanitize_data;
|
|
||||||
};
|
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
static unsigned hash_key(const void *key, unsigned key_size)
|
static unsigned hash_key(const void *key, unsigned key_size)
|
||||||
{
|
{
|
||||||
|
@ -234,21 +226,16 @@ struct cso_hash_iter cso_find_state_template(struct cso_cache *sc,
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cso_cache *cso_cache_create(void)
|
void cso_cache_init(struct cso_cache *sc)
|
||||||
{
|
{
|
||||||
struct cso_cache *sc = MALLOC_STRUCT(cso_cache);
|
memset(sc, 0, sizeof(*sc));
|
||||||
int i;
|
|
||||||
if (!sc)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
sc->max_size = 4096;
|
sc->max_size = 4096;
|
||||||
for (i = 0; i < CSO_CACHE_MAX; i++)
|
for (int i = 0; i < CSO_CACHE_MAX; i++)
|
||||||
cso_hash_init(&sc->hashes[i]);
|
cso_hash_init(&sc->hashes[i]);
|
||||||
|
|
||||||
sc->sanitize_cb = sanitize_cb;
|
sc->sanitize_cb = sanitize_cb;
|
||||||
sc->sanitize_data = 0;
|
sc->sanitize_data = 0;
|
||||||
|
|
||||||
return sc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type,
|
void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type,
|
||||||
|
@ -270,10 +257,6 @@ void cso_for_each_state(struct cso_cache *sc, enum cso_cache_type type,
|
||||||
void cso_cache_delete(struct cso_cache *sc)
|
void cso_cache_delete(struct cso_cache *sc)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
assert(sc);
|
|
||||||
|
|
||||||
if (!sc)
|
|
||||||
return;
|
|
||||||
|
|
||||||
/* delete driver data */
|
/* delete driver data */
|
||||||
cso_for_each_state(sc, CSO_BLEND, delete_blend_state, 0);
|
cso_for_each_state(sc, CSO_BLEND, delete_blend_state, 0);
|
||||||
|
@ -284,8 +267,6 @@ void cso_cache_delete(struct cso_cache *sc)
|
||||||
|
|
||||||
for (i = 0; i < CSO_CACHE_MAX; i++)
|
for (i = 0; i < CSO_CACHE_MAX; i++)
|
||||||
cso_hash_deinit(&sc->hashes[i]);
|
cso_hash_deinit(&sc->hashes[i]);
|
||||||
|
|
||||||
FREE(sc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cso_set_maximum_cache_size(struct cso_cache *sc, int number)
|
void cso_set_maximum_cache_size(struct cso_cache *sc, int number)
|
||||||
|
|
|
@ -101,7 +101,13 @@ typedef void (*cso_sanitize_callback)(struct cso_hash *hash,
|
||||||
int max_size,
|
int max_size,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
struct cso_cache;
|
struct cso_cache {
|
||||||
|
struct cso_hash hashes[CSO_CACHE_MAX];
|
||||||
|
int max_size;
|
||||||
|
|
||||||
|
cso_sanitize_callback sanitize_cb;
|
||||||
|
void *sanitize_data;
|
||||||
|
};
|
||||||
|
|
||||||
struct cso_blend {
|
struct cso_blend {
|
||||||
struct pipe_blend_state state;
|
struct pipe_blend_state state;
|
||||||
|
@ -146,7 +152,7 @@ struct cso_velements {
|
||||||
|
|
||||||
unsigned cso_construct_key(void *item, int item_size);
|
unsigned cso_construct_key(void *item, int item_size);
|
||||||
|
|
||||||
struct cso_cache *cso_cache_create(void);
|
void cso_cache_init(struct cso_cache *sc);
|
||||||
void cso_cache_delete(struct cso_cache *sc);
|
void cso_cache_delete(struct cso_cache *sc);
|
||||||
|
|
||||||
void cso_cache_set_sanitize_callback(struct cso_cache *sc,
|
void cso_cache_set_sanitize_callback(struct cso_cache *sc,
|
||||||
|
|
|
@ -63,7 +63,6 @@ struct sampler_info
|
||||||
|
|
||||||
struct cso_context {
|
struct cso_context {
|
||||||
struct pipe_context *pipe;
|
struct pipe_context *pipe;
|
||||||
struct cso_cache *cache;
|
|
||||||
|
|
||||||
struct u_vbuf *vbuf;
|
struct u_vbuf *vbuf;
|
||||||
struct u_vbuf *vbuf_current;
|
struct u_vbuf *vbuf_current;
|
||||||
|
@ -128,6 +127,9 @@ struct cso_context {
|
||||||
unsigned sample_mask, sample_mask_saved;
|
unsigned sample_mask, sample_mask_saved;
|
||||||
unsigned min_samples, min_samples_saved;
|
unsigned min_samples, min_samples_saved;
|
||||||
struct pipe_stencil_ref stencil_ref, stencil_ref_saved;
|
struct pipe_stencil_ref stencil_ref, stencil_ref_saved;
|
||||||
|
|
||||||
|
/* This should be last to keep all of the above together in memory. */
|
||||||
|
struct cso_cache cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct pipe_context *cso_get_pipe_context(struct cso_context *cso)
|
struct pipe_context *cso_get_pipe_context(struct cso_context *cso)
|
||||||
|
@ -312,12 +314,8 @@ cso_create_context(struct pipe_context *pipe, unsigned flags)
|
||||||
if (!ctx)
|
if (!ctx)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
ctx->cache = cso_cache_create();
|
cso_cache_init(&ctx->cache);
|
||||||
if (ctx->cache == NULL)
|
cso_cache_set_sanitize_callback(&ctx->cache, sanitize_hash, ctx);
|
||||||
goto out;
|
|
||||||
cso_cache_set_sanitize_callback(ctx->cache,
|
|
||||||
sanitize_hash,
|
|
||||||
ctx);
|
|
||||||
|
|
||||||
ctx->pipe = pipe;
|
ctx->pipe = pipe;
|
||||||
ctx->sample_mask = ~0;
|
ctx->sample_mask = ~0;
|
||||||
|
@ -325,7 +323,7 @@ cso_create_context(struct pipe_context *pipe, unsigned flags)
|
||||||
cso_init_vbuf(ctx, flags);
|
cso_init_vbuf(ctx, flags);
|
||||||
|
|
||||||
/* Enable for testing: */
|
/* Enable for testing: */
|
||||||
if (0) cso_set_maximum_cache_size( ctx->cache, 4 );
|
if (0) cso_set_maximum_cache_size(&ctx->cache, 4);
|
||||||
|
|
||||||
if (pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_GEOMETRY,
|
if (pipe->screen->get_shader_param(pipe->screen, PIPE_SHADER_GEOMETRY,
|
||||||
PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
|
PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
|
||||||
|
@ -352,10 +350,6 @@ cso_create_context(struct pipe_context *pipe, unsigned flags)
|
||||||
|
|
||||||
ctx->max_sampler_seen = -1;
|
ctx->max_sampler_seen = -1;
|
||||||
return ctx;
|
return ctx;
|
||||||
|
|
||||||
out:
|
|
||||||
cso_destroy_context( ctx );
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -449,10 +443,7 @@ void cso_destroy_context( struct cso_context *ctx )
|
||||||
pipe_so_target_reference(&ctx->so_targets_saved[i], NULL);
|
pipe_so_target_reference(&ctx->so_targets_saved[i], NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->cache) {
|
cso_cache_delete(&ctx->cache);
|
||||||
cso_cache_delete( ctx->cache );
|
|
||||||
ctx->cache = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ctx->vbuf)
|
if (ctx->vbuf)
|
||||||
u_vbuf_destroy(ctx->vbuf);
|
u_vbuf_destroy(ctx->vbuf);
|
||||||
|
@ -481,7 +472,7 @@ enum pipe_error cso_set_blend(struct cso_context *ctx,
|
||||||
sizeof(struct pipe_blend_state) :
|
sizeof(struct pipe_blend_state) :
|
||||||
(char *)&(templ->rt[1]) - (char *)templ;
|
(char *)&(templ->rt[1]) - (char *)templ;
|
||||||
hash_key = cso_construct_key((void*)templ, key_size);
|
hash_key = cso_construct_key((void*)templ, key_size);
|
||||||
iter = cso_find_state_template(ctx->cache, hash_key, CSO_BLEND,
|
iter = cso_find_state_template(&ctx->cache, hash_key, CSO_BLEND,
|
||||||
(void*)templ, key_size);
|
(void*)templ, key_size);
|
||||||
|
|
||||||
if (cso_hash_iter_is_null(iter)) {
|
if (cso_hash_iter_is_null(iter)) {
|
||||||
|
@ -495,7 +486,7 @@ enum pipe_error cso_set_blend(struct cso_context *ctx,
|
||||||
cso->delete_state = (cso_state_callback)ctx->pipe->delete_blend_state;
|
cso->delete_state = (cso_state_callback)ctx->pipe->delete_blend_state;
|
||||||
cso->context = ctx->pipe;
|
cso->context = ctx->pipe;
|
||||||
|
|
||||||
iter = cso_insert_state(ctx->cache, hash_key, CSO_BLEND, cso);
|
iter = cso_insert_state(&ctx->cache, hash_key, CSO_BLEND, cso);
|
||||||
if (cso_hash_iter_is_null(iter)) {
|
if (cso_hash_iter_is_null(iter)) {
|
||||||
FREE(cso);
|
FREE(cso);
|
||||||
return PIPE_ERROR_OUT_OF_MEMORY;
|
return PIPE_ERROR_OUT_OF_MEMORY;
|
||||||
|
@ -539,7 +530,7 @@ cso_set_depth_stencil_alpha(struct cso_context *ctx,
|
||||||
{
|
{
|
||||||
unsigned key_size = sizeof(struct pipe_depth_stencil_alpha_state);
|
unsigned key_size = sizeof(struct pipe_depth_stencil_alpha_state);
|
||||||
unsigned hash_key = cso_construct_key((void*)templ, key_size);
|
unsigned hash_key = cso_construct_key((void*)templ, key_size);
|
||||||
struct cso_hash_iter iter = cso_find_state_template(ctx->cache,
|
struct cso_hash_iter iter = cso_find_state_template(&ctx->cache,
|
||||||
hash_key,
|
hash_key,
|
||||||
CSO_DEPTH_STENCIL_ALPHA,
|
CSO_DEPTH_STENCIL_ALPHA,
|
||||||
(void*)templ, key_size);
|
(void*)templ, key_size);
|
||||||
|
@ -558,7 +549,7 @@ cso_set_depth_stencil_alpha(struct cso_context *ctx,
|
||||||
(cso_state_callback)ctx->pipe->delete_depth_stencil_alpha_state;
|
(cso_state_callback)ctx->pipe->delete_depth_stencil_alpha_state;
|
||||||
cso->context = ctx->pipe;
|
cso->context = ctx->pipe;
|
||||||
|
|
||||||
iter = cso_insert_state(ctx->cache, hash_key,
|
iter = cso_insert_state(&ctx->cache, hash_key,
|
||||||
CSO_DEPTH_STENCIL_ALPHA, cso);
|
CSO_DEPTH_STENCIL_ALPHA, cso);
|
||||||
if (cso_hash_iter_is_null(iter)) {
|
if (cso_hash_iter_is_null(iter)) {
|
||||||
FREE(cso);
|
FREE(cso);
|
||||||
|
@ -604,7 +595,7 @@ enum pipe_error cso_set_rasterizer(struct cso_context *ctx,
|
||||||
{
|
{
|
||||||
unsigned key_size = sizeof(struct pipe_rasterizer_state);
|
unsigned key_size = sizeof(struct pipe_rasterizer_state);
|
||||||
unsigned hash_key = cso_construct_key((void*)templ, key_size);
|
unsigned hash_key = cso_construct_key((void*)templ, key_size);
|
||||||
struct cso_hash_iter iter = cso_find_state_template(ctx->cache,
|
struct cso_hash_iter iter = cso_find_state_template(&ctx->cache,
|
||||||
hash_key,
|
hash_key,
|
||||||
CSO_RASTERIZER,
|
CSO_RASTERIZER,
|
||||||
(void*)templ, key_size);
|
(void*)templ, key_size);
|
||||||
|
@ -626,7 +617,7 @@ enum pipe_error cso_set_rasterizer(struct cso_context *ctx,
|
||||||
(cso_state_callback)ctx->pipe->delete_rasterizer_state;
|
(cso_state_callback)ctx->pipe->delete_rasterizer_state;
|
||||||
cso->context = ctx->pipe;
|
cso->context = ctx->pipe;
|
||||||
|
|
||||||
iter = cso_insert_state(ctx->cache, hash_key, CSO_RASTERIZER, cso);
|
iter = cso_insert_state(&ctx->cache, hash_key, CSO_RASTERIZER, cso);
|
||||||
if (cso_hash_iter_is_null(iter)) {
|
if (cso_hash_iter_is_null(iter)) {
|
||||||
FREE(cso);
|
FREE(cso);
|
||||||
return PIPE_ERROR_OUT_OF_MEMORY;
|
return PIPE_ERROR_OUT_OF_MEMORY;
|
||||||
|
@ -1028,7 +1019,7 @@ cso_set_vertex_elements_direct(struct cso_context *ctx,
|
||||||
key_size = sizeof(struct pipe_vertex_element) * velems->count +
|
key_size = sizeof(struct pipe_vertex_element) * velems->count +
|
||||||
sizeof(unsigned);
|
sizeof(unsigned);
|
||||||
hash_key = cso_construct_key((void*)velems, key_size);
|
hash_key = cso_construct_key((void*)velems, key_size);
|
||||||
iter = cso_find_state_template(ctx->cache, hash_key, CSO_VELEMENTS,
|
iter = cso_find_state_template(&ctx->cache, hash_key, CSO_VELEMENTS,
|
||||||
(void*)velems, key_size);
|
(void*)velems, key_size);
|
||||||
|
|
||||||
if (cso_hash_iter_is_null(iter)) {
|
if (cso_hash_iter_is_null(iter)) {
|
||||||
|
@ -1044,7 +1035,7 @@ cso_set_vertex_elements_direct(struct cso_context *ctx,
|
||||||
(cso_state_callback) ctx->pipe->delete_vertex_elements_state;
|
(cso_state_callback) ctx->pipe->delete_vertex_elements_state;
|
||||||
cso->context = ctx->pipe;
|
cso->context = ctx->pipe;
|
||||||
|
|
||||||
iter = cso_insert_state(ctx->cache, hash_key, CSO_VELEMENTS, cso);
|
iter = cso_insert_state(&ctx->cache, hash_key, CSO_VELEMENTS, cso);
|
||||||
if (cso_hash_iter_is_null(iter)) {
|
if (cso_hash_iter_is_null(iter)) {
|
||||||
FREE(cso);
|
FREE(cso);
|
||||||
return;
|
return;
|
||||||
|
@ -1247,7 +1238,7 @@ cso_single_sampler(struct cso_context *ctx, enum pipe_shader_type shader_stage,
|
||||||
unsigned hash_key = cso_construct_key((void*)templ, key_size);
|
unsigned hash_key = cso_construct_key((void*)templ, key_size);
|
||||||
struct cso_sampler *cso;
|
struct cso_sampler *cso;
|
||||||
struct cso_hash_iter iter =
|
struct cso_hash_iter iter =
|
||||||
cso_find_state_template(ctx->cache,
|
cso_find_state_template(&ctx->cache,
|
||||||
hash_key, CSO_SAMPLER,
|
hash_key, CSO_SAMPLER,
|
||||||
(void *) templ, key_size);
|
(void *) templ, key_size);
|
||||||
|
|
||||||
|
@ -1263,7 +1254,7 @@ cso_single_sampler(struct cso_context *ctx, enum pipe_shader_type shader_stage,
|
||||||
cso->context = ctx->pipe;
|
cso->context = ctx->pipe;
|
||||||
cso->hash_key = hash_key;
|
cso->hash_key = hash_key;
|
||||||
|
|
||||||
iter = cso_insert_state(ctx->cache, hash_key, CSO_SAMPLER, cso);
|
iter = cso_insert_state(&ctx->cache, hash_key, CSO_SAMPLER, cso);
|
||||||
if (cso_hash_iter_is_null(iter)) {
|
if (cso_hash_iter_is_null(iter)) {
|
||||||
FREE(cso);
|
FREE(cso);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -150,7 +150,7 @@ struct u_vbuf {
|
||||||
|
|
||||||
struct pipe_context *pipe;
|
struct pipe_context *pipe;
|
||||||
struct translate_cache *translate_cache;
|
struct translate_cache *translate_cache;
|
||||||
struct cso_cache *cso_cache;
|
struct cso_cache cso_cache;
|
||||||
|
|
||||||
/* This is what was set in set_vertex_buffers.
|
/* This is what was set in set_vertex_buffers.
|
||||||
* May contain user buffers. */
|
* May contain user buffers. */
|
||||||
|
@ -322,7 +322,7 @@ u_vbuf_create(struct pipe_context *pipe, struct u_vbuf_caps *caps)
|
||||||
|
|
||||||
mgr->caps = *caps;
|
mgr->caps = *caps;
|
||||||
mgr->pipe = pipe;
|
mgr->pipe = pipe;
|
||||||
mgr->cso_cache = cso_cache_create();
|
cso_cache_init(&mgr->cso_cache);
|
||||||
mgr->translate_cache = translate_cache_create();
|
mgr->translate_cache = translate_cache_create();
|
||||||
memset(mgr->fallback_vbs, ~0, sizeof(mgr->fallback_vbs));
|
memset(mgr->fallback_vbs, ~0, sizeof(mgr->fallback_vbs));
|
||||||
mgr->allowed_vb_mask = u_bit_consecutive(0, mgr->caps.max_vertex_buffers);
|
mgr->allowed_vb_mask = u_bit_consecutive(0, mgr->caps.max_vertex_buffers);
|
||||||
|
@ -349,7 +349,7 @@ u_vbuf_set_vertex_elements_internal(struct u_vbuf *mgr,
|
||||||
key_size = sizeof(struct pipe_vertex_element) * velems->count +
|
key_size = sizeof(struct pipe_vertex_element) * velems->count +
|
||||||
sizeof(unsigned);
|
sizeof(unsigned);
|
||||||
hash_key = cso_construct_key((void*)velems, key_size);
|
hash_key = cso_construct_key((void*)velems, key_size);
|
||||||
iter = cso_find_state_template(mgr->cso_cache, hash_key, CSO_VELEMENTS,
|
iter = cso_find_state_template(&mgr->cso_cache, hash_key, CSO_VELEMENTS,
|
||||||
(void*)velems, key_size);
|
(void*)velems, key_size);
|
||||||
|
|
||||||
if (cso_hash_iter_is_null(iter)) {
|
if (cso_hash_iter_is_null(iter)) {
|
||||||
|
@ -360,7 +360,7 @@ u_vbuf_set_vertex_elements_internal(struct u_vbuf *mgr,
|
||||||
cso->delete_state = (cso_state_callback)u_vbuf_delete_vertex_elements;
|
cso->delete_state = (cso_state_callback)u_vbuf_delete_vertex_elements;
|
||||||
cso->context = (void*)mgr;
|
cso->context = (void*)mgr;
|
||||||
|
|
||||||
iter = cso_insert_state(mgr->cso_cache, hash_key, CSO_VELEMENTS, cso);
|
iter = cso_insert_state(&mgr->cso_cache, hash_key, CSO_VELEMENTS, cso);
|
||||||
ve = cso->data;
|
ve = cso->data;
|
||||||
} else {
|
} else {
|
||||||
ve = ((struct cso_velements *)cso_hash_iter_data(iter))->data;
|
ve = ((struct cso_velements *)cso_hash_iter_data(iter))->data;
|
||||||
|
@ -402,7 +402,7 @@ void u_vbuf_destroy(struct u_vbuf *mgr)
|
||||||
pipe_vertex_buffer_unreference(&mgr->vertex_buffer0_saved);
|
pipe_vertex_buffer_unreference(&mgr->vertex_buffer0_saved);
|
||||||
|
|
||||||
translate_cache_destroy(mgr->translate_cache);
|
translate_cache_destroy(mgr->translate_cache);
|
||||||
cso_cache_delete(mgr->cso_cache);
|
cso_cache_delete(&mgr->cso_cache);
|
||||||
FREE(mgr);
|
FREE(mgr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue