freedreno/ir3: move the libdrm dependency out of shared code
authorRob Clark <robdclark@chromium.org>
Fri, 5 Jun 2020 19:56:04 +0000 (12:56 -0700)
committerMarge Bot <eric+marge@anholt.net>
Mon, 15 Jun 2020 15:46:37 +0000 (15:46 +0000)
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>

src/freedreno/ir3/ir3_shader.c
src/freedreno/ir3/ir3_shader.h
src/gallium/drivers/freedreno/ir3/ir3_gallium.c

index 652129108bf8dc0d73503c6caa4cc293182e38df..ddb2c997baf6071d8498476f5505c9f5ef6c4b53 100644 (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;
        }
index 809af42d6cbe3bf60144d22041b2158be93c37d1..9fc175595ba031fc0ea5447c44da085f218b2155 100644 (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;
index 6c0aa9f4b80bbbdcae57bab8740c62d44883eb44..5544e0e50c71e5f1ac8510d2b303aea542381736 100644 (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);
 }