From: Mike Blumenkrantz Date: Mon, 3 Apr 2023 19:42:08 +0000 (-0400) Subject: zink: store spirv onto zink_shader_object structs X-Git-Tag: upstream/23.3.3~9433 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=36b014b28dbd1e712b37e108fbd5d9ef5a433755;p=platform%2Fupstream%2Fmesa.git zink: store spirv onto zink_shader_object structs this makes it convenient for reuse Part-of: --- diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index 6040d94..99f11b6 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -3310,7 +3310,7 @@ zink_shader_spirv_compile(struct zink_screen *screen, struct zink_shader *zs, st #endif VkResult ret; - struct zink_shader_object obj; + struct zink_shader_object obj = {0}; if (!can_shobj || !screen->info.have_EXT_shader_object) ret = VKSCR(CreateShaderModule)(screen->dev, &smci, NULL, &obj.mod); else @@ -3541,7 +3541,7 @@ compile_module(struct zink_screen *screen, struct zink_shader *zs, nir_shader *n if (zs->info.stage == MESA_SHADER_TESS_CTRL && zs->non_fs.is_generated) zs->spirv = spirv; else - ralloc_free(spirv); + obj.spirv = spirv; return obj; } @@ -3811,10 +3811,14 @@ zink_shader_compile_separate(struct zink_screen *screen, struct zink_shader *zs) NIR_PASS_V(nir_clone, nir_remove_dead_variables, nir_var_shader_temp, NULL); optimize_nir(nir_clone, NULL); zs->precompile.no_psiz_obj = compile_module(screen, zs, nir_clone, true); + spirv_shader_delete(zs->precompile.no_psiz_obj.spirv); + zs->precompile.no_psiz_obj.spirv = NULL; } } } ralloc_free(nir); + spirv_shader_delete(obj.spirv); + obj.spirv = NULL; return obj; } diff --git a/src/gallium/drivers/zink/zink_program.c b/src/gallium/drivers/zink/zink_program.c index 2b5b2a0..52f6334 100644 --- a/src/gallium/drivers/zink/zink_program.c +++ b/src/gallium/drivers/zink/zink_program.c @@ -344,6 +344,7 @@ static void zink_destroy_shader_module(struct zink_screen *screen, struct zink_shader_module *zm) { VKSCR(DestroyShaderModule)(screen->dev, zm->obj.mod, NULL); + ralloc_free(zm->obj.spirv); free(zm); } @@ -847,7 +848,7 @@ update_cs_shader_module(struct zink_context *ctx, struct zink_compute_program *c return; } zm->obj = zink_shader_compile(screen, zs, zink_shader_blob_deserialize(screen, &comp->shader->blob), key, zs_swizzle_size ? &ctx->di.zs_swizzle[MESA_SHADER_COMPUTE] : NULL); - if (!zm->obj.mod) { + if (!zm->obj.spirv) { FREE(zm); return; } @@ -1298,7 +1299,7 @@ precompile_compute_job(void *data, void *gdata, int thread_index) comp->module->obj = zink_shader_compile(screen, comp->shader, comp->nir, NULL, NULL); /* comp->nir will be freed by zink_shader_compile */ comp->nir = NULL; - assert(comp->module->obj.mod); + assert(comp->module->obj.spirv); util_dynarray_init(&comp->shader_cache[0], comp); util_dynarray_init(&comp->shader_cache[1], comp); diff --git a/src/gallium/drivers/zink/zink_types.h b/src/gallium/drivers/zink/zink_types.h index ae55ab9..d18e80d 100644 --- a/src/gallium/drivers/zink/zink_types.h +++ b/src/gallium/drivers/zink/zink_types.h @@ -738,6 +738,7 @@ struct zink_shader_object { VkShaderEXT obj; VkShaderModule mod; }; + struct spirv_shader *spirv; }; struct zink_shader {