d3d11/tests: Port test_create_shader_resource_view() from d3d10core.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob8bf31dc3b589f460e0bb65ce1fb1ce40a8420a03
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 ULONG get_refcount(IUnknown *iface)
27 IUnknown_AddRef(iface);
28 return IUnknown_Release(iface);
31 static ID3D11Device *create_device(const D3D_FEATURE_LEVEL *feature_level)
33 ID3D11Device *device;
34 UINT feature_level_count = feature_level ? 1 : 0;
36 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, feature_level, feature_level_count,
37 D3D11_SDK_VERSION, &device, NULL, NULL)))
38 return device;
39 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, 0, feature_level, feature_level_count,
40 D3D11_SDK_VERSION, &device, NULL, NULL)))
41 return device;
42 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, 0, feature_level, feature_level_count,
43 D3D11_SDK_VERSION, &device, NULL, NULL)))
44 return device;
46 return NULL;
49 static void test_create_device(void)
51 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
52 ID3D11DeviceContext *immediate_context = NULL;
53 ID3D11Device *device;
54 ULONG refcount;
55 HRESULT hr;
57 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, &device,
58 NULL, NULL);
59 if (FAILED(hr))
61 skip("Failed to create HAL device, skipping tests.\n");
62 return;
65 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
66 ID3D11Device_Release(device);
68 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
69 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
71 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
72 &feature_level, NULL);
73 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
74 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
75 feature_level, supported_feature_level);
77 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
78 &immediate_context);
79 ok(SUCCEEDED(hr), "D3D11CreateDevice failed %#x.\n", hr);
81 todo_wine ok(!!immediate_context, "Immediate context is NULL.\n");
82 if (!immediate_context) return;
84 refcount = get_refcount((IUnknown *)immediate_context);
85 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
87 ID3D11DeviceContext_GetDevice(immediate_context, &device);
88 refcount = ID3D11Device_Release(device);
89 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
91 refcount = ID3D11DeviceContext_Release(immediate_context);
92 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
95 static void test_device_interfaces(void)
97 static const D3D_FEATURE_LEVEL feature_levels[] =
99 D3D_FEATURE_LEVEL_11_1,
100 D3D_FEATURE_LEVEL_11_0,
101 D3D_FEATURE_LEVEL_10_1,
102 D3D_FEATURE_LEVEL_10_0,
103 D3D_FEATURE_LEVEL_9_3,
104 D3D_FEATURE_LEVEL_9_2,
105 D3D_FEATURE_LEVEL_9_1
107 ID3D11Device *device;
108 IUnknown *iface;
109 ULONG refcount;
110 unsigned int i;
111 HRESULT hr;
113 for (i = 0; i < sizeof(feature_levels) / sizeof(*feature_levels); i++)
115 if (!(device = create_device(&feature_levels[i])))
117 skip("Failed to create device for feature level %#x, skipping tests.\n", feature_levels[i]);
118 continue;
121 hr = ID3D11Device_QueryInterface(device, &IID_IUnknown, (void **)&iface);
122 ok(SUCCEEDED(hr), "Device should implement IUnknown interface, hr %#x.\n", hr);
123 IUnknown_Release(iface);
125 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIObject, (void **)&iface);
126 ok(SUCCEEDED(hr), "Device should implement IDXGIObject interface, hr %#x.\n", hr);
127 IUnknown_Release(iface);
129 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&iface);
130 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice interface, hr %#x.\n", hr);
131 IUnknown_Release(iface);
133 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Multithread, (void **)&iface);
134 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
135 "Device should implement ID3D10Multithread interface, hr %#x.\n", hr);
136 if (SUCCEEDED(hr)) IUnknown_Release(iface);
138 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device, (void **)&iface);
139 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device interface, hr %#x.\n", hr);
140 if (SUCCEEDED(hr)) IUnknown_Release(iface);
142 hr = ID3D11Device_QueryInterface(device, &IID_ID3D10Device1, (void **)&iface);
143 todo_wine ok(hr == E_NOINTERFACE, "Device should not implement ID3D10Device1 interface, hr %#x.\n", hr);
144 if (SUCCEEDED(hr)) IUnknown_Release(iface);
146 refcount = ID3D11Device_Release(device);
147 ok(!refcount, "Device has %u references left.\n", refcount);
151 static void test_create_texture2d(void)
153 ULONG refcount, expected_refcount;
154 D3D11_SUBRESOURCE_DATA data = {0};
155 ID3D11Device *device, *tmp;
156 D3D11_TEXTURE2D_DESC desc;
157 ID3D11Texture2D *texture;
158 IDXGISurface *surface;
159 HRESULT hr;
161 if (!(device = create_device(NULL)))
163 skip("Failed to create device, skipping tests.\n");
164 return;
167 desc.Width = 512;
168 desc.Height = 512;
169 desc.MipLevels = 1;
170 desc.ArraySize = 1;
171 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
172 desc.SampleDesc.Count = 1;
173 desc.SampleDesc.Quality = 0;
174 desc.Usage = D3D11_USAGE_DEFAULT;
175 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
176 desc.CPUAccessFlags = 0;
177 desc.MiscFlags = 0;
179 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
180 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
182 expected_refcount = get_refcount((IUnknown *)device) + 1;
183 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
184 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
185 refcount = get_refcount((IUnknown *)device);
186 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
187 tmp = NULL;
188 expected_refcount = refcount + 1;
189 ID3D11Texture2D_GetDevice(texture, &tmp);
190 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
191 refcount = get_refcount((IUnknown *)device);
192 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
193 ID3D11Device_Release(tmp);
195 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
196 ok(SUCCEEDED(hr), "Texture should implement IDXGISurface.\n");
197 IDXGISurface_Release(surface);
198 ID3D11Texture2D_Release(texture);
200 desc.MipLevels = 0;
201 expected_refcount = get_refcount((IUnknown *)device) + 1;
202 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
203 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
204 refcount = get_refcount((IUnknown *)device);
205 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
206 tmp = NULL;
207 expected_refcount = refcount + 1;
208 ID3D11Texture2D_GetDevice(texture, &tmp);
209 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
210 refcount = get_refcount((IUnknown *)device);
211 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
212 ID3D11Device_Release(tmp);
214 ID3D11Texture2D_GetDesc(texture, &desc);
215 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
216 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
217 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
218 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
219 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
220 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
221 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
222 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
223 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
224 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
225 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
227 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
228 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
229 ID3D11Texture2D_Release(texture);
231 desc.MipLevels = 1;
232 desc.ArraySize = 2;
233 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
234 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
236 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
237 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
238 ID3D11Texture2D_Release(texture);
240 refcount = ID3D11Device_Release(device);
241 ok(!refcount, "Device has %u references left.\n", refcount);
244 static void test_texture2d_interfaces(void)
246 ID3D10Texture2D *d3d10_texture;
247 D3D11_TEXTURE2D_DESC desc;
248 ID3D11Texture2D *texture;
249 IDXGISurface *surface;
250 ID3D11Device *device;
251 unsigned int i;
252 ULONG refcount;
253 HRESULT hr;
255 static const struct test
257 BOOL implements_d3d10_interfaces;
258 UINT bind_flags;
259 UINT misc_flags;
260 UINT expected_bind_flags;
261 UINT expected_misc_flags;
263 desc_conversion_tests[] =
266 TRUE,
267 D3D11_BIND_SHADER_RESOURCE, 0,
268 D3D10_BIND_SHADER_RESOURCE, 0
271 TRUE,
272 D3D11_BIND_UNORDERED_ACCESS, 0,
273 D3D11_BIND_UNORDERED_ACCESS, 0
276 FALSE,
277 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
278 0, 0
281 TRUE,
282 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
283 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
286 TRUE,
287 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
288 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
292 if (!(device = create_device(NULL)))
294 skip("Failed to create ID3D11Device, skipping tests.\n");
295 return;
298 desc.Width = 512;
299 desc.Height = 512;
300 desc.MipLevels = 0;
301 desc.ArraySize = 1;
302 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
303 desc.SampleDesc.Count = 1;
304 desc.SampleDesc.Quality = 0;
305 desc.Usage = D3D11_USAGE_DEFAULT;
306 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
307 desc.CPUAccessFlags = 0;
308 desc.MiscFlags = 0;
310 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
311 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
313 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
314 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
316 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
317 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
318 "Texture should implement ID3D10Texture2D.\n");
319 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
320 ID3D11Texture2D_Release(texture);
322 if (FAILED(hr))
324 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
325 ID3D11Device_Release(device);
326 return;
329 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
331 const struct test *current = &desc_conversion_tests[i];
332 D3D10_TEXTURE2D_DESC d3d10_desc;
333 ID3D10Device *d3d10_device;
335 desc.Width = 512;
336 desc.Height = 512;
337 desc.MipLevels = 1;
338 desc.ArraySize = 1;
339 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
340 desc.SampleDesc.Count = 1;
341 desc.SampleDesc.Quality = 0;
342 desc.Usage = D3D11_USAGE_DEFAULT;
343 desc.BindFlags = current->bind_flags;
344 desc.CPUAccessFlags = 0;
345 desc.MiscFlags = current->misc_flags;
347 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
348 /* Shared resources are not supported by REF and WARP devices. */
349 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
350 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
351 if (FAILED(hr))
353 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
354 continue;
357 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
358 ok(SUCCEEDED(hr), "Test %u: Texture should implement IDXGISurface.\n", i);
359 IDXGISurface_Release(surface);
361 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
362 ID3D11Texture2D_Release(texture);
364 if (current->implements_d3d10_interfaces)
366 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
368 else
370 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
371 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
372 continue;
375 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
377 ok(d3d10_desc.Width == desc.Width,
378 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
379 ok(d3d10_desc.Height == desc.Height,
380 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
381 ok(d3d10_desc.MipLevels == desc.MipLevels,
382 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
383 ok(d3d10_desc.ArraySize == desc.ArraySize,
384 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
385 ok(d3d10_desc.Format == desc.Format,
386 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
387 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
388 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
389 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
390 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
391 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
392 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
393 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
394 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
395 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
396 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
397 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
398 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
400 d3d10_device = (ID3D10Device *)0xdeadbeef;
401 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
402 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
403 if (d3d10_device) ID3D10Device_Release(d3d10_device);
405 ID3D10Texture2D_Release(d3d10_texture);
408 refcount = ID3D11Device_Release(device);
409 ok(!refcount, "Device has %u references left.\n", refcount);
412 static void test_create_texture3d(void)
414 ULONG refcount, expected_refcount;
415 D3D11_SUBRESOURCE_DATA data = {0};
416 ID3D11Device *device, *tmp;
417 D3D11_TEXTURE3D_DESC desc;
418 ID3D11Texture3D *texture;
419 IDXGISurface *surface;
420 HRESULT hr;
422 if (!(device = create_device(NULL)))
424 skip("Failed to create ID3D11Device, skipping tests.\n");
425 return;
428 desc.Width = 64;
429 desc.Height = 64;
430 desc.Depth = 64;
431 desc.MipLevels = 1;
432 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
433 desc.Usage = D3D11_USAGE_DEFAULT;
434 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
435 desc.CPUAccessFlags = 0;
436 desc.MiscFlags = 0;
438 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
439 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
441 expected_refcount = get_refcount((IUnknown *)device) + 1;
442 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
443 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
444 refcount = get_refcount((IUnknown *)device);
445 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
446 tmp = NULL;
447 expected_refcount = refcount + 1;
448 ID3D11Texture3D_GetDevice(texture, &tmp);
449 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
450 refcount = get_refcount((IUnknown *)device);
451 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
452 ID3D11Device_Release(tmp);
454 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
455 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
456 ID3D11Texture3D_Release(texture);
458 desc.MipLevels = 0;
459 expected_refcount = get_refcount((IUnknown *)device) + 1;
460 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
461 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
462 refcount = get_refcount((IUnknown *)device);
463 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
464 tmp = NULL;
465 expected_refcount = refcount + 1;
466 ID3D11Texture3D_GetDevice(texture, &tmp);
467 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
468 refcount = get_refcount((IUnknown *)device);
469 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
470 ID3D11Device_Release(tmp);
472 ID3D11Texture3D_GetDesc(texture, &desc);
473 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
474 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
475 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
476 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
477 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
478 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
479 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
480 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
481 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
483 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
484 ok(FAILED(hr), "Texture should not implement IDXGISurface.\n");
485 ID3D11Texture3D_Release(texture);
487 refcount = ID3D11Device_Release(device);
488 ok(!refcount, "Device has %u references left.\n", refcount);
491 static void test_texture3d_interfaces(void)
493 ID3D10Texture3D *d3d10_texture;
494 D3D11_TEXTURE3D_DESC desc;
495 ID3D11Texture3D *texture;
496 IDXGISurface *surface;
497 ID3D11Device *device;
498 unsigned int i;
499 ULONG refcount;
500 HRESULT hr;
502 static const struct test
504 BOOL implements_d3d10_interfaces;
505 UINT bind_flags;
506 UINT misc_flags;
507 UINT expected_bind_flags;
508 UINT expected_misc_flags;
510 desc_conversion_tests[] =
513 TRUE,
514 D3D11_BIND_SHADER_RESOURCE, 0,
515 D3D10_BIND_SHADER_RESOURCE, 0
518 TRUE,
519 D3D11_BIND_UNORDERED_ACCESS, 0,
520 D3D11_BIND_UNORDERED_ACCESS, 0
523 FALSE,
524 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
525 0, 0
528 TRUE,
529 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
530 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
534 if (!(device = create_device(NULL)))
536 skip("Failed to create ID3D11Device.\n");
537 return;
540 desc.Width = 64;
541 desc.Height = 64;
542 desc.Depth = 64;
543 desc.MipLevels = 0;
544 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
545 desc.Usage = D3D11_USAGE_DEFAULT;
546 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
547 desc.CPUAccessFlags = 0;
548 desc.MiscFlags = 0;
550 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
551 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
553 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
554 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
556 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
557 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
558 "Texture should implement ID3D10Texture3D.\n");
559 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
560 ID3D11Texture3D_Release(texture);
562 if (FAILED(hr))
564 win_skip("3D textures do not implement ID3D10Texture3D.\n");
565 ID3D11Device_Release(device);
566 return;
569 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
571 const struct test *current = &desc_conversion_tests[i];
572 D3D10_TEXTURE3D_DESC d3d10_desc;
573 ID3D10Device *d3d10_device;
575 desc.Width = 64;
576 desc.Height = 64;
577 desc.Depth = 64;
578 desc.MipLevels = 1;
579 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
580 desc.Usage = D3D11_USAGE_DEFAULT;
581 desc.BindFlags = current->bind_flags;
582 desc.CPUAccessFlags = 0;
583 desc.MiscFlags = current->misc_flags;
585 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
586 /* Shared resources are not supported by REF and WARP devices. */
587 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
588 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
589 if (FAILED(hr))
591 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
592 continue;
595 hr = ID3D11Texture3D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
596 ok(hr == E_NOINTERFACE, "Texture should not implement IDXGISurface.\n");
598 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
599 ID3D11Texture3D_Release(texture);
601 if (current->implements_d3d10_interfaces)
603 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
605 else
607 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
608 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
609 continue;
612 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
614 ok(d3d10_desc.Width == desc.Width,
615 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
616 ok(d3d10_desc.Height == desc.Height,
617 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
618 ok(d3d10_desc.Depth == desc.Depth,
619 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
620 ok(d3d10_desc.MipLevels == desc.MipLevels,
621 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
622 ok(d3d10_desc.Format == desc.Format,
623 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
624 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
625 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
626 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
627 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
628 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
629 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
630 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
631 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
633 d3d10_device = (ID3D10Device *)0xdeadbeef;
634 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
635 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
636 if (d3d10_device) ID3D10Device_Release(d3d10_device);
638 ID3D10Texture3D_Release(d3d10_texture);
641 refcount = ID3D11Device_Release(device);
642 ok(!refcount, "Device has %u references left.\n", refcount);
645 static void test_buffer_interfaces(void)
647 ID3D10Buffer *d3d10_buffer;
648 D3D11_BUFFER_DESC desc;
649 ID3D11Buffer *buffer;
650 ID3D11Device *device;
651 unsigned int i;
652 ULONG refcount;
653 HRESULT hr;
655 static const struct test
657 BOOL implements_d3d10_interfaces;
658 UINT bind_flags;
659 UINT misc_flags;
660 UINT structure_stride;
661 UINT expected_bind_flags;
662 UINT expected_misc_flags;
664 desc_conversion_tests[] =
667 TRUE,
668 D3D11_BIND_VERTEX_BUFFER, 0, 0,
669 D3D10_BIND_VERTEX_BUFFER, 0
672 TRUE,
673 D3D11_BIND_INDEX_BUFFER, 0, 0,
674 D3D10_BIND_INDEX_BUFFER, 0
677 TRUE,
678 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
679 D3D10_BIND_CONSTANT_BUFFER, 0
682 TRUE,
683 D3D11_BIND_SHADER_RESOURCE, 0, 0,
684 D3D10_BIND_SHADER_RESOURCE, 0
687 TRUE,
688 D3D11_BIND_STREAM_OUTPUT, 0, 0,
689 D3D10_BIND_STREAM_OUTPUT, 0
692 TRUE,
693 D3D11_BIND_RENDER_TARGET, 0, 0,
694 D3D10_BIND_RENDER_TARGET, 0
697 TRUE,
698 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
699 D3D11_BIND_UNORDERED_ACCESS, 0
702 TRUE,
703 0, D3D11_RESOURCE_MISC_SHARED, 0,
704 0, D3D10_RESOURCE_MISC_SHARED
707 TRUE,
708 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
709 0, 0
712 TRUE,
713 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
714 D3D10_BIND_SHADER_RESOURCE, 0
717 FALSE /* Structured buffers do not implement ID3D10Buffer. */,
718 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
719 0, 0
722 TRUE,
723 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
724 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
728 if (!(device = create_device(NULL)))
730 skip("Failed to create ID3D11Device.\n");
731 return;
734 desc.ByteWidth = 1024;
735 desc.Usage = D3D11_USAGE_DEFAULT;
736 desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
737 desc.CPUAccessFlags = 0;
738 desc.MiscFlags = 0;
739 desc.StructureByteStride = 0;
741 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
742 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
744 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
745 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
746 "Buffer should implement ID3D10Buffer.\n");
747 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
748 ID3D11Buffer_Release(buffer);
750 if (FAILED(hr))
752 win_skip("Buffers do not implement ID3D10Buffer.\n");
753 ID3D11Device_Release(device);
754 return;
757 for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i)
759 const struct test *current = &desc_conversion_tests[i];
760 D3D10_BUFFER_DESC d3d10_desc;
761 ID3D10Device *d3d10_device;
763 desc.ByteWidth = 1024;
764 desc.Usage = D3D11_USAGE_DEFAULT;
765 desc.BindFlags = current->bind_flags;
766 desc.CPUAccessFlags = 0;
767 desc.MiscFlags = current->misc_flags;
768 desc.StructureByteStride = current->structure_stride;
770 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
771 /* Shared resources are not supported by REF and WARP devices. */
772 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY), "Test %u: Failed to create a buffer, hr %#x.\n", i, hr);
773 if (FAILED(hr))
775 win_skip("Failed to create a buffer, skipping test %u.\n", i);
776 continue;
779 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
780 ID3D11Buffer_Release(buffer);
782 if (current->implements_d3d10_interfaces)
784 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
786 else
788 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
789 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
790 continue;
793 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
795 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
796 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
797 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
798 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
799 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
800 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
801 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
802 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
803 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
804 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
806 d3d10_device = (ID3D10Device *)0xdeadbeef;
807 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
808 todo_wine ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
809 if (d3d10_device) ID3D10Device_Release(d3d10_device);
811 ID3D10Buffer_Release(d3d10_buffer);
814 refcount = ID3D11Device_Release(device);
815 ok(!refcount, "Device has %u references left.\n", refcount);
818 static void test_depthstencil_view_interfaces(void)
820 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
821 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
822 ID3D10DepthStencilView *d3d10_dsview;
823 D3D11_TEXTURE2D_DESC texture_desc;
824 ID3D11DepthStencilView *dsview;
825 ID3D11Texture2D *texture;
826 ID3D11Device *device;
827 ULONG refcount;
828 HRESULT hr;
830 if (!(device = create_device(NULL)))
832 skip("Failed to create device.\n");
833 return;
836 texture_desc.Width = 512;
837 texture_desc.Height = 512;
838 texture_desc.MipLevels = 1;
839 texture_desc.ArraySize = 1;
840 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
841 texture_desc.SampleDesc.Count = 1;
842 texture_desc.SampleDesc.Quality = 0;
843 texture_desc.Usage = D3D11_USAGE_DEFAULT;
844 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
845 texture_desc.CPUAccessFlags = 0;
846 texture_desc.MiscFlags = 0;
848 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
849 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
851 dsv_desc.Format = texture_desc.Format;
852 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
853 dsv_desc.Flags = 0;
854 U(dsv_desc).Texture2D.MipSlice = 0;
856 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
857 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
859 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
860 ID3D11DepthStencilView_Release(dsview);
861 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
862 "Depth stencil view should implement ID3D10DepthStencilView.\n");
864 if (FAILED(hr))
866 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
867 goto done;
870 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
871 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
872 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
873 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
874 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
875 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
877 ID3D10DepthStencilView_Release(d3d10_dsview);
879 done:
880 ID3D11Texture2D_Release(texture);
882 refcount = ID3D11Device_Release(device);
883 ok(!refcount, "Device has %u references left.\n", refcount);
886 static void test_create_rendertarget_view(void)
888 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
889 D3D11_SUBRESOURCE_DATA data = {0};
890 D3D11_TEXTURE2D_DESC texture_desc;
891 ULONG refcount, expected_refcount;
892 D3D11_BUFFER_DESC buffer_desc;
893 ID3D11RenderTargetView *rtview;
894 ID3D11Device *device, *tmp;
895 ID3D11Texture2D *texture;
896 ID3D11Buffer *buffer;
897 IUnknown *iface;
898 HRESULT hr;
900 if (!(device = create_device(NULL)))
902 skip("Failed to create device.\n");
903 return;
906 buffer_desc.ByteWidth = 1024;
907 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
908 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
909 buffer_desc.CPUAccessFlags = 0;
910 buffer_desc.MiscFlags = 0;
911 buffer_desc.StructureByteStride = 0;
913 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
914 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
916 expected_refcount = get_refcount((IUnknown *)device) + 1;
917 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
918 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
919 refcount = get_refcount((IUnknown *)device);
920 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
921 tmp = NULL;
922 expected_refcount = refcount + 1;
923 ID3D11Buffer_GetDevice(buffer, &tmp);
924 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
925 refcount = get_refcount((IUnknown *)device);
926 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
927 ID3D11Device_Release(tmp);
929 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
930 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
931 U(rtv_desc).Buffer.ElementOffset = 0;
932 U(rtv_desc).Buffer.ElementWidth = 64;
934 expected_refcount = get_refcount((IUnknown *)device) + 1;
935 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
936 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
937 refcount = get_refcount((IUnknown *)device);
938 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
939 tmp = NULL;
940 expected_refcount = refcount + 1;
941 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
942 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
943 refcount = get_refcount((IUnknown *)device);
944 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
945 ID3D11Device_Release(tmp);
947 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
948 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
949 "Render target view should implement ID3D10RenderTargetView.\n");
950 if (SUCCEEDED(hr)) IUnknown_Release(iface);
952 ID3D11RenderTargetView_Release(rtview);
953 ID3D11Buffer_Release(buffer);
955 texture_desc.Width = 512;
956 texture_desc.Height = 512;
957 texture_desc.MipLevels = 1;
958 texture_desc.ArraySize = 1;
959 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
960 texture_desc.SampleDesc.Count = 1;
961 texture_desc.SampleDesc.Quality = 0;
962 texture_desc.Usage = D3D11_USAGE_DEFAULT;
963 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
964 texture_desc.CPUAccessFlags = 0;
965 texture_desc.MiscFlags = 0;
967 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
968 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
970 /* For texture resources it's allowed to specify NULL as desc */
971 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtview);
972 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
974 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
975 ok(rtv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", rtv_desc.Format);
976 ok(rtv_desc.ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D, "Got unexpected view dimension %#x.\n",
977 rtv_desc.ViewDimension);
978 ok(U(rtv_desc).Texture2D.MipSlice == 0, "Got unexpected mip slice %#x.\n", U(rtv_desc).Texture2D.MipSlice);
980 hr = ID3D11RenderTargetView_QueryInterface(rtview, &IID_ID3D10RenderTargetView, (void **)&iface);
981 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
982 "Render target view should implement ID3D10RenderTargetView.\n");
983 if (SUCCEEDED(hr)) IUnknown_Release(iface);
985 ID3D11RenderTargetView_Release(rtview);
986 ID3D11Texture2D_Release(texture);
988 refcount = ID3D11Device_Release(device);
989 ok(!refcount, "Device has %u references left.\n", refcount);
992 static void test_create_shader_resource_view(void)
994 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
995 D3D11_TEXTURE2D_DESC texture_desc;
996 ULONG refcount, expected_refcount;
997 ID3D11ShaderResourceView *srview;
998 D3D11_BUFFER_DESC buffer_desc;
999 ID3D11Device *device, *tmp;
1000 ID3D11Texture2D *texture;
1001 ID3D11Buffer *buffer;
1002 IUnknown *iface;
1003 HRESULT hr;
1005 if (!(device = create_device(NULL)))
1007 skip("Failed to create device.\n");
1008 return;
1011 buffer_desc.ByteWidth = 1024;
1012 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
1013 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1014 buffer_desc.CPUAccessFlags = 0;
1015 buffer_desc.MiscFlags = 0;
1016 buffer_desc.StructureByteStride = 0;
1018 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
1019 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
1021 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
1022 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
1024 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
1025 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
1026 U(srv_desc).Buffer.ElementOffset = 0;
1027 U(srv_desc).Buffer.ElementWidth = 64;
1029 expected_refcount = get_refcount((IUnknown *)device) + 1;
1030 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
1031 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
1032 refcount = get_refcount((IUnknown *)device);
1033 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
1034 tmp = NULL;
1035 expected_refcount = refcount + 1;
1036 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
1037 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
1038 refcount = get_refcount((IUnknown *)device);
1039 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
1040 ID3D11Device_Release(tmp);
1042 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
1043 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1044 "Shader resource view should implement ID3D10ShaderResourceView.\n");
1045 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1047 ID3D11ShaderResourceView_Release(srview);
1048 ID3D11Buffer_Release(buffer);
1050 texture_desc.Width = 512;
1051 texture_desc.Height = 512;
1052 texture_desc.MipLevels = 0;
1053 texture_desc.ArraySize = 1;
1054 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1055 texture_desc.SampleDesc.Count = 1;
1056 texture_desc.SampleDesc.Quality = 0;
1057 texture_desc.Usage = D3D11_USAGE_DEFAULT;
1058 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
1059 texture_desc.CPUAccessFlags = 0;
1060 texture_desc.MiscFlags = 0;
1062 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
1063 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
1065 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srview);
1066 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
1068 hr = ID3D11ShaderResourceView_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface);
1069 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
1070 "Shader resource view should implement ID3D10ShaderResourceView.\n");
1071 if (SUCCEEDED(hr)) IUnknown_Release(iface);
1073 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
1074 ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format);
1075 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D,
1076 "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension);
1077 ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n",
1078 U(srv_desc).Texture2D.MostDetailedMip);
1079 ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels);
1081 ID3D11ShaderResourceView_Release(srview);
1082 ID3D11Texture2D_Release(texture);
1084 refcount = ID3D11Device_Release(device);
1085 ok(!refcount, "Device has %u references left.\n", refcount);
1088 START_TEST(d3d11)
1090 test_create_device();
1091 test_device_interfaces();
1092 test_create_texture2d();
1093 test_texture2d_interfaces();
1094 test_create_texture3d();
1095 test_texture3d_interfaces();
1096 test_buffer_interfaces();
1097 test_depthstencil_view_interfaces();
1098 test_create_rendertarget_view();
1099 test_create_shader_resource_view();