zink: incrementally hash gfx shader stages
Reviewed-by: Dave Airlie <airlied@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12605>
This commit is contained in:
committed by
Marge Bot
parent
07240424ca
commit
7f23c9daca
@@ -985,6 +985,8 @@ zink_shader_create(struct zink_screen *screen, struct nir_shader *nir,
|
||||
struct zink_shader *ret = CALLOC_STRUCT(zink_shader);
|
||||
bool have_psiz = false;
|
||||
|
||||
ret->hash = _mesa_hash_pointer(ret);
|
||||
|
||||
ret->programs = _mesa_pointer_set_create(NULL);
|
||||
simple_mtx_init(&ret->lock, mtx_plain);
|
||||
|
||||
@@ -1183,6 +1185,7 @@ zink_shader_tcs_create(struct zink_context *ctx, struct zink_shader *vs)
|
||||
{
|
||||
unsigned vertices_per_patch = ctx->gfx_pipeline_state.vertices_per_patch + 1;
|
||||
struct zink_shader *ret = CALLOC_STRUCT(zink_shader);
|
||||
ret->hash = _mesa_hash_pointer(ret);
|
||||
ret->programs = _mesa_pointer_set_create(NULL);
|
||||
simple_mtx_init(&ret->lock, mtx_plain);
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ zink_tgsi_to_nir(struct pipe_screen *screen, const struct tgsi_token *tokens);
|
||||
|
||||
struct zink_shader {
|
||||
struct util_live_shader base;
|
||||
uint32_t hash;
|
||||
struct nir_shader *nir;
|
||||
|
||||
struct zink_so_info streamout;
|
||||
|
||||
@@ -218,6 +218,7 @@ struct zink_context {
|
||||
* thus only 3 stages need to be considered, giving 2^3 = 8 program caches.
|
||||
*/
|
||||
struct hash_table program_cache[8];
|
||||
uint32_t gfx_hash;
|
||||
struct zink_gfx_program *curr_program;
|
||||
|
||||
struct zink_descriptor_data *dd;
|
||||
|
||||
@@ -190,7 +190,7 @@ update_gfx_program(struct zink_context *ctx)
|
||||
struct zink_gfx_program *prog = NULL;
|
||||
|
||||
struct hash_table *ht = &ctx->program_cache[ctx->shader_stages >> 2];
|
||||
uint32_t hash = ht->key_hash_function(ctx->gfx_stages);
|
||||
const uint32_t hash = ctx->gfx_hash;
|
||||
struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(ht, hash, ctx->gfx_stages);
|
||||
if (entry) {
|
||||
prog = (struct zink_gfx_program*)entry->data;
|
||||
@@ -913,24 +913,23 @@ template <unsigned STAGE_MASK>
|
||||
static uint32_t
|
||||
hash_gfx_program(const void *key)
|
||||
{
|
||||
const void **shaders = (const void**)key;
|
||||
uint32_t base_hash = _mesa_hash_data(key, sizeof(void*) * 2);
|
||||
uint32_t gs_hash = _mesa_hash_data(key, sizeof(void*) * 3);
|
||||
const struct zink_shader **shaders = (const struct zink_shader**)key;
|
||||
uint32_t base_hash = shaders[PIPE_SHADER_VERTEX]->hash ^ shaders[PIPE_SHADER_FRAGMENT]->hash;
|
||||
if (STAGE_MASK == 0) //VS+FS
|
||||
return base_hash;
|
||||
if (STAGE_MASK == 1) //VS+GS+FS
|
||||
return gs_hash;
|
||||
return base_hash ^ shaders[PIPE_SHADER_GEOMETRY]->hash;
|
||||
/*VS+TCS+FS isn't a thing */
|
||||
/*VS+TCS+GS+FS isn't a thing */
|
||||
if (STAGE_MASK == 4) //VS+TES+FS
|
||||
return XXH32(&shaders[PIPE_SHADER_TESS_EVAL], sizeof(void*), base_hash);
|
||||
return base_hash ^ shaders[PIPE_SHADER_TESS_EVAL]->hash;
|
||||
if (STAGE_MASK == 5) //VS+TES+GS+FS
|
||||
return XXH32(&shaders[PIPE_SHADER_TESS_EVAL], sizeof(void*), gs_hash);
|
||||
return base_hash ^ shaders[PIPE_SHADER_GEOMETRY]->hash ^ shaders[PIPE_SHADER_TESS_EVAL]->hash;
|
||||
if (STAGE_MASK == 6) //VS+TCS+TES+FS
|
||||
return XXH32(&shaders[PIPE_SHADER_TESS_CTRL], sizeof(void*) * 2, base_hash);
|
||||
return base_hash ^ shaders[PIPE_SHADER_TESS_CTRL]->hash ^ shaders[PIPE_SHADER_TESS_EVAL]->hash;
|
||||
|
||||
/* all stages */
|
||||
return _mesa_hash_data(key, sizeof(void*) * ZINK_SHADER_COUNT);
|
||||
return base_hash ^ shaders[PIPE_SHADER_GEOMETRY]->hash ^ shaders[PIPE_SHADER_TESS_CTRL]->hash ^ shaders[PIPE_SHADER_TESS_EVAL]->hash;
|
||||
}
|
||||
|
||||
template <unsigned STAGE_MASK>
|
||||
|
||||
@@ -908,12 +908,15 @@ bind_stage(struct zink_context *ctx, enum pipe_shader_type stage,
|
||||
ctx->compute_stage = shader;
|
||||
zink_select_launch_grid(ctx);
|
||||
} else {
|
||||
if (ctx->gfx_stages[stage])
|
||||
ctx->gfx_hash ^= ctx->gfx_stages[stage]->hash;
|
||||
ctx->gfx_stages[stage] = shader;
|
||||
ctx->gfx_dirty = ctx->gfx_stages[PIPE_SHADER_FRAGMENT] && ctx->gfx_stages[PIPE_SHADER_VERTEX];
|
||||
ctx->gfx_pipeline_state.combined_dirty = true;
|
||||
if (shader)
|
||||
if (shader) {
|
||||
ctx->shader_stages |= BITFIELD_BIT(stage);
|
||||
else {
|
||||
ctx->gfx_hash ^= ctx->gfx_stages[stage]->hash;
|
||||
} else {
|
||||
ctx->gfx_pipeline_state.modules[stage] = VK_NULL_HANDLE;
|
||||
ctx->curr_program = NULL;
|
||||
ctx->shader_stages &= ~BITFIELD_BIT(stage);
|
||||
|
||||
Reference in New Issue
Block a user