radeonsi/nir: call nir_serialize only once per shader
We were calling it twice. First serialize it, then use it to compute the cache key. Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
This commit is contained in:
@@ -47,7 +47,6 @@
|
|||||||
void si_get_ir_cache_key(struct si_shader_selector *sel, bool ngg, bool es,
|
void si_get_ir_cache_key(struct si_shader_selector *sel, bool ngg, bool es,
|
||||||
unsigned char ir_sha1_cache_key[20])
|
unsigned char ir_sha1_cache_key[20])
|
||||||
{
|
{
|
||||||
struct blob blob;
|
|
||||||
unsigned ir_size;
|
unsigned ir_size;
|
||||||
void *ir_binary;
|
void *ir_binary;
|
||||||
|
|
||||||
@@ -56,12 +55,9 @@ void si_get_ir_cache_key(struct si_shader_selector *sel, bool ngg, bool es,
|
|||||||
ir_size = tgsi_num_tokens(sel->tokens) *
|
ir_size = tgsi_num_tokens(sel->tokens) *
|
||||||
sizeof(struct tgsi_token);
|
sizeof(struct tgsi_token);
|
||||||
} else {
|
} else {
|
||||||
assert(sel->nir);
|
assert(sel->nir_binary);
|
||||||
|
ir_binary = sel->nir_binary;
|
||||||
blob_init(&blob);
|
ir_size = sel->nir_size;
|
||||||
nir_serialize(&blob, sel->nir, true);
|
|
||||||
ir_binary = blob.data;
|
|
||||||
ir_size = blob.size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* These settings affect the compilation, but they are not derived
|
/* These settings affect the compilation, but they are not derived
|
||||||
@@ -87,9 +83,6 @@ void si_get_ir_cache_key(struct si_shader_selector *sel, bool ngg, bool es,
|
|||||||
sel->type == PIPE_SHADER_GEOMETRY)
|
sel->type == PIPE_SHADER_GEOMETRY)
|
||||||
_mesa_sha1_update(&ctx, &sel->so, sizeof(sel->so));
|
_mesa_sha1_update(&ctx, &sel->so, sizeof(sel->so));
|
||||||
_mesa_sha1_final(&ctx, ir_sha1_cache_key);
|
_mesa_sha1_final(&ctx, ir_sha1_cache_key);
|
||||||
|
|
||||||
if (sel->nir)
|
|
||||||
blob_finish(&blob);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Copy "data" to "ptr" and return the next dword following copied data. */
|
/** Copy "data" to "ptr" and return the next dword following copied data. */
|
||||||
@@ -2465,6 +2458,23 @@ static void si_init_shader_selector_async(void *job, int thread_index)
|
|||||||
if (!compiler->passes)
|
if (!compiler->passes)
|
||||||
si_init_compiler(sscreen, compiler);
|
si_init_compiler(sscreen, compiler);
|
||||||
|
|
||||||
|
/* Serialize NIR to save memory. Monolithic shader variants
|
||||||
|
* have to deserialize NIR before compilation.
|
||||||
|
*/
|
||||||
|
if (sel->nir) {
|
||||||
|
struct blob blob;
|
||||||
|
size_t size;
|
||||||
|
|
||||||
|
blob_init(&blob);
|
||||||
|
/* true = remove optional debugging data to increase
|
||||||
|
* the likehood of getting more shader cache hits.
|
||||||
|
* It also drops variable names, so we'll save more memory.
|
||||||
|
*/
|
||||||
|
nir_serialize(&blob, sel->nir, true);
|
||||||
|
blob_finish_get_buffer(&blob, &sel->nir_binary, &size);
|
||||||
|
sel->nir_size = size;
|
||||||
|
}
|
||||||
|
|
||||||
/* Compile the main shader part for use with a prolog and/or epilog.
|
/* Compile the main shader part for use with a prolog and/or epilog.
|
||||||
* If this fails, the driver will try to compile a monolithic shader
|
* If this fails, the driver will try to compile a monolithic shader
|
||||||
* on demand.
|
* on demand.
|
||||||
@@ -2582,18 +2592,8 @@ static void si_init_shader_selector_async(void *job, int thread_index)
|
|||||||
si_shader_vs(sscreen, sel->gs_copy_shader, sel);
|
si_shader_vs(sscreen, sel->gs_copy_shader, sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Free NIR. We only keep serialized NIR after this point. */
|
||||||
if (sel->nir) {
|
if (sel->nir) {
|
||||||
/* Serialize NIR to save memory. Monolithic shader variants
|
|
||||||
* have to deserialize NIR before compilation.
|
|
||||||
*/
|
|
||||||
struct blob blob;
|
|
||||||
blob_init(&blob);
|
|
||||||
nir_serialize(&blob, sel->nir, false);
|
|
||||||
sel->nir_binary = malloc(blob.size);
|
|
||||||
memcpy(sel->nir_binary, blob.data, blob.size);
|
|
||||||
sel->nir_size = blob.size;
|
|
||||||
blob_finish(&blob);
|
|
||||||
|
|
||||||
ralloc_free(sel->nir);
|
ralloc_free(sel->nir);
|
||||||
sel->nir = NULL;
|
sel->nir = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user