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 D3D10CoreCreateDevice(IDXGIFactory *factory, IDXGIAdapter *adapter,
25 UINT flags, void *unknown0, ID3D10Device **device);
27 static ID3D10Device *create_device(void)
29 IDXGIFactory *factory = NULL;
30 IDXGIAdapter *adapter = NULL;
31 ID3D10Device *device = NULL;
34 hr = CreateDXGIFactory(&IID_IDXGIFactory, (void *)&factory);
35 if (FAILED(hr)) goto cleanup;
37 hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
39 hr == DXGI_ERROR_NOT_FOUND, /* Some VMware and VirtualBox */
40 "EnumAdapters failed, hr %#x\n", hr);
41 if (FAILED(hr)) goto cleanup;
43 hr = D3D10CoreCreateDevice(factory, adapter, 0, NULL, &device);
48 trace("Failed to create a HW device, trying REF\n");
49 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 = D3D10CoreCreateDevice(factory, adapter, 0, NULL, &device);
65 ok(SUCCEEDED(hr), "Failed to create a REF device, hr %#x\n", hr);
66 if (FAILED(hr)) goto cleanup;
70 if (adapter) IDXGIAdapter_Release(adapter);
71 if (factory) IDXGIFactory_Release(factory);
76 static void test_device_interfaces(ID3D10Device *device)
81 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_IUnknown, (void **)&obj)))
82 IUnknown_Release(obj);
83 ok(SUCCEEDED(hr), "ID3D10Device does not implement IUnknown\n");
85 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_IDXGIObject, (void **)&obj)))
86 IUnknown_Release(obj);
87 ok(SUCCEEDED(hr), "ID3D10Device does not implement IDXGIObject\n");
89 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&obj)))
90 IUnknown_Release(obj);
91 ok(SUCCEEDED(hr), "ID3D10Device does not implement IDXGIDevice\n");
93 if (SUCCEEDED(hr = ID3D10Device_QueryInterface(device, &IID_ID3D10Device, (void **)&obj)))
94 IUnknown_Release(obj);
95 ok(SUCCEEDED(hr), "ID3D10Device does not implement ID3D10Device\n");
98 static void test_create_texture2d(ID3D10Device *device)
100 D3D10_TEXTURE2D_DESC desc;
101 ID3D10Texture2D *texture;
102 IDXGISurface *surface;
109 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
110 desc.SampleDesc.Count = 1;
111 desc.SampleDesc.Quality = 0;
112 desc.Usage = D3D10_USAGE_DEFAULT;
113 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
114 desc.CPUAccessFlags = 0;
117 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
118 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
120 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
121 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface\n");
122 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
123 ID3D10Texture2D_Release(texture);
126 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
127 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
129 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
130 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
131 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
132 ID3D10Texture2D_Release(texture);
136 hr = ID3D10Device_CreateTexture2D(device, &desc, NULL, &texture);
137 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
139 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
140 ok(FAILED(hr), "Texture should not implement IDXGISurface\n");
141 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
142 ID3D10Texture2D_Release(texture);
145 static void test_create_texture3d(ID3D10Device *device)
147 D3D10_TEXTURE3D_DESC desc;
148 ID3D10Texture3D *texture;
149 IDXGISurface *surface;
156 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
157 desc.Usage = D3D10_USAGE_DEFAULT;
158 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
159 desc.CPUAccessFlags = 0;
162 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
163 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
165 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
166 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
167 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
168 ID3D10Texture3D_Release(texture);
171 hr = ID3D10Device_CreateTexture3D(device, &desc, NULL, &texture);
172 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
174 hr = ID3D10Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
175 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
176 if (SUCCEEDED(hr)) IDXGISurface_Release(surface);
177 ID3D10Texture3D_Release(texture);
180 static void test_create_rendertarget_view(ID3D10Device *device)
182 D3D10_RENDER_TARGET_VIEW_DESC rtv_desc;
183 D3D10_TEXTURE2D_DESC texture_desc;
184 D3D10_BUFFER_DESC buffer_desc;
185 ID3D10RenderTargetView *rtview;
186 ID3D10Texture2D *texture;
187 ID3D10Buffer *buffer;
190 buffer_desc.ByteWidth = 1024;
191 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
192 buffer_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
193 buffer_desc.CPUAccessFlags = 0;
194 buffer_desc.MiscFlags = 0;
196 hr = ID3D10Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
197 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr);
199 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
200 rtv_desc.ViewDimension = D3D10_RTV_DIMENSION_BUFFER;
201 U(rtv_desc).Buffer.ElementOffset = 0;
202 U(rtv_desc).Buffer.ElementWidth = 64;
204 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)buffer, &rtv_desc, &rtview);
205 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
207 ID3D10RenderTargetView_Release(rtview);
208 ID3D10Buffer_Release(buffer);
210 texture_desc.Width = 512;
211 texture_desc.Height = 512;
212 texture_desc.MipLevels = 1;
213 texture_desc.ArraySize = 1;
214 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
215 texture_desc.SampleDesc.Count = 1;
216 texture_desc.SampleDesc.Quality = 0;
217 texture_desc.Usage = D3D10_USAGE_DEFAULT;
218 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET;
219 texture_desc.CPUAccessFlags = 0;
220 texture_desc.MiscFlags = 0;
222 hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
223 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
225 /* For texture resources it's allowed to specify NULL as desc */
226 hr = ID3D10Device_CreateRenderTargetView(device, (ID3D10Resource *)texture, NULL, &rtview);
227 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x\n", hr);
229 ID3D10RenderTargetView_GetDesc(rtview, &rtv_desc);
230 ok(rtv_desc.Format == texture_desc.Format, "Expected format %#x, got %#x\n", texture_desc.Format, rtv_desc.Format);
231 ok(rtv_desc.ViewDimension == D3D10_RTV_DIMENSION_TEXTURE2D,
232 "Expected view dimension D3D10_RTV_DIMENSION_TEXTURE2D, got %#x\n", rtv_desc.ViewDimension);
233 ok(U(rtv_desc).Texture2D.MipSlice == 0, "Expected mip slice 0, got %#x\n", U(rtv_desc).Texture2D.MipSlice);
235 ID3D10RenderTargetView_Release(rtview);
236 ID3D10Texture2D_Release(texture);
241 ID3D10Device *device;
244 device = create_device();
247 skip("Failed to create device, skipping tests\n");
251 test_device_interfaces(device);
252 test_create_texture2d(device);
253 test_create_texture3d(device);
254 test_create_rendertarget_view(device);
256 refcount = ID3D10Device_Release(device);
257 ok(!refcount, "Device has %u references left\n", refcount);