/*1* Copyright 2016 Józef Kucia for CodeWeavers2*3* This library is free software; you can redistribute it and/or4* modify it under the terms of the GNU Lesser General Public5* License as published by the Free Software Foundation; either6* version 2.1 of the License, or (at your option) any later version.7*8* This library is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11* Lesser General Public License for more details.12*13* You should have received a copy of the GNU Lesser General Public14* License along with this library; if not, write to the Free Software15* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA16*/1718#ifndef __VKD3D_H19#define __VKD3D_H2021#include <vkd3d_types.h>2223#ifndef VKD3D_NO_WIN32_TYPES24# include <windows.h>25# include <d3d12.h>26#endif /* VKD3D_NO_WIN32_TYPES */2728#ifndef VKD3D_NO_VULKAN_H29# include <wine/vulkan.h>30#endif /* VKD3D_NO_VULKAN_H */3132#ifdef __cplusplus33extern "C" {34#endif /* __cplusplus */3536/**37* \file vkd3d.h38*39* This file contains definitions for the vkd3d library.40*41* The vkd3d library is a 3D graphics library built on top of42* Vulkan. It has an API very similar, but not identical, to43* Direct3D 12.44*45* \since 1.046*/4748/** The type of a chained structure. */49enum vkd3d_structure_type50{51/** The structure is a vkd3d_instance_create_info structure. */52VKD3D_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,53/** The structure is a vkd3d_device_create_info structure. */54VKD3D_STRUCTURE_TYPE_DEVICE_CREATE_INFO,55/** The structure is a vkd3d_image_resource_create_info structure. */56VKD3D_STRUCTURE_TYPE_IMAGE_RESOURCE_CREATE_INFO,5758/**59* The structure is a vkd3d_optional_instance_extensions_info structure.60* \since 1.161*/62VKD3D_STRUCTURE_TYPE_OPTIONAL_INSTANCE_EXTENSIONS_INFO,6364/**65* The structure is a vkd3d_optional_device_extensions_info structure.66* \since 1.267*/68VKD3D_STRUCTURE_TYPE_OPTIONAL_DEVICE_EXTENSIONS_INFO,69/**70* The structure is a vkd3d_application_info structure.71* \since 1.272*/73VKD3D_STRUCTURE_TYPE_APPLICATION_INFO,7475/**76* The structure is a vkd3d_host_time_domain_info structure.77* \since 1.378*/79VKD3D_STRUCTURE_TYPE_HOST_TIME_DOMAIN_INFO,8081VKD3D_FORCE_32_BIT_ENUM(VKD3D_STRUCTURE_TYPE),82};8384enum vkd3d_api_version85{86VKD3D_API_VERSION_1_0,87VKD3D_API_VERSION_1_1,88VKD3D_API_VERSION_1_2,89VKD3D_API_VERSION_1_3,90VKD3D_API_VERSION_1_4,91VKD3D_API_VERSION_1_5,92VKD3D_API_VERSION_1_6,93VKD3D_API_VERSION_1_7,94VKD3D_API_VERSION_1_8,95VKD3D_API_VERSION_1_9,96VKD3D_API_VERSION_1_10,97VKD3D_API_VERSION_1_11,98VKD3D_API_VERSION_1_12,99VKD3D_API_VERSION_1_13,100VKD3D_API_VERSION_1_14,101VKD3D_API_VERSION_1_15,102VKD3D_API_VERSION_1_16,103VKD3D_API_VERSION_1_17,104VKD3D_API_VERSION_1_18,105106VKD3D_FORCE_32_BIT_ENUM(VKD3D_API_VERSION),107};108109typedef HRESULT (*PFN_vkd3d_signal_event)(HANDLE event);110111typedef void * (*PFN_vkd3d_thread)(void *data);112113typedef void * (*PFN_vkd3d_create_thread)(PFN_vkd3d_thread thread_main, void *data);114typedef HRESULT (*PFN_vkd3d_join_thread)(void *thread);115116struct vkd3d_instance;117118/**119* A chained structure containing instance creation parameters.120*/121struct vkd3d_instance_create_info122{123/** Must be set to VKD3D_STRUCTURE_TYPE_INSTANCE_CREATE_INFO. */124enum vkd3d_structure_type type;125/** Optional pointer to a structure containing further parameters. */126const void *next;127128/** An pointer to a function to signal events. */129PFN_vkd3d_signal_event pfn_signal_event;130/**131* An optional pointer to a function to create threads. If this is NULL vkd3d will use a132* function of its choice, depending on the platform. It must be NULL if and only if133* pfn_join_thread is NULL.134*/135PFN_vkd3d_create_thread pfn_create_thread;136/**137* An optional pointer to a function to join threads. If this is NULL vkd3d will use a138* function of its choice, depending on the platform. It must be NULL if and only if139* pfn_create_thread is NULL.140*/141PFN_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). */143size_t wchar_size;144145/**146* A pointer to the vkGetInstanceProcAddr Vulkan function, which will be used to load all the147* other Vulkan functions. If set to NULL, vkd3d will search and use the Vulkan loader.148*/149PFN_vkGetInstanceProcAddr pfn_vkGetInstanceProcAddr;150151/**152* A list of Vulkan instance extensions to request. They are intended as required, so instance153* creation will fail if any of them is not available.154*/155const char * const *instance_extensions;156/** The number of elements in the instance_extensions array. */157uint32_t instance_extension_count;158};159160/**161* A chained structure to specify optional instance extensions.162*163* This structure extends vkd3d_instance_create_info.164*165* \since 1.1166*/167struct vkd3d_optional_instance_extensions_info168{169/** Must be set to VKD3D_STRUCTURE_TYPE_OPTIONAL_INSTANCE_EXTENSIONS_INFO. */170enum vkd3d_structure_type type;171/** Optional pointer to a structure containing further parameters. */172const void *next;173174/**175* A list of optional Vulkan instance extensions to request. Instance creation does not fail if176* they are not available.177*/178const char * const *extensions;179/** The number of elements in the extensions array. */180uint32_t extension_count;181};182183/**184* A chained structure to specify application information.185*186* This structure extends vkd3d_instance_create_info.187*188* \since 1.2189*/190struct vkd3d_application_info191{192/** Must be set to VKD3D_STRUCTURE_TYPE_APPLICATION_INFO. */193enum vkd3d_structure_type type;194/** Optional pointer to a structure containing further parameters. */195const void *next;196197/**198* The application's name, to be passed to the Vulkan implementation. If it is NULL, a name is199* computed from the process executable filename. If that cannot be done, the empty string is200* used.201*/202const char *application_name;203/** The application's version, to be passed to the Vulkan implementation. */204uint32_t application_version;205206/**207* The engine name, to be passed to the Vulkan implementation. If it is NULL, "vkd3d" is used.208*/209const char *engine_name;210/**211* The engine version, to be passed to the Vulkan implementation. If it is 0, the version is212* computed from the vkd3d library version.213*/214uint32_t engine_version;215216/**217* The vkd3d API version to use, to guarantee backward compatibility of the shared library. If218* this chained structure is not used then VKD3D_API_VERSION_1_0 is used.219*/220enum vkd3d_api_version api_version;221};222223/**224* A chained structure to specify the host time domain.225*226* This structure extends vkd3d_instance_create_info.227*228* \since 1.3229*/230struct vkd3d_host_time_domain_info231{232/** Must be set to VKD3D_STRUCTURE_TYPE_HOST_TIME_DOMAIN_INFO. */233enum vkd3d_structure_type type;234/** Optional pointer to a structure containing further parameters. */235const void *next;236237/**238* The number of clock ticks per second, used for GetClockCalibration(). It should normally239* match the expected result of QueryPerformanceFrequency(). If this chained structure is not240* used then 10 millions is used, which means that each tick is a tenth of microsecond, or241* equivalently 100 nanoseconds.242*/243uint64_t ticks_per_second;244};245246/**247* A chained structure containing device creation parameters.248*/249struct vkd3d_device_create_info250{251/** Must be set to VKD3D_STRUCTURE_TYPE_DEVICE_CREATE_INFO. */252enum vkd3d_structure_type type;253/** Optional pointer to a structure containing further parameters. */254const void *next;255256/** The minimum feature level to request. Device creation will fail with E_INVALIDARG if the257* Vulkan device doesn't have the features needed to fulfill the request. */258D3D_FEATURE_LEVEL minimum_feature_level;259260/**261* The vkd3d instance to use to create a device. Either this or instance_create_info must be262* set.263*/264struct vkd3d_instance *instance;265/**266* The parameters used to create an instance, which is then used to create a device. Either267* this or instance must be set.268*/269const struct vkd3d_instance_create_info *instance_create_info;270271/**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*/277VkPhysicalDevice vk_physical_device;278279/**280* A list of Vulkan device extensions to request. They are intended as required, so device281* creation will fail if any of them is not available.282*/283const char * const *device_extensions;284/** The number of elements in the device_extensions array. */285uint32_t device_extension_count;286287/**288* An object to be set as the device parent. This is not used by vkd3d except for being289* returned by vkd3d_get_device_parent.290*/291IUnknown *parent;292/**293* The adapter LUID to be set for the device. This is not used by vkd3d except for being294* returned by GetAdapterLuid.295*/296LUID adapter_luid;297};298299/**300* A chained structure to specify optional device extensions.301*302* This structure extends vkd3d_device_create_info.303*304* \since 1.2305*/306struct vkd3d_optional_device_extensions_info307{308/** Must be set to VKD3D_STRUCTURE_TYPE_OPTIONAL_DEVICE_EXTENSIONS_INFO. */309enum vkd3d_structure_type type;310/** Optional pointer to a structure containing further parameters. */311const void *next;312313/**314* A list of optional Vulkan device extensions to request. Device creation does not fail if315* they are not available.316*/317const char * const *extensions;318/** The number of elements in the extensions array. */319uint32_t extension_count;320};321322/**323* When specified as a flag of vkd3d_image_resource_create_info, it means that vkd3d will do the324* initial transition operation on the image from VK_IMAGE_LAYOUT_UNDEFINED to its appropriate325* Vulkan layout (depending on its D3D12 resource state). If this flag is not specified the caller326* is responsible for transitioning the Vulkan image to the appropriate layout.327*/328#define VKD3D_RESOURCE_INITIAL_STATE_TRANSITION 0x00000001329/**330* When specified as a flag of vkd3d_image_resource_create_info, it means that field present_state331* is honored.332*/333#define VKD3D_RESOURCE_PRESENT_STATE_TRANSITION 0x00000002334335/**336* A chained structure containing the parameters to create a D3D12 resource backed by a Vulkan337* image.338*/339struct vkd3d_image_resource_create_info340{341/** Must be set to VKD3D_STRUCTURE_TYPE_IMAGE_RESOURCE_CREATE_INFO. */342enum vkd3d_structure_type type;343/** Optional pointer to a structure containing further parameters. */344const void *next;345346/** The Vulkan image that backs the resource. */347VkImage vk_image;348/** The resource description. */349D3D12_RESOURCE_DESC desc;350/**351* A combination of zero or more flags. The valid flags are352* VKD3D_RESOURCE_INITIAL_STATE_TRANSITION and VKD3D_RESOURCE_PRESENT_STATE_TRANSITION.353*/354unsigned int flags;355/**356* This field specifies how to handle resource state D3D12_RESOURCE_STATE_PRESENT for357* the resource. Notice that on D3D12 there is no difference between358* 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 and360* VK_IMAGE_LAYOUT_PRESENT_SRC_KHR).361*362* * When flag VKD3D_RESOURCE_PRESENT_STATE_TRANSITION is not specified, field363* present_state is ignored and resource state D3D12_RESOURCE_STATE_COMMON/_PRESENT is364* 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 state366* 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 swapchain368* image.369* * Otherwise, resource state D3D12_RESOURCE_STATE_COMMON/_PRESENT is treated as resource370* state present_state; this is useful for swapchain resources that backed by a Vulkan371* non-swapchain image, which the client will likely consume with a copy or drawing372* operation at presentation time.373*/374D3D12_RESOURCE_STATES present_state;375};376377#ifdef LIBVKD3D_SOURCE378# define VKD3D_API VKD3D_EXPORT379#else380# define VKD3D_API VKD3D_IMPORT381#endif382383#ifndef VKD3D_NO_PROTOTYPES384385VKD3D_API HRESULT vkd3d_create_instance(const struct vkd3d_instance_create_info *create_info,386struct vkd3d_instance **instance);387VKD3D_API ULONG vkd3d_instance_decref(struct vkd3d_instance *instance);388VKD3D_API VkInstance vkd3d_instance_get_vk_instance(struct vkd3d_instance *instance);389VKD3D_API ULONG vkd3d_instance_incref(struct vkd3d_instance *instance);390391VKD3D_API HRESULT vkd3d_create_device(const struct vkd3d_device_create_info *create_info,392REFIID iid, void **device);393VKD3D_API IUnknown *vkd3d_get_device_parent(ID3D12Device *device);394VKD3D_API VkDevice vkd3d_get_vk_device(ID3D12Device *device);395VKD3D_API VkPhysicalDevice vkd3d_get_vk_physical_device(ID3D12Device *device);396VKD3D_API struct vkd3d_instance *vkd3d_instance_from_device(ID3D12Device *device);397398VKD3D_API uint32_t vkd3d_get_vk_queue_family_index(ID3D12CommandQueue *queue);399400/**401* Acquire the Vulkan queue backing a command queue.402*403* While a queue is acquired by the client, it is locked so that404* neither the vkd3d library nor other threads can submit work to405* it. For that reason it should be released as soon as possible with406* vkd3d_release_vk_queue(). The lock is not reentrant, so the same407* 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 not410* always immediately submitted to the Vulkan queue; sometimes it is411* kept in another internal queue, which might not necessarily be412* empty at the time vkd3d_acquire_vk_queue() is called. For this413* reason, work submitted directly to the Vulkan queue might appear to414* the Vulkan driver as being submitted before other work submitted415* though the Direct3D 12 API. If this is not desired, it is416* recommended to synchronize work submission using an ID3D12Fence417* 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 submitted422* at point 1 has already been submitted to Vulkan (though not necessarily423* executed).424*425* \since 1.0426*/427VKD3D_API VkQueue vkd3d_acquire_vk_queue(ID3D12CommandQueue *queue);428429/**430* Release the Vulkan queue backing a command queue.431*432* This must be paired to an earlier corresponding433* vkd3d_acquire_vk_queue(). After this function is called, the Vulkan434* queue returned by vkd3d_acquire_vk_queue() must not be used any435* more.436*437* \since 1.0438*/439VKD3D_API void vkd3d_release_vk_queue(ID3D12CommandQueue *queue);440441VKD3D_API HRESULT vkd3d_create_image_resource(ID3D12Device *device,442const struct vkd3d_image_resource_create_info *create_info, ID3D12Resource **resource);443VKD3D_API ULONG vkd3d_resource_decref(ID3D12Resource *resource);444VKD3D_API ULONG vkd3d_resource_incref(ID3D12Resource *resource);445446VKD3D_API HRESULT vkd3d_serialize_root_signature(const D3D12_ROOT_SIGNATURE_DESC *desc,447D3D_ROOT_SIGNATURE_VERSION version, ID3DBlob **blob, ID3DBlob **error_blob);448VKD3D_API HRESULT vkd3d_create_root_signature_deserializer(const void *data, SIZE_T data_size,449REFIID iid, void **deserializer);450451VKD3D_API VkFormat vkd3d_get_vk_format(DXGI_FORMAT format);452453/* 1.1 */454VKD3D_API DXGI_FORMAT vkd3d_get_dxgi_format(VkFormat format);455456/* 1.2 */457VKD3D_API HRESULT vkd3d_serialize_versioned_root_signature(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC *desc,458ID3DBlob **blob, ID3DBlob **error_blob);459VKD3D_API HRESULT vkd3d_create_versioned_root_signature_deserializer(const void *data, SIZE_T data_size,460REFIID iid, void **deserializer);461462/**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 all466* 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.4473*/474VKD3D_API void vkd3d_set_log_callback(PFN_vkd3d_log callback);475476/**477* Signal a fence on the CPU once all the currently outstanding queue work is478* submitted to Vulkan.479*480* The fence will be signalled on the CPU (as if ID3D12Fence_Signal() was481* called) once all the work submitted through the Direct3D 12 API before482* vkd3d_queue_signal_on_cpu() is called has left the internal queue and has483* been submitted to the underlying Vulkan queue. Read the documentation for484* vkd3d_acquire_vk_queue() for more details.485*486* \since 1.15487*/488VKD3D_API HRESULT vkd3d_queue_signal_on_cpu(ID3D12CommandQueue *queue,489ID3D12Fence *fence, uint64_t value);490491#endif /* VKD3D_NO_PROTOTYPES */492493/*494* Function pointer typedefs for vkd3d functions.495*/496typedef HRESULT (*PFN_vkd3d_create_instance)(const struct vkd3d_instance_create_info *create_info,497struct vkd3d_instance **instance);498typedef ULONG (*PFN_vkd3d_instance_decref)(struct vkd3d_instance *instance);499typedef VkInstance (*PFN_vkd3d_instance_get_vk_instance)(struct vkd3d_instance *instance);500typedef ULONG (*PFN_vkd3d_instance_incref)(struct vkd3d_instance *instance);501502typedef HRESULT (*PFN_vkd3d_create_device)(const struct vkd3d_device_create_info *create_info,503REFIID iid, void **device);504typedef IUnknown * (*PFN_vkd3d_get_device_parent)(ID3D12Device *device);505typedef VkDevice (*PFN_vkd3d_get_vk_device)(ID3D12Device *device);506typedef VkPhysicalDevice (*PFN_vkd3d_get_vk_physical_device)(ID3D12Device *device);507typedef struct vkd3d_instance * (*PFN_vkd3d_instance_from_device)(ID3D12Device *device);508509typedef uint32_t (*PFN_vkd3d_get_vk_queue_family_index)(ID3D12CommandQueue *queue);510typedef VkQueue (*PFN_vkd3d_acquire_vk_queue)(ID3D12CommandQueue *queue);511typedef void (*PFN_vkd3d_release_vk_queue)(ID3D12CommandQueue *queue);512513typedef HRESULT (*PFN_vkd3d_create_image_resource)(ID3D12Device *device,514const struct vkd3d_image_resource_create_info *create_info, ID3D12Resource **resource);515typedef ULONG (*PFN_vkd3d_resource_decref)(ID3D12Resource *resource);516typedef ULONG (*PFN_vkd3d_resource_incref)(ID3D12Resource *resource);517518typedef HRESULT (*PFN_vkd3d_serialize_root_signature)(const D3D12_ROOT_SIGNATURE_DESC *desc,519D3D_ROOT_SIGNATURE_VERSION version, ID3DBlob **blob, ID3DBlob **error_blob);520typedef HRESULT (*PFN_vkd3d_create_root_signature_deserializer)(const void *data, SIZE_T data_size,521REFIID iid, void **deserializer);522523typedef VkFormat (*PFN_vkd3d_get_vk_format)(DXGI_FORMAT format);524525/* 1.1 */526typedef DXGI_FORMAT (*PFN_vkd3d_get_dxgi_format)(VkFormat format);527528/* 1.2 */529typedef HRESULT (*PFN_vkd3d_serialize_versioned_root_signature)(const D3D12_VERSIONED_ROOT_SIGNATURE_DESC *desc,530ID3DBlob **blob, ID3DBlob **error_blob);531typedef HRESULT (*PFN_vkd3d_create_versioned_root_signature_deserializer)(const void *data, SIZE_T data_size,532REFIID iid, void **deserializer);533534/** Type of vkd3d_set_log_callback(). \since 1.4 */535typedef void (*PFN_vkd3d_set_log_callback)(PFN_vkd3d_log callback);536537/** Type of vkd3d_queue_signal_on_cpu(). \since 1.15 */538typedef HRESULT (*PFN_vkd3d_queue_signal_on_cpu)(ID3D12CommandQueue *queue,539ID3D12Fence *fence, uint64_t value);540541#ifdef __cplusplus542}543#endif /* __cplusplus */544545#endif /* __VKD3D_H */546547548