vkd3d  1.18
The vkd3d 3D Graphics Library
vkd3d.h
Go to the documentation of this file.
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 <vkd3d_windows.h>
26 # include <vkd3d_d3d12.h>
27 #endif /* VKD3D_NO_WIN32_TYPES */
28 
29 #ifndef VKD3D_NO_VULKAN_H
30 # include <vulkan/vulkan.h>
31 #endif /* VKD3D_NO_VULKAN_H */
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif /* __cplusplus */
36 
51 {
58 
64 
75 
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 
123 {
127  const void *next;
128 
130  PFN_vkd3d_signal_event pfn_signal_event;
136  PFN_vkd3d_create_thread pfn_create_thread;
142  PFN_vkd3d_join_thread pfn_join_thread;
144  size_t wchar_size;
145 
150  PFN_vkGetInstanceProcAddr pfn_vkGetInstanceProcAddr;
151 
156  const char * const *instance_extensions;
159 };
160 
169 {
173  const void *next;
174 
179  const char * const *extensions;
181  uint32_t extension_count;
182 };
183 
192 {
196  const void *next;
197 
203  const char *application_name;
206 
210  const char *engine_name;
215  uint32_t engine_version;
216 
221  enum vkd3d_api_version api_version;
222 };
223 
232 {
236  const void *next;
237 
245 };
246 
251 {
255  const void *next;
256 
259  D3D_FEATURE_LEVEL minimum_feature_level;
260 
265  struct vkd3d_instance *instance;
271 
278  VkPhysicalDevice vk_physical_device;
279 
284  const char * const *device_extensions;
287 
292  IUnknown *parent;
298 };
299 
308 {
312  const void *next;
313 
318  const char * const *extensions;
320  uint32_t extension_count;
321 };
322 
329 #define VKD3D_RESOURCE_INITIAL_STATE_TRANSITION 0x00000001
330 
334 #define VKD3D_RESOURCE_PRESENT_STATE_TRANSITION 0x00000002
335 
341 {
345  const void *next;
346 
348  VkImage vk_image;
350  D3D12_RESOURCE_DESC desc;
355  unsigned int flags;
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 
428 VKD3D_API VkQueue vkd3d_acquire_vk_queue(ID3D12CommandQueue *queue);
429 
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 
475 VKD3D_API void vkd3d_set_log_callback(PFN_vkd3d_log callback);
476 
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 
536 typedef void (*PFN_vkd3d_set_log_callback)(PFN_vkd3d_log callback);
537 
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 */
enum vkd3d_api_version api_version
The vkd3d API version to use, to guarantee backward compatibility of the shared library.
Definition: vkd3d.h:221
A chained structure containing the parameters to create a D3D12 resource backed by a Vulkan image...
Definition: vkd3d.h:340
uint32_t extension_count
The number of elements in the extensions array.
Definition: vkd3d.h:320
enum vkd3d_structure_type type
Must be set to VKD3D_STRUCTURE_TYPE_APPLICATION_INFO.
Definition: vkd3d.h:194
A chained structure to specify application information.
Definition: vkd3d.h:191
const void * next
Optional pointer to a structure containing further parameters.
Definition: vkd3d.h:345
The structure is a vkd3d_image_resource_create_info structure.
Definition: vkd3d.h:57
enum vkd3d_structure_type type
Must be set to VKD3D_STRUCTURE_TYPE_IMAGE_RESOURCE_CREATE_INFO.
Definition: vkd3d.h:343
LUID adapter_luid
The adapter LUID to be set for the device.
Definition: vkd3d.h:297
A chained structure containing device creation parameters.
Definition: vkd3d.h:250
const void * next
Optional pointer to a structure containing further parameters.
Definition: vkd3d.h:236
uint32_t application_version
The application&#39;s version, to be passed to the Vulkan implementation.
Definition: vkd3d.h:205
enum vkd3d_structure_type type
Must be set to VKD3D_STRUCTURE_TYPE_OPTIONAL_DEVICE_EXTENSIONS_INFO.
Definition: vkd3d.h:310
const void * next
Optional pointer to a structure containing further parameters.
Definition: vkd3d.h:127
const char *const * device_extensions
A list of Vulkan device extensions to request.
Definition: vkd3d.h:284
VkImage vk_image
The Vulkan image that backs the resource.
Definition: vkd3d.h:348
HRESULT(* PFN_vkd3d_queue_signal_on_cpu)(ID3D12CommandQueue *queue, ID3D12Fence *fence, uint64_t value)
Type of vkd3d_queue_signal_on_cpu().
Definition: vkd3d.h:539
A chained structure to specify optional instance extensions.
Definition: vkd3d.h:168
const char *const * extensions
A list of optional Vulkan instance extensions to request.
Definition: vkd3d.h:179
const void * next
Optional pointer to a structure containing further parameters.
Definition: vkd3d.h:312
uint32_t engine_version
The engine version, to be passed to the Vulkan implementation.
Definition: vkd3d.h:215
VKD3D_API void vkd3d_release_vk_queue(ID3D12CommandQueue *queue)
Release the Vulkan queue backing a command queue.
const struct vkd3d_instance_create_info * instance_create_info
The parameters used to create an instance, which is then used to create a device. ...
Definition: vkd3d.h:270
void(* PFN_vkd3d_set_log_callback)(PFN_vkd3d_log callback)
Type of vkd3d_set_log_callback().
Definition: vkd3d.h:536
PFN_vkGetInstanceProcAddr pfn_vkGetInstanceProcAddr
A pointer to the vkGetInstanceProcAddr Vulkan function, which will be used to load all the other Vulk...
Definition: vkd3d.h:150
The structure is a vkd3d_host_time_domain_info structure.
Definition: vkd3d.h:80
enum vkd3d_structure_type type
Must be set to VKD3D_STRUCTURE_TYPE_OPTIONAL_INSTANCE_EXTENSIONS_INFO.
Definition: vkd3d.h:171
The structure is a vkd3d_optional_instance_extensions_info structure.
Definition: vkd3d.h:63
struct vkd3d_instance * instance
The vkd3d instance to use to create a device.
Definition: vkd3d.h:265
vkd3d_structure_type
The type of a chained structure.
Definition: vkd3d.h:50
PFN_vkd3d_signal_event pfn_signal_event
An pointer to a function to signal events.
Definition: vkd3d.h:130
uint32_t instance_extension_count
The number of elements in the instance_extensions array.
Definition: vkd3d.h:158
The structure is a vkd3d_device_create_info structure.
Definition: vkd3d.h:55
The structure is a vkd3d_application_info structure.
Definition: vkd3d.h:74
uint32_t extension_count
The number of elements in the extensions array.
Definition: vkd3d.h:181
const char *const * extensions
A list of optional Vulkan device extensions to request.
Definition: vkd3d.h:318
const char * engine_name
The engine name, to be passed to the Vulkan implementation.
Definition: vkd3d.h:210
enum vkd3d_structure_type type
Must be set to VKD3D_STRUCTURE_TYPE_DEVICE_CREATE_INFO.
Definition: vkd3d.h:253
IUnknown * parent
An object to be set as the device parent.
Definition: vkd3d.h:292
enum vkd3d_structure_type type
Must be set to VKD3D_STRUCTURE_TYPE_HOST_TIME_DOMAIN_INFO.
Definition: vkd3d.h:234
D3D12_RESOURCE_DESC desc
The resource description.
Definition: vkd3d.h:350
The structure is a vkd3d_instance_create_info structure.
Definition: vkd3d.h:53
uint32_t device_extension_count
The number of elements in the device_extensions array.
Definition: vkd3d.h:286
const char * application_name
The application&#39;s name, to be passed to the Vulkan implementation.
Definition: vkd3d.h:203
PFN_vkd3d_join_thread pfn_join_thread
An optional pointer to a function to join threads.
Definition: vkd3d.h:142
const void * next
Optional pointer to a structure containing further parameters.
Definition: vkd3d.h:196
PFN_vkd3d_create_thread pfn_create_thread
An optional pointer to a function to create threads.
Definition: vkd3d.h:136
A chained structure containing instance creation parameters.
Definition: vkd3d.h:122
D3D12_RESOURCE_STATES present_state
This field specifies how to handle resource state D3D12_RESOURCE_STATE_PRESENT for the resource...
Definition: vkd3d.h:375
This file contains definitions for basic types used by vkd3d libraries.
A chained structure to specify the host time domain.
Definition: vkd3d.h:231
enum vkd3d_structure_type type
Must be set to VKD3D_STRUCTURE_TYPE_INSTANCE_CREATE_INFO.
Definition: vkd3d.h:125
VKD3D_API void vkd3d_set_log_callback(PFN_vkd3d_log callback)
Set a callback to be called when vkd3d outputs debug logging.
size_t wchar_size
The size of type WCHAR.
Definition: vkd3d.h:144
VKD3D_API HRESULT vkd3d_queue_signal_on_cpu(ID3D12CommandQueue *queue, ID3D12Fence *fence, uint64_t value)
Signal a fence on the CPU once all the currently outstanding queue work is submitted to Vulkan...
uint64_t ticks_per_second
The number of clock ticks per second, used for GetClockCalibration().
Definition: vkd3d.h:244
D3D_FEATURE_LEVEL minimum_feature_level
The minimum feature level to request.
Definition: vkd3d.h:259
const void * next
Optional pointer to a structure containing further parameters.
Definition: vkd3d.h:255
VkPhysicalDevice vk_physical_device
The Vulkan physical device to use.
Definition: vkd3d.h:278
unsigned int flags
A combination of zero or more flags.
Definition: vkd3d.h:355
const char *const * instance_extensions
A list of Vulkan instance extensions to request.
Definition: vkd3d.h:156
const void * next
Optional pointer to a structure containing further parameters.
Definition: vkd3d.h:173
The structure is a vkd3d_optional_device_extensions_info structure.
Definition: vkd3d.h:69
A chained structure to specify optional device extensions.
Definition: vkd3d.h:307
VKD3D_API VkQueue vkd3d_acquire_vk_queue(ID3D12CommandQueue *queue)
Acquire the Vulkan queue backing a command queue.