Commit 122a28a3 authored by Zhiyi Zhang's avatar Zhiyi Zhang Committed by Alexandre Julliard

wined3d: Use valid adapter LUIDs if they are available.

parent 597433ab
...@@ -139,7 +139,7 @@ static void print_adapter_info(void) ...@@ -139,7 +139,7 @@ static void print_adapter_info(void)
hr = CreateDXGIFactory2(0, &IID_IDXGIFactory4, (void **)&factory); hr = CreateDXGIFactory2(0, &IID_IDXGIFactory4, (void **)&factory);
ok(hr == S_OK, "Failed to create factory, hr %#x.\n", hr); ok(hr == S_OK, "Failed to create factory, hr %#x.\n", hr);
hr = IDXGIFactory4_EnumAdapterByLuid(factory, luid, &IID_IDXGIAdapter, (void **)&adapter); 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); IDXGIFactory4_Release(factory);
if (FAILED(hr)) if (FAILED(hr))
......
...@@ -973,7 +973,7 @@ static void test_adapter_luid(void) ...@@ -973,7 +973,7 @@ static void test_adapter_luid(void)
ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr); ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
/* Older versions of WARP aren't enumerated by IDXGIFactory_EnumAdapters(). */ /* 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 %u adapters for LUID %08x:%08x.\n",
found_adapter_count, device_adapter_desc.AdapterLuid.HighPart, found_adapter_count, device_adapter_desc.AdapterLuid.HighPart,
device_adapter_desc.AdapterLuid.LowPart); device_adapter_desc.AdapterLuid.LowPart);
...@@ -996,7 +996,7 @@ static void test_adapter_luid(void) ...@@ -996,7 +996,7 @@ static void test_adapter_luid(void)
hr = IDXGIFactory4_EnumAdapterByLuid(factory4, device_adapter_desc.AdapterLuid, hr = IDXGIFactory4_EnumAdapterByLuid(factory4, device_adapter_desc.AdapterLuid,
&IID_IDXGIAdapter, (void **)&adapter); &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)) if (SUCCEEDED(hr))
{ {
hr = IDXGIAdapter_GetDesc(adapter, &desc); hr = IDXGIAdapter_GetDesc(adapter, &desc);
......
...@@ -5136,12 +5136,16 @@ static BOOL wined3d_adapter_gl_init(struct wined3d_adapter_gl *adapter_gl, ...@@ -5136,12 +5136,16 @@ static BOOL wined3d_adapter_gl_init(struct wined3d_adapter_gl *adapter_gl,
}; };
struct wined3d_gl_info *gl_info = &adapter_gl->a.gl_info; struct wined3d_gl_info *gl_info = &adapter_gl->a.gl_info;
struct wined3d_caps_gl_ctx caps_gl_ctx = {0}; struct wined3d_caps_gl_ctx caps_gl_ctx = {0};
LUID primary_luid, *luid = NULL;
unsigned int i; unsigned int i;
TRACE("adapter_gl %p, ordinal %u, wined3d_creation_flags %#x.\n", TRACE("adapter_gl %p, ordinal %u, wined3d_creation_flags %#x.\n",
adapter_gl, ordinal, wined3d_creation_flags); adapter_gl, ordinal, wined3d_creation_flags);
if (!wined3d_adapter_init(&adapter_gl->a, ordinal, &wined3d_adapter_gl_ops)) if (ordinal == 0 && wined3d_get_primary_adapter_luid(&primary_luid))
luid = &primary_luid;
if (!wined3d_adapter_init(&adapter_gl->a, ordinal, luid, &wined3d_adapter_gl_ops))
return FALSE; return FALSE;
/* Dynamically load all GL core functions */ /* Dynamically load all GL core functions */
......
...@@ -2166,17 +2166,15 @@ static BOOL wined3d_adapter_vk_init(struct wined3d_adapter_vk *adapter_vk, ...@@ -2166,17 +2166,15 @@ static BOOL wined3d_adapter_vk_init(struct wined3d_adapter_vk *adapter_vk,
struct wined3d_adapter *adapter = &adapter_vk->a; struct wined3d_adapter *adapter = &adapter_vk->a;
VkPhysicalDeviceIDProperties id_properties; VkPhysicalDeviceIDProperties id_properties;
VkPhysicalDeviceProperties2 properties2; VkPhysicalDeviceProperties2 properties2;
LUID *luid = NULL;
TRACE("adapter_vk %p, ordinal %u, wined3d_creation_flags %#x.\n", TRACE("adapter_vk %p, ordinal %u, wined3d_creation_flags %#x.\n",
adapter_vk, ordinal, wined3d_creation_flags); adapter_vk, ordinal, wined3d_creation_flags);
if (!wined3d_adapter_init(adapter, ordinal, &wined3d_adapter_vk_ops))
return FALSE;
if (!wined3d_init_vulkan(vk_info)) if (!wined3d_init_vulkan(vk_info))
{ {
WARN("Failed to initialize Vulkan.\n"); WARN("Failed to initialize Vulkan.\n");
goto fail; return FALSE;
} }
if (!(adapter_vk->physical_device = get_vulkan_physical_device(vk_info))) if (!(adapter_vk->physical_device = get_vulkan_physical_device(vk_info)))
...@@ -2195,6 +2193,12 @@ static BOOL wined3d_adapter_vk_init(struct wined3d_adapter_vk *adapter_vk, ...@@ -2195,6 +2193,12 @@ static BOOL wined3d_adapter_vk_init(struct wined3d_adapter_vk *adapter_vk,
VK_CALL(vkGetPhysicalDeviceMemoryProperties(adapter_vk->physical_device, &adapter_vk->memory_properties)); VK_CALL(vkGetPhysicalDeviceMemoryProperties(adapter_vk->physical_device, &adapter_vk->memory_properties));
if (id_properties.deviceLUIDValid)
luid = (LUID *)id_properties.deviceLUID;
if (!wined3d_adapter_init(adapter, ordinal, luid, &wined3d_adapter_vk_ops))
goto fail_vulkan;
adapter_vk_init_driver_info(adapter_vk, &properties2.properties); adapter_vk_init_driver_info(adapter_vk, &properties2.properties);
adapter->vram_bytes_used = 0; adapter->vram_bytes_used = 0;
TRACE("Emulating 0x%s bytes of video ram.\n", wine_dbgstr_longlong(adapter->driver_info.vram_bytes)); TRACE("Emulating 0x%s bytes of video ram.\n", wine_dbgstr_longlong(adapter->driver_info.vram_bytes));
...@@ -2203,7 +2207,7 @@ static BOOL wined3d_adapter_vk_init(struct wined3d_adapter_vk *adapter_vk, ...@@ -2203,7 +2207,7 @@ static BOOL wined3d_adapter_vk_init(struct wined3d_adapter_vk *adapter_vk,
memcpy(&adapter->device_uuid, id_properties.deviceUUID, sizeof(adapter->device_uuid)); memcpy(&adapter->device_uuid, id_properties.deviceUUID, sizeof(adapter->device_uuid));
if (!wined3d_adapter_vk_init_format_info(adapter_vk, vk_info)) if (!wined3d_adapter_vk_init_format_info(adapter_vk, vk_info))
goto fail_vulkan; goto fail;
adapter->vertex_pipe = wined3d_spirv_vertex_pipe_init_vk(); adapter->vertex_pipe = wined3d_spirv_vertex_pipe_init_vk();
adapter->fragment_pipe = wined3d_spirv_fragment_pipe_init_vk(); adapter->fragment_pipe = wined3d_spirv_fragment_pipe_init_vk();
...@@ -2214,11 +2218,11 @@ static BOOL wined3d_adapter_vk_init(struct wined3d_adapter_vk *adapter_vk, ...@@ -2214,11 +2218,11 @@ static BOOL wined3d_adapter_vk_init(struct wined3d_adapter_vk *adapter_vk,
return TRUE; return TRUE;
fail:
wined3d_adapter_cleanup(adapter);
fail_vulkan: fail_vulkan:
VK_CALL(vkDestroyInstance(vk_info->instance, NULL)); VK_CALL(vkDestroyInstance(vk_info->instance, NULL));
wined3d_unload_vulkan(vk_info); wined3d_unload_vulkan(vk_info);
fail:
wined3d_adapter_cleanup(adapter);
return FALSE; return FALSE;
} }
......
...@@ -2903,6 +2903,7 @@ static void wined3d_adapter_no3d_init_d3d_info(struct wined3d_adapter *adapter, ...@@ -2903,6 +2903,7 @@ static void wined3d_adapter_no3d_init_d3d_info(struct wined3d_adapter *adapter,
static struct wined3d_adapter *wined3d_adapter_no3d_create(unsigned int ordinal, unsigned int wined3d_creation_flags) static struct wined3d_adapter *wined3d_adapter_no3d_create(unsigned int ordinal, unsigned int wined3d_creation_flags)
{ {
struct wined3d_adapter *adapter; struct wined3d_adapter *adapter;
LUID primary_luid, *luid = NULL;
static const struct wined3d_gpu_description gpu_description = static const struct wined3d_gpu_description gpu_description =
{ {
...@@ -2914,7 +2915,10 @@ static struct wined3d_adapter *wined3d_adapter_no3d_create(unsigned int ordinal, ...@@ -2914,7 +2915,10 @@ static struct wined3d_adapter *wined3d_adapter_no3d_create(unsigned int ordinal,
if (!(adapter = heap_alloc_zero(sizeof(*adapter)))) if (!(adapter = heap_alloc_zero(sizeof(*adapter))))
return NULL; return NULL;
if (!wined3d_adapter_init(adapter, ordinal, &wined3d_adapter_no3d_ops)) if (ordinal == 0 && wined3d_get_primary_adapter_luid(&primary_luid))
luid = &primary_luid;
if (!wined3d_adapter_init(adapter, ordinal, luid, &wined3d_adapter_no3d_ops))
{ {
heap_free(adapter); heap_free(adapter);
return NULL; return NULL;
...@@ -2942,7 +2946,7 @@ static struct wined3d_adapter *wined3d_adapter_no3d_create(unsigned int ordinal, ...@@ -2942,7 +2946,7 @@ static struct wined3d_adapter *wined3d_adapter_no3d_create(unsigned int ordinal,
return adapter; return adapter;
} }
BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, const LUID *luid,
const struct wined3d_adapter_ops *adapter_ops) const struct wined3d_adapter_ops *adapter_ops)
{ {
DISPLAY_DEVICEW display_device; DISPLAY_DEVICEW display_device;
...@@ -2953,6 +2957,21 @@ BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, ...@@ -2953,6 +2957,21 @@ BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal,
adapter->ordinal = ordinal; adapter->ordinal = ordinal;
adapter->output_count = 0; adapter->output_count = 0;
if (luid)
{
adapter->luid = *luid;
}
else
{
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); display_device.cb = sizeof(display_device);
EnumDisplayDevicesW(NULL, ordinal, &display_device, 0); EnumDisplayDevicesW(NULL, ordinal, &display_device, 0);
TRACE("Display device: %s.\n", debugstr_w(display_device.DeviceName)); TRACE("Display device: %s.\n", debugstr_w(display_device.DeviceName));
...@@ -2972,14 +2991,6 @@ BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, ...@@ -2972,14 +2991,6 @@ BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal,
} }
adapter->output_count = 1; 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->driver_uuid, 0, sizeof(adapter->driver_uuid));
memset(&adapter->device_uuid, 0, sizeof(adapter->device_uuid)); memset(&adapter->device_uuid, 0, sizeof(adapter->device_uuid));
......
...@@ -5719,6 +5719,41 @@ void get_fog_start_end(const struct wined3d_context *context, const struct wined ...@@ -5719,6 +5719,41 @@ void get_fog_start_end(const struct wined3d_context *context, const struct wined
} }
} }
static BOOL wined3d_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;
}
BOOL wined3d_get_primary_adapter_luid(LUID *luid)
{
D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME open_adapter_param;
D3DKMT_CLOSEADAPTER close_adapter_param;
if (!wined3d_get_primary_display(open_adapter_param.DeviceName))
return FALSE;
if (D3DKMTOpenAdapterFromGdiDisplayName(&open_adapter_param))
return FALSE;
*luid = open_adapter_param.AdapterLuid;
close_adapter_param.hAdapter = open_adapter_param.hAdapter;
D3DKMTCloseAdapter(&close_adapter_param);
return TRUE;
}
/* Note: It's the caller's responsibility to ensure values can be expressed /* Note: It's the caller's responsibility to ensure values can be expressed
* in the requested format. UNORM formats for example can only express values * in the requested format. UNORM formats for example can only express values
* in the range 0.0f -> 1.0f. */ * in the range 0.0f -> 1.0f. */
......
...@@ -3300,9 +3300,10 @@ struct wined3d_adapter ...@@ -3300,9 +3300,10 @@ struct wined3d_adapter
const struct wined3d_adapter_ops *adapter_ops; const struct wined3d_adapter_ops *adapter_ops;
}; };
BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, const LUID *luid,
const struct wined3d_adapter_ops *adapter_ops) DECLSPEC_HIDDEN; const struct wined3d_adapter_ops *adapter_ops) DECLSPEC_HIDDEN;
void wined3d_adapter_cleanup(struct wined3d_adapter *adapter) DECLSPEC_HIDDEN; void wined3d_adapter_cleanup(struct wined3d_adapter *adapter) DECLSPEC_HIDDEN;
BOOL wined3d_get_primary_adapter_luid(LUID *luid) DECLSPEC_HIDDEN;
struct wined3d_adapter_gl struct wined3d_adapter_gl
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment