Mesa (master): vc4: Fix simulator when more than one vc4_screen is opened.

Eric Anholt anholt at kemper.freedesktop.org
Fri Oct 7 01:30:46 UTC 2016


Module: Mesa
Branch: master
Commit: 06cc3dfda49b557b177ea6a5bc4fb87e087df21a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=06cc3dfda49b557b177ea6a5bc4fb87e087df21a

Author: Eric Anholt <eric at anholt.net>
Date:   Tue Oct  4 16:29:26 2016 -0700

vc4: Fix simulator when more than one vc4_screen is opened.

We would assertion fail in setting up the simulator the second time
around.  This at least postpones the assertion failure until we've closed
all of the first set of screens and started opening a new set.

---

 src/gallium/drivers/vc4/vc4_context.h   |  1 +
 src/gallium/drivers/vc4/vc4_screen.c    |  5 +++++
 src/gallium/drivers/vc4/vc4_simulator.c | 36 ++++++++++++++++++++++++++++++---
 3 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/vc4/vc4_context.h b/src/gallium/drivers/vc4/vc4_context.h
index 0d6b8d0..313630a 100644
--- a/src/gallium/drivers/vc4/vc4_context.h
+++ b/src/gallium/drivers/vc4/vc4_context.h
@@ -423,6 +423,7 @@ void vc4_program_init(struct pipe_context *pctx);
 void vc4_program_fini(struct pipe_context *pctx);
 void vc4_query_init(struct pipe_context *pctx);
 void vc4_simulator_init(struct vc4_screen *screen);
+void vc4_simulator_destroy(struct vc4_screen *screen);
 int vc4_simulator_flush(struct vc4_context *vc4,
                         struct drm_vc4_submit_cl *args,
                         struct vc4_job *job);
diff --git a/src/gallium/drivers/vc4/vc4_screen.c b/src/gallium/drivers/vc4/vc4_screen.c
index 64bff5d..045f3fb 100644
--- a/src/gallium/drivers/vc4/vc4_screen.c
+++ b/src/gallium/drivers/vc4/vc4_screen.c
@@ -99,6 +99,11 @@ vc4_screen_destroy(struct pipe_screen *pscreen)
         util_hash_table_destroy(screen->bo_handles);
         vc4_bufmgr_destroy(pscreen);
         slab_destroy_parent(&screen->transfer_pool);
+
+#if USE_VC4_SIMULATOR
+        vc4_simulator_destroy(screen);
+#endif
+
         close(screen->fd);
         ralloc_free(pscreen);
 }
diff --git a/src/gallium/drivers/vc4/vc4_simulator.c b/src/gallium/drivers/vc4/vc4_simulator.c
index b802391..0291a4e 100644
--- a/src/gallium/drivers/vc4/vc4_simulator.c
+++ b/src/gallium/drivers/vc4/vc4_simulator.c
@@ -32,6 +32,8 @@
 #include "vc4_simulator_validate.h"
 #include "simpenrose/simpenrose.h"
 
+static mtx_t exec_mutex = _MTX_INITIALIZER_NP;
+
 /* A marker placed just after each BO, then checked after rendering to make
  * sure it's still there.
  */
@@ -318,12 +320,27 @@ vc4_simulator_flush(struct vc4_context *vc4,
         return 0;
 }
 
+static void *sim_mem_base = NULL;
+static int sim_mem_refcount = 0;
+static ssize_t sim_mem_size = 256 * 1024 * 1024;
+
 void
 vc4_simulator_init(struct vc4_screen *screen)
 {
-        screen->simulator_mem_size = 256 * 1024 * 1024;
-        screen->simulator_mem_base = ralloc_size(screen,
-                                                 screen->simulator_mem_size);
+        mtx_lock(&exec_mutex);
+        if (sim_mem_refcount++) {
+                screen->simulator_mem_size = sim_mem_size;
+                screen->simulator_mem_base = sim_mem_base;
+                mtx_unlock(&exec_mutex);
+                return;
+        }
+
+        sim_mem_base = calloc(sim_mem_size, 1);
+        if (!sim_mem_base)
+                abort();
+
+        screen->simulator_mem_size = sim_mem_size;
+        screen->simulator_mem_base = sim_mem_base;
 
         /* We supply our own memory so that we can have more aperture
          * available (256MB instead of simpenrose's default 64MB).
@@ -339,6 +356,19 @@ vc4_simulator_init(struct vc4_screen *screen)
          * flush), so it had better be big.
          */
         simpenrose_supply_overflow_mem(0, OVERFLOW_SIZE);
+
+        mtx_unlock(&exec_mutex);
+}
+
+void
+vc4_simulator_destroy(struct vc4_screen *screen)
+{
+        mtx_lock(&exec_mutex);
+        if (!--sim_mem_refcount) {
+                free(sim_mem_base);
+                sim_mem_base = NULL;
+        }
+        mtx_unlock(&exec_mutex);
 }
 
 #endif /* USE_VC4_SIMULATOR */




More information about the mesa-commit mailing list