Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/vkd3d/include/vkd3d.h
4389 views
1
/*
2
* Copyright 2016 Józef Kucia for CodeWeavers
3
*
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.
8
*
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.
13
*
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
17
*/
18
19
#ifndef __VKD3D_H
20
#define __VKD3D_H
21
22
#include <vkd3d_types.h>
23
24
#ifndef VKD3D_NO_WIN32_TYPES
25
# include <windows.h>
26
# include <d3d12.h>
27
#endif /* VKD3D_NO_WIN32_TYPES */
28
29
#ifndef VKD3D_NO_VULKAN_H
30
# include <wine/vulkan.h>
31
#endif /* VKD3D_NO_VULKAN_H */
32
33
#ifdef __cplusplus
34
extern "C" {
35
#endif /* __cplusplus */
36
37
/**
38
* \file vkd3d.h
39
*
40
* This file contains definitions for the vkd3d library.
41
*
42
* The vkd3d library is a 3D graphics library built on top of
43
* Vulkan. It has an API very similar, but not identical, to
44
* Direct3D 12.
45
*
46
* \since 1.0
47
*/
48
49
/** The type of a chained structure. */
50
enum vkd3d_structure_type
51
{
52
/** The structure is a vkd3d_instance_create_info structure. */
53
VKD3D_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
54
/** The structure is a vkd3d_device_create_info structure. */
55
VKD3D_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
56
/** The structure is a vkd3d_image_resource_create_info structure. */
57
VKD3D_STRUCTURE_TYPE_IMAGE_RESOURCE_CREATE_INFO,
58
59
/**
60
* The structure is a vkd3d_optional_instance_extensions_info structure.
61
* \since 1.1
62
*/
63
VKD3D_STRUCTURE_TYPE_OPTIONAL_INSTANCE_EXTENSIONS_INFO,
64
65
/**
66
* The structure is a vkd3d_optional_device_extensions_info structure.
67
* \since 1.2
68
*/
69
VKD3D_STRUCTURE_TYPE_OPTIONAL_DEVICE_EXTENSIONS_INFO,
70
/**
71
* The structure is a vkd3d_application_info structure.
72
* \since 1.2
73
*/
74
VKD3D_STRUCTURE_TYPE_APPLICATION_INFO,
75
76
/**
77
* The structure is a vkd3d_host_time_domain_info structure.
78
* \since 1.3
79
*/
80
VKD3D_STRUCTURE_TYPE_HOST_TIME_DOMAIN_INFO,
81
82
VKD3D_FORCE_32_BIT_ENUM(VKD3D_STRUCTURE_TYPE),
83
};
84
85
enum vkd3d_api_version
86
{
87
VKD3D_API_VERSION_1_0,
88
VKD3D_API_VERSION_1_1,
89
VKD3D_API_VERSION_1_2,
90
VKD3D_API_VERSION_1_3,
91
VKD3D_API_VERSION_1_4,
92
VKD3D_API_VERSION_1_5,
93
VKD3D_API_VERSION_1_6,
94
VKD3D_API_VERSION_1_7,
95
VKD3D_API_VERSION_1_8,
96
VKD3D_API_VERSION_1_9,
97
VKD3D_API_VERSION_1_10,
98
VKD3D_API_VERSION_1_11,
99
VKD3D_API_VERSION_1_12,
100
VKD3D_API_VERSION_1_13,
101
VKD3D_API_VERSION_1_14,
102
VKD3D_API_VERSION_1_15,
103
VKD3D_API_VERSION_1_16,
104
VKD3D_API_VERSION_1_17,
105
106
VKD3D_FORCE_32_BIT_ENUM(VKD3D_API_VERSION),
107
};
108
109
typedef HRESULT (*PFN_vkd3d_signal_event)(HANDLE event);
110
111
typedef void * (*PFN_vkd3d_thread)(void *data);
112
113
typedef void * (*PFN_vkd3d_create_thread)(PFN_vkd3d_thread thread_main, void *data);
114
typedef HRESULT (*PFN_vkd3d_join_thread)(void *thread);
115
116
struct vkd3d_instance;
117
118
/**
119
* A chained structure containing instance creation parameters.
120
*/
121
struct vkd3d_instance_create_info
122
{
123
/** Must be set to VKD3D_STRUCTURE_TYPE_INSTANCE_CREATE_INFO. */
124
enum vkd3d_structure_type type;
125
/** Optional pointer to a structure containing further parameters. */
126
const void *next;
127
128
/** An pointer to a function to signal events. */
129
PFN_vkd3d_signal_event pfn_signal_event;
130
/**
131
* An optional pointer to a function to create threads. If this is NULL vkd3d will use a
132
* function of its choice, depending on the platform. It must be NULL if and only if
133
* pfn_join_thread is NULL.
134
*/
135
PFN_vkd3d_create_thread pfn_create_thread;
136
/**
137
* An optional pointer to a function to join threads. If this is NULL vkd3d will use a
138
* function of its choice, depending on the platform. It must be NULL if and only if
139
* pfn_create_thread is NULL.
140
*/
141
PFN_vkd3d_join_thread pfn_join_thread;
142
/** The size of type WCHAR. It must be 2 or 4 and should normally be set to sizeof(WCHAR). */
143
size_t wchar_size;
144
145
/**
146
* A pointer to the vkGetInstanceProcAddr Vulkan function, which will be used to load all the
147
* other Vulkan functions. If set to NULL, vkd3d will search and use the Vulkan loader.
148
*/
149
PFN_vkGetInstanceProcAddr pfn_vkGetInstanceProcAddr;
150
151
/**
152
* A list of Vulkan instance extensions to request. They are intended as required, so instance
153
* creation will fail if any of them is not available.
154
*/
155
const char * const *instance_extensions;
156
/** The number of elements in the instance_extensions array. */
157
uint32_t instance_extension_count;
158
};
159
160
/**
161
* A chained structure to specify optional instance extensions.
162
*
163
* This structure extends vkd3d_instance_create_info.
164
*
165
* \since 1.1
166
*/
167
struct vkd3d_optional_instance_extensions_info
168
{
169
/** Must be set to VKD3D_STRUCTURE_TYPE_OPTIONAL_INSTANCE_EXTENSIONS_INFO. */
170
enum vkd3d_structure_type type;
171
/** Optional pointer to a structure containing further parameters. */
172
const void *next;
173
174
/**
175
* A list of optional Vulkan instance extensions to request. Instance creation does not fail if
176
* they are not available.
177
*/
178
const char * const *extensions;
179
/** The number of elements in the extensions array. */
180
uint32_t extension_count;
181
};
182
183
/**
184
* A chained structure to specify application information.
185
*
186
* This structure extends vkd3d_instance_create_info.
187
*
188
* \since 1.2
189
*/
190
struct vkd3d_application_info
191
{
192
/** Must be set to VKD3D_STRUCTURE_TYPE_APPLICATION_INFO. */
193
enum vkd3d_structure_type type;
194
/** Optional pointer to a structure containing further parameters. */
195
const void *next;
196
197
/**
198
* The application's name, to be passed to the Vulkan implementation. If it is NULL, a name is
199
* computed from the process executable filename. If that cannot be done, the empty string is
200
* used.
201
*/
202
const char *application_name;
203
/** The application's version, to be passed to the Vulkan implementation. */
204
uint32_t application_version;
205
206
/**
207
* The engine name, to be passed to the Vulkan implementation. If it is NULL, "vkd3d" is used.
208
*/
209
const char *engine_name;
210
/**
211
* The engine version, to be passed to the Vulkan implementation. If it is 0, the version is
212
* computed from the vkd3d library version.
213
*/
214
uint32_t engine_version;
215
216
/**
217
* The vkd3d API version to use, to guarantee backward compatibility of the shared library. If
218
* this chained structure is not used then VKD3D_API_VERSION_1_0 is used.
219
*/
220
enum vkd3d_api_version api_version;
221
};
222
223
/**
224
* A chained structure to specify the host time domain.
225
*
226
* This structure extends vkd3d_instance_create_info.
227
*
228
* \since 1.3
229
*/
230
struct vkd3d_host_time_domain_info
231
{
232
/** Must be set to VKD3D_STRUCTURE_TYPE_HOST_TIME_DOMAIN_INFO. */
233
enum vkd3d_structure_type type;
234
/** Optional pointer to a structure containing further parameters. */
235
const void *next;
236
237
/**
238
* The number of clock ticks per second, used for GetClockCalibration(). It should normally
239
* match the expected result of QueryPerformanceFrequency(). If this chained structure is not
240
* used then 10 millions is used, which means that each tick is a tenth of microsecond, or
241
* equivalently 100 nanoseconds.
242
*/
243
uint64_t ticks_per_second;
244
};
245
246
/**
247
* A chained structure containing device creation parameters.
248
*/
249
struct vkd3d_device_create_info
250
{
251
/** Must be set to VKD3D_STRUCTURE_TYPE_DEVICE_CREATE_INFO. */
252
enum vkd3d_structure_type type;
253
/** Optional pointer to a structure containing further parameters. */
254
const void *next;
255
256
/** The minimum feature level to request. Device creation will fail with E_INVALIDARG if the
257
* Vulkan device doesn't have the features needed to fulfill the request. */
258
D3D_FEATURE_LEVEL minimum_feature_level;
259
260
/**
261
* The vkd3d instance to use to create a device. Either this or instance_create_info must be
262
* set.
263
*/
264
struct vkd3d_instance *instance;
265
/**
266
* The parameters used to create an instance, which is then used to create a device. Either
267
* this or instance must be set.
268
*/
269
const struct vkd3d_instance_create_info *instance_create_info;
270
271
/**
272
* The Vulkan physical device to use. If it is NULL, the first physical device found is used,
273
* prioritizing discrete GPUs over integrated GPUs and integrated GPUs over all the others.
274
*
275
* This parameter can be overridden by setting environment variable VKD3D_VULKAN_DEVICE.
276
*/
277
VkPhysicalDevice vk_physical_device;
278
279
/**
280
* A list of Vulkan device extensions to request. They are intended as required, so device
281
* creation will fail if any of them is not available.
282
*/
283
const char * const *device_extensions;
284
/** The number of elements in the device_extensions array. */
285
uint32_t device_extension_count;
286
287
/**
288
* An object to be set as the device parent. This is not used by vkd3d except for being
289
* returned by vkd3d_get_device_parent.
290
*/
291
IUnknown *parent;
292
/**
293
* The adapter LUID to be set for the device. This is not used by vkd3d except for being
294
* returned by GetAdapterLuid.
295
*/
296
LUID adapter_luid;
297
};
298
299
/**
300
* A chained structure to specify optional device extensions.
301
*
302
* This structure extends vkd3d_device_create_info.
303
*
304
* \since 1.2
305
*/
306
struct vkd3d_optional_device_extensions_info
307
{
308
/** Must be set to VKD3D_STRUCTURE_TYPE_OPTIONAL_DEVICE_EXTENSIONS_INFO. */
309
enum vkd3d_structure_type type;
310
/** Optional pointer to a structure containing further parameters. */
311
const void *next;
312
313
/**
314
* A list of optional Vulkan device extensions to request. Device creation does not fail if
315
* they are not available.
316
*/
317
const char * const *extensions;
318
/** The number of elements in the extensions array. */
319
uint32_t extension_count;
320
};
321
322
/**
323
* When specified as a flag of vkd3d_image_resource_create_info, it means that vkd3d will do the
324
* initial transition operation on the image from VK_IMAGE_LAYOUT_UNDEFINED to its appropriate
325
* Vulkan layout (depending on its D3D12 resource state). If this flag is not specified the caller
326
* is responsible for transitioning the Vulkan image to the appropriate layout.
327
*/
328
#define VKD3D_RESOURCE_INITIAL_STATE_TRANSITION 0x00000001
329
/**
330
* When specified as a flag of vkd3d_image_resource_create_info, it means that field present_state
331
* is honored.
332
*/
333
#define VKD3D_RESOURCE_PRESENT_STATE_TRANSITION 0x00000002
334
335
/**
336
* A chained structure containing the parameters to create a D3D12 resource backed by a Vulkan
337
* image.
338
*/
339
struct vkd3d_image_resource_create_info
340
{
341
/** Must be set to VKD3D_STRUCTURE_TYPE_IMAGE_RESOURCE_CREATE_INFO. */
342
enum vkd3d_structure_type type;
343
/** Optional pointer to a structure containing further parameters. */
344
const void *next;
345
346
/** The Vulkan image that backs the resource. */
347
VkImage vk_image;
348
/** The resource description. */
349
D3D12_RESOURCE_DESC desc;
350
/**
351
* A combination of zero or more flags. The valid flags are
352
* VKD3D_RESOURCE_INITIAL_STATE_TRANSITION and VKD3D_RESOURCE_PRESENT_STATE_TRANSITION.
353
*/
354
unsigned int flags;
355
/**
356
* This field specifies how to handle resource state D3D12_RESOURCE_STATE_PRESENT for
357
* the resource. Notice that on D3D12 there is no difference between
358
* D3D12_RESOURCE_STATE_COMMON and D3D12_RESOURCE_STATE_PRESENT (they have the same value),
359
* while on Vulkan two different layouts are used (VK_IMAGE_LAYOUT_GENERAL and
360
* VK_IMAGE_LAYOUT_PRESENT_SRC_KHR).
361
*
362
* * When flag VKD3D_RESOURCE_PRESENT_STATE_TRANSITION is not specified, field
363
* present_state is ignored and resource state D3D12_RESOURCE_STATE_COMMON/_PRESENT is
364
* mapped to VK_IMAGE_LAYOUT_GENERAL; this is useful for non-swapchain resources.
365
* * Otherwise, when present_state is D3D12_RESOURCE_STATE_PRESENT/_COMMON, resource state
366
* D3D12_RESOURCE_STATE_COMMON/_PRESENT is mapped to VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
367
* this is useful for swapchain resources that are directly backed by a Vulkan swapchain
368
* image.
369
* * Otherwise, resource state D3D12_RESOURCE_STATE_COMMON/_PRESENT is treated as resource
370
* state present_state; this is useful for swapchain resources that backed by a Vulkan
371
* non-swapchain image, which the client will likely consume with a copy or drawing
372
* operation at presentation time.
373
*/
374
D3D12_RESOURCE_STATES present_state;
375
};
376
377
#ifdef LIBVKD3D_SOURCE
378
# define VKD3D_API VKD3D_EXPORT
379
#else
380
# define VKD3D_API VKD3D_IMPORT
381
#endif
382
383
#ifndef VKD3D_NO_PROTOTYPES
384
385
VKD3D_API HRESULT vkd3d_create_instance(const struct vkd3d_instance_create_info *create_info,
386
struct vkd3d_instance **instance);
387
VKD3D_API ULONG vkd3d_instance_decref(struct vkd3d_instance *instance);
388
VKD3D_API VkInstance vkd3d_instance_get_vk_instance(struct vkd3d_instance *instance);
389
VKD3D_API ULONG vkd3d_instance_incref(struct vkd3d_instance *instance);
390
391
VKD3D_API HRESULT vkd3d_create_device(const struct vkd3d_device_create_info *create_info,
392
REFIID iid, void **device);
393
VKD3D_API IUnknown *vkd3d_get_device_parent(ID3D12Device *device);
394
VKD3D_API VkDevice vkd3d_get_vk_device(ID3D12Device *device);
395
VKD3D_API VkPhysicalDevice vkd3d_get_vk_physical_device(ID3D12Device *device);
396
VKD3D_API struct vkd3d_instance *vkd3d_instance_from_device(ID3D12Device *device);
397
398
VKD3D_API uint32_t vkd3d_get_vk_queue_family_index(ID3D12CommandQueue *queue);
399
400
/**
401
* Acquire the Vulkan queue backing a command queue.
402
*
403
* While a queue is acquired by the client, it is locked so that
404
* neither the vkd3d library nor other threads can submit work to
405
* it. For that reason it should be released as soon as possible with
406
* vkd3d_release_vk_queue(). The lock is not reentrant, so the same
407
* queue must not be acquired more than once by the same thread.
408
*
409
* Work submitted through the Direct3D 12 API exposed by vkd3d is not
410
* always immediately submitted to the Vulkan queue; sometimes it is
411
* kept in another internal queue, which might not necessarily be
412
* empty at the time vkd3d_acquire_vk_queue() is called. For this
413
* reason, work submitted directly to the Vulkan queue might appear to
414
* the Vulkan driver as being submitted before other work submitted
415
* though the Direct3D 12 API. If this is not desired, it is
416
* recommended to synchronize work submission using an ID3D12Fence
417
* object:
418
* 1. submit work through the Direct3D 12 API;
419
* 2. call vkd3d_queue_signal_on_cpu();
420
* 3. wait for the fence to be signalled;
421
* 4. call vkd3d_acquire_vk_queue(); it is guaranteed that all work submitted
422
* at point 1 has already been submitted to Vulkan (though not necessarily
423
* executed).
424
*
425
* \since 1.0
426
*/
427
VKD3D_API VkQueue vkd3d_acquire_vk_queue(ID3D12CommandQueue *queue);
428
429
/**
430
* Release the Vulkan queue backing a command queue.
431
*
432
* This must be paired to an earlier corresponding
433
* vkd3d_acquire_vk_queue(). After this function is called, the Vulkan
434
* queue returned by vkd3d_acquire_vk_queue() must not be used any
435
* more.
436
*
437
* \since 1.0
438
*/
439
VKD3D_API void vkd3d_release_vk_queue(ID3D12CommandQueue *queue);
440
441
VKD3D_API HRESULT vkd3d_create_image_resource(ID3D12Device *device,
442
const struct vkd3d_image_resource_create_info *create_info, ID3D12Resource **resource);
443
VKD3D_API ULONG vkd3d_resource_decref(ID3D12Resource *resource);
444
VKD3D_API ULONG vkd3d_resource_incref(ID3D12Resource *resource);
445
446
VKD3D_API HRESULT vkd3d_serialize_root_signature(const D3D12_ROOT_SIGNATURE_DESC *desc,
447
D3D_ROOT_SIGNATURE_VERSION version, ID3DBlob **blob, ID3DBlob **error_blob);
448
VKD3D_API HRESULT vkd3d_create_root_signature_deserializer(const void *data, SIZE_T data_size,
449
REFIID iid, void **deserializer);
450
451
VKD3D_API VkFormat vkd3d_get_vk_format(DXGI_FORMAT format);
452
453
/* 1.1 */
454
VKD3D_API DXGI_FORMAT vkd3d_get_dxgi_format(VkFormat format);
455
456
/* 1.2 */
457
VKD3D_API HRESULT vkd3d_serialize_versioned_root_signature(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC *desc,
458
ID3DBlob **blob, ID3DBlob **error_blob);
459
VKD3D_API HRESULT vkd3d_create_versioned_root_signature_deserializer(const void *data, SIZE_T data_size,
460
REFIID iid, void **deserializer);
461
462
/**
463
* Set a callback to be called when vkd3d outputs debug logging.
464
*
465
* If NULL, or if this function has not been called, libvkd3d will print all
466
* enabled log output to stderr.
467
*
468
* Calling this function will also set the log callback for libvkd3d-shader.
469
*
470
* \param callback Callback function to set.
471
*
472
* \since 1.4
473
*/
474
VKD3D_API void vkd3d_set_log_callback(PFN_vkd3d_log callback);
475
476
/**
477
* Signal a fence on the CPU once all the currently outstanding queue work is
478
* submitted to Vulkan.
479
*
480
* The fence will be signalled on the CPU (as if ID3D12Fence_Signal() was
481
* called) once all the work submitted through the Direct3D 12 API before
482
* vkd3d_queue_signal_on_cpu() is called has left the internal queue and has
483
* been submitted to the underlying Vulkan queue. Read the documentation for
484
* vkd3d_acquire_vk_queue() for more details.
485
*
486
* \since 1.15
487
*/
488
VKD3D_API HRESULT vkd3d_queue_signal_on_cpu(ID3D12CommandQueue *queue,
489
ID3D12Fence *fence, uint64_t value);
490
491
#endif /* VKD3D_NO_PROTOTYPES */
492
493
/*
494
* Function pointer typedefs for vkd3d functions.
495
*/
496
typedef HRESULT (*PFN_vkd3d_create_instance)(const struct vkd3d_instance_create_info *create_info,
497
struct vkd3d_instance **instance);
498
typedef ULONG (*PFN_vkd3d_instance_decref)(struct vkd3d_instance *instance);
499
typedef VkInstance (*PFN_vkd3d_instance_get_vk_instance)(struct vkd3d_instance *instance);
500
typedef ULONG (*PFN_vkd3d_instance_incref)(struct vkd3d_instance *instance);
501
502
typedef HRESULT (*PFN_vkd3d_create_device)(const struct vkd3d_device_create_info *create_info,
503
REFIID iid, void **device);
504
typedef IUnknown * (*PFN_vkd3d_get_device_parent)(ID3D12Device *device);
505
typedef VkDevice (*PFN_vkd3d_get_vk_device)(ID3D12Device *device);
506
typedef VkPhysicalDevice (*PFN_vkd3d_get_vk_physical_device)(ID3D12Device *device);
507
typedef struct vkd3d_instance * (*PFN_vkd3d_instance_from_device)(ID3D12Device *device);
508
509
typedef uint32_t (*PFN_vkd3d_get_vk_queue_family_index)(ID3D12CommandQueue *queue);
510
typedef VkQueue (*PFN_vkd3d_acquire_vk_queue)(ID3D12CommandQueue *queue);
511
typedef void (*PFN_vkd3d_release_vk_queue)(ID3D12CommandQueue *queue);
512
513
typedef HRESULT (*PFN_vkd3d_create_image_resource)(ID3D12Device *device,
514
const struct vkd3d_image_resource_create_info *create_info, ID3D12Resource **resource);
515
typedef ULONG (*PFN_vkd3d_resource_decref)(ID3D12Resource *resource);
516
typedef ULONG (*PFN_vkd3d_resource_incref)(ID3D12Resource *resource);
517
518
typedef HRESULT (*PFN_vkd3d_serialize_root_signature)(const D3D12_ROOT_SIGNATURE_DESC *desc,
519
D3D_ROOT_SIGNATURE_VERSION version, ID3DBlob **blob, ID3DBlob **error_blob);
520
typedef HRESULT (*PFN_vkd3d_create_root_signature_deserializer)(const void *data, SIZE_T data_size,
521
REFIID iid, void **deserializer);
522
523
typedef VkFormat (*PFN_vkd3d_get_vk_format)(DXGI_FORMAT format);
524
525
/* 1.1 */
526
typedef DXGI_FORMAT (*PFN_vkd3d_get_dxgi_format)(VkFormat format);
527
528
/* 1.2 */
529
typedef HRESULT (*PFN_vkd3d_serialize_versioned_root_signature)(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC *desc,
530
ID3DBlob **blob, ID3DBlob **error_blob);
531
typedef HRESULT (*PFN_vkd3d_create_versioned_root_signature_deserializer)(const void *data, SIZE_T data_size,
532
REFIID iid, void **deserializer);
533
534
/** Type of vkd3d_set_log_callback(). \since 1.4 */
535
typedef void (*PFN_vkd3d_set_log_callback)(PFN_vkd3d_log callback);
536
537
/** Type of vkd3d_queue_signal_on_cpu(). \since 1.15 */
538
typedef HRESULT (*PFN_vkd3d_queue_signal_on_cpu)(ID3D12CommandQueue *queue,
539
ID3D12Fence *fence, uint64_t value);
540
541
#ifdef __cplusplus
542
}
543
#endif /* __cplusplus */
544
545
#endif /* __VKD3D_H */
546
547