panfrost: Stub out panfrost_bo_cache_get
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 15 Jul 2019 15:13:10 +0000 (08:13 -0700)
committerAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Mon, 15 Jul 2019 23:12:55 +0000 (16:12 -0700)
We will use this function to fetch cached BOs instead of freshly
allocating them.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
src/gallium/drivers/panfrost/meson.build
src/gallium/drivers/panfrost/pan_bo_cache.c [new file with mode: 0644]
src/gallium/drivers/panfrost/pan_drm.c
src/gallium/drivers/panfrost/pan_screen.h

index 03dd4f5c20ae8dce2fc3ca8192ef715d039c48aa..a050a286d5edc5a19b20dcca409ff67b99ae88cc 100644 (file)
@@ -33,6 +33,7 @@ files_panfrost = files(
 
   'pan_context.c',
   'pan_afbc.c',
+  'pan_bo_cache.c',
   'pan_blit.c',
   'pan_job.c',
   'pan_drm.c',
diff --git a/src/gallium/drivers/panfrost/pan_bo_cache.c b/src/gallium/drivers/panfrost/pan_bo_cache.c
new file mode 100644 (file)
index 0000000..b64f9fe
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2019 Collabora, Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Authors (Collabora):
+ *   Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
+ */
+
+#include "pan_screen.h"
+
+struct panfrost_bo *
+panfrost_bo_cache_fetch(
+                struct panfrost_screen *screen,
+                size_t size, uint32_t flags)
+{
+        /* Stub */
+        return NULL;
+}
index c64117ce014ad35da0c23c52870207c463aa4afe..135eb4d829146c5da75e4ba26bae7e8c47b2560d 100644 (file)
@@ -83,7 +83,7 @@ struct panfrost_bo *
 panfrost_drm_create_bo(struct panfrost_screen *screen, size_t size,
                        uint32_t flags)
 {
-        struct panfrost_bo *bo = rzalloc(screen, struct panfrost_bo);
+        struct panfrost_bo *bo;
 
         /* Kernel will fail (confusingly) with EPERM otherwise */
         assert(size > 0);
@@ -96,17 +96,31 @@ panfrost_drm_create_bo(struct panfrost_screen *screen, size_t size,
                 .size = size,
                 .flags = translated_flags,
         };
-        int ret;
 
-        ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_CREATE_BO, &create_bo);
-        if (ret) {
-                fprintf(stderr, "DRM_IOCTL_PANFROST_CREATE_BO failed: %d\n", ret);
-                assert(0);
-        }
+        /* Before creating a BO, we first want to check the cache */
+
+        bo = panfrost_bo_cache_fetch(screen, size, flags);
 
-        bo->size = create_bo.size;
-        bo->gpu = create_bo.offset;
-        bo->gem_handle = create_bo.handle;
+        if (bo == NULL) {
+                /* Otherwise, the cache misses and we need to allocate a BO fresh from
+                 * the kernel */
+
+                int ret;
+
+                ret = drmIoctl(screen->fd, DRM_IOCTL_PANFROST_CREATE_BO, &create_bo);
+                if (ret) {
+                        fprintf(stderr, "DRM_IOCTL_PANFROST_CREATE_BO failed: %d\n", ret);
+                        assert(0);
+                }
+
+                /* We have a BO allocated from the kernel; fill in the userspace
+                 * version */
+
+                bo = rzalloc(screen, struct panfrost_bo);
+                bo->size = create_bo.size;
+                bo->gpu = create_bo.offset;
+                bo->gem_handle = create_bo.handle;
+        }
 
         /* Only mmap now if we know we need to. For CPU-invisible buffers, we
          * never map since we don't care about their contents; they're purely
index a0c6e2df63d8b88573f2acb62f55f5997d974e31..d34574f7a7550d9a5d6961a4777c1d558affebf7 100644 (file)
@@ -161,5 +161,10 @@ panfrost_drm_fence_finish(struct pipe_screen *pscreen,
                           struct pipe_context *ctx,
                           struct pipe_fence_handle *fence,
                           uint64_t timeout);
+struct panfrost_bo *
+panfrost_bo_cache_fetch(
+                struct panfrost_screen *screen,
+                size_t size, uint32_t flags);
+
 
 #endif /* PAN_SCREEN_H */