Skip to content

Commit

Permalink
start import of d3d12
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkFire01 committed Sep 19, 2023
1 parent 4fc13f1 commit b77319f
Show file tree
Hide file tree
Showing 86 changed files with 19,267 additions and 19,650 deletions.
133 changes: 35 additions & 98 deletions dll/directx/wine/d3d12/d3d12_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,25 @@
*
*/

#include "config.h"
#include "wine/port.h"

#define COBJMACROS
#define VK_NO_PROTOTYPES
#define VKD3D_NO_VULKAN_H
#define VKD3D_NO_WIN32_TYPES
#ifndef USE_WIN32_VULKAN
#define USE_WIN32_VULKAN
#endif

#include "wine/debug.h"
#include "wine/heap.h"
#include "wine/vulkan.h"
#include "wine/vulkan_driver.h"

#include "windef.h"
#include "dxgi1_6.h"
#include "d3d12.h"
#include "wine/vulkan.h"

#include <vkd3d.h>

#include "initguid.h"
#include "wine/wined3d.h"
#include "wine/winedxgi.h"
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(d3d12);
WINE_DECLARE_DEBUG_CHANNEL(winediag);

#ifdef USE_WIN32_VULKAN

static HMODULE vulkan_module;

/* FIXME: We should unload vulkan-1.dll. */
Expand All @@ -68,25 +57,6 @@ static PFN_vkGetInstanceProcAddr load_vulkan(void)
return NULL;
}

#else

static PFN_vkGetInstanceProcAddr load_vulkan(void)
{
const struct vulkan_funcs *vk_funcs;
HDC hdc;

hdc = GetDC(0);
vk_funcs = __wine_get_vulkan_driver(hdc, WINE_VULKAN_DRIVER_VERSION);
ReleaseDC(0, hdc);

if (vk_funcs)
return (PFN_vkGetInstanceProcAddr)vk_funcs->p_vkGetInstanceProcAddr;

return NULL;
}

#endif /* USE_WIN32_VULKAN */

HRESULT WINAPI D3D12GetDebugInterface(REFIID iid, void **debug)
{
TRACE("iid %s, debug %p.\n", debugstr_guid(iid), debug);
Expand All @@ -109,52 +79,6 @@ static HRESULT d3d12_signal_event(HANDLE event)
return SetEvent(event) ? S_OK : E_FAIL;
}

struct d3d12_thread_data
{
PFN_vkd3d_thread main_pfn;
void *data;
};

static DWORD WINAPI d3d12_thread_main(void *data)
{
struct d3d12_thread_data *thread_data = data;

thread_data->main_pfn(thread_data->data);
heap_free(thread_data);
return 0;
}

static void *d3d12_create_thread(PFN_vkd3d_thread main_pfn, void *data)
{
struct d3d12_thread_data *thread_data;
HANDLE thread;

if (!(thread_data = heap_alloc(sizeof(*thread_data))))
{
ERR("Failed to allocate thread data.\n");
return NULL;
}

thread_data->main_pfn = main_pfn;
thread_data->data = data;

if (!(thread = CreateThread(NULL, 0, d3d12_thread_main, thread_data, 0, NULL)))
heap_free(thread_data);

return thread;
}

static HRESULT d3d12_join_thread(void *handle)
{
HANDLE thread = handle;
DWORD ret;

if ((ret = WaitForSingleObject(thread, INFINITE)) != WAIT_OBJECT_0)
ERR("Failed to wait for thread, ret %#x.\n", ret);
CloseHandle(thread);
return ret == WAIT_OBJECT_0 ? S_OK : E_FAIL;
}

static HRESULT d3d12_get_adapter(IWineDXGIAdapter **wine_adapter, IUnknown *adapter)
{
IDXGIAdapter *dxgi_adapter = NULL;
Expand All @@ -165,21 +89,21 @@ static HRESULT d3d12_get_adapter(IWineDXGIAdapter **wine_adapter, IUnknown *adap
{
if (FAILED(hr = CreateDXGIFactory2(0, &IID_IDXGIFactory4, (void **)&factory)))
{
WARN("Failed to create DXGI factory, hr %#x.\n", hr);
WARN("Failed to create DXGI factory, hr %#lx.\n", hr);
goto done;
}

if (FAILED(hr = IDXGIFactory4_EnumAdapters(factory, 0, &dxgi_adapter)))
{
WARN("Failed to enumerate primary adapter, hr %#x.\n", hr);
WARN("Failed to enumerate primary adapter, hr %#lx.\n", hr);
goto done;
}

adapter = (IUnknown *)dxgi_adapter;
}

if (FAILED(hr = IUnknown_QueryInterface(adapter, &IID_IWineDXGIAdapter, (void **)wine_adapter)))
WARN("Invalid adapter %p, hr %#x.\n", adapter, hr);
WARN("Invalid adapter %p, hr %#lx.\n", adapter, hr);

done:
if (dxgi_adapter)
Expand All @@ -205,7 +129,7 @@ static BOOL check_vk_instance_extension(VkInstance vk_instance,
if (pfn_vkEnumerateInstanceExtensionProperties(NULL, &count, NULL) < 0)
return FALSE;

if (!(properties = heap_calloc(count, sizeof(*properties))))
if (!(properties = calloc(count, sizeof(*properties))))
return FALSE;

if (pfn_vkEnumerateInstanceExtensionProperties(NULL, &count, properties) >= 0)
Expand All @@ -220,7 +144,7 @@ static BOOL check_vk_instance_extension(VkInstance vk_instance,
}
}

heap_free(properties);
free(properties);
return ret;
}

Expand Down Expand Up @@ -259,13 +183,15 @@ static VkPhysicalDevice d3d12_get_vk_physical_device(struct vkd3d_instance *inst
return VK_NULL_HANDLE;
}

if (!(vk_physical_devices = heap_calloc(count, sizeof(*vk_physical_devices))))
if (!(vk_physical_devices = calloc(count, sizeof(*vk_physical_devices))))
return VK_NULL_HANDLE;

if ((vr = pfn_vkEnumeratePhysicalDevices(vk_instance, &count, vk_physical_devices)) < 0)
goto done;

if (!IsEqualGUID(&adapter_info->driver_uuid, &GUID_NULL) && pfn_vkGetPhysicalDeviceProperties2)
if (!IsEqualGUID(&adapter_info->driver_uuid, &GUID_NULL) && pfn_vkGetPhysicalDeviceProperties2
&& check_vk_instance_extension(vk_instance, pfn_vkGetInstanceProcAddr,
VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME))
{
TRACE("Matching adapters by UUIDs.\n");

Expand Down Expand Up @@ -308,7 +234,7 @@ static VkPhysicalDevice d3d12_get_vk_physical_device(struct vkd3d_instance *inst
FIXME("Could not find Vulkan physical device for DXGI adapter.\n");

done:
heap_free(vk_physical_devices);
free(vk_physical_devices);
return vk_physical_device;
}

Expand All @@ -331,12 +257,18 @@ HRESULT WINAPI D3D12CreateDevice(IUnknown *adapter, D3D_FEATURE_LEVEL minimum_fe
};
static const char * const optional_instance_extensions[] =
{
VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME,
VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME,
};
static const char * const device_extensions[] =
{
VK_KHR_SWAPCHAIN_EXTENSION_NAME,
};
static const struct vkd3d_application_info application_info =
{
.type = VKD3D_STRUCTURE_TYPE_APPLICATION_INFO,
.api_version = VKD3D_API_VERSION_1_2,
};

TRACE("adapter %p, minimum_feature_level %#x, iid %s, device %p.\n",
adapter, minimum_feature_level, debugstr_guid(iid), device);
Expand All @@ -352,28 +284,28 @@ HRESULT WINAPI D3D12CreateDevice(IUnknown *adapter, D3D_FEATURE_LEVEL minimum_fe

if (FAILED(hr = IWineDXGIAdapter_get_adapter_info(wine_adapter, &adapter_info)))
{
WARN("Failed to get adapter info, hr %#x.\n", hr);
WARN("Failed to get adapter info, hr %#lx.\n", hr);
goto done;
}

optional_extensions_info.type = VKD3D_STRUCTURE_TYPE_OPTIONAL_INSTANCE_EXTENSIONS_INFO;
optional_extensions_info.next = NULL;
optional_extensions_info.next = &application_info;
optional_extensions_info.extensions = optional_instance_extensions;
optional_extensions_info.extension_count = ARRAY_SIZE(optional_instance_extensions);

instance_create_info.type = VKD3D_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
instance_create_info.next = &optional_extensions_info;
instance_create_info.pfn_signal_event = d3d12_signal_event;
instance_create_info.pfn_create_thread = d3d12_create_thread;
instance_create_info.pfn_join_thread = d3d12_join_thread;
instance_create_info.pfn_create_thread = NULL;
instance_create_info.pfn_join_thread = NULL;
instance_create_info.wchar_size = sizeof(WCHAR);
instance_create_info.pfn_vkGetInstanceProcAddr = pfn_vkGetInstanceProcAddr;
instance_create_info.instance_extensions = instance_extensions;
instance_create_info.instance_extension_count = ARRAY_SIZE(instance_extensions);

if (FAILED(hr = vkd3d_create_instance(&instance_create_info, &instance)))
{
WARN("Failed to create vkd3d instance, hr %#x.\n", hr);
WARN("Failed to create vkd3d instance, hr %#lx.\n", hr);
goto done;
}

Expand All @@ -400,12 +332,21 @@ HRESULT WINAPI D3D12CreateDevice(IUnknown *adapter, D3D_FEATURE_LEVEL minimum_fe
HRESULT WINAPI D3D12CreateRootSignatureDeserializer(const void *data, SIZE_T data_size,
REFIID iid, void **deserializer)
{
TRACE("data %p, data_size %lu, iid %s, deserializer %p.\n",
TRACE("data %p, data_size %Iu, iid %s, deserializer %p.\n",
data, data_size, debugstr_guid(iid), deserializer);

return vkd3d_create_root_signature_deserializer(data, data_size, iid, deserializer);
}

HRESULT WINAPI D3D12CreateVersionedRootSignatureDeserializer(const void *data, SIZE_T data_size,
REFIID iid, void **deserializer)
{
TRACE("data %p, data_size %Iu, iid %s, deserializer %p.\n",
data, data_size, debugstr_guid(iid), deserializer);

return vkd3d_create_versioned_root_signature_deserializer(data, data_size, iid, deserializer);
}

HRESULT WINAPI D3D12SerializeRootSignature(const D3D12_ROOT_SIGNATURE_DESC *root_signature_desc,
D3D_ROOT_SIGNATURE_VERSION version, ID3DBlob **blob, ID3DBlob **error_blob)
{
Expand All @@ -420,9 +361,5 @@ HRESULT WINAPI D3D12SerializeVersionedRootSignature(const D3D12_VERSIONED_ROOT_S
{
TRACE("desc %p, blob %p, error_blob %p.\n", desc, blob, error_blob);

if (desc->Version == D3D_ROOT_SIGNATURE_VERSION_1_0)
return vkd3d_serialize_root_signature(&desc->Desc_1_0, desc->Version, blob, error_blob);

FIXME("Unsupported version %#x.\n", desc->Version);
return E_NOTIMPL;
return vkd3d_serialize_versioned_root_signature(desc, blob, error_blob);
}
7 changes: 0 additions & 7 deletions dll/directx/wine/d3d12/vkd3d/CMakeLists.txt

This file was deleted.

15 changes: 0 additions & 15 deletions dll/directx/wine/d3d12/vkd3d/include/.gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions dll/directx/wine/d3d12/vkd3d/include/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit b77319f

Please sign in to comment.