Don't disown Win32 handle after import
authorPiers Daniell <pdaniell@nvidia.com>
Wed, 3 Apr 2019 20:20:09 +0000 (14:20 -0600)
committerPiers Daniell <pdaniell@nvidia.com>
Wed, 3 Apr 2019 20:22:04 +0000 (14:22 -0600)
For Win32 fences and semaphores, the Vulkan implementation does not take
ownership of the handle after import. It is up to the application to
maintain ownership while the handle is in use and to call
CloseHandle() after.

Affects:
dEQP-VK.api.external.*.opaque_win32*

Components: Vulkan

VK-GL-CTS issue: 1720

Change-Id: I4e26ef53c9bf27c30efd71992fd02a574f81b3a0

external/vulkancts/modules/vulkan/api/vktApiExternalMemoryTests.cpp
external/vulkancts/modules/vulkan/vktExternalMemoryUtil.cpp

index ccafd67..65f1dda 100644 (file)
@@ -2038,10 +2038,8 @@ tcu::TestStatus testFenceReset (Context&                         context,
                VK_CHECK(vkd.queueWaitIdle(queue));
 
                submitDummySignalAndGetFenceNative(vkd, *device, queue, queueFamilyIndex, *fenceA, config.externalType, handle);
-               {
-                       NativeHandle                                    handleB (handle);
-                       importFence(vkd, *device, *fenceB, config.externalType, handleB, flags);
-               }
+               NativeHandle                                    handleB (handle);
+               importFence(vkd, *device, *fenceB, config.externalType, handleB, flags);
                importFence(vkd, *device, *fenceC, config.externalType, handle, flags);
 
                VK_CHECK(vkd.queueWaitIdle(queue));
index 4ced4a1..062357c 100644 (file)
@@ -648,7 +648,7 @@ void importFence (const vk::DeviceInterface&                                vkd,
        {
                const vk::VkImportFenceWin32HandleInfoKHR       importInfo      =
                {
-                       vk::VK_STRUCTURE_TYPE_IMPORT_FENCE_FD_INFO_KHR,
+                       vk::VK_STRUCTURE_TYPE_IMPORT_FENCE_WIN32_HANDLE_INFO_KHR,
                        DE_NULL,
                        fence,
                        flags,
@@ -658,8 +658,8 @@ void importFence (const vk::DeviceInterface&                                vkd,
                };
 
                VK_CHECK(vkd.importFenceWin32HandleKHR(device, &importInfo));
-               // \note File descriptors and win32 handles behave differently, but this call wil make it seem like they would behave in same way
-               handle.reset();
+               // \note Importing a fence payload from Windows handles does not transfer ownership of the handle to the Vulkan implementation,
+               //   so we do not disown the handle until after all use has complete.
        }
        else
                DE_FATAL("Unknown fence external handle type");
@@ -803,7 +803,7 @@ void importSemaphore (const vk::DeviceInterface&                                    vkd,
        {
                const vk::VkImportSemaphoreWin32HandleInfoKHR   importInfo      =
                {
-                       vk::VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR,
+                       vk::VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR,
                        DE_NULL,
                        semaphore,
                        flags,
@@ -813,8 +813,8 @@ void importSemaphore (const vk::DeviceInterface&                                    vkd,
                };
 
                VK_CHECK(vkd.importSemaphoreWin32HandleKHR(device, &importInfo));
-               // \note File descriptors and win32 handles behave differently, but this call wil make it seem like they would behave in same way
-               handle.reset();
+               // \note Importing a semaphore payload from Windows handles does not transfer ownership of the handle to the Vulkan implementation,
+               //   so we do not disown the handle until after all use has complete.
        }
        else
                DE_FATAL("Unknown semaphore external handle type");