#ifdef _WIN32
#include <windows.h>
#include <shlobj.h>
+#include "dzn_dxgi.h"
#endif
#include <directx/d3d12sdklayers.h>
};
}
-static VkResult
+VkResult
dzn_instance_add_physical_device(struct dzn_instance *instance,
IUnknown *adapter,
const struct dzn_physical_device_desc *desc)
VK_FROM_HANDLE(dzn_instance, instance, inst);
if (!instance->physical_devices_enumerated) {
- IDXGIFactory4 *factory = dxgi_get_factory(false);
- IDXGIAdapter1 *adapter = NULL;
- VkResult result = VK_SUCCESS;
- for (UINT i = 0; SUCCEEDED(IDXGIFactory4_EnumAdapters1(factory, i, &adapter)); ++i) {
- DXGI_ADAPTER_DESC1 dxgi_desc;
- IDXGIAdapter1_GetDesc1(adapter, &dxgi_desc);
-
- struct dzn_physical_device_desc desc = {
- .adapter_luid = dxgi_desc.AdapterLuid,
- .vendor_id = dxgi_desc.VendorId,
- .device_id = dxgi_desc.DeviceId,
- .subsys_id = dxgi_desc.SubSysId,
- .revision = dxgi_desc.Revision,
- .shared_system_memory = dxgi_desc.SharedSystemMemory,
- .dedicated_system_memory = dxgi_desc.DedicatedSystemMemory,
- .dedicated_video_memory = dxgi_desc.DedicatedVideoMemory,
- .is_warp = (dxgi_desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0,
- };
- WideCharToMultiByte(CP_ACP, 0, dxgi_desc.Description, ARRAYSIZE(dxgi_desc.Description),
- desc.description, ARRAYSIZE(desc.description), NULL, NULL);
-
- result =
- dzn_instance_add_physical_device(instance, (IUnknown *)adapter, &desc);
-
- IDXGIAdapter1_Release(adapter);
-
- if (result != VK_SUCCESS)
- break;
- }
-
- IDXGIFactory4_Release(factory);
-
+#ifdef _WIN32
+ VkResult result = dzn_enumerate_physical_devices_dxgi(instance);
if (result != VK_SUCCESS)
return result;
+#endif
}
VK_OUTARRAY_MAKE_TYPED(VkPhysicalDevice, out, pPhysicalDevices,
--- /dev/null
+/*
+ * Copyright © Microsoft Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#define COBJMACROS
+#include "dzn_physical_device_enum.h"
+#include "dzn_dxgi.h"
+
+#include "log.h"
+
+VkResult
+dzn_enumerate_physical_devices_dxgi(struct dzn_instance *instance)
+{
+ IDXGIFactory4 *factory = dxgi_get_factory(false);
+ IDXGIAdapter1 *adapter = NULL;
+ VkResult result = VK_SUCCESS;
+ for (UINT i = 0; SUCCEEDED(IDXGIFactory4_EnumAdapters1(factory, i, &adapter)); ++i) {
+ DXGI_ADAPTER_DESC1 dxgi_desc;
+ IDXGIAdapter1_GetDesc1(adapter, &dxgi_desc);
+
+ struct dzn_physical_device_desc desc = {
+ .adapter_luid = dxgi_desc.AdapterLuid,
+ .vendor_id = dxgi_desc.VendorId,
+ .device_id = dxgi_desc.DeviceId,
+ .subsys_id = dxgi_desc.SubSysId,
+ .revision = dxgi_desc.Revision,
+ .shared_system_memory = dxgi_desc.SharedSystemMemory,
+ .dedicated_system_memory = dxgi_desc.DedicatedSystemMemory,
+ .dedicated_video_memory = dxgi_desc.DedicatedVideoMemory,
+ .is_warp = (dxgi_desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) != 0,
+ };
+ WideCharToMultiByte(CP_ACP, 0, dxgi_desc.Description, ARRAYSIZE(dxgi_desc.Description),
+ desc.description, ARRAYSIZE(desc.description), NULL, NULL);
+ result =
+ dzn_instance_add_physical_device(instance, (IUnknown *)adapter, &desc);
+
+ IDXGIAdapter1_Release(adapter);
+
+ if (result != VK_SUCCESS)
+ break;
+ }
+
+ IDXGIFactory4_Release(factory);
+
+ return result;
+}
+
+IDXGIFactory4 *
+dxgi_get_factory(bool debug)
+{
+ static const GUID IID_IDXGIFactory4 = {
+ 0x1bc6ea02, 0xef36, 0x464f,
+ { 0xbf, 0x0c, 0x21, 0xca, 0x39, 0xe5, 0x16, 0x8a }
+ };
+
+ HMODULE dxgi_mod = LoadLibraryA("DXGI.DLL");
+ if (!dxgi_mod) {
+ mesa_loge("failed to load DXGI.DLL\n");
+ return NULL;
+ }
+
+ typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY2)(UINT flags, REFIID riid, void **ppFactory);
+ PFN_CREATE_DXGI_FACTORY2 CreateDXGIFactory2;
+
+ CreateDXGIFactory2 = (PFN_CREATE_DXGI_FACTORY2)GetProcAddress(dxgi_mod, "CreateDXGIFactory2");
+ if (!CreateDXGIFactory2) {
+ mesa_loge("failed to load CreateDXGIFactory2 from DXGI.DLL\n");
+ return NULL;
+ }
+
+ UINT flags = 0;
+ if (debug)
+ flags |= DXGI_CREATE_FACTORY_DEBUG;
+
+ IDXGIFactory4 *factory;
+ HRESULT hr = CreateDXGIFactory2(flags, &IID_IDXGIFactory4, (void **)&factory);
+ if (FAILED(hr)) {
+ mesa_loge("CreateDXGIFactory2 failed: %08x\n", (int32_t)hr);
+ return NULL;
+ }
+
+ return factory;
+}
--- /dev/null
+/*
+ * Copyright © Microsoft Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef DZN_DXGI_H
+#define DZN_DXGI_H
+
+#include <dxgi1_4.h>
+
+struct dzn_instance;
+
+IDXGIFactory4 *
+dxgi_get_factory(bool debug);
+
+#endif /* DZN_DXGI_H */
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright © Microsoft Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef DZN_PHYSICAL_DEVICE_ENUM_H
+#define DZN_PHYSICAL_DEVICE_ENUM_H
+
+#include <vulkan/vulkan.h>
+
+#include <unknwn.h>
+
+#ifndef _WIN32
+#include <wsl/winadapter.h>
+#endif
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct dzn_instance;
+
+struct dzn_physical_device_desc {
+ LUID adapter_luid;
+ uint32_t vendor_id;
+ uint32_t device_id;
+ uint32_t subsys_id;
+ uint32_t revision;
+ uint64_t shared_system_memory;
+ uint64_t dedicated_system_memory;
+ uint64_t dedicated_video_memory;
+ bool is_warp;
+ char description[128];
+};
+
+VkResult
+dzn_enumerate_physical_devices_dxgi(struct dzn_instance *instance);
+
+VkResult
+dzn_instance_add_physical_device(struct dzn_instance *instance,
+ IUnknown *adapter,
+ const struct dzn_physical_device_desc *desc);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* DZN_PHYSICAL_DEVICE_ENUM_H */
#include "dzn_entrypoints.h"
#include "dzn_nir.h"
+#include "dzn_physical_device_enum.h"
#include <vulkan/vulkan.h>
#include <vulkan/vk_icd.h>
#define D3D12_IGNORE_SDK_LAYERS
#include <unknwn.h>
-#include <dxgi1_4.h>
#include <directx/d3d12.h>
#include "spirv_to_dxil.h"
#define MAX_SYNC_TYPES 3
#define MAX_QUEUE_FAMILIES 3
-struct dzn_physical_device_desc {
- LUID adapter_luid;
- uint32_t vendor_id;
- uint32_t device_id;
- uint32_t subsys_id;
- uint32_t revision;
- uint64_t shared_system_memory;
- uint64_t dedicated_system_memory;
- uint64_t dedicated_video_memory;
- bool is_warp;
- char description[128];
-};
-
struct dzn_physical_device {
struct vk_physical_device vk;
struct list_head link;
#define dzn_debug_ignored_stype(sType) \
mesa_logd("%s: ignored VkStructureType %u\n", __func__, (sType))
-IDXGIFactory4 *
-dxgi_get_factory(bool debug);
-
PFN_D3D12_SERIALIZE_VERSIONED_ROOT_SIGNATURE
d3d12_get_serialize_root_sig(void);
#include <directx/d3d12sdklayers.h>
#include <util/u_dl.h>
-#include <dxgi1_4.h>
static const DXGI_FORMAT formats[PIPE_FORMAT_COUNT] = {
#define MAP_FORMAT_NORM(FMT) \
out->bottom = in->offset.y + in->extent.height;
}
-IDXGIFactory4 *
-dxgi_get_factory(bool debug)
-{
- static const GUID IID_IDXGIFactory4 = {
- 0x1bc6ea02, 0xef36, 0x464f,
- { 0xbf, 0x0c, 0x21, 0xca, 0x39, 0xe5, 0x16, 0x8a }
- };
-
- HMODULE dxgi_mod = LoadLibraryA("DXGI.DLL");
- if (!dxgi_mod) {
- mesa_loge("failed to load DXGI.DLL\n");
- return NULL;
- }
-
- typedef HRESULT(WINAPI *PFN_CREATE_DXGI_FACTORY2)(UINT flags, REFIID riid, void **ppFactory);
- PFN_CREATE_DXGI_FACTORY2 CreateDXGIFactory2;
-
- CreateDXGIFactory2 = (PFN_CREATE_DXGI_FACTORY2)GetProcAddress(dxgi_mod, "CreateDXGIFactory2");
- if (!CreateDXGIFactory2) {
- mesa_loge("failed to load CreateDXGIFactory2 from DXGI.DLL\n");
- return NULL;
- }
-
- UINT flags = 0;
- if (debug)
- flags |= DXGI_CREATE_FACTORY_DEBUG;
-
- IDXGIFactory4 *factory;
- HRESULT hr = CreateDXGIFactory2(flags, &IID_IDXGIFactory4, (void **)&factory);
- if (FAILED(hr)) {
- mesa_loge("CreateDXGIFactory2 failed: %08x\n", (int32_t)hr);
- return NULL;
- }
-
- return factory;
-}
-
static ID3D12Debug *
get_debug_interface()
{
if with_platform_windows
dzn_flags += '-DVK_USE_PLATFORM_WIN32_KHR'
+ libdzn_files += files('dzn_dxgi.c')
endif
if cc.get_argument_syntax() != 'msvc'