2 * Copyright 2018 Józef Kucia for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/port.h"
23 #define VK_NO_PROTOTYPES
24 #define VKD3D_NO_VULKAN_H
25 #define VKD3D_NO_WIN32_TYPES
28 #include "wine/debug.h"
29 #include "wine/heap.h"
30 #include "wine/vulkan.h"
31 #include "wine/vulkan_driver.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3d12
);
38 WINE_DECLARE_DEBUG_CHANNEL(winediag
);
40 HRESULT WINAPI
D3D12GetDebugInterface(REFIID iid
, void **debug
)
42 TRACE("iid %s, debug %p.\n", debugstr_guid(iid
), debug
);
44 WARN("Returning DXGI_ERROR_SDK_COMPONENT_MISSING.\n");
45 return DXGI_ERROR_SDK_COMPONENT_MISSING
;
48 static HRESULT
d3d12_signal_event(HANDLE event
)
50 return SetEvent(event
) ? S_OK
: E_FAIL
;
53 struct d3d12_thread_data
55 PFN_vkd3d_thread main_pfn
;
59 static DWORD WINAPI
d3d12_thread_main(void *data
)
61 struct d3d12_thread_data
*thread_data
= data
;
63 thread_data
->main_pfn(thread_data
->data
);
64 heap_free(thread_data
);
68 static void *d3d12_create_thread(PFN_vkd3d_thread main_pfn
, void *data
)
70 struct d3d12_thread_data
*thread_data
;
73 if (!(thread_data
= heap_alloc(sizeof(*thread_data
))))
75 ERR("Failed to allocate thread data.\n");
79 thread_data
->main_pfn
= main_pfn
;
80 thread_data
->data
= data
;
82 if (!(thread
= CreateThread(NULL
, 0, d3d12_thread_main
, thread_data
, 0, NULL
)))
83 heap_free(thread_data
);
88 static HRESULT
d3d12_join_thread(void *handle
)
90 HANDLE thread
= handle
;
93 if ((ret
= WaitForSingleObject(thread
, INFINITE
)) != WAIT_OBJECT_0
)
94 ERR("Failed to wait for thread, ret %#x.\n", ret
);
96 return ret
== WAIT_OBJECT_0
? S_OK
: E_FAIL
;
99 static const struct vulkan_funcs
*get_vk_funcs(void)
101 const struct vulkan_funcs
*vk_funcs
;
105 vk_funcs
= __wine_get_vulkan_driver(hdc
, WINE_VULKAN_DRIVER_VERSION
);
110 HRESULT WINAPI
D3D12CreateDevice(IUnknown
*adapter
, D3D_FEATURE_LEVEL minimum_feature_level
,
111 REFIID iid
, void **device
)
113 struct vkd3d_instance_create_info instance_create_info
;
114 struct vkd3d_device_create_info device_create_info
;
115 const struct vulkan_funcs
*vk_funcs
;
117 static const char * const instance_extensions
[] =
119 VK_KHR_SURFACE_EXTENSION_NAME
,
120 VK_KHR_WIN32_SURFACE_EXTENSION_NAME
,
122 static const char * const device_extensions
[] =
124 VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
127 TRACE("adapter %p, minimum_feature_level %#x, iid %s, device %p.\n",
128 adapter
, minimum_feature_level
, debugstr_guid(iid
), device
);
130 if (!(vk_funcs
= get_vk_funcs()))
132 ERR_(winediag
)("Failed to load Wine Vulkan driver.\n");
136 FIXME("Ignoring adapter %p.\n", adapter
);
138 memset(&instance_create_info
, 0, sizeof(instance_create_info
));
139 instance_create_info
.type
= VKD3D_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
;
140 instance_create_info
.pfn_signal_event
= d3d12_signal_event
;
141 instance_create_info
.pfn_create_thread
= d3d12_create_thread
;
142 instance_create_info
.pfn_join_thread
= d3d12_join_thread
;
143 instance_create_info
.wchar_size
= sizeof(WCHAR
);
144 instance_create_info
.pfn_vkGetInstanceProcAddr
145 = (PFN_vkGetInstanceProcAddr
)vk_funcs
->p_vkGetInstanceProcAddr
;
146 instance_create_info
.instance_extensions
= instance_extensions
;
147 instance_create_info
.instance_extension_count
= ARRAY_SIZE(instance_extensions
);
149 memset(&device_create_info
, 0, sizeof(device_create_info
));
150 device_create_info
.type
= VKD3D_STRUCTURE_TYPE_DEVICE_CREATE_INFO
;
151 device_create_info
.minimum_feature_level
= minimum_feature_level
;
152 device_create_info
.instance_create_info
= &instance_create_info
;
153 device_create_info
.device_extensions
= device_extensions
;
154 device_create_info
.device_extension_count
= ARRAY_SIZE(device_extensions
);
156 return vkd3d_create_device(&device_create_info
, iid
, device
);
159 HRESULT WINAPI
D3D12CreateRootSignatureDeserializer(const void *data
, SIZE_T data_size
,
160 REFIID iid
, void **deserializer
)
162 TRACE("data %p, data_size %lu, iid %s, deserializer %p.\n",
163 data
, data_size
, debugstr_guid(iid
), deserializer
);
165 return vkd3d_create_root_signature_deserializer(data
, data_size
, iid
, deserializer
);
168 HRESULT WINAPI
D3D12SerializeRootSignature(const D3D12_ROOT_SIGNATURE_DESC
*root_signature_desc
,
169 D3D_ROOT_SIGNATURE_VERSION version
, ID3DBlob
**blob
, ID3DBlob
**error_blob
)
171 TRACE("root_signature_desc %p, version %#x, blob %p, error_blob %p.\n",
172 root_signature_desc
, version
, blob
, error_blob
);
174 return vkd3d_serialize_root_signature(root_signature_desc
, version
, blob
, error_blob
);