Module: Mesa
Branch: main
Commit: 30316246d0809bf9d148f961a15a475dd22a97aa
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=30316246d0809bf9d148f961a15a475dd22a97aa

Author: Yiwei Zhang <zzyi...@chromium.org>
Date:   Thu Dec 28 17:22:42 2023 -0800

venus: make tls hint specific to pipeline creation

This is to prepare for a new multi-ring design. A preview is as below:
- primary ring will migrate to be asynchronous only
- synchronous commands will be via thread local rings
- pipeline creations will be synchronous and dispatched to thread local
  rings unless being forced to be async on primary ring
- perf option no_multi_ring is made generic to force a single ring

Pipeline cache retrieval is temporarily moved back to primary ring, but
will be moved to thread local later since it's a synchronous command.
The dependency resolving will follow the same with pipeline create with
detailed rationale later.

Signed-off-by: Yiwei Zhang <zzyi...@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26838>

---

 src/virtio/vulkan/vn_android.c        |  2 +-
 src/virtio/vulkan/vn_command_buffer.c |  2 +-
 src/virtio/vulkan/vn_common.h         | 17 +++++++----------
 src/virtio/vulkan/vn_device.c         |  5 -----
 src/virtio/vulkan/vn_device.h         |  1 -
 src/virtio/vulkan/vn_pipeline.c       |  8 +++-----
 src/virtio/vulkan/vn_wsi.c            |  2 +-
 7 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/src/virtio/vulkan/vn_android.c b/src/virtio/vulkan/vn_android.c
index 185587dea15..7eeb118a875 100644
--- a/src/virtio/vulkan/vn_android.c
+++ b/src/virtio/vulkan/vn_android.c
@@ -342,7 +342,7 @@ vn_GetSwapchainGrallocUsage2ANDROID(
    if (swapchainImageUsage & VK_SWAPCHAIN_IMAGE_USAGE_SHARED_BIT_ANDROID)
       *grallocProducerUsage |= vn_android_gralloc_get_shared_present_usage();
 
-   vn_tls_set_primary_ring_submission();
+   vn_tls_set_async_pipeline_create();
 
    return VK_SUCCESS;
 }
diff --git a/src/virtio/vulkan/vn_command_buffer.c 
b/src/virtio/vulkan/vn_command_buffer.c
index 8c275335ca1..215357486d9 100644
--- a/src/virtio/vulkan/vn_command_buffer.c
+++ b/src/virtio/vulkan/vn_command_buffer.c
@@ -687,7 +687,7 @@ vn_CreateCommandPool(VkDevice device,
    vn_async_vkCreateCommandPool(dev->primary_ring, device, pCreateInfo, NULL,
                                 &pool_handle);
 
-   vn_tls_set_primary_ring_submission();
+   vn_tls_set_async_pipeline_create();
 
    *pCommandPool = pool_handle;
 
diff --git a/src/virtio/vulkan/vn_common.h b/src/virtio/vulkan/vn_common.h
index 3359f211703..c802b28493e 100644
--- a/src/virtio/vulkan/vn_common.h
+++ b/src/virtio/vulkan/vn_common.h
@@ -211,13 +211,10 @@ struct vn_relax_state {
 };
 
 struct vn_tls {
-   /* Track swapchain and command pool creations on threads so dispatch of the
-    * following on non-tracked threads can be routed as synchronous on the
-    * secondary ring:
-    * - pipeline creations
-    * - pipeline cache retrievals
+   /* Track the threads on which swapchain and command pool creations occur.
+    * Pipeline create on those threads are forced async via the primary ring.
     */
-   bool primary_ring_submission;
+   bool async_pipeline_create;
 };
 
 void
@@ -488,19 +485,19 @@ struct vn_tls *
 vn_tls_get(void);
 
 static inline void
-vn_tls_set_primary_ring_submission(void)
+vn_tls_set_async_pipeline_create(void)
 {
    struct vn_tls *tls = vn_tls_get();
    if (likely(tls))
-      tls->primary_ring_submission = true;
+      tls->async_pipeline_create = true;
 }
 
 static inline bool
-vn_tls_get_primary_ring_submission(void)
+vn_tls_get_async_pipeline_create(void)
 {
    const struct vn_tls *tls = vn_tls_get();
    if (likely(tls))
-      return tls->primary_ring_submission;
+      return tls->async_pipeline_create;
    return true;
 }
 
diff --git a/src/virtio/vulkan/vn_device.c b/src/virtio/vulkan/vn_device.c
index ea6410c2d7e..0844f8b9747 100644
--- a/src/virtio/vulkan/vn_device.c
+++ b/src/virtio/vulkan/vn_device.c
@@ -441,8 +441,6 @@ vn_device_secondary_ring_init_once(struct vn_device *dev)
 {
    VN_TRACE_FUNC();
 
-   assert(!dev->force_primary_ring_submission);
-
    static bool ok = true;
    if (!ok)
       return ok;
@@ -489,9 +487,6 @@ vn_device_init(struct vn_device *dev,
    dev->renderer = instance->renderer;
    dev->primary_ring = instance->ring.ring;
 
-   /* can be extended for app compat purpose */
-   dev->force_primary_ring_submission = VN_PERF(NO_MULTI_RING);
-
    create_info =
       vn_device_fix_create_info(dev, create_info, alloc, &local_create_info);
    if (!create_info)
diff --git a/src/virtio/vulkan/vn_device.h b/src/virtio/vulkan/vn_device.h
index 9fde8ce161a..d5c610bee7a 100644
--- a/src/virtio/vulkan/vn_device.h
+++ b/src/virtio/vulkan/vn_device.h
@@ -30,7 +30,6 @@ struct vn_device {
    struct vn_physical_device *physical_device;
    struct vn_renderer *renderer;
    struct vn_ring *primary_ring;
-   bool force_primary_ring_submission;
 
    mtx_t ring_mutex;
    struct vn_ring *secondary_ring;
diff --git a/src/virtio/vulkan/vn_pipeline.c b/src/virtio/vulkan/vn_pipeline.c
index ff197625251..375b47ef0f1 100644
--- a/src/virtio/vulkan/vn_pipeline.c
+++ b/src/virtio/vulkan/vn_pipeline.c
@@ -449,10 +449,10 @@ vn_DestroyPipelineCache(VkDevice device,
 static struct vn_ring *
 vn_get_target_ring(struct vn_device *dev)
 {
-   if (dev->force_primary_ring_submission)
+   if (VN_PERF(NO_MULTI_RING))
       return dev->primary_ring;
 
-   if (vn_tls_get_primary_ring_submission())
+   if (vn_tls_get_async_pipeline_create())
       return dev->primary_ring;
 
    if (!dev->secondary_ring) {
@@ -483,9 +483,7 @@ vn_GetPipelineCacheData(VkDevice device,
    VN_TRACE_FUNC();
    struct vn_device *dev = vn_device_from_handle(device);
    struct vn_physical_device *physical_dev = dev->physical_device;
-
-   struct vn_ring *target_ring = vn_get_target_ring(dev);
-   assert(target_ring);
+   struct vn_ring *target_ring = dev->primary_ring;
 
    struct vk_pipeline_cache_header *header = pData;
    VkResult result;
diff --git a/src/virtio/vulkan/vn_wsi.c b/src/virtio/vulkan/vn_wsi.c
index 7ff7210cefa..ca8e2a078ba 100644
--- a/src/virtio/vulkan/vn_wsi.c
+++ b/src/virtio/vulkan/vn_wsi.c
@@ -273,7 +273,7 @@ vn_CreateSwapchainKHR(VkDevice device,
              VN_WSI_PTR(pCreateInfo->oldSwapchain));
    }
 
-   vn_tls_set_primary_ring_submission();
+   vn_tls_set_async_pipeline_create();
 
    return vn_result(dev->instance, result);
 }

Reply via email to