1 /*
2 * Copyright © Microsoft Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "dzn_physical_device_enum.h"
25 #include <directx/dxcore.h>
26 #include <dxguids/dxguids.h>
27
28 #include "u_dl.h"
29 #include "log.h"
30
31 VkResult
dzn_enumerate_physical_devices_dxcore(struct dzn_instance * instance)32 dzn_enumerate_physical_devices_dxcore(struct dzn_instance *instance)
33 {
34 util_dl_library *dxcore = util_dl_open(UTIL_DL_PREFIX "dxcore" UTIL_DL_EXT);
35 if (!dxcore) {
36 mesa_loge("Failed to load DXCore\n");
37 return VK_ERROR_INITIALIZATION_FAILED;
38 }
39
40 using PFNDXCoreCreateAdapterFactory = HRESULT (APIENTRY*)(REFIID, void **);
41 PFNDXCoreCreateAdapterFactory create_func = (PFNDXCoreCreateAdapterFactory)util_dl_get_proc_address(dxcore, "DXCoreCreateAdapterFactory");
42 if (!create_func) {
43 mesa_loge("Failed to load DXCoreCreateAdapterFactory\n");
44 return VK_ERROR_INITIALIZATION_FAILED;
45 }
46
47 IDXCoreAdapterFactory *factory;
48 if (FAILED(create_func(IID_PPV_ARGS(&factory)))) {
49 mesa_loge("Failed to create DXCore adapter factory\n");
50 return VK_ERROR_INITIALIZATION_FAILED;
51 }
52
53 IDXCoreAdapterList *list;
54 if (FAILED(factory->CreateAdapterList(1, &DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS, IID_PPV_ARGS(&list)))) {
55 factory->Release();
56 mesa_loge("Failed to create DXCore adapter list\n");
57 return VK_ERROR_INITIALIZATION_FAILED;
58 }
59
60 VkResult result = VK_SUCCESS;
61 uint32_t adapter_count = list->GetAdapterCount();
62 IDXCoreAdapter *adapter;
63 for (uint32_t i = 0; i < adapter_count && result == VK_SUCCESS; ++i) {
64 result = VK_ERROR_INITIALIZATION_FAILED;
65 if (SUCCEEDED(list->GetAdapter(i, IID_PPV_ARGS(&adapter)))) {
66 dzn_physical_device_desc desc = { 0 };
67 DXCoreHardwareID hardware_id;
68 bool is_hardware;
69 if (FAILED(adapter->GetProperty(DXCoreAdapterProperty::HardwareID, &hardware_id)) ||
70 FAILED(adapter->GetProperty(DXCoreAdapterProperty::DedicatedAdapterMemory, &desc.dedicated_video_memory)) ||
71 FAILED(adapter->GetProperty(DXCoreAdapterProperty::SharedSystemMemory, &desc.shared_system_memory)) ||
72 FAILED(adapter->GetProperty(DXCoreAdapterProperty::DedicatedSystemMemory, &desc.dedicated_system_memory)) ||
73 FAILED(adapter->GetProperty(DXCoreAdapterProperty::InstanceLuid, &desc.adapter_luid)) ||
74 FAILED(adapter->GetProperty(DXCoreAdapterProperty::IsHardware, &is_hardware)) ||
75 FAILED(adapter->GetProperty(DXCoreAdapterProperty::DriverDescription, sizeof(desc.description), desc.description))) {
76 mesa_loge("Failed to retrieve DXCore adapter properties\n");
77 result = VK_ERROR_INITIALIZATION_FAILED;
78 } else {
79 desc.vendor_id = hardware_id.vendorID;
80 desc.device_id = hardware_id.deviceID;
81 desc.subsys_id = hardware_id.subSysID;
82 desc.revision = hardware_id.revision;
83 desc.is_warp = !is_hardware;
84 result = dzn_instance_add_physical_device(instance, adapter, &desc);
85 }
86
87 adapter->Release();
88 }
89 }
90
91 list->Release();
92 factory->Release();
93 return result;
94 }
95
96