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
);
40 hr
== DXGI_ERROR_NOT_FOUND
, /* Some VMware and VirtualBox */
41 "EnumAdapters failed, hr %#x\n", hr
);
42 if (FAILED(hr
)) goto cleanup
;
44 hr
= DXGID3D10CreateDevice(d3d10core
, factory
, adapter
, 0, NULL
, (void **)&device
);
49 trace("Failed to create a HW device, trying REF\n");
50 IDXGIAdapter_Release(adapter
);
53 d3d10ref
= LoadLibraryA("d3d10ref.dll");
56 trace("d3d10ref.dll not available, unable to create a REF device\n");
60 hr
= IDXGIFactory_CreateSoftwareAdapter(factory
, d3d10ref
, &adapter
);
61 FreeLibrary(d3d10ref
);
62 ok(SUCCEEDED(hr
), "CreateSoftwareAdapter failed, hr %#x\n", hr
);
63 if (FAILED(hr
)) goto cleanup
;
65 hr
= DXGID3D10CreateDevice(d3d10core
, factory
, adapter
, 0, NULL
, (void **)&device
);
66 ok(SUCCEEDED(hr
), "Failed to create a REF device, hr %#x\n", hr
);
67 if (FAILED(hr
)) goto cleanup
;
70 hr
= IUnknown_QueryInterface(device
, &IID_IDXGIDevice
, (void **)&dxgi_device
);
71 ok(SUCCEEDED(hr
), "Created device does not implement IDXGIDevice\n");
72 IUnknown_Release(device
);
75 if (adapter
) IDXGIAdapter_Release(adapter
);
76 if (factory
) IDXGIFactory_Release(factory
);
81 static void test_device_interfaces(IDXGIDevice
*device
)
86 if (SUCCEEDED(hr
= IDXGIDevice_QueryInterface(device
, &IID_IUnknown
, (void **)&obj
)))
87 IUnknown_Release(obj
);
88 ok(SUCCEEDED(hr
), "IDXGIDevice does not implement IUnknown\n");
90 if (SUCCEEDED(hr
= IDXGIDevice_QueryInterface(device
, &IID_IDXGIObject
, (void **)&obj
)))
91 IUnknown_Release(obj
);
92 ok(SUCCEEDED(hr
), "IDXGIDevice does not implement IDXGIObject\n");
94 if (SUCCEEDED(hr
= IDXGIDevice_QueryInterface(device
, &IID_IDXGIDevice
, (void **)&obj
)))
95 IUnknown_Release(obj
);
96 ok(SUCCEEDED(hr
), "IDXGIDevice does not implement IDXGIDevice\n");
98 if (SUCCEEDED(hr
= IDXGIDevice_QueryInterface(device
, &IID_ID3D10Device
, (void **)&obj
)))
99 IUnknown_Release(obj
);
100 ok(SUCCEEDED(hr
), "IDXGIDevice does not implement ID3D10Device\n");
103 static void test_adapter_desc(IDXGIDevice
*device
)
105 DXGI_ADAPTER_DESC desc
;
106 IDXGIAdapter
*adapter
;
109 hr
= IDXGIDevice_GetAdapter(device
, &adapter
);
110 ok(SUCCEEDED(hr
), "GetAdapter failed, hr %#x.\n", hr
);
112 hr
= IDXGIAdapter_GetDesc(adapter
, NULL
);
113 ok(hr
== E_INVALIDARG
, "GetDesc returned %#x, expected %#x.\n",
116 hr
= IDXGIAdapter_GetDesc(adapter
, &desc
);
117 ok(SUCCEEDED(hr
), "GetDesc failed, hr %#x.\n", hr
);
119 trace("%s.\n", wine_dbgstr_w(desc
.Description
));
120 trace("%04x: %04x:%04x (rev %02x).\n",
121 desc
.SubSysId
, desc
.VendorId
, desc
.DeviceId
, desc
.Revision
);
122 trace("Dedicated video memory: %lu (%lu MB).\n",
123 desc
.DedicatedVideoMemory
, desc
.DedicatedVideoMemory
/ (1024 * 1024));
124 trace("Dedicated system memory: %lu (%lu MB).\n",
125 desc
.DedicatedSystemMemory
, desc
.DedicatedSystemMemory
/ (1024 * 1024));
126 trace("Shared system memory: %lu (%lu MB).\n",
127 desc
.SharedSystemMemory
, desc
.SharedSystemMemory
/ (1024 * 1024));
128 trace("LUID: %08x:%08x.\n", desc
.AdapterLuid
.HighPart
, desc
.AdapterLuid
.LowPart
);
130 IDXGIAdapter_Release(adapter
);
133 static void test_create_surface(IDXGIDevice
*device
)
135 ID3D10Texture2D
*texture
;
136 IDXGISurface
*surface
;
137 DXGI_SURFACE_DESC desc
;
142 desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
143 desc
.SampleDesc
.Count
= 1;
144 desc
.SampleDesc
.Quality
= 0;
146 hr
= IDXGIDevice_CreateSurface(device
, &desc
, 1, DXGI_USAGE_RENDER_TARGET_OUTPUT
, NULL
, &surface
);
147 ok(SUCCEEDED(hr
), "Failed to create a dxgi surface, hr %#x\n", hr
);
149 hr
= IDXGISurface_QueryInterface(surface
, &IID_ID3D10Texture2D
, (void **)&texture
);
150 ok(SUCCEEDED(hr
), "Surface should implement ID3D10Texture2D\n");
151 if (SUCCEEDED(hr
)) ID3D10Texture2D_Release(texture
);
153 IDXGISurface_Release(surface
);
156 static void test_parents(IDXGIDevice
*device
)
158 DXGI_SURFACE_DESC surface_desc
;
159 IDXGISurface
*surface
;
160 IDXGIFactory
*factory
;
161 IDXGIAdapter
*adapter
;
166 surface_desc
.Width
= 512;
167 surface_desc
.Height
= 512;
168 surface_desc
.Format
= DXGI_FORMAT_R8G8B8A8_UNORM
;
169 surface_desc
.SampleDesc
.Count
= 1;
170 surface_desc
.SampleDesc
.Quality
= 0;
172 hr
= IDXGIDevice_CreateSurface(device
, &surface_desc
, 1, DXGI_USAGE_RENDER_TARGET_OUTPUT
, NULL
, &surface
);
173 ok(SUCCEEDED(hr
), "Failed to create a dxgi surface, hr %#x\n", hr
);
175 hr
= IDXGISurface_GetParent(surface
, &IID_IDXGIDevice
, (void **)&parent
);
176 IDXGISurface_Release(surface
);
177 ok(SUCCEEDED(hr
), "GetParent failed, hr %#x.\n", hr
);
178 ok(parent
== (IUnknown
*)device
, "Got parent %p, expected %p.\n", parent
, device
);
179 IUnknown_Release(parent
);
181 hr
= IDXGIDevice_GetAdapter(device
, &adapter
);
182 ok(SUCCEEDED(hr
), "GetAdapter failed, hr %#x.\n", hr
);
184 hr
= IDXGIAdapter_EnumOutputs(adapter
, 0, &output
);
185 if (hr
== DXGI_ERROR_NOT_FOUND
)
187 skip("Adapter has not outputs, skipping output tests.\n");
191 ok(SUCCEEDED(hr
), "EnumOutputs failed, hr %#x.\n", hr
);
193 hr
= IDXGIOutput_GetParent(output
, &IID_IDXGIAdapter
, (void **)&parent
);
194 IDXGIOutput_Release(output
);
195 ok(SUCCEEDED(hr
), "GetParent failed, hr %#x.\n", hr
);
196 ok(parent
== (IUnknown
*)adapter
, "Got parent %p, expected %p.\n", parent
, adapter
);
197 IUnknown_Release(parent
);
200 hr
= IDXGIAdapter_GetParent(adapter
, &IID_IDXGIFactory
, (void **)&factory
);
201 ok(SUCCEEDED(hr
), "GetParent failed, hr %#x.\n", hr
);
203 hr
= IDXGIFactory_GetParent(factory
, &IID_IUnknown
, (void **)&parent
);
204 ok(hr
== E_NOINTERFACE
, "GetParent returned %#x, expected %#x.\n", hr
, E_NOINTERFACE
);
205 ok(parent
== NULL
, "Got parent %p, expected %p.\n", parent
, NULL
);
206 IDXGIFactory_Release(factory
);
208 hr
= IDXGIDevice_GetParent(device
, &IID_IDXGIAdapter
, (void **)&parent
);
209 ok(SUCCEEDED(hr
), "GetParent failed, hr %#x.\n", hr
);
210 ok(parent
== (IUnknown
*)adapter
, "Got parent %p, expected %p.\n", parent
, adapter
);
211 IUnknown_Release(parent
);
213 IDXGIAdapter_Release(adapter
);
218 HMODULE d3d10core
= LoadLibraryA("d3d10core.dll");
224 win_skip("d3d10core.dll not available, skipping tests\n");
228 device
= create_device(d3d10core
);
231 skip("Failed to create device, skipping tests\n");
232 FreeLibrary(d3d10core
);
236 test_adapter_desc(device
);
237 test_device_interfaces(device
);
238 test_create_surface(device
);
239 test_parents(device
);
241 refcount
= IDXGIDevice_Release(device
);
242 ok(!refcount
, "Device has %u references left\n", refcount
);
243 FreeLibrary(d3d10core
);