panfrost: Move to use ralloc for some allocations
authorTomeu Vizoso <tomeu.vizoso@collabora.com>
Tue, 18 Jun 2019 12:24:57 +0000 (14:24 +0200)
committerTomeu Vizoso <tomeu.vizoso@collabora.com>
Wed, 19 Jun 2019 05:34:15 +0000 (07:34 +0200)
We have some serious leaks, so plug some and also move to ralloc to
limit the lifetime of some objects to that of their parent.

Lots more such work to do.

For some reason, this fixes:

dEQP-GLES2.functional.lifetime.attach.deleted_output.texture_framebuffer

Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/ci/expected-failures.txt
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_drm.c
src/gallium/drivers/panfrost/pan_job.c
src/gallium/drivers/panfrost/pan_resource.c
src/gallium/drivers/panfrost/pan_resource.h
src/gallium/drivers/panfrost/pan_screen.c

index cd86b1c663818f46600c05d41aa1e5dcd0fa3498..350d4b529ff02778341075b1254953fa7060d0f0 100644 (file)
@@ -281,7 +281,6 @@ dEQP-GLES2.functional.fragment_ops.random.97
 dEQP-GLES2.functional.fragment_ops.random.98
 dEQP-GLES2.functional.fragment_ops.random.99
 dEQP-GLES2.functional.lifetime.attach.deleted_output.renderbuffer_framebuffer
-dEQP-GLES2.functional.lifetime.attach.deleted_output.texture_framebuffer
 dEQP-GLES2.functional.negative_api.shader.uniform_matrixfv_invalid_transpose
 dEQP-GLES2.functional.negative_api.texture.generatemipmap_zero_level_array_compressed
 dEQP-GLES2.functional.polygon_offset.fixed16_displacement_with_units
index 3b2b63045962c65606eac56daaf43a420ec490bc..e4a04dd821f5815b9bfcb50b53450dad0a3827e3 100644 (file)
@@ -2020,7 +2020,7 @@ panfrost_set_constant_buffer(
         pbuf->size = sz;
 
         if (pbuf->buffer) {
-                free(pbuf->buffer);
+                ralloc_free(pbuf->buffer);
                 pbuf->buffer = NULL;
         }
 
@@ -2047,7 +2047,7 @@ panfrost_set_constant_buffer(
 
         /* Copy the constant buffer into the driver context for later upload */
 
-        pbuf->buffer = malloc(sz);
+        pbuf->buffer = rzalloc_size(ctx, sz);
         memcpy(pbuf->buffer, cpu + buf->buffer_offset, sz);
 }
 
@@ -2095,7 +2095,7 @@ panfrost_create_sampler_view(
         struct pipe_resource *texture,
         const struct pipe_sampler_view *template)
 {
-        struct panfrost_sampler_view *so = CALLOC_STRUCT(panfrost_sampler_view);
+        struct panfrost_sampler_view *so = rzalloc(pctx, struct panfrost_sampler_view);
         int bytes_per_pixel = util_format_get_blocksize(texture->format);
 
         pipe_reference(NULL, &texture->reference);
@@ -2233,7 +2233,7 @@ panfrost_sampler_view_destroy(
         struct pipe_sampler_view *view)
 {
         pipe_resource_reference(&view->texture, NULL);
-        free(view);
+        ralloc_free(view);
 }
 
 static void
@@ -2326,7 +2326,7 @@ panfrost_create_blend_state(struct pipe_context *pipe,
                             const struct pipe_blend_state *blend)
 {
         struct panfrost_context *ctx = pan_context(pipe);
-        struct panfrost_blend_state *so = CALLOC_STRUCT(panfrost_blend_state);
+        struct panfrost_blend_state *so = rzalloc(ctx, struct panfrost_blend_state);
         so->base = *blend;
 
         /* TODO: The following features are not yet implemented */
@@ -2376,7 +2376,7 @@ panfrost_delete_blend_state(struct pipe_context *pipe,
                 DBG("Deleting blend state leak blend shaders bytecode\n");
         }
 
-        free(blend);
+        ralloc_free(blend);
 }
 
 static void
@@ -2522,6 +2522,8 @@ panfrost_destroy(struct pipe_context *pipe)
         screen->driver->free_slab(screen, &panfrost->shaders);
         screen->driver->free_slab(screen, &panfrost->tiler_heap);
         screen->driver->free_slab(screen, &panfrost->tiler_polygon_list);
+
+        ralloc_free(pipe);
 }
 
 static struct pipe_query *
@@ -2529,7 +2531,7 @@ panfrost_create_query(struct pipe_context *pipe,
                      unsigned type,
                      unsigned index)
 {
-        struct panfrost_query *q = CALLOC_STRUCT(panfrost_query);
+        struct panfrost_query *q = rzalloc(pipe, struct panfrost_query);
 
         q->type = type;
         q->index = index;
@@ -2540,7 +2542,7 @@ panfrost_create_query(struct pipe_context *pipe,
 static void
 panfrost_destroy_query(struct pipe_context *pipe, struct pipe_query *q)
 {
-        FREE(q);
+        ralloc_free(q);
 }
 
 static boolean
@@ -2624,7 +2626,7 @@ panfrost_create_stream_output_target(struct pipe_context *pctx,
 {
         struct pipe_stream_output_target *target;
 
-        target = CALLOC_STRUCT(pipe_stream_output_target);
+        target = rzalloc(pctx, struct pipe_stream_output_target);
 
         if (!target)
                 return NULL;
@@ -2644,7 +2646,7 @@ panfrost_stream_output_target_destroy(struct pipe_context *pctx,
                                  struct pipe_stream_output_target *target)
 {
         pipe_resource_reference(&target->buffer, NULL);
-        free(target);
+        ralloc_free(target);
 }
 
 static void
@@ -2687,7 +2689,7 @@ panfrost_setup_hardware(struct panfrost_context *ctx)
 struct pipe_context *
 panfrost_create_context(struct pipe_screen *screen, void *priv, unsigned flags)
 {
-        struct panfrost_context *ctx = CALLOC_STRUCT(panfrost_context);
+        struct panfrost_context *ctx = rzalloc(screen, struct panfrost_context);
         struct panfrost_screen *pscreen = pan_screen(screen);
         memset(ctx, 0, sizeof(*ctx));
         struct pipe_context *gallium = (struct pipe_context *) ctx;
index cacc6a7f715d404e456a49cb551f32083a23ef3a..aed50477ff7d4caea318894395ffba5c2d754074 100644 (file)
@@ -124,7 +124,7 @@ panfrost_drm_free_slab(struct panfrost_screen *screen, struct panfrost_memory *m
 static struct panfrost_bo *
 panfrost_drm_import_bo(struct panfrost_screen *screen, struct winsys_handle *whandle)
 {
-       struct panfrost_bo *bo = CALLOC_STRUCT(panfrost_bo);
+       struct panfrost_bo *bo = rzalloc(screen, struct panfrost_bo);
        struct panfrost_drm *drm = (struct panfrost_drm *)screen->driver;
         struct drm_panfrost_get_bo_offset get_bo_offset = {0,};
        struct drm_panfrost_mmap_bo mmap_bo = {0,};
index 1882cc4faf3239345292c7f85bc6be0077cacf52..96f05c663540a9bd5b8a713d933151b7ac827cbe 100644 (file)
@@ -269,13 +269,11 @@ panfrost_job_hash(const void *key)
 void
 panfrost_job_init(struct panfrost_context *ctx)
 {
-        /* TODO: Don't leak */
-        ctx->jobs = _mesa_hash_table_create(NULL,
+        ctx->jobs = _mesa_hash_table_create(ctx,
                                             panfrost_job_hash,
                                             panfrost_job_compare);
 
-        ctx->write_jobs = _mesa_hash_table_create(NULL,
+        ctx->write_jobs = _mesa_hash_table_create(ctx,
                                             _mesa_hash_pointer,
                                             _mesa_key_pointer_equal);
-
 }
index ac83f38b3279915bbde9d204a754e65343cab692..332208d4e2fe7c0168d886b8a2339e37a48fd8b2 100644 (file)
@@ -58,7 +58,7 @@ panfrost_resource_from_handle(struct pipe_screen *pscreen,
 
         assert(whandle->type == WINSYS_HANDLE_TYPE_FD);
 
-        rsc = CALLOC_STRUCT(panfrost_resource);
+        rsc = rzalloc(pscreen, struct panfrost_resource);
         if (!rsc)
                 return NULL;
 
@@ -138,7 +138,7 @@ panfrost_create_surface(struct pipe_context *pipe,
 {
         struct pipe_surface *ps = NULL;
 
-        ps = CALLOC_STRUCT(pipe_surface);
+        ps = rzalloc(pipe, struct pipe_surface);
 
         if (ps) {
                 pipe_reference_init(&ps->reference, 1);
@@ -173,7 +173,7 @@ panfrost_surface_destroy(struct pipe_context *pipe,
 {
         assert(surf->texture);
         pipe_resource_reference(&surf->texture, NULL);
-        free(surf);
+        ralloc_free(surf);
 }
 
 static void
@@ -265,7 +265,7 @@ panfrost_setup_slices(const struct pipe_resource *tmpl, struct panfrost_bo *bo)
 static struct panfrost_bo *
 panfrost_create_bo(struct panfrost_screen *screen, const struct pipe_resource *template)
 {
-       struct panfrost_bo *bo = CALLOC_STRUCT(panfrost_bo);
+       struct panfrost_bo *bo = rzalloc(screen, struct panfrost_bo);
         pipe_reference_init(&bo->reference, 1);
 
         /* Based on the usage, figure out what storing will be used. There are
@@ -313,7 +313,7 @@ static struct pipe_resource *
 panfrost_resource_create(struct pipe_screen *screen,
                          const struct pipe_resource *template)
 {
-        struct panfrost_resource *so = CALLOC_STRUCT(panfrost_resource);
+        struct panfrost_resource *so = rzalloc(screen, struct panfrost_resource);
         struct panfrost_screen *pscreen = (struct panfrost_screen *) screen;
 
         so->base = *template;
@@ -369,10 +369,8 @@ panfrost_resource_create(struct pipe_screen *screen,
 }
 
 static void
-panfrost_destroy_bo(struct panfrost_screen *screen, struct panfrost_bo *pbo)
+panfrost_destroy_bo(struct panfrost_screen *screen, struct panfrost_bo *bo)
 {
-       struct panfrost_bo *bo = (struct panfrost_bo *)pbo;
-
         if ((bo->layout == PAN_LINEAR || bo->layout == PAN_TILED) &&
                         !bo->imported) {
                 struct panfrost_memory mem = {
@@ -404,6 +402,8 @@ panfrost_destroy_bo(struct panfrost_screen *screen, struct panfrost_bo *pbo)
         if (bo->imported) {
                 screen->driver->free_imported_bo(screen, bo);
         }
+
+        ralloc_free(bo);
 }
 
 void
@@ -436,7 +436,7 @@ panfrost_resource_destroy(struct pipe_screen *screen,
                 panfrost_bo_unreference(screen, rsrc->bo);
 
         util_range_destroy(&rsrc->valid_buffer_range);
-       FREE(rsrc);
+       ralloc_free(rsrc);
 }
 
 static void *
@@ -451,7 +451,7 @@ panfrost_transfer_map(struct pipe_context *pctx,
         struct panfrost_resource *rsrc = pan_resource(resource);
         struct panfrost_bo *bo = rsrc->bo;
 
-        struct panfrost_gtransfer *transfer = CALLOC_STRUCT(panfrost_gtransfer);
+        struct panfrost_gtransfer *transfer = rzalloc(pctx, struct panfrost_gtransfer);
         transfer->base.level = level;
         transfer->base.usage = usage;
         transfer->base.box = *box;
@@ -508,7 +508,7 @@ panfrost_transfer_map(struct pipe_context *pctx,
                 transfer->base.layer_stride = transfer->base.stride * box->height;
 
                 /* TODO: Reads */
-                transfer->map = malloc(transfer->base.layer_stride * box->depth);
+                transfer->map = rzalloc_size(transfer, transfer->base.layer_stride * box->depth);
 
                 return transfer->map;
         } else {
@@ -569,8 +569,6 @@ panfrost_transfer_unmap(struct pipe_context *pctx,
                                 panfrost_tile_texture(screen, prsrc, trans);
                         }
                 }
-
-                free(trans->map);
         }
 
 
@@ -581,8 +579,8 @@ panfrost_transfer_unmap(struct pipe_context *pctx,
         /* Derefence the resource */
         pipe_resource_reference(&transfer->resource, NULL);
 
-        /* Transfer itself is CALLOCed at the moment */
-        free(transfer);
+        /* Transfer itself is RALLOCed at the moment */
+        ralloc_free(transfer);
 }
 
 static void
@@ -603,7 +601,7 @@ static struct pb_slab *
 panfrost_slab_alloc(void *priv, unsigned heap, unsigned entry_size, unsigned group_index)
 {
         struct panfrost_screen *screen = (struct panfrost_screen *) priv;
-        struct panfrost_memory *mem = CALLOC_STRUCT(panfrost_memory);
+        struct panfrost_memory *mem = rzalloc(screen, struct panfrost_memory);
 
         size_t slab_size = (1 << (MAX_SLAB_ENTRY_SIZE + 1));
 
@@ -613,7 +611,7 @@ panfrost_slab_alloc(void *priv, unsigned heap, unsigned entry_size, unsigned gro
         LIST_INITHEAD(&mem->slab.free);
         for (unsigned i = 0; i < mem->slab.num_entries; ++i) {
                 /* Create a slab entry */
-                struct panfrost_memory_entry *entry = CALLOC_STRUCT(panfrost_memory_entry);
+                struct panfrost_memory_entry *entry = rzalloc(mem, struct panfrost_memory_entry);
                 entry->offset = entry_size * i;
 
                 entry->base.slab = &mem->slab;
@@ -644,6 +642,7 @@ panfrost_slab_free(void *priv, struct pb_slab *slab)
         struct panfrost_screen *screen = (struct panfrost_screen *) priv;
 
         screen->driver->free_slab(screen, mem);
+        ralloc_free(mem);
 }
 
 static void
@@ -708,6 +707,12 @@ panfrost_resource_screen_init(struct panfrost_screen *pscreen)
                         panfrost_slab_free);
 }
 
+void
+panfrost_resource_screen_deinit(struct panfrost_screen *pscreen)
+{
+        pb_slabs_deinit(&pscreen->slabs);
+}
+
 void
 panfrost_resource_context_init(struct pipe_context *pctx)
 {
index d75b68c2ebceb2bc55dbf070d3e0166084dc8d1e..114e283889b09860169747c784f73de206f11ffc 100644 (file)
@@ -122,6 +122,7 @@ pan_transfer(struct pipe_transfer *p)
 }
 
 void panfrost_resource_screen_init(struct panfrost_screen *screen);
+void panfrost_resource_screen_deinit(struct panfrost_screen *screen);
 
 void panfrost_resource_context_init(struct pipe_context *pctx);
 
index 70bff565930fd5d2d37f0dd7a236a0274e52928b..5d3acc0a0dd552a50ae376cab5a1507a104e2722 100644 (file)
@@ -514,9 +514,11 @@ panfrost_is_format_supported( struct pipe_screen *screen,
 
 
 static void
-panfrost_destroy_screen( struct pipe_screen *screen )
+panfrost_destroy_screen(struct pipe_screen *pscreen)
 {
-        FREE(screen);
+        struct panfrost_screen *screen = pan_screen(pscreen);
+        panfrost_resource_screen_deinit(screen);
+        ralloc_free(screen);
 }
 
 static void
@@ -565,7 +567,7 @@ panfrost_screen_get_compiler_options(struct pipe_screen *pscreen,
 struct pipe_screen *
 panfrost_create_screen(int fd, struct renderonly *ro)
 {
-        struct panfrost_screen *screen = CALLOC_STRUCT(panfrost_screen);
+        struct panfrost_screen *screen = rzalloc(NULL, struct panfrost_screen);
 
        pan_debug = debug_get_option_pan_debug();