Signed-off-by: Zhiyi Zhang zzhang@codeweavers.com --- dlls/d3d12/tests/d3d12.c | 2 +- dlls/dxgi/tests/dxgi.c | 4 +-- dlls/wined3d/directx.c | 54 ++++++++++++++++++++++++++++++++++------ 3 files changed, 49 insertions(+), 11 deletions(-)
diff --git a/dlls/d3d12/tests/d3d12.c b/dlls/d3d12/tests/d3d12.c index 0200047fd17..8c57f07357c 100644 --- a/dlls/d3d12/tests/d3d12.c +++ b/dlls/d3d12/tests/d3d12.c @@ -139,7 +139,7 @@ static void print_adapter_info(void) hr = CreateDXGIFactory2(0, &IID_IDXGIFactory4, (void **)&factory); ok(hr == S_OK, "Failed to create factory, hr %#x.\n", hr); hr = IDXGIFactory4_EnumAdapterByLuid(factory, luid, &IID_IDXGIAdapter, (void **)&adapter); - todo_wine ok(hr == S_OK, "Failed to enum adapter by LUID, hr %#x.\n", hr); + ok(hr == S_OK, "Failed to enum adapter by LUID, hr %#x.\n", hr); IDXGIFactory4_Release(factory);
if (FAILED(hr)) diff --git a/dlls/dxgi/tests/dxgi.c b/dlls/dxgi/tests/dxgi.c index 8f52e1d9e72..d50c4f14566 100644 --- a/dlls/dxgi/tests/dxgi.c +++ b/dlls/dxgi/tests/dxgi.c @@ -958,7 +958,7 @@ static void test_adapter_luid(void) ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
/* Older versions of WARP aren't enumerated by IDXGIFactory_EnumAdapters(). */ - todo_wine ok(found_adapter_count == 1 || broken(is_null_luid_adapter), + ok(found_adapter_count == 1 || broken(is_null_luid_adapter), "Found %u adapters for LUID %08x:%08x.\n", found_adapter_count, device_adapter_desc.AdapterLuid.HighPart, device_adapter_desc.AdapterLuid.LowPart); @@ -981,7 +981,7 @@ static void test_adapter_luid(void)
hr = IDXGIFactory4_EnumAdapterByLuid(factory4, device_adapter_desc.AdapterLuid, &IID_IDXGIAdapter, (void **)&adapter); - todo_wine ok(hr == S_OK, "Failed to enum adapter by LUID, hr %#x.\n", hr); + ok(hr == S_OK, "Failed to enum adapter by LUID, hr %#x.\n", hr); if (SUCCEEDED(hr)) { hr = IDXGIAdapter_GetDesc(adapter, &desc); diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c index 456cb9ad124..e77283832ca 100644 --- a/dlls/wined3d/directx.c +++ b/dlls/wined3d/directx.c @@ -2942,6 +2942,41 @@ static struct wined3d_adapter *wined3d_adapter_no3d_create(unsigned int ordinal, return adapter; }
+static BOOL get_primary_display(WCHAR *display) +{ + DISPLAY_DEVICEW display_device; + DWORD device_idx = 0; + + display_device.cb = sizeof(display_device); + while (EnumDisplayDevicesW(NULL, device_idx++, &display_device, 0)) + { + if (display_device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) + { + lstrcpyW(display, display_device.DeviceName); + return TRUE; + } + } + + return FALSE; +} + +static BOOL wined3d_adapter_init_luid(struct wined3d_adapter *adapter) +{ + D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME open_adapter_param; + D3DKMT_CLOSEADAPTER close_adapter_param; + + if (!get_primary_display(open_adapter_param.DeviceName)) + return FALSE; + + if (D3DKMTOpenAdapterFromGdiDisplayName(&open_adapter_param)) + return FALSE; + + adapter->luid = open_adapter_param.AdapterLuid; + close_adapter_param.hAdapter = open_adapter_param.hAdapter; + D3DKMTCloseAdapter(&close_adapter_param); + return TRUE; +} + BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, const struct wined3d_adapter_ops *adapter_ops) { @@ -2953,6 +2988,17 @@ BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, adapter->ordinal = ordinal; adapter->output_count = 0;
+ if (!wined3d_adapter_init_luid(adapter)) + { + WARN("Allocating a random LUID.\n"); + if (!AllocateLocallyUniqueId(&adapter->luid)) + { + ERR("Failed to allocate a LUID, error %#x.\n", GetLastError()); + return FALSE; + } + } + TRACE("adapter %p LUID %08x:%08x.\n", adapter, adapter->luid.HighPart, adapter->luid.LowPart); + display_device.cb = sizeof(display_device); EnumDisplayDevicesW(NULL, ordinal, &display_device, 0); TRACE("Display device: %s.\n", debugstr_w(display_device.DeviceName)); @@ -2972,14 +3018,6 @@ BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, } adapter->output_count = 1;
- if (!AllocateLocallyUniqueId(&adapter->luid)) - { - ERR("Failed to set adapter LUID (%#x).\n", GetLastError()); - goto done; - } - TRACE("Allocated LUID %08x:%08x for adapter %p.\n", - adapter->luid.HighPart, adapter->luid.LowPart, adapter); - memset(&adapter->driver_uuid, 0, sizeof(adapter->driver_uuid)); memset(&adapter->device_uuid, 0, sizeof(adapter->device_uuid));