freedreno/ir3: move the libdrm dependency out of shared code

The only reason for this dependency was the fd_bo used for the uploaded
shader.  But this isn't used by turnip.  Now that we've unified the
cleanup path from gallium, it isn't hard to pull the fd_bo upload/free
parts into ir3_gallium.

This cleanup has the added benefit that the shader disk-cache will not
have to deal with it.

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5476>
This commit is contained in:
Rob Clark 2020-06-05 12:56:04 -07:00 committed by Marge Bot
parent 43e0062c5b
commit 1a33faea8c
3 changed files with 45 additions and 19 deletions

View File

@ -46,10 +46,10 @@ delete_variant(struct ir3_shader_variant *v)
{
if (v->ir)
ir3_destroy(v->ir);
if (v->bo)
fd_bo_del(v->bo);
assert(!v->bo);
if (v->binning)
delete_variant(v->binning);
free(v->bin);
free(v);
}
@ -160,32 +160,18 @@ static void
assemble_variant(struct ir3_shader_variant *v)
{
struct ir3_compiler *compiler = v->shader->compiler;
struct shader_info *info = &v->shader->nir->info;
uint32_t gpu_id = compiler->gpu_id;
uint32_t sz, *bin;
bin = ir3_shader_assemble(v, gpu_id);
sz = v->info.sizedwords * 4;
v->bo = fd_bo_new(compiler->dev, sz,
DRM_FREEDRENO_GEM_CACHE_WCOMBINE |
DRM_FREEDRENO_GEM_TYPE_KMEM,
"%s:%s", ir3_shader_stage(v), info->name);
/* Always include shaders in kernel crash dumps. */
fd_bo_mark_for_dump(v->bo);
memcpy(fd_bo_map(v->bo), bin, sz);
v->bin = ir3_shader_assemble(v, gpu_id);
if (shader_debug_enabled(v->shader->type)) {
fprintf(stdout, "Native code for unnamed %s shader %s:\n",
ir3_shader_stage(v), v->shader->nir->info.name);
if (v->shader->type == MESA_SHADER_FRAGMENT)
fprintf(stdout, "SIMD0\n");
ir3_shader_disasm(v, bin, stdout);
ir3_shader_disasm(v, v->bin, stdout);
}
free(bin);
/* no need to keep the ir around beyond this point: */
ir3_destroy(v->ir);
v->ir = NULL;
@ -220,7 +206,7 @@ create_variant(struct ir3_shader *shader, struct ir3_shader_key *key,
}
assemble_variant(v);
if (!v->bo) {
if (!v->bin) {
debug_error("assemble failed!");
goto fail;
}

View File

@ -429,6 +429,9 @@ struct ir3_shader_variant {
struct ir3_info info;
struct ir3 *ir;
/* The actual binary shader instructions, size given by info.sizedwords: */
uint32_t *bin;
/* Levels of nesting of flow control:
*/
unsigned branchstack;

View File

@ -70,6 +70,27 @@ dump_shader_info(struct ir3_shader_variant *v, bool binning_pass,
v->max_sun, v->loops);
}
static void
upload_shader_variant(struct ir3_shader_variant *v)
{
struct shader_info *info = &v->shader->nir->info;
struct ir3_compiler *compiler = v->shader->compiler;
assert(!v->bo);
unsigned sz = v->info.sizedwords * 4;
v->bo = fd_bo_new(compiler->dev, sz,
DRM_FREEDRENO_GEM_CACHE_WCOMBINE |
DRM_FREEDRENO_GEM_TYPE_KMEM,
"%s:%s", ir3_shader_stage(v), info->name);
/* Always include shaders in kernel crash dumps. */
fd_bo_mark_for_dump(v->bo);
memcpy(fd_bo_map(v->bo), v->bin, sz);
}
struct ir3_shader_variant *
ir3_shader_variant(struct ir3_shader *shader, struct ir3_shader_key key,
bool binning_pass, struct pipe_debug_callback *debug)
@ -98,6 +119,8 @@ ir3_shader_variant(struct ir3_shader *shader, struct ir3_shader_key key,
}
dump_shader_info(v, binning_pass, debug);
upload_shader_variant(v);
}
return v;
@ -237,6 +260,20 @@ void
ir3_shader_state_delete(struct pipe_context *pctx, void *hwcso)
{
struct ir3_shader *so = hwcso;
/* free the uploaded shaders, since this is handled outside of the
* shared ir3 code (ie. not used by turnip):
*/
for (struct ir3_shader_variant *v = so->variants; v; v = v->next) {
fd_bo_del(v->bo);
v->bo = NULL;
if (v->binning) {
fd_bo_del(v->binning->bo);
v->binning->bo = NULL;
}
}
ir3_shader_destroy(so);
}