Jan Sikorski : wined3d: Defer destroying Vulkan compute pipelines.

Alexandre Julliard julliard at winehq.org
Wed Jul 13 16:56:08 CDT 2022


Module: wine
Branch: master
Commit: a3d5026e42bf2f870f38be767bcd482807d8a03c
URL:    https://gitlab.winehq.org/wine/wine/-/commit/a3d5026e42bf2f870f38be767bcd482807d8a03c

Author: Jan Sikorski <jsikorski at codeweavers.com>
Date:   Tue Jul 12 15:13:43 2022 +0200

wined3d: Defer destroying Vulkan compute pipelines.

Vulkan pipelines should be destroyed only after the last command buffer using
the pipeline is done executing. Since we do not track which pipelines are
encoded into which command buffers, defer destruction until the current command
buffer finishes.

Signed-off-by: Jan Sikorski <jsikorski at codeweavers.com>

---

 dlls/wined3d/context_vk.c      | 31 +++++++++++++++++++++++++++++++
 dlls/wined3d/shader_spirv.c    |  3 ++-
 dlls/wined3d/wined3d_private.h |  4 ++++
 3 files changed, 37 insertions(+), 1 deletion(-)

diff --git a/dlls/wined3d/context_vk.c b/dlls/wined3d/context_vk.c
index a9b875a132e..b738e97b6cf 100644
--- a/dlls/wined3d/context_vk.c
+++ b/dlls/wined3d/context_vk.c
@@ -964,6 +964,32 @@ static void wined3d_context_vk_reset_completed_queries(struct wined3d_context_vk
     memset(pool_vk->completed, 0, sizeof(pool_vk->completed));
 }
 
+void wined3d_context_vk_destroy_vk_pipeline(struct wined3d_context_vk *context_vk,
+        VkPipeline vk_pipeline, uint64_t command_buffer_id)
+{
+    struct wined3d_device_vk *device_vk = wined3d_device_vk(context_vk->c.device);
+    const struct wined3d_vk_info *vk_info = context_vk->vk_info;
+    struct wined3d_retired_object_vk *o;
+
+    if (context_vk->completed_command_buffer_id > command_buffer_id)
+    {
+        VK_CALL(vkDestroyPipeline(device_vk->vk_device, vk_pipeline, NULL));
+        TRACE("Destroyed pipeline 0x%s.\n", wine_dbgstr_longlong(vk_pipeline));
+        return;
+    }
+
+    if (!(o = wined3d_context_vk_get_retired_object_vk(context_vk)))
+    {
+        ERR("Leaking pipeline 0x%s.\n", wine_dbgstr_longlong(vk_pipeline));
+        return;
+    }
+
+    o->type = WINED3D_RETIRED_PIPELINE_VK;
+    o->u.vk_pipeline = vk_pipeline;
+    o->command_buffer_id = command_buffer_id;
+}
+
+
 void wined3d_context_vk_destroy_vk_sampler(struct wined3d_context_vk *context_vk,
         VkSampler vk_sampler, uint64_t command_buffer_id)
 {
@@ -1184,6 +1210,11 @@ static void wined3d_context_vk_cleanup_resources(struct wined3d_context_vk *cont
                 TRACE("Destroyed event 0x%s.\n", wine_dbgstr_longlong(o->u.vk_event));
                 break;
 
+            case WINED3D_RETIRED_PIPELINE_VK:
+                VK_CALL(vkDestroyPipeline(device_vk->vk_device, o->u.vk_pipeline, NULL));
+                TRACE("Destroyed pipeline 0x%s.\n", wine_dbgstr_longlong(o->u.vk_pipeline));
+                break;
+
             default:
                 ERR("Unhandled object type %#x.\n", o->type);
                 break;
diff --git a/dlls/wined3d/shader_spirv.c b/dlls/wined3d/shader_spirv.c
index 14665dee0f2..1f89e3d3ef5 100644
--- a/dlls/wined3d/shader_spirv.c
+++ b/dlls/wined3d/shader_spirv.c
@@ -926,10 +926,11 @@ static void shader_spirv_destroy_compute_vk(struct wined3d_shader *shader)
 {
     struct wined3d_device_vk *device_vk = wined3d_device_vk(shader->device);
     struct shader_spirv_compute_program_vk *program = shader->backend_data;
+    struct wined3d_context_vk *context_vk = &device_vk->context_vk;
     struct wined3d_vk_info *vk_info = &device_vk->vk_info;
 
     shader_spirv_invalidate_contexts_compute_program(&device_vk->d, program);
-    VK_CALL(vkDestroyPipeline(device_vk->vk_device, program->vk_pipeline, NULL));
+    wined3d_context_vk_destroy_vk_pipeline(context_vk, program->vk_pipeline, context_vk->current_command_buffer.id);
     VK_CALL(vkDestroyShaderModule(device_vk->vk_device, program->vk_module, NULL));
     vkd3d_shader_free_scan_descriptor_info(&program->descriptor_info);
     shader->backend_data = NULL;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 5f058d11ba9..72732df7b4d 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2479,6 +2479,7 @@ enum wined3d_retired_object_type_vk
     WINED3D_RETIRED_SAMPLER_VK,
     WINED3D_RETIRED_QUERY_POOL_VK,
     WINED3D_RETIRED_EVENT_VK,
+    WINED3D_RETIRED_PIPELINE_VK,
 };
 
 struct wined3d_retired_object_vk
@@ -2502,6 +2503,7 @@ struct wined3d_retired_object_vk
         VkImageView vk_image_view;
         VkSampler vk_sampler;
         VkEvent vk_event;
+        VkPipeline vk_pipeline;
         struct
         {
             struct wined3d_query_pool_vk *pool_vk;
@@ -2735,6 +2737,8 @@ void wined3d_context_vk_destroy_vk_sampler(struct wined3d_context_vk *context_vk
         VkSampler vk_sampler, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
 void wined3d_context_vk_destroy_vk_event(struct wined3d_context_vk *context_vk,
         VkEvent vk_event, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
+void wined3d_context_vk_destroy_vk_pipeline(struct wined3d_context_vk *context_vk,
+        VkPipeline vk_pipeline, uint64_t command_buffer_id) DECLSPEC_HIDDEN;
 void wined3d_context_vk_end_current_render_pass(struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
 VkCommandBuffer wined3d_context_vk_get_command_buffer(struct wined3d_context_vk *context_vk) DECLSPEC_HIDDEN;
 struct wined3d_pipeline_layout_vk *wined3d_context_vk_get_pipeline_layout(struct wined3d_context_vk *context_vk,




More information about the wine-cvs mailing list