 
            From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/vulkan.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/dlls/win32u/vulkan.c b/dlls/win32u/vulkan.c index 4ed9ad0dbf2..9e8762f92f9 100644 --- a/dlls/win32u/vulkan.c +++ b/dlls/win32u/vulkan.c @@ -212,6 +212,35 @@ static HANDLE create_shared_handle( D3DKMT_HANDLE local, const VkExportMemoryWin return NULL; }
+static HANDLE open_shared_handle_from_name( const WCHAR *name ) +{ + D3DKMT_OPENNTHANDLEFROMNAME open_name = {0}; + UINT size = wcslen( name ) * sizeof(WCHAR); + UNICODE_STRING name_str; + OBJECT_ATTRIBUTES attr; + WCHAR bufferW[MAX_PATH]; + char buffer[MAX_PATH]; + NTSTATUS status; + + snprintf( buffer, ARRAY_SIZE(buffer), "\Sessions\%u\BaseNamedObjects\", + NtCurrentTeb()->Peb->SessionId ); + name_str.MaximumLength = asciiz_to_unicode( bufferW, buffer ); + name_str.Length = name_str.MaximumLength - sizeof(WCHAR); + + memcpy( name_str.Buffer + name_str.Length / sizeof(WCHAR), name, size * sizeof(WCHAR) ); + name_str.MaximumLength += size * sizeof(WCHAR); + name_str.Length = size * sizeof(WCHAR); + + init_unicode_string( &name_str, name ); + InitializeObjectAttributes( &attr, &name_str, OBJ_OPENIF, NULL, NULL ); + + open_name.dwDesiredAccess = GENERIC_ALL; + open_name.pObjAttrib = &attr; + if ((status = NtGdiDdDDIOpenNtHandleFromName( &open_name ))) + WARN( "Failed to open shared handle name %s, status %#x\n", debugstr_w( name ), status ); + return open_name.hNtHandle; +} + static VkResult win32u_vkAllocateMemory( VkDevice client_device, const VkMemoryAllocateInfo *client_alloc_info, const VkAllocationCallbacks *allocator, VkDeviceMemory *ret ) { @@ -288,8 +317,13 @@ static VkResult win32u_vkAllocateMemory( VkDevice client_device, const VkMemoryA case VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT: case VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_HEAP_BIT: case VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D12_RESOURCE_BIT: - memory->local = d3dkmt_open_resource( 0, import_win32->handle ); + { + HANDLE shared = import_win32->handle; + if (import_win32->name && !(shared = open_shared_handle_from_name( import_win32->name ))) break; + memory->local = d3dkmt_open_resource( 0, shared ); + if (shared && shared != import_win32->handle) NtClose( shared ); break; + } default: FIXME( "Unsupported handle type %#x\n", import_win32->handleType ); break;