pvr: Move pvrsrv sync prim code into new pvr_srv_sync_prim.{c,h}
authorKarmjit Mahil <Karmjit.Mahil@imgtec.com>
Fri, 12 May 2023 12:43:51 +0000 (13:43 +0100)
committerMarge Bot <emma+marge@anholt.net>
Thu, 18 May 2023 12:07:22 +0000 (12:07 +0000)
Some setup for later on when we'll start keeping track of sync
prim allocation with a proper allocator.

Signed-off-by: Karmjit Mahil <Karmjit.Mahil@imgtec.com>
Reviewed-by: Frank Binns <frank.binns@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23076>

src/imagination/vulkan/meson.build
src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv.c
src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv.h
src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv_job_render.c
src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv_sync_prim.c [new file with mode: 0644]
src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv_sync_prim.h [new file with mode: 0644]

index 687738d..6c4ce7f 100644 (file)
@@ -103,6 +103,7 @@ if with_imagination_srv
     'winsys/pvrsrvkm/pvr_srv_job_render.c',
     'winsys/pvrsrvkm/pvr_srv_job_transfer.c',
     'winsys/pvrsrvkm/pvr_srv_sync.c',
+    'winsys/pvrsrvkm/pvr_srv_sync_prim.c',
   )
   pvr_flags += '-DPVR_SUPPORT_SERVICES_DRIVER'
 endif
index 6d75251..f3386e4 100644 (file)
@@ -39,6 +39,7 @@
 #include "pvr_srv_job_transfer.h"
 #include "pvr_srv_public.h"
 #include "pvr_srv_sync.h"
+#include "pvr_srv_sync_prim.h"
 #include "pvr_srv_job_null.h"
 #include "pvr_types.h"
 #include "pvr_winsys.h"
 #include "util/log.h"
 #include "util/macros.h"
 #include "util/os_misc.h"
+#include "util/u_atomic.h"
 #include "vk_log.h"
 #include "vk_sync.h"
 #include "vk_sync_timeline.h"
 
-/* Amount of space used to hold sync prim values (in bytes). */
-#define PVR_SRV_SYNC_PRIM_VALUE_SIZE 4U
-
 /* reserved_size can be 0 when no reserved region is needed. reserved_address
  * must be 0 if reserved_size is 0.
  */
@@ -430,27 +429,6 @@ static void pvr_srv_memctx_finish(struct pvr_srv_winsys *srv_ws)
    pvr_srv_int_ctx_destroy(srv_ws->render_fd, srv_ws->server_memctx);
 }
 
-static VkResult pvr_srv_sync_prim_block_init(struct pvr_srv_winsys *srv_ws)
-{
-   /* We don't currently make use of this value, but we're required to provide
-    * a valid pointer to pvr_srv_alloc_sync_primitive_block.
-    */
-   void *sync_block_pmr;
-
-   return pvr_srv_alloc_sync_primitive_block(srv_ws->render_fd,
-                                             &srv_ws->sync_block_handle,
-                                             &sync_block_pmr,
-                                             &srv_ws->sync_block_size,
-                                             &srv_ws->sync_block_fw_addr);
-}
-
-static void pvr_srv_sync_prim_block_finish(struct pvr_srv_winsys *srv_ws)
-{
-   pvr_srv_free_sync_primitive_block(srv_ws->render_fd,
-                                     srv_ws->sync_block_handle);
-   srv_ws->sync_block_handle = NULL;
-}
-
 static void pvr_srv_winsys_destroy(struct pvr_winsys *ws)
 {
    struct pvr_srv_winsys *srv_ws = to_pvr_srv_winsys(ws);
@@ -772,54 +750,6 @@ err_pvr_srv_connection_destroy:
    return NULL;
 }
 
-struct pvr_srv_sync_prim *pvr_srv_sync_prim_alloc(struct pvr_srv_winsys *srv_ws)
-{
-   struct pvr_srv_sync_prim *sync_prim;
-
-   if (p_atomic_read(&srv_ws->sync_block_offset) == srv_ws->sync_block_size) {
-      vk_error(NULL, VK_ERROR_UNKNOWN);
-      return NULL;
-   }
-
-   sync_prim = vk_alloc(srv_ws->alloc,
-                        sizeof(*sync_prim),
-                        8,
-                        VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
-   if (!sync_prim) {
-      vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
-      return NULL;
-   }
-
-   /* p_atomic_add_return() returns the new value rather than the old one, so
-    * we have to subtract PVR_SRV_SYNC_PRIM_VALUE_SIZE to get the old value.
-    */
-   sync_prim->offset = p_atomic_add_return(&srv_ws->sync_block_offset,
-                                           PVR_SRV_SYNC_PRIM_VALUE_SIZE);
-   sync_prim->offset -= PVR_SRV_SYNC_PRIM_VALUE_SIZE;
-   if (sync_prim->offset == srv_ws->sync_block_size) {
-      /* FIXME: need to free offset back to srv_ws->sync_block_offset. */
-      vk_free(srv_ws->alloc, sync_prim);
-
-      vk_error(NULL, VK_ERROR_UNKNOWN);
-
-      return NULL;
-   }
-
-   sync_prim->srv_ws = srv_ws;
-
-   return sync_prim;
-}
-
-/* FIXME: Add support for freeing offsets back to the sync block. */
-void pvr_srv_sync_prim_free(struct pvr_srv_sync_prim *sync_prim)
-{
-   if (sync_prim) {
-      struct pvr_srv_winsys *srv_ws = sync_prim->srv_ws;
-
-      vk_free(srv_ws->alloc, sync_prim);
-   }
-}
-
 static VkResult pvr_srv_create_presignaled_sync(struct pvr_device *device,
                                                 struct pvr_srv_sync **out_sync)
 {
index f6127d6..0cf301c 100644 (file)
@@ -29,6 +29,7 @@
 #include <vulkan/vulkan.h>
 
 #include "pvr_srv_sync.h"
+#include "pvr_srv_sync_prim.h"
 #include "pvr_winsys.h"
 #include "util/macros.h"
 #include "util/vma.h"
@@ -99,17 +100,7 @@ struct pvr_srv_winsys {
    struct pvr_winsys_vma *usc_vma;
    struct pvr_winsys_vma *general_vma;
 
-   /* Sync block used for allocating sync primitives. */
-   void *sync_block_handle;
-   uint32_t sync_block_size;
-   uint32_t sync_block_fw_addr;
-   uint16_t sync_block_offset;
-};
-
-struct pvr_srv_sync_prim {
-   struct pvr_srv_winsys *srv_ws;
-   uint32_t offset;
-   uint32_t value;
+   struct pvr_srv_sync_prim_ctx sync_prim_ctx;
 };
 
 /*******************************************
@@ -124,16 +115,6 @@ struct pvr_srv_sync_prim {
     functions
  *******************************************/
 
-struct pvr_srv_sync_prim *
-pvr_srv_sync_prim_alloc(struct pvr_srv_winsys *srv_ws);
-void pvr_srv_sync_prim_free(struct pvr_srv_sync_prim *sync_prim);
-
-static inline uint32_t
-pvr_srv_sync_prim_get_fw_addr(const struct pvr_srv_sync_prim *const sync_prim)
-{
-   return sync_prim->srv_ws->sync_block_fw_addr + sync_prim->offset;
-}
-
 VkResult pvr_srv_sync_get_presignaled_sync(struct pvr_device *device,
                                            struct pvr_srv_sync **out_sync);
 
index 95b1e72..55386d4 100644 (file)
@@ -41,6 +41,7 @@
 #include "pvr_srv_job_common.h"
 #include "pvr_srv_job_render.h"
 #include "pvr_srv_sync.h"
+#include "pvr_srv_sync_prim.h"
 #include "pvr_types.h"
 #include "pvr_winsys.h"
 #include "util/log.h"
@@ -254,7 +255,7 @@ VkResult pvr_srv_render_target_dataset_create(
 
 err_srv_sync_prim_free:
    for (uint32_t i = 0; i < ARRAY_SIZE(srv_rt_dataset->rt_datas); i++) {
-      pvr_srv_sync_prim_free(srv_rt_dataset->rt_datas[i].sync_prim);
+      pvr_srv_sync_prim_free(srv_ws, srv_rt_dataset->rt_datas[i].sync_prim);
 
       if (srv_rt_dataset->rt_datas[i].handle) {
          pvr_srv_rgx_destroy_hwrt_dataset(srv_ws->render_fd,
@@ -276,7 +277,7 @@ void pvr_srv_render_target_dataset_destroy(
       to_pvr_srv_winsys_rt_dataset(rt_dataset);
 
    for (uint32_t i = 0; i < ARRAY_SIZE(srv_rt_dataset->rt_datas); i++) {
-      pvr_srv_sync_prim_free(srv_rt_dataset->rt_datas[i].sync_prim);
+      pvr_srv_sync_prim_free(srv_ws, srv_rt_dataset->rt_datas[i].sync_prim);
 
       if (srv_rt_dataset->rt_datas[i].handle) {
          pvr_srv_rgx_destroy_hwrt_dataset(srv_ws->render_fd,
@@ -754,14 +755,14 @@ VkResult pvr_srv_winsys_render_submit(
                                         NULL,
                                         NULL,
                                         1,
-                                        &sync_prim->srv_ws->sync_block_handle,
+                                        &sync_prim->ctx->block_handle,
                                         &sync_prim->offset,
                                         &sync_prim->value,
                                         0,
                                         NULL,
                                         NULL,
                                         NULL,
-                                        sync_prim->srv_ws->sync_block_handle,
+                                        sync_prim->ctx->block_handle,
                                         sync_prim->offset,
                                         sync_prim->value,
                                         in_geom_fd,
diff --git a/src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv_sync_prim.c b/src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv_sync_prim.c
new file mode 100644 (file)
index 0000000..8e580da
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright © 2023 Imagination Technologies 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.
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+#include <vulkan/vulkan_core.h>
+
+#include "pvr_srv.h"
+#include "pvr_srv_bridge.h"
+#include "pvr_srv_sync_prim.h"
+#include "util/u_atomic.h"
+#include "vk_alloc.h"
+#include "vk_log.h"
+
+/* Amount of space used to hold sync prim values (in bytes). */
+#define PVR_SRV_SYNC_PRIM_VALUE_SIZE 4
+
+VkResult pvr_srv_sync_prim_block_init(struct pvr_srv_winsys *srv_ws)
+{
+   /* We don't currently make use of this value, but we're required to provide
+    * a valid pointer to pvr_srv_alloc_sync_primitive_block.
+    */
+   void *sync_block_pmr;
+
+   return pvr_srv_alloc_sync_primitive_block(
+      srv_ws->render_fd,
+      &srv_ws->sync_prim_ctx.block_handle,
+      &sync_block_pmr,
+      &srv_ws->sync_prim_ctx.block_size,
+      &srv_ws->sync_prim_ctx.block_fw_addr);
+}
+
+void pvr_srv_sync_prim_block_finish(struct pvr_srv_winsys *srv_ws)
+{
+   pvr_srv_free_sync_primitive_block(srv_ws->render_fd,
+                                     srv_ws->sync_prim_ctx.block_handle);
+   srv_ws->sync_prim_ctx.block_handle = NULL;
+}
+
+struct pvr_srv_sync_prim *pvr_srv_sync_prim_alloc(struct pvr_srv_winsys *srv_ws)
+{
+   struct pvr_srv_sync_prim *sync_prim;
+
+   if (p_atomic_read(&srv_ws->sync_prim_ctx.block_offset) ==
+       srv_ws->sync_prim_ctx.block_size) {
+      vk_error(NULL, VK_ERROR_UNKNOWN);
+      return NULL;
+   }
+
+   sync_prim = vk_alloc(srv_ws->alloc,
+                        sizeof(*sync_prim),
+                        8,
+                        VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
+   if (!sync_prim) {
+      vk_error(NULL, VK_ERROR_OUT_OF_HOST_MEMORY);
+      return NULL;
+   }
+
+   /* p_atomic_add_return() returns the new value rather than the old one, so
+    * we have to subtract PVR_SRV_SYNC_PRIM_VALUE_SIZE to get the old value.
+    */
+   sync_prim->offset = p_atomic_add_return(&srv_ws->sync_prim_ctx.block_offset,
+                                           PVR_SRV_SYNC_PRIM_VALUE_SIZE);
+   sync_prim->offset -= PVR_SRV_SYNC_PRIM_VALUE_SIZE;
+   if (sync_prim->offset == srv_ws->sync_prim_ctx.block_size) {
+      /* FIXME: need to free offset back to srv_ws->sync_block_offset. */
+      vk_free(srv_ws->alloc, sync_prim);
+
+      vk_error(NULL, VK_ERROR_UNKNOWN);
+
+      return NULL;
+   }
+
+   sync_prim->ctx = &srv_ws->sync_prim_ctx;
+
+   return sync_prim;
+}
+
+/* FIXME: Add support for freeing offsets back to the sync block. */
+void pvr_srv_sync_prim_free(struct pvr_srv_winsys *srv_ws,
+                            struct pvr_srv_sync_prim *sync_prim)
+{
+   vk_free(srv_ws->alloc, sync_prim);
+}
diff --git a/src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv_sync_prim.h b/src/imagination/vulkan/winsys/pvrsrvkm/pvr_srv_sync_prim.h
new file mode 100644 (file)
index 0000000..6854f13
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright © 2023 Imagination Technologies 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.
+ */
+
+#ifndef PVR_SRV_SYNC_PRIM_H
+#define PVR_SRV_SYNC_PRIM_H
+
+#include <stdint.h>
+#include <vulkan/vulkan_core.h>
+
+struct pvr_srv_winsys;
+
+struct pvr_srv_sync_prim_ctx {
+   /* Sync block used for allocating sync primitives. */
+   void *block_handle;
+   uint32_t block_size;
+   uint32_t block_fw_addr;
+   uint16_t block_offset;
+};
+
+struct pvr_srv_sync_prim {
+   struct pvr_srv_sync_prim_ctx *ctx;
+   uint32_t offset;
+   uint32_t value;
+};
+
+VkResult pvr_srv_sync_prim_block_init(struct pvr_srv_winsys *srv_ws);
+void pvr_srv_sync_prim_block_finish(struct pvr_srv_winsys *srv_ws);
+
+struct pvr_srv_sync_prim *
+pvr_srv_sync_prim_alloc(struct pvr_srv_winsys *srv_ws);
+void pvr_srv_sync_prim_free(struct pvr_srv_winsys *srv_ws,
+                            struct pvr_srv_sync_prim *sync_prim);
+
+static inline uint32_t
+pvr_srv_sync_prim_get_fw_addr(const struct pvr_srv_sync_prim *const sync_prim)
+{
+   return sync_prim->ctx->block_fw_addr + sync_prim->offset;
+}
+
+#endif /* PVR_SRV_SYNC_PRIM_H */