d3d/tests: Check that device implements IDXGIDevice1.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob7adea47fe64c6eb5f0ca3b032c1afc692dbcd77e
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 D3D_FEATURE_LEVEL d3d11_feature_levels[] =
27 D3D_FEATURE_LEVEL_11_1,
28 D3D_FEATURE_LEVEL_11_0,
29 D3D_FEATURE_LEVEL_10_1,
30 D3D_FEATURE_LEVEL_10_0,
31 D3D_FEATURE_LEVEL_9_3,
32 D3D_FEATURE_LEVEL_9_2,
33 D3D_FEATURE_LEVEL_9_1
36 static ULONG get_refcount(IUnknown *iface)
38 IUnknown_AddRef(iface);
39 return IUnknown_Release(iface);
42 static ID3D11Device *create_device(const D3D_FEATURE_LEVEL *feature_level)
44 ID3D11Device *device;
45 UINT feature_level_count = feature_level ? 1 : 0;
47 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, feature_level, feature_level_count,
48 D3D11_SDK_VERSION, &device, NULL, NULL)))
49 return device;
50 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, 0, feature_level, feature_level_count,
51 D3D11_SDK_VERSION, &device, NULL, NULL)))
52 return device;
53 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0, feature_level, feature_level_count,
54 D3D11_SDK_VERSION, &device, NULL, NULL)))
55 return device;
57 return NULL;
60 static void test_create_device(void)
62 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
63 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
64 ID3D11DeviceContext *immediate_context;
65 IDXGISwapChain *swapchain;
66 ID3D11Device *device;
67 ULONG refcount;
68 HWND window;
69 HRESULT hr;
71 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, &device,
72 NULL, NULL);
73 if (FAILED(hr))
75 skip("Failed to create HAL device.\n");
76 return;
79 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
80 ID3D11Device_Release(device);
82 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
83 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
85 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
86 &feature_level, NULL);
87 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
88 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
89 feature_level, supported_feature_level);
91 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
92 &immediate_context);
93 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
95 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
96 refcount = get_refcount((IUnknown *)immediate_context);
97 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
99 ID3D11DeviceContext_GetDevice(immediate_context, &device);
100 refcount = ID3D11Device_Release(device);
101 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
103 refcount = ID3D11DeviceContext_Release(immediate_context);
104 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
106 device = (ID3D11Device *)0xdeadbeef;
107 feature_level = 0xdeadbeef;
108 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
109 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
110 &device, &feature_level, &immediate_context);
111 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
112 ok(!device, "Got unexpected device pointer %p.\n", device);
113 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
114 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
116 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
118 swapchain_desc.BufferDesc.Width = 800;
119 swapchain_desc.BufferDesc.Height = 600;
120 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
121 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
122 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
123 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
124 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
125 swapchain_desc.SampleDesc.Count = 1;
126 swapchain_desc.SampleDesc.Quality = 0;
127 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
128 swapchain_desc.BufferCount = 1;
129 swapchain_desc.OutputWindow = window;
130 swapchain_desc.Windowed = TRUE;
131 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
132 swapchain_desc.Flags = 0;
134 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
135 &swapchain_desc, NULL, NULL, NULL, NULL);
136 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
138 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
139 &swapchain_desc, NULL, NULL, &feature_level, NULL);
140 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
141 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
142 feature_level, supported_feature_level);
144 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
145 &swapchain_desc, &swapchain, &device, NULL, NULL);
146 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
148 memset(&obtained_desc, 0, sizeof(obtained_desc));
149 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
150 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
151 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
152 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
153 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
154 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
155 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
156 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
157 obtained_desc.BufferDesc.RefreshRate.Numerator);
158 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
159 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
160 obtained_desc.BufferDesc.RefreshRate.Denominator);
161 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
162 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
163 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
164 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
165 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
166 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
167 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
168 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
169 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
170 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
171 todo_wine ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
172 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
173 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
174 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
175 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
176 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
177 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
178 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
179 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
180 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
181 ok(obtained_desc.Flags == swapchain_desc.Flags,
182 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
184 refcount = IDXGISwapChain_Release(swapchain);
185 ok(!refcount, "Swapchain has %u references left.\n", refcount);
187 feature_level = ID3D11Device_GetFeatureLevel(device);
188 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
189 feature_level, supported_feature_level);
191 refcount = ID3D11Device_Release(device);
192 ok(!refcount, "Device has %u references left.\n", refcount);
194 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
195 NULL, NULL, &device, NULL, NULL);
196 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
197 ID3D11Device_Release(device);
199 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
200 NULL, NULL, NULL, NULL, NULL);
201 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
203 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
204 NULL, NULL, NULL, &feature_level, NULL);
205 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
206 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
207 feature_level, supported_feature_level);
209 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
210 &swapchain_desc, NULL, NULL, NULL, NULL);
211 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
213 swapchain_desc.OutputWindow = NULL;
214 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
215 &swapchain_desc, NULL, &device, NULL, NULL);
216 ok(SUCCEEDED(hr), "D3D11CreateDeviceAndSwapChain failed %#x.\n", hr);
217 ID3D11Device_Release(device);
219 swapchain = (IDXGISwapChain *)0xdeadbeef;
220 device = (ID3D11Device *)0xdeadbeef;
221 feature_level = 0xdeadbeef;
222 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
223 swapchain_desc.OutputWindow = NULL;
224 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
225 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
226 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
227 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
228 ok(!device, "Got unexpected device pointer %p.\n", device);
229 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
230 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
232 swapchain = (IDXGISwapChain *)0xdeadbeef;
233 device = (ID3D11Device *)0xdeadbeef;
234 feature_level = 0xdeadbeef;
235 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
236 swapchain_desc.OutputWindow = window;
237 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
238 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
239 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
240 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
241 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
242 ok(!device, "Got unexpected device pointer %p.\n", device);
243 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
244 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
246 DestroyWindow(window);
249 static void test_device_interfaces(void)
251 IDXGIAdapter *dxgi_adapter;
252 IDXGIDevice *dxgi_device;
253 ID3D11Device *device;
254 IUnknown *iface;
255 ULONG refcount;
256 unsigned int i;
257 HRESULT hr;
259 for (i = 0; i < sizeof(d3d11_feature_levels) / sizeof(*d3d11_feature_levels); ++i)
261 if (!(device = create_device(&d3d11_feature_levels[i])))
263 skip("Failed to create device for feature level %#x.\n", d3d11_feature_levels[i]);
264 continue;
267 hr = ID3D11Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
268 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
269 IUnknown_Release(iface);
271 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
272 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
273 IUnknown_Release(iface);
275 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
276 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
277 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
278 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
279 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
280 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
281 IUnknown_Release(iface);
282 IDXGIAdapter_Release(dxgi_adapter);
283 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
284 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
285 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
286 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
287 IUnknown_Release(iface);
288 IDXGIAdapter_Release(dxgi_adapter);
289 IDXGIDevice_Release(dxgi_device);
291 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice1, (void **)&iface);
292 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice1.\n");
293 IUnknown_Release(iface);
295 hr = ID3D11Device_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 = ID3D11Device_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
301 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device interface, hr %#x.\n", hr);
302 if (SUCCEEDED(hr)) IUnknown_Release(iface);
304 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
305 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device1 interface, hr %#x.\n", hr);
306 if (SUCCEEDED(hr)) IUnknown_Release(iface);
308 refcount = ID3D11Device_Release(device);
309 ok(!refcount, "Device has %u references left.\n", refcount);
313 static void test_get_immediate_context(void)
315 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
316 ULONG expected_refcount, refcount;
317 ID3D11Device *device;
319 if (!(device = create_device(NULL)))
321 skip("Failed to create device.\n");
322 return;
325 expected_refcount = get_refcount((IUnknown *)device) + 1;
326 ID3D11Device_GetImmediateContext(device, &immediate_context);
327 refcount = get_refcount((IUnknown *)device);
328 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
329 previous_immediate_context = immediate_context;
331 ID3D11Device_GetImmediateContext(device, &immediate_context);
332 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
333 refcount = get_refcount((IUnknown *)device);
334 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
336 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
337 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
338 refcount = ID3D11DeviceContext_Release(immediate_context);
339 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
341 ID3D11Device_GetImmediateContext(device, &immediate_context);
342 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
343 refcount = ID3D11DeviceContext_Release(immediate_context);
344 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
346 refcount = ID3D11Device_Release(device);
347 ok(!refcount, "Device has %u references left.\n", refcount);
350 static void test_create_texture2d(void)
352 ULONG refcount, expected_refcount;
353 D3D11_SUBRESOURCE_DATA data = {0};
354 ID3D11Device *device, *tmp;
355 D3D11_TEXTURE2D_DESC desc;
356 ID3D11Texture2D *texture;
357 IDXGISurface *surface;
358 HRESULT hr;
360 if (!(device = create_device(NULL)))
362 skip("Failed to create device, skipping tests.\n");
363 return;
366 desc.Width = 512;
367 desc.Height = 512;
368 desc.MipLevels = 1;
369 desc.ArraySize = 1;
370 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
371 desc.SampleDesc.Count = 1;
372 desc.SampleDesc.Quality = 0;
373 desc.Usage = D3D11_USAGE_DEFAULT;
374 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
375 desc.CPUAccessFlags = 0;
376 desc.MiscFlags = 0;
378 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
379 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
381 expected_refcount = get_refcount((IUnknown *)device) + 1;
382 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
383 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
384 refcount = get_refcount((IUnknown *)device);
385 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
386 tmp = NULL;
387 expected_refcount = refcount + 1;
388 ID3D11Texture2D_GetDevice(texture, &tmp);
389 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
390 refcount = get_refcount((IUnknown *)device);
391 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
392 ID3D11Device_Release(tmp);
394 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
395 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface.\n");
396 IDXGISurface_Release(surface);
397 ID3D11Texture2D_Release(texture);
399 desc.MipLevels = 0;
400 expected_refcount = get_refcount((IUnknown *)device) + 1;
401 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
402 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
403 refcount = get_refcount((IUnknown *)device);
404 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
405 tmp = NULL;
406 expected_refcount = refcount + 1;
407 ID3D11Texture2D_GetDevice(texture, &tmp);
408 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
409 refcount = get_refcount((IUnknown *)device);
410 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
411 ID3D11Device_Release(tmp);
413 ID3D11Texture2D_GetDesc(texture, &desc);
414 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
415 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
416 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
417 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
418 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
419 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
420 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
421 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
422 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
423 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
424 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
426 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
427 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
428 ID3D11Texture2D_Release(texture);
430 desc.MipLevels = 1;
431 desc.ArraySize = 2;
432 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
433 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
435 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
436 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
437 ID3D11Texture2D_Release(texture);
439 refcount = ID3D11Device_Release(device);
440 ok(!refcount, "Device has %u references left.\n", refcount);
443 static void test_texture2d_interfaces(void)
445 ID3D10Texture2D *d3d10_texture;
446 D3D11_TEXTURE2D_DESC desc;
447 ID3D11Texture2D *texture;
448 IDXGISurface *surface;
449 ID3D11Device *device;
450 unsigned int i;
451 ULONG refcount;
452 HRESULT hr;
454 static const struct test
456 BOOL implements_d3d10_interfaces;
457 UINT bind_flags;
458 UINT misc_flags;
459 UINT expected_bind_flags;
460 UINT expected_misc_flags;
462 desc_conversion_tests[] =
465 TRUE,
466 D3D11_BIND_SHADER_RESOURCE, 0,
467 D3D10_BIND_SHADER_RESOURCE, 0
470 TRUE,
471 D3D11_BIND_UNORDERED_ACCESS, 0,
472 D3D11_BIND_UNORDERED_ACCESS, 0
475 FALSE,
476 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
477 0, 0
480 TRUE,
481 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
482 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
485 TRUE,
486 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
487 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
491 if (!(device = create_device(NULL)))
493 skip("Failed to create ID3D11Device, skipping tests.\n");
494 return;
497 desc.Width = 512;
498 desc.Height = 512;
499 desc.MipLevels = 0;
500 desc.ArraySize = 1;
501 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
502 desc.SampleDesc.Count = 1;
503 desc.SampleDesc.Quality = 0;
504 desc.Usage = D3D11_USAGE_DEFAULT;
505 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
506 desc.CPUAccessFlags = 0;
507 desc.MiscFlags = 0;
509 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
510 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
512 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
513 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
515 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
516 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
517 "Texture should implement ID3D10Texture2D.\n");
518 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
519 ID3D11Texture2D_Release(texture);
521 if (FAILED(hr))
523 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
524 ID3D11Device_Release(device);
525 return;
528 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
530 const struct test *current = &desc_conversion_tests[i];
531 D3D10_TEXTURE2D_DESC d3d10_desc;
532 ID3D10Device *d3d10_device;
534 desc.Width = 512;
535 desc.Height = 512;
536 desc.MipLevels = 1;
537 desc.ArraySize = 1;
538 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
539 desc.SampleDesc.Count = 1;
540 desc.SampleDesc.Quality = 0;
541 desc.Usage = D3D11_USAGE_DEFAULT;
542 desc.BindFlags = current->bind_flags;
543 desc.CPUAccessFlags = 0;
544 desc.MiscFlags = current->misc_flags;
546 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
547 /* Shared resources are not supported by REF and WARP devices. */
548 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
549 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
550 if (FAILED(hr))
552 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
553 continue;
556 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
557 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
558 IDXGISurface_Release(surface);
560 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
561 ID3D11Texture2D_Release(texture);
563 if (current->implements_d3d10_interfaces)
565 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
567 else
569 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
570 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
571 continue;
574 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
576 ok(d3d10_desc.Width == desc.Width,
577 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
578 ok(d3d10_desc.Height == desc.Height,
579 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
580 ok(d3d10_desc.MipLevels == desc.MipLevels,
581 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
582 ok(d3d10_desc.ArraySize == desc.ArraySize,
583 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
584 ok(d3d10_desc.Format == desc.Format,
585 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
586 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
587 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
588 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
589 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
590 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
591 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
592 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
593 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
594 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
595 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
596 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
597 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
599 d3d10_device = (ID3D10Device *)0xdeadbeef;
600 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
601 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
602 if (d3d10_device) ID3D10Device_Release(d3d10_device);
604 ID3D10Texture2D_Release(d3d10_texture);
607 refcount = ID3D11Device_Release(device);
608 ok(!refcount, "Device has %u references left.\n", refcount);
611 static void test_create_texture3d(void)
613 ULONG refcount, expected_refcount;
614 D3D11_SUBRESOURCE_DATA data = {0};
615 ID3D11Device *device, *tmp;
616 D3D11_TEXTURE3D_DESC desc;
617 ID3D11Texture3D *texture;
618 IDXGISurface *surface;
619 HRESULT hr;
621 if (!(device = create_device(NULL)))
623 skip("Failed to create ID3D11Device, skipping tests.\n");
624 return;
627 desc.Width = 64;
628 desc.Height = 64;
629 desc.Depth = 64;
630 desc.MipLevels = 1;
631 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
632 desc.Usage = D3D11_USAGE_DEFAULT;
633 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
634 desc.CPUAccessFlags = 0;
635 desc.MiscFlags = 0;
637 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
638 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
640 expected_refcount = get_refcount((IUnknown *)device) + 1;
641 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
642 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
643 refcount = get_refcount((IUnknown *)device);
644 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
645 tmp = NULL;
646 expected_refcount = refcount + 1;
647 ID3D11Texture3D_GetDevice(texture, &tmp);
648 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
649 refcount = get_refcount((IUnknown *)device);
650 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
651 ID3D11Device_Release(tmp);
653 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
654 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
655 ID3D11Texture3D_Release(texture);
657 desc.MipLevels = 0;
658 expected_refcount = get_refcount((IUnknown *)device) + 1;
659 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
660 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
661 refcount = get_refcount((IUnknown *)device);
662 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
663 tmp = NULL;
664 expected_refcount = refcount + 1;
665 ID3D11Texture3D_GetDevice(texture, &tmp);
666 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
667 refcount = get_refcount((IUnknown *)device);
668 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
669 ID3D11Device_Release(tmp);
671 ID3D11Texture3D_GetDesc(texture, &desc);
672 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
673 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
674 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
675 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
676 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
677 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
678 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
679 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
680 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
682 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
683 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
684 ID3D11Texture3D_Release(texture);
686 refcount = ID3D11Device_Release(device);
687 ok(!refcount, "Device has %u references left.\n", refcount);
690 static void test_texture3d_interfaces(void)
692 ID3D10Texture3D *d3d10_texture;
693 D3D11_TEXTURE3D_DESC desc;
694 ID3D11Texture3D *texture;
695 IDXGISurface *surface;
696 ID3D11Device *device;
697 unsigned int i;
698 ULONG refcount;
699 HRESULT hr;
701 static const struct test
703 BOOL implements_d3d10_interfaces;
704 UINT bind_flags;
705 UINT misc_flags;
706 UINT expected_bind_flags;
707 UINT expected_misc_flags;
709 desc_conversion_tests[] =
712 TRUE,
713 D3D11_BIND_SHADER_RESOURCE, 0,
714 D3D10_BIND_SHADER_RESOURCE, 0
717 TRUE,
718 D3D11_BIND_UNORDERED_ACCESS, 0,
719 D3D11_BIND_UNORDERED_ACCESS, 0
722 FALSE,
723 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
724 0, 0
727 TRUE,
728 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
729 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
733 if (!(device = create_device(NULL)))
735 skip("Failed to create ID3D11Device.\n");
736 return;
739 desc.Width = 64;
740 desc.Height = 64;
741 desc.Depth = 64;
742 desc.MipLevels = 0;
743 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
744 desc.Usage = D3D11_USAGE_DEFAULT;
745 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
746 desc.CPUAccessFlags = 0;
747 desc.MiscFlags = 0;
749 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
750 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
752 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
753 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
755 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
756 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
757 "Texture should implement ID3D10Texture3D.\n");
758 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
759 ID3D11Texture3D_Release(texture);
761 if (FAILED(hr))
763 win_skip("3D textures do not implement ID3D10Texture3D.\n");
764 ID3D11Device_Release(device);
765 return;
768 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
770 const struct test *current = &desc_conversion_tests[i];
771 D3D10_TEXTURE3D_DESC d3d10_desc;
772 ID3D10Device *d3d10_device;
774 desc.Width = 64;
775 desc.Height = 64;
776 desc.Depth = 64;
777 desc.MipLevels = 1;
778 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
779 desc.Usage = D3D11_USAGE_DEFAULT;
780 desc.BindFlags = current->bind_flags;
781 desc.CPUAccessFlags = 0;
782 desc.MiscFlags = current->misc_flags;
784 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
785 /* Shared resources are not supported by REF and WARP devices. */
786 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
787 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
788 if (FAILED(hr))
790 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
791 continue;
794 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
795 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
797 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
798 ID3D11Texture3D_Release(texture);
800 if (current->implements_d3d10_interfaces)
802 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
804 else
806 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
807 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
808 continue;
811 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
813 ok(d3d10_desc.Width == desc.Width,
814 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
815 ok(d3d10_desc.Height == desc.Height,
816 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
817 ok(d3d10_desc.Depth == desc.Depth,
818 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
819 ok(d3d10_desc.MipLevels == desc.MipLevels,
820 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
821 ok(d3d10_desc.Format == desc.Format,
822 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
823 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
824 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
825 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
826 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
827 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
828 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
829 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
830 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
832 d3d10_device = (ID3D10Device *)0xdeadbeef;
833 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
834 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
835 if (d3d10_device) ID3D10Device_Release(d3d10_device);
837 ID3D10Texture3D_Release(d3d10_texture);
840 refcount = ID3D11Device_Release(device);
841 ok(!refcount, "Device has %u references left.\n", refcount);
844 static void test_buffer_interfaces(void)
846 ID3D10Buffer *d3d10_buffer;
847 D3D11_BUFFER_DESC desc;
848 ID3D11Buffer *buffer;
849 ID3D11Device *device;
850 unsigned int i;
851 ULONG refcount;
852 HRESULT hr;
854 static const struct test
856 BOOL implements_d3d10_interfaces;
857 UINT bind_flags;
858 UINT misc_flags;
859 UINT structure_stride;
860 UINT expected_bind_flags;
861 UINT expected_misc_flags;
863 desc_conversion_tests[] =
866 TRUE,
867 D3D11_BIND_VERTEX_BUFFER, 0, 0,
868 D3D10_BIND_VERTEX_BUFFER, 0
871 TRUE,
872 D3D11_BIND_INDEX_BUFFER, 0, 0,
873 D3D10_BIND_INDEX_BUFFER, 0
876 TRUE,
877 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
878 D3D10_BIND_CONSTANT_BUFFER, 0
881 TRUE,
882 D3D11_BIND_SHADER_RESOURCE, 0, 0,
883 D3D10_BIND_SHADER_RESOURCE, 0
886 TRUE,
887 D3D11_BIND_STREAM_OUTPUT, 0, 0,
888 D3D10_BIND_STREAM_OUTPUT, 0
891 TRUE,
892 D3D11_BIND_RENDER_TARGET, 0, 0,
893 D3D10_BIND_RENDER_TARGET, 0
896 TRUE,
897 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
898 D3D11_BIND_UNORDERED_ACCESS, 0
901 TRUE,
902 0, D3D11_RESOURCE_MISC_SHARED, 0,
903 0, D3D10_RESOURCE_MISC_SHARED
906 TRUE,
907 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
908 0, 0
911 TRUE,
912 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
913 D3D10_BIND_SHADER_RESOURCE, 0
916 FALSE /* Structured buffers do not implement ID3D10Buffer. */,
917 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
918 0, 0
921 TRUE,
922 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
923 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
927 if (!(device = create_device(NULL)))
929 skip("Failed to create ID3D11Device.\n");
930 return;
933 desc.ByteWidth = 1024;
934 desc.Usage = D3D11_USAGE_DEFAULT;
935 desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
936 desc.CPUAccessFlags = 0;
937 desc.MiscFlags = 0;
938 desc.StructureByteStride = 0;
940 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
941 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
943 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
944 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
945 "Buffer should implement ID3D10Buffer.\n");
946 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
947 ID3D11Buffer_Release(buffer);
949 if (FAILED(hr))
951 win_skip("Buffers do not implement ID3D10Buffer.\n");
952 ID3D11Device_Release(device);
953 return;
956 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
958 const struct test *current = &desc_conversion_tests[i];
959 D3D10_BUFFER_DESC d3d10_desc;
960 ID3D10Device *d3d10_device;
962 desc.ByteWidth = 1024;
963 desc.Usage = D3D11_USAGE_DEFAULT;
964 desc.BindFlags = current->bind_flags;
965 desc.CPUAccessFlags = 0;
966 desc.MiscFlags = current->misc_flags;
967 desc.StructureByteStride = current->structure_stride;
969 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
970 /* Shared resources are not supported by REF and WARP devices. */
971 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
972 if (FAILED(hr))
974 win_skip("Failed to create a buffer, skipping test %u.\n", i);
975 continue;
978 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
979 ID3D11Buffer_Release(buffer);
981 if (current->implements_d3d10_interfaces)
983 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
985 else
987 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
988 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
989 continue;
992 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
994 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
995 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
996 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
997 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
998 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
999 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
1000 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
1001 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
1002 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
1003 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
1005 d3d10_device = (ID3D10Device *)0xdeadbeef;
1006 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
1007 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
1008 if (d3d10_device) ID3D10Device_Release(d3d10_device);
1010 ID3D10Buffer_Release(d3d10_buffer);
1013 refcount = ID3D11Device_Release(device);
1014 ok(!refcount, "Device has %u references left.\n", refcount);
1017 static void test_create_depthstencil_view(void)
1019 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1020 D3D11_TEXTURE2D_DESC texture_desc;
1021 ULONG refcount, expected_refcount;
1022 ID3D11DepthStencilView *dsview;
1023 ID3D11Device *device, *tmp;
1024 ID3D11Texture2D *texture;
1025 HRESULT hr;
1027 if (!(device = create_device(NULL)))
1029 skip("Failed to create device.\n");
1030 return;
1033 texture_desc.Width = 512;
1034 texture_desc.Height = 512;
1035 texture_desc.MipLevels = 1;
1036 texture_desc.ArraySize = 1;
1037 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1038 texture_desc.SampleDesc.Count = 1;
1039 texture_desc.SampleDesc.Quality = 0;
1040 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1041 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
1042 texture_desc.CPUAccessFlags = 0;
1043 texture_desc.MiscFlags = 0;
1045 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1046 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1048 expected_refcount = get_refcount((IUnknown *)device) + 1;
1049 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
1050 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1051 refcount = get_refcount((IUnknown *)device);
1052 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1053 tmp = NULL;
1054 expected_refcount = refcount + 1;
1055 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
1056 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1057 refcount = get_refcount((IUnknown *)device);
1058 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1059 ID3D11Device_Release(tmp);
1061 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
1062 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
1063 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
1064 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
1065 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
1066 ok(U(dsv_desc).Texture2D.MipSlice == 0, "Got Unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
1068 ID3D11DepthStencilView_Release(dsview);
1069 ID3D11Texture2D_Release(texture);
1071 refcount = ID3D11Device_Release(device);
1072 ok(!refcount, "Device has %u references left.\n", refcount);
1075 static void test_depthstencil_view_interfaces(void)
1077 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
1078 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
1079 ID3D10DepthStencilView *d3d10_dsview;
1080 D3D11_TEXTURE2D_DESC texture_desc;
1081 ID3D11DepthStencilView *dsview;
1082 ID3D11Texture2D *texture;
1083 ID3D11Device *device;
1084 ULONG refcount;
1085 HRESULT hr;
1087 if (!(device = create_device(NULL)))
1089 skip("Failed to create device.\n");
1090 return;
1093 texture_desc.Width = 512;
1094 texture_desc.Height = 512;
1095 texture_desc.MipLevels = 1;
1096 texture_desc.ArraySize = 1;
1097 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
1098 texture_desc.SampleDesc.Count = 1;
1099 texture_desc.SampleDesc.Quality = 0;
1100 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1101 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
1102 texture_desc.CPUAccessFlags = 0;
1103 texture_desc.MiscFlags = 0;
1105 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1106 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1108 dsv_desc.Format = texture_desc.Format;
1109 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
1110 dsv_desc.Flags = 0;
1111 U(dsv_desc).Texture2D.MipSlice = 0;
1113 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
1114 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
1116 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
1117 ID3D11DepthStencilView_Release(dsview);
1118 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1119 "Depth stencil view should implement ID3D10DepthStencilView.\n");
1121 if (FAILED(hr))
1123 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
1124 goto done;
1127 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
1128 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
1129 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
1130 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
1131 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
1132 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
1134 ID3D10DepthStencilView_Release(d3d10_dsview);
1136 done:
1137 ID3D11Texture2D_Release(texture);
1139 refcount = ID3D11Device_Release(device);
1140 ok(!refcount, "Device has %u references left.\n", refcount);
1143 static void test_create_rendertarget_view(void)
1145 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
1146 D3D11_SUBRESOURCE_DATA data = {0};
1147 D3D11_TEXTURE2D_DESC texture_desc;
1148 ULONG refcount, expected_refcount;
1149 D3D11_BUFFER_DESC buffer_desc;
1150 ID3D11RenderTargetView *rtview;
1151 ID3D11Device *device, *tmp;
1152 ID3D11Texture2D *texture;
1153 ID3D11Buffer *buffer;
1154 IUnknown *iface;
1155 HRESULT hr;
1157 if (!(device = create_device(NULL)))
1159 skip("Failed to create device.\n");
1160 return;
1163 buffer_desc.ByteWidth = 1024;
1164 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
1165 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1166 buffer_desc.CPUAccessFlags = 0;
1167 buffer_desc.MiscFlags = 0;
1168 buffer_desc.StructureByteStride = 0;
1170 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
1171 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1173 expected_refcount = get_refcount((IUnknown *)device) + 1;
1174 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
1175 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1176 refcount = get_refcount((IUnknown *)device);
1177 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1178 tmp = NULL;
1179 expected_refcount = refcount + 1;
1180 ID3D11Buffer_GetDevice(buffer, &tmp);
1181 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1182 refcount = get_refcount((IUnknown *)device);
1183 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1184 ID3D11Device_Release(tmp);
1186 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1187 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
1188 U(rtv_desc).Buffer.ElementOffset = 0;
1189 U(rtv_desc).Buffer.ElementWidth = 64;
1191 expected_refcount = get_refcount((IUnknown *)device) + 1;
1192 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
1193 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1194 refcount = get_refcount((IUnknown *)device);
1195 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1196 tmp = NULL;
1197 expected_refcount = refcount + 1;
1198 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
1199 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1200 refcount = get_refcount((IUnknown *)device);
1201 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1202 ID3D11Device_Release(tmp);
1204 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
1205 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1206 "Render target view should implement ID3D10RenderTargetView.\n");
1207 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1209 ID3D11RenderTargetView_Release(rtview);
1210 ID3D11Buffer_Release(buffer);
1212 texture_desc.Width = 512;
1213 texture_desc.Height = 512;
1214 texture_desc.MipLevels = 1;
1215 texture_desc.ArraySize = 1;
1216 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1217 texture_desc.SampleDesc.Count = 1;
1218 texture_desc.SampleDesc.Quality = 0;
1219 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1220 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
1221 texture_desc.CPUAccessFlags = 0;
1222 texture_desc.MiscFlags = 0;
1224 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1225 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1227 /* For texture resources it's allowed to specify NULL as desc */
1228 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtview);
1229 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
1231 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
1232 ok(rtv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", rtv_desc.Format);
1233 ok(rtv_desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D, "Got unexpected view dimension %#x.\n",
1234 rtv_desc.ViewDimension);
1235 ok(U(rtv_desc).Texture2D.MipSlice == 0, "Got unexpected mip slice %#x.\n", U(rtv_desc).Texture2D.MipSlice);
1237 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
1238 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1239 "Render target view should implement ID3D10RenderTargetView.\n");
1240 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1242 ID3D11RenderTargetView_Release(rtview);
1243 ID3D11Texture2D_Release(texture);
1245 refcount = ID3D11Device_Release(device);
1246 ok(!refcount, "Device has %u references left.\n", refcount);
1249 static void test_create_shader_resource_view(void)
1251 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
1252 D3D11_TEXTURE2D_DESC texture_desc;
1253 ULONG refcount, expected_refcount;
1254 ID3D11ShaderResourceView *srview;
1255 D3D11_BUFFER_DESC buffer_desc;
1256 ID3D11Device *device, *tmp;
1257 ID3D11Texture2D *texture;
1258 ID3D11Buffer *buffer;
1259 IUnknown *iface;
1260 HRESULT hr;
1262 if (!(device = create_device(NULL)))
1264 skip("Failed to create device.\n");
1265 return;
1268 buffer_desc.ByteWidth = 1024;
1269 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
1270 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1271 buffer_desc.CPUAccessFlags = 0;
1272 buffer_desc.MiscFlags = 0;
1273 buffer_desc.StructureByteStride = 0;
1275 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
1276 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1278 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
1279 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1281 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1282 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
1283 U(srv_desc).Buffer.ElementOffset = 0;
1284 U(srv_desc).Buffer.ElementWidth = 64;
1286 expected_refcount = get_refcount((IUnknown *)device) + 1;
1287 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
1288 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
1289 refcount = get_refcount((IUnknown *)device);
1290 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1291 tmp = NULL;
1292 expected_refcount = refcount + 1;
1293 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
1294 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1295 refcount = get_refcount((IUnknown *)device);
1296 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1297 ID3D11Device_Release(tmp);
1299 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
1300 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1301 "Shader resource view should implement ID3D10ShaderResourceView.\n");
1302 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1303 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
1304 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1305 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
1306 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1308 ID3D11ShaderResourceView_Release(srview);
1309 ID3D11Buffer_Release(buffer);
1311 texture_desc.Width = 512;
1312 texture_desc.Height = 512;
1313 texture_desc.MipLevels = 0;
1314 texture_desc.ArraySize = 1;
1315 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1316 texture_desc.SampleDesc.Count = 1;
1317 texture_desc.SampleDesc.Quality = 0;
1318 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1319 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1320 texture_desc.CPUAccessFlags = 0;
1321 texture_desc.MiscFlags = 0;
1323 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1324 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1326 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srview);
1327 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
1329 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
1330 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1331 "Shader resource view should implement ID3D10ShaderResourceView.\n");
1332 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1333 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView1, (void **)&iface);
1334 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1335 "Shader resource view should implement ID3D10ShaderResourceView1.\n");
1336 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1338 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
1339 ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
1340 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D,
1341 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
1342 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
1343 U(srv_desc).Texture2D.MostDetailedMip);
1344 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
1346 ID3D11ShaderResourceView_Release(srview);
1347 ID3D11Texture2D_Release(texture);
1349 refcount = ID3D11Device_Release(device);
1350 ok(!refcount, "Device has %u references left.\n", refcount);
1353 static void test_create_shader(void)
1355 #if 0
1356 float4 light;
1357 float4x4 mat;
1359 struct input
1361 float4 position : POSITION;
1362 float3 normal : NORMAL;
1365 struct output
1367 float4 position : POSITION;
1368 float4 diffuse : COLOR;
1371 output main(const input v)
1373 output o;
1375 o.position = mul(v.position, mat);
1376 o.diffuse = dot((float3)light, v.normal);
1378 return o;
1380 #endif
1381 static const DWORD vs_4_0[] =
1383 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
1384 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
1385 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1386 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
1387 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
1388 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
1389 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
1390 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
1391 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
1392 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
1393 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
1394 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
1395 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
1396 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
1397 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
1398 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
1401 static const DWORD vs_2_0[] =
1403 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
1404 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
1405 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
1406 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
1407 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
1408 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
1409 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
1410 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
1411 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
1412 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
1413 0x90e40001, 0x0000ffff,
1416 static const DWORD vs_3_0[] =
1418 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
1419 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
1420 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
1421 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
1422 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
1423 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
1424 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
1425 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
1426 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
1427 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
1428 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
1429 0x0000ffff,
1432 #if 0
1433 float4 main(const float4 color : COLOR) : SV_TARGET
1435 float4 o;
1437 o = color;
1439 return o;
1441 #endif
1442 static const DWORD ps_4_0[] =
1444 0x43425844, 0x4da9446f, 0xfbe1f259, 0x3fdb3009, 0x517521fa, 0x00000001, 0x000001ac,
1445 0x00000005, 0x00000034, 0x0000008c, 0x000000bc, 0x000000f0, 0x00000130, 0x46454452,
1446 0x00000050, 0x00000000, 0x00000000, 0x00000000, 0x0000001c, 0xffff0400, 0x00000100,
1447 0x0000001c, 0x7263694d, 0x666f736f, 0x52282074, 0x4c482029, 0x53204c53, 0x65646168,
1448 0x6f432072, 0x6c69706d, 0x39207265, 0x2e39322e, 0x2e323539, 0x31313133, 0xababab00,
1449 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1450 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
1451 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
1452 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
1453 0x0000000e, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000,
1454 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x54415453,
1455 0x00000074, 0x00000002, 0x00000000, 0x00000000, 0x00000002, 0x00000000, 0x00000000,
1456 0x00000000, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1457 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000001,
1458 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
1459 0x00000000, 0x00000000,
1462 #if 0
1463 struct gs_out
1465 float4 pos : SV_POSITION;
1468 [maxvertexcount(4)]
1469 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
1471 float offset = 0.1 * vin[0].w;
1472 gs_out v;
1474 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
1475 vout.Append(v);
1476 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
1477 vout.Append(v);
1478 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
1479 vout.Append(v);
1480 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
1481 vout.Append(v);
1483 #endif
1484 static const DWORD gs_4_0[] =
1486 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
1487 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1488 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1489 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1490 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
1491 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
1492 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
1493 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
1494 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
1495 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1496 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
1497 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
1498 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
1499 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
1500 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
1501 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
1502 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
1503 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
1506 ULONG refcount, expected_refcount;
1507 ID3D11Device *device, *tmp;
1508 ID3D11GeometryShader *gs;
1509 ID3D11VertexShader *vs;
1510 ID3D11PixelShader *ps;
1511 IUnknown *iface;
1512 unsigned int i;
1513 HRESULT hr;
1515 for (i = 0; i < sizeof(d3d11_feature_levels) / sizeof(*d3d11_feature_levels); ++i)
1517 D3D_FEATURE_LEVEL feature_level = d3d11_feature_levels[i];
1518 if (!(device = create_device(&feature_level)))
1520 skip("Failed to create device for feature level %#x.\n", feature_level);
1521 continue;
1524 /* vertex shader */
1525 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
1526 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
1528 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
1529 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
1531 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
1532 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
1533 hr, feature_level);
1535 if (feature_level < D3D_FEATURE_LEVEL_10_0)
1537 refcount = ID3D11Device_Release(device);
1538 ok(!refcount, "Device has %u references left.\n", refcount);
1539 continue;
1542 expected_refcount = get_refcount((IUnknown *)device) + 1;
1543 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
1544 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
1546 refcount = get_refcount((IUnknown *)device);
1547 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
1548 refcount, expected_refcount);
1549 tmp = NULL;
1550 expected_refcount = refcount + 1;
1551 ID3D11VertexShader_GetDevice(vs, &tmp);
1552 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1553 refcount = get_refcount((IUnknown *)device);
1554 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
1555 refcount, expected_refcount);
1556 ID3D11Device_Release(tmp);
1558 hr = ID3D11VertexShader_QueryInterface(vs, &IID_ID3D10VertexShader, (void **)&iface);
1559 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1560 "Vertex shader should implement ID3D10VertexShader.\n");
1561 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1563 refcount = ID3D11VertexShader_Release(vs);
1564 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
1566 /* pixel shader */
1567 expected_refcount = get_refcount((IUnknown *)device) + 1;
1568 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
1569 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
1571 refcount = get_refcount((IUnknown *)device);
1572 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
1573 refcount, expected_refcount);
1574 tmp = NULL;
1575 expected_refcount = refcount + 1;
1576 ID3D11PixelShader_GetDevice(ps, &tmp);
1577 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1578 refcount = get_refcount((IUnknown *)device);
1579 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
1580 refcount, expected_refcount);
1581 ID3D11Device_Release(tmp);
1583 hr = ID3D11PixelShader_QueryInterface(ps, &IID_ID3D10PixelShader, (void **)&iface);
1584 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1585 "Pixel shader should implement ID3D10PixelShader.\n");
1586 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1588 refcount = ID3D11PixelShader_Release(ps);
1589 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
1591 /* geometry shader */
1592 expected_refcount = get_refcount((IUnknown *)device) + 1;
1593 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
1594 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x.\n", hr);
1596 refcount = get_refcount((IUnknown *)device);
1597 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
1598 refcount, expected_refcount);
1599 tmp = NULL;
1600 expected_refcount = refcount + 1;
1601 ID3D11GeometryShader_GetDevice(gs, &tmp);
1602 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1603 refcount = get_refcount((IUnknown *)device);
1604 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
1605 refcount, expected_refcount);
1606 ID3D11Device_Release(tmp);
1608 hr = ID3D11GeometryShader_QueryInterface(gs, &IID_ID3D10GeometryShader, (void **)&iface);
1609 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1610 "Geometry shader should implement ID3D10GeometryShader.\n");
1611 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1613 refcount = ID3D11GeometryShader_Release(gs);
1614 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
1616 refcount = ID3D11Device_Release(device);
1617 ok(!refcount, "Device has %u references left.\n", refcount);
1621 static void test_create_sampler_state(void)
1623 static const struct test
1625 D3D11_FILTER filter;
1626 D3D10_FILTER expected_filter;
1628 desc_conversion_tests[] =
1630 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
1631 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
1632 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
1633 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
1634 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
1635 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
1636 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
1637 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
1638 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
1639 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
1640 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
1642 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
1643 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
1645 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
1646 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
1648 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
1649 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
1651 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
1652 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
1653 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
1656 ID3D11SamplerState *sampler_state1, *sampler_state2;
1657 ID3D10SamplerState *d3d10_sampler_state;
1658 ULONG refcount, expected_refcount;
1659 ID3D11Device *device, *tmp;
1660 D3D11_SAMPLER_DESC desc;
1661 unsigned int i;
1662 HRESULT hr;
1664 if (!(device = create_device(NULL)))
1666 skip("Failed to create device.\n");
1667 return;
1670 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
1671 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1673 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
1674 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
1675 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
1676 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
1677 desc.MipLODBias = 0.0f;
1678 desc.MaxAnisotropy = 16;
1679 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
1680 desc.BorderColor[0] = 0.0f;
1681 desc.BorderColor[1] = 1.0f;
1682 desc.BorderColor[2] = 0.0f;
1683 desc.BorderColor[3] = 1.0f;
1684 desc.MinLOD = 0.0f;
1685 desc.MaxLOD = 16.0f;
1687 expected_refcount = get_refcount((IUnknown *)device) + 1;
1688 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
1689 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
1690 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
1691 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
1692 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
1693 refcount = get_refcount((IUnknown *)device);
1694 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1695 tmp = NULL;
1696 expected_refcount = refcount + 1;
1697 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
1698 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1699 refcount = get_refcount((IUnknown *)device);
1700 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1701 ID3D11Device_Release(tmp);
1703 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
1704 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
1705 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
1706 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
1707 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
1708 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
1709 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
1710 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
1711 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
1712 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
1713 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
1714 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
1715 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
1717 refcount = ID3D11SamplerState_Release(sampler_state2);
1718 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1719 refcount = ID3D11SamplerState_Release(sampler_state1);
1720 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
1722 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1724 const struct test *current = &desc_conversion_tests[i];
1725 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
1727 desc.Filter = current->filter;
1728 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
1729 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
1730 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
1731 desc.MipLODBias = 0.0f;
1732 desc.MaxAnisotropy = 16;
1733 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
1734 desc.BorderColor[0] = 0.0f;
1735 desc.BorderColor[1] = 1.0f;
1736 desc.BorderColor[2] = 0.0f;
1737 desc.BorderColor[3] = 1.0f;
1738 desc.MinLOD = 0.0f;
1739 desc.MaxLOD = 16.0f;
1741 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
1742 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
1744 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
1745 (void **)&d3d10_sampler_state);
1746 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1747 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
1748 if (FAILED(hr))
1750 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
1751 ID3D11SamplerState_Release(sampler_state1);
1752 break;
1755 memcpy(&expected_desc, &desc, sizeof(expected_desc));
1756 expected_desc.Filter = current->expected_filter;
1757 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
1758 expected_desc.MaxAnisotropy = 0;
1759 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
1760 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
1762 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
1763 ok(d3d10_desc.Filter == expected_desc.Filter,
1764 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
1765 ok(d3d10_desc.AddressU == expected_desc.AddressU,
1766 "Test %u: Got unexpected adress u %u.\n", i, d3d10_desc.AddressU);
1767 ok(d3d10_desc.AddressV == expected_desc.AddressV,
1768 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
1769 ok(d3d10_desc.AddressW == expected_desc.AddressW,
1770 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
1771 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
1772 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
1773 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
1774 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
1775 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
1776 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
1777 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
1778 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
1779 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
1780 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
1781 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
1782 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
1783 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
1784 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
1785 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
1786 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
1787 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
1789 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
1790 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
1791 refcount = ID3D11SamplerState_Release(sampler_state1);
1792 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
1795 refcount = ID3D11Device_Release(device);
1796 ok(!refcount, "Device has %u references left.\n", refcount);
1799 static void test_create_blend_state(void)
1801 static const D3D11_BLEND_DESC desc_conversion_tests[] =
1804 FALSE, FALSE,
1807 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1808 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
1813 FALSE, TRUE,
1816 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1817 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1820 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1821 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
1824 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1825 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1828 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1829 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
1832 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1833 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1836 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1837 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1840 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1841 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1844 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1845 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1850 FALSE, TRUE,
1853 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1854 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1857 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
1858 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1861 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
1862 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1865 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1866 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1869 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
1870 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1873 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
1874 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1877 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1878 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1881 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
1882 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
1888 ID3D11BlendState *blend_state1, *blend_state2;
1889 D3D11_BLEND_DESC desc, obtained_desc;
1890 ID3D10BlendState *d3d10_blend_state;
1891 D3D10_BLEND_DESC d3d10_blend_desc;
1892 ULONG refcount, expected_refcount;
1893 ID3D11Device *device, *tmp;
1894 unsigned int i, j;
1895 IUnknown *iface;
1896 HRESULT hr;
1898 if (!(device = create_device(NULL)))
1900 skip("Failed to create device.\n");
1901 return;
1904 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
1905 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1907 memset(&desc, 0, sizeof(desc));
1908 desc.AlphaToCoverageEnable = FALSE;
1909 desc.IndependentBlendEnable = FALSE;
1910 desc.RenderTarget[0].BlendEnable = FALSE;
1911 desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
1912 desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
1913 desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
1914 desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
1915 desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
1916 desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
1917 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
1919 expected_refcount = get_refcount((IUnknown *)device) + 1;
1920 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
1921 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
1922 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
1923 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
1924 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
1925 refcount = get_refcount((IUnknown *)device);
1926 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1927 tmp = NULL;
1928 expected_refcount = refcount + 1;
1929 ID3D11BlendState_GetDevice(blend_state1, &tmp);
1930 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1931 refcount = get_refcount((IUnknown *)device);
1932 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1933 ID3D11Device_Release(tmp);
1935 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
1936 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
1937 obtained_desc.AlphaToCoverageEnable);
1938 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
1939 obtained_desc.IndependentBlendEnable);
1940 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1942 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
1943 "Got unexpected blend enable %#x for render target %u.\n",
1944 obtained_desc.RenderTarget[i].BlendEnable, i);
1945 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
1946 "Got unexpected src blend %u for render target %u.\n",
1947 obtained_desc.RenderTarget[i].SrcBlend, i);
1948 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
1949 "Got unexpected dest blend %u for render target %u.\n",
1950 obtained_desc.RenderTarget[i].DestBlend, i);
1951 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
1952 "Got unexpected blend op %u for render target %u.\n",
1953 obtained_desc.RenderTarget[i].BlendOp, i);
1954 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
1955 "Got unexpected src blend alpha %u for render target %u.\n",
1956 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
1957 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
1958 "Got unexpected dest blend alpha %u for render target %u.\n",
1959 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
1960 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
1961 "Got unexpected blend op alpha %u for render target %u.\n",
1962 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
1963 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
1964 "Got unexpected render target write mask %#x for render target %u.\n",
1965 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
1968 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&iface);
1969 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1970 "Blend state should implement ID3D10BlendState.\n");
1971 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1972 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState1, (void **)&iface);
1973 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1974 "Blend state should implement ID3D10BlendState1.\n");
1975 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1977 refcount = ID3D11BlendState_Release(blend_state1);
1978 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
1979 refcount = ID3D11BlendState_Release(blend_state2);
1980 ok(!refcount, "Blend state has %u references left.\n", refcount);
1982 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
1984 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
1986 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
1987 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
1989 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
1990 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1991 "Blend state should implement ID3D10BlendState.\n");
1992 if (FAILED(hr))
1994 win_skip("Blend state does not implement ID3D10BlendState.\n");
1995 ID3D11BlendState_Release(blend_state1);
1996 break;
1999 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
2000 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
2001 "Got unexpected alpha to coverage enable %#x for test %u.\n",
2002 d3d10_blend_desc.AlphaToCoverageEnable, i);
2003 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
2004 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
2005 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
2006 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
2007 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
2008 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
2009 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
2010 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
2011 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
2012 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
2013 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
2014 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
2015 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
2017 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
2018 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
2019 "Got unexpected blend enable %#x for test %u, render target %u.\n",
2020 d3d10_blend_desc.BlendEnable[j], i, j);
2021 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
2022 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
2023 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
2026 ID3D10BlendState_Release(d3d10_blend_state);
2028 refcount = ID3D11BlendState_Release(blend_state1);
2029 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2032 refcount = ID3D11Device_Release(device);
2033 ok(!refcount, "Device has %u references left.\n", refcount);
2036 static void test_create_depthstencil_state(void)
2038 ID3D11DepthStencilState *ds_state1, *ds_state2;
2039 ID3D10DepthStencilState *d3d10_ds_state;
2040 ULONG refcount, expected_refcount;
2041 D3D11_DEPTH_STENCIL_DESC ds_desc;
2042 ID3D11Device *device, *tmp;
2043 HRESULT hr;
2045 if (!(device = create_device(NULL)))
2047 skip("Failed to create device.\n");
2048 return;
2051 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
2052 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2054 ds_desc.DepthEnable = TRUE;
2055 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
2056 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
2057 ds_desc.StencilEnable = FALSE;
2058 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
2059 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
2060 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2061 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2062 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2063 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2064 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
2065 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
2066 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
2067 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
2069 expected_refcount = get_refcount((IUnknown *)device) + 1;
2070 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
2071 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
2072 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
2073 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
2074 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
2075 refcount = get_refcount((IUnknown *)device);
2076 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2077 tmp = NULL;
2078 expected_refcount = refcount + 1;
2079 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
2080 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2081 refcount = get_refcount((IUnknown *)device);
2082 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2083 ID3D11Device_Release(tmp);
2085 hr = ID3D11DepthStencilState_QueryInterface(ds_state1, &IID_ID3D10DepthStencilState, (void **)&d3d10_ds_state);
2086 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2087 "Depth stencil state should implement ID3D10DepthStencilState.\n");
2088 if (SUCCEEDED(hr)) ID3D10DepthStencilState_Release(d3d10_ds_state);
2090 refcount = ID3D11DepthStencilState_Release(ds_state2);
2091 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2092 refcount = ID3D11DepthStencilState_Release(ds_state1);
2093 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2095 refcount = ID3D11Device_Release(device);
2096 ok(!refcount, "Device has %u references left.\n", refcount);
2099 static void test_create_rasterizer_state(void)
2101 ID3D11RasterizerState *rast_state1, *rast_state2;
2102 ID3D10RasterizerState *d3d10_rast_state;
2103 ULONG refcount, expected_refcount;
2104 D3D10_RASTERIZER_DESC d3d10_desc;
2105 D3D11_RASTERIZER_DESC desc;
2106 ID3D11Device *device, *tmp;
2107 HRESULT hr;
2109 if (!(device = create_device(NULL)))
2111 skip("Failed to create device.\n");
2112 return;
2115 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
2116 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2118 desc.FillMode = D3D11_FILL_SOLID;
2119 desc.CullMode = D3D11_CULL_BACK;
2120 desc.FrontCounterClockwise = FALSE;
2121 desc.DepthBias = 0;
2122 desc.DepthBiasClamp = 0.0f;
2123 desc.SlopeScaledDepthBias = 0.0f;
2124 desc.DepthClipEnable = TRUE;
2125 desc.ScissorEnable = FALSE;
2126 desc.MultisampleEnable = FALSE;
2127 desc.AntialiasedLineEnable = FALSE;
2129 expected_refcount = get_refcount((IUnknown *)device) + 1;
2130 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
2131 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
2132 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
2133 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
2134 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
2135 refcount = get_refcount((IUnknown *)device);
2136 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2137 tmp = NULL;
2138 expected_refcount = refcount + 1;
2139 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
2140 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2141 refcount = get_refcount((IUnknown *)device);
2142 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2143 ID3D11Device_Release(tmp);
2145 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
2146 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2147 "Rasterizer state should implement ID3D10RasterizerState.\n");
2148 if (SUCCEEDED(hr))
2150 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
2151 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
2152 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
2153 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
2154 d3d10_desc.FrontCounterClockwise);
2155 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
2156 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
2157 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
2158 d3d10_desc.SlopeScaledDepthBias);
2159 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
2160 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
2161 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
2162 d3d10_desc.MultisampleEnable);
2163 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
2164 d3d10_desc.AntialiasedLineEnable);
2166 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
2167 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
2170 refcount = ID3D11RasterizerState_Release(rast_state2);
2171 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2172 refcount = ID3D11RasterizerState_Release(rast_state1);
2173 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2175 refcount = ID3D11Device_Release(device);
2176 ok(!refcount, "Device has %u references left.\n", refcount);
2179 static void test_device_removed_reason(void)
2181 ID3D11Device *device;
2182 ULONG refcount;
2183 HRESULT hr;
2185 if (!(device = create_device(NULL)))
2187 skip("Failed to create device.\n");
2188 return;
2191 hr = ID3D11Device_GetDeviceRemovedReason(device);
2192 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2193 hr = ID3D11Device_GetDeviceRemovedReason(device);
2194 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2196 refcount = ID3D11Device_Release(device);
2197 ok(!refcount, "Device has %u references left.\n", refcount);
2200 static void test_private_data(void)
2202 ULONG refcount, expected_refcount;
2203 D3D11_TEXTURE2D_DESC texture_desc;
2204 ID3D10Texture2D *d3d10_texture;
2205 ID3D11Device *test_object;
2206 ID3D11Texture2D *texture;
2207 IDXGIDevice *dxgi_device;
2208 IDXGISurface *surface;
2209 ID3D11Device *device;
2210 IUnknown *ptr;
2211 HRESULT hr;
2212 UINT size;
2214 static const GUID test_guid =
2215 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
2216 static const GUID test_guid2 =
2217 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
2218 static const DWORD data[] = {1, 2, 3, 4};
2220 if (!(device = create_device(NULL)))
2222 skip("Failed to create device.\n");
2223 return;
2226 test_object = create_device(NULL);
2228 texture_desc.Width = 512;
2229 texture_desc.Height = 512;
2230 texture_desc.MipLevels = 1;
2231 texture_desc.ArraySize = 1;
2232 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2233 texture_desc.SampleDesc.Count = 1;
2234 texture_desc.SampleDesc.Quality = 0;
2235 texture_desc.Usage = D3D11_USAGE_DEFAULT;
2236 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2237 texture_desc.CPUAccessFlags = 0;
2238 texture_desc.MiscFlags = 0;
2240 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
2241 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
2242 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
2243 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
2245 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
2246 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2247 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
2248 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2249 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
2250 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2251 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
2252 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2254 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
2255 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2256 size = sizeof(ptr) * 2;
2257 ptr = (IUnknown *)0xdeadbeef;
2258 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
2259 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2260 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
2261 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
2263 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
2264 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
2265 size = sizeof(ptr) * 2;
2266 ptr = (IUnknown *)0xdeadbeef;
2267 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
2268 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2269 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
2270 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
2271 IDXGIDevice_Release(dxgi_device);
2273 refcount = get_refcount((IUnknown *)test_object);
2274 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
2275 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2276 expected_refcount = refcount + 1;
2277 refcount = get_refcount((IUnknown *)test_object);
2278 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2279 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
2280 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2281 refcount = get_refcount((IUnknown *)test_object);
2282 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2284 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
2285 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2286 --expected_refcount;
2287 refcount = get_refcount((IUnknown *)test_object);
2288 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2290 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
2291 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2292 size = sizeof(data);
2293 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
2294 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2295 refcount = get_refcount((IUnknown *)test_object);
2296 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2297 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
2298 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2299 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
2300 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2302 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
2303 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2304 ++expected_refcount;
2305 size = 2 * sizeof(ptr);
2306 ptr = NULL;
2307 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
2308 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2309 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
2310 ++expected_refcount;
2311 refcount = get_refcount((IUnknown *)test_object);
2312 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2313 IUnknown_Release(ptr);
2314 --expected_refcount;
2316 ptr = (IUnknown *)0xdeadbeef;
2317 size = 1;
2318 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
2319 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2320 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2321 size = 2 * sizeof(ptr);
2322 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
2323 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2324 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2325 refcount = get_refcount((IUnknown *)test_object);
2326 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2328 size = 1;
2329 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
2330 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
2331 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
2332 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2333 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
2334 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2335 size = 0xdeadbabe;
2336 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
2337 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
2338 ok(size == 0, "Got unexpected size %u.\n", size);
2339 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2340 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
2341 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2342 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
2344 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
2345 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2346 ptr = NULL;
2347 size = sizeof(ptr);
2348 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
2349 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2350 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
2351 IUnknown_Release(ptr);
2353 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2354 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
2355 "Texture should implement ID3D10Texture2D.\n");
2356 if (SUCCEEDED(hr))
2358 ptr = NULL;
2359 size = sizeof(ptr);
2360 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
2361 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2362 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
2363 IUnknown_Release(ptr);
2364 ID3D10Texture2D_Release(d3d10_texture);
2367 IDXGISurface_Release(surface);
2368 ID3D11Texture2D_Release(texture);
2369 refcount = ID3D11Device_Release(device);
2370 ok(!refcount, "Device has %u references left.\n", refcount);
2371 refcount = ID3D11Device_Release(test_object);
2372 ok(!refcount, "Test object has %u references left.\n", refcount);
2375 START_TEST(d3d11)
2377 test_create_device();
2378 test_device_interfaces();
2379 test_get_immediate_context();
2380 test_create_texture2d();
2381 test_texture2d_interfaces();
2382 test_create_texture3d();
2383 test_texture3d_interfaces();
2384 test_buffer_interfaces();
2385 test_create_depthstencil_view();
2386 test_depthstencil_view_interfaces();
2387 test_create_rendertarget_view();
2388 test_create_shader_resource_view();
2389 test_create_shader();
2390 test_create_sampler_state();
2391 test_create_blend_state();
2392 test_create_depthstencil_state();
2393 test_create_rasterizer_state();
2394 test_device_removed_reason();
2395 test_private_data();