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