OSDN Git Service

vc4: Use GEM under simulation even for non-winsys BOs.
authorEric Anholt <eric@anholt.net>
Mon, 4 Aug 2014 20:01:29 +0000 (13:01 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 11 Aug 2014 21:45:32 +0000 (14:45 -0700)
In addition to reducing sim-specific code, it also avoids our local handle
allocation conflicting with the host GEM's handle numbering, which was
causing vc4_gem_hindex() to not distinguish between winsys BOs and the
same-numbered non-winsys bo.

src/gallium/drivers/vc4/vc4_bufmgr.c
src/gallium/drivers/vc4/vc4_simulator.c

index 581ba89..faec853 100644 (file)
@@ -45,7 +45,6 @@ vc4_bo_alloc(struct vc4_screen *screen, uint32_t size, const char *name)
         bo->size = size;
         bo->name = name;
 
-#ifndef USE_VC4_SIMULATOR
         struct drm_mode_create_dumb create;
         memset(&create, 0, sizeof(create));
 
@@ -59,12 +58,6 @@ vc4_bo_alloc(struct vc4_screen *screen, uint32_t size, const char *name)
 
         bo->handle = create.handle;
         assert(create.size >= size);
-#else /* USE_VC4_SIMULATOR */
-        static int next_handle = 0;
-        bo->handle = next_handle++;
-
-        bo->map = malloc(size);
-#endif /* USE_VC4_SIMULATOR */
 
         return bo;
 }
@@ -72,20 +65,23 @@ vc4_bo_alloc(struct vc4_screen *screen, uint32_t size, const char *name)
 void
 vc4_bo_free(struct vc4_bo *bo)
 {
-#ifndef USE_VC4_SIMULATOR
         struct vc4_screen *screen = bo->screen;
 
-        if (bo->map)
+        if (bo->map) {
+#ifdef USE_VC4_SIMULATOR
+                if (bo->simulator_winsys_map) {
+                        free(bo->map);
+                        bo->map = bo->simulator_winsys_map;
+                }
+#endif
                 munmap(bo->map, bo->size);
+        }
 
         struct drm_gem_close c;
         c.handle = bo->handle;
         int ret = drmIoctl(screen->fd, DRM_IOCTL_GEM_CLOSE, &c);
         if (ret != 0)
                 fprintf(stderr, "close object %d: %s\n", bo->handle, strerror(errno));
-#else
-        free(bo->map);
-#endif
 
         free(bo);
 }
@@ -137,7 +133,6 @@ vc4_bo_alloc_mem(struct vc4_screen *screen, const void *data, uint32_t size,
 bool
 vc4_bo_flink(struct vc4_bo *bo, uint32_t *name)
 {
-#ifndef USE_VC4_SIMULATOR
         struct drm_gem_flink flink = {
                 .handle = bo->handle,
         };
@@ -150,7 +145,6 @@ vc4_bo_flink(struct vc4_bo *bo, uint32_t *name)
         }
 
         *name = flink.name;
-#endif /* USE_VC4_SIMULATOR */
 
         return true;
 }
index 88eda4f..8038fee 100644 (file)
@@ -75,6 +75,7 @@ vc4_simulator_pin_bos(struct drm_device *dev, struct exec_info *exec)
                 struct vc4_bo *bo = bos[i];
                 struct drm_gem_cma_object *obj = vc4_wrap_bo_with_cma(dev, bo);
 
+                vc4_bo_map(bo);
                 memcpy(obj->vaddr, bo->map, bo->size);
 
                 exec->bo[i].bo = obj;