2 * Copyright 2008 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/test.h"
24 HRESULT WINAPI DXGID3D10CreateDevice(HMODULE d3d10core, IDXGIFactory *factory,
25 IDXGIAdapter *adapter, UINT flags, void *unknown0, void **device);
27 static IDXGIDevice *create_device(HMODULE d3d10core)
29 IDXGIDevice *dxgi_device = NULL;
30 IDXGIFactory *factory = NULL;
31 IDXGIAdapter *adapter = NULL;
32 IUnknown *device = NULL;
35 hr = CreateDXGIFactory(&IID_IDXGIFactory, (void *)&factory);
36 if (FAILED(hr)) goto cleanup;
38 hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
41 hr = DXGID3D10CreateDevice(d3d10core, factory, adapter, 0, NULL, (void **)&device);
48 trace("Failed to create a HW device, trying REF\n");
49 if (adapter) IDXGIAdapter_Release(adapter);
52 d3d10ref = LoadLibraryA("d3d10ref.dll");
55 trace("d3d10ref.dll not available, unable to create a REF device\n");
59 hr = IDXGIFactory_CreateSoftwareAdapter(factory, d3d10ref, &adapter);
60 FreeLibrary(d3d10ref);
61 ok(SUCCEEDED(hr), "CreateSoftwareAdapter failed, hr %#x\n", hr);
62 if (FAILED(hr)) goto cleanup;
64 hr = DXGID3D10CreateDevice(d3d10core, factory, adapter, 0, NULL, (void **)&device);
65 ok(SUCCEEDED(hr), "Failed to create a REF device, hr %#x\n", hr);
66 if (FAILED(hr)) goto cleanup;
69 hr = IUnknown_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
70 ok(SUCCEEDED(hr), "Created device does not implement IDXGIDevice\n");
71 IUnknown_Release(device);
74 if (adapter) IDXGIAdapter_Release(adapter);
75 if (factory) IDXGIFactory_Release(factory);
80 static void test_device_interfaces(IDXGIDevice *device)
85 if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_IUnknown, (void **)&obj)))
86 IUnknown_Release(obj);
87 ok(SUCCEEDED(hr), "IDXGIDevice does not implement IUnknown\n");
89 if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_IDXGIObject, (void **)&obj)))
90 IUnknown_Release(obj);
91 ok(SUCCEEDED(hr), "IDXGIDevice does not implement IDXGIObject\n");
93 if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_IDXGIDevice, (void **)&obj)))
94 IUnknown_Release(obj);
95 ok(SUCCEEDED(hr), "IDXGIDevice does not implement IDXGIDevice\n");
97 if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_ID3D10Device, (void **)&obj)))
98 IUnknown_Release(obj);
99 ok(SUCCEEDED(hr), "IDXGIDevice does not implement ID3D10Device\n");
102 static void test_adapter_desc(IDXGIDevice *device)
104 DXGI_ADAPTER_DESC desc;
105 IDXGIAdapter *adapter;
108 hr = IDXGIDevice_GetAdapter(device, &adapter);
109 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
111 hr = IDXGIAdapter_GetDesc(adapter, NULL);
112 ok(hr == E_INVALIDARG, "GetDesc returned %#x, expected %#x.\n",
115 hr = IDXGIAdapter_GetDesc(adapter, &desc);
116 ok(SUCCEEDED(hr), "GetDesc failed, hr %#x.\n", hr);
118 trace("%s.\n", wine_dbgstr_w(desc.Description));
119 trace("%04x: %04x:%04x (rev %02x).\n",
120 desc.SubSysId, desc.VendorId, desc.DeviceId, desc.Revision);
121 trace("Dedicated video memory: %lu (%lu MB).\n",
122 desc.DedicatedVideoMemory, desc.DedicatedVideoMemory / (1024 * 1024));
123 trace("Dedicated system memory: %lu (%lu MB).\n",
124 desc.DedicatedSystemMemory, desc.DedicatedSystemMemory / (1024 * 1024));
125 trace("Shared system memory: %lu (%lu MB).\n",
126 desc.SharedSystemMemory, desc.SharedSystemMemory / (1024 * 1024));
127 trace("LUID: %08x:%08x.\n", desc.AdapterLuid.HighPart, desc.AdapterLuid.LowPart);
129 IDXGIAdapter_Release(adapter);
132 static void test_create_surface(IDXGIDevice *device)
134 ID3D10Texture2D *texture;
135 IDXGISurface *surface;
136 DXGI_SURFACE_DESC desc;
141 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
142 desc.SampleDesc.Count = 1;
143 desc.SampleDesc.Quality = 0;
145 hr = IDXGIDevice_CreateSurface(device, &desc, 1, DXGI_USAGE_RENDER_TARGET_OUTPUT, NULL, &surface);
146 ok(SUCCEEDED(hr), "Failed to create a dxgi surface, hr %#x\n", hr);
148 hr = IDXGISurface_QueryInterface(surface, &IID_ID3D10Texture2D, (void **)&texture);
149 ok(SUCCEEDED(hr), "Surface should implement ID3D10Texture2D\n");
150 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(texture);
152 IDXGISurface_Release(surface);
155 static void test_parents(IDXGIDevice *device)
157 DXGI_SURFACE_DESC surface_desc;
158 IDXGISurface *surface;
159 IDXGIFactory *factory;
160 IDXGIAdapter *adapter;
165 surface_desc.Width = 512;
166 surface_desc.Height = 512;
167 surface_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
168 surface_desc.SampleDesc.Count = 1;
169 surface_desc.SampleDesc.Quality = 0;
171 hr = IDXGIDevice_CreateSurface(device, &surface_desc, 1, DXGI_USAGE_RENDER_TARGET_OUTPUT, NULL, &surface);
172 ok(SUCCEEDED(hr), "Failed to create a dxgi surface, hr %#x\n", hr);
174 hr = IDXGISurface_GetParent(surface, &IID_IDXGIDevice, (void **)&parent);
175 IDXGISurface_Release(surface);
176 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
177 ok(parent == (IUnknown *)device, "Got parent %p, expected %p.\n", parent, device);
178 IUnknown_Release(parent);
180 hr = IDXGIDevice_GetAdapter(device, &adapter);
181 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
183 hr = IDXGIAdapter_EnumOutputs(adapter, 0, &output);
184 if (hr == DXGI_ERROR_NOT_FOUND)
186 skip("Adapter has not outputs, skipping output tests.\n");
190 ok(SUCCEEDED(hr), "EnumOutputs failed, hr %#x.\n", hr);
192 hr = IDXGIOutput_GetParent(output, &IID_IDXGIAdapter, (void **)&parent);
193 IDXGIOutput_Release(output);
194 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
195 ok(parent == (IUnknown *)adapter, "Got parent %p, expected %p.\n", parent, adapter);
196 IUnknown_Release(parent);
199 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
200 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
202 hr = IDXGIFactory_GetParent(factory, &IID_IUnknown, (void **)&parent);
203 ok(hr == E_NOINTERFACE, "GetParent returned %#x, expected %#x.\n", hr, E_NOINTERFACE);
204 ok(parent == NULL, "Got parent %p, expected %p.\n", parent, NULL);
205 IDXGIFactory_Release(factory);
207 hr = IDXGIDevice_GetParent(device, &IID_IDXGIAdapter, (void **)&parent);
208 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
209 ok(parent == (IUnknown *)adapter, "Got parent %p, expected %p.\n", parent, adapter);
210 IUnknown_Release(parent);
212 IDXGIAdapter_Release(adapter);
217 HMODULE d3d10core = LoadLibraryA("d3d10core.dll");
223 win_skip("d3d10core.dll not available, skipping tests\n");
227 device = create_device(d3d10core);
230 skip("Failed to create device, skipping tests\n");
231 FreeLibrary(d3d10core);
235 test_adapter_desc(device);
236 test_device_interfaces(device);
237 test_create_surface(device);
238 test_parents(device);
240 refcount = IDXGIDevice_Release(device);
241 ok(!refcount, "Device has %u references left\n", refcount);
242 FreeLibrary(d3d10core);