vc4: Flush the job early if we're referencing too many BOs.
authorEric Anholt <eric@anholt.net>
Wed, 4 Jan 2017 19:24:31 +0000 (11:24 -0800)
committerEric Anholt <eric@anholt.net>
Fri, 6 Jan 2017 00:23:32 +0000 (16:23 -0800)
If we get up toward 256MB (or whatever the CMA area size is),
VC4_GEM_CREATE will start throwing errors.  Even if we don't trigger
that, when we flush the kernel's BO allocation for the CLs or bin
memory may end up throwing an error, at which point our job won't get
rendered at all.

Just flush early (half of maximum CMA size) so that hopefully we never
get to that point.

src/gallium/drivers/vc4/vc4_cl.c
src/gallium/drivers/vc4/vc4_context.h
src/gallium/drivers/vc4/vc4_draw.c

index 91f51b02bb666e51e60cc03be17f58cab7ef9bd8..35578370e2ca50c38191adb9cb9bbe429fdecb9c 100644 (file)
@@ -76,5 +76,7 @@ vc4_gem_hindex(struct vc4_job *job, struct vc4_bo *bo)
         cl_ptr(&out, vc4_bo_reference(bo));
         cl_end(&job->bo_pointers, out);
 
+        job->bo_space += bo->size;
+
         return hindex;
 }
index 2005ae0e4eaf6f0b95f467a7b513f6f386826841..6bd2424ec797a2ac90a6491f980b189ba2b99dc4 100644 (file)
@@ -228,6 +228,13 @@ struct vc4_job {
         struct vc4_cl bo_handles;
         struct vc4_cl bo_pointers;
         uint32_t shader_rec_count;
+        /**
+         * Amount of memory used by the BOs in bo_pointers.
+         *
+         * Used for checking when we should flush the job early so we don't
+         * OOM.
+         */
+        uint32_t bo_space;
 
         /** @{ Surfaces to submit rendering for. */
         struct pipe_surface *color_read;
index 13db9daeb9ed2d478b18c26a843870b26981aabb..ebd080298a4b37cff6ad329a950d321c1fda584b 100644 (file)
@@ -466,6 +466,13 @@ vc4_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
 
         job->resolve |= PIPE_CLEAR_COLOR0;
 
+        /* If we've used half of the presumably 256MB CMA area, flush the job
+         * so that we don't accumulate a job that will end up not being
+         * executable.
+         */
+        if (job->bo_space > 128 * 1024 * 1024)
+                vc4_flush(pctx);
+
         if (vc4_debug & VC4_DEBUG_ALWAYS_FLUSH)
                 vc4_flush(pctx);
 }