Mesa (main): vulkan: Depend on vk_pipeline_layout in vk_cmd_enqueue

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 29 21:01:20 UTC 2022


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

Author: Jason Ekstrand <jason.ekstrand at collabora.com>
Date:   Tue Jun 28 14:54:30 2022 -0500

vulkan: Depend on vk_pipeline_layout in vk_cmd_enqueue

Now that we have a common pipeline layout with reference counting, we
don't need these driver hooks for reference counting anymore.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Reviewed-by: Jesse Natalie <jenatali at microsoft.com>
Reviewed-by: Boris Brezillon <boris.brezillon at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17286>

---

 src/gallium/frontends/lavapipe/lvp_device.c | 19 -------------------
 src/microsoft/vulkan/dzn_device.c           | 18 ------------------
 src/panfrost/vulkan/panvk_device.c          | 20 --------------------
 src/vulkan/runtime/vk_cmd_enqueue.c         |  9 +++++----
 src/vulkan/runtime/vk_device.h              | 16 ----------------
 5 files changed, 5 insertions(+), 77 deletions(-)

diff --git a/src/gallium/frontends/lavapipe/lvp_device.c b/src/gallium/frontends/lavapipe/lvp_device.c
index 1f15f26ebba..996f86eaf21 100644
--- a/src/gallium/frontends/lavapipe/lvp_device.c
+++ b/src/gallium/frontends/lavapipe/lvp_device.c
@@ -1493,22 +1493,6 @@ lvp_queue_finish(struct lvp_queue *queue)
    queue->ctx->destroy(queue->ctx);
 }
 
-static void
-ref_pipeline_layout(struct vk_device *vk_device, VkPipelineLayout _layout)
-{
-   LVP_FROM_HANDLE(lvp_pipeline_layout, layout, _layout);
-
-   vk_pipeline_layout_ref(&layout->vk);
-}
-
-static void
-unref_pipeline_layout(struct vk_device *device, VkPipelineLayout _layout)
-{
-   LVP_FROM_HANDLE(lvp_pipeline_layout, layout, _layout);
-
-   vk_pipeline_layout_unref(device, &layout->vk);
-}
-
 VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDevice(
    VkPhysicalDevice                            physicalDevice,
    const VkDeviceCreateInfo*                   pCreateInfo,
@@ -1553,9 +1537,6 @@ VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateDevice(
    device->instance = (struct lvp_instance *)physical_device->vk.instance;
    device->physical_device = physical_device;
 
-   device->vk.ref_pipeline_layout = ref_pipeline_layout;
-   device->vk.unref_pipeline_layout = unref_pipeline_layout;
-
    device->pscreen = physical_device->pscreen;
 
    assert(pCreateInfo->queueCreateInfoCount == 1);
diff --git a/src/microsoft/vulkan/dzn_device.c b/src/microsoft/vulkan/dzn_device.c
index cdccd1e3cbc..33b6b595a3a 100644
--- a/src/microsoft/vulkan/dzn_device.c
+++ b/src/microsoft/vulkan/dzn_device.c
@@ -1857,22 +1857,6 @@ dzn_device_create_sync_for_memory(struct vk_device *device,
                          0, 1, sync_out);
 }
 
-static void
-dzn_device_ref_pipeline_layout(struct vk_device *dev, VkPipelineLayout layout)
-{
-   VK_FROM_HANDLE(dzn_pipeline_layout, playout, layout);
-
-   dzn_pipeline_layout_ref(playout);
-}
-
-static void
-dzn_device_unref_pipeline_layout(struct vk_device *dev, VkPipelineLayout layout)
-{
-   VK_FROM_HANDLE(dzn_pipeline_layout, playout, layout);
-
-   dzn_pipeline_layout_unref(playout);
-}
-
 static VkResult
 dzn_device_query_init(struct dzn_device *device)
 {
@@ -2008,8 +1992,6 @@ dzn_device_create(struct dzn_physical_device *pdev,
     * whole struct.
     */
    device->vk.command_dispatch_table = &device->cmd_dispatch;
-   device->vk.ref_pipeline_layout = dzn_device_ref_pipeline_layout;
-   device->vk.unref_pipeline_layout = dzn_device_unref_pipeline_layout;
    device->vk.create_sync_for_memory = dzn_device_create_sync_for_memory;
    device->vk.check_status = dzn_device_check_status;
 
diff --git a/src/panfrost/vulkan/panvk_device.c b/src/panfrost/vulkan/panvk_device.c
index 4664c93111c..4dfa080d5c2 100644
--- a/src/panfrost/vulkan/panvk_device.c
+++ b/src/panfrost/vulkan/panvk_device.c
@@ -932,24 +932,6 @@ panvk_queue_finish(struct panvk_queue *queue)
    vk_queue_finish(&queue->vk);
 }
 
-static void
-panvk_ref_pipeline_layout(struct vk_device *dev,
-                          VkPipelineLayout layout)
-{
-   VK_FROM_HANDLE(vk_pipeline_layout, playout, layout);
-
-   vk_pipeline_layout_ref(playout);
-}
-
-static void
-panvk_unref_pipeline_layout(struct vk_device *dev,
-                            VkPipelineLayout layout)
-{
-   VK_FROM_HANDLE(vk_pipeline_layout, playout, layout);
-
-   vk_pipeline_layout_unref(dev, playout);
-}
-
 VkResult
 panvk_CreateDevice(VkPhysicalDevice physicalDevice,
                    const VkDeviceCreateInfo *pCreateInfo,
@@ -1019,8 +1001,6 @@ panvk_CreateDevice(VkPhysicalDevice physicalDevice,
     * whole struct.
     */
    device->vk.command_dispatch_table = &device->cmd_dispatch;
-   device->vk.ref_pipeline_layout = panvk_ref_pipeline_layout;
-   device->vk.unref_pipeline_layout = panvk_unref_pipeline_layout;
 
    device->instance = physical_device->instance;
    device->physical_device = physical_device;
diff --git a/src/vulkan/runtime/vk_cmd_enqueue.c b/src/vulkan/runtime/vk_cmd_enqueue.c
index ce3b530d531..f40c3a6693e 100644
--- a/src/vulkan/runtime/vk_cmd_enqueue.c
+++ b/src/vulkan/runtime/vk_cmd_enqueue.c
@@ -26,6 +26,7 @@
 #include "vk_cmd_enqueue_entrypoints.h"
 #include "vk_command_buffer.h"
 #include "vk_device.h"
+#include "vk_pipeline_layout.h"
 #include "vk_util.h"
 
 VKAPI_ATTR void VKAPI_CALL
@@ -202,11 +203,12 @@ unref_pipeline_layout(struct vk_cmd_queue *queue,
 {
    struct vk_command_buffer *cmd_buffer =
       container_of(queue, struct vk_command_buffer, cmd_queue);
-   struct vk_device *device = cmd_buffer->base.device;
+   VK_FROM_HANDLE(vk_pipeline_layout, layout,
+                  cmd->u.bind_descriptor_sets.layout);
 
    assert(cmd->type == VK_CMD_BIND_DESCRIPTOR_SETS);
 
-   device->unref_pipeline_layout(device, cmd->u.bind_descriptor_sets.layout);
+   vk_pipeline_layout_unref(cmd_buffer->base.device, layout);
 }
 
 VKAPI_ATTR void VKAPI_CALL
@@ -220,7 +222,6 @@ vk_cmd_enqueue_CmdBindDescriptorSets(VkCommandBuffer commandBuffer,
                                      const uint32_t *pDynamicOffsets)
 {
    VK_FROM_HANDLE(vk_command_buffer, cmd_buffer, commandBuffer);
-   struct vk_device *device = cmd_buffer->base.device;
 
    struct vk_cmd_queue_entry *cmd =
       vk_zalloc(cmd_buffer->cmd_queue.alloc, sizeof(*cmd), 8,
@@ -235,7 +236,7 @@ vk_cmd_enqueue_CmdBindDescriptorSets(VkCommandBuffer commandBuffer,
     * command is in the queue.  Otherwise, it may get deleted out from under
     * us before the command is replayed.
     */
-   device->ref_pipeline_layout(device, layout);
+   vk_pipeline_layout_ref(vk_pipeline_layout_from_handle(layout));
    cmd->u.bind_descriptor_sets.layout = layout;
    cmd->driver_free_cb = unref_pipeline_layout;
 
diff --git a/src/vulkan/runtime/vk_device.h b/src/vulkan/runtime/vk_device.h
index 97b286fc413..52afa783090 100644
--- a/src/vulkan/runtime/vk_device.h
+++ b/src/vulkan/runtime/vk_device.h
@@ -169,22 +169,6 @@ struct vk_device {
                                       bool signal_memory,
                                       struct vk_sync **sync_out);
 
-   /** Increments the reference count on a pipeline layout
-    *
-    * This is required for vk_enqueue_CmdBindDescriptorSets() to avoid
-    * use-after-free problems with pipeline layouts.  If you're not using
-    * the command queue, you can ignore this.
-    */
-   void (*ref_pipeline_layout)(struct vk_device *device,
-                               VkPipelineLayout layout);
-
-   /** Decrements the reference count on a pipeline layout
-    *
-    * See ref_pipeline_layout above.
-    */
-   void (*unref_pipeline_layout)(struct vk_device *device,
-                                 VkPipelineLayout layout);
-
    /* Set by vk_device_set_drm_fd() */
    int drm_fd;
 



More information about the mesa-commit mailing list