Release 2.9.
[wine.git] / dlls / d3d10_1 / tests / d3d10_1.c
blobe1d6d4c97c287a15c8850d6feba722f316629869
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
3 * Copyright 2015 Józef Kucia for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #define COBJMACROS
21 #include "initguid.h"
22 #include "d3d11.h"
23 #include "wine/test.h"
25 static const D3D10_FEATURE_LEVEL1 d3d10_feature_levels[] =
27 D3D10_FEATURE_LEVEL_10_1,
28 D3D10_FEATURE_LEVEL_10_0,
29 D3D10_FEATURE_LEVEL_9_3,
30 D3D10_FEATURE_LEVEL_9_2,
31 D3D10_FEATURE_LEVEL_9_1
34 static ULONG get_refcount(IUnknown *iface)
36 IUnknown_AddRef(iface);
37 return IUnknown_Release(iface);
40 struct device_desc
42 D3D10_FEATURE_LEVEL1 feature_level;
43 UINT flags;
46 static ID3D10Device1 *create_device(const struct device_desc *desc)
48 D3D10_FEATURE_LEVEL1 feature_level = D3D10_FEATURE_LEVEL_10_1;
49 ID3D10Device1 *device;
50 UINT flags = 0;
52 if (desc)
54 feature_level = desc->feature_level;
55 flags = desc->flags;
58 if (SUCCEEDED(D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_HARDWARE,
59 NULL, flags, feature_level, D3D10_1_SDK_VERSION, &device)))
60 return device;
61 if (SUCCEEDED(D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_WARP,
62 NULL, flags, feature_level, D3D10_1_SDK_VERSION, &device)))
63 return device;
64 if (SUCCEEDED(D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_REFERENCE,
65 NULL, flags, feature_level, D3D10_1_SDK_VERSION, &device)))
66 return device;
68 return NULL;
71 static void test_create_device(void)
73 D3D10_FEATURE_LEVEL1 feature_level, supported_feature_level;
74 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
75 IDXGISwapChain *swapchain;
76 ID3D10Device1 *device;
77 unsigned int i;
78 ULONG refcount;
79 HWND window;
80 HRESULT hr;
82 for (i = 0; i < sizeof(d3d10_feature_levels) / sizeof(*d3d10_feature_levels); ++i)
84 if (SUCCEEDED(hr = D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
85 d3d10_feature_levels[i], D3D10_1_SDK_VERSION, &device)))
87 supported_feature_level = d3d10_feature_levels[i];
88 break;
92 if (FAILED(hr))
94 skip("Failed to create HAL device.\n");
95 return;
98 feature_level = ID3D10Device1_GetFeatureLevel(device);
99 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
100 feature_level, supported_feature_level);
102 ID3D10Device1_Release(device);
104 hr = D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
105 supported_feature_level, D3D10_1_SDK_VERSION, NULL);
106 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
108 device = (ID3D10Device1 *)0xdeadbeef;
109 hr = D3D10CreateDevice1(NULL, 0xffffffff, NULL, 0,
110 supported_feature_level, D3D10_1_SDK_VERSION, &device);
111 todo_wine ok(hr == E_INVALIDARG, "D3D10CreateDevice1 returned %#x.\n", hr);
112 ok(!device, "Got unexpected device pointer %p.\n", device);
114 device = (ID3D10Device1 *)0xdeadbeef;
115 hr = D3D10CreateDevice1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
116 0, D3D10_1_SDK_VERSION, &device);
117 ok(hr == E_INVALIDARG, "D3D10CreateDevice1 returned %#x.\n", hr);
118 ok(!device, "Got unexpected device pointer %p.\n", device);
120 window = CreateWindowA("static", "d3d10_1_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
122 swapchain_desc.BufferDesc.Width = 800;
123 swapchain_desc.BufferDesc.Height = 600;
124 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
125 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
126 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
127 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
128 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
129 swapchain_desc.SampleDesc.Count = 1;
130 swapchain_desc.SampleDesc.Quality = 0;
131 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
132 swapchain_desc.BufferCount = 1;
133 swapchain_desc.OutputWindow = window;
134 swapchain_desc.Windowed = TRUE;
135 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
136 swapchain_desc.Flags = 0;
138 hr = D3D10CreateDeviceAndSwapChain1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
139 supported_feature_level, D3D10_1_SDK_VERSION, &swapchain_desc, &swapchain, &device);
140 ok(SUCCEEDED(hr), "D3D10CreateDeviceAndSwapChain1 failed %#x.\n", hr);
142 memset(&obtained_desc, 0, sizeof(obtained_desc));
143 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
144 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
145 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
146 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
147 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
148 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
149 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
150 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
151 obtained_desc.BufferDesc.RefreshRate.Numerator);
152 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
153 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
154 obtained_desc.BufferDesc.RefreshRate.Denominator);
155 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
156 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
157 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
158 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
159 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
160 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
161 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
162 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
163 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
164 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
165 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
166 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
167 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
168 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
169 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
170 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
171 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
172 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
173 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
174 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
175 ok(obtained_desc.Flags == swapchain_desc.Flags,
176 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
178 refcount = IDXGISwapChain_Release(swapchain);
179 ok(!refcount, "Swapchain has %u references left.\n", refcount);
181 feature_level = ID3D10Device1_GetFeatureLevel(device);
182 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
183 feature_level, supported_feature_level);
185 refcount = ID3D10Device1_Release(device);
186 ok(!refcount, "Device has %u references left.\n", refcount);
188 hr = D3D10CreateDeviceAndSwapChain1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
189 supported_feature_level, D3D10_1_SDK_VERSION, NULL, NULL, &device);
190 ok(SUCCEEDED(hr), "D3D10CreateDeviceAndSwapChain1 failed %#x.\n", hr);
191 refcount = ID3D10Device1_Release(device);
192 ok(!refcount, "Device has %u references left.\n", refcount);
194 hr = D3D10CreateDeviceAndSwapChain1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
195 supported_feature_level, D3D10_1_SDK_VERSION, NULL, NULL, NULL);
196 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
198 hr = D3D10CreateDeviceAndSwapChain1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
199 supported_feature_level, D3D10_1_SDK_VERSION, &swapchain_desc, NULL, NULL);
200 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
202 swapchain = (IDXGISwapChain *)0xdeadbeef;
203 device = (ID3D10Device1 *)0xdeadbeef;
204 hr = D3D10CreateDeviceAndSwapChain1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
205 0, D3D10_1_SDK_VERSION, &swapchain_desc, &swapchain, &device);
206 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
207 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
208 ok(!device, "Got unexpected device pointer %p.\n", device);
210 swapchain = (IDXGISwapChain *)0xdeadbeef;
211 hr = D3D10CreateDeviceAndSwapChain1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
212 supported_feature_level, D3D10_1_SDK_VERSION, &swapchain_desc, &swapchain, NULL);
213 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
214 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
216 swapchain_desc.OutputWindow = NULL;
217 hr = D3D10CreateDeviceAndSwapChain1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
218 supported_feature_level, D3D10_1_SDK_VERSION, &swapchain_desc, NULL, &device);
219 ok(SUCCEEDED(hr), "D3D10CreateDeviceAndSwapChain1 failed %#x.\n", hr);
220 refcount = ID3D10Device1_Release(device);
221 ok(!refcount, "Device has %u references left.\n", refcount);
223 swapchain = (IDXGISwapChain *)0xdeadbeef;
224 device = (ID3D10Device1 *)0xdeadbeef;
225 swapchain_desc.OutputWindow = NULL;
226 hr = D3D10CreateDeviceAndSwapChain1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
227 supported_feature_level, D3D10_1_SDK_VERSION, &swapchain_desc, &swapchain, &device);
228 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D10CreateDeviceAndSwapChain1 returned %#x.\n", hr);
229 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
230 ok(!device, "Got unexpected device pointer %p.\n", device);
232 swapchain = (IDXGISwapChain *)0xdeadbeef;
233 device = (ID3D10Device1 *)0xdeadbeef;
234 swapchain_desc.OutputWindow = window;
235 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
236 hr = D3D10CreateDeviceAndSwapChain1(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0,
237 supported_feature_level, D3D10_1_SDK_VERSION, &swapchain_desc, &swapchain, &device);
238 ok(hr == E_INVALIDARG, "D3D10CreateDeviceAndSwapChain1 returned %#x.\n", hr);
239 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
240 ok(!device, "Got unexpected device pointer %p.\n", device);
242 DestroyWindow(window);
245 static void test_device_interfaces(void)
247 IDXGIAdapter *dxgi_adapter;
248 IDXGIDevice *dxgi_device;
249 ID3D10Device1 *device;
250 IUnknown *iface;
251 ULONG refcount;
252 unsigned int i;
253 HRESULT hr;
255 for (i = 0; i < sizeof(d3d10_feature_levels) / sizeof(*d3d10_feature_levels); ++i)
257 struct device_desc device_desc;
259 device_desc.feature_level = d3d10_feature_levels[i];
260 device_desc.flags = 0;
262 if (!(device = create_device(&device_desc)))
264 skip("Failed to create device for feature level %#x.\n", d3d10_feature_levels[i]);
265 continue;
268 hr = ID3D10Device1_QueryInterface(device, &IID_IUnknown, (void **)&iface);
269 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
270 IUnknown_Release(iface);
272 hr = ID3D10Device1_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
273 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
274 IUnknown_Release(iface);
276 hr = ID3D10Device1_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
277 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
278 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
279 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
280 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
281 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
282 IUnknown_Release(iface);
283 IDXGIAdapter_Release(dxgi_adapter);
284 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
285 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
286 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
287 ok(hr == E_NOINTERFACE, "Adapter parent should not implement IDXGIFactory1.\n");
288 IDXGIAdapter_Release(dxgi_adapter);
289 IDXGIDevice_Release(dxgi_device);
291 hr = ID3D10Device1_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
292 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice1.\n");
293 IUnknown_Release(iface);
295 hr = ID3D10Device1_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
296 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
297 "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
298 if (SUCCEEDED(hr)) IUnknown_Release(iface);
300 hr = ID3D10Device1_QueryInterface(device, &IID_ID3D10InfoQueue, (void **)&iface);
301 ok(hr == E_NOINTERFACE, "Found ID3D10InfoQueue interface in non-debug mode, hr %#x.\n", hr);
303 hr = ID3D10Device1_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
304 ok(SUCCEEDED(hr), "Device should implement ID3D10Device interface, hr %#x.\n", hr);
305 IUnknown_Release(iface);
307 hr = ID3D10Device1_QueryInterface(device, &IID_ID3D11Device, (void **)&iface);
308 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
309 "Device should implement ID3D11Device interface, hr %#x.\n", hr);
310 if (SUCCEEDED(hr)) IUnknown_Release(iface);
312 refcount = ID3D10Device1_Release(device);
313 ok(!refcount, "Device has %u references left.\n", refcount);
316 for (i = 0; i < sizeof(d3d10_feature_levels) / sizeof(*d3d10_feature_levels); ++i)
318 struct device_desc device_desc;
320 device_desc.feature_level = d3d10_feature_levels[i];
321 device_desc.flags = D3D10_CREATE_DEVICE_DEBUG;
322 if (!(device = create_device(&device_desc)))
324 skip("Failed to create device for feature level %#x.\n", d3d10_feature_levels[i]);
325 continue;
328 hr = ID3D10Device1_QueryInterface(device, &IID_ID3D10InfoQueue, (void **)&iface);
329 todo_wine ok(hr == S_OK, "Device should implement ID3D10InfoQueue interface, hr %#x.\n", hr);
330 if (SUCCEEDED(hr)) IUnknown_Release(iface);
332 refcount = ID3D10Device1_Release(device);
333 ok(!refcount, "Device has %u references left.\n", refcount);
337 static void test_create_shader_resource_view(void)
339 D3D10_SHADER_RESOURCE_VIEW_DESC1 srv_desc;
340 D3D10_TEXTURE2D_DESC texture_desc;
341 ULONG refcount, expected_refcount;
342 ID3D10ShaderResourceView1 *srview;
343 D3D10_BUFFER_DESC buffer_desc;
344 ID3D10Texture2D *texture;
345 ID3D10Device *tmp_device;
346 ID3D10Device1 *device;
347 ID3D10Buffer *buffer;
348 IUnknown *iface;
349 HRESULT hr;
351 if (!(device = create_device(NULL)))
353 skip("Failed to create device.\n");
354 return;
357 buffer_desc.ByteWidth = 1024;
358 buffer_desc.Usage = D3D10_USAGE_DEFAULT;
359 buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
360 buffer_desc.CPUAccessFlags = 0;
361 buffer_desc.MiscFlags = 0;
363 hr = ID3D10Device1_CreateBuffer(device, &buffer_desc, NULL, &buffer);
364 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr);
366 hr = ID3D10Device1_CreateShaderResourceView1(device, (ID3D10Resource *)buffer, NULL, &srview);
367 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
369 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
370 srv_desc.ViewDimension = D3D10_1_SRV_DIMENSION_BUFFER;
371 U(srv_desc).Buffer.ElementOffset = 0;
372 U(srv_desc).Buffer.ElementWidth = 64;
374 hr = ID3D10Device1_CreateShaderResourceView1(device, NULL, &srv_desc, &srview);
375 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
377 expected_refcount = get_refcount((IUnknown *)device) + 1;
378 hr = ID3D10Device1_CreateShaderResourceView1(device, (ID3D10Resource *)buffer, &srv_desc, &srview);
379 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr);
380 refcount = get_refcount((IUnknown *)device);
381 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
382 tmp_device = NULL;
383 expected_refcount = refcount + 1;
384 ID3D10ShaderResourceView1_GetDevice(srview, &tmp_device);
385 ok(tmp_device == (ID3D10Device *)device, "Got unexpected device %p, expected %p.\n", tmp_device, device);
386 refcount = get_refcount((IUnknown *)device);
387 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
388 ID3D10Device_Release(tmp_device);
390 hr = ID3D10ShaderResourceView1_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
391 ok(SUCCEEDED(hr), "Shader resource view should implement ID3D10ShaderResourceView.\n");
392 IUnknown_Release(iface);
393 hr = ID3D10ShaderResourceView1_QueryInterface(srview, &IID_ID3D11ShaderResourceView, (void **)&iface);
394 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
395 "Shader resource view should implement ID3D11ShaderResourceView.\n");
396 if (SUCCEEDED(hr)) IUnknown_Release(iface);
398 ID3D10ShaderResourceView1_Release(srview);
399 ID3D10Buffer_Release(buffer);
401 texture_desc.Width = 512;
402 texture_desc.Height = 512;
403 texture_desc.MipLevels = 0;
404 texture_desc.ArraySize = 1;
405 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
406 texture_desc.SampleDesc.Count = 1;
407 texture_desc.SampleDesc.Quality = 0;
408 texture_desc.Usage = D3D10_USAGE_DEFAULT;
409 texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
410 texture_desc.CPUAccessFlags = 0;
411 texture_desc.MiscFlags = 0;
413 hr = ID3D10Device1_CreateTexture2D(device, &texture_desc, NULL, &texture);
414 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr);
416 hr = ID3D10Device1_CreateShaderResourceView1(device, (ID3D10Resource *)texture, NULL, &srview);
417 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr);
419 ID3D10ShaderResourceView1_GetDesc1(srview, &srv_desc);
420 ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
421 ok(srv_desc.ViewDimension == D3D10_1_SRV_DIMENSION_TEXTURE2D,
422 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
423 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
424 U(srv_desc).Texture2D.MostDetailedMip);
425 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
427 hr = ID3D10ShaderResourceView1_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
428 ok(SUCCEEDED(hr), "Shader resource view should implement ID3D10ShaderResourceView.\n");
429 IUnknown_Release(iface);
430 hr = ID3D10ShaderResourceView1_QueryInterface(srview, &IID_ID3D11ShaderResourceView, (void **)&iface);
431 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
432 "Shader resource view should implement ID3D11ShaderResourceView.\n");
433 if (SUCCEEDED(hr)) IUnknown_Release(iface);
435 ID3D10ShaderResourceView1_Release(srview);
436 ID3D10Texture2D_Release(texture);
438 refcount = ID3D10Device1_Release(device);
439 ok(!refcount, "Device has %u references left.\n", refcount);
442 static void test_create_blend_state(void)
444 static const D3D10_BLEND_DESC1 desc_conversion_tests[] =
447 FALSE, FALSE,
450 FALSE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
451 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD
456 FALSE, TRUE,
459 TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
460 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
463 FALSE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
464 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_RED
467 TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
468 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
471 FALSE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
472 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_GREEN
475 TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
476 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
479 TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
480 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
483 TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
484 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
487 TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
488 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
493 FALSE, TRUE,
496 TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
497 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
500 TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_SUBTRACT,
501 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
504 TRUE, D3D10_BLEND_ZERO, D3D10_BLEND_ONE, D3D10_BLEND_OP_ADD,
505 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
508 TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
509 D3D10_BLEND_ZERO, D3D10_BLEND_ONE, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
512 TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ONE, D3D10_BLEND_OP_MAX,
513 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
516 TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ONE, D3D10_BLEND_OP_MIN,
517 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
520 FALSE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
521 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
524 FALSE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD,
525 D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL
531 ID3D10BlendState1 *blend_state1, *blend_state2;
532 D3D10_BLEND_DESC1 desc, obtained_desc;
533 ID3D10BlendState *d3d10_blend_state;
534 D3D10_BLEND_DESC d3d10_blend_desc;
535 ULONG refcount, expected_refcount;
536 ID3D10Device1 *device;
537 ID3D10Device *tmp;
538 unsigned int i, j;
539 IUnknown *iface;
540 HRESULT hr;
542 if (!(device = create_device(NULL)))
544 skip("Failed to create device.\n");
545 return;
548 hr = ID3D10Device1_CreateBlendState1(device, NULL, &blend_state1);
549 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
551 memset(&desc, 0, sizeof(desc));
552 desc.AlphaToCoverageEnable = FALSE;
553 desc.IndependentBlendEnable = FALSE;
554 desc.RenderTarget[0].BlendEnable = FALSE;
555 desc.RenderTarget[0].SrcBlend = D3D10_BLEND_ONE;
556 desc.RenderTarget[0].DestBlend = D3D10_BLEND_ZERO;
557 desc.RenderTarget[0].BlendOp = D3D10_BLEND_OP_ADD;
558 desc.RenderTarget[0].SrcBlendAlpha = D3D10_BLEND_ONE;
559 desc.RenderTarget[0].DestBlendAlpha = D3D10_BLEND_ZERO;
560 desc.RenderTarget[0].BlendOpAlpha = D3D10_BLEND_OP_ADD;
561 desc.RenderTarget[0].RenderTargetWriteMask = D3D10_COLOR_WRITE_ENABLE_ALL;
563 expected_refcount = get_refcount((IUnknown *)device) + 1;
564 hr = ID3D10Device1_CreateBlendState1(device, &desc, &blend_state1);
565 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
566 hr = ID3D10Device1_CreateBlendState1(device, &desc, &blend_state2);
567 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
568 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
569 refcount = get_refcount((IUnknown *)device);
570 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
571 tmp = NULL;
572 expected_refcount = refcount + 1;
573 ID3D10BlendState1_GetDevice(blend_state1, &tmp);
574 ok(tmp == (ID3D10Device *)device, "Got unexpected device %p, expected %p.\n", tmp, device);
575 refcount = get_refcount((IUnknown *)device);
576 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
577 ID3D10Device_Release(tmp);
579 ID3D10BlendState1_GetDesc1(blend_state1, &obtained_desc);
580 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
581 obtained_desc.AlphaToCoverageEnable);
582 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
583 obtained_desc.IndependentBlendEnable);
584 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
586 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
587 "Got unexpected blend enable %#x for render target %u.\n",
588 obtained_desc.RenderTarget[i].BlendEnable, i);
589 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D10_BLEND_ONE,
590 "Got unexpected src blend %u for render target %u.\n",
591 obtained_desc.RenderTarget[i].SrcBlend, i);
592 ok(obtained_desc.RenderTarget[i].DestBlend == D3D10_BLEND_ZERO,
593 "Got unexpected dest blend %u for render target %u.\n",
594 obtained_desc.RenderTarget[i].DestBlend, i);
595 ok(obtained_desc.RenderTarget[i].BlendOp == D3D10_BLEND_OP_ADD,
596 "Got unexpected blend op %u for render target %u.\n",
597 obtained_desc.RenderTarget[i].BlendOp, i);
598 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D10_BLEND_ONE,
599 "Got unexpected src blend alpha %u for render target %u.\n",
600 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
601 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D10_BLEND_ZERO,
602 "Got unexpected dest blend alpha %u for render target %u.\n",
603 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
604 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D10_BLEND_OP_ADD,
605 "Got unexpected blend op alpha %u for render target %u.\n",
606 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
607 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D10_COLOR_WRITE_ENABLE_ALL,
608 "Got unexpected render target write mask %#x for render target %u.\n",
609 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
612 hr = ID3D10BlendState1_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&iface);
613 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
614 IUnknown_Release(iface);
615 hr = ID3D10BlendState1_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&iface);
616 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
617 "Blend state should implement ID3D11BlendState.\n");
618 if (SUCCEEDED(hr)) IUnknown_Release(iface);
620 refcount = ID3D10BlendState1_Release(blend_state1);
621 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
622 refcount = ID3D10BlendState1_Release(blend_state2);
623 ok(!refcount, "Blend state has %u references left.\n", refcount);
625 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
627 const D3D10_BLEND_DESC1 *current_desc = &desc_conversion_tests[i];
629 hr = ID3D10Device1_CreateBlendState1(device, current_desc, &blend_state1);
630 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
632 hr = ID3D10BlendState1_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
633 ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n");
635 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
636 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
637 "Got unexpected alpha to coverage enable %#x for test %u.\n",
638 d3d10_blend_desc.AlphaToCoverageEnable, i);
639 ok(d3d10_blend_desc.SrcBlend == current_desc->RenderTarget[0].SrcBlend,
640 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
641 ok(d3d10_blend_desc.DestBlend == current_desc->RenderTarget[0].DestBlend,
642 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
643 ok(d3d10_blend_desc.BlendOp == current_desc->RenderTarget[0].BlendOp,
644 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
645 ok(d3d10_blend_desc.SrcBlendAlpha == current_desc->RenderTarget[0].SrcBlendAlpha,
646 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
647 ok(d3d10_blend_desc.DestBlendAlpha == current_desc->RenderTarget[0].DestBlendAlpha,
648 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
649 ok(d3d10_blend_desc.BlendOpAlpha == current_desc->RenderTarget[0].BlendOpAlpha,
650 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
651 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
653 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
654 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
655 "Got unexpected blend enable %#x for test %u, render target %u.\n",
656 d3d10_blend_desc.BlendEnable[j], i, j);
657 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
658 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
659 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
662 ID3D10BlendState_Release(d3d10_blend_state);
664 refcount = ID3D10BlendState1_Release(blend_state1);
665 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
668 refcount = ID3D10Device1_Release(device);
669 ok(!refcount, "Device has %u references left.\n", refcount);
672 static void test_getdc(void)
674 struct device_desc device_desc;
675 D3D10_TEXTURE2D_DESC desc;
676 ID3D10Texture2D *texture;
677 IDXGISurface1 *surface1;
678 ID3D10Device1 *device;
679 ULONG refcount;
680 HRESULT hr;
681 HDC dc;
683 device_desc.feature_level = D3D10_FEATURE_LEVEL_10_1;
684 device_desc.flags = D3D10_CREATE_DEVICE_BGRA_SUPPORT;
685 if (!(device = create_device(&device_desc)))
687 skip("Failed to create device.\n");
688 return;
691 /* Without D3D10_RESOURCE_MISC_GDI_COMPATIBLE. */
692 desc.Width = 512;
693 desc.Height = 512;
694 desc.MipLevels = 1;
695 desc.ArraySize = 1;
696 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
697 desc.SampleDesc.Count = 1;
698 desc.SampleDesc.Quality = 0;
699 desc.Usage = D3D10_USAGE_DEFAULT;
700 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
701 desc.CPUAccessFlags = 0;
702 desc.MiscFlags = 0;
703 hr = ID3D10Device1_CreateTexture2D(device, &desc, NULL, &texture);
704 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
706 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface1);
707 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
709 hr = IDXGISurface1_GetDC(surface1, FALSE, &dc);
710 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
712 IDXGISurface1_Release(surface1);
713 ID3D10Texture2D_Release(texture);
715 desc.MiscFlags = D3D10_RESOURCE_MISC_GDI_COMPATIBLE;
716 hr = ID3D10Device1_CreateTexture2D(device, &desc, NULL, &texture);
717 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
719 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface1);
720 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
722 hr = IDXGISurface1_ReleaseDC(surface1, NULL);
723 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
725 hr = IDXGISurface1_GetDC(surface1, FALSE, &dc);
726 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
728 /* One more time. */
729 dc = (HDC)0xdeadbeef;
730 hr = IDXGISurface1_GetDC(surface1, FALSE, &dc);
731 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
732 ok(dc == (HDC)0xdeadbeef, "Got unexpected dc %p.\n", dc);
734 hr = IDXGISurface1_ReleaseDC(surface1, NULL);
735 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
737 hr = IDXGISurface1_ReleaseDC(surface1, NULL);
738 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
740 IDXGISurface1_Release(surface1);
741 ID3D10Texture2D_Release(texture);
743 refcount = ID3D10Device1_Release(device);
744 ok(!refcount, "Device has %u references left.\n", refcount);
747 START_TEST(d3d10_1)
749 test_create_device();
750 test_device_interfaces();
751 test_create_shader_resource_view();
752 test_create_blend_state();
753 test_getdc();