d3d11: Always initialize out view pointer in CreateShaderResourceView().
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob1db367f39fa645921a4a8fccdf71fe0c32b43cc5
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 #include <assert.h>
21 #include <float.h>
22 #include <limits.h>
23 #include <math.h>
24 #include <stdlib.h>
25 #define COBJMACROS
26 #include "initguid.h"
27 #include "d3d11_4.h"
28 #include "wine/heap.h"
29 #include "wine/test.h"
31 #define BITS_NNAN 0xffc00000
32 #define BITS_NAN 0x7fc00000
33 #define BITS_NINF 0xff800000
34 #define BITS_INF 0x7f800000
35 #define BITS_N1_0 0xbf800000
36 #define BITS_1_0 0x3f800000
38 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
40 static unsigned int use_adapter_idx;
41 static BOOL enable_debug_layer;
42 static BOOL use_warp_adapter;
43 static BOOL use_mt = TRUE;
45 static struct test_entry
47 union
49 void (*test)(void);
50 void (*test_fl)(D3D_FEATURE_LEVEL fl);
51 } u;
52 D3D_FEATURE_LEVEL fl;
53 } *mt_tests;
54 size_t mt_tests_size, mt_test_count;
56 struct format_support
58 DXGI_FORMAT format;
59 D3D_FEATURE_LEVEL fl_required;
60 D3D_FEATURE_LEVEL fl_optional;
63 static const struct format_support display_format_support[] =
65 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
66 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
67 {DXGI_FORMAT_B8G8R8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
68 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
69 {DXGI_FORMAT_R16G16B16A16_FLOAT, D3D_FEATURE_LEVEL_10_0},
70 {DXGI_FORMAT_R10G10B10A2_UNORM, D3D_FEATURE_LEVEL_10_0},
71 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0},
74 struct vec2
76 float x, y;
79 struct vec3
81 float x, y, z;
84 struct vec4
86 float x, y, z, w;
89 struct ivec4
91 int x, y, z, w;
94 struct uvec4
96 unsigned int x, y, z, w;
99 struct device_desc
101 const D3D_FEATURE_LEVEL *feature_level;
102 UINT flags;
105 struct resource_desc
107 D3D11_RESOURCE_DIMENSION dimension;
108 unsigned int width;
109 unsigned int height;
110 unsigned int depth_or_array_size;
111 unsigned int level_count;
112 DXGI_FORMAT format;
113 DXGI_SAMPLE_DESC sample_desc;
114 D3D11_USAGE usage;
115 unsigned int bind_flags;
116 unsigned int cpu_access_flags;
117 unsigned int misc_flags;
118 unsigned int structure_byte_stride;
121 struct swapchain_desc
123 BOOL windowed;
124 unsigned buffer_count;
125 unsigned int width, height;
126 DXGI_SWAP_EFFECT swap_effect;
127 DWORD flags;
130 static void queue_test_entry(const struct test_entry *t)
132 if (mt_test_count >= mt_tests_size)
134 mt_tests_size = max(16, mt_tests_size * 2);
135 mt_tests = heap_realloc(mt_tests, mt_tests_size * sizeof(*t));
137 mt_tests[mt_test_count++] = *t;
140 static void queue_test_fl(void (*test)(const D3D_FEATURE_LEVEL fl), D3D_FEATURE_LEVEL fl)
142 struct test_entry t;
144 t.u.test_fl = test;
145 t.fl = fl;
146 queue_test_entry(&t);
149 static void queue_test(void (*test)(void))
151 struct test_entry t;
153 t.u.test = test;
154 t.fl = 0;
155 queue_test_entry(&t);
158 static void run_mt_test(const struct test_entry *t)
160 if (t->fl)
161 t->u.test_fl(t->fl);
162 else
163 t->u.test();
166 static DWORD WINAPI thread_func(void *ctx)
168 LONG *i = ctx, j;
170 while (*i < mt_test_count)
172 j = *i;
173 if (InterlockedCompareExchange(i, j + 1, j) == j)
174 run_mt_test(&mt_tests[j]);
177 return 0;
180 static void run_queued_tests(void)
182 unsigned int thread_count, i;
183 HANDLE *threads;
184 SYSTEM_INFO si;
185 LONG test_idx;
187 if (!use_mt)
189 for (i = 0; i < mt_test_count; ++i)
191 run_mt_test(&mt_tests[i]);
194 return;
197 GetSystemInfo(&si);
198 thread_count = si.dwNumberOfProcessors;
199 threads = heap_calloc(thread_count, sizeof(*threads));
200 for (i = 0, test_idx = 0; i < thread_count; ++i)
202 threads[i] = CreateThread(NULL, 0, thread_func, &test_idx, 0, NULL);
203 ok(!!threads[i], "Failed to create thread %u.\n", i);
205 WaitForMultipleObjects(thread_count, threads, TRUE, INFINITE);
206 for (i = 0; i < thread_count; ++i)
208 CloseHandle(threads[i]);
210 heap_free(threads);
213 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
215 box->left = left;
216 box->top = top;
217 box->front = front;
218 box->right = right;
219 box->bottom = bottom;
220 box->back = back;
223 static ULONG get_refcount(void *iface)
225 IUnknown *unknown = iface;
226 IUnknown_AddRef(unknown);
227 return IUnknown_Release(unknown);
230 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
231 static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOOL supported, BOOL is_broken)
233 HRESULT hr, expected_hr, broken_hr;
234 IUnknown *unknown = iface, *out;
236 if (supported)
238 expected_hr = S_OK;
239 broken_hr = E_NOINTERFACE;
241 else
243 expected_hr = E_NOINTERFACE;
244 broken_hr = S_OK;
247 hr = IUnknown_QueryInterface(unknown, riid, (void **)&out);
248 ok_(__FILE__, line)(hr == expected_hr || broken(is_broken && hr == broken_hr),
249 "Got hr %#x, expected %#x.\n", hr, expected_hr);
250 if (SUCCEEDED(hr))
251 IUnknown_Release(out);
252 return hr;
255 static BOOL compare_float(float f, float g, unsigned int ulps)
257 int x = *(int *)&f;
258 int y = *(int *)&g;
260 if (x < 0)
261 x = INT_MIN - x;
262 if (y < 0)
263 y = INT_MIN - y;
265 if (abs(x - y) > ulps)
266 return FALSE;
268 return TRUE;
271 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
273 return compare_float(v1->x, v2->x, ulps)
274 && compare_float(v1->y, v2->y, ulps)
275 && compare_float(v1->z, v2->z, ulps)
276 && compare_float(v1->w, v2->w, ulps);
279 static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
281 unsigned int diff = x > y ? x - y : y - x;
283 return diff <= max_diff;
286 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
288 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
291 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
293 return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
294 && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
295 && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
296 && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
299 static char const *debugstr_viewport(D3D11_VIEWPORT *vp)
301 if (!vp) return "(null)";
302 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}",
303 vp->TopLeftX, vp->TopLeftY, vp->Width, vp->Height, vp->MinDepth, vp->MaxDepth);
306 struct srv_desc
308 DXGI_FORMAT format;
309 D3D11_SRV_DIMENSION dimension;
310 unsigned int miplevel_idx;
311 unsigned int miplevel_count;
312 unsigned int layer_idx;
313 unsigned int layer_count;
316 static void get_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *d3d11_desc, const struct srv_desc *desc)
318 d3d11_desc->Format = desc->format;
319 d3d11_desc->ViewDimension = desc->dimension;
320 if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1D)
322 U(*d3d11_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
323 U(*d3d11_desc).Texture1D.MipLevels = desc->miplevel_count;
325 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
327 U(*d3d11_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
328 U(*d3d11_desc).Texture1DArray.MipLevels = desc->miplevel_count;
329 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
330 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
332 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
334 U(*d3d11_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
335 U(*d3d11_desc).Texture2D.MipLevels = desc->miplevel_count;
337 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
339 U(*d3d11_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
340 U(*d3d11_desc).Texture2DArray.MipLevels = desc->miplevel_count;
341 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
342 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
344 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
346 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
347 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
349 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE3D)
351 U(*d3d11_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
352 U(*d3d11_desc).Texture3D.MipLevels = desc->miplevel_count;
354 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
356 U(*d3d11_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
357 U(*d3d11_desc).TextureCube.MipLevels = desc->miplevel_count;
359 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
361 U(*d3d11_desc).TextureCubeArray.MostDetailedMip = desc->miplevel_idx;
362 U(*d3d11_desc).TextureCubeArray.MipLevels = desc->miplevel_count;
363 U(*d3d11_desc).TextureCubeArray.First2DArrayFace = desc->layer_idx;
364 U(*d3d11_desc).TextureCubeArray.NumCubes = desc->layer_count;
366 else if (desc->dimension != D3D11_SRV_DIMENSION_UNKNOWN
367 && desc->dimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
369 trace("Unhandled view dimension %#x.\n", desc->dimension);
373 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
374 static void check_srv_desc_(unsigned int line, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
375 const struct srv_desc *expected_desc)
377 ok_(__FILE__, line)(desc->Format == expected_desc->format,
378 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
379 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
380 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
382 if (desc->ViewDimension != expected_desc->dimension)
383 return;
385 if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D)
387 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
388 "Got MostDetailedMip %u, expected %u.\n",
389 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
390 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
391 "Got MipLevels %u, expected %u.\n",
392 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
394 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
396 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
397 "Got MostDetailedMip %u, expected %u.\n",
398 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
399 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
400 "Got MipLevels %u, expected %u.\n",
401 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
402 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
403 "Got FirstArraySlice %u, expected %u.\n",
404 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
405 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
406 "Got ArraySize %u, expected %u.\n",
407 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
409 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
411 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
412 "Got FirstArraySlice %u, expected %u.\n",
413 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
414 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
415 "Got ArraySize %u, expected %u.\n",
416 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
418 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
420 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
421 "Got MostDetailedMip %u, expected %u.\n",
422 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
423 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
424 "Got MipLevels %u, expected %u.\n",
425 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
427 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
429 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
430 "Got MostDetailedMip %u, expected %u.\n",
431 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
432 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
433 "Got MipLevels %u, expected %u.\n",
434 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
436 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
438 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MostDetailedMip == expected_desc->miplevel_idx,
439 "Got MostDetailedMip %u, expected %u.\n",
440 U(*desc).TextureCubeArray.MostDetailedMip, expected_desc->miplevel_idx);
441 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MipLevels == expected_desc->miplevel_count,
442 "Got MipLevels %u, expected %u.\n",
443 U(*desc).TextureCubeArray.MipLevels, expected_desc->miplevel_count);
444 ok_(__FILE__, line)(U(*desc).TextureCubeArray.First2DArrayFace == expected_desc->layer_idx,
445 "Got First2DArrayFace %u, expected %u.\n",
446 U(*desc).TextureCubeArray.First2DArrayFace, expected_desc->layer_idx);
447 ok_(__FILE__, line)(U(*desc).TextureCubeArray.NumCubes == expected_desc->layer_count,
448 "Got NumCubes %u, expected %u.\n",
449 U(*desc).TextureCubeArray.NumCubes, expected_desc->layer_count);
451 else if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
453 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
457 struct rtv_desc
459 DXGI_FORMAT format;
460 D3D11_RTV_DIMENSION dimension;
461 unsigned int miplevel_idx;
462 unsigned int layer_idx;
463 unsigned int layer_count;
466 static void get_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *d3d11_desc, const struct rtv_desc *desc)
468 d3d11_desc->Format = desc->format;
469 d3d11_desc->ViewDimension = desc->dimension;
470 if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1D)
472 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
474 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1DARRAY)
476 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
477 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
478 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
480 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
482 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
484 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
486 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
487 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
488 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
490 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
492 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
493 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
495 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE3D)
497 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
498 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
499 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
501 else if (desc->dimension != D3D11_RTV_DIMENSION_UNKNOWN
502 && desc->dimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
504 trace("Unhandled view dimension %#x.\n", desc->dimension);
508 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
509 static void check_rtv_desc_(unsigned int line, const D3D11_RENDER_TARGET_VIEW_DESC *desc,
510 const struct rtv_desc *expected_desc)
512 ok_(__FILE__, line)(desc->Format == expected_desc->format,
513 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
514 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
515 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
517 if (desc->ViewDimension != expected_desc->dimension)
518 return;
520 if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D)
522 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
523 "Got MipSlice %u, expected %u.\n",
524 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
526 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
528 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
529 "Got MipSlice %u, expected %u.\n",
530 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
531 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
532 "Got FirstArraySlice %u, expected %u.\n",
533 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
534 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
535 "Got ArraySize %u, expected %u.\n",
536 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
538 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
540 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
541 "Got FirstArraySlice %u, expected %u.\n",
542 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
543 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
544 "Got ArraySize %u, expected %u.\n",
545 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
547 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE3D)
549 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
550 "Got MipSlice %u, expected %u.\n",
551 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
552 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
553 "Got FirstWSlice %u, expected %u.\n",
554 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
555 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
556 "Got WSize %u, expected %u.\n",
557 U(*desc).Texture3D.WSize, expected_desc->layer_count);
559 else if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
561 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
565 struct dsv_desc
567 DXGI_FORMAT format;
568 D3D11_DSV_DIMENSION dimension;
569 unsigned int miplevel_idx;
570 unsigned int layer_idx;
571 unsigned int layer_count;
574 static void get_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *d3d11_desc, const struct dsv_desc *desc)
576 d3d11_desc->Format = desc->format;
577 d3d11_desc->ViewDimension = desc->dimension;
578 d3d11_desc->Flags = 0;
579 if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1D)
581 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
583 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1DARRAY)
585 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
586 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
587 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
589 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2D)
591 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
593 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
595 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
596 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
597 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
599 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
601 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
602 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
604 else if (desc->dimension != D3D11_DSV_DIMENSION_UNKNOWN
605 && desc->dimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
607 trace("Unhandled view dimension %#x.\n", desc->dimension);
611 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
612 static void check_dsv_desc_(unsigned int line, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc,
613 const struct dsv_desc *expected_desc)
615 ok_(__FILE__, line)(desc->Format == expected_desc->format,
616 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
617 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
618 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
620 if (desc->ViewDimension != expected_desc->dimension)
621 return;
623 if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D)
625 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
626 "Got MipSlice %u, expected %u.\n",
627 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
629 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
631 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
632 "Got MipSlice %u, expected %u.\n",
633 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
634 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
635 "Got FirstArraySlice %u, expected %u.\n",
636 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
637 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
638 "Got ArraySize %u, expected %u.\n",
639 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
641 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
643 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
644 "Got FirstArraySlice %u, expected %u.\n",
645 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
646 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
647 "Got ArraySize %u, expected %u.\n",
648 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
650 else if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
652 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
656 struct uav_desc
658 DXGI_FORMAT format;
659 D3D11_UAV_DIMENSION dimension;
660 unsigned int miplevel_idx;
661 unsigned int layer_idx;
662 unsigned int layer_count;
665 static void get_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC *d3d11_desc, const struct uav_desc *desc)
667 d3d11_desc->Format = desc->format;
668 d3d11_desc->ViewDimension = desc->dimension;
669 if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1D)
671 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
673 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
675 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
676 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
677 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
679 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2D)
681 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
683 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
685 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
686 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
687 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
689 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE3D)
691 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
692 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
693 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
695 else if (desc->dimension != D3D11_UAV_DIMENSION_UNKNOWN)
697 trace("Unhandled view dimension %#x.\n", desc->dimension);
701 #define check_uav_desc(a, b) check_uav_desc_(__LINE__, a, b)
702 static void check_uav_desc_(unsigned int line, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc,
703 const struct uav_desc *expected_desc)
705 ok_(__FILE__, line)(desc->Format == expected_desc->format,
706 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
707 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
708 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
710 if (desc->ViewDimension != expected_desc->dimension)
711 return;
713 if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D)
715 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
716 "Got MipSlice %u, expected %u.\n",
717 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
719 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
721 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
722 "Got MipSlice %u, expected %u.\n",
723 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
724 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
725 "Got FirstArraySlice %u, expected %u.\n",
726 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
727 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
728 "Got ArraySize %u, expected %u.\n",
729 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
731 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
733 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
734 "Got MipSlice %u, expected %u.\n",
735 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
736 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
737 "Got FirstWSlice %u, expected %u.\n",
738 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
739 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
740 "Got WSize %u, expected %u.\n",
741 U(*desc).Texture3D.WSize, expected_desc->layer_count);
743 else
745 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
749 static void set_viewport(ID3D11DeviceContext *context, float x, float y,
750 float width, float height, float min_depth, float max_depth)
752 D3D11_VIEWPORT vp;
754 vp.TopLeftX = x;
755 vp.TopLeftY = y;
756 vp.Width = width;
757 vp.Height = height;
758 vp.MinDepth = min_depth;
759 vp.MaxDepth = max_depth;
761 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
764 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, 0, c, d)
765 #define create_buffer_misc(a, b, c, d, e) create_buffer_(__LINE__, a, b, c, d, e)
766 static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
767 unsigned int bind_flags, unsigned int misc_flags, unsigned int size, const void *data)
769 D3D11_SUBRESOURCE_DATA resource_data;
770 D3D11_BUFFER_DESC buffer_desc;
771 ID3D11Buffer *buffer;
772 HRESULT hr;
774 buffer_desc.ByteWidth = size;
775 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
776 buffer_desc.BindFlags = bind_flags;
777 buffer_desc.CPUAccessFlags = 0;
778 buffer_desc.MiscFlags = misc_flags;
779 buffer_desc.StructureByteStride = 0;
781 resource_data.pSysMem = data;
782 resource_data.SysMemPitch = 0;
783 resource_data.SysMemSlicePitch = 0;
785 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
786 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
787 return buffer;
790 static HRESULT create_resource(ID3D11Device *device, const struct resource_desc *desc,
791 const D3D11_SUBRESOURCE_DATA *data, ID3D11Resource **resource)
793 D3D11_TEXTURE1D_DESC texture1d_desc;
794 D3D11_TEXTURE2D_DESC texture2d_desc;
795 D3D11_TEXTURE3D_DESC texture3d_desc;
796 D3D11_BUFFER_DESC buffer_desc;
798 switch (desc->dimension)
800 case D3D11_RESOURCE_DIMENSION_BUFFER:
801 buffer_desc.ByteWidth = desc->width;
802 buffer_desc.Usage = desc->usage;
803 buffer_desc.BindFlags = desc->bind_flags;
804 buffer_desc.CPUAccessFlags = desc->cpu_access_flags;
805 buffer_desc.MiscFlags = desc->misc_flags;
806 buffer_desc.StructureByteStride = desc->structure_byte_stride;
807 return ID3D11Device_CreateBuffer(device, &buffer_desc, data, (ID3D11Buffer **)resource);
809 case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
810 texture1d_desc.Width = desc->width;
811 texture1d_desc.MipLevels = desc->level_count;
812 texture1d_desc.ArraySize = desc->depth_or_array_size;
813 texture1d_desc.Format = desc->format;
814 texture1d_desc.Usage = desc->usage;
815 texture1d_desc.BindFlags = desc->bind_flags;
816 texture1d_desc.CPUAccessFlags = desc->cpu_access_flags;
817 texture1d_desc.MiscFlags = desc->misc_flags;
818 return ID3D11Device_CreateTexture1D(device, &texture1d_desc, data, (ID3D11Texture1D **)resource);
820 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
821 texture2d_desc.Width = desc->width;
822 texture2d_desc.Height = desc->height;
823 texture2d_desc.MipLevels = desc->level_count;
824 texture2d_desc.ArraySize = desc->depth_or_array_size;
825 texture2d_desc.Format = desc->format;
826 texture2d_desc.SampleDesc = desc->sample_desc;
827 texture2d_desc.Usage = desc->usage;
828 texture2d_desc.BindFlags = desc->bind_flags;
829 texture2d_desc.CPUAccessFlags = desc->cpu_access_flags;
830 texture2d_desc.MiscFlags = desc->misc_flags;
831 return ID3D11Device_CreateTexture2D(device, &texture2d_desc, data, (ID3D11Texture2D **)resource);
833 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
834 texture3d_desc.Width = desc->width;
835 texture3d_desc.Height = desc->height;
836 texture3d_desc.Depth = desc->depth_or_array_size;
837 texture3d_desc.MipLevels = desc->level_count;
838 texture3d_desc.Format = desc->format;
839 texture3d_desc.Usage = desc->usage;
840 texture3d_desc.BindFlags = desc->bind_flags;
841 texture3d_desc.CPUAccessFlags = desc->cpu_access_flags;
842 texture3d_desc.MiscFlags = desc->misc_flags;
843 return ID3D11Device_CreateTexture3D(device, &texture3d_desc, data, (ID3D11Texture3D **)resource);
845 default:
846 return E_INVALIDARG;
850 struct resource_readback
852 ID3D11Resource *resource;
853 D3D11_MAPPED_SUBRESOURCE map_desc;
854 ID3D11DeviceContext *immediate_context;
855 unsigned int width, height, depth, sub_resource_idx;
858 static void init_resource_readback(ID3D11Resource *resource, ID3D11Resource *readback_resource,
859 unsigned int width, unsigned int height, unsigned int depth, unsigned int sub_resource_idx,
860 ID3D11Device *device, struct resource_readback *rb)
862 HRESULT hr;
864 rb->resource = readback_resource;
865 rb->width = width;
866 rb->height = height;
867 rb->depth = depth;
868 rb->sub_resource_idx = sub_resource_idx;
870 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
872 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, resource);
873 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context,
874 rb->resource, sub_resource_idx, D3D11_MAP_READ, 0, &rb->map_desc)))
876 trace("Failed to map resource, hr %#x.\n", hr);
877 ID3D11Resource_Release(rb->resource);
878 rb->resource = NULL;
879 ID3D11DeviceContext_Release(rb->immediate_context);
880 rb->immediate_context = NULL;
884 static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
886 D3D11_BUFFER_DESC buffer_desc;
887 ID3D11Resource *rb_buffer;
888 ID3D11Device *device;
889 HRESULT hr;
891 memset(rb, 0, sizeof(*rb));
893 ID3D11Buffer_GetDevice(buffer, &device);
895 ID3D11Buffer_GetDesc(buffer, &buffer_desc);
896 buffer_desc.Usage = D3D11_USAGE_STAGING;
897 buffer_desc.BindFlags = 0;
898 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
899 buffer_desc.MiscFlags = 0;
900 buffer_desc.StructureByteStride = 0;
901 if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb_buffer)))
903 trace("Failed to create staging buffer, hr %#x.\n", hr);
904 ID3D11Device_Release(device);
905 return;
908 init_resource_readback((ID3D11Resource *)buffer, rb_buffer,
909 buffer_desc.ByteWidth, 1, 1, 0, device, rb);
911 ID3D11Device_Release(device);
914 static void get_texture1d_readback(ID3D11Texture1D *texture, unsigned int sub_resource_idx,
915 struct resource_readback *rb)
917 D3D11_TEXTURE1D_DESC texture_desc;
918 ID3D11Resource *rb_texture;
919 unsigned int miplevel;
920 ID3D11Device *device;
921 HRESULT hr;
923 memset(rb, 0, sizeof(*rb));
925 ID3D11Texture1D_GetDevice(texture, &device);
927 ID3D11Texture1D_GetDesc(texture, &texture_desc);
928 texture_desc.Usage = D3D11_USAGE_STAGING;
929 texture_desc.BindFlags = 0;
930 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
931 texture_desc.MiscFlags = 0;
932 if (FAILED(hr = ID3D11Device_CreateTexture1D(device, &texture_desc, NULL, (ID3D11Texture1D **)&rb_texture)))
934 trace("Failed to create texture, hr %#x.\n", hr);
935 ID3D11Device_Release(device);
936 return;
939 miplevel = sub_resource_idx % texture_desc.MipLevels;
940 init_resource_readback((ID3D11Resource *)texture, rb_texture,
941 max(1, texture_desc.Width >> miplevel), 1, 1, sub_resource_idx, device, rb);
943 ID3D11Device_Release(device);
946 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
947 struct resource_readback *rb)
949 D3D11_TEXTURE2D_DESC texture_desc;
950 ID3D11Resource *rb_texture;
951 unsigned int miplevel;
952 ID3D11Device *device;
953 HRESULT hr;
955 memset(rb, 0, sizeof(*rb));
957 ID3D11Texture2D_GetDevice(texture, &device);
959 ID3D11Texture2D_GetDesc(texture, &texture_desc);
960 texture_desc.Usage = D3D11_USAGE_STAGING;
961 texture_desc.BindFlags = 0;
962 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
963 texture_desc.MiscFlags = 0;
964 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb_texture)))
966 trace("Failed to create texture, hr %#x.\n", hr);
967 ID3D11Device_Release(device);
968 return;
971 miplevel = sub_resource_idx % texture_desc.MipLevels;
972 init_resource_readback((ID3D11Resource *)texture, rb_texture,
973 max(1, texture_desc.Width >> miplevel),
974 max(1, texture_desc.Height >> miplevel),
975 1, sub_resource_idx, device, rb);
977 ID3D11Device_Release(device);
980 static void get_texture3d_readback(ID3D11Texture3D *texture, unsigned int sub_resource_idx,
981 struct resource_readback *rb)
983 D3D11_TEXTURE3D_DESC texture_desc;
984 ID3D11Resource *rb_texture;
985 unsigned int miplevel;
986 ID3D11Device *device;
987 HRESULT hr;
989 memset(rb, 0, sizeof(*rb));
991 ID3D11Texture3D_GetDevice(texture, &device);
993 ID3D11Texture3D_GetDesc(texture, &texture_desc);
994 texture_desc.Usage = D3D11_USAGE_STAGING;
995 texture_desc.BindFlags = 0;
996 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
997 texture_desc.MiscFlags = 0;
998 if (FAILED(hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, (ID3D11Texture3D **)&rb_texture)))
1000 trace("Failed to create texture, hr %#x.\n", hr);
1001 ID3D11Device_Release(device);
1002 return;
1005 miplevel = sub_resource_idx % texture_desc.MipLevels;
1006 init_resource_readback((ID3D11Resource *)texture, rb_texture,
1007 max(1, texture_desc.Width >> miplevel),
1008 max(1, texture_desc.Height >> miplevel),
1009 max(1, texture_desc.Depth >> miplevel),
1010 sub_resource_idx, device, rb);
1012 ID3D11Device_Release(device);
1015 static void get_resource_readback(ID3D11Resource *resource,
1016 unsigned int sub_resource_idx, struct resource_readback *rb)
1018 D3D11_RESOURCE_DIMENSION d;
1020 ID3D11Resource_GetType(resource, &d);
1021 switch (d)
1023 case D3D11_RESOURCE_DIMENSION_BUFFER:
1024 get_buffer_readback((ID3D11Buffer *)resource, rb);
1025 return;
1027 case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
1028 get_texture1d_readback((ID3D11Texture1D *)resource, sub_resource_idx, rb);
1029 return;
1031 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
1032 get_texture_readback((ID3D11Texture2D *)resource, sub_resource_idx, rb);
1033 return;
1035 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
1036 get_texture3d_readback((ID3D11Texture3D *)resource, sub_resource_idx, rb);
1037 return;
1039 default:
1040 memset(rb, 0, sizeof(*rb));
1041 return;
1045 static void *get_readback_data(struct resource_readback *rb,
1046 unsigned int x, unsigned int y, unsigned int z, unsigned byte_width)
1048 return (BYTE *)rb->map_desc.pData + z * rb->map_desc.DepthPitch + y * rb->map_desc.RowPitch + x * byte_width;
1051 static BYTE get_readback_u8(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
1053 return *(BYTE *)get_readback_data(rb, x, y, z, sizeof(BYTE));
1056 static WORD get_readback_u16(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
1058 return *(WORD *)get_readback_data(rb, x, y, z, sizeof(WORD));
1061 static DWORD get_readback_u32(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
1063 return *(DWORD *)get_readback_data(rb, x, y, z, sizeof(DWORD));
1066 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
1068 return get_readback_u32(rb, x, y, z);
1071 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
1073 return *(float *)get_readback_data(rb, x, y, 0, sizeof(float));
1076 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
1078 return get_readback_data(rb, x, y, 0, sizeof(struct vec4));
1081 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
1083 return get_readback_data(rb, x, y, 0, sizeof(struct uvec4));
1086 static void release_resource_readback(struct resource_readback *rb)
1088 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
1089 ID3D11Resource_Release(rb->resource);
1090 ID3D11DeviceContext_Release(rb->immediate_context);
1093 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
1095 struct resource_readback rb;
1096 DWORD color;
1098 get_texture_readback(texture, 0, &rb);
1099 color = get_readback_color(&rb, x, y, 0);
1100 release_resource_readback(&rb);
1102 return color;
1105 #define check_readback_data_u8(a, b, c, d) check_readback_data_u8_(__LINE__, a, b, c, d)
1106 static void check_readback_data_u8_(unsigned int line, struct resource_readback *rb,
1107 const RECT *rect, BYTE expected_value, BYTE max_diff)
1109 unsigned int x = 0, y = 0, z = 0;
1110 BOOL all_match = FALSE;
1111 RECT default_rect;
1112 BYTE value = 0;
1114 if (!rect)
1116 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1117 rect = &default_rect;
1120 for (z = 0; z < rb->depth; ++z)
1122 for (y = rect->top; y < rect->bottom; ++y)
1124 for (x = rect->left; x < rect->right; ++x)
1126 value = get_readback_u8(rb, x, y, z);
1127 if (!compare_uint(value, expected_value, max_diff))
1128 goto done;
1132 all_match = TRUE;
1134 done:
1135 ok_(__FILE__, line)(all_match,
1136 "Got 0x%02x, expected 0x%02x at (%u, %u, %u), sub-resource %u.\n",
1137 value, expected_value, x, y, z, rb->sub_resource_idx);
1140 #define check_readback_data_u16(a, b, c, d) check_readback_data_u16_(__LINE__, a, b, c, d)
1141 static void check_readback_data_u16_(unsigned int line, struct resource_readback *rb,
1142 const RECT *rect, WORD expected_value, BYTE max_diff)
1144 unsigned int x = 0, y = 0, z = 0;
1145 BOOL all_match = FALSE;
1146 RECT default_rect;
1147 WORD value = 0;
1149 if (!rect)
1151 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1152 rect = &default_rect;
1155 for (z = 0; z < rb->depth; ++z)
1157 for (y = rect->top; y < rect->bottom; ++y)
1159 for (x = rect->left; x < rect->right; ++x)
1161 value = get_readback_u16(rb, x, y, z);
1162 if (!compare_uint(value, expected_value, max_diff))
1163 goto done;
1167 all_match = TRUE;
1169 done:
1170 ok_(__FILE__, line)(all_match,
1171 "Got 0x%04x, expected 0x%04x at (%u, %u, %u), sub-resource %u.\n",
1172 value, expected_value, x, y, z, rb->sub_resource_idx);
1175 #define check_readback_data_u24(a, b, c, d, e) check_readback_data_u24_(__LINE__, a, b, c, d, e)
1176 static void check_readback_data_u24_(unsigned int line, struct resource_readback *rb,
1177 const RECT *rect, unsigned int shift, DWORD expected_value, BYTE max_diff)
1179 unsigned int x = 0, y = 0, z = 0;
1180 BOOL all_match = FALSE;
1181 RECT default_rect;
1182 DWORD value = 0;
1184 if (!rect)
1186 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1187 rect = &default_rect;
1190 for (z = 0; z < rb->depth; ++z)
1192 for (y = rect->top; y < rect->bottom; ++y)
1194 for (x = rect->left; x < rect->right; ++x)
1196 value = get_readback_u32(rb, x, y, z) >> shift;
1197 if (!compare_uint(value, expected_value, max_diff))
1198 goto done;
1202 all_match = TRUE;
1204 done:
1205 ok_(__FILE__, line)(all_match,
1206 "Got 0x%06x, expected 0x%06x at (%u, %u, %u), sub-resource %u.\n",
1207 value, expected_value, x, y, z, rb->sub_resource_idx);
1210 #define check_readback_data_color(a, b, c, d) check_readback_data_color_(__LINE__, a, b, c, d)
1211 static void check_readback_data_color_(unsigned int line, struct resource_readback *rb,
1212 const RECT *rect, DWORD expected_color, BYTE max_diff)
1214 unsigned int x = 0, y = 0, z = 0;
1215 BOOL all_match = FALSE;
1216 RECT default_rect;
1217 DWORD color = 0;
1219 if (!rect)
1221 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1222 rect = &default_rect;
1225 for (z = 0; z < rb->depth; ++z)
1227 for (y = rect->top; y < rect->bottom; ++y)
1229 for (x = rect->left; x < rect->right; ++x)
1231 color = get_readback_color(rb, x, y, z);
1232 if (!compare_color(color, expected_color, max_diff))
1233 goto done;
1237 all_match = TRUE;
1239 done:
1240 ok_(__FILE__, line)(all_match,
1241 "Got 0x%08x, expected 0x%08x at (%u, %u, %u), sub-resource %u.\n",
1242 color, expected_color, x, y, z, rb->sub_resource_idx);
1245 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
1246 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
1247 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1249 struct resource_readback rb;
1251 get_texture_readback(texture, sub_resource_idx, &rb);
1252 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1253 release_resource_readback(&rb);
1256 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
1257 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
1258 DWORD expected_color, BYTE max_diff)
1260 unsigned int sub_resource_idx, sub_resource_count;
1261 D3D11_TEXTURE2D_DESC texture_desc;
1263 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1264 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1265 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1266 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1269 #define check_texture1d_sub_resource_color(a, b, c, d, e) check_texture1d_sub_resource_color_(__LINE__, a, b, c, d, e)
1270 static void check_texture1d_sub_resource_color_(unsigned int line, ID3D11Texture1D *texture,
1271 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1273 struct resource_readback rb;
1275 get_texture1d_readback(texture, sub_resource_idx, &rb);
1276 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1277 release_resource_readback(&rb);
1280 #define check_texture1d_color(t, c, d) check_texture1d_color_(__LINE__, t, c, d)
1281 static void check_texture1d_color_(unsigned int line, ID3D11Texture1D *texture,
1282 DWORD expected_color, BYTE max_diff)
1284 unsigned int sub_resource_idx, sub_resource_count;
1285 D3D11_TEXTURE1D_DESC texture_desc;
1287 ID3D11Texture1D_GetDesc(texture, &texture_desc);
1288 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1289 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1290 check_texture1d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1293 #define check_texture3d_sub_resource_color(a, b, c, d, e) check_texture3d_sub_resource_color_(__LINE__, a, b, c, d, e)
1294 static void check_texture3d_sub_resource_color_(unsigned int line, ID3D11Texture3D *texture,
1295 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1297 struct resource_readback rb;
1299 get_texture3d_readback(texture, sub_resource_idx, &rb);
1300 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1301 release_resource_readback(&rb);
1304 #define check_texture3d_color(t, c, d) check_texture3d_color_(__LINE__, t, c, d)
1305 static void check_texture3d_color_(unsigned int line, ID3D11Texture3D *texture,
1306 DWORD expected_color, BYTE max_diff)
1308 unsigned int sub_resource_idx, sub_resource_count;
1309 D3D11_TEXTURE3D_DESC texture_desc;
1311 ID3D11Texture3D_GetDesc(texture, &texture_desc);
1312 sub_resource_count = texture_desc.MipLevels;
1313 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1314 check_texture3d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1317 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
1318 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
1319 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
1321 struct resource_readback rb;
1322 unsigned int x = 0, y = 0;
1323 BOOL all_match = TRUE;
1324 float value = 0.0f;
1325 RECT default_rect;
1327 get_texture_readback(texture, sub_resource_idx, &rb);
1328 if (!rect)
1330 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1331 rect = &default_rect;
1333 for (y = rect->top; y < rect->bottom; ++y)
1335 for (x = rect->left; x < rect->right; ++x)
1337 value = get_readback_float(&rb, x, y);
1338 if (!compare_float(value, expected_value, max_diff))
1340 all_match = FALSE;
1341 break;
1344 if (!all_match)
1345 break;
1347 release_resource_readback(&rb);
1348 ok_(__FILE__, line)(all_match,
1349 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
1350 value, expected_value, x, y, sub_resource_idx);
1353 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
1354 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
1355 float expected_value, BYTE max_diff)
1357 unsigned int sub_resource_idx, sub_resource_count;
1358 D3D11_TEXTURE2D_DESC texture_desc;
1360 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1361 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1362 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1363 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1366 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
1367 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
1368 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
1370 struct resource_readback rb;
1371 unsigned int x = 0, y = 0;
1372 struct vec4 value = {0};
1373 BOOL all_match = TRUE;
1374 RECT default_rect;
1376 get_texture_readback(texture, sub_resource_idx, &rb);
1377 if (!rect)
1379 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1380 rect = &default_rect;
1382 for (y = rect->top; y < rect->bottom; ++y)
1384 for (x = rect->left; x < rect->right; ++x)
1386 value = *get_readback_vec4(&rb, x, y);
1387 if (!compare_vec4(&value, expected_value, max_diff))
1389 all_match = FALSE;
1390 break;
1393 if (!all_match)
1394 break;
1396 release_resource_readback(&rb);
1397 ok_(__FILE__, line)(all_match,
1398 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
1399 value.x, value.y, value.z, value.w,
1400 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1401 x, y, sub_resource_idx);
1404 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
1405 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
1406 const struct vec4 *expected_value, BYTE max_diff)
1408 unsigned int sub_resource_idx, sub_resource_count;
1409 D3D11_TEXTURE2D_DESC texture_desc;
1411 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1412 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1413 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1414 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1417 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
1418 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
1419 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
1421 struct resource_readback rb;
1422 unsigned int x = 0, y = 0;
1423 struct uvec4 value = {0};
1424 BOOL all_match = TRUE;
1425 RECT default_rect;
1427 get_texture_readback(texture, sub_resource_idx, &rb);
1428 if (!rect)
1430 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1431 rect = &default_rect;
1433 for (y = rect->top; y < rect->bottom; ++y)
1435 for (x = rect->left; x < rect->right; ++x)
1437 value = *get_readback_uvec4(&rb, x, y);
1438 if (!compare_uvec4(&value, expected_value))
1440 all_match = FALSE;
1441 break;
1444 if (!all_match)
1445 break;
1447 release_resource_readback(&rb);
1448 ok_(__FILE__, line)(all_match,
1449 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
1450 "at (%u, %u), sub-resource %u.\n",
1451 value.x, value.y, value.z, value.w,
1452 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1453 x, y, sub_resource_idx);
1456 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
1457 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
1458 const struct uvec4 *expected_value)
1460 unsigned int sub_resource_idx, sub_resource_count;
1461 D3D11_TEXTURE2D_DESC texture_desc;
1463 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1464 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1465 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1466 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
1469 static IDXGIAdapter *create_adapter(void)
1471 IDXGIFactory4 *factory4;
1472 IDXGIFactory *factory;
1473 IDXGIAdapter *adapter;
1474 HRESULT hr;
1476 if (!use_warp_adapter && !use_adapter_idx)
1477 return NULL;
1479 if (FAILED(hr = CreateDXGIFactory1(&IID_IDXGIFactory, (void **)&factory)))
1481 trace("Failed to create IDXGIFactory, hr %#x.\n", hr);
1482 return NULL;
1485 adapter = NULL;
1486 if (use_warp_adapter)
1488 if (SUCCEEDED(hr = IDXGIFactory_QueryInterface(factory, &IID_IDXGIFactory4, (void **)&factory4)))
1490 hr = IDXGIFactory4_EnumWarpAdapter(factory4, &IID_IDXGIAdapter, (void **)&adapter);
1491 IDXGIFactory4_Release(factory4);
1493 else
1495 trace("Failed to get IDXGIFactory4, hr %#x.\n", hr);
1498 else
1500 hr = IDXGIFactory_EnumAdapters(factory, use_adapter_idx, &adapter);
1502 IDXGIFactory_Release(factory);
1503 if (FAILED(hr))
1504 trace("Failed to get adapter, hr %#x.\n", hr);
1505 return adapter;
1508 static ID3D11Device *create_device(const struct device_desc *desc)
1510 static const D3D_FEATURE_LEVEL default_feature_level[] =
1512 D3D_FEATURE_LEVEL_11_0,
1513 D3D_FEATURE_LEVEL_10_1,
1514 D3D_FEATURE_LEVEL_10_0,
1516 const D3D_FEATURE_LEVEL *feature_level;
1517 UINT flags = desc ? desc->flags : 0;
1518 unsigned int feature_level_count;
1519 IDXGIAdapter *adapter;
1520 ID3D11Device *device;
1521 HRESULT hr;
1523 if (desc && desc->feature_level)
1525 feature_level = desc->feature_level;
1526 feature_level_count = 1;
1528 else
1530 feature_level = default_feature_level;
1531 feature_level_count = ARRAY_SIZE(default_feature_level);
1534 if (enable_debug_layer)
1535 flags |= D3D11_CREATE_DEVICE_DEBUG;
1537 if ((adapter = create_adapter()))
1539 hr = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags,
1540 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL);
1541 IDXGIAdapter_Release(adapter);
1542 return SUCCEEDED(hr) ? device : NULL;
1545 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags,
1546 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1547 return device;
1548 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags,
1549 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1550 return device;
1551 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags,
1552 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1553 return device;
1555 return NULL;
1558 static void get_device_adapter_desc(ID3D11Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1560 IDXGIDevice *dxgi_device;
1561 IDXGIAdapter *adapter;
1562 HRESULT hr;
1564 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1565 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1566 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1567 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1568 IDXGIDevice_Release(dxgi_device);
1569 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1570 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1571 IDXGIAdapter_Release(adapter);
1574 static void print_adapter_info(void)
1576 DXGI_ADAPTER_DESC adapter_desc;
1577 ID3D11Device *device;
1579 if (!(device = create_device(NULL)))
1580 return;
1582 get_device_adapter_desc(device, &adapter_desc);
1583 trace("Adapter: %s, %04x:%04x.\n", wine_dbgstr_w(adapter_desc.Description),
1584 adapter_desc.VendorId, adapter_desc.DeviceId);
1585 ID3D11Device_Release(device);
1588 static BOOL is_warp_device(ID3D11Device *device)
1590 DXGI_ADAPTER_DESC adapter_desc;
1591 get_device_adapter_desc(device, &adapter_desc);
1592 return !adapter_desc.SubSysId && !adapter_desc.Revision
1593 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1594 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1597 static BOOL is_vendor_device(ID3D11Device *device, unsigned int vendor_id)
1599 DXGI_ADAPTER_DESC adapter_desc;
1601 if (!strcmp(winetest_platform, "wine"))
1602 return FALSE;
1604 get_device_adapter_desc(device, &adapter_desc);
1605 return adapter_desc.VendorId == vendor_id;
1608 static BOOL is_amd_device(ID3D11Device *device)
1610 return is_vendor_device(device, 0x1002);
1613 static BOOL is_intel_device(ID3D11Device *device)
1615 return is_vendor_device(device, 0x8086);
1618 static BOOL is_nvidia_device(ID3D11Device *device)
1620 return is_vendor_device(device, 0x10de);
1623 static BOOL is_d3d11_2_runtime(ID3D11Device *device)
1625 ID3D11Device2 *device2;
1626 HRESULT hr;
1628 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11Device2, (void **)&device2);
1629 if (SUCCEEDED(hr))
1630 ID3D11Device2_Release(device2);
1631 return hr == S_OK;
1634 static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device)
1636 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
1638 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1639 D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options))))
1640 return FALSE;
1641 return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
1644 static BOOL check_viewport_array_index_from_any_shader_support(ID3D11Device *device)
1646 D3D11_FEATURE_DATA_D3D11_OPTIONS3 options;
1648 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1649 D3D11_FEATURE_D3D11_OPTIONS3, &options, sizeof(options))))
1650 return FALSE;
1651 return options.VPAndRTArrayIndexFromAnyShaderFeedingRasterizer;
1654 static BOOL is_buffer(ID3D11Resource *resource)
1656 D3D11_RESOURCE_DIMENSION dimension;
1657 ID3D11Resource_GetType(resource, &dimension);
1658 return dimension == D3D11_RESOURCE_DIMENSION_BUFFER;
1661 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window,
1662 const struct swapchain_desc *swapchain_desc)
1664 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1665 IDXGISwapChain *swapchain;
1666 IDXGIDevice *dxgi_device;
1667 IDXGIAdapter *adapter;
1668 IDXGIFactory *factory;
1669 HRESULT hr;
1671 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1672 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1673 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1674 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1675 IDXGIDevice_Release(dxgi_device);
1676 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1677 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1678 IDXGIAdapter_Release(adapter);
1680 dxgi_desc.BufferDesc.Width = 640;
1681 dxgi_desc.BufferDesc.Height = 480;
1682 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1683 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1684 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1685 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1686 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1687 dxgi_desc.SampleDesc.Count = 1;
1688 dxgi_desc.SampleDesc.Quality = 0;
1689 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1690 dxgi_desc.BufferCount = 1;
1691 dxgi_desc.OutputWindow = window;
1692 dxgi_desc.Windowed = TRUE;
1693 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1694 dxgi_desc.Flags = 0;
1696 if (swapchain_desc)
1698 dxgi_desc.Windowed = swapchain_desc->windowed;
1699 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1700 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1701 if (swapchain_desc->width)
1702 dxgi_desc.BufferDesc.Width = swapchain_desc->width;
1703 if (swapchain_desc->height)
1704 dxgi_desc.BufferDesc.Height = swapchain_desc->height;
1706 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1707 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1710 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1711 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1712 IDXGIFactory_Release(factory);
1714 return swapchain;
1717 struct d3d11_test_context
1719 ID3D11Device *device;
1720 HWND window;
1721 IDXGISwapChain *swapchain;
1722 ID3D11Texture2D *backbuffer;
1723 ID3D11RenderTargetView *backbuffer_rtv;
1724 ID3D11DeviceContext *immediate_context;
1726 ID3D11InputLayout *input_layout;
1727 ID3D11VertexShader *vs;
1728 const DWORD *vs_code;
1729 ID3D11Buffer *vs_cb;
1730 ID3D11Buffer *vb;
1732 ID3D11PixelShader *ps;
1733 ID3D11Buffer *ps_cb;
1736 #define init_test_context(a, b) init_test_context_(__LINE__, a, b, NULL)
1737 #define init_test_context_ext(a, b, c) init_test_context_(__LINE__, a, b, c)
1738 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1739 const D3D_FEATURE_LEVEL *feature_level, const struct swapchain_desc *swapchain_desc)
1741 unsigned int rt_width, rt_height;
1742 struct device_desc device_desc;
1743 HRESULT hr;
1744 RECT rect;
1746 memset(context, 0, sizeof(*context));
1748 device_desc.feature_level = feature_level;
1749 device_desc.flags = 0;
1750 if (!(context->device = create_device(&device_desc)))
1752 skip_(__FILE__, line)("Failed to create device.\n");
1753 return FALSE;
1756 rt_width = swapchain_desc && swapchain_desc->width ? swapchain_desc->width : 640;
1757 rt_height = swapchain_desc && swapchain_desc->height ? swapchain_desc->height : 480;
1758 SetRect(&rect, 0, 0, rt_width, rt_height);
1759 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1760 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1761 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1762 context->swapchain = create_swapchain(context->device, context->window, swapchain_desc);
1763 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1764 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1766 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1767 NULL, &context->backbuffer_rtv);
1768 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1770 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1772 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1774 set_viewport(context->immediate_context, 0.0f, 0.0f, rt_width, rt_height, 0.0f, 1.0f);
1776 return TRUE;
1779 #define release_test_context(context) release_test_context_(__LINE__, context)
1780 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1782 ULONG ref;
1784 if (context->input_layout)
1785 ID3D11InputLayout_Release(context->input_layout);
1786 if (context->vs)
1787 ID3D11VertexShader_Release(context->vs);
1788 if (context->vs_cb)
1789 ID3D11Buffer_Release(context->vs_cb);
1790 if (context->vb)
1791 ID3D11Buffer_Release(context->vb);
1792 if (context->ps)
1793 ID3D11PixelShader_Release(context->ps);
1794 if (context->ps_cb)
1795 ID3D11Buffer_Release(context->ps_cb);
1797 ID3D11DeviceContext_Release(context->immediate_context);
1798 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1799 ID3D11Texture2D_Release(context->backbuffer);
1800 IDXGISwapChain_Release(context->swapchain);
1801 DestroyWindow(context->window);
1803 ref = ID3D11Device_Release(context->device);
1804 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1807 #define draw_quad(context) draw_quad_vs_(__LINE__, context, NULL, 0)
1808 #define draw_quad_vs(a, b, c) draw_quad_vs_(__LINE__, a, b, c)
1809 static void draw_quad_vs_(unsigned int line, struct d3d11_test_context *context,
1810 const DWORD *vs_code, size_t vs_code_size)
1812 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1814 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1816 static const DWORD default_vs_code[] =
1818 #if 0
1819 float4 main(float4 position : POSITION) : SV_POSITION
1821 return position;
1823 #endif
1824 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1825 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1826 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1827 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1828 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1829 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1830 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1831 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1832 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1833 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1834 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1835 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1836 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1837 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1838 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1840 static const struct vec3 quad[] =
1842 {-1.0f, -1.0f, 0.0f},
1843 {-1.0f, 1.0f, 0.0f},
1844 { 1.0f, -1.0f, 0.0f},
1845 { 1.0f, 1.0f, 0.0f},
1848 ID3D11Device *device = context->device;
1849 unsigned int stride, offset;
1850 HRESULT hr;
1852 if (!vs_code)
1854 vs_code = default_vs_code;
1855 vs_code_size = sizeof(default_vs_code);
1858 if (!context->input_layout)
1860 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1861 vs_code, vs_code_size, &context->input_layout);
1862 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1865 if (context->vs_code != vs_code)
1867 if (context->vs)
1868 ID3D11VertexShader_Release(context->vs);
1870 hr = ID3D11Device_CreateVertexShader(device, vs_code, vs_code_size, NULL, &context->vs);
1871 ok_(__FILE__, line)(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
1873 context->vs_code = vs_code;
1876 if (!context->vb)
1877 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1879 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1880 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1881 stride = sizeof(*quad);
1882 offset = 0;
1883 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1884 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1886 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1889 #define draw_quad_z(context, z) draw_quad_z_(__LINE__, context, z)
1890 static void draw_quad_z_(unsigned int line, struct d3d11_test_context *context, float z)
1892 static const DWORD vs_code[] =
1894 #if 0
1895 float depth;
1897 void main(float4 in_position : POSITION, out float4 out_position : SV_Position)
1899 out_position = in_position;
1900 out_position.z = depth;
1902 #endif
1903 0x43425844, 0x22d7ff76, 0xd53b167c, 0x1b49ccf1, 0xbebfec39, 0x00000001, 0x00000100, 0x00000003,
1904 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1905 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000b0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1906 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1907 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x00000064, 0x00010040,
1908 0x00000019, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010b2, 0x00000000,
1909 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, 0x001020b2, 0x00000000, 0x00101c46,
1910 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
1913 struct vec4 data = {z};
1915 if (!context->vs_cb)
1916 context->vs_cb = create_buffer(context->device, D3D11_BIND_CONSTANT_BUFFER, sizeof(data), NULL);
1918 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1919 (ID3D11Resource *)context->vs_cb, 0, NULL, &data, 0, 0);
1921 ID3D11DeviceContext_VSSetConstantBuffers(context->immediate_context, 0, 1, &context->vs_cb);
1922 draw_quad_vs_(__LINE__, context, vs_code, sizeof(vs_code));
1925 static void set_quad_color(struct d3d11_test_context *context, const struct vec4 *color)
1927 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1928 (ID3D11Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1931 #define draw_color_quad(a, b) draw_color_quad_(__LINE__, a, b, NULL, 0)
1932 #define draw_color_quad_vs(a, b, c, d) draw_color_quad_(__LINE__, a, b, c, d)
1933 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context,
1934 const struct vec4 *color, const DWORD *vs_code, size_t vs_code_size)
1936 static const DWORD ps_color_code[] =
1938 #if 0
1939 float4 color;
1941 float4 main() : SV_TARGET
1943 return color;
1945 #endif
1946 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1947 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1948 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1949 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1950 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1951 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1952 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1953 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1954 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1955 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1956 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1959 ID3D11Device *device = context->device;
1960 HRESULT hr;
1962 if (!context->ps)
1964 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1965 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1968 if (!context->ps_cb)
1969 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1971 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1972 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1974 set_quad_color(context, color);
1976 draw_quad_vs_(line, context, vs_code, vs_code_size);
1979 static void test_create_device(void)
1981 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1983 D3D_FEATURE_LEVEL_11_0,
1984 D3D_FEATURE_LEVEL_10_1,
1985 D3D_FEATURE_LEVEL_10_0,
1986 D3D_FEATURE_LEVEL_9_3,
1987 D3D_FEATURE_LEVEL_9_2,
1988 D3D_FEATURE_LEVEL_9_1,
1990 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1991 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1992 ID3D11DeviceContext *immediate_context;
1993 IDXGISwapChain *swapchain;
1994 ID3D11Device *device;
1995 ULONG refcount;
1996 HWND window;
1997 HRESULT hr;
1999 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2000 &device, NULL, NULL)))
2002 skip("Failed to create HAL device.\n");
2003 if ((device = create_device(NULL)))
2005 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
2006 ID3D11Device_Release(device);
2008 return;
2011 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
2012 trace("Feature level %#x.\n", supported_feature_level);
2013 ID3D11Device_Release(device);
2015 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
2016 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2018 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
2019 &feature_level, NULL);
2020 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2021 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2022 feature_level, supported_feature_level);
2024 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
2025 ARRAY_SIZE(default_feature_levels), D3D11_SDK_VERSION, NULL, &feature_level, NULL);
2026 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2027 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2028 feature_level, supported_feature_level);
2030 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
2031 &immediate_context);
2032 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2034 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
2035 refcount = get_refcount(immediate_context);
2036 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
2038 ID3D11DeviceContext_GetDevice(immediate_context, &device);
2039 refcount = ID3D11Device_Release(device);
2040 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
2042 refcount = ID3D11DeviceContext_Release(immediate_context);
2043 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
2045 device = (ID3D11Device *)0xdeadbeef;
2046 feature_level = 0xdeadbeef;
2047 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
2048 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2049 &device, &feature_level, &immediate_context);
2050 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
2051 ok(!device, "Got unexpected device pointer %p.\n", device);
2052 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
2053 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
2055 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
2057 swapchain_desc.BufferDesc.Width = 800;
2058 swapchain_desc.BufferDesc.Height = 600;
2059 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
2060 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
2061 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2062 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
2063 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
2064 swapchain_desc.SampleDesc.Count = 1;
2065 swapchain_desc.SampleDesc.Quality = 0;
2066 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
2067 swapchain_desc.BufferCount = 1;
2068 swapchain_desc.OutputWindow = window;
2069 swapchain_desc.Windowed = TRUE;
2070 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
2071 swapchain_desc.Flags = 0;
2073 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2074 &swapchain_desc, NULL, NULL, NULL, NULL);
2075 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2077 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2078 &swapchain_desc, NULL, NULL, &feature_level, NULL);
2079 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2080 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2081 feature_level, supported_feature_level);
2083 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2084 &swapchain_desc, &swapchain, &device, NULL, NULL);
2085 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2087 check_interface(swapchain, &IID_IDXGISwapChain1, TRUE, FALSE);
2089 memset(&obtained_desc, 0, sizeof(obtained_desc));
2090 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
2091 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
2092 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
2093 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
2094 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
2095 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
2096 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
2097 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
2098 obtained_desc.BufferDesc.RefreshRate.Numerator);
2099 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
2100 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
2101 obtained_desc.BufferDesc.RefreshRate.Denominator);
2102 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
2103 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
2104 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
2105 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
2106 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
2107 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
2108 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
2109 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
2110 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
2111 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
2112 ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
2113 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
2114 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
2115 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
2116 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
2117 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
2118 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
2119 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
2120 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
2121 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
2122 ok(obtained_desc.Flags == swapchain_desc.Flags,
2123 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
2125 refcount = IDXGISwapChain_Release(swapchain);
2126 ok(!refcount, "Swapchain has %u references left.\n", refcount);
2128 feature_level = ID3D11Device_GetFeatureLevel(device);
2129 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2130 feature_level, supported_feature_level);
2132 refcount = ID3D11Device_Release(device);
2133 ok(!refcount, "Device has %u references left.\n", refcount);
2135 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2136 NULL, NULL, &device, NULL, NULL);
2137 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2138 ID3D11Device_Release(device);
2140 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2141 NULL, NULL, NULL, NULL, NULL);
2142 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2144 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2145 NULL, NULL, NULL, &feature_level, NULL);
2146 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2147 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2148 feature_level, supported_feature_level);
2150 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2151 NULL, NULL, NULL, NULL, &immediate_context);
2152 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2153 ID3D11DeviceContext_Release(immediate_context);
2155 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2156 &swapchain_desc, NULL, NULL, NULL, NULL);
2157 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2159 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2160 &swapchain_desc, &swapchain, NULL, NULL, NULL);
2161 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2162 IDXGISwapChain_Release(swapchain);
2164 swapchain_desc.OutputWindow = NULL;
2165 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2166 &swapchain_desc, NULL, NULL, NULL, NULL);
2167 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2168 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2169 &swapchain_desc, NULL, &device, NULL, NULL);
2170 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2171 ID3D11Device_Release(device);
2173 swapchain = (IDXGISwapChain *)0xdeadbeef;
2174 device = (ID3D11Device *)0xdeadbeef;
2175 feature_level = 0xdeadbeef;
2176 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
2177 swapchain_desc.OutputWindow = NULL;
2178 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2179 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
2180 ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2181 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
2182 ok(!device, "Got unexpected device pointer %p.\n", device);
2183 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
2184 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
2186 swapchain = (IDXGISwapChain *)0xdeadbeef;
2187 device = (ID3D11Device *)0xdeadbeef;
2188 feature_level = 0xdeadbeef;
2189 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
2190 swapchain_desc.OutputWindow = window;
2191 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
2192 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2193 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
2194 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2195 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
2196 ok(!device, "Got unexpected device pointer %p.\n", device);
2197 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
2198 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
2200 DestroyWindow(window);
2203 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
2205 struct device_desc device_desc;
2206 IDXGIAdapter *dxgi_adapter;
2207 IDXGIDevice *dxgi_device;
2208 ID3D11Device *device;
2209 IUnknown *iface;
2210 ULONG refcount;
2211 HRESULT hr;
2213 device_desc.feature_level = &feature_level;
2214 device_desc.flags = 0;
2215 if (!(device = create_device(&device_desc)))
2217 skip("Failed to create device for feature level %#x.\n", feature_level);
2218 return;
2221 check_interface(device, &IID_IUnknown, TRUE, FALSE);
2222 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
2223 check_interface(device, &IID_IDXGIDevice, TRUE, FALSE);
2224 check_interface(device, &IID_IDXGIDevice1, TRUE, FALSE);
2225 check_interface(device, &IID_ID3D10Multithread, TRUE, TRUE); /* Not available on all Windows versions. */
2226 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
2227 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
2228 check_interface(device, &IID_ID3D11InfoQueue, enable_debug_layer, FALSE);
2230 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
2231 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
2232 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
2233 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
2234 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
2235 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
2236 IUnknown_Release(iface);
2237 IDXGIAdapter_Release(dxgi_adapter);
2238 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
2239 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
2240 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
2241 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
2242 IUnknown_Release(iface);
2243 IDXGIAdapter_Release(dxgi_adapter);
2244 IDXGIDevice_Release(dxgi_device);
2246 refcount = ID3D11Device_Release(device);
2247 ok(!refcount, "Device has %u references left.\n", refcount);
2249 device_desc.feature_level = &feature_level;
2250 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
2251 if (!(device = create_device(&device_desc)))
2253 skip("Failed to create debug device for feature level %#x.\n", feature_level);
2254 return;
2257 todo_wine check_interface(device, &IID_ID3D11InfoQueue, TRUE, FALSE);
2259 refcount = ID3D11Device_Release(device);
2260 ok(!refcount, "Device has %u references left.\n", refcount);
2263 static void test_immediate_context(void)
2265 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
2266 ULONG expected_refcount, refcount;
2267 ID3D11CommandList *command_list;
2268 ID3D11Multithread *multithread;
2269 ID3D11Buffer *buffer[2];
2270 ID3D11Device *device;
2271 unsigned int flags;
2272 BOOL enabled;
2273 HRESULT hr;
2275 static const unsigned int buffer_contents[] =
2277 0x11111111, 0x22222222, 0x33333333, 0x44444444,
2278 0x55555555, 0x66666666, 0x77777777, 0x88888888,
2281 if (!(device = create_device(NULL)))
2283 skip("Failed to create device.\n");
2284 return;
2287 expected_refcount = get_refcount(device) + 1;
2288 ID3D11Device_GetImmediateContext(device, &immediate_context);
2289 refcount = get_refcount(device);
2290 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
2291 previous_immediate_context = immediate_context;
2293 ID3D11Device_GetImmediateContext(device, &immediate_context);
2294 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
2295 refcount = get_refcount(device);
2296 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
2298 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
2299 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2300 refcount = ID3D11DeviceContext_Release(immediate_context);
2301 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2303 ID3D11Device_GetImmediateContext(device, &immediate_context);
2304 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
2305 refcount = ID3D11DeviceContext_Release(immediate_context);
2306 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2308 ID3D11Device_GetImmediateContext(device, &immediate_context);
2309 expected_refcount = get_refcount(immediate_context) + 1;
2310 hr = ID3D11DeviceContext_QueryInterface(immediate_context, &IID_ID3D11Multithread, (void **)&multithread);
2311 if (hr == E_NOINTERFACE)
2313 win_skip("ID3D11Multithread is not supported.\n");
2314 goto done;
2316 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2318 refcount = get_refcount(immediate_context);
2319 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2321 expected_refcount = refcount;
2322 refcount = get_refcount(multithread);
2323 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2325 enabled = ID3D11Multithread_GetMultithreadProtected(multithread);
2326 todo_wine ok(!enabled, "Multithread protection is %#x.\n", enabled);
2328 ID3D11Multithread_Release(multithread);
2330 ID3D11Device_GetImmediateContext(device, &immediate_context);
2332 flags = ID3D11DeviceContext_GetContextFlags(immediate_context);
2333 ok(!flags, "Got unexpected flags %#x.\n", flags);
2335 hr = ID3D11DeviceContext_FinishCommandList(immediate_context, FALSE, &command_list);
2336 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
2338 buffer[0] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 16, &buffer_contents[0]);
2339 buffer[1] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 16, &buffer_contents[4]);
2341 ID3D11DeviceContext_CopyResource(immediate_context, (ID3D11Resource *)buffer[1], (ID3D11Resource *)buffer[0]);
2343 hr = ID3D11DeviceContext_FinishCommandList(immediate_context, FALSE, &command_list);
2344 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
2346 ID3D11Buffer_Release(buffer[1]);
2347 ID3D11Buffer_Release(buffer[0]);
2348 ID3D11DeviceContext_Release(immediate_context);
2350 done:
2351 refcount = ID3D11DeviceContext_Release(immediate_context);
2352 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2353 refcount = ID3D11Device_Release(device);
2354 ok(!refcount, "Device has %u references left.\n", refcount);
2357 static void test_create_deferred_context(void)
2359 ULONG refcount, expected_refcount;
2360 struct device_desc device_desc;
2361 ID3D11DeviceContext *context;
2362 ID3D11Device *device;
2363 HRESULT hr;
2365 device_desc.feature_level = NULL;
2366 device_desc.flags = D3D11_CREATE_DEVICE_SINGLETHREADED;
2367 if (!(device = create_device(&device_desc)))
2369 skip("Failed to create single-threaded device.\n");
2370 return;
2373 hr = ID3D11Device_CreateDeferredContext(device, 0, &context);
2374 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Failed to create deferred context, hr %#x.\n", hr);
2375 if (hr == S_OK)
2376 ID3D11DeviceContext_Release(context);
2378 refcount = ID3D11Device_Release(device);
2379 ok(!refcount, "Device has %u references left.\n", refcount);
2381 if (!(device = create_device(NULL)))
2383 skip("Failed to create device.\n");
2384 return;
2387 expected_refcount = get_refcount(device) + 1;
2388 hr = ID3D11Device_CreateDeferredContext(device, 0, &context);
2389 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
2390 refcount = get_refcount(device);
2391 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2392 refcount = get_refcount(context);
2393 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2395 check_interface(context, &IID_IUnknown, TRUE, FALSE);
2396 check_interface(context, &IID_ID3D11DeviceChild, TRUE, FALSE);
2397 check_interface(context, &IID_ID3D11DeviceContext, TRUE, FALSE);
2398 check_interface(context, &IID_ID3D11Multithread, FALSE, FALSE);
2400 refcount = ID3D11DeviceContext_Release(context);
2401 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2403 refcount = ID3D11Device_Release(device);
2404 ok(!refcount, "Device has %u references left.\n", refcount);
2407 static void test_create_texture1d(void)
2409 ULONG refcount, expected_refcount;
2410 D3D11_SUBRESOURCE_DATA data = {0};
2411 ID3D11Device *device, *tmp;
2412 D3D11_TEXTURE1D_DESC desc;
2413 ID3D11Texture1D *texture;
2414 unsigned int i;
2415 HRESULT hr;
2417 if (!(device = create_device(NULL)))
2419 skip("Failed to create device.\n");
2420 return;
2423 desc.Width = 512;
2424 desc.MipLevels = 1;
2425 desc.ArraySize = 1;
2426 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2427 desc.Usage = D3D11_USAGE_DEFAULT;
2428 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2429 desc.CPUAccessFlags = 0;
2430 desc.MiscFlags = 0;
2432 hr = ID3D11Device_CreateTexture1D(device, &desc, &data, &texture);
2433 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2435 expected_refcount = get_refcount(device) + 1;
2436 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2437 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2438 refcount = get_refcount(device);
2439 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2440 tmp = NULL;
2441 expected_refcount = refcount + 1;
2442 ID3D11Texture1D_GetDevice(texture, &tmp);
2443 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2444 refcount = get_refcount(device);
2445 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2446 ID3D11Device_Release(tmp);
2448 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2449 ID3D11Texture1D_Release(texture);
2451 desc.MipLevels = 0;
2452 expected_refcount = get_refcount(device) + 1;
2453 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2454 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2455 refcount = get_refcount(device);
2456 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2457 tmp = NULL;
2458 expected_refcount = refcount + 1;
2459 ID3D11Texture1D_GetDevice(texture, &tmp);
2460 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2461 refcount = get_refcount(device);
2462 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2463 ID3D11Device_Release(tmp);
2465 ID3D11Texture1D_GetDesc(texture, &desc);
2466 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2467 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2468 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2469 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2470 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2471 ok(desc.BindFlags == D3D11_BIND_SHADER_RESOURCE, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
2472 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
2473 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
2475 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2476 ID3D11Texture1D_Release(texture);
2478 desc.MipLevels = 1;
2479 desc.ArraySize = 2;
2480 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2481 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2483 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2484 ID3D11Texture1D_Release(texture);
2486 for (i = 0; i < 4; ++i)
2488 desc.ArraySize = i;
2489 desc.Format = DXGI_FORMAT_R32G32B32A32_TYPELESS;
2490 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2491 desc.MiscFlags = 0;
2492 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2493 ok(hr == (i ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2494 if (SUCCEEDED(hr))
2495 ID3D11Texture1D_Release(texture);
2498 refcount = ID3D11Device_Release(device);
2499 ok(!refcount, "Device has %u references left.\n", refcount);
2502 static void test_texture1d_interfaces(void)
2504 ID3D10Texture1D *d3d10_texture;
2505 D3D11_TEXTURE1D_DESC desc;
2506 ID3D11Texture1D *texture;
2507 ID3D11Device *device;
2508 unsigned int i;
2509 ULONG refcount;
2510 HRESULT hr;
2512 static const struct test
2514 BOOL implements_d3d10_interfaces;
2515 UINT bind_flags;
2516 UINT misc_flags;
2517 UINT expected_bind_flags;
2518 UINT expected_misc_flags;
2520 desc_conversion_tests[] =
2523 TRUE,
2524 D3D11_BIND_SHADER_RESOURCE, 0,
2525 D3D10_BIND_SHADER_RESOURCE, 0
2528 TRUE,
2529 D3D11_BIND_UNORDERED_ACCESS, 0,
2530 D3D11_BIND_UNORDERED_ACCESS, 0
2533 FALSE,
2534 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2535 0, 0
2538 TRUE,
2539 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2540 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2544 if (!(device = create_device(NULL)))
2546 skip("Failed to create ID3D11Device, skipping tests.\n");
2547 return;
2550 desc.Width = 512;
2551 desc.MipLevels = 0;
2552 desc.ArraySize = 1;
2553 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2554 desc.Usage = D3D11_USAGE_DEFAULT;
2555 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2556 desc.CPUAccessFlags = 0;
2557 desc.MiscFlags = 0;
2559 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2560 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2561 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2562 hr = check_interface(texture, &IID_ID3D10Texture1D, TRUE, TRUE); /* Not available on all Windows versions. */
2563 ID3D11Texture1D_Release(texture);
2564 if (FAILED(hr))
2566 win_skip("1D textures do not implement ID3D10Texture1D, skipping tests.\n");
2567 ID3D11Device_Release(device);
2568 return;
2571 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2573 const struct test *current = &desc_conversion_tests[i];
2574 D3D10_TEXTURE1D_DESC d3d10_desc;
2575 ID3D10Device *d3d10_device;
2577 desc.Width = 512;
2578 desc.MipLevels = 1;
2579 desc.ArraySize = 1;
2580 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2581 desc.Usage = D3D11_USAGE_DEFAULT;
2582 desc.BindFlags = current->bind_flags;
2583 desc.CPUAccessFlags = 0;
2584 desc.MiscFlags = current->misc_flags;
2586 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2587 /* Shared resources are not supported by REF and WARP devices. */
2588 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2589 "Test %u: Failed to create a 1d texture, hr %#x.\n", i, hr);
2590 if (FAILED(hr))
2592 win_skip("Failed to create ID3D11Texture1D, skipping test %u.\n", i);
2593 continue;
2596 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2598 hr = ID3D11Texture1D_QueryInterface(texture, &IID_ID3D10Texture1D, (void **)&d3d10_texture);
2599 ID3D11Texture1D_Release(texture);
2601 if (current->implements_d3d10_interfaces)
2603 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture1D.\n", i);
2605 else
2607 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture1D.\n", i);
2608 if (SUCCEEDED(hr)) ID3D10Texture1D_Release(d3d10_texture);
2609 continue;
2612 ID3D10Texture1D_GetDesc(d3d10_texture, &d3d10_desc);
2614 ok(d3d10_desc.Width == desc.Width,
2615 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2616 ok(d3d10_desc.MipLevels == desc.MipLevels,
2617 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2618 ok(d3d10_desc.ArraySize == desc.ArraySize,
2619 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2620 ok(d3d10_desc.Format == desc.Format,
2621 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2622 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2623 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2624 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2625 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2626 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2627 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2629 d3d10_device = (ID3D10Device *)0xdeadbeef;
2630 ID3D10Texture1D_GetDevice(d3d10_texture, &d3d10_device);
2631 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2632 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2634 ID3D10Texture1D_Release(d3d10_texture);
2637 refcount = ID3D11Device_Release(device);
2638 ok(!refcount, "Device has %u references left.\n", refcount);
2641 static void test_create_texture2d(void)
2643 ULONG refcount, expected_refcount;
2644 D3D11_SUBRESOURCE_DATA data = {0};
2645 D3D_FEATURE_LEVEL feature_level;
2646 ID3D11Device *device, *tmp;
2647 D3D11_TEXTURE2D_DESC desc;
2648 ID3D11Texture2D *texture;
2649 UINT quality_level_count;
2650 unsigned int i;
2651 HRESULT hr;
2653 static const struct
2655 DXGI_FORMAT format;
2656 UINT array_size;
2657 D3D11_BIND_FLAG bind_flags;
2658 UINT misc_flags;
2659 BOOL succeeds;
2660 BOOL todo;
2662 tests[] =
2664 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
2665 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
2666 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
2667 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
2668 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2669 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2670 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2671 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2672 FALSE, FALSE},
2673 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2674 FALSE, FALSE},
2675 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2676 FALSE, FALSE},
2677 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2678 TRUE, FALSE},
2679 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2680 TRUE, FALSE},
2681 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2682 TRUE, FALSE},
2683 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2684 TRUE, FALSE},
2685 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2686 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2687 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2688 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2689 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2690 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2691 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2692 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2693 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2694 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2695 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2696 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2697 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2698 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2699 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2700 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2701 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2702 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2703 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2704 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
2705 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2706 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2707 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
2708 TRUE, FALSE},
2709 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2710 TRUE, FALSE},
2711 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2712 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
2713 FALSE, TRUE},
2714 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2715 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
2716 FALSE, TRUE},
2717 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
2718 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
2719 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
2720 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2721 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2722 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2723 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2724 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2725 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2726 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2727 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2728 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2729 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2730 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2731 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2732 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2733 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2734 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2735 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2736 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2737 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2738 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2739 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_SHARED | D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2740 FALSE, TRUE},
2741 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
2742 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2743 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
2744 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
2745 FALSE, TRUE},
2746 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2747 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2748 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2749 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2750 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2753 if (!(device = create_device(NULL)))
2755 skip("Failed to create device.\n");
2756 return;
2759 feature_level = ID3D11Device_GetFeatureLevel(device);
2761 desc.Width = 512;
2762 desc.Height = 512;
2763 desc.MipLevels = 1;
2764 desc.ArraySize = 1;
2765 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2766 desc.SampleDesc.Count = 1;
2767 desc.SampleDesc.Quality = 0;
2768 desc.Usage = D3D11_USAGE_DEFAULT;
2769 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2770 desc.CPUAccessFlags = 0;
2771 desc.MiscFlags = 0;
2773 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
2774 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2776 expected_refcount = get_refcount(device) + 1;
2777 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2778 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2779 refcount = get_refcount(device);
2780 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2781 tmp = NULL;
2782 expected_refcount = refcount + 1;
2783 ID3D11Texture2D_GetDevice(texture, &tmp);
2784 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2785 refcount = get_refcount(device);
2786 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2787 ID3D11Device_Release(tmp);
2789 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2790 ID3D11Texture2D_Release(texture);
2792 desc.MipLevels = 0;
2793 expected_refcount = get_refcount(device) + 1;
2794 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2795 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2796 refcount = get_refcount(device);
2797 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2798 tmp = NULL;
2799 expected_refcount = refcount + 1;
2800 ID3D11Texture2D_GetDevice(texture, &tmp);
2801 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2802 refcount = get_refcount(device);
2803 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2804 ID3D11Device_Release(tmp);
2806 ID3D11Texture2D_GetDesc(texture, &desc);
2807 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2808 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
2809 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2810 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2811 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2812 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
2813 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
2814 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2815 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
2816 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
2817 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
2819 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2820 ID3D11Texture2D_Release(texture);
2822 desc.MipLevels = 1;
2823 desc.ArraySize = 2;
2824 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2825 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2827 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2828 ID3D11Texture2D_Release(texture);
2830 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
2831 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
2832 desc.ArraySize = 1;
2833 desc.SampleDesc.Count = 2;
2834 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2835 if (quality_level_count)
2837 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
2838 ID3D11Texture2D_Release(texture);
2839 desc.SampleDesc.Quality = quality_level_count;
2840 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2842 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2844 /* We assume 15 samples multisampling is never supported in practice. */
2845 desc.SampleDesc.Count = 15;
2846 desc.SampleDesc.Quality = 0;
2847 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2848 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2850 desc.SampleDesc.Count = 1;
2851 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2853 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
2854 BOOL todo = tests[i].todo;
2856 if (feature_level < D3D_FEATURE_LEVEL_10_1
2857 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
2858 && tests[i].array_size > 6)
2860 expected_hr = E_INVALIDARG;
2861 todo = TRUE;
2864 desc.ArraySize = tests[i].array_size;
2865 desc.Format = tests[i].format;
2866 desc.BindFlags = tests[i].bind_flags;
2867 desc.MiscFlags = tests[i].misc_flags;
2868 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2870 todo_wine_if(todo)
2871 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
2872 i, hr, desc.Format);
2874 if (SUCCEEDED(hr))
2875 ID3D11Texture2D_Release(texture);
2878 refcount = ID3D11Device_Release(device);
2879 ok(!refcount, "Device has %u references left.\n", refcount);
2882 static void test_texture2d_interfaces(void)
2884 ID3D10Texture2D *d3d10_texture;
2885 D3D11_TEXTURE2D_DESC desc;
2886 ID3D11Texture2D *texture;
2887 ID3D11Device *device;
2888 unsigned int i;
2889 ULONG refcount;
2890 HRESULT hr;
2892 static const struct test
2894 BOOL implements_d3d10_interfaces;
2895 UINT bind_flags;
2896 UINT misc_flags;
2897 UINT expected_bind_flags;
2898 UINT expected_misc_flags;
2900 desc_conversion_tests[] =
2903 TRUE,
2904 D3D11_BIND_SHADER_RESOURCE, 0,
2905 D3D10_BIND_SHADER_RESOURCE, 0
2908 TRUE,
2909 D3D11_BIND_UNORDERED_ACCESS, 0,
2910 D3D11_BIND_UNORDERED_ACCESS, 0
2913 FALSE,
2914 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2915 0, 0
2918 TRUE,
2919 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2920 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2923 TRUE,
2924 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
2925 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2929 if (!(device = create_device(NULL)))
2931 skip("Failed to create ID3D11Device, skipping tests.\n");
2932 return;
2935 desc.Width = 512;
2936 desc.Height = 512;
2937 desc.MipLevels = 0;
2938 desc.ArraySize = 1;
2939 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2940 desc.SampleDesc.Count = 1;
2941 desc.SampleDesc.Quality = 0;
2942 desc.Usage = D3D11_USAGE_DEFAULT;
2943 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2944 desc.CPUAccessFlags = 0;
2945 desc.MiscFlags = 0;
2947 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2948 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2949 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2950 hr = check_interface(texture, &IID_ID3D10Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
2951 ID3D11Texture2D_Release(texture);
2952 if (FAILED(hr))
2954 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
2955 ID3D11Device_Release(device);
2956 return;
2959 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2961 const struct test *current = &desc_conversion_tests[i];
2962 D3D10_TEXTURE2D_DESC d3d10_desc;
2963 ID3D10Device *d3d10_device;
2965 desc.Width = 512;
2966 desc.Height = 512;
2967 desc.MipLevels = 1;
2968 desc.ArraySize = 1;
2969 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2970 desc.SampleDesc.Count = 1;
2971 desc.SampleDesc.Quality = 0;
2972 desc.Usage = D3D11_USAGE_DEFAULT;
2973 desc.BindFlags = current->bind_flags;
2974 desc.CPUAccessFlags = 0;
2975 desc.MiscFlags = current->misc_flags;
2977 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2978 /* Shared resources are not supported by REF and WARP devices. */
2979 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2980 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2981 if (FAILED(hr))
2983 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
2984 continue;
2987 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2989 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2990 ID3D11Texture2D_Release(texture);
2992 if (current->implements_d3d10_interfaces)
2994 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2996 else
2998 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2999 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
3000 continue;
3003 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
3005 ok(d3d10_desc.Width == desc.Width,
3006 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
3007 ok(d3d10_desc.Height == desc.Height,
3008 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
3009 ok(d3d10_desc.MipLevels == desc.MipLevels,
3010 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
3011 ok(d3d10_desc.ArraySize == desc.ArraySize,
3012 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
3013 ok(d3d10_desc.Format == desc.Format,
3014 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
3015 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
3016 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
3017 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
3018 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
3019 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3020 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3021 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3022 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3023 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3024 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3025 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3026 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3028 d3d10_device = (ID3D10Device *)0xdeadbeef;
3029 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
3030 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3031 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3033 ID3D10Texture2D_Release(d3d10_texture);
3036 refcount = ID3D11Device_Release(device);
3037 ok(!refcount, "Device has %u references left.\n", refcount);
3040 static void test_create_texture3d(void)
3042 ULONG refcount, expected_refcount;
3043 D3D11_SUBRESOURCE_DATA data = {0};
3044 ID3D11Device *device, *tmp;
3045 D3D11_TEXTURE3D_DESC desc;
3046 ID3D11Texture3D *texture;
3047 unsigned int i;
3048 HRESULT hr;
3050 static const struct
3052 DXGI_FORMAT format;
3053 D3D11_BIND_FLAG bind_flags;
3054 BOOL succeeds;
3055 BOOL todo;
3057 tests[] =
3059 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
3060 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
3061 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
3062 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
3063 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
3064 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
3065 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
3066 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
3067 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
3068 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
3069 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
3070 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
3073 if (!(device = create_device(NULL)))
3075 skip("Failed to create ID3D11Device, skipping tests.\n");
3076 return;
3079 desc.Width = 64;
3080 desc.Height = 64;
3081 desc.Depth = 64;
3082 desc.MipLevels = 1;
3083 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3084 desc.Usage = D3D11_USAGE_DEFAULT;
3085 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3086 desc.CPUAccessFlags = 0;
3087 desc.MiscFlags = 0;
3089 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
3090 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3092 expected_refcount = get_refcount(device) + 1;
3093 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3094 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
3095 refcount = get_refcount(device);
3096 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3097 tmp = NULL;
3098 expected_refcount = refcount + 1;
3099 ID3D11Texture3D_GetDevice(texture, &tmp);
3100 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3101 refcount = get_refcount(device);
3102 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3103 ID3D11Device_Release(tmp);
3105 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3106 ID3D11Texture3D_Release(texture);
3108 desc.MipLevels = 0;
3109 expected_refcount = get_refcount(device) + 1;
3110 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3111 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
3112 refcount = get_refcount(device);
3113 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3114 tmp = NULL;
3115 expected_refcount = refcount + 1;
3116 ID3D11Texture3D_GetDevice(texture, &tmp);
3117 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3118 refcount = get_refcount(device);
3119 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3120 ID3D11Device_Release(tmp);
3122 ID3D11Texture3D_GetDesc(texture, &desc);
3123 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
3124 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
3125 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
3126 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
3127 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
3128 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
3129 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
3130 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
3131 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
3133 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3134 ID3D11Texture3D_Release(texture);
3136 desc.MipLevels = 1;
3137 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3139 desc.Format = tests[i].format;
3140 desc.BindFlags = tests[i].bind_flags;
3141 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3143 todo_wine_if(tests[i].todo)
3144 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
3146 if (SUCCEEDED(hr))
3147 ID3D11Texture3D_Release(texture);
3150 refcount = ID3D11Device_Release(device);
3151 ok(!refcount, "Device has %u references left.\n", refcount);
3154 static void test_texture3d_interfaces(void)
3156 ID3D10Texture3D *d3d10_texture;
3157 D3D11_TEXTURE3D_DESC desc;
3158 ID3D11Texture3D *texture;
3159 ID3D11Device *device;
3160 unsigned int i;
3161 ULONG refcount;
3162 HRESULT hr;
3164 static const struct test
3166 BOOL implements_d3d10_interfaces;
3167 UINT bind_flags;
3168 UINT misc_flags;
3169 UINT expected_bind_flags;
3170 UINT expected_misc_flags;
3172 desc_conversion_tests[] =
3175 TRUE,
3176 D3D11_BIND_SHADER_RESOURCE, 0,
3177 D3D10_BIND_SHADER_RESOURCE, 0
3180 TRUE,
3181 D3D11_BIND_UNORDERED_ACCESS, 0,
3182 D3D11_BIND_UNORDERED_ACCESS, 0
3185 FALSE,
3186 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
3187 0, 0
3190 TRUE,
3191 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
3192 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
3196 if (!(device = create_device(NULL)))
3198 skip("Failed to create ID3D11Device.\n");
3199 return;
3202 desc.Width = 64;
3203 desc.Height = 64;
3204 desc.Depth = 64;
3205 desc.MipLevels = 0;
3206 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3207 desc.Usage = D3D11_USAGE_DEFAULT;
3208 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3209 desc.CPUAccessFlags = 0;
3210 desc.MiscFlags = 0;
3212 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3213 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
3214 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3215 hr = check_interface(texture, &IID_ID3D10Texture3D, TRUE, TRUE); /* Not available on all Windows versions. */
3216 ID3D11Texture3D_Release(texture);
3217 if (FAILED(hr))
3219 win_skip("3D textures do not implement ID3D10Texture3D.\n");
3220 ID3D11Device_Release(device);
3221 return;
3224 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
3226 const struct test *current = &desc_conversion_tests[i];
3227 D3D10_TEXTURE3D_DESC d3d10_desc;
3228 ID3D10Device *d3d10_device;
3230 desc.Width = 64;
3231 desc.Height = 64;
3232 desc.Depth = 64;
3233 desc.MipLevels = 1;
3234 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3235 desc.Usage = D3D11_USAGE_DEFAULT;
3236 desc.BindFlags = current->bind_flags;
3237 desc.CPUAccessFlags = 0;
3238 desc.MiscFlags = current->misc_flags;
3240 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3241 /* Shared resources are not supported by REF and WARP devices. */
3242 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
3243 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
3244 if (FAILED(hr))
3246 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
3247 continue;
3250 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3252 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
3253 ID3D11Texture3D_Release(texture);
3255 if (current->implements_d3d10_interfaces)
3257 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
3259 else
3261 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
3262 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
3263 continue;
3266 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
3268 ok(d3d10_desc.Width == desc.Width,
3269 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
3270 ok(d3d10_desc.Height == desc.Height,
3271 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
3272 ok(d3d10_desc.Depth == desc.Depth,
3273 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
3274 ok(d3d10_desc.MipLevels == desc.MipLevels,
3275 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
3276 ok(d3d10_desc.Format == desc.Format,
3277 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
3278 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3279 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3280 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3281 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3282 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3283 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3284 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3285 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3287 d3d10_device = (ID3D10Device *)0xdeadbeef;
3288 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
3289 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3290 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3292 ID3D10Texture3D_Release(d3d10_texture);
3295 refcount = ID3D11Device_Release(device);
3296 ok(!refcount, "Device has %u references left.\n", refcount);
3299 static void test_create_buffer(void)
3301 ID3D10Buffer *d3d10_buffer;
3302 HRESULT expected_hr, hr;
3303 D3D11_BUFFER_DESC desc;
3304 ID3D11Buffer *buffer;
3305 ID3D11Device *device;
3306 unsigned int i;
3307 ULONG refcount;
3309 static const struct test
3311 BOOL succeeds;
3312 BOOL implements_d3d10_interfaces;
3313 UINT bind_flags;
3314 UINT misc_flags;
3315 UINT structure_stride;
3316 UINT expected_bind_flags;
3317 UINT expected_misc_flags;
3319 tests[] =
3322 TRUE, TRUE,
3323 D3D11_BIND_VERTEX_BUFFER, 0, 0,
3324 D3D10_BIND_VERTEX_BUFFER, 0
3327 TRUE, TRUE,
3328 D3D11_BIND_INDEX_BUFFER, 0, 0,
3329 D3D10_BIND_INDEX_BUFFER, 0
3332 TRUE, TRUE,
3333 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
3334 D3D10_BIND_CONSTANT_BUFFER, 0
3337 TRUE, TRUE,
3338 D3D11_BIND_SHADER_RESOURCE, 0, 0,
3339 D3D10_BIND_SHADER_RESOURCE, 0
3342 TRUE, TRUE,
3343 D3D11_BIND_STREAM_OUTPUT, 0, 0,
3344 D3D10_BIND_STREAM_OUTPUT, 0
3347 TRUE, TRUE,
3348 D3D11_BIND_RENDER_TARGET, 0, 0,
3349 D3D10_BIND_RENDER_TARGET, 0
3352 TRUE, TRUE,
3353 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
3354 D3D11_BIND_UNORDERED_ACCESS, 0
3357 TRUE, TRUE,
3358 0, D3D11_RESOURCE_MISC_SHARED, 0,
3359 0, D3D10_RESOURCE_MISC_SHARED
3362 TRUE, TRUE,
3363 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
3364 0, 0
3367 FALSE, FALSE,
3368 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3371 FALSE, FALSE,
3372 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3375 FALSE, FALSE,
3376 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3379 TRUE, TRUE,
3380 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3381 D3D10_BIND_SHADER_RESOURCE, 0
3384 FALSE, FALSE,
3385 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3388 FALSE, FALSE,
3389 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3392 TRUE, TRUE,
3393 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3394 D3D11_BIND_UNORDERED_ACCESS, 0
3397 FALSE, FALSE,
3398 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3400 /* Structured buffers do not implement ID3D10Buffer. */
3402 TRUE, FALSE,
3403 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3406 TRUE, FALSE,
3407 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3410 FALSE, FALSE,
3411 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
3414 FALSE, FALSE,
3415 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
3418 FALSE, FALSE,
3419 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
3422 FALSE, FALSE,
3423 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
3426 FALSE, FALSE,
3427 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
3430 TRUE, FALSE,
3431 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
3434 FALSE, FALSE,
3435 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
3438 TRUE, FALSE,
3439 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
3442 TRUE, FALSE,
3443 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
3446 FALSE, FALSE,
3447 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
3450 TRUE, FALSE,
3451 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
3454 TRUE, TRUE,
3455 0, 0, 513,
3456 0, 0
3459 TRUE, TRUE,
3460 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
3461 D3D10_BIND_CONSTANT_BUFFER, 0
3464 TRUE, TRUE,
3465 D3D11_BIND_SHADER_RESOURCE, 0, 513,
3466 D3D10_BIND_SHADER_RESOURCE, 0
3469 TRUE, TRUE,
3470 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
3471 D3D11_BIND_UNORDERED_ACCESS, 0
3474 FALSE, FALSE,
3475 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3478 FALSE, FALSE,
3479 D3D11_BIND_SHADER_RESOURCE,
3480 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3483 TRUE, TRUE,
3484 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
3485 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
3489 if (!(device = create_device(NULL)))
3491 skip("Failed to create ID3D11Device.\n");
3492 return;
3495 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
3496 hr = check_interface(buffer, &IID_ID3D10Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
3497 ID3D11Buffer_Release(buffer);
3498 if (FAILED(hr))
3500 win_skip("Buffers do not implement ID3D10Buffer.\n");
3501 ID3D11Device_Release(device);
3502 return;
3505 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3507 const struct test *current = &tests[i];
3508 D3D11_BUFFER_DESC obtained_desc;
3509 D3D10_BUFFER_DESC d3d10_desc;
3510 ID3D10Device *d3d10_device;
3512 desc.ByteWidth = 1024;
3513 desc.Usage = D3D11_USAGE_DEFAULT;
3514 desc.BindFlags = current->bind_flags;
3515 desc.CPUAccessFlags = 0;
3516 desc.MiscFlags = current->misc_flags;
3517 desc.StructureByteStride = current->structure_stride;
3519 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
3520 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
3521 /* Shared resources are not supported by REF and WARP devices. */
3522 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
3523 i, hr, expected_hr);
3524 if (FAILED(hr))
3526 if (hr == E_OUTOFMEMORY)
3527 win_skip("Failed to create a buffer, skipping test %u.\n", i);
3528 continue;
3531 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
3532 desc.StructureByteStride = 0;
3534 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
3536 ok(obtained_desc.ByteWidth == desc.ByteWidth,
3537 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
3538 ok(obtained_desc.Usage == desc.Usage,
3539 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
3540 ok(obtained_desc.BindFlags == desc.BindFlags,
3541 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
3542 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
3543 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
3544 ok(obtained_desc.MiscFlags == desc.MiscFlags,
3545 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
3546 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
3547 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
3549 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
3550 ID3D11Buffer_Release(buffer);
3552 if (current->implements_d3d10_interfaces)
3554 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
3556 else
3558 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
3559 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
3560 continue;
3563 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
3565 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
3566 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
3567 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3568 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3569 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3570 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3571 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3572 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3573 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3574 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3576 d3d10_device = (ID3D10Device *)0xdeadbeef;
3577 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
3578 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3579 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3581 ID3D10Buffer_Release(d3d10_buffer);
3584 memset(&desc, 0, sizeof(desc));
3585 desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
3586 for (i = 0; i <= 32; ++i)
3588 desc.ByteWidth = i;
3589 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
3590 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
3591 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
3592 if (SUCCEEDED(hr))
3593 ID3D11Buffer_Release(buffer);
3596 refcount = ID3D11Device_Release(device);
3597 ok(!refcount, "Device has %u references left.\n", refcount);
3600 static void test_create_depthstencil_view(void)
3602 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
3603 D3D11_TEXTURE2D_DESC texture_desc;
3604 ULONG refcount, expected_refcount;
3605 ID3D11DepthStencilView *dsview;
3606 ID3D11Device *device, *tmp;
3607 ID3D11Texture2D *texture;
3608 unsigned int i;
3609 HRESULT hr;
3611 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3612 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
3613 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
3614 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
3615 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
3616 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
3617 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
3618 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
3619 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
3620 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
3621 static const struct
3623 struct
3625 unsigned int miplevel_count;
3626 unsigned int array_size;
3627 DXGI_FORMAT format;
3628 } texture;
3629 struct dsv_desc dsv_desc;
3630 struct dsv_desc expected_dsv_desc;
3632 tests[] =
3634 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
3635 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
3636 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3637 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
3638 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
3639 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3640 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3641 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3642 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3643 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3644 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
3645 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
3646 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
3647 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
3648 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
3649 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
3650 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
3651 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3652 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3653 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3654 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3655 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3656 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3657 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3658 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3659 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
3660 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
3662 static const struct
3664 struct
3666 unsigned int miplevel_count;
3667 unsigned int array_size;
3668 DXGI_FORMAT format;
3669 } texture;
3670 struct dsv_desc dsv_desc;
3672 invalid_desc_tests[] =
3674 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
3675 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
3676 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
3677 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
3678 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
3679 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3680 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
3681 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
3682 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
3683 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
3684 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
3685 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
3686 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
3688 #undef FMT_UNKNOWN
3689 #undef D24S8
3690 #undef R24G8_TL
3691 #undef DIM_UNKNOWN
3692 #undef TEX_1D
3693 #undef TEX_1D_ARRAY
3694 #undef TEX_2D
3695 #undef TEX_2D_ARRAY
3696 #undef TEX_2DMS
3697 #undef TEX_2DMS_ARR
3699 if (!(device = create_device(NULL)))
3701 skip("Failed to create device.\n");
3702 return;
3705 texture_desc.Width = 512;
3706 texture_desc.Height = 512;
3707 texture_desc.MipLevels = 1;
3708 texture_desc.ArraySize = 1;
3709 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
3710 texture_desc.SampleDesc.Count = 1;
3711 texture_desc.SampleDesc.Quality = 0;
3712 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3713 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3714 texture_desc.CPUAccessFlags = 0;
3715 texture_desc.MiscFlags = 0;
3717 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3718 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
3720 expected_refcount = get_refcount(device) + 1;
3721 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
3722 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
3723 refcount = get_refcount(device);
3724 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3725 tmp = NULL;
3726 expected_refcount = refcount + 1;
3727 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
3728 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3729 refcount = get_refcount(device);
3730 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3731 ID3D11Device_Release(tmp);
3733 memset(&dsv_desc, 0, sizeof(dsv_desc));
3734 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
3735 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
3736 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
3737 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
3738 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
3739 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
3741 ID3D11DepthStencilView_Release(dsview);
3742 ID3D11Texture2D_Release(texture);
3744 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3746 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
3748 texture_desc.MipLevels = tests[i].texture.miplevel_count;
3749 texture_desc.ArraySize = tests[i].texture.array_size;
3750 texture_desc.Format = tests[i].texture.format;
3752 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3753 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3755 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
3757 current_desc = NULL;
3759 else
3761 current_desc = &dsv_desc;
3762 get_dsv_desc(current_desc, &tests[i].dsv_desc);
3765 expected_refcount = get_refcount(texture);
3766 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
3767 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
3768 refcount = get_refcount(texture);
3769 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3771 /* Not available on all Windows versions. */
3772 check_interface(dsview, &IID_ID3D10DepthStencilView, TRUE, TRUE);
3774 memset(&dsv_desc, 0, sizeof(dsv_desc));
3775 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
3776 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
3778 ID3D11DepthStencilView_Release(dsview);
3779 ID3D11Texture2D_Release(texture);
3782 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3784 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3785 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
3786 texture_desc.Format = invalid_desc_tests[i].texture.format;
3788 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3789 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3791 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
3792 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
3793 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3795 ID3D11Texture2D_Release(texture);
3798 refcount = ID3D11Device_Release(device);
3799 ok(!refcount, "Device has %u references left.\n", refcount);
3802 static void test_depthstencil_view_interfaces(void)
3804 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
3805 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
3806 ID3D10DepthStencilView *d3d10_dsview;
3807 D3D11_TEXTURE2D_DESC texture_desc;
3808 ID3D11DepthStencilView *dsview;
3809 ID3D11Texture2D *texture;
3810 ID3D11Device *device;
3811 ULONG refcount;
3812 HRESULT hr;
3814 if (!(device = create_device(NULL)))
3816 skip("Failed to create device.\n");
3817 return;
3820 texture_desc.Width = 512;
3821 texture_desc.Height = 512;
3822 texture_desc.MipLevels = 1;
3823 texture_desc.ArraySize = 1;
3824 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
3825 texture_desc.SampleDesc.Count = 1;
3826 texture_desc.SampleDesc.Quality = 0;
3827 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3828 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3829 texture_desc.CPUAccessFlags = 0;
3830 texture_desc.MiscFlags = 0;
3832 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3833 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
3835 dsv_desc.Format = texture_desc.Format;
3836 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
3837 dsv_desc.Flags = 0;
3838 U(dsv_desc).Texture2D.MipSlice = 0;
3840 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
3841 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
3843 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
3844 ID3D11DepthStencilView_Release(dsview);
3845 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3846 "Depth stencil view should implement ID3D10DepthStencilView.\n");
3848 if (FAILED(hr))
3850 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
3851 goto done;
3854 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
3855 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
3856 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
3857 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
3858 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
3859 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
3861 ID3D10DepthStencilView_Release(d3d10_dsview);
3863 done:
3864 ID3D11Texture2D_Release(texture);
3866 refcount = ID3D11Device_Release(device);
3867 ok(!refcount, "Device has %u references left.\n", refcount);
3870 static void test_create_rendertarget_view(void)
3872 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
3873 D3D11_TEXTURE3D_DESC texture3d_desc;
3874 D3D11_TEXTURE2D_DESC texture2d_desc;
3875 D3D11_SUBRESOURCE_DATA data = {0};
3876 ULONG refcount, expected_refcount;
3877 D3D11_BUFFER_DESC buffer_desc;
3878 ID3D11RenderTargetView *rtview;
3879 ID3D11Device *device, *tmp;
3880 ID3D11Texture3D *texture3d;
3881 ID3D11Texture2D *texture2d;
3882 ID3D11Resource *texture;
3883 ID3D11Buffer *buffer;
3884 unsigned int i;
3885 HRESULT hr;
3887 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3888 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3889 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3890 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
3891 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
3892 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
3893 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
3894 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
3895 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
3896 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
3897 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
3898 static const struct
3900 struct
3902 unsigned int miplevel_count;
3903 unsigned int depth_or_array_size;
3904 DXGI_FORMAT format;
3905 } texture;
3906 struct rtv_desc rtv_desc;
3907 struct rtv_desc expected_rtv_desc;
3909 tests[] =
3911 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
3912 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
3913 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3914 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
3915 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
3916 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3917 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3918 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3919 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3920 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3921 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
3922 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
3923 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
3924 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
3925 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
3926 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
3927 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
3928 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3929 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3930 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3931 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3932 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3933 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3934 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3935 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3936 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3937 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3938 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3939 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3940 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3941 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3942 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3943 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
3944 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
3945 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
3946 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
3947 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3948 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3949 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
3950 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
3951 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
3952 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
3953 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
3954 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
3956 static const struct
3958 struct
3960 D3D11_RTV_DIMENSION dimension;
3961 unsigned int miplevel_count;
3962 unsigned int depth_or_array_size;
3963 DXGI_FORMAT format;
3964 } texture;
3965 struct rtv_desc rtv_desc;
3967 invalid_desc_tests[] =
3969 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3970 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3971 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3972 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3973 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
3974 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
3975 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
3976 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3977 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
3978 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
3979 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
3980 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
3981 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
3982 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
3983 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
3984 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3985 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3986 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3987 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3988 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3989 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3990 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3991 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3992 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
3993 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3994 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3995 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3996 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3997 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3998 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3999 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
4000 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
4001 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
4002 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
4003 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
4005 #undef FMT_UNKNOWN
4006 #undef RGBA8_UNORM
4007 #undef RGBA8_TL
4008 #undef DIM_UNKNOWN
4009 #undef TEX_1D
4010 #undef TEX_1D_ARRAY
4011 #undef TEX_2D
4012 #undef TEX_2D_ARRAY
4013 #undef TEX_2DMS
4014 #undef TEX_2DMS_ARR
4015 #undef TEX_3D
4017 if (!(device = create_device(NULL)))
4019 skip("Failed to create device.\n");
4020 return;
4023 buffer_desc.ByteWidth = 1024;
4024 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4025 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4026 buffer_desc.CPUAccessFlags = 0;
4027 buffer_desc.MiscFlags = 0;
4028 buffer_desc.StructureByteStride = 0;
4030 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
4031 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4033 expected_refcount = get_refcount(device) + 1;
4034 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
4035 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
4036 refcount = get_refcount(device);
4037 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4038 tmp = NULL;
4039 expected_refcount = refcount + 1;
4040 ID3D11Buffer_GetDevice(buffer, &tmp);
4041 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4042 refcount = get_refcount(device);
4043 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4044 ID3D11Device_Release(tmp);
4046 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4047 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
4048 U1(U(rtv_desc).Buffer).ElementOffset = 0;
4049 U2(U(rtv_desc).Buffer).ElementWidth = 64;
4051 if (!enable_debug_layer)
4053 rtview = (void *)0xdeadbeef;
4054 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
4055 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4056 ok(!rtview, "Unexpected pointer %p.\n", rtview);
4059 expected_refcount = get_refcount(device) + 1;
4060 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
4061 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
4062 refcount = get_refcount(device);
4063 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4064 tmp = NULL;
4065 expected_refcount = refcount + 1;
4066 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
4067 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4068 refcount = get_refcount(device);
4069 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4070 ID3D11Device_Release(tmp);
4072 /* Not available on all Windows versions. */
4073 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
4075 ID3D11RenderTargetView_Release(rtview);
4076 ID3D11Buffer_Release(buffer);
4078 texture2d_desc.Width = 512;
4079 texture2d_desc.Height = 512;
4080 texture2d_desc.SampleDesc.Count = 1;
4081 texture2d_desc.SampleDesc.Quality = 0;
4082 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
4083 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4084 texture2d_desc.CPUAccessFlags = 0;
4085 texture2d_desc.MiscFlags = 0;
4087 texture3d_desc.Width = 64;
4088 texture3d_desc.Height = 64;
4089 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
4090 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4091 texture3d_desc.CPUAccessFlags = 0;
4092 texture3d_desc.MiscFlags = 0;
4094 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4096 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
4098 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
4100 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
4101 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
4102 texture2d_desc.Format = tests[i].texture.format;
4104 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4105 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4106 texture = (ID3D11Resource *)texture2d;
4108 else
4110 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
4111 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
4112 texture3d_desc.Format = tests[i].texture.format;
4114 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4115 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4116 texture = (ID3D11Resource *)texture3d;
4119 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
4121 current_desc = NULL;
4123 else
4125 current_desc = &rtv_desc;
4126 get_rtv_desc(current_desc, &tests[i].rtv_desc);
4129 expected_refcount = get_refcount(texture);
4130 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
4131 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
4132 refcount = get_refcount(texture);
4133 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
4135 /* Not available on all Windows versions. */
4136 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
4138 memset(&rtv_desc, 0, sizeof(rtv_desc));
4139 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
4140 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
4142 ID3D11RenderTargetView_Release(rtview);
4143 ID3D11Resource_Release(texture);
4146 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
4148 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
4149 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
4151 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
4153 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4154 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
4155 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
4157 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4158 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4159 texture = (ID3D11Resource *)texture2d;
4161 else
4163 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4164 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
4165 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
4167 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4168 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4169 texture = (ID3D11Resource *)texture3d;
4172 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
4173 rtview = (void *)0xdeadbeef;
4174 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
4175 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
4176 ok(!rtview, "Unexpected pointer %p.\n", rtview);
4178 ID3D11Resource_Release(texture);
4181 refcount = ID3D11Device_Release(device);
4182 ok(!refcount, "Device has %u references left.\n", refcount);
4185 static void test_create_shader_resource_view(void)
4187 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
4188 D3D11_TEXTURE3D_DESC texture3d_desc;
4189 D3D11_TEXTURE2D_DESC texture2d_desc;
4190 ULONG refcount, expected_refcount;
4191 ID3D11ShaderResourceView *srview;
4192 D3D_FEATURE_LEVEL feature_level;
4193 D3D11_BUFFER_DESC buffer_desc;
4194 ID3D11Device *device, *tmp;
4195 ID3D11Texture3D *texture3d;
4196 ID3D11Texture2D *texture2d;
4197 ID3D11Resource *texture;
4198 ID3D11Buffer *buffer;
4199 unsigned int i;
4200 HRESULT hr;
4202 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
4203 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
4204 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
4205 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
4206 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
4207 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
4208 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
4209 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
4210 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
4211 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
4212 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
4213 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
4214 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
4215 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
4216 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
4217 static const struct
4219 struct
4221 unsigned int miplevel_count;
4222 unsigned int depth_or_array_size;
4223 DXGI_FORMAT format;
4224 } texture;
4225 struct srv_desc srv_desc;
4226 struct srv_desc expected_srv_desc;
4228 tests[] =
4230 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4231 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4232 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4233 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4234 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4235 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4236 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
4237 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
4238 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
4239 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
4240 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
4241 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
4242 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
4243 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
4244 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
4245 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4246 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4247 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4248 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4249 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4250 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4251 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4252 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4253 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
4254 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
4255 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4256 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4257 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4258 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
4259 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4260 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4261 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4262 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4263 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4264 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
4265 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
4266 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4267 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
4268 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4269 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4270 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4271 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4272 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4273 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4274 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4275 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
4276 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
4277 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
4279 static const struct
4281 struct
4283 D3D11_SRV_DIMENSION dimension;
4284 unsigned int miplevel_count;
4285 unsigned int depth_or_array_size;
4286 DXGI_FORMAT format;
4287 } texture;
4288 struct srv_desc srv_desc;
4290 invalid_desc_tests[] =
4292 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
4293 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
4294 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4295 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4296 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4297 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
4298 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
4299 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
4300 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
4301 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
4302 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
4303 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
4304 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
4305 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
4306 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
4307 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
4308 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
4309 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
4310 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
4311 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
4312 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
4313 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
4314 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4315 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
4316 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
4317 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
4318 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
4319 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
4320 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
4321 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
4322 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
4323 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
4324 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
4325 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
4326 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4327 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4328 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 1}},
4329 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4330 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 1}},
4331 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4332 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4333 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4334 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4335 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4336 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
4337 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4338 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4339 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4340 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4341 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
4342 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
4343 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
4344 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
4345 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
4346 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
4347 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
4349 #undef FMT_UNKNOWN
4350 #undef RGBA8_UNORM
4351 #undef RGBA8_SRGB
4352 #undef RGBA8_UINT
4353 #undef RGBA8_TL
4354 #undef DIM_UNKNOWN
4355 #undef TEX_1D
4356 #undef TEX_1D_ARRAY
4357 #undef TEX_2D
4358 #undef TEX_2D_ARRAY
4359 #undef TEX_2DMS
4360 #undef TEX_2DMS_ARR
4361 #undef TEX_3D
4362 #undef TEX_CUBE
4363 #undef CUBE_ARRAY
4365 if (!(device = create_device(NULL)))
4367 skip("Failed to create device.\n");
4368 return;
4370 feature_level = ID3D11Device_GetFeatureLevel(device);
4372 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
4374 srview = (void *)0xdeadbeef;
4375 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
4376 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4377 ok(!srview, "Unexpected pointer %p.\n", srview);
4379 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4380 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
4381 U1(U(srv_desc).Buffer).ElementOffset = 0;
4382 U2(U(srv_desc).Buffer).ElementWidth = 64;
4384 srview = (void *)0xdeadbeef;
4385 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
4386 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4387 ok(!srview, "Unexpected pointer %p.\n", srview);
4389 expected_refcount = get_refcount(device) + 1;
4390 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
4391 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
4392 refcount = get_refcount(device);
4393 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4394 tmp = NULL;
4395 expected_refcount = refcount + 1;
4396 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
4397 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4398 refcount = get_refcount(device);
4399 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4400 ID3D11Device_Release(tmp);
4402 /* Not available on all Windows versions. */
4403 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
4404 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
4406 ID3D11ShaderResourceView_Release(srview);
4407 ID3D11Buffer_Release(buffer);
4409 /* Without D3D11_BIND_SHADER_RESOURCE. */
4410 buffer = create_buffer(device, 0, 1024, NULL);
4412 srview = (void *)0xdeadbeef;
4413 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
4414 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4415 ok(!srview, "Unexpected pointer %p.\n", srview);
4417 ID3D11Buffer_Release(buffer);
4419 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
4421 buffer_desc.ByteWidth = 1024;
4422 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4423 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4424 buffer_desc.CPUAccessFlags = 0;
4425 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
4426 buffer_desc.StructureByteStride = 4;
4428 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
4429 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
4431 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
4432 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
4434 memset(&srv_desc, 0, sizeof(srv_desc));
4435 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
4437 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
4438 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
4439 srv_desc.ViewDimension);
4440 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
4441 U1(U(srv_desc).Buffer).FirstElement);
4442 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
4443 U2(U(srv_desc).Buffer).NumElements);
4445 ID3D11ShaderResourceView_Release(srview);
4446 ID3D11Buffer_Release(buffer);
4448 else
4450 skip("Structured buffers require feature level 11_0.\n");
4453 texture2d_desc.Width = 512;
4454 texture2d_desc.Height = 512;
4455 texture2d_desc.SampleDesc.Count = 1;
4456 texture2d_desc.SampleDesc.Quality = 0;
4457 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
4458 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4459 texture2d_desc.CPUAccessFlags = 0;
4461 texture3d_desc.Width = 64;
4462 texture3d_desc.Height = 64;
4463 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
4464 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4465 texture3d_desc.CPUAccessFlags = 0;
4466 texture3d_desc.MiscFlags = 0;
4468 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4470 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
4472 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
4474 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
4475 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
4476 texture2d_desc.Format = tests[i].texture.format;
4477 texture2d_desc.MiscFlags = 0;
4479 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
4480 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4481 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
4483 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
4484 && (texture2d_desc.ArraySize != 6
4485 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4486 && feature_level < D3D_FEATURE_LEVEL_10_1)
4488 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
4489 continue;
4492 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4493 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4494 texture = (ID3D11Resource *)texture2d;
4496 else
4498 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
4499 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
4500 texture3d_desc.Format = tests[i].texture.format;
4502 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4503 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4504 texture = (ID3D11Resource *)texture3d;
4507 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
4509 current_desc = NULL;
4511 else
4513 current_desc = &srv_desc;
4514 get_srv_desc(current_desc, &tests[i].srv_desc);
4517 expected_refcount = get_refcount(texture);
4518 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
4519 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
4520 refcount = get_refcount(texture);
4521 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
4523 /* Not available on all Windows versions. */
4524 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
4525 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
4527 memset(&srv_desc, 0, sizeof(srv_desc));
4528 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
4529 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
4531 ID3D11ShaderResourceView_Release(srview);
4532 ID3D11Resource_Release(texture);
4535 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
4537 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
4538 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
4540 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
4542 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4543 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
4544 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
4545 texture2d_desc.MiscFlags = 0;
4547 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
4548 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4549 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
4551 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
4552 && feature_level < D3D_FEATURE_LEVEL_10_1)
4554 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
4555 continue;
4558 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4559 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4560 texture = (ID3D11Resource *)texture2d;
4562 else
4564 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4565 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
4566 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
4568 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4569 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4570 texture = (ID3D11Resource *)texture3d;
4573 srview = (void *)0xdeadbeef;
4574 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
4575 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
4576 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
4577 ok(!srview, "Unexpected pointer %p.\n", srview);
4579 ID3D11Resource_Release(texture);
4582 refcount = ID3D11Device_Release(device);
4583 ok(!refcount, "Device has %u references left.\n", refcount);
4586 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
4588 #if 0
4589 float4 light;
4590 float4x4 mat;
4592 struct input
4594 float4 position : POSITION;
4595 float3 normal : NORMAL;
4598 struct output
4600 float4 position : POSITION;
4601 float4 diffuse : COLOR;
4604 output main(const input v)
4606 output o;
4608 o.position = mul(v.position, mat);
4609 o.diffuse = dot((float3)light, v.normal);
4611 return o;
4613 #endif
4614 static const DWORD vs_4_1[] =
4616 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
4617 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
4618 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
4619 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
4620 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4621 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
4622 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
4623 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
4624 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
4625 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
4626 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
4627 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
4628 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
4629 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
4630 0x0100003e,
4632 static const DWORD vs_4_0[] =
4634 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
4635 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
4636 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
4637 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
4638 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
4639 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
4640 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
4641 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
4642 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
4643 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
4644 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
4645 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
4646 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
4647 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
4648 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
4649 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
4651 static const DWORD vs_3_0[] =
4653 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
4654 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
4655 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
4656 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
4657 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
4658 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
4659 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
4660 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
4661 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
4662 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
4663 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
4664 0x0000ffff,
4666 static const DWORD vs_2_0[] =
4668 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
4669 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
4670 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
4671 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
4672 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
4673 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
4674 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
4675 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
4676 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
4677 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
4678 0x90e40001, 0x0000ffff,
4681 #if 0
4682 float4 main(const float4 color : COLOR) : SV_TARGET
4684 float4 o;
4686 o = color;
4688 return o;
4690 #endif
4691 static const DWORD ps_4_1[] =
4693 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
4694 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4695 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4696 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4697 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
4698 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4699 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4701 static const DWORD ps_4_0[] =
4703 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
4704 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4705 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4706 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4707 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4708 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4709 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4711 static const DWORD ps_4_0_level_9_0[] =
4713 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
4714 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
4715 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
4716 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
4717 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
4718 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
4719 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
4720 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
4721 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4722 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
4723 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
4724 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4725 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
4726 0xabab0054,
4728 static const DWORD ps_4_0_level_9_1[] =
4730 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
4731 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
4732 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
4733 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
4734 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4735 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4736 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
4737 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4738 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
4739 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
4740 0x45475241, 0xabab0054,
4742 static const DWORD ps_4_0_level_9_3[] =
4744 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
4745 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
4746 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
4747 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
4748 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4749 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4750 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
4751 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4752 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
4753 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
4754 0x45475241, 0xabab0054,
4757 #if 0
4758 struct gs_out
4760 float4 pos : SV_POSITION;
4763 [maxvertexcount(4)]
4764 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
4766 float offset = 0.1 * vin[0].w;
4767 gs_out v;
4769 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
4770 vout.Append(v);
4771 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
4772 vout.Append(v);
4773 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
4774 vout.Append(v);
4775 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
4776 vout.Append(v);
4778 #endif
4779 static const DWORD gs_4_1[] =
4781 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
4782 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4783 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4784 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4785 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
4786 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
4787 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
4788 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
4789 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
4790 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
4791 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
4792 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4793 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
4794 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4795 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
4796 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
4797 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
4798 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4800 static const DWORD gs_4_0[] =
4802 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
4803 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4804 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4805 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4806 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
4807 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
4808 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
4809 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4810 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
4811 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4812 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
4813 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
4814 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
4815 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
4816 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
4817 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4818 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
4819 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4822 ULONG refcount, expected_refcount;
4823 struct device_desc device_desc;
4824 ID3D11Device *device, *tmp;
4825 ID3D11GeometryShader *gs;
4826 ID3D11VertexShader *vs;
4827 ID3D11PixelShader *ps;
4828 HRESULT hr;
4830 device_desc.feature_level = &feature_level;
4831 device_desc.flags = 0;
4832 if (!(device = create_device(&device_desc)))
4834 skip("Failed to create device for feature level %#x.\n", feature_level);
4835 return;
4838 /* level_9 shaders */
4839 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
4840 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4841 ID3D11PixelShader_Release(ps);
4843 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
4844 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4845 ID3D11PixelShader_Release(ps);
4847 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
4848 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4849 ID3D11PixelShader_Release(ps);
4851 /* vertex shader */
4852 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
4853 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4855 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
4856 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4858 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
4859 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
4860 hr, feature_level);
4862 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4863 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
4864 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4865 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4866 else
4867 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4869 refcount = get_refcount(device);
4870 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4871 refcount, expected_refcount);
4872 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4874 tmp = NULL;
4875 expected_refcount = refcount + 1;
4876 ID3D11VertexShader_GetDevice(vs, &tmp);
4877 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4878 refcount = get_refcount(device);
4879 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4880 refcount, expected_refcount);
4881 ID3D11Device_Release(tmp);
4883 /* Not available on all Windows versions. */
4884 check_interface(vs, &IID_ID3D10VertexShader, TRUE, TRUE);
4886 refcount = ID3D11VertexShader_Release(vs);
4887 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
4890 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
4891 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4893 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
4894 hr, feature_level);
4895 refcount = ID3D11VertexShader_Release(vs);
4896 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
4898 else
4900 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4901 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
4902 hr, feature_level);
4903 if (SUCCEEDED(hr))
4904 ID3D11VertexShader_Release(vs);
4907 /* pixel shader */
4908 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4909 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
4910 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4911 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4912 else
4913 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4915 refcount = get_refcount(device);
4916 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4917 refcount, expected_refcount);
4918 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4920 tmp = NULL;
4921 expected_refcount = refcount + 1;
4922 ID3D11PixelShader_GetDevice(ps, &tmp);
4923 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4924 refcount = get_refcount(device);
4925 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4926 refcount, expected_refcount);
4927 ID3D11Device_Release(tmp);
4929 /* Not available on all Windows versions. */
4930 check_interface(ps, &IID_ID3D10PixelShader, TRUE, TRUE);
4932 refcount = ID3D11PixelShader_Release(ps);
4933 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
4936 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
4937 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4939 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
4940 hr, feature_level);
4941 refcount = ID3D11PixelShader_Release(ps);
4942 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
4944 else
4946 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4947 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4948 if (SUCCEEDED(hr))
4949 ID3D11PixelShader_Release(ps);
4952 /* geometry shader */
4953 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4954 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
4955 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4956 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4957 else
4958 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4960 refcount = get_refcount(device);
4961 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4962 refcount, expected_refcount);
4963 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4965 tmp = NULL;
4966 expected_refcount = refcount + 1;
4967 ID3D11GeometryShader_GetDevice(gs, &tmp);
4968 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4969 refcount = get_refcount(device);
4970 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4971 refcount, expected_refcount);
4972 ID3D11Device_Release(tmp);
4974 /* Not available on all Windows versions. */
4975 check_interface(gs, &IID_ID3D10GeometryShader, TRUE, TRUE);
4977 refcount = ID3D11GeometryShader_Release(gs);
4978 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4981 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
4982 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4984 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4985 hr, feature_level);
4986 refcount = ID3D11GeometryShader_Release(gs);
4987 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4989 else
4991 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4992 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4993 hr, feature_level);
4994 if (SUCCEEDED(hr))
4995 ID3D11GeometryShader_Release(gs);
4998 refcount = ID3D11Device_Release(device);
4999 ok(!refcount, "Device has %u references left.\n", refcount);
5002 static void test_create_sampler_state(void)
5004 static const struct test
5006 D3D11_FILTER filter;
5007 D3D10_FILTER expected_filter;
5009 desc_conversion_tests[] =
5011 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
5012 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
5013 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
5014 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
5015 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
5016 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
5017 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
5018 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
5019 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
5020 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
5021 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
5023 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
5024 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
5026 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
5027 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
5029 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
5030 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
5032 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
5033 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
5034 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
5037 ID3D11SamplerState *sampler_state1, *sampler_state2;
5038 ID3D10SamplerState *d3d10_sampler_state;
5039 ULONG refcount, expected_refcount;
5040 ID3D11Device *device, *tmp;
5041 D3D11_SAMPLER_DESC desc;
5042 unsigned int i;
5043 HRESULT hr;
5045 if (!(device = create_device(NULL)))
5047 skip("Failed to create device.\n");
5048 return;
5051 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
5052 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5054 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5055 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5056 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5057 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5058 desc.MipLODBias = 0.0f;
5059 desc.MaxAnisotropy = 16;
5060 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
5061 desc.BorderColor[0] = 0.0f;
5062 desc.BorderColor[1] = 1.0f;
5063 desc.BorderColor[2] = 0.0f;
5064 desc.BorderColor[3] = 1.0f;
5065 desc.MinLOD = 0.0f;
5066 desc.MaxLOD = 16.0f;
5068 expected_refcount = get_refcount(device) + 1;
5069 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
5070 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5071 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
5072 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5073 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
5074 refcount = get_refcount(device);
5075 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5076 tmp = NULL;
5077 expected_refcount = refcount + 1;
5078 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
5079 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5080 refcount = get_refcount(device);
5081 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5082 ID3D11Device_Release(tmp);
5084 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
5085 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
5086 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
5087 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
5088 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
5089 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
5090 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
5091 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
5092 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
5093 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
5094 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
5095 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
5096 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
5098 refcount = ID3D11SamplerState_Release(sampler_state2);
5099 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5100 refcount = ID3D11SamplerState_Release(sampler_state1);
5101 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5103 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
5105 const struct test *current = &desc_conversion_tests[i];
5106 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
5108 desc.Filter = current->filter;
5109 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5110 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5111 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
5112 desc.MipLODBias = 0.0f;
5113 desc.MaxAnisotropy = 16;
5114 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
5115 desc.BorderColor[0] = 0.0f;
5116 desc.BorderColor[1] = 1.0f;
5117 desc.BorderColor[2] = 0.0f;
5118 desc.BorderColor[3] = 1.0f;
5119 desc.MinLOD = 0.0f;
5120 desc.MaxLOD = 16.0f;
5122 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
5123 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
5125 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
5126 (void **)&d3d10_sampler_state);
5127 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5128 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
5129 if (FAILED(hr))
5131 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
5132 ID3D11SamplerState_Release(sampler_state1);
5133 break;
5136 memcpy(&expected_desc, &desc, sizeof(expected_desc));
5137 expected_desc.Filter = current->expected_filter;
5138 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
5139 expected_desc.MaxAnisotropy = 0;
5140 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
5141 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
5143 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
5144 ok(d3d10_desc.Filter == expected_desc.Filter,
5145 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
5146 ok(d3d10_desc.AddressU == expected_desc.AddressU,
5147 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
5148 ok(d3d10_desc.AddressV == expected_desc.AddressV,
5149 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
5150 ok(d3d10_desc.AddressW == expected_desc.AddressW,
5151 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
5152 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
5153 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
5154 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
5155 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
5156 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
5157 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
5158 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
5159 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
5160 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
5161 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
5162 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
5163 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
5164 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
5165 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
5166 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
5167 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
5168 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
5170 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
5171 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
5172 refcount = ID3D11SamplerState_Release(sampler_state1);
5173 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
5176 refcount = ID3D11Device_Release(device);
5177 ok(!refcount, "Device has %u references left.\n", refcount);
5180 static void test_create_blend_state(void)
5182 static const D3D11_BLEND_DESC desc_conversion_tests[] =
5185 FALSE, FALSE,
5188 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5189 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
5194 FALSE, TRUE,
5197 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5198 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5201 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5202 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
5205 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5206 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5209 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5210 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
5213 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5214 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5217 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5218 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5221 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5222 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5225 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5226 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5231 FALSE, TRUE,
5234 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5235 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5238 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
5239 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5242 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
5243 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5246 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5247 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5250 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
5251 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5254 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
5255 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5258 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5259 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5262 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5263 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5269 ID3D11BlendState *blend_state1, *blend_state2;
5270 D3D11_BLEND_DESC desc, obtained_desc;
5271 ID3D10BlendState *d3d10_blend_state;
5272 D3D10_BLEND_DESC d3d10_blend_desc;
5273 ULONG refcount, expected_refcount;
5274 ID3D11Device *device, *tmp;
5275 unsigned int i, j;
5276 HRESULT hr;
5278 if (!(device = create_device(NULL)))
5280 skip("Failed to create device.\n");
5281 return;
5284 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
5285 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5287 memset(&desc, 0, sizeof(desc));
5288 desc.AlphaToCoverageEnable = FALSE;
5289 desc.IndependentBlendEnable = FALSE;
5290 desc.RenderTarget[0].BlendEnable = FALSE;
5291 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5293 expected_refcount = get_refcount(device) + 1;
5294 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
5295 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5296 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
5297 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5298 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
5299 refcount = get_refcount(device);
5300 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5301 tmp = NULL;
5302 expected_refcount = refcount + 1;
5303 ID3D11BlendState_GetDevice(blend_state1, &tmp);
5304 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5305 refcount = get_refcount(device);
5306 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5307 ID3D11Device_Release(tmp);
5309 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
5310 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
5311 obtained_desc.AlphaToCoverageEnable);
5312 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
5313 obtained_desc.IndependentBlendEnable);
5314 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5316 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
5317 "Got unexpected blend enable %#x for render target %u.\n",
5318 obtained_desc.RenderTarget[i].BlendEnable, i);
5319 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
5320 "Got unexpected src blend %u for render target %u.\n",
5321 obtained_desc.RenderTarget[i].SrcBlend, i);
5322 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
5323 "Got unexpected dest blend %u for render target %u.\n",
5324 obtained_desc.RenderTarget[i].DestBlend, i);
5325 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
5326 "Got unexpected blend op %u for render target %u.\n",
5327 obtained_desc.RenderTarget[i].BlendOp, i);
5328 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
5329 "Got unexpected src blend alpha %u for render target %u.\n",
5330 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
5331 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
5332 "Got unexpected dest blend alpha %u for render target %u.\n",
5333 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
5334 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
5335 "Got unexpected blend op alpha %u for render target %u.\n",
5336 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
5337 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
5338 "Got unexpected render target write mask %#x for render target %u.\n",
5339 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
5342 /* Not available on all Windows versions. */
5343 check_interface(blend_state1, &IID_ID3D10BlendState, TRUE, TRUE);
5344 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
5346 refcount = ID3D11BlendState_Release(blend_state1);
5347 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5348 refcount = ID3D11BlendState_Release(blend_state2);
5349 ok(!refcount, "Blend state has %u references left.\n", refcount);
5351 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
5353 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
5355 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
5356 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5358 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
5359 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5360 "Blend state should implement ID3D10BlendState.\n");
5361 if (FAILED(hr))
5363 win_skip("Blend state does not implement ID3D10BlendState.\n");
5364 ID3D11BlendState_Release(blend_state1);
5365 break;
5368 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
5369 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
5370 "Got unexpected alpha to coverage enable %#x for test %u.\n",
5371 d3d10_blend_desc.AlphaToCoverageEnable, i);
5372 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
5373 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
5374 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
5375 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
5376 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
5377 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
5378 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
5379 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
5380 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
5381 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
5382 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
5383 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
5384 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
5386 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
5387 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
5388 "Got unexpected blend enable %#x for test %u, render target %u.\n",
5389 d3d10_blend_desc.BlendEnable[j], i, j);
5390 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
5391 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
5392 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
5395 ID3D10BlendState_Release(d3d10_blend_state);
5397 refcount = ID3D11BlendState_Release(blend_state1);
5398 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5401 refcount = ID3D11Device_Release(device);
5402 ok(!refcount, "Device has %u references left.\n", refcount);
5405 static void test_create_depthstencil_state(void)
5407 ID3D11DepthStencilState *ds_state1, *ds_state2;
5408 ULONG refcount, expected_refcount;
5409 D3D11_DEPTH_STENCIL_DESC ds_desc;
5410 ID3D11Device *device, *tmp;
5411 HRESULT hr;
5413 if (!(device = create_device(NULL)))
5415 skip("Failed to create device.\n");
5416 return;
5419 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
5420 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5422 ds_desc.DepthEnable = TRUE;
5423 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
5424 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
5425 ds_desc.StencilEnable = FALSE;
5426 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
5427 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
5428 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
5429 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
5430 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
5431 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
5432 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
5433 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
5434 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
5435 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
5437 expected_refcount = get_refcount(device) + 1;
5438 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
5439 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5440 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
5441 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5442 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
5443 refcount = get_refcount(device);
5444 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5445 tmp = NULL;
5446 expected_refcount = refcount + 1;
5447 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
5448 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5449 refcount = get_refcount(device);
5450 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5451 ID3D11Device_Release(tmp);
5453 /* Not available on all Windows versions. */
5454 check_interface(ds_state1, &IID_ID3D10DepthStencilState, TRUE, TRUE);
5456 refcount = ID3D11DepthStencilState_Release(ds_state2);
5457 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5458 refcount = ID3D11DepthStencilState_Release(ds_state1);
5459 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5461 ds_desc.DepthEnable = FALSE;
5462 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
5463 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
5464 ds_desc.StencilEnable = FALSE;
5465 ds_desc.StencilReadMask = 0;
5466 ds_desc.StencilWriteMask = 0;
5467 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
5468 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
5469 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
5470 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
5471 ds_desc.BackFace = ds_desc.FrontFace;
5473 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
5474 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5476 memset(&ds_desc, 0, sizeof(ds_desc));
5477 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
5478 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
5479 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
5480 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
5481 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
5482 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
5483 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
5484 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
5485 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
5486 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
5487 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
5488 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
5489 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
5490 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
5491 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
5492 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
5493 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
5494 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
5495 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
5496 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
5497 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
5498 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
5499 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
5500 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
5501 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
5502 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
5504 ID3D11DepthStencilState_Release(ds_state1);
5506 refcount = ID3D11Device_Release(device);
5507 ok(!refcount, "Device has %u references left.\n", refcount);
5510 static void test_create_rasterizer_state(void)
5512 ID3D11RasterizerState *rast_state1, *rast_state2;
5513 ID3D10RasterizerState *d3d10_rast_state;
5514 ULONG refcount, expected_refcount;
5515 D3D10_RASTERIZER_DESC d3d10_desc;
5516 D3D11_RASTERIZER_DESC desc;
5517 ID3D11Device *device, *tmp;
5518 ID3D11Device1 *device1;
5519 HRESULT hr;
5521 if (!(device = create_device(NULL)))
5523 skip("Failed to create device.\n");
5524 return;
5527 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
5528 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5530 desc.FillMode = D3D11_FILL_SOLID;
5531 desc.CullMode = D3D11_CULL_BACK;
5532 desc.FrontCounterClockwise = FALSE;
5533 desc.DepthBias = 0;
5534 desc.DepthBiasClamp = 0.0f;
5535 desc.SlopeScaledDepthBias = 0.0f;
5536 desc.DepthClipEnable = TRUE;
5537 desc.ScissorEnable = FALSE;
5538 desc.MultisampleEnable = FALSE;
5539 desc.AntialiasedLineEnable = FALSE;
5541 expected_refcount = get_refcount(device) + 1;
5542 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
5543 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5544 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
5545 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5546 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
5547 refcount = get_refcount(device);
5548 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5549 tmp = NULL;
5550 expected_refcount = refcount + 1;
5551 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
5552 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5553 refcount = get_refcount(device);
5554 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5555 ID3D11Device_Release(tmp);
5557 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
5558 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5559 "Rasterizer state should implement ID3D10RasterizerState.\n");
5560 if (SUCCEEDED(hr))
5562 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
5563 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
5564 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
5565 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
5566 d3d10_desc.FrontCounterClockwise);
5567 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
5568 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
5569 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
5570 d3d10_desc.SlopeScaledDepthBias);
5571 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
5572 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
5573 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
5574 d3d10_desc.MultisampleEnable);
5575 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
5576 d3d10_desc.AntialiasedLineEnable);
5578 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
5579 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5582 if (ID3D11Device_QueryInterface(device, &IID_ID3D11Device1, (void **)&device1) == S_OK)
5584 ID3D11RasterizerState1 *state_ex1;
5585 D3D11_RASTERIZER_DESC1 desc1;
5587 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D11RasterizerState1, (void **)&state_ex1);
5588 ok(hr == S_OK, "Got hr %#x.\n", hr);
5590 memset(&desc1, 0xcc, sizeof(desc1));
5591 ID3D11RasterizerState1_GetDesc1(state_ex1, &desc1);
5592 ok(!memcmp(&desc1, &desc, sizeof(desc)), "D3D11 desc didn't match.\n");
5593 ok(!desc1.ForcedSampleCount, "Got forced sample count %u.\n", desc1.ForcedSampleCount);
5595 ID3D11RasterizerState1_Release(state_ex1);
5597 memcpy(&desc1, &desc, sizeof(desc));
5598 desc1.ForcedSampleCount = 0;
5599 hr = ID3D11Device1_CreateRasterizerState1(device1, &desc1, &state_ex1);
5600 ok(hr == S_OK, "Got hr %#x.\n", hr);
5602 ID3D11RasterizerState1_Release(state_ex1);
5604 ID3D11Device1_Release(device1);
5607 refcount = ID3D11RasterizerState_Release(rast_state2);
5608 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5609 refcount = ID3D11RasterizerState_Release(rast_state1);
5610 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5612 refcount = ID3D11Device_Release(device);
5613 ok(!refcount, "Device has %u references left.\n", refcount);
5616 static void test_create_query(void)
5618 static const struct
5620 D3D11_QUERY query;
5621 D3D_FEATURE_LEVEL required_feature_level;
5622 BOOL is_predicate;
5623 BOOL can_use_create_predicate;
5624 BOOL todo;
5626 tests[] =
5628 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5629 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5630 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5631 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5632 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5633 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
5634 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5635 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
5636 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5637 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5638 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5639 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5640 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5641 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5642 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5643 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5646 ULONG refcount, expected_refcount;
5647 D3D_FEATURE_LEVEL feature_level;
5648 D3D11_QUERY_DESC query_desc;
5649 ID3D11Predicate *predicate;
5650 ID3D11Device *device, *tmp;
5651 HRESULT hr, expected_hr;
5652 ID3D11Query *query;
5653 unsigned int i;
5655 if (!(device = create_device(NULL)))
5657 skip("Failed to create device.\n");
5658 return;
5660 feature_level = ID3D11Device_GetFeatureLevel(device);
5662 hr = ID3D11Device_CreateQuery(device, NULL, &query);
5663 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5664 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
5665 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5667 for (i = 0; i < ARRAY_SIZE(tests); ++i)
5669 if (tests[i].required_feature_level > feature_level)
5671 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
5672 continue;
5675 query_desc.Query = tests[i].query;
5676 query_desc.MiscFlags = 0;
5678 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
5679 todo_wine_if(tests[i].todo)
5680 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5682 query_desc.Query = tests[i].query;
5683 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
5684 todo_wine_if(tests[i].todo)
5685 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5686 if (FAILED(hr))
5687 continue;
5689 check_interface(query, &IID_ID3D11Predicate, tests[i].is_predicate, FALSE);
5690 ID3D11Query_Release(query);
5692 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
5693 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
5694 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5696 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
5697 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
5698 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5699 if (SUCCEEDED(hr))
5700 ID3D11Predicate_Release(predicate);
5703 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
5704 expected_refcount = get_refcount(device) + 1;
5705 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
5706 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5707 refcount = get_refcount(device);
5708 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5709 tmp = NULL;
5710 expected_refcount = refcount + 1;
5711 ID3D11Predicate_GetDevice(predicate, &tmp);
5712 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5713 refcount = get_refcount(device);
5714 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5715 ID3D11Device_Release(tmp);
5716 /* Not available on all Windows versions. */
5717 check_interface(predicate, &IID_ID3D10Predicate, TRUE, TRUE);
5718 ID3D11Predicate_Release(predicate);
5720 refcount = ID3D11Device_Release(device);
5721 ok(!refcount, "Device has %u references left.\n", refcount);
5724 #define get_query_data(a, b, c, d) get_query_data_(__LINE__, a, b, c, d)
5725 static void get_query_data_(unsigned int line, ID3D11DeviceContext *context,
5726 ID3D11Asynchronous *query, void *data, unsigned int data_size)
5728 unsigned int i;
5729 HRESULT hr;
5731 for (i = 0; i < 500; ++i)
5733 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
5734 break;
5735 Sleep(10);
5737 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5738 memset(data, 0xff, data_size);
5739 hr = ID3D11DeviceContext_GetData(context, query, data, data_size, 0);
5740 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5743 static void test_occlusion_query(void)
5745 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5746 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5748 struct d3d11_test_context test_context;
5749 D3D11_TEXTURE2D_DESC texture_desc;
5750 ID3D11DeviceContext *context;
5751 ID3D11RenderTargetView *rtv;
5752 D3D11_QUERY_DESC query_desc;
5753 ID3D11Asynchronous *query;
5754 unsigned int data_size, i;
5755 ID3D11Texture2D *texture;
5756 ID3D11Device *device;
5757 union
5759 UINT64 uint;
5760 DWORD dword[2];
5761 } data;
5762 HRESULT hr;
5764 if (!init_test_context(&test_context, NULL))
5765 return;
5767 device = test_context.device;
5768 context = test_context.immediate_context;
5770 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5772 query_desc.Query = D3D11_QUERY_OCCLUSION;
5773 query_desc.MiscFlags = 0;
5774 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5775 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5776 data_size = ID3D11Asynchronous_GetDataSize(query);
5777 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
5779 memset(&data, 0xff, sizeof(data));
5780 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5781 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5782 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5783 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5784 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5785 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5787 ID3D11DeviceContext_End(context, query);
5788 ID3D11DeviceContext_Begin(context, query);
5789 ID3D11DeviceContext_Begin(context, query);
5791 memset(&data, 0xff, sizeof(data));
5792 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5793 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5794 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5795 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5796 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5797 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5799 draw_color_quad(&test_context, &red);
5801 ID3D11DeviceContext_End(context, query);
5802 get_query_data(context, query, &data, sizeof(data));
5803 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5805 memset(&data, 0xff, sizeof(data));
5806 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
5807 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5808 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
5809 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5810 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
5811 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5812 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
5813 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5814 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5815 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5817 memset(&data, 0xff, sizeof(data));
5818 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
5819 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5820 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5821 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5823 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
5824 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5825 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
5826 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5828 ID3D11DeviceContext_Begin(context, query);
5829 ID3D11DeviceContext_End(context, query);
5830 ID3D11DeviceContext_End(context, query);
5832 get_query_data(context, query, &data, sizeof(data));
5833 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5834 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5835 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5837 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
5838 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
5839 texture_desc.MipLevels = 1;
5840 texture_desc.ArraySize = 1;
5841 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
5842 texture_desc.SampleDesc.Count = 1;
5843 texture_desc.SampleDesc.Quality = 0;
5844 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5845 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5846 texture_desc.CPUAccessFlags = 0;
5847 texture_desc.MiscFlags = 0;
5848 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5849 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5850 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5851 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5853 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
5854 set_viewport(context, 0.0f, 0.0f, texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
5856 ID3D11DeviceContext_Begin(context, query);
5857 for (i = 0; i < 100; i++)
5858 draw_color_quad(&test_context, &red);
5859 ID3D11DeviceContext_End(context, query);
5861 get_query_data(context, query, &data, sizeof(data));
5862 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
5863 || (data.dword[0] == 0xffffffff && !data.dword[1])
5864 || broken(!data.uint),
5865 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5866 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5867 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5869 ID3D11Asynchronous_Release(query);
5871 /* The following test exercises a code path in wined3d. A wined3d context
5872 * associated with the query is destroyed when the swapchain is released. */
5873 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5874 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5876 set_viewport(context, 0.0f, 0.0f, 64.0f, 64.0f, 0.0f, 1.0f);
5877 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5878 ID3D11DeviceContext_Begin(context, query);
5879 draw_color_quad(&test_context, &red);
5880 ID3D11DeviceContext_End(context, query);
5882 ID3D11RenderTargetView_Release(test_context.backbuffer_rtv);
5883 ID3D11Texture2D_Release(test_context.backbuffer);
5884 IDXGISwapChain_Release(test_context.swapchain);
5885 test_context.swapchain = create_swapchain(device, test_context.window, NULL);
5886 hr = IDXGISwapChain_GetBuffer(test_context.swapchain, 0, &IID_ID3D11Texture2D,
5887 (void **)&test_context.backbuffer);
5888 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
5889 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer,
5890 NULL, &test_context.backbuffer_rtv);
5891 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5892 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
5893 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5895 get_query_data(context, query, &data, sizeof(data));
5896 /* This test occasionally succeeds with CSMT enabled because of a race condition. */
5897 if (0)
5899 todo_wine ok(data.dword[0] == 0x1000 && !data.dword[1],
5900 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5903 ID3D11Asynchronous_Release(query);
5904 ID3D11RenderTargetView_Release(rtv);
5905 ID3D11Texture2D_Release(texture);
5906 release_test_context(&test_context);
5909 static void test_pipeline_statistics_query(void)
5911 static const D3D11_QUERY_DATA_PIPELINE_STATISTICS zero_data = {0};
5912 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5913 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5915 D3D11_QUERY_DATA_PIPELINE_STATISTICS data;
5916 struct d3d11_test_context test_context;
5917 ID3D11DeviceContext *context;
5918 D3D11_QUERY_DESC query_desc;
5919 ID3D11Asynchronous *query;
5920 unsigned int data_size;
5921 ID3D11Device *device;
5922 HRESULT hr;
5924 if (!init_test_context(&test_context, NULL))
5925 return;
5927 device = test_context.device;
5928 context = test_context.immediate_context;
5930 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5932 query_desc.Query = D3D11_QUERY_PIPELINE_STATISTICS;
5933 query_desc.MiscFlags = 0;
5934 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5935 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5936 data_size = ID3D11Asynchronous_GetDataSize(query);
5937 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
5939 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5940 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5941 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5942 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5944 ID3D11DeviceContext_End(context, query);
5945 ID3D11DeviceContext_Begin(context, query);
5946 ID3D11DeviceContext_Begin(context, query);
5948 memset(&data, 0xff, sizeof(data));
5949 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5950 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5951 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5952 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5953 ok(data.IAVertices == ~(UINT64)0, "Data was modified.\n");
5955 draw_quad(&test_context);
5957 ID3D11DeviceContext_End(context, query);
5958 get_query_data(context, query, &data, sizeof(data));
5960 /* WARP devices randomly return all-zeroed structures as if the draw did not happen. Flushing and
5961 * sleeping a second before ending the query reduces the likelyhood of hitting the bug a lot, but
5962 * does not eliminate it entirely. To make things work reliably ignore such broken results. */
5963 if (is_warp_device(device) && !memcmp(&data, &zero_data, sizeof(data)))
5965 win_skip("WARP device randomly returns zeroed query results.\n");
5967 else
5969 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5970 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5971 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5972 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5973 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5974 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5975 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5976 todo_wine
5977 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5978 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5979 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5980 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5983 ID3D11DeviceContext_Begin(context, query);
5984 draw_color_quad(&test_context, &red);
5985 ID3D11DeviceContext_End(context, query);
5986 get_query_data(context, query, &data, sizeof(data));
5987 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5988 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5989 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5990 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5991 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5992 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5993 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5994 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5995 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5996 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5997 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5999 ID3D11Asynchronous_Release(query);
6000 release_test_context(&test_context);
6003 static void test_timestamp_query(void)
6005 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
6007 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
6008 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
6009 struct d3d11_test_context test_context;
6010 ID3D11DeviceContext *context;
6011 D3D11_QUERY_DESC query_desc;
6012 unsigned int data_size;
6013 ID3D11Device *device;
6014 UINT64 timestamp;
6015 HRESULT hr;
6017 if (!init_test_context(&test_context, NULL))
6018 return;
6020 device = test_context.device;
6021 context = test_context.immediate_context;
6023 query_desc.Query = D3D11_QUERY_TIMESTAMP;
6024 query_desc.MiscFlags = 0;
6025 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
6026 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6027 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
6028 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
6030 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
6031 query_desc.MiscFlags = 0;
6032 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
6033 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6034 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
6035 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
6037 disjoint.Frequency = 0xdeadbeef;
6038 disjoint.Disjoint = 0xdeadbeef;
6039 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
6040 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6041 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
6042 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6043 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
6044 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
6046 /* Test a TIMESTAMP_DISJOINT query. */
6047 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
6049 disjoint.Frequency = 0xdeadbeef;
6050 disjoint.Disjoint = 0xdeadbeef;
6051 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
6052 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6053 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
6054 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6055 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
6056 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
6058 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
6059 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
6060 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
6061 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
6063 prev_disjoint = disjoint;
6065 disjoint.Frequency = 0xdeadbeef;
6066 disjoint.Disjoint = 0xff;
6067 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
6068 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6069 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
6070 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6071 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
6072 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6073 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
6074 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6075 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
6076 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
6078 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
6079 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6080 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
6081 D3D11_ASYNC_GETDATA_DONOTFLUSH);
6082 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6083 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
6084 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
6086 memset(&timestamp, 0xff, sizeof(timestamp));
6087 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
6088 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6089 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
6090 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6091 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
6093 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
6094 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
6096 memset(&timestamp, 0xff, sizeof(timestamp));
6097 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
6098 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6099 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
6101 draw_color_quad(&test_context, &red);
6103 ID3D11DeviceContext_End(context, timestamp_query);
6104 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
6106 timestamp = 0xdeadbeef;
6107 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
6108 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6109 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
6111 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
6112 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6113 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
6115 timestamp = 0xdeadbeef;
6116 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
6117 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6118 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
6119 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6120 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
6121 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6122 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
6123 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6124 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
6126 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
6127 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
6128 disjoint.Frequency = 0xdeadbeef;
6129 disjoint.Disjoint = 0xff;
6130 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
6131 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6132 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
6133 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
6135 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
6136 ID3D11Asynchronous_Release(timestamp_query);
6137 query_desc.Query = D3D11_QUERY_TIMESTAMP;
6138 query_desc.MiscFlags = 0;
6139 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
6140 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6142 draw_color_quad(&test_context, &red);
6144 ID3D11DeviceContext_End(context, timestamp_query);
6145 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
6147 ID3D11Asynchronous_Release(timestamp_query);
6148 ID3D11Asynchronous_Release(timestamp_disjoint_query);
6149 release_test_context(&test_context);
6152 static void test_so_statistics_query(void)
6154 struct d3d11_test_context test_context;
6155 D3D11_QUERY_DATA_SO_STATISTICS data;
6156 ID3D11DeviceContext *context;
6157 unsigned int vertex_count[4];
6158 D3D11_QUERY_DESC query_desc;
6159 ID3D11Buffer *so_buffer[4];
6160 ID3D11Asynchronous *query;
6161 ID3D11GeometryShader *gs;
6162 ID3D11VertexShader *vs;
6163 unsigned int data_size;
6164 ID3D11Device *device;
6165 ID3D11Buffer *cb;
6166 unsigned int i;
6167 HRESULT hr;
6169 static const DWORD vs_code[] =
6171 #if 0
6172 float4 main(uint id : SV_VertexID) : custom
6174 return (float4)id;
6176 #endif
6177 0x43425844, 0x8b0e47b9, 0x6efc9512, 0xd55ca6ff, 0x487c5ef2, 0x00000001, 0x000000d4, 0x00000003,
6178 0x0000002c, 0x00000060, 0x00000090, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6179 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
6180 0x4e47534f, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6181 0x00000000, 0x0000000f, 0x74737563, 0xab006d6f, 0x52444853, 0x0000003c, 0x00010040, 0x0000000f,
6182 0x04000060, 0x00101012, 0x00000000, 0x00000006, 0x03000065, 0x001020f2, 0x00000000, 0x05000056,
6183 0x001020f2, 0x00000000, 0x00101006, 0x00000000, 0x0100003e,
6185 static const DWORD gs_code[] =
6187 #if 0
6188 struct vertex
6190 float4 data : custom;
6193 uint4 vertex_count;
6195 [maxvertexcount(32)]
6196 void main(point vertex input[1], uint id : SV_PrimitiveID,
6197 inout PointStream<vertex> output0,
6198 inout PointStream<vertex> output1,
6199 inout PointStream<vertex> output2,
6200 inout PointStream<vertex> output3)
6202 if (id < vertex_count.x)
6203 output0.Append(input[0]);
6204 if (id < vertex_count.y)
6205 output1.Append(input[0]);
6206 if (id < vertex_count.z)
6207 output2.Append(input[0]);
6208 if (id < vertex_count.w)
6209 output3.Append(input[0]);
6211 #endif
6212 0x43425844, 0xd616829d, 0x4355ce2a, 0xd71909e5, 0xdc916d4c, 0x00000001, 0x000002bc, 0x00000003,
6213 0x0000002c, 0x00000084, 0x0000010c, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
6214 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000003f, 0x00000000, 0x00000007,
6215 0x00000001, 0xffffffff, 0x00000101, 0x74737563, 0x53006d6f, 0x72505f56, 0x74696d69, 0x49657669,
6216 0xabab0044, 0x3547534f, 0x00000080, 0x00000004, 0x00000008, 0x00000000, 0x00000078, 0x00000000,
6217 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000001, 0x00000078, 0x00000000, 0x00000000,
6218 0x00000003, 0x00000000, 0x0000000f, 0x00000002, 0x00000078, 0x00000000, 0x00000000, 0x00000003,
6219 0x00000000, 0x0000000f, 0x00000003, 0x00000078, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
6220 0x0000000f, 0x74737563, 0xab006d6f, 0x58454853, 0x000001a8, 0x00020050, 0x0000006a, 0x0100086a,
6221 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000,
6222 0x0200005f, 0x0000b000, 0x02000068, 0x00000001, 0x0100085d, 0x0300008f, 0x00110000, 0x00000000,
6223 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000001, 0x0100085c,
6224 0x03000065, 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000002, 0x0100085c, 0x03000065,
6225 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000003, 0x0100085c, 0x03000065, 0x001020f2,
6226 0x00000000, 0x0200005e, 0x00000020, 0x0700004f, 0x001000f2, 0x00000000, 0x0000b001, 0x00208e46,
6227 0x00000000, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000,
6228 0x00201e46, 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x01000015, 0x0304001f,
6229 0x0010001a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000, 0x00000000,
6230 0x03000075, 0x00110000, 0x00000001, 0x01000015, 0x0304001f, 0x0010002a, 0x00000000, 0x06000036,
6231 0x001020f2, 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000002,
6232 0x01000015, 0x0304001f, 0x0010003a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
6233 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000003, 0x01000015, 0x0100003e,
6235 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
6237 {0, "custom", 0, 0, 4, 0},
6238 {1, "custom", 0, 0, 4, 1},
6239 {2, "custom", 0, 0, 4, 2},
6240 {3, "custom", 0, 0, 4, 3},
6242 static const unsigned int offset[4] = {0};
6244 static const struct
6246 D3D11_QUERY query;
6247 D3D_FEATURE_LEVEL feature_level;
6249 tests[] =
6251 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0},
6252 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0},
6253 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0},
6254 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0},
6255 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0},
6258 if (!init_test_context(&test_context, NULL))
6259 return;
6261 device = test_context.device;
6262 context = test_context.immediate_context;
6264 for (i = 0; i < ARRAY_SIZE(tests); ++i)
6266 if (ID3D11Device_GetFeatureLevel(device) < tests[i].feature_level)
6268 skip("Feature level %#x is required.\n", tests[i].feature_level);
6269 continue;
6272 query_desc.Query = tests[i].query;
6273 query_desc.MiscFlags = 0;
6274 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
6275 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6276 data_size = ID3D11Asynchronous_GetDataSize(query);
6277 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
6279 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
6280 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6281 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
6282 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6284 ID3D11DeviceContext_End(context, query);
6285 ID3D11DeviceContext_Begin(context, query);
6286 ID3D11DeviceContext_Begin(context, query);
6288 memset(&data, 0xff, sizeof(data));
6289 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
6290 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6291 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
6292 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6293 ok(data.NumPrimitivesWritten == ~(UINT64)0, "Data was modified.\n");
6294 ok(data.PrimitivesStorageNeeded == ~(UINT64)0, "Data was modified.\n");
6296 draw_quad(&test_context);
6298 ID3D11DeviceContext_End(context, query);
6299 get_query_data(context, query, &data, sizeof(data));
6300 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
6301 (unsigned int)data.NumPrimitivesWritten);
6302 todo_wine
6303 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
6304 (unsigned int)data.PrimitivesStorageNeeded);
6306 ID3D11DeviceContext_Begin(context, query);
6307 draw_quad(&test_context);
6308 ID3D11DeviceContext_End(context, query);
6309 get_query_data(context, query, &data, sizeof(data));
6310 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
6311 (unsigned int)data.NumPrimitivesWritten);
6312 todo_wine
6313 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
6314 (unsigned int)data.PrimitivesStorageNeeded);
6316 ID3D11Asynchronous_Release(query);
6319 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
6321 skip("Vertex streams are not supported.\n");
6322 goto done;
6325 /* multiple vertex streams */
6326 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
6327 ok(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
6328 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
6330 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
6331 so_declaration, ARRAY_SIZE(so_declaration),
6332 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
6333 todo_wine
6334 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
6335 if (FAILED(hr))
6337 ID3D11VertexShader_Release(vs);
6338 goto done;
6340 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
6342 for (i = 0; i < ARRAY_SIZE(vertex_count); ++i)
6343 vertex_count[i] = 5;
6344 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(vertex_count), vertex_count);
6345 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
6347 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
6349 query_desc.Query = D3D11_QUERY_SO_STATISTICS;
6350 query_desc.MiscFlags = 0;
6351 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
6352 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6354 ID3D11DeviceContext_Begin(context, query);
6355 ID3D11DeviceContext_Draw(context, 5, 0);
6356 ID3D11DeviceContext_End(context, query);
6358 memset(&data, 0xff, sizeof(data));
6359 get_query_data(context, query, &data, sizeof(data));
6360 ok(!data.NumPrimitivesWritten, "Got unexpected primitives written %u.\n",
6361 (unsigned int)data.NumPrimitivesWritten);
6362 ok(data.PrimitivesStorageNeeded == 5, "Got unexpected primitives storage needed %u.\n",
6363 (unsigned int)data.PrimitivesStorageNeeded);
6365 for (i = 0; i < ARRAY_SIZE(so_buffer); ++i)
6366 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(struct vec4) * 10, NULL);
6368 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6369 ID3D11DeviceContext_Begin(context, query);
6370 ID3D11DeviceContext_Draw(context, 16, 0);
6371 ID3D11DeviceContext_End(context, query);
6372 memset(&data, 0xff, sizeof(data));
6373 get_query_data(context, query, &data, sizeof(data));
6374 ok(data.NumPrimitivesWritten == 5, "Got unexpected primitives written %u.\n",
6375 (unsigned int)data.NumPrimitivesWritten);
6376 ok(data.PrimitivesStorageNeeded == 5, "Got unexpected primitives storage needed %u.\n",
6377 (unsigned int)data.PrimitivesStorageNeeded);
6379 vertex_count[0] = 3;
6380 vertex_count[1] = 6;
6381 vertex_count[2] = 4;
6382 vertex_count[3] = 12;
6383 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, vertex_count, 0, 0);
6385 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6386 ID3D11DeviceContext_Begin(context, query);
6387 ID3D11DeviceContext_Draw(context, 32, 0);
6388 ID3D11DeviceContext_End(context, query);
6389 memset(&data, 0xff, sizeof(data));
6390 get_query_data(context, query, &data, sizeof(data));
6391 ok(data.NumPrimitivesWritten == 3, "Got unexpected primitives written %u.\n",
6392 (unsigned int)data.NumPrimitivesWritten);
6393 ok(data.PrimitivesStorageNeeded == 3, "Got unexpected primitives storage needed %u.\n",
6394 (unsigned int)data.PrimitivesStorageNeeded);
6396 vertex_count[0] = 16;
6397 vertex_count[1] = 6;
6398 vertex_count[2] = 4;
6399 vertex_count[3] = 12;
6400 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, vertex_count, 0, 0);
6402 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6403 ID3D11DeviceContext_Begin(context, query);
6404 ID3D11DeviceContext_Draw(context, 32, 0);
6405 ID3D11DeviceContext_End(context, query);
6406 memset(&data, 0xff, sizeof(data));
6407 get_query_data(context, query, &data, sizeof(data));
6408 ok(data.NumPrimitivesWritten == 10, "Got unexpected primitives written %u.\n",
6409 (unsigned int)data.NumPrimitivesWritten);
6410 ok(data.PrimitivesStorageNeeded == 16, "Got unexpected primitives storage needed %u.\n",
6411 (unsigned int)data.PrimitivesStorageNeeded);
6413 ID3D11Asynchronous_Release(query);
6415 for (i = 0; i < ARRAY_SIZE(so_buffer); ++i)
6416 ID3D11Buffer_Release(so_buffer[i]);
6417 ID3D11Buffer_Release(cb);
6418 ID3D11GeometryShader_Release(gs);
6419 ID3D11VertexShader_Release(vs);
6421 done:
6422 release_test_context(&test_context);
6425 static void test_device_removed_reason(void)
6427 ID3D11Device *device;
6428 ULONG refcount;
6429 HRESULT hr;
6431 if (!(device = create_device(NULL)))
6433 skip("Failed to create device.\n");
6434 return;
6437 hr = ID3D11Device_GetDeviceRemovedReason(device);
6438 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6439 hr = ID3D11Device_GetDeviceRemovedReason(device);
6440 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6442 refcount = ID3D11Device_Release(device);
6443 ok(!refcount, "Device has %u references left.\n", refcount);
6446 static void test_private_data(void)
6448 ULONG refcount, expected_refcount;
6449 D3D11_TEXTURE2D_DESC texture_desc;
6450 ID3D10Texture2D *d3d10_texture;
6451 ID3D11Device *test_object;
6452 ID3D11Texture2D *texture;
6453 IDXGIDevice *dxgi_device;
6454 IDXGISurface *surface;
6455 ID3D11Device *device;
6456 IUnknown *ptr;
6457 HRESULT hr;
6458 UINT size;
6460 static const GUID test_guid =
6461 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
6462 static const GUID test_guid2 =
6463 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
6464 static const DWORD data[] = {1, 2, 3, 4};
6466 if (!(device = create_device(NULL)))
6468 skip("Failed to create device.\n");
6469 return;
6472 test_object = create_device(NULL);
6474 texture_desc.Width = 512;
6475 texture_desc.Height = 512;
6476 texture_desc.MipLevels = 1;
6477 texture_desc.ArraySize = 1;
6478 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6479 texture_desc.SampleDesc.Count = 1;
6480 texture_desc.SampleDesc.Quality = 0;
6481 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6482 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6483 texture_desc.CPUAccessFlags = 0;
6484 texture_desc.MiscFlags = 0;
6486 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6487 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6488 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
6489 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
6491 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
6492 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6493 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6494 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6495 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6496 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6497 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6498 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6500 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6501 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6502 size = sizeof(ptr) * 2;
6503 ptr = (IUnknown *)0xdeadbeef;
6504 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6505 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6506 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6507 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6509 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
6510 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
6511 size = sizeof(ptr) * 2;
6512 ptr = (IUnknown *)0xdeadbeef;
6513 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
6514 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6515 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6516 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6517 IDXGIDevice_Release(dxgi_device);
6519 refcount = get_refcount(test_object);
6520 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6521 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6522 expected_refcount = refcount + 1;
6523 refcount = get_refcount(test_object);
6524 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6525 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6526 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6527 refcount = get_refcount(test_object);
6528 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6530 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6531 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6532 --expected_refcount;
6533 refcount = get_refcount(test_object);
6534 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6536 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6537 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6538 size = sizeof(data);
6539 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
6540 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6541 refcount = get_refcount(test_object);
6542 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6543 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
6544 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6545 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
6546 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6548 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6549 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6550 ++expected_refcount;
6551 size = 2 * sizeof(ptr);
6552 ptr = NULL;
6553 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6554 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6555 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
6556 ++expected_refcount;
6557 refcount = get_refcount(test_object);
6558 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6559 IUnknown_Release(ptr);
6560 --expected_refcount;
6562 ptr = (IUnknown *)0xdeadbeef;
6563 size = 1;
6564 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
6565 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6566 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6567 size = 2 * sizeof(ptr);
6568 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
6569 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6570 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6571 refcount = get_refcount(test_object);
6572 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6574 size = 1;
6575 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6576 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
6577 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6578 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6579 if (!enable_debug_layer)
6581 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
6582 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6583 size = 0xdeadbabe;
6584 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
6585 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
6586 ok(size == 0, "Got unexpected size %u.\n", size);
6587 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6588 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
6589 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6590 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6593 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
6594 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6595 ptr = NULL;
6596 size = sizeof(ptr);
6597 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
6598 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6599 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6600 IUnknown_Release(ptr);
6602 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
6603 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
6604 "Texture should implement ID3D10Texture2D.\n");
6605 if (SUCCEEDED(hr))
6607 ptr = NULL;
6608 size = sizeof(ptr);
6609 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
6610 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6611 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6612 IUnknown_Release(ptr);
6613 ID3D10Texture2D_Release(d3d10_texture);
6616 IDXGISurface_Release(surface);
6617 ID3D11Texture2D_Release(texture);
6618 refcount = ID3D11Device_Release(device);
6619 ok(!refcount, "Device has %u references left.\n", refcount);
6620 refcount = ID3D11Device_Release(test_object);
6621 ok(!refcount, "Test object has %u references left.\n", refcount);
6624 static void test_state_refcounting(const D3D_FEATURE_LEVEL feature_level)
6626 ID3D11RasterizerState *rasterizer_state, *tmp_rasterizer_state;
6627 ID3D11Predicate *predicate, *tmp_predicate;
6628 ID3D11SamplerState *sampler, *tmp_sampler;
6629 ID3D11ShaderResourceView *srv, *tmp_srv;
6630 ID3D11RenderTargetView *rtv, *tmp_rtv;
6631 D3D11_RASTERIZER_DESC rasterizer_desc;
6632 D3D11_TEXTURE2D_DESC texture_desc;
6633 D3D11_QUERY_DESC predicate_desc;
6634 D3D11_SAMPLER_DESC sampler_desc;
6635 struct device_desc device_desc;
6636 ID3D11DeviceContext *context;
6637 ID3D11Texture2D *texture;
6638 ID3D11Device *device;
6639 ULONG refcount;
6640 HRESULT hr;
6642 device_desc.feature_level = &feature_level;
6643 device_desc.flags = 0;
6644 if (!(device = create_device(&device_desc)))
6646 skip("Failed to create device for feature level %#x.\n", feature_level);
6647 return;
6650 ID3D11Device_GetImmediateContext(device, &context);
6652 /* ID3D11SamplerState */
6653 memset(&sampler_desc, 0, sizeof(sampler_desc));
6654 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
6655 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
6656 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
6657 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
6658 sampler_desc.MaxLOD = FLT_MAX;
6659 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6660 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6662 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
6663 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6664 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6665 ID3D11SamplerState_Release(tmp_sampler);
6667 tmp_sampler = sampler;
6668 refcount = get_refcount(sampler);
6669 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
6670 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6671 refcount = ID3D11SamplerState_Release(sampler);
6672 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6673 sampler = NULL;
6674 ID3D11DeviceContext_PSGetSamplers(context, 0, 1, &sampler);
6675 ok(sampler == tmp_sampler, "Got sampler %p, expected %p.\n", sampler, tmp_sampler);
6676 refcount = ID3D11SamplerState_Release(sampler);
6677 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6679 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
6680 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6681 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6682 refcount = ID3D11SamplerState_Release(tmp_sampler);
6683 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6685 /* ID3D11RasterizerState */
6686 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
6687 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
6688 rasterizer_desc.CullMode = D3D11_CULL_BACK;
6689 rasterizer_desc.DepthClipEnable = TRUE;
6690 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
6691 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
6693 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
6694 refcount = ID3D11RasterizerState_Release(rasterizer_state);
6695 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6696 ID3D11DeviceContext_RSGetState(context, &tmp_rasterizer_state);
6697 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
6698 tmp_rasterizer_state, rasterizer_state);
6699 refcount = ID3D11RasterizerState_Release(tmp_rasterizer_state);
6700 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6702 /* ID3D11ShaderResourceView */
6703 memset(&texture_desc, 0, sizeof(texture_desc));
6704 texture_desc.Width = 32;
6705 texture_desc.Height = 32;
6706 texture_desc.MipLevels = 1;
6707 texture_desc.ArraySize = 1;
6708 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6709 texture_desc.SampleDesc.Count = 1;
6710 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6711 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6712 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6713 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6714 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6715 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
6716 ID3D11Texture2D_Release(texture);
6718 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6719 refcount = ID3D11ShaderResourceView_Release(srv);
6720 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6721 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &tmp_srv);
6722 ok(tmp_srv == srv, "Got SRV %p, expected %p.\n", tmp_srv, srv);
6723 refcount = ID3D11ShaderResourceView_Release(tmp_srv);
6724 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6726 /* ID3D11RenderTargetView */
6727 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6728 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6729 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6730 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
6731 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
6732 ID3D11Texture2D_Release(texture);
6734 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6735 refcount = ID3D11RenderTargetView_Release(rtv);
6736 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6737 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &tmp_rtv, NULL);
6738 ok(tmp_rtv == rtv, "Got RTV %p, expected %p.\n", tmp_rtv, rtv);
6739 refcount = ID3D11RenderTargetView_Release(tmp_rtv);
6740 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6742 /* ID3D11Predicate */
6743 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
6745 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
6746 predicate_desc.MiscFlags = 0;
6747 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
6748 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
6750 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
6751 refcount = ID3D11Predicate_Release(predicate);
6752 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6753 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, NULL);
6754 ok(tmp_predicate == predicate, "Got predicate %p, expected %p.\n", tmp_predicate, predicate);
6755 refcount = ID3D11Predicate_Release(tmp_predicate);
6756 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6759 ID3D11DeviceContext_Release(context);
6760 refcount = ID3D11Device_Release(device);
6761 ok(!refcount, "Device has %u references left.\n", refcount);
6764 static void test_device_context_state(void)
6766 static const GUID test_guid =
6767 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
6768 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
6770 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
6772 static const float custom_blend_factor[] = {0.1f, 0.2f, 0.3f, 0.4f};
6773 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
6774 #if 0
6775 float4 main(float4 pos : POSITION) : POSITION
6777 return pos;
6779 #endif
6780 static const DWORD simple_vs[] =
6782 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
6783 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6784 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6785 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6786 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
6787 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
6788 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6790 #if 0
6791 struct data
6793 float4 position : SV_Position;
6796 struct patch_constant_data
6798 float edges[3] : SV_TessFactor;
6799 float inside : SV_InsideTessFactor;
6802 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
6804 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
6805 output.inside = 1.0f;
6808 [domain("tri")]
6809 [outputcontrolpoints(3)]
6810 [partitioning("integer")]
6811 [outputtopology("triangle_ccw")]
6812 [patchconstantfunc("patch_constant")]
6813 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
6815 return input[i];
6818 [domain("tri")]
6819 void ds_main(patch_constant_data input,
6820 float3 tess_coord : SV_DomainLocation,
6821 const OutputPatch<data, 3> patch,
6822 out data output)
6824 output.position = tess_coord.x * patch[0].position
6825 + tess_coord.y * patch[1].position
6826 + tess_coord.z * patch[2].position;
6828 #endif
6829 static const DWORD simple_hs[] =
6831 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
6832 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
6833 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
6834 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
6835 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
6836 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
6837 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
6838 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
6839 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
6840 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
6841 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
6842 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
6843 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
6844 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
6845 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
6846 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
6847 0x00004001, 0x3f800000, 0x0100003e,
6849 static const DWORD simple_ds[] =
6851 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
6852 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
6853 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
6854 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
6855 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
6856 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
6857 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
6858 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
6859 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
6860 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
6861 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
6862 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
6863 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
6864 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
6865 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
6867 #if 0
6868 struct gs_out
6870 float4 pos : SV_POSITION;
6873 [maxvertexcount(4)]
6874 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
6876 float offset = 0.1 * vin[0].w;
6877 gs_out v;
6879 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
6880 vout.Append(v);
6881 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
6882 vout.Append(v);
6883 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
6884 vout.Append(v);
6885 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
6886 vout.Append(v);
6888 #endif
6889 static const DWORD simple_gs[] =
6891 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
6892 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6893 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6894 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
6895 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
6896 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
6897 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
6898 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
6899 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
6900 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
6901 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
6902 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
6903 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
6904 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
6905 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
6906 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
6907 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
6908 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
6910 #if 0
6911 float4 main(float4 color : COLOR) : SV_TARGET
6913 return color;
6915 #endif
6916 static const DWORD simple_ps[] =
6918 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
6919 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
6920 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
6921 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
6922 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
6923 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
6924 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6926 #if 0
6927 [numthreads(1, 1, 1)]
6928 void main() { }
6929 #endif
6930 static const DWORD simple_cs[] =
6932 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
6933 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
6934 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
6935 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
6937 static const struct vec4 constant = {1.257f, 1.885f, 2.513f, 3.770f};
6939 ID3DDeviceContextState *context_state, *previous_context_state, *tmp_context_state, *context_state2;
6940 UINT ib_offset, vb_offset, vb_stride, so_offset, offset, stride, sample_mask, stencil_ref, count;
6941 ID3D11Buffer *cb, *srvb, *uavb, *ib, *vb, *sob, *tmp_cb, *tmp_ib, *tmp_vb, *tmp_sob;
6942 D3D_FEATURE_LEVEL feature_level, selected_feature_level;
6943 ID3D11UnorderedAccessView *tmp_uav, *uav, *ps_uav;
6944 ID3D11Device *d3d11_device, *d3d11_device2;
6945 ID3D11SamplerState *sampler, *tmp_sampler;
6946 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
6947 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
6948 ID3D11DeviceContext1 *context, *context2;
6949 ID3D11ShaderResourceView *tmp_srv, *srv;
6950 D3D11_DEVICE_CONTEXT_TYPE context_type;
6951 ID3D11DepthStencilState *tmp_dss, *dss;
6952 ID3D11RenderTargetView *tmp_rtv, *rtv;
6953 ID3D11DepthStencilView *tmp_dsv, *dsv;
6954 ID3D11VertexShader *tmp_vs, *vs, *vs2;
6955 ID3D11RasterizerState *tmp_rs, *rs;
6956 D3D11_TEXTURE2D_DESC texture_desc;
6957 ID3D11GeometryShader *tmp_gs, *gs;
6958 enum D3D_PRIMITIVE_TOPOLOGY topo;
6959 ID3D11ComputeShader *tmp_cs, *cs;
6960 D3D11_DEPTH_STENCIL_DESC ds_desc;
6961 ID3D11Predicate *tmp_pred, *pred;
6962 ID3D11DomainShader *tmp_ds, *ds;
6963 D3D11_SAMPLER_DESC sampler_desc;
6964 D3D11_QUERY_DESC predicate_desc;
6965 ID3D11Device1 *device, *device2;
6966 ID3D11InputLayout *il, *tmp_il;
6967 ID3D11PixelShader *tmp_ps, *ps;
6968 D3D11_RASTERIZER_DESC rs_desc;
6969 ID3D11BlendState *tmp_bs, *bs;
6970 ID3D11HullShader *tmp_hs, *hs;
6971 D3D11_VIEWPORT tmp_vp[2], vp;
6972 D3D11_RECT tmp_rect[2], rect;
6973 D3D11_BLEND_DESC blend_desc;
6974 ID3D11Texture2D *texture;
6975 enum DXGI_FORMAT format;
6976 float blend_factor[4];
6977 DWORD data_size;
6978 BOOL pred_value;
6979 ULONG refcount;
6980 char data[64];
6981 HRESULT hr;
6983 if (!(d3d11_device = create_device(NULL)))
6985 skip("Failed to create device.\n");
6986 return;
6989 hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Device1, (void **)&device);
6990 ID3D11Device_Release(d3d11_device);
6991 if (FAILED(hr))
6993 skip("ID3D11Device1 is not available.\n");
6994 return;
6997 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
6998 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
7000 feature_level = ID3D11Device1_GetFeatureLevel(device);
7001 context = NULL;
7002 ID3D11Device1_GetImmediateContext1(device, &context);
7003 ok(!!context, "Failed to get immediate context.\n");
7005 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
7006 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
7007 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
7008 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
7009 sampler_desc.MipLODBias = 0.0f;
7010 sampler_desc.MaxAnisotropy = 0;
7011 sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
7012 sampler_desc.BorderColor[0] = 0.0f;
7013 sampler_desc.BorderColor[1] = 1.0f;
7014 sampler_desc.BorderColor[2] = 0.0f;
7015 sampler_desc.BorderColor[3] = 1.0f;
7016 sampler_desc.MinLOD = 0.0f;
7017 sampler_desc.MaxLOD = 16.0f;
7018 hr = ID3D11Device1_CreateSamplerState(device, &sampler_desc, &sampler);
7019 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
7021 feature_level = min(feature_level, D3D_FEATURE_LEVEL_11_1);
7023 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level,
7024 1, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, NULL);
7025 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
7027 selected_feature_level = 0xc0de0000;
7028 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1,
7029 D3D11_SDK_VERSION, &IID_ID3D11Device1, &selected_feature_level, NULL);
7030 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
7031 ok(selected_feature_level == feature_level, "Got unexpected feature level %#x, expected %#x.\n",
7032 selected_feature_level, feature_level);
7034 selected_feature_level = 0xc0de0000;
7035 context_state = (void *)0xc0de0001;
7036 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 0,
7037 D3D11_SDK_VERSION, &IID_ID3D11Device1, &selected_feature_level, &context_state);
7038 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7039 ok(!selected_feature_level, "Got unexpected feature level %#x.\n", selected_feature_level);
7040 ok(!context_state, "Got unexpected context state %p.\n", context_state);
7042 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level,
7043 0, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, NULL);
7044 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7046 hr = ID3D11Device1_CreateDeviceContextState(device, 0, NULL,
7047 0, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, NULL);
7048 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
7050 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level,
7051 1, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, &context_state);
7052 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
7053 refcount = get_refcount(context_state);
7054 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7056 context_type = ID3D11DeviceContext1_GetType(context);
7057 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7059 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
7060 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
7061 check_interface(device, &IID_ID3D11Device, TRUE, FALSE);
7062 check_interface(device, &IID_ID3D11Device1, TRUE, FALSE);
7064 cb = create_buffer((ID3D11Device *)device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), NULL);
7065 srvb = create_buffer((ID3D11Device *)device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
7066 uavb = create_buffer((ID3D11Device *)device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
7067 ib = create_buffer((ID3D11Device *)device, D3D11_BIND_INDEX_BUFFER, 1024, NULL);
7068 vb = create_buffer((ID3D11Device *)device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
7069 sob = create_buffer((ID3D11Device *)device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
7071 hr = ID3D11Device1_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
7072 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7074 hr = ID3D11Device1_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
7075 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
7077 hr = ID3D11Device1_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
7078 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7080 if (feature_level < D3D_FEATURE_LEVEL_11_0) hs = NULL;
7081 else
7083 hr = ID3D11Device1_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
7084 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
7087 if (feature_level < D3D_FEATURE_LEVEL_11_0) ds = NULL;
7088 else
7090 hr = ID3D11Device1_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
7091 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
7094 if (feature_level < D3D_FEATURE_LEVEL_11_0) cs = NULL;
7095 else
7097 hr = ID3D11Device1_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
7098 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
7101 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
7102 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
7103 U(srv_desc).Buffer.ElementOffset = 0;
7104 U(srv_desc).Buffer.ElementWidth = 64;
7105 hr = ID3D11Device1_CreateShaderResourceView(device, (ID3D11Resource *)srvb, &srv_desc, &srv);
7106 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7107 ID3D11Buffer_Release(srvb);
7109 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
7110 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
7111 U(uav_desc).Buffer.FirstElement = 0;
7112 U(uav_desc).Buffer.NumElements = 4;
7113 U(uav_desc).Buffer.Flags = 0;
7114 hr = ID3D11Device1_CreateUnorderedAccessView(device, (ID3D11Resource *)uavb, &uav_desc, &uav);
7115 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
7116 ID3D11Buffer_Release(uavb);
7118 uavb = create_buffer((ID3D11Device *)device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
7119 hr = ID3D11Device1_CreateUnorderedAccessView(device, (ID3D11Resource *)uavb, &uav_desc, &ps_uav);
7120 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
7121 ID3D11Buffer_Release(uavb);
7123 hr = ID3D11Device1_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
7124 simple_vs, sizeof(simple_vs), &il);
7125 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7127 ib_offset = 16;
7128 vb_offset = 16;
7129 vb_stride = 16;
7130 so_offset = 16;
7132 texture_desc.Width = 512;
7133 texture_desc.Height = 512;
7134 texture_desc.MipLevels = 1;
7135 texture_desc.ArraySize = 1;
7136 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7137 texture_desc.SampleDesc.Count = 1;
7138 texture_desc.SampleDesc.Quality = 0;
7139 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7140 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7141 texture_desc.CPUAccessFlags = 0;
7142 texture_desc.MiscFlags = 0;
7143 hr = ID3D11Device1_CreateTexture2D(device, &texture_desc, NULL, &texture);
7144 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7145 hr = ID3D11Device1_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
7146 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7147 ID3D11Texture2D_Release(texture);
7149 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
7150 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
7151 hr = ID3D11Device1_CreateTexture2D(device, &texture_desc, NULL, &texture);
7152 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7153 hr = ID3D11Device1_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
7154 ok(SUCCEEDED(hr), "Failed to create depth/stencil view, hr %#x.\n", hr);
7155 ID3D11Texture2D_Release(texture);
7157 memset(&blend_desc, 0, sizeof(blend_desc));
7158 blend_desc.RenderTarget[0].BlendEnable = TRUE;
7159 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
7160 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
7161 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
7162 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
7163 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
7164 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
7165 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
7166 hr = ID3D11Device1_CreateBlendState(device, &blend_desc, &bs);
7167 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
7169 ds_desc.DepthEnable = TRUE;
7170 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
7171 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
7172 ds_desc.StencilEnable = FALSE;
7173 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
7174 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
7175 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
7176 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
7177 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
7178 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
7179 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
7180 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
7181 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
7182 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
7183 hr = ID3D11Device1_CreateDepthStencilState(device, &ds_desc, &dss);
7184 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
7186 rs_desc.FillMode = D3D11_FILL_SOLID;
7187 rs_desc.CullMode = D3D11_CULL_BACK;
7188 rs_desc.FrontCounterClockwise = FALSE;
7189 rs_desc.DepthBias = 0;
7190 rs_desc.DepthBiasClamp = 0.0f;
7191 rs_desc.SlopeScaledDepthBias = 0.0f;
7192 rs_desc.DepthClipEnable = TRUE;
7193 rs_desc.ScissorEnable = TRUE;
7194 rs_desc.MultisampleEnable = FALSE;
7195 rs_desc.AntialiasedLineEnable = FALSE;
7196 hr = ID3D11Device1_CreateRasterizerState(device, &rs_desc, &rs);
7197 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
7199 SetRect(&rect, 0, 0, 1, 2);
7200 vp.TopLeftX = 0;
7201 vp.TopLeftY = 0;
7202 vp.Width = 3;
7203 vp.Height = 4;
7204 vp.MinDepth = 0.f;
7205 vp.MaxDepth = 0.01f;
7207 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
7208 predicate_desc.MiscFlags = 0;
7209 ID3D11Device1_CreatePredicate(device, &predicate_desc, &pred);
7211 ID3D11DeviceContext1_VSSetConstantBuffers(context, 0, 1, &cb);
7212 ID3D11DeviceContext1_VSSetSamplers(context, 0, 1, &sampler);
7213 ID3D11DeviceContext1_VSSetShader(context, vs, NULL, 0);
7214 ID3D11DeviceContext1_VSSetShaderResources(context, 0, 1, &srv);
7215 refcount = get_refcount(vs);
7216 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7218 ID3D11DeviceContext1_GSSetConstantBuffers(context, 0, 1, &cb);
7219 ID3D11DeviceContext1_GSSetSamplers(context, 0, 1, &sampler);
7220 ID3D11DeviceContext1_GSSetShader(context, gs, NULL, 0);
7221 ID3D11DeviceContext1_GSSetShaderResources(context, 0, 1, &srv);
7223 ID3D11DeviceContext1_PSSetConstantBuffers(context, 0, 1, &cb);
7224 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
7225 ID3D11DeviceContext1_PSSetShader(context, ps, NULL, 0);
7226 ID3D11DeviceContext1_PSSetShaderResources(context, 0, 1, &srv);
7228 ID3D11DeviceContext1_HSSetConstantBuffers(context, 0, 1, &cb);
7229 ID3D11DeviceContext1_HSSetSamplers(context, 0, 1, &sampler);
7230 ID3D11DeviceContext1_HSSetShader(context, hs, NULL, 0);
7231 ID3D11DeviceContext1_HSSetShaderResources(context, 0, 1, &srv);
7233 ID3D11DeviceContext1_DSSetConstantBuffers(context, 0, 1, &cb);
7234 ID3D11DeviceContext1_DSSetSamplers(context, 0, 1, &sampler);
7235 ID3D11DeviceContext1_DSSetShader(context, ds, NULL, 0);
7236 ID3D11DeviceContext1_DSSetShaderResources(context, 0, 1, &srv);
7238 ID3D11DeviceContext1_CSSetConstantBuffers(context, 0, 1, &cb);
7239 ID3D11DeviceContext1_CSSetSamplers(context, 0, 1, &sampler);
7240 ID3D11DeviceContext1_CSSetShader(context, cs, NULL, 0);
7241 ID3D11DeviceContext1_CSSetShaderResources(context, 0, 1, &srv);
7242 ID3D11DeviceContext1_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
7244 ID3D11DeviceContext1_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7245 ID3D11DeviceContext1_IASetInputLayout(context, il);
7246 ID3D11DeviceContext1_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, ib_offset);
7247 ID3D11DeviceContext1_IASetVertexBuffers(context, 0, 1, &vb, &vb_stride, &vb_offset);
7249 ID3D11DeviceContext1_OMSetBlendState(context, bs, custom_blend_factor, 0xff00ff00);
7250 ID3D11DeviceContext1_OMSetDepthStencilState(context, dss, 3);
7251 ID3D11DeviceContext1_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, dsv, 1, 1, &ps_uav, NULL);
7253 ID3D11DeviceContext1_RSSetScissorRects(context, 1, &rect);
7254 ID3D11DeviceContext1_RSSetViewports(context, 1, &vp);
7255 ID3D11DeviceContext1_RSSetState(context, rs);
7257 ID3D11DeviceContext1_SOSetTargets(context, 1, &sob, &so_offset);
7258 ID3D11DeviceContext1_SetPredication(context, pred, TRUE);
7260 previous_context_state = (ID3DDeviceContextState *)0xdeadbeef;
7261 ID3D11DeviceContext1_SwapDeviceContextState(context, NULL, &previous_context_state);
7262 ok(previous_context_state == NULL, "Got unexpected state pointer.\n");
7263 previous_context_state = NULL;
7264 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
7265 ok(previous_context_state != NULL, "Failed to get previous context state\n");
7266 refcount = get_refcount(vs);
7267 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7269 hr = ID3DDeviceContextState_SetPrivateData(context_state, &test_guid, sizeof(constant), &constant);
7270 ok(hr == S_OK, "Failed to set private data, hr %#x.\n", hr);
7271 refcount = ID3DDeviceContextState_Release(context_state);
7272 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7273 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
7274 data_size = sizeof(data);
7275 memset(data, 0xa5, sizeof(data));
7276 hr = ID3DDeviceContextState_GetPrivateData(context_state, &test_guid, &data_size, data);
7277 ok(hr == S_OK, "Failed to get private data, hr %#x.\n", hr);
7278 ok(data_size == sizeof(constant), "Got private data size %x, expected %x.\n", data_size, sizeof(constant));
7279 ok(!memcmp(data, &constant, sizeof(constant)), "Got unexpected private data.\n");
7280 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, NULL);
7282 context_type = ID3D11DeviceContext1_GetType(context);
7283 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7285 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7286 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7287 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7288 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7289 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7290 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7291 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7292 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7293 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7294 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7295 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7296 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7298 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7299 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7300 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7301 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7302 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7303 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7304 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7305 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7306 ok(!tmp_gs, "Got unexpected shader %p.\n", tmp_gs);
7307 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7308 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7309 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7311 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7312 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7313 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7314 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7315 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7316 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7317 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7318 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7319 ok(!tmp_ps, "Got unexpected shader %p.\n", tmp_ps);
7320 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7321 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7322 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7324 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7325 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7326 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7327 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7328 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7329 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7330 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7331 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7332 if (hs) ok(!tmp_hs, "Got unexpected shader %p.\n", tmp_hs);
7333 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7334 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7335 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7337 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7338 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7339 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7340 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7341 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7342 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7343 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7344 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7345 if (ds) ok(!tmp_ds, "Got unexpected shader %p.\n", tmp_ds);
7346 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7347 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7348 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7350 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7351 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7352 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7353 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7354 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7355 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7356 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7357 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7358 if (cs) ok(!tmp_cs, "Got unexpected shader %p.\n", tmp_cs);
7359 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7360 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7361 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7362 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7363 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7364 ok(!tmp_uav, "Got unexpected uav %p.\n", tmp_uav);
7366 topo = 0xdeadbeef;
7367 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7368 ok(topo == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected topology %#x.\n", topo);
7369 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7370 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7371 ok(!tmp_il, "Got unexpected input layout %p.\n", tmp_il);
7372 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7373 format = 0xdeadbeef;
7374 offset = 0xdeadbeef;
7375 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7376 ok(!tmp_ib, "Got unexpected input buffer %p.\n", tmp_ib);
7377 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected input buffer format %#x.\n", format);
7378 ok(offset == 0, "Got unexpected input buffer offset %#x.\n", offset);
7379 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7380 stride = 0xdeadbeef;
7381 offset = 0xdeadbeef;
7382 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7383 ok(!tmp_vb, "Got unexpected vertex buffer %p.\n", tmp_vb);
7384 ok(stride == 0, "Got unexpected vertex buffer stride %#x.\n", stride);
7385 ok(offset == 0, "Got unexpected vertex buffer offset %#x.\n", offset);
7387 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7388 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7389 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7390 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7391 ok(!tmp_rtv, "Got unexpected rendertarget view %p.\n", tmp_rtv);
7392 ok(!tmp_dsv, "Got unexpected depth/stencil view %p.\n", tmp_dsv);
7393 ok(!tmp_uav, "Got unexpected unordered access view %p.\n", tmp_uav);
7394 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7395 memset(blend_factor, 0xcd, sizeof(blend_factor));
7396 sample_mask = 0xdeadbeef;
7397 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7398 ok(!tmp_bs, "Got unexpected blend state %p.\n", tmp_bs);
7399 ok(!memcmp(blend_factor, default_blend_factor, sizeof(blend_factor)),
7400 "Got unexpected blend factor %f,%f,%f,%f.\n",
7401 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
7402 ok(sample_mask == ~0, "Got unexpected sample mask %#x.\n", sample_mask);
7403 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7404 stencil_ref = 0xdeadbeef;
7405 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7406 ok(!tmp_dss, "Got unexpected depth/stencil state %p.\n", tmp_dss);
7407 ok(stencil_ref == 0, "Got unexpected stencil ref %#x.\n", stencil_ref);
7409 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7410 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7411 ok(!tmp_rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7412 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7413 count = 2;
7414 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7415 ok(count == 0, "Got unexpected viewport count %u.\n", count);
7416 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7417 count = 2;
7418 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7419 ok(count == 0, "Got unexpected scissor rect count %u.\n", count);
7421 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7422 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7423 ok(!tmp_sob, "Got unexpected stream output buffer %p.\n", tmp_sob);
7425 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7426 pred_value = 0xdeadbeef;
7427 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7428 ok(!tmp_pred, "Got unexpected predicate %p.\n", tmp_pred);
7429 ok(!pred_value, "Got unexpected predicate value %d.\n", pred_value);
7431 /* updating the device context should also update the device context state */
7432 hr = ID3D11Device1_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs2);
7433 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7434 ID3D11DeviceContext1_VSSetShader(context, vs2, NULL, 0);
7435 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &tmp_context_state);
7436 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7437 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7438 ok(tmp_context_state == context_state, "Got unexpected state pointer.\n");
7439 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7440 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7441 ok(tmp_vs == vs2, "Got shader %p, expected %p.\n", tmp_vs, vs2);
7442 refcount = ID3D11VertexShader_Release(tmp_vs);
7443 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7445 /* context states may be used with other devices instances too
7447 * Or at least, no error is returned right away. Using objects like shaders
7448 * from other device instances causes a segfault later on Nvidia Windows
7449 * drivers. This suggests the feature tested below is more a bug than a
7450 * feature.
7452 * The tests below suggest that a ContextState object stores its own state
7453 * for every device it is used with. This isn't entirely true, e.g. the
7454 * primitive topology can be transfered between devices, but will cause odd
7455 * refcounting behavior afterwards (IAGetPrimitiveTopology will leak 54
7456 * references on the context's device for example). */
7457 if (0)
7459 d3d11_device2 = create_device(NULL);
7460 ok(!!d3d11_device2, "Failed to create device.\n");
7461 hr = ID3D11Device_QueryInterface(d3d11_device2, &IID_ID3D11Device1, (void **)&device2);
7462 ok(SUCCEEDED(hr), "Failed to query device interface, hr %#x.\n", hr);
7463 ID3D11Device_Release(d3d11_device2);
7464 ID3D11Device1_GetImmediateContext1(device2, &context2);
7465 ok(!!context2, "Failed to get immediate context.\n");
7467 /* but they track a distinct state on each context */
7468 ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, &tmp_context_state);
7469 ok(!!tmp_context_state, "Failed to get context state.\n");
7470 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7471 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7472 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7474 /* updating context2 vertex shader doesn't update other contexts using the same state */
7475 ID3D11DeviceContext1_VSSetShader(context2, vs, NULL, 0);
7476 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7477 ok(tmp_vs == vs2, "Got shader %p, expected %p.\n", tmp_vs, vs2);
7478 refcount = ID3D11VertexShader_Release(tmp_vs);
7479 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7481 ID3D11DeviceContext1_SwapDeviceContextState(context2, tmp_context_state, &context_state2);
7482 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7483 ok(refcount == 0, "Got refcount %u, expected 1.\n", refcount);
7484 refcount = ID3DDeviceContextState_Release(context_state2);
7485 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7486 ok(context_state2 == context_state, "Got unexpected state pointer.\n");
7488 /* swapping the default state on context2 effectively clears the vertex shader */
7489 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7490 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7491 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7493 ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, &tmp_context_state);
7494 ok(!!tmp_context_state, "Failed to get context state.\n");
7495 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7496 ok(refcount == 0, "Got refcount %u, expected 1.\n", refcount);
7498 /* clearing the vertex shader on context doesn't have side effect on context2 */
7499 ID3D11DeviceContext1_VSSetShader(context, NULL, NULL, 0);
7500 refcount = get_refcount(vs2);
7501 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7502 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7503 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7504 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7505 refcount = ID3D11VertexShader_Release(tmp_vs);
7506 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7508 /* even after swapping it again */
7509 ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, NULL);
7510 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7511 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7512 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7513 refcount = ID3D11VertexShader_Release(tmp_vs);
7514 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7516 /* swapping the initial state on context2 doesn't have side effect on context either */
7517 ID3D11DeviceContext1_SwapDeviceContextState(context2, previous_context_state, NULL);
7518 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7519 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7520 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7522 refcount = ID3D11DeviceContext1_Release(context2);
7523 ok(refcount == 0, "Got refcount %u, expected 0.\n", refcount);
7524 refcount = ID3D11Device1_Release(device2);
7525 ok(refcount == 0, "Got refcount %u, expected 0.\n", refcount);
7528 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &tmp_context_state);
7529 refcount = ID3DDeviceContextState_Release(previous_context_state);
7530 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7531 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7532 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7533 refcount = ID3DDeviceContextState_Release(context_state);
7534 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7535 ok(tmp_context_state == context_state, "Got unexpected state pointer.\n");
7536 refcount = get_refcount(vs);
7537 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7539 /* ID3DDeviceContextState retains the previous state. */
7541 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7542 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7543 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7544 ID3D11SamplerState_Release(tmp_sampler);
7545 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7546 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7547 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7548 ID3D11Buffer_Release(tmp_cb);
7549 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7550 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7551 ok(tmp_ps == ps, "Got shader %p, expected %p.\n", tmp_ps, ps);
7552 ID3D11PixelShader_Release(tmp_ps);
7553 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7554 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7555 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7556 ID3D11ShaderResourceView_Release(tmp_srv);
7558 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7559 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7560 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7561 ID3D11SamplerState_Release(tmp_sampler);
7562 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7563 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7564 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7565 ID3D11Buffer_Release(tmp_cb);
7566 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7567 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7568 ok(tmp_cs == cs, "Got shader %p, expected %p.\n", tmp_cs, cs);
7569 if (cs) ID3D11ComputeShader_Release(tmp_cs);
7570 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7571 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7572 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7573 ID3D11ShaderResourceView_Release(tmp_srv);
7574 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7575 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7576 ok(tmp_uav == uav, "Got uav %p, expected %p.\n", tmp_uav, uav);
7577 ID3D11UnorderedAccessView_Release(tmp_uav);
7579 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7580 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7581 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7582 ID3D11SamplerState_Release(tmp_sampler);
7583 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7584 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7585 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7586 ID3D11Buffer_Release(tmp_cb);
7587 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7588 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7589 ok(tmp_ds == ds, "Got shader %p, expected %p.\n", tmp_ds, ds);
7590 if (ds) ID3D11DomainShader_Release(tmp_ds);
7591 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7592 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7593 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7594 ID3D11ShaderResourceView_Release(tmp_srv);
7596 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7597 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7598 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7599 ID3D11SamplerState_Release(tmp_sampler);
7600 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7601 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7602 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7603 ID3D11Buffer_Release(tmp_cb);
7604 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7605 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7606 ok(tmp_gs == gs, "Got shader %p, expected %p.\n", tmp_gs, gs);
7607 ID3D11GeometryShader_Release(tmp_gs);
7608 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7609 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7610 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7611 ID3D11ShaderResourceView_Release(tmp_srv);
7613 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7614 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7615 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7616 ID3D11SamplerState_Release(tmp_sampler);
7617 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7618 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7619 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7620 ID3D11Buffer_Release(tmp_cb);
7621 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7622 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7623 ok(tmp_hs == hs, "Got shader %p, expected %p.\n", tmp_hs, hs);
7624 if (hs) ID3D11HullShader_Release(tmp_hs);
7625 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7626 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7627 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7628 ID3D11ShaderResourceView_Release(tmp_srv);
7630 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7631 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7632 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7633 ID3D11SamplerState_Release(tmp_sampler);
7634 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7635 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7636 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7637 ID3D11Buffer_Release(tmp_cb);
7638 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7639 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7640 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7641 ID3D11VertexShader_Release(tmp_vs);
7642 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7643 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7644 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7645 ID3D11ShaderResourceView_Release(tmp_srv);
7647 topo = 0xdeadbeef;
7648 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7649 ok(topo == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got topology %#x, expected %#x.\n", topo, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7650 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7651 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7652 ok(tmp_il == il, "Got input layout %p, expected %p.\n", tmp_il, il);
7653 ID3D11InputLayout_Release(tmp_il);
7654 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7655 format = 0xdeadbeef;
7656 offset = 0xdeadbeef;
7657 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7658 ok(tmp_ib == ib, "Got input buffer %p, expected %p.\n", tmp_ib, ib);
7659 ID3D11Buffer_Release(tmp_ib);
7660 ok(format == DXGI_FORMAT_R32_UINT, "Got input buffer format %#x, expected %#x.\n", format, DXGI_FORMAT_R32_UINT);
7661 ok(offset == 16, "Got input buffer offset %#x, expected 16.\n", offset);
7662 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7663 stride = 0xdeadbeef;
7664 offset = 0xdeadbeef;
7665 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7666 ok(tmp_vb == vb, "Got vertex buffer %p, expected %p.\n", tmp_vb, vb);
7667 ID3D11Buffer_Release(tmp_vb);
7668 ok(stride == 16, "Got vertex buffer stride %#x, expected 16.\n", stride);
7669 ok(offset == 16, "Got vertex buffer offset %#x, expected 16.\n", offset);
7671 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7672 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7673 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7674 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7675 ok(tmp_rtv == rtv, "Got rendertarget view %p, expected %p.\n", tmp_rtv, rtv);
7676 ID3D11RenderTargetView_Release(tmp_rtv);
7677 ok(tmp_dsv == dsv, "Got depth/stencil view %p, expected %p.\n", tmp_dsv, dsv);
7678 ID3D11DepthStencilView_Release(tmp_dsv);
7679 ok(tmp_uav == ps_uav, "Got unordered access view %p, expected %p.\n", tmp_uav, ps_uav);
7680 ID3D11UnorderedAccessView_Release(tmp_uav);
7681 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7682 memset(blend_factor, 0xcd, sizeof(blend_factor));
7683 sample_mask = 0xdeadbeef;
7684 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7685 ok(tmp_bs == bs, "Got blend state %p, expected %p.\n", tmp_bs, bs);
7686 ID3D11BlendState_Release(tmp_bs);
7687 ok(!memcmp(blend_factor, custom_blend_factor, sizeof(blend_factor)),
7688 "Got blend factor %f,%f,%f,%f, expected %f,%f,%f,%f.\n",
7689 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3],
7690 custom_blend_factor[0], custom_blend_factor[1], custom_blend_factor[2], custom_blend_factor[3]);
7691 ok(sample_mask == 0xff00ff00, "Got sample mask %#x, expected %#x.\n", sample_mask, 0xff00ff00);
7692 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7693 stencil_ref = 0xdeadbeef;
7694 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7695 ok(tmp_dss == dss, "Got depth/stencil state %p, expected %p.\n", tmp_dss, dss);
7696 ID3D11DepthStencilState_Release(tmp_dss);
7697 ok(stencil_ref == 3, "Got stencil ref %#x, expected 3.\n", stencil_ref);
7699 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7700 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7701 ok(tmp_rs == rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7702 ID3D11RasterizerState_Release(tmp_rs);
7703 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7704 count = 2;
7705 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7706 ok(count == 1, "Got viewport count %u, expected 1.\n", count);
7707 ok(!memcmp(tmp_vp, &vp, sizeof(vp)), "Got viewport %s, expected %s.\n",
7708 debugstr_viewport(tmp_vp), debugstr_viewport(&vp));
7709 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7710 count = 2;
7711 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7712 ok(count == 1, "Got scissor rect count %u, expected 1.\n", count);
7713 ok(!memcmp(tmp_rect, &rect, sizeof(rect)), "Got scissor rect %s, expected %s.\n",
7714 wine_dbgstr_rect(tmp_rect), wine_dbgstr_rect(&rect));
7716 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7717 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7718 ok(tmp_sob == sob, "Got stream output buffer %p, expected %p.\n", tmp_sob, sob);
7719 ID3D11Buffer_Release(tmp_sob);
7721 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7722 pred_value = 0xdeadbeef;
7723 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7724 ok(tmp_pred == pred, "Got predicate %p, expected %p.\n", tmp_pred, pred);
7725 ID3D11Predicate_Release(tmp_pred);
7726 ok(pred_value == TRUE, "Got predicate value %#x, expected TRUE.\n", pred_value);
7728 feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1);
7729 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
7730 &IID_ID3D10Device, NULL, &context_state);
7731 ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr);
7732 refcount = get_refcount(context_state);
7733 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7735 context_type = ID3D11DeviceContext1_GetType(context);
7736 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7738 /* Enable ID3D10Device behavior. */
7739 previous_context_state = NULL;
7740 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
7741 refcount = ID3DDeviceContextState_Release(context_state);
7742 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7743 ok(previous_context_state != NULL, "Failed to get previous context state\n");
7745 context_type = ID3D11DeviceContext1_GetType(context);
7746 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7748 ID3D11DeviceContext1_VSSetConstantBuffers(context, 0, 1, &cb);
7749 ID3D11DeviceContext1_VSSetSamplers(context, 0, 1, &sampler);
7750 ID3D11DeviceContext1_VSSetShader(context, vs, NULL, 0);
7751 ID3D11DeviceContext1_VSSetShaderResources(context, 0, 1, &srv);
7753 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7754 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7755 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7756 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7757 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7758 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7759 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7760 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7761 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7762 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7763 todo_wine ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7764 if (tmp_vs && tmp_vs != (ID3D11VertexShader *)0xdeadbeef) ID3D11VertexShader_Release(tmp_vs);
7765 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7766 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7767 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7768 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7770 ID3D11DeviceContext1_GSSetConstantBuffers(context, 0, 1, &cb);
7771 ID3D11DeviceContext1_GSSetSamplers(context, 0, 1, &sampler);
7772 ID3D11DeviceContext1_GSSetShader(context, gs, NULL, 0);
7773 ID3D11DeviceContext1_GSSetShaderResources(context, 0, 1, &srv);
7775 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7776 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7777 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7778 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7779 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7780 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7781 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7782 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7783 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7784 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7785 todo_wine ok(!tmp_gs, "Got unexpected shader %p.\n", tmp_gs);
7786 if (tmp_gs && tmp_gs != (ID3D11GeometryShader *)0xdeadbeef) ID3D11GeometryShader_Release(tmp_gs);
7787 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7788 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7789 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7790 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7792 ID3D11DeviceContext1_PSSetConstantBuffers(context, 0, 1, &cb);
7793 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
7794 ID3D11DeviceContext1_PSSetShader(context, ps, NULL, 0);
7795 ID3D11DeviceContext1_PSSetShaderResources(context, 0, 1, &srv);
7797 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7798 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7799 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7800 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7801 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7802 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7803 todo_wine ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler);
7804 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7805 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7806 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7807 todo_wine ok(!tmp_ps, "Got unexpected shader %p.\n", tmp_ps);
7808 if (tmp_ps && tmp_ps != (ID3D11PixelShader *)0xdeadbeef) ID3D11PixelShader_Release(tmp_ps);
7809 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7810 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7811 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7812 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7814 ID3D11DeviceContext1_HSSetConstantBuffers(context, 0, 1, &cb);
7815 ID3D11DeviceContext1_HSSetSamplers(context, 0, 1, &sampler);
7816 ID3D11DeviceContext1_HSSetShader(context, hs, NULL, 0);
7817 ID3D11DeviceContext1_HSSetShaderResources(context, 0, 1, &srv);
7819 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7820 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7821 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7822 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7823 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7824 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7825 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7826 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7827 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7828 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7829 if (hs) todo_wine ok(!tmp_hs, "Got unexpected shader %p.\n", tmp_hs);
7830 if (tmp_hs && tmp_hs != (ID3D11HullShader *)0xdeadbeef) ID3D11HullShader_Release(tmp_hs);
7831 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7832 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7833 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7834 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7836 ID3D11DeviceContext1_DSSetConstantBuffers(context, 0, 1, &cb);
7837 ID3D11DeviceContext1_DSSetSamplers(context, 0, 1, &sampler);
7838 ID3D11DeviceContext1_DSSetShader(context, ds, NULL, 0);
7839 ID3D11DeviceContext1_DSSetShaderResources(context, 0, 1, &srv);
7841 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7842 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7843 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7844 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7845 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7846 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7847 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7848 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7849 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7850 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7851 if (ds) todo_wine ok(!tmp_ds, "Got unexpected shader %p.\n", tmp_ds);
7852 if (tmp_ds && tmp_ds != (ID3D11DomainShader *)0xdeadbeef) ID3D11DomainShader_Release(tmp_ds);
7853 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7854 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7855 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7856 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7858 ID3D11DeviceContext1_CSSetConstantBuffers(context, 0, 1, &cb);
7859 ID3D11DeviceContext1_CSSetSamplers(context, 0, 1, &sampler);
7860 ID3D11DeviceContext1_CSSetShader(context, cs, NULL, 0);
7861 ID3D11DeviceContext1_CSSetShaderResources(context, 0, 1, &srv);
7862 ID3D11DeviceContext1_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
7864 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7865 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7866 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7867 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7868 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7869 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7870 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7871 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7872 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7873 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7874 if (cs) todo_wine ok(!tmp_cs, "Got unexpected shader %p.\n", tmp_cs);
7875 if (tmp_cs && tmp_cs != (ID3D11ComputeShader *)0xdeadbeef) ID3D11ComputeShader_Release(tmp_cs);
7876 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7877 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7878 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7879 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7880 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7881 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7882 todo_wine ok(!tmp_uav, "Got unexpected uav %p.\n", tmp_uav);
7883 if (tmp_uav && tmp_uav != (ID3D11UnorderedAccessView *)0xdeadbeef) ID3D11UnorderedAccessView_Release(tmp_uav);
7885 ID3D11DeviceContext1_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7886 ID3D11DeviceContext1_IASetInputLayout(context, il);
7887 ID3D11DeviceContext1_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, ib_offset);
7888 ID3D11DeviceContext1_IASetVertexBuffers(context, 0, 1, &vb, &vb_stride, &vb_offset);
7890 topo = 0xdeadbeef;
7891 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7892 todo_wine ok(topo == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected topology %#x.\n", topo);
7893 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7894 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7895 todo_wine ok(!tmp_il, "Got unexpected input layout %p.\n", tmp_il);
7896 if (tmp_il) ID3D11InputLayout_Release(tmp_il);
7897 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7898 format = 0xdeadbeef;
7899 offset = 0xdeadbeef;
7900 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7901 todo_wine ok(!tmp_ib, "Got unexpected input buffer %p.\n", tmp_ib);
7902 if (tmp_ib) ID3D11Buffer_Release(tmp_ib);
7903 todo_wine ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected input buffer format %#x.\n", format);
7904 todo_wine ok(offset == 0, "Got unexpected input buffer offset %#x.\n", offset);
7905 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7906 stride = 0xdeadbeef;
7907 offset = 0xdeadbeef;
7908 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7909 todo_wine ok(!tmp_vb, "Got unexpected vertex buffer %p.\n", tmp_vb);
7910 if (tmp_vb) ID3D11Buffer_Release(tmp_vb);
7911 todo_wine ok(stride == 0, "Got unexpected vertex buffer stride %#x.\n", stride);
7912 todo_wine ok(offset == 0, "Got unexpected vertex buffer offset %#x.\n", offset);
7914 ID3D11DeviceContext1_OMSetBlendState(context, bs, custom_blend_factor, 0xff00ff00);
7915 ID3D11DeviceContext1_OMSetDepthStencilState(context, dss, 3);
7916 ID3D11DeviceContext1_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, dsv, 1, 1, &ps_uav, NULL);
7918 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7919 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7920 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7921 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7922 todo_wine ok(!tmp_rtv, "Got unexpected rendertarget view %p.\n", tmp_rtv);
7923 if (tmp_rtv) ID3D11RenderTargetView_Release(tmp_rtv);
7924 todo_wine ok(!tmp_dsv, "Got unexpected depth/stencil view %p.\n", tmp_dsv);
7925 if (tmp_dsv) ID3D11DepthStencilView_Release(tmp_dsv);
7926 todo_wine ok(!tmp_uav, "Got unexpected unordered access view %p.\n", tmp_uav);
7927 if (tmp_uav) ID3D11UnorderedAccessView_Release(tmp_uav);
7928 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7929 memset(blend_factor, 0xcd, sizeof(blend_factor));
7930 sample_mask = 0xdeadbeef;
7931 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7932 todo_wine ok(!tmp_bs, "Got unexpected blend state %p.\n", tmp_bs);
7933 if (tmp_bs) ID3D11BlendState_Release(tmp_bs);
7934 todo_wine ok(!memcmp(blend_factor, default_blend_factor, sizeof(blend_factor)),
7935 "Got unexpected blend factor %f,%f,%f,%f.\n",
7936 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
7937 todo_wine ok(sample_mask == ~0, "Got unexpected sample mask %#x.\n", sample_mask);
7938 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7939 stencil_ref = 0xdeadbeef;
7940 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7941 todo_wine ok(!tmp_dss, "Got unexpected depth/stencil state %p.\n", tmp_dss);
7942 if (tmp_dss) ID3D11DepthStencilState_Release(tmp_dss);
7943 todo_wine ok(stencil_ref == 0, "Got unexpected stencil ref %#x.\n", stencil_ref);
7945 ID3D11DeviceContext1_RSSetScissorRects(context, 1, &rect);
7946 ID3D11DeviceContext1_RSSetViewports(context, 1, &vp);
7947 ID3D11DeviceContext1_RSSetState(context, rs);
7949 ID3D11DeviceContext1_SOSetTargets(context, 1, &sob, &so_offset);
7950 ID3D11DeviceContext1_SetPredication(context, pred, TRUE);
7952 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7953 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7954 todo_wine ok(!tmp_rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7955 if (tmp_rs) ID3D11RasterizerState_Release(tmp_rs);
7956 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7957 count = 2;
7958 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7959 todo_wine ok(count == 0, "Got unexpected viewport count %u.\n", count);
7960 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7961 count = 2;
7962 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7963 todo_wine ok(count == 0, "Got unexpected scissor rect count %u.\n", count);
7965 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7966 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7967 todo_wine ok(!tmp_sob, "Got unexpected stream output buffer %p.\n", tmp_sob);
7968 if (tmp_sob) ID3D11Buffer_Release(tmp_sob);
7970 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7971 pred_value = 0xdeadbeef;
7972 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7973 todo_wine ok(!tmp_pred, "Got unexpected predicate %p.\n", tmp_pred);
7974 if (tmp_pred) ID3D11Predicate_Release(tmp_pred);
7975 todo_wine ok(!pred_value, "Got unexpected predicate value %d.\n", pred_value);
7977 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
7978 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
7980 context_state = NULL;
7981 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
7982 refcount = ID3DDeviceContextState_Release(context_state);
7983 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7984 refcount = ID3DDeviceContextState_Release(previous_context_state);
7985 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7987 /* ID3DDeviceContextState retains the previous state. */
7989 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7990 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7991 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7992 ID3D11SamplerState_Release(tmp_sampler);
7993 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7994 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7995 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7996 ID3D11Buffer_Release(tmp_cb);
7997 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7998 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7999 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
8000 ID3D11VertexShader_Release(tmp_vs);
8001 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
8002 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
8003 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
8004 ID3D11ShaderResourceView_Release(tmp_srv);
8006 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
8007 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
8008 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
8009 ID3D11SamplerState_Release(tmp_sampler);
8010 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
8011 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
8012 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
8013 ID3D11Buffer_Release(tmp_cb);
8014 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
8015 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
8016 ok(tmp_gs == gs, "Got shader %p, expected %p.\n", tmp_gs, gs);
8017 ID3D11GeometryShader_Release(tmp_gs);
8018 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
8019 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
8020 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
8021 ID3D11ShaderResourceView_Release(tmp_srv);
8023 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
8024 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
8025 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
8026 ID3D11SamplerState_Release(tmp_sampler);
8027 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
8028 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
8029 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
8030 ID3D11Buffer_Release(tmp_cb);
8031 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
8032 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
8033 ok(tmp_ps == ps, "Got shader %p, expected %p.\n", tmp_ps, ps);
8034 ID3D11PixelShader_Release(tmp_ps);
8035 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
8036 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
8037 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
8038 ID3D11ShaderResourceView_Release(tmp_srv);
8040 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
8041 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
8042 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
8043 ID3D11SamplerState_Release(tmp_sampler);
8044 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
8045 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
8046 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
8047 ID3D11Buffer_Release(tmp_cb);
8048 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
8049 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
8050 ok(tmp_hs == hs, "Got shader %p, expected %p.\n", tmp_hs, hs);
8051 if (hs) ID3D11HullShader_Release(tmp_hs);
8052 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
8053 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
8054 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
8055 ID3D11ShaderResourceView_Release(tmp_srv);
8057 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
8058 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
8059 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
8060 ID3D11SamplerState_Release(tmp_sampler);
8061 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
8062 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
8063 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
8064 ID3D11Buffer_Release(tmp_cb);
8065 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
8066 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
8067 ok(tmp_ds == ds, "Got shader %p, expected %p.\n", tmp_ds, ds);
8068 if (ds) ID3D11DomainShader_Release(tmp_ds);
8069 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
8070 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
8071 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
8072 ID3D11ShaderResourceView_Release(tmp_srv);
8074 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
8075 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
8076 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
8077 ID3D11SamplerState_Release(tmp_sampler);
8078 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
8079 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
8080 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
8081 ID3D11Buffer_Release(tmp_cb);
8082 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
8083 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
8084 ok(tmp_cs == cs, "Got shader %p, expected %p.\n", tmp_cs, cs);
8085 if (cs) ID3D11ComputeShader_Release(tmp_cs);
8086 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
8087 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
8088 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
8089 ID3D11ShaderResourceView_Release(tmp_srv);
8090 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
8091 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
8092 ok(tmp_uav == uav, "Got uav %p, expected %p.\n", tmp_uav, uav);
8093 ID3D11UnorderedAccessView_Release(tmp_uav);
8095 topo = 0xdeadbeef;
8096 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
8097 ok(topo == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got topology %#x, expected %#x.\n", topo, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8098 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
8099 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
8100 ok(tmp_il == il, "Got input layout %p, expected %p.\n", tmp_il, il);
8101 ID3D11InputLayout_Release(tmp_il);
8102 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
8103 format = 0xdeadbeef;
8104 offset = 0xdeadbeef;
8105 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
8106 ok(tmp_ib == ib, "Got input buffer %p, expected %p.\n", tmp_ib, ib);
8107 ID3D11Buffer_Release(tmp_ib);
8108 ok(format == DXGI_FORMAT_R32_UINT, "Got input buffer format %#x, expected %#x.\n", format, DXGI_FORMAT_R32_UINT);
8109 ok(offset == 16, "Got input buffer offset %#x, expected 16.\n", offset);
8110 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
8111 stride = 0xdeadbeef;
8112 offset = 0xdeadbeef;
8113 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
8114 ok(tmp_vb == vb, "Got vertex buffer %p, expected %p.\n", tmp_vb, vb);
8115 ID3D11Buffer_Release(tmp_vb);
8116 ok(stride == 16, "Got vertex buffer stride %#x, expected 16.\n", stride);
8117 ok(offset == 16, "Got vertex buffer offset %#x, expected 16.\n", offset);
8119 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
8120 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
8121 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
8122 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
8123 ok(tmp_rtv == rtv, "Got rendertarget view %p, expected %p.\n", tmp_rtv, rtv);
8124 ID3D11RenderTargetView_Release(tmp_rtv);
8125 ok(tmp_dsv == dsv, "Got depth/stencil view %p, expected %p.\n", tmp_dsv, dsv);
8126 ID3D11DepthStencilView_Release(tmp_dsv);
8127 ok(tmp_uav == ps_uav, "Got unordered access view %p, expected %p.\n", tmp_uav, ps_uav);
8128 ID3D11UnorderedAccessView_Release(tmp_uav);
8129 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
8130 memset(blend_factor, 0xcd, sizeof(blend_factor));
8131 sample_mask = 0xdeadbeef;
8132 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
8133 ok(tmp_bs == bs, "Got blend state %p, expected %p.\n", tmp_bs, bs);
8134 ID3D11BlendState_Release(tmp_bs);
8135 ok(!memcmp(blend_factor, custom_blend_factor, sizeof(blend_factor)),
8136 "Got blend factor %f,%f,%f,%f, expected %f,%f,%f,%f.\n",
8137 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3],
8138 custom_blend_factor[0], custom_blend_factor[1], custom_blend_factor[2], custom_blend_factor[3]);
8139 ok(sample_mask == 0xff00ff00, "Got sample mask %#x, expected %#x.\n", sample_mask, 0xff00ff00);
8140 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
8141 stencil_ref = 0xdeadbeef;
8142 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
8143 ok(tmp_dss == dss, "Got depth/stencil state %p, expected %p.\n", tmp_dss, dss);
8144 ID3D11DepthStencilState_Release(tmp_dss);
8145 ok(stencil_ref == 3, "Got stencil ref %#x, expected 3.\n", stencil_ref);
8147 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
8148 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
8149 ok(tmp_rs == rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
8150 ID3D11RasterizerState_Release(tmp_rs);
8151 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
8152 count = 2;
8153 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
8154 ok(count == 1, "Got viewport count %u, expected 1.\n", count);
8155 ok(!memcmp(tmp_vp, &vp, sizeof(vp)), "Got viewport %s, expected %s.\n",
8156 debugstr_viewport(tmp_vp), debugstr_viewport(&vp));
8157 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
8158 count = 2;
8159 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
8160 ok(count == 1, "Got scissor rect count %u, expected 1.\n", count);
8161 ok(!memcmp(tmp_rect, &rect, sizeof(rect)), "Got scissor rect %s, expected %s.\n",
8162 wine_dbgstr_rect(tmp_rect), wine_dbgstr_rect(&rect));
8164 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
8165 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
8166 ok(tmp_sob == sob, "Got stream output buffer %p, expected %p.\n", tmp_sob, sob);
8167 ID3D11Buffer_Release(tmp_sob);
8169 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
8170 pred_value = 0xdeadbeef;
8171 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
8172 ok(tmp_pred == pred, "Got predicate %p, expected %p.\n", tmp_pred, pred);
8173 ID3D11Predicate_Release(tmp_pred);
8174 ok(pred_value == TRUE, "Got predicate value %#x, expected TRUE.\n", pred_value);
8176 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
8177 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
8179 ID3D11Predicate_Release(pred);
8180 ID3D11Buffer_Release(sob);
8181 ID3D11RasterizerState_Release(rs);
8182 ID3D11BlendState_Release(bs);
8183 ID3D11DepthStencilState_Release(dss);
8184 ID3D11DepthStencilView_Release(dsv);
8185 ID3D11RenderTargetView_Release(rtv);
8186 ID3D11UnorderedAccessView_Release(ps_uav);
8187 ID3D11InputLayout_Release(il);
8188 ID3D11Buffer_Release(ib);
8189 ID3D11Buffer_Release(vb);
8190 if (cs) ID3D11ComputeShader_Release(cs);
8191 if (ds) ID3D11DomainShader_Release(ds);
8192 if (hs) ID3D11HullShader_Release(hs);
8193 ID3D11PixelShader_Release(ps);
8194 ID3D11GeometryShader_Release(gs);
8195 ID3D11VertexShader_Release(vs2);
8196 ID3D11VertexShader_Release(vs);
8197 ID3D11Buffer_Release(cb);
8198 ID3D11ShaderResourceView_Release(srv);
8199 ID3D11UnorderedAccessView_Release(uav);
8200 ID3D11SamplerState_Release(sampler);
8201 ID3D11DeviceContext1_Release(context);
8202 refcount = ID3D11Device1_Release(device);
8203 ok(!refcount, "Device has %u references left.\n", refcount);
8206 static void test_blend(void)
8208 ID3D11BlendState *src_blend, *dst_blend, *dst_blend_factor;
8209 struct d3d11_test_context test_context;
8210 ID3D11RenderTargetView *offscreen_rtv;
8211 D3D11_TEXTURE2D_DESC texture_desc;
8212 ID3D11InputLayout *input_layout;
8213 ID3D11DeviceContext *context;
8214 D3D11_BLEND_DESC blend_desc;
8215 unsigned int stride, offset;
8216 ID3D11Texture2D *offscreen;
8217 ID3D11VertexShader *vs;
8218 ID3D11PixelShader *ps;
8219 ID3D11Device *device;
8220 ID3D11Buffer *vb;
8221 DWORD color;
8222 HRESULT hr;
8224 static const DWORD vs_code[] =
8226 #if 0
8227 struct vs_out
8229 float4 position : SV_POSITION;
8230 float4 color : COLOR;
8233 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
8235 struct vs_out o;
8237 o.position = position;
8238 o.color = color;
8240 return o;
8242 #endif
8243 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
8244 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
8245 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8246 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
8247 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
8248 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
8249 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
8250 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
8251 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
8252 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
8254 static const DWORD ps_code[] =
8256 #if 0
8257 struct vs_out
8259 float4 position : SV_POSITION;
8260 float4 color : COLOR;
8263 float4 main(struct vs_out i) : SV_TARGET
8265 return i.color;
8267 #endif
8268 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
8269 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8270 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
8271 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
8272 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8273 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
8274 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
8275 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8277 static const struct
8279 struct vec3 position;
8280 DWORD diffuse;
8282 quads[] =
8284 /* quad1 */
8285 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
8286 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
8287 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
8288 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
8289 /* quad2 */
8290 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
8291 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
8292 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
8293 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
8295 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8297 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8298 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
8300 static const float blend_factor[] = {0.3f, 0.4f, 0.8f, 0.9f};
8301 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8303 if (!init_test_context(&test_context, NULL))
8304 return;
8306 device = test_context.device;
8307 context = test_context.immediate_context;
8309 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8310 vs_code, sizeof(vs_code), &input_layout);
8311 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8313 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
8315 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
8316 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8317 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8318 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8320 memset(&blend_desc, 0, sizeof(blend_desc));
8321 blend_desc.RenderTarget[0].BlendEnable = TRUE;
8322 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
8323 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
8324 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
8325 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
8326 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
8327 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
8328 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
8330 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
8331 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8333 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
8334 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
8335 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
8336 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
8338 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
8339 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8341 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_BLEND_FACTOR;
8342 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_BLEND_FACTOR;
8343 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
8344 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
8346 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend_factor);
8347 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8349 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
8350 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8351 stride = sizeof(*quads);
8352 offset = 0;
8353 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
8354 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
8355 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8357 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8359 ID3D11DeviceContext_OMSetBlendState(context, src_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8360 ID3D11DeviceContext_Draw(context, 4, 0);
8361 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8362 ID3D11DeviceContext_Draw(context, 4, 4);
8364 color = get_texture_color(test_context.backbuffer, 320, 360);
8365 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
8366 color = get_texture_color(test_context.backbuffer, 320, 120);
8367 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
8369 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8371 ID3D11DeviceContext_OMSetBlendState(context, dst_blend_factor, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
8372 ID3D11DeviceContext_Draw(context, 4, 0);
8373 ID3D11DeviceContext_Draw(context, 4, 4);
8375 color = get_texture_color(test_context.backbuffer, 320, 360);
8376 ok(compare_color(color, 0x600066b3, 1), "Got unexpected color 0x%08x.\n", color);
8377 color = get_texture_color(test_context.backbuffer, 320, 120);
8378 ok(compare_color(color, 0xa0cc00b3, 1), "Got unexpected color 0x%08x.\n", color);
8380 texture_desc.Width = 128;
8381 texture_desc.Height = 128;
8382 texture_desc.MipLevels = 1;
8383 texture_desc.ArraySize = 1;
8384 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
8385 texture_desc.SampleDesc.Count = 1;
8386 texture_desc.SampleDesc.Quality = 0;
8387 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8388 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
8389 texture_desc.CPUAccessFlags = 0;
8390 texture_desc.MiscFlags = 0;
8392 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
8393 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
8395 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
8396 goto done;
8399 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
8400 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8402 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
8404 set_viewport(context, 0.0f, 0.0f, 128.0f, 128.0f, 0.0f, 1.0f);
8406 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
8408 ID3D11DeviceContext_OMSetBlendState(context, src_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8409 ID3D11DeviceContext_Draw(context, 4, 0);
8410 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8411 ID3D11DeviceContext_Draw(context, 4, 4);
8413 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
8414 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
8415 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
8416 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
8418 ID3D11RenderTargetView_Release(offscreen_rtv);
8419 ID3D11Texture2D_Release(offscreen);
8420 done:
8421 ID3D11BlendState_Release(dst_blend_factor);
8422 ID3D11BlendState_Release(dst_blend);
8423 ID3D11BlendState_Release(src_blend);
8424 ID3D11PixelShader_Release(ps);
8425 ID3D11VertexShader_Release(vs);
8426 ID3D11Buffer_Release(vb);
8427 ID3D11InputLayout_Release(input_layout);
8428 release_test_context(&test_context);
8431 static void test_texture1d(void)
8433 struct shader
8435 const DWORD *code;
8436 size_t size;
8438 struct texture
8440 UINT width;
8441 UINT miplevel_count;
8442 UINT array_size;
8443 DXGI_FORMAT format;
8444 D3D11_SUBRESOURCE_DATA data[3];
8447 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8448 struct d3d11_test_context test_context;
8449 const struct texture *current_texture;
8450 D3D11_TEXTURE1D_DESC texture_desc;
8451 D3D11_SAMPLER_DESC sampler_desc;
8452 const struct shader *current_ps;
8453 D3D_FEATURE_LEVEL feature_level;
8454 ID3D11ShaderResourceView *srv;
8455 ID3D11DeviceContext *context;
8456 ID3D11SamplerState *sampler;
8457 struct resource_readback rb;
8458 ID3D11Texture1D *texture;
8459 struct vec4 ps_constant;
8460 ID3D11PixelShader *ps;
8461 ID3D11Device *device;
8462 unsigned int i, x;
8463 ID3D11Buffer *cb;
8464 DWORD color;
8465 HRESULT hr;
8467 static const DWORD ps_ld_code[] =
8469 #if 0
8470 Texture1D t;
8472 float miplevel;
8474 float4 main(float4 position : SV_POSITION) : SV_TARGET
8476 float2 p;
8477 t.GetDimensions(miplevel, p.x, p.y);
8478 p.y = miplevel;
8479 p *= float2(position.x / 640.0f, 1.0f);
8480 return t.Load(int2(p));
8482 #endif
8483 0x43425844, 0x7b0c6359, 0x598178f6, 0xef2ddbdb, 0x88fc794c, 0x00000001, 0x000001ac, 0x00000003,
8484 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8485 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8486 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8487 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
8488 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001058, 0x00107000, 0x00000000,
8489 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8490 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
8491 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
8492 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000e2,
8493 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
8494 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
8495 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
8496 0x00107e46, 0x00000000, 0x0100003e,
8498 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
8499 static const DWORD ps_ld_sint8_code[] =
8501 #if 0
8502 Texture1D<int4> t;
8504 float4 main(float4 position : SV_POSITION) : SV_TARGET
8506 float2 p, s;
8507 int4 c;
8509 p = float2(position.x / 640.0f, 0.0f);
8510 t.GetDimensions(0, s.x, s.y);
8511 p *= s;
8513 c = t.Load(int2(p));
8514 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
8516 #endif
8517 0x43425844, 0x65a13d1e, 0x8a0bfc92, 0xa2f2708a, 0x0bafafb6, 0x00000001, 0x00000234, 0x00000003,
8518 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8519 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8520 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8521 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000198, 0x00000040,
8522 0x00000066, 0x04001058, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101012, 0x00000000,
8523 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8524 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
8525 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
8526 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
8527 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8528 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0500002b,
8529 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
8530 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204, 0x3c010204, 0x0a000034, 0x001000f2,
8531 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000, 0xbf800000, 0xbf800000, 0xbf800000,
8532 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
8533 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002,
8534 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
8536 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
8537 static const DWORD ps_ld_uint8_code[] =
8539 #if 0
8540 Texture1D<uint4> t;
8542 float4 main(float4 position : SV_POSITION) : SV_TARGET
8544 float2 p, s;
8546 p = float2(position.x / 640.0f, 0.0f);
8547 t.GetDimensions(0, s.x, s.y);
8548 p *= s;
8550 return t.Load(int2(p)) / (float4)255;
8552 #endif
8553 0x43425844, 0x35186c1f, 0x55bad4fd, 0xb7c97a57, 0x99c060e7, 0x00000001, 0x000001bc, 0x00000003,
8554 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8555 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8556 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8557 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000120, 0x00000040,
8558 0x00000048, 0x04001058, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101012, 0x00000000,
8559 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8560 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
8561 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
8562 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
8563 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8564 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x05000056,
8565 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46,
8566 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081, 0x3b808081, 0x0100003e,
8568 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
8569 static DWORD ps_ld_array_code[] =
8571 #if 0
8572 Texture1DArray t;
8574 float miplevel;
8576 float4 main(float4 position : SV_POSITION) : SV_TARGET
8578 float3 p;
8579 t.GetDimensions(miplevel, p.x, p.y, p.z);
8580 p.y = 1;
8581 p.z = miplevel;
8582 p *= float3(position.x / 640.0f, 1.0f, 1.0f);
8583 return t.Load(int3(p));
8585 #endif
8586 0x43425844, 0xbfccadc4, 0xc00ff13d, 0x2ba75365, 0xf747cbee, 0x00000001, 0x000001c0, 0x00000003,
8587 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8588 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8589 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8590 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000124, 0x00000040,
8591 0x00000049, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003858, 0x00107000, 0x00000000,
8592 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8593 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
8594 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
8595 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000c2,
8596 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x00100072, 0x00000000, 0x00100386,
8597 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x00000000, 0x0500001b, 0x001000d2,
8598 0x00000000, 0x00100906, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000001,
8599 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
8601 static const struct shader ps_ld_array = {ps_ld_array_code, sizeof(ps_ld_array_code)};
8603 static const DWORD rgba_level_0[] =
8605 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8607 static const DWORD rgba_level_1[] =
8609 0xffffffff, 0xff0000ff,
8611 static const DWORD rgba_level_2[] =
8613 0xffff0000,
8615 static const DWORD srgb_data[] =
8617 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
8619 static const DWORD r32_uint[] =
8621 0, 1, 2, 3,
8623 static const DWORD r9g9b9e5_data[] =
8625 0x80000100, 0x80020000, 0x84000000, 0x84000100,
8627 static const DWORD array_data0[] =
8629 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8631 static const DWORD array_data1[] =
8633 0x00ffff00, 0xff000000, 0x00ff0000, 0x000000ff,
8635 static const DWORD array_data2[] =
8637 0x000000ff, 0xffff00ff, 0x0000ff00, 0xff000000,
8639 static const struct texture rgba_texture =
8641 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
8643 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
8644 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
8645 {rgba_level_2, sizeof(*rgba_level_2), 0},
8648 static const struct texture srgb_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
8649 {{srgb_data, 4 * sizeof(*srgb_data)}}};
8650 static const struct texture sint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
8651 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
8652 static const struct texture uint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
8653 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
8654 static const struct texture r32u_typeless = {4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
8655 {{r32_uint, 4 * sizeof(*r32_uint)}}};
8656 static const struct texture r9g9b9e5_texture = {4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
8657 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
8658 static const struct texture array_texture = {4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
8660 {array_data0, 4 * sizeof(*array_data0)},
8661 {array_data1, 4 * sizeof(*array_data1)},
8662 {array_data2, 4 * sizeof(*array_data2)},
8666 static const DWORD level_1_colors[] =
8668 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
8670 static const DWORD level_2_colors[] =
8672 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
8674 static const DWORD srgb_colors[] =
8676 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
8678 static const DWORD sint8_colors[] =
8680 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
8682 static const DWORD r32u_colors[4] =
8684 0x01000000, 0x01000001, 0x01000002, 0x01000003,
8686 static const DWORD r9g9b9e5_colors[4] =
8688 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
8690 static const DWORD zero_colors[4] = {0};
8691 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8692 static const struct texture_test
8694 const struct shader *ps;
8695 const struct texture *texture;
8696 D3D11_FILTER filter;
8697 float lod_bias;
8698 float min_lod;
8699 float max_lod;
8700 float ps_constant;
8701 const DWORD *expected_colors;
8703 texture_tests[] =
8705 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
8706 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
8707 #define MIP_MAX D3D11_FLOAT32_MAX
8708 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
8709 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
8710 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
8711 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
8712 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
8713 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
8714 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
8715 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
8716 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
8717 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
8718 {&ps_ld_array, &array_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, array_data1},
8720 #undef POINT
8721 #undef POINT_LINEAR
8722 #undef MIP_MAX
8723 static const struct srv_test
8725 const struct shader *ps;
8726 const struct texture *texture;
8727 struct srv_desc srv_desc;
8728 float ps_constant;
8729 const DWORD *expected_colors;
8731 srv_tests[] =
8733 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
8734 #define R32_UINT DXGI_FORMAT_R32_UINT
8735 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_1D, 0, 1}, 0.0f, r32u_colors},
8736 #undef TEX_1D
8737 #undef R32_UINT
8738 #undef FMT_UNKNOWN
8741 if (!init_test_context(&test_context, NULL))
8742 return;
8744 device = test_context.device;
8745 context = test_context.immediate_context;
8746 feature_level = ID3D11Device_GetFeatureLevel(device);
8748 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
8750 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8752 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8753 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
8754 texture_desc.CPUAccessFlags = 0;
8755 texture_desc.MiscFlags = 0;
8757 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8758 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8759 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8760 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8761 sampler_desc.MipLODBias = 0.0f;
8762 sampler_desc.MaxAnisotropy = 0;
8763 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8764 sampler_desc.BorderColor[0] = 0.0f;
8765 sampler_desc.BorderColor[1] = 0.0f;
8766 sampler_desc.BorderColor[2] = 0.0f;
8767 sampler_desc.BorderColor[3] = 0.0f;
8768 sampler_desc.MinLOD = 0.0f;
8769 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
8771 ps = NULL;
8772 srv = NULL;
8773 sampler = NULL;
8774 texture = NULL;
8775 current_ps = NULL;
8776 current_texture = NULL;
8777 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
8779 const struct texture_test *test = &texture_tests[i];
8781 if (current_ps != test->ps)
8783 if (ps)
8784 ID3D11PixelShader_Release(ps);
8786 current_ps = test->ps;
8788 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
8789 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
8791 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8794 if (current_texture != test->texture)
8796 if (texture)
8797 ID3D11Texture1D_Release(texture);
8798 if (srv)
8799 ID3D11ShaderResourceView_Release(srv);
8801 current_texture = test->texture;
8803 if (current_texture)
8805 texture_desc.Width = current_texture->width;
8806 texture_desc.MipLevels = current_texture->miplevel_count;
8807 texture_desc.ArraySize = current_texture->array_size;
8808 texture_desc.Format = current_texture->format;
8810 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
8811 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
8813 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
8814 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
8816 else
8818 texture = NULL;
8819 srv = NULL;
8822 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8825 if (!sampler || (sampler_desc.Filter != test->filter
8826 || sampler_desc.MipLODBias != test->lod_bias
8827 || sampler_desc.MinLOD != test->min_lod
8828 || sampler_desc.MaxLOD != test->max_lod))
8830 if (sampler)
8831 ID3D11SamplerState_Release(sampler);
8833 sampler_desc.Filter = test->filter;
8834 sampler_desc.MipLODBias = test->lod_bias;
8835 sampler_desc.MinLOD = test->min_lod;
8836 sampler_desc.MaxLOD = test->max_lod;
8838 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
8839 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
8841 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8844 ps_constant.x = test->ps_constant;
8845 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
8847 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8849 draw_quad(&test_context);
8851 get_texture_readback(test_context.backbuffer, 0, &rb);
8852 for (x = 0; x < 4; ++x)
8854 color = get_readback_color(&rb, 80 + x * 160, 0, 0);
8855 ok(compare_color(color, test->expected_colors[x], 2),
8856 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
8858 release_resource_readback(&rb);
8860 if (srv)
8861 ID3D11ShaderResourceView_Release(srv);
8862 ID3D11SamplerState_Release(sampler);
8863 if (texture)
8864 ID3D11Texture1D_Release(texture);
8865 ID3D11PixelShader_Release(ps);
8867 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
8869 win_skip("SRV tests are broken on WARP.\n");
8870 ID3D11Buffer_Release(cb);
8871 release_test_context(&test_context);
8872 return;
8875 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8876 sampler_desc.MipLODBias = 0.0f;
8877 sampler_desc.MinLOD = 0.0f;
8878 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
8880 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
8881 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8883 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8885 ps = NULL;
8886 srv = NULL;
8887 texture = NULL;
8888 current_ps = NULL;
8889 current_texture = NULL;
8890 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
8892 const struct srv_test *test = &srv_tests[i];
8894 if (current_ps != test->ps)
8896 if (ps)
8897 ID3D11PixelShader_Release(ps);
8899 current_ps = test->ps;
8901 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
8902 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
8904 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8907 if (current_texture != test->texture)
8909 if (texture)
8910 ID3D11Texture1D_Release(texture);
8912 current_texture = test->texture;
8914 texture_desc.Width = current_texture->width;
8915 texture_desc.MipLevels = current_texture->miplevel_count;
8916 texture_desc.ArraySize = current_texture->array_size;
8917 texture_desc.Format = current_texture->format;
8919 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
8920 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
8923 if (srv)
8924 ID3D11ShaderResourceView_Release(srv);
8926 get_srv_desc(&srv_desc, &test->srv_desc);
8927 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
8928 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
8930 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8932 ps_constant.x = test->ps_constant;
8933 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
8935 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8937 draw_quad(&test_context);
8939 get_texture_readback(test_context.backbuffer, 0, &rb);
8940 for (x = 0; x < 4; ++x)
8942 color = get_readback_color(&rb, 80 + x * 160, 0, 0);
8943 ok(compare_color(color, test->expected_colors[x], 1),
8944 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
8946 release_resource_readback(&rb);
8948 ID3D11PixelShader_Release(ps);
8949 ID3D11Texture1D_Release(texture);
8950 ID3D11ShaderResourceView_Release(srv);
8951 ID3D11SamplerState_Release(sampler);
8953 ID3D11Buffer_Release(cb);
8954 release_test_context(&test_context);
8957 static void test_texture(void)
8959 struct shader
8961 const DWORD *code;
8962 size_t size;
8964 struct texture
8966 UINT width;
8967 UINT height;
8968 UINT miplevel_count;
8969 UINT array_size;
8970 DXGI_FORMAT format;
8971 D3D11_SUBRESOURCE_DATA data[3];
8974 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8975 struct d3d11_test_context test_context;
8976 const struct texture *current_texture;
8977 D3D11_TEXTURE2D_DESC texture_desc;
8978 D3D11_SAMPLER_DESC sampler_desc;
8979 const struct shader *current_ps;
8980 D3D_FEATURE_LEVEL feature_level;
8981 ID3D11ShaderResourceView *srv;
8982 ID3D11DeviceContext *context;
8983 ID3D11SamplerState *sampler;
8984 struct resource_readback rb;
8985 ID3D11Texture2D *texture;
8986 struct vec4 ps_constant;
8987 ID3D11PixelShader *ps;
8988 ID3D11Device *device;
8989 unsigned int i, x, y;
8990 ID3D11Buffer *cb;
8991 DWORD color;
8992 HRESULT hr;
8994 static const DWORD ps_ld_code[] =
8996 #if 0
8997 Texture2D t;
8999 float miplevel;
9001 float4 main(float4 position : SV_POSITION) : SV_TARGET
9003 float3 p;
9004 t.GetDimensions(miplevel, p.x, p.y, p.z);
9005 p.z = miplevel;
9006 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
9007 return t.Load(int3(p));
9009 #endif
9010 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
9011 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9012 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9013 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9014 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
9015 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
9016 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
9017 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
9018 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
9019 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
9020 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
9021 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
9022 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
9023 0x00107e46, 0x00000000, 0x0100003e,
9025 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
9026 static const DWORD ps_ld_sint8_code[] =
9028 #if 0
9029 Texture2D<int4> t;
9031 float4 main(float4 position : SV_POSITION) : SV_TARGET
9033 float3 p, s;
9034 int4 c;
9036 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
9037 t.GetDimensions(0, s.x, s.y, s.z);
9038 p *= s;
9040 c = t.Load(int3(p));
9041 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
9043 #endif
9044 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
9045 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9046 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9047 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9048 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
9049 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
9050 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
9051 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
9052 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
9053 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
9054 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
9055 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
9056 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
9057 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
9058 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
9059 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
9060 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
9061 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
9063 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
9064 static const DWORD ps_ld_uint8_code[] =
9066 #if 0
9067 Texture2D<uint4> t;
9069 float4 main(float4 position : SV_POSITION) : SV_TARGET
9071 float3 p, s;
9073 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
9074 t.GetDimensions(0, s.x, s.y, s.z);
9075 p *= s;
9077 return t.Load(int3(p)) / (float4)255;
9079 #endif
9080 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
9081 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9082 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9083 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9084 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
9085 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
9086 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
9087 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
9088 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
9089 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
9090 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
9091 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
9092 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
9093 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
9094 0x3b808081, 0x0100003e,
9096 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
9097 static const DWORD ps_sample_code[] =
9099 #if 0
9100 Texture2D t;
9101 SamplerState s;
9103 float4 main(float4 position : SV_POSITION) : SV_Target
9105 float2 p;
9107 p.x = position.x / 640.0f;
9108 p.y = position.y / 480.0f;
9109 return t.Sample(s, p);
9111 #endif
9112 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9113 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9114 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9115 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9116 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9117 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9118 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9119 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9120 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9121 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9123 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
9124 static const DWORD ps_sample_b_code[] =
9126 #if 0
9127 Texture2D t;
9128 SamplerState s;
9130 float bias;
9132 float4 main(float4 position : SV_POSITION) : SV_Target
9134 float2 p;
9136 p.x = position.x / 640.0f;
9137 p.y = position.y / 480.0f;
9138 return t.SampleBias(s, p, bias);
9140 #endif
9141 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
9142 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9143 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9144 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9145 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
9146 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9147 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9148 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
9149 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
9150 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
9151 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
9153 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
9154 static const DWORD ps_sample_l_code[] =
9156 #if 0
9157 Texture2D t;
9158 SamplerState s;
9160 float level;
9162 float4 main(float4 position : SV_POSITION) : SV_Target
9164 float2 p;
9166 p.x = position.x / 640.0f;
9167 p.y = position.y / 480.0f;
9168 return t.SampleLevel(s, p, level);
9170 #endif
9171 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
9172 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9173 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9174 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9175 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
9176 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9177 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9178 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
9179 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
9180 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
9181 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
9183 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
9184 static const DWORD ps_sample_2d_array_code[] =
9186 #if 0
9187 Texture2DArray t;
9188 SamplerState s;
9190 float layer;
9192 float4 main(float4 position : SV_POSITION) : SV_TARGET
9194 float3 d;
9195 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
9196 t.GetDimensions(d.x, d.y, d.z);
9197 d.z = layer;
9198 return t.Sample(s, p * d);
9200 #endif
9201 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
9202 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9203 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9204 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9205 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
9206 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9207 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9208 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
9209 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
9210 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
9211 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
9212 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
9213 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9215 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
9216 static const DWORD red_data[] =
9218 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9219 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9220 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9221 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9223 static const DWORD green_data[] =
9225 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9226 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9227 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9228 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9230 static const DWORD blue_data[] =
9232 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9233 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9234 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9235 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9237 static const DWORD rgba_level_0[] =
9239 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9240 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9241 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9242 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9244 static const DWORD rgba_level_1[] =
9246 0xffffffff, 0xff0000ff,
9247 0xff000000, 0xff00ff00,
9249 static const DWORD rgba_level_2[] =
9251 0xffff0000,
9253 static const DWORD srgb_data[] =
9255 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
9256 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
9257 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
9258 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
9260 static const WORD r8g8_data[] =
9262 0x0000, 0xffff, 0x0000, 0x7fff,
9263 0x0203, 0xff10, 0x0b0c, 0x8000,
9264 0xc4de, 0xfff0, 0xfdfe, 0x5a6f,
9265 0xff00, 0xffc8, 0x00aa, 0xdd5b,
9267 static const BYTE a8_data[] =
9269 0x00, 0x10, 0x20, 0x30,
9270 0x40, 0x50, 0x60, 0x70,
9271 0x80, 0x90, 0xa0, 0xb0,
9272 0xc0, 0xd0, 0xe0, 0xf0,
9274 static const BYTE bc1_data[] =
9276 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
9277 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
9278 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
9279 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
9281 static const BYTE bc2_data[] =
9283 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
9284 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
9285 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
9286 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
9288 static const BYTE bc3_data[] =
9290 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
9291 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
9292 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
9293 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
9295 static const BYTE bc4_data[] =
9297 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
9298 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
9299 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
9300 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
9302 static const BYTE bc5_data[] =
9304 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
9305 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
9306 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
9307 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
9309 static const BYTE bc6h_u_data[] =
9311 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9312 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9313 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9314 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9316 static const BYTE bc6h_s_data[] =
9318 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9319 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9320 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9321 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9323 static const BYTE bc7_data[] =
9325 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9326 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9327 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9328 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
9330 static const float r32_float[] =
9332 0.0f, 1.0f, 0.5f, 0.50f,
9333 1.0f, 0.0f, 0.0f, 0.75f,
9334 0.0f, 1.0f, 0.5f, 0.25f,
9335 1.0f, 0.0f, 0.0f, 0.75f,
9337 static const DWORD r32_uint[] =
9339 0, 1, 2, 3,
9340 100, 200, 255, 128,
9341 40, 30, 20, 10,
9342 250, 210, 155, 190,
9344 static const DWORD r9g9b9e5_data[] =
9346 0x80000100, 0x80020000, 0x84000000, 0x84000100,
9347 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
9348 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
9349 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
9351 static const struct texture rgba_texture =
9353 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
9355 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
9356 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
9357 {rgba_level_2, sizeof(*rgba_level_2), 0},
9360 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
9361 {{srgb_data, 4 * sizeof(*srgb_data)}}};
9362 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
9363 {{srgb_data, 4 * sizeof(*srgb_data)}}};
9364 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
9365 {{a8_data, 4 * sizeof(*a8_data)}}};
9366 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
9367 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
9368 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
9369 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
9370 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
9371 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
9372 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
9373 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
9374 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
9375 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
9376 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
9377 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
9378 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
9379 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
9380 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
9381 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
9382 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
9383 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
9384 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
9385 static const struct texture array_2d_texture =
9387 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
9389 {red_data, 6 * sizeof(*red_data)},
9390 {green_data, 4 * sizeof(*green_data)},
9391 {blue_data, 5 * sizeof(*blue_data)},
9394 static const struct texture r32f_float = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
9395 {{r32_float, 4 * sizeof(*r32_float)}}};
9396 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
9397 {{r32_float, 4 * sizeof(*r32_float)}}};
9398 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
9399 {{r32_uint, 4 * sizeof(*r32_uint)}}};
9400 static const struct texture r8g8_snorm = {4, 4, 1, 1, DXGI_FORMAT_R8G8_SNORM,
9401 {{r8g8_data, 4 * sizeof(*r8g8_data)}}};
9402 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
9403 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
9404 static const DWORD red_colors[] =
9406 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9407 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9408 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9409 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9411 static const DWORD blue_colors[] =
9413 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9414 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9415 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9416 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9418 static const DWORD level_1_colors[] =
9420 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
9421 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
9422 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
9423 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
9425 static const DWORD lerp_1_2_colors[] =
9427 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
9428 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
9429 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
9430 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
9432 static const DWORD level_2_colors[] =
9434 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9435 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9436 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9437 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9439 static const DWORD srgb_colors[] =
9441 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
9442 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
9443 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
9444 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
9446 static const DWORD a8_colors[] =
9448 0x00000000, 0x10000000, 0x20000000, 0x30000000,
9449 0x40000000, 0x50000000, 0x60000000, 0x70000000,
9450 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
9451 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
9453 static const DWORD bc_colors[] =
9455 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
9456 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
9457 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
9458 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
9460 static const DWORD bc4_colors[] =
9462 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
9463 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
9464 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
9465 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
9467 static const DWORD bc5_colors[] =
9469 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
9470 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
9471 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
9472 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
9474 static const DWORD bc7_colors[] =
9476 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
9477 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
9478 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
9479 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
9481 static const DWORD sint8_colors[] =
9483 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
9484 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
9485 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
9486 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
9488 static const DWORD snorm_colors[] =
9490 0xff000000, 0xff000000, 0xff000000, 0xff00ff00,
9491 0xff000406, 0xff000020, 0xff001618, 0xff000000,
9492 0xff000000, 0xff000000, 0xff000000, 0xff00b5df,
9493 0xff000000, 0xff000000, 0xff000000, 0xff0000b7,
9495 static const DWORD r32f_colors[] =
9497 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
9498 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
9499 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
9500 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
9502 static const DWORD r32u_colors[16] =
9504 0x01000000, 0x01000001, 0x01000002, 0x01000003,
9505 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
9506 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
9507 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
9509 static const DWORD r9g9b9e5_colors[16] =
9511 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
9512 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
9513 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
9514 0xff000033, 0xff003300, 0xff330000, 0xff333333,
9516 static const DWORD zero_colors[4 * 4] = {0};
9517 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9519 static const struct texture_test
9521 const struct shader *ps;
9522 const struct texture *texture;
9523 D3D11_FILTER filter;
9524 float lod_bias;
9525 float min_lod;
9526 float max_lod;
9527 float ps_constant;
9528 const DWORD *expected_colors;
9530 texture_tests[] =
9532 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
9533 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
9534 #define MIP_MAX D3D11_FLOAT32_MAX
9535 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
9536 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
9537 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
9538 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
9539 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
9540 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9541 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9542 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9543 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9544 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9545 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9546 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9547 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9548 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9549 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
9550 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
9551 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9552 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9553 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9554 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9555 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
9556 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9557 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9558 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
9559 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
9560 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9561 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9562 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9563 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
9564 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
9565 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9566 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9567 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9568 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9569 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
9570 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9571 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9572 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
9573 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
9574 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
9575 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
9576 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9577 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9578 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9579 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
9580 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
9581 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
9582 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
9583 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
9584 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
9585 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
9586 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
9587 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
9588 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9589 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9590 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9591 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
9592 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
9593 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9594 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
9595 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
9596 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
9597 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
9598 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
9599 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
9600 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
9601 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
9602 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
9603 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
9604 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
9605 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
9606 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
9607 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
9608 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
9609 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
9610 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
9611 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
9612 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
9613 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
9614 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
9615 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
9616 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
9617 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
9618 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
9619 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
9620 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
9621 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
9622 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
9623 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
9624 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
9625 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
9626 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
9627 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
9628 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
9629 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
9630 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
9631 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
9632 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
9633 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
9634 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9635 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9636 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
9637 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9638 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
9639 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
9640 #undef POINT
9641 #undef POINT_LINEAR
9642 #undef MIP_MAX
9644 static const struct srv_test
9646 const struct shader *ps;
9647 const struct texture *texture;
9648 struct srv_desc srv_desc;
9649 float ps_constant;
9650 const DWORD *expected_colors;
9652 srv_tests[] =
9654 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
9655 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
9656 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
9657 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
9658 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
9659 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
9660 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
9661 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
9662 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
9663 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
9664 #define R8G8_SNORM DXGI_FORMAT_R8G8_SNORM
9665 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
9666 #define R32_UINT DXGI_FORMAT_R32_UINT
9667 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
9668 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
9669 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
9670 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
9671 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
9672 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
9673 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
9674 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
9675 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
9676 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
9677 {&ps_sample, &r32f_float, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
9678 {&ps_sample, &r8g8_snorm, {R8G8_SNORM, TEX_2D, 0, 1}, 0.0f, snorm_colors},
9679 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
9680 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
9681 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
9682 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
9683 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
9684 #undef TEX_2D
9685 #undef TEX_2D_ARRAY
9686 #undef BC1_UNORM
9687 #undef BC1_UNORM_SRGB
9688 #undef BC2_UNORM
9689 #undef BC2_UNORM_SRGB
9690 #undef BC3_UNORM
9691 #undef BC3_UNORM_SRGB
9692 #undef R8G8B8A8_UNORM_SRGB
9693 #undef R8G8B8A8_UNORM
9694 #undef R8G8_SNORM
9695 #undef R32_FLOAT
9696 #undef R32_UINT
9697 #undef FMT_UNKNOWN
9700 if (!init_test_context(&test_context, NULL))
9701 return;
9703 device = test_context.device;
9704 context = test_context.immediate_context;
9705 feature_level = ID3D11Device_GetFeatureLevel(device);
9707 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
9709 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9711 texture_desc.SampleDesc.Count = 1;
9712 texture_desc.SampleDesc.Quality = 0;
9713 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9714 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
9715 texture_desc.CPUAccessFlags = 0;
9716 texture_desc.MiscFlags = 0;
9718 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9719 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
9720 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
9721 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
9722 sampler_desc.MipLODBias = 0.0f;
9723 sampler_desc.MaxAnisotropy = 0;
9724 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
9725 sampler_desc.BorderColor[0] = 0.0f;
9726 sampler_desc.BorderColor[1] = 0.0f;
9727 sampler_desc.BorderColor[2] = 0.0f;
9728 sampler_desc.BorderColor[3] = 0.0f;
9729 sampler_desc.MinLOD = 0.0f;
9730 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
9732 ps = NULL;
9733 srv = NULL;
9734 sampler = NULL;
9735 texture = NULL;
9736 current_ps = NULL;
9737 current_texture = NULL;
9738 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
9740 const struct texture_test *test = &texture_tests[i];
9742 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
9743 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
9744 && feature_level < D3D_FEATURE_LEVEL_11_0)
9746 skip("Feature level >= 11.0 is required for BC7 tests.\n");
9747 continue;
9750 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
9751 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
9752 && feature_level < D3D_FEATURE_LEVEL_11_0)
9754 skip("Feature level >= 11.0 is required for BC6H tests.\n");
9755 continue;
9758 if (current_ps != test->ps)
9760 if (ps)
9761 ID3D11PixelShader_Release(ps);
9763 current_ps = test->ps;
9765 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
9766 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
9768 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9771 if (current_texture != test->texture)
9773 if (texture)
9774 ID3D11Texture2D_Release(texture);
9775 if (srv)
9776 ID3D11ShaderResourceView_Release(srv);
9778 current_texture = test->texture;
9780 if (current_texture)
9782 texture_desc.Width = current_texture->width;
9783 texture_desc.Height = current_texture->height;
9784 texture_desc.MipLevels = current_texture->miplevel_count;
9785 texture_desc.ArraySize = current_texture->array_size;
9786 texture_desc.Format = current_texture->format;
9788 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
9789 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9791 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
9792 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
9794 else
9796 texture = NULL;
9797 srv = NULL;
9800 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
9803 if (!sampler || (sampler_desc.Filter != test->filter
9804 || sampler_desc.MipLODBias != test->lod_bias
9805 || sampler_desc.MinLOD != test->min_lod
9806 || sampler_desc.MaxLOD != test->max_lod))
9808 if (sampler)
9809 ID3D11SamplerState_Release(sampler);
9811 sampler_desc.Filter = test->filter;
9812 sampler_desc.MipLODBias = test->lod_bias;
9813 sampler_desc.MinLOD = test->min_lod;
9814 sampler_desc.MaxLOD = test->max_lod;
9816 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
9817 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
9819 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9822 ps_constant.x = test->ps_constant;
9823 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
9825 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9827 draw_quad(&test_context);
9829 get_texture_readback(test_context.backbuffer, 0, &rb);
9830 for (y = 0; y < 4; ++y)
9832 for (x = 0; x < 4; ++x)
9834 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
9835 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
9836 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
9839 release_resource_readback(&rb);
9841 if (srv)
9842 ID3D11ShaderResourceView_Release(srv);
9843 ID3D11SamplerState_Release(sampler);
9844 if (texture)
9845 ID3D11Texture2D_Release(texture);
9846 ID3D11PixelShader_Release(ps);
9848 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
9850 win_skip("SRV tests are broken on WARP.\n");
9851 ID3D11Buffer_Release(cb);
9852 release_test_context(&test_context);
9853 return;
9856 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9857 sampler_desc.MipLODBias = 0.0f;
9858 sampler_desc.MinLOD = 0.0f;
9859 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
9861 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
9862 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9864 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9866 ps = NULL;
9867 srv = NULL;
9868 texture = NULL;
9869 current_ps = NULL;
9870 current_texture = NULL;
9871 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
9873 const struct srv_test *test = &srv_tests[i];
9875 if (current_ps != test->ps)
9877 if (ps)
9878 ID3D11PixelShader_Release(ps);
9880 current_ps = test->ps;
9882 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
9883 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
9885 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9888 if (current_texture != test->texture)
9890 if (texture)
9891 ID3D11Texture2D_Release(texture);
9893 current_texture = test->texture;
9895 texture_desc.Width = current_texture->width;
9896 texture_desc.Height = current_texture->height;
9897 texture_desc.MipLevels = current_texture->miplevel_count;
9898 texture_desc.ArraySize = current_texture->array_size;
9899 texture_desc.Format = current_texture->format;
9901 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
9902 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9905 if (srv)
9906 ID3D11ShaderResourceView_Release(srv);
9908 get_srv_desc(&srv_desc, &test->srv_desc);
9909 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
9910 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
9912 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
9914 ps_constant.x = test->ps_constant;
9915 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
9917 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9919 draw_quad(&test_context);
9921 get_texture_readback(test_context.backbuffer, 0, &rb);
9922 for (y = 0; y < 4; ++y)
9924 for (x = 0; x < 4; ++x)
9926 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
9927 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
9928 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
9931 release_resource_readback(&rb);
9933 ID3D11PixelShader_Release(ps);
9934 ID3D11Texture2D_Release(texture);
9935 ID3D11ShaderResourceView_Release(srv);
9936 ID3D11SamplerState_Release(sampler);
9938 ID3D11Buffer_Release(cb);
9939 release_test_context(&test_context);
9942 static void test_cube_maps(void)
9944 struct shader
9946 const DWORD *code;
9947 size_t size;
9950 unsigned int i, j, sub_resource_idx, sub_resource_count;
9951 struct d3d11_test_context test_context;
9952 D3D11_TEXTURE2D_DESC texture_desc;
9953 const struct shader *current_ps;
9954 D3D_FEATURE_LEVEL feature_level;
9955 ID3D11ShaderResourceView *srv;
9956 ID3D11DeviceContext *context;
9957 ID3D11Texture2D *rtv_texture;
9958 ID3D11RenderTargetView *rtv;
9959 struct vec4 expected_result;
9960 ID3D11Resource *texture;
9961 ID3D11PixelShader *ps;
9962 ID3D11Device *device;
9963 float data[64 * 64];
9964 ID3D11Buffer *cb;
9965 HRESULT hr;
9966 RECT rect;
9967 struct
9969 unsigned int face;
9970 unsigned int level;
9971 unsigned int cube;
9972 unsigned int padding;
9973 } constant;
9975 static const DWORD ps_cube_code[] =
9977 #if 0
9978 TextureCube t;
9979 SamplerState s;
9981 uint face;
9982 uint level;
9984 float4 main(float4 position : SV_POSITION) : SV_Target
9986 float2 p;
9987 p.x = position.x / 640.0f;
9988 p.y = position.y / 480.0f;
9990 float3 coord;
9991 switch (face)
9993 case 0:
9994 coord = float3(1.0f, p.x, p.y);
9995 break;
9996 case 1:
9997 coord = float3(-1.0f, p.x, p.y);
9998 break;
9999 case 2:
10000 coord = float3(p.x, 1.0f, p.y);
10001 break;
10002 case 3:
10003 coord = float3(p.x, -1.0f, p.y);
10004 break;
10005 case 4:
10006 coord = float3(p.x, p.y, 1.0f);
10007 break;
10008 case 5:
10009 default:
10010 coord = float3(p.x, p.y, -1.0f);
10011 break;
10013 return t.SampleLevel(s, coord, level);
10015 #endif
10016 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
10017 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10018 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10019 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10020 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
10021 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
10022 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
10023 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
10024 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
10025 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
10026 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
10027 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
10028 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
10029 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
10030 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
10031 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
10032 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
10033 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
10034 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
10035 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
10036 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10037 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
10038 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
10039 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
10040 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
10042 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
10043 static const DWORD ps_cube_array_code[] =
10045 #if 0
10046 TextureCubeArray t;
10047 SamplerState s;
10049 uint face;
10050 uint level;
10051 uint cube;
10053 float4 main(float4 position : SV_POSITION) : SV_Target
10055 float2 p;
10056 p.x = position.x / 640.0f;
10057 p.y = position.y / 480.0f;
10059 float3 coord;
10060 switch (face)
10062 case 0:
10063 coord = float3(1.0f, p.x, p.y);
10064 break;
10065 case 1:
10066 coord = float3(-1.0f, p.x, p.y);
10067 break;
10068 case 2:
10069 coord = float3(p.x, 1.0f, p.y);
10070 break;
10071 case 3:
10072 coord = float3(p.x, -1.0f, p.y);
10073 break;
10074 case 4:
10075 coord = float3(p.x, p.y, 1.0f);
10076 break;
10077 case 5:
10078 default:
10079 coord = float3(p.x, p.y, -1.0f);
10080 break;
10082 return t.SampleLevel(s, float4(coord, cube), level);
10084 #endif
10085 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
10086 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10087 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10088 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10089 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
10090 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
10091 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
10092 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
10093 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
10094 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
10095 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
10096 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
10097 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
10098 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
10099 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
10100 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
10101 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
10102 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
10103 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10104 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
10105 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
10106 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
10107 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
10108 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
10109 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
10110 0x00000001, 0x0100003e,
10112 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
10113 static const struct ps_test
10115 const struct shader *ps;
10116 unsigned int miplevel_count;
10117 unsigned int array_size;
10119 ps_tests[] =
10121 {&ps_cube, 1, 6},
10122 {&ps_cube, 2, 6},
10123 {&ps_cube, 3, 6},
10124 {&ps_cube, 0, 6},
10126 {&ps_cube_array, 1, 12},
10127 {&ps_cube_array, 2, 12},
10128 {&ps_cube_array, 3, 12},
10129 {&ps_cube_array, 0, 12},
10132 if (!init_test_context(&test_context, NULL))
10133 return;
10135 device = test_context.device;
10136 context = test_context.immediate_context;
10137 feature_level = ID3D11Device_GetFeatureLevel(device);
10139 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10140 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10141 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
10142 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10143 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
10144 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10146 memset(&constant, 0, sizeof(constant));
10147 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
10149 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10150 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10152 ps = NULL;
10153 current_ps = NULL;
10154 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
10156 const struct ps_test *test = &ps_tests[i];
10158 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
10160 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
10161 continue;
10164 if (current_ps != test->ps)
10166 if (ps)
10167 ID3D11PixelShader_Release(ps);
10169 current_ps = test->ps;
10171 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
10172 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
10173 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10176 if (!test->miplevel_count)
10178 srv = NULL;
10179 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10181 memset(&expected_result, 0, sizeof(expected_result));
10183 memset(&constant, 0, sizeof(constant));
10184 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10185 draw_quad(&test_context);
10186 check_texture_vec4(rtv_texture, &expected_result, 0);
10187 constant.level = 1;
10188 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10189 draw_quad(&test_context);
10190 check_texture_vec4(rtv_texture, &expected_result, 0);
10191 continue;
10194 texture_desc.Width = 64;
10195 texture_desc.Height = 64;
10196 texture_desc.MipLevels = test->miplevel_count;
10197 texture_desc.ArraySize = test->array_size;
10198 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
10199 texture_desc.SampleDesc.Count = 1;
10200 texture_desc.SampleDesc.Quality = 0;
10201 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10202 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
10203 texture_desc.CPUAccessFlags = 0;
10204 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
10205 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
10206 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
10208 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
10209 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
10210 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10212 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
10213 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
10215 for (j = 0; j < ARRAY_SIZE(data); ++j)
10216 data[j] = sub_resource_idx;
10217 ID3D11DeviceContext_UpdateSubresource(context, texture, sub_resource_idx, NULL, data,
10218 texture_desc.Width * sizeof(*data), 0);
10221 expected_result.y = expected_result.z = 0.0f;
10222 expected_result.w = 1.0f;
10223 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
10225 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
10226 constant.level = sub_resource_idx % texture_desc.MipLevels;
10227 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
10228 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10230 draw_quad(&test_context);
10231 expected_result.x = sub_resource_idx;
10232 /* Avoid testing values affected by seamless cube map filtering. */
10233 SetRect(&rect, 100, 100, 540, 380);
10234 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
10237 ID3D11Resource_Release(texture);
10238 ID3D11ShaderResourceView_Release(srv);
10240 ID3D11PixelShader_Release(ps);
10242 ID3D11Buffer_Release(cb);
10243 ID3D11RenderTargetView_Release(rtv);
10244 ID3D11Texture2D_Release(rtv_texture);
10245 release_test_context(&test_context);
10248 static void test_depth_stencil_sampling(void)
10250 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
10251 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
10252 ID3D11SamplerState *cmp_sampler, *sampler;
10253 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10254 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
10255 struct d3d11_test_context test_context;
10256 ID3D11Texture2D *texture, *rt_texture;
10257 D3D11_TEXTURE2D_DESC texture_desc;
10258 D3D11_SAMPLER_DESC sampler_desc;
10259 ID3D11DeviceContext *context;
10260 ID3D11DepthStencilView *dsv;
10261 ID3D11RenderTargetView *rtv;
10262 struct vec4 ps_constant;
10263 ID3D11Device *device;
10264 ID3D11Buffer *cb;
10265 unsigned int i;
10266 HRESULT hr;
10268 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
10269 static const DWORD ps_compare_code[] =
10271 #if 0
10272 Texture2D t;
10273 SamplerComparisonState s;
10275 float ref;
10277 float4 main(float4 position : SV_Position) : SV_Target
10279 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
10281 #endif
10282 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
10283 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10284 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10285 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10286 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
10287 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
10288 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
10289 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
10290 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
10291 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
10292 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
10293 0x0100003e,
10295 static const DWORD ps_sample_code[] =
10297 #if 0
10298 Texture2D t;
10299 SamplerState s;
10301 float4 main(float4 position : SV_Position) : SV_Target
10303 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
10305 #endif
10306 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
10307 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10308 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10309 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10310 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
10311 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10312 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10313 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10314 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
10315 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
10317 static const DWORD ps_stencil_code[] =
10319 #if 0
10320 Texture2D<uint4> t;
10322 float4 main(float4 position : SV_Position) : SV_Target
10324 float2 s;
10325 t.GetDimensions(s.x, s.y);
10326 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
10328 #endif
10329 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
10330 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10331 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10332 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10333 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
10334 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
10335 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
10336 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
10337 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
10338 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
10339 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
10340 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
10341 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
10343 static const DWORD ps_depth_stencil_code[] =
10345 #if 0
10346 SamplerState samp;
10347 Texture2D depth_tex;
10348 Texture2D<uint4> stencil_tex;
10350 float main(float4 position: SV_Position) : SV_Target
10352 float2 s, p;
10353 float depth, stencil;
10354 depth_tex.GetDimensions(s.x, s.y);
10355 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
10356 depth = depth_tex.Sample(samp, p).r;
10357 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
10358 return depth + stencil;
10360 #endif
10361 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
10362 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10363 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10364 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10365 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
10366 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10367 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
10368 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
10369 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
10370 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
10371 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
10372 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
10373 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
10374 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
10375 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
10376 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
10378 static const struct test
10380 DXGI_FORMAT typeless_format;
10381 DXGI_FORMAT dsv_format;
10382 DXGI_FORMAT depth_view_format;
10383 DXGI_FORMAT stencil_view_format;
10385 tests[] =
10387 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
10388 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
10389 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
10390 DXGI_FORMAT_R32_FLOAT},
10391 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
10392 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
10393 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
10394 DXGI_FORMAT_R16_UNORM},
10397 if (!init_test_context(&test_context, NULL))
10398 return;
10400 device = test_context.device;
10401 context = test_context.immediate_context;
10403 if (is_amd_device(device))
10405 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
10406 win_skip("Some AMD drivers have a bug affecting the test.\n");
10407 release_test_context(&test_context);
10408 return;
10411 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
10412 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10413 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10414 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10415 sampler_desc.MipLODBias = 0.0f;
10416 sampler_desc.MaxAnisotropy = 0;
10417 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
10418 sampler_desc.BorderColor[0] = 0.0f;
10419 sampler_desc.BorderColor[1] = 0.0f;
10420 sampler_desc.BorderColor[2] = 0.0f;
10421 sampler_desc.BorderColor[3] = 0.0f;
10422 sampler_desc.MinLOD = 0.0f;
10423 sampler_desc.MaxLOD = 0.0f;
10424 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
10425 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10427 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
10428 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
10429 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
10430 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10432 texture_desc.Width = 640;
10433 texture_desc.Height = 480;
10434 texture_desc.MipLevels = 1;
10435 texture_desc.ArraySize = 1;
10436 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
10437 texture_desc.SampleDesc.Count = 1;
10438 texture_desc.SampleDesc.Quality = 0;
10439 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10440 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10441 texture_desc.CPUAccessFlags = 0;
10442 texture_desc.MiscFlags = 0;
10443 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
10444 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10445 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
10446 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
10447 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10449 memset(&ps_constant, 0, sizeof(ps_constant));
10450 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
10451 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10453 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
10454 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10455 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
10456 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10457 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
10458 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10459 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
10460 &ps_depth_stencil);
10461 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10463 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10465 texture_desc.Format = tests[i].typeless_format;
10466 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
10467 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10468 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
10469 texture_desc.Format, hr);
10471 dsv_desc.Format = tests[i].dsv_format;
10472 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
10473 dsv_desc.Flags = 0;
10474 U(dsv_desc).Texture2D.MipSlice = 0;
10475 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10476 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
10477 dsv_desc.Format, hr);
10479 srv_desc.Format = tests[i].depth_view_format;
10480 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
10481 U(srv_desc).Texture2D.MostDetailedMip = 0;
10482 U(srv_desc).Texture2D.MipLevels = 1;
10483 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
10484 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
10485 srv_desc.Format, hr);
10487 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
10488 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
10489 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
10491 ps_constant.x = 0.5f;
10492 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10493 NULL, &ps_constant, 0, 0);
10495 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10496 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10497 draw_quad(&test_context);
10498 check_texture_float(rt_texture, 0.0f, 2);
10500 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
10501 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10502 draw_quad(&test_context);
10503 check_texture_float(rt_texture, 1.0f, 2);
10505 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
10506 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10507 draw_quad(&test_context);
10508 check_texture_float(rt_texture, 0.0f, 2);
10510 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
10511 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10512 draw_quad(&test_context);
10513 check_texture_float(rt_texture, 0.0f, 2);
10515 ps_constant.x = 0.7f;
10516 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10517 NULL, &ps_constant, 0, 0);
10519 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10520 draw_quad(&test_context);
10521 check_texture_float(rt_texture, 1.0f, 2);
10523 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
10524 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10526 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10527 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10528 draw_quad(&test_context);
10529 check_texture_float(rt_texture, 1.0f, 2);
10531 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
10532 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10533 draw_quad(&test_context);
10534 check_texture_float(rt_texture, 0.2f, 2);
10536 if (!tests[i].stencil_view_format)
10538 ID3D11DepthStencilView_Release(dsv);
10539 ID3D11ShaderResourceView_Release(depth_srv);
10540 ID3D11Texture2D_Release(texture);
10541 continue;
10544 srv_desc.Format = tests[i].stencil_view_format;
10545 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
10546 if (hr == E_OUTOFMEMORY)
10548 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
10549 ID3D11DepthStencilView_Release(dsv);
10550 ID3D11ShaderResourceView_Release(depth_srv);
10551 ID3D11Texture2D_Release(texture);
10552 continue;
10554 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
10555 srv_desc.Format, hr);
10557 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
10558 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
10560 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
10561 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10562 draw_quad(&test_context);
10563 check_texture_float(rt_texture, 0.0f, 0);
10565 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
10566 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10567 draw_quad(&test_context);
10568 check_texture_float(rt_texture, 100.0f, 0);
10570 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
10571 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10572 draw_quad(&test_context);
10573 check_texture_float(rt_texture, 255.0f, 0);
10575 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
10576 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
10577 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
10579 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
10580 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10581 draw_quad(&test_context);
10582 check_texture_float(rt_texture, 3.3f, 2);
10584 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
10585 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10586 draw_quad(&test_context);
10587 check_texture_float(rt_texture, 4.0f, 2);
10589 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
10590 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10591 draw_quad(&test_context);
10592 check_texture_float(rt_texture, 0.0f, 2);
10594 ID3D11DepthStencilView_Release(dsv);
10595 ID3D11ShaderResourceView_Release(depth_srv);
10596 ID3D11ShaderResourceView_Release(stencil_srv);
10597 ID3D11Texture2D_Release(texture);
10600 ID3D11Buffer_Release(cb);
10601 ID3D11PixelShader_Release(ps_cmp);
10602 ID3D11PixelShader_Release(ps_depth);
10603 ID3D11PixelShader_Release(ps_depth_stencil);
10604 ID3D11PixelShader_Release(ps_stencil);
10605 ID3D11RenderTargetView_Release(rtv);
10606 ID3D11SamplerState_Release(cmp_sampler);
10607 ID3D11SamplerState_Release(sampler);
10608 ID3D11Texture2D_Release(rt_texture);
10609 release_test_context(&test_context);
10612 static void test_sample_c_lz(void)
10614 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10615 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
10616 struct d3d11_test_context test_context;
10617 ID3D11Texture2D *texture, *rt_texture;
10618 D3D11_TEXTURE2D_DESC texture_desc;
10619 D3D11_SAMPLER_DESC sampler_desc;
10620 ID3D11ShaderResourceView *srv;
10621 ID3D11DeviceContext *context;
10622 ID3D11DepthStencilView *dsv;
10623 ID3D11RenderTargetView *rtv;
10624 ID3D11SamplerState *sampler;
10625 struct vec4 ps_constant;
10626 ID3D11PixelShader *ps;
10627 ID3D11Device *device;
10628 ID3D11Buffer *cb;
10629 unsigned int i;
10630 HRESULT hr;
10631 RECT rect;
10633 static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
10634 static const DWORD ps_array_code[] =
10636 #if 0
10637 Texture2DArray t;
10638 SamplerComparisonState s;
10640 float ref;
10641 float layer;
10643 float4 main(float4 position : SV_Position) : SV_Target
10645 return t.SampleCmpLevelZero(s, float3(position.x / 640.0f, position.y / 480.0f, layer), ref);
10647 #endif
10648 0x43425844, 0xfe28b3c3, 0xdd7ef404, 0x8d5874a1, 0x984ff182, 0x00000001, 0x00000180, 0x00000003,
10649 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10650 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10651 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10652 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000e4, 0x00000041,
10653 0x00000039, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
10654 0x00000000, 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
10655 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
10656 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
10657 0x06000036, 0x00100042, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0c000047, 0x00100012,
10658 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000, 0x0020800a,
10659 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
10661 static const DWORD ps_cube_code[] =
10663 #if 0
10664 TextureCube t;
10665 SamplerComparisonState s;
10667 float ref;
10668 float face;
10670 float4 main(float4 position : SV_Position) : SV_Target
10672 float2 p;
10673 p.x = position.x / 640.0f;
10674 p.y = position.y / 480.0f;
10676 float3 coord;
10677 switch ((uint)face)
10679 case 0:
10680 coord = float3(1.0f, p.x, p.y);
10681 break;
10682 case 1:
10683 coord = float3(-1.0f, p.x, p.y);
10684 break;
10685 case 2:
10686 coord = float3(p.x, 1.0f, p.y);
10687 break;
10688 case 3:
10689 coord = float3(p.x, -1.0f, p.y);
10690 break;
10691 case 4:
10692 coord = float3(p.x, p.y, 1.0f);
10693 break;
10694 case 5:
10695 default:
10696 coord = float3(p.x, p.y, -1.0f);
10697 break;
10700 return t.SampleCmpLevelZero(s, coord, ref);
10702 #endif
10703 0x43425844, 0xde5655e5, 0x1b116fa1, 0xfce9e757, 0x41c28aac, 0x00000001, 0x00000328, 0x00000003,
10704 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10705 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10706 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10707 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
10708 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
10709 0x00000000, 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
10710 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012,
10711 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006,
10712 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038,
10713 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889,
10714 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000,
10715 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
10716 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002,
10717 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000,
10718 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
10719 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
10720 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
10721 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032,
10722 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
10723 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038,
10724 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000,
10725 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017,
10726 0x0c000047, 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000,
10727 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006,
10728 0x00000000, 0x0100003e,
10730 static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
10731 static const struct
10733 unsigned int layer;
10734 float d_ref;
10735 float expected;
10737 tests[] =
10739 {0, 0.5f, 0.0f},
10740 {1, 0.5f, 1.0f},
10741 {2, 0.5f, 0.0f},
10742 {3, 0.5f, 0.0f},
10743 {4, 0.5f, 1.0f},
10744 {5, 0.5f, 1.0f},
10746 {0, 0.0f, 0.0f},
10747 {1, 0.0f, 0.0f},
10748 {2, 0.0f, 0.0f},
10749 {3, 0.0f, 0.0f},
10750 {4, 0.0f, 0.0f},
10751 {5, 0.0f, 0.0f},
10753 {0, 1.0f, 0.0f},
10754 {1, 1.0f, 1.0f},
10755 {2, 1.0f, 1.0f},
10756 {3, 1.0f, 1.0f},
10757 {4, 1.0f, 1.0f},
10758 {5, 1.0f, 1.0f},
10761 if (!init_test_context(&test_context, NULL))
10762 return;
10764 device = test_context.device;
10765 context = test_context.immediate_context;
10767 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
10768 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10769 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10770 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10771 sampler_desc.MipLODBias = 0.0f;
10772 sampler_desc.MaxAnisotropy = 0;
10773 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
10774 sampler_desc.BorderColor[0] = 0.0f;
10775 sampler_desc.BorderColor[1] = 0.0f;
10776 sampler_desc.BorderColor[2] = 0.0f;
10777 sampler_desc.BorderColor[3] = 0.0f;
10778 sampler_desc.MinLOD = 0.0f;
10779 sampler_desc.MaxLOD = 10.0f;
10780 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
10781 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10783 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10784 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
10785 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
10786 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10787 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
10788 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10789 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10791 memset(&ps_constant, 0, sizeof(ps_constant));
10792 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
10794 /* 2D array texture */
10795 texture_desc.Width = 32;
10796 texture_desc.Height = 32;
10797 texture_desc.MipLevels = 2;
10798 texture_desc.ArraySize = ARRAY_SIZE(depth_values);
10799 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
10800 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
10801 texture_desc.MiscFlags = 0;
10802 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10803 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10805 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
10807 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
10808 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
10809 dsv_desc.Flags = 0;
10810 U(dsv_desc).Texture2DArray.MipSlice = 0;
10811 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
10812 U(dsv_desc).Texture2DArray.ArraySize = 1;
10814 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10815 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10816 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
10817 ID3D11DepthStencilView_Release(dsv);
10819 U(dsv_desc).Texture2DArray.MipSlice = 1;
10820 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10821 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10822 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10823 ID3D11DepthStencilView_Release(dsv);
10826 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
10827 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
10828 U(srv_desc).Texture2DArray.MostDetailedMip = 0;
10829 U(srv_desc).Texture2DArray.MipLevels = ~0u;
10830 U(srv_desc).Texture2DArray.FirstArraySlice = 0;
10831 U(srv_desc).Texture2DArray.ArraySize = ~0u;
10832 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
10833 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10835 hr = ID3D11Device_CreatePixelShader(device, ps_array_code, sizeof(ps_array_code), NULL, &ps);
10836 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10838 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10839 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10840 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10841 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10843 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10845 ps_constant.x = tests[i].d_ref;
10846 ps_constant.y = tests[i].layer;
10847 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10848 NULL, &ps_constant, 0, 0);
10849 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
10850 draw_quad(&test_context);
10851 check_texture_float(rt_texture, tests[i].expected, 2);
10854 ID3D11Texture2D_Release(texture);
10855 ID3D11ShaderResourceView_Release(srv);
10856 ID3D11PixelShader_Release(ps);
10858 /* cube texture */
10859 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
10860 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10861 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10863 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
10865 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
10866 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
10867 dsv_desc.Flags = 0;
10868 U(dsv_desc).Texture2DArray.MipSlice = 0;
10869 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
10870 U(dsv_desc).Texture2DArray.ArraySize = 1;
10872 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10873 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10874 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
10875 ID3D11DepthStencilView_Release(dsv);
10877 U(dsv_desc).Texture2DArray.MipSlice = 1;
10878 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10879 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10880 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10881 ID3D11DepthStencilView_Release(dsv);
10884 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
10885 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
10886 U(srv_desc).TextureCube.MostDetailedMip = 0;
10887 U(srv_desc).TextureCube.MipLevels = ~0u;
10888 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
10889 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10891 hr = ID3D11Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), NULL, &ps);
10892 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10894 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10895 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10896 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10897 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10899 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10901 ps_constant.x = tests[i].d_ref;
10902 ps_constant.y = tests[i].layer;
10903 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10904 NULL, &ps_constant, 0, 0);
10905 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
10906 draw_quad(&test_context);
10907 /* Avoid testing values affected by seamless cube map filtering. */
10908 SetRect(&rect, 100, 100, 540, 380);
10909 check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
10912 ID3D11Texture2D_Release(texture);
10913 ID3D11ShaderResourceView_Release(srv);
10915 ID3D11Buffer_Release(cb);
10916 ID3D11PixelShader_Release(ps);
10917 ID3D11RenderTargetView_Release(rtv);
10918 ID3D11SamplerState_Release(sampler);
10919 ID3D11Texture2D_Release(rt_texture);
10920 release_test_context(&test_context);
10923 static void test_multiple_render_targets(void)
10925 ID3D11RenderTargetView *rtv[4], *tmp_rtv[4];
10926 D3D11_TEXTURE2D_DESC texture_desc;
10927 ID3D11InputLayout *input_layout;
10928 unsigned int stride, offset, i;
10929 ID3D11DeviceContext *context;
10930 ID3D11Texture2D *rt[4];
10931 ID3D11VertexShader *vs;
10932 ID3D11PixelShader *ps;
10933 ID3D11Device *device;
10934 ID3D11Buffer *vb;
10935 ULONG refcount;
10936 HRESULT hr;
10938 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
10940 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10942 static const DWORD vs_code[] =
10944 #if 0
10945 float4 main(float4 position : POSITION) : SV_POSITION
10947 return position;
10949 #endif
10950 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
10951 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10952 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10953 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
10954 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
10955 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10956 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10958 static const DWORD ps_code[] =
10960 #if 0
10961 struct output
10963 float4 t1 : SV_TARGET0;
10964 float4 t2 : SV_Target1;
10965 float4 t3 : SV_TARGET2;
10966 float4 t4 : SV_Target3;
10969 output main(float4 position : SV_POSITION)
10971 struct output o;
10972 o.t1 = (float4)1.0f;
10973 o.t2 = (float4)0.5f;
10974 o.t3 = (float4)0.2f;
10975 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
10976 return o;
10978 #endif
10979 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
10980 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10981 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
10982 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
10983 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10984 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
10985 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
10986 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
10987 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
10988 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
10989 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
10990 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
10991 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
10992 0x3f800000, 0x0100003e,
10994 static const struct vec2 quad[] =
10996 {-1.0f, -1.0f},
10997 {-1.0f, 1.0f},
10998 { 1.0f, -1.0f},
10999 { 1.0f, 1.0f},
11001 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
11003 if (!(device = create_device(NULL)))
11005 skip("Failed to create device.\n");
11006 return;
11009 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
11010 vs_code, sizeof(vs_code), &input_layout);
11011 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
11013 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
11015 texture_desc.Width = 640;
11016 texture_desc.Height = 480;
11017 texture_desc.MipLevels = 1;
11018 texture_desc.ArraySize = 1;
11019 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11020 texture_desc.SampleDesc.Count = 1;
11021 texture_desc.SampleDesc.Quality = 0;
11022 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11023 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11024 texture_desc.CPUAccessFlags = 0;
11025 texture_desc.MiscFlags = 0;
11027 for (i = 0; i < ARRAY_SIZE(rt); ++i)
11029 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
11030 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
11032 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
11033 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
11036 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11037 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
11038 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11039 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11041 ID3D11Device_GetImmediateContext(device, &context);
11043 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
11044 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
11045 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
11046 stride = sizeof(*quad);
11047 offset = 0;
11048 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
11049 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
11050 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11052 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
11054 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
11055 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
11056 ID3D11DeviceContext_Draw(context, 4, 0);
11057 check_texture_color(rt[0], 0xffffffff, 2);
11058 check_texture_color(rt[1], 0x7f7f7f7f, 2);
11059 check_texture_color(rt[2], 0x33333333, 2);
11060 check_texture_color(rt[3], 0xff7f3300, 2);
11062 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
11063 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
11064 for (i = 0; i < ARRAY_SIZE(tmp_rtv); ++i)
11066 memset(tmp_rtv, 0, sizeof(tmp_rtv));
11067 tmp_rtv[i] = rtv[i];
11068 ID3D11DeviceContext_OMSetRenderTargets(context, 4, tmp_rtv, NULL);
11069 ID3D11DeviceContext_Draw(context, 4, 0);
11071 check_texture_color(rt[0], 0xffffffff, 2);
11072 check_texture_color(rt[1], 0x7f7f7f7f, 2);
11073 check_texture_color(rt[2], 0x33333333, 2);
11074 check_texture_color(rt[3], 0xff7f3300, 2);
11076 ID3D11Buffer_Release(vb);
11077 ID3D11PixelShader_Release(ps);
11078 ID3D11VertexShader_Release(vs);
11079 ID3D11InputLayout_Release(input_layout);
11080 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
11082 ID3D11RenderTargetView_Release(rtv[i]);
11083 ID3D11Texture2D_Release(rt[i]);
11085 ID3D11DeviceContext_Release(context);
11086 refcount = ID3D11Device_Release(device);
11087 ok(!refcount, "Device has %u references left.\n", refcount);
11090 static void test_render_target_views(void)
11092 struct texture
11094 UINT miplevel_count;
11095 UINT array_size;
11098 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
11099 static struct test
11101 struct texture texture;
11102 struct rtv_desc rtv;
11103 DWORD expected_colors[4];
11105 tests[] =
11107 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
11108 {0xff0000ff, 0x00000000}},
11109 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
11110 {0x00000000, 0xff0000ff}},
11111 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
11112 {0xff0000ff, 0x00000000}},
11113 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
11114 {0x00000000, 0xff0000ff}},
11115 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
11116 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
11117 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
11118 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
11119 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
11120 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
11121 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
11122 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
11123 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
11124 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
11125 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
11126 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
11127 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
11128 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
11129 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
11130 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
11131 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
11132 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
11133 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
11134 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
11135 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
11136 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
11138 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
11139 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
11140 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
11141 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
11142 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
11143 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
11144 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
11145 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
11146 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
11147 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
11148 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
11149 static const struct
11151 struct
11153 D3D11_RTV_DIMENSION dimension;
11154 unsigned int miplevel_count;
11155 unsigned int depth_or_array_size;
11156 DXGI_FORMAT format;
11157 } texture;
11158 struct rtv_desc rtv_desc;
11160 invalid_desc_tests[] =
11162 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
11163 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
11164 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11165 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11166 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
11167 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
11168 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
11169 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
11170 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
11171 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
11172 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
11173 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
11174 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
11175 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
11176 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
11177 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
11178 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
11179 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11180 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11181 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
11182 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
11183 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11184 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11185 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
11186 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
11187 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
11188 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
11189 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
11190 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
11191 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
11192 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
11193 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
11194 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
11195 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
11196 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
11197 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
11198 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
11200 #undef FMT_UNKNOWN
11201 #undef RGBA8_UNORM
11202 #undef RGBA8_SRGB
11203 #undef RGBA8_UINT
11204 #undef RGBA8_TL
11205 #undef DIM_UNKNOWN
11206 #undef TEX_1D
11207 #undef TEX_1D_ARRAY
11208 #undef TEX_2D
11209 #undef TEX_2D_ARRAY
11210 #undef TEX_3D
11212 struct d3d11_test_context test_context;
11213 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
11214 D3D11_TEXTURE3D_DESC texture3d_desc;
11215 D3D11_TEXTURE2D_DESC texture_desc;
11216 ID3D11DeviceContext *context;
11217 ID3D11RenderTargetView *rtv;
11218 ID3D11Texture3D *texture3d;
11219 ID3D11Texture2D *texture;
11220 ID3D11Resource *resource;
11221 ID3D11Device *device;
11222 unsigned int i, j, k;
11223 void *data;
11224 HRESULT hr;
11226 if (!init_test_context(&test_context, NULL))
11227 return;
11229 device = test_context.device;
11230 context = test_context.immediate_context;
11232 texture_desc.Width = 32;
11233 texture_desc.Height = 32;
11234 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11235 texture_desc.SampleDesc.Count = 1;
11236 texture_desc.SampleDesc.Quality = 0;
11237 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11238 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11239 texture_desc.CPUAccessFlags = 0;
11240 texture_desc.MiscFlags = 0;
11242 data = heap_alloc_zero(texture_desc.Width * texture_desc.Height * 4);
11243 ok(!!data, "Failed to allocate memory.\n");
11245 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11247 const struct test *test = &tests[i];
11248 unsigned int sub_resource_count;
11250 texture_desc.MipLevels = test->texture.miplevel_count;
11251 texture_desc.ArraySize = test->texture.array_size;
11253 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11254 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
11256 get_rtv_desc(&rtv_desc, &test->rtv);
11257 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11258 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
11260 for (j = 0; j < texture_desc.ArraySize; ++j)
11262 for (k = 0; k < texture_desc.MipLevels; ++k)
11264 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
11265 ID3D11DeviceContext_UpdateSubresource(context,
11266 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
11269 check_texture_color(texture, 0, 0);
11271 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11272 draw_color_quad(&test_context, &red);
11274 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
11275 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
11276 for (j = 0; j < sub_resource_count; ++j)
11277 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
11279 ID3D11RenderTargetView_Release(rtv);
11280 ID3D11Texture2D_Release(texture);
11283 texture3d_desc.Width = 32;
11284 texture3d_desc.Height = 32;
11285 texture3d_desc.Depth = 32;
11286 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11287 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
11288 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11289 texture3d_desc.CPUAccessFlags = 0;
11290 texture3d_desc.MiscFlags = 0;
11292 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
11294 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
11295 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
11297 if (invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
11299 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
11300 texture_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
11301 texture_desc.Format = invalid_desc_tests[i].texture.format;
11302 texture_desc.MiscFlags = 0;
11304 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11305 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
11306 resource = (ID3D11Resource *)texture;
11308 else
11310 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
11311 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
11312 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
11314 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
11315 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
11316 resource = (ID3D11Resource *)texture3d;
11319 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
11320 hr = ID3D11Device_CreateRenderTargetView(device, resource, &rtv_desc, &rtv);
11321 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
11323 ID3D11Resource_Release(resource);
11326 heap_free(data);
11327 release_test_context(&test_context);
11330 static void test_layered_rendering(void)
11332 struct
11334 unsigned int layer_offset;
11335 unsigned int draw_id;
11336 unsigned int padding[2];
11337 } constant;
11338 struct d3d11_test_context test_context;
11339 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
11340 unsigned int i, sub_resource_count;
11341 D3D11_TEXTURE2D_DESC texture_desc;
11342 ID3D11DeviceContext *context;
11343 ID3D11RenderTargetView *rtv;
11344 ID3D11Texture2D *texture;
11345 ID3D11GeometryShader *gs;
11346 ID3D11VertexShader *vs;
11347 ID3D11PixelShader *ps;
11348 ID3D11Device *device;
11349 ID3D11Buffer *cb;
11350 HRESULT hr;
11351 BOOL warp;
11353 static const DWORD vs_code[] =
11355 #if 0
11356 uint layer_offset;
11358 void main(float4 position : POSITION,
11359 out float4 out_position : SV_POSITION,
11360 out uint layer : SV_RenderTargetArrayIndex)
11362 out_position = position;
11363 layer = layer_offset;
11365 #endif
11366 0x43425844, 0x71f7b9cd, 0x2ab8c713, 0x53e77663, 0x54a9ba68, 0x00000001, 0x00000158, 0x00000004,
11367 0x00000030, 0x00000064, 0x000000cc, 0x00000148, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11368 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954,
11369 0xababab00, 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
11370 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001,
11371 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567,
11372 0x79617272, 0x65646e49, 0xabab0078, 0x52444853, 0x00000074, 0x00010040, 0x0000001d, 0x04000059,
11373 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2,
11374 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x05000036, 0x001020f2,
11375 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020800a, 0x00000000,
11376 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00002000, 0x00000000,
11378 static const DWORD gs_5_code[] =
11380 #if 0
11381 uint layer_offset;
11383 struct gs_in
11385 float4 pos : SV_Position;
11388 struct gs_out
11390 float4 pos : SV_Position;
11391 uint layer : SV_RenderTargetArrayIndex;
11394 [instance(4)]
11395 [maxvertexcount(3)]
11396 void main(triangle gs_in vin[3], in uint instance_id : SV_GSInstanceID,
11397 inout TriangleStream<gs_out> vout)
11399 gs_out o;
11400 o.layer = layer_offset + instance_id;
11401 for (uint i = 0; i < 3; ++i)
11403 o.pos = vin[i].pos;
11404 vout.Append(o);
11407 #endif
11408 0x43425844, 0xb52da162, 0x9a13d8ee, 0xf7c30b50, 0xe80bc2e7, 0x00000001, 0x00000218, 0x00000003,
11409 0x0000002c, 0x00000060, 0x000000d0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11410 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
11411 0x3547534f, 0x00000068, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
11412 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000004, 0x00000001,
11413 0x00000001, 0x00000e01, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472,
11414 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x58454853, 0x00000140, 0x00020050, 0x00000050,
11415 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
11416 0x00000000, 0x00000001, 0x0200005f, 0x00025000, 0x02000068, 0x00000001, 0x020000ce, 0x00000004,
11417 0x0100185d, 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
11418 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x00000003, 0x0700001e,
11419 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0002500a, 0x05000036, 0x00100022,
11420 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a,
11421 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000, 0x07000036, 0x001020f2,
11422 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001,
11423 0x0010000a, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x0700001e, 0x00100022, 0x00000000,
11424 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
11426 static const DWORD gs_4_code[] =
11428 #if 0
11429 uint layer_offset;
11431 struct gs_in
11433 float4 pos : SV_Position;
11436 struct gs_out
11438 float4 pos : SV_Position;
11439 uint layer : SV_RenderTargetArrayIndex;
11442 [maxvertexcount(12)]
11443 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
11445 gs_out o;
11446 for (uint instance_id = 0; instance_id < 4; ++instance_id)
11448 o.layer = layer_offset + instance_id;
11449 for (uint i = 0; i < 3; ++i)
11451 o.pos = vin[i].pos;
11452 vout.Append(o);
11454 vout.RestartStrip();
11457 #endif
11458 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
11459 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11460 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
11461 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11462 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
11463 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
11464 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
11465 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
11466 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
11467 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
11468 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
11469 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
11470 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
11471 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
11472 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
11473 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
11474 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
11475 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
11476 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
11478 static const DWORD ps_code[] =
11480 #if 0
11481 uint layer_offset;
11482 uint draw_id;
11484 float4 main(in float4 pos : SV_Position,
11485 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
11487 return float4(layer, draw_id, 0, 0);
11489 #endif
11490 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
11491 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
11492 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
11493 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
11494 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
11495 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
11496 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
11497 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
11498 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
11499 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
11500 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
11502 static const struct vec4 expected_values[] =
11504 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
11505 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
11506 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
11507 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
11509 static const struct vec4 vs_expected_value = {1.0f, 42.0f};
11511 if (!init_test_context(&test_context, NULL))
11512 return;
11514 device = test_context.device;
11515 context = test_context.immediate_context;
11517 warp = is_warp_device(device);
11519 memset(&constant, 0, sizeof(constant));
11520 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
11521 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
11522 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
11523 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11525 /* Geometry shader instancing seems broken on WARP. */
11526 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0 || warp)
11528 hr = ID3D11Device_CreateGeometryShader(device, gs_4_code, sizeof(gs_4_code), NULL, &gs);
11529 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
11531 else
11533 hr = ID3D11Device_CreateGeometryShader(device, gs_5_code, sizeof(gs_5_code), NULL, &gs);
11534 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
11536 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
11538 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11539 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11540 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11542 texture_desc.Width = 32;
11543 texture_desc.Height = 32;
11544 texture_desc.MipLevels = 3;
11545 texture_desc.ArraySize = 8;
11546 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11547 texture_desc.SampleDesc.Count = 1;
11548 texture_desc.SampleDesc.Quality = 0;
11549 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11550 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11551 texture_desc.CPUAccessFlags = 0;
11552 texture_desc.MiscFlags = 0;
11553 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11554 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11556 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11557 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11558 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11559 constant.layer_offset = 0;
11560 constant.draw_id = 0;
11561 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11562 draw_quad(&test_context);
11563 constant.layer_offset = 4;
11564 constant.draw_id = 1;
11565 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11566 draw_quad(&test_context);
11567 ID3D11RenderTargetView_Release(rtv);
11569 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11570 rtv_desc.Format = texture_desc.Format;
11571 U(rtv_desc).Texture2DArray.MipSlice = 0;
11572 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
11573 U(rtv_desc).Texture2DArray.ArraySize = 1;
11574 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11575 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11576 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11577 constant.layer_offset = 1;
11578 constant.draw_id = 2;
11579 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11580 draw_quad(&test_context);
11581 ID3D11RenderTargetView_Release(rtv);
11583 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11584 U(rtv_desc).Texture2DArray.MipSlice = 1;
11585 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
11586 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
11587 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11588 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11589 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11590 constant.layer_offset = 0;
11591 constant.draw_id = 3;
11592 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11593 draw_quad(&test_context);
11594 constant.layer_offset = 4;
11595 constant.draw_id = 3;
11596 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11597 draw_quad(&test_context);
11598 ID3D11RenderTargetView_Release(rtv);
11600 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11601 U(rtv_desc).Texture2DArray.MipSlice = 2;
11602 U(rtv_desc).Texture2DArray.ArraySize = 1;
11603 for (i = 0; i < texture_desc.ArraySize; ++i)
11605 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
11606 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11607 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11608 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11609 constant.layer_offset = 0;
11610 constant.draw_id = 4 + i;
11611 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11612 draw_quad(&test_context);
11613 ID3D11RenderTargetView_Release(rtv);
11616 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
11617 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
11618 for (i = 0; i < sub_resource_count; ++i)
11620 if (warp && (i == 3 || i == 4)) /* Broken on WARP. */
11621 continue;
11622 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
11625 /* layered rendering without GS */
11626 if (!check_viewport_array_index_from_any_shader_support(device))
11628 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11629 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11630 if (SUCCEEDED(hr))
11631 ID3D11VertexShader_Release(vs);
11632 skip("Viewport array index not supported in vertex shaders.\n");
11633 goto done;
11636 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
11638 constant.layer_offset = 1;
11639 constant.draw_id = 42;
11640 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11641 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11642 U(rtv_desc).Texture2DArray.MipSlice = 0;
11643 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
11644 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
11645 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11646 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
11647 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11648 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
11649 check_texture_sub_resource_vec4(texture,
11650 constant.layer_offset * texture_desc.MipLevels, NULL, &vs_expected_value, 1);
11651 ID3D11RenderTargetView_Release(rtv);
11653 done:
11654 ID3D11Texture2D_Release(texture);
11656 ID3D11Buffer_Release(cb);
11657 ID3D11GeometryShader_Release(gs);
11658 ID3D11PixelShader_Release(ps);
11659 release_test_context(&test_context);
11662 static void test_scissor(void)
11664 struct d3d11_test_context test_context;
11665 ID3D11DeviceContext *immediate_context;
11666 D3D11_RASTERIZER_DESC rs_desc;
11667 ID3D11RasterizerState *rs;
11668 D3D11_RECT scissor_rect;
11669 ID3D11Device *device;
11670 DWORD color;
11671 HRESULT hr;
11673 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
11674 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11676 if (!init_test_context(&test_context, NULL))
11677 return;
11679 device = test_context.device;
11680 immediate_context = test_context.immediate_context;
11682 rs_desc.FillMode = D3D11_FILL_SOLID;
11683 rs_desc.CullMode = D3D11_CULL_BACK;
11684 rs_desc.FrontCounterClockwise = FALSE;
11685 rs_desc.DepthBias = 0;
11686 rs_desc.DepthBiasClamp = 0.0f;
11687 rs_desc.SlopeScaledDepthBias = 0.0f;
11688 rs_desc.DepthClipEnable = TRUE;
11689 rs_desc.ScissorEnable = TRUE;
11690 rs_desc.MultisampleEnable = FALSE;
11691 rs_desc.AntialiasedLineEnable = FALSE;
11692 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
11693 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11695 SetRect(&scissor_rect, 160, 120, 480, 360);
11696 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
11698 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
11699 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
11701 draw_color_quad(&test_context, &green);
11702 color = get_texture_color(test_context.backbuffer, 320, 60);
11703 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11704 color = get_texture_color(test_context.backbuffer, 80, 240);
11705 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11706 color = get_texture_color(test_context.backbuffer, 320, 240);
11707 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11708 color = get_texture_color(test_context.backbuffer, 560, 240);
11709 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11710 color = get_texture_color(test_context.backbuffer, 320, 420);
11711 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11713 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
11714 ID3D11DeviceContext_RSSetState(immediate_context, rs);
11715 draw_color_quad(&test_context, &green);
11716 color = get_texture_color(test_context.backbuffer, 320, 60);
11717 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11718 color = get_texture_color(test_context.backbuffer, 80, 240);
11719 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11720 color = get_texture_color(test_context.backbuffer, 320, 240);
11721 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11722 color = get_texture_color(test_context.backbuffer, 560, 240);
11723 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11724 color = get_texture_color(test_context.backbuffer, 320, 420);
11725 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11727 set_viewport(immediate_context, -1.0f, 0.0f, 641, 480, 0.0f, 1.0f);
11728 SetRect(&scissor_rect, -1, 0, 640, 480);
11729 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
11730 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
11731 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
11732 draw_color_quad(&test_context, &green);
11733 color = get_texture_color(test_context.backbuffer, 320, 60);
11734 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11735 color = get_texture_color(test_context.backbuffer, 80, 240);
11736 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11737 color = get_texture_color(test_context.backbuffer, 320, 240);
11738 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11739 color = get_texture_color(test_context.backbuffer, 560, 240);
11740 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11741 color = get_texture_color(test_context.backbuffer, 320, 420);
11742 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11744 ID3D11RasterizerState_Release(rs);
11745 release_test_context(&test_context);
11748 static void test_clear_state(void)
11750 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11751 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11753 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11755 #if 0
11756 float4 main(float4 pos : POSITION) : POSITION
11758 return pos;
11760 #endif
11761 static const DWORD simple_vs[] =
11763 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
11764 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11765 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11766 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11767 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
11768 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
11769 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11771 #if 0
11772 struct data
11774 float4 position : SV_Position;
11777 struct patch_constant_data
11779 float edges[3] : SV_TessFactor;
11780 float inside : SV_InsideTessFactor;
11783 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
11785 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
11786 output.inside = 1.0f;
11789 [domain("tri")]
11790 [outputcontrolpoints(3)]
11791 [partitioning("integer")]
11792 [outputtopology("triangle_ccw")]
11793 [patchconstantfunc("patch_constant")]
11794 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
11796 return input[i];
11799 [domain("tri")]
11800 void ds_main(patch_constant_data input,
11801 float3 tess_coord : SV_DomainLocation,
11802 const OutputPatch<data, 3> patch,
11803 out data output)
11805 output.position = tess_coord.x * patch[0].position
11806 + tess_coord.y * patch[1].position
11807 + tess_coord.z * patch[2].position;
11809 #endif
11810 static const DWORD simple_hs[] =
11812 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
11813 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11814 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
11815 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11816 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
11817 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
11818 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
11819 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
11820 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
11821 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
11822 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
11823 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
11824 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
11825 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
11826 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
11827 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
11828 0x00004001, 0x3f800000, 0x0100003e,
11830 static const DWORD simple_ds[] =
11832 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
11833 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11834 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
11835 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
11836 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
11837 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
11838 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
11839 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
11840 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
11841 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
11842 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
11843 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
11844 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
11845 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
11846 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
11848 #if 0
11849 struct gs_out
11851 float4 pos : SV_POSITION;
11854 [maxvertexcount(4)]
11855 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
11857 float offset = 0.1 * vin[0].w;
11858 gs_out v;
11860 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
11861 vout.Append(v);
11862 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
11863 vout.Append(v);
11864 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
11865 vout.Append(v);
11866 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
11867 vout.Append(v);
11869 #endif
11870 static const DWORD simple_gs[] =
11872 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
11873 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11874 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11875 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
11876 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
11877 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
11878 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
11879 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
11880 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
11881 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
11882 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
11883 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
11884 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
11885 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
11886 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
11887 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
11888 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
11889 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
11891 #if 0
11892 float4 main(float4 color : COLOR) : SV_TARGET
11894 return color;
11896 #endif
11897 static const DWORD simple_ps[] =
11899 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
11900 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
11901 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
11902 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11903 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11904 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
11905 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11907 #if 0
11908 [numthreads(1, 1, 1)]
11909 void main() { }
11910 #endif
11911 static const DWORD simple_cs[] =
11913 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
11914 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11915 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
11916 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
11919 D3D11_VIEWPORT tmp_viewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
11920 ID3D11ShaderResourceView *tmp_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
11921 ID3D11ShaderResourceView *srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
11922 ID3D11RenderTargetView *tmp_rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11923 RECT tmp_rect[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
11924 ID3D11SamplerState *tmp_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
11925 ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11926 ID3D11Texture2D *rt_texture[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11927 ID3D11Buffer *cb[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
11928 ID3D11Buffer *tmp_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11929 ID3D11SamplerState *sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
11930 ID3D11UnorderedAccessView *tmp_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
11931 ID3D11UnorderedAccessView *cs_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
11932 ID3D11Buffer *buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11933 ID3D11Buffer *cs_uav_buffer[D3D11_PS_CS_UAV_REGISTER_COUNT];
11934 UINT offset[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11935 UINT stride[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11936 ID3D11Buffer *so_buffer[D3D11_SO_BUFFER_SLOT_COUNT];
11937 ID3D11InputLayout *tmp_input_layout, *input_layout;
11938 ID3D11DepthStencilState *tmp_ds_state, *ds_state;
11939 ID3D11BlendState *tmp_blend_state, *blend_state;
11940 ID3D11RasterizerState *tmp_rs_state, *rs_state;
11941 ID3D11Predicate *tmp_predicate, *predicate;
11942 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
11943 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
11944 ID3D11DepthStencilView *tmp_dsv, *dsv;
11945 ID3D11UnorderedAccessView *ps_uav;
11946 D3D11_PRIMITIVE_TOPOLOGY topology;
11947 D3D11_TEXTURE2D_DESC texture_desc;
11948 ID3D11GeometryShader *tmp_gs, *gs;
11949 ID3D11ComputeShader *tmp_cs, *cs;
11950 D3D11_DEPTH_STENCIL_DESC ds_desc;
11951 ID3D11VertexShader *tmp_vs, *vs;
11952 ID3D11DomainShader *tmp_ds, *ds;
11953 D3D11_SAMPLER_DESC sampler_desc;
11954 D3D11_QUERY_DESC predicate_desc;
11955 struct device_desc device_desc;
11956 ID3D11PixelShader *tmp_ps, *ps;
11957 ID3D11HullShader *tmp_hs, *hs;
11958 D3D11_RASTERIZER_DESC rs_desc;
11959 ID3D11DeviceContext *context;
11960 D3D11_BLEND_DESC blend_desc;
11961 ID3D11Texture2D *ds_texture;
11962 ID3D11Buffer *ps_uav_buffer;
11963 float blend_factor[4];
11964 ID3D11Device *device;
11965 BOOL predicate_value;
11966 UINT instance_count;
11967 DXGI_FORMAT format;
11968 UINT sample_mask;
11969 UINT stencil_ref;
11970 ULONG refcount;
11971 UINT count, i;
11972 HRESULT hr;
11974 device_desc.feature_level = &feature_level;
11975 device_desc.flags = 0;
11976 if (!(device = create_device(&device_desc)))
11978 skip("Failed to create device.\n");
11979 return;
11982 ID3D11Device_GetImmediateContext(device, &context);
11984 /* Verify the initial state after device creation. */
11986 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11987 tmp_buffer);
11988 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11990 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11992 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11993 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11995 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11997 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11998 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12000 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12002 instance_count = 100;
12003 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, &instance_count);
12004 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
12005 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
12007 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12008 tmp_buffer);
12009 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12011 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12013 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12014 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12016 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12018 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12019 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12021 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12023 instance_count = 100;
12024 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, &instance_count);
12025 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
12026 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
12028 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12029 tmp_buffer);
12030 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12032 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12034 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12035 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12037 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12039 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12040 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12042 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12044 instance_count = 100;
12045 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, &instance_count);
12046 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
12047 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
12049 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12050 tmp_buffer);
12051 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12053 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12055 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12056 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12058 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12060 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12061 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12063 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12065 instance_count = 100;
12066 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, &instance_count);
12067 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
12068 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
12070 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12071 tmp_buffer);
12072 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12074 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12076 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
12077 tmp_srv);
12078 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12080 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12082 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12083 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12085 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12087 instance_count = 100;
12088 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, &instance_count);
12089 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
12090 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
12092 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12093 tmp_buffer);
12094 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12096 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12098 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
12099 tmp_srv);
12100 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12102 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12104 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12105 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12107 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12109 instance_count = 100;
12110 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, &instance_count);
12111 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
12112 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
12113 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12114 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12116 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12119 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12120 tmp_buffer, stride, offset);
12121 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12123 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
12124 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
12125 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
12127 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
12128 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
12129 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
12130 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
12131 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
12132 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
12133 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
12134 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
12136 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
12137 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
12138 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
12139 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
12140 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12141 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12142 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
12143 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
12144 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
12145 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
12146 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
12147 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12149 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12151 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12152 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
12153 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
12154 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12155 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12157 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12159 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12160 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12162 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12165 if (!enable_debug_layer)
12167 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
12168 ok(!count, "Got unexpected scissor rect count %u.\n", count);
12170 memset(tmp_rect, 0x55, sizeof(tmp_rect));
12171 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12172 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
12173 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12175 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
12176 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
12178 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12179 ok(!count, "Got unexpected viewport count %u.\n", count);
12180 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12181 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12182 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12183 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12185 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
12186 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
12187 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12188 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12189 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12191 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12192 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
12194 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12195 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12197 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
12200 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12201 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
12202 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12204 /* Create resources. */
12206 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12207 cb[i] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 1024, NULL);
12209 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12211 buffer[i] = create_buffer(device,
12212 D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE,
12213 1024, NULL);
12215 stride[i] = (i + 1) * 4;
12216 offset[i] = (i + 1) * 16;
12219 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12220 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
12222 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12223 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
12224 U(srv_desc).Buffer.ElementOffset = 0;
12225 U(srv_desc).Buffer.ElementWidth = 64;
12227 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12229 hr = ID3D11Device_CreateShaderResourceView(device,
12230 (ID3D11Resource *)buffer[i % D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
12231 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12234 uav_desc.Format = DXGI_FORMAT_R32_UINT;
12235 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
12236 U(uav_desc).Buffer.FirstElement = 0;
12237 U(uav_desc).Buffer.NumElements = 8;
12238 U(uav_desc).Buffer.Flags = 0;
12240 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12242 cs_uav_buffer[i] = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
12243 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_uav_buffer[i],
12244 &uav_desc, &cs_uav[i]);
12245 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12248 ps_uav_buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
12249 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_uav_buffer,
12250 &uav_desc, &ps_uav);
12251 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12253 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
12254 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
12255 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
12256 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
12257 sampler_desc.MipLODBias = 0.0f;
12258 sampler_desc.MaxAnisotropy = 16;
12259 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
12260 sampler_desc.BorderColor[0] = 0.0f;
12261 sampler_desc.BorderColor[1] = 0.0f;
12262 sampler_desc.BorderColor[2] = 0.0f;
12263 sampler_desc.BorderColor[3] = 0.0f;
12264 sampler_desc.MinLOD = 0.0f;
12265 sampler_desc.MaxLOD = 16.0f;
12267 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12269 sampler_desc.MinLOD = (float)i;
12271 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
12272 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
12275 hr = ID3D11Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
12276 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12278 hr = ID3D11Device_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
12279 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
12281 hr = ID3D11Device_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
12282 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
12284 hr = ID3D11Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
12285 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
12287 hr = ID3D11Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
12288 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12290 hr = ID3D11Device_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
12291 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
12293 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12294 simple_vs, sizeof(simple_vs), &input_layout);
12295 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12297 memset(&blend_desc, 0, sizeof(blend_desc));
12298 blend_desc.AlphaToCoverageEnable = FALSE;
12299 blend_desc.IndependentBlendEnable = FALSE;
12300 blend_desc.RenderTarget[0].BlendEnable = TRUE;
12301 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
12302 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
12303 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
12304 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
12305 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
12306 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
12307 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
12309 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
12310 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
12312 ds_desc.DepthEnable = TRUE;
12313 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
12314 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
12315 ds_desc.StencilEnable = FALSE;
12316 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
12317 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
12318 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
12319 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
12320 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
12321 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
12322 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
12323 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
12324 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
12325 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
12327 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
12328 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
12330 texture_desc.Width = 512;
12331 texture_desc.Height = 512;
12332 texture_desc.MipLevels = 1;
12333 texture_desc.ArraySize = 1;
12334 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12335 texture_desc.SampleDesc.Count = 1;
12336 texture_desc.SampleDesc.Quality = 0;
12337 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12338 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12339 texture_desc.CPUAccessFlags = 0;
12340 texture_desc.MiscFlags = 0;
12342 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12344 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
12345 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12348 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
12349 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
12351 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
12352 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12354 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12356 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture[i], NULL, &rtv[i]);
12357 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12360 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)ds_texture, NULL, &dsv);
12361 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
12363 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12365 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
12367 tmp_viewport[i].TopLeftX = i * 3;
12368 tmp_viewport[i].TopLeftY = i * 4;
12369 tmp_viewport[i].Width = 3;
12370 tmp_viewport[i].Height = 4;
12371 tmp_viewport[i].MinDepth = i * 0.01f;
12372 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
12375 rs_desc.FillMode = D3D11_FILL_SOLID;
12376 rs_desc.CullMode = D3D11_CULL_BACK;
12377 rs_desc.FrontCounterClockwise = FALSE;
12378 rs_desc.DepthBias = 0;
12379 rs_desc.DepthBiasClamp = 0.0f;
12380 rs_desc.SlopeScaledDepthBias = 0.0f;
12381 rs_desc.DepthClipEnable = TRUE;
12382 rs_desc.ScissorEnable = FALSE;
12383 rs_desc.MultisampleEnable = FALSE;
12384 rs_desc.AntialiasedLineEnable = FALSE;
12386 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs_state);
12387 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12389 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
12390 predicate_desc.MiscFlags = 0;
12392 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
12393 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
12395 /* Setup state. */
12397 /* Some versions of Windows AMD drivers hang while the device is being
12398 * released, if the total number of used resource slots exceeds some limit.
12399 * Do not use all constant buffers slots in order to not trigger this
12400 * driver bug. */
12401 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb[0]);
12402 ID3D11DeviceContext_VSSetConstantBuffers(context, 7, 1, &cb[7]);
12403 ID3D11DeviceContext_VSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12404 ID3D11DeviceContext_VSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12405 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12407 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb[0]);
12408 ID3D11DeviceContext_HSSetConstantBuffers(context, 7, 1, &cb[7]);
12409 ID3D11DeviceContext_HSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12410 ID3D11DeviceContext_HSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12411 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
12413 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12414 ID3D11DeviceContext_DSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12415 ID3D11DeviceContext_DSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12416 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
12418 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12419 ID3D11DeviceContext_GSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12420 ID3D11DeviceContext_GSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12421 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
12423 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12424 ID3D11DeviceContext_PSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12425 ID3D11DeviceContext_PSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12426 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12428 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12429 ID3D11DeviceContext_CSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12430 ID3D11DeviceContext_CSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12431 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
12432 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, cs_uav, NULL);
12434 ID3D11DeviceContext_IASetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12435 buffer, stride, offset);
12436 ID3D11DeviceContext_IASetIndexBuffer(context, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
12437 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12438 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12440 blend_factor[0] = 0.1f;
12441 blend_factor[1] = 0.2f;
12442 blend_factor[2] = 0.3f;
12443 blend_factor[3] = 0.4f;
12444 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, 0xff00ff00);
12445 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 3);
12446 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
12447 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, rtv, dsv,
12448 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, 1, &ps_uav, NULL);
12450 ID3D11DeviceContext_RSSetScissorRects(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12451 tmp_rect);
12452 ID3D11DeviceContext_RSSetViewports(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12453 tmp_viewport);
12454 ID3D11DeviceContext_RSSetState(context, rs_state);
12456 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
12458 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
12460 /* Verify the set state. */
12462 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12463 tmp_buffer);
12464 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12466 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
12467 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12468 tmp_buffer[i], i, expected_cb);
12469 if (tmp_buffer[i])
12470 ID3D11Buffer_Release(tmp_buffer[i]);
12472 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12473 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12475 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12476 tmp_srv[i], i, srv[i]);
12477 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12479 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12480 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12482 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12483 tmp_sampler[i], i, sampler[i]);
12484 ID3D11SamplerState_Release(tmp_sampler[i]);
12486 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
12487 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
12488 ID3D11VertexShader_Release(tmp_vs);
12490 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12491 tmp_buffer);
12492 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12494 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
12495 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12496 tmp_buffer[i], i, expected_cb);
12497 if (tmp_buffer[i])
12498 ID3D11Buffer_Release(tmp_buffer[i]);
12500 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12501 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12503 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12504 tmp_srv[i], i, srv[i]);
12505 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12507 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12508 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12510 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12511 tmp_sampler[i], i, sampler[i]);
12512 ID3D11SamplerState_Release(tmp_sampler[i]);
12514 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
12515 ok(tmp_hs == hs, "Got unexpected hull shader %p, expected %p.\n", tmp_hs, hs);
12516 ID3D11HullShader_Release(tmp_hs);
12518 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12519 tmp_buffer);
12520 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12522 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12523 tmp_buffer[i], i, cb[i]);
12524 ID3D11Buffer_Release(tmp_buffer[i]);
12526 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12527 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12529 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12530 tmp_srv[i], i, srv[i]);
12531 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12533 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12534 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12536 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12537 tmp_sampler[i], i, sampler[i]);
12538 ID3D11SamplerState_Release(tmp_sampler[i]);
12540 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
12541 ok(tmp_ds == ds, "Got unexpected domain shader %p, expected %p.\n", tmp_ds, ds);
12542 ID3D11DomainShader_Release(tmp_ds);
12544 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12545 tmp_buffer);
12546 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12548 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12549 tmp_buffer[i], i, cb[i]);
12550 ID3D11Buffer_Release(tmp_buffer[i]);
12552 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12553 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12555 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12556 tmp_srv[i], i, srv[i]);
12557 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12559 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12560 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12562 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12563 tmp_sampler[i], i, sampler[i]);
12564 ID3D11SamplerState_Release(tmp_sampler[i]);
12566 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
12567 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
12568 ID3D11GeometryShader_Release(tmp_gs);
12570 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12571 tmp_buffer);
12572 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12574 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12575 tmp_buffer[i], i, cb[i]);
12576 ID3D11Buffer_Release(tmp_buffer[i]);
12578 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12579 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12581 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12582 tmp_srv[i], i, srv[i]);
12583 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12585 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12586 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12588 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12589 tmp_sampler[i], i, sampler[i]);
12590 ID3D11SamplerState_Release(tmp_sampler[i]);
12592 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
12593 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
12594 ID3D11PixelShader_Release(tmp_ps);
12596 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12597 tmp_buffer);
12598 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12600 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12601 tmp_buffer[i], i, cb[i]);
12602 ID3D11Buffer_Release(tmp_buffer[i]);
12604 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12605 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12607 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12608 tmp_srv[i], i, srv[i]);
12609 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12611 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12612 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12614 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12615 tmp_sampler[i], i, sampler[i]);
12616 ID3D11SamplerState_Release(tmp_sampler[i]);
12618 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
12619 ok(tmp_cs == cs, "Got unexpected compute shader %p, expected %p.\n", tmp_cs, cs);
12620 ID3D11ComputeShader_Release(tmp_cs);
12621 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12622 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12624 ok(tmp_uav[i] == cs_uav[i], "Got unexpected unordered access view %p in slot %u, expected %p.\n",
12625 tmp_uav[i], i, cs_uav[i]);
12626 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
12629 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12630 tmp_buffer, stride, offset);
12631 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12633 todo_wine_if(i >= D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
12635 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
12636 tmp_buffer[i], i, buffer[i]);
12637 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
12638 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
12640 if (tmp_buffer[i])
12641 ID3D11Buffer_Release(tmp_buffer[i]);
12643 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
12644 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
12645 ID3D11Buffer_Release(tmp_buffer[0]);
12646 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
12647 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
12648 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
12649 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
12650 tmp_input_layout, input_layout);
12651 ID3D11InputLayout_Release(tmp_input_layout);
12652 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
12653 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
12655 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
12656 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
12657 ID3D11BlendState_Release(tmp_blend_state);
12658 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
12659 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
12660 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12661 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12662 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
12663 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
12664 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
12665 ID3D11DepthStencilState_Release(tmp_ds_state);
12666 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
12667 /* For OMGetDepthStencilState() both arguments are optional. */
12668 ID3D11DeviceContext_OMGetDepthStencilState(context, NULL, NULL);
12669 stencil_ref = 0;
12670 ID3D11DeviceContext_OMGetDepthStencilState(context, NULL, &stencil_ref);
12671 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
12672 tmp_ds_state = NULL;
12673 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, NULL);
12674 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
12675 ID3D11DepthStencilState_Release(tmp_ds_state);
12676 /* OMGetBlendState() arguments are optional */
12677 ID3D11DeviceContext_OMGetBlendState(context, NULL, NULL, NULL);
12678 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, NULL, NULL);
12679 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
12680 ID3D11BlendState_Release(tmp_blend_state);
12681 sample_mask = 0;
12682 ID3D11DeviceContext_OMGetBlendState(context, NULL, NULL, &sample_mask);
12683 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
12684 memset(blend_factor, 0, sizeof(blend_factor));
12685 ID3D11DeviceContext_OMGetBlendState(context, NULL, blend_factor, NULL);
12686 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
12687 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
12688 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12689 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12691 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
12692 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
12694 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
12695 tmp_rtv[i], i, rtv[i]);
12696 ID3D11RenderTargetView_Release(tmp_rtv[i]);
12698 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12699 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
12700 ID3D11DepthStencilView_Release(tmp_dsv);
12701 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
12702 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
12703 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12704 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
12706 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
12707 tmp_rtv[i], i, rtv[i]);
12708 ID3D11RenderTargetView_Release(tmp_rtv[i]);
12710 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12711 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
12712 ID3D11DepthStencilView_Release(tmp_dsv);
12713 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT - 1; ++i)
12715 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12717 ok(tmp_uav[i] == ps_uav, "Got unexpected unordered access view %p in slot %u, expected %p.\n",
12718 tmp_uav[i], i, ps_uav);
12719 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
12721 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
12722 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12723 "Got unexpected scissor rect count %u.\n", count);
12724 memset(tmp_rect, 0x55, sizeof(tmp_rect));
12725 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
12726 for (i = 0; i < count; ++i)
12728 ok(tmp_rect[i].left == i
12729 && tmp_rect[i].top == i * 2
12730 && tmp_rect[i].right == i + 1
12731 && tmp_rect[i].bottom == (i + 1) * 2,
12732 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
12734 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12735 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12736 "Got unexpected viewport count %u.\n", count);
12737 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12738 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12739 for (i = 0; i < count; ++i)
12741 ok(tmp_viewport[i].TopLeftX == i * 3
12742 && tmp_viewport[i].TopLeftY == i * 4
12743 && tmp_viewport[i].Width == 3
12744 && tmp_viewport[i].Height == 4
12745 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
12746 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
12747 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12748 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12749 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12751 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12752 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
12753 ID3D11RasterizerState_Release(tmp_rs_state);
12755 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12756 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12758 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
12759 tmp_buffer[i], i, so_buffer[i]);
12760 ID3D11Buffer_Release(tmp_buffer[i]);
12763 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12764 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
12765 ID3D11Predicate_Release(tmp_predicate);
12766 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12768 /* Verify ClearState(). */
12770 ID3D11DeviceContext_ClearState(context);
12772 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12773 tmp_buffer);
12774 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12776 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12778 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12779 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12781 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12783 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12784 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12786 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12788 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
12789 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
12791 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12792 tmp_buffer);
12793 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12795 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12797 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12798 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12800 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12802 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12803 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12805 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12807 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
12808 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
12810 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12811 tmp_buffer);
12812 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12814 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12816 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12817 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12819 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12821 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12822 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12824 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12826 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
12827 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
12829 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12830 tmp_buffer);
12831 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12833 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12835 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12836 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12838 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12840 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12841 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12843 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12845 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
12846 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
12848 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12849 tmp_buffer);
12850 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12852 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12854 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12855 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12857 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12859 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12860 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12862 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12864 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
12865 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
12867 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12868 tmp_buffer);
12869 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12871 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12873 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
12874 tmp_srv);
12875 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12877 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12879 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12880 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12882 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12884 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
12885 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
12886 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12887 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12889 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12892 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12893 tmp_buffer, stride, offset);
12894 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12896 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
12897 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
12898 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
12900 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
12901 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
12902 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
12903 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
12904 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
12905 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
12906 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
12907 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
12909 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
12910 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
12911 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
12912 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
12913 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12914 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12915 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
12916 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
12917 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
12918 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
12919 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
12920 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12922 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12924 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12925 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
12926 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
12927 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12928 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12930 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12932 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12933 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12935 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12938 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
12939 ok(!count, "Got unexpected scissor rect count %u.\n", count);
12940 memset(tmp_rect, 0x55, sizeof(tmp_rect));
12941 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12942 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
12943 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12945 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
12946 "Got unexpected scissor rect %s in slot %u.\n",
12947 wine_dbgstr_rect(&tmp_rect[i]), i);
12949 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12950 ok(!count, "Got unexpected viewport count %u.\n", count);
12951 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12952 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12953 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12954 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12956 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
12957 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
12958 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12959 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12960 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12962 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12963 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
12965 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12966 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12968 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
12971 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12972 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
12973 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12975 /* Cleanup. */
12977 ID3D11Predicate_Release(predicate);
12978 ID3D11RasterizerState_Release(rs_state);
12979 ID3D11DepthStencilView_Release(dsv);
12980 ID3D11Texture2D_Release(ds_texture);
12982 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12984 ID3D11RenderTargetView_Release(rtv[i]);
12985 ID3D11Texture2D_Release(rt_texture[i]);
12988 ID3D11DepthStencilState_Release(ds_state);
12989 ID3D11BlendState_Release(blend_state);
12990 ID3D11InputLayout_Release(input_layout);
12991 ID3D11VertexShader_Release(vs);
12992 ID3D11HullShader_Release(hs);
12993 ID3D11DomainShader_Release(ds);
12994 ID3D11GeometryShader_Release(gs);
12995 ID3D11PixelShader_Release(ps);
12996 ID3D11ComputeShader_Release(cs);
12998 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
13000 ID3D11SamplerState_Release(sampler[i]);
13003 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
13005 ID3D11ShaderResourceView_Release(srv[i]);
13008 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
13010 ID3D11UnorderedAccessView_Release(cs_uav[i]);
13011 ID3D11Buffer_Release(cs_uav_buffer[i]);
13013 ID3D11UnorderedAccessView_Release(ps_uav);
13014 ID3D11Buffer_Release(ps_uav_buffer);
13016 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
13018 ID3D11Buffer_Release(so_buffer[i]);
13021 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
13023 ID3D11Buffer_Release(buffer[i]);
13026 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
13028 ID3D11Buffer_Release(cb[i]);
13031 ID3D11DeviceContext_Release(context);
13032 refcount = ID3D11Device_Release(device);
13033 ok(!refcount, "Device has %u references left.\n", refcount);
13036 static void test_il_append_aligned(void)
13038 struct d3d11_test_context test_context;
13039 ID3D11InputLayout *input_layout;
13040 ID3D11DeviceContext *context;
13041 unsigned int stride, offset;
13042 ID3D11VertexShader *vs;
13043 ID3D11PixelShader *ps;
13044 ID3D11Device *device;
13045 ID3D11Buffer *vb[3];
13046 DWORD color;
13047 HRESULT hr;
13049 /* Semantic names are case-insensitive. */
13050 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13052 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
13053 D3D11_INPUT_PER_INSTANCE_DATA, 2},
13054 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
13055 D3D11_INPUT_PER_INSTANCE_DATA, 1},
13056 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
13057 D3D11_INPUT_PER_VERTEX_DATA, 0},
13058 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
13059 D3D11_INPUT_PER_INSTANCE_DATA, 1},
13060 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
13061 D3D11_INPUT_PER_INSTANCE_DATA, 2},
13063 static const DWORD vs_code[] =
13065 #if 0
13066 struct vs_in
13068 float4 position : POSITION;
13069 float2 color_xy : COLOR0;
13070 float2 color_zw : COLOR1;
13071 unsigned int instance_id : SV_INSTANCEID;
13074 struct vs_out
13076 float4 position : SV_POSITION;
13077 float2 color_xy : COLOR0;
13078 float2 color_zw : COLOR1;
13081 struct vs_out main(struct vs_in i)
13083 struct vs_out o;
13085 o.position = i.position;
13086 o.position.x += i.instance_id * 0.5;
13087 o.color_xy = i.color_xy;
13088 o.color_zw = i.color_zw;
13090 return o;
13092 #endif
13093 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
13094 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
13095 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
13096 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
13097 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
13098 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
13099 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
13100 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
13101 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
13102 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
13103 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
13104 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
13105 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
13106 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
13107 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
13108 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
13109 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
13111 static const DWORD ps_code[] =
13113 #if 0
13114 struct vs_out
13116 float4 position : SV_POSITION;
13117 float2 color_xy : COLOR0;
13118 float2 color_zw : COLOR1;
13121 float4 main(struct vs_out i) : SV_TARGET
13123 return float4(i.color_xy.xy, i.color_zw.xy);
13125 #endif
13126 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
13127 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
13128 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
13129 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
13130 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
13131 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
13132 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
13133 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13134 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
13136 static const struct
13138 struct vec4 position;
13140 stream0[] =
13142 {{-1.0f, -1.0f, 0.0f, 1.0f}},
13143 {{-1.0f, 1.0f, 0.0f, 1.0f}},
13144 {{-0.5f, -1.0f, 0.0f, 1.0f}},
13145 {{-0.5f, 1.0f, 0.0f, 1.0f}},
13147 static const struct
13149 struct vec2 color2;
13150 struct vec2 color1;
13152 stream1[] =
13154 {{0.5f, 0.5f}, {0.0f, 1.0f}},
13155 {{0.5f, 0.5f}, {1.0f, 1.0f}},
13157 static const struct
13159 struct vec2 color3;
13160 struct vec2 color0;
13162 stream2[] =
13164 {{0.5f, 0.5f}, {1.0f, 0.0f}},
13165 {{0.5f, 0.5f}, {0.0f, 1.0f}},
13166 {{0.5f, 0.5f}, {0.0f, 0.0f}},
13167 {{0.5f, 0.5f}, {1.0f, 0.0f}},
13169 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13171 if (!init_test_context(&test_context, NULL))
13172 return;
13174 device = test_context.device;
13175 context = test_context.immediate_context;
13177 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13178 vs_code, sizeof(vs_code), &input_layout);
13179 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13181 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
13182 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
13183 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
13185 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13186 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13187 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13188 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13190 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13191 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13192 offset = 0;
13193 stride = sizeof(*stream0);
13194 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
13195 stride = sizeof(*stream1);
13196 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
13197 stride = sizeof(*stream2);
13198 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
13199 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13200 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13202 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13204 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
13206 color = get_texture_color(test_context.backbuffer, 80, 240);
13207 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
13208 color = get_texture_color(test_context.backbuffer, 240, 240);
13209 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13210 color = get_texture_color(test_context.backbuffer, 400, 240);
13211 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13212 color = get_texture_color(test_context.backbuffer, 560, 240);
13213 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
13215 ID3D11PixelShader_Release(ps);
13216 ID3D11VertexShader_Release(vs);
13217 ID3D11Buffer_Release(vb[2]);
13218 ID3D11Buffer_Release(vb[1]);
13219 ID3D11Buffer_Release(vb[0]);
13220 ID3D11InputLayout_Release(input_layout);
13221 release_test_context(&test_context);
13224 static void test_instanced_draw(void)
13226 struct d3d11_test_context test_context;
13227 D3D11_TEXTURE2D_DESC texture_desc;
13228 ID3D11InputLayout *input_layout;
13229 ID3D11RenderTargetView *rtvs[2];
13230 ID3D11Texture2D *render_target;
13231 ID3D11DeviceContext *context;
13232 struct resource_readback rb;
13233 unsigned int stride, offset;
13234 ID3D11Buffer *args_buffer;
13235 ID3D11VertexShader *vs;
13236 ID3D11PixelShader *ps;
13237 ID3D11Device *device;
13238 ID3D11Buffer *vb[4];
13239 unsigned int i;
13240 HRESULT hr;
13242 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13244 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
13245 D3D11_INPUT_PER_VERTEX_DATA, 0},
13246 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT,
13247 D3D11_INPUT_PER_INSTANCE_DATA, 1},
13248 {"color", 1, DXGI_FORMAT_R8_UNORM, 2, D3D11_APPEND_ALIGNED_ELEMENT,
13249 D3D10_INPUT_PER_INSTANCE_DATA, 0},
13250 {"color", 2, DXGI_FORMAT_R8_UNORM, 3, D3D11_APPEND_ALIGNED_ELEMENT,
13251 D3D10_INPUT_PER_INSTANCE_DATA, 2},
13252 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
13253 D3D11_INPUT_PER_INSTANCE_DATA, 1},
13255 static const DWORD vs_code[] =
13257 #if 0
13258 struct vs_in
13260 float4 position : Position;
13261 float r : color0;
13262 float g : color1;
13263 float b : color2;
13264 float v_offset : V_Offset;
13265 uint instance_id : SV_InstanceId;
13268 struct vs_out
13270 float4 position : SV_Position;
13271 float r : color0;
13272 float g : color1;
13273 float b : color2;
13274 uint instance_id : InstanceId;
13277 void main(vs_in i, out vs_out o)
13279 o.position = i.position;
13280 o.position.x += i.v_offset;
13281 o.r = i.r;
13282 o.g = i.g;
13283 o.b = i.b;
13284 o.instance_id = i.instance_id;
13286 #endif
13287 0x43425844, 0x036df42e, 0xff0da346, 0x7b23a14a, 0xc26ec9be, 0x00000001, 0x000002bc, 0x00000003,
13288 0x0000002c, 0x000000f4, 0x0000019c, 0x4e475349, 0x000000c0, 0x00000006, 0x00000008, 0x00000098,
13289 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a1, 0x00000000, 0x00000000,
13290 0x00000003, 0x00000001, 0x00000101, 0x000000a1, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
13291 0x00000101, 0x000000a1, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000a7,
13292 0x00000000, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000b0, 0x00000000, 0x00000008,
13293 0x00000001, 0x00000005, 0x00000101, 0x69736f50, 0x6e6f6974, 0x6c6f6300, 0x5600726f, 0x66664f5f,
13294 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e, 0xabab0064, 0x4e47534f, 0x000000a0, 0x00000005,
13295 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c,
13296 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000008c, 0x00000001, 0x00000000,
13297 0x00000003, 0x00000001, 0x00000d02, 0x0000008c, 0x00000002, 0x00000000, 0x00000003, 0x00000001,
13298 0x00000b04, 0x00000092, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
13299 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
13300 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
13301 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
13302 0x00101012, 0x00000004, 0x04000060, 0x00101012, 0x00000005, 0x00000008, 0x04000067, 0x001020f2,
13303 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065, 0x00102022, 0x00000001,
13304 0x03000065, 0x00102042, 0x00000001, 0x03000065, 0x00102012, 0x00000002, 0x07000000, 0x00102012,
13305 0x00000000, 0x0010100a, 0x00000000, 0x0010100a, 0x00000004, 0x05000036, 0x001020e2, 0x00000000,
13306 0x00101e56, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x05000036,
13307 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042, 0x00000001, 0x0010100a,
13308 0x00000003, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x0100003e,
13310 static const DWORD ps_code[] =
13312 #if 0
13313 struct vs_out
13315 float4 position : SV_Position;
13316 float r : color0;
13317 float g : color1;
13318 float b : color2;
13319 uint instance_id : InstanceId;
13322 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
13324 o0 = float4(i.r, i.g, i.b, 1.0f);
13325 o1 = i.instance_id;
13327 #endif
13328 0x43425844, 0xc9f9c86d, 0xa24d87aa, 0xff75d05b, 0xfbe0581a, 0x00000001, 0x000001b8, 0x00000003,
13329 0x0000002c, 0x000000d4, 0x00000120, 0x4e475349, 0x000000a0, 0x00000005, 0x00000008, 0x00000080,
13330 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
13331 0x00000003, 0x00000001, 0x00000101, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
13332 0x00000202, 0x0000008c, 0x00000002, 0x00000000, 0x00000003, 0x00000001, 0x00000404, 0x00000092,
13333 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
13334 0x6f6c6f63, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x4e47534f, 0x00000044, 0x00000002,
13335 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000038,
13336 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
13337 0x52444853, 0x00000090, 0x00000040, 0x00000024, 0x03001062, 0x00101012, 0x00000001, 0x03001062,
13338 0x00101022, 0x00000001, 0x03001062, 0x00101042, 0x00000001, 0x03000862, 0x00101012, 0x00000002,
13339 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072,
13340 0x00000000, 0x00101246, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
13341 0x05000036, 0x001020f2, 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
13343 static const struct vec4 stream0[] =
13345 {-1.00f, 0.0f, 0.0f, 1.0f},
13346 {-1.00f, 1.0f, 0.0f, 1.0f},
13347 {-0.75f, 0.0f, 0.0f, 1.0f},
13348 {-0.75f, 1.0f, 0.0f, 1.0f},
13349 /* indirect draws data */
13350 {-1.00f, -1.0f, 0.0f, 1.0f},
13351 {-1.00f, 0.0f, 0.0f, 1.0f},
13352 {-0.75f, -1.0f, 0.0f, 1.0f},
13353 {-0.75f, 0.0f, 0.0f, 1.0f},
13355 static const struct
13357 BYTE red;
13358 float v_offset;
13360 stream1[] =
13362 {0xf0, 0.00f},
13363 {0x80, 0.25f},
13364 {0x10, 0.50f},
13365 {0x40, 0.75f},
13367 {0xaa, 1.00f},
13368 {0xbb, 1.25f},
13369 {0xcc, 1.50f},
13370 {0x90, 1.75f},
13372 static const BYTE stream2[] = {0xf0, 0x80, 0x10, 0x40, 0xaa, 0xbb, 0xcc, 0x90};
13373 static const BYTE stream3[] = {0xf0, 0x80, 0x10, 0x40, 0xaa, 0xbb, 0xcc, 0x90};
13374 static const D3D11_DRAW_INSTANCED_INDIRECT_ARGS argument_data[] =
13376 {4, 4, 4, 0},
13377 {4, 4, 4, 4},
13379 static const struct
13381 RECT rect;
13382 unsigned int color;
13383 unsigned int instance_id;
13385 expected_results[] =
13387 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
13388 {{ 80, 0, 160, 240}, 0xfff0f080, 1},
13389 {{160, 0, 240, 240}, 0xff80f010, 2},
13390 {{240, 0, 320, 240}, 0xff80f040, 3},
13391 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
13392 {{400, 0, 480, 240}, 0xffaaaabb, 1},
13393 {{480, 0, 560, 240}, 0xffbbaacc, 2},
13394 {{560, 0, 640, 240}, 0xffbbaa90, 3},
13395 /* indirect draws results */
13396 {{ 0, 240, 80, 480}, 0xfff0f0f0, 0},
13397 {{ 80, 240, 160, 480}, 0xfff0f080, 1},
13398 {{160, 240, 240, 480}, 0xff80f010, 2},
13399 {{240, 240, 320, 480}, 0xff80f040, 3},
13400 {{320, 240, 400, 480}, 0xffaaaaaa, 0},
13401 {{400, 240, 480, 480}, 0xffaaaabb, 1},
13402 {{480, 240, 560, 480}, 0xffbbaacc, 2},
13403 {{560, 240, 640, 480}, 0xffbbaa90, 3},
13405 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13406 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13408 if (!init_test_context(&test_context, &feature_level))
13409 return;
13410 device = test_context.device;
13411 context = test_context.immediate_context;
13413 rtvs[0] = test_context.backbuffer_rtv;
13415 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13416 texture_desc.Format = DXGI_FORMAT_R32_UINT;
13417 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
13418 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13419 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtvs[1]);
13420 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13422 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13423 vs_code, sizeof(vs_code), &input_layout);
13424 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13426 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13427 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13428 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13429 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13431 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
13432 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
13433 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
13434 vb[3] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream3), stream3);
13436 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13437 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13438 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13439 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13440 offset = 0;
13441 stride = sizeof(*stream0);
13442 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
13443 stride = sizeof(*stream1);
13444 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
13445 stride = sizeof(*stream2);
13446 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
13447 stride = sizeof(*stream3);
13448 ID3D11DeviceContext_IASetVertexBuffers(context, 3, 1, &vb[3], &stride, &offset);
13450 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
13451 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[1], white);
13453 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
13454 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
13455 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 4);
13457 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
13458 sizeof(argument_data), argument_data);
13460 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, 0);
13461 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, sizeof(*argument_data));
13463 get_texture_readback(test_context.backbuffer, 0, &rb);
13464 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
13465 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
13466 release_resource_readback(&rb);
13468 get_texture_readback(render_target, 0, &rb);
13469 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
13470 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
13471 release_resource_readback(&rb);
13473 ID3D11Buffer_Release(vb[0]);
13474 ID3D11Buffer_Release(vb[1]);
13475 ID3D11Buffer_Release(vb[2]);
13476 ID3D11Buffer_Release(vb[3]);
13477 ID3D11Buffer_Release(args_buffer);
13478 ID3D11RenderTargetView_Release(rtvs[1]);
13479 ID3D11Texture2D_Release(render_target);
13480 ID3D11VertexShader_Release(vs);
13481 ID3D11PixelShader_Release(ps);
13482 ID3D11InputLayout_Release(input_layout);
13483 release_test_context(&test_context);
13486 static void test_vertex_id(void)
13488 static const DWORD vs_code[] =
13490 #if 0
13491 uint4 main(uint id : ID, uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID) : OUTPUT
13493 return uint4(id, instance_id, vertex_id, 0);
13495 #endif
13496 0x43425844, 0x5625197b, 0x588ccf8f, 0x48694905, 0x961d19ca, 0x00000001, 0x00000170, 0x00000003,
13497 0x0000002c, 0x000000a4, 0x000000d4, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
13498 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000101, 0x00000053, 0x00000000, 0x00000008,
13499 0x00000001, 0x00000001, 0x00000101, 0x00000061, 0x00000000, 0x00000006, 0x00000001, 0x00000002,
13500 0x00000101, 0x53004449, 0x6e495f56, 0x6e617473, 0x44496563, 0x5f565300, 0x74726556, 0x44497865,
13501 0xababab00, 0x4e47534f, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
13502 0x00000001, 0x00000000, 0x0000000f, 0x5054554f, 0xab005455, 0x52444853, 0x00000094, 0x00010040,
13503 0x00000025, 0x0300005f, 0x00101012, 0x00000000, 0x04000060, 0x00101012, 0x00000001, 0x00000008,
13504 0x04000060, 0x00101012, 0x00000002, 0x00000006, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
13505 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010100a,
13506 0x00000001, 0x05000036, 0x00102042, 0x00000000, 0x0010100a, 0x00000002, 0x05000036, 0x00102082,
13507 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
13509 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13511 {"ID", 0, DXGI_FORMAT_R32_UINT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
13513 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
13515 {0, "OUTPUT", 0, 0, 4, 0},
13517 static const unsigned int vertices[] =
13535 static const unsigned int indices[] =
13537 6, 7, 8,
13539 0, 1, 2,
13541 struct uvec4 expected_values[] =
13543 {0, 0, 0},
13544 {1, 0, 1},
13545 {2, 0, 2},
13546 {0, 1, 0},
13547 {1, 1, 1},
13548 {2, 1, 2},
13550 {3, 0, 0},
13551 {4, 0, 1},
13552 {5, 0, 2},
13554 {6, 0, 6},
13555 {7, 0, 7},
13556 {8, 0, 8},
13557 {6, 1, 6},
13558 {7, 1, 7},
13559 {8, 1, 8},
13561 {5, 0, 0},
13562 {6, 0, 1},
13563 {7, 0, 2},
13566 BOOL found_values[ARRAY_SIZE(expected_values)] = {0};
13567 BOOL used_values[ARRAY_SIZE(expected_values)] = {0};
13568 struct d3d11_test_context test_context;
13569 D3D11_QUERY_DATA_SO_STATISTICS data;
13570 ID3D11Buffer *vb, *ib, *so_buffer;
13571 ID3D11InputLayout *input_layout;
13572 ID3D11DeviceContext *context;
13573 D3D11_QUERY_DESC query_desc;
13574 struct resource_readback rb;
13575 unsigned int stride, offset;
13576 ID3D11Asynchronous *query;
13577 ID3D11GeometryShader *gs;
13578 ID3D11VertexShader *vs;
13579 ID3D11Device *device;
13580 unsigned int count;
13581 unsigned int i, j;
13582 HRESULT hr;
13584 if (!init_test_context(&test_context, NULL))
13585 return;
13586 device = test_context.device;
13587 context = test_context.immediate_context;
13589 query_desc.Query = D3D11_QUERY_SO_STATISTICS;
13590 query_desc.MiscFlags = 0;
13591 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
13592 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
13594 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13595 vs_code, sizeof(vs_code), &input_layout);
13596 ok(hr == S_OK, "Failed to create input layout, hr %#x.\n", hr);
13598 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13599 ok(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
13601 stride = 16;
13602 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
13603 so_declaration, ARRAY_SIZE(so_declaration), &stride, 1, 0, NULL, &gs);
13604 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
13606 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13607 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
13608 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
13610 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13611 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
13612 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13613 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
13614 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
13615 offset = 0;
13616 stride = sizeof(*vertices);
13617 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
13619 offset = 0;
13620 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
13622 ID3D11DeviceContext_Begin(context, query);
13624 ID3D11DeviceContext_DrawInstanced(context, 3, 2, 0, 0);
13625 ID3D11DeviceContext_DrawInstanced(context, 3, 1, 3, 16);
13627 ID3D11DeviceContext_DrawIndexedInstanced(context, 3, 2, 0, 0, 0);
13628 ID3D11DeviceContext_DrawIndexedInstanced(context, 3, 1, 3, 9, 7);
13630 ID3D11DeviceContext_End(context, query);
13632 get_query_data(context, query, &data, sizeof(data));
13633 count = data.NumPrimitivesWritten;
13634 ok(count == ARRAY_SIZE(expected_values), "Got unexpected value %u.\n", count);
13636 count = min(count, ARRAY_SIZE(used_values));
13637 get_buffer_readback(so_buffer, &rb);
13638 for (i = 0; i < ARRAY_SIZE(expected_values); ++i)
13640 for (j = 0; j < count; ++j)
13642 if (!used_values[j] && compare_uvec4(get_readback_uvec4(&rb, j, 0), &expected_values[i]))
13644 found_values[i] = TRUE;
13645 used_values[j] = TRUE;
13646 break;
13651 for (i = 0; i < count; ++i)
13653 const struct uvec4 *v = get_readback_uvec4(&rb, i, 0);
13654 ok(used_values[i], "Found unexpected value {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n", v->x, v->y, v->z, v->w);
13656 release_resource_readback(&rb);
13658 for (i = 0; i < ARRAY_SIZE(expected_values); ++i)
13660 ok(found_values[i], "Failed to find value {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n",
13661 expected_values[i].x, expected_values[i].y, expected_values[i].z, expected_values[i].w);
13664 ID3D11Asynchronous_Release(query);
13665 ID3D11Buffer_Release(so_buffer);
13666 ID3D11Buffer_Release(vb);
13667 ID3D11Buffer_Release(ib);
13668 ID3D11GeometryShader_Release(gs);
13669 ID3D11VertexShader_Release(vs);
13670 ID3D11InputLayout_Release(input_layout);
13671 release_test_context(&test_context);
13674 static void test_fragment_coords(void)
13676 struct d3d11_test_context test_context;
13677 ID3D11PixelShader *ps, *ps_frac;
13678 ID3D11DeviceContext *context;
13679 ID3D11Device *device;
13680 ID3D11Buffer *ps_cb;
13681 DWORD color;
13682 HRESULT hr;
13684 static const DWORD ps_code[] =
13686 #if 0
13687 float2 cutoff;
13689 float4 main(float4 position : SV_POSITION) : SV_TARGET
13691 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
13693 if (position.x > cutoff.x)
13694 ret.y = 1.0;
13695 if (position.y > cutoff.y)
13696 ret.z = 1.0;
13698 return ret;
13700 #endif
13701 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
13702 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13703 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13704 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13705 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
13706 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
13707 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
13708 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
13709 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
13710 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
13711 0x0100003e,
13713 static const DWORD ps_frac_code[] =
13715 #if 0
13716 float4 main(float4 position : SV_POSITION) : SV_TARGET
13718 return float4(frac(position.xy), 0.0, 1.0);
13720 #endif
13721 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
13722 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13723 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13724 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13725 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
13726 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13727 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
13728 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
13730 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13731 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
13733 if (!init_test_context(&test_context, NULL))
13734 return;
13736 device = test_context.device;
13737 context = test_context.immediate_context;
13739 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
13741 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13742 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13743 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
13744 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13746 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
13747 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13749 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13751 draw_quad(&test_context);
13753 color = get_texture_color(test_context.backbuffer, 319, 239);
13754 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
13755 color = get_texture_color(test_context.backbuffer, 320, 239);
13756 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13757 color = get_texture_color(test_context.backbuffer, 319, 240);
13758 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13759 color = get_texture_color(test_context.backbuffer, 320, 240);
13760 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
13762 ID3D11Buffer_Release(ps_cb);
13763 cutoff.x = 16.0f;
13764 cutoff.y = 16.0f;
13765 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
13766 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
13768 draw_quad(&test_context);
13770 color = get_texture_color(test_context.backbuffer, 14, 14);
13771 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
13772 color = get_texture_color(test_context.backbuffer, 18, 14);
13773 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13774 color = get_texture_color(test_context.backbuffer, 14, 18);
13775 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13776 color = get_texture_color(test_context.backbuffer, 18, 18);
13777 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
13779 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
13780 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13782 ID3D11DeviceContext_Draw(context, 4, 0);
13784 color = get_texture_color(test_context.backbuffer, 14, 14);
13785 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
13787 ID3D11Buffer_Release(ps_cb);
13788 ID3D11PixelShader_Release(ps_frac);
13789 ID3D11PixelShader_Release(ps);
13790 release_test_context(&test_context);
13793 static void test_initial_texture_data(void)
13795 ID3D11Texture2D *texture, *staging_texture;
13796 struct d3d11_test_context test_context;
13797 D3D11_SUBRESOURCE_DATA resource_data;
13798 D3D11_TEXTURE2D_DESC texture_desc;
13799 ID3D11SamplerState *sampler_state;
13800 ID3D11ShaderResourceView *ps_srv;
13801 D3D11_SAMPLER_DESC sampler_desc;
13802 ID3D11DeviceContext *context;
13803 struct resource_readback rb;
13804 ID3D11PixelShader *ps;
13805 ID3D11Device *device;
13806 unsigned int i, j;
13807 DWORD color;
13808 HRESULT hr;
13810 static const DWORD ps_code[] =
13812 #if 0
13813 Texture2D t;
13814 SamplerState s;
13816 float4 main(float4 position : SV_POSITION) : SV_Target
13818 float2 p;
13820 p.x = position.x / 640.0f;
13821 p.y = position.y / 480.0f;
13822 return t.Sample(s, p);
13824 #endif
13825 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13826 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13827 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13828 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13829 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13830 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13831 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13832 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13833 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13834 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13836 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13837 static const DWORD bitmap_data[] =
13839 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
13840 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
13841 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
13842 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
13845 if (!init_test_context(&test_context, NULL))
13846 return;
13848 device = test_context.device;
13849 context = test_context.immediate_context;
13851 texture_desc.Width = 4;
13852 texture_desc.Height = 4;
13853 texture_desc.MipLevels = 1;
13854 texture_desc.ArraySize = 1;
13855 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13856 texture_desc.SampleDesc.Count = 1;
13857 texture_desc.SampleDesc.Quality = 0;
13858 texture_desc.Usage = D3D11_USAGE_STAGING;
13859 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
13860 texture_desc.BindFlags = 0;
13861 texture_desc.MiscFlags = 0;
13863 resource_data.pSysMem = bitmap_data;
13864 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
13865 resource_data.SysMemSlicePitch = 0;
13867 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &staging_texture);
13868 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
13870 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13871 texture_desc.CPUAccessFlags = 0;
13872 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13873 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13874 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
13876 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)texture, (ID3D11Resource *)staging_texture);
13878 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
13879 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
13881 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
13882 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
13883 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
13884 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
13885 sampler_desc.MipLODBias = 0.0f;
13886 sampler_desc.MaxAnisotropy = 0;
13887 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
13888 sampler_desc.BorderColor[0] = 0.0f;
13889 sampler_desc.BorderColor[1] = 0.0f;
13890 sampler_desc.BorderColor[2] = 0.0f;
13891 sampler_desc.BorderColor[3] = 0.0f;
13892 sampler_desc.MinLOD = 0.0f;
13893 sampler_desc.MaxLOD = 0.0f;
13894 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
13895 ok(hr == S_OK, "Failed to create sampler state, hr %#x.\n", hr);
13897 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13898 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
13900 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
13901 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
13902 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13904 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13905 draw_quad(&test_context);
13906 get_texture_readback(test_context.backbuffer, 0, &rb);
13907 for (i = 0; i < 4; ++i)
13909 for (j = 0; j < 4; ++j)
13911 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13912 ok(compare_color(color, bitmap_data[j + i * 4], 1),
13913 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13914 color, j, i, bitmap_data[j + i * 4]);
13917 release_resource_readback(&rb);
13919 ID3D11PixelShader_Release(ps);
13920 ID3D11SamplerState_Release(sampler_state);
13921 ID3D11ShaderResourceView_Release(ps_srv);
13922 ID3D11Texture2D_Release(staging_texture);
13923 ID3D11Texture2D_Release(texture);
13924 release_test_context(&test_context);
13927 static void test_update_subresource(void)
13929 struct d3d11_test_context test_context;
13930 D3D11_SUBRESOURCE_DATA resource_data;
13931 D3D11_TEXTURE3D_DESC texture_desc_3d;
13932 D3D11_TEXTURE2D_DESC texture_desc;
13933 ID3D11SamplerState *sampler_state;
13934 ID3D11ShaderResourceView *ps_srv;
13935 D3D11_SAMPLER_DESC sampler_desc;
13936 ID3D11DeviceContext *context;
13937 struct resource_readback rb;
13938 ID3D11Texture3D *texture_3d;
13939 ID3D11Texture2D *texture;
13940 ID3D11PixelShader *ps;
13941 ID3D11Device *device;
13942 unsigned int i, j;
13943 D3D11_BOX box;
13944 DWORD color;
13945 HRESULT hr;
13947 static const DWORD ps_code[] =
13949 #if 0
13950 Texture2D t;
13951 SamplerState s;
13953 float4 main(float4 position : SV_POSITION) : SV_Target
13955 float2 p;
13957 p.x = position.x / 640.0f;
13958 p.y = position.y / 480.0f;
13959 return t.Sample(s, p);
13961 #endif
13962 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13963 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13964 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13965 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13966 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13967 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13968 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13969 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13970 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13971 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13973 static const DWORD ps_code_3d[] =
13975 #if 0
13976 Texture3D t;
13977 SamplerState s;
13979 float4 main(float4 position : SV_POSITION) : SV_Target
13981 float3 p1, p2;
13982 p2.x = p1.x = position.x / 640.0f;
13983 p2.y = p1.y = position.y / 480.0f;
13984 p1.z = 0.25;
13985 p2.z = 0.75;
13986 return 0.5 * (t.Sample(s, p1) + t.Sample(s, p2));
13988 #endif
13989 0x43425844, 0x4d466d63, 0xa3d10db1, 0xd6534470, 0x16d738ef, 0x00000001, 0x000001ec, 0x00000003,
13990 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13991 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13992 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13993 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000150, 0x00000040,
13994 0x00000054, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
13995 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13996 0x00000002, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13997 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3e800000,
13998 0x09000045, 0x001000f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
13999 0x00000000, 0x0a000038, 0x00100032, 0x00000001, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
14000 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000001, 0x00004001, 0x3f400000,
14001 0x09000045, 0x001000f2, 0x00000001, 0x00100246, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
14002 0x00000000, 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
14003 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000,
14004 0x3f000000, 0x3f000000, 0x0100003e,
14006 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
14007 static const DWORD initial_data[32] = {0};
14008 static const DWORD bitmap_data[] =
14010 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14011 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14012 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14013 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14015 static const DWORD expected_colors[] =
14017 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
14018 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
14019 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
14020 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
14022 static const DWORD bc7_data[] =
14024 0x3a7b944b, 0x982a5800, 0x9cab4983, 0xc6a09579,
14025 0x5f7f2bfe, 0xa95d98f2, 0x3bfb4c03, 0x8be16a41,
14026 0x8362e6c0, 0x358ed7a2, 0xec3e130b, 0x86cebc86,
14027 0xf045be66, 0x7a16507f, 0xfe9ccc9f, 0x3f103e16,
14028 0x84d466c5, 0xfaf5cb5a, 0x9b9e1859, 0x384589b0,
14029 0x9268b4b8, 0x212b3643, 0x813f853a, 0x4a2bd7c2,
14030 0x1809f3e0, 0xf646d5ef, 0x40e80679, 0x05791fe5,
14031 0x6604e7e5, 0x5c28b55d, 0x1ef211f5, 0x632d47f6,
14033 static const DWORD bc7_expected_colors[] =
14035 0xc1752752, 0xc39859a9, 0xff79c08e, 0xff63bf6c,
14036 0xbf7d2756, 0xb89f3d40, 0xffda3a77, 0xffd08099,
14037 0x415f1f37, 0x43671d3f, 0xffc64758, 0xff57a194,
14038 0x405a2032, 0x39422619, 0xff749b76, 0xffabb879,
14040 static const DWORD expected_colors_3d[] = { 0xffff8000, 0xffff8080, 0x80008000, 0xff8080ff };
14042 if (!init_test_context(&test_context, NULL))
14043 return;
14045 device = test_context.device;
14046 context = test_context.immediate_context;
14048 texture_desc.Width = 4;
14049 texture_desc.Height = 4;
14050 texture_desc.MipLevels = 1;
14051 texture_desc.ArraySize = 1;
14052 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14053 texture_desc.SampleDesc.Count = 1;
14054 texture_desc.SampleDesc.Quality = 0;
14055 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14056 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14057 texture_desc.CPUAccessFlags = 0;
14058 texture_desc.MiscFlags = 0;
14060 resource_data.pSysMem = initial_data;
14061 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
14062 resource_data.SysMemSlicePitch = 0;
14064 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
14065 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14067 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
14068 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14070 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14071 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14072 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14073 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14074 sampler_desc.MipLODBias = 0.0f;
14075 sampler_desc.MaxAnisotropy = 0;
14076 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14077 sampler_desc.BorderColor[0] = 0.0f;
14078 sampler_desc.BorderColor[1] = 0.0f;
14079 sampler_desc.BorderColor[2] = 0.0f;
14080 sampler_desc.BorderColor[3] = 0.0f;
14081 sampler_desc.MinLOD = 0.0f;
14082 sampler_desc.MaxLOD = 0.0f;
14084 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
14085 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14087 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14088 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14090 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14091 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14092 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14094 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14095 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
14097 draw_quad(&test_context);
14098 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14100 set_box(&box, 1, 1, 0, 3, 3, 1);
14101 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
14102 bitmap_data, 4 * sizeof(*bitmap_data), 0);
14103 set_box(&box, 0, 3, 0, 3, 4, 1);
14104 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
14105 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
14106 set_box(&box, 0, 0, 0, 4, 1, 1);
14107 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
14108 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
14109 set_box(&box, 0, 1, 0, 1, 3, 1);
14110 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
14111 &bitmap_data[2], sizeof(*bitmap_data), 0);
14112 set_box(&box, 4, 4, 0, 3, 1, 1);
14113 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
14114 bitmap_data, sizeof(*bitmap_data), 0);
14115 set_box(&box, 0, 0, 0, 4, 4, 0);
14116 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
14117 bitmap_data, 4 * sizeof(*bitmap_data), 0);
14118 draw_quad(&test_context);
14119 get_texture_readback(test_context.backbuffer, 0, &rb);
14120 for (i = 0; i < 4; ++i)
14122 for (j = 0; j < 4; ++j)
14124 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14125 ok(compare_color(color, expected_colors[j + i * 4], 1),
14126 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14127 color, j, i, expected_colors[j + i * 4]);
14130 release_resource_readback(&rb);
14132 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
14133 bitmap_data, 4 * sizeof(*bitmap_data), 0);
14134 draw_quad(&test_context);
14135 get_texture_readback(test_context.backbuffer, 0, &rb);
14136 for (i = 0; i < 4; ++i)
14138 for (j = 0; j < 4; ++j)
14140 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14141 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14142 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14143 color, j, i, bitmap_data[j + i * 4]);
14146 release_resource_readback(&rb);
14148 ID3D11ShaderResourceView_Release(ps_srv);
14149 ID3D11Texture2D_Release(texture);
14150 ID3D11PixelShader_Release(ps);
14152 hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps);
14153 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14155 texture_desc_3d.Width = 2;
14156 texture_desc_3d.Height = 2;
14157 texture_desc_3d.Depth = 2;
14158 texture_desc_3d.MipLevels = 1;
14159 texture_desc_3d.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14160 texture_desc_3d.Usage = D3D11_USAGE_DEFAULT;
14161 texture_desc_3d.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14162 texture_desc_3d.CPUAccessFlags = 0;
14163 texture_desc_3d.MiscFlags = 0;
14165 resource_data.SysMemPitch = texture_desc_3d.Width * sizeof(*initial_data);
14166 resource_data.SysMemSlicePitch = texture_desc_3d.Width * texture_desc_3d.Height * sizeof(*initial_data);
14168 hr = ID3D11Device_CreateTexture3D(device, &texture_desc_3d, &resource_data, &texture_3d);
14169 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
14171 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture_3d, NULL, &ps_srv);
14172 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14174 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14175 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14177 set_box(&box, 0, 0, 0, 1, 2, 1);
14178 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data, 8, 16);
14179 set_box(&box, 0, 0, 0, 1, 1, 2);
14180 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 4, 16, 32);
14181 set_box(&box, 1, 0, 0, 2, 1, 2);
14182 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 8, 4, 0);
14183 set_box(&box, 0, 0, 1, 2, 1, 2);
14184 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 2, 4, 5);
14185 set_box(&box, 0, 0, 1, 2, 1, 2);
14186 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 3, 12, 0);
14187 set_box(&box, 1, 1, 0, 2, 2, 2);
14188 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data, 0, 32);
14190 draw_quad(&test_context);
14191 get_texture_readback(test_context.backbuffer, 0, &rb);
14192 for (i = 0; i < 2; ++i)
14194 for (j = 0; j < 2; ++j)
14196 color = get_readback_color(&rb, 160 + j * 320, 120 + i * 240, 0);
14197 ok(compare_color(color, expected_colors_3d[j + i * 2], 1),
14198 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14199 color, j, i, expected_colors_3d[j + i * 2]);
14202 release_resource_readback(&rb);
14203 ID3D11ShaderResourceView_Release(ps_srv);
14204 ID3D11Texture3D_Release(texture_3d);
14206 texture_desc_3d.Width = 8;
14207 texture_desc_3d.Height = 8;
14208 texture_desc_3d.Depth = 2;
14209 texture_desc_3d.Format = DXGI_FORMAT_BC7_UNORM;
14211 resource_data.SysMemPitch = 32;
14212 resource_data.SysMemSlicePitch = 64;
14214 hr = ID3D11Device_CreateTexture3D(device, &texture_desc_3d, &resource_data, &texture_3d);
14215 if (FAILED(hr))
14217 skip("Failed to create BC7 3d texture, hr %#x.\n", hr);
14219 else
14221 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture_3d, NULL, &ps_srv);
14222 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14224 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14225 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14227 set_box(&box, 0, 0, 0, 8, 8, 2);
14228 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data, 32, 64);
14229 set_box(&box, 0, 0, 1, 8, 8, 2);
14230 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data, 16, 0);
14231 set_box(&box, 0, 0, 0, 4, 4, 1);
14232 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 8, 0, 0);
14233 set_box(&box, 4, 4, 0, 8, 8, 2);
14234 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 16, 0, 16);
14235 set_box(&box, 0, 4, 1, 8, 8, 2);
14236 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 1, 4, 32);
14237 set_box(&box, 4, 0, 0, 8, 4, 2);
14238 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 2, 0, 1);
14240 draw_quad(&test_context);
14241 get_texture_readback(test_context.backbuffer, 0, &rb);
14242 for (i = 0; i < 4; ++i)
14244 for (j = 0; j < 4; ++j)
14246 color = get_readback_color(&rb, 70 + j * 160, 50 + i * 120, 0);
14247 ok(compare_color(color, bc7_expected_colors[j + i * 4], 1),
14248 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14249 color, j, i, bc7_expected_colors[j + i * 4]);
14252 release_resource_readback(&rb);
14253 ID3D11ShaderResourceView_Release(ps_srv);
14254 ID3D11Texture3D_Release(texture_3d);
14257 ID3D11PixelShader_Release(ps);
14258 ID3D11SamplerState_Release(sampler_state);
14259 release_test_context(&test_context);
14262 static void test_copy_subresource_region(void)
14264 ID3D11Texture2D *dst_texture, *src_texture;
14265 struct d3d11_test_context test_context;
14266 ID3D11Buffer *dst_buffer, *src_buffer;
14267 D3D11_SUBRESOURCE_DATA resource_data;
14268 D3D11_TEXTURE2D_DESC texture_desc;
14269 ID3D11SamplerState *sampler_state;
14270 ID3D11ShaderResourceView *ps_srv;
14271 D3D11_SAMPLER_DESC sampler_desc;
14272 ID3D11DeviceContext1 *context1;
14273 ID3D11DeviceContext *context;
14274 struct vec4 float_colors[16];
14275 struct resource_readback rb;
14276 ID3D11PixelShader *ps;
14277 ID3D11Device *device;
14278 unsigned int i, j;
14279 D3D11_BOX box;
14280 DWORD color;
14281 HRESULT hr;
14283 static const DWORD ps_code[] =
14285 #if 0
14286 Texture2D t;
14287 SamplerState s;
14289 float4 main(float4 position : SV_POSITION) : SV_Target
14291 float2 p;
14293 p.x = position.x / 640.0f;
14294 p.y = position.y / 480.0f;
14295 return t.Sample(s, p);
14297 #endif
14298 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
14299 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14300 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14301 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14302 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
14303 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
14304 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14305 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
14306 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
14307 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
14309 static const DWORD ps_buffer_code[] =
14311 #if 0
14312 float4 buffer[16];
14314 float4 main(float4 position : SV_POSITION) : SV_TARGET
14316 float2 p = (float2)4;
14317 p *= float2(position.x / 640.0f, position.y / 480.0f);
14318 return buffer[(int)p.y * 4 + (int)p.x];
14320 #endif
14321 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
14322 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14323 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14324 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14325 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
14326 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
14327 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
14328 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
14329 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
14330 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
14331 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
14332 0x0010000a, 0x00000000, 0x0100003e,
14334 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
14335 static const DWORD initial_data[16] = {0};
14336 static const DWORD bitmap_data[] =
14338 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14339 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14340 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14341 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14343 static const DWORD expected_colors[] =
14345 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14346 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
14347 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
14348 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
14351 if (!init_test_context(&test_context, NULL))
14352 return;
14354 device = test_context.device;
14355 context = test_context.immediate_context;
14357 texture_desc.Width = 4;
14358 texture_desc.Height = 4;
14359 texture_desc.MipLevels = 1;
14360 texture_desc.ArraySize = 1;
14361 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14362 texture_desc.SampleDesc.Count = 1;
14363 texture_desc.SampleDesc.Quality = 0;
14364 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14365 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14366 texture_desc.CPUAccessFlags = 0;
14367 texture_desc.MiscFlags = 0;
14369 resource_data.pSysMem = initial_data;
14370 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
14371 resource_data.SysMemSlicePitch = 0;
14373 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
14374 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14376 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
14378 resource_data.pSysMem = bitmap_data;
14379 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
14380 resource_data.SysMemSlicePitch = 0;
14382 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
14383 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14385 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
14386 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14388 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14389 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14390 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14391 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14392 sampler_desc.MipLODBias = 0.0f;
14393 sampler_desc.MaxAnisotropy = 0;
14394 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14395 sampler_desc.BorderColor[0] = 0.0f;
14396 sampler_desc.BorderColor[1] = 0.0f;
14397 sampler_desc.BorderColor[2] = 0.0f;
14398 sampler_desc.BorderColor[3] = 0.0f;
14399 sampler_desc.MinLOD = 0.0f;
14400 sampler_desc.MaxLOD = 0.0f;
14402 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
14403 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14405 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14406 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14408 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14409 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14410 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14412 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14414 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14415 1, 1, 0, NULL, 0, &box);
14416 ID3D11DeviceContext_CopySubresourceRegion(context, NULL, 0,
14417 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14419 set_box(&box, 0, 0, 0, 2, 2, 1);
14420 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14421 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14422 set_box(&box, 1, 2, 0, 4, 3, 1);
14423 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14424 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
14425 set_box(&box, 0, 3, 0, 4, 4, 1);
14426 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14427 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14428 set_box(&box, 3, 0, 0, 4, 2, 1);
14429 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14430 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14431 set_box(&box, 3, 1, 0, 4, 2, 1);
14432 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14433 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
14434 set_box(&box, 0, 0, 0, 4, 4, 0);
14435 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14436 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14437 draw_quad(&test_context);
14438 get_texture_readback(test_context.backbuffer, 0, &rb);
14439 for (i = 0; i < 4; ++i)
14441 for (j = 0; j < 4; ++j)
14443 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14444 ok(compare_color(color, expected_colors[j + i * 4], 1),
14445 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14446 color, j, i, expected_colors[j + i * 4]);
14449 release_resource_readback(&rb);
14451 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14452 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
14453 draw_quad(&test_context);
14454 get_texture_readback(test_context.backbuffer, 0, &rb);
14455 for (i = 0; i < 4; ++i)
14457 for (j = 0; j < 4; ++j)
14459 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14460 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14461 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14462 color, j, i, bitmap_data[j + i * 4]);
14465 release_resource_readback(&rb);
14467 hr = ID3D11DeviceContext_QueryInterface(context, &IID_ID3D11DeviceContext1, (void **)&context1);
14468 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
14469 "Failed to query ID3D11DeviceContext1, hr %#x.\n", hr);
14471 if (SUCCEEDED(hr))
14473 ID3D11DeviceContext1_ClearRenderTargetView(context1, test_context.backbuffer_rtv, red);
14474 check_texture_color(test_context.backbuffer, 0x800000ff, 2);
14476 memset(float_colors, 0, sizeof(float_colors));
14477 for (i = 0; i < texture_desc.Width; ++i)
14478 ((unsigned int *)float_colors)[i] = 0x45454545;
14480 ID3D11DeviceContext1_UpdateSubresource1(context1, (ID3D11Resource *)dst_texture, 0, NULL,
14481 float_colors, 0, 0, 0);
14482 draw_quad(&test_context);
14483 check_texture_color(test_context.backbuffer, 0x45454545, 1);
14485 ID3D11DeviceContext1_CopySubresourceRegion1(context1, (ID3D11Resource *)dst_texture, 0,
14486 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL, 0);
14487 draw_quad(&test_context);
14489 get_texture_readback(test_context.backbuffer, 0, &rb);
14490 for (i = 0; i < 4; ++i)
14492 for (j = 0; j < 4; ++j)
14494 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14495 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14496 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14497 color, j, i, bitmap_data[j + i * 4]);
14500 release_resource_readback(&rb);
14502 ID3D11DeviceContext1_Release(context1);
14506 ID3D11PixelShader_Release(ps);
14507 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
14508 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14510 ID3D11ShaderResourceView_Release(ps_srv);
14511 ps_srv = NULL;
14513 ID3D11SamplerState_Release(sampler_state);
14514 sampler_state = NULL;
14516 ID3D11Texture2D_Release(dst_texture);
14517 ID3D11Texture2D_Release(src_texture);
14519 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14520 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14521 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14523 memset(float_colors, 0, sizeof(float_colors));
14524 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
14525 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
14527 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
14529 for (i = 0; i < 4; ++i)
14531 for (j = 0; j < 4; ++j)
14533 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
14534 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
14535 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
14536 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
14539 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
14540 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
14542 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
14543 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14544 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14545 draw_quad(&test_context);
14546 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14548 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
14549 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14550 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14551 draw_quad(&test_context);
14552 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14554 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
14555 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14556 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14557 draw_quad(&test_context);
14558 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14560 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
14561 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14562 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14563 draw_quad(&test_context);
14564 get_texture_readback(test_context.backbuffer, 0, &rb);
14565 for (i = 0; i < 4; ++i)
14567 for (j = 0; j < 4; ++j)
14569 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14570 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14571 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14572 color, j, i, bitmap_data[j + i * 4]);
14575 release_resource_readback(&rb);
14577 ID3D11Buffer_Release(dst_buffer);
14578 ID3D11Buffer_Release(src_buffer);
14579 ID3D11PixelShader_Release(ps);
14580 release_test_context(&test_context);
14583 static void test_copy_subresource_region_1d(void)
14585 D3D11_SUBRESOURCE_DATA resource_data[4];
14586 struct d3d11_test_context test_context;
14587 D3D11_TEXTURE1D_DESC texture1d_desc;
14588 D3D11_TEXTURE2D_DESC texture2d_desc;
14589 ID3D11DeviceContext *context;
14590 struct resource_readback rb;
14591 ID3D11Texture1D *texture1d;
14592 ID3D11Texture2D *texture2d;
14593 ID3D11Device *device;
14594 unsigned int i, j;
14595 D3D11_BOX box;
14596 DWORD color;
14597 HRESULT hr;
14599 static const DWORD bitmap_data[] =
14601 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14602 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14603 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14604 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14607 if (!init_test_context(&test_context, NULL))
14608 return;
14609 device = test_context.device;
14610 context = test_context.immediate_context;
14612 texture1d_desc.Width = 4;
14613 texture1d_desc.MipLevels = 1;
14614 texture1d_desc.ArraySize = 4;
14615 texture1d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14616 texture1d_desc.Usage = D3D11_USAGE_DEFAULT;
14617 texture1d_desc.BindFlags = 0;
14618 texture1d_desc.CPUAccessFlags = 0;
14619 texture1d_desc.MiscFlags = 0;
14621 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14623 resource_data[i].pSysMem = &bitmap_data[4 * i];
14624 resource_data[i].SysMemPitch = texture1d_desc.Width * sizeof(bitmap_data);
14625 resource_data[i].SysMemSlicePitch = 0;
14628 hr = ID3D11Device_CreateTexture1D(device, &texture1d_desc, resource_data, &texture1d);
14629 ok(hr == S_OK, "Failed to create 1d texture, hr %#x.\n", hr);
14631 texture2d_desc.Width = 4;
14632 texture2d_desc.Height = 4;
14633 texture2d_desc.MipLevels = 1;
14634 texture2d_desc.ArraySize = 1;
14635 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14636 texture2d_desc.SampleDesc.Count = 1;
14637 texture2d_desc.SampleDesc.Quality = 0;
14638 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
14639 texture2d_desc.BindFlags = 0;
14640 texture2d_desc.CPUAccessFlags = 0;
14641 texture2d_desc.MiscFlags = 0;
14643 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14644 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
14646 set_box(&box, 0, 0, 0, 4, 1, 1);
14647 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14649 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2d, 0,
14650 0, i, 0, (ID3D11Resource *)texture1d, i, &box);
14653 get_texture_readback(texture2d, 0, &rb);
14654 for (i = 0; i < 4; ++i)
14656 for (j = 0; j < 4; ++j)
14658 color = get_readback_color(&rb, j, i, 0);
14659 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14660 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14661 color, j, i, bitmap_data[j + i * 4]);
14664 release_resource_readback(&rb);
14666 get_texture1d_readback(texture1d, 0, &rb);
14667 for (i = 0; i < texture1d_desc.Width; ++i)
14669 color = get_readback_color(&rb, i, 0, 0);
14670 ok(compare_color(color, bitmap_data[i], 1),
14671 "Got color 0x%08x at %u, expected 0x%08x.\n",
14672 color, i, bitmap_data[i]);
14674 release_resource_readback(&rb);
14676 ID3D11Texture1D_Release(texture1d);
14677 ID3D11Texture2D_Release(texture2d);
14678 release_test_context(&test_context);
14681 static void test_copy_subresource_region_3d(void)
14683 ID3D11ShaderResourceView *dst_srv, *src_srv;
14684 ID3D11Texture3D *dst_texture, *src_texture;
14685 D3D11_SUBRESOURCE_DATA resource_data[4];
14686 struct d3d11_test_context test_context;
14687 D3D11_TEXTURE2D_DESC texture2d_desc;
14688 D3D11_TEXTURE3D_DESC texture3d_desc;
14689 ID3D11SamplerState *sampler_state;
14690 D3D11_SAMPLER_DESC sampler_desc;
14691 ID3D11DeviceContext *context;
14692 struct resource_readback rb;
14693 ID3D11Texture2D *texture2d;
14694 ID3D11PixelShader *ps;
14695 ID3D11Device *device;
14696 unsigned int i, j;
14697 DWORD data[4][16];
14698 D3D11_BOX box;
14699 DWORD color;
14700 HRESULT hr;
14702 static const DWORD ps_code[] =
14704 #if 0
14705 Texture3D t;
14706 SamplerState s;
14708 float4 main(float4 position : SV_POSITION) : SV_Target
14710 return t.Sample(s, position.xyz / float3(640, 480, 1));
14712 #endif
14713 0x43425844, 0x27b15ae8, 0xbebf46f7, 0x6cd88d8d, 0x5118de51, 0x00000001, 0x00000134, 0x00000003,
14714 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14715 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000070f, 0x505f5653, 0x5449534f, 0x004e4f49,
14716 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14717 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
14718 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
14719 0x04002064, 0x00101072, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14720 0x00000001, 0x0a000038, 0x00100072, 0x00000000, 0x00101246, 0x00000000, 0x00004002, 0x3acccccd,
14721 0x3b088889, 0x3f800000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
14722 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
14724 static const DWORD bitmap_data[] =
14726 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14727 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14728 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14729 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14732 if (!init_test_context(&test_context, NULL))
14733 return;
14734 device = test_context.device;
14735 context = test_context.immediate_context;
14737 texture3d_desc.Width = 4;
14738 texture3d_desc.Height = 4;
14739 texture3d_desc.Depth = 4;
14740 texture3d_desc.MipLevels = 1;
14741 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14742 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
14743 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14744 texture3d_desc.CPUAccessFlags = 0;
14745 texture3d_desc.MiscFlags = 0;
14747 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &src_texture);
14748 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
14749 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &dst_texture);
14750 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
14752 texture2d_desc.Width = 4;
14753 texture2d_desc.Height = 4;
14754 texture2d_desc.MipLevels = 1;
14755 texture2d_desc.ArraySize = 4;
14756 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14757 texture2d_desc.SampleDesc.Count = 1;
14758 texture2d_desc.SampleDesc.Quality = 0;
14759 texture2d_desc.Usage = D3D11_USAGE_IMMUTABLE;
14760 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14761 texture2d_desc.CPUAccessFlags = 0;
14762 texture2d_desc.MiscFlags = 0;
14764 for (i = 0; i < ARRAY_SIZE(*data); ++i)
14766 data[0][i] = 0xff0000ff;
14767 data[1][i] = bitmap_data[i];
14768 data[2][i] = 0xff00ff00;
14769 data[3][i] = 0xffff00ff;
14772 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14774 resource_data[i].pSysMem = data[i];
14775 resource_data[i].SysMemPitch = texture2d_desc.Width * sizeof(data[0][0]);
14776 resource_data[i].SysMemSlicePitch = 0;
14779 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, resource_data, &texture2d);
14780 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
14782 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)src_texture, NULL, &src_srv);
14783 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
14784 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &dst_srv);
14785 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
14787 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14788 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14789 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14790 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14791 sampler_desc.MipLODBias = 0.0f;
14792 sampler_desc.MaxAnisotropy = 0;
14793 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14794 sampler_desc.BorderColor[0] = 0.0f;
14795 sampler_desc.BorderColor[1] = 0.0f;
14796 sampler_desc.BorderColor[2] = 0.0f;
14797 sampler_desc.BorderColor[3] = 0.0f;
14798 sampler_desc.MinLOD = 0.0f;
14799 sampler_desc.MaxLOD = 0.0f;
14801 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
14802 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14804 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14805 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
14807 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &src_srv);
14808 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14809 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14811 set_box(&box, 0, 0, 0, 4, 4, 1);
14812 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14814 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
14815 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
14817 draw_quad(&test_context);
14818 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14819 draw_quad_z(&test_context, 0.25f);
14820 get_texture_readback(test_context.backbuffer, 0, &rb);
14821 for (i = 0; i < 4; ++i)
14823 for (j = 0; j < 4; ++j)
14825 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14826 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14827 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14828 color, j, i, bitmap_data[j + i * 4]);
14831 release_resource_readback(&rb);
14832 draw_quad_z(&test_context, 0.5f);
14833 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14834 draw_quad_z(&test_context, 1.0f);
14835 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
14837 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &dst_srv);
14839 set_box(&box, 0, 0, 0, 4, 4, 2);
14840 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14841 0, 0, 2, (ID3D11Resource *)src_texture, 0, &box);
14842 set_box(&box, 0, 0, 2, 4, 4, 4);
14843 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14844 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14846 set_box(&box, 0, 0, 0, 4, 4, 1);
14847 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14849 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
14850 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
14852 draw_quad(&test_context);
14853 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14854 draw_quad_z(&test_context, 0.25f);
14855 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
14856 draw_quad_z(&test_context, 0.5f);
14857 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14858 draw_quad_z(&test_context, 1.0f);
14859 get_texture_readback(test_context.backbuffer, 0, &rb);
14860 for (i = 0; i < 4; ++i)
14862 for (j = 0; j < 4; ++j)
14864 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14865 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14866 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14867 color, j, i, bitmap_data[j + i * 4]);
14870 release_resource_readback(&rb);
14872 ID3D11PixelShader_Release(ps);
14873 ID3D11SamplerState_Release(sampler_state);
14874 ID3D11ShaderResourceView_Release(dst_srv);
14875 ID3D11ShaderResourceView_Release(src_srv);
14876 ID3D11Texture2D_Release(texture2d);
14877 ID3D11Texture3D_Release(dst_texture);
14878 ID3D11Texture3D_Release(src_texture);
14879 release_test_context(&test_context);
14882 static void test_resource_map(void)
14884 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
14885 D3D11_TEXTURE3D_DESC texture3d_desc;
14886 D3D11_TEXTURE2D_DESC texture2d_desc;
14887 D3D11_BUFFER_DESC buffer_desc;
14888 ID3D11DeviceContext *context;
14889 ID3D11Texture3D *texture3d;
14890 ID3D11Texture2D *texture2d;
14891 ID3D11Buffer *buffer;
14892 ID3D11Device *device;
14893 ULONG refcount;
14894 HRESULT hr;
14895 DWORD data;
14897 if (!(device = create_device(NULL)))
14899 skip("Failed to create device.\n");
14900 return;
14903 ID3D11Device_GetImmediateContext(device, &context);
14905 buffer_desc.ByteWidth = 1024;
14906 buffer_desc.Usage = D3D11_USAGE_STAGING;
14907 buffer_desc.BindFlags = 0;
14908 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14909 buffer_desc.MiscFlags = 0;
14910 buffer_desc.StructureByteStride = 0;
14912 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14913 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14915 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14916 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14918 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14919 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14920 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
14921 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14922 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
14923 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14924 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
14926 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14927 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14928 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
14929 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14930 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
14931 data = *((DWORD *)mapped_subresource.pData);
14932 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14933 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
14935 refcount = ID3D11Buffer_Release(buffer);
14936 ok(!refcount, "Buffer has %u references left.\n", refcount);
14938 texture2d_desc.Width = 512;
14939 texture2d_desc.Height = 512;
14940 texture2d_desc.MipLevels = 1;
14941 texture2d_desc.ArraySize = 1;
14942 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14943 texture2d_desc.SampleDesc.Count = 1;
14944 texture2d_desc.SampleDesc.Quality = 0;
14945 texture2d_desc.Usage = D3D11_USAGE_STAGING;
14946 texture2d_desc.BindFlags = 0;
14947 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14948 texture2d_desc.MiscFlags = 0;
14950 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14951 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14953 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14954 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14956 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14957 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14958 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14959 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14960 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
14961 mapped_subresource.DepthPitch);
14962 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14963 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
14965 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14966 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14967 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14968 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14969 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
14970 mapped_subresource.DepthPitch);
14971 data = *((DWORD *)mapped_subresource.pData);
14972 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14973 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
14975 refcount = ID3D11Texture2D_Release(texture2d);
14976 ok(!refcount, "2D texture has %u references left.\n", refcount);
14978 texture3d_desc.Width = 64;
14979 texture3d_desc.Height = 64;
14980 texture3d_desc.Depth = 64;
14981 texture3d_desc.MipLevels = 1;
14982 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14983 texture3d_desc.Usage = D3D11_USAGE_STAGING;
14984 texture3d_desc.BindFlags = 0;
14985 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14986 texture3d_desc.MiscFlags = 0;
14988 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14989 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
14991 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14992 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14994 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14995 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14996 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14997 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14998 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
14999 mapped_subresource.DepthPitch);
15000 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
15001 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
15003 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
15004 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
15005 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
15006 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
15007 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
15008 mapped_subresource.DepthPitch);
15009 data = *((DWORD *)mapped_subresource.pData);
15010 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
15011 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
15013 refcount = ID3D11Texture3D_Release(texture3d);
15014 ok(!refcount, "3D texture has %u references left.\n", refcount);
15016 ID3D11DeviceContext_Release(context);
15018 refcount = ID3D11Device_Release(device);
15019 ok(!refcount, "Device has %u references left.\n", refcount);
15022 #define check_resource_cpu_access(a, b, c, d, e) check_resource_cpu_access_(__LINE__, a, b, c, d, e)
15023 static void check_resource_cpu_access_(unsigned int line, ID3D11DeviceContext *context,
15024 ID3D11Resource *resource, D3D11_USAGE usage, UINT bind_flags, UINT cpu_access)
15026 BOOL cpu_write = cpu_access & D3D11_CPU_ACCESS_WRITE;
15027 BOOL cpu_read = cpu_access & D3D11_CPU_ACCESS_READ;
15028 BOOL dynamic = usage == D3D11_USAGE_DYNAMIC;
15029 D3D11_MAPPED_SUBRESOURCE map_desc;
15030 HRESULT hr, expected_hr;
15031 ID3D11Device *device;
15033 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
15034 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ, 0, &map_desc);
15035 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
15036 if (SUCCEEDED(hr))
15037 ID3D11DeviceContext_Unmap(context, resource, 0);
15039 /* WRITE_DISCARD and WRITE_NO_OVERWRITE are the only allowed options for dynamic resources. */
15040 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
15041 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE, 0, &map_desc);
15042 todo_wine_if(dynamic && cpu_write)
15043 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
15044 if (SUCCEEDED(hr))
15045 ID3D11DeviceContext_Unmap(context, resource, 0);
15047 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
15048 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
15049 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
15050 if (SUCCEEDED(hr))
15051 ID3D11DeviceContext_Unmap(context, resource, 0);
15053 expected_hr = dynamic ? S_OK : E_INVALIDARG;
15054 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
15055 todo_wine_if(!dynamic && cpu_write)
15056 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
15057 if (SUCCEEDED(hr))
15058 ID3D11DeviceContext_Unmap(context, resource, 0);
15060 if (!dynamic)
15061 return;
15063 ID3D11DeviceContext_GetDevice(context, &device);
15065 /* WRITE_NO_OVERWRITE is supported only for buffers. */
15066 expected_hr = is_buffer(resource) ? S_OK : E_INVALIDARG;
15067 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
15068 /* D3D11.1 is required for constant and shader buffers. */
15069 todo_wine_if(expected_hr != S_OK)
15070 ok_(__FILE__, line)(hr == expected_hr
15071 || broken(bind_flags & (D3D11_BIND_CONSTANT_BUFFER | D3D11_BIND_SHADER_RESOURCE)),
15072 "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
15073 if (SUCCEEDED(hr))
15074 ID3D11DeviceContext_Unmap(context, resource, 0);
15076 ID3D11Device_Release(device);
15079 static void test_resource_access(const D3D_FEATURE_LEVEL feature_level)
15081 D3D11_TEXTURE2D_DESC texture_desc;
15082 struct device_desc device_desc;
15083 D3D11_BUFFER_DESC buffer_desc;
15084 ID3D11DeviceContext *context;
15085 D3D11_SUBRESOURCE_DATA data;
15086 ID3D11Resource *resource;
15087 BOOL required_cpu_access;
15088 BOOL cpu_write, cpu_read;
15089 HRESULT hr, expected_hr;
15090 UINT allowed_cpu_access;
15091 BOOL broken_validation;
15092 ID3D11Device *device;
15093 unsigned int i;
15094 ULONG refcount;
15096 static const struct
15098 D3D11_USAGE usage;
15099 UINT bind_flags;
15100 BOOL is_valid;
15101 UINT allowed_cpu_access;
15103 tests[] =
15105 /* Default resources cannot be written by CPU. */
15106 {D3D11_USAGE_DEFAULT, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
15107 {D3D11_USAGE_DEFAULT, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
15108 {D3D11_USAGE_DEFAULT, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
15109 {D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
15110 {D3D11_USAGE_DEFAULT, D3D11_BIND_STREAM_OUTPUT, TRUE, 0},
15111 {D3D11_USAGE_DEFAULT, D3D11_BIND_RENDER_TARGET, TRUE, 0},
15112 {D3D11_USAGE_DEFAULT, D3D11_BIND_DEPTH_STENCIL, TRUE, 0},
15113 {D3D11_USAGE_DEFAULT, D3D11_BIND_UNORDERED_ACCESS, TRUE, 0},
15115 /* Immutable resources cannot be written by CPU and GPU. */
15116 {D3D11_USAGE_IMMUTABLE, 0, FALSE, 0},
15117 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
15118 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
15119 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
15120 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
15121 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
15122 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_RENDER_TARGET, FALSE, 0},
15123 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
15124 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
15126 /* Dynamic resources cannot be written by GPU. */
15127 {D3D11_USAGE_DYNAMIC, 0, FALSE, D3D11_CPU_ACCESS_WRITE},
15128 {D3D11_USAGE_DYNAMIC, D3D11_BIND_VERTEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
15129 {D3D11_USAGE_DYNAMIC, D3D11_BIND_INDEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
15130 {D3D11_USAGE_DYNAMIC, D3D11_BIND_CONSTANT_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
15131 {D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE, TRUE, D3D11_CPU_ACCESS_WRITE},
15132 {D3D11_USAGE_DYNAMIC, D3D11_BIND_STREAM_OUTPUT, FALSE, D3D11_CPU_ACCESS_WRITE},
15133 {D3D11_USAGE_DYNAMIC, D3D11_BIND_RENDER_TARGET, FALSE, D3D11_CPU_ACCESS_WRITE},
15134 {D3D11_USAGE_DYNAMIC, D3D11_BIND_DEPTH_STENCIL, FALSE, D3D11_CPU_ACCESS_WRITE},
15135 {D3D11_USAGE_DYNAMIC, D3D11_BIND_UNORDERED_ACCESS, FALSE, D3D11_CPU_ACCESS_WRITE},
15137 /* Staging resources support only data transfer. */
15138 {D3D11_USAGE_STAGING, 0, TRUE, D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ},
15139 {D3D11_USAGE_STAGING, D3D11_BIND_VERTEX_BUFFER, FALSE, 0},
15140 {D3D11_USAGE_STAGING, D3D11_BIND_INDEX_BUFFER, FALSE, 0},
15141 {D3D11_USAGE_STAGING, D3D11_BIND_CONSTANT_BUFFER, FALSE, 0},
15142 {D3D11_USAGE_STAGING, D3D11_BIND_SHADER_RESOURCE, FALSE, 0},
15143 {D3D11_USAGE_STAGING, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
15144 {D3D11_USAGE_STAGING, D3D11_BIND_RENDER_TARGET, FALSE, 0},
15145 {D3D11_USAGE_STAGING, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
15146 {D3D11_USAGE_STAGING, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
15149 device_desc.feature_level = &feature_level;
15150 device_desc.flags = 0;
15151 if (!(device = create_device(&device_desc)))
15153 skip("Failed to create device for feature level %#x.\n", feature_level);
15154 return;
15156 ID3D11Device_GetImmediateContext(device, &context);
15158 data.SysMemPitch = 0;
15159 data.SysMemSlicePitch = 0;
15160 data.pSysMem = heap_alloc(10240);
15161 ok(!!data.pSysMem, "Failed to allocate memory.\n");
15163 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15165 switch (tests[i].bind_flags)
15167 case D3D11_BIND_DEPTH_STENCIL:
15168 continue;
15170 case D3D11_BIND_SHADER_RESOURCE:
15171 case D3D11_BIND_STREAM_OUTPUT:
15172 case D3D11_BIND_RENDER_TARGET:
15173 if (feature_level < D3D_FEATURE_LEVEL_10_0)
15174 continue;
15175 break;
15177 case D3D11_BIND_UNORDERED_ACCESS:
15178 if (feature_level < D3D_FEATURE_LEVEL_11_0)
15179 continue;
15180 break;
15182 default:
15183 break;
15186 allowed_cpu_access = tests[i].allowed_cpu_access;
15187 if (feature_level >= D3D_FEATURE_LEVEL_11_0 && is_d3d11_2_runtime(device)
15188 && tests[i].usage == D3D11_USAGE_DEFAULT
15189 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
15190 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS))
15191 allowed_cpu_access |= D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
15193 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
15194 cpu_write = allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
15195 cpu_read = allowed_cpu_access & D3D11_CPU_ACCESS_READ;
15197 buffer_desc.ByteWidth = 1024;
15198 buffer_desc.Usage = tests[i].usage;
15199 buffer_desc.BindFlags = tests[i].bind_flags;
15200 buffer_desc.MiscFlags = 0;
15201 buffer_desc.StructureByteStride = 0;
15203 buffer_desc.CPUAccessFlags = 0;
15204 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
15205 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15206 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15207 if (SUCCEEDED(hr))
15209 check_resource_cpu_access(context, resource,
15210 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15211 ID3D11Resource_Release(resource);
15214 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
15215 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
15216 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15217 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15218 if (SUCCEEDED(hr))
15220 check_resource_cpu_access(context, resource,
15221 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15222 ID3D11Resource_Release(resource);
15225 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
15226 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
15227 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15228 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15229 if (SUCCEEDED(hr))
15231 check_resource_cpu_access(context, resource,
15232 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15233 ID3D11Resource_Release(resource);
15236 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
15237 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
15238 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15239 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15240 if (SUCCEEDED(hr))
15242 check_resource_cpu_access(context, resource,
15243 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15244 ID3D11Resource_Release(resource);
15248 data.SysMemPitch = 16;
15250 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15252 switch (tests[i].bind_flags)
15254 case D3D11_BIND_VERTEX_BUFFER:
15255 case D3D11_BIND_INDEX_BUFFER:
15256 case D3D11_BIND_CONSTANT_BUFFER:
15257 case D3D11_BIND_STREAM_OUTPUT:
15258 continue;
15260 case D3D11_BIND_UNORDERED_ACCESS:
15261 if (feature_level < D3D_FEATURE_LEVEL_11_0)
15262 continue;
15263 break;
15265 default:
15266 break;
15269 broken_validation = tests[i].usage == D3D11_USAGE_DEFAULT
15270 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
15271 || tests[i].bind_flags == D3D11_BIND_RENDER_TARGET
15272 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS);
15274 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
15275 cpu_write = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
15276 cpu_read = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_READ;
15278 texture_desc.Width = 4;
15279 texture_desc.Height = 4;
15280 texture_desc.MipLevels = 1;
15281 texture_desc.ArraySize = 1;
15282 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15283 texture_desc.SampleDesc.Count = 1;
15284 texture_desc.SampleDesc.Quality = 0;
15285 texture_desc.Usage = tests[i].usage;
15286 texture_desc.BindFlags = tests[i].bind_flags;
15287 texture_desc.MiscFlags = 0;
15288 if (tests[i].bind_flags == D3D11_BIND_DEPTH_STENCIL)
15289 texture_desc.Format = DXGI_FORMAT_D16_UNORM;
15291 texture_desc.CPUAccessFlags = 0;
15292 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
15293 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15294 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15295 if (SUCCEEDED(hr))
15297 check_resource_cpu_access(context, resource,
15298 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15299 ID3D11Resource_Release(resource);
15302 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
15303 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
15304 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15305 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15306 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15307 if (SUCCEEDED(hr))
15309 if (broken_validation)
15310 texture_desc.CPUAccessFlags = 0;
15311 check_resource_cpu_access(context, resource,
15312 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15313 ID3D11Resource_Release(resource);
15316 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
15317 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
15318 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15319 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15320 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15321 if (SUCCEEDED(hr))
15323 if (broken_validation)
15324 texture_desc.CPUAccessFlags = 0;
15325 check_resource_cpu_access(context, resource,
15326 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15327 ID3D11Resource_Release(resource);
15330 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
15331 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
15332 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15333 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15334 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15335 if (SUCCEEDED(hr))
15337 if (broken_validation)
15338 texture_desc.CPUAccessFlags = 0;
15339 check_resource_cpu_access(context, resource,
15340 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15341 ID3D11Resource_Release(resource);
15345 heap_free((void *)data.pSysMem);
15347 ID3D11DeviceContext_Release(context);
15348 refcount = ID3D11Device_Release(device);
15349 ok(!refcount, "Device has %u references left.\n", refcount);
15352 static void test_check_multisample_quality_levels(void)
15354 ID3D11Device *device;
15355 UINT quality_levels;
15356 ULONG refcount;
15357 HRESULT hr;
15359 if (!(device = create_device(NULL)))
15361 skip("Failed to create device.\n");
15362 return;
15365 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
15366 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
15367 if (!quality_levels)
15369 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
15370 goto done;
15373 quality_levels = 0xdeadbeef;
15374 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
15375 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15376 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15377 quality_levels = 0xdeadbeef;
15378 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
15379 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15380 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
15382 if (!enable_debug_layer)
15384 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
15385 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15386 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
15387 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15388 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
15389 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15392 quality_levels = 0xdeadbeef;
15393 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
15394 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15395 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15397 quality_levels = 0xdeadbeef;
15398 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
15399 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15400 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
15402 quality_levels = 0xdeadbeef;
15403 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
15404 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15405 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15407 /* We assume 15 samples multisampling is never supported in practice. */
15408 quality_levels = 0xdeadbeef;
15409 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
15410 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15411 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15412 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
15413 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15414 quality_levels = 0xdeadbeef;
15415 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
15416 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15417 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15418 quality_levels = 0xdeadbeef;
15419 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
15420 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15421 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15423 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
15424 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15425 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15427 done:
15428 refcount = ID3D11Device_Release(device);
15429 ok(!refcount, "Device has %u references left.\n", refcount);
15432 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
15434 DXGI_SWAP_CHAIN_DESC swapchain_desc;
15435 struct device_desc device_desc;
15436 IDXGISwapChain *swapchain;
15437 IDXGIDevice *dxgi_device;
15438 HRESULT hr, expected_hr;
15439 IDXGIAdapter *adapter;
15440 IDXGIFactory *factory;
15441 ID3D11Device *device;
15442 unsigned int i;
15443 ULONG refcount;
15445 swapchain_desc.BufferDesc.Width = 800;
15446 swapchain_desc.BufferDesc.Height = 600;
15447 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
15448 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
15449 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
15450 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
15451 swapchain_desc.SampleDesc.Count = 1;
15452 swapchain_desc.SampleDesc.Quality = 0;
15453 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
15454 swapchain_desc.BufferCount = 1;
15455 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
15456 swapchain_desc.Windowed = TRUE;
15457 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
15458 swapchain_desc.Flags = 0;
15460 device_desc.feature_level = &feature_level;
15461 device_desc.flags = 0;
15462 if (!(device = create_device(&device_desc)))
15464 skip("Failed to create device for feature level %#x.\n", feature_level);
15465 return;
15468 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
15469 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
15470 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
15471 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
15472 IDXGIDevice_Release(dxgi_device);
15473 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
15474 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
15475 IDXGIAdapter_Release(adapter);
15477 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15478 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
15479 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
15480 hr, feature_level);
15481 if (SUCCEEDED(hr))
15482 IDXGISwapChain_Release(swapchain);
15484 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
15486 DXGI_FORMAT format = display_format_support[i].format;
15487 BOOL todo = FALSE;
15489 if (display_format_support[i].fl_required <= feature_level)
15491 expected_hr = S_OK;
15492 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
15493 todo = TRUE;
15495 else if (!display_format_support[i].fl_optional
15496 || display_format_support[i].fl_optional > feature_level)
15498 expected_hr = E_INVALIDARG;
15499 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
15500 todo = TRUE;
15502 else
15504 continue;
15507 swapchain_desc.BufferDesc.Format = format;
15508 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
15509 todo_wine_if(todo)
15510 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
15511 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
15512 hr, expected_hr, feature_level, format);
15513 if (FAILED(hr))
15514 continue;
15515 refcount = IDXGISwapChain_Release(swapchain);
15516 ok(!refcount, "Swapchain has %u references left.\n", refcount);
15519 refcount = ID3D11Device_Release(device);
15520 ok(!refcount, "Device has %u references left.\n", refcount);
15521 refcount = IDXGIFactory_Release(factory);
15522 ok(!refcount, "Factory has %u references left.\n", refcount);
15523 DestroyWindow(swapchain_desc.OutputWindow);
15526 static void test_swapchain_views(void)
15528 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
15529 struct d3d11_test_context test_context;
15530 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15531 ID3D11ShaderResourceView *srv;
15532 ID3D11DeviceContext *context;
15533 ID3D11RenderTargetView *rtv;
15534 ID3D11Device *device;
15535 ULONG refcount;
15536 HRESULT hr;
15538 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
15540 if (!init_test_context(&test_context, NULL))
15541 return;
15543 device = test_context.device;
15544 context = test_context.immediate_context;
15546 refcount = get_refcount(test_context.backbuffer);
15547 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
15549 draw_color_quad(&test_context, &color);
15550 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
15552 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15553 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15554 U(rtv_desc).Texture2D.MipSlice = 0;
15555 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
15556 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15557 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15559 refcount = get_refcount(test_context.backbuffer);
15560 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
15562 draw_color_quad(&test_context, &color);
15563 check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
15565 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15566 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
15567 U(srv_desc).Texture2D.MostDetailedMip = 0;
15568 U(srv_desc).Texture2D.MipLevels = 1;
15569 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
15570 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15571 if (SUCCEEDED(hr))
15572 ID3D11ShaderResourceView_Release(srv);
15574 ID3D11RenderTargetView_Release(rtv);
15575 release_test_context(&test_context);
15578 static void test_swapchain_flip(void)
15580 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
15581 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
15582 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
15583 D3D11_TEXTURE2D_DESC texture_desc;
15584 ID3D11InputLayout *input_layout;
15585 ID3D11DeviceContext *context;
15586 unsigned int stride, offset;
15587 struct swapchain_desc desc;
15588 IDXGISwapChain *swapchain;
15589 ID3D11VertexShader *vs;
15590 ID3D11PixelShader *ps;
15591 ID3D11Device *device;
15592 ID3D11Buffer *vb;
15593 ULONG refcount;
15594 DWORD color;
15595 HWND window;
15596 HRESULT hr;
15597 RECT rect;
15599 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15601 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15603 static const DWORD vs_code[] =
15605 #if 0
15606 float4 main(float4 position : POSITION) : SV_POSITION
15608 return position;
15610 #endif
15611 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
15612 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15613 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
15614 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
15615 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
15616 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15617 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
15620 static const DWORD ps_code[] =
15622 #if 0
15623 Texture2D t0, t1;
15624 SamplerState s;
15626 float4 main(float4 position : SV_POSITION) : SV_Target
15628 float2 p;
15630 p.x = 0.5;
15631 p.y = 0.5;
15632 if (position.x < 320)
15633 return t0.Sample(s, p);
15634 return t1.Sample(s, p);
15636 #endif
15637 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
15638 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15639 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
15640 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15641 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
15642 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
15643 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
15644 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
15645 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
15646 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
15647 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
15648 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
15649 0x00000000, 0x0100003e,
15651 static const struct vec2 quad[] =
15653 {-1.0f, -1.0f},
15654 {-1.0f, 1.0f},
15655 { 1.0f, -1.0f},
15656 { 1.0f, 1.0f},
15658 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
15659 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15660 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
15662 if (!(device = create_device(NULL)))
15664 skip("Failed to create device, skipping tests.\n");
15665 return;
15667 SetRect(&rect, 0, 0, 640, 480);
15668 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
15669 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
15670 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
15671 desc.buffer_count = 3;
15672 desc.width = desc.height = 0;
15673 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
15674 desc.windowed = TRUE;
15675 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
15676 swapchain = create_swapchain(device, window, &desc);
15678 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
15679 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15680 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
15681 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15682 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
15683 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15685 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
15686 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15687 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
15688 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15689 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
15690 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15692 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
15693 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
15694 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
15695 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
15696 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
15698 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
15699 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
15700 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
15701 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
15702 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
15704 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
15705 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15706 if (SUCCEEDED(hr))
15707 ID3D11RenderTargetView_Release(offscreen_rtv);
15709 ID3D11Device_GetImmediateContext(device, &context);
15711 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
15712 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
15714 texture_desc.Width = 640;
15715 texture_desc.Height = 480;
15716 texture_desc.MipLevels = 1;
15717 texture_desc.ArraySize = 1;
15718 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15719 texture_desc.SampleDesc.Count = 1;
15720 texture_desc.SampleDesc.Quality = 0;
15721 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15722 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15723 texture_desc.CPUAccessFlags = 0;
15724 texture_desc.MiscFlags = 0;
15725 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
15726 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
15727 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
15728 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15729 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
15730 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
15732 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
15734 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15735 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15736 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15737 vs_code, sizeof(vs_code), &input_layout);
15738 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15739 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15740 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
15741 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15742 stride = sizeof(*quad);
15743 offset = 0;
15744 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15746 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15747 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15748 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15750 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
15752 ID3D11DeviceContext_Draw(context, 4, 0);
15753 color = get_texture_color(offscreen, 120, 240);
15754 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15756 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
15757 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
15758 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
15760 * What is this good for? I don't know. Ad-hoc tests suggest that
15761 * Present() always waits for the next V-sync interval, even if there are
15762 * still untouched buffers. Buffer 0 is the buffer that is shown on the
15763 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
15764 * rendering finishes before the V-sync interval is over. I haven't found
15765 * any productive use for more than one buffer. */
15766 IDXGISwapChain_Present(swapchain, 0, 0);
15768 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
15770 ID3D11DeviceContext_Draw(context, 4, 0);
15771 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
15772 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15773 /* Buffer 1 is still untouched. */
15775 color = get_texture_color(backbuffer_0, 320, 240); /* green */
15776 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15777 color = get_texture_color(backbuffer_2, 320, 240); /* red */
15778 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15780 IDXGISwapChain_Present(swapchain, 0, 0);
15782 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
15784 ID3D11DeviceContext_Draw(context, 4, 0);
15785 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
15786 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
15787 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
15788 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15790 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
15791 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
15792 color = get_texture_color(backbuffer_1, 320, 240); /* red */
15793 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15794 color = get_texture_color(backbuffer_2, 320, 240); /* green */
15795 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15797 ID3D11VertexShader_Release(vs);
15798 ID3D11PixelShader_Release(ps);
15799 ID3D11Buffer_Release(vb);
15800 ID3D11InputLayout_Release(input_layout);
15801 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
15802 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
15803 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
15804 ID3D11RenderTargetView_Release(offscreen_rtv);
15805 ID3D11Texture2D_Release(offscreen);
15806 ID3D11Texture2D_Release(backbuffer_0);
15807 ID3D11Texture2D_Release(backbuffer_1);
15808 ID3D11Texture2D_Release(backbuffer_2);
15809 IDXGISwapChain_Release(swapchain);
15811 ID3D11DeviceContext_Release(context);
15812 refcount = ID3D11Device_Release(device);
15813 ok(!refcount, "Device has %u references left.\n", refcount);
15814 DestroyWindow(window);
15817 static void test_clear_render_target_view_1d(void)
15819 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
15820 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15822 struct d3d11_test_context test_context;
15823 D3D11_TEXTURE1D_DESC texture_desc;
15824 ID3D11DeviceContext *context;
15825 ID3D11RenderTargetView *rtv;
15826 ID3D11Texture1D *texture;
15827 ID3D11Device *device;
15828 HRESULT hr;
15830 if (!init_test_context(&test_context, NULL))
15831 return;
15833 device = test_context.device;
15834 context = test_context.immediate_context;
15836 texture_desc.Width = 64;
15837 texture_desc.MipLevels = 1;
15838 texture_desc.ArraySize = 1;
15839 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15840 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15841 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15842 texture_desc.CPUAccessFlags = 0;
15843 texture_desc.MiscFlags = 0;
15844 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, NULL, &texture);
15845 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15847 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15848 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15850 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15851 check_texture1d_color(texture, 0xbf4c7f19, 1);
15853 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15854 check_texture1d_color(texture, 0x8000ff00, 1);
15856 ID3D11RenderTargetView_Release(rtv);
15857 ID3D11Texture1D_Release(texture);
15858 release_test_context(&test_context);
15861 static void test_clear_render_target_view_2d(void)
15863 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
15864 static const float clear_colour[] = {0.1f, 0.5f, 0.3f, 0.75f};
15865 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15866 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
15868 ID3D11RenderTargetView *rtv[3], *srgb_rtv;
15869 ID3D11Texture2D *texture, *srgb_texture;
15870 struct d3d11_test_context test_context;
15871 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15872 D3D11_TEXTURE2D_DESC texture_desc;
15873 ID3D11DeviceContext *context;
15874 struct resource_readback rb;
15875 ID3D11Device *device;
15876 unsigned int i, j;
15877 DWORD colour;
15878 HRESULT hr;
15880 if (!init_test_context(&test_context, NULL))
15881 return;
15883 device = test_context.device;
15884 context = test_context.immediate_context;
15886 texture_desc.Width = 640;
15887 texture_desc.Height = 480;
15888 texture_desc.MipLevels = 1;
15889 texture_desc.ArraySize = 1;
15890 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15891 texture_desc.SampleDesc.Count = 1;
15892 texture_desc.SampleDesc.Quality = 0;
15893 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15894 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15895 texture_desc.CPUAccessFlags = 0;
15896 texture_desc.MiscFlags = 0;
15897 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15898 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15900 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15901 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
15902 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15904 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv[0]);
15905 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15907 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
15908 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15910 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, clear_colour);
15911 check_texture_color(test_context.backbuffer, expected_color, 1);
15913 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], clear_colour);
15914 check_texture_color(texture, expected_color, 1);
15916 if (!enable_debug_layer)
15917 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
15918 check_texture_color(texture, expected_color, 1);
15920 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, clear_colour);
15921 check_texture_color(srgb_texture, expected_srgb_color, 1);
15923 ID3D11RenderTargetView_Release(srgb_rtv);
15924 ID3D11RenderTargetView_Release(rtv[0]);
15925 ID3D11Texture2D_Release(srgb_texture);
15926 ID3D11Texture2D_Release(texture);
15928 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15929 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15930 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15932 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15933 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15934 U(rtv_desc).Texture2D.MipSlice = 0;
15935 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
15936 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15938 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15939 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15940 U(rtv_desc).Texture2D.MipSlice = 0;
15941 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[0]);
15942 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15944 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], clear_colour);
15945 check_texture_color(texture, expected_color, 1);
15947 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, clear_colour);
15948 get_texture_readback(texture, 0, &rb);
15949 for (i = 0; i < 4; ++i)
15951 for (j = 0; j < 4; ++j)
15953 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
15954 colour = get_readback_color(&rb, 80 + i * 160, 60 + j * 120, 0);
15955 ok(compare_color(colour, expected_srgb_color, 1)
15956 || broken(compare_color(colour, expected_color, 1) && broken_device),
15957 "Got unexpected colour 0x%08x.\n", colour);
15960 release_resource_readback(&rb);
15962 ID3D11RenderTargetView_Release(srgb_rtv);
15963 ID3D11RenderTargetView_Release(rtv[0]);
15964 ID3D11Texture2D_Release(texture);
15966 texture_desc.Width = 16;
15967 texture_desc.Height = 16;
15968 texture_desc.ArraySize = 5;
15969 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15970 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15972 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
15973 U(rtv_desc).Texture2DArray.MipSlice = 0;
15974 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
15975 U(rtv_desc).Texture2DArray.ArraySize = 5;
15976 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[0]);
15977 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15979 U(rtv_desc).Texture2DArray.FirstArraySlice = 1;
15980 U(rtv_desc).Texture2DArray.ArraySize = 3;
15981 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[1]);
15982 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15984 U(rtv_desc).Texture2DArray.FirstArraySlice = 2;
15985 U(rtv_desc).Texture2DArray.ArraySize = 1;
15986 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[2]);
15987 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15989 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], blue);
15990 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[1], green);
15991 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[2], clear_colour);
15993 get_texture_readback(texture, 0, &rb);
15994 colour = get_readback_color(&rb, 8, 8, 0);
15995 ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
15996 release_resource_readback(&rb);
15998 get_texture_readback(texture, 1, &rb);
15999 colour = get_readback_color(&rb, 8, 8, 0);
16000 ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
16001 release_resource_readback(&rb);
16003 get_texture_readback(texture, 2, &rb);
16004 colour = get_readback_color(&rb, 8, 8, 0);
16005 ok(compare_color(colour, 0xbf4c7f19, 1), "Got unexpected colour 0x%08x.\n", colour);
16006 release_resource_readback(&rb);
16008 get_texture_readback(texture, 3, &rb);
16009 colour = get_readback_color(&rb, 8, 8, 0);
16010 ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
16011 release_resource_readback(&rb);
16013 get_texture_readback(texture, 4, &rb);
16014 colour = get_readback_color(&rb, 8, 8, 0);
16015 ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
16016 release_resource_readback(&rb);
16018 ID3D11RenderTargetView_Release(rtv[2]);
16019 ID3D11RenderTargetView_Release(rtv[1]);
16020 ID3D11RenderTargetView_Release(rtv[0]);
16021 ID3D11Texture2D_Release(texture);
16023 release_test_context(&test_context);
16026 static void test_clear_render_target_view_3d(void)
16028 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
16029 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
16031 struct d3d11_test_context test_context;
16032 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
16033 D3D11_TEXTURE3D_DESC texture_desc;
16034 ID3D11DeviceContext *context;
16035 ID3D11RenderTargetView *rtv;
16036 ID3D11Texture3D *texture;
16037 ID3D11Device *device;
16038 HRESULT hr;
16040 if (!init_test_context(&test_context, NULL))
16041 return;
16042 device = test_context.device;
16043 context = test_context.immediate_context;
16045 texture_desc.Width = 8;
16046 texture_desc.Height = 8;
16047 texture_desc.Depth = 4;
16048 texture_desc.MipLevels = 1;
16049 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
16050 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16051 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16052 texture_desc.CPUAccessFlags = 0;
16053 texture_desc.MiscFlags = 0;
16054 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
16055 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16057 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
16058 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
16060 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
16061 check_texture3d_color(texture, 0xbf4c7f19, 1);
16062 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
16063 check_texture3d_color(texture, 0x8000ff00, 1);
16065 ID3D11RenderTargetView_Release(rtv);
16066 ID3D11Texture3D_Release(texture);
16068 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
16069 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
16070 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16072 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
16073 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
16074 U(rtv_desc).Texture3D.MipSlice = 0;
16075 U(rtv_desc).Texture3D.FirstWSlice = 0;
16076 U(rtv_desc).Texture3D.WSize = ~0u;
16077 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
16078 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
16080 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
16081 check_texture3d_color(texture, 0xbf95bc59, 1);
16082 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
16083 check_texture3d_color(texture, 0x8000ff00, 1);
16085 ID3D11RenderTargetView_Release(rtv);
16086 ID3D11Texture3D_Release(texture);
16087 release_test_context(&test_context);
16090 static void test_clear_depth_stencil_view(void)
16092 D3D11_TEXTURE2D_DESC texture_desc;
16093 ID3D11Texture2D *depth_texture;
16094 ID3D11DeviceContext *context;
16095 ID3D11DepthStencilView *dsv;
16096 ID3D11Device *device;
16097 ULONG refcount;
16098 HRESULT hr;
16100 if (!(device = create_device(NULL)))
16102 skip("Failed to create device.\n");
16103 return;
16106 ID3D11Device_GetImmediateContext(device, &context);
16108 texture_desc.Width = 640;
16109 texture_desc.Height = 480;
16110 texture_desc.MipLevels = 1;
16111 texture_desc.ArraySize = 1;
16112 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
16113 texture_desc.SampleDesc.Count = 1;
16114 texture_desc.SampleDesc.Quality = 0;
16115 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16116 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16117 texture_desc.CPUAccessFlags = 0;
16118 texture_desc.MiscFlags = 0;
16119 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
16120 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
16122 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
16123 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16125 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16126 check_texture_float(depth_texture, 1.0f, 0);
16128 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
16129 check_texture_float(depth_texture, 0.25f, 0);
16131 if (!enable_debug_layer)
16132 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
16133 check_texture_float(depth_texture, 0.25f, 0);
16135 ID3D11Texture2D_Release(depth_texture);
16136 ID3D11DepthStencilView_Release(dsv);
16138 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
16139 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
16140 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
16142 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
16143 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16145 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
16146 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
16148 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
16149 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
16151 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
16152 check_texture_color(depth_texture, 0xffffffff, 0);
16154 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
16155 check_texture_color(depth_texture, 0x00000000, 0);
16157 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
16158 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
16160 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
16161 check_texture_color(depth_texture, 0xffffffff, 0);
16163 ID3D11Texture2D_Release(depth_texture);
16164 ID3D11DepthStencilView_Release(dsv);
16166 ID3D11DeviceContext_Release(context);
16168 refcount = ID3D11Device_Release(device);
16169 ok(!refcount, "Device has %u references left.\n", refcount);
16172 static unsigned int to_sint8(unsigned int x)
16174 union
16176 signed int s;
16177 unsigned int u;
16178 } bits;
16179 bits.u = x;
16180 return min(max(bits.s, -128), 127) & 0xff;
16183 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
16184 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
16186 unsigned int x = to_sint8(v->x);
16187 unsigned int y = to_sint8(v->y);
16188 unsigned int z = to_sint8(v->z);
16189 unsigned int w = to_sint8(v->w);
16190 DWORD expected[] =
16192 /* Windows 7 - Nvidia, WARP */
16193 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
16194 /* Windows 10 - AMD */
16195 x | y << 8 | z << 16 | w << 24,
16196 /* Windows 10 - Intel */
16197 x | x << 8 | x << 16 | x << 24,
16200 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
16201 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
16202 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
16205 static void test_clear_buffer_unordered_access_view(void)
16207 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16208 ID3D11UnorderedAccessView *uav, *uav2;
16209 struct device_desc device_desc;
16210 D3D11_BUFFER_DESC buffer_desc;
16211 ID3D11DeviceContext *context;
16212 struct resource_readback rb;
16213 ID3D11Buffer *buffer;
16214 ID3D11Device *device;
16215 struct uvec4 uvec4;
16216 unsigned int i, x;
16217 ULONG refcount;
16218 HRESULT hr;
16219 RECT rect;
16221 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16222 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
16223 static const struct uvec4 uvec4_data[] =
16225 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
16227 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
16228 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
16229 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
16230 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
16231 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
16233 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
16234 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
16235 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
16236 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
16237 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
16238 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
16239 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
16241 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
16242 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
16243 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
16244 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
16245 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
16246 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
16247 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
16248 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
16249 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
16250 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
16252 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
16253 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
16254 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
16255 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
16256 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
16257 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
16258 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
16259 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
16260 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
16261 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
16263 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
16264 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
16265 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
16266 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
16267 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
16268 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
16269 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
16270 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
16271 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
16272 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
16274 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
16275 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
16276 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
16277 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
16278 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
16279 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
16280 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
16281 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
16282 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
16283 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
16286 device_desc.feature_level = &feature_level;
16287 device_desc.flags = 0;
16288 if (!(device = create_device(&device_desc)))
16290 skip("Failed to create device for feature level %#x.\n", feature_level);
16291 return;
16294 ID3D11Device_GetImmediateContext(device, &context);
16296 /* Structured buffer views */
16297 buffer_desc.ByteWidth = 64;
16298 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
16299 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16300 buffer_desc.CPUAccessFlags = 0;
16301 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
16302 buffer_desc.StructureByteStride = 8;
16303 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16304 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16306 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
16307 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16309 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
16310 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16311 U(uav_desc).Buffer.FirstElement = 0;
16312 U(uav_desc).Buffer.NumElements = 4;
16313 U(uav_desc).Buffer.Flags = 0;
16314 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16315 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16317 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16319 uvec4 = uvec4_data[i];
16320 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16321 get_buffer_readback(buffer, &rb);
16322 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16323 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16324 release_resource_readback(&rb);
16326 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16327 get_buffer_readback(buffer, &rb);
16328 SetRect(&rect, 0, 0, U(uav_desc).Buffer.NumElements * buffer_desc.StructureByteStride / sizeof(uvec4.x), 1);
16329 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16330 rect.left = rect.right;
16331 rect.right = buffer_desc.ByteWidth / sizeof(uvec4.x);
16332 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16333 release_resource_readback(&rb);
16336 ID3D11Buffer_Release(buffer);
16337 ID3D11UnorderedAccessView_Release(uav);
16338 ID3D11UnorderedAccessView_Release(uav2);
16340 /* Raw buffer views */
16341 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
16342 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16343 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16345 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
16346 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16347 U(uav_desc).Buffer.FirstElement = 0;
16348 U(uav_desc).Buffer.NumElements = 16;
16349 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
16350 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16351 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16352 U(uav_desc).Buffer.FirstElement = 8;
16353 U(uav_desc).Buffer.NumElements = 8;
16354 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16355 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16357 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16359 uvec4 = uvec4_data[i];
16360 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16361 get_buffer_readback(buffer, &rb);
16362 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16363 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16364 release_resource_readback(&rb);
16366 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16367 get_buffer_readback(buffer, &rb);
16368 SetRect(&rect, 0, 0, U(uav_desc).Buffer.FirstElement, 1);
16369 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16370 SetRect(&rect, U(uav_desc).Buffer.FirstElement, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16371 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16372 release_resource_readback(&rb);
16375 ID3D11Buffer_Release(buffer);
16376 ID3D11UnorderedAccessView_Release(uav);
16377 ID3D11UnorderedAccessView_Release(uav2);
16379 /* Typed buffer views */
16380 buffer_desc.MiscFlags = 0;
16381 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16382 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16384 uav_desc.Format = DXGI_FORMAT_R32_SINT;
16385 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16386 U(uav_desc).Buffer.FirstElement = 0;
16387 U(uav_desc).Buffer.NumElements = 16;
16388 U(uav_desc).Buffer.Flags = 0;
16389 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16390 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16391 U(uav_desc).Buffer.FirstElement = 9;
16392 U(uav_desc).Buffer.NumElements = 7;
16393 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16394 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16396 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16398 uvec4 = uvec4_data[i];
16399 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16400 get_buffer_readback(buffer, &rb);
16401 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16402 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16403 release_resource_readback(&rb);
16405 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16406 get_buffer_readback(buffer, &rb);
16407 SetRect(&rect, 0, 0, U(uav_desc).Buffer.FirstElement, 1);
16408 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16409 SetRect(&rect, U(uav_desc).Buffer.FirstElement, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16410 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16411 release_resource_readback(&rb);
16414 ID3D11UnorderedAccessView_Release(uav);
16415 ID3D11UnorderedAccessView_Release(uav2);
16417 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
16418 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16419 U(uav_desc).Buffer.FirstElement = 0;
16420 U(uav_desc).Buffer.NumElements = 4;
16421 U(uav_desc).Buffer.Flags = 0;
16422 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16423 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16424 U(uav_desc).Buffer.FirstElement = 2;
16425 U(uav_desc).Buffer.NumElements = 2;
16426 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16427 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16429 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16431 const struct uvec4 *data = NULL;
16432 BOOL all_match;
16434 uvec4 = uvec4_data[i];
16435 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16436 get_buffer_readback(buffer, &rb);
16437 for (x = 0, all_match = TRUE; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
16439 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
16440 data = get_readback_uvec4(&rb, x, 0);
16441 if (!(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result))))
16443 all_match = FALSE;
16444 break;
16447 ok(all_match, "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
16448 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, x);
16449 release_resource_readback(&rb);
16451 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16452 get_buffer_readback(buffer, &rb);
16453 for (x = 0, all_match = TRUE; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
16455 struct uvec4 broken_result;
16456 data = get_readback_uvec4(&rb, x, 0);
16457 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
16458 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
16459 if (!(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result))))
16461 all_match = FALSE;
16462 break;
16465 ok(all_match, "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
16466 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, x);
16467 release_resource_readback(&rb);
16470 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
16471 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16472 ID3D11UnorderedAccessView_Release(uav);
16473 ID3D11UnorderedAccessView_Release(uav2);
16475 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
16476 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16477 U(uav_desc).Buffer.FirstElement = 0;
16478 U(uav_desc).Buffer.NumElements = 16;
16479 U(uav_desc).Buffer.Flags = 0;
16480 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16481 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16482 U(uav_desc).Buffer.FirstElement = 8;
16483 U(uav_desc).Buffer.NumElements = 8;
16484 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16485 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16487 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16489 uvec4 = uvec4_data[i];
16490 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16491 get_buffer_readback(buffer, &rb);
16492 todo_wine check_rgba_sint8(get_readback_color(&rb, 0, 0, 0), &uvec4);
16493 todo_wine check_rgba_sint8(get_readback_color(&rb, 7, 0, 0), &uvec4);
16494 todo_wine check_rgba_sint8(get_readback_color(&rb, 15, 0, 0), &uvec4);
16495 release_resource_readback(&rb);
16497 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16498 get_buffer_readback(buffer, &rb);
16499 todo_wine check_rgba_sint8(get_readback_color(&rb, 0, 0, 0), &uvec4);
16500 todo_wine check_rgba_sint8(get_readback_color(&rb, U(uav_desc).Buffer.FirstElement - 1, 0, 0), &uvec4);
16501 todo_wine check_rgba_sint8(get_readback_color(&rb, U(uav_desc).Buffer.FirstElement, 0, 0), &fe_uvec4);
16502 release_resource_readback(&rb);
16505 ID3D11UnorderedAccessView_Release(uav);
16506 ID3D11UnorderedAccessView_Release(uav2);
16508 ID3D11Buffer_Release(buffer);
16510 ID3D11DeviceContext_Release(context);
16511 refcount = ID3D11Device_Release(device);
16512 ok(!refcount, "Device has %u references left.\n", refcount);
16515 static void test_clear_image_unordered_access_view(void)
16517 unsigned int expected_colour, actual_colour;
16518 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16519 unsigned int i, j, d, p, x, y, z, layer;
16520 struct d3d11_test_context test_context;
16521 unsigned int image_size, image_depth;
16522 struct resource_desc resource_desc;
16523 ID3D11UnorderedAccessView *uav[2];
16524 ID3D11DeviceContext *context;
16525 struct resource_readback rb;
16526 BOOL is_small_float_format;
16527 ID3D11Resource *resource;
16528 BOOL is_inside, success;
16529 ID3D11Device *device;
16530 UINT clear_value[4];
16531 HRESULT hr;
16533 #define IMAGE_SIZE 16
16534 static const struct
16536 DXGI_FORMAT format;
16537 unsigned int image_mips;
16538 unsigned int image_layers;
16539 unsigned int mip_level;
16540 unsigned int first_layer;
16541 unsigned int layer_count;
16542 unsigned int values[4];
16543 unsigned int expected;
16544 BOOL is_float;
16545 unsigned int clamped;
16547 tests[] =
16549 /* Test clearing a specific mip level. */
16550 {DXGI_FORMAT_R32_FLOAT, 2, 1, 0, 0, 1, {1, 0, 0, 0}, 0x00000001},
16551 {DXGI_FORMAT_R32_FLOAT, 2, 1, 1, 0, 1, {1, 0, 0, 0}, 0x00000001},
16552 {DXGI_FORMAT_R32_FLOAT, 2, 1, 0, 0, 1, {0x3f000000, 0, 0, 0}, 0x3f000000, TRUE},
16553 {DXGI_FORMAT_R32_FLOAT, 2, 1, 1, 0, 1, {0x3f000000, 0, 0, 0}, 0x3f000000, TRUE},
16554 /* Test clearing specific array layers. */
16555 {DXGI_FORMAT_R32_FLOAT, 1, IMAGE_SIZE, 0, 0, IMAGE_SIZE, {1, 0, 0, 0}, 0x00000001},
16556 {DXGI_FORMAT_R32_FLOAT, 1, IMAGE_SIZE, 0, 3, 2, {1, 0, 0, 0}, 0x00000001},
16557 {DXGI_FORMAT_R32_FLOAT, 1, IMAGE_SIZE, 0, 0, IMAGE_SIZE, {0x3f000000, 0, 0, 0}, 0x3f000000, TRUE},
16558 {DXGI_FORMAT_R32_FLOAT, 1, IMAGE_SIZE, 0, 3, 2, {0x3f000000, 0, 0, 0}, 0x3f000000, TRUE},
16559 /* Test uint clears with formats. */
16560 {DXGI_FORMAT_R16G16_UINT, 1, 1, 0, 0, 1, {1, 2, 3, 4}, 0x00020001},
16561 {DXGI_FORMAT_R16G16_UINT, 1, 1, 0, 0, 1, {0x12345, 0, 0, 0}, 0x00002345, FALSE, 0x0000ffff},
16562 {DXGI_FORMAT_R16G16_UNORM, 1, 1, 0, 0, 1, {1, 2, 3, 4}, 0x00020001},
16563 {DXGI_FORMAT_R16G16_FLOAT, 1, 1, 0, 0, 1, {1, 2, 3, 4}, 0x00020001},
16564 {DXGI_FORMAT_R8G8B8A8_UINT, 1, 1, 0, 0, 1, {1, 2, 3, 4}, 0x04030201},
16565 {DXGI_FORMAT_R8G8B8A8_UINT, 1, 1, 0, 0, 1, {0x123, 0, 0, 0}, 0x00000023, FALSE, 0x000000ff},
16566 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1, 0, 0, 1, {1, 2, 3, 4}, 0x04030201},
16567 {DXGI_FORMAT_R11G11B10_FLOAT, 1, 1, 0, 0, 1, {1, 2, 3, 4}, 0x00c01001},
16568 /* Test float clears with formats. */
16569 {DXGI_FORMAT_R16G16_UNORM, 1, 1, 0, 0, 1,
16570 {0x3f000000 /* 0.5f */, 0x3f800000 /* 1.0f */, 0, 0}, 0xffff8000, TRUE},
16571 {DXGI_FORMAT_R16G16_FLOAT, 1, 1, 0, 0, 1,
16572 {0x3f000000 /* 0.5f */, 0x3f800000 /* 1.0f */, 0, 0}, 0x3c003800, TRUE},
16573 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1, 0, 0, 1,
16574 {0x3f000000 /* 0.5f */, 0x3f800000 /* 1.0f */, 0, 0}, 0x0000ff80, TRUE},
16575 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1, 0, 0, 1,
16576 {0, 0, 0x3f000000 /* 0.5f */, 0x3f800000 /* 1.0f */}, 0xff800000, TRUE},
16577 {DXGI_FORMAT_R11G11B10_FLOAT, 1, 1, 0, 0, 1,
16578 {0x3f000000 /* 1.0f */, 0 /* 0.0f */, 0xbf800000 /* -1.0f */, 0x3f000000 /* 1.0f */},
16579 0x00000380, TRUE},
16582 static const struct
16584 D3D11_RESOURCE_DIMENSION resource_dim;
16585 D3D11_UAV_DIMENSION view_dim;
16586 BOOL is_layered;
16588 uav_dimensions[] =
16590 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_UAV_DIMENSION_TEXTURE2D, FALSE},
16591 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_UAV_DIMENSION_TEXTURE2DARRAY, TRUE },
16592 {D3D11_RESOURCE_DIMENSION_TEXTURE3D, D3D11_UAV_DIMENSION_TEXTURE3D, TRUE },
16595 if (!init_test_context(&test_context, NULL))
16596 return;
16597 device = test_context.device;
16598 context = test_context.immediate_context;
16600 memset(&resource_desc, 0, sizeof(resource_desc));
16601 resource_desc.width = IMAGE_SIZE;
16602 resource_desc.height = IMAGE_SIZE;
16603 resource_desc.sample_desc.Count = 1;
16604 resource_desc.usage = D3D11_USAGE_DEFAULT;
16605 resource_desc.bind_flags = D3D11_BIND_UNORDERED_ACCESS;
16607 for (d = 0; d < ARRAY_SIZE(uav_dimensions); ++d)
16609 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16611 if (tests[i].image_layers > 1 && !uav_dimensions[d].is_layered)
16612 continue;
16614 /* Expected behaviour with partial layer coverage is unclear. */
16615 if (uav_dimensions[d].view_dim == D3D11_UAV_DIMENSION_TEXTURE3D
16616 && tests[i].image_layers != tests[i].layer_count)
16617 continue;
16619 winetest_push_context("Dim %u, Test %u", d, i);
16621 resource_desc.dimension = uav_dimensions[d].resource_dim;
16622 resource_desc.depth_or_array_size = tests[i].image_layers;
16623 resource_desc.level_count = tests[i].image_mips;
16624 resource_desc.format = tests[i].format;
16625 if (FAILED(hr = create_resource(device, &resource_desc, NULL, &resource)))
16627 skip("Failed to create resource, hr %#x.\n", hr);
16628 winetest_pop_context();
16629 continue;
16632 uav_desc.Format = tests[i].format;
16633 uav_desc.ViewDimension = uav_dimensions[d].view_dim;
16635 for (j = 0; j < 2; ++j)
16637 unsigned int first_layer = j ? 0 : tests[i].first_layer;
16638 unsigned int layer_count = j ? tests[i].image_layers : tests[i].layer_count;
16640 switch (uav_desc.ViewDimension)
16642 case D3D11_UAV_DIMENSION_TEXTURE2D:
16643 uav_desc.Texture2D.MipSlice = tests[i].mip_level;
16644 break;
16646 case D3D11_UAV_DIMENSION_TEXTURE2DARRAY:
16647 uav_desc.Texture2DArray.MipSlice = tests[i].mip_level;
16648 uav_desc.Texture2DArray.FirstArraySlice = first_layer;
16649 uav_desc.Texture2DArray.ArraySize = layer_count;
16650 break;
16652 case D3D11_UAV_DIMENSION_TEXTURE3D:
16653 uav_desc.Texture3D.MipSlice = tests[i].mip_level;
16654 uav_desc.Texture3D.FirstWSlice = first_layer;
16655 uav_desc.Texture3D.WSize = layer_count;
16656 break;
16658 default:
16659 ok(0, "Unhandled uav dimension %#x.\n", uav_dimensions[d].view_dim);
16660 break;
16663 hr = ID3D11Device_CreateUnorderedAccessView(device, resource, &uav_desc, &uav[j]);
16664 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
16667 for (j = 0; j < 4; ++j)
16669 clear_value[j] = tests[i].expected ? 0u : ~0u;
16672 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav[1], clear_value);
16673 if (tests[i].is_float)
16674 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav[0], (const float *)tests[i].values);
16675 else
16676 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav[0], tests[i].values);
16678 image_depth = uav_dimensions[d].resource_dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D
16679 ? max(tests[i].image_layers >> tests[i].mip_level, 1u) : 1;
16680 image_size = max(IMAGE_SIZE >> tests[i].mip_level, 1u);
16682 is_small_float_format = tests[i].format == DXGI_FORMAT_R16G16_UNORM
16683 || tests[i].format == DXGI_FORMAT_R16G16_FLOAT
16684 || tests[i].format == DXGI_FORMAT_R11G11B10_FLOAT
16685 || tests[i].format == DXGI_FORMAT_R8G8B8A8_UNORM;
16686 for (layer = 0; layer < tests[i].image_layers / image_depth; ++layer)
16688 get_resource_readback(resource, tests[i].mip_level + (layer * tests[i].image_mips), &rb);
16690 success = TRUE;
16691 expected_colour = actual_colour = x = y = z = 0;
16692 for (p = 0; p < image_depth * image_size * image_size; ++p)
16694 x = p % image_size;
16695 y = (p / image_size) % image_size;
16696 z = p / (image_size * image_size);
16698 if (uav_dimensions[d].resource_dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D)
16699 is_inside = z >= tests[i].first_layer
16700 && z < tests[i].first_layer + tests[i].layer_count;
16701 else
16702 is_inside = layer >= tests[i].first_layer
16703 && layer < tests[i].first_layer + tests[i].layer_count;
16705 expected_colour = is_inside ? tests[i].expected : clear_value[0];
16706 actual_colour = get_readback_u32(&rb, x, y, z);
16707 if (!(success = compare_color(actual_colour, expected_colour, tests[i].is_float ? 1 : 0)
16708 /* Some drivers/GPUs clamp clear values that can't
16709 * be represented by the format. (Windows 7
16710 * testbot, AMD PALM) */
16711 || broken(is_inside && tests[i].clamped && actual_colour == tests[i].clamped)
16712 /* Some drivers/GPUs mishandle integer clears of
16713 * small float/normalised formats. (AMD PALM) */
16714 || broken(is_inside && !tests[i].is_float && is_small_float_format && !actual_colour)))
16715 break;
16717 ok(success, "At layer %u, (%u,%u,%u), expected 0x%08x, got 0x%08x.\n",
16718 layer, x, y, z, expected_colour, actual_colour);
16720 release_resource_readback(&rb);
16723 ID3D11UnorderedAccessView_Release(uav[1]);
16724 ID3D11UnorderedAccessView_Release(uav[0]);
16725 ID3D11Resource_Release(resource);
16726 winetest_pop_context();
16730 release_test_context(&test_context);
16731 #undef IMAGE_SIZE
16734 static void test_initial_depth_stencil_state(void)
16736 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16737 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
16738 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16739 struct d3d11_test_context test_context;
16740 D3D11_TEXTURE2D_DESC texture_desc;
16741 ID3D11DeviceContext *context;
16742 ID3D11DepthStencilView *dsv;
16743 ID3D11Texture2D *texture;
16744 ID3D11Device *device;
16745 unsigned int count;
16746 D3D11_VIEWPORT vp;
16747 HRESULT hr;
16749 if (!init_test_context(&test_context, NULL))
16750 return;
16752 device = test_context.device;
16753 context = test_context.immediate_context;
16755 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16756 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
16757 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16758 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16759 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16761 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
16762 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16764 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
16766 count = 1;
16767 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
16769 /* check if depth function is D3D11_COMPARISON_LESS */
16770 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16771 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
16772 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.4f);
16773 draw_color_quad(&test_context, &green);
16774 draw_color_quad(&test_context, &red);
16775 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.6f, 0.6f);
16776 draw_color_quad(&test_context, &red);
16777 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16778 check_texture_float(texture, 0.4f, 1);
16780 ID3D11DepthStencilView_Release(dsv);
16781 ID3D11Texture2D_Release(texture);
16782 release_test_context(&test_context);
16785 static void test_draw_depth_only(void)
16787 struct d3d11_test_context test_context;
16788 ID3D11PixelShader *ps_color, *ps_depth;
16789 D3D11_TEXTURE2D_DESC texture_desc;
16790 ID3D11DeviceContext *context;
16791 ID3D11DepthStencilView *dsv;
16792 struct resource_readback rb;
16793 ID3D11Texture2D *texture;
16794 ID3D11Device *device;
16795 unsigned int i, j;
16796 struct vec4 depth;
16797 ID3D11Buffer *cb;
16798 HRESULT hr;
16800 static const DWORD ps_color_code[] =
16802 #if 0
16803 float4 main(float4 position : SV_POSITION) : SV_Target
16805 return float4(0.0, 1.0, 0.0, 1.0);
16807 #endif
16808 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
16809 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16810 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
16811 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16812 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
16813 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
16814 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
16816 static const DWORD ps_depth_code[] =
16818 #if 0
16819 float depth;
16821 float main() : SV_Depth
16823 return depth;
16825 #endif
16826 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
16827 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16828 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
16829 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
16830 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
16831 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
16834 if (!init_test_context(&test_context, NULL))
16835 return;
16837 device = test_context.device;
16838 context = test_context.immediate_context;
16840 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
16842 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16843 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
16844 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16845 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16846 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16848 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
16849 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16851 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
16852 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16853 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
16854 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16856 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16857 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
16858 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
16860 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16861 check_texture_float(texture, 1.0f, 1);
16862 draw_quad(&test_context);
16863 check_texture_float(texture, 0.0f, 1);
16865 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
16867 depth.x = 0.7f;
16868 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16869 draw_quad(&test_context);
16870 check_texture_float(texture, 0.0f, 1);
16871 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16872 check_texture_float(texture, 1.0f, 1);
16873 draw_quad(&test_context);
16874 check_texture_float(texture, 0.7f, 1);
16875 depth.x = 0.8f;
16876 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16877 draw_quad(&test_context);
16878 check_texture_float(texture, 0.7f, 1);
16879 depth.x = 0.5f;
16880 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16881 draw_quad(&test_context);
16882 check_texture_float(texture, 0.5f, 1);
16884 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16885 for (i = 0; i < 4; ++i)
16887 for (j = 0; j < 4; ++j)
16889 depth.x = 1.0f / 16.0f * (j + 4 * i);
16890 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16892 set_viewport(context, 160.0f * j, 120.0f * i, 160.0f, 120.0f, 0.0f, 1.0f);
16894 draw_quad(&test_context);
16897 get_texture_readback(texture, 0, &rb);
16898 for (i = 0; i < 4; ++i)
16900 for (j = 0; j < 4; ++j)
16902 float obtained_depth, expected_depth;
16904 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
16905 expected_depth = 1.0f / 16.0f * (j + 4 * i);
16906 ok(compare_float(obtained_depth, expected_depth, 1),
16907 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
16908 obtained_depth, j, i, expected_depth);
16911 release_resource_readback(&rb);
16913 ID3D11Buffer_Release(cb);
16914 ID3D11PixelShader_Release(ps_color);
16915 ID3D11PixelShader_Release(ps_depth);
16916 ID3D11DepthStencilView_Release(dsv);
16917 ID3D11Texture2D_Release(texture);
16918 release_test_context(&test_context);
16921 static void test_draw_uav_only(void)
16923 struct d3d11_test_context test_context;
16924 D3D11_TEXTURE2D_DESC texture_desc;
16925 ID3D11UnorderedAccessView *uav;
16926 ID3D11DeviceContext *context;
16927 ID3D11Texture2D *texture;
16928 ID3D11PixelShader *ps;
16929 ID3D11Device *device;
16930 HRESULT hr;
16932 static const DWORD ps_code[] =
16934 #if 0
16935 RWTexture2D<int> u;
16937 void main()
16939 InterlockedAdd(u[uint2(0, 0)], 1);
16941 #endif
16942 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
16943 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16944 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
16945 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
16946 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
16948 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16949 static const UINT values[4] = {0};
16951 if (!init_test_context(&test_context, &feature_level))
16952 return;
16954 device = test_context.device;
16955 context = test_context.immediate_context;
16957 texture_desc.Width = 1;
16958 texture_desc.Height = 1;
16959 texture_desc.MipLevels = 1;
16960 texture_desc.ArraySize = 1;
16961 texture_desc.Format = DXGI_FORMAT_R32_SINT;
16962 texture_desc.SampleDesc.Count = 1;
16963 texture_desc.SampleDesc.Quality = 0;
16964 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16965 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16966 texture_desc.CPUAccessFlags = 0;
16967 texture_desc.MiscFlags = 0;
16969 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16970 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16972 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
16973 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16975 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16976 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16978 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16979 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
16980 0, 1, &uav, NULL);
16982 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
16983 set_viewport(context, 0.0f, 0.0f, 10.0f, 10.0f, 0.0f, 0.0f);
16984 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
16985 draw_quad(&test_context);
16986 check_texture_color(texture, 100, 1);
16988 draw_quad(&test_context);
16989 draw_quad(&test_context);
16990 draw_quad(&test_context);
16991 draw_quad(&test_context);
16992 check_texture_color(texture, 500, 1);
16994 ID3D11PixelShader_Release(ps);
16995 ID3D11Texture2D_Release(texture);
16996 ID3D11UnorderedAccessView_Release(uav);
16997 release_test_context(&test_context);
17000 static void test_cb_relative_addressing(void)
17002 struct d3d11_test_context test_context;
17003 ID3D11Buffer *colors_cb, *index_cb;
17004 unsigned int i, index[4] = {0};
17005 ID3D11DeviceContext *context;
17006 ID3D11PixelShader *ps;
17007 ID3D11Device *device;
17008 HRESULT hr;
17010 static const DWORD vs_code[] =
17012 #if 0
17013 int color_index;
17015 cbuffer colors
17017 float4 colors[8];
17020 struct vs_in
17022 float4 position : POSITION;
17025 struct vs_out
17027 float4 position : SV_POSITION;
17028 float4 color : COLOR;
17031 vs_out main(const vs_in v)
17033 vs_out o;
17035 o.position = v.position;
17036 o.color = colors[color_index];
17038 return o;
17040 #endif
17041 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
17042 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17043 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
17044 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
17045 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17046 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
17047 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
17048 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
17049 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
17050 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
17051 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
17052 0x0100003e,
17054 static const DWORD ps_code[] =
17056 #if 0
17057 struct ps_in
17059 float4 position : SV_POSITION;
17060 float4 color : COLOR;
17063 float4 main(const ps_in v) : SV_TARGET
17065 return v.color;
17067 #endif
17068 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
17069 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17070 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17071 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
17072 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17073 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
17074 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17075 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
17077 static const struct
17079 float color[4];
17081 colors[10] =
17083 {{0.0f, 0.0f, 0.0f, 1.0f}},
17084 {{0.0f, 0.0f, 1.0f, 0.0f}},
17085 {{0.0f, 0.0f, 1.0f, 1.0f}},
17086 {{0.0f, 1.0f, 0.0f, 0.0f}},
17087 {{0.0f, 1.0f, 0.0f, 1.0f}},
17088 {{0.0f, 1.0f, 1.0f, 0.0f}},
17089 {{0.0f, 1.0f, 1.0f, 1.0f}},
17090 {{1.0f, 0.0f, 0.0f, 0.0f}},
17091 {{1.0f, 0.0f, 0.0f, 1.0f}},
17092 {{1.0f, 0.0f, 1.0f, 0.0f}},
17094 static const struct
17096 unsigned int index;
17097 DWORD expected;
17099 test_data[] =
17101 {0, 0xff000000},
17102 {1, 0x00ff0000},
17103 {2, 0xffff0000},
17104 {3, 0x0000ff00},
17105 {4, 0xff00ff00},
17106 {5, 0x00ffff00},
17107 {6, 0xffffff00},
17108 {7, 0x000000ff},
17110 {8, 0xff0000ff},
17111 {9, 0x00ff00ff},
17113 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
17114 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17116 if (!init_test_context(&test_context, &feature_level))
17117 return;
17119 device = test_context.device;
17120 context = test_context.immediate_context;
17122 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
17123 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
17125 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17126 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17128 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
17129 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
17130 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17132 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
17134 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
17136 index[0] = test_data[i].index;
17137 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
17139 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
17140 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
17143 ID3D11Buffer_Release(index_cb);
17144 ID3D11Buffer_Release(colors_cb);
17145 ID3D11PixelShader_Release(ps);
17147 release_test_context(&test_context);
17150 static void test_vs_input_relative_addressing(void)
17152 struct d3d11_test_context test_context;
17153 ID3D11DeviceContext *context;
17154 unsigned int offset, stride;
17155 unsigned int index[4] = {0};
17156 ID3D11PixelShader *ps;
17157 ID3D11Buffer *vb, *cb;
17158 ID3D11Device *device;
17159 unsigned int i;
17160 HRESULT hr;
17162 static const DWORD vs_code[] =
17164 #if 0
17165 struct vertex
17167 float4 position : POSITION;
17168 float4 colors[4] : COLOR;
17171 uint index;
17173 void main(vertex vin, out float4 position : SV_Position,
17174 out float4 color : COLOR)
17176 position = vin.position;
17177 color = vin.colors[index];
17179 #endif
17180 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
17181 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
17182 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
17183 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
17184 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
17185 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
17186 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
17187 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
17188 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
17189 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
17190 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
17191 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
17192 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
17193 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
17194 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
17195 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
17197 static const DWORD ps_code[] =
17199 #if 0
17200 struct vs_out
17202 float4 position : SV_POSITION;
17203 float4 color : COLOR;
17206 float4 main(struct vs_out i) : SV_TARGET
17208 return i.color;
17210 #endif
17211 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
17212 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17213 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17214 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
17215 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17216 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
17217 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
17218 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
17220 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17222 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17223 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1},
17224 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D11_INPUT_PER_INSTANCE_DATA, 1},
17225 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D11_INPUT_PER_INSTANCE_DATA, 1},
17226 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D11_INPUT_PER_INSTANCE_DATA, 1},
17228 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
17229 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17231 if (!init_test_context(&test_context, NULL))
17232 return;
17233 device = test_context.device;
17234 context = test_context.immediate_context;
17236 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17237 vs_code, sizeof(vs_code), &test_context.input_layout);
17238 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17240 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
17241 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
17243 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(colors), colors);
17244 stride = sizeof(colors);
17245 offset = 0;
17246 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
17248 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17249 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17250 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17252 for (i = 0; i < ARRAY_SIZE(colors); ++i)
17254 *index = i;
17255 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
17256 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17257 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
17258 check_texture_color(test_context.backbuffer, colors[i], 1);
17261 ID3D11Buffer_Release(cb);
17262 ID3D11Buffer_Release(vb);
17263 ID3D11PixelShader_Release(ps);
17264 release_test_context(&test_context);
17267 static void test_getdc(void)
17269 static const struct
17271 const char *name;
17272 DXGI_FORMAT format;
17273 BOOL getdc_supported;
17275 testdata[] =
17277 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
17278 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
17279 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
17280 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
17281 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
17282 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
17284 struct device_desc device_desc;
17285 D3D11_TEXTURE2D_DESC desc;
17286 ID3D11Texture2D *texture;
17287 IDXGISurface1 *surface;
17288 ID3D11Device *device;
17289 unsigned int i;
17290 ULONG refcount;
17291 HRESULT hr;
17292 HDC dc;
17294 device_desc.feature_level = NULL;
17295 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
17296 if (!(device = create_device(&device_desc)))
17298 skip("Failed to create device.\n");
17299 return;
17302 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
17303 desc.Width = 512;
17304 desc.Height = 512;
17305 desc.MipLevels = 1;
17306 desc.ArraySize = 1;
17307 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
17308 desc.SampleDesc.Count = 1;
17309 desc.SampleDesc.Quality = 0;
17310 desc.Usage = D3D11_USAGE_DEFAULT;
17311 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17312 desc.CPUAccessFlags = 0;
17313 desc.MiscFlags = 0;
17314 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
17315 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17317 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
17318 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
17320 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
17321 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
17323 IDXGISurface1_Release(surface);
17324 ID3D11Texture2D_Release(texture);
17326 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
17327 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
17328 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17330 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
17331 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
17333 hr = IDXGISurface1_ReleaseDC(surface, NULL);
17334 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
17336 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
17337 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
17339 hr = IDXGISurface1_ReleaseDC(surface, NULL);
17340 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
17342 IDXGISurface1_Release(surface);
17343 ID3D11Texture2D_Release(texture);
17345 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
17347 static const unsigned int bit_count = 32;
17348 unsigned int width_bytes;
17349 DIBSECTION dib;
17350 HBITMAP bitmap;
17351 DWORD type;
17352 int size;
17354 desc.Width = 64;
17355 desc.Height = 64;
17356 desc.MipLevels = 1;
17357 desc.ArraySize = 1;
17358 desc.Format = testdata[i].format;
17359 desc.SampleDesc.Count = 1;
17360 desc.SampleDesc.Quality = 0;
17361 desc.Usage = D3D11_USAGE_STAGING;
17362 desc.BindFlags = 0;
17363 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
17364 desc.MiscFlags = 0;
17366 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
17367 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17368 ID3D11Texture2D_Release(texture);
17370 /* STAGING usage, requesting GDI compatibility mode. */
17371 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
17372 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
17373 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
17375 desc.Usage = D3D11_USAGE_DEFAULT;
17376 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17377 desc.CPUAccessFlags = 0;
17378 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
17379 if (testdata[i].getdc_supported)
17380 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
17381 else
17382 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
17384 if (FAILED(hr))
17385 continue;
17387 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
17388 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
17390 dc = (void *)0x1234;
17391 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
17392 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
17394 if (FAILED(hr))
17396 IDXGISurface1_Release(surface);
17397 ID3D11Texture2D_Release(texture);
17398 continue;
17401 type = GetObjectType(dc);
17402 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
17403 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
17404 type = GetObjectType(bitmap);
17405 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
17407 size = GetObjectA(bitmap, sizeof(dib), &dib);
17408 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
17409 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
17411 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
17412 dib.dsBm.bmType, testdata[i].name);
17413 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
17414 dib.dsBm.bmWidth, testdata[i].name);
17415 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
17416 dib.dsBm.bmHeight, testdata[i].name);
17417 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
17418 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
17419 dib.dsBm.bmWidthBytes, testdata[i].name);
17420 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
17421 dib.dsBm.bmPlanes, testdata[i].name);
17422 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
17423 dib.dsBm.bmBitsPixel, testdata[i].name);
17425 if (size == sizeof(dib))
17426 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
17427 dib.dsBm.bmBits, testdata[i].name);
17428 else
17429 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
17430 dib.dsBm.bmBits, testdata[i].name);
17432 if (size == sizeof(dib))
17434 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
17435 dib.dsBmih.biSize, testdata[i].name);
17436 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
17437 dib.dsBmih.biHeight, testdata[i].name);
17438 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
17439 dib.dsBmih.biHeight, testdata[i].name);
17440 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
17441 dib.dsBmih.biPlanes, testdata[i].name);
17442 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
17443 dib.dsBmih.biBitCount, testdata[i].name);
17444 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
17445 dib.dsBmih.biCompression, testdata[i].name);
17446 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
17447 dib.dsBmih.biSizeImage, testdata[i].name);
17448 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
17449 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
17450 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
17451 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
17452 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
17453 dib.dsBmih.biClrUsed, testdata[i].name);
17454 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
17455 dib.dsBmih.biClrImportant, testdata[i].name);
17456 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
17457 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
17458 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
17459 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
17460 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
17463 hr = IDXGISurface1_ReleaseDC(surface, NULL);
17464 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
17466 IDXGISurface1_Release(surface);
17467 ID3D11Texture2D_Release(texture);
17470 refcount = ID3D11Device_Release(device);
17471 ok(!refcount, "Device has %u references left.\n", refcount);
17474 static void test_shader_stage_input_output_matching(void)
17476 struct d3d11_test_context test_context;
17477 D3D11_TEXTURE2D_DESC texture_desc;
17478 ID3D11Texture2D *render_target;
17479 ID3D11RenderTargetView *rtv[2];
17480 ID3D11DeviceContext *context;
17481 ID3D11VertexShader *vs;
17482 ID3D11PixelShader *ps;
17483 ID3D11Device *device;
17484 HRESULT hr;
17486 static const DWORD vs_code[] =
17488 #if 0
17489 struct output
17491 float4 position : SV_PoSiTion;
17492 float4 color0 : COLOR0;
17493 float4 color1 : COLOR1;
17496 void main(uint id : SV_VertexID, out output o)
17498 float2 coords = float2((id << 1) & 2, id & 2);
17499 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
17500 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
17501 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
17503 #endif
17504 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
17505 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17506 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
17507 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
17508 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17509 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
17510 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
17511 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
17512 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
17513 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
17514 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
17515 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
17516 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
17517 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
17518 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
17519 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
17520 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
17521 0x0100003e,
17523 static const DWORD ps_code[] =
17525 #if 0
17526 struct input
17528 float4 position : SV_PoSiTiOn;
17529 float4 color1 : COLOR1;
17530 float4 color0 : COLOR0;
17533 struct output
17535 float4 target0 : SV_Target0;
17536 float4 target1 : SV_Target1;
17539 void main(const in input i, out output o)
17541 o.target0 = i.color0;
17542 o.target1 = i.color1;
17544 #endif
17545 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
17546 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
17547 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
17548 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
17549 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
17550 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
17551 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
17552 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
17553 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
17554 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
17555 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
17558 if (!init_test_context(&test_context, NULL))
17559 return;
17561 device = test_context.device;
17562 context = test_context.immediate_context;
17564 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17565 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17566 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17567 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17569 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17570 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
17571 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17573 rtv[0] = test_context.backbuffer_rtv;
17574 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
17575 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17577 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17578 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17579 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
17580 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
17581 ID3D11DeviceContext_Draw(context, 3, 0);
17583 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17584 check_texture_color(render_target, 0xff0000ff, 0);
17586 ID3D11RenderTargetView_Release(rtv[1]);
17587 ID3D11Texture2D_Release(render_target);
17588 ID3D11PixelShader_Release(ps);
17589 ID3D11VertexShader_Release(vs);
17590 release_test_context(&test_context);
17593 static void test_unbound_streams(void)
17595 struct d3d11_test_context test_context;
17596 ID3D11DeviceContext *context;
17597 ID3D11PixelShader *ps;
17598 ID3D11Device *device;
17599 HRESULT hr;
17601 static const DWORD vs_code[] =
17603 #if 0
17604 struct vs_ps
17606 float4 position : SV_POSITION;
17607 float4 color : COLOR0;
17610 vs_ps vs_main(float4 position : POSITION, float4 color : COLOR0)
17612 vs_ps result;
17613 result.position = position;
17614 result.color = color;
17615 result.color.w = 1.0;
17616 return result;
17618 #endif
17619 0x43425844, 0x4a9efaec, 0xe2c6cdf5, 0x15dd28a7, 0xae68e320, 0x00000001, 0x00000154, 0x00000003,
17620 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
17621 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
17622 0x00000003, 0x00000001, 0x0000070f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
17623 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
17624 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
17625 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x0000007c, 0x00010040, 0x0000001f,
17626 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101072, 0x00000001, 0x04000067, 0x001020f2,
17627 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
17628 0x00101e46, 0x00000000, 0x05000036, 0x00102072, 0x00000001, 0x00101246, 0x00000001, 0x05000036,
17629 0x00102082, 0x00000001, 0x00004001, 0x3f800000, 0x0100003e,
17632 static const DWORD ps_code[] =
17634 #if 0
17635 float4 ps_main(vs_ps input) : SV_TARGET
17637 return input.color;
17639 #endif
17640 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
17641 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17642 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17643 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
17644 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17645 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
17646 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
17647 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
17650 static const float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
17652 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17654 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17655 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
17658 if (!init_test_context(&test_context, NULL))
17659 return;
17661 device = test_context.device;
17662 context = test_context.immediate_context;
17664 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17665 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17667 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17668 vs_code, sizeof(vs_code), &test_context.input_layout);
17669 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17671 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17672 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17673 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
17674 check_texture_color(test_context.backbuffer, 0xff000000, 1);
17676 ID3D11PixelShader_Release(ps);
17677 release_test_context(&test_context);
17680 static void test_shader_interstage_interface(void)
17682 struct d3d11_test_context test_context;
17683 D3D11_TEXTURE2D_DESC texture_desc;
17684 ID3D11InputLayout *input_layout;
17685 ID3D11Texture2D *render_target;
17686 ID3D11DeviceContext *context;
17687 ID3D11RenderTargetView *rtv;
17688 ID3D11VertexShader *vs;
17689 ID3D11PixelShader *ps;
17690 ID3D11Device *device;
17691 UINT stride, offset;
17692 ID3D11Buffer *vb;
17693 unsigned int i;
17694 HRESULT hr;
17696 static const DWORD vs_code[] =
17698 #if 0
17699 struct vertex
17701 float4 position : SV_Position;
17702 float2 t0 : TEXCOORD0;
17703 nointerpolation float t1 : TEXCOORD1;
17704 uint t2 : TEXCOORD2;
17705 uint t3 : TEXCOORD3;
17706 float t4 : TEXCOORD4;
17709 void main(in vertex vin, out vertex vout)
17711 vout = vin;
17713 #endif
17714 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
17715 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
17716 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
17717 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
17718 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
17719 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
17720 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17721 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
17722 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
17723 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
17724 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
17725 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
17726 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
17727 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
17728 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
17729 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
17730 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
17731 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
17732 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
17733 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
17734 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
17735 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
17737 static const DWORD ps_code[] =
17739 #if 0
17740 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
17741 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
17742 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
17744 o.x = t0.y + t1;
17745 o.y = t2 + t3;
17746 o.z = t4;
17747 o.w = t0.x;
17749 #endif
17750 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
17751 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
17752 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
17753 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
17754 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
17755 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
17756 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17757 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
17758 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
17759 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
17760 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
17761 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
17762 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
17763 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
17764 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
17766 static const DWORD ps_partial_input_code[] =
17768 #if 0
17769 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
17770 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
17771 uint t3 : TEXCOORD3, out float4 o : SV_Target)
17773 o.x = t0.y + t1;
17774 o.y = t2 + t3;
17775 o.z = 0.0f;
17776 o.w = t0.x;
17778 #endif
17779 0x43425844, 0x5b1db356, 0xaa5a5e9d, 0xb916a081, 0x61e6dcb1, 0x00000001, 0x000001cc, 0x00000003,
17780 0x0000002c, 0x000000cc, 0x00000100, 0x4e475349, 0x00000098, 0x00000005, 0x00000008, 0x00000080,
17781 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
17782 0x00000003, 0x00000001, 0x00000303, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
17783 0x00000101, 0x0000008c, 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x0000008c,
17784 0x00000003, 0x00000000, 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
17785 0x43584554, 0x44524f4f, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17786 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
17787 0x52444853, 0x000000c4, 0x00000040, 0x00000031, 0x03001062, 0x00101032, 0x00000001, 0x03000862,
17788 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042, 0x00000002,
17789 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012, 0x00000000,
17790 0x0010102a, 0x00000002, 0x0010101a, 0x00000002, 0x05000056, 0x00102022, 0x00000000, 0x0010000a,
17791 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a, 0x00000002,
17792 0x05000036, 0x00102042, 0x00000000, 0x00004001, 0x00000000, 0x05000036, 0x00102082, 0x00000000,
17793 0x0010100a, 0x00000001, 0x0100003e,
17795 static const DWORD ps_single_input_code[] =
17797 #if 0
17798 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0, out float4 o : SV_Target)
17800 o.x = t0.x;
17801 o.y = t0.y;
17802 o.z = 1.0f;
17803 o.w = 2.0f;
17805 #endif
17806 0x43425844, 0x7cc601b6, 0xc65b8bdb, 0x54d0f606, 0x9cc74d3d, 0x00000001, 0x00000118, 0x00000003,
17807 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
17808 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17809 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17810 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
17811 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058,
17812 0x00000040, 0x00000016, 0x03001062, 0x00101032, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17813 0x05000036, 0x00102032, 0x00000000, 0x00101046, 0x00000001, 0x08000036, 0x001020c2, 0x00000000,
17814 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x40000000, 0x0100003e,
17816 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17818 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17819 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
17820 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
17821 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
17822 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
17823 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
17825 static const struct
17827 struct vec2 position;
17828 struct vec2 t0;
17829 float t1;
17830 unsigned int t2;
17831 unsigned int t3;
17832 float t4;
17834 quad[] =
17836 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17837 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17838 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17839 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17841 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17842 static const struct
17844 const DWORD *ps_code;
17845 size_t ps_size;
17846 struct vec4 expected_result;
17848 tests[] =
17850 {ps_code, sizeof(ps_code), {10.0f, 8.0f, 7.0f, 3.0f}},
17851 {ps_partial_input_code, sizeof(ps_partial_input_code), {10.0f, 8.0f, 0.0f, 3.0f}},
17852 {ps_single_input_code, sizeof(ps_single_input_code), {3.0f, 5.0f, 1.0f, 2.0f}},
17855 if (!init_test_context(&test_context, NULL))
17856 return;
17858 device = test_context.device;
17859 context = test_context.immediate_context;
17861 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17862 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17864 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17865 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17866 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
17867 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17869 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
17870 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17872 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17873 vs_code, sizeof(vs_code), &input_layout);
17874 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17876 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
17878 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
17880 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17881 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17882 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
17883 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
17884 offset = 0;
17885 stride = sizeof(*quad);
17886 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
17888 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17890 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_size, NULL, &ps);
17891 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
17892 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17893 ID3D11DeviceContext_Draw(context, 4, 0);
17894 check_texture_vec4(render_target, &tests[i].expected_result, 0);
17895 ID3D11PixelShader_Release(ps);
17898 ID3D11InputLayout_Release(input_layout);
17899 ID3D11RenderTargetView_Release(rtv);
17900 ID3D11Texture2D_Release(render_target);
17901 ID3D11VertexShader_Release(vs);
17902 ID3D11Buffer_Release(vb);
17903 release_test_context(&test_context);
17906 static void test_sm4_if_instruction(void)
17908 struct d3d11_test_context test_context;
17909 ID3D11PixelShader *ps_if_nz, *ps_if_z;
17910 ID3D11DeviceContext *context;
17911 ID3D11Device *device;
17912 unsigned int bits[4];
17913 DWORD expected_color;
17914 ID3D11Buffer *cb;
17915 unsigned int i;
17916 HRESULT hr;
17918 static const DWORD ps_if_nz_code[] =
17920 #if 0
17921 uint bits;
17923 float4 main() : SV_TARGET
17925 if (bits)
17926 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17927 else
17928 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17930 #endif
17931 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
17932 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17933 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17934 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
17935 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
17936 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17937 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17938 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17940 static const DWORD ps_if_z_code[] =
17942 #if 0
17943 uint bits;
17945 float4 main() : SV_TARGET
17947 if (!bits)
17948 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17949 else
17950 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17952 #endif
17953 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
17954 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17955 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17956 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
17957 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
17958 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17959 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17960 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17962 static unsigned int bit_patterns[] =
17964 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
17967 if (!init_test_context(&test_context, NULL))
17968 return;
17970 device = test_context.device;
17971 context = test_context.immediate_context;
17973 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
17974 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
17975 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
17976 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
17978 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
17979 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17981 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
17983 *bits = bit_patterns[i];
17984 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
17986 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
17987 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
17988 draw_quad(&test_context);
17989 check_texture_color(test_context.backbuffer, expected_color, 0);
17991 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
17992 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
17993 draw_quad(&test_context);
17994 check_texture_color(test_context.backbuffer, expected_color, 0);
17997 ID3D11Buffer_Release(cb);
17998 ID3D11PixelShader_Release(ps_if_z);
17999 ID3D11PixelShader_Release(ps_if_nz);
18000 release_test_context(&test_context);
18003 static void test_sm4_breakc_instruction(void)
18005 struct d3d11_test_context test_context;
18006 ID3D11DeviceContext *context;
18007 ID3D11PixelShader *ps;
18008 ID3D11Device *device;
18009 HRESULT hr;
18011 static const DWORD ps_breakc_nz_code[] =
18013 #if 0
18014 float4 main() : SV_TARGET
18016 uint counter = 0;
18018 for (uint i = 0; i < 255; ++i)
18019 ++counter;
18021 if (counter == 255)
18022 return float4(0.0f, 1.0f, 0.0f, 1.0f);
18023 else
18024 return float4(1.0f, 0.0f, 0.0f, 1.0f);
18026 #endif
18027 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
18028 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18029 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18030 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
18031 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
18032 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
18033 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
18034 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
18035 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
18036 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
18037 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
18038 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
18039 0x01000015, 0x0100003e,
18041 static const DWORD ps_breakc_z_code[] =
18043 #if 0
18044 float4 main() : SV_TARGET
18046 uint counter = 0;
18048 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
18049 ++counter;
18051 if (counter == 255)
18052 return float4(0.0f, 1.0f, 0.0f, 1.0f);
18053 else
18054 return float4(1.0f, 0.0f, 0.0f, 1.0f);
18056 #endif
18057 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
18058 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18059 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18060 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
18061 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
18062 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
18063 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
18064 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
18065 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
18066 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
18067 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
18068 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
18069 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
18070 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
18073 if (!init_test_context(&test_context, NULL))
18074 return;
18076 device = test_context.device;
18077 context = test_context.immediate_context;
18079 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
18080 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
18081 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18082 draw_quad(&test_context);
18083 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18084 ID3D11PixelShader_Release(ps);
18086 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
18087 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
18088 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18089 draw_quad(&test_context);
18090 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18091 ID3D11PixelShader_Release(ps);
18093 release_test_context(&test_context);
18096 static void test_sm4_continuec_instruction(void)
18098 struct d3d11_test_context test_context;
18099 ID3D11DeviceContext *context;
18100 ID3D11PixelShader *ps;
18101 ID3D11Device *device;
18102 HRESULT hr;
18104 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
18105 * with a normal continue inside, the shaders have been compiled with
18106 * the /Gfa flag. */
18107 static const DWORD ps_continuec_nz_code[] =
18109 #if 0
18110 float4 main() : SV_TARGET
18112 uint counter = 0;
18113 int i = -1;
18115 while (i < 255) {
18116 ++i;
18118 if (i != 0)
18119 continue;
18121 ++counter;
18124 if (counter == 1)
18125 return float4(0.0f, 1.0f, 0.0f, 1.0f);
18126 else
18127 return float4(1.0f, 0.0f, 0.0f, 1.0f);
18129 #endif
18130 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
18131 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18132 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18133 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
18134 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
18135 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
18136 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
18137 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
18138 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
18139 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
18140 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
18141 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
18142 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
18143 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
18144 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
18145 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
18146 0x3f800000, 0x0100003e,
18149 static const DWORD ps_continuec_z_code[] =
18151 #if 0
18152 float4 main() : SV_TARGET
18154 uint counter = 0;
18155 int i = -1;
18157 while (i < 255) {
18158 ++i;
18160 if (i == 0)
18161 continue;
18163 ++counter;
18166 if (counter == 255)
18167 return float4(0.0f, 1.0f, 0.0f, 1.0f);
18168 else
18169 return float4(1.0f, 0.0f, 0.0f, 1.0f);
18171 #endif
18172 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
18173 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18174 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18175 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
18176 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
18177 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
18178 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
18179 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
18180 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
18181 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
18182 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
18183 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
18184 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
18185 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
18186 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
18189 if (!init_test_context(&test_context, NULL))
18190 return;
18192 device = test_context.device;
18193 context = test_context.immediate_context;
18195 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
18196 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
18197 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18198 draw_quad(&test_context);
18199 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18200 ID3D11PixelShader_Release(ps);
18202 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
18203 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
18204 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18205 draw_quad(&test_context);
18206 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18207 ID3D11PixelShader_Release(ps);
18209 release_test_context(&test_context);
18212 static void test_sm4_discard_instruction(void)
18214 ID3D11PixelShader *ps_discard_nz, *ps_discard_z;
18215 struct d3d11_test_context test_context;
18216 ID3D11DeviceContext *context;
18217 ID3D11Device *device;
18218 ID3D11Buffer *cb;
18219 unsigned int i;
18220 HRESULT hr;
18222 static const DWORD ps_discard_nz_code[] =
18224 #if 0
18225 uint data;
18227 float4 main() : SV_Target
18229 if (data)
18230 discard;
18231 return float4(0.0f, 0.5f, 0.0f, 1.0f);
18233 #endif
18234 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
18235 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18236 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18237 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
18238 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
18239 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
18240 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
18242 static const DWORD ps_discard_z_code[] =
18244 #if 0
18245 uint data;
18247 float4 main() : SV_Target
18249 if (!data)
18250 discard;
18251 return float4(0.0f, 1.0f, 0.0f, 1.0f);
18253 #endif
18254 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
18255 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18256 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18257 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
18258 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
18259 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
18260 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
18262 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
18263 static const struct uvec4 values[] =
18265 {0x0000000},
18266 {0x0000001},
18267 {0x8000000},
18268 {0xfffffff},
18271 if (!init_test_context(&test_context, NULL))
18272 return;
18274 device = test_context.device;
18275 context = test_context.immediate_context;
18277 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
18278 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18280 hr = ID3D11Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code),
18281 NULL, &ps_discard_nz);
18282 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
18283 hr = ID3D11Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code),
18284 NULL, &ps_discard_z);
18285 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
18287 for (i = 0; i < ARRAY_SIZE(values); ++i)
18289 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &values[i], 0, 0);
18291 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
18292 ID3D11DeviceContext_PSSetShader(context, ps_discard_nz, NULL, 0);
18293 draw_quad(&test_context);
18294 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
18296 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
18297 ID3D11DeviceContext_PSSetShader(context, ps_discard_z, NULL, 0);
18298 draw_quad(&test_context);
18299 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
18302 ID3D11Buffer_Release(cb);
18303 ID3D11PixelShader_Release(ps_discard_nz);
18304 ID3D11PixelShader_Release(ps_discard_z);
18305 release_test_context(&test_context);
18308 static void test_sm5_swapc_instruction(void)
18310 struct input
18312 struct uvec4 src0;
18313 struct uvec4 src1;
18314 struct uvec4 src2;
18317 struct d3d11_test_context test_context;
18318 D3D11_TEXTURE2D_DESC texture_desc;
18319 ID3D11DeviceContext *context;
18320 ID3D11RenderTargetView *rtv;
18321 ID3D11Texture2D *texture;
18322 ID3D11PixelShader *ps[6];
18323 ID3D11Device *device;
18324 ID3D11Buffer *cb;
18325 unsigned int i;
18326 HRESULT hr;
18328 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18329 static const DWORD ps_swapc0_code[] =
18331 #if 0
18332 ps_5_0
18333 dcl_globalFlags refactoringAllowed
18334 dcl_constantbuffer cb0[3], immediateIndexed
18335 dcl_output o0.xyzw
18336 dcl_temps 2
18337 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
18338 mov o0.xyzw, r0.xyzw
18340 #endif
18341 0x43425844, 0x9e089246, 0x9f8b5cbe, 0xbac66faf, 0xaef23488, 0x00000001, 0x000000f8, 0x00000003,
18342 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18343 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18344 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
18345 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18346 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
18347 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
18348 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
18350 static const DWORD ps_swapc1_code[] =
18352 #if 0
18353 ps_5_0
18354 dcl_globalFlags refactoringAllowed
18355 dcl_constantbuffer cb0[3], immediateIndexed
18356 dcl_output o0.xyzw
18357 dcl_temps 2
18358 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
18359 mov o0.xyzw, r1.xyzw
18361 #endif
18362 0x43425844, 0xf2daed61, 0xede211f7, 0x7300dbea, 0x573ed49f, 0x00000001, 0x000000f8, 0x00000003,
18363 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18364 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18365 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
18366 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18367 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
18368 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
18369 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
18371 static const DWORD ps_swapc2_code[] =
18373 #if 0
18374 ps_5_0
18375 dcl_globalFlags refactoringAllowed
18376 dcl_constantbuffer cb0[3], immediateIndexed
18377 dcl_output o0.xyzw
18378 dcl_temps 2
18379 mov r0.xyzw, cb0[1].xyzw
18380 mov r1.xyzw, cb0[2].xyzw
18381 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
18382 mov o0.xyzw, r0.xyzw
18384 #endif
18385 0x43425844, 0x230fcb22, 0x70d99148, 0x65814d89, 0x97473498, 0x00000001, 0x00000120, 0x00000003,
18386 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18387 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18388 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
18389 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18390 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
18391 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
18392 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
18393 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
18395 static const DWORD ps_swapc3_code[] =
18397 #if 0
18398 ps_5_0
18399 dcl_globalFlags refactoringAllowed
18400 dcl_constantbuffer cb0[3], immediateIndexed
18401 dcl_output o0.xyzw
18402 dcl_temps 2
18403 mov r0.xyzw, cb0[1].xyzw
18404 mov r1.xyzw, cb0[2].xyzw
18405 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
18406 mov o0.xyzw, r1.xyzw
18408 #endif
18409 0x43425844, 0xce595d62, 0x98305541, 0xb04e74c8, 0xfc010f3a, 0x00000001, 0x00000120, 0x00000003,
18410 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18411 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18412 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
18413 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18414 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
18415 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
18416 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
18417 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
18419 static const DWORD ps_swapc4_code[] =
18421 #if 0
18422 ps_5_0
18423 dcl_globalFlags refactoringAllowed
18424 dcl_constantbuffer cb0[3], immediateIndexed
18425 dcl_output o0.xyzw
18426 dcl_temps 2
18427 mov r0.xyzw, cb0[0].xyzw
18428 swapc r0.xyzw, r1.xyzw, r0.xyzw, cb0[1].xyzw, cb0[2].xyzw
18429 mov o0.xyzw, r0.xyzw
18431 #endif
18432 0x43425844, 0x72067c48, 0xb53572a0, 0x9dd9e0fd, 0x903e37e3, 0x00000001, 0x0000010c, 0x00000003,
18433 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18434 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18435 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
18436 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18437 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
18438 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000000, 0x00208e46,
18439 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
18440 0x00100e46, 0x00000000, 0x0100003e,
18442 static const DWORD ps_swapc5_code[] =
18444 #if 0
18445 ps_5_0
18446 dcl_globalFlags refactoringAllowed
18447 dcl_constantbuffer cb0[3], immediateIndexed
18448 dcl_output o0.xyzw
18449 dcl_temps 2
18450 mov r1.xyzw, cb0[0].xyzw
18451 swapc r0.xyzw, r1.xyzw, r1.xyzw, cb0[1].xyzw, cb0[2].xyzw
18452 mov o0.xyzw, r1.xyzw
18454 #endif
18455 0x43425844, 0x7078fb08, 0xdd24cd44, 0x469d3258, 0x9e33a0bc, 0x00000001, 0x0000010c, 0x00000003,
18456 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18457 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18458 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
18459 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18460 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000,
18461 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001, 0x00208e46,
18462 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
18463 0x00100e46, 0x00000001, 0x0100003e,
18465 static const struct
18467 struct input input;
18468 struct uvec4 dst0;
18469 struct uvec4 dst1;
18471 tests[] =
18474 {{0, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18475 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}
18478 {{1, 1, 1, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18479 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
18482 {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
18483 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18484 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
18487 {{1, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18488 {0xaaaa, 0xc0de, 0xcccc, 0xeeee}, {0xdead, 0xbbbb, 0xffff, 0xdddd},
18491 {{1, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18492 {0xaaaa, 0xc0de, 0xffff, 0xdddd}, {0xdead, 0xbbbb, 0xcccc, 0xeeee},
18495 {{1, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18496 {0xaaaa, 0xc0de, 0xffff, 0xeeee}, {0xdead, 0xbbbb, 0xcccc, 0xdddd}
18499 {{0, 1, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18500 {0xdead, 0xbbbb, 0xffff, 0xeeee}, {0xaaaa, 0xc0de, 0xcccc, 0xdddd}
18503 {{0, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18504 {0xdead, 0xc0de, 0xcccc, 0xeeee}, {0xaaaa, 0xbbbb, 0xffff, 0xdddd}
18507 {{0, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18508 {0xdead, 0xc0de, 0xffff, 0xdddd}, {0xaaaa, 0xbbbb, 0xcccc, 0xeeee},
18512 if (!init_test_context(&test_context, &feature_level))
18513 return;
18515 device = test_context.device;
18516 context = test_context.immediate_context;
18518 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18519 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
18520 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18521 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18523 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18524 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
18526 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18528 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct input), NULL);
18529 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18531 hr = ID3D11Device_CreatePixelShader(device, ps_swapc0_code, sizeof(ps_swapc0_code), NULL, &ps[0]);
18532 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18533 hr = ID3D11Device_CreatePixelShader(device, ps_swapc1_code, sizeof(ps_swapc1_code), NULL, &ps[1]);
18534 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18535 hr = ID3D11Device_CreatePixelShader(device, ps_swapc2_code, sizeof(ps_swapc2_code), NULL, &ps[2]);
18536 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18537 hr = ID3D11Device_CreatePixelShader(device, ps_swapc3_code, sizeof(ps_swapc3_code), NULL, &ps[3]);
18538 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18539 hr = ID3D11Device_CreatePixelShader(device, ps_swapc4_code, sizeof(ps_swapc4_code), NULL, &ps[4]);
18540 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18541 hr = ID3D11Device_CreatePixelShader(device, ps_swapc5_code, sizeof(ps_swapc5_code), NULL, &ps[5]);
18542 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18544 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18546 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &tests[i].input, 0, 0);
18548 ID3D11DeviceContext_PSSetShader(context, ps[0], NULL, 0);
18549 draw_quad(&test_context);
18550 check_texture_uvec4(texture, &tests[i].dst0);
18552 ID3D11DeviceContext_PSSetShader(context, ps[1], NULL, 0);
18553 draw_quad(&test_context);
18554 check_texture_uvec4(texture, &tests[i].dst1);
18556 ID3D11DeviceContext_PSSetShader(context, ps[2], NULL, 0);
18557 draw_quad(&test_context);
18558 check_texture_uvec4(texture, &tests[i].dst0);
18560 ID3D11DeviceContext_PSSetShader(context, ps[3], NULL, 0);
18561 draw_quad(&test_context);
18562 check_texture_uvec4(texture, &tests[i].dst1);
18564 ID3D11DeviceContext_PSSetShader(context, ps[4], NULL, 0);
18565 draw_quad(&test_context);
18566 check_texture_uvec4(texture, &tests[i].dst0);
18568 ID3D11DeviceContext_PSSetShader(context, ps[5], NULL, 0);
18569 draw_quad(&test_context);
18570 check_texture_uvec4(texture, &tests[i].dst1);
18573 for (i = 0; i < ARRAY_SIZE(ps); ++i)
18574 ID3D11PixelShader_Release(ps[i]);
18575 ID3D11RenderTargetView_Release(rtv);
18576 ID3D11Texture2D_Release(texture);
18577 ID3D11Buffer_Release(cb);
18578 release_test_context(&test_context);
18581 static void test_create_input_layout(void)
18583 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
18585 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18587 ULONG refcount, expected_refcount;
18588 ID3D11InputLayout *input_layout;
18589 ID3D11Device *device;
18590 unsigned int i;
18591 HRESULT hr;
18593 static const DWORD vs_code[] =
18595 #if 0
18596 float4 main(float4 position : POSITION) : SV_POSITION
18598 return position;
18600 #endif
18601 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
18602 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18603 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
18604 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
18605 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
18606 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18607 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
18609 static const DXGI_FORMAT vertex_formats[] =
18611 DXGI_FORMAT_R32G32_FLOAT,
18612 DXGI_FORMAT_R32G32_UINT,
18613 DXGI_FORMAT_R32G32_SINT,
18614 DXGI_FORMAT_R16G16_FLOAT,
18615 DXGI_FORMAT_R16G16_UINT,
18616 DXGI_FORMAT_R16G16_SINT,
18617 DXGI_FORMAT_R11G11B10_FLOAT,
18618 DXGI_FORMAT_R32_FLOAT,
18619 DXGI_FORMAT_R32_UINT,
18620 DXGI_FORMAT_R32_SINT,
18621 DXGI_FORMAT_R16_FLOAT,
18622 DXGI_FORMAT_R16_UINT,
18623 DXGI_FORMAT_R16_SINT,
18624 DXGI_FORMAT_R8G8_UNORM,
18625 DXGI_FORMAT_R8_UINT,
18626 DXGI_FORMAT_R8_SINT,
18629 if (!(device = create_device(NULL)))
18631 skip("Failed to create device.\n");
18632 return;
18635 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
18637 expected_refcount = get_refcount(device) + 1;
18638 layout_desc->Format = vertex_formats[i];
18639 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
18640 vs_code, sizeof(vs_code), &input_layout);
18641 ok(hr == S_OK, "Failed to create input layout for format %#x, hr %#x.\n",
18642 vertex_formats[i], hr);
18643 refcount = get_refcount(device);
18644 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
18645 refcount, expected_refcount);
18646 ID3D11InputLayout_Release(input_layout);
18649 refcount = ID3D11Device_Release(device);
18650 ok(!refcount, "Device has %u references left.\n", refcount);
18653 static void test_input_layout_alignment(void)
18655 ID3D11InputLayout *layout;
18656 ID3D11Device *device;
18657 unsigned int i;
18658 ULONG refcount;
18659 HRESULT hr;
18661 static const DWORD vs_code[] =
18663 #if 0
18664 float4 main(float4 position : POSITION) : SV_POSITION
18666 return position;
18668 #endif
18669 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
18670 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18671 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
18672 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
18673 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
18674 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18675 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
18678 static const struct
18680 D3D11_INPUT_ELEMENT_DESC elements[2];
18681 HRESULT hr;
18683 test_data[] =
18686 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18687 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18688 }, S_OK},
18690 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18691 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 1, D3D11_INPUT_PER_VERTEX_DATA, 0},
18692 }, E_INVALIDARG},
18694 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18695 {"COLOR", 0, DXGI_FORMAT_R8_UINT, 0, 1, D3D11_INPUT_PER_VERTEX_DATA, 0},
18696 }, S_OK},
18698 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18699 {"COLOR", 0, DXGI_FORMAT_R32_UINT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18700 }, E_INVALIDARG},
18702 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18703 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18704 }, E_INVALIDARG},
18706 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18707 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
18708 }, S_OK},
18710 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18711 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 17, D3D11_INPUT_PER_VERTEX_DATA, 0},
18712 }, E_INVALIDARG},
18714 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18715 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 18, D3D11_INPUT_PER_VERTEX_DATA, 0},
18716 }, E_INVALIDARG},
18718 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18719 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 19, D3D11_INPUT_PER_VERTEX_DATA, 0},
18720 }, E_INVALIDARG},
18722 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18723 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
18724 }, S_OK},
18727 if (!(device = create_device(NULL)))
18729 skip("Failed to create device.\n");
18730 return;
18733 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
18735 hr = ID3D11Device_CreateInputLayout(device, test_data[i].elements, 2, vs_code, sizeof(vs_code), &layout);
18736 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
18737 if (SUCCEEDED(hr))
18738 ID3D11InputLayout_Release(layout);
18741 refcount = ID3D11Device_Release(device);
18742 ok(!refcount, "Device has %u references left.\n", refcount);
18745 static void test_input_assembler(void)
18747 enum layout_id
18749 LAYOUT_FLOAT32,
18750 LAYOUT_UINT16,
18751 LAYOUT_SINT16,
18752 LAYOUT_UNORM16,
18753 LAYOUT_SNORM16,
18754 LAYOUT_UINT8,
18755 LAYOUT_SINT8,
18756 LAYOUT_UNORM8,
18757 LAYOUT_SNORM8,
18758 LAYOUT_UNORM10_2,
18759 LAYOUT_UINT10_2,
18761 LAYOUT_COUNT,
18764 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
18766 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18767 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18769 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
18770 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
18771 ID3D11Buffer *vb_position, *vb_attribute;
18772 struct d3d11_test_context test_context;
18773 D3D11_TEXTURE2D_DESC texture_desc;
18774 unsigned int i, j, stride, offset;
18775 ID3D11Texture2D *render_target;
18776 ID3D11DeviceContext *context;
18777 ID3D11RenderTargetView *rtv;
18778 ID3D11PixelShader *ps;
18779 ID3D11Device *device;
18780 HRESULT hr;
18782 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
18784 DXGI_FORMAT_R32G32B32A32_FLOAT,
18785 DXGI_FORMAT_R16G16B16A16_UINT,
18786 DXGI_FORMAT_R16G16B16A16_SINT,
18787 DXGI_FORMAT_R16G16B16A16_UNORM,
18788 DXGI_FORMAT_R16G16B16A16_SNORM,
18789 DXGI_FORMAT_R8G8B8A8_UINT,
18790 DXGI_FORMAT_R8G8B8A8_SINT,
18791 DXGI_FORMAT_R8G8B8A8_UNORM,
18792 DXGI_FORMAT_R8G8B8A8_SNORM,
18793 DXGI_FORMAT_R10G10B10A2_UNORM,
18794 DXGI_FORMAT_R10G10B10A2_UINT,
18796 static const struct vec2 quad[] =
18798 {-1.0f, -1.0f},
18799 {-1.0f, 1.0f},
18800 { 1.0f, -1.0f},
18801 { 1.0f, 1.0f},
18803 static const DWORD ps_code[] =
18805 #if 0
18806 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
18808 return color;
18810 #endif
18811 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
18812 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
18813 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
18814 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
18815 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18816 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
18817 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
18818 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
18820 static const DWORD vs_float_code[] =
18822 #if 0
18823 struct output
18825 float4 position : SV_Position;
18826 float4 color : COLOR;
18829 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
18831 o.position = position;
18832 o.color = color;
18834 #endif
18835 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
18836 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18837 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18838 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18839 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18840 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18841 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18842 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18843 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18844 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18845 0x0100003e,
18847 static const DWORD vs_uint_code[] =
18849 #if 0
18850 struct output
18852 float4 position : SV_Position;
18853 float4 color : COLOR;
18856 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
18858 o.position = position;
18859 o.color = color;
18861 #endif
18862 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
18863 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18864 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18865 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18866 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18867 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18868 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18869 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18870 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18871 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18872 0x0100003e,
18874 static const DWORD vs_sint_code[] =
18876 #if 0
18877 struct output
18879 float4 position : SV_Position;
18880 float4 color : COLOR;
18883 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
18885 o.position = position;
18886 o.color = color;
18888 #endif
18889 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
18890 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18891 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18892 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18893 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18894 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18895 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18896 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18897 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18898 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18899 0x0100003e,
18901 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
18902 static const unsigned short uint16_data[] = {6, 8, 55, 777};
18903 static const short sint16_data[] = {-1, 33, 8, -77};
18904 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
18905 static const short snorm16_data[] = {-32768, 0, 32767, 0};
18906 static const unsigned char uint8_data[] = {0, 64, 128, 255};
18907 static const signed char sint8_data[] = {-128, 0, 127, 64};
18908 static const unsigned int uint32_zero = 0;
18909 static const unsigned int uint32_max = 0xffffffff;
18910 static const unsigned int unorm10_2_data= 0xa00003ff;
18911 static const unsigned int g10_data = 0x000ffc00;
18912 static const unsigned int a2_data = 0xc0000000;
18913 static const struct
18915 enum layout_id layout_id;
18916 unsigned int stride;
18917 const void *data;
18918 struct vec4 expected_color;
18919 BOOL todo;
18921 tests[] =
18923 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
18924 {1.0f, 2.0f, 3.0f, 4.0f}},
18925 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
18926 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
18927 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
18928 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
18929 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
18930 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
18931 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
18932 {-1.0f, 0.0f, 1.0f, 0.0f}},
18933 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
18934 {0.0f, 0.0f, 0.0f, 0.0f}},
18935 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
18936 {255.0f, 255.0f, 255.0f, 255.0f}},
18937 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
18938 {0.0f, 64.0f, 128.0f, 255.0f}},
18939 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
18940 {0.0f, 0.0f, 0.0f, 0.0f}},
18941 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
18942 {-1.0f, -1.0f, -1.0f, -1.0f}},
18943 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
18944 {-128.0f, 0.0f, 127.0f, 64.0f}},
18945 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
18946 {0.0f, 0.0f, 0.0f, 0.0f}},
18947 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
18948 {1.0f, 1.0f, 1.0f, 1.0f}},
18949 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
18950 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
18951 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
18952 {0.0f, 0.0f, 0.0f, 0.0f}},
18953 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
18954 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
18955 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
18956 {0.0f, 0.0f, 0.0f, 0.0f}},
18957 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
18958 {1.0f, 1.0f, 1.0f, 1.0f}},
18959 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
18960 {0.0f, 1.0f, 0.0f, 0.0f}},
18961 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
18962 {0.0f, 0.0f, 0.0f, 1.0f}},
18963 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
18964 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
18965 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
18966 {0.0f, 0.0f, 0.0f, 0.0f}},
18967 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
18968 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
18969 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
18970 {0.0f, 1023.0f, 0.0f, 0.0f}},
18971 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
18972 {0.0f, 0.0f, 0.0f, 3.0f}},
18973 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
18974 {1023.0f, 0.0f, 512.0f, 2.0f}},
18977 if (!init_test_context(&test_context, NULL))
18978 return;
18980 device = test_context.device;
18981 context = test_context.immediate_context;
18983 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18984 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18986 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
18987 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
18988 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
18989 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
18990 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
18991 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
18993 for (i = 0; i < LAYOUT_COUNT; ++i)
18995 input_layout_desc[1].Format = layout_formats[i];
18996 input_layout[i] = NULL;
18997 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
18998 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
18999 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
19000 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
19003 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
19004 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
19006 texture_desc.Width = 640;
19007 texture_desc.Height = 480;
19008 texture_desc.MipLevels = 1;
19009 texture_desc.ArraySize = 1;
19010 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19011 texture_desc.SampleDesc.Count = 1;
19012 texture_desc.SampleDesc.Quality = 0;
19013 texture_desc.Usage = D3D11_USAGE_DEFAULT;
19014 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
19015 texture_desc.CPUAccessFlags = 0;
19016 texture_desc.MiscFlags = 0;
19018 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
19019 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
19021 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
19022 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
19024 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
19025 offset = 0;
19026 stride = sizeof(*quad);
19027 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
19028 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19029 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19031 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19033 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
19035 if (tests[i].layout_id == LAYOUT_UINT10_2)
19036 continue;
19038 assert(tests[i].layout_id < LAYOUT_COUNT);
19039 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
19041 assert(4 * tests[i].stride <= 1024);
19042 box.right = tests[i].stride;
19043 for (j = 0; j < 4; ++j)
19045 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
19046 &box, tests[i].data, 0, 0);
19047 box.left += tests[i].stride;
19048 box.right += tests[i].stride;
19051 stride = tests[i].stride;
19052 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
19054 switch (layout_formats[tests[i].layout_id])
19056 case DXGI_FORMAT_R16G16B16A16_UINT:
19057 case DXGI_FORMAT_R10G10B10A2_UINT:
19058 case DXGI_FORMAT_R8G8B8A8_UINT:
19059 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
19060 break;
19061 case DXGI_FORMAT_R16G16B16A16_SINT:
19062 case DXGI_FORMAT_R8G8B8A8_SINT:
19063 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
19064 break;
19066 default:
19067 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
19068 /* Fall through. */
19069 case DXGI_FORMAT_R32G32B32A32_FLOAT:
19070 case DXGI_FORMAT_R16G16B16A16_UNORM:
19071 case DXGI_FORMAT_R16G16B16A16_SNORM:
19072 case DXGI_FORMAT_R10G10B10A2_UNORM:
19073 case DXGI_FORMAT_R8G8B8A8_UNORM:
19074 case DXGI_FORMAT_R8G8B8A8_SNORM:
19075 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
19076 break;
19079 ID3D11DeviceContext_Draw(context, 4, 0);
19080 check_texture_vec4(render_target, &tests[i].expected_color, 2);
19083 ID3D11Texture2D_Release(render_target);
19084 ID3D11RenderTargetView_Release(rtv);
19085 ID3D11Buffer_Release(vb_attribute);
19086 ID3D11Buffer_Release(vb_position);
19087 for (i = 0; i < LAYOUT_COUNT; ++i)
19089 if (input_layout[i])
19090 ID3D11InputLayout_Release(input_layout[i]);
19092 ID3D11PixelShader_Release(ps);
19093 ID3D11VertexShader_Release(vs_float);
19094 ID3D11VertexShader_Release(vs_uint);
19095 ID3D11VertexShader_Release(vs_sint);
19096 release_test_context(&test_context);
19099 static void test_null_sampler(void)
19101 struct d3d11_test_context test_context;
19102 D3D11_TEXTURE2D_DESC texture_desc;
19103 ID3D11ShaderResourceView *srv;
19104 ID3D11DeviceContext *context;
19105 ID3D11RenderTargetView *rtv;
19106 ID3D11SamplerState *sampler;
19107 ID3D11Texture2D *texture;
19108 ID3D11PixelShader *ps;
19109 ID3D11Device *device;
19110 HRESULT hr;
19112 static const DWORD ps_code[] =
19114 #if 0
19115 Texture2D t;
19116 SamplerState s;
19118 float4 main(float4 position : SV_POSITION) : SV_Target
19120 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
19122 #endif
19123 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
19124 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19125 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
19126 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19127 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
19128 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
19129 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
19130 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
19131 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
19132 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
19134 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
19136 if (!init_test_context(&test_context, NULL))
19137 return;
19139 device = test_context.device;
19140 context = test_context.immediate_context;
19142 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19143 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19145 texture_desc.Width = 64;
19146 texture_desc.Height = 64;
19147 texture_desc.MipLevels = 1;
19148 texture_desc.ArraySize = 1;
19149 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
19150 texture_desc.SampleDesc.Count = 1;
19151 texture_desc.SampleDesc.Quality = 0;
19152 texture_desc.Usage = D3D11_USAGE_DEFAULT;
19153 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
19154 texture_desc.CPUAccessFlags = 0;
19155 texture_desc.MiscFlags = 0;
19157 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19158 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19160 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19161 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19163 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
19164 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
19166 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
19168 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19169 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
19170 sampler = NULL;
19171 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
19172 draw_quad(&test_context);
19173 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
19175 ID3D11ShaderResourceView_Release(srv);
19176 ID3D11RenderTargetView_Release(rtv);
19177 ID3D11Texture2D_Release(texture);
19178 ID3D11PixelShader_Release(ps);
19179 release_test_context(&test_context);
19182 static void test_check_feature_support(void)
19184 D3D11_FEATURE_DATA_THREADING threading[2];
19185 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
19186 D3D11_FEATURE_DATA_ARCHITECTURE_INFO archinfo;
19187 ID3D11Device *device;
19188 ULONG refcount;
19189 HRESULT hr;
19191 if (!(device = create_device(NULL)))
19193 skip("Failed to create device.\n");
19194 return;
19197 memset(threading, 0xef, sizeof(threading));
19199 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
19200 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19201 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
19202 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19203 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
19204 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19205 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
19206 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19207 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
19208 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19209 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
19210 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19212 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
19213 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
19214 ok(threading[0].DriverCommandLists == 0xefefefef,
19215 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
19216 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
19217 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
19218 ok(threading[1].DriverCommandLists == 0xefefefef,
19219 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
19221 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
19222 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
19223 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
19224 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
19225 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
19226 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
19228 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
19229 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19230 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
19231 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19232 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
19233 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19234 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
19235 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19236 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
19237 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19238 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
19239 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19241 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
19242 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
19243 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
19245 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo));
19246 ok(hr == S_OK || broken(hr == E_INVALIDARG) /* Not available on all Windows versions. */,
19247 "Got unexpected hr %#x.\n", hr);
19248 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo)*2);
19249 ok(hr == E_INVALIDARG /* Not available on all Windows versions but they will return E_INVALIDARG anyways. */,
19250 "Got unexpected hr %#x.\n", hr);
19252 refcount = ID3D11Device_Release(device);
19253 ok(!refcount, "Device has %u references left.\n", refcount);
19256 static void test_create_unordered_access_view(void)
19258 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19259 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19260 D3D11_TEXTURE3D_DESC texture3d_desc;
19261 D3D11_TEXTURE2D_DESC texture2d_desc;
19262 ULONG refcount, expected_refcount;
19263 D3D11_SUBRESOURCE_DATA data = {0};
19264 ID3D11UnorderedAccessView *uav;
19265 struct device_desc device_desc;
19266 D3D11_BUFFER_DESC buffer_desc;
19267 ID3D11Device *device, *tmp;
19268 ID3D11Texture3D *texture3d;
19269 ID3D11Texture2D *texture2d;
19270 ID3D11Resource *texture;
19271 ID3D11Buffer *buffer;
19272 unsigned int i;
19273 HRESULT hr;
19275 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
19276 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
19277 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
19278 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
19279 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
19280 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
19281 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
19282 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
19283 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
19284 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
19285 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
19286 static const struct
19288 struct
19290 unsigned int miplevel_count;
19291 unsigned int depth_or_array_size;
19292 DXGI_FORMAT format;
19293 } texture;
19294 struct uav_desc uav_desc;
19295 struct uav_desc expected_uav_desc;
19297 tests[] =
19299 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
19300 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
19301 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
19302 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
19303 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
19304 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
19305 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
19306 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
19307 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
19308 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
19309 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
19310 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
19311 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
19312 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
19313 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
19314 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
19315 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
19316 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
19317 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
19318 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
19319 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
19320 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
19321 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
19322 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
19323 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
19324 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
19325 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
19326 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
19327 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
19328 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
19329 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
19330 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
19331 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
19332 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
19333 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
19334 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
19336 static const struct
19338 struct
19340 D3D11_UAV_DIMENSION dimension;
19341 unsigned int miplevel_count;
19342 unsigned int depth_or_array_size;
19343 DXGI_FORMAT format;
19344 } texture;
19345 struct uav_desc uav_desc;
19347 invalid_desc_tests[] =
19349 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
19350 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
19351 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
19352 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
19353 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
19354 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
19355 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
19356 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
19357 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
19358 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
19359 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
19360 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
19361 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
19362 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
19363 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
19364 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
19365 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
19366 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
19367 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
19368 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
19369 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
19370 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
19371 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
19372 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
19373 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
19374 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
19375 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
19376 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
19377 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
19378 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
19379 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
19380 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
19381 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
19382 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
19383 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
19384 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
19385 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
19387 #undef FMT_UNKNOWN
19388 #undef RGBA8_UNORM
19389 #undef RGBA8_SRGB
19390 #undef RGBA8_UINT
19391 #undef RGBA8_TL
19392 #undef DIM_UNKNOWN
19393 #undef TEX_1D
19394 #undef TEX_1D_ARRAY
19395 #undef TEX_2D
19396 #undef TEX_2D_ARRAY
19397 #undef TEX_3D
19399 device_desc.feature_level = &feature_level;
19400 device_desc.flags = 0;
19401 if (!(device = create_device(&device_desc)))
19403 skip("Failed to create device.\n");
19404 return;
19407 buffer_desc.ByteWidth = 1024;
19408 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19409 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19410 buffer_desc.CPUAccessFlags = 0;
19411 buffer_desc.MiscFlags = 0;
19412 buffer_desc.StructureByteStride = 0;
19414 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
19415 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19417 expected_refcount = get_refcount(device) + 1;
19418 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19419 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19420 refcount = get_refcount(device);
19421 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
19422 tmp = NULL;
19423 expected_refcount = refcount + 1;
19424 ID3D11Buffer_GetDevice(buffer, &tmp);
19425 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
19426 refcount = get_refcount(device);
19427 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
19428 ID3D11Device_Release(tmp);
19430 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19431 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19432 U(uav_desc).Buffer.FirstElement = 0;
19433 U(uav_desc).Buffer.NumElements = 64;
19434 U(uav_desc).Buffer.Flags = 0;
19436 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19437 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19439 expected_refcount = get_refcount(device) + 1;
19440 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19441 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19442 refcount = get_refcount(device);
19443 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
19444 tmp = NULL;
19445 expected_refcount = refcount + 1;
19446 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
19447 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
19448 refcount = get_refcount(device);
19449 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
19450 ID3D11Device_Release(tmp);
19452 ID3D11UnorderedAccessView_Release(uav);
19453 ID3D11Buffer_Release(buffer);
19455 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19456 buffer_desc.StructureByteStride = 4;
19458 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19459 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19461 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19462 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19464 memset(&uav_desc, 0, sizeof(uav_desc));
19465 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
19467 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
19468 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
19469 uav_desc.ViewDimension);
19470 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
19471 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
19472 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
19474 ID3D11UnorderedAccessView_Release(uav);
19475 ID3D11Buffer_Release(buffer);
19477 /* Without D3D11_BIND_UNORDERED_ACCESS. */
19478 buffer = create_buffer(device, 0, 1024, NULL);
19480 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19481 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19482 U(uav_desc).Buffer.FirstElement = 0;
19483 U(uav_desc).Buffer.NumElements = 64;
19484 U(uav_desc).Buffer.Flags = 0;
19486 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19487 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19489 ID3D11Buffer_Release(buffer);
19491 texture2d_desc.Width = 512;
19492 texture2d_desc.Height = 512;
19493 texture2d_desc.SampleDesc.Count = 1;
19494 texture2d_desc.SampleDesc.Quality = 0;
19495 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
19496 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19497 texture2d_desc.CPUAccessFlags = 0;
19498 texture2d_desc.MiscFlags = 0;
19500 texture3d_desc.Width = 64;
19501 texture3d_desc.Height = 64;
19502 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
19503 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19504 texture3d_desc.CPUAccessFlags = 0;
19505 texture3d_desc.MiscFlags = 0;
19507 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19509 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
19511 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
19513 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
19514 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
19515 texture2d_desc.Format = tests[i].texture.format;
19517 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
19518 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
19519 texture = (ID3D11Resource *)texture2d;
19521 else
19523 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
19524 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
19525 texture3d_desc.Format = tests[i].texture.format;
19527 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
19528 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
19529 texture = (ID3D11Resource *)texture3d;
19532 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
19534 current_desc = NULL;
19536 else
19538 current_desc = &uav_desc;
19539 get_uav_desc(current_desc, &tests[i].uav_desc);
19542 expected_refcount = get_refcount(texture);
19543 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
19544 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
19545 refcount = get_refcount(texture);
19546 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
19548 memset(&uav_desc, 0, sizeof(uav_desc));
19549 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
19550 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
19552 ID3D11UnorderedAccessView_Release(uav);
19553 ID3D11Resource_Release(texture);
19556 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
19558 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
19559 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
19561 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
19563 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
19564 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
19565 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
19567 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
19568 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
19569 texture = (ID3D11Resource *)texture2d;
19571 else
19573 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
19574 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
19575 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
19577 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
19578 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
19579 texture = (ID3D11Resource *)texture3d;
19582 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
19583 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
19584 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
19586 ID3D11Resource_Release(texture);
19589 refcount = ID3D11Device_Release(device);
19590 ok(!refcount, "Device has %u references left.\n", refcount);
19593 static void test_immediate_constant_buffer(void)
19595 struct d3d11_test_context test_context;
19596 D3D11_TEXTURE2D_DESC texture_desc;
19597 ID3D11DeviceContext *context;
19598 ID3D11RenderTargetView *rtv;
19599 unsigned int index[4] = {0};
19600 ID3D11Texture2D *texture;
19601 ID3D11PixelShader *ps;
19602 ID3D11Device *device;
19603 ID3D11Buffer *cb;
19604 unsigned int i;
19605 HRESULT hr;
19607 static const DWORD ps_code[] =
19609 #if 0
19610 uint index;
19612 static const int int_array[6] =
19614 310, 111, 212, -513, -318, 0,
19617 static const uint uint_array[6] =
19619 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
19622 static const float float_array[6] =
19624 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
19627 float4 main() : SV_Target
19629 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
19631 #endif
19632 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
19633 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19634 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19635 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
19636 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
19637 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
19638 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
19639 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
19640 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19641 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
19642 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
19643 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
19644 0x0100003e,
19646 static struct vec4 expected_result[] =
19648 { 310.0f, 2.0f, 76.00f, 1.0f},
19649 { 111.0f, 7.0f, 83.50f, 1.0f},
19650 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
19651 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
19652 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
19653 { 0.0f, 0.0f, 0.0f, 1.0f},
19656 if (!init_test_context(&test_context, NULL))
19657 return;
19659 device = test_context.device;
19660 context = test_context.immediate_context;
19662 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19663 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19664 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19666 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
19667 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19669 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19670 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19671 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19672 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19674 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19675 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19676 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19678 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
19680 *index = i;
19681 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
19683 draw_quad(&test_context);
19684 check_texture_vec4(texture, &expected_result[i], 0);
19687 ID3D11Buffer_Release(cb);
19688 ID3D11PixelShader_Release(ps);
19689 ID3D11Texture2D_Release(texture);
19690 ID3D11RenderTargetView_Release(rtv);
19691 release_test_context(&test_context);
19694 static void test_fp_specials(void)
19696 struct d3d11_test_context test_context;
19697 D3D11_TEXTURE2D_DESC texture_desc;
19698 ID3D11DeviceContext *context;
19699 ID3D11RenderTargetView *rtv;
19700 ID3D11Texture2D *texture;
19701 ID3D11PixelShader *ps;
19702 ID3D11Device *device;
19703 HRESULT hr;
19705 static const DWORD ps_code[] =
19707 #if 0
19708 float4 main() : SV_Target
19710 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
19712 #endif
19713 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
19714 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19715 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19716 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
19717 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
19718 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
19720 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
19722 if (!init_test_context(&test_context, NULL))
19723 return;
19725 device = test_context.device;
19726 context = test_context.immediate_context;
19728 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19729 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19730 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19732 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19733 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19734 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19735 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19737 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19738 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19740 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19742 draw_quad(&test_context);
19743 check_texture_uvec4(texture, &expected_result);
19745 ID3D11PixelShader_Release(ps);
19746 ID3D11Texture2D_Release(texture);
19747 ID3D11RenderTargetView_Release(rtv);
19748 release_test_context(&test_context);
19751 static void test_uint_shader_instructions(void)
19753 struct shader
19755 const DWORD *code;
19756 size_t size;
19757 D3D_FEATURE_LEVEL required_feature_level;
19760 struct d3d11_test_context test_context;
19761 D3D11_TEXTURE2D_DESC texture_desc;
19762 D3D_FEATURE_LEVEL feature_level;
19763 ID3D11DeviceContext *context;
19764 ID3D11RenderTargetView *rtv;
19765 ID3D11Texture2D *texture;
19766 ID3D11PixelShader *ps;
19767 ID3D11Device *device;
19768 ID3D11Buffer *cb;
19769 unsigned int i;
19770 HRESULT hr;
19772 static const DWORD ps_bfi_code[] =
19774 #if 0
19775 uint bits, offset, insert, base;
19777 uint4 main() : SV_Target
19779 uint mask = ((1 << bits) - 1) << offset;
19780 return ((insert << offset) & mask) | (base & ~mask);
19782 #endif
19783 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
19784 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19785 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19786 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
19787 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19788 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
19789 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
19791 static const DWORD ps_bfi2_code[] =
19793 #if 0
19794 ps_5_0
19795 dcl_globalFlags refactoringAllowed
19796 dcl_constantbuffer cb0[1], immediateIndexed
19797 dcl_output o0.xyzw
19798 dcl_temps 1
19799 mov r0.xyzw, cb0[0].xyzw
19800 bfi r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz, r0.wwww
19801 mov o0.xyzw, r0.xyzw
19803 #endif
19804 0x43425844, 0x900f86b6, 0x73f4dabf, 0xea1b1106, 0x591ac790, 0x00000001, 0x00000104, 0x00000003,
19805 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19806 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19807 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000008c, 0x00000050, 0x00000023,
19808 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19809 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19810 0x0b00008c, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19811 0x00000000, 0x00100ff6, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
19812 0x0100003e,
19814 static const DWORD ps_ibfe_code[] =
19816 #if 0
19817 ps_5_0
19818 dcl_globalFlags refactoringAllowed
19819 dcl_constantbuffer cb0[1], immediateIndexed
19820 dcl_output o0.xyzw
19821 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
19823 #endif
19824 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
19825 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19826 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19827 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
19828 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19829 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
19830 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
19832 static const DWORD ps_ibfe2_code[] =
19834 #if 0
19835 ps_5_0
19836 dcl_globalFlags refactoringAllowed
19837 dcl_constantbuffer cb0[1], immediateIndexed
19838 dcl_output o0.xyzw
19839 dcl_temps 1
19840 mov r0.xyzw, cb0[0].xyzw
19841 ibfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
19842 mov o0.xyzw, r0.xyzw
19844 #endif
19845 0x43425844, 0x347a9c0e, 0x3eff39a4, 0x3dd41cc5, 0xff87ec8d, 0x00000001, 0x000000fc, 0x00000003,
19846 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19847 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19848 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
19849 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19850 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19851 0x0900008b, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19852 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19854 static const DWORD ps_ubfe_code[] =
19856 #if 0
19857 uint u;
19859 uint4 main() : SV_Target
19861 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
19863 #endif
19864 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
19865 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19866 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19867 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
19868 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19869 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
19870 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
19871 0x0100003e,
19873 static const DWORD ps_ubfe2_code[] =
19875 #if 0
19876 ps_5_0
19877 dcl_globalFlags refactoringAllowed
19878 dcl_constantbuffer cb0[1], immediateIndexed
19879 dcl_output o0.xyzw
19880 dcl_temps 1
19881 mov r0.xyzw, cb0[0].xyzw
19882 ubfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
19883 mov o0.xyzw, r0.xyzw
19885 #endif
19886 0x43425844, 0xf377b7fc, 0x1e4cb9e7, 0xb9b1020d, 0xde484388, 0x00000001, 0x000000fc, 0x00000003,
19887 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19888 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19889 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
19890 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19891 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19892 0x0900008a, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19893 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19895 static const DWORD ps_bfrev_code[] =
19897 #if 0
19898 uint bits;
19900 uint4 main() : SV_Target
19902 return uint4(reversebits(bits), reversebits(reversebits(bits)),
19903 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
19905 #endif
19906 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
19907 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19908 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19909 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
19910 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19911 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
19912 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
19913 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
19914 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
19915 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
19916 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
19918 static const DWORD ps_bits_code[] =
19920 #if 0
19921 uint u;
19922 int i;
19924 uint4 main() : SV_Target
19926 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
19928 #endif
19929 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
19930 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19931 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19932 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
19933 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19934 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
19935 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
19936 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
19937 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
19938 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
19939 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
19940 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
19941 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
19942 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
19944 static const DWORD ps_ftou_code[] =
19946 #if 0
19947 float f;
19949 uint4 main() : SV_Target
19951 return uint4(f, -f, 0, 0);
19953 #endif
19954 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
19955 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19956 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19957 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
19958 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
19959 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
19960 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
19961 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
19963 static const DWORD ps_f16tof32_code[] =
19965 #if 0
19966 uint4 hf;
19968 uint4 main() : SV_Target
19970 return f16tof32(hf);
19972 #endif
19973 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
19974 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19975 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19976 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
19977 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19978 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19979 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19981 static const DWORD ps_f32tof16_code[] =
19983 #if 0
19984 float4 f;
19986 uint4 main() : SV_Target
19988 return f32tof16(f);
19990 #endif
19991 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
19992 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19993 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19994 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
19995 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19996 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
19998 static const DWORD ps_not_code[] =
20000 #if 0
20001 uint2 bits;
20003 uint4 main() : SV_Target
20005 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
20007 #endif
20008 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
20009 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20010 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
20011 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
20012 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
20013 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
20014 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
20015 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
20017 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
20018 static const struct shader ps_bfi2 = {ps_bfi2_code, sizeof(ps_bfi2_code), D3D_FEATURE_LEVEL_11_0};
20019 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
20020 static const struct shader ps_ibfe2 = {ps_ibfe2_code, sizeof(ps_ibfe2_code), D3D_FEATURE_LEVEL_11_0};
20021 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
20022 static const struct shader ps_ubfe2 = {ps_ubfe2_code, sizeof(ps_ubfe2_code), D3D_FEATURE_LEVEL_11_0};
20023 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
20024 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
20025 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
20026 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
20027 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
20028 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
20029 static const struct
20031 const struct shader *ps;
20032 unsigned int bits[4];
20033 struct uvec4 expected_result;
20035 tests[] =
20037 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
20038 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
20039 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
20040 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
20041 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
20042 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
20043 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
20044 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
20045 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
20046 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
20047 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
20048 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
20049 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
20050 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
20051 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
20052 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
20053 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
20054 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
20055 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
20057 {&ps_bfi2, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
20058 {&ps_bfi2, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
20059 {&ps_bfi2, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
20060 {&ps_bfi2, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
20062 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20063 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20064 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20065 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20066 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
20067 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
20068 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20069 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
20070 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
20071 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
20072 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20073 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
20074 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
20075 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20076 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
20077 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
20078 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
20079 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
20080 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
20081 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
20082 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
20083 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
20084 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
20085 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
20086 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
20087 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20089 {&ps_ibfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
20091 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20092 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
20093 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
20094 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
20095 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
20096 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20097 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
20099 {&ps_ubfe2, { 4, 4, 0x7fffffff}, {0x0000000f, 0x0000000f, 0x0000000f, 0x0000000f}},
20100 {&ps_ubfe2, {23, 8, 0xffffffff}, {0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff}},
20101 {&ps_ubfe2, {30, 1, 0xffffffff}, {0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff}},
20102 {&ps_ubfe2, {15, 15, 0x7fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
20103 {&ps_ubfe2, {15, 15, 0xffff00ff}, {0x00007ffe, 0x00007ffe, 0x00007ffe, 0x00007ffe}},
20104 {&ps_ubfe2, {16, 15, 0xffffffff}, {0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff}},
20105 {&ps_ubfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
20106 {&ps_ubfe2, {20, 15, 0xffffffff}, {0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff}},
20107 {&ps_ubfe2, {31, 31, 0xffffffff}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
20108 {&ps_ubfe2, {31, 31, 0x80000000}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
20109 {&ps_ubfe2, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20111 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
20112 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
20113 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
20115 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
20116 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
20117 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
20118 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
20119 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
20120 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
20121 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
20122 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
20123 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
20124 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
20125 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
20126 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
20128 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
20129 {&ps_ftou, {BITS_NAN}, { 0, 0}},
20130 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
20131 {&ps_ftou, {BITS_INF}, {~0u, 0}},
20132 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
20133 {&ps_ftou, {BITS_1_0}, { 1, 0}},
20135 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
20136 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
20137 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
20138 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
20140 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
20142 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
20143 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
20146 if (!init_test_context(&test_context, NULL))
20147 return;
20149 device = test_context.device;
20150 context = test_context.immediate_context;
20151 feature_level = ID3D11Device_GetFeatureLevel(device);
20153 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
20154 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
20156 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
20157 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
20158 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
20159 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20161 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
20162 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
20164 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20166 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20168 if (feature_level < tests[i].ps->required_feature_level)
20169 continue;
20171 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
20172 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20173 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20175 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
20177 draw_quad(&test_context);
20178 check_texture_uvec4(texture, &tests[i].expected_result);
20180 ID3D11PixelShader_Release(ps);
20183 ID3D11Buffer_Release(cb);
20184 ID3D11Texture2D_Release(texture);
20185 ID3D11RenderTargetView_Release(rtv);
20186 release_test_context(&test_context);
20189 static void test_index_buffer_offset(void)
20191 ID3D11Buffer *vb, *ib, *so_buffer, *args_buffer;
20192 struct d3d11_test_context test_context;
20193 ID3D11InputLayout *input_layout;
20194 ID3D11DeviceContext *context;
20195 struct resource_readback rb;
20196 ID3D11GeometryShader *gs;
20197 const struct vec4 *data;
20198 ID3D11VertexShader *vs;
20199 ID3D11Device *device;
20200 UINT stride, offset;
20201 unsigned int i;
20202 HRESULT hr;
20204 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20205 static const DWORD vs_code[] =
20207 #if 0
20208 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
20209 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
20211 out_position = position;
20212 out_attrib = attrib;
20214 #endif
20215 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
20216 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20217 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
20218 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
20219 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
20220 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
20221 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
20222 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
20223 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
20224 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
20225 0x0100003e,
20227 static const DWORD gs_code[] =
20229 #if 0
20230 struct vertex
20232 float4 position : SV_POSITION;
20233 float4 attrib : ATTRIB;
20236 [maxvertexcount(1)]
20237 void main(point vertex input[1], inout PointStream<vertex> output)
20239 output.Append(input[0]);
20240 output.RestartStrip();
20242 #endif
20243 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
20244 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20245 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
20246 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
20247 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
20248 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
20249 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
20250 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
20251 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20252 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
20253 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
20254 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
20256 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
20258 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
20259 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
20261 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
20263 {0, "SV_Position", 0, 0, 4, 0},
20264 {0, "ATTRIB", 0, 0, 4, 0},
20266 static const struct
20268 struct vec4 position;
20269 struct vec4 attrib;
20271 vertices[] =
20273 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
20274 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
20275 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
20276 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
20278 static const unsigned int indices[] =
20280 0, 1, 2, 3,
20281 3, 2, 1, 0,
20282 1, 3, 2, 0,
20284 static const struct vec4 expected_data[] =
20286 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
20287 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
20288 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
20289 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
20291 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
20292 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
20293 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
20294 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
20296 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
20297 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
20298 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
20299 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
20301 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
20302 static const D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS argument_data[] =
20304 {4, 1, 0, 0, 0},
20307 if (!init_test_context(&test_context, &feature_level))
20308 return;
20310 device = test_context.device;
20311 context = test_context.immediate_context;
20313 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
20314 vs_code, sizeof(vs_code), &input_layout);
20315 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
20317 stride = 32;
20318 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
20319 so_declaration, ARRAY_SIZE(so_declaration),
20320 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
20321 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
20323 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
20324 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
20326 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
20327 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
20328 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
20330 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
20331 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
20333 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
20334 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
20335 stride = sizeof(*vertices);
20336 offset = 0;
20337 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
20339 offset = 0;
20340 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20342 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
20343 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
20345 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
20346 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
20348 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
20349 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
20351 get_buffer_readback(so_buffer, &rb);
20352 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
20354 data = get_readback_vec4(&rb, i, 0);
20355 ok(compare_vec4(data, &expected_data[i], 0)
20356 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
20357 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
20358 data->x, data->y, data->z, data->w, i);
20360 release_resource_readback(&rb);
20362 /* indirect draws */
20363 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
20364 sizeof(argument_data), argument_data);
20366 offset = 0;
20367 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20369 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
20370 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
20372 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
20373 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
20375 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
20376 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
20378 get_buffer_readback(so_buffer, &rb);
20379 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
20381 data = get_readback_vec4(&rb, i, 0);
20382 todo_wine_if(i >= 8 && i != 20 && i != 21)
20383 ok(compare_vec4(data, &expected_data[i], 0)
20384 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
20385 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
20386 data->x, data->y, data->z, data->w, i);
20388 release_resource_readback(&rb);
20390 ID3D11Buffer_Release(so_buffer);
20391 ID3D11Buffer_Release(args_buffer);
20392 ID3D11Buffer_Release(ib);
20393 ID3D11Buffer_Release(vb);
20394 ID3D11VertexShader_Release(vs);
20395 ID3D11GeometryShader_Release(gs);
20396 ID3D11InputLayout_Release(input_layout);
20397 release_test_context(&test_context);
20400 static void test_face_culling(void)
20402 struct d3d11_test_context test_context;
20403 D3D11_RASTERIZER_DESC rasterizer_desc;
20404 ID3D11RasterizerState *state;
20405 ID3D11DeviceContext *context;
20406 ID3D11Buffer *cw_vb, *ccw_vb;
20407 ID3D11Device *device;
20408 BOOL broken_warp;
20409 unsigned int i;
20410 HRESULT hr;
20412 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
20413 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
20414 static const DWORD ps_code[] =
20416 #if 0
20417 float4 main(uint front : SV_IsFrontFace) : SV_Target
20419 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
20421 #endif
20422 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
20423 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
20424 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
20425 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20426 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
20427 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
20428 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
20429 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
20430 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
20431 0x3f800000, 0x0100003e,
20433 static const struct vec3 ccw_quad[] =
20435 {-1.0f, 1.0f, 0.0f},
20436 {-1.0f, -1.0f, 0.0f},
20437 { 1.0f, 1.0f, 0.0f},
20438 { 1.0f, -1.0f, 0.0f},
20440 static const struct
20442 D3D11_CULL_MODE cull_mode;
20443 BOOL front_ccw;
20444 BOOL expected_cw;
20445 BOOL expected_ccw;
20447 tests[] =
20449 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
20450 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
20451 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
20452 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
20453 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
20454 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
20457 if (!init_test_context(&test_context, NULL))
20458 return;
20460 device = test_context.device;
20461 context = test_context.immediate_context;
20463 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20464 draw_color_quad(&test_context, &green);
20465 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20467 cw_vb = test_context.vb;
20468 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
20470 test_context.vb = ccw_vb;
20471 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20472 draw_color_quad(&test_context, &green);
20473 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
20475 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
20476 rasterizer_desc.CullMode = D3D11_CULL_BACK;
20477 rasterizer_desc.FrontCounterClockwise = FALSE;
20478 rasterizer_desc.DepthBias = 0;
20479 rasterizer_desc.DepthBiasClamp = 0.0f;
20480 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
20481 rasterizer_desc.DepthClipEnable = TRUE;
20482 rasterizer_desc.ScissorEnable = FALSE;
20483 rasterizer_desc.MultisampleEnable = FALSE;
20484 rasterizer_desc.AntialiasedLineEnable = FALSE;
20486 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20488 rasterizer_desc.CullMode = tests[i].cull_mode;
20489 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
20490 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20491 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
20493 ID3D11DeviceContext_RSSetState(context, state);
20495 test_context.vb = cw_vb;
20496 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20497 draw_color_quad(&test_context, &green);
20498 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
20500 test_context.vb = ccw_vb;
20501 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20502 draw_color_quad(&test_context, &green);
20503 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
20505 ID3D11RasterizerState_Release(state);
20508 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0;
20510 /* Test SV_IsFrontFace. */
20511 ID3D11PixelShader_Release(test_context.ps);
20512 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
20513 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20515 rasterizer_desc.CullMode = D3D11_CULL_NONE;
20516 rasterizer_desc.FrontCounterClockwise = FALSE;
20517 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20518 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20519 ID3D11DeviceContext_RSSetState(context, state);
20521 test_context.vb = cw_vb;
20522 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20523 draw_color_quad(&test_context, &green);
20524 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20525 test_context.vb = ccw_vb;
20526 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20527 draw_color_quad(&test_context, &green);
20528 if (!broken_warp)
20529 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
20530 else
20531 win_skip("Broken WARP.\n");
20533 ID3D11RasterizerState_Release(state);
20535 rasterizer_desc.CullMode = D3D11_CULL_NONE;
20536 rasterizer_desc.FrontCounterClockwise = TRUE;
20537 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20538 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20539 ID3D11DeviceContext_RSSetState(context, state);
20541 test_context.vb = cw_vb;
20542 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20543 draw_color_quad(&test_context, &green);
20544 if (!broken_warp)
20545 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
20546 else
20547 win_skip("Broken WARP.\n");
20548 test_context.vb = ccw_vb;
20549 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20550 draw_color_quad(&test_context, &green);
20551 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20553 ID3D11RasterizerState_Release(state);
20555 test_context.vb = cw_vb;
20556 ID3D11Buffer_Release(ccw_vb);
20557 release_test_context(&test_context);
20560 static void test_line_antialiasing_blending(void)
20562 ID3D11RasterizerState *rasterizer_state;
20563 struct d3d11_test_context test_context;
20564 D3D11_RASTERIZER_DESC rasterizer_desc;
20565 ID3D11BlendState *blend_state;
20566 ID3D11DeviceContext *context;
20567 D3D11_BLEND_DESC blend_desc;
20568 ID3D11Device *device;
20569 HRESULT hr;
20571 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
20572 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
20574 if (!init_test_context(&test_context, NULL))
20575 return;
20577 device = test_context.device;
20578 context = test_context.immediate_context;
20580 memset(&blend_desc, 0, sizeof(blend_desc));
20581 blend_desc.AlphaToCoverageEnable = FALSE;
20582 blend_desc.IndependentBlendEnable = FALSE;
20583 blend_desc.RenderTarget[0].BlendEnable = TRUE;
20584 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
20585 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
20586 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
20587 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
20588 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
20589 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
20590 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
20592 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
20593 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
20594 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
20596 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20597 draw_color_quad(&test_context, &green);
20598 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
20600 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20601 draw_color_quad(&test_context, &red);
20602 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
20604 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
20605 ID3D11BlendState_Release(blend_state);
20607 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20608 draw_color_quad(&test_context, &green);
20609 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
20611 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20612 draw_color_quad(&test_context, &red);
20613 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
20615 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
20616 rasterizer_desc.CullMode = D3D11_CULL_BACK;
20617 rasterizer_desc.FrontCounterClockwise = FALSE;
20618 rasterizer_desc.DepthBias = 0;
20619 rasterizer_desc.DepthBiasClamp = 0.0f;
20620 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
20621 rasterizer_desc.DepthClipEnable = TRUE;
20622 rasterizer_desc.ScissorEnable = FALSE;
20623 rasterizer_desc.MultisampleEnable = FALSE;
20624 rasterizer_desc.AntialiasedLineEnable = TRUE;
20626 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
20627 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20628 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
20630 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20631 draw_color_quad(&test_context, &green);
20632 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
20634 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20635 draw_color_quad(&test_context, &red);
20636 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
20638 ID3D11RasterizerState_Release(rasterizer_state);
20639 release_test_context(&test_context);
20642 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
20643 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
20644 const char *feature_name)
20646 unsigned int i;
20648 for (i = 0; i < format_count; ++i)
20650 DXGI_FORMAT format = formats[i].format;
20651 unsigned int supported = format_support[format] & feature_flag;
20653 if (formats[i].fl_required <= feature_level)
20655 todo_wine_if (feature_flag == D3D11_FORMAT_SUPPORT_DISPLAY)
20656 ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
20657 format, feature_name, feature_level, format_support[format]);
20658 continue;
20661 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
20663 if (supported)
20664 trace("Optional format %#x - %s supported, feature level %#x.\n",
20665 format, feature_name, feature_level);
20666 continue;
20669 todo_wine_if (feature_flag != D3D11_FORMAT_SUPPORT_DISPLAY)
20670 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
20671 format, feature_name, feature_level, format_support[format]);
20675 static void test_format_support(const D3D_FEATURE_LEVEL feature_level)
20677 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
20678 struct device_desc device_desc;
20679 ID3D11Device *device;
20680 DXGI_FORMAT format;
20681 ULONG refcount;
20682 UINT support;
20683 HRESULT hr;
20685 static const struct format_support index_buffers[] =
20687 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
20688 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
20691 static const struct format_support vertex_buffers[] =
20693 {DXGI_FORMAT_R8G8_UINT, D3D_FEATURE_LEVEL_10_0},
20694 {DXGI_FORMAT_R11G11B10_FLOAT, D3D_FEATURE_LEVEL_10_0},
20695 {DXGI_FORMAT_R16_FLOAT, D3D_FEATURE_LEVEL_10_0},
20698 device_desc.feature_level = &feature_level;
20699 device_desc.flags = 0;
20700 if (!(device = create_device(&device_desc)))
20702 skip("Failed to create device for feature level %#x.\n", feature_level);
20703 return;
20706 support = 0xdeadbeef;
20707 hr = ID3D11Device_CheckFormatSupport(device, ~0u, &support);
20708 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
20709 ok(!support, "Got unexpected format support %#x.\n", support);
20711 memset(format_support, 0, sizeof(format_support));
20712 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
20714 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
20715 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
20716 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
20717 format, hr, format_support[format]);
20718 if (format_support[format] & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN)
20720 ok(format_support[format] & D3D11_FORMAT_SUPPORT_TEXTURE2D,
20721 "Got unexpected format support %#x for format %#x", format_support[format], format);
20725 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
20727 if (feature_level < D3D_FEATURE_LEVEL_10_0)
20729 /* SHADER_SAMPLE_COMPARISON is never advertised as supported on feature level 9. */
20730 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON),
20731 "Unexpected SHADER_SAMPLE_COMPARISON for format %#x, feature level %#x.\n",
20732 format, feature_level);
20733 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_BUFFER),
20734 "Unexpected BUFFER for format %#x, feature level %#x.\n",
20735 format, feature_level);
20737 if (feature_level < D3D_FEATURE_LEVEL_10_1)
20739 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER),
20740 "Unexpected SHADER_GATHER for format %#x, feature level %#x.\n",
20741 format, feature_level);
20742 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON),
20743 "Unexpected SHADER_GATHER_COMPARISON for format %#x, feature level %#x.\n",
20744 format, feature_level);
20748 ok(format_support[DXGI_FORMAT_R8G8B8A8_UNORM] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE,
20749 "SHADER_SAMPLE is not supported for R8G8B8A8_UNORM.\n");
20750 todo_wine
20751 ok(!(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE),
20752 "SHADER_SAMPLE is supported for R32G32B32A32_UINT.\n");
20753 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
20755 ok(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_LOAD,
20756 "SHADER_LOAD is not supported for R32G32B32A32_UINT.\n");
20759 check_format_support(format_support, feature_level,
20760 index_buffers, ARRAY_SIZE(index_buffers),
20761 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
20763 check_format_support(format_support, feature_level,
20764 vertex_buffers, ARRAY_SIZE(vertex_buffers),
20765 D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER, "vertex buffer");
20767 check_format_support(format_support, feature_level,
20768 display_format_support, ARRAY_SIZE(display_format_support),
20769 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
20771 refcount = ID3D11Device_Release(device);
20772 ok(!refcount, "Device has %u references left.\n", refcount);
20775 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
20777 struct d3d11_test_context test_context;
20778 D3D11_SUBRESOURCE_DATA resource_data;
20779 D3D11_TEXTURE2D_DESC texture_desc;
20780 ID3D11ShaderResourceView *srv;
20781 ID3D11DeviceContext *context;
20782 ID3D11Texture2D *texture;
20783 ID3D11PixelShader *ps;
20784 ID3D11Device *device;
20785 HRESULT hr;
20787 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
20788 static const DWORD ps_code[] =
20790 #if 0
20791 float4 main() : SV_TARGET
20793 return float4(1.0f, 0.0f, 0.0f, 0.5f);
20795 #endif
20796 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
20797 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
20798 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
20799 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
20800 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
20801 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
20802 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
20803 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
20804 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
20805 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
20806 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
20807 0x45475241, 0xabab0054,
20809 static const DWORD ps_texture_code[] =
20811 #if 0
20812 Texture2D t;
20813 SamplerState s;
20815 float4 main() : SV_TARGET
20817 return t.Sample(s, (float2)0);
20819 #endif
20820 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
20821 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
20822 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
20823 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
20824 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
20825 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
20826 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
20827 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
20828 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
20829 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
20830 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
20831 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
20832 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
20833 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20834 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
20836 static const DWORD texture_data[] = {0xffffff00};
20838 if (!init_test_context(&test_context, &feature_level))
20839 return;
20841 device = test_context.device;
20842 context = test_context.immediate_context;
20844 texture_desc.Width = 1;
20845 texture_desc.Height = 1;
20846 texture_desc.MipLevels = 0;
20847 texture_desc.ArraySize = 1;
20848 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20849 texture_desc.SampleDesc.Count = 1;
20850 texture_desc.SampleDesc.Quality = 0;
20851 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20852 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20853 texture_desc.CPUAccessFlags = 0;
20854 texture_desc.MiscFlags = 0;
20855 resource_data.pSysMem = texture_data;
20856 resource_data.SysMemPitch = sizeof(texture_data);
20857 resource_data.SysMemSlicePitch = 0;
20858 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20859 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
20860 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
20861 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20863 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20864 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
20865 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20866 draw_quad(&test_context);
20867 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
20868 ID3D11PixelShader_Release(ps);
20870 draw_color_quad(&test_context, &color);
20871 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
20873 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
20874 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
20875 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20876 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20877 draw_quad(&test_context);
20878 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
20879 ID3D11PixelShader_Release(ps);
20881 ID3D11ShaderResourceView_Release(srv);
20882 ID3D11Texture2D_Release(texture);
20883 release_test_context(&test_context);
20886 static void queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
20887 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
20889 static const D3D_FEATURE_LEVEL feature_levels[] =
20891 D3D_FEATURE_LEVEL_11_1,
20892 D3D_FEATURE_LEVEL_11_0,
20893 D3D_FEATURE_LEVEL_10_1,
20894 D3D_FEATURE_LEVEL_10_0,
20895 D3D_FEATURE_LEVEL_9_3,
20896 D3D_FEATURE_LEVEL_9_2,
20897 D3D_FEATURE_LEVEL_9_1
20899 unsigned int i;
20901 assert(begin <= end);
20902 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
20904 if (begin <= feature_levels[i] && feature_levels[i] <= end)
20905 queue_test_fl(test_func, feature_levels[i]);
20909 static void queue_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
20911 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
20912 D3D_FEATURE_LEVEL_11_1, test_func);
20915 static void queue_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
20917 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
20918 D3D_FEATURE_LEVEL_9_3, test_func);
20921 static void test_ddy(void)
20923 static const struct
20925 struct vec4 position;
20926 unsigned int color;
20928 quad[] =
20930 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
20931 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
20932 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
20933 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
20935 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
20937 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
20938 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
20940 #if 0
20941 struct vs_data
20943 float4 pos : SV_POSITION;
20944 float4 color : COLOR;
20947 void main(in struct vs_data vs_input, out struct vs_data vs_output)
20949 vs_output.pos = vs_input.pos;
20950 vs_output.color = vs_input.color;
20952 #endif
20953 static const DWORD vs_code[] =
20955 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
20956 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20957 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
20958 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20959 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
20960 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
20961 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
20962 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
20963 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
20964 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
20965 0x0100003e,
20967 #if 0
20968 struct ps_data
20970 float4 pos : SV_POSITION;
20971 float4 color : COLOR;
20974 float4 main(struct ps_data ps_input) : SV_Target
20976 return ddy(ps_input.color) * 240.0 + 0.5;
20978 #endif
20979 static const DWORD ps_code_ddy[] =
20981 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
20982 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20983 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20984 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20985 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20986 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
20987 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
20988 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
20989 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
20990 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20992 #if 0
20993 struct ps_data
20995 float4 pos : SV_POSITION;
20996 float4 color : COLOR;
20999 float4 main(struct ps_data ps_input) : SV_Target
21001 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
21003 #endif
21004 static const DWORD ps_code_ddy_coarse[] =
21006 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
21007 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
21008 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
21009 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
21010 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21011 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
21012 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
21013 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
21014 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
21015 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
21017 #if 0
21018 struct ps_data
21020 float4 pos : SV_POSITION;
21021 float4 color : COLOR;
21024 float4 main(struct ps_data ps_input) : SV_Target
21026 return ddy_fine(ps_input.color) * 240.0 + 0.5;
21028 #endif
21029 static const DWORD ps_code_ddy_fine[] =
21031 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
21032 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
21033 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
21034 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
21035 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21036 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
21037 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
21038 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
21039 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
21040 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
21042 static const struct
21044 D3D_FEATURE_LEVEL min_feature_level;
21045 const DWORD *ps_code;
21046 unsigned int ps_code_size;
21048 tests[] =
21050 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
21051 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
21052 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
21054 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
21055 struct d3d11_test_context test_context;
21056 D3D11_TEXTURE2D_DESC texture_desc;
21057 D3D_FEATURE_LEVEL feature_level;
21058 ID3D11InputLayout *input_layout;
21059 ID3D11DeviceContext *context;
21060 unsigned int stride, offset;
21061 struct resource_readback rb;
21062 ID3D11RenderTargetView *rtv;
21063 ID3D11Texture2D *texture;
21064 ID3D11VertexShader *vs;
21065 ID3D11PixelShader *ps;
21066 ID3D11Device *device;
21067 ID3D11Buffer *vb;
21068 unsigned int i;
21069 DWORD color;
21070 HRESULT hr;
21072 if (!init_test_context(&test_context, NULL))
21073 return;
21075 device = test_context.device;
21076 context = test_context.immediate_context;
21077 feature_level = ID3D11Device_GetFeatureLevel(device);
21079 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
21080 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21081 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21083 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
21084 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
21086 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
21087 vs_code, sizeof(vs_code), &input_layout);
21088 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
21090 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
21092 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
21093 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
21095 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
21096 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
21097 stride = sizeof(*quad);
21098 offset = 0;
21099 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
21100 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
21102 for (i = 0; i < ARRAY_SIZE(tests); ++i)
21104 if (feature_level < tests[i].min_feature_level)
21106 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
21107 feature_level, tests[i].min_feature_level);
21108 continue;
21111 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
21112 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21114 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21116 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21117 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
21118 ID3D11DeviceContext_Draw(context, 4, 0);
21120 get_texture_readback(texture, 0, &rb);
21121 color = get_readback_color(&rb, 320, 190, 0);
21122 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21123 color = get_readback_color(&rb, 255, 240, 0);
21124 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21125 color = get_readback_color(&rb, 320, 240, 0);
21126 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21127 color = get_readback_color(&rb, 385, 240, 0);
21128 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21129 color = get_readback_color(&rb, 320, 290, 0);
21130 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21131 release_resource_readback(&rb);
21133 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
21134 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
21135 ID3D11DeviceContext_Draw(context, 4, 0);
21137 get_texture_readback(test_context.backbuffer, 0, &rb);
21138 color = get_readback_color(&rb, 320, 190, 0);
21139 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21140 color = get_readback_color(&rb, 255, 240, 0);
21141 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21142 color = get_readback_color(&rb, 320, 240, 0);
21143 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21144 color = get_readback_color(&rb, 385, 240, 0);
21145 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21146 color = get_readback_color(&rb, 320, 290, 0);
21147 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21148 release_resource_readback(&rb);
21150 ID3D11PixelShader_Release(ps);
21153 ID3D11VertexShader_Release(vs);
21154 ID3D11Buffer_Release(vb);
21155 ID3D11InputLayout_Release(input_layout);
21156 ID3D11Texture2D_Release(texture);
21157 ID3D11RenderTargetView_Release(rtv);
21158 release_test_context(&test_context);
21161 static void test_shader_input_registers_limits(void)
21163 struct d3d11_test_context test_context;
21164 D3D11_SUBRESOURCE_DATA resource_data;
21165 D3D11_TEXTURE2D_DESC texture_desc;
21166 D3D11_SAMPLER_DESC sampler_desc;
21167 ID3D11ShaderResourceView *srv;
21168 ID3D11DeviceContext *context;
21169 ID3D11SamplerState *sampler;
21170 ID3D11Texture2D *texture;
21171 ID3D11PixelShader *ps;
21172 ID3D11Device *device;
21173 HRESULT hr;
21175 static const DWORD ps_last_register_code[] =
21177 #if 0
21178 Texture2D t : register(t127);
21179 SamplerState s : register(s15);
21181 void main(out float4 target : SV_Target)
21183 target = t.Sample(s, float2(0, 0));
21185 #endif
21186 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
21187 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21188 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
21189 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
21190 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
21191 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
21192 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
21194 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
21195 static const DWORD texture_data[] = {0xff00ff00};
21197 if (!init_test_context(&test_context, NULL))
21198 return;
21200 device = test_context.device;
21201 context = test_context.immediate_context;
21203 texture_desc.Width = 1;
21204 texture_desc.Height = 1;
21205 texture_desc.MipLevels = 0;
21206 texture_desc.ArraySize = 1;
21207 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
21208 texture_desc.SampleDesc.Count = 1;
21209 texture_desc.SampleDesc.Quality = 0;
21210 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21211 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
21212 texture_desc.CPUAccessFlags = 0;
21213 texture_desc.MiscFlags = 0;
21215 resource_data.pSysMem = texture_data;
21216 resource_data.SysMemPitch = sizeof(texture_data);
21217 resource_data.SysMemSlicePitch = 0;
21219 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
21220 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
21222 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
21223 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
21225 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
21226 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
21227 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
21228 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
21229 sampler_desc.MipLODBias = 0.0f;
21230 sampler_desc.MaxAnisotropy = 0;
21231 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
21232 sampler_desc.BorderColor[0] = 0.0f;
21233 sampler_desc.BorderColor[1] = 0.0f;
21234 sampler_desc.BorderColor[2] = 0.0f;
21235 sampler_desc.BorderColor[3] = 0.0f;
21236 sampler_desc.MinLOD = 0.0f;
21237 sampler_desc.MaxLOD = 0.0f;
21239 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
21240 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
21242 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
21243 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21244 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21246 ID3D11DeviceContext_PSSetShaderResources(context,
21247 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
21248 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
21249 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
21250 draw_quad(&test_context);
21251 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
21253 ID3D11PixelShader_Release(ps);
21254 ID3D11SamplerState_Release(sampler);
21255 ID3D11ShaderResourceView_Release(srv);
21256 ID3D11Texture2D_Release(texture);
21257 release_test_context(&test_context);
21260 static void test_unbind_shader_resource_view(void)
21262 struct d3d11_test_context test_context;
21263 D3D11_SUBRESOURCE_DATA resource_data;
21264 ID3D11ShaderResourceView *srv, *srv2;
21265 D3D11_TEXTURE2D_DESC texture_desc;
21266 ID3D11DeviceContext *context;
21267 ID3D11Texture2D *texture;
21268 ID3D11PixelShader *ps;
21269 ID3D11Device *device;
21270 HRESULT hr;
21272 static const DWORD ps_code[] =
21274 #if 0
21275 Texture2D t0;
21276 Texture2D t1;
21277 SamplerState s;
21279 float4 main() : SV_Target
21281 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
21283 #endif
21284 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
21285 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21286 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
21287 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
21288 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
21289 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
21290 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21291 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
21292 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
21293 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
21294 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
21295 0x3f800000, 0x0100003e,
21297 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
21298 static const DWORD texture_data[] = {0xff00ff00};
21300 if (!init_test_context(&test_context, NULL))
21301 return;
21303 device = test_context.device;
21304 context = test_context.immediate_context;
21306 texture_desc.Width = 1;
21307 texture_desc.Height = 1;
21308 texture_desc.MipLevels = 0;
21309 texture_desc.ArraySize = 1;
21310 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
21311 texture_desc.SampleDesc.Count = 1;
21312 texture_desc.SampleDesc.Quality = 0;
21313 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21314 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
21315 texture_desc.CPUAccessFlags = 0;
21316 texture_desc.MiscFlags = 0;
21318 resource_data.pSysMem = texture_data;
21319 resource_data.SysMemPitch = sizeof(texture_data);
21320 resource_data.SysMemSlicePitch = 0;
21322 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
21323 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
21324 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
21325 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
21326 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
21327 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21328 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21330 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21331 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
21332 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
21333 draw_quad(&test_context);
21334 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
21336 srv2 = NULL;
21337 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
21338 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
21339 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
21340 draw_quad(&test_context);
21341 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
21343 ID3D11PixelShader_Release(ps);
21344 ID3D11ShaderResourceView_Release(srv);
21345 ID3D11Texture2D_Release(texture);
21346 release_test_context(&test_context);
21349 static void test_stencil_separate(void)
21351 struct d3d11_test_context test_context;
21352 D3D11_TEXTURE2D_DESC texture_desc;
21353 D3D11_DEPTH_STENCIL_DESC ds_desc;
21354 ID3D11DepthStencilState *ds_state;
21355 ID3D11DepthStencilView *ds_view;
21356 D3D11_RASTERIZER_DESC rs_desc;
21357 ID3D11DeviceContext *context;
21358 ID3D11RasterizerState *rs;
21359 ID3D11Texture2D *texture;
21360 ID3D11Device *device;
21361 HRESULT hr;
21363 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
21364 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
21365 static const struct vec3 ccw_quad[] =
21367 {-1.0f, -1.0f, 0.0f},
21368 { 1.0f, -1.0f, 0.0f},
21369 {-1.0f, 1.0f, 0.0f},
21370 { 1.0f, 1.0f, 0.0f},
21373 if (!init_test_context(&test_context, NULL))
21374 return;
21376 device = test_context.device;
21377 context = test_context.immediate_context;
21379 texture_desc.Width = 640;
21380 texture_desc.Height = 480;
21381 texture_desc.MipLevels = 1;
21382 texture_desc.ArraySize = 1;
21383 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
21384 texture_desc.SampleDesc.Count = 1;
21385 texture_desc.SampleDesc.Quality = 0;
21386 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21387 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
21388 texture_desc.CPUAccessFlags = 0;
21389 texture_desc.MiscFlags = 0;
21390 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21391 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21392 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
21393 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
21395 ds_desc.DepthEnable = TRUE;
21396 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
21397 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
21398 ds_desc.StencilEnable = TRUE;
21399 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
21400 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
21401 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
21402 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
21403 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
21404 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
21405 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
21406 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
21407 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
21408 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
21409 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
21410 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
21412 rs_desc.FillMode = D3D11_FILL_SOLID;
21413 rs_desc.CullMode = D3D11_CULL_NONE;
21414 rs_desc.FrontCounterClockwise = FALSE;
21415 rs_desc.DepthBias = 0;
21416 rs_desc.DepthBiasClamp = 0.0f;
21417 rs_desc.SlopeScaledDepthBias = 0.0f;
21418 rs_desc.DepthClipEnable = TRUE;
21419 rs_desc.ScissorEnable = FALSE;
21420 rs_desc.MultisampleEnable = FALSE;
21421 rs_desc.AntialiasedLineEnable = FALSE;
21422 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
21423 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
21425 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
21426 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
21427 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
21428 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
21429 ID3D11DeviceContext_RSSetState(context, rs);
21431 draw_color_quad(&test_context, &green);
21432 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
21434 ID3D11Buffer_Release(test_context.vb);
21435 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
21437 draw_color_quad(&test_context, &green);
21438 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
21440 ID3D11RasterizerState_Release(rs);
21441 rs_desc.FrontCounterClockwise = TRUE;
21442 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
21443 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
21444 ID3D11DeviceContext_RSSetState(context, rs);
21446 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
21447 draw_color_quad(&test_context, &green);
21448 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
21450 ID3D11DepthStencilState_Release(ds_state);
21451 ID3D11DepthStencilView_Release(ds_view);
21452 ID3D11RasterizerState_Release(rs);
21453 ID3D11Texture2D_Release(texture);
21454 release_test_context(&test_context);
21457 static void test_uav_load(void)
21459 struct shader
21461 const DWORD *code;
21462 size_t size;
21464 struct texture
21466 UINT width;
21467 UINT height;
21468 UINT miplevel_count;
21469 UINT array_size;
21470 DXGI_FORMAT format;
21471 D3D11_SUBRESOURCE_DATA data[3];
21474 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
21475 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21476 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
21477 struct d3d11_test_context test_context;
21478 const struct texture *current_texture;
21479 ID3D11Texture2D *texture, *rt_texture;
21480 D3D11_TEXTURE2D_DESC texture_desc;
21481 const struct shader *current_ps;
21482 ID3D11UnorderedAccessView *uav;
21483 ID3D11DeviceContext *context;
21484 struct resource_readback rb;
21485 ID3D11PixelShader *ps;
21486 ID3D11Device *device;
21487 unsigned int i, x, y;
21488 ID3D11Buffer *cb;
21489 HRESULT hr;
21491 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
21492 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21493 static const DWORD ps_ld_2d_float_code[] =
21495 #if 0
21496 RWTexture2D<float> u;
21498 float main(float4 position : SV_Position) : SV_Target
21500 float2 s;
21501 u.GetDimensions(s.x, s.y);
21502 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21504 #endif
21505 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
21506 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21507 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21508 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21509 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21510 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
21511 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21512 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21513 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21514 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21515 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21516 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21517 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21519 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
21520 static const DWORD ps_ld_2d_uint_code[] =
21522 #if 0
21523 RWTexture2D<uint> u;
21525 uint main(float4 position : SV_Position) : SV_Target
21527 float2 s;
21528 u.GetDimensions(s.x, s.y);
21529 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21531 #endif
21532 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
21533 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21534 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21535 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
21536 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21537 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
21538 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21539 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21540 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21541 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21542 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21543 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21544 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21546 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
21547 static const DWORD ps_ld_2d_int_code[] =
21549 #if 0
21550 RWTexture2D<int> u;
21552 int main(float4 position : SV_Position) : SV_Target
21554 float2 s;
21555 u.GetDimensions(s.x, s.y);
21556 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21558 #endif
21559 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
21560 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21561 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21562 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
21563 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21564 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
21565 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21566 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21567 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21568 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21569 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21570 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21571 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21573 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
21574 static const DWORD ps_ld_2d_uint_arr_code[] =
21576 #if 0
21577 RWTexture2DArray<uint> u;
21579 uint layer;
21581 uint main(float4 position : SV_Position) : SV_Target
21583 float3 s;
21584 u.GetDimensions(s.x, s.y, s.z);
21585 s.z = layer;
21586 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
21588 #endif
21589 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
21590 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21591 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21592 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
21593 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
21594 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
21595 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
21596 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
21597 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
21598 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
21599 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
21600 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
21601 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
21602 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21604 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
21605 static const float float_data[] =
21607 0.50f, 0.25f, 1.00f, 0.00f,
21608 -1.00f, -2.00f, -3.00f, -4.00f,
21609 -0.50f, -0.25f, -1.00f, -0.00f,
21610 1.00f, 2.00f, 3.00f, 4.00f,
21612 static const unsigned int uint_data[] =
21614 0x00, 0x10, 0x20, 0x30,
21615 0x40, 0x50, 0x60, 0x70,
21616 0x80, 0x90, 0xa0, 0xb0,
21617 0xc0, 0xd0, 0xe0, 0xf0,
21619 static const unsigned int uint_data2[] =
21621 0xffff, 0xffff, 0xffff, 0xffff,
21622 0xffff, 0xc000, 0xc000, 0xffff,
21623 0xffff, 0xc000, 0xc000, 0xffff,
21624 0xffff, 0xffff, 0xffff, 0xffff,
21626 static const unsigned int uint_data3[] =
21628 0xaa, 0xaa, 0xcc, 0xcc,
21629 0xaa, 0xaa, 0xdd, 0xdd,
21630 0xbb, 0xbb, 0xee, 0xee,
21631 0xbb, 0xbb, 0xff, 0xff,
21633 static const int int_data[] =
21635 -1, 0x10, 0x20, 0x30,
21636 0x40, 0x50, 0x60, -777,
21637 -666, 0x90, -555, 0xb0,
21638 0xc0, 0xd0, 0xe0, -101,
21640 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
21641 {{float_data, 4 * sizeof(*float_data), 0}}};
21642 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
21643 {{uint_data, 4 * sizeof(*uint_data), 0}}};
21644 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
21645 {{uint_data, 4 * sizeof(*uint_data), 0},
21646 {uint_data2, 4 * sizeof(*uint_data2), 0},
21647 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
21648 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
21649 {{int_data, 4 * sizeof(*int_data), 0}}};
21651 static const struct test
21653 const struct shader *ps;
21654 const struct texture *texture;
21655 struct uav_desc uav_desc;
21656 struct uvec4 constant;
21657 const DWORD *expected_colors;
21659 tests[] =
21661 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
21662 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
21663 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
21664 #define R32_UINT DXGI_FORMAT_R32_UINT
21665 #define R32_SINT DXGI_FORMAT_R32_SINT
21666 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {0}, (const DWORD *)float_data},
21667 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {0}, (const DWORD *)uint_data},
21668 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {0}, (const DWORD *)int_data},
21669 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
21670 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
21671 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
21672 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
21673 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
21674 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
21675 #undef TEX_2D
21676 #undef TEX_2D_ARRAY
21677 #undef R32_FLOAT
21678 #undef R32_UINT
21679 #undef R32_SINT
21682 if (!init_test_context(&test_context, &feature_level))
21683 return;
21685 device = test_context.device;
21686 context = test_context.immediate_context;
21688 texture_desc.Width = 640;
21689 texture_desc.Height = 480;
21690 texture_desc.MipLevels = 1;
21691 texture_desc.ArraySize = 1;
21692 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
21693 texture_desc.SampleDesc.Count = 1;
21694 texture_desc.SampleDesc.Quality = 0;
21695 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21696 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21697 texture_desc.CPUAccessFlags = 0;
21698 texture_desc.MiscFlags = 0;
21699 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
21700 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21702 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
21703 U(rtv_desc).Texture2D.MipSlice = 0;
21705 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
21706 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
21707 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21709 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
21710 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
21711 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21713 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
21714 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
21715 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21717 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21719 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
21720 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21722 ps = NULL;
21723 uav = NULL;
21724 texture = NULL;
21725 current_ps = NULL;
21726 current_texture = NULL;
21727 for (i = 0; i < ARRAY_SIZE(tests); ++i)
21729 const struct test *test = &tests[i];
21730 ID3D11RenderTargetView *current_rtv;
21732 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21733 NULL, &test->constant, 0, 0);
21735 if (current_ps != test->ps)
21737 if (ps)
21738 ID3D11PixelShader_Release(ps);
21740 current_ps = test->ps;
21742 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
21743 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
21745 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21748 if (current_texture != test->texture)
21750 if (texture)
21751 ID3D11Texture2D_Release(texture);
21753 current_texture = test->texture;
21755 texture_desc.Width = current_texture->width;
21756 texture_desc.Height = current_texture->height;
21757 texture_desc.MipLevels = current_texture->miplevel_count;
21758 texture_desc.ArraySize = current_texture->array_size;
21759 texture_desc.Format = current_texture->format;
21761 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
21762 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
21765 if (uav)
21766 ID3D11UnorderedAccessView_Release(uav);
21768 get_uav_desc(&uav_desc, &test->uav_desc);
21769 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
21770 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
21772 switch (uav_desc.Format)
21774 case DXGI_FORMAT_R32_FLOAT:
21775 current_rtv = rtv_float;
21776 break;
21777 case DXGI_FORMAT_R32_UINT:
21778 current_rtv = rtv_uint;
21779 break;
21780 case DXGI_FORMAT_R32_SINT:
21781 current_rtv = rtv_sint;
21782 break;
21783 default:
21784 trace("Unhandled format %#x.\n", uav_desc.Format);
21785 current_rtv = NULL;
21786 break;
21789 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
21791 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
21792 1, 1, &uav, NULL);
21794 draw_quad(&test_context);
21796 get_texture_readback(rt_texture, 0, &rb);
21797 for (y = 0; y < 4; ++y)
21799 for (x = 0; x < 4; ++x)
21801 DWORD expected = test->expected_colors[y * 4 + x];
21802 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
21803 ok(compare_color(color, expected, 0),
21804 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
21805 i, color, expected, x, y);
21808 release_resource_readback(&rb);
21810 ID3D11PixelShader_Release(ps);
21811 ID3D11Texture2D_Release(texture);
21812 ID3D11UnorderedAccessView_Release(uav);
21814 ID3D11Buffer_Release(cb);
21815 ID3D11RenderTargetView_Release(rtv_float);
21816 ID3D11RenderTargetView_Release(rtv_sint);
21817 ID3D11RenderTargetView_Release(rtv_uint);
21818 ID3D11Texture2D_Release(rt_texture);
21819 release_test_context(&test_context);
21822 static void test_cs_uav_store(void)
21824 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21825 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21826 static const float zero[4] = {0.0f};
21827 D3D11_TEXTURE2D_DESC texture_desc;
21828 ID3D11UnorderedAccessView *uav;
21829 struct device_desc device_desc;
21830 ID3D11DeviceContext *context;
21831 struct vec4 input = {1.0f};
21832 ID3D11Texture2D *texture;
21833 ID3D11ComputeShader *cs;
21834 ID3D11Device *device;
21835 ID3D11Buffer *cb;
21836 ULONG refcount;
21837 HRESULT hr;
21838 RECT rect;
21840 static const DWORD cs_1_thread_code[] =
21842 #if 0
21843 RWTexture2D<float> u;
21845 float value;
21847 [numthreads(1, 1, 1)]
21848 void main()
21850 uint x, y, width, height;
21851 u.GetDimensions(width, height);
21852 for (y = 0; y < height; ++y)
21854 for (x = 0; x < width; ++x)
21855 u[uint2(x, y)] = value;
21858 #endif
21859 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
21860 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21861 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
21862 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21863 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
21864 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
21865 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
21866 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
21867 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
21868 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
21869 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
21870 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
21871 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
21872 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
21873 0x01000016, 0x0100003e,
21875 static const DWORD cs_1_group_code[] =
21877 #if 0
21878 RWTexture2D<float> u;
21880 float value;
21882 [numthreads(16, 16, 1)]
21883 void main(uint3 threadID : SV_GroupThreadID)
21885 uint2 count, size ;
21886 u.GetDimensions(size.x, size.y);
21887 count = size / (uint2)16;
21888 for (uint y = 0; y < count.y; ++y)
21889 for (uint x = 0; x < count.x; ++x)
21890 u[count * threadID.xy + uint2(x, y)] = value;
21892 #endif
21893 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
21894 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21895 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
21896 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21897 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
21898 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
21899 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
21900 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
21901 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
21902 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
21903 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
21904 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
21905 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
21906 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
21907 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
21908 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
21909 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
21911 static const DWORD cs_1_store_code[] =
21913 #if 0
21914 RWTexture2D<float> u;
21916 float value;
21918 [numthreads(1, 1, 1)]
21919 void main(uint3 groupID : SV_GroupID)
21921 u[groupID.xy] = value;
21923 #endif
21924 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
21925 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21926 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21927 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21928 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
21929 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
21931 static const DWORD cs_dispatch_id_code[] =
21933 #if 0
21934 RWTexture2D<float> u;
21936 float value;
21938 [numthreads(4, 4, 1)]
21939 void main(uint3 id : SV_DispatchThreadID)
21941 u[id.xy] = value;
21943 #endif
21944 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
21945 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21946 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21947 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21948 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
21949 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
21951 static const DWORD cs_group_index_code[] =
21953 #if 0
21954 RWTexture2D<float> u;
21956 float value;
21958 [numthreads(32, 1, 1)]
21959 void main(uint index : SV_GroupIndex)
21961 uint2 size;
21962 u.GetDimensions(size.x, size.y);
21963 uint count = size.x * size.y / 32;
21964 index *= count;
21965 for (uint i = 0; i < count; ++i, ++index)
21966 u[uint2(index % size.x, index / size.x)] = value;
21968 #endif
21969 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
21970 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21971 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
21972 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21973 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
21974 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
21975 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
21976 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
21977 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
21978 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
21979 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
21980 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
21981 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
21982 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
21983 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
21984 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
21987 device_desc.feature_level = &feature_level;
21988 device_desc.flags = 0;
21989 if (!(device = create_device(&device_desc)))
21991 skip("Failed to create device for feature level %#x.\n", feature_level);
21992 return;
21995 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
21997 texture_desc.Width = 64;
21998 texture_desc.Height = 64;
21999 texture_desc.MipLevels = 1;
22000 texture_desc.ArraySize = 1;
22001 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
22002 texture_desc.SampleDesc.Count = 1;
22003 texture_desc.SampleDesc.Quality = 0;
22004 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22005 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22006 texture_desc.CPUAccessFlags = 0;
22007 texture_desc.MiscFlags = 0;
22009 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22010 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22012 uav_desc.Format = texture_desc.Format;
22013 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
22014 U(uav_desc).Texture2D.MipSlice = 0;
22016 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
22017 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22019 ID3D11Device_GetImmediateContext(device, &context);
22021 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
22022 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22024 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
22025 check_texture_float(texture, 0.0f, 2);
22027 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
22028 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22029 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22031 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22032 check_texture_float(texture, 1.0f, 2);
22034 input.x = 0.5f;
22035 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
22036 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22037 check_texture_float(texture, 0.5f, 2);
22039 ID3D11ComputeShader_Release(cs);
22041 input.x = 2.0f;
22042 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
22043 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
22044 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22045 check_texture_float(texture, 0.5f, 2);
22047 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
22048 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22049 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22051 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22052 check_texture_float(texture, 2.0f, 2);
22054 input.x = 4.0f;
22055 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
22056 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22057 check_texture_float(texture, 4.0f, 2);
22059 ID3D11ComputeShader_Release(cs);
22061 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
22062 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22063 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22065 input.x = 1.0f;
22066 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
22067 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
22068 check_texture_float(texture, 1.0f, 2);
22070 input.x = 0.5f;
22071 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
22072 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
22073 SetRect(&rect, 0, 0, 16, 32);
22074 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
22075 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
22076 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
22077 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
22078 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
22080 ID3D11ComputeShader_Release(cs);
22082 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
22083 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22084 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22086 input.x = 0.6f;
22087 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
22088 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
22089 SetRect(&rect, 0, 0, 60, 60);
22090 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
22091 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
22092 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
22093 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
22094 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
22096 input.x = 0.7f;
22097 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
22098 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
22099 check_texture_float(texture, 0.7f, 2);
22101 ID3D11ComputeShader_Release(cs);
22103 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
22104 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22105 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22107 input.x = 0.3f;
22108 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
22109 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22110 check_texture_float(texture, 0.3f, 2);
22112 input.x = 0.1f;
22113 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
22114 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
22115 check_texture_float(texture, 0.1f, 2);
22117 ID3D11ComputeShader_Release(cs);
22119 ID3D11Buffer_Release(cb);
22120 ID3D11Texture2D_Release(texture);
22121 ID3D11UnorderedAccessView_Release(uav);
22122 ID3D11DeviceContext_Release(context);
22123 refcount = ID3D11Device_Release(device);
22124 ok(!refcount, "Device has %u references left.\n", refcount);
22127 static void test_uav_store_immediate_constant(void)
22129 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22130 struct d3d11_test_context test_context;
22131 D3D11_TEXTURE2D_DESC texture_desc;
22132 ID3D11UnorderedAccessView *uav;
22133 ID3D11DeviceContext *context;
22134 struct resource_readback rb;
22135 ID3D11Texture2D *texture;
22136 ID3D11ComputeShader *cs;
22137 unsigned int uint_data;
22138 ID3D11Device *device;
22139 ID3D11Buffer *buffer;
22140 float float_data;
22141 int int_data;
22142 HRESULT hr;
22144 static const DWORD cs_store_int_code[] =
22146 #if 0
22147 RWBuffer<int> u;
22149 [numthreads(1, 1, 1)]
22150 void main()
22152 u[0] = 42;
22154 #endif
22155 0x43425844, 0x7246d785, 0x3f4ccbd6, 0x6a7cdbc0, 0xe2b58c72, 0x00000001, 0x000000b8, 0x00000003,
22156 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22157 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
22158 0x0400089c, 0x0011e000, 0x00000000, 0x00003333, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22159 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
22160 0x00004002, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, 0x0100003e,
22162 static const DWORD cs_store_float_code[] =
22164 #if 0
22165 RWBuffer<float> u;
22167 [numthreads(1, 1, 1)]
22168 void main()
22170 u[0] = 1.0;
22172 #endif
22173 0x43425844, 0x525eea68, 0xc4cd5716, 0xc588f9c4, 0x0da27c5a, 0x00000001, 0x000000b8, 0x00000003,
22174 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22175 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
22176 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22177 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
22178 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
22180 static const DWORD cs_store_unorm_code[] =
22182 #if 0
22183 RWTexture2D<unorm float> u;
22185 [numthreads(1, 1, 1)]
22186 void main()
22188 u[uint2(0, 0)] = 0.5f;
22190 #endif
22191 0x43425844, 0x3623f1de, 0xe847109e, 0x8e3da13f, 0xb6787b06, 0x00000001, 0x000000b8, 0x00000003,
22192 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22193 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
22194 0x0400189c, 0x0011e000, 0x00000000, 0x00001111, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22195 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
22196 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
22198 static const DWORD cs_store_snorm_code[] =
22200 #if 0
22201 RWTexture2D<snorm float> u;
22203 [numthreads(1, 1, 1)]
22204 void main()
22206 u[uint2(0, 0)] = -0.5f;
22208 #endif
22209 0x43425844, 0xce5397fc, 0x7464bc06, 0xc79aa56c, 0x881bd7ef, 0x00000001, 0x000000b8, 0x00000003,
22210 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22211 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
22212 0x0400189c, 0x0011e000, 0x00000000, 0x00002222, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22213 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
22214 0x00004002, 0xbf000000, 0xbf000000, 0xbf000000, 0xbf000000, 0x0100003e,
22216 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22217 static const unsigned int zero[4] = {0};
22219 if (!init_test_context(&test_context, &feature_level))
22220 return;
22222 device = test_context.device;
22223 context = test_context.immediate_context;
22225 buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
22227 uav_desc.Format = DXGI_FORMAT_R32_SINT;
22228 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
22229 U(uav_desc).Buffer.FirstElement = 0;
22230 U(uav_desc).Buffer.NumElements = 1;
22231 U(uav_desc).Buffer.Flags = 0;
22232 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
22233 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22234 hr = ID3D11Device_CreateComputeShader(device, cs_store_int_code, sizeof(cs_store_int_code), NULL, &cs);
22235 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22237 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
22238 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22239 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22240 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22241 get_buffer_readback(buffer, &rb);
22242 int_data = get_readback_color(&rb, 0, 0, 0);
22243 ok(int_data == 42, "Got unexpected value %u.\n", int_data);
22244 release_resource_readback(&rb);
22246 ID3D11ComputeShader_Release(cs);
22247 ID3D11UnorderedAccessView_Release(uav);
22248 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
22249 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
22250 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22251 hr = ID3D11Device_CreateComputeShader(device, cs_store_float_code, sizeof(cs_store_float_code), NULL, &cs);
22252 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22254 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
22255 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22256 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22257 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22258 get_buffer_readback(buffer, &rb);
22259 float_data = get_readback_float(&rb, 0, 0);
22260 ok(float_data == 1.0f, "Got unexpected value %.8e.\n", float_data);
22261 release_resource_readback(&rb);
22263 texture_desc.Width = 64;
22264 texture_desc.Height = 64;
22265 texture_desc.MipLevels = 1;
22266 texture_desc.ArraySize = 1;
22267 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
22268 texture_desc.SampleDesc.Count = 1;
22269 texture_desc.SampleDesc.Quality = 0;
22270 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22271 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22272 texture_desc.CPUAccessFlags = 0;
22273 texture_desc.MiscFlags = 0;
22274 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22275 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
22276 ID3D11UnorderedAccessView_Release(uav);
22277 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
22278 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
22280 ID3D11ComputeShader_Release(cs);
22281 hr = ID3D11Device_CreateComputeShader(device, cs_store_unorm_code, sizeof(cs_store_unorm_code), NULL, &cs);
22282 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
22283 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
22284 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22285 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22286 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22287 get_texture_readback(texture, 0, &rb);
22288 uint_data = get_readback_color(&rb, 0, 0, 0);
22289 ok(compare_color(uint_data, 0x80808080, 1), "Got unexpected color 0x%08x.\n", uint_data);
22290 release_resource_readback(&rb);
22292 ID3D11Texture2D_Release(texture);
22293 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_SNORM;
22294 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22295 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
22296 ID3D11UnorderedAccessView_Release(uav);
22297 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
22298 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
22300 ID3D11ComputeShader_Release(cs);
22301 hr = ID3D11Device_CreateComputeShader(device, cs_store_snorm_code, sizeof(cs_store_snorm_code), NULL, &cs);
22302 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
22303 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
22304 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22305 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22306 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22307 get_texture_readback(texture, 0, &rb);
22308 uint_data = get_readback_color(&rb, 0, 0, 0);
22309 ok(compare_color(uint_data, 0xc0c0c0c0, 1), "Got unexpected color 0x%08x.\n", uint_data);
22310 release_resource_readback(&rb);
22312 ID3D11Buffer_Release(buffer);
22313 ID3D11Texture2D_Release(texture);
22314 ID3D11ComputeShader_Release(cs);
22315 ID3D11UnorderedAccessView_Release(uav);
22316 release_test_context(&test_context);
22319 static void test_ps_cs_uav_binding(void)
22321 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22322 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
22323 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22324 ID3D11Texture2D *cs_texture, *ps_texture;
22325 struct d3d11_test_context test_context;
22326 static const float zero[4] = {0.0f};
22327 D3D11_TEXTURE2D_DESC texture_desc;
22328 ID3D11DeviceContext *context;
22329 ID3D11Buffer *cs_cb, *ps_cb;
22330 struct vec4 input = {1.0f};
22331 ID3D11ComputeShader *cs;
22332 ID3D11PixelShader *ps;
22333 ID3D11Device *device;
22334 HRESULT hr;
22336 static const DWORD cs_code[] =
22338 #if 0
22339 RWTexture2D<float> u;
22341 float value;
22343 [numthreads(1, 1, 1)]
22344 void main()
22346 uint x, y, width, height;
22347 u.GetDimensions(width, height);
22348 for (y = 0; y < height; ++y)
22350 for (x = 0; x < width; ++x)
22351 u[uint2(x, y)] = value;
22354 #endif
22355 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
22356 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22357 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
22358 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
22359 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
22360 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
22361 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
22362 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
22363 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
22364 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
22365 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
22366 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
22367 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
22368 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
22369 0x01000016, 0x0100003e,
22371 static const DWORD ps_code[] =
22373 #if 0
22374 RWTexture2D<float> u : register(u1);
22376 float value;
22378 void main()
22380 uint x, y, width, height;
22381 u.GetDimensions(width, height);
22382 for (y = 0; y < height; ++y)
22384 for (x = 0; x < width; ++x)
22385 u[uint2(x, y)] = value;
22388 #endif
22389 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
22390 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22391 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
22392 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
22393 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
22394 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
22395 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
22396 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
22397 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
22398 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
22399 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
22400 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
22401 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
22402 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
22405 if (!init_test_context(&test_context, &feature_level))
22406 return;
22408 device = test_context.device;
22409 context = test_context.immediate_context;
22411 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
22412 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
22414 texture_desc.Width = 64;
22415 texture_desc.Height = 64;
22416 texture_desc.MipLevels = 1;
22417 texture_desc.ArraySize = 1;
22418 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
22419 texture_desc.SampleDesc.Count = 1;
22420 texture_desc.SampleDesc.Quality = 0;
22421 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22422 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22423 texture_desc.CPUAccessFlags = 0;
22424 texture_desc.MiscFlags = 0;
22425 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
22426 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22427 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
22428 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22430 uav_desc.Format = texture_desc.Format;
22431 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
22432 U(uav_desc).Texture2D.MipSlice = 0;
22433 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
22434 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22435 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
22436 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22438 ID3D11Device_GetImmediateContext(device, &context);
22440 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
22441 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
22442 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
22443 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
22444 0, NULL, NULL, 1, 1, &ps_uav, NULL);
22446 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
22447 check_texture_float(cs_texture, 0.0f, 2);
22448 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
22449 check_texture_float(ps_texture, 0.0f, 2);
22451 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
22452 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22453 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22454 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22455 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22456 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22458 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22459 check_texture_float(cs_texture, 1.0f, 2);
22460 check_texture_float(ps_texture, 0.0f, 2);
22461 draw_quad(&test_context);
22462 check_texture_float(cs_texture, 1.0f, 2);
22463 check_texture_float(ps_texture, 1.0f, 2);
22465 input.x = 0.5f;
22466 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
22467 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22468 check_texture_float(cs_texture, 0.5f, 2);
22469 check_texture_float(ps_texture, 1.0f, 2);
22470 input.x = 2.0f;
22471 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
22472 draw_quad(&test_context);
22473 check_texture_float(cs_texture, 0.5f, 2);
22474 check_texture_float(ps_texture, 2.0f, 2);
22476 input.x = 8.0f;
22477 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
22478 input.x = 4.0f;
22479 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
22480 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22481 check_texture_float(cs_texture, 8.0f, 2);
22482 check_texture_float(ps_texture, 2.0f, 2);
22483 draw_quad(&test_context);
22484 check_texture_float(cs_texture, 8.0f, 2);
22485 check_texture_float(ps_texture, 4.0f, 2);
22487 ID3D11ComputeShader_Release(cs);
22488 ID3D11PixelShader_Release(ps);
22489 ID3D11Buffer_Release(cs_cb);
22490 ID3D11Buffer_Release(ps_cb);
22491 ID3D11Texture2D_Release(cs_texture);
22492 ID3D11Texture2D_Release(ps_texture);
22493 ID3D11UnorderedAccessView_Release(cs_uav);
22494 ID3D11UnorderedAccessView_Release(ps_uav);
22495 ID3D11DeviceContext_Release(context);
22496 release_test_context(&test_context);
22499 static void test_atomic_instructions(void)
22501 ID3D11UnorderedAccessView *in_uav, *out_uav;
22502 ID3D11Buffer *cb, *in_buffer, *out_buffer;
22503 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22504 struct d3d11_test_context test_context;
22505 struct resource_readback rb, out_rb;
22506 D3D11_BUFFER_DESC buffer_desc;
22507 ID3D11DeviceContext *context;
22508 ID3D11ComputeShader *cs;
22509 ID3D11PixelShader *ps;
22510 ID3D11Device *device;
22511 unsigned int i, j;
22512 HRESULT hr;
22514 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22515 static const unsigned int zero[4] = {0, 0, 0, 0};
22516 static const DWORD ps_atomics_code[] =
22518 #if 0
22519 RWByteAddressBuffer u;
22521 uint4 v;
22522 int4 i;
22524 void main()
22526 u.InterlockedAnd(0 * 4, v.x);
22527 u.InterlockedCompareStore(1 * 4, v.y, v.x);
22528 u.InterlockedAdd(2 * 4, v.x);
22529 u.InterlockedOr(3 * 4, v.x);
22530 u.InterlockedMax(4 * 4, i.x);
22531 u.InterlockedMin(5 * 4, i.x);
22532 u.InterlockedMax(6 * 4, v.x);
22533 u.InterlockedMin(7 * 4, v.x);
22534 u.InterlockedXor(8 * 4, v.x);
22536 #endif
22537 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
22538 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22539 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
22540 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
22541 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
22542 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
22543 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
22544 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
22545 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
22546 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
22547 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
22548 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
22549 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
22550 0x00000000, 0x00000000, 0x0100003e,
22552 static const DWORD cs_atomics_code[] =
22554 #if 0
22555 RWByteAddressBuffer u;
22556 RWByteAddressBuffer u2;
22558 uint4 v;
22559 int4 i;
22561 [numthreads(1, 1, 1)]
22562 void main()
22564 uint r;
22565 u.InterlockedAnd(0 * 4, v.x, r);
22566 u2.Store(0 * 4, r);
22567 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
22568 u2.Store(1 * 4, r);
22569 u.InterlockedAdd(2 * 4, v.x, r);
22570 u2.Store(2 * 4, r);
22571 u.InterlockedOr(3 * 4, v.x, r);
22572 u2.Store(3 * 4, r);
22573 u.InterlockedMax(4 * 4, i.x, r);
22574 u2.Store(4 * 4, r);
22575 u.InterlockedMin(5 * 4, i.x, r);
22576 u2.Store(5 * 4, r);
22577 u.InterlockedMax(6 * 4, v.x, r);
22578 u2.Store(6 * 4, r);
22579 u.InterlockedMin(7 * 4, v.x, r);
22580 u2.Store(7 * 4, r);
22581 u.InterlockedXor(8 * 4, v.x, r);
22582 u2.Store(8 * 4, r);
22584 #endif
22585 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
22586 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22587 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
22588 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
22589 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22590 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
22591 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
22592 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
22593 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
22594 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
22595 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
22596 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
22597 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
22598 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
22599 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
22600 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
22601 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
22602 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
22603 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
22604 0x0010000a, 0x00000000, 0x0100003e,
22607 static const char * const instructions[] =
22609 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
22610 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
22612 static const char * const imm_instructions[] =
22614 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
22615 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
22617 static const struct test
22619 struct uvec4 v;
22620 struct ivec4 i;
22621 unsigned int input[ARRAY_SIZE(instructions)];
22622 unsigned int expected_result[ARRAY_SIZE(instructions)];
22624 tests[] =
22626 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
22627 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
22630 if (!init_test_context(&test_context, &feature_level))
22631 return;
22633 device = test_context.device;
22634 context = test_context.immediate_context;
22636 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
22637 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22638 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
22640 buffer_desc.ByteWidth = sizeof(tests->input);
22641 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
22642 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22643 buffer_desc.CPUAccessFlags = 0;
22644 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
22645 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
22646 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22647 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
22648 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22650 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
22651 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
22652 U(uav_desc).Buffer.FirstElement = 0;
22653 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
22654 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
22655 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
22656 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22657 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
22658 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22660 set_viewport(context, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f);
22662 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
22663 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22664 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22666 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
22667 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22668 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22670 for (i = 0; i < ARRAY_SIZE(tests); ++i)
22672 const struct test *test = &tests[i];
22674 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22675 NULL, &test->v, 0, 0);
22677 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
22678 NULL, test->input, 0, 0);
22680 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
22681 0, 1, &in_uav, NULL);
22683 draw_quad(&test_context);
22684 get_buffer_readback(in_buffer, &rb);
22685 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
22687 unsigned int value = get_readback_color(&rb, j, 0, 0);
22688 unsigned int expected = test->expected_result[j];
22690 todo_wine_if(expected != test->input[j]
22691 && (!strcmp(instructions[j], "atomic_imax")
22692 || !strcmp(instructions[j], "atomic_imin")))
22693 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
22694 "with inputs (%u, %u), (%d), %#x (%d).\n",
22695 i, value, value, expected, expected, instructions[j],
22696 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
22698 release_resource_readback(&rb);
22700 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
22701 NULL, test->input, 0, 0);
22702 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
22704 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
22705 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
22707 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22708 get_buffer_readback(in_buffer, &rb);
22709 get_buffer_readback(out_buffer, &out_rb);
22710 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
22712 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
22713 || !strcmp(imm_instructions[j], "imm_atomic_imin");
22714 unsigned int out_value = get_readback_color(&out_rb, j, 0, 0);
22715 unsigned int value = get_readback_color(&rb, j, 0, 0);
22716 unsigned int expected = test->expected_result[j];
22718 todo_wine_if(expected != test->input[j] && todo_instruction)
22719 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
22720 "with inputs (%u, %u), (%d), %#x (%d).\n",
22721 i, value, value, expected, expected, imm_instructions[j],
22722 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
22724 todo_wine_if(todo_instruction && out_value != test->input[j])
22725 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
22726 out_value, test->input[j], imm_instructions[j]);
22728 release_resource_readback(&out_rb);
22729 release_resource_readback(&rb);
22732 ID3D11Buffer_Release(cb);
22733 ID3D11Buffer_Release(in_buffer);
22734 ID3D11Buffer_Release(out_buffer);
22735 ID3D11ComputeShader_Release(cs);
22736 ID3D11PixelShader_Release(ps);
22737 ID3D11UnorderedAccessView_Release(in_uav);
22738 ID3D11UnorderedAccessView_Release(out_uav);
22739 release_test_context(&test_context);
22742 static void test_sm4_ret_instruction(void)
22744 struct d3d11_test_context test_context;
22745 ID3D11DeviceContext *context;
22746 ID3D11PixelShader *ps;
22747 struct uvec4 constant;
22748 ID3D11Device *device;
22749 ID3D11Buffer *cb;
22750 HRESULT hr;
22752 static const DWORD ps_code[] =
22754 #if 0
22755 uint c;
22757 float4 main() : SV_TARGET
22759 if (c == 1)
22760 return float4(1, 0, 0, 1);
22761 if (c == 2)
22762 return float4(0, 1, 0, 1);
22763 if (c == 3)
22764 return float4(0, 0, 1, 1);
22765 return float4(1, 1, 1, 1);
22767 #endif
22768 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
22769 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22770 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22771 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
22772 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
22773 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
22774 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
22775 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
22776 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
22777 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
22778 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
22779 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
22780 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
22781 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
22782 0x0100003e,
22785 if (!init_test_context(&test_context, NULL))
22786 return;
22788 device = test_context.device;
22789 context = test_context.immediate_context;
22791 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22792 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
22793 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22794 memset(&constant, 0, sizeof(constant));
22795 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
22796 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22798 draw_quad(&test_context);
22799 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22801 constant.x = 1;
22802 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22803 draw_quad(&test_context);
22804 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
22806 constant.x = 2;
22807 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22808 draw_quad(&test_context);
22809 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
22811 constant.x = 3;
22812 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22813 draw_quad(&test_context);
22814 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
22816 constant.x = 4;
22817 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22818 draw_quad(&test_context);
22819 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22821 ID3D11Buffer_Release(cb);
22822 ID3D11PixelShader_Release(ps);
22823 release_test_context(&test_context);
22826 static void test_primitive_restart(void)
22828 struct d3d11_test_context test_context;
22829 ID3D11Buffer *ib32, *ib16, *vb;
22830 ID3D11DeviceContext *context;
22831 unsigned int stride, offset;
22832 ID3D11InputLayout *layout;
22833 ID3D11VertexShader *vs;
22834 ID3D11PixelShader *ps;
22835 ID3D11Device *device;
22836 unsigned int i;
22837 HRESULT hr;
22838 RECT rect;
22840 static const DWORD ps_code[] =
22842 #if 0
22843 struct vs_out
22845 float4 position : SV_Position;
22846 float4 color : color;
22849 float4 main(vs_out input) : SV_TARGET
22851 return input.color;
22853 #endif
22854 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
22855 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22856 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
22857 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
22858 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
22859 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
22860 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
22861 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
22863 static const DWORD vs_code[] =
22865 #if 0
22866 struct vs_out
22868 float4 position : SV_Position;
22869 float4 color : color;
22872 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
22874 output.position = position;
22875 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
22877 #endif
22878 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
22879 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
22880 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
22881 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
22882 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
22883 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
22884 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
22885 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
22886 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
22887 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
22888 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
22889 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
22890 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
22892 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
22894 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
22896 static const struct vec2 vertices[] =
22898 {-1.00f, -1.0f},
22899 {-1.00f, 1.0f},
22900 {-0.25f, -1.0f},
22901 {-0.25f, 1.0f},
22902 { 0.25f, -1.0f},
22903 { 0.25f, 1.0f},
22904 { 1.00f, -1.0f},
22905 { 1.00f, 1.0f},
22907 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
22908 static const unsigned short indices16[] =
22910 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
22912 static const unsigned int indices32[] =
22914 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
22917 if (!init_test_context(&test_context, NULL))
22918 return;
22920 device = test_context.device;
22921 context = test_context.immediate_context;
22923 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
22924 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
22925 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22926 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
22928 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
22929 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
22931 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
22932 vs_code, sizeof(vs_code), &layout);
22933 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
22935 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
22937 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
22938 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22940 ID3D11DeviceContext_IASetInputLayout(context, layout);
22941 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
22942 stride = sizeof(*vertices);
22943 offset = 0;
22944 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
22946 for (i = 0; i < 2; ++i)
22948 if (!i)
22949 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
22950 else
22951 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
22953 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
22954 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
22955 SetRect(&rect, 0, 0, 240, 480);
22956 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
22957 SetRect(&rect, 240, 0, 400, 480);
22958 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
22959 SetRect(&rect, 400, 0, 640, 480);
22960 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
22963 ID3D11Buffer_Release(ib16);
22964 ID3D11Buffer_Release(ib32);
22965 ID3D11Buffer_Release(vb);
22966 ID3D11InputLayout_Release(layout);
22967 ID3D11PixelShader_Release(ps);
22968 ID3D11VertexShader_Release(vs);
22969 release_test_context(&test_context);
22972 static void test_resinfo_instruction(void)
22974 struct shader
22976 const DWORD *code;
22977 size_t size;
22980 struct d3d11_test_context test_context;
22981 D3D11_TEXTURE3D_DESC texture3d_desc;
22982 D3D11_TEXTURE2D_DESC texture_desc;
22983 const struct shader *current_ps;
22984 D3D_FEATURE_LEVEL feature_level;
22985 ID3D11ShaderResourceView *srv;
22986 ID3D11DeviceContext *context;
22987 ID3D11Texture2D *rtv_texture;
22988 ID3D11RenderTargetView *rtv;
22989 ID3D11Resource *texture;
22990 struct uvec4 constant;
22991 ID3D11PixelShader *ps;
22992 ID3D11Device *device;
22993 unsigned int i, type;
22994 ID3D11Buffer *cb;
22995 HRESULT hr;
22997 static const DWORD ps_2d_code[] =
22999 #if 0
23000 Texture2D t;
23002 uint type;
23003 uint level;
23005 float4 main() : SV_TARGET
23007 if (!type)
23009 float width, height, miplevels;
23010 t.GetDimensions(level, width, height, miplevels);
23011 return float4(width, height, miplevels, 0);
23013 else
23015 uint width, height, miplevels;
23016 t.GetDimensions(level, width, height, miplevels);
23017 return float4(width, height, miplevels, 0);
23020 #endif
23021 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
23022 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23023 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23024 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
23025 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
23026 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
23027 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
23028 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
23029 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
23030 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
23031 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
23032 0x01000015, 0x0100003e,
23034 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
23035 static const DWORD ps_2d_array_code[] =
23037 #if 0
23038 Texture2DArray t;
23040 uint type;
23041 uint level;
23043 float4 main() : SV_TARGET
23045 if (!type)
23047 float width, height, elements, miplevels;
23048 t.GetDimensions(level, width, height, elements, miplevels);
23049 return float4(width, height, elements, miplevels);
23051 else
23053 uint width, height, elements, miplevels;
23054 t.GetDimensions(level, width, height, elements, miplevels);
23055 return float4(width, height, elements, miplevels);
23058 #endif
23059 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
23060 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23061 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23062 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
23063 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
23064 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
23065 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
23066 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
23067 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
23068 0x0100003e, 0x01000015, 0x0100003e,
23070 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
23071 static const DWORD ps_3d_code[] =
23073 #if 0
23074 Texture3D t;
23076 uint type;
23077 uint level;
23079 float4 main() : SV_TARGET
23081 if (!type)
23083 float width, height, depth, miplevels;
23084 t.GetDimensions(level, width, height, depth, miplevels);
23085 return float4(width, height, depth, miplevels);
23087 else
23089 uint width, height, depth, miplevels;
23090 t.GetDimensions(level, width, height, depth, miplevels);
23091 return float4(width, height, depth, miplevels);
23094 #endif
23095 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
23096 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23097 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23098 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
23099 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
23100 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
23101 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
23102 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
23103 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
23104 0x0100003e, 0x01000015, 0x0100003e,
23106 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
23107 static const DWORD ps_cube_code[] =
23109 #if 0
23110 TextureCube t;
23112 uint type;
23113 uint level;
23115 float4 main() : SV_TARGET
23117 if (!type)
23119 float width, height, miplevels;
23120 t.GetDimensions(level, width, height, miplevels);
23121 return float4(width, height, miplevels, 0);
23123 else
23125 uint width, height, miplevels;
23126 t.GetDimensions(level, width, height, miplevels);
23127 return float4(width, height, miplevels, 0);
23130 #endif
23131 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
23132 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23133 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23134 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
23135 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
23136 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
23137 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
23138 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
23139 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
23140 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
23141 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
23142 0x01000015, 0x0100003e,
23144 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
23145 static const DWORD ps_cube_array_code[] =
23147 #if 0
23148 TextureCubeArray t;
23150 uint type;
23151 uint level;
23153 float4 main() : SV_TARGET
23155 if (!type)
23157 float width, height, elements, miplevels;
23158 t.GetDimensions(level, width, height, elements, miplevels);
23159 return float4(width, height, miplevels, 0);
23161 else
23163 uint width, height, elements, miplevels;
23164 t.GetDimensions(level, width, height, elements, miplevels);
23165 return float4(width, height, miplevels, 0);
23168 #endif
23169 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
23170 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23171 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23172 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
23173 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
23174 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
23175 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
23176 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
23177 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
23178 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
23179 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
23180 0x0100003e, 0x01000015, 0x0100003e,
23182 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
23183 static const struct ps_test
23185 const struct shader *ps;
23186 struct
23188 unsigned int width;
23189 unsigned int height;
23190 unsigned int depth;
23191 unsigned int miplevel_count;
23192 unsigned int array_size;
23193 unsigned int cube_count;
23194 } texture_desc;
23195 unsigned int miplevel;
23196 struct vec4 expected_result;
23198 ps_tests[] =
23200 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
23201 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
23202 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
23203 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
23205 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
23206 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
23207 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
23208 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
23210 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
23211 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
23212 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
23213 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
23214 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
23215 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
23216 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
23217 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
23218 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
23220 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
23221 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
23222 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
23223 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
23224 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
23226 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
23227 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
23228 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
23231 if (!init_test_context(&test_context, NULL))
23232 return;
23234 device = test_context.device;
23235 context = test_context.immediate_context;
23236 feature_level = ID3D11Device_GetFeatureLevel(device);
23238 texture_desc.Width = 64;
23239 texture_desc.Height = 64;
23240 texture_desc.MipLevels = 1;
23241 texture_desc.ArraySize = 1;
23242 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
23243 texture_desc.SampleDesc.Count = 1;
23244 texture_desc.SampleDesc.Quality = 0;
23245 texture_desc.Usage = D3D11_USAGE_DEFAULT;
23246 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23247 texture_desc.CPUAccessFlags = 0;
23248 texture_desc.MiscFlags = 0;
23249 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
23250 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
23251 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
23252 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
23254 memset(&constant, 0, sizeof(constant));
23255 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
23257 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23258 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
23260 ps = NULL;
23261 current_ps = NULL;
23262 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
23264 const struct ps_test *test = &ps_tests[i];
23266 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
23268 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
23269 continue;
23272 if (current_ps != test->ps)
23274 if (ps)
23275 ID3D11PixelShader_Release(ps);
23277 current_ps = test->ps;
23279 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
23280 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
23281 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23284 if (test->texture_desc.depth != 1)
23286 texture3d_desc.Width = test->texture_desc.width;
23287 texture3d_desc.Height = test->texture_desc.height;
23288 texture3d_desc.Depth = test->texture_desc.depth;
23289 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
23290 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
23291 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
23292 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23293 texture3d_desc.CPUAccessFlags = 0;
23294 texture3d_desc.MiscFlags = 0;
23295 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
23296 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
23298 else
23300 texture_desc.Width = test->texture_desc.width;
23301 texture_desc.Height = test->texture_desc.height;
23302 texture_desc.MipLevels = test->texture_desc.miplevel_count;
23303 texture_desc.ArraySize = test->texture_desc.array_size;
23304 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
23305 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23306 texture_desc.MiscFlags = 0;
23307 if (test->texture_desc.cube_count)
23308 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
23309 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
23310 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
23313 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
23314 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
23315 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23317 for (type = 0; type < 2; ++type)
23319 constant.x = type;
23320 constant.y = test->miplevel;
23321 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
23323 draw_quad(&test_context);
23324 check_texture_vec4(rtv_texture, &test->expected_result, 0);
23327 ID3D11Resource_Release(texture);
23328 ID3D11ShaderResourceView_Release(srv);
23330 ID3D11PixelShader_Release(ps);
23332 ID3D11Buffer_Release(cb);
23333 ID3D11RenderTargetView_Release(rtv);
23334 ID3D11Texture2D_Release(rtv_texture);
23335 release_test_context(&test_context);
23338 static void test_sm5_bufinfo_instruction(void)
23340 struct shader
23342 const DWORD *code;
23343 size_t size;
23346 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
23347 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
23348 struct d3d11_test_context test_context;
23349 D3D11_TEXTURE2D_DESC texture_desc;
23350 const struct shader *current_ps;
23351 ID3D11UnorderedAccessView *uav;
23352 ID3D11ShaderResourceView *srv;
23353 D3D11_BUFFER_DESC buffer_desc;
23354 ID3D11DeviceContext *context;
23355 ID3D11RenderTargetView *rtv;
23356 ID3D11Texture2D *texture;
23357 ID3D11PixelShader *ps;
23358 ID3D11Buffer *buffer;
23359 ID3D11Device *device;
23360 unsigned int i;
23361 HRESULT hr;
23363 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23364 static const DWORD ps_uav_structured_code[] =
23366 #if 0
23367 struct s
23369 uint4 u;
23370 bool b;
23373 RWStructuredBuffer<s> b;
23375 uint4 main(void) : SV_Target
23377 uint count, stride;
23378 b.GetDimensions(count, stride);
23379 return uint4(count, stride, 0, 1);
23381 #endif
23382 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
23383 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23384 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23385 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
23386 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
23387 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
23388 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
23389 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
23391 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
23392 static const DWORD ps_uav_structured32_code[] =
23394 #if 0
23395 struct s
23397 uint4 u;
23398 bool4 b;
23401 RWStructuredBuffer<s> b;
23403 uint4 main(void) : SV_Target
23405 uint count, stride;
23406 b.GetDimensions(count, stride);
23407 return uint4(count, stride, 0, 1);
23409 #endif
23410 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
23411 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23412 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23413 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
23414 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
23415 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
23416 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
23417 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
23419 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
23420 static const DWORD ps_srv_structured_code[] =
23422 #if 0
23423 StructuredBuffer<bool> b;
23425 uint4 main(void) : SV_Target
23427 uint count, stride;
23428 b.GetDimensions(count, stride);
23429 return uint4(count, stride, 0, 1);
23431 #endif
23432 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
23433 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23434 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23435 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
23436 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
23437 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
23438 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
23439 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
23441 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
23442 static const DWORD ps_uav_raw_code[] =
23444 #if 0
23445 RWByteAddressBuffer b;
23447 uint4 main(void) : SV_Target
23449 uint width;
23450 b.GetDimensions(width);
23451 return width;
23453 #endif
23454 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
23455 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23456 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23457 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
23458 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
23459 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
23460 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23462 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
23463 static const DWORD ps_srv_raw_code[] =
23465 #if 0
23466 ByteAddressBuffer b;
23468 uint4 main(void) : SV_Target
23470 uint width;
23471 b.GetDimensions(width);
23472 return width;
23474 #endif
23475 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
23476 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23477 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23478 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
23479 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
23480 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
23481 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23483 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
23484 static const DWORD ps_uav_typed_code[] =
23486 #if 0
23487 RWBuffer<float> b;
23489 uint4 main(void) : SV_Target
23491 uint width;
23492 b.GetDimensions(width);
23493 return width;
23495 #endif
23496 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
23497 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23498 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23499 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
23500 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23501 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
23502 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23504 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
23505 static const DWORD ps_srv_typed_code[] =
23507 #if 0
23508 Buffer<float> b;
23510 uint4 main(void) : SV_Target
23512 uint width;
23513 b.GetDimensions(width);
23514 return width;
23516 #endif
23517 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
23518 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23519 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23520 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
23521 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23522 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
23523 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23525 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
23526 static const struct test
23528 const struct shader *ps;
23529 BOOL uav;
23530 unsigned int buffer_size;
23531 unsigned int buffer_misc_flags;
23532 unsigned int buffer_structure_byte_stride;
23533 DXGI_FORMAT view_format;
23534 unsigned int view_element_idx;
23535 unsigned int view_element_count;
23536 struct uvec4 expected_result;
23538 tests[] =
23540 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
23541 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
23542 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
23543 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
23544 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
23545 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
23546 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
23547 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
23548 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
23549 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
23550 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
23551 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
23552 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
23553 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
23554 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
23555 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
23556 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
23557 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
23558 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
23559 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
23560 #undef RAW
23561 #undef STRUCTURED
23564 if (!init_test_context(&test_context, &feature_level))
23565 return;
23567 device = test_context.device;
23568 context = test_context.immediate_context;
23570 texture_desc.Width = 64;
23571 texture_desc.Height = 64;
23572 texture_desc.MipLevels = 1;
23573 texture_desc.ArraySize = 1;
23574 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
23575 texture_desc.SampleDesc.Count = 1;
23576 texture_desc.SampleDesc.Quality = 0;
23577 texture_desc.Usage = D3D11_USAGE_DEFAULT;
23578 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23579 texture_desc.CPUAccessFlags = 0;
23580 texture_desc.MiscFlags = 0;
23581 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23582 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
23583 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23584 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
23586 ps = NULL;
23587 current_ps = NULL;
23588 for (i = 0; i < ARRAY_SIZE(tests); ++i)
23590 const struct test *test = &tests[i];
23592 if (current_ps != test->ps)
23594 if (ps)
23595 ID3D11PixelShader_Release(ps);
23597 current_ps = test->ps;
23599 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
23600 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
23601 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23604 buffer_desc.ByteWidth = test->buffer_size;
23605 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23606 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
23607 buffer_desc.CPUAccessFlags = 0;
23608 buffer_desc.MiscFlags = test->buffer_misc_flags;
23609 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
23610 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
23611 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
23613 if (test->uav)
23615 uav_desc.Format = test->view_format;
23616 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
23617 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
23618 U(uav_desc).Buffer.NumElements = test->view_element_count;
23619 U(uav_desc).Buffer.Flags = 0;
23620 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
23621 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
23622 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
23623 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
23624 srv = NULL;
23626 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
23627 1, 1, &uav, NULL);
23629 else
23631 srv_desc.Format = test->view_format;
23632 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
23633 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
23634 U(srv_desc).BufferEx.NumElements = test->view_element_count;
23635 U(srv_desc).BufferEx.Flags = 0;
23636 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
23637 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
23638 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
23639 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
23640 uav = NULL;
23642 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23643 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23646 draw_quad(&test_context);
23647 check_texture_uvec4(texture, &test->expected_result);
23649 if (srv)
23650 ID3D11ShaderResourceView_Release(srv);
23651 if (uav)
23652 ID3D11UnorderedAccessView_Release(uav);
23653 ID3D11Buffer_Release(buffer);
23655 ID3D11PixelShader_Release(ps);
23657 ID3D11RenderTargetView_Release(rtv);
23658 ID3D11Texture2D_Release(texture);
23659 release_test_context(&test_context);
23662 static void test_sampleinfo_instruction(void)
23664 ID3D11Texture2D *float_rt_texture, *uint_rt_texture;
23665 ID3D11RenderTargetView *float_rtv, *uint_rtv, *rtv;
23666 ID3D11PixelShader *ps_float, *ps_uint, *ps_rt;
23667 ID3D11Texture2D *texture, *readback_texture;
23668 struct d3d11_test_context test_context;
23669 unsigned int sample_count, quality;
23670 D3D11_TEXTURE2D_DESC texture_desc;
23671 ID3D11RenderTargetView *rtvs[2];
23672 ID3D11ShaderResourceView *srv;
23673 ID3D11DeviceContext *context;
23674 struct uvec4 expected_uint;
23675 struct vec4 expected_float;
23676 ID3D11Device *device;
23677 HRESULT hr;
23679 static const DWORD ps_uint_code[] =
23681 #if 0
23682 Texture2DMS<float> t;
23684 uint4 main() : SV_Target1
23686 uint width, height, sample_count;
23687 t.GetDimensions(width, height, sample_count);
23688 return sample_count;
23690 #endif
23691 0x43425844, 0x4342ad12, 0x19addd8c, 0x5cb87c48, 0xe604a242, 0x00000001, 0x000000d4, 0x00000003,
23692 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23693 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
23694 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
23695 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000001,
23696 0x02000068, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a, 0x00000000, 0x05000036,
23697 0x001020f2, 0x00000001, 0x00100006, 0x00000000, 0x0100003e,
23699 static const DWORD ps_float_code[] =
23701 #if 0
23702 Texture2DMS<float> t;
23704 float4 main() : SV_Target
23706 uint width, height, sample_count;
23707 t.GetDimensions(width, height, sample_count);
23708 return sample_count;
23710 #endif
23711 0x43425844, 0x2b8aea46, 0x34ceda6f, 0xf98d222b, 0x235ebc0b, 0x00000001, 0x000000b8, 0x00000003,
23712 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23713 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23714 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000040, 0x00000050, 0x00000010,
23715 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23716 0x0500006f, 0x001020f2, 0x00000000, 0x0010700a, 0x00000000, 0x0100003e,
23718 static const DWORD ps_rt_code[] =
23720 #if 0
23721 float4 main() : SV_Target
23723 return GetRenderTargetSampleCount();
23725 #endif
23726 0x43425844, 0x74404d37, 0xad6f88e4, 0xb006ea57, 0xf07d9e2a, 0x00000001, 0x000000a4, 0x00000003,
23727 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23728 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23729 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000002c, 0x00000050, 0x0000000b,
23730 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x0400006f, 0x001020f2, 0x00000000, 0x0000e00a,
23731 0x0100003e,
23733 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23735 if (!init_test_context(&test_context, &feature_level))
23736 return;
23738 device = test_context.device;
23739 context = test_context.immediate_context;
23741 texture_desc.Width = 64;
23742 texture_desc.Height = 64;
23743 texture_desc.MipLevels = 1;
23744 texture_desc.ArraySize = 1;
23745 texture_desc.SampleDesc.Count = 1;
23746 texture_desc.SampleDesc.Quality = 0;
23747 texture_desc.Usage = D3D11_USAGE_DEFAULT;
23748 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23749 texture_desc.CPUAccessFlags = 0;
23750 texture_desc.MiscFlags = 0;
23752 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
23753 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &float_rt_texture);
23754 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23755 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)float_rt_texture, NULL, &float_rtv);
23756 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
23757 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
23758 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &uint_rt_texture);
23759 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23760 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)uint_rt_texture, NULL, &uint_rtv);
23761 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
23763 rtvs[0] = float_rtv;
23764 rtvs[1] = uint_rtv;
23765 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
23767 hr = ID3D11Device_CreatePixelShader(device, ps_float_code, sizeof(ps_float_code), NULL, &ps_float);
23768 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23769 hr = ID3D11Device_CreatePixelShader(device, ps_uint_code, sizeof(ps_uint_code), NULL, &ps_uint);
23770 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23772 for (sample_count = 2; sample_count <= 8; sample_count *= 2)
23774 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
23775 texture_desc.SampleDesc.Count = sample_count;
23776 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
23778 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
23779 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
23780 if (!quality)
23782 skip("Sample count %u not supported.\n", sample_count);
23783 continue;
23786 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23787 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
23788 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
23789 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
23790 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23792 ID3D11DeviceContext_PSSetShader(context, ps_float, NULL, 0);
23793 draw_quad(&test_context);
23794 ID3D11DeviceContext_PSSetShader(context, ps_uint, NULL, 0);
23795 draw_quad(&test_context);
23797 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
23798 check_texture_vec4(float_rt_texture, &expected_float, 0);
23799 expected_uint.x = expected_uint.y = expected_uint.z = expected_uint.w = sample_count;
23800 check_texture_uvec4(uint_rt_texture, &expected_uint);
23802 ID3D11Texture2D_Release(texture);
23803 ID3D11ShaderResourceView_Release(srv);
23806 hr = ID3D11Device_CreatePixelShader(device, ps_rt_code, sizeof(ps_rt_code), NULL, &ps_rt);
23807 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23808 for (sample_count = 1; sample_count <= 8; sample_count *= 2)
23810 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
23811 texture_desc.SampleDesc.Count = sample_count;
23812 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23814 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
23815 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
23816 if (!quality)
23818 skip("Sample count %u not supported.\n", sample_count);
23819 continue;
23822 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23823 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
23824 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23825 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
23826 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23828 /* Some drivers (AMD Radeon HD 6310) return stale sample counts if we
23829 * don't rebind the pixel shader between runs with different sample
23830 * counts. */
23831 ID3D11DeviceContext_PSSetShader(context, NULL, NULL, 0);
23832 ID3D11DeviceContext_PSSetShader(context, ps_rt, NULL, 0);
23833 draw_quad(&test_context);
23835 if (sample_count != 1)
23837 texture_desc.SampleDesc.Count = 1;
23838 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
23839 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23840 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
23841 (ID3D11Resource *)texture, 0, texture_desc.Format);
23843 else
23845 readback_texture = texture;
23846 ID3D11Texture2D_AddRef(readback_texture);
23849 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
23850 check_texture_vec4(readback_texture, &expected_float, 0);
23852 ID3D11Texture2D_Release(readback_texture);
23853 ID3D11Texture2D_Release(texture);
23854 ID3D11RenderTargetView_Release(rtv);
23857 ID3D11RenderTargetView_Release(float_rtv);
23858 ID3D11RenderTargetView_Release(uint_rtv);
23859 ID3D11Texture2D_Release(float_rt_texture);
23860 ID3D11Texture2D_Release(uint_rt_texture);
23861 ID3D11PixelShader_Release(ps_float);
23862 ID3D11PixelShader_Release(ps_uint);
23863 ID3D11PixelShader_Release(ps_rt);
23864 release_test_context(&test_context);
23867 static void test_render_target_device_mismatch(void)
23869 struct d3d11_test_context test_context;
23870 struct device_desc device_desc = {0};
23871 ID3D11DeviceContext *context;
23872 ID3D11RenderTargetView *rtv;
23873 ID3D11Device *device;
23874 ULONG refcount;
23876 if (!init_test_context(&test_context, NULL))
23877 return;
23879 device = create_device(&device_desc);
23880 ok(!!device, "Failed to create device.\n");
23882 ID3D11Device_GetImmediateContext(device, &context);
23884 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
23885 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
23886 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
23887 if (!enable_debug_layer)
23889 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
23890 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
23891 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
23892 ID3D11RenderTargetView_Release(rtv);
23895 rtv = NULL;
23896 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23898 ID3D11DeviceContext_Release(context);
23899 refcount = ID3D11Device_Release(device);
23900 ok(!refcount, "Device has %u references left.\n", refcount);
23901 release_test_context(&test_context);
23904 static void test_buffer_srv(void)
23906 struct shader
23908 const DWORD *code;
23909 size_t size;
23910 BOOL requires_raw_and_structured_buffers;
23912 struct buffer
23914 unsigned int byte_count;
23915 unsigned int data_offset;
23916 const void *data;
23917 unsigned int structure_byte_stride;
23920 BOOL raw_and_structured_buffers_supported;
23921 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
23922 struct d3d11_test_context test_context;
23923 D3D11_SUBRESOURCE_DATA resource_data;
23924 const struct buffer *current_buffer;
23925 const struct shader *current_shader;
23926 ID3D11ShaderResourceView *srv;
23927 D3D11_BUFFER_DESC buffer_desc;
23928 ID3D11DeviceContext *context;
23929 DWORD color, expected_color;
23930 struct resource_readback rb;
23931 ID3D11Buffer *cb, *buffer;
23932 ID3D11PixelShader *ps;
23933 ID3D11Device *device;
23934 unsigned int i, x, y;
23935 struct vec4 cb_size;
23936 HRESULT hr;
23938 static const DWORD ps_float4_code[] =
23940 #if 0
23941 Buffer<float4> b;
23943 float2 size;
23945 float4 main(float4 position : SV_POSITION) : SV_Target
23947 float2 p;
23948 int2 coords;
23949 p.x = position.x / 640.0f;
23950 p.y = position.y / 480.0f;
23951 coords = int2(p.x * size.x, p.y * size.y);
23952 return b.Load(coords.y * size.x + coords.x);
23954 #endif
23955 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
23956 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
23957 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
23958 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
23959 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
23960 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
23961 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
23962 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
23963 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
23964 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
23965 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
23966 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
23967 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
23969 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
23970 static const DWORD ps_structured_code[] =
23972 #if 0
23973 StructuredBuffer<float4> b;
23975 float2 size;
23977 float4 main(float4 position : SV_POSITION) : SV_Target
23979 float2 p;
23980 int2 coords;
23981 p.x = position.x / 640.0f;
23982 p.y = position.y / 480.0f;
23983 coords = int2(p.x * size.x, p.y * size.y);
23984 return b[coords.y * size.x + coords.x];
23986 #endif
23987 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
23988 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
23989 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
23990 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
23991 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
23992 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
23993 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
23994 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
23995 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
23996 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
23997 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
23998 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
23999 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
24000 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
24002 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
24003 static const DWORD rgba16[] =
24005 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
24006 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
24007 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
24008 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
24010 static const DWORD rgba4[] =
24012 0xffffffff, 0xff0000ff,
24013 0xff000000, 0xff00ff00,
24015 static const BYTE r4[] =
24017 0xde, 0xad,
24018 0xba, 0xbe,
24020 static const struct vec4 rgba_float[] =
24022 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
24023 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
24025 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
24026 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
24027 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
24028 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
24029 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
24030 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
24031 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
24032 &rgba_float, sizeof(*rgba_float)};
24033 static const DWORD rgba16_colors2x2[] =
24035 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
24036 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
24037 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
24038 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
24040 static const DWORD rgba16_colors1x1[] =
24042 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
24043 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
24044 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
24045 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
24047 static const DWORD rgba4_colors[] =
24049 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
24050 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
24051 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
24052 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
24054 static const DWORD r4_colors[] =
24056 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
24057 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
24058 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
24059 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
24061 static const DWORD zero_colors[16] = {0};
24062 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
24064 static const struct test
24066 const struct shader *shader;
24067 const struct buffer *buffer;
24068 DXGI_FORMAT srv_format;
24069 unsigned int srv_first_element;
24070 unsigned int srv_element_count;
24071 struct vec2 size;
24072 const DWORD *expected_colors;
24074 tests[] =
24076 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
24077 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
24078 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
24079 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
24080 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
24081 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
24082 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
24083 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
24084 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
24085 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
24086 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
24089 if (!init_test_context(&test_context, NULL))
24090 return;
24092 device = test_context.device;
24093 context = test_context.immediate_context;
24094 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
24095 || check_compute_shaders_via_sm4_support(device);
24097 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
24098 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
24100 buffer_desc.ByteWidth = 256;
24101 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24102 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
24103 buffer_desc.CPUAccessFlags = 0;
24104 buffer_desc.MiscFlags = 0;
24105 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24106 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24107 srv_desc.Format = DXGI_FORMAT_R8_UNORM;
24108 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
24109 U(srv_desc).Buffer.FirstElement = 0;
24110 U(srv_desc).Buffer.NumElements = 0;
24111 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
24112 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
24113 ID3D11Buffer_Release(buffer);
24115 ps = NULL;
24116 srv = NULL;
24117 buffer = NULL;
24118 current_shader = NULL;
24119 current_buffer = NULL;
24120 for (i = 0; i < ARRAY_SIZE(tests); ++i)
24122 const struct test *test = &tests[i];
24124 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
24126 skip("Test %u: Raw and structured buffers are not supported.\n", i);
24127 continue;
24129 /* Structured buffer views with an offset don't seem to work on WARP. */
24130 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
24131 && is_warp_device(device))
24133 skip("Test %u: Broken WARP.\n", i);
24134 continue;
24137 if (current_shader != test->shader)
24139 if (ps)
24140 ID3D11PixelShader_Release(ps);
24142 current_shader = test->shader;
24144 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
24145 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
24146 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
24149 if (current_buffer != test->buffer)
24151 if (buffer)
24152 ID3D11Buffer_Release(buffer);
24154 current_buffer = test->buffer;
24155 if (current_buffer)
24157 BYTE *data = NULL;
24159 buffer_desc.ByteWidth = current_buffer->byte_count;
24160 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24161 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
24162 buffer_desc.CPUAccessFlags = 0;
24163 buffer_desc.MiscFlags = 0;
24164 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
24165 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24166 resource_data.SysMemPitch = 0;
24167 resource_data.SysMemSlicePitch = 0;
24168 if (current_buffer->data_offset)
24170 data = heap_alloc_zero(current_buffer->byte_count);
24171 ok(!!data, "Failed to allocate memory.\n");
24172 memcpy(data + current_buffer->data_offset, current_buffer->data,
24173 current_buffer->byte_count - current_buffer->data_offset);
24174 resource_data.pSysMem = data;
24176 else
24178 resource_data.pSysMem = current_buffer->data;
24180 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
24181 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
24182 heap_free(data);
24184 else
24186 buffer = NULL;
24190 if (srv)
24191 ID3D11ShaderResourceView_Release(srv);
24192 if (current_buffer)
24194 srv_desc.Format = test->srv_format;
24195 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
24196 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
24197 U(srv_desc).Buffer.NumElements = test->srv_element_count;
24198 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
24199 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
24201 else
24203 srv = NULL;
24205 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
24207 cb_size.x = test->size.x;
24208 cb_size.y = test->size.y;
24209 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
24211 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
24212 draw_quad(&test_context);
24214 get_texture_readback(test_context.backbuffer, 0, &rb);
24215 for (y = 0; y < 4; ++y)
24217 for (x = 0; x < 4; ++x)
24219 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
24220 expected_color = test->expected_colors[y * 4 + x];
24221 ok(compare_color(color, expected_color, 1),
24222 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
24223 i, color, expected_color, x, y);
24226 release_resource_readback(&rb);
24228 if (srv)
24229 ID3D11ShaderResourceView_Release(srv);
24230 if (buffer)
24231 ID3D11Buffer_Release(buffer);
24233 ID3D11Buffer_Release(cb);
24234 ID3D11PixelShader_Release(ps);
24235 release_test_context(&test_context);
24238 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
24240 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24241 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
24242 struct d3d11_test_context test_context;
24243 D3D11_SUBRESOURCE_DATA resource_data;
24244 D3D11_TEXTURE2D_DESC texture_desc;
24245 ID3D11UnorderedAccessView *uav;
24246 ID3D11ShaderResourceView *srv;
24247 D3D11_BUFFER_DESC buffer_desc;
24248 ID3D11Buffer *cb, *raw_buffer;
24249 ID3D11DeviceContext *context;
24250 struct resource_readback rb;
24251 ID3D11RenderTargetView *rtv;
24252 ID3D11Texture2D *texture;
24253 ID3D11ComputeShader *cs;
24254 ID3D11PixelShader *ps;
24255 ID3D11Device *device;
24256 unsigned int i, data;
24257 struct uvec4 offset;
24258 HRESULT hr;
24260 static const unsigned int buffer_data[] =
24262 0xffffffff, 0x00000000,
24264 static const DWORD ps_code[] =
24266 #if 0
24267 ByteAddressBuffer buffer;
24269 uint offset;
24271 uint main() : SV_Target0
24273 return buffer.Load(offset);
24275 #endif
24276 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
24277 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
24278 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
24279 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
24280 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
24281 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
24282 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
24283 0x00000000,
24285 static const DWORD cs_code[] =
24287 #if 0
24288 RWByteAddressBuffer buffer;
24290 uint2 input;
24292 [numthreads(1, 1, 1)]
24293 void main()
24295 buffer.Store(input.x, input.y);
24297 #endif
24298 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
24299 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24300 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
24301 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
24302 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
24303 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
24305 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
24307 if (!init_test_context(&test_context, &feature_level))
24308 return;
24310 device = test_context.device;
24311 context = test_context.immediate_context;
24313 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
24315 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
24316 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
24317 if (SUCCEEDED(hr))
24318 ID3D11PixelShader_Release(ps);
24319 skip("Raw buffers are not supported.\n");
24320 release_test_context(&test_context);
24321 return;
24324 if (is_intel_device(device))
24326 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
24327 * This test checks what happens when offsets are not properly aligned.
24328 * The behavior seems to be undefined on Intel hardware. */
24329 win_skip("Skipping the test on Intel hardware.\n");
24330 release_test_context(&test_context);
24331 return;
24334 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
24335 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
24337 memset(&offset, 0, sizeof(offset));
24338 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
24340 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
24341 texture_desc.Format = DXGI_FORMAT_R32_UINT;
24342 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
24343 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
24344 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
24345 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
24347 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
24349 buffer_desc.ByteWidth = sizeof(buffer_data);
24350 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24351 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
24352 buffer_desc.CPUAccessFlags = 0;
24353 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
24354 resource_data.pSysMem = buffer_data;
24355 resource_data.SysMemPitch = 0;
24356 resource_data.SysMemSlicePitch = 0;
24357 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
24358 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24360 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
24361 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
24362 U(srv_desc).BufferEx.FirstElement = 0;
24363 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
24364 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
24365 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
24366 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
24368 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
24369 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
24370 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
24372 offset.x = 0;
24373 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24374 NULL, &offset, 0, 0);
24375 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
24376 draw_quad(&test_context);
24377 check_texture_color(texture, buffer_data[0], 0);
24378 offset.x = 1;
24379 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24380 NULL, &offset, 0, 0);
24381 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
24382 draw_quad(&test_context);
24383 check_texture_color(texture, buffer_data[0], 0);
24384 offset.x = 2;
24385 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24386 NULL, &offset, 0, 0);
24387 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
24388 draw_quad(&test_context);
24389 check_texture_color(texture, buffer_data[0], 0);
24390 offset.x = 3;
24391 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24392 NULL, &offset, 0, 0);
24393 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
24394 draw_quad(&test_context);
24395 check_texture_color(texture, buffer_data[0], 0);
24397 offset.x = 4;
24398 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24399 NULL, &offset, 0, 0);
24400 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
24401 draw_quad(&test_context);
24402 check_texture_color(texture, buffer_data[1], 0);
24403 offset.x = 7;
24404 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24405 NULL, &offset, 0, 0);
24406 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
24407 draw_quad(&test_context);
24408 check_texture_color(texture, buffer_data[1], 0);
24410 if (feature_level < D3D_FEATURE_LEVEL_11_0)
24412 skip("Feature level 11_0 required for unaligned UAV test.\n");
24413 goto done;
24416 ID3D11Buffer_Release(raw_buffer);
24417 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24418 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
24419 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24421 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
24422 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24423 U(uav_desc).Buffer.FirstElement = 0;
24424 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
24425 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
24426 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
24427 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24429 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
24430 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24432 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24433 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
24434 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24436 offset.x = 0;
24437 offset.y = 0xffffffff;
24438 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24439 NULL, &offset, 0, 0);
24440 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24441 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24442 get_buffer_readback(raw_buffer, &rb);
24443 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24445 data = get_readback_color(&rb, i, 0, 0);
24446 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24448 release_resource_readback(&rb);
24450 offset.x = 1;
24451 offset.y = 0xffffffff;
24452 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24453 NULL, &offset, 0, 0);
24454 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24455 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24456 get_buffer_readback(raw_buffer, &rb);
24457 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24459 data = get_readback_color(&rb, i, 0, 0);
24460 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24462 release_resource_readback(&rb);
24464 offset.x = 2;
24465 offset.y = 0xffffffff;
24466 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24467 NULL, &offset, 0, 0);
24468 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24469 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24470 get_buffer_readback(raw_buffer, &rb);
24471 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24473 data = get_readback_color(&rb, i, 0, 0);
24474 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24476 release_resource_readback(&rb);
24478 offset.x = 3;
24479 offset.y = 0xffffffff;
24480 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24481 NULL, &offset, 0, 0);
24482 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24483 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24484 get_buffer_readback(raw_buffer, &rb);
24485 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24487 data = get_readback_color(&rb, i, 0, 0);
24488 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24490 release_resource_readback(&rb);
24492 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24493 offset.x = 3;
24494 offset.y = 0xffff;
24495 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24496 NULL, &offset, 0, 0);
24497 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24498 offset.x = 4;
24499 offset.y = 0xa;
24500 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24501 NULL, &offset, 0, 0);
24502 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24503 get_buffer_readback(raw_buffer, &rb);
24504 data = get_readback_color(&rb, 0, 0, 0);
24505 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
24506 data = get_readback_color(&rb, 1, 0, 0);
24507 ok(data == 0xa, "Got unexpected result %#x.\n", data);
24508 release_resource_readback(&rb);
24510 ID3D11ComputeShader_Release(cs);
24511 ID3D11UnorderedAccessView_Release(uav);
24513 done:
24514 ID3D11Buffer_Release(cb);
24515 ID3D11Buffer_Release(raw_buffer);
24516 ID3D11PixelShader_Release(ps);
24517 ID3D11RenderTargetView_Release(rtv);
24518 ID3D11ShaderResourceView_Release(srv);
24519 ID3D11Texture2D_Release(texture);
24520 release_test_context(&test_context);
24523 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
24524 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
24526 D3D11_MAPPED_SUBRESOURCE map_desc;
24527 unsigned int counter;
24529 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
24531 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
24532 D3D11_MAP_READ, 0, &map_desc)))
24533 return 0xdeadbeef;
24534 counter = *(unsigned int *)map_desc.pData;
24535 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
24536 return counter;
24539 static int compare_id(const void *a, const void *b)
24541 return *(int *)a - *(int *)b;
24544 static void test_uav_counters(void)
24546 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
24547 ID3D11ComputeShader *cs_producer, *cs_consumer;
24548 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24549 struct d3d11_test_context test_context;
24550 ID3D11UnorderedAccessView *uav, *uav2;
24551 unsigned int data, id[128], i;
24552 D3D11_BUFFER_DESC buffer_desc;
24553 ID3D11DeviceContext *context;
24554 struct resource_readback rb;
24555 ID3D11Device *device;
24556 D3D11_BOX box;
24557 HRESULT hr;
24559 static const DWORD cs_producer_code[] =
24561 #if 0
24562 RWStructuredBuffer<uint> u;
24564 [numthreads(4, 1, 1)]
24565 void main(uint3 dispatch_id : SV_DispatchThreadID)
24567 uint counter = u.IncrementCounter();
24568 u[counter] = dispatch_id.x;
24570 #endif
24571 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
24572 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24573 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
24574 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
24575 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
24576 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
24577 0x0002000a, 0x0100003e,
24579 static const DWORD cs_consumer_code[] =
24581 #if 0
24582 RWStructuredBuffer<uint> u;
24583 RWStructuredBuffer<uint> u2;
24585 [numthreads(4, 1, 1)]
24586 void main()
24588 uint counter = u.DecrementCounter();
24589 u2[counter] = u[counter];
24591 #endif
24592 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
24593 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24594 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
24595 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
24596 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
24597 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
24598 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
24599 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
24601 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24603 if (!init_test_context(&test_context, &feature_level))
24604 return;
24606 device = test_context.device;
24607 context = test_context.immediate_context;
24609 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
24610 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24611 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
24612 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24614 memset(&buffer_desc, 0, sizeof(buffer_desc));
24615 buffer_desc.ByteWidth = sizeof(unsigned int);
24616 buffer_desc.Usage = D3D11_USAGE_STAGING;
24617 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
24618 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
24619 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24621 buffer_desc.ByteWidth = 1024;
24622 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24623 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24624 buffer_desc.CPUAccessFlags = 0;
24625 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24626 buffer_desc.StructureByteStride = sizeof(unsigned int);
24627 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24628 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24629 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
24630 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24631 U(uav_desc).Buffer.FirstElement = 0;
24632 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
24633 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
24634 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24635 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24636 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
24637 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24638 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
24639 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24641 data = read_uav_counter(context, staging_buffer, uav);
24642 ok(!data, "Got unexpected initial value %u.\n", data);
24643 data = 8;
24644 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24645 data = read_uav_counter(context, staging_buffer, uav);
24646 ok(data == 8, "Got unexpected value %u.\n", data);
24647 data = ~0u;
24648 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24649 data = read_uav_counter(context, staging_buffer, uav);
24650 ok(data == 8, "Got unexpected value %u.\n", data);
24651 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24652 data = read_uav_counter(context, staging_buffer, uav);
24653 ok(data == 8, "Got unexpected value %u.\n", data);
24655 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
24656 data = 0;
24657 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24658 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
24659 data = read_uav_counter(context, staging_buffer, uav);
24660 ok(!data, "Got unexpected value %u.\n", data);
24662 /* produce */
24663 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
24664 data = read_uav_counter(context, staging_buffer, uav);
24665 ok(data == 64, "Got unexpected value %u.\n", data);
24666 get_buffer_readback(buffer, &rb);
24667 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
24668 release_resource_readback(&rb);
24669 qsort(id, 64, sizeof(*id), compare_id);
24670 for (i = 0; i < 64; ++i)
24672 if (id[i] != i)
24673 break;
24675 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
24677 /* consume */
24678 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
24679 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
24680 data = read_uav_counter(context, staging_buffer, uav);
24681 ok(!data, "Got unexpected value %u.\n", data);
24682 get_buffer_readback(buffer2, &rb);
24683 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
24684 release_resource_readback(&rb);
24685 qsort(id, 64, sizeof(*id), compare_id);
24686 for (i = 0; i < 64; ++i)
24688 if (id[i] != i)
24689 break;
24691 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
24693 /* produce on CPU */
24694 for (i = 0; i < 8; ++i)
24695 id[i] = 0xdeadbeef;
24696 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
24697 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
24698 data = 8;
24699 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24700 data = read_uav_counter(context, staging_buffer, uav);
24701 ok(data == 8, "Got unexpected value %u.\n", data);
24703 /* consume */
24704 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24705 data = read_uav_counter(context, staging_buffer, uav);
24706 ok(data == 4, "Got unexpected value %u.\n", data);
24707 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24708 data = read_uav_counter(context, staging_buffer, uav);
24709 ok(!data, "Got unexpected value %u.\n", data);
24710 get_buffer_readback(buffer2, &rb);
24711 for (i = 0; i < 8; ++i)
24713 data = get_readback_color(&rb, i, 0, 0);
24714 ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
24716 release_resource_readback(&rb);
24718 ID3D11Buffer_Release(buffer);
24719 ID3D11Buffer_Release(buffer2);
24720 ID3D11Buffer_Release(staging_buffer);
24721 ID3D11ComputeShader_Release(cs_producer);
24722 ID3D11ComputeShader_Release(cs_consumer);
24723 ID3D11UnorderedAccessView_Release(uav);
24724 ID3D11UnorderedAccessView_Release(uav2);
24725 release_test_context(&test_context);
24728 static void test_dispatch_indirect(void)
24730 struct stats
24732 unsigned int dispatch_count;
24733 unsigned int thread_count;
24734 unsigned int max_x;
24735 unsigned int max_y;
24736 unsigned int max_z;
24739 ID3D11Buffer *append_buffer, *stats_buffer, *args_buffer, *staging_buffer;
24740 ID3D11UnorderedAccessView *uav, *stats_uav;
24741 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24742 ID3D11ComputeShader *cs_append, *cs_stats;
24743 struct d3d11_test_context test_context;
24744 D3D11_BUFFER_DESC buffer_desc;
24745 ID3D11DeviceContext *context;
24746 struct resource_readback rb;
24747 ID3D11Device *device;
24748 unsigned int data, i;
24749 struct stats *stats;
24750 HRESULT hr;
24752 static const DWORD cs_append_code[] =
24754 #if 0
24755 struct dispatch_args
24757 uint x, y, z;
24760 AppendStructuredBuffer<dispatch_args> u;
24762 [numthreads(1, 1, 1)]
24763 void main()
24765 dispatch_args args = {4, 2, 1};
24766 u.Append(args);
24767 args.y = 1;
24768 u.Append(args);
24769 args.x = 3;
24770 u.Append(args);
24772 #endif
24773 0x43425844, 0x954de75a, 0x8bb1b78b, 0x84ded464, 0x9d9532b7, 0x00000001, 0x00000158, 0x00000003,
24774 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24775 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000104, 0x00050050, 0x00000041, 0x0100086a,
24776 0x0400009e, 0x0011e000, 0x00000000, 0x0000000c, 0x02000068, 0x00000001, 0x0400009b, 0x00000001,
24777 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x0c0000a8,
24778 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002, 0x00000004,
24779 0x00000002, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000,
24780 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002,
24781 0x00000004, 0x00000001, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
24782 0x00000000, 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
24783 0x00004002, 0x00000003, 0x00000001, 0x00000001, 0x00000000, 0x0100003e,
24785 static const DWORD cs_stats_code[] =
24787 #if 0
24788 struct stats
24790 uint dispatch_count;
24791 uint thread_count;
24792 uint max_x;
24793 uint max_y;
24794 uint max_z;
24797 RWStructuredBuffer<stats> u;
24799 [numthreads(1, 1, 1)]
24800 void main(uint3 id : SV_DispatchThreadID)
24802 if (all(!id))
24803 InterlockedAdd(u[0].dispatch_count, 1);
24804 InterlockedAdd(u[0].thread_count, 1);
24805 InterlockedMax(u[0].max_x, id.x);
24806 InterlockedMax(u[0].max_y, id.y);
24807 InterlockedMax(u[0].max_z, id.z);
24809 #endif
24810 0x43425844, 0xbd3f2e4e, 0xb0f61ff7, 0xa8e10584, 0x2f61aec9, 0x00000001, 0x000001bc, 0x00000003,
24811 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24812 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000168, 0x00050050, 0x0000005a, 0x0100086a,
24813 0x0400009e, 0x0011e000, 0x00000000, 0x00000014, 0x0200005f, 0x00020072, 0x02000068, 0x00000001,
24814 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x09000020, 0x00100072, 0x00000000, 0x00020246,
24815 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000001, 0x00100012, 0x00000000,
24816 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00100012, 0x00000000, 0x0010002a,
24817 0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x0a0000ad, 0x0011e000,
24818 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001,
24819 0x01000015, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000,
24820 0x00000000, 0x00004001, 0x00000001, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002, 0x00000000,
24821 0x00000008, 0x00000000, 0x00000000, 0x0002000a, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002,
24822 0x00000000, 0x0000000c, 0x00000000, 0x00000000, 0x0002001a, 0x090000b0, 0x0011e000, 0x00000000,
24823 0x00004002, 0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x0002002a, 0x0100003e,
24825 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24826 static const unsigned int zero[4] = {0, 0, 0, 0};
24828 if (!init_test_context(&test_context, &feature_level))
24829 return;
24831 device = test_context.device;
24832 context = test_context.immediate_context;
24834 hr = ID3D11Device_CreateComputeShader(device, cs_append_code, sizeof(cs_append_code), NULL, &cs_append);
24835 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24836 hr = ID3D11Device_CreateComputeShader(device, cs_stats_code, sizeof(cs_stats_code), NULL, &cs_stats);
24837 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24839 memset(&buffer_desc, 0, sizeof(buffer_desc));
24840 buffer_desc.ByteWidth = sizeof(unsigned int);
24841 buffer_desc.Usage = D3D11_USAGE_STAGING;
24842 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
24843 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
24844 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24846 buffer_desc.ByteWidth = 60;
24847 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24848 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24849 buffer_desc.CPUAccessFlags = 0;
24850 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24851 buffer_desc.StructureByteStride = 3 * sizeof(unsigned int);
24852 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &append_buffer);
24853 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24854 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
24855 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24856 U(uav_desc).Buffer.FirstElement = 0;
24857 U(uav_desc).Buffer.NumElements = 5;
24858 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
24859 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)append_buffer, &uav_desc, &uav);
24860 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24862 /* We use a separate buffer because D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
24863 * and D3D11_RESOURCE_MISC_BUFFER_STRUCTURED are mutually exclusive flags.
24865 buffer_desc.BindFlags = 0;
24866 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
24867 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &args_buffer);
24868 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24870 buffer_desc.ByteWidth = sizeof(*stats);
24871 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24872 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24873 buffer_desc.StructureByteStride = sizeof(*stats);
24874 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &stats_buffer);
24875 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24876 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)stats_buffer, NULL, &stats_uav);
24877 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24879 data = read_uav_counter(context, staging_buffer, uav);
24880 ok(!data, "Got unexpected initial value %u.\n", data);
24881 data = 8;
24882 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24883 data = read_uav_counter(context, staging_buffer, uav);
24884 ok(data == 8, "Got unexpected value %u.\n", data);
24886 ID3D11DeviceContext_CSSetShader(context, cs_append, NULL, 0);
24887 data = 0;
24888 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24889 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24890 data = read_uav_counter(context, staging_buffer, uav);
24891 ok(data == 3, "Got unexpected value %u.\n", data);
24892 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)args_buffer, (ID3D11Resource *)append_buffer);
24894 ID3D11DeviceContext_CSSetShader(context, cs_stats, NULL, 0);
24895 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, stats_uav, zero);
24896 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &stats_uav, NULL);
24897 data = read_uav_counter(context, staging_buffer, uav);
24898 for (i = 0; i < data; ++i)
24899 ID3D11DeviceContext_DispatchIndirect(context, args_buffer, i * 3 * sizeof(unsigned int));
24900 get_buffer_readback(stats_buffer, &rb);
24901 stats = rb.map_desc.pData;
24902 ok(stats->dispatch_count == 3, "Got unexpected dispatch count %u.\n", stats->dispatch_count);
24903 ok(stats->thread_count == 15, "Got unexpected thread count %u.\n", stats->thread_count);
24904 ok(stats->max_x == 3, "Got unexpected max x %u.\n", stats->max_x);
24905 ok(stats->max_y == 1, "Got unexpected max y %u.\n", stats->max_y);
24906 ok(stats->max_z == 0, "Got unexpected max z %u.\n", stats->max_z);
24907 release_resource_readback(&rb);
24909 ID3D11Buffer_Release(append_buffer);
24910 ID3D11Buffer_Release(args_buffer);
24911 ID3D11Buffer_Release(staging_buffer);
24912 ID3D11Buffer_Release(stats_buffer);
24913 ID3D11ComputeShader_Release(cs_append);
24914 ID3D11ComputeShader_Release(cs_stats);
24915 ID3D11UnorderedAccessView_Release(uav);
24916 ID3D11UnorderedAccessView_Release(stats_uav);
24917 release_test_context(&test_context);
24920 static void test_compute_shader_registers(void)
24922 struct data
24924 unsigned int group_id[3];
24925 unsigned int group_index;
24926 unsigned int dispatch_id[3];
24927 unsigned int thread_id[3];
24930 struct d3d11_test_context test_context;
24931 unsigned int i, x, y, group_x, group_y;
24932 ID3D11UnorderedAccessView *uav;
24933 D3D11_BUFFER_DESC buffer_desc;
24934 ID3D11DeviceContext *context;
24935 struct resource_readback rb;
24936 ID3D11Buffer *cb, *buffer;
24937 struct uvec4 dimensions;
24938 ID3D11ComputeShader *cs;
24939 const struct data *data;
24940 ID3D11Device *device;
24941 HRESULT hr;
24943 static const DWORD cs_code[] =
24945 #if 0
24946 struct data
24948 uint3 group_id;
24949 uint group_index;
24950 uint3 dispatch_id;
24951 uint3 group_thread_id;
24954 RWStructuredBuffer<data> u;
24956 uint2 dim;
24958 [numthreads(3, 2, 1)]
24959 void main(uint3 group_id : SV_GroupID,
24960 uint group_index : SV_GroupIndex,
24961 uint3 dispatch_id : SV_DispatchThreadID,
24962 uint3 group_thread_id : SV_GroupThreadID)
24964 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
24965 u[i].group_id = group_id;
24966 u[i].group_index = group_index;
24967 u[i].dispatch_id = dispatch_id;
24968 u[i].group_thread_id = group_thread_id;
24970 #endif
24971 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
24972 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24973 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
24974 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
24975 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
24976 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
24977 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
24978 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
24979 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
24980 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
24981 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
24982 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
24983 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
24984 0x0100003e,
24986 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24988 if (!init_test_context(&test_context, &feature_level))
24989 return;
24991 device = test_context.device;
24992 context = test_context.immediate_context;
24994 buffer_desc.ByteWidth = 10240;
24995 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24996 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24997 buffer_desc.CPUAccessFlags = 0;
24998 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24999 buffer_desc.StructureByteStride = 40;
25000 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
25001 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
25002 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
25003 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
25004 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
25006 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
25008 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
25009 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
25011 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
25012 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
25013 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
25015 dimensions.x = 2;
25016 dimensions.y = 3;
25017 dimensions.z = 1;
25018 dimensions.w = 0;
25019 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
25020 NULL, &dimensions, 0, 0);
25021 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
25023 get_buffer_readback(buffer, &rb);
25024 i = 0;
25025 data = rb.map_desc.pData;
25026 for (y = 0; y < dimensions.y; ++y)
25028 for (group_y = 0; group_y < 2; ++group_y)
25030 for (x = 0; x < dimensions.x; ++x)
25032 for (group_x = 0; group_x < 3; ++group_x)
25034 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
25035 const unsigned int group_index = group_y * 3 + group_x;
25036 const struct data *d = &data[i];
25038 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
25039 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
25040 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
25041 i, x, y, group_x, group_y);
25042 ok(d->group_index == group_index,
25043 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
25044 d->group_index, group_index, i, x, y, group_x, group_y);
25045 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
25046 && !d->dispatch_id[2],
25047 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
25048 "at %u (%u, %u, %u, %u).\n",
25049 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
25050 dispatch_id[0], dispatch_id[1], 0,
25051 i, x, y, group_x, group_y);
25052 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
25053 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
25054 "at %u (%u, %u, %u, %u).\n",
25055 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
25056 i, x, y, group_x, group_y);
25057 ++i;
25062 release_resource_readback(&rb);
25064 ID3D11Buffer_Release(cb);
25065 ID3D11Buffer_Release(buffer);
25066 ID3D11ComputeShader_Release(cs);
25067 ID3D11UnorderedAccessView_Release(uav);
25068 release_test_context(&test_context);
25071 static void test_tgsm(void)
25073 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
25074 struct d3d11_test_context test_context;
25075 ID3D11UnorderedAccessView *uav, *uav2;
25076 struct resource_readback rb, rb2;
25077 unsigned int i, data, expected;
25078 ID3D11Buffer *buffer, *buffer2;
25079 D3D11_BUFFER_DESC buffer_desc;
25080 ID3D11DeviceContext *context;
25081 ID3D11ComputeShader *cs;
25082 ID3D11Device *device;
25083 float float_data;
25084 HRESULT hr;
25086 static const DWORD raw_tgsm_code[] =
25088 #if 0
25089 RWByteAddressBuffer u;
25090 groupshared uint m;
25092 [numthreads(32, 1, 1)]
25093 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
25095 if (!local_idx)
25096 m = group_id.x;
25097 GroupMemoryBarrierWithGroupSync();
25098 InterlockedAdd(m, group_id.x);
25099 GroupMemoryBarrierWithGroupSync();
25100 if (!local_idx)
25101 u.Store(4 * group_id.x, m);
25103 #endif
25104 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
25105 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
25106 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
25107 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
25108 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
25109 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
25110 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
25111 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
25112 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
25113 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
25114 0x01000015, 0x0100003e,
25116 static const DWORD structured_tgsm_code[] =
25118 #if 0
25119 #define GROUP_SIZE 32
25121 RWByteAddressBuffer u;
25122 RWByteAddressBuffer u2;
25123 groupshared uint m[GROUP_SIZE];
25125 [numthreads(GROUP_SIZE, 1, 1)]
25126 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
25128 uint sum, original, i;
25130 if (!local_idx)
25132 for (i = 0; i < GROUP_SIZE; ++i)
25133 m[i] = 2 * group_id.x;
25135 GroupMemoryBarrierWithGroupSync();
25136 InterlockedAdd(m[local_idx], 1);
25137 GroupMemoryBarrierWithGroupSync();
25138 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
25139 u.InterlockedExchange(4 * group_id.x, sum, original);
25140 u2.Store(4 * group_id.x, original);
25142 #endif
25143 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
25144 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
25145 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
25146 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
25147 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
25148 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
25149 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
25150 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
25151 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
25152 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
25153 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
25154 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
25155 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
25156 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
25157 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
25158 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
25159 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
25160 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
25161 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
25162 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
25163 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
25164 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
25166 static const DWORD structured_tgsm_float_code[] =
25168 #if 0
25169 #define GROUP_SIZE 32
25171 struct data
25173 float f;
25174 uint u;
25177 RWBuffer<float> u;
25178 RWBuffer<uint> u2;
25179 groupshared data m[GROUP_SIZE];
25181 [numthreads(GROUP_SIZE, 1, 1)]
25182 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
25183 uint thread_id : SV_DispatchThreadID)
25185 uint i;
25186 if (!local_idx)
25188 for (i = 0; i < GROUP_SIZE; ++i)
25190 m[i].f = group_id.x;
25191 m[i].u = group_id.x;
25194 GroupMemoryBarrierWithGroupSync();
25195 for (i = 0; i < local_idx; ++i)
25197 m[local_idx].f += group_id.x;
25198 m[local_idx].u += group_id.x;
25200 u[thread_id.x] = m[local_idx].f;
25201 u2[thread_id.x] = m[local_idx].u;
25203 #endif
25204 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
25205 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
25206 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
25207 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
25208 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
25209 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
25210 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
25211 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
25212 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
25213 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
25214 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
25215 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
25216 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
25217 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
25218 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
25219 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
25220 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
25221 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
25222 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
25223 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
25224 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
25225 0x00100556, 0x00000000, 0x0100003e,
25227 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25228 static const unsigned int zero[4] = {0};
25230 if (!init_test_context(&test_context, &feature_level))
25231 return;
25233 device = test_context.device;
25234 context = test_context.immediate_context;
25236 buffer_desc.ByteWidth = 1024;
25237 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
25238 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
25239 buffer_desc.CPUAccessFlags = 0;
25240 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
25241 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
25242 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
25244 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
25245 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
25246 U(uav_desc).Buffer.FirstElement = 0;
25247 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
25248 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
25249 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
25250 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
25252 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
25253 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
25255 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
25256 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
25258 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
25259 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
25260 get_buffer_readback(buffer, &rb);
25261 for (i = 0; i < 64; ++i)
25263 data = get_readback_color(&rb, i, 0, 0);
25264 expected = 33 * i;
25265 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
25267 release_resource_readback(&rb);
25269 ID3D11Buffer_Release(buffer);
25270 ID3D11ComputeShader_Release(cs);
25271 ID3D11UnorderedAccessView_Release(uav);
25273 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
25274 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
25275 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
25276 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
25277 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
25278 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
25279 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
25280 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
25281 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
25282 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
25284 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
25285 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
25286 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
25288 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
25289 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
25290 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
25291 get_buffer_readback(buffer, &rb);
25292 get_buffer_readback(buffer2, &rb2);
25293 for (i = 0; i < 32; ++i)
25295 expected = 64 * i + 32;
25296 data = get_readback_color(&rb, i, 0, 0);
25297 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
25298 data = get_readback_color(&rb2, i, 0, 0);
25299 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
25301 release_resource_readback(&rb);
25302 release_resource_readback(&rb2);
25304 ID3D11Buffer_Release(buffer);
25305 ID3D11Buffer_Release(buffer2);
25306 ID3D11ComputeShader_Release(cs);
25307 ID3D11UnorderedAccessView_Release(uav);
25308 ID3D11UnorderedAccessView_Release(uav2);
25310 buffer_desc.MiscFlags = 0;
25311 U(uav_desc).Buffer.Flags = 0;
25312 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
25313 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
25314 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
25315 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
25316 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
25317 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
25318 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
25319 uav_desc.Format = DXGI_FORMAT_R32_UINT;
25320 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
25321 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
25322 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
25323 sizeof(structured_tgsm_float_code), NULL, &cs);
25324 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
25326 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
25327 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
25328 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
25330 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
25331 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
25332 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
25333 get_buffer_readback(buffer, &rb);
25334 get_buffer_readback(buffer2, &rb2);
25335 for (i = 0; i < 96; ++i)
25337 expected = (i % 32 + 1) * (i / 32);
25338 float_data = get_readback_float(&rb, i, 0);
25339 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
25340 data = get_readback_color(&rb2, i, 0, 0);
25341 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
25343 release_resource_readback(&rb);
25344 release_resource_readback(&rb2);
25346 ID3D11Buffer_Release(buffer);
25347 ID3D11Buffer_Release(buffer2);
25348 ID3D11ComputeShader_Release(cs);
25349 ID3D11UnorderedAccessView_Release(uav);
25350 ID3D11UnorderedAccessView_Release(uav2);
25351 release_test_context(&test_context);
25354 static void test_geometry_shader(void)
25356 static const struct
25358 struct vec4 position;
25359 unsigned int color;
25361 vertex[] =
25363 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
25365 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
25367 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
25368 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
25370 #if 0
25371 struct vs_data
25373 float4 pos : SV_POSITION;
25374 float4 color : COLOR;
25377 void main(in struct vs_data vs_input, out struct vs_data vs_output)
25379 vs_output.pos = vs_input.pos;
25380 vs_output.color = vs_input.color;
25382 #endif
25383 static const DWORD vs_code[] =
25385 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
25386 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25387 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
25388 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25389 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
25390 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
25391 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
25392 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
25393 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
25394 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
25395 0x0100003e,
25397 #if 0
25398 struct gs_data
25400 float4 pos : SV_POSITION;
25401 float4 color : COLOR;
25404 [maxvertexcount(4)]
25405 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
25407 float offset = 0.2 * vin[0].pos.w;
25408 gs_data v;
25410 v.color = vin[0].color;
25412 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
25413 vout.Append(v);
25414 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
25415 vout.Append(v);
25416 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
25417 vout.Append(v);
25418 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
25419 vout.Append(v);
25421 #endif
25422 static const DWORD gs_code[] =
25424 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
25425 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25426 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
25427 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25428 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
25429 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
25430 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
25431 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
25432 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
25433 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
25434 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
25435 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
25436 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
25437 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
25438 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
25439 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
25440 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
25441 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
25442 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
25443 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
25444 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
25445 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
25446 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25447 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
25448 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
25449 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
25450 0x00000001, 0x01000013, 0x0100003e,
25452 static const DWORD gs_5_0_code[] =
25454 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
25455 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25456 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
25457 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25458 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
25459 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
25460 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
25461 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
25462 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
25463 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25464 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
25465 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
25466 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
25467 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
25468 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25469 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
25470 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
25471 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
25472 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
25473 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
25474 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
25475 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
25476 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
25477 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
25478 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
25479 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
25480 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
25481 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
25482 0x0100003e,
25484 #if 0
25485 struct ps_data
25487 float4 pos : SV_POSITION;
25488 float4 color : COLOR;
25491 float4 main(struct ps_data ps_input) : SV_Target
25493 return ps_input.color;
25495 #endif
25496 static const DWORD ps_code[] =
25498 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
25499 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25500 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
25501 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25502 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
25503 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
25504 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
25505 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
25507 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
25508 struct d3d11_test_context test_context;
25509 ID3D11InputLayout *input_layout;
25510 ID3D11DeviceContext *context;
25511 unsigned int stride, offset;
25512 struct resource_readback rb;
25513 ID3D11GeometryShader *gs;
25514 ID3D11VertexShader *vs;
25515 ID3D11PixelShader *ps;
25516 ID3D11Device *device;
25517 ID3D11Buffer *vb;
25518 DWORD color;
25519 HRESULT hr;
25521 if (!init_test_context(&test_context, NULL))
25522 return;
25524 device = test_context.device;
25525 context = test_context.immediate_context;
25527 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
25528 vs_code, sizeof(vs_code), &input_layout);
25529 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
25531 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
25533 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
25534 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
25535 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
25536 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
25537 else
25538 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
25539 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
25540 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
25541 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25543 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
25544 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
25545 stride = sizeof(*vertex);
25546 offset = 0;
25547 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
25548 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
25549 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
25550 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25552 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
25553 ID3D11DeviceContext_Draw(context, 1, 0);
25555 get_texture_readback(test_context.backbuffer, 0, &rb);
25556 color = get_readback_color(&rb, 320, 190, 0);
25557 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25558 color = get_readback_color(&rb, 255, 240, 0);
25559 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25560 color = get_readback_color(&rb, 320, 240, 0);
25561 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
25562 color = get_readback_color(&rb, 385, 240, 0);
25563 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25564 color = get_readback_color(&rb, 320, 290, 0);
25565 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25566 release_resource_readback(&rb);
25568 ID3D11PixelShader_Release(ps);
25569 ID3D11GeometryShader_Release(gs);
25570 ID3D11VertexShader_Release(vs);
25571 ID3D11Buffer_Release(vb);
25572 ID3D11InputLayout_Release(input_layout);
25573 release_test_context(&test_context);
25576 struct triangle
25578 struct vec4 v[3];
25581 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
25582 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
25583 const struct triangle *triangles, unsigned int triangle_count)
25585 const struct triangle *current, *expected;
25586 struct resource_readback rb;
25587 unsigned int i, j, offset;
25588 BOOL all_match = TRUE;
25590 get_buffer_readback(buffer, &rb);
25592 for (i = 0; i < triangle_count; ++i)
25594 current = get_readback_data(&rb, i, 0, 0, sizeof(*current));
25595 expected = &triangles[i];
25597 offset = ~0u;
25598 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
25600 if (compare_vec4(&current->v[0], &expected->v[j], 0))
25602 offset = j;
25603 break;
25607 if (offset == ~0u)
25609 all_match = FALSE;
25610 break;
25613 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
25615 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
25617 all_match = FALSE;
25618 break;
25621 if (!all_match)
25622 break;
25625 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
25626 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
25627 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
25628 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
25629 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
25630 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
25631 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
25632 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
25633 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
25634 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
25636 release_resource_readback(&rb);
25639 static void test_quad_tessellation(void)
25641 #if 0
25642 struct point_data
25644 float4 position : SV_POSITION;
25647 struct patch_constant_data
25649 float edges[4] : SV_TessFactor;
25650 float inside[2] : SV_InsideTessFactor;
25653 float4 tess_factors;
25654 float2 inside_tess_factors;
25656 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
25658 patch_constant_data output;
25660 output.edges[0] = tess_factors.x;
25661 output.edges[1] = tess_factors.y;
25662 output.edges[2] = tess_factors.z;
25663 output.edges[3] = tess_factors.w;
25664 output.inside[0] = inside_tess_factors.x;
25665 output.inside[1] = inside_tess_factors.y;
25667 return output;
25670 [domain("quad")]
25671 [outputcontrolpoints(4)]
25672 [outputtopology("triangle_ccw")]
25673 [partitioning("integer")]
25674 [patchconstantfunc("patch_constant")]
25675 point_data hs_main(InputPatch<point_data, 4> input,
25676 uint i : SV_OutputControlPointID)
25678 return input[i];
25681 [domain("quad")]
25682 point_data ds_main(patch_constant_data input,
25683 float2 tess_coord : SV_DomainLocation,
25684 const OutputPatch<point_data, 4> patch)
25686 point_data output;
25688 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
25689 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
25690 output.position = lerp(a, b, tess_coord.y);
25692 return output;
25694 #endif
25695 static const DWORD hs_quad_ccw_code[] =
25697 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
25698 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25699 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25700 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
25701 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
25702 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
25703 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
25704 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
25705 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
25706 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
25707 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
25708 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
25709 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
25710 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
25711 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
25712 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25713 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
25714 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
25715 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25716 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
25717 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
25718 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
25720 static const DWORD ds_quad_code[] =
25722 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
25723 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25724 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25725 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
25726 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
25727 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
25728 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
25729 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
25730 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
25731 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
25732 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
25733 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
25734 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25735 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
25736 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
25737 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
25738 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
25739 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
25740 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
25741 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
25742 0x0100003e,
25744 #if 0
25746 [outputtopology("triangle_cw")]
25748 #endif
25749 static const DWORD hs_quad_cw_code[] =
25751 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
25752 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25753 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25754 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
25755 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
25756 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
25757 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
25758 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
25759 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
25760 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
25761 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
25762 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
25763 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
25764 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
25765 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
25766 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25767 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
25768 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
25769 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25770 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
25771 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
25772 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
25774 #if 0
25775 struct point_data
25777 float4 pos : SV_POSITION;
25780 [maxvertexcount(3)]
25781 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
25783 for (uint i = 0; i < 3; ++i)
25784 vout.Append(vin[i]);
25786 #endif
25787 static const DWORD gs_code[] =
25789 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
25790 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
25791 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
25792 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
25793 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
25794 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
25795 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
25796 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
25797 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
25798 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
25799 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
25800 0x0100003e,
25802 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
25804 {0, "SV_POSITION", 0, 0, 4, 0},
25806 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25807 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
25808 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
25809 static const BYTE zero_data[1024];
25810 static const struct triangle expected_quad_ccw[] =
25812 {{{-1.0f, -1.0f, 0.0f, 1.0f},
25813 { 1.0f, -1.0f, 0.0f, 1.0f},
25814 {-1.0f, 1.0f, 0.0f, 1.0f}}},
25815 {{{-1.0f, 1.0f, 0.0f, 1.0f},
25816 { 1.0f, -1.0f, 0.0f, 1.0f},
25817 { 1.0f, 1.0f, 0.0f, 1.0f}}},
25818 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
25819 { 0.0f, 0.0f, 0.0f, 0.0f},
25820 { 0.0f, 0.0f, 0.0f, 0.0f}}},
25822 static const struct triangle expected_quad_cw[] =
25824 {{{-1.0f, -1.0f, 0.0f, 1.0f},
25825 {-1.0f, 1.0f, 0.0f, 1.0f},
25826 { 1.0f, -1.0f, 0.0f, 1.0f}}},
25827 {{{-1.0f, 1.0f, 0.0f, 1.0f},
25828 { 1.0f, 1.0f, 0.0f, 1.0f},
25829 { 1.0f, -1.0f, 0.0f, 1.0f}}},
25830 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
25831 { 0.0f, 0.0f, 0.0f, 0.0f},
25832 { 0.0f, 0.0f, 0.0f, 0.0f}}},
25834 struct
25836 float tess_factors[4];
25837 float inside_tess_factors[2];
25838 DWORD padding[2];
25839 } constant;
25841 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
25842 struct d3d11_test_context test_context;
25843 ID3D11DeviceContext *context;
25844 ID3D11Buffer *cb, *so_buffer;
25845 D3D11_QUERY_DESC query_desc;
25846 ID3D11Asynchronous *query;
25847 ID3D11GeometryShader *gs;
25848 ID3D11DomainShader *ds;
25849 const UINT offset = 0;
25850 ID3D11HullShader *hs;
25851 ID3D11Device *device;
25852 unsigned int i;
25853 HRESULT hr;
25855 if (!init_test_context(&test_context, &feature_level))
25856 return;
25858 device = test_context.device;
25859 context = test_context.immediate_context;
25861 draw_color_quad(&test_context, &white);
25862 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25864 set_quad_color(&test_context, &green);
25865 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
25867 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
25868 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
25869 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
25870 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
25871 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
25873 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
25874 constant.tess_factors[i] = 1.0f;
25875 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
25876 constant.inside_tess_factors[i] = 1.0f;
25877 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
25878 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
25879 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
25880 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
25881 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
25882 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
25883 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
25884 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
25886 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25887 ID3D11DeviceContext_Draw(context, 4, 0);
25888 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25889 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
25890 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
25892 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
25894 ID3D11HullShader_Release(hs);
25895 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
25896 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
25897 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
25899 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25900 ID3D11DeviceContext_Draw(context, 4, 0);
25901 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
25902 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
25903 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
25905 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
25907 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25908 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
25909 query_desc.MiscFlags = 0;
25910 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
25911 ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
25912 ID3D11DeviceContext_Begin(context, query);
25914 set_quad_color(&test_context, &white);
25915 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
25916 constant.tess_factors[i] = 2.0f;
25917 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25918 ID3D11DeviceContext_Draw(context, 4, 0);
25919 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25921 set_quad_color(&test_context, &green);
25922 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
25923 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25924 ID3D11DeviceContext_Draw(context, 4, 0);
25925 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25927 ID3D11DeviceContext_End(context, query);
25928 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
25929 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
25930 (unsigned int)so_statistics.NumPrimitivesWritten);
25931 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
25932 (unsigned int)so_statistics.PrimitivesStorageNeeded);
25933 ID3D11DeviceContext_Begin(context, query);
25935 constant.tess_factors[0] = 5.0f;
25936 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25937 ID3D11DeviceContext_Draw(context, 4, 0);
25938 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
25940 ID3D11DeviceContext_End(context, query);
25941 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
25942 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
25943 (unsigned int)so_statistics.NumPrimitivesWritten);
25944 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
25945 (unsigned int)so_statistics.PrimitivesStorageNeeded);
25946 ID3D11Asynchronous_Release(query);
25948 ID3D11Buffer_Release(so_buffer);
25949 ID3D11GeometryShader_Release(gs);
25950 ID3D11DomainShader_Release(ds);
25951 ID3D11HullShader_Release(hs);
25952 ID3D11Buffer_Release(cb);
25953 release_test_context(&test_context);
25956 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
25957 static void check_so_desc_(unsigned int line, ID3D11Device *device,
25958 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
25959 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
25960 unsigned int rasterizer_stream)
25962 ID3D11GeometryShader *gs;
25963 HRESULT hr;
25965 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
25966 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
25967 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
25968 if (SUCCEEDED(hr))
25969 ID3D11GeometryShader_Release(gs);
25972 #define check_invalid_so_desc(a, b, c, d, e, f, g, h) check_invalid_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
25973 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
25974 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
25975 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
25976 unsigned int rasterizer_stream)
25978 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
25979 HRESULT hr;
25981 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
25982 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
25983 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
25984 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
25985 if (SUCCEEDED(hr))
25986 ID3D11GeometryShader_Release(gs);
25989 static void test_stream_output(void)
25991 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
25992 struct d3d11_test_context test_context;
25993 unsigned int i, count;
25994 ID3D11Device *device;
25996 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25997 static const DWORD vs_code[] =
25999 #if 0
26000 struct data
26002 float4 position : SV_Position;
26003 float4 attrib1 : ATTRIB1;
26004 float3 attrib2 : attrib2;
26005 float2 attrib3 : ATTriB3;
26006 float attrib4 : ATTRIB4;
26009 void main(in data i, out data o)
26011 o = i;
26013 #endif
26014 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
26015 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
26016 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
26017 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26018 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
26019 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
26020 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
26021 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26022 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
26023 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
26024 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
26025 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
26026 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
26027 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
26028 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
26029 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
26030 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
26031 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
26032 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
26033 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
26035 static const DWORD gs_code[] =
26037 #if 0
26038 struct data
26040 float4 position : SV_Position;
26041 float4 attrib1 : ATTRIB1;
26042 float3 attrib2 : attrib2;
26043 float2 attrib3 : ATTriB3;
26044 float attrib4 : ATTRIB4;
26047 [maxvertexcount(1)]
26048 void main(point data i[1], inout PointStream<data> o)
26050 o.Append(i[0]);
26052 #endif
26053 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
26054 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
26055 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
26056 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26057 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
26058 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
26059 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
26060 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26061 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
26062 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
26063 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
26064 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
26065 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
26066 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
26067 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
26068 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
26069 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
26070 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
26071 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
26072 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
26073 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
26075 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26077 {0, "SV_Position", 0, 0, 4, 0},
26079 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
26081 {0, "SV_Position", 0, 0, 4, 0},
26082 {0, NULL, 0, 0, 0, 0},
26084 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
26086 /* SemanticName and SemanticIndex */
26088 {0, "sv_position", 0, 0, 4, 0},
26089 {0, "attrib", 1, 0, 4, 0},
26092 {0, "sv_position", 0, 0, 4, 0},
26093 {0, "ATTRIB", 1, 0, 4, 0},
26095 /* Gaps */
26097 {0, "SV_POSITION", 0, 0, 4, 0},
26098 {0, NULL, 0, 0, 8, 0},
26099 {0, "ATTRIB", 1, 0, 4, 0},
26102 {0, "SV_POSITION", 0, 0, 4, 0},
26103 {0, NULL, 0, 0, 4, 0},
26104 {0, NULL, 0, 0, 4, 0},
26105 {0, "ATTRIB", 1, 0, 4, 0},
26107 /* ComponentCount */
26109 {0, "ATTRIB", 1, 0, 4, 0},
26112 {0, "ATTRIB", 2, 0, 3, 0},
26115 {0, "ATTRIB", 3, 0, 2, 0},
26118 {0, "ATTRIB", 4, 0, 1, 0},
26120 /* ComponentIndex */
26122 {0, "ATTRIB", 1, 1, 3, 0},
26125 {0, "ATTRIB", 1, 2, 2, 0},
26128 {0, "ATTRIB", 1, 3, 1, 0},
26131 {0, "ATTRIB", 3, 1, 1, 0},
26133 /* OutputSlot */
26135 {0, "attrib", 1, 0, 4, 0},
26138 {0, "attrib", 1, 0, 4, 1},
26141 {0, "attrib", 1, 0, 4, 2},
26144 {0, "attrib", 1, 0, 4, 3},
26147 {0, "attrib", 1, 0, 4, 0},
26148 {0, "attrib", 2, 0, 3, 1},
26149 {0, NULL, 0, 0, 1, 1},
26150 {0, "attrib", 3, 0, 2, 2},
26151 {0, NULL, 0, 0, 2, 2},
26152 {0, "attrib", 4, 0, 1, 3},
26153 {0, NULL, 0, 0, 7, 3},
26156 {0, "attrib", 1, 0, 4, 0},
26157 {0, "attrib", 2, 0, 3, 1},
26158 {0, NULL, 0, 0, 1, 1},
26159 {0, "attrib", 3, 0, 2, 2},
26160 {0, NULL, 0, 0, 1, 2},
26161 {0, NULL, 0, 0, 1, 2},
26162 {0, "attrib", 4, 0, 1, 3},
26163 {0, NULL, 0, 0, 3, 3},
26164 {0, NULL, 0, 0, 1, 3},
26165 {0, NULL, 0, 0, 1, 3},
26166 {0, NULL, 0, 0, 1, 3},
26167 {0, NULL, 0, 0, 1, 3},
26170 {0, "attrib", 1, 0, 4, 0},
26171 {0, "attrib", 2, 0, 3, 0},
26172 {0, "attrib", 3, 0, 2, 0},
26173 {0, NULL, 0, 0, 1, 0},
26174 {0, "attrib", 4, 0, 1, 0},
26177 {0, "attrib", 1, 0, 4, 0},
26178 {0, "attrib", 2, 0, 3, 0},
26179 {0, "attrib", 3, 0, 2, 3},
26180 {0, NULL, 0, 0, 1, 3},
26181 {0, "attrib", 4, 0, 1, 3},
26183 /* Multiple occurrences of the same output */
26185 {0, "ATTRIB", 1, 0, 2, 0},
26186 {0, "ATTRIB", 1, 2, 2, 1},
26189 {0, "ATTRIB", 1, 0, 1, 0},
26190 {0, "ATTRIB", 1, 1, 3, 0},
26193 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
26195 /* SemanticName and SemanticIndex */
26197 {0, "SV_Position", 0, 0, 4, 0},
26198 {0, "ATTRIB", 0, 0, 4, 0},
26201 {0, "sv_position", 0, 0, 4, 0},
26202 {0, "ATTRIB_", 1, 0, 4, 0},
26204 /* Gaps */
26206 {0, "SV_POSITION", 0, 0, 4, 0},
26207 {0, NULL, 0, 1, 8, 0},
26208 {0, "ATTRIB", 1, 0, 4, 0},
26211 {0, "SV_POSITION", 0, 0, 4, 0},
26212 {0, NULL, 1, 0, 8, 0},
26213 {0, "ATTRIB", 1, 0, 4, 0},
26215 /* Buffer stride */
26217 {0, "SV_POSITION", 0, 0, 4, 0},
26218 {0, NULL, 0, 0, 8, 0},
26219 {0, NULL, 0, 0, 8, 0},
26220 {0, "ATTRIB", 1, 0, 4, 0},
26222 /* ComponentCount */
26224 {0, "ATTRIB", 2, 0, 5, 0},
26227 {0, "ATTRIB", 2, 0, 4, 0},
26230 {0, "ATTRIB", 3, 0, 3, 0},
26233 {0, "ATTRIB", 4, 0, 2, 0},
26235 /* ComponentIndex */
26237 {0, "ATTRIB", 1, 1, 4, 0},
26240 {0, "ATTRIB", 1, 2, 3, 0},
26243 {0, "ATTRIB", 1, 3, 2, 0},
26246 {0, "ATTRIB", 1, 4, 0, 0},
26249 {0, "ATTRIB", 1, 4, 1, 0},
26252 {0, "ATTRIB", 3, 2, 1, 0},
26255 {0, "ATTRIB", 3, 2, 0, 0},
26257 /* OutputSlot */
26259 {0, "attrib", 1, 0, 4, 4},
26262 {0, "attrib", 1, 0, 4, 4},
26265 {0, "attrib", 1, 0, 4, 4},
26268 {0, "attrib", 1, 0, 4, 4},
26271 {0, "attrib", 1, 0, 4, 0},
26272 {0, "attrib", 2, 0, 3, 1},
26273 {0, NULL, 0, 0, 1, 1},
26274 {0, "attrib", 3, 0, 2, 2},
26275 {0, NULL, 0, 0, 2, 2},
26276 {0, "attrib", 4, 0, 1, 3},
26277 {0, NULL, 0, 0, 3, 4},
26280 {0, "attrib", 1, 0, 4, 0},
26281 {0, "attrib", 2, 0, 3, 0},
26282 {0, "attrib", 3, 0, 2, 0},
26283 {0, NULL, 0, 0, 1, 0},
26284 {0, "attrib", 4, 0, 1, 0},
26285 {0, NULL, 0, 0, 3, 3},
26286 {0, NULL, 0, 0, 1, 3},
26287 {0, NULL, 0, 0, 1, 3},
26288 {0, NULL, 0, 0, 1, 3},
26289 {0, NULL, 0, 0, 1, 3},
26292 {0, "attrib", 1, 0, 4, 0},
26293 {0, NULL, 0, 0, 3, 1},
26294 {0, NULL, 0, 0, 1, 1},
26295 {0, NULL, 0, 0, 1, 2},
26296 {0, "attrib", 2, 0, 3, 3},
26297 {0, NULL, 0, 0, 1, 3},
26300 {0, "attrib", 2, 0, 3, 3},
26301 {0, NULL, 0, 0, 3, 1},
26302 {0, NULL, 0, 0, 1, 3},
26303 {0, "attrib", 1, 0, 4, 0},
26304 {0, NULL, 0, 0, 1, 2},
26305 {0, NULL, 0, 0, 1, 1},
26307 /* Stream */
26309 {1, "attrib", 1, 0, 4, 0},
26312 {4, "attrib", 1, 0, 4, 0},
26314 /* Multiple occurrences of the same output */
26316 {0, "ATTRIB", 1, 0, 4, 0},
26317 {0, "ATTRIB", 1, 0, 4, 1},
26320 {0, "ATTRIB", 1, 0, 4, 0},
26321 {0, "ATTRIB", 1, 0, 3, 0},
26325 if (!init_test_context(&test_context, &feature_level))
26326 return;
26328 device = test_context.device;
26330 for (i = 0; i < ARRAY_SIZE(stride); ++i)
26331 stride[i] = 64;
26333 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26334 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26335 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26336 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26337 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26338 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26340 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
26341 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26342 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
26343 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26345 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
26346 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26347 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
26348 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
26349 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26351 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
26352 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26353 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
26354 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26356 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
26358 unsigned int max_output_slot = 0;
26359 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
26361 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
26362 max_output_slot = max(max_output_slot, e->OutputSlot);
26363 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26364 break;
26367 /* Buffer strides are required for all buffers. */
26368 if (!max_output_slot)
26370 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26371 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26372 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26373 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26374 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26375 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
26376 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26377 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
26378 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26379 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
26381 else
26383 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26384 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26385 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26386 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
26390 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
26392 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
26394 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
26395 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26396 break;
26399 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26400 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26401 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26402 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
26403 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26404 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
26405 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26406 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
26409 /* Buffer strides */
26410 stride[1] = 63;
26411 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26412 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
26413 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26414 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
26415 stride[1] = 1;
26416 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26417 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
26418 stride[0] = 0;
26419 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26420 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26422 /* Rasterizer stream */
26423 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
26424 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
26425 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26426 NULL, 0, D3D11_SO_STREAM_COUNT);
26428 release_test_context(&test_context);
26431 static void test_fl10_stream_output_desc(void)
26433 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
26434 struct d3d11_test_context test_context;
26435 unsigned int i, count;
26436 ID3D11Device *device;
26438 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
26439 static const DWORD vs_code[] =
26441 #if 0
26442 struct data
26444 float4 position : SV_Position;
26445 float4 attrib1 : ATTRIB1;
26446 float3 attrib2 : attrib2;
26447 float2 attrib3 : ATTriB3;
26448 float attrib4 : ATTRIB4;
26451 void main(in data i, out data o)
26453 o = i;
26455 #endif
26456 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
26457 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
26458 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
26459 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26460 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
26461 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
26462 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
26463 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26464 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
26465 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
26466 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
26467 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
26468 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
26469 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
26470 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
26471 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
26472 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
26473 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
26474 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
26475 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
26477 static const DWORD gs_code[] =
26479 #if 0
26480 struct data
26482 float4 position : SV_Position;
26483 float4 attrib1 : ATTRIB1;
26484 float3 attrib2 : attrib2;
26485 float2 attrib3 : ATTriB3;
26486 float attrib4 : ATTRIB4;
26489 [maxvertexcount(1)]
26490 void main(point data i[1], inout PointStream<data> o)
26492 o.Append(i[0]);
26494 #endif
26495 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
26496 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
26497 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
26498 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26499 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
26500 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
26501 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
26502 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26503 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
26504 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
26505 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
26506 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
26507 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
26508 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
26509 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
26510 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
26511 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
26512 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
26513 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
26514 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
26515 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
26517 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26519 {0, "SV_Position", 0, 0, 4, 0},
26521 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
26523 {0, "SV_Position", 0, 0, 4, 0},
26524 {0, NULL, 0, 0, 0, 0},
26526 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
26528 /* Gaps */
26530 {0, "SV_POSITION", 0, 0, 4, 0},
26531 {0, NULL, 0, 0, 8, 0},
26532 {0, "ATTRIB", 1, 0, 4, 0},
26535 {0, "SV_POSITION", 0, 0, 4, 0},
26536 {0, NULL, 0, 0, 4, 0},
26537 {0, NULL, 0, 0, 4, 0},
26538 {0, "ATTRIB", 1, 0, 4, 0},
26540 /* OutputSlot */
26542 {0, "attrib", 1, 0, 4, 0},
26543 {0, "attrib", 2, 0, 3, 0},
26544 {0, "attrib", 3, 0, 2, 0},
26545 {0, "attrib", 4, 0, 1, 0},
26548 {0, "attrib", 1, 0, 4, 0},
26549 {0, "attrib", 2, 0, 3, 1},
26550 {0, "attrib", 3, 0, 2, 2},
26551 {0, "attrib", 4, 0, 1, 3},
26554 {0, "attrib", 1, 0, 4, 0},
26555 {0, "attrib", 2, 0, 3, 3},
26558 {0, "attrib", 1, 0, 4, 0},
26559 {0, "attrib", 2, 0, 3, 0},
26560 {0, "attrib", 3, 0, 2, 0},
26561 {0, NULL, 0, 0, 1, 0},
26562 {0, "attrib", 4, 0, 1, 0},
26564 /* Multiple occurrences of the same output */
26566 {0, "ATTRIB", 1, 0, 2, 0},
26567 {0, "ATTRIB", 1, 2, 2, 1},
26570 {0, "ATTRIB", 1, 0, 1, 0},
26571 {0, "ATTRIB", 1, 1, 3, 0},
26574 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
26576 /* OutputSlot */
26578 {0, "attrib", 1, 0, 4, 0},
26579 {0, NULL, 0, 0, 4, 0},
26580 {0, "attrib", 4, 0, 1, 3},
26583 {0, "attrib", 1, 0, 4, 0},
26584 {0, NULL, 0, 0, 4, 0},
26585 {0, NULL, 0, 0, 4, 0},
26586 {0, "attrib", 4, 0, 1, 3},
26589 {0, "attrib", 1, 0, 4, 0},
26590 {0, "attrib", 2, 0, 3, 0},
26591 {0, "attrib", 3, 0, 2, 0},
26592 {0, "attrib", 4, 0, 1, 1},
26595 {0, "attrib", 1, 0, 4, 0},
26596 {0, "attrib", 2, 0, 3, 0},
26597 {0, "attrib", 3, 0, 2, 3},
26598 {0, NULL, 0, 0, 1, 3},
26599 {0, "attrib", 4, 0, 1, 3},
26602 {0, "attrib", 1, 0, 4, 0},
26603 {0, "attrib", 1, 0, 3, 1},
26604 {0, "attrib", 1, 0, 2, 2},
26605 {0, "attrib", 1, 0, 1, 3},
26606 {0, NULL, 0, 0, 3, 3},
26610 if (!init_test_context(&test_context, &feature_level))
26611 return;
26613 device = test_context.device;
26615 for (i = 0; i < ARRAY_SIZE(stride); ++i)
26616 stride[i] = 64;
26618 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
26619 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
26620 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26621 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
26623 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26624 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
26626 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
26627 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
26628 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
26629 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
26630 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
26632 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
26633 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
26635 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
26637 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
26639 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
26640 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26641 break;
26644 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
26647 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
26649 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
26651 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
26652 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26653 break;
26656 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26657 stride, 1, 0);
26658 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26659 stride, 2, 0);
26660 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26661 stride, 3, 0);
26662 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26663 stride, 4, 0);
26666 /* Buffer strides */
26667 stride[1] = 63;
26668 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26669 &stride[1], 1, 0);
26670 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26671 stride, 2, 0);
26672 stride[0] = 0;
26673 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26674 stride, 1, 0);
26676 /* Rasterizer stream */
26677 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26678 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26679 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
26680 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26681 NULL, 0, i);
26682 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26684 release_test_context(&test_context);
26687 static void test_stream_output_resume(void)
26689 ID3D11Buffer *cb, *so_buffer, *so_buffer2, *buffer;
26690 struct d3d11_test_context test_context;
26691 unsigned int i, j, idx, offset;
26692 ID3D11DeviceContext *context;
26693 struct resource_readback rb;
26694 ID3D11GeometryShader *gs;
26695 const struct vec4 *data;
26696 ID3D11Device *device;
26697 HRESULT hr;
26699 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26700 static const DWORD gs_code[] =
26702 #if 0
26703 float4 constant;
26705 struct vertex
26707 float4 position : SV_POSITION;
26710 struct element
26712 float4 position : SV_POSITION;
26713 float4 so_output : so_output;
26716 [maxvertexcount(3)]
26717 void main(triangle vertex input[3], inout PointStream<element> output)
26719 element o;
26720 o.so_output = constant;
26721 o.position = input[0].position;
26722 output.Append(o);
26723 o.position = input[1].position;
26724 output.Append(o);
26725 o.position = input[2].position;
26726 output.Append(o);
26728 #endif
26729 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
26730 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26731 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
26732 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
26733 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
26734 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
26735 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
26736 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
26737 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
26738 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
26739 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
26740 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
26741 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
26742 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
26744 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26746 {0, "so_output", 0, 0, 4, 0},
26748 static const struct vec4 constants[] =
26750 {0.5f, 0.250f, 0.0f, 0.0f},
26751 {0.0f, 0.125f, 0.0f, 1.0f},
26752 {1.0f, 1.000f, 1.0f, 0.0f}
26754 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
26755 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
26756 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
26758 if (!init_test_context(&test_context, &feature_level))
26759 return;
26761 device = test_context.device;
26762 context = test_context.immediate_context;
26764 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
26765 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
26766 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
26768 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
26769 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26770 so_buffer2 = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26772 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26773 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
26775 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
26776 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26778 /* Draw into a SO buffer and then immediately destroy it, to make sure that
26779 * wined3d doesn't try to rebind transform feedback buffers while transform
26780 * feedback is active. */
26781 offset = 0;
26782 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer2, &offset);
26783 draw_color_quad(&test_context, &red);
26784 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
26785 ID3D11Buffer_Release(so_buffer2);
26786 draw_color_quad(&test_context, &red);
26787 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26789 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26790 draw_color_quad(&test_context, &green);
26791 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26793 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
26794 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26795 draw_color_quad(&test_context, &red);
26796 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26798 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26799 draw_color_quad(&test_context, &red);
26800 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
26802 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
26803 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26804 draw_color_quad(&test_context, &white);
26805 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
26807 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26808 draw_color_quad(&test_context, &green);
26809 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26811 buffer = NULL;
26812 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
26813 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26814 draw_color_quad(&test_context, &white);
26815 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26817 idx = 0;
26818 get_buffer_readback(so_buffer, &rb);
26819 for (i = 0; i < ARRAY_SIZE(constants); ++i)
26821 for (j = 0; j < 6; ++j) /* 2 triangles */
26823 data = get_readback_vec4(&rb, idx++, 0);
26824 ok(compare_vec4(data, &constants[i], 0),
26825 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
26826 data->x, data->y, data->z, data->w, idx, i, j);
26829 release_resource_readback(&rb);
26831 ID3D11Buffer_Release(cb);
26832 ID3D11Buffer_Release(so_buffer);
26833 ID3D11GeometryShader_Release(gs);
26834 release_test_context(&test_context);
26837 static void test_stream_output_components(void)
26839 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
26840 struct d3d11_test_context test_context;
26841 ID3D11InputLayout *input_layout[2];
26842 ID3D11Buffer *vb[2], *so_buffer;
26843 ID3D11DeviceContext *context;
26844 struct resource_readback rb;
26845 unsigned int stride, offset;
26846 ID3D11GeometryShader *gs;
26847 ID3D11VertexShader *vs;
26848 ID3D11PixelShader *ps;
26849 ID3D11Device *device;
26850 const float *result;
26851 unsigned int i, j;
26852 HRESULT hr;
26854 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26855 static const DWORD vs_code[] =
26857 #if 0
26858 struct vertex
26860 float4 position : POSITION;
26861 float4 color : COLOR;
26862 float4 color2 : COLOR2;
26865 void main(in vertex i, out vertex o)
26867 o = i;
26869 #endif
26870 0x43425844, 0x95991b76, 0x4898640b, 0xe36ad9d6, 0xfbfe78b4, 0x00000001, 0x00000194, 0x00000003,
26871 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26872 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26873 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26874 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26875 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26876 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
26877 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26878 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
26879 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
26880 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
26881 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
26882 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
26884 static const DWORD gs_code[] =
26886 #if 0
26887 struct vertex
26889 float4 position : POSITION;
26890 float4 color : COLOR;
26891 float4 color2 : COLOR2;
26894 [maxvertexcount(1)]
26895 void main(point vertex input[1], inout PointStream<vertex> output)
26897 output.Append(input[0]);
26899 #endif
26900 0x43425844, 0x218f7d27, 0x555fa7f1, 0x282c545f, 0x3989c843, 0x00000001, 0x000001c0, 0x00000003,
26901 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26902 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26903 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26904 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26905 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26906 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
26907 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26908 0x000000bc, 0x00020040, 0x0000002f, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x0400005f,
26909 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000002, 0x0100085d,
26910 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x03000065,
26911 0x001020f2, 0x00000002, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
26912 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001,
26913 0x06000036, 0x001020f2, 0x00000002, 0x00201e46, 0x00000000, 0x00000002, 0x01000013, 0x0100003e,
26915 static const DWORD ps_code[] =
26917 #if 0
26918 float4 main(float4 position : SV_Position,
26919 float2 texcoord : TEXCOORD) : SV_Target
26921 return float4(position.xy, texcoord);
26923 #endif
26924 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
26925 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
26926 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
26927 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
26928 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
26929 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
26930 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
26931 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
26932 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
26934 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
26936 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26937 {"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26938 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
26940 static const D3D11_INPUT_ELEMENT_DESC layout_desc2[] =
26942 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26943 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26944 {"COLOR", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
26946 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26948 {0, "POSITION", 0, 0, 4, 0},
26949 {0, "COLOR", 0, 0, 3, 0},
26950 {0, "COLOR", 2, 0, 2, 0},
26952 static const D3D11_SO_DECLARATION_ENTRY so_declaration2[] =
26954 {0, "POSITION", 0, 0, 1, 0},
26955 {0, "POSITION", 0, 1, 1, 0},
26956 {0, "POSITION", 0, 2, 1, 0},
26957 {0, "POSITION", 0, 3, 1, 0},
26958 {0, "COLOR", 0, 0, 1, 0},
26959 {0, "COLOR", 0, 1, 1, 0},
26960 {0, "COLOR", 0, 2, 1, 0},
26961 {0, "COLOR", 2, 0, 1, 0},
26962 {0, "COLOR", 2, 1, 1, 0},
26964 static const D3D11_SO_DECLARATION_ENTRY so_declaration3[] =
26966 {0, "COLOR", 0, 2, 2, 0},
26967 {0, "COLOR", 2, 3, 1, 0},
26969 static const struct
26971 struct vec4 position;
26972 struct vec3 color;
26973 struct vec2 color2;
26975 vb_data[] =
26977 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},
26978 {{-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
26979 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.5f, 0.4f}},
26980 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.1f, 0.6f}},
26982 static const struct
26984 struct vec4 position;
26985 struct vec4 color;
26986 struct vec4 color2;
26988 vb_data2[] =
26990 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
26991 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
26992 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
26993 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
26995 static const unsigned int vb_stride[] = {sizeof(*vb_data), sizeof(*vb_data2)};
26996 static const float expected_data[] =
26998 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f,
26999 -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
27000 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.4f,
27001 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.1f, 0.6f,
27003 static const float expected_data2[] =
27005 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
27006 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
27007 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
27008 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
27010 static const float expected_data3[] =
27012 3.0f, 4.0f, 8.0f, 1.2f, 1.3f, 1.7f, 2.0f, 2.1f, 2.5f, 2.7f, 2.8f, 3.2f,
27014 static const struct
27016 BOOL with_ps;
27017 unsigned int vb_idx;
27018 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
27019 unsigned int so_entry_count;
27020 const float *expected_data;
27021 unsigned int expected_data_size;
27023 tests[] =
27025 {TRUE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
27026 {TRUE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
27027 {TRUE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
27028 {TRUE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
27029 {TRUE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
27031 {FALSE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
27032 {FALSE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
27033 {FALSE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
27034 {FALSE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
27035 {FALSE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
27038 if (!init_test_context(&test_context, &feature_level))
27039 return;
27041 device = test_context.device;
27042 context = test_context.immediate_context;
27044 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
27045 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data2), vb_data2);
27047 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
27048 vs_code, sizeof(vs_code), &input_layout[0]);
27049 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
27050 hr = ID3D11Device_CreateInputLayout(device, layout_desc2, ARRAY_SIZE(layout_desc2),
27051 vs_code, sizeof(vs_code), &input_layout[1]);
27052 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
27054 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
27055 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
27056 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
27057 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27059 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
27060 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
27062 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
27064 gs = NULL;
27065 current_so_declaration = NULL;
27066 for (i = 0; i < ARRAY_SIZE(tests); ++i)
27068 ID3D11DeviceContext_PSSetShader(context, tests[i].with_ps ? ps : NULL, NULL, 0);
27070 if (current_so_declaration != tests[i].so_declaration)
27072 if (gs)
27073 ID3D11GeometryShader_Release(gs);
27075 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
27076 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
27077 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
27078 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
27079 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
27080 current_so_declaration = tests[i].so_declaration;
27083 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].vb_idx]);
27084 stride = vb_stride[tests[i].vb_idx];
27085 offset = 0;
27086 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[tests[i].vb_idx], &stride, &offset);
27088 offset = 0;
27089 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
27091 ID3D11DeviceContext_Draw(context, 4, 0);
27093 get_buffer_readback(so_buffer, &rb);
27094 result = rb.map_desc.pData;
27095 for (j = 0; j < tests[i].expected_data_size; ++j)
27097 float expected_value = tests[i].expected_data[j];
27098 ok(compare_float(result[j], expected_value, 2),
27099 "Test %u: Got %.8e, expected %.8e at %u.\n",
27100 i, result[j], expected_value, j);
27102 release_resource_readback(&rb);
27105 for (i = 0; i < ARRAY_SIZE(vb); ++i)
27106 ID3D11Buffer_Release(vb[i]);
27107 ID3D11Buffer_Release(so_buffer);
27108 ID3D11VertexShader_Release(vs);
27109 ID3D11GeometryShader_Release(gs);
27110 ID3D11PixelShader_Release(ps);
27111 for (i = 0; i < ARRAY_SIZE(input_layout); ++i)
27112 ID3D11InputLayout_Release(input_layout[i]);
27113 release_test_context(&test_context);
27116 static void test_stream_output_vs(void)
27118 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
27119 struct d3d11_test_context test_context;
27120 ID3D11InputLayout *input_layout;
27121 ID3D11Buffer *vb, *so_buffer;
27122 ID3D11DeviceContext *context;
27123 struct resource_readback rb;
27124 ID3D11GeometryShader *gs;
27125 ID3D11VertexShader *vs;
27126 ID3D11Device *device;
27127 const float *result;
27128 unsigned int offset;
27129 unsigned int i, j;
27130 HRESULT hr;
27132 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27133 static const DWORD vs_code[] =
27135 #if 0
27136 struct vertex
27138 float4 position : POSITION;
27139 float4 color0 : COLOR0;
27140 float4 color1 : COLOR1;
27143 vertex main(in vertex i)
27145 return i;
27147 #endif
27148 0x43425844, 0xa67e993e, 0x1632c139, 0x02a7725f, 0xfb0221cd, 0x00000001, 0x00000194, 0x00000003,
27149 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
27150 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
27151 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
27152 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
27153 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
27154 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000001, 0x00000000,
27155 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
27156 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
27157 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
27158 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
27159 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
27160 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
27162 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
27164 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
27165 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
27166 {"COLOR", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
27168 static const D3D11_SO_DECLARATION_ENTRY all_so_decl[] =
27170 {0, "POSITION", 0, 0, 4, 0},
27171 {0, "COLOR", 0, 0, 3, 0},
27172 {0, "COLOR", 1, 0, 2, 0},
27174 static const D3D11_SO_DECLARATION_ENTRY position_so_decl[] =
27176 {0, "POSITION", 0, 0, 4, 0},
27178 static const D3D11_SO_DECLARATION_ENTRY position2_so_decl[] =
27180 {0, "POSITION", 0, 0, 2, 0},
27182 static const struct
27184 struct vec4 position;
27185 struct vec4 color0;
27186 struct vec4 color1;
27188 vb_data[] =
27190 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
27191 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
27192 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
27193 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
27195 static const unsigned int vb_stride[] = {sizeof(*vb_data)};
27196 static const float expected_data[] =
27198 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
27199 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
27200 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
27201 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
27203 static const float expected_data2[] =
27205 -1.0f, -1.0f, 0.0f, 1.0f,
27206 -1.0f, 1.0f, 0.0f, 1.0f,
27207 1.0f, -1.0f, 0.0f, 1.0f,
27208 1.0f, 1.0f, 0.0f, 1.0f,
27210 static const float expected_data3[] =
27212 -1.0f, -1.0f,
27213 -1.0f, 1.0f,
27214 1.0f, -1.0f,
27215 1.0f, 1.0f,
27217 static const struct
27219 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
27220 unsigned int so_entry_count;
27221 const float *expected_data;
27222 unsigned int expected_data_size;
27224 tests[] =
27226 {all_so_decl, ARRAY_SIZE(all_so_decl), expected_data, ARRAY_SIZE(expected_data)},
27227 {position_so_decl, ARRAY_SIZE(position_so_decl), expected_data2, ARRAY_SIZE(expected_data2)},
27228 {position2_so_decl, ARRAY_SIZE(position2_so_decl), expected_data3, ARRAY_SIZE(expected_data3)},
27231 if (!init_test_context(&test_context, &feature_level))
27232 return;
27234 device = test_context.device;
27235 context = test_context.immediate_context;
27237 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
27239 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
27240 vs_code, sizeof(vs_code), &input_layout);
27241 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
27243 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
27244 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
27246 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
27248 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
27249 offset = 0;
27250 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, vb_stride, &offset);
27251 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
27253 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
27255 gs = NULL;
27256 current_so_declaration = NULL;
27257 for (i = 0; i < ARRAY_SIZE(tests); ++i)
27259 if (current_so_declaration != tests[i].so_declaration)
27261 if (gs)
27262 ID3D11GeometryShader_Release(gs);
27264 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
27265 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
27266 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
27267 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
27268 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
27269 current_so_declaration = tests[i].so_declaration;
27272 offset = 0;
27273 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
27275 ID3D11DeviceContext_Draw(context, 4, 0);
27277 get_buffer_readback(so_buffer, &rb);
27278 result = rb.map_desc.pData;
27279 for (j = 0; j < tests[i].expected_data_size; ++j)
27281 float expected_value = tests[i].expected_data[j];
27282 ok(compare_float(result[j], expected_value, 2),
27283 "Test %u: Got %.8e, expected %.8e at %u.\n",
27284 i, result[j], expected_value, j);
27286 release_resource_readback(&rb);
27289 ID3D11Buffer_Release(vb);
27290 ID3D11Buffer_Release(so_buffer);
27291 ID3D11VertexShader_Release(vs);
27292 ID3D11GeometryShader_Release(gs);
27293 ID3D11InputLayout_Release(input_layout);
27294 release_test_context(&test_context);
27297 static void test_gather(void)
27299 struct
27301 int width, height;
27302 int offset_x, offset_y;
27303 } constant;
27304 struct d3d11_test_context test_context;
27305 D3D11_TEXTURE2D_DESC texture_desc;
27306 ID3D11ShaderResourceView *srv;
27307 ID3D11Texture2D *texture, *rt;
27308 ID3D11DeviceContext *context;
27309 ID3D11RenderTargetView *rtv;
27310 struct resource_readback rb;
27311 ID3D11PixelShader *ps;
27312 ID3D11Device *device;
27313 unsigned int x, y;
27314 ID3D11Buffer *cb;
27315 HRESULT hr;
27317 static const DWORD gather4_code[] =
27319 #if 0
27320 SamplerState s;
27321 Texture2D<float4> t;
27323 int2 size;
27325 float4 main(float4 position : SV_Position) : SV_Target
27327 return t.Gather(s, position.xy / size);
27329 #endif
27330 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
27331 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27332 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27333 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27334 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
27335 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
27336 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27337 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27338 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27339 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
27340 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
27342 static const DWORD gather4_offset_code[] =
27344 #if 0
27345 SamplerState s;
27346 Texture2D<float4> t;
27348 int2 size;
27350 float4 main(float4 position : SV_Position) : SV_Target
27352 return t.Gather(s, position.xy / size, int2(1, 1));
27354 #endif
27355 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
27356 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27357 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27358 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27359 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
27360 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
27361 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27362 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27363 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27364 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
27365 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
27367 static const DWORD gather4_green_code[] =
27369 #if 0
27370 SamplerState s;
27371 Texture2D<float4> t;
27373 int2 size;
27375 float4 main(float4 position : SV_Position) : SV_Target
27377 return t.GatherGreen(s, position.xy / size);
27379 #endif
27380 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
27381 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27382 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27383 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27384 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
27385 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
27386 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27387 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27388 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27389 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27390 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
27392 static const DWORD gather4_po_code[] =
27394 #if 0
27395 SamplerState s;
27396 Texture2D<float4> t;
27398 int2 size;
27399 int2 offset;
27401 float4 main(float4 position : SV_Position) : SV_Target
27403 return t.Gather(s, position.xy / size, offset);
27405 #endif
27406 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
27407 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27408 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27409 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27410 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
27411 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
27412 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27413 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27414 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27415 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27416 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
27417 0x00000000, 0x0100003e,
27419 static const struct vec4 texture_data[] =
27421 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
27422 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
27423 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
27424 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
27426 static const struct vec4 expected_gather4[] =
27428 {4.0f, 5.0f, 1.0f, 0.0f}, {5.0f, 6.0f, 2.0f, 1.0f}, {6.0f, 7.0f, 3.0f, 2.0f}, {7.0f, 7.0f, 3.0f, 3.0f},
27429 {8.0f, 9.0f, 5.0f, 4.0f}, {9.0f, 0.5f, 6.0f, 5.0f}, {0.5f, 1.5f, 7.0f, 6.0f}, {1.5f, 1.5f, 7.0f, 7.0f},
27430 {2.5f, 3.5f, 9.0f, 8.0f}, {3.5f, 4.5f, 0.5f, 9.0f}, {4.5f, 5.5f, 1.5f, 0.5f}, {5.5f, 5.5f, 1.5f, 1.5f},
27431 {2.5f, 3.5f, 3.5f, 2.5f}, {3.5f, 4.5f, 4.5f, 3.5f}, {4.5f, 5.5f, 5.5f, 4.5f}, {5.5f, 5.5f, 5.5f, 5.5f},
27433 static const struct vec4 expected_gather4_offset[] =
27435 {9.0f, 0.5f, 6.0f, 5.0f}, {0.5f, 1.5f, 7.0f, 6.0f}, {1.5f, 1.5f, 7.0f, 7.0f}, {1.5f, 1.5f, 7.0f, 7.0f},
27436 {3.5f, 4.5f, 0.5f, 9.0f}, {4.5f, 5.5f, 1.5f, 0.5f}, {5.5f, 5.5f, 1.5f, 1.5f}, {5.5f, 5.5f, 1.5f, 1.5f},
27437 {3.5f, 4.5f, 4.5f, 3.5f}, {4.5f, 5.5f, 5.5f, 4.5f}, {5.5f, 5.5f, 5.5f, 5.5f}, {5.5f, 5.5f, 5.5f, 5.5f},
27438 {3.5f, 4.5f, 4.5f, 3.5f}, {4.5f, 5.5f, 5.5f, 4.5f}, {5.5f, 5.5f, 5.5f, 5.5f}, {5.5f, 5.5f, 5.5f, 5.5f},
27440 static const struct vec4 expected_gather4_green[] =
27442 {0.1f, 1.1f, 1.0f, 0.0f}, {1.1f, 2.1f, 2.0f, 1.0f}, {2.1f, 3.1f, 3.0f, 2.0f}, {3.1f, 3.1f, 3.0f, 3.0f},
27443 {0.2f, 1.2f, 1.1f, 0.1f}, {1.2f, 2.2f, 2.1f, 1.1f}, {2.2f, 3.2f, 3.1f, 2.1f}, {3.2f, 3.2f, 3.1f, 3.1f},
27444 {0.3f, 1.3f, 1.2f, 0.2f}, {1.3f, 2.3f, 2.2f, 1.2f}, {2.3f, 3.3f, 3.2f, 2.2f}, {3.3f, 3.3f, 3.2f, 3.2f},
27445 {0.3f, 1.3f, 1.3f, 0.3f}, {1.3f, 2.3f, 2.3f, 1.3f}, {2.3f, 3.3f, 3.3f, 2.3f}, {3.3f, 3.3f, 3.3f, 3.3f},
27447 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
27448 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
27450 if (!init_test_context(&test_context, NULL))
27451 return;
27453 device = test_context.device;
27454 context = test_context.immediate_context;
27456 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
27458 skip("Shader model 4.1 required for gather4 instruction.\n");
27459 release_test_context(&test_context);
27460 return;
27463 texture_desc.Width = 4;
27464 texture_desc.Height = 4;
27465 texture_desc.MipLevels = 1;
27466 texture_desc.ArraySize = 1;
27467 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27468 texture_desc.SampleDesc.Count = 1;
27469 texture_desc.SampleDesc.Quality = 0;
27470 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27471 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27472 texture_desc.CPUAccessFlags = 0;
27473 texture_desc.MiscFlags = 0;
27474 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27475 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27476 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27477 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27478 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27480 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
27481 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
27482 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27483 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
27484 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
27485 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
27487 constant.width = texture_desc.Width;
27488 constant.height = texture_desc.Height;
27489 constant.offset_x = 1;
27490 constant.offset_y = 1;
27491 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
27492 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
27494 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
27495 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27496 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27498 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27499 draw_quad(&test_context);
27500 get_texture_readback(rt, 0, &rb);
27501 for (y = 0; y < texture_desc.Height; ++y)
27503 for (x = 0; x < texture_desc.Width; ++x)
27505 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
27506 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27507 ok(compare_vec4(got, expected, 0),
27508 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27509 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27512 release_resource_readback(&rb);
27514 ID3D11PixelShader_Release(ps);
27515 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
27516 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27517 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27519 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27520 draw_quad(&test_context);
27521 get_texture_readback(rt, 0, &rb);
27522 for (y = 0; y < texture_desc.Height; ++y)
27524 for (x = 0; x < texture_desc.Width; ++x)
27526 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
27527 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27528 ok(compare_vec4(got, expected, 0),
27529 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27530 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27533 release_resource_readback(&rb);
27535 ID3D11PixelShader_Release(ps);
27537 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
27539 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
27540 goto done;
27543 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
27544 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27545 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27547 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27548 draw_quad(&test_context);
27549 get_texture_readback(rt, 0, &rb);
27550 for (y = 0; y < texture_desc.Height; ++y)
27552 for (x = 0; x < texture_desc.Width; ++x)
27554 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
27555 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27556 ok(compare_vec4(got, expected, 0),
27557 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27558 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27561 release_resource_readback(&rb);
27563 ID3D11PixelShader_Release(ps);
27564 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
27565 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27566 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27568 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27569 draw_quad(&test_context);
27570 get_texture_readback(rt, 0, &rb);
27571 for (y = 0; y < texture_desc.Height; ++y)
27573 for (x = 0; x < texture_desc.Width; ++x)
27575 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
27576 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27577 ok(compare_vec4(got, expected, 0),
27578 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27579 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27582 release_resource_readback(&rb);
27584 constant.offset_x = 0;
27585 constant.offset_y = 0;
27586 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
27587 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27588 draw_quad(&test_context);
27589 get_texture_readback(rt, 0, &rb);
27590 for (y = 0; y < texture_desc.Height; ++y)
27592 for (x = 0; x < texture_desc.Width; ++x)
27594 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
27595 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27596 ok(compare_vec4(got, expected, 0),
27597 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27598 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27601 release_resource_readback(&rb);
27603 ID3D11PixelShader_Release(ps);
27605 done:
27606 ID3D11Buffer_Release(cb);
27607 ID3D11Texture2D_Release(rt);
27608 ID3D11Texture2D_Release(texture);
27609 ID3D11RenderTargetView_Release(rtv);
27610 ID3D11ShaderResourceView_Release(srv);
27611 release_test_context(&test_context);
27614 static void test_gather_c(void)
27616 struct
27618 int width, height;
27619 int offset_x, offset_y;
27620 float compare_value;
27621 int padding[3];
27622 } constant;
27623 struct d3d11_test_context test_context;
27624 D3D11_TEXTURE2D_DESC texture_desc;
27625 D3D11_SAMPLER_DESC sampler_desc;
27626 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
27627 ID3D11ShaderResourceView *srv;
27628 ID3D11Texture2D *texture, *rt;
27629 ID3D11DeviceContext *context;
27630 ID3D11SamplerState *sampler;
27631 ID3D11RenderTargetView *rtv;
27632 struct resource_readback rb;
27633 ID3D11PixelShader *ps;
27634 ID3D11Device *device;
27635 unsigned int x, y;
27636 ID3D11Buffer *cb;
27637 HRESULT hr;
27639 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27640 static const DWORD gather4_c_code[] =
27642 #if 0
27643 SamplerComparisonState s;
27644 Texture2D<float4> t;
27646 int2 size;
27647 int2 offset;
27648 float compare;
27650 float4 main(float4 position : SV_Position) : SV_Target
27652 return t.GatherCmp(s, position.xy / size, compare);
27654 #endif
27655 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
27656 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27657 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27658 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27659 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
27660 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
27661 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27662 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27663 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27664 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27665 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
27666 0x00000001, 0x0100003e,
27668 static const DWORD gather4_po_c_code[] =
27670 #if 0
27671 SamplerComparisonState s;
27672 Texture2D<float4> t;
27674 int2 size;
27675 int2 offset;
27676 float compare;
27678 float4 main(float4 position : SV_Position) : SV_Target
27680 return t.GatherCmp(s, position.xy / size, compare, offset);
27682 #endif
27683 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
27684 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27685 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27686 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27687 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
27688 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
27689 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27690 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27691 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27692 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27693 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
27694 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
27696 static const float texture_data[] =
27698 0.00f, 0.10f, 0.20f, 0.30f,
27699 0.40f, 0.50f, 0.60f, 0.70f,
27700 0.80f, 0.90f, 0.05f, 0.15f,
27701 0.25f, 0.35f, 0.45f, 0.55f,
27703 static const struct vec4 expected_gather4_c[] =
27705 {0.0f, 1.00, 0.00, 0.0f}, {1.0f, 1.00, 0.00, 0.0f}, {1.0f, 1.00, 0.00, 0.0f}, {1.0f, 1.00, 0.00, 0.0f},
27706 {1.0f, 1.00, 1.00, 0.0f}, {1.0f, 0.00, 1.00, 1.0f}, {0.0f, 0.00, 1.00, 1.0f}, {0.0f, 0.00, 1.00, 1.0f},
27707 {0.0f, 0.00, 1.00, 1.0f}, {0.0f, 0.00, 0.00, 1.0f}, {0.0f, 1.00, 0.00, 0.0f}, {1.0f, 1.00, 0.00, 0.0f},
27708 {0.0f, 0.00, 0.00, 0.0f}, {0.0f, 0.00, 0.00, 0.0f}, {0.0f, 1.00, 1.00, 0.0f}, {1.0f, 1.00, 1.00, 1.0f},
27710 static const struct vec4 expected_gather4_po_c[] =
27712 {1.0f, 0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 1.0f, 1.0f},
27713 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 0.0f, 0.0f},
27714 {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f},
27715 {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f},
27717 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
27718 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
27720 if (!init_test_context(&test_context, &feature_level))
27721 return;
27723 device = test_context.device;
27724 context = test_context.immediate_context;
27726 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
27727 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
27728 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
27729 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
27730 sampler_desc.MipLODBias = 0.0f;
27731 sampler_desc.MaxAnisotropy = 0;
27732 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
27733 sampler_desc.BorderColor[0] = 0.0f;
27734 sampler_desc.BorderColor[1] = 0.0f;
27735 sampler_desc.BorderColor[2] = 0.0f;
27736 sampler_desc.BorderColor[3] = 0.0f;
27737 sampler_desc.MinLOD = 0.0f;
27738 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
27740 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
27741 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
27742 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
27744 texture_desc.Width = 4;
27745 texture_desc.Height = 4;
27746 texture_desc.MipLevels = 1;
27747 texture_desc.ArraySize = 1;
27748 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27749 texture_desc.SampleDesc.Count = 1;
27750 texture_desc.SampleDesc.Quality = 0;
27751 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27752 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27753 texture_desc.CPUAccessFlags = 0;
27754 texture_desc.MiscFlags = 0;
27755 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27756 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27757 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27758 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27759 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27761 constant.width = texture_desc.Width;
27762 constant.height = texture_desc.Height;
27763 constant.offset_x = 1;
27764 constant.offset_y = 1;
27765 constant.compare_value = 0.5f;
27766 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
27767 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
27769 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
27770 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
27771 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
27772 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27774 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
27775 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
27776 U(srv_desc).Texture2D.MostDetailedMip = 0;
27777 U(srv_desc).Texture2D.MipLevels = 1;
27778 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
27779 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
27780 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
27782 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
27783 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27784 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27786 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27787 draw_quad(&test_context);
27788 get_texture_readback(rt, 0, &rb);
27789 for (y = 0; y < texture_desc.Height; ++y)
27791 for (x = 0; x < texture_desc.Width; ++x)
27793 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
27794 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27795 ok(compare_vec4(got, expected, 0),
27796 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27797 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27800 release_resource_readback(&rb);
27801 ID3D11PixelShader_Release(ps);
27803 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
27804 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27805 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27807 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27808 draw_quad(&test_context);
27809 get_texture_readback(rt, 0, &rb);
27810 for (y = 0; y < texture_desc.Height; ++y)
27812 for (x = 0; x < texture_desc.Width; ++x)
27814 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
27815 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27816 ok(compare_vec4(got, expected, 0),
27817 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27818 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27821 release_resource_readback(&rb);
27822 ID3D11PixelShader_Release(ps);
27824 ID3D11ShaderResourceView_Release(srv);
27825 ID3D11Texture2D_Release(texture);
27827 ID3D11Buffer_Release(cb);
27828 ID3D11Texture2D_Release(rt);
27829 ID3D11RenderTargetView_Release(rtv);
27830 ID3D11SamplerState_Release(sampler);
27831 release_test_context(&test_context);
27834 static float clamp_depth_bias(float bias, float clamp)
27836 if (clamp > 0.0f)
27837 return min(bias, clamp);
27838 if (clamp < 0.0f)
27839 return max(bias, clamp);
27840 return bias;
27843 static void test_depth_bias(void)
27845 struct vec3 vertices[] =
27847 {-1.0f, -1.0f, 0.5f},
27848 {-1.0f, 1.0f, 0.5f},
27849 { 1.0f, -1.0f, 0.5f},
27850 { 1.0f, 1.0f, 0.5f},
27852 struct d3d11_test_context test_context;
27853 D3D11_RASTERIZER_DESC rasterizer_desc;
27854 struct swapchain_desc swapchain_desc;
27855 D3D11_TEXTURE2D_DESC texture_desc;
27856 ID3D11DeviceContext *context;
27857 double m, bias, depth, data;
27858 struct resource_readback rb;
27859 ID3D11DepthStencilView *dsv;
27860 unsigned int expected_value;
27861 ID3D11RasterizerState *rs;
27862 ID3D11Texture2D *texture;
27863 unsigned int format_idx;
27864 unsigned int y, i, j, k;
27865 unsigned int shift = 0;
27866 ID3D11Device *device;
27867 float *depth_values;
27868 DXGI_FORMAT format;
27869 const UINT32 *u32;
27870 const UINT16 *u16;
27871 UINT32 u32_value;
27872 HRESULT hr;
27874 static const struct
27876 float z;
27877 float exponent;
27879 quads[] =
27881 {0.125f, -3.0f},
27882 {0.250f, -2.0f},
27883 {0.500f, -1.0f},
27884 {1.000f, 0.0f},
27886 static const int bias_tests[] =
27888 -10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
27889 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000,
27891 static const float bias_clamp_tests[] =
27893 0.0f, -1e-5f, 1e-5f,
27895 static const float quad_slopes[] =
27897 0.0f, 0.5f, 1.0f
27899 static const float slope_scaled_bias_tests[] =
27901 0.0f, 0.5f, 1.0f, 2.0f, 128.0f, 1000.0f, 10000.0f,
27903 static const DXGI_FORMAT formats[] =
27905 DXGI_FORMAT_D32_FLOAT,
27906 DXGI_FORMAT_D24_UNORM_S8_UINT,
27907 DXGI_FORMAT_D16_UNORM,
27910 swapchain_desc.windowed = TRUE;
27911 swapchain_desc.buffer_count = 1;
27912 swapchain_desc.width = 200;
27913 swapchain_desc.height = 200;
27914 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
27915 swapchain_desc.flags = 0;
27916 if (!init_test_context_ext(&test_context, NULL, &swapchain_desc))
27917 return;
27919 device = test_context.device;
27920 context = test_context.immediate_context;
27922 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
27923 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
27924 rasterizer_desc.CullMode = D3D11_CULL_NONE;
27925 rasterizer_desc.FrontCounterClockwise = FALSE;
27926 rasterizer_desc.DepthBias = 0;
27927 rasterizer_desc.DepthBiasClamp = 0.0f;
27928 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
27929 rasterizer_desc.DepthClipEnable = TRUE;
27931 depth_values = heap_calloc(swapchain_desc.height, sizeof(*depth_values));
27932 ok(!!depth_values, "Failed to allocate memory.\n");
27934 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
27936 format = formats[format_idx];
27938 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
27939 texture_desc.Format = format;
27940 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
27941 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
27942 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27943 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
27944 ok(SUCCEEDED(hr), "Failed to create render depth stencil view, hr %#x.\n", hr);
27945 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
27946 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
27947 draw_quad_z(&test_context, 1.0f);
27948 switch (format)
27950 case DXGI_FORMAT_D32_FLOAT:
27951 check_texture_float(texture, 1.0f, 0);
27952 break;
27953 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27954 /* FIXME: Depth/stencil byte order is reversed in wined3d. */
27955 shift = get_texture_color(texture, 0, 0) == 0xffffff ? 0 : 8;
27956 todo_wine
27957 check_texture_color(texture, 0xffffff, 1);
27958 break;
27959 case DXGI_FORMAT_D16_UNORM:
27960 get_texture_readback(texture, 0, &rb);
27961 check_readback_data_u16(&rb, NULL, 0xffffu, 0);
27962 release_resource_readback(&rb);
27963 break;
27964 default:
27965 trace("Unhandled format %#x.\n", format);
27966 break;
27968 draw_quad(&test_context);
27970 /* DepthBias */
27971 for (i = 0; i < ARRAY_SIZE(quads); ++i)
27973 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
27974 vertices[j].z = quads[i].z;
27975 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
27976 0, NULL, vertices, 0, 0);
27978 for (j = 0; j < ARRAY_SIZE(bias_tests); ++j)
27980 rasterizer_desc.DepthBias = bias_tests[j];
27982 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
27984 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
27985 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
27986 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
27987 ID3D11DeviceContext_RSSetState(context, rs);
27988 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27989 draw_quad(&test_context);
27990 switch (format)
27992 case DXGI_FORMAT_D32_FLOAT:
27993 bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f);
27994 bias = clamp_depth_bias(bias, rasterizer_desc.DepthBiasClamp);
27995 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27997 check_texture_float(texture, depth, 2);
27998 break;
27999 case DXGI_FORMAT_D24_UNORM_S8_UINT:
28000 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 16777215.0f,
28001 rasterizer_desc.DepthBiasClamp);
28002 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
28004 get_texture_readback(texture, 0, &rb);
28005 check_readback_data_u24(&rb, NULL, shift, depth * 16777215.0f + 0.5f, 1);
28006 release_resource_readback(&rb);
28007 break;
28008 case DXGI_FORMAT_D16_UNORM:
28009 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 65535.0f,
28010 rasterizer_desc.DepthBiasClamp);
28011 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
28013 get_texture_readback(texture, 0, &rb);
28014 check_readback_data_u16(&rb, NULL, depth * 65535.0f + 0.5f, 1);
28015 release_resource_readback(&rb);
28016 break;
28017 default:
28018 break;
28020 ID3D11RasterizerState_Release(rs);
28025 /* SlopeScaledDepthBias */
28026 rasterizer_desc.DepthBias = 0;
28027 for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i)
28029 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
28030 vertices[j].z = j == 1 || j == 3 ? 0.0f : quad_slopes[i];
28031 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
28032 0, NULL, vertices, 0, 0);
28034 ID3D11DeviceContext_RSSetState(context, NULL);
28035 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
28036 draw_quad(&test_context);
28037 get_texture_readback(texture, 0, &rb);
28038 for (y = 0; y < texture_desc.Height; ++y)
28040 switch (format)
28042 case DXGI_FORMAT_D32_FLOAT:
28043 depth_values[y] = get_readback_float(&rb, 0, y);
28044 break;
28045 case DXGI_FORMAT_D24_UNORM_S8_UINT:
28046 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
28047 u32_value = *u32 >> shift;
28048 depth_values[y] = u32_value / 16777215.0f;
28049 break;
28050 case DXGI_FORMAT_D16_UNORM:
28051 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
28052 depth_values[y] = *u16 / 65535.0f;
28053 break;
28054 default:
28055 break;
28058 release_resource_readback(&rb);
28060 for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j)
28062 rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j];
28064 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
28066 BOOL all_match = TRUE;
28067 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
28068 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
28069 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
28070 ID3D11DeviceContext_RSSetState(context, rs);
28071 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
28072 draw_quad(&test_context);
28074 m = quad_slopes[i] / texture_desc.Height;
28075 bias = clamp_depth_bias(rasterizer_desc.SlopeScaledDepthBias * m, rasterizer_desc.DepthBiasClamp);
28076 get_texture_readback(texture, 0, &rb);
28077 for (y = 0; y < texture_desc.Height && all_match; ++y)
28079 depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
28080 switch (format)
28082 case DXGI_FORMAT_D32_FLOAT:
28083 data = get_readback_float(&rb, 0, y);
28084 all_match = compare_float(data, depth, 64);
28085 ok(all_match,
28086 "Got depth %.8e, expected %.8e.\n", data, depth);
28087 break;
28088 case DXGI_FORMAT_D24_UNORM_S8_UINT:
28089 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
28090 u32_value = *u32 >> shift;
28091 expected_value = depth * 16777215.0f + 0.5f;
28092 all_match = compare_uint(u32_value, expected_value, 3);
28093 ok(all_match,
28094 "Got value %#x (%.8e), expected %#x (%.8e).\n",
28095 u32_value, u32_value / 16777215.0f,
28096 expected_value, expected_value / 16777215.0f);
28097 break;
28098 case DXGI_FORMAT_D16_UNORM:
28099 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
28100 expected_value = depth * 65535.0f + 0.5f;
28101 all_match = compare_uint(*u16, expected_value, 1);
28102 ok(all_match,
28103 "Got value %#x (%.8e), expected %#x (%.8e).\n",
28104 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
28105 break;
28106 default:
28107 break;
28110 release_resource_readback(&rb);
28111 ID3D11RasterizerState_Release(rs);
28116 ID3D11Texture2D_Release(texture);
28117 ID3D11DepthStencilView_Release(dsv);
28120 heap_free(depth_values);
28121 release_test_context(&test_context);
28124 static void test_fractional_viewports(void)
28126 struct d3d11_test_context test_context;
28127 D3D11_TEXTURE2D_DESC texture_desc;
28128 ID3D11InputLayout *input_layout;
28129 ID3D11DeviceContext *context;
28130 struct resource_readback rb;
28131 ID3D11RenderTargetView *rtv;
28132 ID3D11VertexShader *vs;
28133 ID3D11PixelShader *ps;
28134 unsigned int i, x, y;
28135 ID3D11Device *device;
28136 ID3D11Texture2D *rt;
28137 UINT offset, stride;
28138 ID3D11Buffer *vb;
28139 HRESULT hr;
28141 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
28142 static const DWORD vs_code[] =
28144 #if 0
28145 void main(in float4 in_position : POSITION,
28146 in float2 in_texcoord : TEXCOORD,
28147 out float4 position : SV_Position,
28148 out float2 texcoord : TEXCOORD)
28150 position = in_position;
28151 texcoord = in_texcoord;
28153 #endif
28154 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
28155 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
28156 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
28157 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
28158 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
28159 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
28160 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
28161 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
28162 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
28163 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
28164 0x00000001, 0x0100003e,
28166 static const DWORD ps_code[] =
28168 #if 0
28169 float4 main(float4 position : SV_Position,
28170 float2 texcoord : TEXCOORD) : SV_Target
28172 return float4(position.xy, texcoord);
28174 #endif
28175 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
28176 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
28177 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
28178 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
28179 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
28180 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
28181 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
28182 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
28183 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
28185 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
28187 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
28188 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
28190 static const struct
28192 struct vec2 position;
28193 struct vec2 texcoord;
28195 quad[] =
28197 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
28198 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
28199 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
28200 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
28202 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28203 static const float viewport_offsets[] =
28205 0.0f, 1.0f / 2.0f, 1.0f / 4.0f, 1.0f / 8.0f, 1.0f / 16.0f, 1.0f / 32.0f,
28206 1.0f / 64.0f, 1.0f / 128.0f, 1.0f / 256.0f, 63.0f / 128.0f,
28209 if (!init_test_context(&test_context, &feature_level))
28210 return;
28211 device = test_context.device;
28212 context = test_context.immediate_context;
28214 texture_desc.Width = 4;
28215 texture_desc.Height = 4;
28216 texture_desc.MipLevels = 1;
28217 texture_desc.ArraySize = 1;
28218 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
28219 texture_desc.SampleDesc.Count = 1;
28220 texture_desc.SampleDesc.Quality = 0;
28221 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28222 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
28223 texture_desc.CPUAccessFlags = 0;
28224 texture_desc.MiscFlags = 0;
28225 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
28226 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28227 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
28228 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
28229 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
28231 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
28232 vs_code, sizeof(vs_code), &input_layout);
28233 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
28234 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
28236 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
28237 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
28238 stride = sizeof(*quad);
28239 offset = 0;
28240 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
28242 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
28243 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
28244 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
28246 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
28247 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
28248 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
28250 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
28252 set_viewport(context, viewport_offsets[i], viewport_offsets[i],
28253 texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
28254 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
28255 ID3D11DeviceContext_Draw(context, 4, 0);
28256 get_texture_readback(rt, 0, &rb);
28257 for (y = 0; y < texture_desc.Height; ++y)
28259 for (x = 0; x < texture_desc.Width; ++x)
28261 const struct vec4 *v = get_readback_vec4(&rb, x, y);
28262 struct vec4 expected = {x + 0.5f, y + 0.5f,
28263 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
28264 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
28265 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
28266 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
28267 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
28268 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
28269 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
28270 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
28273 release_resource_readback(&rb);
28276 ID3D11InputLayout_Release(input_layout);
28277 ID3D11Buffer_Release(vb);
28278 ID3D11VertexShader_Release(vs);
28279 ID3D11PixelShader_Release(ps);
28280 ID3D11RenderTargetView_Release(rtv);
28281 ID3D11Texture2D_Release(rt);
28282 release_test_context(&test_context);
28285 static void test_negative_viewports(const D3D_FEATURE_LEVEL feature_level)
28287 struct d3d11_test_context test_context;
28288 ID3D11DeviceContext *context;
28289 BOOL quirk;
28290 RECT rect;
28292 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28293 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
28295 if (!init_test_context(&test_context, &feature_level))
28296 return;
28297 context = test_context.immediate_context;
28299 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
28300 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28301 draw_color_quad(&test_context, &green);
28302 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
28304 set_viewport(context, -0.0f, -0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
28305 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28306 draw_color_quad(&test_context, &green);
28307 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
28309 /* For feature levels greater than or equal to 11_0, a negative top left
28310 * corner shifts the bottom right corner by a whole integer. It seems that
28311 * floor() is used to round viewport corners to integers.
28313 quirk = feature_level >= D3D_FEATURE_LEVEL_11_0;
28315 set_viewport(context, -0.4f, -0.4f, 640.0f, 480.0f, 0.0f, 1.0f);
28316 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28317 draw_color_quad(&test_context, &green);
28318 SetRect(&rect, 0, 0, 639, 479);
28319 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
28320 SetRect(&rect, 639, 479, 640, 480);
28321 todo_wine_if(quirk)
28322 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
28324 set_viewport(context, -1.0f / 128.0f, -1.0 / 128.0f, 640.0f, 480.0f, 0.0f, 1.0f);
28325 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28326 draw_color_quad(&test_context, &green);
28327 SetRect(&rect, 0, 0, 639, 479);
28328 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
28329 SetRect(&rect, 639, 479, 640, 480);
28330 todo_wine_if(quirk)
28331 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
28333 release_test_context(&test_context);
28336 static void test_early_depth_stencil(void)
28338 ID3D11DepthStencilState *depth_stencil_state;
28339 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
28340 ID3D11Texture2D *texture, *depth_texture;
28341 struct d3d11_test_context test_context;
28342 D3D11_TEXTURE2D_DESC texture_desc;
28343 ID3D11UnorderedAccessView *uav;
28344 ID3D11DeviceContext *context;
28345 ID3D11DepthStencilView *dsv;
28346 ID3D11PixelShader *ps;
28347 ID3D11Device *device;
28348 HRESULT hr;
28350 static const DWORD ps_code[] =
28352 #if 0
28353 RWTexture2D<int> u;
28355 [earlydepthstencil]
28356 float4 main() : SV_Target
28358 InterlockedAdd(u[uint2(0, 0)], 1);
28359 return float4(1.0f, 1.0f, 1.0f, 1.0f);
28361 #endif
28362 0x43425844, 0xda4325ad, 0xc01d3815, 0xfd610cc9, 0x8ed1e351, 0x00000001, 0x000000ec, 0x00000003,
28363 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28364 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28365 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000074, 0x00000050, 0x0000001d,
28366 0x0100286a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x03000065, 0x001020f2, 0x00000000,
28367 0x0a0000ad, 0x0011e000, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
28368 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
28369 0x3f800000, 0x3f800000, 0x0100003e,
28371 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
28372 static const UINT values[4] = {0};
28374 if (!init_test_context(&test_context, &feature_level))
28375 return;
28377 device = test_context.device;
28378 context = test_context.immediate_context;
28380 depth_stencil_desc.DepthEnable = TRUE;
28381 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
28382 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
28383 depth_stencil_desc.StencilEnable = FALSE;
28384 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
28385 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
28387 texture_desc.Width = 1;
28388 texture_desc.Height = 1;
28389 texture_desc.MipLevels = 1;
28390 texture_desc.ArraySize = 1;
28391 texture_desc.Format = DXGI_FORMAT_R32_SINT;
28392 texture_desc.SampleDesc.Count = 1;
28393 texture_desc.SampleDesc.Quality = 0;
28394 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28395 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
28396 texture_desc.CPUAccessFlags = 0;
28397 texture_desc.MiscFlags = 0;
28398 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
28399 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28400 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
28401 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
28403 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28404 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
28405 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28406 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
28407 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
28408 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28409 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
28410 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
28412 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
28413 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
28414 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
28416 set_viewport(context, 0.0f, 0.0f, 1.0f, 100.0f, 0.5f, 0.5f);
28417 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
28418 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
28419 1, &test_context.backbuffer_rtv, dsv, 1, 1, &uav, NULL);
28421 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
28423 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
28424 draw_quad(&test_context);
28425 check_texture_color(texture, 100, 1);
28426 draw_quad(&test_context);
28427 check_texture_color(texture, 200, 1);
28428 check_texture_float(depth_texture, 0.6f, 1);
28430 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.3f, 0);
28431 draw_quad(&test_context);
28432 draw_quad(&test_context);
28433 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.55f, 0);
28434 draw_quad(&test_context);
28435 check_texture_color(texture, 300, 1);
28437 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
28438 draw_quad(&test_context);
28439 check_texture_color(texture, 400, 1);
28440 check_texture_float(depth_texture, 0.5f, 1);
28442 ID3D11Texture2D_Release(depth_texture);
28443 ID3D11DepthStencilView_Release(dsv);
28444 ID3D11DepthStencilState_Release(depth_stencil_state);
28445 ID3D11PixelShader_Release(ps);
28446 ID3D11Texture2D_Release(texture);
28447 ID3D11UnorderedAccessView_Release(uav);
28448 release_test_context(&test_context);
28451 static void test_conservative_depth_output(void)
28453 struct shader
28455 const DWORD *code;
28456 size_t size;
28459 ID3D11DepthStencilState *depth_stencil_state;
28460 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
28461 struct d3d11_test_context test_context;
28462 const struct shader *current_shader;
28463 D3D11_TEXTURE2D_DESC texture_desc;
28464 ID3D11DeviceContext *context;
28465 ID3D11DepthStencilView *dsv;
28466 ID3D11Texture2D *texture;
28467 ID3D11PixelShader *ps;
28468 DWORD expected_color;
28469 float expected_depth;
28470 ID3D11Device *device;
28471 struct vec4 ps_depth;
28472 ID3D11Buffer *cb;
28473 unsigned int i;
28474 HRESULT hr;
28476 static const DWORD ps_depth_le_code[] =
28478 #if 0
28479 float depth;
28481 float4 main(out float out_depth : SV_DepthLessEqual) : SV_Target0
28483 out_depth = depth;
28484 return float4(0.0f, 1.0f, 0.f, 1.0f);
28486 #endif
28487 0x43425844, 0x045c8d00, 0xc49e2ebe, 0x76f6022a, 0xf6996ecc, 0x00000001, 0x00000108, 0x00000003,
28488 0x0000002c, 0x0000003c, 0x00000098, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28489 0x00000054, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28490 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
28491 0x65677261, 0x56530074, 0x7065445f, 0x654c6874, 0x71457373, 0x006c6175, 0x58454853, 0x00000068,
28492 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065,
28493 0x001020f2, 0x00000000, 0x02000065, 0x00027001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
28494 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00027001, 0x0020800a, 0x00000000,
28495 0x00000000, 0x0100003e,
28497 static const struct shader ps_depth_le = {ps_depth_le_code, sizeof(ps_depth_le_code)};
28498 static const DWORD ps_depth_ge_code[] =
28500 #if 0
28501 float depth;
28503 float4 main(out float out_depth : SV_DepthGreaterEqual) : SV_Target0
28505 out_depth = depth;
28506 return float4(0.0f, 1.0f, 0.f, 1.0f);
28508 #endif
28509 0x43425844, 0xd17af83e, 0xa32c01cc, 0x0d8e9665, 0xe6dc17c2, 0x00000001, 0x0000010c, 0x00000003,
28510 0x0000002c, 0x0000003c, 0x0000009c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28511 0x00000058, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28512 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
28513 0x65677261, 0x56530074, 0x7065445f, 0x72476874, 0x65746165, 0x75714572, 0xab006c61, 0x58454853,
28514 0x00000068, 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
28515 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x00026001, 0x08000036, 0x001020f2, 0x00000000,
28516 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00026001, 0x0020800a,
28517 0x00000000, 0x00000000, 0x0100003e,
28519 static const struct shader ps_depth_ge = {ps_depth_ge_code, sizeof(ps_depth_ge_code)};
28520 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
28521 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28522 static const struct
28524 const struct shader *ps;
28525 float vs_depth;
28526 float ps_depth;
28527 BOOL passes_depth_test;
28529 tests[] =
28531 {&ps_depth_le, 0.7f, 0.7f, TRUE},
28532 {&ps_depth_le, 0.7f, 0.4f, FALSE},
28533 {&ps_depth_le, 0.4f, 0.4f, FALSE},
28534 /* {&ps_depth_le, 0.4f, 0.6f, FALSE}, undefined result */
28535 {&ps_depth_ge, 0.7f, 0.7f, TRUE},
28536 /* {&ps_depth_ge, 0.7f, 0.4f, TRUE}, undefined result */
28537 {&ps_depth_ge, 0.4f, 0.4f, FALSE},
28538 {&ps_depth_ge, 0.4f, 0.6f, TRUE},
28541 if (!init_test_context(&test_context, &feature_level))
28542 return;
28544 device = test_context.device;
28545 context = test_context.immediate_context;
28547 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_depth), NULL);
28549 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28550 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
28551 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28552 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
28553 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
28554 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28555 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
28556 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
28558 depth_stencil_desc.DepthEnable = TRUE;
28559 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
28560 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_GREATER_EQUAL;
28561 depth_stencil_desc.StencilEnable = FALSE;
28562 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
28563 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
28565 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
28566 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
28567 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
28569 ps = NULL;
28570 current_shader = NULL;
28571 for (i = 0; i < ARRAY_SIZE(tests); ++i)
28573 if (current_shader != tests[i].ps)
28575 if (ps)
28576 ID3D11PixelShader_Release(ps);
28578 current_shader = tests[i].ps;
28579 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
28580 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
28581 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
28584 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28585 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
28586 ps_depth.x = tests[i].ps_depth;
28587 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_depth, 0, 0);
28588 draw_quad_z(&test_context, tests[i].vs_depth);
28590 expected_color = tests[i].passes_depth_test ? 0xff00ff00 : 0xffffffff;
28591 expected_depth = tests[i].passes_depth_test ? max(tests[i].vs_depth, tests[i].ps_depth) : 0.5f;
28592 check_texture_color(test_context.backbuffer, expected_color, 0);
28593 check_texture_float(texture, expected_depth, 1);
28596 ID3D11Buffer_Release(cb);
28597 ID3D11PixelShader_Release(ps);
28598 ID3D11DepthStencilView_Release(dsv);
28599 ID3D11DepthStencilState_Release(depth_stencil_state);
28600 ID3D11Texture2D_Release(texture);
28601 release_test_context(&test_context);
28604 static void test_format_compatibility(void)
28606 ID3D11Texture2D *dst_texture, *src_texture;
28607 D3D11_SUBRESOURCE_DATA resource_data;
28608 D3D11_TEXTURE2D_DESC texture_desc;
28609 ID3D11DeviceContext *context;
28610 struct resource_readback rb;
28611 DWORD colour, expected;
28612 ID3D11Device *device;
28613 unsigned int i, j;
28614 ULONG refcount;
28615 HRESULT hr;
28617 static const struct
28619 DXGI_FORMAT src_format;
28620 DXGI_FORMAT dst_format;
28621 size_t texel_size;
28622 BOOL success;
28623 BOOL src_ds;
28624 BOOL dst_ds;
28626 test_data[] =
28628 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
28629 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
28630 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
28631 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
28632 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
28633 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
28634 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
28635 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
28636 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
28637 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
28638 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
28639 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
28640 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
28641 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
28642 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
28643 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_TYPELESS, 4, TRUE},
28644 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_FLOAT, 4, TRUE},
28645 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_UINT, 4, TRUE},
28646 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_SINT, 4, TRUE},
28647 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, FALSE},
28648 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_B8G8R8A8_TYPELESS, 4, FALSE},
28649 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R16G16_TYPELESS, 4, FALSE},
28650 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
28651 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
28652 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
28653 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
28654 {DXGI_FORMAT_D16_UNORM, DXGI_FORMAT_R16_UNORM, 2, TRUE, TRUE},
28655 {DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_D16_UNORM, 2, TRUE, FALSE, TRUE},
28656 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_TYPELESS, 2, TRUE, TRUE},
28657 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_TYPELESS, 2, TRUE, FALSE, TRUE},
28659 static const DWORD initial_data[16] = {0};
28660 static const DWORD bitmap_data[] =
28662 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28663 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28664 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28665 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28668 if (!(device = create_device(NULL)))
28670 skip("Failed to create device.\n");
28671 return;
28673 ID3D11Device_GetImmediateContext(device, &context);
28675 texture_desc.Height = 4;
28676 texture_desc.MipLevels = 1;
28677 texture_desc.ArraySize = 1;
28678 texture_desc.SampleDesc.Count = 1;
28679 texture_desc.SampleDesc.Quality = 0;
28680 texture_desc.CPUAccessFlags = 0;
28681 texture_desc.MiscFlags = 0;
28683 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
28685 unsigned int x, y, texel_dwords;
28686 BOOL broken = FALSE;
28687 D3D11_BOX box;
28689 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
28690 texture_desc.Format = test_data[i].src_format;
28691 texture_desc.Usage = test_data[i].src_ds ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE;
28692 texture_desc.BindFlags = test_data[i].src_ds ? D3D11_BIND_DEPTH_STENCIL : D3D11_BIND_SHADER_RESOURCE;
28694 resource_data.pSysMem = bitmap_data;
28695 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
28696 resource_data.SysMemSlicePitch = 0;
28698 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
28699 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
28701 texture_desc.Format = test_data[i].dst_format;
28702 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28703 texture_desc.BindFlags = test_data[i].dst_ds ? D3D11_BIND_DEPTH_STENCIL : D3D11_BIND_SHADER_RESOURCE;
28705 resource_data.pSysMem = initial_data;
28707 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
28708 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
28710 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
28711 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0, 1, 1, 0,
28712 (ID3D11Resource *)src_texture, 0, &box);
28714 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
28715 get_texture_readback(dst_texture, 0, &rb);
28716 colour = get_readback_color(&rb, 0, 0, 0);
28717 if (test_data[i].src_format == DXGI_FORMAT_R9G9B9E5_SHAREDEXP && colour == bitmap_data[0])
28719 win_skip("Broken destination offset for %#x -> %#x copy.\n",
28720 test_data[i].src_format, test_data[i].dst_format);
28721 broken = TRUE;
28723 for (j = 0; j < ARRAY_SIZE(bitmap_data) && !broken; ++j)
28725 x = j % 4;
28726 y = j / 4;
28727 colour = get_readback_color(&rb, x, y, 0);
28728 expected = test_data[i].success && !test_data[i].src_ds && !test_data[i].dst_ds
28729 && x >= texel_dwords && y ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
28730 todo_wine_if((test_data[i].src_ds || test_data[i].dst_ds) && colour)
28731 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
28732 i, colour, x, y, expected);
28734 release_resource_readback(&rb);
28736 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
28738 get_texture_readback(dst_texture, 0, &rb);
28739 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
28741 x = j % 4;
28742 y = j / 4;
28743 colour = get_readback_color(&rb, x, y, 0);
28744 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
28745 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
28746 i, colour, x, y, expected);
28748 release_resource_readback(&rb);
28750 ID3D11Texture2D_Release(dst_texture);
28751 ID3D11Texture2D_Release(src_texture);
28754 ID3D11DeviceContext_Release(context);
28755 refcount = ID3D11Device_Release(device);
28756 ok(!refcount, "Device has %u references left.\n", refcount);
28759 static void test_compressed_format_compatibility(const D3D_FEATURE_LEVEL feature_level)
28761 const struct format_info *src_format, *dst_format;
28762 unsigned int row_block_count, row_count, i, j, k;
28763 ID3D11Texture2D *src_texture, *dst_texture;
28764 BOOL supported, broken_dst_offset = FALSE;
28765 D3D11_SUBRESOURCE_DATA resource_data;
28766 D3D11_TEXTURE2D_DESC texture_desc;
28767 ID3D11DeviceContext *context;
28768 unsigned int block_idx, x, y;
28769 struct resource_readback rb;
28770 DWORD colour, expected;
28771 ID3D11Device *device;
28772 UINT format_support;
28773 const BYTE *row;
28774 ULONG refcount;
28775 D3D11_BOX box;
28776 HRESULT hr;
28777 const struct device_desc device_desc =
28779 .feature_level = &feature_level,
28782 static const struct format_info
28784 DXGI_FORMAT id;
28785 size_t block_size;
28786 size_t block_edge;
28787 BOOL supported;
28788 BOOL skip_if_broken;
28790 formats[] =
28792 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 16, 1, TRUE},
28793 {DXGI_FORMAT_R32G32B32A32_FLOAT, 16, 1, TRUE},
28794 {DXGI_FORMAT_R32G32B32A32_UINT, 16, 1, TRUE},
28795 {DXGI_FORMAT_R32G32B32A32_SINT, 16, 1, TRUE},
28797 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 8, 1, TRUE},
28798 {DXGI_FORMAT_R16G16B16A16_FLOAT, 8, 1, TRUE},
28799 {DXGI_FORMAT_R16G16B16A16_UNORM, 8, 1, TRUE},
28800 {DXGI_FORMAT_R16G16B16A16_UINT, 8, 1, TRUE},
28801 {DXGI_FORMAT_R16G16B16A16_SNORM, 8, 1, TRUE},
28802 {DXGI_FORMAT_R16G16B16A16_SINT, 8, 1, TRUE},
28804 {DXGI_FORMAT_R32G32_TYPELESS, 8, 1, TRUE},
28805 {DXGI_FORMAT_R32G32_FLOAT, 8, 1, TRUE},
28806 {DXGI_FORMAT_R32G32_UINT, 8, 1, TRUE},
28807 {DXGI_FORMAT_R32G32_SINT, 8, 1, TRUE},
28809 {DXGI_FORMAT_R32_TYPELESS, 4, 1, TRUE},
28810 {DXGI_FORMAT_R32_FLOAT, 4, 1, TRUE},
28811 {DXGI_FORMAT_R32_UINT, 4, 1, TRUE},
28812 {DXGI_FORMAT_R32_SINT, 4, 1, TRUE},
28814 {DXGI_FORMAT_R32G8X24_TYPELESS, 8, 1},
28815 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 4, 1},
28816 {DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, 1},
28817 {DXGI_FORMAT_R16G16_TYPELESS, 4, 1},
28818 {DXGI_FORMAT_R24G8_TYPELESS, 4, 1},
28819 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 4, 1},
28820 {DXGI_FORMAT_B8G8R8A8_TYPELESS, 4, 1},
28821 {DXGI_FORMAT_R8G8_TYPELESS, 2, 1},
28822 {DXGI_FORMAT_R16_TYPELESS, 2, 1},
28823 {DXGI_FORMAT_R8_TYPELESS, 1, 1},
28825 {DXGI_FORMAT_BC1_TYPELESS, 8, 4},
28826 {DXGI_FORMAT_BC1_UNORM, 8, 4},
28827 {DXGI_FORMAT_BC1_UNORM_SRGB, 8, 4},
28829 {DXGI_FORMAT_BC2_TYPELESS, 16, 4},
28830 {DXGI_FORMAT_BC2_UNORM, 16, 4},
28831 {DXGI_FORMAT_BC2_UNORM_SRGB, 16, 4},
28833 {DXGI_FORMAT_BC3_TYPELESS, 16, 4},
28834 {DXGI_FORMAT_BC3_UNORM, 16, 4},
28835 {DXGI_FORMAT_BC3_UNORM_SRGB, 16, 4},
28837 {DXGI_FORMAT_BC4_TYPELESS, 8, 4},
28838 {DXGI_FORMAT_BC4_UNORM, 8, 4},
28839 {DXGI_FORMAT_BC4_SNORM, 8, 4},
28841 {DXGI_FORMAT_BC5_TYPELESS, 16, 4},
28842 {DXGI_FORMAT_BC5_UNORM, 16, 4},
28843 {DXGI_FORMAT_BC5_SNORM, 16, 4},
28845 {DXGI_FORMAT_BC6H_TYPELESS, 16, 4, FALSE, TRUE},
28846 {DXGI_FORMAT_BC6H_UF16, 16, 4, FALSE, TRUE},
28847 {DXGI_FORMAT_BC6H_SF16, 16, 4, FALSE, TRUE},
28849 {DXGI_FORMAT_BC7_TYPELESS, 16, 4, FALSE, TRUE},
28850 {DXGI_FORMAT_BC7_UNORM, 16, 4, FALSE, TRUE},
28851 {DXGI_FORMAT_BC7_UNORM_SRGB, 16, 4, FALSE, TRUE},
28854 static const DWORD initial_data[64] = {0};
28855 static const DWORD texture_data[] =
28857 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28858 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28859 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28860 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28862 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28863 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28864 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28865 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28867 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
28868 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
28869 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
28870 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
28872 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
28873 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
28874 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
28875 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
28878 if (!(device = create_device(&device_desc)))
28880 skip("Failed to create device for feature level %#x.\n", feature_level);
28881 return;
28883 ID3D11Device_GetImmediateContext(device, &context);
28885 row_block_count = 4;
28887 texture_desc.MipLevels = 1;
28888 texture_desc.ArraySize = 1;
28889 texture_desc.SampleDesc.Count = 1;
28890 texture_desc.SampleDesc.Quality = 0;
28891 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
28892 texture_desc.CPUAccessFlags = 0;
28893 texture_desc.MiscFlags = 0;
28895 resource_data.SysMemSlicePitch = 0;
28897 for (i = 0; i < ARRAY_SIZE(formats); ++i)
28899 src_format = &formats[i];
28900 row_count = sizeof(texture_data) / (row_block_count * src_format->block_size);
28901 texture_desc.Width = row_block_count * src_format->block_edge;
28902 texture_desc.Height = row_count * src_format->block_edge;
28903 texture_desc.Format = src_format->id;
28904 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
28906 resource_data.pSysMem = texture_data;
28907 resource_data.SysMemPitch = row_block_count * src_format->block_size;
28909 hr = ID3D11Device_CheckFormatSupport(device, src_format->id, &format_support);
28910 if (hr == E_FAIL || !(format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
28911 continue;
28913 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
28914 ok(hr == S_OK, "Source format %#x: Got unexpected hr %#x.\n", src_format->id, hr);
28916 for (j = 0; j < ARRAY_SIZE(formats); ++j)
28918 dst_format = &formats[j];
28920 if ((src_format->block_edge == 1 && dst_format->block_edge == 1)
28921 || (src_format->block_edge != 1 && dst_format->block_edge != 1))
28922 continue;
28924 hr = ID3D11Device_CheckFormatSupport(device, dst_format->id, &format_support);
28925 if (hr == E_FAIL || !(format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
28926 continue;
28928 supported = ((src_format->block_edge != 1 && dst_format->supported)
28929 || (src_format->supported && dst_format->block_edge != 1))
28930 && src_format->block_size == dst_format->block_size
28931 && feature_level >= D3D_FEATURE_LEVEL_10_1;
28933 /* These cause the device to be removed on some versions of Windows. */
28934 if (supported && broken_dst_offset && (src_format->skip_if_broken || dst_format->skip_if_broken))
28936 win_skip("Skipping %#x -> %#x tests because of broken destination offset.\n",
28937 src_format->id, dst_format->id);
28938 continue;
28941 row_count = sizeof(initial_data) / (row_block_count * dst_format->block_size);
28942 texture_desc.Width = row_block_count * dst_format->block_edge;
28943 texture_desc.Height = row_count * dst_format->block_edge;
28944 texture_desc.Format = dst_format->id;
28945 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28947 resource_data.pSysMem = initial_data;
28948 resource_data.SysMemPitch = row_block_count * dst_format->block_size;
28950 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
28951 ok(hr == S_OK, "%#x -> %#x: Got unexpected hr %#x.\n", src_format->id, dst_format->id, hr);
28953 if (supported && broken_dst_offset)
28955 win_skip("Skipping %#x -> %#x CopySubresourceRegion() test because of broken destination offset.\n",
28956 src_format->id, dst_format->id);
28958 else
28960 set_box(&box, 0, 0, 0, src_format->block_edge, src_format->block_edge, 1);
28961 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
28962 dst_format->block_edge, dst_format->block_edge, 0, (ID3D11Resource *)src_texture, 0, &box);
28963 get_texture_readback(dst_texture, 0, &rb);
28964 colour = get_readback_color(&rb, 0, 0, 0);
28965 if (supported && colour == texture_data[0])
28967 win_skip("Detected broken destination offset for %#x -> %#x copy.\n",
28968 src_format->id, dst_format->id);
28969 broken_dst_offset = TRUE;
28971 for (k = 0; k < ARRAY_SIZE(texture_data) && (!supported || !broken_dst_offset); ++k)
28973 block_idx = (k * sizeof(colour)) / dst_format->block_size;
28974 x = block_idx % row_block_count;
28975 y = block_idx / row_block_count;
28977 row = rb.map_desc.pData;
28978 row += y * rb.map_desc.RowPitch;
28979 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
28981 if (supported && x == 1 && y == 1)
28982 expected = texture_data[k - ((row_block_count + 1) * dst_format->block_size) / sizeof(colour)];
28983 else
28984 expected = initial_data[k];
28985 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
28986 src_format->id, dst_format->id, colour, k, expected);
28987 if (colour != expected)
28988 break;
28990 release_resource_readback(&rb);
28993 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
28994 get_texture_readback(dst_texture, 0, &rb);
28995 for (k = 0; k < ARRAY_SIZE(texture_data); ++k)
28997 block_idx = (k * sizeof(colour)) / dst_format->block_size;
28998 y = block_idx / row_block_count;
29000 row = rb.map_desc.pData;
29001 row += y * rb.map_desc.RowPitch;
29002 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
29004 if (supported)
29005 expected = texture_data[k];
29006 else
29007 expected = initial_data[k];
29008 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
29009 src_format->id, dst_format->id, colour, k, expected);
29010 if (colour != expected)
29011 break;
29013 release_resource_readback(&rb);
29015 ID3D11Texture2D_Release(dst_texture);
29018 ID3D11Texture2D_Release(src_texture);
29021 ID3D11DeviceContext_Release(context);
29022 refcount = ID3D11Device_Release(device);
29023 ok(!refcount, "Device has %u references left.\n", refcount);
29026 static void check_clip_distance(struct d3d11_test_context *test_context, ID3D11Buffer *vb)
29028 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29029 struct vertex
29031 float clip_distance0;
29032 float clip_distance1;
29035 ID3D11DeviceContext *context = test_context->immediate_context;
29036 struct resource_readback rb;
29037 struct vertex vertices[4];
29038 unsigned int i;
29039 RECT rect;
29041 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29042 vertices[i].clip_distance0 = 1.0f;
29043 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29044 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
29045 ID3D11DeviceContext_Draw(context, 4, 0);
29046 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
29048 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29049 vertices[i].clip_distance0 = 0.0f;
29050 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29051 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
29052 ID3D11DeviceContext_Draw(context, 4, 0);
29053 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
29055 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29056 vertices[i].clip_distance0 = -1.0f;
29057 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29058 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
29059 ID3D11DeviceContext_Draw(context, 4, 0);
29060 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
29062 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29063 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
29064 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29065 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
29066 ID3D11DeviceContext_Draw(context, 4, 0);
29067 get_texture_readback(test_context->backbuffer, 0, &rb);
29068 SetRect(&rect, 0, 0, 320, 480);
29069 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
29070 SetRect(&rect, 320, 0, 320, 480);
29071 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29072 release_resource_readback(&rb);
29074 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29075 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
29076 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29077 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
29078 ID3D11DeviceContext_Draw(context, 4, 0);
29079 get_texture_readback(test_context->backbuffer, 0, &rb);
29080 SetRect(&rect, 0, 0, 640, 240);
29081 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
29082 SetRect(&rect, 0, 240, 640, 240);
29083 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29084 release_resource_readback(&rb);
29087 static void test_clip_distance(void)
29089 struct d3d11_test_context test_context;
29090 ID3D11Buffer *vs_cb, *tess_cb, *gs_cb;
29091 D3D_FEATURE_LEVEL feature_level;
29092 ID3D11DomainShader *ds = NULL;
29093 ID3D11DeviceContext *context;
29094 struct resource_readback rb;
29095 unsigned int offset, stride;
29096 ID3D11HullShader *hs = NULL;
29097 ID3D11GeometryShader *gs;
29098 ID3D11Device *device;
29099 ID3D11Buffer *vb;
29100 unsigned int i;
29101 HRESULT hr;
29102 RECT rect;
29104 static const DWORD vs_code[] =
29106 #if 0
29107 bool use_constant;
29108 float clip_distance;
29110 struct input
29112 float4 position : POSITION;
29113 float distance0 : CLIP_DISTANCE0;
29114 float distance1 : CLIP_DISTANCE1;
29117 struct vertex
29119 float4 position : SV_POSITION;
29120 float user_clip : CLIP_DISTANCE;
29121 float clip : SV_ClipDistance;
29124 void main(input vin, out vertex vertex)
29126 vertex.position = vin.position;
29127 vertex.user_clip = vin.distance0;
29128 vertex.clip = vin.distance0;
29129 if (use_constant)
29130 vertex.clip = clip_distance;
29132 #endif
29133 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
29134 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
29135 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
29136 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
29137 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
29138 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
29139 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
29140 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
29141 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
29142 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
29143 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
29144 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
29145 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
29146 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
29147 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
29149 static const DWORD vs_multiple_code[] =
29151 #if 0
29152 bool use_constant;
29153 float clip_distance0;
29154 float clip_distance1;
29156 struct input
29158 float4 position : POSITION;
29159 float distance0 : CLIP_DISTANCE0;
29160 float distance1 : CLIP_DISTANCE1;
29163 struct vertex
29165 float4 position : SV_POSITION;
29166 float user_clip : CLIP_DISTANCE;
29167 float2 clip : SV_ClipDistance;
29170 void main(input vin, out vertex vertex)
29172 vertex.position = vin.position;
29173 vertex.user_clip = vin.distance0;
29174 vertex.clip.x = vin.distance0;
29175 if (use_constant)
29176 vertex.clip.x = clip_distance0;
29177 vertex.clip.y = vin.distance1;
29178 if (use_constant)
29179 vertex.clip.y = clip_distance1;
29181 #endif
29182 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
29183 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
29184 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
29185 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
29186 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
29187 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
29188 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
29189 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
29190 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
29191 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
29192 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
29193 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
29194 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
29195 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
29196 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
29197 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
29198 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
29200 #if 0
29201 bool use_constant;
29202 float clip_distance0;
29203 float clip_distance1;
29204 float tessellation_factor;
29206 struct vertex
29208 float4 position : SV_POSITION;
29209 float user_clip : CLIP_DISTANCE;
29210 float clip : SV_ClipDistance;
29213 struct patch_constant_data
29215 float edges[4] : SV_TessFactor;
29216 float inside[2] : SV_InsideTessFactor;
29219 patch_constant_data patch_constant()
29221 patch_constant_data output;
29223 output.edges[0] = tessellation_factor;
29224 output.edges[1] = tessellation_factor;
29225 output.edges[2] = tessellation_factor;
29226 output.edges[3] = tessellation_factor;
29227 output.inside[0] = tessellation_factor;
29228 output.inside[1] = tessellation_factor;
29230 return output;
29233 [domain("quad")]
29234 [outputcontrolpoints(4)]
29235 [outputtopology("triangle_cw")]
29236 [partitioning("pow2")]
29237 [patchconstantfunc("patch_constant")]
29238 vertex hs_main(InputPatch<vertex, 4> input,
29239 uint i : SV_OutputControlPointID)
29241 vertex o;
29242 o.position = input[i].position;
29243 o.user_clip = input[i].user_clip;
29244 o.clip = input[i].user_clip;
29245 return o;
29248 float4 interpolate_vec(float4 a, float4 b, float4 c, float4 d, float2 tess_coord)
29250 float4 e = lerp(a, b, tess_coord.x);
29251 float4 f = lerp(c, d, tess_coord.x);
29252 return lerp(e, f, tess_coord.y);
29255 float interpolate(float a, float b, float c, float d, float2 tess_coord)
29257 float e = lerp(a, b, tess_coord.x);
29258 float f = lerp(c, d, tess_coord.x);
29259 return lerp(e, f, tess_coord.y);
29262 [domain("quad")]
29263 vertex ds_main(patch_constant_data input,
29264 float2 tess_coord : SV_DomainLocation,
29265 const OutputPatch<vertex, 4> patch)
29267 vertex output;
29269 output.position = interpolate_vec(patch[0].position, patch[1].position,
29270 patch[2].position, patch[3].position, tess_coord);
29271 output.user_clip = interpolate(patch[0].user_clip, patch[1].user_clip,
29272 patch[2].user_clip, patch[3].user_clip, tess_coord);
29273 output.clip = interpolate(patch[0].clip, patch[1].clip,
29274 patch[2].clip, patch[3].clip, tess_coord);
29275 if (use_constant)
29276 output.clip = clip_distance0;
29278 return output;
29280 #endif
29281 static const DWORD hs_code[] =
29283 0x43425844, 0x5a6d7564, 0x5f30a6c9, 0x2cf3b848, 0x5b4c6dca, 0x00000001, 0x00000414, 0x00000004,
29284 0x00000030, 0x000000b4, 0x00000138, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
29285 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
29286 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
29287 0x00000002, 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
29288 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003,
29289 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c,
29290 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002,
29291 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f,
29292 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc,
29293 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
29294 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
29295 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
29296 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
29297 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
29298 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
29299 0x00000210, 0x00030050, 0x00000084, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01001096,
29300 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x01000072, 0x0200005f,
29301 0x00016000, 0x0400005f, 0x002010f2, 0x00000004, 0x00000000, 0x0400005f, 0x00201012, 0x00000004,
29302 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
29303 0x00102012, 0x00000002, 0x02000068, 0x00000001, 0x04000036, 0x00100012, 0x00000000, 0x00016001,
29304 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x07000036,
29305 0x00102012, 0x00000001, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x07000036, 0x00102012,
29306 0x00000002, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x0100003e, 0x01000073, 0x02000099,
29307 0x00000004, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x0000000b, 0x04000067,
29308 0x00102012, 0x00000001, 0x0000000c, 0x04000067, 0x00102012, 0x00000002, 0x0000000d, 0x04000067,
29309 0x00102012, 0x00000003, 0x0000000e, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000000,
29310 0x00000004, 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, 0x00902012, 0x0010000a,
29311 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002,
29312 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000004, 0x0000000f, 0x04000067, 0x00102012,
29313 0x00000005, 0x00000010, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000004, 0x00000002,
29314 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x08000036, 0x00d02012, 0x00000004, 0x0010000a,
29315 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e,
29317 static const DWORD ds_code[] =
29319 0x43425844, 0xc54dc020, 0x063a9622, 0x6f649eb9, 0xceb1dd36, 0x00000001, 0x0000054c, 0x00000004,
29320 0x00000030, 0x000000b4, 0x00000178, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
29321 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
29322 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
29323 0x00000002, 0x00000101, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
29324 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc, 0x00000006,
29325 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000001, 0x00000098,
29326 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000001, 0x00000098, 0x00000002, 0x0000000b,
29327 0x00000003, 0x00000002, 0x00000001, 0x00000098, 0x00000003, 0x0000000b, 0x00000003, 0x00000003,
29328 0x00000001, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000001, 0x000000a6,
29329 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
29330 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000007c,
29331 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
29332 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000,
29333 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43,
29334 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x58454853,
29335 0x00000348, 0x00040050, 0x000000d2, 0x01002093, 0x01001895, 0x0100086a, 0x04000059, 0x00208e46,
29336 0x00000000, 0x00000001, 0x0200005f, 0x0001c032, 0x0400005f, 0x002190f2, 0x00000004, 0x00000000,
29337 0x0400005f, 0x00219012, 0x00000004, 0x00000001, 0x0400005f, 0x00219012, 0x00000004, 0x00000002,
29338 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067,
29339 0x00102012, 0x00000002, 0x00000002, 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000,
29340 0x80219e46, 0x00000041, 0x00000002, 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032,
29341 0x001000f2, 0x00000000, 0x0001c006, 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000,
29342 0x0a000000, 0x001000f2, 0x00000001, 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46,
29343 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001,
29344 0x00219e46, 0x00000000, 0x00000000, 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
29345 0x80100e46, 0x00000041, 0x00000001, 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46,
29346 0x00000000, 0x00100e46, 0x00000001, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041,
29347 0x00000002, 0x00000001, 0x0021900a, 0x00000003, 0x00000001, 0x09000032, 0x00100012, 0x00000000,
29348 0x0001c00a, 0x0010000a, 0x00000000, 0x0021900a, 0x00000002, 0x00000001, 0x0a000000, 0x00100022,
29349 0x00000000, 0x8021900a, 0x00000041, 0x00000000, 0x00000001, 0x0021900a, 0x00000001, 0x00000001,
29350 0x09000032, 0x00100022, 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000,
29351 0x00000001, 0x08000000, 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a,
29352 0x00000000, 0x08000032, 0x00102012, 0x00000001, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a,
29353 0x00000000, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041, 0x00000002, 0x00000002,
29354 0x0021900a, 0x00000003, 0x00000002, 0x09000032, 0x00100012, 0x00000000, 0x0001c00a, 0x0010000a,
29355 0x00000000, 0x0021900a, 0x00000002, 0x00000002, 0x0a000000, 0x00100022, 0x00000000, 0x8021900a,
29356 0x00000041, 0x00000000, 0x00000002, 0x0021900a, 0x00000001, 0x00000002, 0x09000032, 0x00100022,
29357 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000, 0x00000002, 0x08000000,
29358 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a, 0x00000000, 0x08000032,
29359 0x00100012, 0x00000000, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000, 0x0b000037,
29360 0x00102012, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
29361 0x0010000a, 0x00000000, 0x0100003e,
29363 static const DWORD gs_code[] =
29365 #if 0
29366 bool use_constant;
29367 float clip_distance;
29369 struct vertex
29371 float4 position : SV_POSITION;
29372 float user_clip : CLIP_DISTANCE;
29373 float clip : SV_ClipDistance;
29376 [maxvertexcount(3)]
29377 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
29379 vertex o;
29380 o = input[0];
29381 o.clip = input[0].user_clip;
29382 if (use_constant)
29383 o.clip = clip_distance;
29384 output.Append(o);
29385 o = input[1];
29386 o.clip = input[1].user_clip;
29387 if (use_constant)
29388 o.clip = clip_distance;
29389 output.Append(o);
29390 o = input[2];
29391 o.clip = input[2].user_clip;
29392 if (use_constant)
29393 o.clip = clip_distance;
29394 output.Append(o);
29396 #endif
29397 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
29398 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
29399 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
29400 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
29401 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
29402 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
29403 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
29404 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
29405 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
29406 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
29407 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
29408 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
29409 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
29410 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
29411 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
29412 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
29413 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
29414 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
29415 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
29416 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
29417 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
29418 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
29419 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
29420 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
29421 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
29422 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
29424 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
29426 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29427 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29428 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
29430 struct
29432 float clip_distance0;
29433 float clip_distance1;
29435 vertices[] =
29437 {1.0f, 1.0f},
29438 {1.0f, 1.0f},
29439 {1.0f, 1.0f},
29440 {1.0f, 1.0f},
29442 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29443 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
29444 struct
29446 BOOL use_constant;
29447 float clip_distance0;
29448 float clip_distance1;
29449 float tessellation_factor;
29450 } cb_data;
29452 if (!init_test_context(&test_context, NULL))
29453 return;
29454 device = test_context.device;
29455 context = test_context.immediate_context;
29456 feature_level = ID3D11Device_GetFeatureLevel(device);
29458 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
29459 vs_code, sizeof(vs_code), &test_context.input_layout);
29460 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
29462 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
29463 stride = sizeof(*vertices);
29464 offset = 0;
29465 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
29467 memset(&cb_data, 0, sizeof(cb_data));
29468 cb_data.tessellation_factor = 1.0f;
29469 vs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29470 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &vs_cb);
29471 tess_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29472 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &tess_cb);
29473 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, 1, &tess_cb);
29474 gs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29475 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &gs_cb);
29477 /* vertex shader */
29478 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29479 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29480 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29482 check_clip_distance(&test_context, vb);
29484 cb_data.use_constant = TRUE;
29485 cb_data.clip_distance0 = -1.0f;
29486 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29488 /* tessellation shaders */
29489 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
29491 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
29493 hr = ID3D11Device_CreateHullShader(device, hs_code, sizeof(hs_code), NULL, &hs);
29494 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
29495 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
29496 hr = ID3D11Device_CreateDomainShader(device, ds_code, sizeof(ds_code), NULL, &ds);
29497 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
29498 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
29500 check_clip_distance(&test_context, vb);
29502 cb_data.use_constant = FALSE;
29503 cb_data.tessellation_factor = 2.0f;
29504 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
29506 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29507 vertices[i].clip_distance0 = 1.0f;
29508 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29509 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29510 ID3D11DeviceContext_Draw(context, 4, 0);
29511 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29513 cb_data.use_constant = TRUE;
29514 cb_data.clip_distance0 = -1.0f;
29515 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
29517 else
29519 skip("Tessellation shaders are not supported.\n");
29522 /* geometry shader */
29523 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
29524 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
29525 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
29527 check_clip_distance(&test_context, vb);
29529 cb_data.use_constant = TRUE;
29530 cb_data.clip_distance0 = 1.0f;
29531 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
29532 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29533 ID3D11DeviceContext_Draw(context, 4, 0);
29534 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29536 /* multiple clip distances */
29537 ID3D11DeviceContext_HSSetShader(context, NULL, NULL, 0);
29538 ID3D11DeviceContext_DSSetShader(context, NULL, NULL, 0);
29539 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
29541 cb_data.use_constant = FALSE;
29542 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29544 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29545 vertices[i].clip_distance0 = 1.0f;
29546 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29547 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29548 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29549 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29551 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29553 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
29554 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
29556 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29557 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29558 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29559 get_texture_readback(test_context.backbuffer, 0, &rb);
29560 SetRect(&rect, 0, 0, 320, 240);
29561 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
29562 SetRect(&rect, 0, 240, 320, 480);
29563 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29564 SetRect(&rect, 320, 0, 640, 480);
29565 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29566 release_resource_readback(&rb);
29568 cb_data.use_constant = TRUE;
29569 cb_data.clip_distance0 = 0.0f;
29570 cb_data.clip_distance1 = 0.0f;
29571 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29572 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29573 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29574 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29576 if (hs)
29577 ID3D11HullShader_Release(hs);
29578 if (ds)
29579 ID3D11DomainShader_Release(ds);
29580 ID3D11GeometryShader_Release(gs);
29581 ID3D11Buffer_Release(vb);
29582 ID3D11Buffer_Release(vs_cb);
29583 ID3D11Buffer_Release(tess_cb);
29584 ID3D11Buffer_Release(gs_cb);
29585 release_test_context(&test_context);
29588 static void test_combined_clip_and_cull_distances(void)
29590 struct d3d11_test_context test_context;
29591 ID3D11DeviceContext *context;
29592 struct resource_readback rb;
29593 unsigned int offset, stride;
29594 ID3D11Device *device;
29595 unsigned int i, j, k;
29596 ID3D11Buffer *vb;
29597 HRESULT hr;
29599 static const DWORD vs_code[] =
29601 #if 0
29602 struct input
29604 float4 position : POSITION;
29605 float clip0 : CLIP_DISTANCE0;
29606 float clip1 : CLIP_DISTANCE1;
29607 float clip2 : CLIP_DISTANCE2;
29608 float clip3 : CLIP_DISTANCE3;
29609 float cull0 : CULL_DISTANCE0;
29610 float cull1 : CULL_DISTANCE1;
29611 float cull2 : CULL_DISTANCE2;
29612 float cull3 : CULL_DISTANCE3;
29615 struct vertex
29617 float4 position : SV_Position;
29618 float3 clip0 : SV_ClipDistance1;
29619 float3 cull0 : SV_CullDistance1;
29620 float clip1 : SV_ClipDistance2;
29621 float cull1 : SV_CullDistance2;
29624 void main(input vin, out vertex vertex)
29626 vertex.position = vin.position;
29627 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
29628 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
29629 vertex.clip1 = vin.clip3;
29630 vertex.cull1 = vin.cull3;
29632 #endif
29633 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
29634 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
29635 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
29636 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
29637 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
29638 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
29639 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
29640 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
29641 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
29642 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
29643 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
29644 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
29645 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
29646 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
29647 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
29648 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
29649 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
29650 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
29651 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
29652 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
29653 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
29654 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
29655 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
29656 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
29657 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
29658 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
29659 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
29660 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
29662 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
29664 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29665 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29666 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
29667 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
29668 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
29669 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
29670 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
29671 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
29672 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
29674 struct
29676 float clip_distance[4];
29677 float cull_distance[4];
29679 vertices[4] =
29681 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29682 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29683 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29684 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29686 static const struct test
29688 float vertices[4];
29689 BOOL triangle_visible[2];
29691 cull_distance_tests[] =
29693 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29694 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29695 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29696 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29697 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
29698 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29699 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
29700 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29701 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
29703 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
29704 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29705 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29706 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
29707 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
29709 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
29711 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29712 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
29714 if (!init_test_context(&test_context, NULL))
29715 return;
29716 device = test_context.device;
29717 context = test_context.immediate_context;
29719 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
29720 vs_code, sizeof(vs_code), &test_context.input_layout);
29721 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
29723 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
29724 stride = sizeof(*vertices);
29725 offset = 0;
29726 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
29728 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29729 draw_color_quad(&test_context, &green);
29730 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29732 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
29734 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
29736 const struct test *test = &cull_distance_tests[j];
29737 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
29738 unsigned int color;
29740 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
29741 vertices[k].cull_distance[i] = test->vertices[k];
29742 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29744 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29745 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29747 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
29748 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
29750 if (expected_color[0] == expected_color[1])
29752 check_texture_color(test_context.backbuffer, *expected_color, 1);
29754 else
29756 get_texture_readback(test_context.backbuffer, 0, &rb);
29757 color = get_readback_color(&rb, 160, 240, 0);
29758 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
29759 color = get_readback_color(&rb, 480, 240, 0);
29760 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
29761 release_resource_readback(&rb);
29765 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29766 vertices[j].cull_distance[i] = 1.0f;
29769 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
29771 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29772 vertices[j].clip_distance[i] = -1.0f;
29773 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29775 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29776 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29777 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
29779 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29780 vertices[j].clip_distance[i] = 1.0f;
29783 memset(vertices, 0, sizeof(vertices));
29784 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29785 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29786 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29787 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29789 ID3D11Buffer_Release(vb);
29790 release_test_context(&test_context);
29793 static void test_generate_mips(void)
29795 static const DWORD ps_code[] =
29797 #if 0
29798 Texture2D t;
29799 SamplerState s;
29801 float4 main(float4 position : SV_POSITION) : SV_Target
29803 float2 p;
29805 p.x = position.x / 640.0f;
29806 p.y = position.y / 480.0f;
29807 return t.Sample(s, p);
29809 #endif
29810 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
29811 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29812 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
29813 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
29814 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
29815 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
29816 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
29817 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
29818 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
29819 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
29821 static const DWORD ps_code_3d[] =
29823 #if 0
29824 Texture3D t;
29825 SamplerState s;
29827 float4 main(float4 position : SV_POSITION) : SV_Target
29829 float3 p;
29831 p.x = position.x / 640.0f;
29832 p.y = position.y / 480.0f;
29833 p.z = 0.5f;
29834 return t.Sample(s, p);
29836 #endif
29837 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003,
29838 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29839 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
29840 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
29841 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040,
29842 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
29843 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
29844 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
29845 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000,
29846 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
29847 0x00000000, 0x0100003e,
29849 static const struct
29851 D3D11_RESOURCE_DIMENSION dim;
29852 D3D11_SRV_DIMENSION srv_dim;
29853 unsigned int array_size;
29855 resource_types[] =
29857 {D3D11_RESOURCE_DIMENSION_BUFFER, D3D11_SRV_DIMENSION_BUFFER, 1},
29858 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2D, 1},
29859 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2DARRAY, 4},
29860 {D3D11_RESOURCE_DIMENSION_TEXTURE3D, D3D11_SRV_DIMENSION_TEXTURE3D, 1},
29862 static const struct
29864 DXGI_FORMAT texture_format;
29865 UINT bind_flags;
29866 UINT misc_flags;
29867 BOOL null_srv;
29868 UINT base_level;
29869 BOOL expected_creation;
29870 BOOL expected_mips;
29872 tests[] =
29874 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
29875 0, TRUE, FALSE},
29876 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
29877 0, TRUE, FALSE},
29878 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
29879 0, TRUE, FALSE},
29880 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
29881 0, TRUE, FALSE},
29882 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29883 0, FALSE, FALSE},
29884 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29885 0, FALSE, FALSE},
29886 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29887 0, TRUE, TRUE},
29888 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29889 1, TRUE, TRUE},
29890 {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29891 1, TRUE, TRUE},
29892 {DXGI_FORMAT_R8G8B8A8_UINT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, TRUE,
29893 1, TRUE, FALSE},
29895 static const struct
29897 POINT pos;
29898 DWORD color;
29900 expected[] =
29902 {{200, 200}, 0xffff0000},
29903 {{280, 200}, 0xffff0000},
29904 {{360, 200}, 0xff00ff00},
29905 {{440, 200}, 0xff00ff00},
29906 {{200, 270}, 0xff0000ff},
29907 {{280, 270}, 0xff0000ff},
29908 {{360, 270}, 0xff000000},
29909 {{440, 270}, 0xff000000},
29911 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
29912 static const RECT r1 = {8, 8, 16, 16};
29913 static const RECT r2 = {16, 8, 24, 16};
29914 static const RECT r3 = {8, 16, 16, 24};
29915 static const RECT r4 = {16, 16, 24, 24};
29916 DWORD *data, *zero_data, color, expected_color;
29917 ID3D11ShaderResourceView *srv, *srv_sampling;
29918 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
29919 struct d3d11_test_context test_context;
29920 D3D11_TEXTURE2D_DESC texture2d_desc;
29921 D3D11_TEXTURE3D_DESC texture3d_desc;
29922 ID3D11SamplerState *sampler_state;
29923 D3D11_SAMPLER_DESC sampler_desc;
29924 D3D11_BUFFER_DESC buffer_desc;
29925 unsigned int i, j, k, x, y, z;
29926 ID3D11PixelShader *ps, *ps_3d;
29927 ID3D11DeviceContext *context;
29928 struct resource_readback rb;
29929 ID3D11Resource *resource;
29930 ID3D11Device *device;
29931 HRESULT hr;
29933 if (!init_test_context(&test_context, NULL))
29934 return;
29936 device = test_context.device;
29937 context = test_context.immediate_context;
29939 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
29940 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29942 hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps_3d);
29943 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29945 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
29946 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
29947 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
29948 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
29949 sampler_desc.MipLODBias = 0.0f;
29950 sampler_desc.MaxAnisotropy = 0;
29951 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
29952 sampler_desc.BorderColor[0] = 0.0f;
29953 sampler_desc.BorderColor[1] = 0.0f;
29954 sampler_desc.BorderColor[2] = 0.0f;
29955 sampler_desc.BorderColor[3] = 0.0f;
29956 sampler_desc.MinLOD = 0.0f;
29957 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
29959 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
29960 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
29961 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
29963 data = heap_alloc(sizeof(*data) * 32 * 32 * 32);
29965 for (z = 0; z < 32; ++z)
29967 for (y = 0; y < 32; ++y)
29969 for (x = 0; x < 32; ++x)
29971 DWORD *dst = &data[z * 32 * 32 + y * 32 + x];
29972 POINT pt;
29974 pt.x = x;
29975 pt.y = y;
29976 if (PtInRect(&r1, pt))
29977 *dst = 0xffff0000;
29978 else if (PtInRect(&r2, pt))
29979 *dst = 0xff00ff00;
29980 else if (PtInRect(&r3, pt))
29981 *dst = 0xff0000ff;
29982 else if (PtInRect(&r4, pt))
29983 *dst = 0xff000000;
29984 else
29985 *dst = 0xffffffff;
29990 zero_data = heap_alloc_zero(sizeof(*zero_data) * 16 * 16 * 16);
29992 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
29994 for (j = 0; j < ARRAY_SIZE(tests); ++j)
29996 unsigned int base_multiplier = 1u << tests[j].base_level;
29998 if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT)
30000 /* Testing this format seems to break the WARP device. */
30001 skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n");
30002 continue;
30005 switch (resource_types[i].dim)
30007 case D3D11_RESOURCE_DIMENSION_BUFFER:
30008 buffer_desc.ByteWidth = 32 * base_multiplier;
30009 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
30010 buffer_desc.BindFlags = tests[j].bind_flags;
30011 buffer_desc.CPUAccessFlags = 0;
30012 buffer_desc.MiscFlags = tests[j].misc_flags;
30013 buffer_desc.StructureByteStride = 0;
30015 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL,
30016 (ID3D11Buffer **)&resource);
30017 break;
30018 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
30019 texture2d_desc.Width = 32 * base_multiplier;
30020 texture2d_desc.Height = 32 * base_multiplier;
30021 texture2d_desc.MipLevels = 0;
30022 texture2d_desc.ArraySize = resource_types[i].array_size;
30023 texture2d_desc.Format = tests[j].texture_format;
30024 texture2d_desc.SampleDesc.Count = 1;
30025 texture2d_desc.SampleDesc.Quality = 0;
30026 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
30027 texture2d_desc.BindFlags = tests[j].bind_flags;
30028 texture2d_desc.CPUAccessFlags = 0;
30029 texture2d_desc.MiscFlags = tests[j].misc_flags;
30031 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL,
30032 (ID3D11Texture2D **)&resource);
30033 break;
30034 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
30035 texture3d_desc.Width = 32 * base_multiplier;
30036 texture3d_desc.Height = 32 * base_multiplier;
30037 texture3d_desc.Depth = 32 * base_multiplier;
30038 texture3d_desc.MipLevels = 0;
30039 texture3d_desc.Format = tests[j].texture_format;
30040 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
30041 texture3d_desc.BindFlags = tests[j].bind_flags;
30042 texture3d_desc.CPUAccessFlags = 0;
30043 texture3d_desc.MiscFlags = tests[j].misc_flags;
30045 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL,
30046 (ID3D11Texture3D **)&resource);
30047 break;
30048 default:
30049 break;
30051 if (tests[j].expected_creation && (resource_types[i].dim != D3D11_RESOURCE_DIMENSION_BUFFER
30052 || !(tests[j].misc_flags & D3D11_RESOURCE_MISC_GENERATE_MIPS)))
30054 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr);
30056 else
30058 ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded "
30059 "to create resource, hr %#x.\n", i, j, hr);
30060 continue;
30063 if (tests[j].null_srv)
30065 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
30067 else
30069 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
30070 srv_desc.ViewDimension = resource_types[i].srv_dim;
30071 switch (resource_types[i].srv_dim)
30073 case D3D11_SRV_DIMENSION_BUFFER:
30074 srv_desc.Buffer.ElementOffset = 0;
30075 srv_desc.Buffer.ElementWidth = 0;
30076 break;
30077 case D3D11_SRV_DIMENSION_TEXTURE2D:
30078 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level;
30079 srv_desc.Texture2D.MipLevels = ~0u;
30080 break;
30081 case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
30082 srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level;
30083 srv_desc.Texture2DArray.MipLevels = ~0u;
30084 srv_desc.Texture2DArray.FirstArraySlice = 0;
30085 srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size;
30086 break;
30087 case D3D11_SRV_DIMENSION_TEXTURE3D:
30088 srv_desc.Texture3D.MostDetailedMip = tests[j].base_level;
30089 srv_desc.Texture3D.MipLevels = ~0u;
30090 break;
30091 default:
30092 break;
30094 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
30096 if (resource_types[i].dim == D3D11_RESOURCE_DIMENSION_BUFFER)
30098 ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, "
30099 "hr %#x.\n", j, hr);
30100 ID3D11Resource_Release(resource);
30101 continue;
30103 else
30105 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create "
30106 "shader resource view, hr %#x.\n", i, j, hr);
30109 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level,
30110 NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
30111 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level + 1,
30112 NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16);
30114 ID3D11DeviceContext_GenerateMips(context, srv);
30116 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
30118 srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT
30119 ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
30120 srv_desc.ViewDimension = resource_types[i].dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D
30121 ? D3D11_SRV_DIMENSION_TEXTURE3D : D3D11_SRV_DIMENSION_TEXTURE2D;
30122 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1;
30123 srv_desc.Texture2D.MipLevels = ~0u;
30124 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
30125 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, "
30126 "hr %#x.\n", i, j, hr);
30127 ID3D11DeviceContext_PSSetShader(context, resource_types[i].dim
30128 == D3D11_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps, NULL, 0);
30129 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
30131 draw_quad(&test_context);
30133 get_texture_readback(test_context.backbuffer, 0, &rb);
30134 for (k = 0; k < ARRAY_SIZE(expected); ++k)
30136 color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y, 0);
30137 expected_color = tests[j].expected_mips ? expected[k].color : 0;
30138 ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) "
30139 "has color %08x, expected %08x.\n",
30140 i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color);
30142 release_resource_readback(&rb);
30144 ID3D11ShaderResourceView_Release(srv_sampling);
30145 ID3D11ShaderResourceView_Release(srv);
30146 ID3D11Resource_Release(resource);
30150 /* Test the effect of sRGB views. */
30151 for (y = 0; y < 32; ++y)
30153 for (x = 0; x < 32; ++x)
30155 DWORD *dst = &data[y * 32 + x];
30157 *dst = (x + y) % 2 * 0xffffffff;
30160 texture2d_desc.Width = 32;
30161 texture2d_desc.Height = 32;
30162 texture2d_desc.MipLevels = 0;
30163 texture2d_desc.ArraySize = 1;
30164 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
30165 texture2d_desc.SampleDesc.Count = 1;
30166 texture2d_desc.SampleDesc.Quality = 0;
30167 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
30168 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
30169 texture2d_desc.CPUAccessFlags = 0;
30170 texture2d_desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
30172 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D11Texture2D **)&resource);
30173 ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr);
30174 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
30175 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
30176 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
30177 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
30178 srv_desc.Texture2D.MostDetailedMip = 0;
30179 srv_desc.Texture2D.MipLevels = ~0u;
30180 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
30181 ID3D11DeviceContext_UpdateSubresource(context, resource,
30182 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
30184 ID3D11DeviceContext_GenerateMips(context, srv);
30186 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
30188 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
30189 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
30190 srv_desc.Texture2D.MostDetailedMip = 1;
30191 srv_desc.Texture2D.MipLevels = ~0u;
30192 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
30193 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
30194 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30195 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
30197 draw_quad(&test_context);
30199 get_texture_readback(test_context.backbuffer, 0, &rb);
30200 color = get_readback_color(&rb, 320, 240, 0);
30201 ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */
30202 "Unexpected color %08x.\n", color);
30203 release_resource_readback(&rb);
30205 ID3D11ShaderResourceView_Release(srv_sampling);
30206 ID3D11ShaderResourceView_Release(srv);
30208 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
30209 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
30210 srv_desc.Texture2D.MostDetailedMip = 0;
30211 srv_desc.Texture2D.MipLevels = ~0u;
30212 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
30213 ID3D11DeviceContext_UpdateSubresource(context, resource,
30214 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
30216 ID3D11DeviceContext_GenerateMips(context, srv);
30218 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
30220 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
30221 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
30222 srv_desc.Texture2D.MostDetailedMip = 1;
30223 srv_desc.Texture2D.MipLevels = ~0u;
30224 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
30225 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
30226 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30227 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
30229 draw_quad(&test_context);
30231 get_texture_readback(test_context.backbuffer, 0, &rb);
30232 check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1);
30233 release_resource_readback(&rb);
30235 ID3D11ShaderResourceView_Release(srv_sampling);
30236 ID3D11ShaderResourceView_Release(srv);
30238 ID3D11Resource_Release(resource);
30240 heap_free(zero_data);
30241 heap_free(data);
30243 ID3D11SamplerState_Release(sampler_state);
30244 ID3D11PixelShader_Release(ps_3d);
30245 ID3D11PixelShader_Release(ps);
30246 release_test_context(&test_context);
30249 static void test_alpha_to_coverage(void)
30251 struct ps_cb
30253 struct vec2 top;
30254 struct vec2 bottom;
30255 float alpha[2];
30256 float padding[2];
30259 struct d3d11_test_context test_context;
30260 ID3D11Texture2D *render_targets[3];
30261 D3D11_TEXTURE2D_DESC texture_desc;
30262 ID3D11Texture2D *readback_texture;
30263 ID3D11RenderTargetView *rtvs[3];
30264 ID3D11BlendState *blend_state;
30265 ID3D11DeviceContext *context;
30266 D3D11_BLEND_DESC blend_desc;
30267 struct resource_readback rb;
30268 UINT quality_level_count;
30269 ID3D11PixelShader *ps;
30270 struct ps_cb cb_data;
30271 ID3D11Device *device;
30272 ID3D11Buffer *cb;
30273 unsigned int i;
30274 HRESULT hr;
30275 RECT rect;
30277 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30278 static const DWORD ps_code[] =
30280 #if 0
30281 float2 top;
30282 float2 bottom;
30283 float alpha1;
30284 float alpha2;
30286 void main(float4 position : SV_Position,
30287 out float4 target0 : SV_Target0,
30288 out float4 target1 : SV_Target1,
30289 out float4 target2 : SV_Target2)
30291 float alpha = all(top <= position.xy) && all(position.xy <= bottom) ? 1.0f : 0.0f;
30292 target0 = float4(0.0f, 1.0f, 0.0f, alpha);
30293 target1 = float4(0.0f, 0.0f, 1.0f, alpha1);
30294 target2 = float4(0.0f, 1.0f, 0.0f, alpha2);
30296 #endif
30297 0x43425844, 0x771ff802, 0xca927279, 0x5bdd75ae, 0xf53cb31b, 0x00000001, 0x00000264, 0x00000003,
30298 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30299 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
30300 0x4e47534f, 0x0000005c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003,
30301 0x00000000, 0x0000000f, 0x00000050, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
30302 0x00000050, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x545f5653, 0x65677261,
30303 0xabab0074, 0x52444853, 0x00000198, 0x00000040, 0x00000066, 0x04000059, 0x00208e46, 0x00000000,
30304 0x00000002, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
30305 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001,
30306 0x0800001d, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00208046, 0x00000000, 0x00000000,
30307 0x07000001, 0x00100012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0800001d,
30308 0x00100062, 0x00000000, 0x00208ba6, 0x00000000, 0x00000000, 0x00101106, 0x00000000, 0x07000001,
30309 0x00100022, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x07000001, 0x00100012,
30310 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00102082, 0x00000000,
30311 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x08000036, 0x00102072, 0x00000000, 0x00004002,
30312 0x00000000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x00102072, 0x00000001, 0x00004002,
30313 0x00000000, 0x00000000, 0x3f800000, 0x00000000, 0x06000036, 0x00102082, 0x00000001, 0x0020800a,
30314 0x00000000, 0x00000001, 0x08000036, 0x00102072, 0x00000002, 0x00004002, 0x00000000, 0x3f800000,
30315 0x00000000, 0x00000000, 0x06000036, 0x00102082, 0x00000002, 0x0020801a, 0x00000000, 0x00000001,
30316 0x0100003e,
30318 static const DWORD colors[] = {0xff00ff00, 0xbfff0000, 0x8000ff00};
30320 if (!init_test_context(&test_context, NULL))
30321 return;
30322 device = test_context.device;
30323 context = test_context.immediate_context;
30325 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30326 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
30327 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30329 memset(&blend_desc, 0, sizeof(blend_desc));
30330 blend_desc.AlphaToCoverageEnable = TRUE;
30331 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
30332 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
30333 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
30334 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
30336 render_targets[0] = test_context.backbuffer;
30337 rtvs[0] = test_context.backbuffer_rtv;
30338 for (i = 1; i < ARRAY_SIZE(render_targets); ++i)
30340 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30341 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
30342 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30343 hr = ID3D11Device_CreateRenderTargetView(device,
30344 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
30345 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
30347 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
30349 cb_data.top.x = cb_data.top.y = 0.0f;
30350 cb_data.bottom.x = cb_data.bottom.y = 200.0f;
30351 cb_data.alpha[0] = 0.75;
30352 cb_data.alpha[1] = 0.5f;
30353 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
30354 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30356 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
30357 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
30358 draw_quad(&test_context);
30359 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
30361 DWORD expected_color;
30363 assert(i < ARRAY_SIZE(colors));
30364 expected_color = colors[i];
30365 get_texture_readback(render_targets[i], 0, &rb);
30366 SetRect(&rect, 0, 0, 200, 200);
30367 check_readback_data_color(&rb, &rect, expected_color, 1);
30368 SetRect(&rect, 200, 0, 640, 200);
30369 todo_wine
30370 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30371 SetRect(&rect, 0, 200, 640, 480);
30372 todo_wine
30373 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30374 release_resource_readback(&rb);
30376 if (i > 0)
30377 ID3D11Texture2D_Release(render_targets[i]);
30378 render_targets[i] = NULL;
30381 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30382 texture_desc.Format = DXGI_FORMAT_R16G16_UNORM;
30383 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[0]);
30384 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30385 hr = ID3D11Device_CreateRenderTargetView(device,
30386 (ID3D11Resource *)render_targets[0], NULL, &rtvs[0]);
30387 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
30388 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
30390 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
30391 draw_quad(&test_context);
30392 get_texture_readback(render_targets[0], 0, &rb);
30393 SetRect(&rect, 0, 0, 200, 200);
30394 check_readback_data_color(&rb, &rect, 0xffff0000, 1);
30395 SetRect(&rect, 200, 0, 640, 200);
30396 todo_wine
30397 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30398 SetRect(&rect, 0, 200, 640, 480);
30399 todo_wine
30400 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30401 release_resource_readback(&rb);
30403 ID3D11Texture2D_Release(render_targets[0]);
30404 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
30405 ID3D11RenderTargetView_Release(rtvs[i]);
30407 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30408 hr = ID3D11Device_CheckMultisampleQualityLevels(device,
30409 texture_desc.Format, 4, &quality_level_count);
30410 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
30411 if (!quality_level_count)
30413 skip("4xMSAA not supported.\n");
30414 goto done;
30416 texture_desc.SampleDesc.Count = 4;
30417 texture_desc.SampleDesc.Quality = 0;
30419 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
30421 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
30422 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30423 hr = ID3D11Device_CreateRenderTargetView(device,
30424 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
30425 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
30427 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
30429 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
30430 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
30431 draw_quad(&test_context);
30432 texture_desc.SampleDesc.Count = 1;
30433 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
30434 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30435 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
30437 DWORD expected_color;
30439 assert(i < ARRAY_SIZE(colors));
30440 expected_color = colors[i];
30442 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
30443 (ID3D11Resource *)render_targets[i], 0, texture_desc.Format);
30445 get_texture_readback(readback_texture, 0, &rb);
30446 SetRect(&rect, 0, 0, 200, 200);
30447 check_readback_data_color(&rb, &rect, expected_color, 1);
30448 SetRect(&rect, 200, 0, 640, 200);
30449 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30450 SetRect(&rect, 0, 200, 640, 480);
30451 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30452 release_resource_readback(&rb);
30454 ID3D11Texture2D_Release(readback_texture);
30456 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
30458 ID3D11Texture2D_Release(render_targets[i]);
30459 ID3D11RenderTargetView_Release(rtvs[i]);
30462 done:
30463 ID3D11Buffer_Release(cb);
30464 ID3D11PixelShader_Release(ps);
30465 ID3D11BlendState_Release(blend_state);
30466 release_test_context(&test_context);
30469 static void test_unbound_multisample_texture(void)
30471 struct d3d11_test_context test_context;
30472 ID3D11DeviceContext *context;
30473 ID3D11PixelShader *ps;
30474 struct uvec4 cb_data;
30475 ID3D11Device *device;
30476 ID3D11Buffer *cb;
30477 unsigned int i;
30478 HRESULT hr;
30480 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30481 static const DWORD ps_code[] =
30483 #if 0
30484 Texture2DMS<float4, 4> t;
30486 uint sample_index;
30488 float4 main(float4 position : SV_Position) : SV_Target
30490 float3 p;
30491 t.GetDimensions(p.x, p.y, p.z);
30492 p *= float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
30493 /* sample index must be a literal */
30494 switch (sample_index)
30496 case 1: return t.Load(int2(p.xy), 1);
30497 case 2: return t.Load(int2(p.xy), 2);
30498 case 3: return t.Load(int2(p.xy), 3);
30499 default: return t.Load(int2(p.xy), 0);
30502 #endif
30503 0x43425844, 0x03d62416, 0x1914ee8b, 0xccd08d68, 0x27f42136, 0x00000001, 0x000002f8, 0x00000003,
30504 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30505 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
30506 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
30507 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000025c, 0x00000040,
30508 0x00000097, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04042058, 0x00107000, 0x00000000,
30509 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
30510 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46,
30511 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000,
30512 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
30513 0x00000000, 0x00000000, 0x0400004c, 0x0020800a, 0x00000000, 0x00000000, 0x03000006, 0x00004001,
30514 0x00000001, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000, 0x08000036, 0x001000c2,
30515 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0900002e, 0x001020f2,
30516 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
30517 0x03000006, 0x00004001, 0x00000002, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000,
30518 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
30519 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001,
30520 0x00000002, 0x0100003e, 0x03000006, 0x00004001, 0x00000003, 0x0500001b, 0x00100032, 0x00000001,
30521 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000,
30522 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46,
30523 0x00000000, 0x00004001, 0x00000003, 0x0100003e, 0x0100000a, 0x0500001b, 0x00100032, 0x00000000,
30524 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
30525 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46,
30526 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000017, 0x0100003e,
30529 if (!init_test_context(&test_context, NULL))
30530 return;
30531 device = test_context.device;
30532 context = test_context.immediate_context;
30534 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30535 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30536 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30538 memset(&cb_data, 0, sizeof(cb_data));
30539 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
30540 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30542 for (i = 0; i < 4; ++i)
30544 cb_data.x = i;
30545 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_data, 0, 0);
30546 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
30547 draw_quad(&test_context);
30548 check_texture_color(test_context.backbuffer, 0x00000000, 1);
30551 ID3D11Buffer_Release(cb);
30552 ID3D11PixelShader_Release(ps);
30553 release_test_context(&test_context);
30556 static void test_multiple_viewports(void)
30558 struct
30560 unsigned int draw_id;
30561 unsigned int padding[3];
30562 } constant;
30563 D3D11_VIEWPORT vp[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE + 1];
30564 struct d3d11_test_context test_context;
30565 D3D11_TEXTURE2D_DESC texture_desc;
30566 ID3D11DeviceContext *context;
30567 ID3D11RenderTargetView *rtv;
30568 ID3D11Texture2D *texture;
30569 ID3D11GeometryShader *gs;
30570 ID3D11PixelShader *ps;
30571 ID3D11Device *device;
30572 ID3D11Buffer *cb;
30573 HRESULT hr;
30575 static const DWORD gs_code[] =
30577 #if 0
30578 struct gs_in
30580 float4 pos : SV_Position;
30583 struct gs_out
30585 float4 pos : SV_Position;
30586 uint viewport : SV_ViewportArrayIndex;
30589 [maxvertexcount(6)]
30590 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
30592 gs_out o;
30593 for (uint instance_id = 0; instance_id < 2; ++instance_id)
30595 o.viewport = instance_id;
30596 for (uint i = 0; i < 3; ++i)
30598 o.pos = vin[i].pos;
30599 vout.Append(o);
30601 vout.RestartStrip();
30604 #endif
30605 0x43425844, 0xabbb660f, 0x0729bf23, 0x14a9a104, 0x1b454917, 0x00000001, 0x0000021c, 0x00000003,
30606 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30607 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
30608 0x4e47534f, 0x0000005c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
30609 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005, 0x00000001, 0x00000001, 0x00000e01,
30610 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569, 0x4174726f, 0x79617272, 0x65646e49,
30611 0xabab0078, 0x52444853, 0x00000150, 0x00020040, 0x00000054, 0x05000061, 0x002010f2, 0x00000003,
30612 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
30613 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000005, 0x0200005e, 0x00000006,
30614 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
30615 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x03040003, 0x0010001a, 0x00000000,
30616 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
30617 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000,
30618 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036,
30619 0x00102012, 0x00000001, 0x0010000a, 0x00000000, 0x01000013, 0x0700001e, 0x00100022, 0x00000000,
30620 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012,
30621 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
30623 static const DWORD ps_code[] =
30625 #if 0
30626 uint draw_id;
30628 float4 main(in float4 pos : SV_Position,
30629 in uint viewport : SV_ViewportArrayIndex) : SV_Target
30631 return float4(viewport, draw_id, 0, 0);
30633 #endif
30634 0x43425844, 0x77334c0f, 0x5df3ca7a, 0xc53c00db, 0x3e6e5750, 0x00000001, 0x00000150, 0x00000003,
30635 0x0000002c, 0x00000090, 0x000000c4, 0x4e475349, 0x0000005c, 0x00000002, 0x00000008, 0x00000038,
30636 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005,
30637 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569,
30638 0x4174726f, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
30639 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261,
30640 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46, 0x00000000,
30641 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000005, 0x03000065, 0x001020f2, 0x00000000,
30642 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022, 0x00000000,
30643 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000,
30644 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
30646 static const struct vec4 expected_values[] =
30648 {0.0f, 1.0f}, {1.0f, 1.0f}, {0.0f, 2.0f}, {0.5f, 0.5f}, {0.5f, 0.5f}, {0.0f, 4.0f}, {0.5f, 0.5f}, {0.5f, 0.5f},
30649 {0.0f, 5.0f}, {0.5f, 0.5f}, {1.0f, 5.0f}, {0.5f, 0.5f},
30651 static const float clear_color[] = {0.5f, 0.5f, 0.0f, 0.0f};
30652 ID3D11RasterizerState *rasterizer_state;
30653 D3D11_RASTERIZER_DESC rasterizer_desc;
30654 unsigned int count, i;
30655 D3D11_RECT rects[2];
30656 RECT rect;
30657 int width;
30659 if (!init_test_context(&test_context, NULL))
30660 return;
30662 device = test_context.device;
30663 context = test_context.immediate_context;
30665 memset(&constant, 0, sizeof(constant));
30666 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
30667 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30669 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
30670 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
30671 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
30673 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30674 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
30675 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30677 texture_desc.Width = 32;
30678 texture_desc.Height = 32;
30679 texture_desc.MipLevels = 1;
30680 texture_desc.ArraySize = 1;
30681 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
30682 texture_desc.SampleDesc.Count = 1;
30683 texture_desc.SampleDesc.Quality = 0;
30684 texture_desc.Usage = D3D11_USAGE_DEFAULT;
30685 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
30686 texture_desc.CPUAccessFlags = 0;
30687 texture_desc.MiscFlags = 0;
30688 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30689 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30691 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
30692 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
30693 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30695 width = texture_desc.Width / 2;
30697 vp[0].TopLeftX = 0.0f;
30698 vp[0].TopLeftY = 0.0f;
30699 vp[0].Width = width;
30700 vp[0].Height = texture_desc.Height;
30701 vp[0].MinDepth = 0.0f;
30702 vp[0].MaxDepth = 1.0f;
30704 vp[1] = vp[0];
30705 vp[1].TopLeftX = width;
30706 vp[1].Width = width;
30707 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
30709 count = enable_debug_layer ? ARRAY_SIZE(vp) - 1 : ARRAY_SIZE(vp);
30710 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
30711 ok(count == 2, "Unexpected viewport count %d.\n", count);
30713 constant.draw_id = 0;
30714 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30715 draw_quad(&test_context);
30716 constant.draw_id = 1;
30717 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30718 draw_quad(&test_context);
30720 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
30721 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[0], 1);
30722 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30723 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[1], 1);
30725 /* One viewport. */
30726 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30727 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
30728 constant.draw_id = 2;
30729 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30730 draw_quad(&test_context);
30731 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
30732 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[2], 1);
30733 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30734 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[3], 1);
30736 /* Reset viewports. */
30737 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30738 ID3D11DeviceContext_RSSetViewports(context, 0, NULL);
30739 constant.draw_id = 3;
30740 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30741 draw_quad(&test_context);
30742 check_texture_sub_resource_vec4(texture, 0, NULL, &expected_values[4], 1);
30744 /* Two viewports, only first scissor rectangle set. */
30745 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
30746 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
30747 rasterizer_desc.CullMode = D3D11_CULL_BACK;
30748 rasterizer_desc.DepthClipEnable = TRUE;
30749 rasterizer_desc.ScissorEnable = TRUE;
30750 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
30751 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
30753 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
30754 ID3D11RasterizerState_Release(rasterizer_state);
30756 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30757 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
30759 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
30760 memset(&rects[1], 0, sizeof(*rects));
30761 ID3D11DeviceContext_RSSetScissorRects(context, 1, rects);
30762 constant.draw_id = 4;
30763 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30764 draw_quad(&test_context);
30766 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
30767 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[5], 1);
30768 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
30769 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[6], 1);
30770 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30771 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[7], 1);
30773 /* Set both rectangles. */
30774 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
30775 SetRect(&rects[1], width, 0, 2 * width, texture_desc.Height / 2);
30776 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30777 ID3D11DeviceContext_RSSetScissorRects(context, 2, rects);
30778 constant.draw_id = 5;
30779 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30780 draw_quad(&test_context);
30782 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
30783 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[8], 1);
30784 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
30785 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[9], 1);
30787 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height / 2 - 1);
30788 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[10], 1);
30789 SetRect(&rect, width, texture_desc.Height / 2, 2 * width - 1, texture_desc.Height - 1);
30790 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[11], 1);
30792 if (enable_debug_layer)
30793 goto done;
30795 /* Viewport count exceeding maximum value. */
30796 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
30798 vp[0].TopLeftX = 1.0f;
30799 vp[0].TopLeftY = 0.0f;
30800 vp[0].Width = width;
30801 vp[0].Height = texture_desc.Height;
30802 vp[0].MinDepth = 0.0f;
30803 vp[0].MaxDepth = 1.0f;
30804 for (i = 1; i < ARRAY_SIZE(vp); ++i)
30806 vp[i] = vp[0];
30808 ID3D11DeviceContext_RSSetViewports(context, ARRAY_SIZE(vp), vp);
30810 count = ARRAY_SIZE(vp);
30811 memset(vp, 0, sizeof(vp));
30812 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
30813 ok(count == 1, "Unexpected viewport count %d.\n", count);
30814 ok(vp[0].TopLeftX == 0.0f && vp[0].Width == width, "Unexpected viewport.\n");
30816 done:
30817 ID3D11RenderTargetView_Release(rtv);
30818 ID3D11Texture2D_Release(texture);
30820 ID3D11Buffer_Release(cb);
30821 ID3D11GeometryShader_Release(gs);
30822 ID3D11PixelShader_Release(ps);
30823 release_test_context(&test_context);
30826 static void test_multisample_resolve(void)
30828 struct d3d11_test_context test_context;
30829 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
30830 ID3D11Texture2D *texture, *ms_texture;
30831 D3D11_TEXTURE2D_DESC texture_desc;
30832 ID3D11DeviceContext *context;
30833 ID3D11RenderTargetView *rtv;
30834 ID3D11Device *device;
30835 unsigned int i;
30836 HRESULT hr;
30838 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30839 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
30840 static const struct vec4 color = {0.25f, 0.5f, 0.75f, 1.0f};
30841 static const struct
30843 DXGI_FORMAT src_format;
30844 DXGI_FORMAT dst_format;
30845 DXGI_FORMAT format;
30847 DXGI_FORMAT rtv_format;
30849 const struct vec4 *color;
30850 DWORD expected_color;
30852 BOOL todo;
30854 tests[] =
30856 {DXGI_FORMAT_R8G8B8A8_UNORM,
30857 DXGI_FORMAT_R8G8B8A8_UNORM,
30858 DXGI_FORMAT_R8G8B8A8_UNORM,
30859 DXGI_FORMAT_R8G8B8A8_UNORM,
30860 &green, 0xff80ff80},
30861 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30862 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30863 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30864 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30865 &green, 0xffbcffbc},
30866 {DXGI_FORMAT_R8G8B8A8_UNORM,
30867 DXGI_FORMAT_R8G8B8A8_UNORM,
30868 DXGI_FORMAT_R8G8B8A8_UNORM,
30869 DXGI_FORMAT_R8G8B8A8_UNORM,
30870 &color, 0xffdfc0a0},
30871 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30872 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30873 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30874 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30875 &color, 0xfff1e1cf},
30877 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30878 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30879 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30880 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30881 &green, 0xffbcffbc},
30882 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30883 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30884 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30885 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30886 &green, 0xffbcffbc},
30887 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30888 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30889 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30890 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30891 &color, 0xfff1e1cf},
30892 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30893 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30894 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30895 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30896 &color, 0xfff1e1cf},
30898 {DXGI_FORMAT_R8G8B8A8_UNORM,
30899 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30900 DXGI_FORMAT_R8G8B8A8_UNORM,
30901 DXGI_FORMAT_R8G8B8A8_UNORM,
30902 &green, 0xff80ff80},
30903 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30904 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30905 DXGI_FORMAT_R8G8B8A8_UNORM,
30906 DXGI_FORMAT_R8G8B8A8_UNORM,
30907 &green, 0xff80ff80},
30908 {DXGI_FORMAT_R8G8B8A8_UNORM,
30909 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30910 DXGI_FORMAT_R8G8B8A8_UNORM,
30911 DXGI_FORMAT_R8G8B8A8_UNORM,
30912 &color, 0xffdfc0a0},
30913 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30914 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30915 DXGI_FORMAT_R8G8B8A8_UNORM,
30916 DXGI_FORMAT_R8G8B8A8_UNORM,
30917 &color, 0xffdfc0a0},
30919 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30920 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30921 DXGI_FORMAT_R8G8B8A8_UNORM,
30922 DXGI_FORMAT_R8G8B8A8_UNORM,
30923 &green, 0xff80ff80},
30924 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30925 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30926 DXGI_FORMAT_R8G8B8A8_UNORM,
30927 DXGI_FORMAT_R8G8B8A8_UNORM,
30928 &color, 0xffdfc0a0},
30929 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30930 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30931 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30932 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30933 &green, 0xffbcffbc},
30934 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30935 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30936 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30937 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30938 &color, 0xfff1e1cf},
30939 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30940 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30941 DXGI_FORMAT_R8G8B8A8_UNORM,
30942 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30943 &green, 0xff80ff80},
30944 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30945 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30946 DXGI_FORMAT_R8G8B8A8_UNORM,
30947 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30948 &color, 0xfff0dec4},
30949 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30950 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30951 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30952 DXGI_FORMAT_R8G8B8A8_UNORM,
30953 &green, 0xffbcffbc, TRUE},
30954 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30955 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30956 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30957 DXGI_FORMAT_R8G8B8A8_UNORM,
30958 &color, 0xffe2cdc0, TRUE},
30961 if (!init_test_context(&test_context, NULL))
30962 return;
30963 device = test_context.device;
30964 context = test_context.immediate_context;
30966 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &i);
30967 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
30968 if (!i)
30970 skip("4xMSAA not supported.\n");
30971 release_test_context(&test_context);
30972 return;
30975 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, 3);
30977 for (i = 0; i < ARRAY_SIZE(tests); ++i)
30979 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30980 texture_desc.Format = tests[i].dst_format;
30981 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30982 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30984 texture_desc.Format = tests[i].src_format;
30985 texture_desc.SampleDesc.Count = 4;
30986 texture_desc.SampleDesc.Quality = 0;
30987 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ms_texture);
30988 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30989 rtv_desc.Format = tests[i].rtv_format;
30990 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
30991 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)ms_texture, &rtv_desc, &rtv);
30992 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
30994 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30995 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
30996 draw_color_quad(&test_context, tests[i].color);
30997 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)texture, 0,
30998 (ID3D11Resource *)ms_texture, 0, tests[i].format);
31000 /* Found broken on AMD Radeon HD 6310 */
31001 if (!broken(is_amd_device(device) && tests[i].format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB))
31002 todo_wine_if(tests[i].todo) check_texture_color(texture, tests[i].expected_color, 2);
31004 ID3D11RenderTargetView_Release(rtv);
31005 ID3D11Texture2D_Release(ms_texture);
31006 ID3D11Texture2D_Release(texture);
31009 release_test_context(&test_context);
31012 static void test_sample_shading(void)
31014 struct shader
31016 const DWORD *code;
31017 size_t size;
31020 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
31021 struct d3d11_test_context test_context;
31022 struct swapchain_desc swapchain_desc;
31023 D3D11_TEXTURE2D_DESC texture_desc;
31024 ID3D11UnorderedAccessView *uav;
31025 D3D11_BUFFER_DESC buffer_desc;
31026 ID3D11ShaderResourceView *srv;
31027 ID3D11DeviceContext *context;
31028 ID3D11RenderTargetView *rtv;
31029 struct resource_readback rb;
31030 ID3D11Buffer *buffer, *cb;
31031 ID3D11Texture2D *texture;
31032 struct uvec4 ps_constant;
31033 ID3D11PixelShader *ps;
31034 ID3D11Device *device;
31035 unsigned int data;
31036 unsigned int i;
31037 HRESULT hr;
31039 static const DWORD ps_unused_sample_index_code[] =
31041 #if 0
31042 RWByteAddressBuffer u;
31044 float4 main(uint id : SV_SampleIndex) : SV_Target
31046 u.InterlockedAdd(0, 1);
31047 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31049 #endif
31050 0x43425844, 0x41e4574b, 0x1e6441d6, 0x5e756375, 0xacd5dc27, 0x00000001, 0x00000104, 0x00000003,
31051 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
31052 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000001, 0x535f5653, 0x6c706d61, 0x646e4965,
31053 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
31054 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064,
31055 0x00000050, 0x00000019, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2,
31056 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
31057 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
31058 0x0100003e,
31060 static const struct shader ps_unused_sample_index
31061 = {ps_unused_sample_index_code, sizeof(ps_unused_sample_index_code)};
31062 static const DWORD ps_sample_index_code[] =
31064 #if 0
31065 RWByteAddressBuffer u;
31067 float4 main(uint id : SV_SampleIndex) : SV_Target
31069 u.InterlockedAdd(0, 1);
31070 u.InterlockedAdd(4, id);
31071 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31073 #endif
31074 0x43425844, 0x943ab9ed, 0x91520b4a, 0xb75df9d0, 0x692cd3e6, 0x00000001, 0x00000130, 0x00000003,
31075 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
31076 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
31077 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
31078 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000090,
31079 0x00000050, 0x00000024, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
31080 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001,
31081 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
31082 0x00000004, 0x0010100a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31083 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
31085 static const struct shader ps_sample_index = {ps_sample_index_code, sizeof(ps_sample_index_code)};
31086 static const DWORD ps_samplepos_code[] =
31088 #if 0
31089 Texture2DMS<float> t;
31090 RWByteAddressBuffer u;
31092 float4 main() : SV_Target
31094 float2 sample_position = t.GetSamplePosition(0);
31095 u.InterlockedAdd(0, 1);
31096 u.InterlockedAdd(4, sample_position.x + sample_position.y);
31097 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31099 #endif
31100 0x43425844, 0x9ec7f344, 0x588f5863, 0x436c0531, 0x69dc54bb, 0x00000001, 0x00000160, 0x00000003,
31101 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31102 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31103 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e8, 0x00000050, 0x0000003a,
31104 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
31105 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
31106 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
31107 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
31108 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
31109 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
31110 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
31112 static const struct shader ps_samplepos = {ps_samplepos_code, sizeof(ps_samplepos_code)};
31113 static const DWORD ps_samplepos_rasterizer_code[] =
31115 #if 0
31116 RWByteAddressBuffer u;
31118 float4 main() : SV_Target
31120 float2 sample_position = GetRenderTargetSamplePosition(0);
31121 u.InterlockedAdd(0, 1);
31122 u.InterlockedAdd(4, sample_position.x + sample_position.y);
31123 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31125 #endif
31126 0x43425844, 0xe31795d9, 0x4e9951da, 0xc1713913, 0xfb12da31, 0x00000001, 0x00000148, 0x00000003,
31127 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31128 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31129 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d0, 0x00000050, 0x00000034,
31130 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
31131 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
31132 0x0600006e, 0x00100032, 0x00000000, 0x0000e046, 0x00004001, 0x00000000, 0x07000000, 0x00100012,
31133 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
31134 0x0010000a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
31135 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
31136 0x3f800000, 0x0100003e,
31138 static const struct shader ps_samplepos_rasterizer
31139 = {ps_samplepos_rasterizer_code, sizeof(ps_samplepos_rasterizer_code)};
31140 static const DWORD ps_samplepos_indexed_code[] =
31142 #if 0
31143 RWByteAddressBuffer u;
31145 float4 main(uint id : SV_SampleIndex) : SV_Target
31147 float2 sample_position = GetRenderTargetSamplePosition(id);
31148 u.InterlockedAdd(0, 1);
31149 u.InterlockedAdd(4, sample_position.x + sample_position.y);
31150 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31152 #endif
31153 0x43425844, 0x4b501464, 0x0cd4f636, 0x36428677, 0x6db6b4fb, 0x00000001, 0x00000180, 0x00000003,
31154 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
31155 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
31156 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
31157 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e0,
31158 0x00000050, 0x00000038, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
31159 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad,
31160 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0600006e, 0x00100032,
31161 0x00000000, 0x0000e046, 0x0010100a, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
31162 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
31163 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
31164 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
31166 static const struct shader ps_samplepos_indexed
31167 = {ps_samplepos_indexed_code, sizeof(ps_samplepos_indexed_code)};
31168 static const DWORD ps_sampleinfo_code[] =
31170 #if 0
31171 Texture2DMS<float> t;
31172 RWByteAddressBuffer u;
31174 float4 main() : SV_Target
31176 uint width, height, sample_count;
31177 t.GetDimensions(width, height, sample_count);
31178 u.InterlockedAdd(0, 1);
31179 u.InterlockedAdd(4, sample_count);
31180 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31182 #endif
31183 0x43425844, 0x4e4f4065, 0x20d88902, 0xd4750e8c, 0x652b8c04, 0x00000001, 0x00000124, 0x00000003,
31184 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31185 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31186 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050, 0x0000002b,
31187 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
31188 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
31189 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a,
31190 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000,
31191 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
31192 0x0100003e,
31194 static const struct shader ps_sampleinfo = {ps_sampleinfo_code, sizeof(ps_sampleinfo_code)};
31195 static const DWORD ps_sampleinfo_rasterizer_code[] =
31197 #if 0
31198 RWByteAddressBuffer u;
31200 float4 main() : SV_Target
31202 uint sample_count = GetRenderTargetSampleCount();
31203 u.InterlockedAdd(0, 1);
31204 u.InterlockedAdd(4, sample_count);
31205 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31207 #endif
31208 0x43425844, 0xfbbd8619, 0x9c2654c8, 0xb385363a, 0x4aacd10f, 0x00000001, 0x00000110, 0x00000003,
31209 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31210 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31211 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000098, 0x00000050, 0x00000026,
31212 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
31213 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
31214 0x0400086f, 0x00100012, 0x00000000, 0x0000e00a, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
31215 0x00000004, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31216 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
31218 static const struct shader ps_sampleinfo_rasterizer
31219 = {ps_sampleinfo_rasterizer_code, sizeof(ps_sampleinfo_rasterizer_code)};
31220 static const DWORD ps_sample_code[] =
31222 #if 0
31223 RWByteAddressBuffer u;
31225 float4 main(sample float4 position : SV_Position) : SV_Target
31227 u.InterlockedAdd(0, 1);
31228 u.InterlockedAdd(4, position.x);
31229 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31231 #endif
31232 0x43425844, 0x46ecbadb, 0xedccbea6, 0x236d7923, 0x0c356c8c, 0x00000001, 0x00000148, 0x00000003,
31233 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31234 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x7469736f, 0x006e6f69,
31235 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
31236 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050,
31237 0x0000002b, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04003864, 0x00101012, 0x00000000,
31238 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000,
31239 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500001c, 0x00100012, 0x00000000,
31240 0x0010100a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
31241 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
31242 0x3f800000, 0x0100003e,
31244 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
31245 static const DWORD ps_color_code[] =
31247 #if 0
31248 float4 main(uint id : SV_SampleIndex) : SV_Target
31250 switch (id)
31252 case 0: return float4(1.0f, 0.0f, 0.0f, 1.0f);
31253 case 1: return float4(0.0f, 1.0f, 0.0f, 1.0f);
31254 case 2: return float4(0.0f, 0.0f, 1.0f, 1.0f);
31255 default: return float4(0.0f, 0.0f, 0.0f, 1.0f);
31258 #endif
31259 0x43425844, 0x94c35f48, 0x04c6b0f7, 0x407d8214, 0xc24f01e5, 0x00000001, 0x00000194, 0x00000003,
31260 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
31261 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
31262 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
31263 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f4,
31264 0x00000050, 0x0000003d, 0x0100086a, 0x04000863, 0x00101012, 0x00000000, 0x0000000a, 0x03000065,
31265 0x001020f2, 0x00000000, 0x0300004c, 0x0010100a, 0x00000000, 0x03000006, 0x00004001, 0x00000000,
31266 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
31267 0x0100003e, 0x03000006, 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
31268 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x03000006, 0x00004001, 0x00000002,
31269 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000,
31270 0x0100003e, 0x0100000a, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
31271 0x00000000, 0x3f800000, 0x0100003e, 0x01000017, 0x0100003e,
31273 static const DWORD ps_resolve_code[] =
31275 #if 0
31276 Texture2DMS<float4> t;
31278 uint sample;
31279 uint rt_size;
31281 float4 main(float4 position : SV_Position) : SV_Target
31283 float3 p;
31284 t.GetDimensions(p.x, p.y, p.z);
31285 p *= float3(position.x / rt_size, position.y / rt_size, 0);
31286 return t.Load((int2)p.xy, sample);
31288 #endif
31289 0x43425844, 0x68a4590b, 0xc1ec3070, 0x1b957c43, 0x0c080741, 0x00000001, 0x000001c8, 0x00000003,
31290 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31291 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
31292 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
31293 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000012c, 0x00000050,
31294 0x0000004b, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002058, 0x00107000,
31295 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
31296 0x00000000, 0x02000068, 0x00000001, 0x06000056, 0x00100012, 0x00000000, 0x0020801a, 0x00000000,
31297 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00100006, 0x00000000,
31298 0x8900003d, 0x80000102, 0x00155543, 0x001000c2, 0x00000000, 0x00004001, 0x00000000, 0x001074e6,
31299 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000,
31300 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000,
31301 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8c00002e, 0x80000102, 0x00155543,
31302 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0020800a, 0x00000000,
31303 0x00000000, 0x0100003e,
31305 static const struct
31307 const struct shader *ps;
31308 BOOL sample_shading;
31309 BOOL todo;
31310 BOOL broken;
31312 tests[] =
31314 {&ps_unused_sample_index, FALSE, FALSE, TRUE /* broken on Nvidia */},
31315 {&ps_sample_index, TRUE},
31316 {&ps_samplepos, FALSE},
31317 {&ps_samplepos_rasterizer, FALSE},
31318 {&ps_samplepos_indexed, TRUE, TRUE},
31319 {&ps_sampleinfo, FALSE},
31320 {&ps_sampleinfo_rasterizer, FALSE},
31321 {&ps_sample, TRUE, TRUE, TRUE /* broken on Intel */},
31323 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
31324 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
31325 static const unsigned int zero[4] = {0};
31327 swapchain_desc.windowed = TRUE;
31328 swapchain_desc.buffer_count = 1;
31329 swapchain_desc.width = 32;
31330 swapchain_desc.height = 32;
31331 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
31332 swapchain_desc.flags = 0;
31333 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
31334 return;
31335 device = test_context.device;
31336 context = test_context.immediate_context;
31338 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31339 texture_desc.SampleDesc.Count = 4;
31340 texture_desc.SampleDesc.Quality = 0;
31341 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
31342 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31343 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31344 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
31345 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
31346 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
31347 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
31349 buffer_desc.ByteWidth = 1024;
31350 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
31351 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
31352 buffer_desc.CPUAccessFlags = 0;
31353 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
31354 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
31355 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31356 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
31357 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
31358 U(uav_desc).Buffer.FirstElement = 0;
31359 U(uav_desc).Buffer.NumElements = 256;
31360 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
31361 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
31362 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
31364 for (i = 0; i < ARRAY_SIZE(tests); ++i)
31366 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
31367 ok(hr == S_OK, "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
31368 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31370 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
31371 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
31372 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
31373 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
31374 draw_quad(&test_context);
31375 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
31376 get_buffer_readback(buffer, &rb);
31377 data = get_readback_color(&rb, 0, 0, 0);
31378 ok(1024 <= data && data <= 1056, "Test %u: Got unexpected value %u.\n", i, data);
31379 release_resource_readback(&rb);
31381 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
31382 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
31383 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
31384 1, &rtv, NULL, 1, 1, &uav, NULL);
31385 draw_quad(&test_context);
31386 get_buffer_readback(buffer, &rb);
31387 data = get_readback_color(&rb, 0, 0, 0);
31388 todo_wine_if(tests[i].todo)
31390 if (tests[i].sample_shading)
31392 ok(4096 <= data || broken(tests[i].broken && data >= 1024),
31393 "Test %u: Got unexpected value %u.\n", i, data);
31395 else
31397 ok((1024 <= data && data <= 1056) || broken(tests[i].broken && data >= 4096),
31398 "Test %u: Got unexpected value %u.\n", i, data);
31401 release_resource_readback(&rb);
31403 ID3D11PixelShader_Release(ps);
31406 if (is_warp_device(device))
31408 skip("Sample shading tests fail on WARP.\n");
31409 goto done;
31412 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps);
31413 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31414 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31415 ID3D11PixelShader_Release(ps);
31417 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
31418 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
31419 draw_quad(&test_context);
31420 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
31421 (ID3D11Resource *)texture, 0, texture_desc.Format);
31422 check_texture_color(test_context.backbuffer, 0xff404040, 2);
31424 hr = ID3D11Device_CreatePixelShader(device, ps_resolve_code, sizeof(ps_resolve_code), NULL, &ps);
31425 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31426 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31427 ID3D11PixelShader_Release(ps);
31428 ps_constant.x = 0;
31429 ps_constant.y = texture_desc.Width;
31430 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
31431 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
31433 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
31434 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
31435 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31436 draw_quad(&test_context);
31437 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
31438 ps_constant.x = 1;
31439 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
31440 draw_quad(&test_context);
31441 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
31442 ps_constant.x = 2;
31443 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
31444 draw_quad(&test_context);
31445 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
31446 ps_constant.x = 3;
31447 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
31448 draw_quad(&test_context);
31449 check_texture_color(test_context.backbuffer, 0xff000000, 0);
31451 ID3D11Buffer_Release(cb);
31452 done:
31453 ID3D11Buffer_Release(buffer);
31454 ID3D11UnorderedAccessView_Release(uav);
31455 ID3D11RenderTargetView_Release(rtv);
31456 ID3D11ShaderResourceView_Release(srv);
31457 ID3D11Texture2D_Release(texture);
31458 release_test_context(&test_context);
31461 static void test_sample_mask(void)
31463 static const DWORD ps_code[] =
31465 #if 0
31466 float4 main(in float4 pos : SV_Position, out uint sample_mask : SV_Coverage) : SV_Target
31468 sample_mask = 0x5;
31469 return float4(1.0, 1.0, 1.0, 1.0);
31471 #endif
31472 0x43425844, 0x196779a9, 0xda85988a, 0xb7f0a0b6, 0xb30dd6ba, 0x00000001, 0x00000114, 0x00000003,
31473 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31474 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
31475 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
31476 0x00000000, 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000001, 0xffffffff, 0x00000e01,
31477 0x545f5653, 0x65677261, 0x56530074, 0x766f435f, 0x67617265, 0xabab0065, 0x58454853, 0x00000054,
31478 0x00000050, 0x00000015, 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x0000f000,
31479 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
31480 0x04000036, 0x0000f001, 0x00004001, 0x00000005, 0x0100003e,
31482 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
31483 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
31484 struct d3d11_test_context test_context;
31485 D3D11_TEXTURE2D_DESC texture_desc;
31486 ID3D11DeviceContext *context;
31487 ID3D11RenderTargetView *rtv;
31488 ID3D11Texture2D *texture;
31489 ID3D11PixelShader *ps;
31490 ID3D11Device *device;
31491 UINT quality_levels;
31492 HRESULT hr;
31494 if (!init_test_context(&test_context, &feature_level))
31495 return;
31496 device = test_context.device;
31497 context = test_context.immediate_context;
31499 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &quality_levels);
31500 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
31501 if (!quality_levels)
31503 skip("4xMSAA not supported.\n");
31504 release_test_context(&test_context);
31505 return;
31508 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31509 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31510 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31512 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31513 texture_desc.SampleDesc.Count = 4;
31514 texture_desc.SampleDesc.Quality = 0;
31515 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31516 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31517 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
31518 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
31520 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
31521 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31522 draw_quad(&test_context);
31523 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
31524 (ID3D11Resource *)texture, 0, texture_desc.Format);
31525 check_texture_color(test_context.backbuffer, 0x7f7f7f7f, 1);
31527 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, 0xb);
31528 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31529 draw_quad(&test_context);
31530 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
31531 (ID3D11Resource *)texture, 0, texture_desc.Format);
31532 check_texture_color(test_context.backbuffer, 0x3f3f3f3f, 1);
31534 ID3D11RenderTargetView_Release(rtv);
31535 ID3D11Texture2D_Release(texture);
31536 ID3D11PixelShader_Release(ps);
31537 release_test_context(&test_context);
31540 static void test_depth_clip(void)
31542 struct d3d11_test_context test_context;
31543 D3D11_TEXTURE2D_DESC texture_desc;
31544 D3D11_RASTERIZER_DESC rs_desc;
31545 ID3D11DeviceContext *context;
31546 ID3D11DepthStencilView *dsv;
31547 ID3D11RasterizerState *rs;
31548 ID3D11Texture2D *texture;
31549 ID3D11Device *device;
31550 unsigned int count;
31551 D3D11_VIEWPORT vp;
31552 HRESULT hr;
31554 if (!init_test_context(&test_context, NULL))
31555 return;
31556 device = test_context.device;
31557 context = test_context.immediate_context;
31559 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31560 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
31561 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
31563 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31564 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
31565 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
31566 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
31567 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
31569 count = 1;
31570 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
31572 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
31573 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
31574 draw_quad_z(&test_context, 2.0f);
31575 check_texture_float(texture, 1.0f, 1);
31576 draw_quad_z(&test_context, 0.5f);
31577 check_texture_float(texture, 0.5f, 1);
31578 draw_quad_z(&test_context, -1.0f);
31579 check_texture_float(texture, 0.5f, 1);
31581 rs_desc.FillMode = D3D11_FILL_SOLID;
31582 rs_desc.CullMode = D3D11_CULL_BACK;
31583 rs_desc.FrontCounterClockwise = FALSE;
31584 rs_desc.DepthBias = 0;
31585 rs_desc.DepthBiasClamp = 0.0f;
31586 rs_desc.SlopeScaledDepthBias = 0.0f;
31587 rs_desc.DepthClipEnable = FALSE;
31588 rs_desc.ScissorEnable = FALSE;
31589 rs_desc.MultisampleEnable = FALSE;
31590 rs_desc.AntialiasedLineEnable = FALSE;
31591 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
31592 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
31594 ID3D11DeviceContext_RSSetState(context, rs);
31596 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
31597 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
31598 draw_quad_z(&test_context, 2.0f);
31599 check_texture_float(texture, 0.6f, 1);
31600 draw_quad_z(&test_context, 0.5f);
31601 check_texture_float(texture, 0.5f, 1);
31602 draw_quad_z(&test_context, -1.0f);
31603 check_texture_float(texture, 0.4f, 1);
31605 ID3D11DepthStencilView_Release(dsv);
31606 ID3D11Texture2D_Release(texture);
31607 ID3D11RasterizerState_Release(rs);
31608 release_test_context(&test_context);
31611 static void test_staging_buffers(void)
31613 struct d3d11_test_context test_context;
31614 ID3D11Buffer *dst_buffer, *src_buffer;
31615 D3D11_SUBRESOURCE_DATA resource_data;
31616 D3D11_BUFFER_DESC buffer_desc;
31617 ID3D11DeviceContext *context;
31618 struct resource_readback rb;
31619 float data[16], value;
31620 ID3D11Device *device;
31621 unsigned int i;
31622 HRESULT hr;
31624 if (!init_test_context(&test_context, NULL))
31625 return;
31626 device = test_context.device;
31627 context = test_context.immediate_context;
31629 buffer_desc.ByteWidth = sizeof(data);
31630 buffer_desc.Usage = D3D11_USAGE_STAGING;
31631 buffer_desc.BindFlags = 0;
31632 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
31633 buffer_desc.MiscFlags = 0;
31634 buffer_desc.StructureByteStride = 0;
31636 for (i = 0; i < ARRAY_SIZE(data); ++i)
31637 data[i] = i;
31638 resource_data.pSysMem = data;
31639 resource_data.SysMemPitch = 0;
31640 resource_data.SysMemSlicePitch = 0;
31642 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &src_buffer);
31643 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31645 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
31646 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
31647 buffer_desc.CPUAccessFlags = 0;
31648 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &dst_buffer);
31649 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31651 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
31652 get_buffer_readback(dst_buffer, &rb);
31653 for (i = 0; i < ARRAY_SIZE(data); ++i)
31655 value = get_readback_float(&rb, i, 0);
31656 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
31658 release_resource_readback(&rb);
31660 for (i = 0; i < ARRAY_SIZE(data); ++i)
31661 data[i] = 2 * i;
31662 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, NULL, data, 0, 0);
31663 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
31664 get_buffer_readback(dst_buffer, &rb);
31665 for (i = 0; i < ARRAY_SIZE(data); ++i)
31667 value = get_readback_float(&rb, i, 0);
31668 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
31670 release_resource_readback(&rb);
31672 ID3D11Buffer_Release(dst_buffer);
31673 ID3D11Buffer_Release(src_buffer);
31674 release_test_context(&test_context);
31677 static void test_render_a8(void)
31679 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
31680 struct d3d11_test_context test_context;
31681 D3D11_TEXTURE2D_DESC texture_desc;
31682 ID3D11DeviceContext *context;
31683 ID3D11RenderTargetView *rtv;
31684 struct resource_readback rb;
31685 ID3D11Texture2D *texture;
31686 ID3D11PixelShader *ps;
31687 ID3D11Device *device;
31688 unsigned int i;
31689 HRESULT hr;
31691 static const DWORD ps_code[] =
31693 #if 0
31694 void main(out float4 target : SV_Target)
31696 target = float4(0.0f, 0.25f, 0.5f, 1.0f);
31698 #endif
31699 0x43425844, 0x8a06129f, 0x3041bde2, 0x09389749, 0xb339ba8b, 0x00000001, 0x000000b0, 0x00000003,
31700 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31701 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31702 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
31703 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31704 0x3e800000, 0x3f000000, 0x3f800000, 0x0100003e,
31707 if (!init_test_context(&test_context, NULL))
31708 return;
31709 device = test_context.device;
31710 context = test_context.immediate_context;
31712 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31713 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31714 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31716 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31717 texture_desc.Format = DXGI_FORMAT_A8_UNORM;
31718 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31719 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31720 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
31721 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
31723 for (i = 0; i < 2; ++i)
31725 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31726 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
31727 draw_quad(&test_context);
31728 get_texture_readback(texture, 0, &rb);
31729 check_readback_data_u8(&rb, NULL, 0xff, 0);
31730 release_resource_readback(&rb);
31732 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
31733 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
31734 draw_quad(&test_context);
31735 check_texture_sub_resource_color(test_context.backbuffer, 0, NULL, 0xff7f4000, 1);
31738 ID3D11PixelShader_Release(ps);
31739 ID3D11Texture2D_Release(texture);
31740 ID3D11RenderTargetView_Release(rtv);
31741 release_test_context(&test_context);
31744 static void test_standard_pattern(void)
31746 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
31747 struct d3d11_test_context test_context;
31748 struct swapchain_desc swapchain_desc;
31749 D3D11_TEXTURE2D_DESC texture_desc;
31750 ID3D11UnorderedAccessView *uav;
31751 D3D11_BUFFER_DESC buffer_desc;
31752 ID3D11ShaderResourceView *srv;
31753 ID3D11DeviceContext *context;
31754 struct resource_readback rb;
31755 ID3D11Texture2D *texture;
31756 ID3D11PixelShader *ps;
31757 ID3D11Buffer *buffer;
31758 ID3D11Device *device;
31759 unsigned int i;
31760 HRESULT hr;
31762 static const DWORD ps_samplepos[] =
31764 #if 0
31765 Texture2DMS<float> t;
31766 RWByteAddressBuffer u;
31768 float4 main() : SV_Target
31770 u.Store2(0, asuint(t.GetSamplePosition(0)));
31771 u.Store2(8, asuint(t.GetSamplePosition(1)));
31772 u.Store2(16, asuint(t.GetSamplePosition(2)));
31773 u.Store2(24, asuint(t.GetSamplePosition(3)));
31774 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31776 #endif
31777 0x43425844, 0xa1db77e8, 0x804d8862, 0x0e3c213d, 0x2703dec6, 0x00000001, 0x00000190, 0x00000003,
31778 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31779 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31780 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000118, 0x00000050, 0x00000046,
31781 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
31782 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0800006e, 0x00100032, 0x00000000,
31783 0x00107046, 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x0800006e, 0x001000c2, 0x00000000,
31784 0x00107406, 0x00000000, 0x00004001, 0x00000001, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001,
31785 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
31786 0x00000000, 0x00004001, 0x00000002, 0x00000000, 0x0800006e, 0x001000c2, 0x00000000, 0x00107406,
31787 0x00000000, 0x00004001, 0x00000003, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001,
31788 0x00000010, 0x00100e46, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31789 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e
31791 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
31792 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
31793 static const unsigned int zero[4] = {0};
31794 static const float standard_pos4[] =
31796 -2 / 16.0f, -6 / 16.0f,
31797 6 / 16.0f, -2 / 16.0f,
31798 -6 / 16.0f, 2 / 16.0f,
31799 2 / 16.0f, 6 / 16.0f,
31802 swapchain_desc.windowed = TRUE;
31803 swapchain_desc.buffer_count = 1;
31804 swapchain_desc.width = 32;
31805 swapchain_desc.height = 32;
31806 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
31807 swapchain_desc.flags = 0;
31808 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
31809 return;
31810 device = test_context.device;
31811 context = test_context.immediate_context;
31813 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31814 texture_desc.SampleDesc.Count = 4;
31815 texture_desc.SampleDesc.Quality = D3D11_STANDARD_MULTISAMPLE_PATTERN;
31816 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
31817 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31818 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31819 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
31820 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
31822 buffer_desc.ByteWidth = 1024;
31823 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
31824 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
31825 buffer_desc.CPUAccessFlags = 0;
31826 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
31827 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
31828 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31829 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
31830 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
31831 U(uav_desc).Buffer.FirstElement = 0;
31832 U(uav_desc).Buffer.NumElements = 256;
31833 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
31834 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
31835 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
31837 hr = ID3D11Device_CreatePixelShader(device, ps_samplepos, sizeof(ps_samplepos), NULL, &ps);
31838 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31839 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31841 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
31842 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
31843 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
31844 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
31845 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31846 draw_quad(&test_context);
31847 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
31848 get_buffer_readback(buffer, &rb);
31849 for (i = 0; i < ARRAY_SIZE(standard_pos4); ++i)
31851 float data = get_readback_float(&rb, i, 0);
31852 /* Wine does not support GetSamplePosition. */
31853 todo_wine ok(data == standard_pos4[i], "Got sample position %.8e, expected %.8e.\n", data, standard_pos4[i]);
31855 release_resource_readback(&rb);
31857 ID3D11PixelShader_Release(ps);
31858 ID3D11Buffer_Release(buffer);
31859 ID3D11UnorderedAccessView_Release(uav);
31860 ID3D11ShaderResourceView_Release(srv);
31861 ID3D11Texture2D_Release(texture);
31862 release_test_context(&test_context);
31865 static void test_desktop_window(void)
31867 ID3D11RenderTargetView *backbuffer_rtv;
31868 DXGI_SWAP_CHAIN_DESC swapchain_desc;
31869 ID3D11DeviceContext *context;
31870 ID3D11Texture2D *backbuffer;
31871 IDXGISwapChain *swapchain;
31872 IDXGIDevice *dxgi_device;
31873 IDXGIAdapter *adapter;
31874 IDXGIFactory *factory;
31875 ID3D11Device *device;
31876 ULONG refcount;
31877 HRESULT hr;
31879 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
31881 if (!(device = create_device(NULL)))
31883 skip("Failed to create device.\n");
31884 return;
31887 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
31888 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
31889 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
31890 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
31891 IDXGIDevice_Release(dxgi_device);
31892 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
31893 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
31894 IDXGIAdapter_Release(adapter);
31896 swapchain_desc.BufferDesc.Width = 640;
31897 swapchain_desc.BufferDesc.Height = 480;
31898 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
31899 swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
31900 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31901 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
31902 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
31903 swapchain_desc.SampleDesc.Count = 1;
31904 swapchain_desc.SampleDesc.Quality = 0;
31905 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
31906 swapchain_desc.BufferCount = 1;
31907 swapchain_desc.OutputWindow = GetDesktopWindow();
31908 swapchain_desc.Windowed = TRUE;
31909 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
31910 swapchain_desc.Flags = 0;
31912 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
31913 ok(hr == S_OK || broken(hr == DXGI_ERROR_INVALID_CALL) /* Not available on all Windows versions. */,
31914 "Failed to create swapchain, hr %#x.\n", hr);
31915 IDXGIFactory_Release(factory);
31916 if (FAILED(hr))
31918 ID3D11Device_Release(device);
31919 return;
31922 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
31923 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
31925 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &backbuffer_rtv);
31926 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
31928 ID3D11Device_GetImmediateContext(device, &context);
31930 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
31931 check_texture_color(backbuffer, 0xff0000ff, 1);
31933 hr = IDXGISwapChain_Present(swapchain, 0, 0);
31934 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31936 ID3D11RenderTargetView_Release(backbuffer_rtv);
31937 ID3D11Texture2D_Release(backbuffer);
31938 IDXGISwapChain_Release(swapchain);
31939 ID3D11DeviceContext_Release(context);
31940 refcount = ID3D11Device_Release(device);
31941 ok(!refcount, "Device has %u references left.\n", refcount);
31944 static void test_sample_attached_rtv(void)
31946 ID3D11ShaderResourceView *srv, *srv2, *srv_test, *srv_ds;
31947 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc, srvds_desc;
31948 ID3D11Texture2D *texture, *texture2, *dstexture;
31949 ID3D11RenderTargetView *rtv, *rtv2, *rtvs[2];
31950 D3D11_DEPTH_STENCIL_VIEW_DESC dsview_desc;
31951 struct d3d11_test_context test_context;
31952 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
31953 D3D11_TEXTURE2D_DESC texture_desc;
31954 D3D_FEATURE_LEVEL feature_level;
31955 D3D11_SAMPLER_DESC sampler_desc;
31956 ID3D11DepthStencilView *dsview;
31957 ID3D11BlendState *blend_state;
31958 ID3D11DeviceContext *context;
31959 D3D11_BLEND_DESC blend_desc;
31960 ID3D11SamplerState *sampler;
31961 struct resource_readback rb;
31962 ID3D11PixelShader *ps;
31963 ID3D11Device *device;
31964 unsigned int x, y;
31965 unsigned int i;
31966 D3D11_BOX box;
31967 DWORD color;
31968 HRESULT hr;
31970 static const DWORD ps_ld_code[] =
31972 #if 0
31973 Texture2D t;
31975 struct PS_OUTPUT
31977 float4 color0: SV_Target0;
31978 float4 color1: SV_Target1;
31981 PS_OUTPUT main(float4 position : SV_POSITION)
31983 PS_OUTPUT output;
31984 float3 p;
31986 t.GetDimensions(0, p.x, p.y, p.z);
31987 p.z = 0;
31988 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
31989 output.color0 = output.color1 = t.Load(int3(p)) + float4(0.25, 0.25, 0.25, 0.25);
31990 return output;
31992 #endif
31993 0x43425844, 0x08dd0517, 0x07d7e538, 0x4cad261f, 0xa2ae5942, 0x00000001, 0x00000200, 0x00000003,
31994 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31995 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
31996 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
31997 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
31998 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000014c, 0x00000040, 0x00000053, 0x04001858,
31999 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
32000 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0700003d,
32001 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032,
32002 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000,
32003 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
32004 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0500001b,
32005 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46,
32006 0x00000000, 0x00107e46, 0x00000000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
32007 0x00004002, 0x3e800000, 0x3e800000, 0x3e800000, 0x3e800000, 0x05000036, 0x001020f2, 0x00000000,
32008 0x00100e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00100e46, 0x00000000, 0x0100003e,
32010 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
32011 static const struct
32013 DXGI_FORMAT texture_format, dsv_format, srv_format;
32014 UINT dsv_flags;
32015 BOOL srv_bind_allowed;
32017 ds_tests[] =
32019 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
32020 0, FALSE},
32021 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
32022 D3D11_DSV_READ_ONLY_DEPTH, TRUE},
32023 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_X24_TYPELESS_G8_UINT,
32024 D3D11_DSV_READ_ONLY_DEPTH, FALSE},
32025 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_X24_TYPELESS_G8_UINT,
32026 D3D11_DSV_READ_ONLY_STENCIL, TRUE},
32027 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT,
32028 0, FALSE},
32029 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT,
32030 D3D11_DSV_READ_ONLY_DEPTH, TRUE},
32033 if (!init_test_context(&test_context, NULL))
32034 return;
32036 device = test_context.device;
32037 context = test_context.immediate_context;
32039 feature_level = ID3D11Device_GetFeatureLevel(device);
32041 texture_desc.SampleDesc.Count = 1;
32042 texture_desc.SampleDesc.Quality = 0;
32043 texture_desc.Usage = D3D11_USAGE_DEFAULT;
32044 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
32045 texture_desc.CPUAccessFlags = 0;
32046 texture_desc.MiscFlags = 0;
32048 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
32049 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
32050 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
32051 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
32052 sampler_desc.MipLODBias = 0.0f;
32053 sampler_desc.MaxAnisotropy = 0;
32054 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
32055 sampler_desc.BorderColor[0] = 0.0f;
32056 sampler_desc.BorderColor[1] = 0.0f;
32057 sampler_desc.BorderColor[2] = 0.0f;
32058 sampler_desc.BorderColor[3] = 0.0f;
32059 sampler_desc.MinLOD = 0.0f;
32060 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
32062 hr = ID3D11Device_CreatePixelShader(device, ps_ld_code, sizeof(ps_ld_code), NULL, &ps);
32063 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32065 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32067 texture_desc.Width = 64;
32068 texture_desc.Height = 64;
32069 texture_desc.MipLevels = 2;
32070 texture_desc.ArraySize = 1;
32071 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
32073 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
32074 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32076 texture_desc.Width = 640;
32077 texture_desc.Height = 480;
32078 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture2);
32079 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32081 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
32082 sampler_desc.MipLODBias = 0.0f;
32083 sampler_desc.MinLOD = 0.0f;
32084 sampler_desc.MaxLOD = 0.0f;
32086 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
32087 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32089 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
32091 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
32093 memset(&rtv_desc, 0, sizeof(rtv_desc));
32094 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
32095 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
32096 U(rtv_desc).Texture2D.MipSlice = 0;
32098 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv);
32099 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32100 U(rtv_desc).Texture2D.MipSlice = 1;
32101 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv2);
32102 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32104 rtvs[0] = test_context.backbuffer_rtv;
32105 rtvs[1] = rtv;
32107 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
32109 memset(&srv_desc, 0, sizeof(srv_desc));
32110 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
32111 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
32112 U(srv_desc).Texture2D.MipLevels = 1;
32114 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
32115 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32116 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
32118 draw_quad(&test_context);
32120 set_box(&box, 0, 0, 0, 320, 240, 1);
32121 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2, 1, 0, 0, 0, (ID3D11Resource *)texture2, 0, &box);
32123 get_texture_readback(texture2, 0, &rb);
32124 for (y = 0; y < 4; ++y)
32126 for (x = 0; x < 4; ++x)
32128 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
32129 ok(compare_color(color, 0x40404040, 2),
32130 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
32133 release_resource_readback(&rb);
32134 get_texture_readback(texture2, 1, &rb);
32135 for (y = 0; y < 4; ++y)
32137 for (x = 0; x < 4; ++x)
32139 color = get_readback_color(&rb, 40 + x * 80, 30 + y * 60, 0);
32140 ok(compare_color(color, 0x40404040, 2),
32141 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
32144 release_resource_readback(&rb);
32146 ID3D11ShaderResourceView_Release(srv);
32147 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
32149 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
32151 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv);
32152 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32154 U(srv_desc).Texture2D.MostDetailedMip = 1;
32155 U(srv_desc).Texture2D.MipLevels = 1;
32156 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv2);
32157 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32159 memset(&blend_desc, 0, sizeof(blend_desc));
32160 blend_desc.IndependentBlendEnable = TRUE;
32161 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
32162 blend_desc.RenderTarget[1].RenderTargetWriteMask = 0;
32163 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32164 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32165 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32166 ID3D11BlendState_Release(blend_state);
32168 /* SRV does not get bound if resource is attached as render target, even if write mask is 0. */
32169 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
32170 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32171 ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
32173 blend_desc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
32174 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32175 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32176 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32177 ID3D11BlendState_Release(blend_state);
32179 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
32181 draw_quad(&test_context);
32182 draw_quad(&test_context);
32184 get_texture_readback(test_context.backbuffer, 0, &rb);
32185 for (y = 0; y < 4; ++y)
32187 for (x = 0; x < 4; ++x)
32189 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
32190 ok(compare_color(color, 0x40404040, 2),
32191 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
32194 release_resource_readback(&rb);
32196 get_texture_readback(texture2, 0, &rb);
32197 for (y = 0; y < 4; ++y)
32199 for (x = 0; x < 4; ++x)
32201 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
32202 ok(compare_color(color, 0x40404040, 2),
32203 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
32206 release_resource_readback(&rb);
32208 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
32209 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
32210 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32211 ok(!!srv_test, "Unexpected SRV %p.\n", srv_test);
32212 ID3D11ShaderResourceView_Release(srv_test);
32214 draw_quad(&test_context);
32215 get_texture_readback(test_context.backbuffer, 0, &rb);
32216 for (y = 0; y < 4; ++y)
32218 for (x = 0; x < 4; ++x)
32220 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
32221 ok(compare_color(color, 0x80808080, 2),
32222 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
32225 release_resource_readback(&rb);
32227 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
32229 /* SRV is reset when the same resource is set as render target. */
32230 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32231 ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
32233 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
32234 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
32235 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32236 ok(!!srv_test, "Unexpected SRV %p.\n", srv_test);
32237 ID3D11ShaderResourceView_Release(srv_test);
32239 draw_quad(&test_context);
32240 get_texture_readback(test_context.backbuffer, 0, &rb);
32241 for (y = 0; y < 4; ++y)
32243 for (x = 0; x < 4; ++x)
32245 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
32246 ok(compare_color(color, 0x80808080, 2),
32247 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
32250 release_resource_readback(&rb);
32252 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
32253 memset(&dsview_desc, 0, sizeof(dsview_desc));
32254 dsview_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
32256 memset(&srvds_desc, 0, sizeof(srvds_desc));
32257 srvds_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
32258 U(srvds_desc).Texture2D.MipLevels = 1;
32260 for (i = 0; i < ARRAY_SIZE(ds_tests); ++i)
32262 if (ds_tests[i].dsv_flags && feature_level < D3D_FEATURE_LEVEL_11_0)
32264 static unsigned int skip_once;
32266 if (!skip_once++)
32267 skip("Read only depths or stencils are not supported.\n");
32269 continue;
32272 texture_desc.Format = ds_tests[i].texture_format;
32273 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &dstexture);
32274 ok(hr == S_OK, "Test %u, got unexpected hr %#x.\n", i, hr);
32275 dsview_desc.Format = ds_tests[i].dsv_format;
32276 dsview_desc.Flags = ds_tests[i].dsv_flags;
32277 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)dstexture, &dsview_desc, &dsview);
32278 ok(hr == S_OK, "Test %u, got unexpected hr %#x.\n", i, hr);
32280 srvds_desc.Format = ds_tests[i].srv_format;
32281 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dstexture, &srvds_desc, &srv_ds);
32282 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32284 ID3D11DeviceContext_OMSetRenderTargets(context, 1, rtvs, NULL);
32285 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_ds);
32286 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32287 ok(!!srv_test, "Test %u, unexpected SRV %p.\n", i, srv_test);
32288 ID3D11ShaderResourceView_Release(srv_test);
32290 ID3D11DeviceContext_OMSetRenderTargets(context, 1, rtvs, dsview);
32291 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32292 ok(!!srv_test == ds_tests[i].srv_bind_allowed, "Test %u, unexpected SRV %p.\n", i, srv_test);
32293 if (srv_test)
32294 ID3D11ShaderResourceView_Release(srv_test);
32296 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_ds);
32297 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32298 ok(!!srv_test == ds_tests[i].srv_bind_allowed, "Test %u, unexpected SRV %p.\n", i, srv_test);
32299 if (srv_test)
32300 ID3D11ShaderResourceView_Release(srv_test);
32302 ID3D11Texture2D_Release(dstexture);
32303 ID3D11DepthStencilView_Release(dsview);
32304 ID3D11ShaderResourceView_Release(srv_ds);
32307 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
32309 ID3D11RenderTargetView_Release(rtv2);
32310 ID3D11RenderTargetView_Release(rtv);
32311 ID3D11ShaderResourceView_Release(srv2);
32312 ID3D11ShaderResourceView_Release(srv);
32313 ID3D11SamplerState_Release(sampler);
32314 ID3D11PixelShader_Release(ps);
32315 ID3D11Texture2D_Release(texture2);
32316 ID3D11Texture2D_Release(texture);
32317 ID3D11SamplerState_Release(sampler);
32319 release_test_context(&test_context);
32322 static void test_color_mask(void)
32324 struct d3d11_test_context test_context;
32325 D3D11_TEXTURE2D_DESC texture_desc;
32326 ID3D11RenderTargetView *rtvs[8];
32327 ID3D11BlendState *blend_state;
32328 ID3D11DeviceContext *context;
32329 struct resource_readback rb;
32330 D3D11_BLEND_DESC blend_desc;
32331 ID3D11Texture2D *rts[8];
32332 ID3D11PixelShader *ps;
32333 ID3D11Device *device;
32334 unsigned int i;
32335 DWORD color;
32336 HRESULT hr;
32338 static const DWORD expected_colors[] =
32339 {0xff000080, 0xff0080ff, 0xff8000ff, 0x80808080, 0x800000ff, 0xff008080, 0x800080ff, 0xff0000ff};
32341 static const DWORD ps_code[] =
32343 #if 0
32344 void main(float4 position : SV_Position,
32345 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
32346 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
32347 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
32348 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
32350 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.5f, 0.5f, 0.5f, 0.5f);
32352 #endif
32353 0x43425844, 0x7b1ab233, 0xdbe32d3b, 0x77084cc5, 0xe874d2b5, 0x00000001, 0x000002b0, 0x00000003,
32354 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
32355 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
32356 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
32357 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
32358 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
32359 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
32360 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
32361 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
32362 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
32363 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
32364 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
32365 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
32366 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000,
32367 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000,
32368 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3f000000,
32369 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3f000000,
32370 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3f000000,
32371 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3f000000,
32372 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3f000000,
32373 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3f000000,
32374 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
32377 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
32379 if (!init_test_context(&test_context, NULL))
32380 return;
32382 device = test_context.device;
32383 context = test_context.immediate_context;
32385 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
32386 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
32387 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32389 memset(&blend_desc, 0, sizeof(blend_desc));
32390 blend_desc.IndependentBlendEnable = TRUE;
32391 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED;
32392 blend_desc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN;
32393 blend_desc.RenderTarget[2].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_BLUE;
32394 blend_desc.RenderTarget[3].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
32395 blend_desc.RenderTarget[4].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALPHA;
32396 blend_desc.RenderTarget[5].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED | D3D11_COLOR_WRITE_ENABLE_GREEN;
32397 blend_desc.RenderTarget[6].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN | D3D11_COLOR_WRITE_ENABLE_ALPHA;
32398 blend_desc.RenderTarget[7].RenderTargetWriteMask = 0;
32400 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32401 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32402 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32403 ID3D11BlendState_Release(blend_state);
32405 for (i = 0; i < 8; ++i)
32407 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32408 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
32409 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
32411 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
32412 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
32415 ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
32417 for (i = 0; i < 8; ++i)
32418 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], red);
32419 draw_quad(&test_context);
32421 for (i = 0; i < 8; ++i)
32423 get_texture_readback(rts[i], 0, &rb);
32424 color = get_readback_color(&rb, 320, 240, 0);
32425 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32426 release_resource_readback(&rb);
32429 blend_desc.IndependentBlendEnable = FALSE;
32430 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32431 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32432 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32433 ID3D11BlendState_Release(blend_state);
32435 for (i = 0; i < 8; ++i)
32436 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], red);
32437 draw_quad(&test_context);
32439 for (i = 0; i < 8; ++i)
32441 get_texture_readback(rts[i], 0, &rb);
32442 color = get_readback_color(&rb, 320, 240, 0);
32443 ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32444 release_resource_readback(&rb);
32446 ID3D11Texture2D_Release(rts[i]);
32447 ID3D11RenderTargetView_Release(rtvs[i]);
32450 ID3D11PixelShader_Release(ps);
32451 release_test_context(&test_context);
32454 static void test_independent_blend(void)
32456 struct d3d11_test_context test_context;
32457 D3D11_TEXTURE2D_DESC texture_desc;
32458 ID3D11RenderTargetView *rtvs[8];
32459 ID3D11BlendState *blend_state;
32460 ID3D11DeviceContext *context;
32461 struct resource_readback rb;
32462 ID3D11Texture2D *rts[8];
32463 ID3D11PixelShader *ps;
32464 ID3D11Device *device;
32465 unsigned int i;
32466 DWORD color;
32467 HRESULT hr;
32469 static const DWORD ps_code[] =
32471 #if 0
32472 void main(float4 position : SV_Position,
32473 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
32474 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
32475 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
32476 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
32478 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.1f, 0.2f, 0.3f, 0.4f);
32480 #endif
32481 0x43425844, 0xb3dca7dc, 0x4a31f0f1, 0x747569cb, 0xae7af5ce, 0x00000001, 0x000002b0, 0x00000003,
32482 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
32483 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
32484 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
32485 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
32486 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
32487 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
32488 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
32489 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
32490 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
32491 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
32492 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
32493 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
32494 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3dcccccd,
32495 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3dcccccd,
32496 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3dcccccd,
32497 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3dcccccd,
32498 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3dcccccd,
32499 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3dcccccd,
32500 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3dcccccd,
32501 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3dcccccd,
32502 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x0100003e,
32505 D3D11_BLEND_DESC blend_desc =
32507 .IndependentBlendEnable = TRUE,
32508 .RenderTarget =
32510 {TRUE, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD,
32511 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32512 {TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
32513 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32514 {TRUE, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_OP_ADD,
32515 D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32516 {TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
32517 D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN, D3D11_COLOR_WRITE_ENABLE_ALL},
32518 {TRUE, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_OP_ADD,
32519 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32520 {TRUE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_BLEND_FACTOR, D3D11_BLEND_OP_SUBTRACT,
32521 D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_REV_SUBTRACT, D3D11_COLOR_WRITE_ENABLE_ALL},
32522 {FALSE, 0, 0, 0, 0, 0, 0, D3D11_COLOR_WRITE_ENABLE_ALL},
32523 {TRUE, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_OP_ADD,
32524 D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_DEST_ALPHA, D3D11_BLEND_OP_SUBTRACT,
32525 D3D11_COLOR_WRITE_ENABLE_ALL},
32529 static const DWORD expected_colors[] =
32530 {0x66426e1c, 0xb34c3319, 0xa6214a05, 0x66333319, 0xb34c4829, 0x4d19000a, 0x664c3319, 0x081f3305};
32532 static const float clear_color[] = {0.1f, 0.5f, 0.2f, 0.7f};
32533 static const float blend_factor[] = {0.8f, 0.4f, 0.6f, 0.2f};
32535 if (!init_test_context(&test_context, NULL))
32536 return;
32538 device = test_context.device;
32539 context = test_context.immediate_context;
32541 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
32542 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
32543 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32545 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32546 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32547 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
32548 ID3D11BlendState_Release(blend_state);
32550 for (i = 0; i < 8; ++i)
32552 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32553 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
32554 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
32556 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
32557 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
32560 ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
32562 for (i = 0; i < 8; ++i)
32563 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
32564 draw_quad(&test_context);
32566 for (i = 0; i < 8; ++i)
32568 get_texture_readback(rts[i], 0, &rb);
32569 color = get_readback_color(&rb, 320, 240, 0);
32570 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32571 release_resource_readback(&rb);
32574 blend_desc.IndependentBlendEnable = FALSE;
32575 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32576 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32577 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
32578 ID3D11BlendState_Release(blend_state);
32580 for (i = 0; i < 8; ++i)
32581 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
32582 draw_quad(&test_context);
32584 for (i = 0; i < 8; ++i)
32586 get_texture_readback(rts[i], 0, &rb);
32587 color = get_readback_color(&rb, 320, 240, 0);
32588 ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32589 release_resource_readback(&rb);
32591 ID3D11Texture2D_Release(rts[i]);
32592 ID3D11RenderTargetView_Release(rtvs[i]);
32595 ID3D11PixelShader_Release(ps);
32596 release_test_context(&test_context);
32599 static void test_dual_source_blend(void)
32601 struct d3d11_test_context test_context;
32602 ID3D11BlendState *blend_state;
32603 ID3D11DeviceContext *context;
32604 ID3D11PixelShader *ps;
32605 ID3D11Device *device;
32606 DWORD color;
32607 HRESULT hr;
32609 static const DWORD ps_code[] =
32611 #if 0
32612 void main(float4 position : SV_Position,
32613 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1)
32615 t0 = float4(0.5, 0.5, 0.0, 1.0);
32616 t1 = float4(0.0, 0.5, 0.5, 0.0);
32618 #endif
32619 0x43425844, 0x87120d01, 0xa0014738, 0x3a32d86c, 0x9d757441, 0x00000001, 0x00000118, 0x00000003,
32620 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
32621 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
32622 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
32623 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
32624 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03000065,
32625 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x08000036, 0x001020f2, 0x00000000,
32626 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001,
32627 0x00004002, 0x00000000, 0x3f000000, 0x3f000000, 0x00000000, 0x0100003e
32630 static const D3D11_BLEND_DESC blend_desc =
32632 .RenderTarget[0].BlendEnable = TRUE,
32633 .RenderTarget[0].SrcBlend = D3D11_BLEND_SRC1_COLOR,
32634 .RenderTarget[0].DestBlend = D3D11_BLEND_SRC1_COLOR,
32635 .RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD,
32636 .RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE,
32637 .RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO,
32638 .RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD,
32639 .RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL,
32642 static const float clear_color[] = {0.7f, 0.0f, 1.0f, 1.0f};
32644 if (!init_test_context(&test_context, NULL))
32645 return;
32647 device = test_context.device;
32648 context = test_context.immediate_context;
32650 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
32651 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
32652 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32654 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32655 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32656 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32657 ID3D11BlendState_Release(blend_state);
32659 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, clear_color);
32660 draw_quad(&test_context);
32662 color = get_texture_color(test_context.backbuffer, 320, 240);
32663 ok(compare_color(color, 0x80804000, 1), "Got unexpected color 0x%08x.\n", color);
32665 ID3D11PixelShader_Release(ps);
32666 release_test_context(&test_context);
32669 static void test_deferred_context_state(void)
32671 ID3D11Buffer *green_buffer, *blue_buffer, *ret_buffer;
32672 ID3D11DeviceContext *immediate, *deferred, *deferred2;
32673 ID3D11ShaderResourceView *srv, *ret_srv;
32674 struct d3d11_test_context test_context;
32675 ID3D11RenderTargetView *rtv, *ret_rtv;
32676 D3D11_TEXTURE2D_DESC texture_desc;
32677 ID3D11CommandList *list1, *list2;
32678 ID3D11Texture2D *texture;
32679 ID3D11Device *device;
32680 HRESULT hr;
32682 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32683 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
32685 if (!init_test_context(&test_context, NULL))
32686 return;
32688 device = test_context.device;
32689 immediate = test_context.immediate_context;
32691 green_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(green), &green);
32692 blue_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(blue), &blue);
32693 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32695 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32696 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32698 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32699 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32701 ID3D11DeviceContext_PSSetConstantBuffers(deferred, 0, 1, &blue_buffer);
32703 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32704 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32705 ID3D11Buffer_Release(ret_buffer);
32707 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32708 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32710 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32711 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32712 ID3D11Buffer_Release(ret_buffer);
32714 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list2);
32715 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32717 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32718 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32720 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32721 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32722 ID3D11DeviceContext_PSGetConstantBuffers(immediate, 0, 1, &ret_buffer);
32723 ok(ret_buffer == green_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32724 ID3D11Buffer_Release(ret_buffer);
32726 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32727 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
32728 ID3D11DeviceContext_PSGetConstantBuffers(immediate, 0, 1, &ret_buffer);
32729 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32731 ID3D11CommandList_Release(list2);
32732 ID3D11CommandList_Release(list1);
32734 /* Test recording a command list into another deferred context. */
32736 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred2);
32737 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32739 ID3D11DeviceContext_PSSetConstantBuffers(deferred2, 0, 1, &green_buffer);
32741 hr = ID3D11DeviceContext_FinishCommandList(deferred2, FALSE, &list1);
32742 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32744 ID3D11DeviceContext_PSSetConstantBuffers(deferred, 0, 1, &blue_buffer);
32745 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, TRUE);
32746 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32747 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32748 ID3D11Buffer_Release(ret_buffer);
32750 ID3D11DeviceContext_PSSetConstantBuffers(deferred, 0, 1, &blue_buffer);
32751 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, FALSE);
32752 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32753 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32755 ID3D11CommandList_Release(list1);
32756 ID3D11DeviceContext_Release(deferred2);
32758 /* Test unbinding an SRV when using the same resource as RTV. */
32760 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32761 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
32762 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
32763 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
32764 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
32765 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32766 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
32767 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32769 ID3D11DeviceContext_PSSetShaderResources(deferred, 0, 1, &srv);
32770 ID3D11DeviceContext_PSGetShaderResources(deferred, 0, 1, &ret_srv);
32771 ok(ret_srv == srv, "Got unexpected SRV %p.\n", ret_srv);
32772 ID3D11ShaderResourceView_Release(ret_srv);
32774 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &rtv, NULL);
32775 ID3D11DeviceContext_OMGetRenderTargets(deferred, 1, &ret_rtv, NULL);
32776 ok(ret_rtv == rtv, "Got unexpected RTV %p.\n", ret_rtv);
32777 ID3D11RenderTargetView_Release(ret_rtv);
32778 ID3D11DeviceContext_PSGetShaderResources(deferred, 0, 1, &ret_srv);
32779 ok(!ret_srv, "Got unexpected SRV %p.\n", ret_srv);
32781 ID3D11DeviceContext_PSSetShaderResources(deferred, 0, 1, &srv);
32782 ID3D11DeviceContext_PSGetShaderResources(deferred, 0, 1, &ret_srv);
32783 ok(!ret_srv, "Got unexpected SRV %p.\n", ret_srv);
32785 ID3D11DeviceContext_PSSetShaderResources(immediate, 0, 1, &srv);
32786 ID3D11DeviceContext_PSGetShaderResources(immediate, 0, 1, &ret_srv);
32787 ok(ret_srv == srv, "Got unexpected SRV %p.\n", ret_srv);
32788 ID3D11ShaderResourceView_Release(ret_srv);
32790 ID3D11ShaderResourceView_Release(srv);
32791 ID3D11RenderTargetView_Release(rtv);
32792 ID3D11Texture2D_Release(texture);
32793 ID3D11DeviceContext_Release(deferred);
32794 ID3D11Buffer_Release(blue_buffer);
32795 ID3D11Buffer_Release(green_buffer);
32796 release_test_context(&test_context);
32799 static void test_deferred_context_swap_state(void)
32801 ID3D11DeviceContext1 *immediate, *deferred;
32802 ID3DDeviceContextState *state, *prev_state;
32803 ID3D11Buffer *green_buffer, *ret_buffer;
32804 struct d3d11_test_context test_context;
32805 D3D_FEATURE_LEVEL feature_level;
32806 ID3D11Device1 *device;
32807 HRESULT hr;
32809 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32811 if (!init_test_context(&test_context, NULL))
32812 return;
32814 if (FAILED(ID3D11Device_QueryInterface(test_context.device, &IID_ID3D11Device1, (void **)&device)))
32816 skip("ID3D11Device1 is not available.\n");
32817 release_test_context(&test_context);
32818 return;
32821 ID3D11Device1_GetImmediateContext1(device, &immediate);
32823 green_buffer = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(green), &green);
32824 ID3D11DeviceContext1_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32826 hr = ID3D11Device1_CreateDeferredContext1(device, 0, &deferred);
32827 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32829 feature_level = ID3D11Device1_GetFeatureLevel(device);
32830 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
32831 &IID_ID3D11Device1, NULL, &state);
32832 ok(hr == S_OK, "Failed to create device context state, hr %#x.\n", hr);
32834 prev_state = (void *)0xdeadbeef;
32835 ID3D11DeviceContext1_SwapDeviceContextState(deferred, NULL, &prev_state);
32836 ok(!prev_state, "Got state %p.\n", prev_state);
32838 prev_state = (void *)0xdeadbeef;
32839 ID3D11DeviceContext1_SwapDeviceContextState(deferred, state, &prev_state);
32840 ok(!prev_state, "Got state %p.\n", prev_state);
32842 ID3D11DeviceContext1_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32843 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32845 ID3DDeviceContextState_Release(state);
32846 ID3D11DeviceContext1_Release(deferred);
32848 ID3D11Buffer_Release(green_buffer);
32849 ID3D11DeviceContext1_Release(immediate);
32850 ID3D11Device1_Release(device);
32851 release_test_context(&test_context);
32854 static void test_deferred_context_rendering(void)
32856 ID3D11BlendState *red_blend, *green_blend, *blue_blend, *ret_blend;
32857 ID3D11DeviceContext *immediate, *deferred, *deferred2;
32858 struct d3d11_test_context test_context;
32859 D3D11_TEXTURE2D_DESC texture_desc;
32860 ID3D11CommandList *list1, *list2;
32861 ID3D11RenderTargetView *rtv;
32862 D3D11_BLEND_DESC blend_desc;
32863 ID3D11Texture2D *texture;
32864 float blend_factor[4];
32865 ID3D11Device *device;
32866 UINT sample_mask;
32867 DWORD color;
32868 HRESULT hr;
32870 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
32871 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32872 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
32873 static const float black[] = {0.0f, 0.0f, 0.0f, 1.0f};
32875 if (!init_test_context(&test_context, NULL))
32876 return;
32878 device = test_context.device;
32879 immediate = test_context.immediate_context;
32881 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32882 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32884 memset(&blend_desc, 0, sizeof(blend_desc));
32886 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED;
32887 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &red_blend);
32888 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32889 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN;
32890 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &green_blend);
32891 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32892 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_BLUE;
32893 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blue_blend);
32894 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32896 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32898 ID3D11DeviceContext_ClearRenderTargetView(deferred, test_context.backbuffer_rtv, green);
32900 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32901 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32903 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32904 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32906 color = get_texture_color(test_context.backbuffer, 320, 240);
32907 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32909 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32910 color = get_texture_color(test_context.backbuffer, 320, 240);
32911 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32913 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32914 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32915 color = get_texture_color(test_context.backbuffer, 320, 240);
32916 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32918 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32919 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, TRUE);
32920 color = get_texture_color(test_context.backbuffer, 320, 240);
32921 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32923 ID3D11CommandList_Release(list2);
32925 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, TRUE);
32926 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32927 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32929 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32930 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, TRUE);
32931 color = get_texture_color(test_context.backbuffer, 320, 240);
32932 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32934 ID3D11CommandList_Release(list2);
32935 ID3D11CommandList_Release(list1);
32936 ID3D11DeviceContext_Release(deferred);
32938 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32939 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
32940 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
32941 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
32942 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32944 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32945 ID3D11DeviceContext_ClearRenderTargetView(immediate, rtv, green);
32947 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32948 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32950 ID3D11DeviceContext_CopyResource(deferred, (ID3D11Resource *)test_context.backbuffer, (ID3D11Resource *)texture);
32952 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32953 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32955 ID3D11DeviceContext_ClearRenderTargetView(immediate, rtv, blue);
32956 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32957 color = get_texture_color(test_context.backbuffer, 320, 240);
32958 ok(color == 0xffff0000, "Got unexpected color %#08x.\n", color);
32960 ID3D11CommandList_Release(list1);
32961 ID3D11DeviceContext_Release(deferred);
32963 /* As Get* calls imply, state changes recorded into a command list do not
32964 * affect subsequent draws after the state is restored or cleared. */
32966 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32967 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32969 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32971 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32972 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32974 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32975 ID3D11DeviceContext_OMSetBlendState(immediate, blue_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32976 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32977 draw_color_quad(&test_context, &white);
32978 color = get_texture_color(test_context.backbuffer, 320, 240);
32979 ok(color == 0xffff0000, "Got unexpected color %#08x.\n", color);
32981 ID3D11DeviceContext_OMGetBlendState(immediate, &ret_blend, blend_factor, &sample_mask);
32982 ok(ret_blend == blue_blend, "Got unexpected blend state %p.\n", ret_blend);
32983 ID3D11BlendState_Release(ret_blend);
32985 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32986 ID3D11DeviceContext_OMSetBlendState(immediate, blue_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32987 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
32988 ID3D11DeviceContext_OMSetRenderTargets(immediate, 1, &test_context.backbuffer_rtv, NULL);
32989 set_viewport(immediate, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
32990 draw_color_quad(&test_context, &white);
32991 color = get_texture_color(test_context.backbuffer, 320, 240);
32992 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32994 ID3D11DeviceContext_OMGetBlendState(immediate, &ret_blend, blend_factor, &sample_mask);
32995 ok(!ret_blend, "Got unexpected blend state %p.\n", ret_blend);
32997 ID3D11CommandList_Release(list1);
32998 ID3D11DeviceContext_Release(deferred);
33000 /* Command lists do not inherit state from the immediate context. */
33002 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
33003 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
33005 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
33007 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
33008 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
33009 test_context.immediate_context = deferred;
33010 draw_color_quad(&test_context, &white);
33011 test_context.immediate_context = immediate;
33012 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list1);
33013 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33015 ID3D11DeviceContext_OMSetBlendState(immediate, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
33016 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
33017 color = get_texture_color(test_context.backbuffer, 320, 240);
33018 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
33020 ID3D11CommandList_Release(list1);
33021 ID3D11DeviceContext_Release(deferred);
33023 /* The clearing of state done by FinishCommandList is captured by a
33024 * subsequent call to FinishCommandList... */
33026 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
33027 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
33029 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
33030 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list1);
33031 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33032 ID3D11CommandList_Release(list1);
33034 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
33035 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
33036 test_context.immediate_context = deferred;
33037 draw_color_quad(&test_context, &white);
33038 test_context.immediate_context = immediate;
33039 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
33040 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33042 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
33043 ID3D11DeviceContext_OMSetBlendState(immediate, red_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
33044 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
33045 color = get_texture_color(test_context.backbuffer, 320, 240);
33046 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
33048 ID3D11CommandList_Release(list1);
33050 /* ...and so is the save/restore. */
33052 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
33053 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
33054 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33055 ID3D11CommandList_Release(list1);
33057 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
33058 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
33059 test_context.immediate_context = deferred;
33060 draw_color_quad(&test_context, &white);
33061 test_context.immediate_context = immediate;
33062 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
33063 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33065 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
33066 ID3D11DeviceContext_OMSetBlendState(immediate, red_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
33067 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
33068 color = get_texture_color(test_context.backbuffer, 320, 240);
33069 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
33071 ID3D11CommandList_Release(list1);
33073 ID3D11DeviceContext_Release(deferred);
33075 /* Similarly, clearing of state done by ExecuteCommandList is captured by a
33076 * subsequent call to FinishCommandList. */
33078 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
33079 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
33080 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred2);
33081 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
33083 ID3D11DeviceContext_OMSetBlendState(deferred2, blue_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
33085 hr = ID3D11DeviceContext_FinishCommandList(deferred2, FALSE, &list1);
33086 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33088 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
33089 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, FALSE);
33090 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
33091 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
33092 test_context.immediate_context = deferred;
33093 draw_color_quad(&test_context, &white);
33094 test_context.immediate_context = immediate;
33095 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
33096 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33098 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
33099 ID3D11DeviceContext_OMSetBlendState(immediate, red_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
33100 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, FALSE);
33101 color = get_texture_color(test_context.backbuffer, 320, 240);
33102 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
33104 ID3D11CommandList_Release(list2);
33106 /* Make sure that save/restore is handled correctly as well. */
33108 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
33109 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, TRUE);
33110 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
33111 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
33112 test_context.immediate_context = deferred;
33113 draw_color_quad(&test_context, &white);
33114 test_context.immediate_context = immediate;
33115 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
33116 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33118 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
33119 ID3D11DeviceContext_OMSetBlendState(immediate, red_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
33120 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, FALSE);
33121 color = get_texture_color(test_context.backbuffer, 320, 240);
33122 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
33124 ID3D11CommandList_Release(list2);
33126 ID3D11CommandList_Release(list1);
33127 ID3D11DeviceContext_Release(deferred2);
33128 ID3D11DeviceContext_Release(deferred);
33130 ID3D11BlendState_Release(red_blend);
33131 ID3D11BlendState_Release(green_blend);
33132 ID3D11BlendState_Release(blue_blend);
33133 ID3D11RenderTargetView_Release(rtv);
33134 ID3D11Texture2D_Release(texture);
33135 release_test_context(&test_context);
33138 static void test_deferred_context_queries(void)
33140 ID3D11DeviceContext *immediate, *deferred;
33141 struct d3d11_test_context test_context;
33142 D3D11_QUERY_DESC query_desc;
33143 ID3D11Asynchronous *query;
33144 ID3D11CommandList *list;
33145 ID3D11Device *device;
33146 HRESULT hr;
33148 union
33150 UINT64 uint;
33151 DWORD dword[2];
33152 } data;
33154 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
33156 if (!init_test_context(&test_context, NULL))
33157 return;
33159 device = test_context.device;
33160 immediate = test_context.immediate_context;
33162 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
33163 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
33165 query_desc.Query = D3D11_QUERY_OCCLUSION;
33166 query_desc.MiscFlags = 0;
33167 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
33168 ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
33170 hr = ID3D11DeviceContext_GetData(deferred, query, NULL, 0, 0);
33171 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
33172 hr = ID3D11DeviceContext_GetData(deferred, query, &data, sizeof(data), 0);
33173 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
33175 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
33176 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
33178 ID3D11DeviceContext_Begin(deferred, query);
33180 hr = ID3D11DeviceContext_GetData(deferred, query, &data, sizeof(data), 0);
33181 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
33183 test_context.immediate_context = deferred;
33184 draw_color_quad(&test_context, &white);
33185 test_context.immediate_context = immediate;
33187 ID3D11DeviceContext_End(deferred, query);
33189 hr = ID3D11DeviceContext_GetData(deferred, query, &data, sizeof(data), 0);
33190 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
33191 hr = ID3D11DeviceContext_GetData(immediate, query, &data, sizeof(data), 0);
33192 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
33194 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
33196 hr = ID3D11DeviceContext_GetData(deferred, query, &data, sizeof(data), 0);
33197 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
33198 hr = ID3D11DeviceContext_GetData(immediate, query, &data, sizeof(data), 0);
33199 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
33201 ID3D11DeviceContext_ExecuteCommandList(immediate, list, FALSE);
33203 hr = ID3D11DeviceContext_GetData(deferred, query, &data, sizeof(data), 0);
33204 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
33205 hr = ID3D11DeviceContext_GetData(deferred, query, NULL, 0, 0);
33206 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
33208 get_query_data(immediate, query, &data, sizeof(data));
33209 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
33211 ID3D11Asynchronous_Release(query);
33212 ID3D11CommandList_Release(list);
33213 ID3D11DeviceContext_Release(deferred);
33214 release_test_context(&test_context);
33217 static void test_deferred_context_map(void)
33219 ID3D11DeviceContext *immediate, *deferred;
33220 struct d3d11_test_context test_context;
33221 D3D11_SUBRESOURCE_DATA resource_data;
33222 D3D11_BUFFER_DESC buffer_desc = {0};
33223 D3D11_MAPPED_SUBRESOURCE map_desc;
33224 ID3D11Buffer *buffer, *buffer2;
33225 struct resource_readback rb;
33226 ID3D11CommandList *list;
33227 float data[16], value;
33228 ID3D11Device *device;
33229 float *map_data;
33230 unsigned int i;
33231 HRESULT hr;
33233 if (!init_test_context(&test_context, NULL))
33234 return;
33236 device = test_context.device;
33237 immediate = test_context.immediate_context;
33239 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
33240 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
33242 for (i = 0; i < ARRAY_SIZE(data); ++i)
33243 data[i] = i;
33244 resource_data.pSysMem = data;
33245 resource_data.SysMemPitch = 0;
33246 resource_data.SysMemSlicePitch = 0;
33248 buffer_desc.ByteWidth = sizeof(data);
33249 buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
33250 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
33251 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
33252 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
33253 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
33254 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer2);
33255 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
33257 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &map_desc);
33258 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
33260 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
33261 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
33263 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &map_desc);
33264 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
33266 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
33267 todo_wine ok(hr == D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, "Got unexpected hr %#x.\n", hr);
33269 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33270 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33271 map_data = map_desc.pData;
33272 /* The previous contents of map_data are undefined and may in practice be
33273 * uninitialized garbage. */
33274 for (i = 0; i < ARRAY_SIZE(data); ++i)
33275 map_data[i] = 2 * i;
33277 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33279 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33280 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33281 map_data = map_desc.pData;
33282 for (i = 0; i < ARRAY_SIZE(data); ++i)
33283 map_data[i] = 3 * i;
33284 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33286 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
33287 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33289 get_buffer_readback(buffer, &rb);
33290 for (i = 0; i < ARRAY_SIZE(data); ++i)
33292 value = get_readback_float(&rb, i, 0);
33293 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
33295 release_resource_readback(&rb);
33297 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
33299 get_buffer_readback(buffer, &rb);
33300 for (i = 0; i < ARRAY_SIZE(data); ++i)
33302 value = get_readback_float(&rb, i, 0);
33303 ok(value == 3 * i, "Got unexpected value %.8e at %u.\n", value, i);
33305 release_resource_readback(&rb);
33307 ID3D11CommandList_Release(list);
33309 /* Dead Rising unmaps a resource on the wrong context. */
33311 hr = ID3D11DeviceContext_Map(immediate, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33312 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33314 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33316 ID3D11DeviceContext_Unmap(immediate, (ID3D11Resource *)buffer, 0);
33318 /* Test WRITE_NO_OVERWRITE. */
33320 hr = ID3D11DeviceContext_Map(immediate, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33321 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33322 map_data = map_desc.pData;
33323 for (i = 0; i < ARRAY_SIZE(data); ++i)
33324 map_data[i] = i;
33325 ID3D11DeviceContext_Unmap(immediate, (ID3D11Resource *)buffer, 0);
33327 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
33328 todo_wine ok(hr == D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, "Got unexpected hr %#x.\n", hr);
33330 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33331 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33332 map_data = map_desc.pData;
33333 for (i = 0; i < ARRAY_SIZE(data); ++i)
33334 map_data[i] = 2 * i;
33335 memcpy(data, map_data, sizeof(data));
33336 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33338 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &map_desc);
33339 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
33341 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
33342 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
33344 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &map_desc);
33345 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
33347 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
33348 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33350 map_data = map_desc.pData;
33351 for (i = 0; i < ARRAY_SIZE(data); ++i)
33353 ok(map_data[i] == 2 * i, "Got unexpected value %.8e at %u.\n", map_data[i], i);
33354 if (i % 2)
33355 map_data[i] = 3 * i;
33357 memcpy(data, map_data, sizeof(data));
33359 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33361 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
33362 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33364 map_data = map_desc.pData;
33365 for (i = 0; i < ARRAY_SIZE(data); ++i)
33367 ok(map_data[i] == data[i], "Got unexpected value %.8e at %u.\n", map_data[i], i);
33368 if (i % 3)
33369 map_data[i] = 4 * i;
33371 memcpy(data, map_data, sizeof(data));
33373 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33375 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
33376 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33378 get_buffer_readback(buffer, &rb);
33379 for (i = 0; i < ARRAY_SIZE(data); ++i)
33381 value = get_readback_float(&rb, i, 0);
33382 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
33384 release_resource_readback(&rb);
33386 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
33388 get_buffer_readback(buffer, &rb);
33389 for (i = 0; i < ARRAY_SIZE(data); ++i)
33391 value = get_readback_float(&rb, i, 0);
33392 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
33394 release_resource_readback(&rb);
33396 ID3D11CommandList_Release(list);
33398 /* Do something with the mapped data from within the deferred context. */
33400 hr = ID3D11DeviceContext_Map(immediate, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33401 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33402 map_data = map_desc.pData;
33403 for (i = 0; i < ARRAY_SIZE(data); ++i)
33404 map_data[i] = i;
33405 ID3D11DeviceContext_Unmap(immediate, (ID3D11Resource *)buffer, 0);
33407 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33408 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33409 map_data = map_desc.pData;
33410 for (i = 0; i < ARRAY_SIZE(data); ++i)
33411 map_data[i] = 2 * i;
33412 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33414 ID3D11DeviceContext_CopyResource(deferred, (ID3D11Resource *)buffer2, (ID3D11Resource *)buffer);
33416 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33417 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33418 map_data = map_desc.pData;
33419 for (i = 0; i < ARRAY_SIZE(data); ++i)
33420 map_data[i] = 3 * i;
33421 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33423 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
33424 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33426 get_buffer_readback(buffer, &rb);
33427 for (i = 0; i < ARRAY_SIZE(data); ++i)
33429 value = get_readback_float(&rb, i, 0);
33430 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
33432 release_resource_readback(&rb);
33434 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
33436 get_buffer_readback(buffer2, &rb);
33437 for (i = 0; i < ARRAY_SIZE(data); ++i)
33439 value = get_readback_float(&rb, i, 0);
33440 ok(value == 2 * i, "Got unexpected value %.8e at %u.\n", value, i);
33442 release_resource_readback(&rb);
33444 get_buffer_readback(buffer, &rb);
33445 for (i = 0; i < ARRAY_SIZE(data); ++i)
33447 value = get_readback_float(&rb, i, 0);
33448 ok(value == 3 * i, "Got unexpected value %.8e at %u.\n", value, i);
33450 release_resource_readback(&rb);
33452 ID3D11CommandList_Release(list);
33454 ID3D11Buffer_Release(buffer2);
33455 ID3D11Buffer_Release(buffer);
33457 /* Test UpdateSubresource. */
33459 for (i = 0; i < ARRAY_SIZE(data); ++i)
33460 data[i] = i;
33462 buffer_desc.ByteWidth = sizeof(data);
33463 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
33464 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
33465 buffer_desc.CPUAccessFlags = 0;
33466 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
33467 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
33468 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer2);
33469 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
33471 for (i = 0; i < ARRAY_SIZE(data); ++i)
33472 data[i] = 2 * i;
33473 ID3D11DeviceContext_UpdateSubresource(deferred, (ID3D11Resource *)buffer, 0, NULL, data, 0, 0);
33475 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
33476 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33478 get_buffer_readback(buffer, &rb);
33479 for (i = 0; i < ARRAY_SIZE(data); ++i)
33481 value = get_readback_float(&rb, i, 0);
33482 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
33484 release_resource_readback(&rb);
33486 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
33488 get_buffer_readback(buffer, &rb);
33489 for (i = 0; i < ARRAY_SIZE(data); ++i)
33491 value = get_readback_float(&rb, i, 0);
33492 ok(value == 2 * i, "Got unexpected value %.8e at %u.\n", value, i);
33494 release_resource_readback(&rb);
33496 ID3D11CommandList_Release(list);
33498 ID3D11Buffer_Release(buffer2);
33499 ID3D11Buffer_Release(buffer);
33501 ID3D11DeviceContext_Release(deferred);
33502 release_test_context(&test_context);
33505 static void test_texture_compressed_3d(void)
33507 struct d3d11_test_context test_context;
33508 D3D11_SUBRESOURCE_DATA resource_data;
33509 D3D11_TEXTURE3D_DESC texture_desc;
33510 ID3D11SamplerState *sampler_state;
33511 unsigned int idx, r0, r1, x, y, z;
33512 D3D11_SAMPLER_DESC sampler_desc;
33513 ID3D11ShaderResourceView *srv;
33514 ID3D11DeviceContext *context;
33515 struct resource_readback rb;
33516 ID3D11Texture3D *texture;
33517 DWORD colour, expected;
33518 ID3D11PixelShader *ps;
33519 ID3D11Device *device;
33520 DWORD *texture_data;
33521 BOOL equal = TRUE;
33522 HRESULT hr;
33524 static const DWORD ps_code[] =
33526 #if 0
33527 Texture3D t;
33528 SamplerState s;
33530 float4 main(float4 position : SV_POSITION) : SV_Target
33532 return t.Sample(s, position.xyz / float3(640, 480, 1));
33534 #endif
33535 0x43425844, 0x27b15ae8, 0xbebf46f7, 0x6cd88d8d, 0x5118de51, 0x00000001, 0x00000134, 0x00000003,
33536 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
33537 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000070f, 0x505f5653, 0x5449534f, 0x004e4f49,
33538 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
33539 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
33540 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
33541 0x04002064, 0x00101072, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
33542 0x00000001, 0x0a000038, 0x00100072, 0x00000000, 0x00101246, 0x00000000, 0x00004002, 0x3acccccd,
33543 0x3b088889, 0x3f800000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
33544 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
33547 static const unsigned int block_indices[] =
33549 0, 1, 3, 2,
33550 6, 7, 5, 4,
33551 0, 1, 3, 2,
33552 6, 7, 5, 4,
33555 if (!init_test_context(&test_context, NULL))
33556 return;
33557 device = test_context.device;
33558 context = test_context.immediate_context;
33560 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
33561 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33563 /* Simply test all combinations of r0 and r1. */
33564 texture_data = heap_alloc(256 * 256 * sizeof(UINT64));
33565 for (r1 = 0; r1 < 256; ++r1)
33567 for (r0 = 0; r0 < 256; ++r0)
33569 /* bits = block_indices[] */
33570 texture_data[(r1 * 256 + r0) * 2 + 0] = 0xe4c80000 | (r1 << 8) | r0;
33571 texture_data[(r1 * 256 + r0) * 2 + 1] = 0x97e4c897;
33574 resource_data.pSysMem = texture_data;
33575 resource_data.SysMemPitch = 64 * sizeof(UINT64);
33576 resource_data.SysMemSlicePitch = 64 * resource_data.SysMemPitch;
33578 texture_desc.Width = 256;
33579 texture_desc.Height = 256;
33580 texture_desc.Depth = 16;
33581 texture_desc.MipLevels = 1;
33582 texture_desc.Format = DXGI_FORMAT_BC4_UNORM;
33583 texture_desc.Usage = D3D11_USAGE_DEFAULT;
33584 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
33585 texture_desc.CPUAccessFlags = 0;
33586 texture_desc.MiscFlags = 0;
33587 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, &resource_data, &texture);
33588 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33589 heap_free(texture_data);
33591 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
33592 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33594 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
33595 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
33596 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
33597 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
33598 sampler_desc.MipLODBias = 0.0f;
33599 sampler_desc.MaxAnisotropy = 0;
33600 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
33601 sampler_desc.BorderColor[0] = 0.0f;
33602 sampler_desc.BorderColor[1] = 0.0f;
33603 sampler_desc.BorderColor[2] = 0.0f;
33604 sampler_desc.BorderColor[3] = 0.0f;
33605 sampler_desc.MinLOD = 0.0f;
33606 sampler_desc.MaxLOD = 0.0f;
33607 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
33608 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33610 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
33611 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
33612 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
33614 for (z = 0; z < 16; ++z)
33616 draw_quad_z(&test_context, (z * 2.0f + 1.0f) / 32.0f);
33617 get_texture_readback(test_context.backbuffer, 0, &rb);
33618 for (y = 0; y < 256; ++y)
33620 for (x = 0; x < 256; ++x)
33622 idx = z * 64 * 64 + (y / 4) * 64 + (x / 4);
33623 r0 = idx % 256;
33624 r1 = idx / 256;
33626 switch (block_indices[(y % 4) * 4 + (x % 4)])
33628 case 0: expected = r0; break;
33629 case 1: expected = r1; break;
33630 case 2: expected = r0 > r1 ? (12 * r0 + 2 * r1 + 7) / 14 : (8 * r0 + 2 * r1 + 5) / 10; break;
33631 case 3: expected = r0 > r1 ? (10 * r0 + 4 * r1 + 7) / 14 : (6 * r0 + 4 * r1 + 5) / 10; break;
33632 case 4: expected = r0 > r1 ? ( 8 * r0 + 6 * r1 + 7) / 14 : (4 * r0 + 6 * r1 + 5) / 10; break;
33633 case 5: expected = r0 > r1 ? ( 6 * r0 + 8 * r1 + 7) / 14 : (2 * r0 + 8 * r1 + 5) / 10; break;
33634 case 6: expected = r0 > r1 ? ( 4 * r0 + 10 * r1 + 7) / 14 : 0x00; break;
33635 case 7: expected = r0 > r1 ? ( 2 * r0 + 12 * r1 + 7) / 14 : 0xff; break;
33636 default: expected = ~0u; break;
33638 expected |= 0xff000000;
33639 colour = get_readback_color(&rb, (x * 640 + 128) / 256, (y * 480 + 128) / 256, 0);
33640 if (!(equal = compare_color(colour, expected, 8)))
33641 break;
33643 if (!equal)
33644 break;
33646 release_resource_readback(&rb);
33647 if (!equal)
33648 break;
33650 ok(equal, "Got unexpected colour 0x%08x at (%u, %u, %u), expected 0x%08x.\n", colour, x, y, z, expected);
33652 ID3D11PixelShader_Release(ps);
33653 ID3D11SamplerState_Release(sampler_state);
33654 ID3D11ShaderResourceView_Release(srv);
33655 ID3D11Texture3D_Release(texture);
33656 release_test_context(&test_context);
33659 static void test_constant_buffer_offset(void)
33661 static const float black[] = {0.0f, 0.0f, 0.0f, 1.0f};
33662 ID3D11Buffer *buffers[2], *ret_buffers[2];
33663 D3D11_FEATURE_DATA_D3D11_OPTIONS options;
33664 struct d3d11_test_context test_context;
33665 struct vec4 buffer_data[32] = {{0}};
33666 ID3D11DeviceContext1 *context;
33667 UINT offsets[2], counts[2];
33668 ID3D11PixelShader *ps;
33669 ID3D11Device *device;
33670 DWORD color;
33671 HRESULT hr;
33673 static const DWORD ps_code[] =
33675 #if 0
33676 cbuffer c1 : register(b1)
33678 float r, g;
33680 cbuffer c2 : register(b2)
33682 float b, a;
33685 float4 main() : SV_Target
33687 return float4(r, g, b, a);
33689 #endif
33690 0x43425844, 0x8ca1d640, 0x33cd6f81, 0x987c9395, 0xc2110ba4, 0x00000001, 0x000000e0, 0x00000003,
33691 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
33692 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
33693 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000068, 0x00000040, 0x0000001a,
33694 0x04000059, 0x00208e46, 0x00000001, 0x00000001, 0x04000059, 0x00208e46, 0x00000002, 0x00000001,
33695 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x00102032, 0x00000000, 0x00208046, 0x00000001,
33696 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00208406, 0x00000002, 0x00000000, 0x0100003e,
33699 if (!init_test_context(&test_context, NULL))
33700 return;
33701 device = test_context.device;
33703 if (FAILED(ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D11_OPTIONS, &options, sizeof(options)))
33704 || !options.ConstantBufferOffsetting)
33706 skip("Constant buffer offsetting is not supported.\n");
33707 release_test_context(&test_context);
33708 return;
33711 if (FAILED(ID3D11DeviceContext_QueryInterface(test_context.immediate_context,
33712 &IID_ID3D11DeviceContext1, (void **)&context)))
33714 skip("ID3D11DeviceContext1 is not available.\n");
33715 release_test_context(&test_context);
33716 return;
33719 buffer_data[0].x = 0.1f;
33720 buffer_data[0].y = 0.2f;
33721 buffer_data[16].x = 0.3f;
33722 buffer_data[16].y = 0.4f;
33723 buffers[0] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(buffer_data), buffer_data);
33724 buffer_data[0].x = 0.5f;
33725 buffer_data[0].y = 0.6f;
33726 buffer_data[16].x = 0.7f;
33727 buffer_data[16].y = 0.8f;
33728 buffers[1] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(buffer_data), buffer_data);
33730 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
33731 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
33733 ID3D11DeviceContext1_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
33734 ID3D11DeviceContext1_PSSetShader(context, ps, NULL, 0);
33736 memset(ret_buffers, 0xab, sizeof(ret_buffers));
33737 memset(offsets, 0xab, sizeof(offsets));
33738 memset(counts, 0xab, sizeof(counts));
33739 ID3D11DeviceContext1_PSGetConstantBuffers1(context, 1, 2, ret_buffers, offsets, counts);
33740 ok(!ret_buffers[0], "Got buffer %p.\n", ret_buffers[0]);
33741 ok(!ret_buffers[1], "Got buffer %p.\n", ret_buffers[1]);
33742 ok(!offsets[0], "Got offset %u.\n", offsets[0]);
33743 ok(!offsets[1], "Got offset %u.\n", offsets[1]);
33744 ok(counts[0] == 4096, "Got count %u.\n", counts[0]);
33745 ok(counts[1] == 4096, "Got count %u.\n", counts[1]);
33747 offsets[0] = 0;
33748 offsets[1] = 16;
33749 counts[0] = 16;
33750 counts[1] = 16;
33751 ID3D11DeviceContext1_PSSetConstantBuffers1(context, 1, 2, buffers, offsets, counts);
33753 ID3D11DeviceContext1_PSGetConstantBuffers1(context, 1, 2, ret_buffers, offsets, counts);
33754 ok(ret_buffers[0] == buffers[0], "Got buffer %p.\n", ret_buffers[0]);
33755 ok(ret_buffers[1] == buffers[1], "Got buffer %p.\n", ret_buffers[1]);
33756 ok(offsets[0] == 0, "Got offset %u.\n", offsets[0]);
33757 ok(offsets[1] == 16, "Got offset %u.\n", offsets[1]);
33758 ok(counts[0] == 16, "Got count %u.\n", counts[0]);
33759 ok(counts[1] == 16, "Got count %u.\n", counts[1]);
33760 ID3D11Buffer_Release(ret_buffers[0]);
33761 ID3D11Buffer_Release(ret_buffers[1]);
33763 memset(ret_buffers, 0xab, sizeof(ret_buffers));
33764 memset(offsets, 0xab, sizeof(offsets));
33765 ID3D11DeviceContext1_PSGetConstantBuffers1(context, 1, 2, ret_buffers, offsets, NULL);
33766 ok(ret_buffers[0] == buffers[0], "Got buffer %p.\n", ret_buffers[0]);
33767 ok(ret_buffers[1] == buffers[1], "Got buffer %p.\n", ret_buffers[1]);
33768 ok(offsets[0] == 0, "Got offset %u.\n", offsets[0]);
33769 ok(offsets[1] == 16, "Got offset %u.\n", offsets[1]);
33770 ID3D11Buffer_Release(ret_buffers[0]);
33771 ID3D11Buffer_Release(ret_buffers[1]);
33773 memset(ret_buffers, 0xab, sizeof(ret_buffers));
33774 memset(counts, 0xab, sizeof(counts));
33775 ID3D11DeviceContext1_PSGetConstantBuffers1(context, 1, 2, ret_buffers, NULL, counts);
33776 ok(ret_buffers[0] == buffers[0], "Got buffer %p.\n", ret_buffers[0]);
33777 ok(ret_buffers[1] == buffers[1], "Got buffer %p.\n", ret_buffers[1]);
33778 ok(counts[0] == 16, "Got count %u.\n", counts[0]);
33779 ok(counts[1] == 16, "Got count %u.\n", counts[1]);
33780 ID3D11Buffer_Release(ret_buffers[0]);
33781 ID3D11Buffer_Release(ret_buffers[1]);
33783 draw_quad(&test_context);
33784 color = get_texture_color(test_context.backbuffer, 320, 240);
33785 ok(compare_color(color, 0xccb23319, 1), "Got unexpected color 0x%08x.\n", color);
33787 /* The following calls are all invalid. */
33789 offsets[0] = 0;
33790 offsets[1] = 1;
33791 counts[0] = 32;
33792 counts[1] = 16;
33793 ID3D11DeviceContext1_PSSetConstantBuffers1(context, 1, 2, buffers, offsets, counts);
33795 ID3D11DeviceContext1_PSGetConstantBuffers1(context, 1, 2, ret_buffers, offsets, counts);
33796 ok(ret_buffers[0] == buffers[0], "Got buffer %p.\n", ret_buffers[0]);
33797 ok(ret_buffers[1] == buffers[1], "Got buffer %p.\n", ret_buffers[1]);
33798 ok(offsets[0] == 0, "Got offset %u.\n", offsets[0]);
33799 ok(offsets[1] == 16, "Got offset %u.\n", offsets[1]);
33800 ok(counts[0] == 16, "Got count %u.\n", counts[0]);
33801 ok(counts[1] == 16, "Got count %u.\n", counts[1]);
33802 ID3D11Buffer_Release(ret_buffers[0]);
33803 ID3D11Buffer_Release(ret_buffers[1]);
33805 offsets[0] = 0;
33806 offsets[1] = 0;
33807 counts[0] = 17;
33808 counts[1] = 16;
33809 ID3D11DeviceContext1_PSSetConstantBuffers1(context, 1, 2, buffers, offsets, counts);
33811 ID3D11DeviceContext1_PSGetConstantBuffers1(context, 1, 2, ret_buffers, offsets, counts);
33812 ok(ret_buffers[0] == buffers[0], "Got buffer %p.\n", ret_buffers[0]);
33813 ok(ret_buffers[1] == buffers[1], "Got buffer %p.\n", ret_buffers[1]);
33814 ok(offsets[0] == 0, "Got offset %u.\n", offsets[0]);
33815 ok(offsets[1] == 16, "Got offset %u.\n", offsets[1]);
33816 ok(counts[0] == 16, "Got count %u.\n", counts[0]);
33817 ok(counts[1] == 16, "Got count %u.\n", counts[1]);
33818 ID3D11Buffer_Release(ret_buffers[0]);
33819 ID3D11Buffer_Release(ret_buffers[1]);
33821 ID3D11DeviceContext1_PSSetConstantBuffers1(context, 1, 2, buffers, offsets, NULL);
33823 ID3D11DeviceContext1_PSGetConstantBuffers1(context, 1, 2, ret_buffers, offsets, counts);
33824 ok(ret_buffers[0] == buffers[0], "Got buffer %p.\n", ret_buffers[0]);
33825 ok(ret_buffers[1] == buffers[1], "Got buffer %p.\n", ret_buffers[1]);
33826 ok(offsets[0] == 0, "Got offset %u.\n", offsets[0]);
33827 ok(offsets[1] == 16, "Got offset %u.\n", offsets[1]);
33828 ok(counts[0] == 16, "Got count %u.\n", counts[0]);
33829 ok(counts[1] == 16, "Got count %u.\n", counts[1]);
33830 ID3D11Buffer_Release(ret_buffers[0]);
33831 ID3D11Buffer_Release(ret_buffers[1]);
33833 counts[0] = 32;
33834 counts[1] = 16;
33835 ID3D11DeviceContext1_PSSetConstantBuffers1(context, 1, 2, buffers, NULL, counts);
33837 ID3D11DeviceContext1_PSGetConstantBuffers1(context, 1, 2, ret_buffers, offsets, counts);
33838 ok(ret_buffers[0] == buffers[0], "Got buffer %p.\n", ret_buffers[0]);
33839 ok(ret_buffers[1] == buffers[1], "Got buffer %p.\n", ret_buffers[1]);
33840 ok(offsets[0] == 0, "Got offset %u.\n", offsets[0]);
33841 ok(offsets[1] == 16, "Got offset %u.\n", offsets[1]);
33842 ok(counts[0] == 16, "Got count %u.\n", counts[0]);
33843 ok(counts[1] == 16, "Got count %u.\n", counts[1]);
33844 ID3D11Buffer_Release(ret_buffers[0]);
33845 ID3D11Buffer_Release(ret_buffers[1]);
33847 draw_quad(&test_context);
33848 color = get_texture_color(test_context.backbuffer, 320, 240);
33849 ok(compare_color(color, 0xccb23319, 1), "Got unexpected color 0x%08x.\n", color);
33851 ID3D11DeviceContext1_PSSetConstantBuffers1(context, 1, 2, buffers, NULL, NULL);
33853 ID3D11DeviceContext1_PSGetConstantBuffers1(context, 1, 2, ret_buffers, offsets, counts);
33854 ok(ret_buffers[0] == buffers[0], "Got buffer %p.\n", ret_buffers[0]);
33855 ok(ret_buffers[1] == buffers[1], "Got buffer %p.\n", ret_buffers[1]);
33856 ok(!offsets[0], "Got offset %u.\n", offsets[0]);
33857 ok(!offsets[1], "Got offset %u.\n", offsets[1]);
33858 ok(counts[0] == 4096, "Got count %u.\n", counts[0]);
33859 ok(counts[1] == 4096, "Got count %u.\n", counts[1]);
33860 ID3D11Buffer_Release(ret_buffers[0]);
33861 ID3D11Buffer_Release(ret_buffers[1]);
33863 draw_quad(&test_context);
33864 color = get_texture_color(test_context.backbuffer, 320, 240);
33865 ok(compare_color(color, 0x99803319, 1), "Got unexpected color 0x%08x.\n", color);
33867 offsets[0] = 16;
33868 offsets[1] = 0;
33869 counts[0] = 16;
33870 counts[1] = 32;
33871 ID3D11DeviceContext1_PSSetConstantBuffers1(context, 1, 2, buffers, offsets, counts);
33873 ID3D11DeviceContext1_PSGetConstantBuffers1(context, 1, 2, ret_buffers, offsets, counts);
33874 ok(ret_buffers[0] == buffers[0], "Got buffer %p.\n", ret_buffers[0]);
33875 ok(ret_buffers[1] == buffers[1], "Got buffer %p.\n", ret_buffers[1]);
33876 ok(offsets[0] == 16, "Got offset %u.\n", offsets[0]);
33877 ok(offsets[1] == 0, "Got offset %u.\n", offsets[1]);
33878 ok(counts[0] == 16, "Got count %u.\n", counts[0]);
33879 ok(counts[1] == 32, "Got count %u.\n", counts[1]);
33880 ID3D11Buffer_Release(ret_buffers[0]);
33881 ID3D11Buffer_Release(ret_buffers[1]);
33883 draw_quad(&test_context);
33884 color = get_texture_color(test_context.backbuffer, 320, 240);
33885 ok(compare_color(color, 0x9980664c, 1), "Got unexpected color 0x%08x.\n", color);
33887 ID3D11DeviceContext1_PSSetConstantBuffers(context, 1, 2, buffers);
33889 ID3D11DeviceContext1_PSGetConstantBuffers1(context, 1, 2, ret_buffers, offsets, counts);
33890 ok(ret_buffers[0] == buffers[0], "Got buffer %p.\n", ret_buffers[0]);
33891 ok(ret_buffers[1] == buffers[1], "Got buffer %p.\n", ret_buffers[1]);
33892 ok(!offsets[0], "Got offset %u.\n", offsets[0]);
33893 ok(!offsets[1], "Got offset %u.\n", offsets[1]);
33894 ok(counts[0] == 4096, "Got count %u.\n", counts[0]);
33895 ok(counts[1] == 4096, "Got count %u.\n", counts[1]);
33896 ID3D11Buffer_Release(ret_buffers[0]);
33897 ID3D11Buffer_Release(ret_buffers[1]);
33899 draw_quad(&test_context);
33900 color = get_texture_color(test_context.backbuffer, 320, 240);
33901 ok(compare_color(color, 0x99803319, 1), "Got unexpected color 0x%08x.\n", color);
33903 ID3D11DeviceContext1_Release(context);
33904 ID3D11Buffer_Release(buffers[0]);
33905 ID3D11Buffer_Release(buffers[1]);
33906 ID3D11PixelShader_Release(ps);
33907 release_test_context(&test_context);
33910 static void fill_dynamic_vb_quad(const D3D11_MAPPED_SUBRESOURCE *map_desc, unsigned int x, unsigned int y)
33912 struct vec3 *quad = (struct vec3 *)map_desc->pData + 4 * x;
33914 memset(quad, 0, 4 * sizeof(*quad));
33916 quad[0].x = quad[1].x = -1.0f + 0.01f * x;
33917 quad[2].x = quad[3].x = -1.0f + 0.01f * (x + 1);
33919 quad[0].y = quad[2].y = -1.0f + 0.01f * y;
33920 quad[1].y = quad[3].y = -1.0f + 0.01f * (y + 1);
33923 /* Stress-test dynamic maps, to ensure that we are applying the correct
33924 * synchronization guarantees. */
33925 static void test_dynamic_map_synchronization(void)
33927 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
33928 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
33929 ID3D11DeviceContext *immediate, *deferred;
33930 struct d3d11_test_context test_context;
33931 D3D11_BUFFER_DESC buffer_desc = {0};
33932 D3D11_MAPPED_SUBRESOURCE map_desc;
33933 ID3D11CommandList *list;
33934 ID3D11Device *device;
33935 unsigned int x, y;
33936 HRESULT hr;
33938 if (!init_test_context(&test_context, NULL))
33939 return;
33940 device = test_context.device;
33941 immediate = test_context.immediate_context;
33943 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
33944 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
33946 buffer_desc.ByteWidth = 200 * 4 * sizeof(struct vec3);
33947 buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
33948 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
33949 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
33950 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &test_context.vb);
33951 ok(hr == S_OK, "Failed to create vertex buffer, hr %#x.\n", hr);
33953 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &red.x);
33955 for (y = 0; y < 200; ++y)
33957 if (y % 2)
33959 hr = ID3D11DeviceContext_Map(immediate, (ID3D11Resource *)test_context.vb,
33960 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33961 ok(hr == S_OK, "Failed to map buffer, hr %#x.\n", hr);
33963 fill_dynamic_vb_quad(&map_desc, 0, y);
33965 ID3D11DeviceContext_Unmap(immediate, (ID3D11Resource *)test_context.vb, 0);
33966 draw_color_quad(&test_context, &green);
33968 else
33970 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)test_context.vb,
33971 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33972 ok(hr == S_OK, "Failed to map buffer, hr %#x.\n", hr);
33974 fill_dynamic_vb_quad(&map_desc, 0, y);
33976 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)test_context.vb, 0);
33978 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
33979 ok(hr == S_OK, "Failed to record command list, hr %#x.\n", hr);
33980 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
33981 ID3D11CommandList_Release(list);
33982 draw_color_quad(&test_context, &green);
33985 for (x = 1; x < 200; ++x)
33987 hr = ID3D11DeviceContext_Map(immediate, (ID3D11Resource *)test_context.vb,
33988 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
33989 ok(hr == S_OK, "Failed to map buffer, hr %#x.\n", hr);
33991 fill_dynamic_vb_quad(&map_desc, x, y);
33993 ID3D11DeviceContext_Unmap(immediate, (ID3D11Resource *)test_context.vb, 0);
33994 ID3D11DeviceContext_Draw(immediate, 4, x * 4);
33998 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
34000 ID3D11DeviceContext_Release(deferred);
34001 release_test_context(&test_context);
34004 static void test_user_defined_annotation(void)
34006 struct d3d11_test_context test_context;
34007 ID3DUserDefinedAnnotation *annotation;
34008 ID3D11DeviceContext *context;
34009 HRESULT hr;
34010 int ret;
34012 if (!init_test_context(&test_context, NULL))
34013 return;
34015 hr = ID3D11DeviceContext_QueryInterface(test_context.immediate_context,
34016 &IID_ID3DUserDefinedAnnotation, (void **)&annotation);
34017 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
34018 ret = ID3DUserDefinedAnnotation_BeginEvent(annotation, L"Event 1");
34019 ok(ret == -1, "Got unexpected ret %d.\n", ret);
34020 ret = ID3DUserDefinedAnnotation_EndEvent(annotation);
34021 ok(ret == -1, "Got unexpected ret %d.\n", ret);
34022 ID3DUserDefinedAnnotation_SetMarker(annotation, L"Marker 1");
34023 ret = ID3DUserDefinedAnnotation_GetStatus(annotation);
34024 ok(!ret, "Got unexpected status %#x.\n", ret);
34025 ID3DUserDefinedAnnotation_Release(annotation);
34027 hr = ID3D11Device_CreateDeferredContext(test_context.device, 0, &context);
34028 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
34029 hr = ID3D11DeviceContext_QueryInterface(context, &IID_ID3DUserDefinedAnnotation, (void **)&annotation);
34030 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
34031 ret = ID3DUserDefinedAnnotation_BeginEvent(annotation, L"Event 2");
34032 ok(ret == -1, "Got unexpected ret %d.\n", ret);
34033 ret = ID3DUserDefinedAnnotation_EndEvent(annotation);
34034 ok(ret == -1, "Got unexpected ret %d.\n", ret);
34035 ID3DUserDefinedAnnotation_SetMarker(annotation, L"Marker 2");
34036 ret = ID3DUserDefinedAnnotation_GetStatus(annotation);
34037 ok(!ret, "Got unexpected status %#x.\n", ret);
34038 ID3DUserDefinedAnnotation_Release(annotation);
34039 ID3D11DeviceContext_Release(context);
34041 release_test_context(&test_context);
34044 START_TEST(d3d11)
34046 unsigned int argc, i;
34047 char **argv;
34049 use_mt = !getenv("WINETEST_NO_MT_D3D");
34051 argc = winetest_get_mainargs(&argv);
34052 for (i = 2; i < argc; ++i)
34054 if (!strcmp(argv[i], "--validate"))
34055 enable_debug_layer = TRUE;
34056 else if (!strcmp(argv[i], "--warp"))
34057 use_warp_adapter = TRUE;
34058 else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
34059 use_adapter_idx = atoi(argv[++i]);
34060 else if (!strcmp(argv[i], "--single"))
34061 use_mt = FALSE;
34064 print_adapter_info();
34066 queue_test(test_create_device);
34067 queue_for_each_feature_level(test_device_interfaces);
34068 queue_test(test_immediate_context);
34069 queue_test(test_create_deferred_context);
34070 queue_test(test_create_texture1d);
34071 queue_test(test_texture1d_interfaces);
34072 queue_test(test_create_texture2d);
34073 queue_test(test_texture2d_interfaces);
34074 queue_test(test_create_texture3d);
34075 queue_test(test_texture3d_interfaces);
34076 queue_test(test_create_buffer);
34077 queue_test(test_create_depthstencil_view);
34078 queue_test(test_depthstencil_view_interfaces);
34079 queue_test(test_create_rendertarget_view);
34080 queue_test(test_create_shader_resource_view);
34081 queue_for_each_feature_level(test_create_shader);
34082 queue_test(test_create_sampler_state);
34083 queue_test(test_create_blend_state);
34084 queue_test(test_create_depthstencil_state);
34085 queue_test(test_create_rasterizer_state);
34086 queue_test(test_create_query);
34087 queue_test(test_occlusion_query);
34088 queue_test(test_pipeline_statistics_query);
34089 queue_test(test_timestamp_query);
34090 queue_test(test_so_statistics_query);
34091 queue_test(test_device_removed_reason);
34092 queue_test(test_private_data);
34093 queue_for_each_feature_level(test_state_refcounting);
34094 queue_test(test_device_context_state);
34095 queue_test(test_blend);
34096 queue_test(test_texture1d);
34097 queue_test(test_texture);
34098 queue_test(test_cube_maps);
34099 queue_test(test_depth_stencil_sampling);
34100 queue_test(test_sample_c_lz);
34101 queue_test(test_multiple_render_targets);
34102 queue_test(test_render_target_views);
34103 queue_test(test_layered_rendering);
34104 queue_test(test_scissor);
34105 queue_test(test_clear_state);
34106 queue_test(test_il_append_aligned);
34107 queue_test(test_vertex_id);
34108 queue_test(test_fragment_coords);
34109 queue_test(test_initial_texture_data);
34110 queue_test(test_update_subresource);
34111 queue_test(test_copy_subresource_region);
34112 queue_test(test_copy_subresource_region_1d);
34113 queue_test(test_copy_subresource_region_3d);
34114 queue_test(test_resource_map);
34115 queue_for_each_feature_level(test_resource_access);
34116 queue_test(test_check_multisample_quality_levels);
34117 queue_for_each_feature_level(test_swapchain_formats);
34118 queue_test(test_swapchain_views);
34119 queue_test(test_swapchain_flip);
34120 queue_test(test_clear_render_target_view_1d);
34121 queue_test(test_clear_render_target_view_2d);
34122 queue_test(test_clear_render_target_view_3d);
34123 queue_test(test_clear_depth_stencil_view);
34124 queue_test(test_clear_buffer_unordered_access_view);
34125 queue_test(test_clear_image_unordered_access_view);
34126 queue_test(test_initial_depth_stencil_state);
34127 queue_test(test_draw_depth_only);
34128 queue_test(test_draw_uav_only);
34129 queue_test(test_cb_relative_addressing);
34130 queue_test(test_vs_input_relative_addressing);
34131 queue_test(test_getdc);
34132 queue_test(test_shader_stage_input_output_matching);
34133 queue_test(test_shader_interstage_interface);
34134 queue_test(test_sm4_if_instruction);
34135 queue_test(test_sm4_breakc_instruction);
34136 queue_test(test_sm4_continuec_instruction);
34137 queue_test(test_sm4_discard_instruction);
34138 queue_test(test_sm5_swapc_instruction);
34139 queue_test(test_create_input_layout);
34140 queue_test(test_input_layout_alignment);
34141 queue_test(test_input_assembler);
34142 queue_test(test_null_sampler);
34143 queue_test(test_check_feature_support);
34144 queue_test(test_create_unordered_access_view);
34145 queue_test(test_immediate_constant_buffer);
34146 queue_test(test_fp_specials);
34147 queue_test(test_uint_shader_instructions);
34148 queue_test(test_index_buffer_offset);
34149 queue_test(test_face_culling);
34150 queue_test(test_line_antialiasing_blending);
34151 queue_for_each_feature_level(test_format_support);
34152 queue_for_each_9_x_feature_level(test_fl9_draw);
34153 queue_test(test_ddy);
34154 queue_test(test_shader_input_registers_limits);
34155 queue_test(test_unbind_shader_resource_view);
34156 queue_test(test_stencil_separate);
34157 queue_test(test_uav_load);
34158 queue_test(test_cs_uav_store);
34159 queue_test(test_uav_store_immediate_constant);
34160 queue_test(test_ps_cs_uav_binding);
34161 queue_test(test_atomic_instructions);
34162 queue_test(test_sm4_ret_instruction);
34163 queue_test(test_primitive_restart);
34164 queue_test(test_resinfo_instruction);
34165 queue_test(test_sm5_bufinfo_instruction);
34166 queue_test(test_sampleinfo_instruction);
34167 queue_test(test_render_target_device_mismatch);
34168 queue_test(test_buffer_srv);
34169 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
34170 test_unaligned_raw_buffer_access);
34171 queue_test(test_uav_counters);
34172 queue_test(test_dispatch_indirect);
34173 queue_test(test_compute_shader_registers);
34174 queue_test(test_tgsm);
34175 queue_test(test_geometry_shader);
34176 queue_test(test_quad_tessellation);
34177 queue_test(test_stream_output);
34178 queue_test(test_fl10_stream_output_desc);
34179 queue_test(test_stream_output_resume);
34180 queue_test(test_stream_output_components);
34181 queue_test(test_stream_output_vs);
34182 queue_test(test_gather);
34183 queue_test(test_gather_c);
34184 queue_test(test_depth_bias);
34185 queue_test(test_fractional_viewports);
34186 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0, test_negative_viewports);
34187 queue_test(test_early_depth_stencil);
34188 queue_test(test_conservative_depth_output);
34189 queue_test(test_format_compatibility);
34190 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
34191 test_compressed_format_compatibility);
34192 queue_test(test_clip_distance);
34193 queue_test(test_combined_clip_and_cull_distances);
34194 queue_test(test_alpha_to_coverage);
34195 queue_test(test_unbound_multisample_texture);
34196 queue_test(test_multiple_viewports);
34197 queue_test(test_multisample_resolve);
34198 queue_test(test_sample_shading);
34199 queue_test(test_sample_mask);
34200 queue_test(test_depth_clip);
34201 queue_test(test_staging_buffers);
34202 queue_test(test_render_a8);
34203 queue_test(test_standard_pattern);
34204 queue_test(test_desktop_window);
34205 queue_test(test_sample_attached_rtv);
34206 queue_test(test_color_mask);
34207 queue_test(test_independent_blend);
34208 queue_test(test_dual_source_blend);
34209 queue_test(test_deferred_context_state);
34210 queue_test(test_deferred_context_swap_state);
34211 queue_test(test_deferred_context_rendering);
34212 queue_test(test_deferred_context_map);
34213 queue_test(test_deferred_context_queries);
34214 queue_test(test_unbound_streams);
34215 queue_test(test_texture_compressed_3d);
34216 queue_test(test_constant_buffer_offset);
34217 queue_test(test_dynamic_map_synchronization);
34218 queue_test(test_user_defined_annotation);
34220 run_queued_tests();
34222 /* There should be no reason these tests can't be run in parallel with the
34223 * others, yet they randomly fail or crash when doing so.
34224 * (Radeon 560, Windows 10) */
34225 test_instanced_draw();
34226 test_generate_mips();