d3d11/tests: Initialise "constant" in test_device_context_state() (Valgrind).
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob191df67a41d2047e9404271dcc6d2ff5e321f180
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 swapchain_desc
107 BOOL windowed;
108 unsigned buffer_count;
109 unsigned int width, height;
110 DXGI_SWAP_EFFECT swap_effect;
111 DWORD flags;
114 static void queue_test_entry(const struct test_entry *t)
116 if (mt_test_count >= mt_tests_size)
118 mt_tests_size = max(16, mt_tests_size * 2);
119 mt_tests = heap_realloc(mt_tests, mt_tests_size * sizeof(*t));
121 mt_tests[mt_test_count++] = *t;
124 static void queue_test_fl(void (*test)(const D3D_FEATURE_LEVEL fl), D3D_FEATURE_LEVEL fl)
126 struct test_entry t;
128 t.u.test_fl = test;
129 t.fl = fl;
130 queue_test_entry(&t);
133 static void queue_test(void (*test)(void))
135 struct test_entry t;
137 t.u.test = test;
138 t.fl = 0;
139 queue_test_entry(&t);
142 static void run_mt_test(const struct test_entry *t)
144 if (t->fl)
145 t->u.test_fl(t->fl);
146 else
147 t->u.test();
150 static DWORD WINAPI thread_func(void *ctx)
152 LONG *i = ctx, j;
154 while (*i < mt_test_count)
156 j = *i;
157 if (InterlockedCompareExchange(i, j + 1, j) == j)
158 run_mt_test(&mt_tests[j]);
161 return 0;
164 static void run_queued_tests(void)
166 unsigned int thread_count, i;
167 HANDLE *threads;
168 SYSTEM_INFO si;
169 LONG test_idx;
171 if (!use_mt)
173 for (i = 0; i < mt_test_count; ++i)
175 run_mt_test(&mt_tests[i]);
178 return;
181 GetSystemInfo(&si);
182 thread_count = si.dwNumberOfProcessors;
183 threads = heap_calloc(thread_count, sizeof(*threads));
184 for (i = 0, test_idx = 0; i < thread_count; ++i)
186 threads[i] = CreateThread(NULL, 0, thread_func, &test_idx, 0, NULL);
187 ok(!!threads[i], "Failed to create thread %u.\n", i);
189 WaitForMultipleObjects(thread_count, threads, TRUE, INFINITE);
190 for (i = 0; i < thread_count; ++i)
192 CloseHandle(threads[i]);
194 heap_free(threads);
197 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
199 box->left = left;
200 box->top = top;
201 box->front = front;
202 box->right = right;
203 box->bottom = bottom;
204 box->back = back;
207 static ULONG get_refcount(void *iface)
209 IUnknown *unknown = iface;
210 IUnknown_AddRef(unknown);
211 return IUnknown_Release(unknown);
214 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
215 static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOOL supported, BOOL is_broken)
217 HRESULT hr, expected_hr, broken_hr;
218 IUnknown *unknown = iface, *out;
220 if (supported)
222 expected_hr = S_OK;
223 broken_hr = E_NOINTERFACE;
225 else
227 expected_hr = E_NOINTERFACE;
228 broken_hr = S_OK;
231 hr = IUnknown_QueryInterface(unknown, riid, (void **)&out);
232 ok_(__FILE__, line)(hr == expected_hr || broken(is_broken && hr == broken_hr),
233 "Got hr %#x, expected %#x.\n", hr, expected_hr);
234 if (SUCCEEDED(hr))
235 IUnknown_Release(out);
236 return hr;
239 static BOOL compare_float(float f, float g, unsigned int ulps)
241 int x = *(int *)&f;
242 int y = *(int *)&g;
244 if (x < 0)
245 x = INT_MIN - x;
246 if (y < 0)
247 y = INT_MIN - y;
249 if (abs(x - y) > ulps)
250 return FALSE;
252 return TRUE;
255 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
257 return compare_float(v1->x, v2->x, ulps)
258 && compare_float(v1->y, v2->y, ulps)
259 && compare_float(v1->z, v2->z, ulps)
260 && compare_float(v1->w, v2->w, ulps);
263 static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
265 unsigned int diff = x > y ? x - y : y - x;
267 return diff <= max_diff;
270 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
272 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
275 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
277 return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
278 && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
279 && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
280 && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
283 static char const *debugstr_viewport(D3D11_VIEWPORT *vp)
285 if (!vp) return "(null)";
286 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}",
287 vp->TopLeftX, vp->TopLeftY, vp->Width, vp->Height, vp->MinDepth, vp->MaxDepth);
290 struct srv_desc
292 DXGI_FORMAT format;
293 D3D11_SRV_DIMENSION dimension;
294 unsigned int miplevel_idx;
295 unsigned int miplevel_count;
296 unsigned int layer_idx;
297 unsigned int layer_count;
300 static void get_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *d3d11_desc, const struct srv_desc *desc)
302 d3d11_desc->Format = desc->format;
303 d3d11_desc->ViewDimension = desc->dimension;
304 if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1D)
306 U(*d3d11_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
307 U(*d3d11_desc).Texture1D.MipLevels = desc->miplevel_count;
309 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
311 U(*d3d11_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
312 U(*d3d11_desc).Texture1DArray.MipLevels = desc->miplevel_count;
313 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
314 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
316 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
318 U(*d3d11_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
319 U(*d3d11_desc).Texture2D.MipLevels = desc->miplevel_count;
321 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
323 U(*d3d11_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
324 U(*d3d11_desc).Texture2DArray.MipLevels = desc->miplevel_count;
325 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
326 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
328 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
330 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
331 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
333 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE3D)
335 U(*d3d11_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
336 U(*d3d11_desc).Texture3D.MipLevels = desc->miplevel_count;
338 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
340 U(*d3d11_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
341 U(*d3d11_desc).TextureCube.MipLevels = desc->miplevel_count;
343 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
345 U(*d3d11_desc).TextureCubeArray.MostDetailedMip = desc->miplevel_idx;
346 U(*d3d11_desc).TextureCubeArray.MipLevels = desc->miplevel_count;
347 U(*d3d11_desc).TextureCubeArray.First2DArrayFace = desc->layer_idx;
348 U(*d3d11_desc).TextureCubeArray.NumCubes = desc->layer_count;
350 else if (desc->dimension != D3D11_SRV_DIMENSION_UNKNOWN
351 && desc->dimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
353 trace("Unhandled view dimension %#x.\n", desc->dimension);
357 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
358 static void check_srv_desc_(unsigned int line, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
359 const struct srv_desc *expected_desc)
361 ok_(__FILE__, line)(desc->Format == expected_desc->format,
362 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
363 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
364 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
366 if (desc->ViewDimension != expected_desc->dimension)
367 return;
369 if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D)
371 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
372 "Got MostDetailedMip %u, expected %u.\n",
373 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
374 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
375 "Got MipLevels %u, expected %u.\n",
376 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
378 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
380 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
381 "Got MostDetailedMip %u, expected %u.\n",
382 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
383 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
384 "Got MipLevels %u, expected %u.\n",
385 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
386 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
387 "Got FirstArraySlice %u, expected %u.\n",
388 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
389 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
390 "Got ArraySize %u, expected %u.\n",
391 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
393 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
395 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
396 "Got FirstArraySlice %u, expected %u.\n",
397 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
398 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
399 "Got ArraySize %u, expected %u.\n",
400 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
402 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
404 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
405 "Got MostDetailedMip %u, expected %u.\n",
406 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
407 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
408 "Got MipLevels %u, expected %u.\n",
409 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
411 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
413 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
414 "Got MostDetailedMip %u, expected %u.\n",
415 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
416 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
417 "Got MipLevels %u, expected %u.\n",
418 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
420 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
422 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MostDetailedMip == expected_desc->miplevel_idx,
423 "Got MostDetailedMip %u, expected %u.\n",
424 U(*desc).TextureCubeArray.MostDetailedMip, expected_desc->miplevel_idx);
425 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MipLevels == expected_desc->miplevel_count,
426 "Got MipLevels %u, expected %u.\n",
427 U(*desc).TextureCubeArray.MipLevels, expected_desc->miplevel_count);
428 ok_(__FILE__, line)(U(*desc).TextureCubeArray.First2DArrayFace == expected_desc->layer_idx,
429 "Got First2DArrayFace %u, expected %u.\n",
430 U(*desc).TextureCubeArray.First2DArrayFace, expected_desc->layer_idx);
431 ok_(__FILE__, line)(U(*desc).TextureCubeArray.NumCubes == expected_desc->layer_count,
432 "Got NumCubes %u, expected %u.\n",
433 U(*desc).TextureCubeArray.NumCubes, expected_desc->layer_count);
435 else if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
437 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
441 struct rtv_desc
443 DXGI_FORMAT format;
444 D3D11_RTV_DIMENSION dimension;
445 unsigned int miplevel_idx;
446 unsigned int layer_idx;
447 unsigned int layer_count;
450 static void get_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *d3d11_desc, const struct rtv_desc *desc)
452 d3d11_desc->Format = desc->format;
453 d3d11_desc->ViewDimension = desc->dimension;
454 if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1D)
456 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
458 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1DARRAY)
460 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
461 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
462 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
464 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
466 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
468 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
470 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
471 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
472 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
474 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
476 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
477 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
479 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE3D)
481 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
482 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
483 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
485 else if (desc->dimension != D3D11_RTV_DIMENSION_UNKNOWN
486 && desc->dimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
488 trace("Unhandled view dimension %#x.\n", desc->dimension);
492 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
493 static void check_rtv_desc_(unsigned int line, const D3D11_RENDER_TARGET_VIEW_DESC *desc,
494 const struct rtv_desc *expected_desc)
496 ok_(__FILE__, line)(desc->Format == expected_desc->format,
497 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
498 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
499 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
501 if (desc->ViewDimension != expected_desc->dimension)
502 return;
504 if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D)
506 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
507 "Got MipSlice %u, expected %u.\n",
508 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
510 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
512 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
513 "Got MipSlice %u, expected %u.\n",
514 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
515 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
516 "Got FirstArraySlice %u, expected %u.\n",
517 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
518 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
519 "Got ArraySize %u, expected %u.\n",
520 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
522 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
524 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
525 "Got FirstArraySlice %u, expected %u.\n",
526 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
527 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
528 "Got ArraySize %u, expected %u.\n",
529 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
531 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE3D)
533 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
534 "Got MipSlice %u, expected %u.\n",
535 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
536 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
537 "Got FirstWSlice %u, expected %u.\n",
538 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
539 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
540 "Got WSize %u, expected %u.\n",
541 U(*desc).Texture3D.WSize, expected_desc->layer_count);
543 else if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
545 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
549 struct dsv_desc
551 DXGI_FORMAT format;
552 D3D11_DSV_DIMENSION dimension;
553 unsigned int miplevel_idx;
554 unsigned int layer_idx;
555 unsigned int layer_count;
558 static void get_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *d3d11_desc, const struct dsv_desc *desc)
560 d3d11_desc->Format = desc->format;
561 d3d11_desc->ViewDimension = desc->dimension;
562 d3d11_desc->Flags = 0;
563 if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1D)
565 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
567 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1DARRAY)
569 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
570 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
571 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
573 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2D)
575 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
577 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
579 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
580 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
581 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
583 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
585 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
586 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
588 else if (desc->dimension != D3D11_DSV_DIMENSION_UNKNOWN
589 && desc->dimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
591 trace("Unhandled view dimension %#x.\n", desc->dimension);
595 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
596 static void check_dsv_desc_(unsigned int line, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc,
597 const struct dsv_desc *expected_desc)
599 ok_(__FILE__, line)(desc->Format == expected_desc->format,
600 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
601 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
602 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
604 if (desc->ViewDimension != expected_desc->dimension)
605 return;
607 if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D)
609 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
610 "Got MipSlice %u, expected %u.\n",
611 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
613 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
615 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
616 "Got MipSlice %u, expected %u.\n",
617 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
618 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
619 "Got FirstArraySlice %u, expected %u.\n",
620 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
621 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
622 "Got ArraySize %u, expected %u.\n",
623 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
625 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
627 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
628 "Got FirstArraySlice %u, expected %u.\n",
629 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
630 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
631 "Got ArraySize %u, expected %u.\n",
632 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
634 else if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
636 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
640 struct uav_desc
642 DXGI_FORMAT format;
643 D3D11_UAV_DIMENSION dimension;
644 unsigned int miplevel_idx;
645 unsigned int layer_idx;
646 unsigned int layer_count;
649 static void get_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC *d3d11_desc, const struct uav_desc *desc)
651 d3d11_desc->Format = desc->format;
652 d3d11_desc->ViewDimension = desc->dimension;
653 if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1D)
655 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
657 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
659 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
660 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
661 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
663 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2D)
665 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
667 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
669 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
670 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
671 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
673 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE3D)
675 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
676 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
677 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
679 else if (desc->dimension != D3D11_UAV_DIMENSION_UNKNOWN)
681 trace("Unhandled view dimension %#x.\n", desc->dimension);
685 #define check_uav_desc(a, b) check_uav_desc_(__LINE__, a, b)
686 static void check_uav_desc_(unsigned int line, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc,
687 const struct uav_desc *expected_desc)
689 ok_(__FILE__, line)(desc->Format == expected_desc->format,
690 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
691 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
692 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
694 if (desc->ViewDimension != expected_desc->dimension)
695 return;
697 if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D)
699 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
700 "Got MipSlice %u, expected %u.\n",
701 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
703 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
705 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
706 "Got MipSlice %u, expected %u.\n",
707 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
708 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
709 "Got FirstArraySlice %u, expected %u.\n",
710 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
711 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
712 "Got ArraySize %u, expected %u.\n",
713 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
715 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
717 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
718 "Got MipSlice %u, expected %u.\n",
719 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
720 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
721 "Got FirstWSlice %u, expected %u.\n",
722 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
723 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
724 "Got WSize %u, expected %u.\n",
725 U(*desc).Texture3D.WSize, expected_desc->layer_count);
727 else
729 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
733 static void set_viewport(ID3D11DeviceContext *context, float x, float y,
734 float width, float height, float min_depth, float max_depth)
736 D3D11_VIEWPORT vp;
738 vp.TopLeftX = x;
739 vp.TopLeftY = y;
740 vp.Width = width;
741 vp.Height = height;
742 vp.MinDepth = min_depth;
743 vp.MaxDepth = max_depth;
745 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
748 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, 0, c, d)
749 #define create_buffer_misc(a, b, c, d, e) create_buffer_(__LINE__, a, b, c, d, e)
750 static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
751 unsigned int bind_flags, unsigned int misc_flags, unsigned int size, const void *data)
753 D3D11_SUBRESOURCE_DATA resource_data;
754 D3D11_BUFFER_DESC buffer_desc;
755 ID3D11Buffer *buffer;
756 HRESULT hr;
758 buffer_desc.ByteWidth = size;
759 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
760 buffer_desc.BindFlags = bind_flags;
761 buffer_desc.CPUAccessFlags = 0;
762 buffer_desc.MiscFlags = misc_flags;
763 buffer_desc.StructureByteStride = 0;
765 resource_data.pSysMem = data;
766 resource_data.SysMemPitch = 0;
767 resource_data.SysMemSlicePitch = 0;
769 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
770 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
771 return buffer;
774 struct resource_readback
776 ID3D11Resource *resource;
777 D3D11_MAPPED_SUBRESOURCE map_desc;
778 ID3D11DeviceContext *immediate_context;
779 unsigned int width, height, depth, sub_resource_idx;
782 static void init_resource_readback(ID3D11Resource *resource, ID3D11Resource *readback_resource,
783 unsigned int width, unsigned int height, unsigned int depth, unsigned int sub_resource_idx,
784 ID3D11Device *device, struct resource_readback *rb)
786 HRESULT hr;
788 rb->resource = readback_resource;
789 rb->width = width;
790 rb->height = height;
791 rb->depth = depth;
792 rb->sub_resource_idx = sub_resource_idx;
794 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
796 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, resource);
797 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context,
798 rb->resource, sub_resource_idx, D3D11_MAP_READ, 0, &rb->map_desc)))
800 trace("Failed to map resource, hr %#x.\n", hr);
801 ID3D11Resource_Release(rb->resource);
802 rb->resource = NULL;
803 ID3D11DeviceContext_Release(rb->immediate_context);
804 rb->immediate_context = NULL;
808 static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
810 D3D11_BUFFER_DESC buffer_desc;
811 ID3D11Resource *rb_buffer;
812 ID3D11Device *device;
813 HRESULT hr;
815 memset(rb, 0, sizeof(*rb));
817 ID3D11Buffer_GetDevice(buffer, &device);
819 ID3D11Buffer_GetDesc(buffer, &buffer_desc);
820 buffer_desc.Usage = D3D11_USAGE_STAGING;
821 buffer_desc.BindFlags = 0;
822 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
823 buffer_desc.MiscFlags = 0;
824 buffer_desc.StructureByteStride = 0;
825 if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb_buffer)))
827 trace("Failed to create staging buffer, hr %#x.\n", hr);
828 ID3D11Device_Release(device);
829 return;
832 init_resource_readback((ID3D11Resource *)buffer, rb_buffer,
833 buffer_desc.ByteWidth, 1, 1, 0, device, rb);
835 ID3D11Device_Release(device);
838 static void get_texture1d_readback(ID3D11Texture1D *texture, unsigned int sub_resource_idx,
839 struct resource_readback *rb)
841 D3D11_TEXTURE1D_DESC texture_desc;
842 ID3D11Resource *rb_texture;
843 unsigned int miplevel;
844 ID3D11Device *device;
845 HRESULT hr;
847 memset(rb, 0, sizeof(*rb));
849 ID3D11Texture1D_GetDevice(texture, &device);
851 ID3D11Texture1D_GetDesc(texture, &texture_desc);
852 texture_desc.Usage = D3D11_USAGE_STAGING;
853 texture_desc.BindFlags = 0;
854 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
855 texture_desc.MiscFlags = 0;
856 if (FAILED(hr = ID3D11Device_CreateTexture1D(device, &texture_desc, NULL, (ID3D11Texture1D **)&rb_texture)))
858 trace("Failed to create texture, hr %#x.\n", hr);
859 ID3D11Device_Release(device);
860 return;
863 miplevel = sub_resource_idx % texture_desc.MipLevels;
864 init_resource_readback((ID3D11Resource *)texture, rb_texture,
865 max(1, texture_desc.Width >> miplevel), 1, 1, sub_resource_idx, device, rb);
867 ID3D11Device_Release(device);
870 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
871 struct resource_readback *rb)
873 D3D11_TEXTURE2D_DESC texture_desc;
874 ID3D11Resource *rb_texture;
875 unsigned int miplevel;
876 ID3D11Device *device;
877 HRESULT hr;
879 memset(rb, 0, sizeof(*rb));
881 ID3D11Texture2D_GetDevice(texture, &device);
883 ID3D11Texture2D_GetDesc(texture, &texture_desc);
884 texture_desc.Usage = D3D11_USAGE_STAGING;
885 texture_desc.BindFlags = 0;
886 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
887 texture_desc.MiscFlags = 0;
888 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb_texture)))
890 trace("Failed to create texture, hr %#x.\n", hr);
891 ID3D11Device_Release(device);
892 return;
895 miplevel = sub_resource_idx % texture_desc.MipLevels;
896 init_resource_readback((ID3D11Resource *)texture, rb_texture,
897 max(1, texture_desc.Width >> miplevel),
898 max(1, texture_desc.Height >> miplevel),
899 1, sub_resource_idx, device, rb);
901 ID3D11Device_Release(device);
904 static void get_texture3d_readback(ID3D11Texture3D *texture, unsigned int sub_resource_idx,
905 struct resource_readback *rb)
907 D3D11_TEXTURE3D_DESC texture_desc;
908 ID3D11Resource *rb_texture;
909 unsigned int miplevel;
910 ID3D11Device *device;
911 HRESULT hr;
913 memset(rb, 0, sizeof(*rb));
915 ID3D11Texture3D_GetDevice(texture, &device);
917 ID3D11Texture3D_GetDesc(texture, &texture_desc);
918 texture_desc.Usage = D3D11_USAGE_STAGING;
919 texture_desc.BindFlags = 0;
920 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
921 texture_desc.MiscFlags = 0;
922 if (FAILED(hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, (ID3D11Texture3D **)&rb_texture)))
924 trace("Failed to create texture, hr %#x.\n", hr);
925 ID3D11Device_Release(device);
926 return;
929 miplevel = sub_resource_idx % texture_desc.MipLevels;
930 init_resource_readback((ID3D11Resource *)texture, rb_texture,
931 max(1, texture_desc.Width >> miplevel),
932 max(1, texture_desc.Height >> miplevel),
933 max(1, texture_desc.Depth >> miplevel),
934 sub_resource_idx, device, rb);
936 ID3D11Device_Release(device);
939 static void *get_readback_data(struct resource_readback *rb,
940 unsigned int x, unsigned int y, unsigned int z, unsigned byte_width)
942 return (BYTE *)rb->map_desc.pData + z * rb->map_desc.DepthPitch + y * rb->map_desc.RowPitch + x * byte_width;
945 static BYTE get_readback_u8(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
947 return *(BYTE *)get_readback_data(rb, x, y, z, sizeof(BYTE));
950 static WORD get_readback_u16(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
952 return *(WORD *)get_readback_data(rb, x, y, z, sizeof(WORD));
955 static DWORD get_readback_u32(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
957 return *(DWORD *)get_readback_data(rb, x, y, z, sizeof(DWORD));
960 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
962 return get_readback_u32(rb, x, y, z);
965 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
967 return *(float *)get_readback_data(rb, x, y, 0, sizeof(float));
970 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
972 return get_readback_data(rb, x, y, 0, sizeof(struct vec4));
975 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
977 return get_readback_data(rb, x, y, 0, sizeof(struct uvec4));
980 static void release_resource_readback(struct resource_readback *rb)
982 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
983 ID3D11Resource_Release(rb->resource);
984 ID3D11DeviceContext_Release(rb->immediate_context);
987 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
989 struct resource_readback rb;
990 DWORD color;
992 get_texture_readback(texture, 0, &rb);
993 color = get_readback_color(&rb, x, y, 0);
994 release_resource_readback(&rb);
996 return color;
999 #define check_readback_data_u8(a, b, c, d) check_readback_data_u8_(__LINE__, a, b, c, d)
1000 static void check_readback_data_u8_(unsigned int line, struct resource_readback *rb,
1001 const RECT *rect, BYTE expected_value, BYTE max_diff)
1003 unsigned int x = 0, y = 0, z = 0;
1004 BOOL all_match = FALSE;
1005 RECT default_rect;
1006 BYTE value = 0;
1008 if (!rect)
1010 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1011 rect = &default_rect;
1014 for (z = 0; z < rb->depth; ++z)
1016 for (y = rect->top; y < rect->bottom; ++y)
1018 for (x = rect->left; x < rect->right; ++x)
1020 value = get_readback_u8(rb, x, y, z);
1021 if (!compare_uint(value, expected_value, max_diff))
1022 goto done;
1026 all_match = TRUE;
1028 done:
1029 ok_(__FILE__, line)(all_match,
1030 "Got 0x%02x, expected 0x%02x at (%u, %u, %u), sub-resource %u.\n",
1031 value, expected_value, x, y, z, rb->sub_resource_idx);
1034 #define check_readback_data_u16(a, b, c, d) check_readback_data_u16_(__LINE__, a, b, c, d)
1035 static void check_readback_data_u16_(unsigned int line, struct resource_readback *rb,
1036 const RECT *rect, WORD expected_value, BYTE max_diff)
1038 unsigned int x = 0, y = 0, z = 0;
1039 BOOL all_match = FALSE;
1040 RECT default_rect;
1041 WORD value = 0;
1043 if (!rect)
1045 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1046 rect = &default_rect;
1049 for (z = 0; z < rb->depth; ++z)
1051 for (y = rect->top; y < rect->bottom; ++y)
1053 for (x = rect->left; x < rect->right; ++x)
1055 value = get_readback_u16(rb, x, y, z);
1056 if (!compare_uint(value, expected_value, max_diff))
1057 goto done;
1061 all_match = TRUE;
1063 done:
1064 ok_(__FILE__, line)(all_match,
1065 "Got 0x%04x, expected 0x%04x at (%u, %u, %u), sub-resource %u.\n",
1066 value, expected_value, x, y, z, rb->sub_resource_idx);
1069 #define check_readback_data_u24(a, b, c, d, e) check_readback_data_u24_(__LINE__, a, b, c, d, e)
1070 static void check_readback_data_u24_(unsigned int line, struct resource_readback *rb,
1071 const RECT *rect, unsigned int shift, DWORD expected_value, BYTE max_diff)
1073 unsigned int x = 0, y = 0, z = 0;
1074 BOOL all_match = FALSE;
1075 RECT default_rect;
1076 DWORD value = 0;
1078 if (!rect)
1080 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1081 rect = &default_rect;
1084 for (z = 0; z < rb->depth; ++z)
1086 for (y = rect->top; y < rect->bottom; ++y)
1088 for (x = rect->left; x < rect->right; ++x)
1090 value = get_readback_u32(rb, x, y, z) >> shift;
1091 if (!compare_uint(value, expected_value, max_diff))
1092 goto done;
1096 all_match = TRUE;
1098 done:
1099 ok_(__FILE__, line)(all_match,
1100 "Got 0x%06x, expected 0x%06x at (%u, %u, %u), sub-resource %u.\n",
1101 value, expected_value, x, y, z, rb->sub_resource_idx);
1104 #define check_readback_data_color(a, b, c, d) check_readback_data_color_(__LINE__, a, b, c, d)
1105 static void check_readback_data_color_(unsigned int line, struct resource_readback *rb,
1106 const RECT *rect, DWORD expected_color, BYTE max_diff)
1108 unsigned int x = 0, y = 0, z = 0;
1109 BOOL all_match = FALSE;
1110 RECT default_rect;
1111 DWORD color = 0;
1113 if (!rect)
1115 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1116 rect = &default_rect;
1119 for (z = 0; z < rb->depth; ++z)
1121 for (y = rect->top; y < rect->bottom; ++y)
1123 for (x = rect->left; x < rect->right; ++x)
1125 color = get_readback_color(rb, x, y, z);
1126 if (!compare_color(color, expected_color, max_diff))
1127 goto done;
1131 all_match = TRUE;
1133 done:
1134 ok_(__FILE__, line)(all_match,
1135 "Got 0x%08x, expected 0x%08x at (%u, %u, %u), sub-resource %u.\n",
1136 color, expected_color, x, y, z, rb->sub_resource_idx);
1139 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
1140 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
1141 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1143 struct resource_readback rb;
1145 get_texture_readback(texture, sub_resource_idx, &rb);
1146 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1147 release_resource_readback(&rb);
1150 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
1151 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
1152 DWORD expected_color, BYTE max_diff)
1154 unsigned int sub_resource_idx, sub_resource_count;
1155 D3D11_TEXTURE2D_DESC texture_desc;
1157 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1158 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1159 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1160 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1163 #define check_texture1d_sub_resource_color(a, b, c, d, e) check_texture1d_sub_resource_color_(__LINE__, a, b, c, d, e)
1164 static void check_texture1d_sub_resource_color_(unsigned int line, ID3D11Texture1D *texture,
1165 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1167 struct resource_readback rb;
1169 get_texture1d_readback(texture, sub_resource_idx, &rb);
1170 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1171 release_resource_readback(&rb);
1174 #define check_texture1d_color(t, c, d) check_texture1d_color_(__LINE__, t, c, d)
1175 static void check_texture1d_color_(unsigned int line, ID3D11Texture1D *texture,
1176 DWORD expected_color, BYTE max_diff)
1178 unsigned int sub_resource_idx, sub_resource_count;
1179 D3D11_TEXTURE1D_DESC texture_desc;
1181 ID3D11Texture1D_GetDesc(texture, &texture_desc);
1182 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1183 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1184 check_texture1d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1187 #define check_texture3d_sub_resource_color(a, b, c, d, e) check_texture3d_sub_resource_color_(__LINE__, a, b, c, d, e)
1188 static void check_texture3d_sub_resource_color_(unsigned int line, ID3D11Texture3D *texture,
1189 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1191 struct resource_readback rb;
1193 get_texture3d_readback(texture, sub_resource_idx, &rb);
1194 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1195 release_resource_readback(&rb);
1198 #define check_texture3d_color(t, c, d) check_texture3d_color_(__LINE__, t, c, d)
1199 static void check_texture3d_color_(unsigned int line, ID3D11Texture3D *texture,
1200 DWORD expected_color, BYTE max_diff)
1202 unsigned int sub_resource_idx, sub_resource_count;
1203 D3D11_TEXTURE3D_DESC texture_desc;
1205 ID3D11Texture3D_GetDesc(texture, &texture_desc);
1206 sub_resource_count = texture_desc.MipLevels;
1207 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1208 check_texture3d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1211 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
1212 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
1213 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
1215 struct resource_readback rb;
1216 unsigned int x = 0, y = 0;
1217 BOOL all_match = TRUE;
1218 float value = 0.0f;
1219 RECT default_rect;
1221 get_texture_readback(texture, sub_resource_idx, &rb);
1222 if (!rect)
1224 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1225 rect = &default_rect;
1227 for (y = rect->top; y < rect->bottom; ++y)
1229 for (x = rect->left; x < rect->right; ++x)
1231 value = get_readback_float(&rb, x, y);
1232 if (!compare_float(value, expected_value, max_diff))
1234 all_match = FALSE;
1235 break;
1238 if (!all_match)
1239 break;
1241 release_resource_readback(&rb);
1242 ok_(__FILE__, line)(all_match,
1243 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
1244 value, expected_value, x, y, sub_resource_idx);
1247 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
1248 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
1249 float expected_value, BYTE max_diff)
1251 unsigned int sub_resource_idx, sub_resource_count;
1252 D3D11_TEXTURE2D_DESC texture_desc;
1254 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1255 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1256 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1257 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1260 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
1261 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
1262 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
1264 struct resource_readback rb;
1265 unsigned int x = 0, y = 0;
1266 struct vec4 value = {0};
1267 BOOL all_match = TRUE;
1268 RECT default_rect;
1270 get_texture_readback(texture, sub_resource_idx, &rb);
1271 if (!rect)
1273 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1274 rect = &default_rect;
1276 for (y = rect->top; y < rect->bottom; ++y)
1278 for (x = rect->left; x < rect->right; ++x)
1280 value = *get_readback_vec4(&rb, x, y);
1281 if (!compare_vec4(&value, expected_value, max_diff))
1283 all_match = FALSE;
1284 break;
1287 if (!all_match)
1288 break;
1290 release_resource_readback(&rb);
1291 ok_(__FILE__, line)(all_match,
1292 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
1293 value.x, value.y, value.z, value.w,
1294 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1295 x, y, sub_resource_idx);
1298 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
1299 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
1300 const struct vec4 *expected_value, BYTE max_diff)
1302 unsigned int sub_resource_idx, sub_resource_count;
1303 D3D11_TEXTURE2D_DESC texture_desc;
1305 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1306 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1307 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1308 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1311 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
1312 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
1313 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
1315 struct resource_readback rb;
1316 unsigned int x = 0, y = 0;
1317 struct uvec4 value = {0};
1318 BOOL all_match = TRUE;
1319 RECT default_rect;
1321 get_texture_readback(texture, sub_resource_idx, &rb);
1322 if (!rect)
1324 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1325 rect = &default_rect;
1327 for (y = rect->top; y < rect->bottom; ++y)
1329 for (x = rect->left; x < rect->right; ++x)
1331 value = *get_readback_uvec4(&rb, x, y);
1332 if (!compare_uvec4(&value, expected_value))
1334 all_match = FALSE;
1335 break;
1338 if (!all_match)
1339 break;
1341 release_resource_readback(&rb);
1342 ok_(__FILE__, line)(all_match,
1343 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
1344 "at (%u, %u), sub-resource %u.\n",
1345 value.x, value.y, value.z, value.w,
1346 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1347 x, y, sub_resource_idx);
1350 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
1351 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
1352 const struct uvec4 *expected_value)
1354 unsigned int sub_resource_idx, sub_resource_count;
1355 D3D11_TEXTURE2D_DESC texture_desc;
1357 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1358 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1359 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1360 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
1363 static IDXGIAdapter *create_adapter(void)
1365 IDXGIFactory4 *factory4;
1366 IDXGIFactory *factory;
1367 IDXGIAdapter *adapter;
1368 HRESULT hr;
1370 if (!use_warp_adapter && !use_adapter_idx)
1371 return NULL;
1373 if (FAILED(hr = CreateDXGIFactory1(&IID_IDXGIFactory, (void **)&factory)))
1375 trace("Failed to create IDXGIFactory, hr %#x.\n", hr);
1376 return NULL;
1379 adapter = NULL;
1380 if (use_warp_adapter)
1382 if (SUCCEEDED(hr = IDXGIFactory_QueryInterface(factory, &IID_IDXGIFactory4, (void **)&factory4)))
1384 hr = IDXGIFactory4_EnumWarpAdapter(factory4, &IID_IDXGIAdapter, (void **)&adapter);
1385 IDXGIFactory4_Release(factory4);
1387 else
1389 trace("Failed to get IDXGIFactory4, hr %#x.\n", hr);
1392 else
1394 hr = IDXGIFactory_EnumAdapters(factory, use_adapter_idx, &adapter);
1396 IDXGIFactory_Release(factory);
1397 if (FAILED(hr))
1398 trace("Failed to get adapter, hr %#x.\n", hr);
1399 return adapter;
1402 static ID3D11Device *create_device(const struct device_desc *desc)
1404 static const D3D_FEATURE_LEVEL default_feature_level[] =
1406 D3D_FEATURE_LEVEL_11_0,
1407 D3D_FEATURE_LEVEL_10_1,
1408 D3D_FEATURE_LEVEL_10_0,
1410 const D3D_FEATURE_LEVEL *feature_level;
1411 UINT flags = desc ? desc->flags : 0;
1412 unsigned int feature_level_count;
1413 IDXGIAdapter *adapter;
1414 ID3D11Device *device;
1415 HRESULT hr;
1417 if (desc && desc->feature_level)
1419 feature_level = desc->feature_level;
1420 feature_level_count = 1;
1422 else
1424 feature_level = default_feature_level;
1425 feature_level_count = ARRAY_SIZE(default_feature_level);
1428 if (enable_debug_layer)
1429 flags |= D3D11_CREATE_DEVICE_DEBUG;
1431 if ((adapter = create_adapter()))
1433 hr = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags,
1434 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL);
1435 IDXGIAdapter_Release(adapter);
1436 return SUCCEEDED(hr) ? device : NULL;
1439 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags,
1440 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1441 return device;
1442 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags,
1443 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1444 return device;
1445 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags,
1446 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1447 return device;
1449 return NULL;
1452 static void get_device_adapter_desc(ID3D11Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1454 IDXGIDevice *dxgi_device;
1455 IDXGIAdapter *adapter;
1456 HRESULT hr;
1458 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1459 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1460 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1461 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1462 IDXGIDevice_Release(dxgi_device);
1463 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1464 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1465 IDXGIAdapter_Release(adapter);
1468 static void print_adapter_info(void)
1470 DXGI_ADAPTER_DESC adapter_desc;
1471 ID3D11Device *device;
1473 if (!(device = create_device(NULL)))
1474 return;
1476 get_device_adapter_desc(device, &adapter_desc);
1477 trace("Adapter: %s, %04x:%04x.\n", wine_dbgstr_w(adapter_desc.Description),
1478 adapter_desc.VendorId, adapter_desc.DeviceId);
1479 ID3D11Device_Release(device);
1482 static BOOL is_warp_device(ID3D11Device *device)
1484 DXGI_ADAPTER_DESC adapter_desc;
1485 get_device_adapter_desc(device, &adapter_desc);
1486 return !adapter_desc.SubSysId && !adapter_desc.Revision
1487 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1488 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1491 static BOOL is_vendor_device(ID3D11Device *device, unsigned int vendor_id)
1493 DXGI_ADAPTER_DESC adapter_desc;
1495 if (!strcmp(winetest_platform, "wine"))
1496 return FALSE;
1498 get_device_adapter_desc(device, &adapter_desc);
1499 return adapter_desc.VendorId == vendor_id;
1502 static BOOL is_amd_device(ID3D11Device *device)
1504 return is_vendor_device(device, 0x1002);
1507 static BOOL is_intel_device(ID3D11Device *device)
1509 return is_vendor_device(device, 0x8086);
1512 static BOOL is_nvidia_device(ID3D11Device *device)
1514 return is_vendor_device(device, 0x10de);
1517 static BOOL is_d3d11_2_runtime(ID3D11Device *device)
1519 ID3D11Device2 *device2;
1520 HRESULT hr;
1522 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11Device2, (void **)&device2);
1523 if (SUCCEEDED(hr))
1524 ID3D11Device2_Release(device2);
1525 return hr == S_OK;
1528 static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device)
1530 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
1532 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1533 D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options))))
1534 return FALSE;
1535 return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
1538 static BOOL check_viewport_array_index_from_any_shader_support(ID3D11Device *device)
1540 D3D11_FEATURE_DATA_D3D11_OPTIONS3 options;
1542 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1543 D3D11_FEATURE_D3D11_OPTIONS3, &options, sizeof(options))))
1544 return FALSE;
1545 return options.VPAndRTArrayIndexFromAnyShaderFeedingRasterizer;
1548 static BOOL is_buffer(ID3D11Resource *resource)
1550 D3D11_RESOURCE_DIMENSION dimension;
1551 ID3D11Resource_GetType(resource, &dimension);
1552 return dimension == D3D11_RESOURCE_DIMENSION_BUFFER;
1555 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window,
1556 const struct swapchain_desc *swapchain_desc)
1558 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1559 IDXGISwapChain *swapchain;
1560 IDXGIDevice *dxgi_device;
1561 IDXGIAdapter *adapter;
1562 IDXGIFactory *factory;
1563 HRESULT hr;
1565 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1566 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1567 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1568 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1569 IDXGIDevice_Release(dxgi_device);
1570 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1571 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1572 IDXGIAdapter_Release(adapter);
1574 dxgi_desc.BufferDesc.Width = 640;
1575 dxgi_desc.BufferDesc.Height = 480;
1576 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1577 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1578 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1579 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1580 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1581 dxgi_desc.SampleDesc.Count = 1;
1582 dxgi_desc.SampleDesc.Quality = 0;
1583 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1584 dxgi_desc.BufferCount = 1;
1585 dxgi_desc.OutputWindow = window;
1586 dxgi_desc.Windowed = TRUE;
1587 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1588 dxgi_desc.Flags = 0;
1590 if (swapchain_desc)
1592 dxgi_desc.Windowed = swapchain_desc->windowed;
1593 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1594 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1595 if (swapchain_desc->width)
1596 dxgi_desc.BufferDesc.Width = swapchain_desc->width;
1597 if (swapchain_desc->height)
1598 dxgi_desc.BufferDesc.Height = swapchain_desc->height;
1600 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1601 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1604 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1605 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1606 IDXGIFactory_Release(factory);
1608 return swapchain;
1611 struct d3d11_test_context
1613 ID3D11Device *device;
1614 HWND window;
1615 IDXGISwapChain *swapchain;
1616 ID3D11Texture2D *backbuffer;
1617 ID3D11RenderTargetView *backbuffer_rtv;
1618 ID3D11DeviceContext *immediate_context;
1620 ID3D11InputLayout *input_layout;
1621 ID3D11VertexShader *vs;
1622 const DWORD *vs_code;
1623 ID3D11Buffer *vs_cb;
1624 ID3D11Buffer *vb;
1626 ID3D11PixelShader *ps;
1627 ID3D11Buffer *ps_cb;
1630 #define init_test_context(a, b) init_test_context_(__LINE__, a, b, NULL)
1631 #define init_test_context_ext(a, b, c) init_test_context_(__LINE__, a, b, c)
1632 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1633 const D3D_FEATURE_LEVEL *feature_level, const struct swapchain_desc *swapchain_desc)
1635 unsigned int rt_width, rt_height;
1636 struct device_desc device_desc;
1637 HRESULT hr;
1638 RECT rect;
1640 memset(context, 0, sizeof(*context));
1642 device_desc.feature_level = feature_level;
1643 device_desc.flags = 0;
1644 if (!(context->device = create_device(&device_desc)))
1646 skip_(__FILE__, line)("Failed to create device.\n");
1647 return FALSE;
1650 rt_width = swapchain_desc && swapchain_desc->width ? swapchain_desc->width : 640;
1651 rt_height = swapchain_desc && swapchain_desc->height ? swapchain_desc->height : 480;
1652 SetRect(&rect, 0, 0, rt_width, rt_height);
1653 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1654 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1655 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1656 context->swapchain = create_swapchain(context->device, context->window, swapchain_desc);
1657 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1658 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1660 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1661 NULL, &context->backbuffer_rtv);
1662 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1664 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1666 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1668 set_viewport(context->immediate_context, 0.0f, 0.0f, rt_width, rt_height, 0.0f, 1.0f);
1670 return TRUE;
1673 #define release_test_context(context) release_test_context_(__LINE__, context)
1674 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1676 ULONG ref;
1678 if (context->input_layout)
1679 ID3D11InputLayout_Release(context->input_layout);
1680 if (context->vs)
1681 ID3D11VertexShader_Release(context->vs);
1682 if (context->vs_cb)
1683 ID3D11Buffer_Release(context->vs_cb);
1684 if (context->vb)
1685 ID3D11Buffer_Release(context->vb);
1686 if (context->ps)
1687 ID3D11PixelShader_Release(context->ps);
1688 if (context->ps_cb)
1689 ID3D11Buffer_Release(context->ps_cb);
1691 ID3D11DeviceContext_Release(context->immediate_context);
1692 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1693 ID3D11Texture2D_Release(context->backbuffer);
1694 IDXGISwapChain_Release(context->swapchain);
1695 DestroyWindow(context->window);
1697 ref = ID3D11Device_Release(context->device);
1698 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1701 #define draw_quad(context) draw_quad_vs_(__LINE__, context, NULL, 0)
1702 #define draw_quad_vs(a, b, c) draw_quad_vs_(__LINE__, a, b, c)
1703 static void draw_quad_vs_(unsigned int line, struct d3d11_test_context *context,
1704 const DWORD *vs_code, size_t vs_code_size)
1706 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1708 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1710 static const DWORD default_vs_code[] =
1712 #if 0
1713 float4 main(float4 position : POSITION) : SV_POSITION
1715 return position;
1717 #endif
1718 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1719 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1720 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1721 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1722 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1723 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1724 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1725 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1726 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1727 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1728 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1729 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1730 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1731 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1732 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1734 static const struct vec3 quad[] =
1736 {-1.0f, -1.0f, 0.0f},
1737 {-1.0f, 1.0f, 0.0f},
1738 { 1.0f, -1.0f, 0.0f},
1739 { 1.0f, 1.0f, 0.0f},
1742 ID3D11Device *device = context->device;
1743 unsigned int stride, offset;
1744 HRESULT hr;
1746 if (!vs_code)
1748 vs_code = default_vs_code;
1749 vs_code_size = sizeof(default_vs_code);
1752 if (!context->input_layout)
1754 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1755 vs_code, vs_code_size, &context->input_layout);
1756 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1759 if (context->vs_code != vs_code)
1761 if (context->vs)
1762 ID3D11VertexShader_Release(context->vs);
1764 hr = ID3D11Device_CreateVertexShader(device, vs_code, vs_code_size, NULL, &context->vs);
1765 ok_(__FILE__, line)(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
1767 context->vs_code = vs_code;
1770 if (!context->vb)
1771 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1773 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1774 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1775 stride = sizeof(*quad);
1776 offset = 0;
1777 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1778 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1780 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1783 #define draw_quad_z(context, z) draw_quad_z_(__LINE__, context, z)
1784 static void draw_quad_z_(unsigned int line, struct d3d11_test_context *context, float z)
1786 static const DWORD vs_code[] =
1788 #if 0
1789 float depth;
1791 void main(float4 in_position : POSITION, out float4 out_position : SV_Position)
1793 out_position = in_position;
1794 out_position.z = depth;
1796 #endif
1797 0x43425844, 0x22d7ff76, 0xd53b167c, 0x1b49ccf1, 0xbebfec39, 0x00000001, 0x00000100, 0x00000003,
1798 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1799 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000b0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1800 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1801 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x00000064, 0x00010040,
1802 0x00000019, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010b2, 0x00000000,
1803 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, 0x001020b2, 0x00000000, 0x00101c46,
1804 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
1807 struct vec4 data = {z};
1809 if (!context->vs_cb)
1810 context->vs_cb = create_buffer(context->device, D3D11_BIND_CONSTANT_BUFFER, sizeof(data), NULL);
1812 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1813 (ID3D11Resource *)context->vs_cb, 0, NULL, &data, 0, 0);
1815 ID3D11DeviceContext_VSSetConstantBuffers(context->immediate_context, 0, 1, &context->vs_cb);
1816 draw_quad_vs_(__LINE__, context, vs_code, sizeof(vs_code));
1819 static void set_quad_color(struct d3d11_test_context *context, const struct vec4 *color)
1821 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1822 (ID3D11Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1825 #define draw_color_quad(a, b) draw_color_quad_(__LINE__, a, b, NULL, 0)
1826 #define draw_color_quad_vs(a, b, c, d) draw_color_quad_(__LINE__, a, b, c, d)
1827 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context,
1828 const struct vec4 *color, const DWORD *vs_code, size_t vs_code_size)
1830 static const DWORD ps_color_code[] =
1832 #if 0
1833 float4 color;
1835 float4 main() : SV_TARGET
1837 return color;
1839 #endif
1840 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1841 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1842 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1843 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1844 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1845 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1846 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1847 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1848 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1849 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1850 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1853 ID3D11Device *device = context->device;
1854 HRESULT hr;
1856 if (!context->ps)
1858 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1859 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1862 if (!context->ps_cb)
1863 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1865 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1866 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1868 set_quad_color(context, color);
1870 draw_quad_vs_(line, context, vs_code, vs_code_size);
1873 static void test_create_device(void)
1875 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1877 D3D_FEATURE_LEVEL_11_0,
1878 D3D_FEATURE_LEVEL_10_1,
1879 D3D_FEATURE_LEVEL_10_0,
1880 D3D_FEATURE_LEVEL_9_3,
1881 D3D_FEATURE_LEVEL_9_2,
1882 D3D_FEATURE_LEVEL_9_1,
1884 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1885 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1886 ID3D11DeviceContext *immediate_context;
1887 IDXGISwapChain *swapchain;
1888 ID3D11Device *device;
1889 ULONG refcount;
1890 HWND window;
1891 HRESULT hr;
1893 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1894 &device, NULL, NULL)))
1896 skip("Failed to create HAL device.\n");
1897 if ((device = create_device(NULL)))
1899 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1900 ID3D11Device_Release(device);
1902 return;
1905 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1906 trace("Feature level %#x.\n", supported_feature_level);
1907 ID3D11Device_Release(device);
1909 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1910 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1912 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1913 &feature_level, NULL);
1914 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1915 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1916 feature_level, supported_feature_level);
1918 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1919 ARRAY_SIZE(default_feature_levels), D3D11_SDK_VERSION, NULL, &feature_level, NULL);
1920 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1921 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1922 feature_level, supported_feature_level);
1924 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1925 &immediate_context);
1926 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1928 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1929 refcount = get_refcount(immediate_context);
1930 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1932 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1933 refcount = ID3D11Device_Release(device);
1934 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1936 refcount = ID3D11DeviceContext_Release(immediate_context);
1937 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1939 device = (ID3D11Device *)0xdeadbeef;
1940 feature_level = 0xdeadbeef;
1941 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1942 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1943 &device, &feature_level, &immediate_context);
1944 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1945 ok(!device, "Got unexpected device pointer %p.\n", device);
1946 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1947 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1949 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1951 swapchain_desc.BufferDesc.Width = 800;
1952 swapchain_desc.BufferDesc.Height = 600;
1953 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1954 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1955 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1956 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1957 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1958 swapchain_desc.SampleDesc.Count = 1;
1959 swapchain_desc.SampleDesc.Quality = 0;
1960 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1961 swapchain_desc.BufferCount = 1;
1962 swapchain_desc.OutputWindow = window;
1963 swapchain_desc.Windowed = TRUE;
1964 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1965 swapchain_desc.Flags = 0;
1967 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1968 &swapchain_desc, NULL, NULL, NULL, NULL);
1969 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1971 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1972 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1973 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1974 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1975 feature_level, supported_feature_level);
1977 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1978 &swapchain_desc, &swapchain, &device, NULL, NULL);
1979 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1981 check_interface(swapchain, &IID_IDXGISwapChain1, TRUE, FALSE);
1983 memset(&obtained_desc, 0, sizeof(obtained_desc));
1984 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1985 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1986 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1987 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1988 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1989 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1990 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1991 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1992 obtained_desc.BufferDesc.RefreshRate.Numerator);
1993 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1994 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1995 obtained_desc.BufferDesc.RefreshRate.Denominator);
1996 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1997 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1998 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1999 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
2000 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
2001 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
2002 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
2003 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
2004 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
2005 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
2006 ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
2007 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
2008 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
2009 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
2010 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
2011 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
2012 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
2013 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
2014 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
2015 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
2016 ok(obtained_desc.Flags == swapchain_desc.Flags,
2017 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
2019 refcount = IDXGISwapChain_Release(swapchain);
2020 ok(!refcount, "Swapchain has %u references left.\n", refcount);
2022 feature_level = ID3D11Device_GetFeatureLevel(device);
2023 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2024 feature_level, supported_feature_level);
2026 refcount = ID3D11Device_Release(device);
2027 ok(!refcount, "Device has %u references left.\n", refcount);
2029 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2030 NULL, NULL, &device, NULL, NULL);
2031 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2032 ID3D11Device_Release(device);
2034 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2035 NULL, NULL, NULL, NULL, NULL);
2036 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2038 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2039 NULL, NULL, NULL, &feature_level, NULL);
2040 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2041 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2042 feature_level, supported_feature_level);
2044 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2045 NULL, NULL, NULL, NULL, &immediate_context);
2046 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2047 ID3D11DeviceContext_Release(immediate_context);
2049 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2050 &swapchain_desc, NULL, NULL, NULL, NULL);
2051 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2053 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2054 &swapchain_desc, &swapchain, NULL, NULL, NULL);
2055 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2056 IDXGISwapChain_Release(swapchain);
2058 swapchain_desc.OutputWindow = NULL;
2059 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2060 &swapchain_desc, NULL, NULL, NULL, NULL);
2061 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2062 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2063 &swapchain_desc, NULL, &device, NULL, NULL);
2064 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2065 ID3D11Device_Release(device);
2067 swapchain = (IDXGISwapChain *)0xdeadbeef;
2068 device = (ID3D11Device *)0xdeadbeef;
2069 feature_level = 0xdeadbeef;
2070 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
2071 swapchain_desc.OutputWindow = NULL;
2072 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2073 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
2074 ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2075 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
2076 ok(!device, "Got unexpected device pointer %p.\n", device);
2077 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
2078 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
2080 swapchain = (IDXGISwapChain *)0xdeadbeef;
2081 device = (ID3D11Device *)0xdeadbeef;
2082 feature_level = 0xdeadbeef;
2083 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
2084 swapchain_desc.OutputWindow = window;
2085 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
2086 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2087 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
2088 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2089 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
2090 ok(!device, "Got unexpected device pointer %p.\n", device);
2091 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
2092 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
2094 DestroyWindow(window);
2097 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
2099 struct device_desc device_desc;
2100 IDXGIAdapter *dxgi_adapter;
2101 IDXGIDevice *dxgi_device;
2102 ID3D11Device *device;
2103 IUnknown *iface;
2104 ULONG refcount;
2105 HRESULT hr;
2107 device_desc.feature_level = &feature_level;
2108 device_desc.flags = 0;
2109 if (!(device = create_device(&device_desc)))
2111 skip("Failed to create device for feature level %#x.\n", feature_level);
2112 return;
2115 check_interface(device, &IID_IUnknown, TRUE, FALSE);
2116 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
2117 check_interface(device, &IID_IDXGIDevice, TRUE, FALSE);
2118 check_interface(device, &IID_IDXGIDevice1, TRUE, FALSE);
2119 check_interface(device, &IID_ID3D10Multithread, TRUE, TRUE); /* Not available on all Windows versions. */
2120 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
2121 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
2122 check_interface(device, &IID_ID3D11InfoQueue, enable_debug_layer, FALSE);
2124 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
2125 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
2126 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
2127 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
2128 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
2129 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
2130 IUnknown_Release(iface);
2131 IDXGIAdapter_Release(dxgi_adapter);
2132 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
2133 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
2134 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
2135 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
2136 IUnknown_Release(iface);
2137 IDXGIAdapter_Release(dxgi_adapter);
2138 IDXGIDevice_Release(dxgi_device);
2140 refcount = ID3D11Device_Release(device);
2141 ok(!refcount, "Device has %u references left.\n", refcount);
2143 device_desc.feature_level = &feature_level;
2144 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
2145 if (!(device = create_device(&device_desc)))
2147 skip("Failed to create debug device for feature level %#x.\n", feature_level);
2148 return;
2151 todo_wine check_interface(device, &IID_ID3D11InfoQueue, TRUE, FALSE);
2153 refcount = ID3D11Device_Release(device);
2154 ok(!refcount, "Device has %u references left.\n", refcount);
2157 static void test_immediate_context(void)
2159 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
2160 ULONG expected_refcount, refcount;
2161 ID3D11CommandList *command_list;
2162 ID3D11Multithread *multithread;
2163 ID3D11Buffer *buffer[2];
2164 ID3D11Device *device;
2165 unsigned int flags;
2166 BOOL enabled;
2167 HRESULT hr;
2169 static const unsigned int buffer_contents[] =
2171 0x11111111, 0x22222222, 0x33333333, 0x44444444,
2172 0x55555555, 0x66666666, 0x77777777, 0x88888888,
2175 if (!(device = create_device(NULL)))
2177 skip("Failed to create device.\n");
2178 return;
2181 expected_refcount = get_refcount(device) + 1;
2182 ID3D11Device_GetImmediateContext(device, &immediate_context);
2183 refcount = get_refcount(device);
2184 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
2185 previous_immediate_context = immediate_context;
2187 ID3D11Device_GetImmediateContext(device, &immediate_context);
2188 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
2189 refcount = get_refcount(device);
2190 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
2192 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
2193 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2194 refcount = ID3D11DeviceContext_Release(immediate_context);
2195 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2197 ID3D11Device_GetImmediateContext(device, &immediate_context);
2198 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
2199 refcount = ID3D11DeviceContext_Release(immediate_context);
2200 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2202 ID3D11Device_GetImmediateContext(device, &immediate_context);
2203 expected_refcount = get_refcount(immediate_context) + 1;
2204 hr = ID3D11DeviceContext_QueryInterface(immediate_context, &IID_ID3D11Multithread, (void **)&multithread);
2205 if (hr == E_NOINTERFACE)
2207 win_skip("ID3D11Multithread is not supported.\n");
2208 goto done;
2210 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2212 refcount = get_refcount(immediate_context);
2213 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2215 expected_refcount = refcount;
2216 refcount = get_refcount(multithread);
2217 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2219 enabled = ID3D11Multithread_GetMultithreadProtected(multithread);
2220 todo_wine ok(!enabled, "Multithread protection is %#x.\n", enabled);
2222 ID3D11Multithread_Release(multithread);
2224 ID3D11Device_GetImmediateContext(device, &immediate_context);
2226 flags = ID3D11DeviceContext_GetContextFlags(immediate_context);
2227 ok(!flags, "Got unexpected flags %#x.\n", flags);
2229 hr = ID3D11DeviceContext_FinishCommandList(immediate_context, FALSE, &command_list);
2230 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
2232 buffer[0] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 16, &buffer_contents[0]);
2233 buffer[1] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 16, &buffer_contents[4]);
2235 ID3D11DeviceContext_CopyResource(immediate_context, (ID3D11Resource *)buffer[1], (ID3D11Resource *)buffer[0]);
2237 hr = ID3D11DeviceContext_FinishCommandList(immediate_context, FALSE, &command_list);
2238 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
2240 ID3D11Buffer_Release(buffer[1]);
2241 ID3D11Buffer_Release(buffer[0]);
2242 ID3D11DeviceContext_Release(immediate_context);
2244 done:
2245 refcount = ID3D11DeviceContext_Release(immediate_context);
2246 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2247 refcount = ID3D11Device_Release(device);
2248 ok(!refcount, "Device has %u references left.\n", refcount);
2251 static void test_create_deferred_context(void)
2253 ULONG refcount, expected_refcount;
2254 struct device_desc device_desc;
2255 ID3D11DeviceContext *context;
2256 ID3D11Device *device;
2257 HRESULT hr;
2259 device_desc.feature_level = NULL;
2260 device_desc.flags = D3D11_CREATE_DEVICE_SINGLETHREADED;
2261 if (!(device = create_device(&device_desc)))
2263 skip("Failed to create single-threaded device.\n");
2264 return;
2267 hr = ID3D11Device_CreateDeferredContext(device, 0, &context);
2268 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Failed to create deferred context, hr %#x.\n", hr);
2270 refcount = ID3D11Device_Release(device);
2271 ok(!refcount, "Device has %u references left.\n", refcount);
2273 if (!(device = create_device(NULL)))
2275 skip("Failed to create device.\n");
2276 return;
2279 expected_refcount = get_refcount(device) + 1;
2280 hr = ID3D11Device_CreateDeferredContext(device, 0, &context);
2281 todo_wine ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
2282 if (FAILED(hr))
2283 goto done;
2284 refcount = get_refcount(device);
2285 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2286 refcount = get_refcount(context);
2287 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2289 check_interface(context, &IID_IUnknown, TRUE, FALSE);
2290 check_interface(context, &IID_ID3D11DeviceChild, TRUE, FALSE);
2291 check_interface(context, &IID_ID3D11DeviceContext, TRUE, FALSE);
2292 check_interface(context, &IID_ID3D11Multithread, FALSE, FALSE);
2294 refcount = ID3D11DeviceContext_Release(context);
2295 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2297 done:
2298 refcount = ID3D11Device_Release(device);
2299 ok(!refcount, "Device has %u references left.\n", refcount);
2302 static void test_create_texture1d(void)
2304 ULONG refcount, expected_refcount;
2305 D3D11_SUBRESOURCE_DATA data = {0};
2306 ID3D11Device *device, *tmp;
2307 D3D11_TEXTURE1D_DESC desc;
2308 ID3D11Texture1D *texture;
2309 unsigned int i;
2310 HRESULT hr;
2312 if (!(device = create_device(NULL)))
2314 skip("Failed to create device.\n");
2315 return;
2318 desc.Width = 512;
2319 desc.MipLevels = 1;
2320 desc.ArraySize = 1;
2321 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2322 desc.Usage = D3D11_USAGE_DEFAULT;
2323 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2324 desc.CPUAccessFlags = 0;
2325 desc.MiscFlags = 0;
2327 hr = ID3D11Device_CreateTexture1D(device, &desc, &data, &texture);
2328 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2330 expected_refcount = get_refcount(device) + 1;
2331 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2332 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2333 refcount = get_refcount(device);
2334 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2335 tmp = NULL;
2336 expected_refcount = refcount + 1;
2337 ID3D11Texture1D_GetDevice(texture, &tmp);
2338 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2339 refcount = get_refcount(device);
2340 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2341 ID3D11Device_Release(tmp);
2343 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2344 ID3D11Texture1D_Release(texture);
2346 desc.MipLevels = 0;
2347 expected_refcount = get_refcount(device) + 1;
2348 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2349 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2350 refcount = get_refcount(device);
2351 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2352 tmp = NULL;
2353 expected_refcount = refcount + 1;
2354 ID3D11Texture1D_GetDevice(texture, &tmp);
2355 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2356 refcount = get_refcount(device);
2357 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2358 ID3D11Device_Release(tmp);
2360 ID3D11Texture1D_GetDesc(texture, &desc);
2361 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2362 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2363 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2364 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2365 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2366 ok(desc.BindFlags == D3D11_BIND_SHADER_RESOURCE, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
2367 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
2368 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
2370 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2371 ID3D11Texture1D_Release(texture);
2373 desc.MipLevels = 1;
2374 desc.ArraySize = 2;
2375 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2376 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2378 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2379 ID3D11Texture1D_Release(texture);
2381 for (i = 0; i < 4; ++i)
2383 desc.ArraySize = i;
2384 desc.Format = DXGI_FORMAT_R32G32B32A32_TYPELESS;
2385 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2386 desc.MiscFlags = 0;
2387 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2388 ok(hr == (i ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2389 if (SUCCEEDED(hr))
2390 ID3D11Texture1D_Release(texture);
2393 refcount = ID3D11Device_Release(device);
2394 ok(!refcount, "Device has %u references left.\n", refcount);
2397 static void test_texture1d_interfaces(void)
2399 ID3D10Texture1D *d3d10_texture;
2400 D3D11_TEXTURE1D_DESC desc;
2401 ID3D11Texture1D *texture;
2402 ID3D11Device *device;
2403 unsigned int i;
2404 ULONG refcount;
2405 HRESULT hr;
2407 static const struct test
2409 BOOL implements_d3d10_interfaces;
2410 UINT bind_flags;
2411 UINT misc_flags;
2412 UINT expected_bind_flags;
2413 UINT expected_misc_flags;
2415 desc_conversion_tests[] =
2418 TRUE,
2419 D3D11_BIND_SHADER_RESOURCE, 0,
2420 D3D10_BIND_SHADER_RESOURCE, 0
2423 TRUE,
2424 D3D11_BIND_UNORDERED_ACCESS, 0,
2425 D3D11_BIND_UNORDERED_ACCESS, 0
2428 FALSE,
2429 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2430 0, 0
2433 TRUE,
2434 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2435 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2439 if (!(device = create_device(NULL)))
2441 skip("Failed to create ID3D11Device, skipping tests.\n");
2442 return;
2445 desc.Width = 512;
2446 desc.MipLevels = 0;
2447 desc.ArraySize = 1;
2448 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2449 desc.Usage = D3D11_USAGE_DEFAULT;
2450 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2451 desc.CPUAccessFlags = 0;
2452 desc.MiscFlags = 0;
2454 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2455 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2456 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2457 hr = check_interface(texture, &IID_ID3D10Texture1D, TRUE, TRUE); /* Not available on all Windows versions. */
2458 ID3D11Texture1D_Release(texture);
2459 if (FAILED(hr))
2461 win_skip("1D textures do not implement ID3D10Texture1D, skipping tests.\n");
2462 ID3D11Device_Release(device);
2463 return;
2466 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2468 const struct test *current = &desc_conversion_tests[i];
2469 D3D10_TEXTURE1D_DESC d3d10_desc;
2470 ID3D10Device *d3d10_device;
2472 desc.Width = 512;
2473 desc.MipLevels = 1;
2474 desc.ArraySize = 1;
2475 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2476 desc.Usage = D3D11_USAGE_DEFAULT;
2477 desc.BindFlags = current->bind_flags;
2478 desc.CPUAccessFlags = 0;
2479 desc.MiscFlags = current->misc_flags;
2481 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2482 /* Shared resources are not supported by REF and WARP devices. */
2483 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2484 "Test %u: Failed to create a 1d texture, hr %#x.\n", i, hr);
2485 if (FAILED(hr))
2487 win_skip("Failed to create ID3D11Texture1D, skipping test %u.\n", i);
2488 continue;
2491 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2493 hr = ID3D11Texture1D_QueryInterface(texture, &IID_ID3D10Texture1D, (void **)&d3d10_texture);
2494 ID3D11Texture1D_Release(texture);
2496 if (current->implements_d3d10_interfaces)
2498 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture1D.\n", i);
2500 else
2502 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture1D.\n", i);
2503 if (SUCCEEDED(hr)) ID3D10Texture1D_Release(d3d10_texture);
2504 continue;
2507 ID3D10Texture1D_GetDesc(d3d10_texture, &d3d10_desc);
2509 ok(d3d10_desc.Width == desc.Width,
2510 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2511 ok(d3d10_desc.MipLevels == desc.MipLevels,
2512 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2513 ok(d3d10_desc.ArraySize == desc.ArraySize,
2514 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2515 ok(d3d10_desc.Format == desc.Format,
2516 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2517 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2518 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2519 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2520 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2521 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2522 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2524 d3d10_device = (ID3D10Device *)0xdeadbeef;
2525 ID3D10Texture1D_GetDevice(d3d10_texture, &d3d10_device);
2526 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2527 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2529 ID3D10Texture1D_Release(d3d10_texture);
2532 refcount = ID3D11Device_Release(device);
2533 ok(!refcount, "Device has %u references left.\n", refcount);
2536 static void test_create_texture2d(void)
2538 ULONG refcount, expected_refcount;
2539 D3D11_SUBRESOURCE_DATA data = {0};
2540 D3D_FEATURE_LEVEL feature_level;
2541 ID3D11Device *device, *tmp;
2542 D3D11_TEXTURE2D_DESC desc;
2543 ID3D11Texture2D *texture;
2544 UINT quality_level_count;
2545 unsigned int i;
2546 HRESULT hr;
2548 static const struct
2550 DXGI_FORMAT format;
2551 UINT array_size;
2552 D3D11_BIND_FLAG bind_flags;
2553 UINT misc_flags;
2554 BOOL succeeds;
2555 BOOL todo;
2557 tests[] =
2559 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
2560 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
2561 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
2562 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
2563 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2564 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2565 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2566 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2567 FALSE, FALSE},
2568 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2569 FALSE, FALSE},
2570 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2571 FALSE, FALSE},
2572 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2573 TRUE, FALSE},
2574 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2575 TRUE, FALSE},
2576 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2577 TRUE, FALSE},
2578 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2579 TRUE, FALSE},
2580 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2581 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2582 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2583 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2584 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2585 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2586 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2587 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2588 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2589 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2590 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2591 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2592 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2593 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2594 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2595 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2596 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2597 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2598 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2599 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
2600 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2601 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2602 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
2603 TRUE, FALSE},
2604 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2605 TRUE, FALSE},
2606 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2607 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
2608 FALSE, TRUE},
2609 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2610 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
2611 FALSE, TRUE},
2612 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
2613 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
2614 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
2615 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2616 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2617 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2618 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2619 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2620 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2621 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2622 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2623 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2624 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2625 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2626 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2627 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2628 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2629 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2630 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2631 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2632 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2633 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2634 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
2635 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2636 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
2637 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
2638 FALSE, TRUE},
2639 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2640 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2641 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2642 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2643 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2646 if (!(device = create_device(NULL)))
2648 skip("Failed to create device.\n");
2649 return;
2652 feature_level = ID3D11Device_GetFeatureLevel(device);
2654 desc.Width = 512;
2655 desc.Height = 512;
2656 desc.MipLevels = 1;
2657 desc.ArraySize = 1;
2658 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2659 desc.SampleDesc.Count = 1;
2660 desc.SampleDesc.Quality = 0;
2661 desc.Usage = D3D11_USAGE_DEFAULT;
2662 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2663 desc.CPUAccessFlags = 0;
2664 desc.MiscFlags = 0;
2666 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
2667 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2669 expected_refcount = get_refcount(device) + 1;
2670 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2671 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2672 refcount = get_refcount(device);
2673 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2674 tmp = NULL;
2675 expected_refcount = refcount + 1;
2676 ID3D11Texture2D_GetDevice(texture, &tmp);
2677 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2678 refcount = get_refcount(device);
2679 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2680 ID3D11Device_Release(tmp);
2682 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2683 ID3D11Texture2D_Release(texture);
2685 desc.MipLevels = 0;
2686 expected_refcount = get_refcount(device) + 1;
2687 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2688 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2689 refcount = get_refcount(device);
2690 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2691 tmp = NULL;
2692 expected_refcount = refcount + 1;
2693 ID3D11Texture2D_GetDevice(texture, &tmp);
2694 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2695 refcount = get_refcount(device);
2696 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2697 ID3D11Device_Release(tmp);
2699 ID3D11Texture2D_GetDesc(texture, &desc);
2700 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2701 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
2702 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2703 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2704 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2705 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
2706 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
2707 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2708 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
2709 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
2710 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
2712 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2713 ID3D11Texture2D_Release(texture);
2715 desc.MipLevels = 1;
2716 desc.ArraySize = 2;
2717 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2718 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2720 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2721 ID3D11Texture2D_Release(texture);
2723 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
2724 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
2725 desc.ArraySize = 1;
2726 desc.SampleDesc.Count = 2;
2727 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2728 if (quality_level_count)
2730 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
2731 ID3D11Texture2D_Release(texture);
2732 desc.SampleDesc.Quality = quality_level_count;
2733 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2735 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2737 /* We assume 15 samples multisampling is never supported in practice. */
2738 desc.SampleDesc.Count = 15;
2739 desc.SampleDesc.Quality = 0;
2740 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2741 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2743 desc.SampleDesc.Count = 1;
2744 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2746 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
2747 BOOL todo = tests[i].todo;
2749 if (feature_level < D3D_FEATURE_LEVEL_10_1
2750 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
2751 && tests[i].array_size > 6)
2753 expected_hr = E_INVALIDARG;
2754 todo = TRUE;
2757 desc.ArraySize = tests[i].array_size;
2758 desc.Format = tests[i].format;
2759 desc.BindFlags = tests[i].bind_flags;
2760 desc.MiscFlags = tests[i].misc_flags;
2761 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2763 todo_wine_if(todo)
2764 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
2765 i, hr, desc.Format);
2767 if (SUCCEEDED(hr))
2768 ID3D11Texture2D_Release(texture);
2771 refcount = ID3D11Device_Release(device);
2772 ok(!refcount, "Device has %u references left.\n", refcount);
2775 static void test_texture2d_interfaces(void)
2777 ID3D10Texture2D *d3d10_texture;
2778 D3D11_TEXTURE2D_DESC desc;
2779 ID3D11Texture2D *texture;
2780 ID3D11Device *device;
2781 unsigned int i;
2782 ULONG refcount;
2783 HRESULT hr;
2785 static const struct test
2787 BOOL implements_d3d10_interfaces;
2788 UINT bind_flags;
2789 UINT misc_flags;
2790 UINT expected_bind_flags;
2791 UINT expected_misc_flags;
2793 desc_conversion_tests[] =
2796 TRUE,
2797 D3D11_BIND_SHADER_RESOURCE, 0,
2798 D3D10_BIND_SHADER_RESOURCE, 0
2801 TRUE,
2802 D3D11_BIND_UNORDERED_ACCESS, 0,
2803 D3D11_BIND_UNORDERED_ACCESS, 0
2806 FALSE,
2807 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2808 0, 0
2811 TRUE,
2812 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2813 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2816 TRUE,
2817 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
2818 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2822 if (!(device = create_device(NULL)))
2824 skip("Failed to create ID3D11Device, skipping tests.\n");
2825 return;
2828 desc.Width = 512;
2829 desc.Height = 512;
2830 desc.MipLevels = 0;
2831 desc.ArraySize = 1;
2832 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2833 desc.SampleDesc.Count = 1;
2834 desc.SampleDesc.Quality = 0;
2835 desc.Usage = D3D11_USAGE_DEFAULT;
2836 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2837 desc.CPUAccessFlags = 0;
2838 desc.MiscFlags = 0;
2840 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2841 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2842 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2843 hr = check_interface(texture, &IID_ID3D10Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
2844 ID3D11Texture2D_Release(texture);
2845 if (FAILED(hr))
2847 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
2848 ID3D11Device_Release(device);
2849 return;
2852 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2854 const struct test *current = &desc_conversion_tests[i];
2855 D3D10_TEXTURE2D_DESC d3d10_desc;
2856 ID3D10Device *d3d10_device;
2858 desc.Width = 512;
2859 desc.Height = 512;
2860 desc.MipLevels = 1;
2861 desc.ArraySize = 1;
2862 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2863 desc.SampleDesc.Count = 1;
2864 desc.SampleDesc.Quality = 0;
2865 desc.Usage = D3D11_USAGE_DEFAULT;
2866 desc.BindFlags = current->bind_flags;
2867 desc.CPUAccessFlags = 0;
2868 desc.MiscFlags = current->misc_flags;
2870 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2871 /* Shared resources are not supported by REF and WARP devices. */
2872 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2873 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2874 if (FAILED(hr))
2876 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
2877 continue;
2880 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2882 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2883 ID3D11Texture2D_Release(texture);
2885 if (current->implements_d3d10_interfaces)
2887 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2889 else
2891 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2892 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2893 continue;
2896 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
2898 ok(d3d10_desc.Width == desc.Width,
2899 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2900 ok(d3d10_desc.Height == desc.Height,
2901 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2902 ok(d3d10_desc.MipLevels == desc.MipLevels,
2903 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2904 ok(d3d10_desc.ArraySize == desc.ArraySize,
2905 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2906 ok(d3d10_desc.Format == desc.Format,
2907 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2908 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
2909 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
2910 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2911 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
2912 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2913 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2914 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2915 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2916 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2917 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2918 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2919 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2921 d3d10_device = (ID3D10Device *)0xdeadbeef;
2922 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
2923 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2924 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2926 ID3D10Texture2D_Release(d3d10_texture);
2929 refcount = ID3D11Device_Release(device);
2930 ok(!refcount, "Device has %u references left.\n", refcount);
2933 static void test_create_texture3d(void)
2935 ULONG refcount, expected_refcount;
2936 D3D11_SUBRESOURCE_DATA data = {0};
2937 ID3D11Device *device, *tmp;
2938 D3D11_TEXTURE3D_DESC desc;
2939 ID3D11Texture3D *texture;
2940 unsigned int i;
2941 HRESULT hr;
2943 static const struct
2945 DXGI_FORMAT format;
2946 D3D11_BIND_FLAG bind_flags;
2947 BOOL succeeds;
2948 BOOL todo;
2950 tests[] =
2952 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2953 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2954 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2955 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2956 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2957 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2958 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2959 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2960 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2961 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2962 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2963 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2966 if (!(device = create_device(NULL)))
2968 skip("Failed to create ID3D11Device, skipping tests.\n");
2969 return;
2972 desc.Width = 64;
2973 desc.Height = 64;
2974 desc.Depth = 64;
2975 desc.MipLevels = 1;
2976 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2977 desc.Usage = D3D11_USAGE_DEFAULT;
2978 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2979 desc.CPUAccessFlags = 0;
2980 desc.MiscFlags = 0;
2982 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2983 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2985 expected_refcount = get_refcount(device) + 1;
2986 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2987 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2988 refcount = get_refcount(device);
2989 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2990 tmp = NULL;
2991 expected_refcount = refcount + 1;
2992 ID3D11Texture3D_GetDevice(texture, &tmp);
2993 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2994 refcount = get_refcount(device);
2995 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2996 ID3D11Device_Release(tmp);
2998 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2999 ID3D11Texture3D_Release(texture);
3001 desc.MipLevels = 0;
3002 expected_refcount = get_refcount(device) + 1;
3003 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3004 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
3005 refcount = get_refcount(device);
3006 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3007 tmp = NULL;
3008 expected_refcount = refcount + 1;
3009 ID3D11Texture3D_GetDevice(texture, &tmp);
3010 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3011 refcount = get_refcount(device);
3012 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3013 ID3D11Device_Release(tmp);
3015 ID3D11Texture3D_GetDesc(texture, &desc);
3016 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
3017 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
3018 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
3019 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
3020 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
3021 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
3022 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
3023 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
3024 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
3026 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3027 ID3D11Texture3D_Release(texture);
3029 desc.MipLevels = 1;
3030 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3032 desc.Format = tests[i].format;
3033 desc.BindFlags = tests[i].bind_flags;
3034 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3036 todo_wine_if(tests[i].todo)
3037 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
3039 if (SUCCEEDED(hr))
3040 ID3D11Texture3D_Release(texture);
3043 refcount = ID3D11Device_Release(device);
3044 ok(!refcount, "Device has %u references left.\n", refcount);
3047 static void test_texture3d_interfaces(void)
3049 ID3D10Texture3D *d3d10_texture;
3050 D3D11_TEXTURE3D_DESC desc;
3051 ID3D11Texture3D *texture;
3052 ID3D11Device *device;
3053 unsigned int i;
3054 ULONG refcount;
3055 HRESULT hr;
3057 static const struct test
3059 BOOL implements_d3d10_interfaces;
3060 UINT bind_flags;
3061 UINT misc_flags;
3062 UINT expected_bind_flags;
3063 UINT expected_misc_flags;
3065 desc_conversion_tests[] =
3068 TRUE,
3069 D3D11_BIND_SHADER_RESOURCE, 0,
3070 D3D10_BIND_SHADER_RESOURCE, 0
3073 TRUE,
3074 D3D11_BIND_UNORDERED_ACCESS, 0,
3075 D3D11_BIND_UNORDERED_ACCESS, 0
3078 FALSE,
3079 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
3080 0, 0
3083 TRUE,
3084 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
3085 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
3089 if (!(device = create_device(NULL)))
3091 skip("Failed to create ID3D11Device.\n");
3092 return;
3095 desc.Width = 64;
3096 desc.Height = 64;
3097 desc.Depth = 64;
3098 desc.MipLevels = 0;
3099 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3100 desc.Usage = D3D11_USAGE_DEFAULT;
3101 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3102 desc.CPUAccessFlags = 0;
3103 desc.MiscFlags = 0;
3105 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3106 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
3107 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3108 hr = check_interface(texture, &IID_ID3D10Texture3D, TRUE, TRUE); /* Not available on all Windows versions. */
3109 ID3D11Texture3D_Release(texture);
3110 if (FAILED(hr))
3112 win_skip("3D textures do not implement ID3D10Texture3D.\n");
3113 ID3D11Device_Release(device);
3114 return;
3117 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
3119 const struct test *current = &desc_conversion_tests[i];
3120 D3D10_TEXTURE3D_DESC d3d10_desc;
3121 ID3D10Device *d3d10_device;
3123 desc.Width = 64;
3124 desc.Height = 64;
3125 desc.Depth = 64;
3126 desc.MipLevels = 1;
3127 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3128 desc.Usage = D3D11_USAGE_DEFAULT;
3129 desc.BindFlags = current->bind_flags;
3130 desc.CPUAccessFlags = 0;
3131 desc.MiscFlags = current->misc_flags;
3133 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3134 /* Shared resources are not supported by REF and WARP devices. */
3135 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
3136 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
3137 if (FAILED(hr))
3139 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
3140 continue;
3143 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3145 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
3146 ID3D11Texture3D_Release(texture);
3148 if (current->implements_d3d10_interfaces)
3150 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
3152 else
3154 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
3155 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
3156 continue;
3159 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
3161 ok(d3d10_desc.Width == desc.Width,
3162 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
3163 ok(d3d10_desc.Height == desc.Height,
3164 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
3165 ok(d3d10_desc.Depth == desc.Depth,
3166 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
3167 ok(d3d10_desc.MipLevels == desc.MipLevels,
3168 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
3169 ok(d3d10_desc.Format == desc.Format,
3170 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
3171 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3172 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3173 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3174 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3175 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3176 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3177 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3178 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3180 d3d10_device = (ID3D10Device *)0xdeadbeef;
3181 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
3182 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3183 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3185 ID3D10Texture3D_Release(d3d10_texture);
3188 refcount = ID3D11Device_Release(device);
3189 ok(!refcount, "Device has %u references left.\n", refcount);
3192 static void test_create_buffer(void)
3194 ID3D10Buffer *d3d10_buffer;
3195 HRESULT expected_hr, hr;
3196 D3D11_BUFFER_DESC desc;
3197 ID3D11Buffer *buffer;
3198 ID3D11Device *device;
3199 unsigned int i;
3200 ULONG refcount;
3202 static const struct test
3204 BOOL succeeds;
3205 BOOL implements_d3d10_interfaces;
3206 UINT bind_flags;
3207 UINT misc_flags;
3208 UINT structure_stride;
3209 UINT expected_bind_flags;
3210 UINT expected_misc_flags;
3212 tests[] =
3215 TRUE, TRUE,
3216 D3D11_BIND_VERTEX_BUFFER, 0, 0,
3217 D3D10_BIND_VERTEX_BUFFER, 0
3220 TRUE, TRUE,
3221 D3D11_BIND_INDEX_BUFFER, 0, 0,
3222 D3D10_BIND_INDEX_BUFFER, 0
3225 TRUE, TRUE,
3226 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
3227 D3D10_BIND_CONSTANT_BUFFER, 0
3230 TRUE, TRUE,
3231 D3D11_BIND_SHADER_RESOURCE, 0, 0,
3232 D3D10_BIND_SHADER_RESOURCE, 0
3235 TRUE, TRUE,
3236 D3D11_BIND_STREAM_OUTPUT, 0, 0,
3237 D3D10_BIND_STREAM_OUTPUT, 0
3240 TRUE, TRUE,
3241 D3D11_BIND_RENDER_TARGET, 0, 0,
3242 D3D10_BIND_RENDER_TARGET, 0
3245 TRUE, TRUE,
3246 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
3247 D3D11_BIND_UNORDERED_ACCESS, 0
3250 TRUE, TRUE,
3251 0, D3D11_RESOURCE_MISC_SHARED, 0,
3252 0, D3D10_RESOURCE_MISC_SHARED
3255 TRUE, TRUE,
3256 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
3257 0, 0
3260 FALSE, FALSE,
3261 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3264 FALSE, FALSE,
3265 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3268 FALSE, FALSE,
3269 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3272 TRUE, TRUE,
3273 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3274 D3D10_BIND_SHADER_RESOURCE, 0
3277 FALSE, FALSE,
3278 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3281 FALSE, FALSE,
3282 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3285 TRUE, TRUE,
3286 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3287 D3D11_BIND_UNORDERED_ACCESS, 0
3290 FALSE, FALSE,
3291 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3293 /* Structured buffers do not implement ID3D10Buffer. */
3295 TRUE, FALSE,
3296 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3299 TRUE, FALSE,
3300 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3303 FALSE, FALSE,
3304 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
3307 FALSE, FALSE,
3308 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
3311 FALSE, FALSE,
3312 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
3315 FALSE, FALSE,
3316 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
3319 FALSE, FALSE,
3320 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
3323 TRUE, FALSE,
3324 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
3327 FALSE, FALSE,
3328 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
3331 TRUE, FALSE,
3332 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
3335 TRUE, FALSE,
3336 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
3339 FALSE, FALSE,
3340 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
3343 TRUE, FALSE,
3344 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
3347 TRUE, TRUE,
3348 0, 0, 513,
3349 0, 0
3352 TRUE, TRUE,
3353 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
3354 D3D10_BIND_CONSTANT_BUFFER, 0
3357 TRUE, TRUE,
3358 D3D11_BIND_SHADER_RESOURCE, 0, 513,
3359 D3D10_BIND_SHADER_RESOURCE, 0
3362 TRUE, TRUE,
3363 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
3364 D3D11_BIND_UNORDERED_ACCESS, 0
3367 FALSE, FALSE,
3368 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3371 FALSE, FALSE,
3372 D3D11_BIND_SHADER_RESOURCE,
3373 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3376 TRUE, TRUE,
3377 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
3378 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
3382 if (!(device = create_device(NULL)))
3384 skip("Failed to create ID3D11Device.\n");
3385 return;
3388 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
3389 hr = check_interface(buffer, &IID_ID3D10Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
3390 ID3D11Buffer_Release(buffer);
3391 if (FAILED(hr))
3393 win_skip("Buffers do not implement ID3D10Buffer.\n");
3394 ID3D11Device_Release(device);
3395 return;
3398 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3400 const struct test *current = &tests[i];
3401 D3D11_BUFFER_DESC obtained_desc;
3402 D3D10_BUFFER_DESC d3d10_desc;
3403 ID3D10Device *d3d10_device;
3405 desc.ByteWidth = 1024;
3406 desc.Usage = D3D11_USAGE_DEFAULT;
3407 desc.BindFlags = current->bind_flags;
3408 desc.CPUAccessFlags = 0;
3409 desc.MiscFlags = current->misc_flags;
3410 desc.StructureByteStride = current->structure_stride;
3412 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
3413 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
3414 /* Shared resources are not supported by REF and WARP devices. */
3415 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
3416 i, hr, expected_hr);
3417 if (FAILED(hr))
3419 if (hr == E_OUTOFMEMORY)
3420 win_skip("Failed to create a buffer, skipping test %u.\n", i);
3421 continue;
3424 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
3425 desc.StructureByteStride = 0;
3427 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
3429 ok(obtained_desc.ByteWidth == desc.ByteWidth,
3430 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
3431 ok(obtained_desc.Usage == desc.Usage,
3432 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
3433 ok(obtained_desc.BindFlags == desc.BindFlags,
3434 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
3435 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
3436 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
3437 ok(obtained_desc.MiscFlags == desc.MiscFlags,
3438 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
3439 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
3440 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
3442 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
3443 ID3D11Buffer_Release(buffer);
3445 if (current->implements_d3d10_interfaces)
3447 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
3449 else
3451 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
3452 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
3453 continue;
3456 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
3458 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
3459 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
3460 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3461 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3462 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3463 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3464 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3465 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3466 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3467 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3469 d3d10_device = (ID3D10Device *)0xdeadbeef;
3470 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
3471 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3472 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3474 ID3D10Buffer_Release(d3d10_buffer);
3477 memset(&desc, 0, sizeof(desc));
3478 desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
3479 for (i = 0; i <= 32; ++i)
3481 desc.ByteWidth = i;
3482 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
3483 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
3484 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
3485 if (SUCCEEDED(hr))
3486 ID3D11Buffer_Release(buffer);
3489 refcount = ID3D11Device_Release(device);
3490 ok(!refcount, "Device has %u references left.\n", refcount);
3493 static void test_create_depthstencil_view(void)
3495 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
3496 D3D11_TEXTURE2D_DESC texture_desc;
3497 ULONG refcount, expected_refcount;
3498 ID3D11DepthStencilView *dsview;
3499 ID3D11Device *device, *tmp;
3500 ID3D11Texture2D *texture;
3501 unsigned int i;
3502 HRESULT hr;
3504 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3505 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
3506 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
3507 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
3508 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
3509 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
3510 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
3511 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
3512 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
3513 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
3514 static const struct
3516 struct
3518 unsigned int miplevel_count;
3519 unsigned int array_size;
3520 DXGI_FORMAT format;
3521 } texture;
3522 struct dsv_desc dsv_desc;
3523 struct dsv_desc expected_dsv_desc;
3525 tests[] =
3527 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
3528 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
3529 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3530 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
3531 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
3532 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3533 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3534 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3535 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3536 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3537 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
3538 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
3539 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
3540 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
3541 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
3542 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
3543 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
3544 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3545 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3546 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3547 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3548 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3549 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3550 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3551 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3552 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
3553 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
3555 static const struct
3557 struct
3559 unsigned int miplevel_count;
3560 unsigned int array_size;
3561 DXGI_FORMAT format;
3562 } texture;
3563 struct dsv_desc dsv_desc;
3565 invalid_desc_tests[] =
3567 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
3568 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
3569 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
3570 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
3571 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
3572 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3573 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
3574 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
3575 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
3576 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
3577 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
3578 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
3579 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
3581 #undef FMT_UNKNOWN
3582 #undef D24S8
3583 #undef R24G8_TL
3584 #undef DIM_UNKNOWN
3585 #undef TEX_1D
3586 #undef TEX_1D_ARRAY
3587 #undef TEX_2D
3588 #undef TEX_2D_ARRAY
3589 #undef TEX_2DMS
3590 #undef TEX_2DMS_ARR
3592 if (!(device = create_device(NULL)))
3594 skip("Failed to create device.\n");
3595 return;
3598 texture_desc.Width = 512;
3599 texture_desc.Height = 512;
3600 texture_desc.MipLevels = 1;
3601 texture_desc.ArraySize = 1;
3602 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
3603 texture_desc.SampleDesc.Count = 1;
3604 texture_desc.SampleDesc.Quality = 0;
3605 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3606 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3607 texture_desc.CPUAccessFlags = 0;
3608 texture_desc.MiscFlags = 0;
3610 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3611 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
3613 expected_refcount = get_refcount(device) + 1;
3614 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
3615 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
3616 refcount = get_refcount(device);
3617 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3618 tmp = NULL;
3619 expected_refcount = refcount + 1;
3620 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
3621 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3622 refcount = get_refcount(device);
3623 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3624 ID3D11Device_Release(tmp);
3626 memset(&dsv_desc, 0, sizeof(dsv_desc));
3627 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
3628 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
3629 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
3630 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
3631 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
3632 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
3634 ID3D11DepthStencilView_Release(dsview);
3635 ID3D11Texture2D_Release(texture);
3637 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3639 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
3641 texture_desc.MipLevels = tests[i].texture.miplevel_count;
3642 texture_desc.ArraySize = tests[i].texture.array_size;
3643 texture_desc.Format = tests[i].texture.format;
3645 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3646 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3648 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
3650 current_desc = NULL;
3652 else
3654 current_desc = &dsv_desc;
3655 get_dsv_desc(current_desc, &tests[i].dsv_desc);
3658 expected_refcount = get_refcount(texture);
3659 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
3660 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
3661 refcount = get_refcount(texture);
3662 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3664 /* Not available on all Windows versions. */
3665 check_interface(dsview, &IID_ID3D10DepthStencilView, TRUE, TRUE);
3667 memset(&dsv_desc, 0, sizeof(dsv_desc));
3668 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
3669 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
3671 ID3D11DepthStencilView_Release(dsview);
3672 ID3D11Texture2D_Release(texture);
3675 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3677 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3678 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
3679 texture_desc.Format = invalid_desc_tests[i].texture.format;
3681 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3682 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3684 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
3685 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
3686 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3688 ID3D11Texture2D_Release(texture);
3691 refcount = ID3D11Device_Release(device);
3692 ok(!refcount, "Device has %u references left.\n", refcount);
3695 static void test_depthstencil_view_interfaces(void)
3697 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
3698 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
3699 ID3D10DepthStencilView *d3d10_dsview;
3700 D3D11_TEXTURE2D_DESC texture_desc;
3701 ID3D11DepthStencilView *dsview;
3702 ID3D11Texture2D *texture;
3703 ID3D11Device *device;
3704 ULONG refcount;
3705 HRESULT hr;
3707 if (!(device = create_device(NULL)))
3709 skip("Failed to create device.\n");
3710 return;
3713 texture_desc.Width = 512;
3714 texture_desc.Height = 512;
3715 texture_desc.MipLevels = 1;
3716 texture_desc.ArraySize = 1;
3717 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
3718 texture_desc.SampleDesc.Count = 1;
3719 texture_desc.SampleDesc.Quality = 0;
3720 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3721 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3722 texture_desc.CPUAccessFlags = 0;
3723 texture_desc.MiscFlags = 0;
3725 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3726 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
3728 dsv_desc.Format = texture_desc.Format;
3729 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
3730 dsv_desc.Flags = 0;
3731 U(dsv_desc).Texture2D.MipSlice = 0;
3733 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
3734 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
3736 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
3737 ID3D11DepthStencilView_Release(dsview);
3738 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3739 "Depth stencil view should implement ID3D10DepthStencilView.\n");
3741 if (FAILED(hr))
3743 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
3744 goto done;
3747 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
3748 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
3749 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
3750 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
3751 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
3752 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
3754 ID3D10DepthStencilView_Release(d3d10_dsview);
3756 done:
3757 ID3D11Texture2D_Release(texture);
3759 refcount = ID3D11Device_Release(device);
3760 ok(!refcount, "Device has %u references left.\n", refcount);
3763 static void test_create_rendertarget_view(void)
3765 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
3766 D3D11_TEXTURE3D_DESC texture3d_desc;
3767 D3D11_TEXTURE2D_DESC texture2d_desc;
3768 D3D11_SUBRESOURCE_DATA data = {0};
3769 ULONG refcount, expected_refcount;
3770 D3D11_BUFFER_DESC buffer_desc;
3771 ID3D11RenderTargetView *rtview;
3772 ID3D11Device *device, *tmp;
3773 ID3D11Texture3D *texture3d;
3774 ID3D11Texture2D *texture2d;
3775 ID3D11Resource *texture;
3776 ID3D11Buffer *buffer;
3777 unsigned int i;
3778 HRESULT hr;
3780 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3781 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3782 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3783 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
3784 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
3785 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
3786 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
3787 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
3788 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
3789 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
3790 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
3791 static const struct
3793 struct
3795 unsigned int miplevel_count;
3796 unsigned int depth_or_array_size;
3797 DXGI_FORMAT format;
3798 } texture;
3799 struct rtv_desc rtv_desc;
3800 struct rtv_desc expected_rtv_desc;
3802 tests[] =
3804 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
3805 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
3806 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3807 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
3808 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
3809 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3810 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3811 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3812 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3813 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3814 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
3815 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
3816 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
3817 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
3818 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
3819 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
3820 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
3821 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3822 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3823 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3824 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3825 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3826 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3827 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3828 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3829 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3830 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3831 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3832 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3833 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3834 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3835 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3836 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
3837 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
3838 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
3839 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
3840 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3841 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3842 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
3843 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
3844 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
3845 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
3846 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
3847 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
3849 static const struct
3851 struct
3853 D3D11_RTV_DIMENSION dimension;
3854 unsigned int miplevel_count;
3855 unsigned int depth_or_array_size;
3856 DXGI_FORMAT format;
3857 } texture;
3858 struct rtv_desc rtv_desc;
3860 invalid_desc_tests[] =
3862 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3863 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3864 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3865 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3866 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
3867 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
3868 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
3869 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3870 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
3871 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
3872 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
3873 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
3874 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
3875 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
3876 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
3877 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3878 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3879 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3880 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3881 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3882 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3883 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3884 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3885 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
3886 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3887 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3888 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3889 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3890 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3891 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3892 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3893 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3894 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
3895 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
3896 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
3898 #undef FMT_UNKNOWN
3899 #undef RGBA8_UNORM
3900 #undef RGBA8_TL
3901 #undef DIM_UNKNOWN
3902 #undef TEX_1D
3903 #undef TEX_1D_ARRAY
3904 #undef TEX_2D
3905 #undef TEX_2D_ARRAY
3906 #undef TEX_2DMS
3907 #undef TEX_2DMS_ARR
3908 #undef TEX_3D
3910 if (!(device = create_device(NULL)))
3912 skip("Failed to create device.\n");
3913 return;
3916 buffer_desc.ByteWidth = 1024;
3917 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3918 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3919 buffer_desc.CPUAccessFlags = 0;
3920 buffer_desc.MiscFlags = 0;
3921 buffer_desc.StructureByteStride = 0;
3923 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
3924 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3926 expected_refcount = get_refcount(device) + 1;
3927 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3928 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3929 refcount = get_refcount(device);
3930 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3931 tmp = NULL;
3932 expected_refcount = refcount + 1;
3933 ID3D11Buffer_GetDevice(buffer, &tmp);
3934 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3935 refcount = get_refcount(device);
3936 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3937 ID3D11Device_Release(tmp);
3939 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3940 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
3941 U1(U(rtv_desc).Buffer).ElementOffset = 0;
3942 U2(U(rtv_desc).Buffer).ElementWidth = 64;
3944 if (!enable_debug_layer)
3946 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3947 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3950 expected_refcount = get_refcount(device) + 1;
3951 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3952 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3953 refcount = get_refcount(device);
3954 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3955 tmp = NULL;
3956 expected_refcount = refcount + 1;
3957 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3958 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3959 refcount = get_refcount(device);
3960 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3961 ID3D11Device_Release(tmp);
3963 /* Not available on all Windows versions. */
3964 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3966 ID3D11RenderTargetView_Release(rtview);
3967 ID3D11Buffer_Release(buffer);
3969 texture2d_desc.Width = 512;
3970 texture2d_desc.Height = 512;
3971 texture2d_desc.SampleDesc.Count = 1;
3972 texture2d_desc.SampleDesc.Quality = 0;
3973 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3974 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3975 texture2d_desc.CPUAccessFlags = 0;
3976 texture2d_desc.MiscFlags = 0;
3978 texture3d_desc.Width = 64;
3979 texture3d_desc.Height = 64;
3980 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3981 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3982 texture3d_desc.CPUAccessFlags = 0;
3983 texture3d_desc.MiscFlags = 0;
3985 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3987 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3989 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3991 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3992 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3993 texture2d_desc.Format = tests[i].texture.format;
3995 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3996 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3997 texture = (ID3D11Resource *)texture2d;
3999 else
4001 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
4002 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
4003 texture3d_desc.Format = tests[i].texture.format;
4005 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4006 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4007 texture = (ID3D11Resource *)texture3d;
4010 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
4012 current_desc = NULL;
4014 else
4016 current_desc = &rtv_desc;
4017 get_rtv_desc(current_desc, &tests[i].rtv_desc);
4020 expected_refcount = get_refcount(texture);
4021 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
4022 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
4023 refcount = get_refcount(texture);
4024 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
4026 /* Not available on all Windows versions. */
4027 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
4029 memset(&rtv_desc, 0, sizeof(rtv_desc));
4030 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
4031 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
4033 ID3D11RenderTargetView_Release(rtview);
4034 ID3D11Resource_Release(texture);
4037 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
4039 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
4040 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
4042 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
4044 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4045 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
4046 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
4048 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4049 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4050 texture = (ID3D11Resource *)texture2d;
4052 else
4054 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4055 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
4056 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
4058 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4059 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4060 texture = (ID3D11Resource *)texture3d;
4063 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
4064 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
4065 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
4067 ID3D11Resource_Release(texture);
4070 refcount = ID3D11Device_Release(device);
4071 ok(!refcount, "Device has %u references left.\n", refcount);
4074 static void test_create_shader_resource_view(void)
4076 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
4077 D3D11_TEXTURE3D_DESC texture3d_desc;
4078 D3D11_TEXTURE2D_DESC texture2d_desc;
4079 ULONG refcount, expected_refcount;
4080 ID3D11ShaderResourceView *srview;
4081 D3D_FEATURE_LEVEL feature_level;
4082 D3D11_BUFFER_DESC buffer_desc;
4083 ID3D11Device *device, *tmp;
4084 ID3D11Texture3D *texture3d;
4085 ID3D11Texture2D *texture2d;
4086 ID3D11Resource *texture;
4087 ID3D11Buffer *buffer;
4088 unsigned int i;
4089 HRESULT hr;
4091 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
4092 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
4093 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
4094 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
4095 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
4096 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
4097 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
4098 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
4099 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
4100 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
4101 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
4102 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
4103 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
4104 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
4105 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
4106 static const struct
4108 struct
4110 unsigned int miplevel_count;
4111 unsigned int depth_or_array_size;
4112 DXGI_FORMAT format;
4113 } texture;
4114 struct srv_desc srv_desc;
4115 struct srv_desc expected_srv_desc;
4117 tests[] =
4119 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4120 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4121 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4122 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4123 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4124 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4125 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
4126 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
4127 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
4128 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
4129 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
4130 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
4131 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
4132 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
4133 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
4134 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4135 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4136 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4137 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4138 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4139 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4140 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4141 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4142 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
4143 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
4144 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4145 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4146 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4147 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
4148 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4149 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4150 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4151 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4152 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4153 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
4154 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
4155 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4156 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
4157 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4158 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4159 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4160 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4161 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4162 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4163 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4164 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
4165 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
4166 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
4168 static const struct
4170 struct
4172 D3D11_SRV_DIMENSION dimension;
4173 unsigned int miplevel_count;
4174 unsigned int depth_or_array_size;
4175 DXGI_FORMAT format;
4176 } texture;
4177 struct srv_desc srv_desc;
4179 invalid_desc_tests[] =
4181 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
4182 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
4183 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4184 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4185 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4186 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
4187 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
4188 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
4189 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
4190 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
4191 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
4192 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
4193 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
4194 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
4195 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
4196 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
4197 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
4198 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
4199 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
4200 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
4201 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
4202 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
4203 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4204 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
4205 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
4206 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
4207 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
4208 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
4209 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
4210 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
4211 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
4212 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
4213 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
4214 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
4215 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4216 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4217 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 1}},
4218 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4219 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 1}},
4220 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4221 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4222 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4223 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4224 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4225 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
4226 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4227 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4228 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4229 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4230 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
4231 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
4232 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
4233 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
4234 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
4235 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
4236 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
4238 #undef FMT_UNKNOWN
4239 #undef RGBA8_UNORM
4240 #undef RGBA8_SRGB
4241 #undef RGBA8_UINT
4242 #undef RGBA8_TL
4243 #undef DIM_UNKNOWN
4244 #undef TEX_1D
4245 #undef TEX_1D_ARRAY
4246 #undef TEX_2D
4247 #undef TEX_2D_ARRAY
4248 #undef TEX_2DMS
4249 #undef TEX_2DMS_ARR
4250 #undef TEX_3D
4251 #undef TEX_CUBE
4252 #undef CUBE_ARRAY
4254 if (!(device = create_device(NULL)))
4256 skip("Failed to create device.\n");
4257 return;
4259 feature_level = ID3D11Device_GetFeatureLevel(device);
4261 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
4263 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
4264 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4266 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4267 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
4268 U1(U(srv_desc).Buffer).ElementOffset = 0;
4269 U2(U(srv_desc).Buffer).ElementWidth = 64;
4271 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
4272 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4274 expected_refcount = get_refcount(device) + 1;
4275 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
4276 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
4277 refcount = get_refcount(device);
4278 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4279 tmp = NULL;
4280 expected_refcount = refcount + 1;
4281 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
4282 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4283 refcount = get_refcount(device);
4284 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4285 ID3D11Device_Release(tmp);
4287 /* Not available on all Windows versions. */
4288 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
4289 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
4291 ID3D11ShaderResourceView_Release(srview);
4292 ID3D11Buffer_Release(buffer);
4294 /* Without D3D11_BIND_SHADER_RESOURCE. */
4295 buffer = create_buffer(device, 0, 1024, NULL);
4297 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
4298 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4300 ID3D11Buffer_Release(buffer);
4302 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
4304 buffer_desc.ByteWidth = 1024;
4305 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4306 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4307 buffer_desc.CPUAccessFlags = 0;
4308 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
4309 buffer_desc.StructureByteStride = 4;
4311 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
4312 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
4314 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
4315 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
4317 memset(&srv_desc, 0, sizeof(srv_desc));
4318 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
4320 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
4321 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
4322 srv_desc.ViewDimension);
4323 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
4324 U1(U(srv_desc).Buffer).FirstElement);
4325 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
4326 U2(U(srv_desc).Buffer).NumElements);
4328 ID3D11ShaderResourceView_Release(srview);
4329 ID3D11Buffer_Release(buffer);
4331 else
4333 skip("Structured buffers require feature level 11_0.\n");
4336 texture2d_desc.Width = 512;
4337 texture2d_desc.Height = 512;
4338 texture2d_desc.SampleDesc.Count = 1;
4339 texture2d_desc.SampleDesc.Quality = 0;
4340 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
4341 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4342 texture2d_desc.CPUAccessFlags = 0;
4344 texture3d_desc.Width = 64;
4345 texture3d_desc.Height = 64;
4346 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
4347 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4348 texture3d_desc.CPUAccessFlags = 0;
4349 texture3d_desc.MiscFlags = 0;
4351 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4353 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
4355 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
4357 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
4358 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
4359 texture2d_desc.Format = tests[i].texture.format;
4360 texture2d_desc.MiscFlags = 0;
4362 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
4363 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4364 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
4366 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
4367 && (texture2d_desc.ArraySize != 6
4368 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4369 && feature_level < D3D_FEATURE_LEVEL_10_1)
4371 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
4372 continue;
4375 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4376 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4377 texture = (ID3D11Resource *)texture2d;
4379 else
4381 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
4382 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
4383 texture3d_desc.Format = tests[i].texture.format;
4385 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4386 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4387 texture = (ID3D11Resource *)texture3d;
4390 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
4392 current_desc = NULL;
4394 else
4396 current_desc = &srv_desc;
4397 get_srv_desc(current_desc, &tests[i].srv_desc);
4400 expected_refcount = get_refcount(texture);
4401 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
4402 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
4403 refcount = get_refcount(texture);
4404 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
4406 /* Not available on all Windows versions. */
4407 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
4408 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
4410 memset(&srv_desc, 0, sizeof(srv_desc));
4411 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
4412 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
4414 ID3D11ShaderResourceView_Release(srview);
4415 ID3D11Resource_Release(texture);
4418 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
4420 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
4421 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
4423 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
4425 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4426 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
4427 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
4428 texture2d_desc.MiscFlags = 0;
4430 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
4431 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4432 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
4434 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
4435 && feature_level < D3D_FEATURE_LEVEL_10_1)
4437 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
4438 continue;
4441 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4442 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4443 texture = (ID3D11Resource *)texture2d;
4445 else
4447 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4448 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
4449 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
4451 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4452 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4453 texture = (ID3D11Resource *)texture3d;
4456 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
4457 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
4458 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
4460 ID3D11Resource_Release(texture);
4463 refcount = ID3D11Device_Release(device);
4464 ok(!refcount, "Device has %u references left.\n", refcount);
4467 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
4469 #if 0
4470 float4 light;
4471 float4x4 mat;
4473 struct input
4475 float4 position : POSITION;
4476 float3 normal : NORMAL;
4479 struct output
4481 float4 position : POSITION;
4482 float4 diffuse : COLOR;
4485 output main(const input v)
4487 output o;
4489 o.position = mul(v.position, mat);
4490 o.diffuse = dot((float3)light, v.normal);
4492 return o;
4494 #endif
4495 static const DWORD vs_4_1[] =
4497 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
4498 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
4499 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
4500 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
4501 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4502 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
4503 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
4504 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
4505 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
4506 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
4507 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
4508 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
4509 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
4510 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
4511 0x0100003e,
4513 static const DWORD vs_4_0[] =
4515 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
4516 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
4517 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
4518 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
4519 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
4520 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
4521 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
4522 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
4523 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
4524 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
4525 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
4526 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
4527 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
4528 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
4529 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
4530 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
4532 static const DWORD vs_3_0[] =
4534 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
4535 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
4536 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
4537 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
4538 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
4539 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
4540 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
4541 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
4542 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
4543 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
4544 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
4545 0x0000ffff,
4547 static const DWORD vs_2_0[] =
4549 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
4550 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
4551 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
4552 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
4553 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
4554 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
4555 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
4556 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
4557 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
4558 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
4559 0x90e40001, 0x0000ffff,
4562 #if 0
4563 float4 main(const float4 color : COLOR) : SV_TARGET
4565 float4 o;
4567 o = color;
4569 return o;
4571 #endif
4572 static const DWORD ps_4_1[] =
4574 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
4575 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4576 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4577 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4578 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
4579 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4580 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4582 static const DWORD ps_4_0[] =
4584 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
4585 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4586 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4587 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4588 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4589 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4590 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4592 static const DWORD ps_4_0_level_9_0[] =
4594 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
4595 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
4596 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
4597 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
4598 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
4599 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
4600 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
4601 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
4602 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4603 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
4604 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
4605 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4606 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
4607 0xabab0054,
4609 static const DWORD ps_4_0_level_9_1[] =
4611 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
4612 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
4613 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
4614 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
4615 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4616 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4617 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
4618 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4619 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
4620 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
4621 0x45475241, 0xabab0054,
4623 static const DWORD ps_4_0_level_9_3[] =
4625 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
4626 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
4627 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
4628 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
4629 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4630 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4631 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
4632 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4633 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
4634 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
4635 0x45475241, 0xabab0054,
4638 #if 0
4639 struct gs_out
4641 float4 pos : SV_POSITION;
4644 [maxvertexcount(4)]
4645 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
4647 float offset = 0.1 * vin[0].w;
4648 gs_out v;
4650 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
4651 vout.Append(v);
4652 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
4653 vout.Append(v);
4654 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
4655 vout.Append(v);
4656 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
4657 vout.Append(v);
4659 #endif
4660 static const DWORD gs_4_1[] =
4662 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
4663 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4664 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4665 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4666 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
4667 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
4668 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
4669 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
4670 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
4671 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
4672 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
4673 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4674 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
4675 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4676 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
4677 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
4678 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
4679 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4681 static const DWORD gs_4_0[] =
4683 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
4684 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4685 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4686 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4687 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
4688 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
4689 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
4690 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4691 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
4692 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4693 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
4694 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
4695 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
4696 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
4697 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
4698 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4699 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
4700 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4703 ULONG refcount, expected_refcount;
4704 struct device_desc device_desc;
4705 ID3D11Device *device, *tmp;
4706 ID3D11GeometryShader *gs;
4707 ID3D11VertexShader *vs;
4708 ID3D11PixelShader *ps;
4709 HRESULT hr;
4711 device_desc.feature_level = &feature_level;
4712 device_desc.flags = 0;
4713 if (!(device = create_device(&device_desc)))
4715 skip("Failed to create device for feature level %#x.\n", feature_level);
4716 return;
4719 /* level_9 shaders */
4720 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
4721 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4722 ID3D11PixelShader_Release(ps);
4724 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
4725 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4726 ID3D11PixelShader_Release(ps);
4728 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
4729 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4730 ID3D11PixelShader_Release(ps);
4732 /* vertex shader */
4733 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
4734 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4736 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
4737 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4739 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
4740 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
4741 hr, feature_level);
4743 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4744 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
4745 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4746 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4747 else
4748 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4750 refcount = get_refcount(device);
4751 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4752 refcount, expected_refcount);
4753 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4755 tmp = NULL;
4756 expected_refcount = refcount + 1;
4757 ID3D11VertexShader_GetDevice(vs, &tmp);
4758 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4759 refcount = get_refcount(device);
4760 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4761 refcount, expected_refcount);
4762 ID3D11Device_Release(tmp);
4764 /* Not available on all Windows versions. */
4765 check_interface(vs, &IID_ID3D10VertexShader, TRUE, TRUE);
4767 refcount = ID3D11VertexShader_Release(vs);
4768 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
4771 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
4772 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4774 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
4775 hr, feature_level);
4776 refcount = ID3D11VertexShader_Release(vs);
4777 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
4779 else
4781 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4782 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
4783 hr, feature_level);
4784 if (SUCCEEDED(hr))
4785 ID3D11VertexShader_Release(vs);
4788 /* pixel shader */
4789 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4790 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
4791 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4792 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4793 else
4794 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4796 refcount = get_refcount(device);
4797 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4798 refcount, expected_refcount);
4799 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4801 tmp = NULL;
4802 expected_refcount = refcount + 1;
4803 ID3D11PixelShader_GetDevice(ps, &tmp);
4804 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4805 refcount = get_refcount(device);
4806 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4807 refcount, expected_refcount);
4808 ID3D11Device_Release(tmp);
4810 /* Not available on all Windows versions. */
4811 check_interface(ps, &IID_ID3D10PixelShader, TRUE, TRUE);
4813 refcount = ID3D11PixelShader_Release(ps);
4814 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
4817 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
4818 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4820 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
4821 hr, feature_level);
4822 refcount = ID3D11PixelShader_Release(ps);
4823 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
4825 else
4827 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4828 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4829 if (SUCCEEDED(hr))
4830 ID3D11PixelShader_Release(ps);
4833 /* geometry shader */
4834 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4835 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
4836 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4837 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4838 else
4839 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4841 refcount = get_refcount(device);
4842 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4843 refcount, expected_refcount);
4844 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4846 tmp = NULL;
4847 expected_refcount = refcount + 1;
4848 ID3D11GeometryShader_GetDevice(gs, &tmp);
4849 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4850 refcount = get_refcount(device);
4851 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4852 refcount, expected_refcount);
4853 ID3D11Device_Release(tmp);
4855 /* Not available on all Windows versions. */
4856 check_interface(gs, &IID_ID3D10GeometryShader, TRUE, TRUE);
4858 refcount = ID3D11GeometryShader_Release(gs);
4859 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4862 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
4863 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4865 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4866 hr, feature_level);
4867 refcount = ID3D11GeometryShader_Release(gs);
4868 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4870 else
4872 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4873 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4874 hr, feature_level);
4875 if (SUCCEEDED(hr))
4876 ID3D11GeometryShader_Release(gs);
4879 refcount = ID3D11Device_Release(device);
4880 ok(!refcount, "Device has %u references left.\n", refcount);
4883 static void test_create_sampler_state(void)
4885 static const struct test
4887 D3D11_FILTER filter;
4888 D3D10_FILTER expected_filter;
4890 desc_conversion_tests[] =
4892 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
4893 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
4894 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
4895 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
4896 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
4897 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
4898 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
4899 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
4900 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
4901 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
4902 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
4904 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
4905 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
4907 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
4908 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
4910 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
4911 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
4913 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
4914 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
4915 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
4918 ID3D11SamplerState *sampler_state1, *sampler_state2;
4919 ID3D10SamplerState *d3d10_sampler_state;
4920 ULONG refcount, expected_refcount;
4921 ID3D11Device *device, *tmp;
4922 D3D11_SAMPLER_DESC desc;
4923 unsigned int i;
4924 HRESULT hr;
4926 if (!(device = create_device(NULL)))
4928 skip("Failed to create device.\n");
4929 return;
4932 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
4933 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4935 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
4936 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4937 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4938 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
4939 desc.MipLODBias = 0.0f;
4940 desc.MaxAnisotropy = 16;
4941 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4942 desc.BorderColor[0] = 0.0f;
4943 desc.BorderColor[1] = 1.0f;
4944 desc.BorderColor[2] = 0.0f;
4945 desc.BorderColor[3] = 1.0f;
4946 desc.MinLOD = 0.0f;
4947 desc.MaxLOD = 16.0f;
4949 expected_refcount = get_refcount(device) + 1;
4950 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4951 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4952 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4953 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4954 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4955 refcount = get_refcount(device);
4956 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4957 tmp = NULL;
4958 expected_refcount = refcount + 1;
4959 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4960 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4961 refcount = get_refcount(device);
4962 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4963 ID3D11Device_Release(tmp);
4965 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4966 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4967 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4968 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4969 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4970 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4971 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4972 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4973 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4974 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4975 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4976 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4977 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4979 refcount = ID3D11SamplerState_Release(sampler_state2);
4980 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4981 refcount = ID3D11SamplerState_Release(sampler_state1);
4982 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4984 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4986 const struct test *current = &desc_conversion_tests[i];
4987 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4989 desc.Filter = current->filter;
4990 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4991 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4992 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4993 desc.MipLODBias = 0.0f;
4994 desc.MaxAnisotropy = 16;
4995 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4996 desc.BorderColor[0] = 0.0f;
4997 desc.BorderColor[1] = 1.0f;
4998 desc.BorderColor[2] = 0.0f;
4999 desc.BorderColor[3] = 1.0f;
5000 desc.MinLOD = 0.0f;
5001 desc.MaxLOD = 16.0f;
5003 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
5004 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
5006 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
5007 (void **)&d3d10_sampler_state);
5008 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5009 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
5010 if (FAILED(hr))
5012 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
5013 ID3D11SamplerState_Release(sampler_state1);
5014 break;
5017 memcpy(&expected_desc, &desc, sizeof(expected_desc));
5018 expected_desc.Filter = current->expected_filter;
5019 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
5020 expected_desc.MaxAnisotropy = 0;
5021 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
5022 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
5024 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
5025 ok(d3d10_desc.Filter == expected_desc.Filter,
5026 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
5027 ok(d3d10_desc.AddressU == expected_desc.AddressU,
5028 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
5029 ok(d3d10_desc.AddressV == expected_desc.AddressV,
5030 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
5031 ok(d3d10_desc.AddressW == expected_desc.AddressW,
5032 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
5033 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
5034 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
5035 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
5036 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
5037 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
5038 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
5039 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
5040 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
5041 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
5042 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
5043 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
5044 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
5045 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
5046 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
5047 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
5048 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
5049 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
5051 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
5052 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
5053 refcount = ID3D11SamplerState_Release(sampler_state1);
5054 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
5057 refcount = ID3D11Device_Release(device);
5058 ok(!refcount, "Device has %u references left.\n", refcount);
5061 static void test_create_blend_state(void)
5063 static const D3D11_BLEND_DESC desc_conversion_tests[] =
5066 FALSE, FALSE,
5069 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5070 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
5075 FALSE, TRUE,
5078 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5079 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5082 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5083 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
5086 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5087 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5090 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5091 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
5094 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5095 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5098 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5099 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5102 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5103 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5106 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5107 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5112 FALSE, TRUE,
5115 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5116 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5119 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
5120 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5123 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
5124 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5127 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5128 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5131 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
5132 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5135 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
5136 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5139 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5140 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5143 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5144 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5150 ID3D11BlendState *blend_state1, *blend_state2;
5151 D3D11_BLEND_DESC desc, obtained_desc;
5152 ID3D10BlendState *d3d10_blend_state;
5153 D3D10_BLEND_DESC d3d10_blend_desc;
5154 ULONG refcount, expected_refcount;
5155 ID3D11Device *device, *tmp;
5156 unsigned int i, j;
5157 HRESULT hr;
5159 if (!(device = create_device(NULL)))
5161 skip("Failed to create device.\n");
5162 return;
5165 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
5166 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5168 memset(&desc, 0, sizeof(desc));
5169 desc.AlphaToCoverageEnable = FALSE;
5170 desc.IndependentBlendEnable = FALSE;
5171 desc.RenderTarget[0].BlendEnable = FALSE;
5172 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5174 expected_refcount = get_refcount(device) + 1;
5175 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
5176 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5177 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
5178 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5179 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
5180 refcount = get_refcount(device);
5181 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5182 tmp = NULL;
5183 expected_refcount = refcount + 1;
5184 ID3D11BlendState_GetDevice(blend_state1, &tmp);
5185 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5186 refcount = get_refcount(device);
5187 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5188 ID3D11Device_Release(tmp);
5190 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
5191 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
5192 obtained_desc.AlphaToCoverageEnable);
5193 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
5194 obtained_desc.IndependentBlendEnable);
5195 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5197 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
5198 "Got unexpected blend enable %#x for render target %u.\n",
5199 obtained_desc.RenderTarget[i].BlendEnable, i);
5200 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
5201 "Got unexpected src blend %u for render target %u.\n",
5202 obtained_desc.RenderTarget[i].SrcBlend, i);
5203 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
5204 "Got unexpected dest blend %u for render target %u.\n",
5205 obtained_desc.RenderTarget[i].DestBlend, i);
5206 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
5207 "Got unexpected blend op %u for render target %u.\n",
5208 obtained_desc.RenderTarget[i].BlendOp, i);
5209 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
5210 "Got unexpected src blend alpha %u for render target %u.\n",
5211 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
5212 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
5213 "Got unexpected dest blend alpha %u for render target %u.\n",
5214 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
5215 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
5216 "Got unexpected blend op alpha %u for render target %u.\n",
5217 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
5218 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
5219 "Got unexpected render target write mask %#x for render target %u.\n",
5220 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
5223 /* Not available on all Windows versions. */
5224 check_interface(blend_state1, &IID_ID3D10BlendState, TRUE, TRUE);
5225 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
5227 refcount = ID3D11BlendState_Release(blend_state1);
5228 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5229 refcount = ID3D11BlendState_Release(blend_state2);
5230 ok(!refcount, "Blend state has %u references left.\n", refcount);
5232 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
5234 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
5236 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
5237 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5239 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
5240 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5241 "Blend state should implement ID3D10BlendState.\n");
5242 if (FAILED(hr))
5244 win_skip("Blend state does not implement ID3D10BlendState.\n");
5245 ID3D11BlendState_Release(blend_state1);
5246 break;
5249 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
5250 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
5251 "Got unexpected alpha to coverage enable %#x for test %u.\n",
5252 d3d10_blend_desc.AlphaToCoverageEnable, i);
5253 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
5254 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
5255 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
5256 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
5257 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
5258 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
5259 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
5260 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
5261 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
5262 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
5263 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
5264 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
5265 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
5267 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
5268 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
5269 "Got unexpected blend enable %#x for test %u, render target %u.\n",
5270 d3d10_blend_desc.BlendEnable[j], i, j);
5271 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
5272 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
5273 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
5276 ID3D10BlendState_Release(d3d10_blend_state);
5278 refcount = ID3D11BlendState_Release(blend_state1);
5279 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5282 refcount = ID3D11Device_Release(device);
5283 ok(!refcount, "Device has %u references left.\n", refcount);
5286 static void test_create_depthstencil_state(void)
5288 ID3D11DepthStencilState *ds_state1, *ds_state2;
5289 ULONG refcount, expected_refcount;
5290 D3D11_DEPTH_STENCIL_DESC ds_desc;
5291 ID3D11Device *device, *tmp;
5292 HRESULT hr;
5294 if (!(device = create_device(NULL)))
5296 skip("Failed to create device.\n");
5297 return;
5300 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
5301 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5303 ds_desc.DepthEnable = TRUE;
5304 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
5305 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
5306 ds_desc.StencilEnable = FALSE;
5307 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
5308 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
5309 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
5310 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
5311 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
5312 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
5313 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
5314 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
5315 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
5316 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
5318 expected_refcount = get_refcount(device) + 1;
5319 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
5320 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5321 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
5322 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5323 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
5324 refcount = get_refcount(device);
5325 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5326 tmp = NULL;
5327 expected_refcount = refcount + 1;
5328 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
5329 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5330 refcount = get_refcount(device);
5331 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5332 ID3D11Device_Release(tmp);
5334 /* Not available on all Windows versions. */
5335 check_interface(ds_state1, &IID_ID3D10DepthStencilState, TRUE, TRUE);
5337 refcount = ID3D11DepthStencilState_Release(ds_state2);
5338 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5339 refcount = ID3D11DepthStencilState_Release(ds_state1);
5340 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5342 ds_desc.DepthEnable = FALSE;
5343 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
5344 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
5345 ds_desc.StencilEnable = FALSE;
5346 ds_desc.StencilReadMask = 0;
5347 ds_desc.StencilWriteMask = 0;
5348 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
5349 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
5350 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
5351 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
5352 ds_desc.BackFace = ds_desc.FrontFace;
5354 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
5355 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5357 memset(&ds_desc, 0, sizeof(ds_desc));
5358 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
5359 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
5360 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
5361 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
5362 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
5363 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
5364 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
5365 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
5366 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
5367 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
5368 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
5369 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
5370 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
5371 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
5372 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
5373 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
5374 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
5375 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
5376 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
5377 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
5378 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
5379 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
5380 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
5381 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
5382 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
5383 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
5385 ID3D11DepthStencilState_Release(ds_state1);
5387 refcount = ID3D11Device_Release(device);
5388 ok(!refcount, "Device has %u references left.\n", refcount);
5391 static void test_create_rasterizer_state(void)
5393 ID3D11RasterizerState *rast_state1, *rast_state2;
5394 ID3D10RasterizerState *d3d10_rast_state;
5395 ULONG refcount, expected_refcount;
5396 D3D10_RASTERIZER_DESC d3d10_desc;
5397 D3D11_RASTERIZER_DESC desc;
5398 ID3D11Device *device, *tmp;
5399 HRESULT hr;
5401 if (!(device = create_device(NULL)))
5403 skip("Failed to create device.\n");
5404 return;
5407 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
5408 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5410 desc.FillMode = D3D11_FILL_SOLID;
5411 desc.CullMode = D3D11_CULL_BACK;
5412 desc.FrontCounterClockwise = FALSE;
5413 desc.DepthBias = 0;
5414 desc.DepthBiasClamp = 0.0f;
5415 desc.SlopeScaledDepthBias = 0.0f;
5416 desc.DepthClipEnable = TRUE;
5417 desc.ScissorEnable = FALSE;
5418 desc.MultisampleEnable = FALSE;
5419 desc.AntialiasedLineEnable = FALSE;
5421 expected_refcount = get_refcount(device) + 1;
5422 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
5423 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5424 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
5425 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5426 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
5427 refcount = get_refcount(device);
5428 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5429 tmp = NULL;
5430 expected_refcount = refcount + 1;
5431 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
5432 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5433 refcount = get_refcount(device);
5434 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5435 ID3D11Device_Release(tmp);
5437 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
5438 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5439 "Rasterizer state should implement ID3D10RasterizerState.\n");
5440 if (SUCCEEDED(hr))
5442 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
5443 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
5444 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
5445 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
5446 d3d10_desc.FrontCounterClockwise);
5447 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
5448 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
5449 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
5450 d3d10_desc.SlopeScaledDepthBias);
5451 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
5452 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
5453 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
5454 d3d10_desc.MultisampleEnable);
5455 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
5456 d3d10_desc.AntialiasedLineEnable);
5458 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
5459 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5462 refcount = ID3D11RasterizerState_Release(rast_state2);
5463 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5464 refcount = ID3D11RasterizerState_Release(rast_state1);
5465 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5467 refcount = ID3D11Device_Release(device);
5468 ok(!refcount, "Device has %u references left.\n", refcount);
5471 static void test_create_query(void)
5473 static const struct
5475 D3D11_QUERY query;
5476 D3D_FEATURE_LEVEL required_feature_level;
5477 BOOL is_predicate;
5478 BOOL can_use_create_predicate;
5479 BOOL todo;
5481 tests[] =
5483 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5484 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5485 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5486 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5487 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5488 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
5489 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5490 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
5491 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5492 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5493 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5494 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5495 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5496 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5497 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5498 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5501 ULONG refcount, expected_refcount;
5502 D3D_FEATURE_LEVEL feature_level;
5503 D3D11_QUERY_DESC query_desc;
5504 ID3D11Predicate *predicate;
5505 ID3D11Device *device, *tmp;
5506 HRESULT hr, expected_hr;
5507 ID3D11Query *query;
5508 unsigned int i;
5510 if (!(device = create_device(NULL)))
5512 skip("Failed to create device.\n");
5513 return;
5515 feature_level = ID3D11Device_GetFeatureLevel(device);
5517 hr = ID3D11Device_CreateQuery(device, NULL, &query);
5518 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5519 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
5520 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5522 for (i = 0; i < ARRAY_SIZE(tests); ++i)
5524 if (tests[i].required_feature_level > feature_level)
5526 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
5527 continue;
5530 query_desc.Query = tests[i].query;
5531 query_desc.MiscFlags = 0;
5533 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
5534 todo_wine_if(tests[i].todo)
5535 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5537 query_desc.Query = tests[i].query;
5538 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
5539 todo_wine_if(tests[i].todo)
5540 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5541 if (FAILED(hr))
5542 continue;
5544 check_interface(query, &IID_ID3D11Predicate, tests[i].is_predicate, FALSE);
5545 ID3D11Query_Release(query);
5547 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
5548 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
5549 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5551 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
5552 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
5553 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5554 if (SUCCEEDED(hr))
5555 ID3D11Predicate_Release(predicate);
5558 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
5559 expected_refcount = get_refcount(device) + 1;
5560 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
5561 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5562 refcount = get_refcount(device);
5563 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5564 tmp = NULL;
5565 expected_refcount = refcount + 1;
5566 ID3D11Predicate_GetDevice(predicate, &tmp);
5567 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5568 refcount = get_refcount(device);
5569 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5570 ID3D11Device_Release(tmp);
5571 /* Not available on all Windows versions. */
5572 check_interface(predicate, &IID_ID3D10Predicate, TRUE, TRUE);
5573 ID3D11Predicate_Release(predicate);
5575 refcount = ID3D11Device_Release(device);
5576 ok(!refcount, "Device has %u references left.\n", refcount);
5579 #define get_query_data(a, b, c, d) get_query_data_(__LINE__, a, b, c, d)
5580 static void get_query_data_(unsigned int line, ID3D11DeviceContext *context,
5581 ID3D11Asynchronous *query, void *data, unsigned int data_size)
5583 unsigned int i;
5584 HRESULT hr;
5586 for (i = 0; i < 500; ++i)
5588 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
5589 break;
5590 Sleep(10);
5592 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5593 memset(data, 0xff, data_size);
5594 hr = ID3D11DeviceContext_GetData(context, query, data, data_size, 0);
5595 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5598 static void test_occlusion_query(void)
5600 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5601 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5603 struct d3d11_test_context test_context;
5604 D3D11_TEXTURE2D_DESC texture_desc;
5605 ID3D11DeviceContext *context;
5606 ID3D11RenderTargetView *rtv;
5607 D3D11_QUERY_DESC query_desc;
5608 ID3D11Asynchronous *query;
5609 unsigned int data_size, i;
5610 ID3D11Texture2D *texture;
5611 ID3D11Device *device;
5612 union
5614 UINT64 uint;
5615 DWORD dword[2];
5616 } data;
5617 HRESULT hr;
5619 if (!init_test_context(&test_context, NULL))
5620 return;
5622 device = test_context.device;
5623 context = test_context.immediate_context;
5625 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5627 query_desc.Query = D3D11_QUERY_OCCLUSION;
5628 query_desc.MiscFlags = 0;
5629 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5630 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5631 data_size = ID3D11Asynchronous_GetDataSize(query);
5632 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
5634 memset(&data, 0xff, sizeof(data));
5635 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5636 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5637 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5638 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5639 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5640 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5642 ID3D11DeviceContext_End(context, query);
5643 ID3D11DeviceContext_Begin(context, query);
5644 ID3D11DeviceContext_Begin(context, query);
5646 memset(&data, 0xff, sizeof(data));
5647 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5648 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5649 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5650 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5651 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5652 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5654 draw_color_quad(&test_context, &red);
5656 ID3D11DeviceContext_End(context, query);
5657 get_query_data(context, query, &data, sizeof(data));
5658 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5660 memset(&data, 0xff, sizeof(data));
5661 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
5662 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5663 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
5664 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5665 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
5666 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5667 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
5668 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5669 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5670 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5672 memset(&data, 0xff, sizeof(data));
5673 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
5674 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5675 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5676 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5678 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
5679 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5680 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
5681 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5683 ID3D11DeviceContext_Begin(context, query);
5684 ID3D11DeviceContext_End(context, query);
5685 ID3D11DeviceContext_End(context, query);
5687 get_query_data(context, query, &data, sizeof(data));
5688 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5689 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5690 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5692 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
5693 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
5694 texture_desc.MipLevels = 1;
5695 texture_desc.ArraySize = 1;
5696 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
5697 texture_desc.SampleDesc.Count = 1;
5698 texture_desc.SampleDesc.Quality = 0;
5699 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5700 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5701 texture_desc.CPUAccessFlags = 0;
5702 texture_desc.MiscFlags = 0;
5703 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5704 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5705 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5706 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5708 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
5709 set_viewport(context, 0.0f, 0.0f, texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
5711 ID3D11DeviceContext_Begin(context, query);
5712 for (i = 0; i < 100; i++)
5713 draw_color_quad(&test_context, &red);
5714 ID3D11DeviceContext_End(context, query);
5716 get_query_data(context, query, &data, sizeof(data));
5717 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
5718 || (data.dword[0] == 0xffffffff && !data.dword[1])
5719 || broken(!data.uint),
5720 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5721 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5722 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5724 ID3D11Asynchronous_Release(query);
5726 /* The following test exercises a code path in wined3d. A wined3d context
5727 * associated with the query is destroyed when the swapchain is released. */
5728 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5729 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5731 set_viewport(context, 0.0f, 0.0f, 64.0f, 64.0f, 0.0f, 1.0f);
5732 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5733 ID3D11DeviceContext_Begin(context, query);
5734 draw_color_quad(&test_context, &red);
5735 ID3D11DeviceContext_End(context, query);
5737 ID3D11RenderTargetView_Release(test_context.backbuffer_rtv);
5738 ID3D11Texture2D_Release(test_context.backbuffer);
5739 IDXGISwapChain_Release(test_context.swapchain);
5740 test_context.swapchain = create_swapchain(device, test_context.window, NULL);
5741 hr = IDXGISwapChain_GetBuffer(test_context.swapchain, 0, &IID_ID3D11Texture2D,
5742 (void **)&test_context.backbuffer);
5743 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
5744 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer,
5745 NULL, &test_context.backbuffer_rtv);
5746 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5747 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
5748 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5750 get_query_data(context, query, &data, sizeof(data));
5751 /* This test occasionally succeeds with CSMT enabled because of a race condition. */
5752 if (0)
5753 todo_wine ok(data.dword[0] == 0x1000 && !data.dword[1],
5754 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5756 ID3D11Asynchronous_Release(query);
5757 ID3D11RenderTargetView_Release(rtv);
5758 ID3D11Texture2D_Release(texture);
5759 release_test_context(&test_context);
5762 static void test_pipeline_statistics_query(void)
5764 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5765 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5767 D3D11_QUERY_DATA_PIPELINE_STATISTICS data;
5768 struct d3d11_test_context test_context;
5769 ID3D11DeviceContext *context;
5770 D3D11_QUERY_DESC query_desc;
5771 ID3D11Asynchronous *query;
5772 unsigned int data_size;
5773 ID3D11Device *device;
5774 HRESULT hr;
5776 if (!init_test_context(&test_context, NULL))
5777 return;
5779 device = test_context.device;
5780 context = test_context.immediate_context;
5782 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5784 query_desc.Query = D3D11_QUERY_PIPELINE_STATISTICS;
5785 query_desc.MiscFlags = 0;
5786 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5787 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5788 data_size = ID3D11Asynchronous_GetDataSize(query);
5789 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
5791 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5792 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5793 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5794 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5796 ID3D11DeviceContext_End(context, query);
5797 ID3D11DeviceContext_Begin(context, query);
5798 ID3D11DeviceContext_Begin(context, query);
5800 memset(&data, 0xff, sizeof(data));
5801 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5802 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5803 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5804 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5805 ok(data.IAVertices == ~(UINT64)0, "Data was modified.\n");
5807 draw_quad(&test_context);
5809 ID3D11DeviceContext_End(context, query);
5810 get_query_data(context, query, &data, sizeof(data));
5811 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5812 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5813 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5814 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5815 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5816 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5817 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5818 todo_wine
5819 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5820 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5821 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5822 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5824 ID3D11DeviceContext_Begin(context, query);
5825 draw_color_quad(&test_context, &red);
5826 ID3D11DeviceContext_End(context, query);
5827 get_query_data(context, query, &data, sizeof(data));
5828 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5829 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5830 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5831 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5832 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5833 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5834 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5835 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5836 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5837 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5838 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5840 ID3D11Asynchronous_Release(query);
5841 release_test_context(&test_context);
5844 static void test_timestamp_query(void)
5846 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5848 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
5849 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
5850 struct d3d11_test_context test_context;
5851 ID3D11DeviceContext *context;
5852 D3D11_QUERY_DESC query_desc;
5853 unsigned int data_size;
5854 ID3D11Device *device;
5855 UINT64 timestamp;
5856 HRESULT hr;
5858 if (!init_test_context(&test_context, NULL))
5859 return;
5861 device = test_context.device;
5862 context = test_context.immediate_context;
5864 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5865 query_desc.MiscFlags = 0;
5866 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5867 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5868 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
5869 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
5871 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
5872 query_desc.MiscFlags = 0;
5873 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
5874 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5875 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
5876 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
5878 disjoint.Frequency = 0xdeadbeef;
5879 disjoint.Disjoint = 0xdeadbeef;
5880 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5881 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5882 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5883 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5884 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5885 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5887 /* Test a TIMESTAMP_DISJOINT query. */
5888 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5890 disjoint.Frequency = 0xdeadbeef;
5891 disjoint.Disjoint = 0xdeadbeef;
5892 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5893 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5894 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5895 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5896 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5897 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5899 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5900 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5901 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
5902 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5904 prev_disjoint = disjoint;
5906 disjoint.Frequency = 0xdeadbeef;
5907 disjoint.Disjoint = 0xff;
5908 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
5909 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5910 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
5911 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5912 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
5913 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5914 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
5915 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5916 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5917 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
5919 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5920 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5921 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
5922 D3D11_ASYNC_GETDATA_DONOTFLUSH);
5923 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5924 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
5925 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
5927 memset(&timestamp, 0xff, sizeof(timestamp));
5928 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
5929 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5930 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5931 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5932 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5934 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
5935 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5937 memset(&timestamp, 0xff, sizeof(timestamp));
5938 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5939 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5940 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5942 draw_color_quad(&test_context, &red);
5944 ID3D11DeviceContext_End(context, timestamp_query);
5945 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5947 timestamp = 0xdeadbeef;
5948 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5949 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5950 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5952 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5953 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5954 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
5956 timestamp = 0xdeadbeef;
5957 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
5958 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5959 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
5960 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5961 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5962 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5963 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
5964 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5965 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5967 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5968 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5969 disjoint.Frequency = 0xdeadbeef;
5970 disjoint.Disjoint = 0xff;
5971 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5972 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5973 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
5974 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5976 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
5977 ID3D11Asynchronous_Release(timestamp_query);
5978 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5979 query_desc.MiscFlags = 0;
5980 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5981 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5983 draw_color_quad(&test_context, &red);
5985 ID3D11DeviceContext_End(context, timestamp_query);
5986 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5988 ID3D11Asynchronous_Release(timestamp_query);
5989 ID3D11Asynchronous_Release(timestamp_disjoint_query);
5990 release_test_context(&test_context);
5993 static void test_so_statistics_query(void)
5995 struct d3d11_test_context test_context;
5996 D3D11_QUERY_DATA_SO_STATISTICS data;
5997 ID3D11DeviceContext *context;
5998 unsigned int vertex_count[4];
5999 D3D11_QUERY_DESC query_desc;
6000 ID3D11Buffer *so_buffer[4];
6001 ID3D11Asynchronous *query;
6002 ID3D11GeometryShader *gs;
6003 ID3D11VertexShader *vs;
6004 unsigned int data_size;
6005 ID3D11Device *device;
6006 ID3D11Buffer *cb;
6007 unsigned int i;
6008 HRESULT hr;
6010 static const DWORD vs_code[] =
6012 #if 0
6013 float4 main(uint id : SV_VertexID) : custom
6015 return (float4)id;
6017 #endif
6018 0x43425844, 0x8b0e47b9, 0x6efc9512, 0xd55ca6ff, 0x487c5ef2, 0x00000001, 0x000000d4, 0x00000003,
6019 0x0000002c, 0x00000060, 0x00000090, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6020 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
6021 0x4e47534f, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6022 0x00000000, 0x0000000f, 0x74737563, 0xab006d6f, 0x52444853, 0x0000003c, 0x00010040, 0x0000000f,
6023 0x04000060, 0x00101012, 0x00000000, 0x00000006, 0x03000065, 0x001020f2, 0x00000000, 0x05000056,
6024 0x001020f2, 0x00000000, 0x00101006, 0x00000000, 0x0100003e,
6026 static const DWORD gs_code[] =
6028 #if 0
6029 struct vertex
6031 float4 data : custom;
6034 uint4 vertex_count;
6036 [maxvertexcount(32)]
6037 void main(point vertex input[1], uint id : SV_PrimitiveID,
6038 inout PointStream<vertex> output0,
6039 inout PointStream<vertex> output1,
6040 inout PointStream<vertex> output2,
6041 inout PointStream<vertex> output3)
6043 if (id < vertex_count.x)
6044 output0.Append(input[0]);
6045 if (id < vertex_count.y)
6046 output1.Append(input[0]);
6047 if (id < vertex_count.z)
6048 output2.Append(input[0]);
6049 if (id < vertex_count.w)
6050 output3.Append(input[0]);
6052 #endif
6053 0x43425844, 0xd616829d, 0x4355ce2a, 0xd71909e5, 0xdc916d4c, 0x00000001, 0x000002bc, 0x00000003,
6054 0x0000002c, 0x00000084, 0x0000010c, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
6055 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000003f, 0x00000000, 0x00000007,
6056 0x00000001, 0xffffffff, 0x00000101, 0x74737563, 0x53006d6f, 0x72505f56, 0x74696d69, 0x49657669,
6057 0xabab0044, 0x3547534f, 0x00000080, 0x00000004, 0x00000008, 0x00000000, 0x00000078, 0x00000000,
6058 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000001, 0x00000078, 0x00000000, 0x00000000,
6059 0x00000003, 0x00000000, 0x0000000f, 0x00000002, 0x00000078, 0x00000000, 0x00000000, 0x00000003,
6060 0x00000000, 0x0000000f, 0x00000003, 0x00000078, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
6061 0x0000000f, 0x74737563, 0xab006d6f, 0x58454853, 0x000001a8, 0x00020050, 0x0000006a, 0x0100086a,
6062 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000,
6063 0x0200005f, 0x0000b000, 0x02000068, 0x00000001, 0x0100085d, 0x0300008f, 0x00110000, 0x00000000,
6064 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000001, 0x0100085c,
6065 0x03000065, 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000002, 0x0100085c, 0x03000065,
6066 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000003, 0x0100085c, 0x03000065, 0x001020f2,
6067 0x00000000, 0x0200005e, 0x00000020, 0x0700004f, 0x001000f2, 0x00000000, 0x0000b001, 0x00208e46,
6068 0x00000000, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000,
6069 0x00201e46, 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x01000015, 0x0304001f,
6070 0x0010001a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000, 0x00000000,
6071 0x03000075, 0x00110000, 0x00000001, 0x01000015, 0x0304001f, 0x0010002a, 0x00000000, 0x06000036,
6072 0x001020f2, 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000002,
6073 0x01000015, 0x0304001f, 0x0010003a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
6074 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000003, 0x01000015, 0x0100003e,
6076 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
6078 {0, "custom", 0, 0, 4, 0},
6079 {1, "custom", 0, 0, 4, 1},
6080 {2, "custom", 0, 0, 4, 2},
6081 {3, "custom", 0, 0, 4, 3},
6083 static const unsigned int offset[4] = {0};
6085 static const struct
6087 D3D11_QUERY query;
6088 D3D_FEATURE_LEVEL feature_level;
6090 tests[] =
6092 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0},
6093 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0},
6094 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0},
6095 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0},
6096 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0},
6099 if (!init_test_context(&test_context, NULL))
6100 return;
6102 device = test_context.device;
6103 context = test_context.immediate_context;
6105 for (i = 0; i < ARRAY_SIZE(tests); ++i)
6107 if (ID3D11Device_GetFeatureLevel(device) < tests[i].feature_level)
6109 skip("Feature level %#x is required.\n", tests[i].feature_level);
6110 continue;
6113 query_desc.Query = tests[i].query;
6114 query_desc.MiscFlags = 0;
6115 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
6116 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6117 data_size = ID3D11Asynchronous_GetDataSize(query);
6118 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
6120 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
6121 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6122 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
6123 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6125 ID3D11DeviceContext_End(context, query);
6126 ID3D11DeviceContext_Begin(context, query);
6127 ID3D11DeviceContext_Begin(context, query);
6129 memset(&data, 0xff, sizeof(data));
6130 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
6131 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6132 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
6133 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6134 ok(data.NumPrimitivesWritten == ~(UINT64)0, "Data was modified.\n");
6135 ok(data.PrimitivesStorageNeeded == ~(UINT64)0, "Data was modified.\n");
6137 draw_quad(&test_context);
6139 ID3D11DeviceContext_End(context, query);
6140 get_query_data(context, query, &data, sizeof(data));
6141 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
6142 (unsigned int)data.NumPrimitivesWritten);
6143 todo_wine_if(query_desc.Query == D3D11_QUERY_SO_STATISTICS || query_desc.Query == D3D11_QUERY_SO_STATISTICS_STREAM0)
6144 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
6145 (unsigned int)data.PrimitivesStorageNeeded);
6147 ID3D11DeviceContext_Begin(context, query);
6148 draw_quad(&test_context);
6149 ID3D11DeviceContext_End(context, query);
6150 get_query_data(context, query, &data, sizeof(data));
6151 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
6152 (unsigned int)data.NumPrimitivesWritten);
6153 todo_wine_if(query_desc.Query == D3D11_QUERY_SO_STATISTICS || query_desc.Query == D3D11_QUERY_SO_STATISTICS_STREAM0)
6154 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
6155 (unsigned int)data.PrimitivesStorageNeeded);
6157 ID3D11Asynchronous_Release(query);
6160 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
6162 skip("Vertex streams are not supported.\n");
6163 goto done;
6166 /* multiple vertex streams */
6167 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
6168 ok(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
6169 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
6171 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
6172 so_declaration, ARRAY_SIZE(so_declaration),
6173 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
6174 todo_wine
6175 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
6176 if (FAILED(hr))
6178 ID3D11VertexShader_Release(vs);
6179 goto done;
6181 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
6183 for (i = 0; i < ARRAY_SIZE(vertex_count); ++i)
6184 vertex_count[i] = 5;
6185 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(vertex_count), vertex_count);
6186 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
6188 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
6190 query_desc.Query = D3D11_QUERY_SO_STATISTICS;
6191 query_desc.MiscFlags = 0;
6192 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
6193 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6195 ID3D11DeviceContext_Begin(context, query);
6196 ID3D11DeviceContext_Draw(context, 5, 0);
6197 ID3D11DeviceContext_End(context, query);
6199 memset(&data, 0xff, sizeof(data));
6200 get_query_data(context, query, &data, sizeof(data));
6201 ok(!data.NumPrimitivesWritten, "Got unexpected primitives written %u.\n",
6202 (unsigned int)data.NumPrimitivesWritten);
6203 ok(data.PrimitivesStorageNeeded == 5, "Got unexpected primitives storage needed %u.\n",
6204 (unsigned int)data.PrimitivesStorageNeeded);
6206 for (i = 0; i < ARRAY_SIZE(so_buffer); ++i)
6207 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(struct vec4) * 10, NULL);
6209 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6210 ID3D11DeviceContext_Begin(context, query);
6211 ID3D11DeviceContext_Draw(context, 16, 0);
6212 ID3D11DeviceContext_End(context, query);
6213 memset(&data, 0xff, sizeof(data));
6214 get_query_data(context, query, &data, sizeof(data));
6215 ok(data.NumPrimitivesWritten == 5, "Got unexpected primitives written %u.\n",
6216 (unsigned int)data.NumPrimitivesWritten);
6217 ok(data.PrimitivesStorageNeeded == 5, "Got unexpected primitives storage needed %u.\n",
6218 (unsigned int)data.PrimitivesStorageNeeded);
6220 vertex_count[0] = 3;
6221 vertex_count[1] = 6;
6222 vertex_count[2] = 4;
6223 vertex_count[3] = 12;
6224 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, vertex_count, 0, 0);
6226 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6227 ID3D11DeviceContext_Begin(context, query);
6228 ID3D11DeviceContext_Draw(context, 32, 0);
6229 ID3D11DeviceContext_End(context, query);
6230 memset(&data, 0xff, sizeof(data));
6231 get_query_data(context, query, &data, sizeof(data));
6232 ok(data.NumPrimitivesWritten == 3, "Got unexpected primitives written %u.\n",
6233 (unsigned int)data.NumPrimitivesWritten);
6234 ok(data.PrimitivesStorageNeeded == 3, "Got unexpected primitives storage needed %u.\n",
6235 (unsigned int)data.PrimitivesStorageNeeded);
6237 vertex_count[0] = 16;
6238 vertex_count[1] = 6;
6239 vertex_count[2] = 4;
6240 vertex_count[3] = 12;
6241 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, vertex_count, 0, 0);
6243 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6244 ID3D11DeviceContext_Begin(context, query);
6245 ID3D11DeviceContext_Draw(context, 32, 0);
6246 ID3D11DeviceContext_End(context, query);
6247 memset(&data, 0xff, sizeof(data));
6248 get_query_data(context, query, &data, sizeof(data));
6249 ok(data.NumPrimitivesWritten == 10, "Got unexpected primitives written %u.\n",
6250 (unsigned int)data.NumPrimitivesWritten);
6251 ok(data.PrimitivesStorageNeeded == 16, "Got unexpected primitives storage needed %u.\n",
6252 (unsigned int)data.PrimitivesStorageNeeded);
6254 ID3D11Asynchronous_Release(query);
6256 for (i = 0; i < ARRAY_SIZE(so_buffer); ++i)
6257 ID3D11Buffer_Release(so_buffer[i]);
6258 ID3D11Buffer_Release(cb);
6259 ID3D11GeometryShader_Release(gs);
6260 ID3D11VertexShader_Release(vs);
6262 done:
6263 release_test_context(&test_context);
6266 static void test_device_removed_reason(void)
6268 ID3D11Device *device;
6269 ULONG refcount;
6270 HRESULT hr;
6272 if (!(device = create_device(NULL)))
6274 skip("Failed to create device.\n");
6275 return;
6278 hr = ID3D11Device_GetDeviceRemovedReason(device);
6279 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6280 hr = ID3D11Device_GetDeviceRemovedReason(device);
6281 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6283 refcount = ID3D11Device_Release(device);
6284 ok(!refcount, "Device has %u references left.\n", refcount);
6287 static void test_private_data(void)
6289 ULONG refcount, expected_refcount;
6290 D3D11_TEXTURE2D_DESC texture_desc;
6291 ID3D10Texture2D *d3d10_texture;
6292 ID3D11Device *test_object;
6293 ID3D11Texture2D *texture;
6294 IDXGIDevice *dxgi_device;
6295 IDXGISurface *surface;
6296 ID3D11Device *device;
6297 IUnknown *ptr;
6298 HRESULT hr;
6299 UINT size;
6301 static const GUID test_guid =
6302 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
6303 static const GUID test_guid2 =
6304 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
6305 static const DWORD data[] = {1, 2, 3, 4};
6307 if (!(device = create_device(NULL)))
6309 skip("Failed to create device.\n");
6310 return;
6313 test_object = create_device(NULL);
6315 texture_desc.Width = 512;
6316 texture_desc.Height = 512;
6317 texture_desc.MipLevels = 1;
6318 texture_desc.ArraySize = 1;
6319 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6320 texture_desc.SampleDesc.Count = 1;
6321 texture_desc.SampleDesc.Quality = 0;
6322 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6323 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6324 texture_desc.CPUAccessFlags = 0;
6325 texture_desc.MiscFlags = 0;
6327 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6328 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6329 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
6330 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
6332 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
6333 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6334 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6335 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6336 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6337 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6338 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6339 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6341 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6342 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6343 size = sizeof(ptr) * 2;
6344 ptr = (IUnknown *)0xdeadbeef;
6345 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6346 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6347 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6348 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6350 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
6351 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
6352 size = sizeof(ptr) * 2;
6353 ptr = (IUnknown *)0xdeadbeef;
6354 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
6355 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6356 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6357 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6358 IDXGIDevice_Release(dxgi_device);
6360 refcount = get_refcount(test_object);
6361 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6362 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6363 expected_refcount = refcount + 1;
6364 refcount = get_refcount(test_object);
6365 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6366 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6367 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6368 refcount = get_refcount(test_object);
6369 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6371 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6372 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6373 --expected_refcount;
6374 refcount = get_refcount(test_object);
6375 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6377 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6378 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6379 size = sizeof(data);
6380 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
6381 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6382 refcount = get_refcount(test_object);
6383 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6384 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
6385 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6386 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
6387 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6389 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6390 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6391 ++expected_refcount;
6392 size = 2 * sizeof(ptr);
6393 ptr = NULL;
6394 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6395 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6396 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
6397 ++expected_refcount;
6398 refcount = get_refcount(test_object);
6399 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6400 IUnknown_Release(ptr);
6401 --expected_refcount;
6403 ptr = (IUnknown *)0xdeadbeef;
6404 size = 1;
6405 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
6406 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6407 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6408 size = 2 * sizeof(ptr);
6409 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
6410 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6411 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6412 refcount = get_refcount(test_object);
6413 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6415 size = 1;
6416 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6417 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
6418 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6419 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6420 if (!enable_debug_layer)
6422 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
6423 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6424 size = 0xdeadbabe;
6425 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
6426 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
6427 ok(size == 0, "Got unexpected size %u.\n", size);
6428 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6429 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
6430 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6431 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6434 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
6435 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6436 ptr = NULL;
6437 size = sizeof(ptr);
6438 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
6439 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6440 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6441 IUnknown_Release(ptr);
6443 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
6444 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
6445 "Texture should implement ID3D10Texture2D.\n");
6446 if (SUCCEEDED(hr))
6448 ptr = NULL;
6449 size = sizeof(ptr);
6450 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
6451 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6452 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6453 IUnknown_Release(ptr);
6454 ID3D10Texture2D_Release(d3d10_texture);
6457 IDXGISurface_Release(surface);
6458 ID3D11Texture2D_Release(texture);
6459 refcount = ID3D11Device_Release(device);
6460 ok(!refcount, "Device has %u references left.\n", refcount);
6461 refcount = ID3D11Device_Release(test_object);
6462 ok(!refcount, "Test object has %u references left.\n", refcount);
6465 static void test_state_refcounting(const D3D_FEATURE_LEVEL feature_level)
6467 ID3D11RasterizerState *rasterizer_state, *tmp_rasterizer_state;
6468 ID3D11Predicate *predicate, *tmp_predicate;
6469 ID3D11SamplerState *sampler, *tmp_sampler;
6470 ID3D11ShaderResourceView *srv, *tmp_srv;
6471 ID3D11RenderTargetView *rtv, *tmp_rtv;
6472 D3D11_RASTERIZER_DESC rasterizer_desc;
6473 D3D11_TEXTURE2D_DESC texture_desc;
6474 D3D11_QUERY_DESC predicate_desc;
6475 D3D11_SAMPLER_DESC sampler_desc;
6476 struct device_desc device_desc;
6477 ID3D11DeviceContext *context;
6478 ID3D11Texture2D *texture;
6479 ID3D11Device *device;
6480 ULONG refcount;
6481 HRESULT hr;
6483 device_desc.feature_level = &feature_level;
6484 device_desc.flags = 0;
6485 if (!(device = create_device(&device_desc)))
6487 skip("Failed to create device for feature level %#x.\n", feature_level);
6488 return;
6491 ID3D11Device_GetImmediateContext(device, &context);
6493 /* ID3D11SamplerState */
6494 memset(&sampler_desc, 0, sizeof(sampler_desc));
6495 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
6496 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
6497 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
6498 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
6499 sampler_desc.MaxLOD = FLT_MAX;
6500 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6501 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6503 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
6504 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6505 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6506 ID3D11SamplerState_Release(tmp_sampler);
6508 tmp_sampler = sampler;
6509 refcount = get_refcount(sampler);
6510 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
6511 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6512 refcount = ID3D11SamplerState_Release(sampler);
6513 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6514 sampler = NULL;
6515 ID3D11DeviceContext_PSGetSamplers(context, 0, 1, &sampler);
6516 ok(sampler == tmp_sampler, "Got sampler %p, expected %p.\n", sampler, tmp_sampler);
6517 refcount = ID3D11SamplerState_Release(sampler);
6518 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6520 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
6521 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6522 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6523 refcount = ID3D11SamplerState_Release(tmp_sampler);
6524 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6526 /* ID3D11RasterizerState */
6527 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
6528 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
6529 rasterizer_desc.CullMode = D3D11_CULL_BACK;
6530 rasterizer_desc.DepthClipEnable = TRUE;
6531 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
6532 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
6534 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
6535 refcount = ID3D11RasterizerState_Release(rasterizer_state);
6536 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6537 ID3D11DeviceContext_RSGetState(context, &tmp_rasterizer_state);
6538 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
6539 tmp_rasterizer_state, rasterizer_state);
6540 refcount = ID3D11RasterizerState_Release(tmp_rasterizer_state);
6541 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6543 /* ID3D11ShaderResourceView */
6544 memset(&texture_desc, 0, sizeof(texture_desc));
6545 texture_desc.Width = 32;
6546 texture_desc.Height = 32;
6547 texture_desc.MipLevels = 1;
6548 texture_desc.ArraySize = 1;
6549 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6550 texture_desc.SampleDesc.Count = 1;
6551 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6552 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6553 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6554 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6555 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6556 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
6557 ID3D11Texture2D_Release(texture);
6559 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6560 refcount = ID3D11ShaderResourceView_Release(srv);
6561 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6562 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &tmp_srv);
6563 ok(tmp_srv == srv, "Got SRV %p, expected %p.\n", tmp_srv, srv);
6564 refcount = ID3D11ShaderResourceView_Release(tmp_srv);
6565 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6567 /* ID3D11RenderTargetView */
6568 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6569 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6570 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6571 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
6572 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
6573 ID3D11Texture2D_Release(texture);
6575 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6576 refcount = ID3D11RenderTargetView_Release(rtv);
6577 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6578 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &tmp_rtv, NULL);
6579 ok(tmp_rtv == rtv, "Got RTV %p, expected %p.\n", tmp_rtv, rtv);
6580 refcount = ID3D11RenderTargetView_Release(tmp_rtv);
6581 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6583 /* ID3D11Predicate */
6584 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
6586 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
6587 predicate_desc.MiscFlags = 0;
6588 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
6589 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
6591 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
6592 refcount = ID3D11Predicate_Release(predicate);
6593 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6594 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, NULL);
6595 ok(tmp_predicate == predicate, "Got predicate %p, expected %p.\n", tmp_predicate, predicate);
6596 refcount = ID3D11Predicate_Release(tmp_predicate);
6597 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6600 ID3D11DeviceContext_Release(context);
6601 refcount = ID3D11Device_Release(device);
6602 ok(!refcount, "Device has %u references left.\n", refcount);
6605 static void test_device_context_state(void)
6607 static const GUID test_guid =
6608 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
6609 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
6611 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
6613 static const float custom_blend_factor[] = {0.1f, 0.2f, 0.3f, 0.4f};
6614 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
6615 #if 0
6616 float4 main(float4 pos : POSITION) : POSITION
6618 return pos;
6620 #endif
6621 static const DWORD simple_vs[] =
6623 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
6624 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6625 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6626 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6627 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
6628 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
6629 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6631 #if 0
6632 struct data
6634 float4 position : SV_Position;
6637 struct patch_constant_data
6639 float edges[3] : SV_TessFactor;
6640 float inside : SV_InsideTessFactor;
6643 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
6645 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
6646 output.inside = 1.0f;
6649 [domain("tri")]
6650 [outputcontrolpoints(3)]
6651 [partitioning("integer")]
6652 [outputtopology("triangle_ccw")]
6653 [patchconstantfunc("patch_constant")]
6654 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
6656 return input[i];
6659 [domain("tri")]
6660 void ds_main(patch_constant_data input,
6661 float3 tess_coord : SV_DomainLocation,
6662 const OutputPatch<data, 3> patch,
6663 out data output)
6665 output.position = tess_coord.x * patch[0].position
6666 + tess_coord.y * patch[1].position
6667 + tess_coord.z * patch[2].position;
6669 #endif
6670 static const DWORD simple_hs[] =
6672 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
6673 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
6674 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
6675 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
6676 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
6677 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
6678 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
6679 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
6680 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
6681 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
6682 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
6683 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
6684 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
6685 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
6686 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
6687 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
6688 0x00004001, 0x3f800000, 0x0100003e,
6690 static const DWORD simple_ds[] =
6692 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
6693 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
6694 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
6695 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
6696 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
6697 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
6698 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
6699 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
6700 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
6701 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
6702 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
6703 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
6704 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
6705 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
6706 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
6708 #if 0
6709 struct gs_out
6711 float4 pos : SV_POSITION;
6714 [maxvertexcount(4)]
6715 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
6717 float offset = 0.1 * vin[0].w;
6718 gs_out v;
6720 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
6721 vout.Append(v);
6722 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
6723 vout.Append(v);
6724 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
6725 vout.Append(v);
6726 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
6727 vout.Append(v);
6729 #endif
6730 static const DWORD simple_gs[] =
6732 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
6733 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6734 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6735 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
6736 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
6737 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
6738 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
6739 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
6740 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
6741 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
6742 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
6743 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
6744 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
6745 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
6746 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
6747 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
6748 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
6749 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
6751 #if 0
6752 float4 main(float4 color : COLOR) : SV_TARGET
6754 return color;
6756 #endif
6757 static const DWORD simple_ps[] =
6759 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
6760 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
6761 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
6762 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
6763 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
6764 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
6765 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6767 #if 0
6768 [numthreads(1, 1, 1)]
6769 void main() { }
6770 #endif
6771 static const DWORD simple_cs[] =
6773 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
6774 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
6775 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
6776 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
6778 static const struct vec4 constant = {1.257f, 1.885f, 2.513f, 3.770f};
6780 ID3DDeviceContextState *context_state, *previous_context_state, *tmp_context_state, *context_state2;
6781 UINT ib_offset, vb_offset, vb_stride, so_offset, offset, stride, sample_mask, stencil_ref, count;
6782 ID3D11Buffer *cb, *srvb, *uavb, *ib, *vb, *sob, *tmp_cb, *tmp_ib, *tmp_vb, *tmp_sob;
6783 D3D_FEATURE_LEVEL feature_level, selected_feature_level;
6784 ID3D11UnorderedAccessView *tmp_uav, *uav, *ps_uav;
6785 ID3D11Device *d3d11_device, *d3d11_device2;
6786 ID3D11SamplerState *sampler, *tmp_sampler;
6787 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
6788 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
6789 ID3D11DeviceContext1 *context, *context2;
6790 ID3D11ShaderResourceView *tmp_srv, *srv;
6791 D3D11_DEVICE_CONTEXT_TYPE context_type;
6792 ID3D11DepthStencilState *tmp_dss, *dss;
6793 ID3D11RenderTargetView *tmp_rtv, *rtv;
6794 ID3D11DepthStencilView *tmp_dsv, *dsv;
6795 ID3D11VertexShader *tmp_vs, *vs, *vs2;
6796 ID3D11RasterizerState *tmp_rs, *rs;
6797 D3D11_TEXTURE2D_DESC texture_desc;
6798 ID3D11GeometryShader *tmp_gs, *gs;
6799 enum D3D_PRIMITIVE_TOPOLOGY topo;
6800 ID3D11ComputeShader *tmp_cs, *cs;
6801 D3D11_DEPTH_STENCIL_DESC ds_desc;
6802 ID3D11Predicate *tmp_pred, *pred;
6803 ID3D11DomainShader *tmp_ds, *ds;
6804 D3D11_SAMPLER_DESC sampler_desc;
6805 D3D11_QUERY_DESC predicate_desc;
6806 ID3D11Device1 *device, *device2;
6807 ID3D11InputLayout *il, *tmp_il;
6808 ID3D11PixelShader *tmp_ps, *ps;
6809 D3D11_RASTERIZER_DESC rs_desc;
6810 ID3D11BlendState *tmp_bs, *bs;
6811 ID3D11HullShader *tmp_hs, *hs;
6812 D3D11_VIEWPORT tmp_vp[2], vp;
6813 D3D11_RECT tmp_rect[2], rect;
6814 D3D11_BLEND_DESC blend_desc;
6815 ID3D11Texture2D *texture;
6816 enum DXGI_FORMAT format;
6817 float blend_factor[4];
6818 DWORD data_size;
6819 BOOL pred_value;
6820 ULONG refcount;
6821 char data[64];
6822 HRESULT hr;
6824 if (!(d3d11_device = create_device(NULL)))
6826 skip("Failed to create device.\n");
6827 return;
6830 hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Device1, (void **)&device);
6831 ID3D11Device_Release(d3d11_device);
6832 if (FAILED(hr))
6834 skip("ID3D11Device1 is not available.\n");
6835 return;
6838 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
6839 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
6841 feature_level = ID3D11Device1_GetFeatureLevel(device);
6842 context = NULL;
6843 ID3D11Device1_GetImmediateContext1(device, &context);
6844 ok(!!context, "Failed to get immediate context.\n");
6846 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
6847 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
6848 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
6849 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
6850 sampler_desc.MipLODBias = 0.0f;
6851 sampler_desc.MaxAnisotropy = 0;
6852 sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
6853 sampler_desc.BorderColor[0] = 0.0f;
6854 sampler_desc.BorderColor[1] = 1.0f;
6855 sampler_desc.BorderColor[2] = 0.0f;
6856 sampler_desc.BorderColor[3] = 1.0f;
6857 sampler_desc.MinLOD = 0.0f;
6858 sampler_desc.MaxLOD = 16.0f;
6859 hr = ID3D11Device1_CreateSamplerState(device, &sampler_desc, &sampler);
6860 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6862 feature_level = min(feature_level, D3D_FEATURE_LEVEL_11_1);
6864 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level,
6865 1, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, NULL);
6866 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6868 selected_feature_level = 0xc0de0000;
6869 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1,
6870 D3D11_SDK_VERSION, &IID_ID3D11Device1, &selected_feature_level, NULL);
6871 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6872 ok(selected_feature_level == feature_level, "Got unexpected feature level %#x, expected %#x.\n",
6873 selected_feature_level, feature_level);
6875 selected_feature_level = 0xc0de0000;
6876 context_state = (void *)0xc0de0001;
6877 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 0,
6878 D3D11_SDK_VERSION, &IID_ID3D11Device1, &selected_feature_level, &context_state);
6879 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6880 ok(!selected_feature_level, "Got unexpected feature level %#x.\n", selected_feature_level);
6881 ok(!context_state, "Got unexpected context state %p.\n", context_state);
6883 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level,
6884 0, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, NULL);
6885 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6887 hr = ID3D11Device1_CreateDeviceContextState(device, 0, NULL,
6888 0, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, NULL);
6889 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6891 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level,
6892 1, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, &context_state);
6893 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6894 refcount = get_refcount(context_state);
6895 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6897 context_type = ID3D11DeviceContext1_GetType(context);
6898 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
6900 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
6901 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
6902 check_interface(device, &IID_ID3D11Device, TRUE, FALSE);
6903 check_interface(device, &IID_ID3D11Device1, TRUE, FALSE);
6905 cb = create_buffer((ID3D11Device *)device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), NULL);
6906 srvb = create_buffer((ID3D11Device *)device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
6907 uavb = create_buffer((ID3D11Device *)device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
6908 ib = create_buffer((ID3D11Device *)device, D3D11_BIND_INDEX_BUFFER, 1024, NULL);
6909 vb = create_buffer((ID3D11Device *)device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
6910 sob = create_buffer((ID3D11Device *)device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
6912 hr = ID3D11Device1_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
6913 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6915 hr = ID3D11Device1_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
6916 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
6918 hr = ID3D11Device1_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
6919 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6921 if (feature_level < D3D_FEATURE_LEVEL_11_0) hs = NULL;
6922 else
6924 hr = ID3D11Device1_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
6925 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
6928 if (feature_level < D3D_FEATURE_LEVEL_11_0) ds = NULL;
6929 else
6931 hr = ID3D11Device1_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
6932 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
6935 if (feature_level < D3D_FEATURE_LEVEL_11_0) cs = NULL;
6936 else
6938 hr = ID3D11Device1_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
6939 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
6942 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
6943 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
6944 U(srv_desc).Buffer.ElementOffset = 0;
6945 U(srv_desc).Buffer.ElementWidth = 64;
6946 hr = ID3D11Device1_CreateShaderResourceView(device, (ID3D11Resource *)srvb, &srv_desc, &srv);
6947 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
6948 ID3D11Buffer_Release(srvb);
6950 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
6951 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
6952 U(uav_desc).Buffer.FirstElement = 0;
6953 U(uav_desc).Buffer.NumElements = 4;
6954 U(uav_desc).Buffer.Flags = 0;
6955 hr = ID3D11Device1_CreateUnorderedAccessView(device, (ID3D11Resource *)uavb, &uav_desc, &uav);
6956 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
6957 ID3D11Buffer_Release(uavb);
6959 uavb = create_buffer((ID3D11Device *)device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
6960 hr = ID3D11Device1_CreateUnorderedAccessView(device, (ID3D11Resource *)uavb, &uav_desc, &ps_uav);
6961 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
6962 ID3D11Buffer_Release(uavb);
6964 hr = ID3D11Device1_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
6965 simple_vs, sizeof(simple_vs), &il);
6966 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6968 ib_offset = 16;
6969 vb_offset = 16;
6970 vb_stride = 16;
6971 so_offset = 16;
6973 texture_desc.Width = 512;
6974 texture_desc.Height = 512;
6975 texture_desc.MipLevels = 1;
6976 texture_desc.ArraySize = 1;
6977 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6978 texture_desc.SampleDesc.Count = 1;
6979 texture_desc.SampleDesc.Quality = 0;
6980 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6981 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6982 texture_desc.CPUAccessFlags = 0;
6983 texture_desc.MiscFlags = 0;
6984 hr = ID3D11Device1_CreateTexture2D(device, &texture_desc, NULL, &texture);
6985 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6986 hr = ID3D11Device1_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
6987 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
6988 ID3D11Texture2D_Release(texture);
6990 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
6991 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
6992 hr = ID3D11Device1_CreateTexture2D(device, &texture_desc, NULL, &texture);
6993 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6994 hr = ID3D11Device1_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
6995 ok(SUCCEEDED(hr), "Failed to create depth/stencil view, hr %#x.\n", hr);
6996 ID3D11Texture2D_Release(texture);
6998 memset(&blend_desc, 0, sizeof(blend_desc));
6999 blend_desc.RenderTarget[0].BlendEnable = TRUE;
7000 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
7001 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
7002 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
7003 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
7004 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
7005 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
7006 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
7007 hr = ID3D11Device1_CreateBlendState(device, &blend_desc, &bs);
7008 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
7010 ds_desc.DepthEnable = TRUE;
7011 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
7012 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
7013 ds_desc.StencilEnable = FALSE;
7014 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
7015 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
7016 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
7017 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
7018 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
7019 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
7020 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
7021 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
7022 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
7023 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
7024 hr = ID3D11Device1_CreateDepthStencilState(device, &ds_desc, &dss);
7025 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
7027 rs_desc.FillMode = D3D11_FILL_SOLID;
7028 rs_desc.CullMode = D3D11_CULL_BACK;
7029 rs_desc.FrontCounterClockwise = FALSE;
7030 rs_desc.DepthBias = 0;
7031 rs_desc.DepthBiasClamp = 0.0f;
7032 rs_desc.SlopeScaledDepthBias = 0.0f;
7033 rs_desc.DepthClipEnable = TRUE;
7034 rs_desc.ScissorEnable = TRUE;
7035 rs_desc.MultisampleEnable = FALSE;
7036 rs_desc.AntialiasedLineEnable = FALSE;
7037 hr = ID3D11Device1_CreateRasterizerState(device, &rs_desc, &rs);
7038 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
7040 SetRect(&rect, 0, 0, 1, 2);
7041 vp.TopLeftX = 0;
7042 vp.TopLeftY = 0;
7043 vp.Width = 3;
7044 vp.Height = 4;
7045 vp.MinDepth = 0.f;
7046 vp.MaxDepth = 0.01f;
7048 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
7049 predicate_desc.MiscFlags = 0;
7050 ID3D11Device1_CreatePredicate(device, &predicate_desc, &pred);
7052 ID3D11DeviceContext1_VSSetConstantBuffers(context, 0, 1, &cb);
7053 ID3D11DeviceContext1_VSSetSamplers(context, 0, 1, &sampler);
7054 ID3D11DeviceContext1_VSSetShader(context, vs, NULL, 0);
7055 ID3D11DeviceContext1_VSSetShaderResources(context, 0, 1, &srv);
7056 refcount = get_refcount(vs);
7057 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7059 ID3D11DeviceContext1_GSSetConstantBuffers(context, 0, 1, &cb);
7060 ID3D11DeviceContext1_GSSetSamplers(context, 0, 1, &sampler);
7061 ID3D11DeviceContext1_GSSetShader(context, gs, NULL, 0);
7062 ID3D11DeviceContext1_GSSetShaderResources(context, 0, 1, &srv);
7064 ID3D11DeviceContext1_PSSetConstantBuffers(context, 0, 1, &cb);
7065 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
7066 ID3D11DeviceContext1_PSSetShader(context, ps, NULL, 0);
7067 ID3D11DeviceContext1_PSSetShaderResources(context, 0, 1, &srv);
7069 ID3D11DeviceContext1_HSSetConstantBuffers(context, 0, 1, &cb);
7070 ID3D11DeviceContext1_HSSetSamplers(context, 0, 1, &sampler);
7071 ID3D11DeviceContext1_HSSetShader(context, hs, NULL, 0);
7072 ID3D11DeviceContext1_HSSetShaderResources(context, 0, 1, &srv);
7074 ID3D11DeviceContext1_DSSetConstantBuffers(context, 0, 1, &cb);
7075 ID3D11DeviceContext1_DSSetSamplers(context, 0, 1, &sampler);
7076 ID3D11DeviceContext1_DSSetShader(context, ds, NULL, 0);
7077 ID3D11DeviceContext1_DSSetShaderResources(context, 0, 1, &srv);
7079 ID3D11DeviceContext1_CSSetConstantBuffers(context, 0, 1, &cb);
7080 ID3D11DeviceContext1_CSSetSamplers(context, 0, 1, &sampler);
7081 ID3D11DeviceContext1_CSSetShader(context, cs, NULL, 0);
7082 ID3D11DeviceContext1_CSSetShaderResources(context, 0, 1, &srv);
7083 ID3D11DeviceContext1_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
7085 ID3D11DeviceContext1_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7086 ID3D11DeviceContext1_IASetInputLayout(context, il);
7087 ID3D11DeviceContext1_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, ib_offset);
7088 ID3D11DeviceContext1_IASetVertexBuffers(context, 0, 1, &vb, &vb_stride, &vb_offset);
7090 ID3D11DeviceContext1_OMSetBlendState(context, bs, custom_blend_factor, 0xff00ff00);
7091 ID3D11DeviceContext1_OMSetDepthStencilState(context, dss, 3);
7092 ID3D11DeviceContext1_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, dsv, 1, 1, &ps_uav, NULL);
7094 ID3D11DeviceContext1_RSSetScissorRects(context, 1, &rect);
7095 ID3D11DeviceContext1_RSSetViewports(context, 1, &vp);
7096 ID3D11DeviceContext1_RSSetState(context, rs);
7098 ID3D11DeviceContext1_SOSetTargets(context, 1, &sob, &so_offset);
7099 ID3D11DeviceContext1_SetPredication(context, pred, TRUE);
7101 previous_context_state = (ID3DDeviceContextState *)0xdeadbeef;
7102 ID3D11DeviceContext1_SwapDeviceContextState(context, NULL, &previous_context_state);
7103 ok(previous_context_state == NULL, "Got unexpected state pointer.\n");
7104 previous_context_state = NULL;
7105 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
7106 ok(previous_context_state != NULL, "Failed to get previous context state\n");
7107 refcount = get_refcount(vs);
7108 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7110 hr = ID3DDeviceContextState_SetPrivateData(context_state, &test_guid, sizeof(constant), &constant);
7111 ok(hr == S_OK, "Failed to set private data, hr %#x.\n", hr);
7112 refcount = ID3DDeviceContextState_Release(context_state);
7113 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7114 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
7115 data_size = sizeof(data);
7116 memset(data, 0xa5, sizeof(data));
7117 hr = ID3DDeviceContextState_GetPrivateData(context_state, &test_guid, &data_size, data);
7118 ok(hr == S_OK, "Failed to get private data, hr %#x.\n", hr);
7119 ok(data_size == sizeof(constant), "Got private data size %x, expected %x.\n", data_size, sizeof(constant));
7120 ok(!memcmp(data, &constant, sizeof(constant)), "Got unexpected private data.\n");
7121 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, NULL);
7123 context_type = ID3D11DeviceContext1_GetType(context);
7124 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7126 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7127 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7128 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7129 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7130 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7131 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7132 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7133 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7134 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7135 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7136 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7137 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7139 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7140 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7141 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7142 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7143 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7144 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7145 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7146 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7147 ok(!tmp_gs, "Got unexpected shader %p.\n", tmp_gs);
7148 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7149 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7150 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7152 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7153 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7154 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7155 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7156 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7157 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7158 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7159 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7160 ok(!tmp_ps, "Got unexpected shader %p.\n", tmp_ps);
7161 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7162 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7163 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7165 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7166 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7167 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7168 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7169 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7170 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7171 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7172 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7173 if (hs) ok(!tmp_hs, "Got unexpected shader %p.\n", tmp_hs);
7174 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7175 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7176 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7178 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7179 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7180 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7181 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7182 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7183 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7184 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7185 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7186 if (ds) ok(!tmp_ds, "Got unexpected shader %p.\n", tmp_ds);
7187 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7188 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7189 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7191 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7192 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7193 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7194 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7195 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7196 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7197 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7198 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7199 if (cs) ok(!tmp_cs, "Got unexpected shader %p.\n", tmp_cs);
7200 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7201 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7202 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7203 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7204 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7205 ok(!tmp_uav, "Got unexpected uav %p.\n", tmp_uav);
7207 topo = 0xdeadbeef;
7208 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7209 ok(topo == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected topology %#x.\n", topo);
7210 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7211 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7212 ok(!tmp_il, "Got unexpected input layout %p.\n", tmp_il);
7213 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7214 format = 0xdeadbeef;
7215 offset = 0xdeadbeef;
7216 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7217 ok(!tmp_ib, "Got unexpected input buffer %p.\n", tmp_ib);
7218 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected input buffer format %#x.\n", format);
7219 ok(offset == 0, "Got unexpected input buffer offset %#x.\n", offset);
7220 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7221 stride = 0xdeadbeef;
7222 offset = 0xdeadbeef;
7223 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7224 ok(!tmp_vb, "Got unexpected vertex buffer %p.\n", tmp_vb);
7225 ok(stride == 0, "Got unexpected vertex buffer stride %#x.\n", stride);
7226 ok(offset == 0, "Got unexpected vertex buffer offset %#x.\n", offset);
7228 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7229 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7230 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7231 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7232 ok(!tmp_rtv, "Got unexpected rendertarget view %p.\n", tmp_rtv);
7233 ok(!tmp_dsv, "Got unexpected depth/stencil view %p.\n", tmp_dsv);
7234 ok(!tmp_uav, "Got unexpected unordered access view %p.\n", tmp_uav);
7235 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7236 memset(blend_factor, 0xcd, sizeof(blend_factor));
7237 sample_mask = 0xdeadbeef;
7238 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7239 ok(!tmp_bs, "Got unexpected blend state %p.\n", tmp_bs);
7240 ok(!memcmp(blend_factor, default_blend_factor, sizeof(blend_factor)),
7241 "Got unexpected blend factor %f,%f,%f,%f.\n",
7242 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
7243 ok(sample_mask == ~0, "Got unexpected sample mask %#x.\n", sample_mask);
7244 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7245 stencil_ref = 0xdeadbeef;
7246 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7247 ok(!tmp_dss, "Got unexpected depth/stencil state %p.\n", tmp_dss);
7248 ok(stencil_ref == 0, "Got unexpected stencil ref %#x.\n", stencil_ref);
7250 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7251 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7252 ok(!tmp_rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7253 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7254 count = 2;
7255 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7256 ok(count == 0, "Got unexpected viewport count %u.\n", count);
7257 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7258 count = 2;
7259 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7260 ok(count == 0, "Got unexpected scissor rect count %u.\n", count);
7262 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7263 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7264 ok(!tmp_sob, "Got unexpected stream output buffer %p.\n", tmp_sob);
7266 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7267 pred_value = 0xdeadbeef;
7268 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7269 ok(!tmp_pred, "Got unexpected predicate %p.\n", tmp_pred);
7270 ok(!pred_value, "Got unexpected predicate value %d.\n", pred_value);
7272 /* updating the device context should also update the device context state */
7273 hr = ID3D11Device1_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs2);
7274 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7275 ID3D11DeviceContext1_VSSetShader(context, vs2, NULL, 0);
7276 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &tmp_context_state);
7277 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7278 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7279 ok(tmp_context_state == context_state, "Got unexpected state pointer.\n");
7280 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7281 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7282 ok(tmp_vs == vs2, "Got shader %p, expected %p.\n", tmp_vs, vs2);
7283 refcount = ID3D11VertexShader_Release(tmp_vs);
7284 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7286 /* context states may be used with other devices instances too */
7287 d3d11_device2 = create_device(NULL);
7288 ok(!!d3d11_device2, "Failed to create device.\n");
7289 hr = ID3D11Device_QueryInterface(d3d11_device2, &IID_ID3D11Device1, (void **)&device2);
7290 ok(SUCCEEDED(hr), "Failed to query device interface, hr %#x.\n", hr);
7291 ID3D11Device_Release(d3d11_device2);
7292 ID3D11Device1_GetImmediateContext1(device2, &context2);
7293 ok(!!context2, "Failed to get immediate context.\n");
7295 /* but they track a distinct state on each context */
7296 ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, &tmp_context_state);
7297 ok(!!tmp_context_state, "Failed to get context state.\n");
7298 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7299 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7300 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7302 /* updating context2 vertex shader doesn't update other contexts using the same state */
7303 ID3D11DeviceContext1_VSSetShader(context2, vs, NULL, 0);
7304 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7305 ok(tmp_vs == vs2, "Got shader %p, expected %p.\n", tmp_vs, vs2);
7306 refcount = ID3D11VertexShader_Release(tmp_vs);
7307 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7309 ID3D11DeviceContext1_SwapDeviceContextState(context2, tmp_context_state, &context_state2);
7310 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7311 ok(refcount == 0, "Got refcount %u, expected 1.\n", refcount);
7312 refcount = ID3DDeviceContextState_Release(context_state2);
7313 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7314 ok(context_state2 == context_state, "Got unexpected state pointer.\n");
7316 /* swapping the default state on context2 effectively clears the vertex shader */
7317 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7318 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7319 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7321 ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, &tmp_context_state);
7322 ok(!!tmp_context_state, "Failed to get context state.\n");
7323 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7324 ok(refcount == 0, "Got refcount %u, expected 1.\n", refcount);
7326 /* clearing the vertex shader on context doesn't have side effect on context2 */
7327 ID3D11DeviceContext1_VSSetShader(context, NULL, NULL, 0);
7328 refcount = ID3D11VertexShader_Release(vs2);
7329 ok(refcount == 0, "Got refcount %u, expected 0.\n", refcount);
7330 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7331 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7332 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7333 refcount = ID3D11VertexShader_Release(tmp_vs);
7334 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7336 /* even after swapping it again */
7337 ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, NULL);
7338 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7339 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7340 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7341 refcount = ID3D11VertexShader_Release(tmp_vs);
7342 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7344 /* swapping the initial state on context2 doesn't have side effect on context either */
7345 ID3D11DeviceContext1_SwapDeviceContextState(context2, previous_context_state, NULL);
7346 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7347 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7348 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7350 refcount = ID3D11DeviceContext1_Release(context2);
7351 ok(refcount == 0, "Got refcount %u, expected 0.\n", refcount);
7352 refcount = ID3D11Device1_Release(device2);
7353 ok(refcount == 0, "Got refcount %u, expected 0.\n", refcount);
7355 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &tmp_context_state);
7356 refcount = ID3DDeviceContextState_Release(previous_context_state);
7357 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7358 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7359 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7360 refcount = ID3DDeviceContextState_Release(context_state);
7361 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7362 ok(tmp_context_state == context_state, "Got unexpected state pointer.\n");
7363 refcount = get_refcount(vs);
7364 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7366 /* ID3DDeviceContextState retains the previous state. */
7368 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7369 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7370 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7371 ID3D11SamplerState_Release(tmp_sampler);
7372 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7373 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7374 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7375 ID3D11Buffer_Release(tmp_cb);
7376 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7377 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7378 ok(tmp_ps == ps, "Got shader %p, expected %p.\n", tmp_ps, ps);
7379 ID3D11PixelShader_Release(tmp_ps);
7380 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7381 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7382 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7383 ID3D11ShaderResourceView_Release(tmp_srv);
7385 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7386 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7387 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7388 ID3D11SamplerState_Release(tmp_sampler);
7389 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7390 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7391 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7392 ID3D11Buffer_Release(tmp_cb);
7393 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7394 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7395 ok(tmp_cs == cs, "Got shader %p, expected %p.\n", tmp_cs, cs);
7396 if (cs) ID3D11ComputeShader_Release(tmp_cs);
7397 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7398 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7399 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7400 ID3D11ShaderResourceView_Release(tmp_srv);
7401 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7402 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7403 ok(tmp_uav == uav, "Got uav %p, expected %p.\n", tmp_uav, uav);
7404 ID3D11UnorderedAccessView_Release(tmp_uav);
7406 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7407 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7408 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7409 ID3D11SamplerState_Release(tmp_sampler);
7410 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7411 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7412 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7413 ID3D11Buffer_Release(tmp_cb);
7414 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7415 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7416 ok(tmp_ds == ds, "Got shader %p, expected %p.\n", tmp_ds, ds);
7417 if (ds) ID3D11DomainShader_Release(tmp_ds);
7418 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7419 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7420 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7421 ID3D11ShaderResourceView_Release(tmp_srv);
7423 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7424 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7425 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7426 ID3D11SamplerState_Release(tmp_sampler);
7427 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7428 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7429 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7430 ID3D11Buffer_Release(tmp_cb);
7431 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7432 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7433 ok(tmp_gs == gs, "Got shader %p, expected %p.\n", tmp_gs, gs);
7434 ID3D11GeometryShader_Release(tmp_gs);
7435 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7436 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7437 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7438 ID3D11ShaderResourceView_Release(tmp_srv);
7440 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7441 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7442 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7443 ID3D11SamplerState_Release(tmp_sampler);
7444 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7445 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7446 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7447 ID3D11Buffer_Release(tmp_cb);
7448 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7449 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7450 ok(tmp_hs == hs, "Got shader %p, expected %p.\n", tmp_hs, hs);
7451 if (hs) ID3D11HullShader_Release(tmp_hs);
7452 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7453 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7454 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7455 ID3D11ShaderResourceView_Release(tmp_srv);
7457 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7458 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7459 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7460 ID3D11SamplerState_Release(tmp_sampler);
7461 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7462 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7463 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7464 ID3D11Buffer_Release(tmp_cb);
7465 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7466 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7467 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7468 ID3D11VertexShader_Release(tmp_vs);
7469 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7470 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7471 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7472 ID3D11ShaderResourceView_Release(tmp_srv);
7474 topo = 0xdeadbeef;
7475 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7476 ok(topo == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got topology %#x, expected %#x.\n", topo, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7477 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7478 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7479 ok(tmp_il == il, "Got input layout %p, expected %p.\n", tmp_il, il);
7480 ID3D11InputLayout_Release(tmp_il);
7481 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7482 format = 0xdeadbeef;
7483 offset = 0xdeadbeef;
7484 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7485 ok(tmp_ib == ib, "Got input buffer %p, expected %p.\n", tmp_ib, ib);
7486 ID3D11Buffer_Release(tmp_ib);
7487 ok(format == DXGI_FORMAT_R32_UINT, "Got input buffer format %#x, expected %#x.\n", format, DXGI_FORMAT_R32_UINT);
7488 ok(offset == 16, "Got input buffer offset %#x, expected 16.\n", offset);
7489 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7490 stride = 0xdeadbeef;
7491 offset = 0xdeadbeef;
7492 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7493 ok(tmp_vb == vb, "Got vertex buffer %p, expected %p.\n", tmp_vb, vb);
7494 ID3D11Buffer_Release(tmp_vb);
7495 ok(stride == 16, "Got vertex buffer stride %#x, expected 16.\n", stride);
7496 ok(offset == 16, "Got vertex buffer offset %#x, expected 16.\n", offset);
7498 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7499 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7500 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7501 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7502 ok(tmp_rtv == rtv, "Got rendertarget view %p, expected %p.\n", tmp_rtv, rtv);
7503 ID3D11RenderTargetView_Release(tmp_rtv);
7504 ok(tmp_dsv == dsv, "Got depth/stencil view %p, expected %p.\n", tmp_dsv, dsv);
7505 ID3D11DepthStencilView_Release(tmp_dsv);
7506 ok(tmp_uav == ps_uav, "Got unordered access view %p, expected %p.\n", tmp_uav, ps_uav);
7507 ID3D11UnorderedAccessView_Release(tmp_uav);
7508 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7509 memset(blend_factor, 0xcd, sizeof(blend_factor));
7510 sample_mask = 0xdeadbeef;
7511 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7512 ok(tmp_bs == bs, "Got blend state %p, expected %p.\n", tmp_bs, bs);
7513 ID3D11BlendState_Release(tmp_bs);
7514 ok(!memcmp(blend_factor, custom_blend_factor, sizeof(blend_factor)),
7515 "Got blend factor %f,%f,%f,%f, expected %f,%f,%f,%f.\n",
7516 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3],
7517 custom_blend_factor[0], custom_blend_factor[1], custom_blend_factor[2], custom_blend_factor[3]);
7518 ok(sample_mask == 0xff00ff00, "Got sample mask %#x, expected %#x.\n", sample_mask, 0xff00ff00);
7519 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7520 stencil_ref = 0xdeadbeef;
7521 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7522 ok(tmp_dss == dss, "Got depth/stencil state %p, expected %p.\n", tmp_dss, dss);
7523 ID3D11DepthStencilState_Release(tmp_dss);
7524 ok(stencil_ref == 3, "Got stencil ref %#x, expected 3.\n", stencil_ref);
7526 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7527 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7528 ok(tmp_rs == rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7529 ID3D11RasterizerState_Release(tmp_rs);
7530 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7531 count = 2;
7532 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7533 ok(count == 1, "Got viewport count %u, expected 1.\n", count);
7534 ok(!memcmp(tmp_vp, &vp, sizeof(vp)), "Got viewport %s, expected %s.\n",
7535 debugstr_viewport(tmp_vp), debugstr_viewport(&vp));
7536 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7537 count = 2;
7538 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7539 ok(count == 1, "Got scissor rect count %u, expected 1.\n", count);
7540 ok(!memcmp(tmp_rect, &rect, sizeof(rect)), "Got scissor rect %s, expected %s.\n",
7541 wine_dbgstr_rect(tmp_rect), wine_dbgstr_rect(&rect));
7543 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7544 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7545 ok(tmp_sob == sob, "Got stream output buffer %p, expected %p.\n", tmp_sob, sob);
7546 ID3D11Buffer_Release(tmp_sob);
7548 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7549 pred_value = 0xdeadbeef;
7550 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7551 ok(tmp_pred == pred, "Got predicate %p, expected %p.\n", tmp_pred, pred);
7552 ID3D11Predicate_Release(tmp_pred);
7553 ok(pred_value == TRUE, "Got predicate value %#x, expected TRUE.\n", pred_value);
7555 feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1);
7556 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
7557 &IID_ID3D10Device, NULL, &context_state);
7558 ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr);
7559 refcount = get_refcount(context_state);
7560 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7562 context_type = ID3D11DeviceContext1_GetType(context);
7563 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7565 /* Enable ID3D10Device behavior. */
7566 previous_context_state = NULL;
7567 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
7568 refcount = ID3DDeviceContextState_Release(context_state);
7569 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7570 ok(previous_context_state != NULL, "Failed to get previous context state\n");
7572 context_type = ID3D11DeviceContext1_GetType(context);
7573 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7575 ID3D11DeviceContext1_VSSetConstantBuffers(context, 0, 1, &cb);
7576 ID3D11DeviceContext1_VSSetSamplers(context, 0, 1, &sampler);
7577 ID3D11DeviceContext1_VSSetShader(context, vs, NULL, 0);
7578 ID3D11DeviceContext1_VSSetShaderResources(context, 0, 1, &srv);
7580 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7581 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7582 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7583 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7584 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7585 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7586 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7587 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7588 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7589 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7590 todo_wine ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7591 if (tmp_vs && tmp_vs != (ID3D11VertexShader *)0xdeadbeef) ID3D11VertexShader_Release(tmp_vs);
7592 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7593 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7594 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7595 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7597 ID3D11DeviceContext1_GSSetConstantBuffers(context, 0, 1, &cb);
7598 ID3D11DeviceContext1_GSSetSamplers(context, 0, 1, &sampler);
7599 ID3D11DeviceContext1_GSSetShader(context, gs, NULL, 0);
7600 ID3D11DeviceContext1_GSSetShaderResources(context, 0, 1, &srv);
7602 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7603 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7604 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7605 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7606 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7607 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7608 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7609 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7610 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7611 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7612 todo_wine ok(!tmp_gs, "Got unexpected shader %p.\n", tmp_gs);
7613 if (tmp_gs && tmp_gs != (ID3D11GeometryShader *)0xdeadbeef) ID3D11GeometryShader_Release(tmp_gs);
7614 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7615 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7616 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7617 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7619 ID3D11DeviceContext1_PSSetConstantBuffers(context, 0, 1, &cb);
7620 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
7621 ID3D11DeviceContext1_PSSetShader(context, ps, NULL, 0);
7622 ID3D11DeviceContext1_PSSetShaderResources(context, 0, 1, &srv);
7624 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7625 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7626 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7627 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7628 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7629 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7630 todo_wine ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler);
7631 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7632 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7633 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7634 todo_wine ok(!tmp_ps, "Got unexpected shader %p.\n", tmp_ps);
7635 if (tmp_ps && tmp_ps != (ID3D11PixelShader *)0xdeadbeef) ID3D11PixelShader_Release(tmp_ps);
7636 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7637 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7638 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7639 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7641 ID3D11DeviceContext1_HSSetConstantBuffers(context, 0, 1, &cb);
7642 ID3D11DeviceContext1_HSSetSamplers(context, 0, 1, &sampler);
7643 ID3D11DeviceContext1_HSSetShader(context, hs, NULL, 0);
7644 ID3D11DeviceContext1_HSSetShaderResources(context, 0, 1, &srv);
7646 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7647 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7648 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7649 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7650 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7651 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7652 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7653 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7654 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7655 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7656 if (hs) todo_wine ok(!tmp_hs, "Got unexpected shader %p.\n", tmp_hs);
7657 if (tmp_hs && tmp_hs != (ID3D11HullShader *)0xdeadbeef) ID3D11HullShader_Release(tmp_hs);
7658 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7659 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7660 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7661 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7663 ID3D11DeviceContext1_DSSetConstantBuffers(context, 0, 1, &cb);
7664 ID3D11DeviceContext1_DSSetSamplers(context, 0, 1, &sampler);
7665 ID3D11DeviceContext1_DSSetShader(context, ds, NULL, 0);
7666 ID3D11DeviceContext1_DSSetShaderResources(context, 0, 1, &srv);
7668 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7669 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7670 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7671 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7672 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7673 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7674 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7675 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7676 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7677 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7678 if (ds) todo_wine ok(!tmp_ds, "Got unexpected shader %p.\n", tmp_ds);
7679 if (tmp_ds && tmp_ds != (ID3D11DomainShader *)0xdeadbeef) ID3D11DomainShader_Release(tmp_ds);
7680 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7681 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7682 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7683 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7685 ID3D11DeviceContext1_CSSetConstantBuffers(context, 0, 1, &cb);
7686 ID3D11DeviceContext1_CSSetSamplers(context, 0, 1, &sampler);
7687 ID3D11DeviceContext1_CSSetShader(context, cs, NULL, 0);
7688 ID3D11DeviceContext1_CSSetShaderResources(context, 0, 1, &srv);
7689 ID3D11DeviceContext1_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
7691 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7692 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7693 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7694 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7695 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7696 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7697 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7698 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7699 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7700 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7701 if (cs) todo_wine ok(!tmp_cs, "Got unexpected shader %p.\n", tmp_cs);
7702 if (tmp_cs && tmp_cs != (ID3D11ComputeShader *)0xdeadbeef) ID3D11ComputeShader_Release(tmp_cs);
7703 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7704 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7705 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7706 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7707 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7708 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7709 todo_wine ok(!tmp_uav, "Got unexpected uav %p.\n", tmp_uav);
7710 if (tmp_uav && tmp_uav != (ID3D11UnorderedAccessView *)0xdeadbeef) ID3D11UnorderedAccessView_Release(tmp_uav);
7712 ID3D11DeviceContext1_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7713 ID3D11DeviceContext1_IASetInputLayout(context, il);
7714 ID3D11DeviceContext1_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, ib_offset);
7715 ID3D11DeviceContext1_IASetVertexBuffers(context, 0, 1, &vb, &vb_stride, &vb_offset);
7717 topo = 0xdeadbeef;
7718 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7719 todo_wine ok(topo == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected topology %#x.\n", topo);
7720 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7721 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7722 todo_wine ok(!tmp_il, "Got unexpected input layout %p.\n", tmp_il);
7723 if (tmp_il) ID3D11InputLayout_Release(tmp_il);
7724 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7725 format = 0xdeadbeef;
7726 offset = 0xdeadbeef;
7727 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7728 todo_wine ok(!tmp_ib, "Got unexpected input buffer %p.\n", tmp_ib);
7729 if (tmp_ib) ID3D11Buffer_Release(tmp_ib);
7730 todo_wine ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected input buffer format %#x.\n", format);
7731 todo_wine ok(offset == 0, "Got unexpected input buffer offset %#x.\n", offset);
7732 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7733 stride = 0xdeadbeef;
7734 offset = 0xdeadbeef;
7735 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7736 todo_wine ok(!tmp_vb, "Got unexpected vertex buffer %p.\n", tmp_vb);
7737 if (tmp_vb) ID3D11Buffer_Release(tmp_vb);
7738 todo_wine ok(stride == 0, "Got unexpected vertex buffer stride %#x.\n", stride);
7739 todo_wine ok(offset == 0, "Got unexpected vertex buffer offset %#x.\n", offset);
7741 ID3D11DeviceContext1_OMSetBlendState(context, bs, custom_blend_factor, 0xff00ff00);
7742 ID3D11DeviceContext1_OMSetDepthStencilState(context, dss, 3);
7743 ID3D11DeviceContext1_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, dsv, 1, 1, &ps_uav, NULL);
7745 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7746 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7747 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7748 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7749 todo_wine ok(!tmp_rtv, "Got unexpected rendertarget view %p.\n", tmp_rtv);
7750 if (tmp_rtv) ID3D11RenderTargetView_Release(tmp_rtv);
7751 todo_wine ok(!tmp_dsv, "Got unexpected depth/stencil view %p.\n", tmp_dsv);
7752 if (tmp_dsv) ID3D11DepthStencilView_Release(tmp_dsv);
7753 todo_wine ok(!tmp_uav, "Got unexpected unordered access view %p.\n", tmp_uav);
7754 if (tmp_uav) ID3D11UnorderedAccessView_Release(tmp_uav);
7755 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7756 memset(blend_factor, 0xcd, sizeof(blend_factor));
7757 sample_mask = 0xdeadbeef;
7758 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7759 todo_wine ok(!tmp_bs, "Got unexpected blend state %p.\n", tmp_bs);
7760 if (tmp_bs) ID3D11BlendState_Release(tmp_bs);
7761 todo_wine ok(!memcmp(blend_factor, default_blend_factor, sizeof(blend_factor)),
7762 "Got unexpected blend factor %f,%f,%f,%f.\n",
7763 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
7764 todo_wine ok(sample_mask == ~0, "Got unexpected sample mask %#x.\n", sample_mask);
7765 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7766 stencil_ref = 0xdeadbeef;
7767 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7768 todo_wine ok(!tmp_dss, "Got unexpected depth/stencil state %p.\n", tmp_dss);
7769 if (tmp_dss) ID3D11DepthStencilState_Release(tmp_dss);
7770 todo_wine ok(stencil_ref == 0, "Got unexpected stencil ref %#x.\n", stencil_ref);
7772 ID3D11DeviceContext1_RSSetScissorRects(context, 1, &rect);
7773 ID3D11DeviceContext1_RSSetViewports(context, 1, &vp);
7774 ID3D11DeviceContext1_RSSetState(context, rs);
7776 ID3D11DeviceContext1_SOSetTargets(context, 1, &sob, &so_offset);
7777 ID3D11DeviceContext1_SetPredication(context, pred, TRUE);
7779 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7780 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7781 todo_wine ok(!tmp_rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7782 if (tmp_rs) ID3D11RasterizerState_Release(tmp_rs);
7783 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7784 count = 2;
7785 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7786 todo_wine ok(count == 0, "Got unexpected viewport count %u.\n", count);
7787 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7788 count = 2;
7789 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7790 todo_wine ok(count == 0, "Got unexpected scissor rect count %u.\n", count);
7792 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7793 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7794 todo_wine ok(!tmp_sob, "Got unexpected stream output buffer %p.\n", tmp_sob);
7795 if (tmp_sob) ID3D11Buffer_Release(tmp_sob);
7797 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7798 pred_value = 0xdeadbeef;
7799 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7800 todo_wine ok(!tmp_pred, "Got unexpected predicate %p.\n", tmp_pred);
7801 if (tmp_pred) ID3D11Predicate_Release(tmp_pred);
7802 todo_wine ok(!pred_value, "Got unexpected predicate value %d.\n", pred_value);
7804 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
7805 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
7807 context_state = NULL;
7808 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
7809 refcount = ID3DDeviceContextState_Release(context_state);
7810 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7811 refcount = ID3DDeviceContextState_Release(previous_context_state);
7812 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7814 /* ID3DDeviceContextState retains the previous state. */
7816 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7817 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7818 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7819 ID3D11SamplerState_Release(tmp_sampler);
7820 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7821 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7822 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7823 ID3D11Buffer_Release(tmp_cb);
7824 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7825 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7826 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7827 ID3D11VertexShader_Release(tmp_vs);
7828 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7829 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7830 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7831 ID3D11ShaderResourceView_Release(tmp_srv);
7833 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7834 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7835 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7836 ID3D11SamplerState_Release(tmp_sampler);
7837 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7838 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7839 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7840 ID3D11Buffer_Release(tmp_cb);
7841 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7842 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7843 ok(tmp_gs == gs, "Got shader %p, expected %p.\n", tmp_gs, gs);
7844 ID3D11GeometryShader_Release(tmp_gs);
7845 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7846 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7847 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7848 ID3D11ShaderResourceView_Release(tmp_srv);
7850 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7851 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7852 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7853 ID3D11SamplerState_Release(tmp_sampler);
7854 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7855 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7856 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7857 ID3D11Buffer_Release(tmp_cb);
7858 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7859 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7860 ok(tmp_ps == ps, "Got shader %p, expected %p.\n", tmp_ps, ps);
7861 ID3D11PixelShader_Release(tmp_ps);
7862 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7863 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7864 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7865 ID3D11ShaderResourceView_Release(tmp_srv);
7867 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7868 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7869 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7870 ID3D11SamplerState_Release(tmp_sampler);
7871 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7872 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7873 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7874 ID3D11Buffer_Release(tmp_cb);
7875 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7876 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7877 ok(tmp_hs == hs, "Got shader %p, expected %p.\n", tmp_hs, hs);
7878 if (hs) ID3D11HullShader_Release(tmp_hs);
7879 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7880 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7881 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7882 ID3D11ShaderResourceView_Release(tmp_srv);
7884 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7885 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7886 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7887 ID3D11SamplerState_Release(tmp_sampler);
7888 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7889 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7890 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7891 ID3D11Buffer_Release(tmp_cb);
7892 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7893 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7894 ok(tmp_ds == ds, "Got shader %p, expected %p.\n", tmp_ds, ds);
7895 if (ds) ID3D11DomainShader_Release(tmp_ds);
7896 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7897 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7898 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7899 ID3D11ShaderResourceView_Release(tmp_srv);
7901 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7902 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7903 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7904 ID3D11SamplerState_Release(tmp_sampler);
7905 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7906 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7907 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7908 ID3D11Buffer_Release(tmp_cb);
7909 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7910 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7911 ok(tmp_cs == cs, "Got shader %p, expected %p.\n", tmp_cs, cs);
7912 if (cs) ID3D11ComputeShader_Release(tmp_cs);
7913 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7914 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7915 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7916 ID3D11ShaderResourceView_Release(tmp_srv);
7917 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7918 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7919 ok(tmp_uav == uav, "Got uav %p, expected %p.\n", tmp_uav, uav);
7920 ID3D11UnorderedAccessView_Release(tmp_uav);
7922 topo = 0xdeadbeef;
7923 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7924 ok(topo == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got topology %#x, expected %#x.\n", topo, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7925 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7926 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7927 ok(tmp_il == il, "Got input layout %p, expected %p.\n", tmp_il, il);
7928 ID3D11InputLayout_Release(tmp_il);
7929 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7930 format = 0xdeadbeef;
7931 offset = 0xdeadbeef;
7932 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7933 ok(tmp_ib == ib, "Got input buffer %p, expected %p.\n", tmp_ib, ib);
7934 ID3D11Buffer_Release(tmp_ib);
7935 ok(format == DXGI_FORMAT_R32_UINT, "Got input buffer format %#x, expected %#x.\n", format, DXGI_FORMAT_R32_UINT);
7936 ok(offset == 16, "Got input buffer offset %#x, expected 16.\n", offset);
7937 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7938 stride = 0xdeadbeef;
7939 offset = 0xdeadbeef;
7940 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7941 ok(tmp_vb == vb, "Got vertex buffer %p, expected %p.\n", tmp_vb, vb);
7942 ID3D11Buffer_Release(tmp_vb);
7943 ok(stride == 16, "Got vertex buffer stride %#x, expected 16.\n", stride);
7944 ok(offset == 16, "Got vertex buffer offset %#x, expected 16.\n", offset);
7946 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7947 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7948 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7949 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7950 ok(tmp_rtv == rtv, "Got rendertarget view %p, expected %p.\n", tmp_rtv, rtv);
7951 ID3D11RenderTargetView_Release(tmp_rtv);
7952 ok(tmp_dsv == dsv, "Got depth/stencil view %p, expected %p.\n", tmp_dsv, dsv);
7953 ID3D11DepthStencilView_Release(tmp_dsv);
7954 ok(tmp_uav == ps_uav, "Got unordered access view %p, expected %p.\n", tmp_uav, ps_uav);
7955 ID3D11UnorderedAccessView_Release(tmp_uav);
7956 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7957 memset(blend_factor, 0xcd, sizeof(blend_factor));
7958 sample_mask = 0xdeadbeef;
7959 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7960 ok(tmp_bs == bs, "Got blend state %p, expected %p.\n", tmp_bs, bs);
7961 ID3D11BlendState_Release(tmp_bs);
7962 ok(!memcmp(blend_factor, custom_blend_factor, sizeof(blend_factor)),
7963 "Got blend factor %f,%f,%f,%f, expected %f,%f,%f,%f.\n",
7964 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3],
7965 custom_blend_factor[0], custom_blend_factor[1], custom_blend_factor[2], custom_blend_factor[3]);
7966 ok(sample_mask == 0xff00ff00, "Got sample mask %#x, expected %#x.\n", sample_mask, 0xff00ff00);
7967 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7968 stencil_ref = 0xdeadbeef;
7969 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7970 ok(tmp_dss == dss, "Got depth/stencil state %p, expected %p.\n", tmp_dss, dss);
7971 ID3D11DepthStencilState_Release(tmp_dss);
7972 ok(stencil_ref == 3, "Got stencil ref %#x, expected 3.\n", stencil_ref);
7974 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7975 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7976 ok(tmp_rs == rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7977 ID3D11RasterizerState_Release(tmp_rs);
7978 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7979 count = 2;
7980 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7981 ok(count == 1, "Got viewport count %u, expected 1.\n", count);
7982 ok(!memcmp(tmp_vp, &vp, sizeof(vp)), "Got viewport %s, expected %s.\n",
7983 debugstr_viewport(tmp_vp), debugstr_viewport(&vp));
7984 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7985 count = 2;
7986 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7987 ok(count == 1, "Got scissor rect count %u, expected 1.\n", count);
7988 ok(!memcmp(tmp_rect, &rect, sizeof(rect)), "Got scissor rect %s, expected %s.\n",
7989 wine_dbgstr_rect(tmp_rect), wine_dbgstr_rect(&rect));
7991 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7992 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7993 ok(tmp_sob == sob, "Got stream output buffer %p, expected %p.\n", tmp_sob, sob);
7994 ID3D11Buffer_Release(tmp_sob);
7996 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7997 pred_value = 0xdeadbeef;
7998 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7999 ok(tmp_pred == pred, "Got predicate %p, expected %p.\n", tmp_pred, pred);
8000 ID3D11Predicate_Release(tmp_pred);
8001 ok(pred_value == TRUE, "Got predicate value %#x, expected TRUE.\n", pred_value);
8003 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
8004 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
8006 ID3D11Predicate_Release(pred);
8007 ID3D11Buffer_Release(sob);
8008 ID3D11RasterizerState_Release(rs);
8009 ID3D11BlendState_Release(bs);
8010 ID3D11DepthStencilState_Release(dss);
8011 ID3D11DepthStencilView_Release(dsv);
8012 ID3D11RenderTargetView_Release(rtv);
8013 ID3D11UnorderedAccessView_Release(ps_uav);
8014 ID3D11InputLayout_Release(il);
8015 ID3D11Buffer_Release(ib);
8016 ID3D11Buffer_Release(vb);
8017 if (cs) ID3D11ComputeShader_Release(cs);
8018 if (ds) ID3D11DomainShader_Release(ds);
8019 if (hs) ID3D11HullShader_Release(hs);
8020 ID3D11PixelShader_Release(ps);
8021 ID3D11GeometryShader_Release(gs);
8022 ID3D11VertexShader_Release(vs);
8023 ID3D11Buffer_Release(cb);
8024 ID3D11ShaderResourceView_Release(srv);
8025 ID3D11UnorderedAccessView_Release(uav);
8026 ID3D11SamplerState_Release(sampler);
8027 ID3D11DeviceContext1_Release(context);
8028 refcount = ID3D11Device1_Release(device);
8029 ok(!refcount, "Device has %u references left.\n", refcount);
8032 static void test_blend(void)
8034 ID3D11BlendState *src_blend, *dst_blend, *dst_blend_factor;
8035 struct d3d11_test_context test_context;
8036 ID3D11RenderTargetView *offscreen_rtv;
8037 D3D11_TEXTURE2D_DESC texture_desc;
8038 ID3D11InputLayout *input_layout;
8039 ID3D11DeviceContext *context;
8040 D3D11_BLEND_DESC blend_desc;
8041 unsigned int stride, offset;
8042 ID3D11Texture2D *offscreen;
8043 ID3D11VertexShader *vs;
8044 ID3D11PixelShader *ps;
8045 ID3D11Device *device;
8046 ID3D11Buffer *vb;
8047 DWORD color;
8048 HRESULT hr;
8050 static const DWORD vs_code[] =
8052 #if 0
8053 struct vs_out
8055 float4 position : SV_POSITION;
8056 float4 color : COLOR;
8059 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
8061 struct vs_out o;
8063 o.position = position;
8064 o.color = color;
8066 return o;
8068 #endif
8069 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
8070 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
8071 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8072 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
8073 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
8074 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
8075 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
8076 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
8077 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
8078 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
8080 static const DWORD ps_code[] =
8082 #if 0
8083 struct vs_out
8085 float4 position : SV_POSITION;
8086 float4 color : COLOR;
8089 float4 main(struct vs_out i) : SV_TARGET
8091 return i.color;
8093 #endif
8094 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
8095 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8096 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
8097 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
8098 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8099 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
8100 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
8101 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8103 static const struct
8105 struct vec3 position;
8106 DWORD diffuse;
8108 quads[] =
8110 /* quad1 */
8111 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
8112 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
8113 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
8114 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
8115 /* quad2 */
8116 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
8117 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
8118 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
8119 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
8121 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8123 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8124 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
8126 static const float blend_factor[] = {0.3f, 0.4f, 0.8f, 0.9f};
8127 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8129 if (!init_test_context(&test_context, NULL))
8130 return;
8132 device = test_context.device;
8133 context = test_context.immediate_context;
8135 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8136 vs_code, sizeof(vs_code), &input_layout);
8137 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8139 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
8141 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
8142 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8143 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8144 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8146 memset(&blend_desc, 0, sizeof(blend_desc));
8147 blend_desc.RenderTarget[0].BlendEnable = TRUE;
8148 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
8149 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
8150 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
8151 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
8152 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
8153 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
8154 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
8156 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
8157 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8159 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
8160 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
8161 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
8162 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
8164 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
8165 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8167 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_BLEND_FACTOR;
8168 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_BLEND_FACTOR;
8169 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
8170 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
8172 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend_factor);
8173 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8175 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
8176 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8177 stride = sizeof(*quads);
8178 offset = 0;
8179 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
8180 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
8181 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8183 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8185 ID3D11DeviceContext_OMSetBlendState(context, src_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8186 ID3D11DeviceContext_Draw(context, 4, 0);
8187 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8188 ID3D11DeviceContext_Draw(context, 4, 4);
8190 color = get_texture_color(test_context.backbuffer, 320, 360);
8191 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
8192 color = get_texture_color(test_context.backbuffer, 320, 120);
8193 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
8195 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8197 ID3D11DeviceContext_OMSetBlendState(context, dst_blend_factor, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
8198 ID3D11DeviceContext_Draw(context, 4, 0);
8199 ID3D11DeviceContext_Draw(context, 4, 4);
8201 color = get_texture_color(test_context.backbuffer, 320, 360);
8202 ok(compare_color(color, 0x600066b3, 1), "Got unexpected color 0x%08x.\n", color);
8203 color = get_texture_color(test_context.backbuffer, 320, 120);
8204 ok(compare_color(color, 0xa0cc00b3, 1), "Got unexpected color 0x%08x.\n", color);
8206 texture_desc.Width = 128;
8207 texture_desc.Height = 128;
8208 texture_desc.MipLevels = 1;
8209 texture_desc.ArraySize = 1;
8210 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
8211 texture_desc.SampleDesc.Count = 1;
8212 texture_desc.SampleDesc.Quality = 0;
8213 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8214 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
8215 texture_desc.CPUAccessFlags = 0;
8216 texture_desc.MiscFlags = 0;
8218 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
8219 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
8221 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
8222 goto done;
8225 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
8226 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8228 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
8230 set_viewport(context, 0.0f, 0.0f, 128.0f, 128.0f, 0.0f, 1.0f);
8232 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
8234 ID3D11DeviceContext_OMSetBlendState(context, src_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8235 ID3D11DeviceContext_Draw(context, 4, 0);
8236 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8237 ID3D11DeviceContext_Draw(context, 4, 4);
8239 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
8240 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
8241 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
8242 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
8244 ID3D11RenderTargetView_Release(offscreen_rtv);
8245 ID3D11Texture2D_Release(offscreen);
8246 done:
8247 ID3D11BlendState_Release(dst_blend_factor);
8248 ID3D11BlendState_Release(dst_blend);
8249 ID3D11BlendState_Release(src_blend);
8250 ID3D11PixelShader_Release(ps);
8251 ID3D11VertexShader_Release(vs);
8252 ID3D11Buffer_Release(vb);
8253 ID3D11InputLayout_Release(input_layout);
8254 release_test_context(&test_context);
8257 static void test_texture1d(void)
8259 struct shader
8261 const DWORD *code;
8262 size_t size;
8264 struct texture
8266 UINT width;
8267 UINT miplevel_count;
8268 UINT array_size;
8269 DXGI_FORMAT format;
8270 D3D11_SUBRESOURCE_DATA data[3];
8273 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8274 struct d3d11_test_context test_context;
8275 const struct texture *current_texture;
8276 D3D11_TEXTURE1D_DESC texture_desc;
8277 D3D11_SAMPLER_DESC sampler_desc;
8278 const struct shader *current_ps;
8279 D3D_FEATURE_LEVEL feature_level;
8280 ID3D11ShaderResourceView *srv;
8281 ID3D11DeviceContext *context;
8282 ID3D11SamplerState *sampler;
8283 struct resource_readback rb;
8284 ID3D11Texture1D *texture;
8285 struct vec4 ps_constant;
8286 ID3D11PixelShader *ps;
8287 ID3D11Device *device;
8288 unsigned int i, x;
8289 ID3D11Buffer *cb;
8290 DWORD color;
8291 HRESULT hr;
8293 static const DWORD ps_ld_code[] =
8295 #if 0
8296 Texture1D t;
8298 float miplevel;
8300 float4 main(float4 position : SV_POSITION) : SV_TARGET
8302 float2 p;
8303 t.GetDimensions(miplevel, p.x, p.y);
8304 p.y = miplevel;
8305 p *= float2(position.x / 640.0f, 1.0f);
8306 return t.Load(int2(p));
8308 #endif
8309 0x43425844, 0x7b0c6359, 0x598178f6, 0xef2ddbdb, 0x88fc794c, 0x00000001, 0x000001ac, 0x00000003,
8310 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8311 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8312 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8313 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
8314 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001058, 0x00107000, 0x00000000,
8315 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8316 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
8317 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
8318 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000e2,
8319 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
8320 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
8321 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
8322 0x00107e46, 0x00000000, 0x0100003e,
8324 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
8325 static const DWORD ps_ld_sint8_code[] =
8327 #if 0
8328 Texture1D<int4> t;
8330 float4 main(float4 position : SV_POSITION) : SV_TARGET
8332 float2 p, s;
8333 int4 c;
8335 p = float2(position.x / 640.0f, 0.0f);
8336 t.GetDimensions(0, s.x, s.y);
8337 p *= s;
8339 c = t.Load(int2(p));
8340 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
8342 #endif
8343 0x43425844, 0x65a13d1e, 0x8a0bfc92, 0xa2f2708a, 0x0bafafb6, 0x00000001, 0x00000234, 0x00000003,
8344 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8345 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8346 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8347 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000198, 0x00000040,
8348 0x00000066, 0x04001058, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101012, 0x00000000,
8349 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8350 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
8351 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
8352 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
8353 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8354 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0500002b,
8355 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
8356 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204, 0x3c010204, 0x0a000034, 0x001000f2,
8357 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000, 0xbf800000, 0xbf800000, 0xbf800000,
8358 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
8359 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002,
8360 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
8362 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
8363 static const DWORD ps_ld_uint8_code[] =
8365 #if 0
8366 Texture1D<uint4> t;
8368 float4 main(float4 position : SV_POSITION) : SV_TARGET
8370 float2 p, s;
8372 p = float2(position.x / 640.0f, 0.0f);
8373 t.GetDimensions(0, s.x, s.y);
8374 p *= s;
8376 return t.Load(int2(p)) / (float4)255;
8378 #endif
8379 0x43425844, 0x35186c1f, 0x55bad4fd, 0xb7c97a57, 0x99c060e7, 0x00000001, 0x000001bc, 0x00000003,
8380 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8381 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8382 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8383 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000120, 0x00000040,
8384 0x00000048, 0x04001058, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101012, 0x00000000,
8385 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8386 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
8387 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
8388 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
8389 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8390 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x05000056,
8391 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46,
8392 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081, 0x3b808081, 0x0100003e,
8394 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
8395 static DWORD ps_ld_array_code[] =
8397 #if 0
8398 Texture1DArray t;
8400 float miplevel;
8402 float4 main(float4 position : SV_POSITION) : SV_TARGET
8404 float3 p;
8405 t.GetDimensions(miplevel, p.x, p.y, p.z);
8406 p.y = 1;
8407 p.z = miplevel;
8408 p *= float3(position.x / 640.0f, 1.0f, 1.0f);
8409 return t.Load(int3(p));
8411 #endif
8412 0x43425844, 0xbfccadc4, 0xc00ff13d, 0x2ba75365, 0xf747cbee, 0x00000001, 0x000001c0, 0x00000003,
8413 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8414 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8415 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8416 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000124, 0x00000040,
8417 0x00000049, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003858, 0x00107000, 0x00000000,
8418 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8419 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
8420 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
8421 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000c2,
8422 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x00100072, 0x00000000, 0x00100386,
8423 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x00000000, 0x0500001b, 0x001000d2,
8424 0x00000000, 0x00100906, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000001,
8425 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
8427 static const struct shader ps_ld_array = {ps_ld_array_code, sizeof(ps_ld_array_code)};
8429 static const DWORD rgba_level_0[] =
8431 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8433 static const DWORD rgba_level_1[] =
8435 0xffffffff, 0xff0000ff,
8437 static const DWORD rgba_level_2[] =
8439 0xffff0000,
8441 static const DWORD srgb_data[] =
8443 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
8445 static const DWORD r32_uint[] =
8447 0, 1, 2, 3,
8449 static const DWORD r9g9b9e5_data[] =
8451 0x80000100, 0x80020000, 0x84000000, 0x84000100,
8453 static const DWORD array_data0[] =
8455 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8457 static const DWORD array_data1[] =
8459 0x00ffff00, 0xff000000, 0x00ff0000, 0x000000ff,
8461 static const DWORD array_data2[] =
8463 0x000000ff, 0xffff00ff, 0x0000ff00, 0xff000000,
8465 static const struct texture rgba_texture =
8467 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
8469 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
8470 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
8471 {rgba_level_2, sizeof(*rgba_level_2), 0},
8474 static const struct texture srgb_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
8475 {{srgb_data, 4 * sizeof(*srgb_data)}}};
8476 static const struct texture sint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
8477 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
8478 static const struct texture uint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
8479 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
8480 static const struct texture r32u_typeless = {4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
8481 {{r32_uint, 4 * sizeof(*r32_uint)}}};
8482 static const struct texture r9g9b9e5_texture = {4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
8483 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
8484 static const struct texture array_texture = {4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
8486 {array_data0, 4 * sizeof(*array_data0)},
8487 {array_data1, 4 * sizeof(*array_data1)},
8488 {array_data2, 4 * sizeof(*array_data2)},
8492 static const DWORD level_1_colors[] =
8494 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
8496 static const DWORD level_2_colors[] =
8498 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
8500 static const DWORD srgb_colors[] =
8502 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
8504 static const DWORD sint8_colors[] =
8506 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
8508 static const DWORD r32u_colors[4] =
8510 0x01000000, 0x01000001, 0x01000002, 0x01000003,
8512 static const DWORD r9g9b9e5_colors[4] =
8514 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
8516 static const DWORD zero_colors[4] = {0};
8517 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8518 static const struct texture_test
8520 const struct shader *ps;
8521 const struct texture *texture;
8522 D3D11_FILTER filter;
8523 float lod_bias;
8524 float min_lod;
8525 float max_lod;
8526 float ps_constant;
8527 const DWORD *expected_colors;
8529 texture_tests[] =
8531 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
8532 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
8533 #define MIP_MAX D3D11_FLOAT32_MAX
8534 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
8535 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
8536 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
8537 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
8538 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
8539 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
8540 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
8541 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
8542 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
8543 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
8544 {&ps_ld_array, &array_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, array_data1},
8546 #undef POINT
8547 #undef POINT_LINEAR
8548 #undef MIP_MAX
8549 static const struct srv_test
8551 const struct shader *ps;
8552 const struct texture *texture;
8553 struct srv_desc srv_desc;
8554 float ps_constant;
8555 const DWORD *expected_colors;
8557 srv_tests[] =
8559 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
8560 #define R32_UINT DXGI_FORMAT_R32_UINT
8561 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_1D, 0, 1}, 0.0f, r32u_colors},
8562 #undef TEX_1D
8563 #undef R32_UINT
8564 #undef FMT_UNKNOWN
8567 if (!init_test_context(&test_context, NULL))
8568 return;
8570 device = test_context.device;
8571 context = test_context.immediate_context;
8572 feature_level = ID3D11Device_GetFeatureLevel(device);
8574 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
8576 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8578 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8579 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
8580 texture_desc.CPUAccessFlags = 0;
8581 texture_desc.MiscFlags = 0;
8583 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8584 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8585 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8586 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8587 sampler_desc.MipLODBias = 0.0f;
8588 sampler_desc.MaxAnisotropy = 0;
8589 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8590 sampler_desc.BorderColor[0] = 0.0f;
8591 sampler_desc.BorderColor[1] = 0.0f;
8592 sampler_desc.BorderColor[2] = 0.0f;
8593 sampler_desc.BorderColor[3] = 0.0f;
8594 sampler_desc.MinLOD = 0.0f;
8595 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
8597 ps = NULL;
8598 srv = NULL;
8599 sampler = NULL;
8600 texture = NULL;
8601 current_ps = NULL;
8602 current_texture = NULL;
8603 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
8605 const struct texture_test *test = &texture_tests[i];
8607 if (current_ps != test->ps)
8609 if (ps)
8610 ID3D11PixelShader_Release(ps);
8612 current_ps = test->ps;
8614 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
8615 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
8617 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8620 if (current_texture != test->texture)
8622 if (texture)
8623 ID3D11Texture1D_Release(texture);
8624 if (srv)
8625 ID3D11ShaderResourceView_Release(srv);
8627 current_texture = test->texture;
8629 if (current_texture)
8631 texture_desc.Width = current_texture->width;
8632 texture_desc.MipLevels = current_texture->miplevel_count;
8633 texture_desc.ArraySize = current_texture->array_size;
8634 texture_desc.Format = current_texture->format;
8636 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
8637 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
8639 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
8640 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
8642 else
8644 texture = NULL;
8645 srv = NULL;
8648 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8651 if (!sampler || (sampler_desc.Filter != test->filter
8652 || sampler_desc.MipLODBias != test->lod_bias
8653 || sampler_desc.MinLOD != test->min_lod
8654 || sampler_desc.MaxLOD != test->max_lod))
8656 if (sampler)
8657 ID3D11SamplerState_Release(sampler);
8659 sampler_desc.Filter = test->filter;
8660 sampler_desc.MipLODBias = test->lod_bias;
8661 sampler_desc.MinLOD = test->min_lod;
8662 sampler_desc.MaxLOD = test->max_lod;
8664 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
8665 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
8667 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8670 ps_constant.x = test->ps_constant;
8671 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
8673 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8675 draw_quad(&test_context);
8677 get_texture_readback(test_context.backbuffer, 0, &rb);
8678 for (x = 0; x < 4; ++x)
8680 color = get_readback_color(&rb, 80 + x * 160, 0, 0);
8681 ok(compare_color(color, test->expected_colors[x], 2),
8682 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
8684 release_resource_readback(&rb);
8686 if (srv)
8687 ID3D11ShaderResourceView_Release(srv);
8688 ID3D11SamplerState_Release(sampler);
8689 if (texture)
8690 ID3D11Texture1D_Release(texture);
8691 ID3D11PixelShader_Release(ps);
8693 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
8695 win_skip("SRV tests are broken on WARP.\n");
8696 ID3D11Buffer_Release(cb);
8697 release_test_context(&test_context);
8698 return;
8701 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8702 sampler_desc.MipLODBias = 0.0f;
8703 sampler_desc.MinLOD = 0.0f;
8704 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
8706 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
8707 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8709 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8711 ps = NULL;
8712 srv = NULL;
8713 texture = NULL;
8714 current_ps = NULL;
8715 current_texture = NULL;
8716 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
8718 const struct srv_test *test = &srv_tests[i];
8720 if (current_ps != test->ps)
8722 if (ps)
8723 ID3D11PixelShader_Release(ps);
8725 current_ps = test->ps;
8727 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
8728 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
8730 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8733 if (current_texture != test->texture)
8735 if (texture)
8736 ID3D11Texture1D_Release(texture);
8738 current_texture = test->texture;
8740 texture_desc.Width = current_texture->width;
8741 texture_desc.MipLevels = current_texture->miplevel_count;
8742 texture_desc.ArraySize = current_texture->array_size;
8743 texture_desc.Format = current_texture->format;
8745 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
8746 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
8749 if (srv)
8750 ID3D11ShaderResourceView_Release(srv);
8752 get_srv_desc(&srv_desc, &test->srv_desc);
8753 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
8754 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
8756 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8758 ps_constant.x = test->ps_constant;
8759 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
8761 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8763 draw_quad(&test_context);
8765 get_texture_readback(test_context.backbuffer, 0, &rb);
8766 for (x = 0; x < 4; ++x)
8768 color = get_readback_color(&rb, 80 + x * 160, 0, 0);
8769 ok(compare_color(color, test->expected_colors[x], 1),
8770 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
8772 release_resource_readback(&rb);
8774 ID3D11PixelShader_Release(ps);
8775 ID3D11Texture1D_Release(texture);
8776 ID3D11ShaderResourceView_Release(srv);
8777 ID3D11SamplerState_Release(sampler);
8779 ID3D11Buffer_Release(cb);
8780 release_test_context(&test_context);
8783 static void test_texture(void)
8785 struct shader
8787 const DWORD *code;
8788 size_t size;
8790 struct texture
8792 UINT width;
8793 UINT height;
8794 UINT miplevel_count;
8795 UINT array_size;
8796 DXGI_FORMAT format;
8797 D3D11_SUBRESOURCE_DATA data[3];
8800 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8801 struct d3d11_test_context test_context;
8802 const struct texture *current_texture;
8803 D3D11_TEXTURE2D_DESC texture_desc;
8804 D3D11_SAMPLER_DESC sampler_desc;
8805 const struct shader *current_ps;
8806 D3D_FEATURE_LEVEL feature_level;
8807 ID3D11ShaderResourceView *srv;
8808 ID3D11DeviceContext *context;
8809 ID3D11SamplerState *sampler;
8810 struct resource_readback rb;
8811 ID3D11Texture2D *texture;
8812 struct vec4 ps_constant;
8813 ID3D11PixelShader *ps;
8814 ID3D11Device *device;
8815 unsigned int i, x, y;
8816 ID3D11Buffer *cb;
8817 DWORD color;
8818 HRESULT hr;
8820 static const DWORD ps_ld_code[] =
8822 #if 0
8823 Texture2D t;
8825 float miplevel;
8827 float4 main(float4 position : SV_POSITION) : SV_TARGET
8829 float3 p;
8830 t.GetDimensions(miplevel, p.x, p.y, p.z);
8831 p.z = miplevel;
8832 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
8833 return t.Load(int3(p));
8835 #endif
8836 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
8837 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8838 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8839 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8840 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
8841 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
8842 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8843 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
8844 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
8845 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
8846 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
8847 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
8848 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
8849 0x00107e46, 0x00000000, 0x0100003e,
8851 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
8852 static const DWORD ps_ld_sint8_code[] =
8854 #if 0
8855 Texture2D<int4> t;
8857 float4 main(float4 position : SV_POSITION) : SV_TARGET
8859 float3 p, s;
8860 int4 c;
8862 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
8863 t.GetDimensions(0, s.x, s.y, s.z);
8864 p *= s;
8866 c = t.Load(int3(p));
8867 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
8869 #endif
8870 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
8871 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8872 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8873 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8874 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
8875 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
8876 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8877 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
8878 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
8879 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
8880 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
8881 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8882 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
8883 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
8884 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
8885 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8886 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
8887 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
8889 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
8890 static const DWORD ps_ld_uint8_code[] =
8892 #if 0
8893 Texture2D<uint4> t;
8895 float4 main(float4 position : SV_POSITION) : SV_TARGET
8897 float3 p, s;
8899 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
8900 t.GetDimensions(0, s.x, s.y, s.z);
8901 p *= s;
8903 return t.Load(int3(p)) / (float4)255;
8905 #endif
8906 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
8907 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8908 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8909 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8910 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
8911 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
8912 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8913 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
8914 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
8915 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
8916 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
8917 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8918 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
8919 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
8920 0x3b808081, 0x0100003e,
8922 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
8923 static const DWORD ps_sample_code[] =
8925 #if 0
8926 Texture2D t;
8927 SamplerState s;
8929 float4 main(float4 position : SV_POSITION) : SV_Target
8931 float2 p;
8933 p.x = position.x / 640.0f;
8934 p.y = position.y / 480.0f;
8935 return t.Sample(s, p);
8937 #endif
8938 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
8939 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8940 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8941 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8942 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
8943 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8944 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
8945 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8946 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
8947 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
8949 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
8950 static const DWORD ps_sample_b_code[] =
8952 #if 0
8953 Texture2D t;
8954 SamplerState s;
8956 float bias;
8958 float4 main(float4 position : SV_POSITION) : SV_Target
8960 float2 p;
8962 p.x = position.x / 640.0f;
8963 p.y = position.y / 480.0f;
8964 return t.SampleBias(s, p, bias);
8966 #endif
8967 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
8968 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8969 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8970 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8971 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
8972 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
8973 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
8974 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
8975 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
8976 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
8977 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
8979 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
8980 static const DWORD ps_sample_l_code[] =
8982 #if 0
8983 Texture2D t;
8984 SamplerState s;
8986 float level;
8988 float4 main(float4 position : SV_POSITION) : SV_Target
8990 float2 p;
8992 p.x = position.x / 640.0f;
8993 p.y = position.y / 480.0f;
8994 return t.SampleLevel(s, p, level);
8996 #endif
8997 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
8998 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8999 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9000 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9001 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
9002 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9003 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9004 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
9005 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
9006 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
9007 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
9009 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
9010 static const DWORD ps_sample_2d_array_code[] =
9012 #if 0
9013 Texture2DArray t;
9014 SamplerState s;
9016 float layer;
9018 float4 main(float4 position : SV_POSITION) : SV_TARGET
9020 float3 d;
9021 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
9022 t.GetDimensions(d.x, d.y, d.z);
9023 d.z = layer;
9024 return t.Sample(s, p * d);
9026 #endif
9027 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
9028 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9029 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9030 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9031 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
9032 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9033 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9034 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
9035 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
9036 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
9037 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
9038 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
9039 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9041 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
9042 static const DWORD red_data[] =
9044 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9045 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9046 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9047 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9049 static const DWORD green_data[] =
9051 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9052 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9053 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9054 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9056 static const DWORD blue_data[] =
9058 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9059 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9060 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9061 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9063 static const DWORD rgba_level_0[] =
9065 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9066 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9067 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9068 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9070 static const DWORD rgba_level_1[] =
9072 0xffffffff, 0xff0000ff,
9073 0xff000000, 0xff00ff00,
9075 static const DWORD rgba_level_2[] =
9077 0xffff0000,
9079 static const DWORD srgb_data[] =
9081 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
9082 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
9083 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
9084 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
9086 static const WORD r8g8_data[] =
9088 0x0000, 0xffff, 0x0000, 0x7fff,
9089 0x0203, 0xff10, 0x0b0c, 0x8000,
9090 0xc4de, 0xfff0, 0xfdfe, 0x5a6f,
9091 0xff00, 0xffc8, 0x00aa, 0xdd5b,
9093 static const BYTE a8_data[] =
9095 0x00, 0x10, 0x20, 0x30,
9096 0x40, 0x50, 0x60, 0x70,
9097 0x80, 0x90, 0xa0, 0xb0,
9098 0xc0, 0xd0, 0xe0, 0xf0,
9100 static const BYTE bc1_data[] =
9102 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
9103 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
9104 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
9105 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
9107 static const BYTE bc2_data[] =
9109 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
9110 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
9111 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
9112 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
9114 static const BYTE bc3_data[] =
9116 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
9117 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
9118 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
9119 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
9121 static const BYTE bc4_data[] =
9123 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
9124 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
9125 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
9126 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
9128 static const BYTE bc5_data[] =
9130 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
9131 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
9132 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
9133 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
9135 static const BYTE bc6h_u_data[] =
9137 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9138 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9139 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9140 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9142 static const BYTE bc6h_s_data[] =
9144 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9145 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9146 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9147 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9149 static const BYTE bc7_data[] =
9151 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9152 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9153 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9154 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
9156 static const float r32_float[] =
9158 0.0f, 1.0f, 0.5f, 0.50f,
9159 1.0f, 0.0f, 0.0f, 0.75f,
9160 0.0f, 1.0f, 0.5f, 0.25f,
9161 1.0f, 0.0f, 0.0f, 0.75f,
9163 static const DWORD r32_uint[] =
9165 0, 1, 2, 3,
9166 100, 200, 255, 128,
9167 40, 30, 20, 10,
9168 250, 210, 155, 190,
9170 static const DWORD r9g9b9e5_data[] =
9172 0x80000100, 0x80020000, 0x84000000, 0x84000100,
9173 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
9174 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
9175 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
9177 static const struct texture rgba_texture =
9179 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
9181 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
9182 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
9183 {rgba_level_2, sizeof(*rgba_level_2), 0},
9186 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
9187 {{srgb_data, 4 * sizeof(*srgb_data)}}};
9188 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
9189 {{srgb_data, 4 * sizeof(*srgb_data)}}};
9190 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
9191 {{a8_data, 4 * sizeof(*a8_data)}}};
9192 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
9193 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
9194 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
9195 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
9196 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
9197 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
9198 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
9199 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
9200 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
9201 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
9202 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
9203 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
9204 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
9205 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
9206 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
9207 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
9208 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
9209 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
9210 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
9211 static const struct texture array_2d_texture =
9213 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
9215 {red_data, 6 * sizeof(*red_data)},
9216 {green_data, 4 * sizeof(*green_data)},
9217 {blue_data, 5 * sizeof(*blue_data)},
9220 static const struct texture r32f_float = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
9221 {{r32_float, 4 * sizeof(*r32_float)}}};
9222 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
9223 {{r32_float, 4 * sizeof(*r32_float)}}};
9224 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
9225 {{r32_uint, 4 * sizeof(*r32_uint)}}};
9226 static const struct texture r8g8_snorm = {4, 4, 1, 1, DXGI_FORMAT_R8G8_SNORM,
9227 {{r8g8_data, 4 * sizeof(*r8g8_data)}}};
9228 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
9229 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
9230 static const DWORD red_colors[] =
9232 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9233 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9234 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9235 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9237 static const DWORD blue_colors[] =
9239 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9240 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9241 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9242 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9244 static const DWORD level_1_colors[] =
9246 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
9247 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
9248 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
9249 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
9251 static const DWORD lerp_1_2_colors[] =
9253 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
9254 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
9255 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
9256 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
9258 static const DWORD level_2_colors[] =
9260 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9261 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9262 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9263 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9265 static const DWORD srgb_colors[] =
9267 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
9268 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
9269 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
9270 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
9272 static const DWORD a8_colors[] =
9274 0x00000000, 0x10000000, 0x20000000, 0x30000000,
9275 0x40000000, 0x50000000, 0x60000000, 0x70000000,
9276 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
9277 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
9279 static const DWORD bc_colors[] =
9281 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
9282 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
9283 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
9284 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
9286 static const DWORD bc4_colors[] =
9288 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
9289 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
9290 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
9291 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
9293 static const DWORD bc5_colors[] =
9295 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
9296 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
9297 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
9298 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
9300 static const DWORD bc7_colors[] =
9302 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
9303 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
9304 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
9305 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
9307 static const DWORD sint8_colors[] =
9309 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
9310 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
9311 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
9312 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
9314 static const DWORD snorm_colors[] =
9316 0xff000000, 0xff000000, 0xff000000, 0xff00ff00,
9317 0xff000406, 0xff000020, 0xff001618, 0xff000000,
9318 0xff000000, 0xff000000, 0xff000000, 0xff00b5df,
9319 0xff000000, 0xff000000, 0xff000000, 0xff0000b7,
9321 static const DWORD r32f_colors[] =
9323 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
9324 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
9325 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
9326 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
9328 static const DWORD r32u_colors[16] =
9330 0x01000000, 0x01000001, 0x01000002, 0x01000003,
9331 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
9332 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
9333 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
9335 static const DWORD r9g9b9e5_colors[16] =
9337 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
9338 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
9339 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
9340 0xff000033, 0xff003300, 0xff330000, 0xff333333,
9342 static const DWORD zero_colors[4 * 4] = {0};
9343 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9345 static const struct texture_test
9347 const struct shader *ps;
9348 const struct texture *texture;
9349 D3D11_FILTER filter;
9350 float lod_bias;
9351 float min_lod;
9352 float max_lod;
9353 float ps_constant;
9354 const DWORD *expected_colors;
9356 texture_tests[] =
9358 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
9359 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
9360 #define MIP_MAX D3D11_FLOAT32_MAX
9361 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
9362 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
9363 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
9364 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
9365 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
9366 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9367 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9368 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9369 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9370 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9371 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9372 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9373 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9374 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9375 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
9376 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
9377 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9378 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9379 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9380 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9381 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
9382 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9383 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9384 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
9385 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
9386 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9387 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9388 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9389 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
9390 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
9391 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9392 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9393 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9394 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9395 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
9396 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9397 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9398 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
9399 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
9400 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
9401 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
9402 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9403 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9404 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9405 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
9406 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
9407 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
9408 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
9409 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
9410 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
9411 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
9412 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
9413 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
9414 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9415 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9416 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9417 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
9418 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
9419 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9420 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
9421 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
9422 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
9423 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
9424 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
9425 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
9426 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
9427 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
9428 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
9429 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
9430 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
9431 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
9432 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
9433 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
9434 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
9435 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
9436 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
9437 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
9438 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
9439 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
9440 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
9441 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
9442 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
9443 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
9444 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
9445 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
9446 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
9447 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
9448 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
9449 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
9450 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
9451 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
9452 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
9453 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
9454 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
9455 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
9456 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
9457 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
9458 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
9459 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
9460 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9461 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9462 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
9463 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9464 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
9465 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
9466 #undef POINT
9467 #undef POINT_LINEAR
9468 #undef MIP_MAX
9470 static const struct srv_test
9472 const struct shader *ps;
9473 const struct texture *texture;
9474 struct srv_desc srv_desc;
9475 float ps_constant;
9476 const DWORD *expected_colors;
9478 srv_tests[] =
9480 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
9481 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
9482 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
9483 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
9484 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
9485 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
9486 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
9487 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
9488 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
9489 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
9490 #define R8G8_SNORM DXGI_FORMAT_R8G8_SNORM
9491 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
9492 #define R32_UINT DXGI_FORMAT_R32_UINT
9493 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
9494 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
9495 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
9496 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
9497 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
9498 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
9499 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
9500 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
9501 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
9502 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
9503 {&ps_sample, &r32f_float, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
9504 {&ps_sample, &r8g8_snorm, {R8G8_SNORM, TEX_2D, 0, 1}, 0.0f, snorm_colors},
9505 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
9506 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
9507 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
9508 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
9509 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
9510 #undef TEX_2D
9511 #undef TEX_2D_ARRAY
9512 #undef BC1_UNORM
9513 #undef BC1_UNORM_SRGB
9514 #undef BC2_UNORM
9515 #undef BC2_UNORM_SRGB
9516 #undef BC3_UNORM
9517 #undef BC3_UNORM_SRGB
9518 #undef R8G8B8A8_UNORM_SRGB
9519 #undef R8G8B8A8_UNORM
9520 #undef R8G8_SNORM
9521 #undef R32_FLOAT
9522 #undef R32_UINT
9523 #undef FMT_UNKNOWN
9526 if (!init_test_context(&test_context, NULL))
9527 return;
9529 device = test_context.device;
9530 context = test_context.immediate_context;
9531 feature_level = ID3D11Device_GetFeatureLevel(device);
9533 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
9535 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9537 texture_desc.SampleDesc.Count = 1;
9538 texture_desc.SampleDesc.Quality = 0;
9539 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9540 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
9541 texture_desc.CPUAccessFlags = 0;
9542 texture_desc.MiscFlags = 0;
9544 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9545 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
9546 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
9547 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
9548 sampler_desc.MipLODBias = 0.0f;
9549 sampler_desc.MaxAnisotropy = 0;
9550 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
9551 sampler_desc.BorderColor[0] = 0.0f;
9552 sampler_desc.BorderColor[1] = 0.0f;
9553 sampler_desc.BorderColor[2] = 0.0f;
9554 sampler_desc.BorderColor[3] = 0.0f;
9555 sampler_desc.MinLOD = 0.0f;
9556 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
9558 ps = NULL;
9559 srv = NULL;
9560 sampler = NULL;
9561 texture = NULL;
9562 current_ps = NULL;
9563 current_texture = NULL;
9564 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
9566 const struct texture_test *test = &texture_tests[i];
9568 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
9569 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
9570 && feature_level < D3D_FEATURE_LEVEL_11_0)
9572 skip("Feature level >= 11.0 is required for BC7 tests.\n");
9573 continue;
9576 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
9577 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
9578 && feature_level < D3D_FEATURE_LEVEL_11_0)
9580 skip("Feature level >= 11.0 is required for BC6H tests.\n");
9581 continue;
9584 if (current_ps != test->ps)
9586 if (ps)
9587 ID3D11PixelShader_Release(ps);
9589 current_ps = test->ps;
9591 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
9592 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
9594 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9597 if (current_texture != test->texture)
9599 if (texture)
9600 ID3D11Texture2D_Release(texture);
9601 if (srv)
9602 ID3D11ShaderResourceView_Release(srv);
9604 current_texture = test->texture;
9606 if (current_texture)
9608 texture_desc.Width = current_texture->width;
9609 texture_desc.Height = current_texture->height;
9610 texture_desc.MipLevels = current_texture->miplevel_count;
9611 texture_desc.ArraySize = current_texture->array_size;
9612 texture_desc.Format = current_texture->format;
9614 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
9615 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9617 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
9618 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
9620 else
9622 texture = NULL;
9623 srv = NULL;
9626 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
9629 if (!sampler || (sampler_desc.Filter != test->filter
9630 || sampler_desc.MipLODBias != test->lod_bias
9631 || sampler_desc.MinLOD != test->min_lod
9632 || sampler_desc.MaxLOD != test->max_lod))
9634 if (sampler)
9635 ID3D11SamplerState_Release(sampler);
9637 sampler_desc.Filter = test->filter;
9638 sampler_desc.MipLODBias = test->lod_bias;
9639 sampler_desc.MinLOD = test->min_lod;
9640 sampler_desc.MaxLOD = test->max_lod;
9642 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
9643 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
9645 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9648 ps_constant.x = test->ps_constant;
9649 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
9651 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9653 draw_quad(&test_context);
9655 get_texture_readback(test_context.backbuffer, 0, &rb);
9656 for (y = 0; y < 4; ++y)
9658 for (x = 0; x < 4; ++x)
9660 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
9661 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
9662 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
9665 release_resource_readback(&rb);
9667 if (srv)
9668 ID3D11ShaderResourceView_Release(srv);
9669 ID3D11SamplerState_Release(sampler);
9670 if (texture)
9671 ID3D11Texture2D_Release(texture);
9672 ID3D11PixelShader_Release(ps);
9674 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
9676 win_skip("SRV tests are broken on WARP.\n");
9677 ID3D11Buffer_Release(cb);
9678 release_test_context(&test_context);
9679 return;
9682 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9683 sampler_desc.MipLODBias = 0.0f;
9684 sampler_desc.MinLOD = 0.0f;
9685 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
9687 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
9688 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9690 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9692 ps = NULL;
9693 srv = NULL;
9694 texture = NULL;
9695 current_ps = NULL;
9696 current_texture = NULL;
9697 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
9699 const struct srv_test *test = &srv_tests[i];
9701 if (current_ps != test->ps)
9703 if (ps)
9704 ID3D11PixelShader_Release(ps);
9706 current_ps = test->ps;
9708 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
9709 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
9711 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9714 if (current_texture != test->texture)
9716 if (texture)
9717 ID3D11Texture2D_Release(texture);
9719 current_texture = test->texture;
9721 texture_desc.Width = current_texture->width;
9722 texture_desc.Height = current_texture->height;
9723 texture_desc.MipLevels = current_texture->miplevel_count;
9724 texture_desc.ArraySize = current_texture->array_size;
9725 texture_desc.Format = current_texture->format;
9727 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
9728 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9731 if (srv)
9732 ID3D11ShaderResourceView_Release(srv);
9734 get_srv_desc(&srv_desc, &test->srv_desc);
9735 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
9736 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
9738 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
9740 ps_constant.x = test->ps_constant;
9741 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
9743 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9745 draw_quad(&test_context);
9747 get_texture_readback(test_context.backbuffer, 0, &rb);
9748 for (y = 0; y < 4; ++y)
9750 for (x = 0; x < 4; ++x)
9752 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
9753 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
9754 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
9757 release_resource_readback(&rb);
9759 ID3D11PixelShader_Release(ps);
9760 ID3D11Texture2D_Release(texture);
9761 ID3D11ShaderResourceView_Release(srv);
9762 ID3D11SamplerState_Release(sampler);
9764 ID3D11Buffer_Release(cb);
9765 release_test_context(&test_context);
9768 static void test_cube_maps(void)
9770 struct shader
9772 const DWORD *code;
9773 size_t size;
9776 unsigned int i, j, sub_resource_idx, sub_resource_count;
9777 struct d3d11_test_context test_context;
9778 D3D11_TEXTURE2D_DESC texture_desc;
9779 const struct shader *current_ps;
9780 D3D_FEATURE_LEVEL feature_level;
9781 ID3D11ShaderResourceView *srv;
9782 ID3D11DeviceContext *context;
9783 ID3D11Texture2D *rtv_texture;
9784 ID3D11RenderTargetView *rtv;
9785 struct vec4 expected_result;
9786 ID3D11Resource *texture;
9787 ID3D11PixelShader *ps;
9788 ID3D11Device *device;
9789 float data[64 * 64];
9790 ID3D11Buffer *cb;
9791 HRESULT hr;
9792 RECT rect;
9793 struct
9795 unsigned int face;
9796 unsigned int level;
9797 unsigned int cube;
9798 unsigned int padding;
9799 } constant;
9801 static const DWORD ps_cube_code[] =
9803 #if 0
9804 TextureCube t;
9805 SamplerState s;
9807 uint face;
9808 uint level;
9810 float4 main(float4 position : SV_POSITION) : SV_Target
9812 float2 p;
9813 p.x = position.x / 640.0f;
9814 p.y = position.y / 480.0f;
9816 float3 coord;
9817 switch (face)
9819 case 0:
9820 coord = float3(1.0f, p.x, p.y);
9821 break;
9822 case 1:
9823 coord = float3(-1.0f, p.x, p.y);
9824 break;
9825 case 2:
9826 coord = float3(p.x, 1.0f, p.y);
9827 break;
9828 case 3:
9829 coord = float3(p.x, -1.0f, p.y);
9830 break;
9831 case 4:
9832 coord = float3(p.x, p.y, 1.0f);
9833 break;
9834 case 5:
9835 default:
9836 coord = float3(p.x, p.y, -1.0f);
9837 break;
9839 return t.SampleLevel(s, coord, level);
9841 #endif
9842 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
9843 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9844 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9845 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9846 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
9847 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9848 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9849 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
9850 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
9851 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
9852 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
9853 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
9854 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
9855 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
9856 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
9857 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
9858 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
9859 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
9860 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
9861 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
9862 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9863 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
9864 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
9865 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
9866 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
9868 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
9869 static const DWORD ps_cube_array_code[] =
9871 #if 0
9872 TextureCubeArray t;
9873 SamplerState s;
9875 uint face;
9876 uint level;
9877 uint cube;
9879 float4 main(float4 position : SV_POSITION) : SV_Target
9881 float2 p;
9882 p.x = position.x / 640.0f;
9883 p.y = position.y / 480.0f;
9885 float3 coord;
9886 switch (face)
9888 case 0:
9889 coord = float3(1.0f, p.x, p.y);
9890 break;
9891 case 1:
9892 coord = float3(-1.0f, p.x, p.y);
9893 break;
9894 case 2:
9895 coord = float3(p.x, 1.0f, p.y);
9896 break;
9897 case 3:
9898 coord = float3(p.x, -1.0f, p.y);
9899 break;
9900 case 4:
9901 coord = float3(p.x, p.y, 1.0f);
9902 break;
9903 case 5:
9904 default:
9905 coord = float3(p.x, p.y, -1.0f);
9906 break;
9908 return t.SampleLevel(s, float4(coord, cube), level);
9910 #endif
9911 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
9912 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9913 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9914 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9915 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
9916 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
9917 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
9918 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
9919 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
9920 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
9921 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
9922 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
9923 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
9924 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
9925 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
9926 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
9927 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
9928 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
9929 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9930 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
9931 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
9932 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
9933 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
9934 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
9935 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
9936 0x00000001, 0x0100003e,
9938 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
9939 static const struct ps_test
9941 const struct shader *ps;
9942 unsigned int miplevel_count;
9943 unsigned int array_size;
9945 ps_tests[] =
9947 {&ps_cube, 1, 6},
9948 {&ps_cube, 2, 6},
9949 {&ps_cube, 3, 6},
9950 {&ps_cube, 0, 6},
9952 {&ps_cube_array, 1, 12},
9953 {&ps_cube_array, 2, 12},
9954 {&ps_cube_array, 3, 12},
9955 {&ps_cube_array, 0, 12},
9958 if (!init_test_context(&test_context, NULL))
9959 return;
9961 device = test_context.device;
9962 context = test_context.immediate_context;
9963 feature_level = ID3D11Device_GetFeatureLevel(device);
9965 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9966 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9967 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
9968 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9969 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
9970 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9972 memset(&constant, 0, sizeof(constant));
9973 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
9975 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9976 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9978 ps = NULL;
9979 current_ps = NULL;
9980 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
9982 const struct ps_test *test = &ps_tests[i];
9984 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
9986 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
9987 continue;
9990 if (current_ps != test->ps)
9992 if (ps)
9993 ID3D11PixelShader_Release(ps);
9995 current_ps = test->ps;
9997 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
9998 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
9999 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10002 if (!test->miplevel_count)
10004 srv = NULL;
10005 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10007 memset(&expected_result, 0, sizeof(expected_result));
10009 memset(&constant, 0, sizeof(constant));
10010 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10011 draw_quad(&test_context);
10012 check_texture_vec4(rtv_texture, &expected_result, 0);
10013 constant.level = 1;
10014 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10015 draw_quad(&test_context);
10016 check_texture_vec4(rtv_texture, &expected_result, 0);
10017 continue;
10020 texture_desc.Width = 64;
10021 texture_desc.Height = 64;
10022 texture_desc.MipLevels = test->miplevel_count;
10023 texture_desc.ArraySize = test->array_size;
10024 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
10025 texture_desc.SampleDesc.Count = 1;
10026 texture_desc.SampleDesc.Quality = 0;
10027 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10028 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
10029 texture_desc.CPUAccessFlags = 0;
10030 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
10031 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
10032 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
10034 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
10035 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
10036 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10038 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
10039 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
10041 for (j = 0; j < ARRAY_SIZE(data); ++j)
10042 data[j] = sub_resource_idx;
10043 ID3D11DeviceContext_UpdateSubresource(context, texture, sub_resource_idx, NULL, data,
10044 texture_desc.Width * sizeof(*data), 0);
10047 expected_result.y = expected_result.z = 0.0f;
10048 expected_result.w = 1.0f;
10049 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
10051 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
10052 constant.level = sub_resource_idx % texture_desc.MipLevels;
10053 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
10054 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10056 draw_quad(&test_context);
10057 expected_result.x = sub_resource_idx;
10058 /* Avoid testing values affected by seamless cube map filtering. */
10059 SetRect(&rect, 100, 100, 540, 380);
10060 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
10063 ID3D11Resource_Release(texture);
10064 ID3D11ShaderResourceView_Release(srv);
10066 ID3D11PixelShader_Release(ps);
10068 ID3D11Buffer_Release(cb);
10069 ID3D11RenderTargetView_Release(rtv);
10070 ID3D11Texture2D_Release(rtv_texture);
10071 release_test_context(&test_context);
10074 static void test_depth_stencil_sampling(void)
10076 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
10077 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
10078 ID3D11SamplerState *cmp_sampler, *sampler;
10079 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10080 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
10081 struct d3d11_test_context test_context;
10082 ID3D11Texture2D *texture, *rt_texture;
10083 D3D11_TEXTURE2D_DESC texture_desc;
10084 D3D11_SAMPLER_DESC sampler_desc;
10085 ID3D11DeviceContext *context;
10086 ID3D11DepthStencilView *dsv;
10087 ID3D11RenderTargetView *rtv;
10088 struct vec4 ps_constant;
10089 ID3D11Device *device;
10090 ID3D11Buffer *cb;
10091 unsigned int i;
10092 HRESULT hr;
10094 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
10095 static const DWORD ps_compare_code[] =
10097 #if 0
10098 Texture2D t;
10099 SamplerComparisonState s;
10101 float ref;
10103 float4 main(float4 position : SV_Position) : SV_Target
10105 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
10107 #endif
10108 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
10109 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10110 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10111 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10112 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
10113 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
10114 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
10115 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
10116 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
10117 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
10118 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
10119 0x0100003e,
10121 static const DWORD ps_sample_code[] =
10123 #if 0
10124 Texture2D t;
10125 SamplerState s;
10127 float4 main(float4 position : SV_Position) : SV_Target
10129 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
10131 #endif
10132 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
10133 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10134 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10135 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10136 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
10137 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10138 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10139 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10140 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
10141 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
10143 static const DWORD ps_stencil_code[] =
10145 #if 0
10146 Texture2D<uint4> t;
10148 float4 main(float4 position : SV_Position) : SV_Target
10150 float2 s;
10151 t.GetDimensions(s.x, s.y);
10152 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
10154 #endif
10155 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
10156 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10157 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10158 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10159 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
10160 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
10161 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
10162 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
10163 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
10164 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
10165 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
10166 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
10167 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
10169 static const DWORD ps_depth_stencil_code[] =
10171 #if 0
10172 SamplerState samp;
10173 Texture2D depth_tex;
10174 Texture2D<uint4> stencil_tex;
10176 float main(float4 position: SV_Position) : SV_Target
10178 float2 s, p;
10179 float depth, stencil;
10180 depth_tex.GetDimensions(s.x, s.y);
10181 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
10182 depth = depth_tex.Sample(samp, p).r;
10183 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
10184 return depth + stencil;
10186 #endif
10187 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
10188 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10189 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10190 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10191 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
10192 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10193 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
10194 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
10195 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
10196 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
10197 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
10198 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
10199 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
10200 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
10201 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
10202 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
10204 static const struct test
10206 DXGI_FORMAT typeless_format;
10207 DXGI_FORMAT dsv_format;
10208 DXGI_FORMAT depth_view_format;
10209 DXGI_FORMAT stencil_view_format;
10211 tests[] =
10213 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
10214 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
10215 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
10216 DXGI_FORMAT_R32_FLOAT},
10217 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
10218 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
10219 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
10220 DXGI_FORMAT_R16_UNORM},
10223 if (!init_test_context(&test_context, NULL))
10224 return;
10226 device = test_context.device;
10227 context = test_context.immediate_context;
10229 if (is_amd_device(device))
10231 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
10232 win_skip("Some AMD drivers have a bug affecting the test.\n");
10233 release_test_context(&test_context);
10234 return;
10237 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
10238 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10239 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10240 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10241 sampler_desc.MipLODBias = 0.0f;
10242 sampler_desc.MaxAnisotropy = 0;
10243 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
10244 sampler_desc.BorderColor[0] = 0.0f;
10245 sampler_desc.BorderColor[1] = 0.0f;
10246 sampler_desc.BorderColor[2] = 0.0f;
10247 sampler_desc.BorderColor[3] = 0.0f;
10248 sampler_desc.MinLOD = 0.0f;
10249 sampler_desc.MaxLOD = 0.0f;
10250 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
10251 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10253 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
10254 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
10255 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
10256 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10258 texture_desc.Width = 640;
10259 texture_desc.Height = 480;
10260 texture_desc.MipLevels = 1;
10261 texture_desc.ArraySize = 1;
10262 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
10263 texture_desc.SampleDesc.Count = 1;
10264 texture_desc.SampleDesc.Quality = 0;
10265 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10266 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10267 texture_desc.CPUAccessFlags = 0;
10268 texture_desc.MiscFlags = 0;
10269 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
10270 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10271 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
10272 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
10273 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10275 memset(&ps_constant, 0, sizeof(ps_constant));
10276 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
10277 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10279 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
10280 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10281 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
10282 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10283 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
10284 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10285 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
10286 &ps_depth_stencil);
10287 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10289 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10291 texture_desc.Format = tests[i].typeless_format;
10292 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
10293 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10294 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
10295 texture_desc.Format, hr);
10297 dsv_desc.Format = tests[i].dsv_format;
10298 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
10299 dsv_desc.Flags = 0;
10300 U(dsv_desc).Texture2D.MipSlice = 0;
10301 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10302 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
10303 dsv_desc.Format, hr);
10305 srv_desc.Format = tests[i].depth_view_format;
10306 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
10307 U(srv_desc).Texture2D.MostDetailedMip = 0;
10308 U(srv_desc).Texture2D.MipLevels = 1;
10309 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
10310 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
10311 srv_desc.Format, hr);
10313 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
10314 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
10315 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
10317 ps_constant.x = 0.5f;
10318 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10319 NULL, &ps_constant, 0, 0);
10321 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10322 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10323 draw_quad(&test_context);
10324 check_texture_float(rt_texture, 0.0f, 2);
10326 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
10327 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10328 draw_quad(&test_context);
10329 check_texture_float(rt_texture, 1.0f, 2);
10331 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
10332 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10333 draw_quad(&test_context);
10334 check_texture_float(rt_texture, 0.0f, 2);
10336 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
10337 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10338 draw_quad(&test_context);
10339 check_texture_float(rt_texture, 0.0f, 2);
10341 ps_constant.x = 0.7f;
10342 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10343 NULL, &ps_constant, 0, 0);
10345 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10346 draw_quad(&test_context);
10347 check_texture_float(rt_texture, 1.0f, 2);
10349 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
10350 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10352 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10353 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10354 draw_quad(&test_context);
10355 check_texture_float(rt_texture, 1.0f, 2);
10357 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
10358 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10359 draw_quad(&test_context);
10360 check_texture_float(rt_texture, 0.2f, 2);
10362 if (!tests[i].stencil_view_format)
10364 ID3D11DepthStencilView_Release(dsv);
10365 ID3D11ShaderResourceView_Release(depth_srv);
10366 ID3D11Texture2D_Release(texture);
10367 continue;
10370 srv_desc.Format = tests[i].stencil_view_format;
10371 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
10372 if (hr == E_OUTOFMEMORY)
10374 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
10375 ID3D11DepthStencilView_Release(dsv);
10376 ID3D11ShaderResourceView_Release(depth_srv);
10377 ID3D11Texture2D_Release(texture);
10378 continue;
10380 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
10381 srv_desc.Format, hr);
10383 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
10384 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
10386 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
10387 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10388 draw_quad(&test_context);
10389 check_texture_float(rt_texture, 0.0f, 0);
10391 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
10392 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10393 draw_quad(&test_context);
10394 check_texture_float(rt_texture, 100.0f, 0);
10396 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
10397 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10398 draw_quad(&test_context);
10399 check_texture_float(rt_texture, 255.0f, 0);
10401 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
10402 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
10403 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
10405 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
10406 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10407 draw_quad(&test_context);
10408 check_texture_float(rt_texture, 3.3f, 2);
10410 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
10411 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10412 draw_quad(&test_context);
10413 check_texture_float(rt_texture, 4.0f, 2);
10415 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
10416 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10417 draw_quad(&test_context);
10418 check_texture_float(rt_texture, 0.0f, 2);
10420 ID3D11DepthStencilView_Release(dsv);
10421 ID3D11ShaderResourceView_Release(depth_srv);
10422 ID3D11ShaderResourceView_Release(stencil_srv);
10423 ID3D11Texture2D_Release(texture);
10426 ID3D11Buffer_Release(cb);
10427 ID3D11PixelShader_Release(ps_cmp);
10428 ID3D11PixelShader_Release(ps_depth);
10429 ID3D11PixelShader_Release(ps_depth_stencil);
10430 ID3D11PixelShader_Release(ps_stencil);
10431 ID3D11RenderTargetView_Release(rtv);
10432 ID3D11SamplerState_Release(cmp_sampler);
10433 ID3D11SamplerState_Release(sampler);
10434 ID3D11Texture2D_Release(rt_texture);
10435 release_test_context(&test_context);
10438 static void test_sample_c_lz(void)
10440 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10441 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
10442 struct d3d11_test_context test_context;
10443 ID3D11Texture2D *texture, *rt_texture;
10444 D3D11_TEXTURE2D_DESC texture_desc;
10445 D3D11_SAMPLER_DESC sampler_desc;
10446 ID3D11ShaderResourceView *srv;
10447 ID3D11DeviceContext *context;
10448 ID3D11DepthStencilView *dsv;
10449 ID3D11RenderTargetView *rtv;
10450 ID3D11SamplerState *sampler;
10451 struct vec4 ps_constant;
10452 ID3D11PixelShader *ps;
10453 ID3D11Device *device;
10454 ID3D11Buffer *cb;
10455 unsigned int i;
10456 HRESULT hr;
10457 RECT rect;
10459 static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
10460 static const DWORD ps_array_code[] =
10462 #if 0
10463 Texture2DArray t;
10464 SamplerComparisonState s;
10466 float ref;
10467 float layer;
10469 float4 main(float4 position : SV_Position) : SV_Target
10471 return t.SampleCmpLevelZero(s, float3(position.x / 640.0f, position.y / 480.0f, layer), ref);
10473 #endif
10474 0x43425844, 0xfe28b3c3, 0xdd7ef404, 0x8d5874a1, 0x984ff182, 0x00000001, 0x00000180, 0x00000003,
10475 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10476 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10477 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10478 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000e4, 0x00000041,
10479 0x00000039, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
10480 0x00000000, 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
10481 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
10482 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
10483 0x06000036, 0x00100042, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0c000047, 0x00100012,
10484 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000, 0x0020800a,
10485 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
10487 static const DWORD ps_cube_code[] =
10489 #if 0
10490 TextureCube t;
10491 SamplerComparisonState s;
10493 float ref;
10494 float face;
10496 float4 main(float4 position : SV_Position) : SV_Target
10498 float2 p;
10499 p.x = position.x / 640.0f;
10500 p.y = position.y / 480.0f;
10502 float3 coord;
10503 switch ((uint)face)
10505 case 0:
10506 coord = float3(1.0f, p.x, p.y);
10507 break;
10508 case 1:
10509 coord = float3(-1.0f, p.x, p.y);
10510 break;
10511 case 2:
10512 coord = float3(p.x, 1.0f, p.y);
10513 break;
10514 case 3:
10515 coord = float3(p.x, -1.0f, p.y);
10516 break;
10517 case 4:
10518 coord = float3(p.x, p.y, 1.0f);
10519 break;
10520 case 5:
10521 default:
10522 coord = float3(p.x, p.y, -1.0f);
10523 break;
10526 return t.SampleCmpLevelZero(s, coord, ref);
10528 #endif
10529 0x43425844, 0xde5655e5, 0x1b116fa1, 0xfce9e757, 0x41c28aac, 0x00000001, 0x00000328, 0x00000003,
10530 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10531 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10532 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10533 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
10534 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
10535 0x00000000, 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
10536 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012,
10537 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006,
10538 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038,
10539 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889,
10540 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000,
10541 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
10542 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002,
10543 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000,
10544 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
10545 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
10546 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
10547 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032,
10548 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
10549 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038,
10550 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000,
10551 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017,
10552 0x0c000047, 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000,
10553 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006,
10554 0x00000000, 0x0100003e,
10556 static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
10557 static const struct
10559 unsigned int layer;
10560 float d_ref;
10561 float expected;
10563 tests[] =
10565 {0, 0.5f, 0.0f},
10566 {1, 0.5f, 1.0f},
10567 {2, 0.5f, 0.0f},
10568 {3, 0.5f, 0.0f},
10569 {4, 0.5f, 1.0f},
10570 {5, 0.5f, 1.0f},
10572 {0, 0.0f, 0.0f},
10573 {1, 0.0f, 0.0f},
10574 {2, 0.0f, 0.0f},
10575 {3, 0.0f, 0.0f},
10576 {4, 0.0f, 0.0f},
10577 {5, 0.0f, 0.0f},
10579 {0, 1.0f, 0.0f},
10580 {1, 1.0f, 1.0f},
10581 {2, 1.0f, 1.0f},
10582 {3, 1.0f, 1.0f},
10583 {4, 1.0f, 1.0f},
10584 {5, 1.0f, 1.0f},
10587 if (!init_test_context(&test_context, NULL))
10588 return;
10590 device = test_context.device;
10591 context = test_context.immediate_context;
10593 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
10594 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10595 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10596 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10597 sampler_desc.MipLODBias = 0.0f;
10598 sampler_desc.MaxAnisotropy = 0;
10599 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
10600 sampler_desc.BorderColor[0] = 0.0f;
10601 sampler_desc.BorderColor[1] = 0.0f;
10602 sampler_desc.BorderColor[2] = 0.0f;
10603 sampler_desc.BorderColor[3] = 0.0f;
10604 sampler_desc.MinLOD = 0.0f;
10605 sampler_desc.MaxLOD = 10.0f;
10606 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
10607 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10609 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10610 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
10611 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
10612 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10613 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
10614 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10615 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10617 memset(&ps_constant, 0, sizeof(ps_constant));
10618 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
10620 /* 2D array texture */
10621 texture_desc.Width = 32;
10622 texture_desc.Height = 32;
10623 texture_desc.MipLevels = 2;
10624 texture_desc.ArraySize = ARRAY_SIZE(depth_values);
10625 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
10626 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
10627 texture_desc.MiscFlags = 0;
10628 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10629 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10631 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
10633 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
10634 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
10635 dsv_desc.Flags = 0;
10636 U(dsv_desc).Texture2DArray.MipSlice = 0;
10637 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
10638 U(dsv_desc).Texture2DArray.ArraySize = 1;
10640 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10641 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10642 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
10643 ID3D11DepthStencilView_Release(dsv);
10645 U(dsv_desc).Texture2DArray.MipSlice = 1;
10646 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10647 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10648 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10649 ID3D11DepthStencilView_Release(dsv);
10652 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
10653 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
10654 U(srv_desc).Texture2DArray.MostDetailedMip = 0;
10655 U(srv_desc).Texture2DArray.MipLevels = ~0u;
10656 U(srv_desc).Texture2DArray.FirstArraySlice = 0;
10657 U(srv_desc).Texture2DArray.ArraySize = ~0u;
10658 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
10659 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10661 hr = ID3D11Device_CreatePixelShader(device, ps_array_code, sizeof(ps_array_code), NULL, &ps);
10662 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10664 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10665 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10666 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10667 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10669 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10671 ps_constant.x = tests[i].d_ref;
10672 ps_constant.y = tests[i].layer;
10673 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10674 NULL, &ps_constant, 0, 0);
10675 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
10676 draw_quad(&test_context);
10677 check_texture_float(rt_texture, tests[i].expected, 2);
10680 ID3D11Texture2D_Release(texture);
10681 ID3D11ShaderResourceView_Release(srv);
10682 ID3D11PixelShader_Release(ps);
10684 /* cube texture */
10685 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
10686 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10687 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10689 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
10691 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
10692 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
10693 dsv_desc.Flags = 0;
10694 U(dsv_desc).Texture2DArray.MipSlice = 0;
10695 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
10696 U(dsv_desc).Texture2DArray.ArraySize = 1;
10698 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10699 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10700 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
10701 ID3D11DepthStencilView_Release(dsv);
10703 U(dsv_desc).Texture2DArray.MipSlice = 1;
10704 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10705 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10706 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10707 ID3D11DepthStencilView_Release(dsv);
10710 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
10711 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
10712 U(srv_desc).TextureCube.MostDetailedMip = 0;
10713 U(srv_desc).TextureCube.MipLevels = ~0u;
10714 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
10715 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10717 hr = ID3D11Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), NULL, &ps);
10718 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10720 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10721 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10722 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10723 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10725 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10727 ps_constant.x = tests[i].d_ref;
10728 ps_constant.y = tests[i].layer;
10729 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10730 NULL, &ps_constant, 0, 0);
10731 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
10732 draw_quad(&test_context);
10733 /* Avoid testing values affected by seamless cube map filtering. */
10734 SetRect(&rect, 100, 100, 540, 380);
10735 check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
10738 ID3D11Texture2D_Release(texture);
10739 ID3D11ShaderResourceView_Release(srv);
10741 ID3D11Buffer_Release(cb);
10742 ID3D11PixelShader_Release(ps);
10743 ID3D11RenderTargetView_Release(rtv);
10744 ID3D11SamplerState_Release(sampler);
10745 ID3D11Texture2D_Release(rt_texture);
10746 release_test_context(&test_context);
10749 static void test_multiple_render_targets(void)
10751 ID3D11RenderTargetView *rtv[4], *tmp_rtv[4];
10752 D3D11_TEXTURE2D_DESC texture_desc;
10753 ID3D11InputLayout *input_layout;
10754 unsigned int stride, offset, i;
10755 ID3D11DeviceContext *context;
10756 ID3D11Texture2D *rt[4];
10757 ID3D11VertexShader *vs;
10758 ID3D11PixelShader *ps;
10759 ID3D11Device *device;
10760 ID3D11Buffer *vb;
10761 ULONG refcount;
10762 HRESULT hr;
10764 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
10766 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10768 static const DWORD vs_code[] =
10770 #if 0
10771 float4 main(float4 position : POSITION) : SV_POSITION
10773 return position;
10775 #endif
10776 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
10777 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10778 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10779 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
10780 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
10781 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10782 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10784 static const DWORD ps_code[] =
10786 #if 0
10787 struct output
10789 float4 t1 : SV_TARGET0;
10790 float4 t2 : SV_Target1;
10791 float4 t3 : SV_TARGET2;
10792 float4 t4 : SV_Target3;
10795 output main(float4 position : SV_POSITION)
10797 struct output o;
10798 o.t1 = (float4)1.0f;
10799 o.t2 = (float4)0.5f;
10800 o.t3 = (float4)0.2f;
10801 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
10802 return o;
10804 #endif
10805 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
10806 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10807 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
10808 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
10809 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10810 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
10811 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
10812 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
10813 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
10814 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
10815 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
10816 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
10817 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
10818 0x3f800000, 0x0100003e,
10820 static const struct vec2 quad[] =
10822 {-1.0f, -1.0f},
10823 {-1.0f, 1.0f},
10824 { 1.0f, -1.0f},
10825 { 1.0f, 1.0f},
10827 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
10829 if (!(device = create_device(NULL)))
10831 skip("Failed to create device.\n");
10832 return;
10835 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10836 vs_code, sizeof(vs_code), &input_layout);
10837 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10839 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10841 texture_desc.Width = 640;
10842 texture_desc.Height = 480;
10843 texture_desc.MipLevels = 1;
10844 texture_desc.ArraySize = 1;
10845 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10846 texture_desc.SampleDesc.Count = 1;
10847 texture_desc.SampleDesc.Quality = 0;
10848 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10849 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10850 texture_desc.CPUAccessFlags = 0;
10851 texture_desc.MiscFlags = 0;
10853 for (i = 0; i < ARRAY_SIZE(rt); ++i)
10855 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
10856 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
10858 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
10859 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
10862 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
10863 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10864 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10865 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10867 ID3D11Device_GetImmediateContext(device, &context);
10869 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
10870 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
10871 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10872 stride = sizeof(*quad);
10873 offset = 0;
10874 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
10875 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
10876 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10878 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
10880 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
10881 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
10882 ID3D11DeviceContext_Draw(context, 4, 0);
10883 check_texture_color(rt[0], 0xffffffff, 2);
10884 check_texture_color(rt[1], 0x7f7f7f7f, 2);
10885 check_texture_color(rt[2], 0x33333333, 2);
10886 check_texture_color(rt[3], 0xff7f3300, 2);
10888 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
10889 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
10890 for (i = 0; i < ARRAY_SIZE(tmp_rtv); ++i)
10892 memset(tmp_rtv, 0, sizeof(tmp_rtv));
10893 tmp_rtv[i] = rtv[i];
10894 ID3D11DeviceContext_OMSetRenderTargets(context, 4, tmp_rtv, NULL);
10895 ID3D11DeviceContext_Draw(context, 4, 0);
10897 check_texture_color(rt[0], 0xffffffff, 2);
10898 check_texture_color(rt[1], 0x7f7f7f7f, 2);
10899 check_texture_color(rt[2], 0x33333333, 2);
10900 check_texture_color(rt[3], 0xff7f3300, 2);
10902 ID3D11Buffer_Release(vb);
10903 ID3D11PixelShader_Release(ps);
10904 ID3D11VertexShader_Release(vs);
10905 ID3D11InputLayout_Release(input_layout);
10906 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
10908 ID3D11RenderTargetView_Release(rtv[i]);
10909 ID3D11Texture2D_Release(rt[i]);
10911 ID3D11DeviceContext_Release(context);
10912 refcount = ID3D11Device_Release(device);
10913 ok(!refcount, "Device has %u references left.\n", refcount);
10916 static void test_render_target_views(void)
10918 struct texture
10920 UINT miplevel_count;
10921 UINT array_size;
10924 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
10925 static struct test
10927 struct texture texture;
10928 struct rtv_desc rtv;
10929 DWORD expected_colors[4];
10931 tests[] =
10933 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
10934 {0xff0000ff, 0x00000000}},
10935 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
10936 {0x00000000, 0xff0000ff}},
10937 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
10938 {0xff0000ff, 0x00000000}},
10939 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
10940 {0x00000000, 0xff0000ff}},
10941 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
10942 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
10943 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
10944 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
10945 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
10946 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
10947 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
10948 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
10949 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
10950 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
10951 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
10952 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
10953 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
10954 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
10955 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
10956 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
10957 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
10958 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
10959 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
10960 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
10961 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
10962 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
10964 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
10965 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
10966 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
10967 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
10968 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
10969 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
10970 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
10971 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
10972 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
10973 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
10974 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
10975 static const struct
10977 struct
10979 D3D11_RTV_DIMENSION dimension;
10980 unsigned int miplevel_count;
10981 unsigned int depth_or_array_size;
10982 DXGI_FORMAT format;
10983 } texture;
10984 struct rtv_desc rtv_desc;
10986 invalid_desc_tests[] =
10988 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
10989 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
10990 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
10991 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
10992 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
10993 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
10994 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
10995 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
10996 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
10997 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
10998 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
10999 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
11000 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
11001 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
11002 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
11003 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
11004 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
11005 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11006 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11007 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
11008 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
11009 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11010 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11011 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
11012 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
11013 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
11014 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
11015 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
11016 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
11017 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
11018 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
11019 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
11020 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
11021 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
11022 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
11023 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
11024 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
11026 #undef FMT_UNKNOWN
11027 #undef RGBA8_UNORM
11028 #undef RGBA8_SRGB
11029 #undef RGBA8_UINT
11030 #undef RGBA8_TL
11031 #undef DIM_UNKNOWN
11032 #undef TEX_1D
11033 #undef TEX_1D_ARRAY
11034 #undef TEX_2D
11035 #undef TEX_2D_ARRAY
11036 #undef TEX_3D
11038 struct d3d11_test_context test_context;
11039 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
11040 D3D11_TEXTURE3D_DESC texture3d_desc;
11041 D3D11_TEXTURE2D_DESC texture_desc;
11042 ID3D11DeviceContext *context;
11043 ID3D11RenderTargetView *rtv;
11044 ID3D11Texture3D *texture3d;
11045 ID3D11Texture2D *texture;
11046 ID3D11Resource *resource;
11047 ID3D11Device *device;
11048 unsigned int i, j, k;
11049 void *data;
11050 HRESULT hr;
11052 if (!init_test_context(&test_context, NULL))
11053 return;
11055 device = test_context.device;
11056 context = test_context.immediate_context;
11058 texture_desc.Width = 32;
11059 texture_desc.Height = 32;
11060 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11061 texture_desc.SampleDesc.Count = 1;
11062 texture_desc.SampleDesc.Quality = 0;
11063 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11064 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11065 texture_desc.CPUAccessFlags = 0;
11066 texture_desc.MiscFlags = 0;
11068 data = heap_alloc_zero(texture_desc.Width * texture_desc.Height * 4);
11069 ok(!!data, "Failed to allocate memory.\n");
11071 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11073 const struct test *test = &tests[i];
11074 unsigned int sub_resource_count;
11076 texture_desc.MipLevels = test->texture.miplevel_count;
11077 texture_desc.ArraySize = test->texture.array_size;
11079 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11080 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
11082 get_rtv_desc(&rtv_desc, &test->rtv);
11083 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11084 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
11086 for (j = 0; j < texture_desc.ArraySize; ++j)
11088 for (k = 0; k < texture_desc.MipLevels; ++k)
11090 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
11091 ID3D11DeviceContext_UpdateSubresource(context,
11092 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
11095 check_texture_color(texture, 0, 0);
11097 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11098 draw_color_quad(&test_context, &red);
11100 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
11101 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
11102 for (j = 0; j < sub_resource_count; ++j)
11103 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
11105 ID3D11RenderTargetView_Release(rtv);
11106 ID3D11Texture2D_Release(texture);
11109 texture3d_desc.Width = 32;
11110 texture3d_desc.Height = 32;
11111 texture3d_desc.Depth = 32;
11112 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11113 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
11114 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11115 texture3d_desc.CPUAccessFlags = 0;
11116 texture3d_desc.MiscFlags = 0;
11118 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
11120 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
11121 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
11123 if (invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
11125 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
11126 texture_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
11127 texture_desc.Format = invalid_desc_tests[i].texture.format;
11128 texture_desc.MiscFlags = 0;
11130 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11131 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
11132 resource = (ID3D11Resource *)texture;
11134 else
11136 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
11137 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
11138 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
11140 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
11141 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
11142 resource = (ID3D11Resource *)texture3d;
11145 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
11146 hr = ID3D11Device_CreateRenderTargetView(device, resource, &rtv_desc, &rtv);
11147 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
11149 ID3D11Resource_Release(resource);
11152 heap_free(data);
11153 release_test_context(&test_context);
11156 static void test_layered_rendering(void)
11158 struct
11160 unsigned int layer_offset;
11161 unsigned int draw_id;
11162 unsigned int padding[2];
11163 } constant;
11164 struct d3d11_test_context test_context;
11165 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
11166 unsigned int i, sub_resource_count;
11167 D3D11_TEXTURE2D_DESC texture_desc;
11168 ID3D11DeviceContext *context;
11169 ID3D11RenderTargetView *rtv;
11170 ID3D11Texture2D *texture;
11171 ID3D11GeometryShader *gs;
11172 ID3D11VertexShader *vs;
11173 ID3D11PixelShader *ps;
11174 ID3D11Device *device;
11175 ID3D11Buffer *cb;
11176 HRESULT hr;
11177 BOOL warp;
11179 static const DWORD vs_code[] =
11181 #if 0
11182 uint layer_offset;
11184 void main(float4 position : POSITION,
11185 out float4 out_position : SV_POSITION,
11186 out uint layer : SV_RenderTargetArrayIndex)
11188 out_position = position;
11189 layer = layer_offset;
11191 #endif
11192 0x43425844, 0x71f7b9cd, 0x2ab8c713, 0x53e77663, 0x54a9ba68, 0x00000001, 0x00000158, 0x00000004,
11193 0x00000030, 0x00000064, 0x000000cc, 0x00000148, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11194 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954,
11195 0xababab00, 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
11196 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001,
11197 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567,
11198 0x79617272, 0x65646e49, 0xabab0078, 0x52444853, 0x00000074, 0x00010040, 0x0000001d, 0x04000059,
11199 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2,
11200 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x05000036, 0x001020f2,
11201 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020800a, 0x00000000,
11202 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00002000, 0x00000000,
11204 static const DWORD gs_5_code[] =
11206 #if 0
11207 uint layer_offset;
11209 struct gs_in
11211 float4 pos : SV_Position;
11214 struct gs_out
11216 float4 pos : SV_Position;
11217 uint layer : SV_RenderTargetArrayIndex;
11220 [instance(4)]
11221 [maxvertexcount(3)]
11222 void main(triangle gs_in vin[3], in uint instance_id : SV_GSInstanceID,
11223 inout TriangleStream<gs_out> vout)
11225 gs_out o;
11226 o.layer = layer_offset + instance_id;
11227 for (uint i = 0; i < 3; ++i)
11229 o.pos = vin[i].pos;
11230 vout.Append(o);
11233 #endif
11234 0x43425844, 0xb52da162, 0x9a13d8ee, 0xf7c30b50, 0xe80bc2e7, 0x00000001, 0x00000218, 0x00000003,
11235 0x0000002c, 0x00000060, 0x000000d0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11236 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
11237 0x3547534f, 0x00000068, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
11238 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000004, 0x00000001,
11239 0x00000001, 0x00000e01, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472,
11240 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x58454853, 0x00000140, 0x00020050, 0x00000050,
11241 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
11242 0x00000000, 0x00000001, 0x0200005f, 0x00025000, 0x02000068, 0x00000001, 0x020000ce, 0x00000004,
11243 0x0100185d, 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
11244 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x00000003, 0x0700001e,
11245 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0002500a, 0x05000036, 0x00100022,
11246 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a,
11247 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000, 0x07000036, 0x001020f2,
11248 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001,
11249 0x0010000a, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x0700001e, 0x00100022, 0x00000000,
11250 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
11252 static const DWORD gs_4_code[] =
11254 #if 0
11255 uint layer_offset;
11257 struct gs_in
11259 float4 pos : SV_Position;
11262 struct gs_out
11264 float4 pos : SV_Position;
11265 uint layer : SV_RenderTargetArrayIndex;
11268 [maxvertexcount(12)]
11269 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
11271 gs_out o;
11272 for (uint instance_id = 0; instance_id < 4; ++instance_id)
11274 o.layer = layer_offset + instance_id;
11275 for (uint i = 0; i < 3; ++i)
11277 o.pos = vin[i].pos;
11278 vout.Append(o);
11280 vout.RestartStrip();
11283 #endif
11284 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
11285 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11286 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
11287 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11288 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
11289 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
11290 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
11291 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
11292 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
11293 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
11294 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
11295 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
11296 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
11297 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
11298 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
11299 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
11300 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
11301 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
11302 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
11304 static const DWORD ps_code[] =
11306 #if 0
11307 uint layer_offset;
11308 uint draw_id;
11310 float4 main(in float4 pos : SV_Position,
11311 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
11313 return float4(layer, draw_id, 0, 0);
11315 #endif
11316 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
11317 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
11318 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
11319 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
11320 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
11321 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
11322 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
11323 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
11324 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
11325 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
11326 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
11328 static const struct vec4 expected_values[] =
11330 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
11331 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
11332 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
11333 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
11335 static const struct vec4 vs_expected_value = {1.0f, 42.0f};
11337 if (!init_test_context(&test_context, NULL))
11338 return;
11340 device = test_context.device;
11341 context = test_context.immediate_context;
11343 warp = is_warp_device(device);
11345 memset(&constant, 0, sizeof(constant));
11346 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
11347 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
11348 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
11349 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11351 /* Geometry shader instancing seems broken on WARP. */
11352 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0 || warp)
11354 hr = ID3D11Device_CreateGeometryShader(device, gs_4_code, sizeof(gs_4_code), NULL, &gs);
11355 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
11357 else
11359 hr = ID3D11Device_CreateGeometryShader(device, gs_5_code, sizeof(gs_5_code), NULL, &gs);
11360 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
11362 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
11364 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11365 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11366 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11368 texture_desc.Width = 32;
11369 texture_desc.Height = 32;
11370 texture_desc.MipLevels = 3;
11371 texture_desc.ArraySize = 8;
11372 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11373 texture_desc.SampleDesc.Count = 1;
11374 texture_desc.SampleDesc.Quality = 0;
11375 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11376 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11377 texture_desc.CPUAccessFlags = 0;
11378 texture_desc.MiscFlags = 0;
11379 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11380 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11382 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11383 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11384 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11385 constant.layer_offset = 0;
11386 constant.draw_id = 0;
11387 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11388 draw_quad(&test_context);
11389 constant.layer_offset = 4;
11390 constant.draw_id = 1;
11391 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11392 draw_quad(&test_context);
11393 ID3D11RenderTargetView_Release(rtv);
11395 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11396 rtv_desc.Format = texture_desc.Format;
11397 U(rtv_desc).Texture2DArray.MipSlice = 0;
11398 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
11399 U(rtv_desc).Texture2DArray.ArraySize = 1;
11400 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11401 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11402 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11403 constant.layer_offset = 1;
11404 constant.draw_id = 2;
11405 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11406 draw_quad(&test_context);
11407 ID3D11RenderTargetView_Release(rtv);
11409 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11410 U(rtv_desc).Texture2DArray.MipSlice = 1;
11411 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
11412 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
11413 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11414 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11415 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11416 constant.layer_offset = 0;
11417 constant.draw_id = 3;
11418 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11419 draw_quad(&test_context);
11420 constant.layer_offset = 4;
11421 constant.draw_id = 3;
11422 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11423 draw_quad(&test_context);
11424 ID3D11RenderTargetView_Release(rtv);
11426 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11427 U(rtv_desc).Texture2DArray.MipSlice = 2;
11428 U(rtv_desc).Texture2DArray.ArraySize = 1;
11429 for (i = 0; i < texture_desc.ArraySize; ++i)
11431 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
11432 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11433 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11434 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11435 constant.layer_offset = 0;
11436 constant.draw_id = 4 + i;
11437 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11438 draw_quad(&test_context);
11439 ID3D11RenderTargetView_Release(rtv);
11442 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
11443 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
11444 for (i = 0; i < sub_resource_count; ++i)
11446 if (warp && (i == 3 || i == 4)) /* Broken on WARP. */
11447 continue;
11448 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
11451 /* layered rendering without GS */
11452 if (!check_viewport_array_index_from_any_shader_support(device))
11454 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11455 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11456 if (SUCCEEDED(hr))
11457 ID3D11VertexShader_Release(vs);
11458 skip("Viewport array index not supported in vertex shaders.\n");
11459 goto done;
11462 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
11464 constant.layer_offset = 1;
11465 constant.draw_id = 42;
11466 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11467 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11468 U(rtv_desc).Texture2DArray.MipSlice = 0;
11469 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
11470 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
11471 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11472 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
11473 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11474 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
11475 check_texture_sub_resource_vec4(texture,
11476 constant.layer_offset * texture_desc.MipLevels, NULL, &vs_expected_value, 1);
11477 ID3D11RenderTargetView_Release(rtv);
11479 done:
11480 ID3D11Texture2D_Release(texture);
11482 ID3D11Buffer_Release(cb);
11483 ID3D11GeometryShader_Release(gs);
11484 ID3D11PixelShader_Release(ps);
11485 release_test_context(&test_context);
11488 static void test_scissor(void)
11490 struct d3d11_test_context test_context;
11491 ID3D11DeviceContext *immediate_context;
11492 D3D11_RASTERIZER_DESC rs_desc;
11493 ID3D11RasterizerState *rs;
11494 D3D11_RECT scissor_rect;
11495 ID3D11Device *device;
11496 DWORD color;
11497 HRESULT hr;
11499 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
11500 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11502 if (!init_test_context(&test_context, NULL))
11503 return;
11505 device = test_context.device;
11506 immediate_context = test_context.immediate_context;
11508 rs_desc.FillMode = D3D11_FILL_SOLID;
11509 rs_desc.CullMode = D3D11_CULL_BACK;
11510 rs_desc.FrontCounterClockwise = FALSE;
11511 rs_desc.DepthBias = 0;
11512 rs_desc.DepthBiasClamp = 0.0f;
11513 rs_desc.SlopeScaledDepthBias = 0.0f;
11514 rs_desc.DepthClipEnable = TRUE;
11515 rs_desc.ScissorEnable = TRUE;
11516 rs_desc.MultisampleEnable = FALSE;
11517 rs_desc.AntialiasedLineEnable = FALSE;
11518 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
11519 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11521 SetRect(&scissor_rect, 160, 120, 480, 360);
11522 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
11524 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
11525 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
11527 draw_color_quad(&test_context, &green);
11528 color = get_texture_color(test_context.backbuffer, 320, 60);
11529 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11530 color = get_texture_color(test_context.backbuffer, 80, 240);
11531 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11532 color = get_texture_color(test_context.backbuffer, 320, 240);
11533 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11534 color = get_texture_color(test_context.backbuffer, 560, 240);
11535 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11536 color = get_texture_color(test_context.backbuffer, 320, 420);
11537 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11539 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
11540 ID3D11DeviceContext_RSSetState(immediate_context, rs);
11541 draw_color_quad(&test_context, &green);
11542 color = get_texture_color(test_context.backbuffer, 320, 60);
11543 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11544 color = get_texture_color(test_context.backbuffer, 80, 240);
11545 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11546 color = get_texture_color(test_context.backbuffer, 320, 240);
11547 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11548 color = get_texture_color(test_context.backbuffer, 560, 240);
11549 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11550 color = get_texture_color(test_context.backbuffer, 320, 420);
11551 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11553 ID3D11RasterizerState_Release(rs);
11554 release_test_context(&test_context);
11557 static void test_clear_state(void)
11559 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11560 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11562 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11564 #if 0
11565 float4 main(float4 pos : POSITION) : POSITION
11567 return pos;
11569 #endif
11570 static const DWORD simple_vs[] =
11572 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
11573 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11574 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11575 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11576 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
11577 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
11578 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11580 #if 0
11581 struct data
11583 float4 position : SV_Position;
11586 struct patch_constant_data
11588 float edges[3] : SV_TessFactor;
11589 float inside : SV_InsideTessFactor;
11592 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
11594 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
11595 output.inside = 1.0f;
11598 [domain("tri")]
11599 [outputcontrolpoints(3)]
11600 [partitioning("integer")]
11601 [outputtopology("triangle_ccw")]
11602 [patchconstantfunc("patch_constant")]
11603 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
11605 return input[i];
11608 [domain("tri")]
11609 void ds_main(patch_constant_data input,
11610 float3 tess_coord : SV_DomainLocation,
11611 const OutputPatch<data, 3> patch,
11612 out data output)
11614 output.position = tess_coord.x * patch[0].position
11615 + tess_coord.y * patch[1].position
11616 + tess_coord.z * patch[2].position;
11618 #endif
11619 static const DWORD simple_hs[] =
11621 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
11622 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11623 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
11624 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11625 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
11626 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
11627 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
11628 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
11629 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
11630 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
11631 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
11632 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
11633 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
11634 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
11635 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
11636 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
11637 0x00004001, 0x3f800000, 0x0100003e,
11639 static const DWORD simple_ds[] =
11641 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
11642 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11643 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
11644 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
11645 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
11646 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
11647 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
11648 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
11649 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
11650 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
11651 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
11652 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
11653 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
11654 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
11655 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
11657 #if 0
11658 struct gs_out
11660 float4 pos : SV_POSITION;
11663 [maxvertexcount(4)]
11664 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
11666 float offset = 0.1 * vin[0].w;
11667 gs_out v;
11669 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
11670 vout.Append(v);
11671 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
11672 vout.Append(v);
11673 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
11674 vout.Append(v);
11675 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
11676 vout.Append(v);
11678 #endif
11679 static const DWORD simple_gs[] =
11681 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
11682 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11683 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11684 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
11685 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
11686 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
11687 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
11688 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
11689 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
11690 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
11691 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
11692 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
11693 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
11694 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
11695 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
11696 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
11697 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
11698 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
11700 #if 0
11701 float4 main(float4 color : COLOR) : SV_TARGET
11703 return color;
11705 #endif
11706 static const DWORD simple_ps[] =
11708 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
11709 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
11710 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
11711 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11712 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11713 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
11714 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11716 #if 0
11717 [numthreads(1, 1, 1)]
11718 void main() { }
11719 #endif
11720 static const DWORD simple_cs[] =
11722 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
11723 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11724 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
11725 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
11728 D3D11_VIEWPORT tmp_viewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
11729 ID3D11ShaderResourceView *tmp_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
11730 ID3D11ShaderResourceView *srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
11731 ID3D11RenderTargetView *tmp_rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11732 RECT tmp_rect[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
11733 ID3D11SamplerState *tmp_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
11734 ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11735 ID3D11Texture2D *rt_texture[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11736 ID3D11Buffer *cb[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
11737 ID3D11Buffer *tmp_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11738 ID3D11SamplerState *sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
11739 ID3D11UnorderedAccessView *tmp_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
11740 ID3D11UnorderedAccessView *cs_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
11741 ID3D11Buffer *buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11742 ID3D11Buffer *cs_uav_buffer[D3D11_PS_CS_UAV_REGISTER_COUNT];
11743 UINT offset[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11744 UINT stride[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11745 ID3D11Buffer *so_buffer[D3D11_SO_BUFFER_SLOT_COUNT];
11746 ID3D11InputLayout *tmp_input_layout, *input_layout;
11747 ID3D11DepthStencilState *tmp_ds_state, *ds_state;
11748 ID3D11BlendState *tmp_blend_state, *blend_state;
11749 ID3D11RasterizerState *tmp_rs_state, *rs_state;
11750 ID3D11Predicate *tmp_predicate, *predicate;
11751 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
11752 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
11753 ID3D11DepthStencilView *tmp_dsv, *dsv;
11754 ID3D11UnorderedAccessView *ps_uav;
11755 D3D11_PRIMITIVE_TOPOLOGY topology;
11756 D3D11_TEXTURE2D_DESC texture_desc;
11757 ID3D11GeometryShader *tmp_gs, *gs;
11758 ID3D11ComputeShader *tmp_cs, *cs;
11759 D3D11_DEPTH_STENCIL_DESC ds_desc;
11760 ID3D11VertexShader *tmp_vs, *vs;
11761 ID3D11DomainShader *tmp_ds, *ds;
11762 D3D11_SAMPLER_DESC sampler_desc;
11763 D3D11_QUERY_DESC predicate_desc;
11764 struct device_desc device_desc;
11765 ID3D11PixelShader *tmp_ps, *ps;
11766 ID3D11HullShader *tmp_hs, *hs;
11767 D3D11_RASTERIZER_DESC rs_desc;
11768 ID3D11DeviceContext *context;
11769 D3D11_BLEND_DESC blend_desc;
11770 ID3D11Texture2D *ds_texture;
11771 ID3D11Buffer *ps_uav_buffer;
11772 float blend_factor[4];
11773 ID3D11Device *device;
11774 BOOL predicate_value;
11775 UINT instance_count;
11776 DXGI_FORMAT format;
11777 UINT sample_mask;
11778 UINT stencil_ref;
11779 ULONG refcount;
11780 UINT count, i;
11781 HRESULT hr;
11783 device_desc.feature_level = &feature_level;
11784 device_desc.flags = 0;
11785 if (!(device = create_device(&device_desc)))
11787 skip("Failed to create device.\n");
11788 return;
11791 ID3D11Device_GetImmediateContext(device, &context);
11793 /* Verify the initial state after device creation. */
11795 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11796 tmp_buffer);
11797 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11799 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11801 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11802 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11804 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11806 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11807 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11809 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11811 instance_count = 100;
11812 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, &instance_count);
11813 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
11814 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11816 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11817 tmp_buffer);
11818 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11820 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11822 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11823 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11825 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11827 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11828 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11830 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11832 instance_count = 100;
11833 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, &instance_count);
11834 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
11835 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11837 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11838 tmp_buffer);
11839 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11841 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11843 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11844 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11846 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11848 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11849 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11851 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11853 instance_count = 100;
11854 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, &instance_count);
11855 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
11856 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11858 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11859 tmp_buffer);
11860 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11862 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11864 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11865 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11867 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11869 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11870 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11872 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11874 instance_count = 100;
11875 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, &instance_count);
11876 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
11877 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11879 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11880 tmp_buffer);
11881 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11883 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11885 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
11886 tmp_srv);
11887 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11889 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11891 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11892 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11894 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11896 instance_count = 100;
11897 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, &instance_count);
11898 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
11899 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11901 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11902 tmp_buffer);
11903 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11905 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11907 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
11908 tmp_srv);
11909 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11911 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11913 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11914 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11916 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11918 instance_count = 100;
11919 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, &instance_count);
11920 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
11921 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11922 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
11923 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
11925 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
11928 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
11929 tmp_buffer, stride, offset);
11930 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
11932 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
11933 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
11934 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
11936 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
11937 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
11938 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
11939 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
11940 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
11941 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
11942 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
11943 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
11945 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
11946 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
11947 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
11948 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
11949 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
11950 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
11951 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
11952 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
11953 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
11954 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
11955 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
11956 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
11958 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
11960 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
11961 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
11962 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
11963 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
11964 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
11966 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
11968 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
11969 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
11971 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
11974 if (!enable_debug_layer)
11976 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
11977 ok(!count, "Got unexpected scissor rect count %u.\n", count);
11979 memset(tmp_rect, 0x55, sizeof(tmp_rect));
11980 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
11981 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
11982 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
11984 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
11985 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
11987 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
11988 ok(!count, "Got unexpected viewport count %u.\n", count);
11989 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
11990 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
11991 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
11992 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
11994 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
11995 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
11996 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
11997 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
11998 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12000 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12001 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
12003 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12004 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12006 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
12009 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12010 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
12011 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12013 /* Create resources. */
12015 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12016 cb[i] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 1024, NULL);
12018 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12020 buffer[i] = create_buffer(device,
12021 D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE,
12022 1024, NULL);
12024 stride[i] = (i + 1) * 4;
12025 offset[i] = (i + 1) * 16;
12028 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12029 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
12031 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12032 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
12033 U(srv_desc).Buffer.ElementOffset = 0;
12034 U(srv_desc).Buffer.ElementWidth = 64;
12036 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12038 hr = ID3D11Device_CreateShaderResourceView(device,
12039 (ID3D11Resource *)buffer[i % D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
12040 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12043 uav_desc.Format = DXGI_FORMAT_R32_UINT;
12044 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
12045 U(uav_desc).Buffer.FirstElement = 0;
12046 U(uav_desc).Buffer.NumElements = 8;
12047 U(uav_desc).Buffer.Flags = 0;
12049 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12051 cs_uav_buffer[i] = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
12052 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_uav_buffer[i],
12053 &uav_desc, &cs_uav[i]);
12054 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12057 ps_uav_buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
12058 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_uav_buffer,
12059 &uav_desc, &ps_uav);
12060 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12062 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
12063 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
12064 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
12065 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
12066 sampler_desc.MipLODBias = 0.0f;
12067 sampler_desc.MaxAnisotropy = 16;
12068 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
12069 sampler_desc.BorderColor[0] = 0.0f;
12070 sampler_desc.BorderColor[1] = 0.0f;
12071 sampler_desc.BorderColor[2] = 0.0f;
12072 sampler_desc.BorderColor[3] = 0.0f;
12073 sampler_desc.MinLOD = 0.0f;
12074 sampler_desc.MaxLOD = 16.0f;
12076 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12078 sampler_desc.MinLOD = (float)i;
12080 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
12081 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
12084 hr = ID3D11Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
12085 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12087 hr = ID3D11Device_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
12088 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
12090 hr = ID3D11Device_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
12091 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
12093 hr = ID3D11Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
12094 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
12096 hr = ID3D11Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
12097 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12099 hr = ID3D11Device_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
12100 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
12102 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12103 simple_vs, sizeof(simple_vs), &input_layout);
12104 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12106 memset(&blend_desc, 0, sizeof(blend_desc));
12107 blend_desc.AlphaToCoverageEnable = FALSE;
12108 blend_desc.IndependentBlendEnable = FALSE;
12109 blend_desc.RenderTarget[0].BlendEnable = TRUE;
12110 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
12111 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
12112 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
12113 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
12114 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
12115 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
12116 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
12118 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
12119 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
12121 ds_desc.DepthEnable = TRUE;
12122 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
12123 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
12124 ds_desc.StencilEnable = FALSE;
12125 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
12126 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
12127 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
12128 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
12129 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
12130 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
12131 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
12132 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
12133 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
12134 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
12136 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
12137 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
12139 texture_desc.Width = 512;
12140 texture_desc.Height = 512;
12141 texture_desc.MipLevels = 1;
12142 texture_desc.ArraySize = 1;
12143 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12144 texture_desc.SampleDesc.Count = 1;
12145 texture_desc.SampleDesc.Quality = 0;
12146 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12147 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12148 texture_desc.CPUAccessFlags = 0;
12149 texture_desc.MiscFlags = 0;
12151 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12153 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
12154 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12157 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
12158 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
12160 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
12161 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12163 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12165 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture[i], NULL, &rtv[i]);
12166 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12169 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)ds_texture, NULL, &dsv);
12170 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
12172 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12174 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
12176 tmp_viewport[i].TopLeftX = i * 3;
12177 tmp_viewport[i].TopLeftY = i * 4;
12178 tmp_viewport[i].Width = 3;
12179 tmp_viewport[i].Height = 4;
12180 tmp_viewport[i].MinDepth = i * 0.01f;
12181 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
12184 rs_desc.FillMode = D3D11_FILL_SOLID;
12185 rs_desc.CullMode = D3D11_CULL_BACK;
12186 rs_desc.FrontCounterClockwise = FALSE;
12187 rs_desc.DepthBias = 0;
12188 rs_desc.DepthBiasClamp = 0.0f;
12189 rs_desc.SlopeScaledDepthBias = 0.0f;
12190 rs_desc.DepthClipEnable = TRUE;
12191 rs_desc.ScissorEnable = FALSE;
12192 rs_desc.MultisampleEnable = FALSE;
12193 rs_desc.AntialiasedLineEnable = FALSE;
12195 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs_state);
12196 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12198 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
12199 predicate_desc.MiscFlags = 0;
12201 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
12202 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
12204 /* Setup state. */
12206 /* Some versions of Windows AMD drivers hang while the device is being
12207 * released, if the total number of used resource slots exceeds some limit.
12208 * Do not use all constant buffers slots in order to not trigger this
12209 * driver bug. */
12210 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb[0]);
12211 ID3D11DeviceContext_VSSetConstantBuffers(context, 7, 1, &cb[7]);
12212 ID3D11DeviceContext_VSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12213 ID3D11DeviceContext_VSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12214 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12216 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb[0]);
12217 ID3D11DeviceContext_HSSetConstantBuffers(context, 7, 1, &cb[7]);
12218 ID3D11DeviceContext_HSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12219 ID3D11DeviceContext_HSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12220 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
12222 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12223 ID3D11DeviceContext_DSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12224 ID3D11DeviceContext_DSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12225 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
12227 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12228 ID3D11DeviceContext_GSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12229 ID3D11DeviceContext_GSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12230 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
12232 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12233 ID3D11DeviceContext_PSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12234 ID3D11DeviceContext_PSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12235 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12237 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12238 ID3D11DeviceContext_CSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12239 ID3D11DeviceContext_CSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12240 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
12241 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, cs_uav, NULL);
12243 ID3D11DeviceContext_IASetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12244 buffer, stride, offset);
12245 ID3D11DeviceContext_IASetIndexBuffer(context, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
12246 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12247 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12249 blend_factor[0] = 0.1f;
12250 blend_factor[1] = 0.2f;
12251 blend_factor[2] = 0.3f;
12252 blend_factor[3] = 0.4f;
12253 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, 0xff00ff00);
12254 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 3);
12255 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
12256 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, rtv, dsv,
12257 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, 1, &ps_uav, NULL);
12259 ID3D11DeviceContext_RSSetScissorRects(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12260 tmp_rect);
12261 ID3D11DeviceContext_RSSetViewports(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12262 tmp_viewport);
12263 ID3D11DeviceContext_RSSetState(context, rs_state);
12265 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
12267 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
12269 /* Verify the set state. */
12271 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12272 tmp_buffer);
12273 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12275 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
12276 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12277 tmp_buffer[i], i, expected_cb);
12278 if (tmp_buffer[i])
12279 ID3D11Buffer_Release(tmp_buffer[i]);
12281 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12282 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12284 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12285 tmp_srv[i], i, srv[i]);
12286 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12288 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12289 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12291 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12292 tmp_sampler[i], i, sampler[i]);
12293 ID3D11SamplerState_Release(tmp_sampler[i]);
12295 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
12296 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
12297 ID3D11VertexShader_Release(tmp_vs);
12299 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12300 tmp_buffer);
12301 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12303 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
12304 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12305 tmp_buffer[i], i, expected_cb);
12306 if (tmp_buffer[i])
12307 ID3D11Buffer_Release(tmp_buffer[i]);
12309 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12310 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12312 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12313 tmp_srv[i], i, srv[i]);
12314 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12316 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12317 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12319 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12320 tmp_sampler[i], i, sampler[i]);
12321 ID3D11SamplerState_Release(tmp_sampler[i]);
12323 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
12324 ok(tmp_hs == hs, "Got unexpected hull shader %p, expected %p.\n", tmp_hs, hs);
12325 ID3D11HullShader_Release(tmp_hs);
12327 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12328 tmp_buffer);
12329 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12331 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12332 tmp_buffer[i], i, cb[i]);
12333 ID3D11Buffer_Release(tmp_buffer[i]);
12335 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12336 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12338 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12339 tmp_srv[i], i, srv[i]);
12340 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12342 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12343 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12345 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12346 tmp_sampler[i], i, sampler[i]);
12347 ID3D11SamplerState_Release(tmp_sampler[i]);
12349 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
12350 ok(tmp_ds == ds, "Got unexpected domain shader %p, expected %p.\n", tmp_ds, ds);
12351 ID3D11DomainShader_Release(tmp_ds);
12353 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12354 tmp_buffer);
12355 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12357 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12358 tmp_buffer[i], i, cb[i]);
12359 ID3D11Buffer_Release(tmp_buffer[i]);
12361 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12362 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12364 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12365 tmp_srv[i], i, srv[i]);
12366 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12368 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12369 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12371 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12372 tmp_sampler[i], i, sampler[i]);
12373 ID3D11SamplerState_Release(tmp_sampler[i]);
12375 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
12376 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
12377 ID3D11GeometryShader_Release(tmp_gs);
12379 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12380 tmp_buffer);
12381 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12383 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12384 tmp_buffer[i], i, cb[i]);
12385 ID3D11Buffer_Release(tmp_buffer[i]);
12387 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12388 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12390 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12391 tmp_srv[i], i, srv[i]);
12392 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12394 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12395 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12397 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12398 tmp_sampler[i], i, sampler[i]);
12399 ID3D11SamplerState_Release(tmp_sampler[i]);
12401 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
12402 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
12403 ID3D11PixelShader_Release(tmp_ps);
12405 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12406 tmp_buffer);
12407 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12409 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12410 tmp_buffer[i], i, cb[i]);
12411 ID3D11Buffer_Release(tmp_buffer[i]);
12413 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12414 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12416 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12417 tmp_srv[i], i, srv[i]);
12418 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12420 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12421 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12423 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12424 tmp_sampler[i], i, sampler[i]);
12425 ID3D11SamplerState_Release(tmp_sampler[i]);
12427 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
12428 ok(tmp_cs == cs, "Got unexpected compute shader %p, expected %p.\n", tmp_cs, cs);
12429 ID3D11ComputeShader_Release(tmp_cs);
12430 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12431 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12433 ok(tmp_uav[i] == cs_uav[i], "Got unexpected unordered access view %p in slot %u, expected %p.\n",
12434 tmp_uav[i], i, cs_uav[i]);
12435 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
12438 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12439 tmp_buffer, stride, offset);
12440 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12442 todo_wine_if(i >= D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
12444 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
12445 tmp_buffer[i], i, buffer[i]);
12446 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
12447 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
12449 if (tmp_buffer[i])
12450 ID3D11Buffer_Release(tmp_buffer[i]);
12452 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
12453 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
12454 ID3D11Buffer_Release(tmp_buffer[0]);
12455 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
12456 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
12457 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
12458 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
12459 tmp_input_layout, input_layout);
12460 ID3D11InputLayout_Release(tmp_input_layout);
12461 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
12462 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
12464 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
12465 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
12466 ID3D11BlendState_Release(tmp_blend_state);
12467 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
12468 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
12469 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12470 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12471 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
12472 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
12473 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
12474 ID3D11DepthStencilState_Release(tmp_ds_state);
12475 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
12476 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
12477 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
12479 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
12480 tmp_rtv[i], i, rtv[i]);
12481 ID3D11RenderTargetView_Release(tmp_rtv[i]);
12483 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12484 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
12485 ID3D11DepthStencilView_Release(tmp_dsv);
12486 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
12487 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
12488 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12489 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
12491 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
12492 tmp_rtv[i], i, rtv[i]);
12493 ID3D11RenderTargetView_Release(tmp_rtv[i]);
12495 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12496 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
12497 ID3D11DepthStencilView_Release(tmp_dsv);
12498 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT - 1; ++i)
12500 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12502 ok(tmp_uav[i] == ps_uav, "Got unexpected unordered access view %p in slot %u, expected %p.\n",
12503 tmp_uav[i], i, ps_uav);
12504 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
12506 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
12507 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12508 "Got unexpected scissor rect count %u.\n", count);
12509 memset(tmp_rect, 0x55, sizeof(tmp_rect));
12510 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
12511 for (i = 0; i < count; ++i)
12513 ok(tmp_rect[i].left == i
12514 && tmp_rect[i].top == i * 2
12515 && tmp_rect[i].right == i + 1
12516 && tmp_rect[i].bottom == (i + 1) * 2,
12517 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
12519 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12520 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12521 "Got unexpected viewport count %u.\n", count);
12522 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12523 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12524 for (i = 0; i < count; ++i)
12526 ok(tmp_viewport[i].TopLeftX == i * 3
12527 && tmp_viewport[i].TopLeftY == i * 4
12528 && tmp_viewport[i].Width == 3
12529 && tmp_viewport[i].Height == 4
12530 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
12531 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
12532 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12533 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12534 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12536 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12537 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
12538 ID3D11RasterizerState_Release(tmp_rs_state);
12540 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12541 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12543 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
12544 tmp_buffer[i], i, so_buffer[i]);
12545 ID3D11Buffer_Release(tmp_buffer[i]);
12548 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12549 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
12550 ID3D11Predicate_Release(tmp_predicate);
12551 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12553 /* Verify ClearState(). */
12555 ID3D11DeviceContext_ClearState(context);
12557 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12558 tmp_buffer);
12559 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12561 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12563 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12564 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12566 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12568 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12569 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12571 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12573 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
12574 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
12576 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12577 tmp_buffer);
12578 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12580 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12582 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12583 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12585 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12587 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12588 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12590 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12592 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
12593 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
12595 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12596 tmp_buffer);
12597 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12599 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12601 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12602 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12604 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12606 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12607 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12609 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12611 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
12612 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
12614 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12615 tmp_buffer);
12616 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12618 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12620 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12621 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12623 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12625 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12626 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12628 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12630 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
12631 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
12633 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12634 tmp_buffer);
12635 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12637 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12639 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12640 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12642 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12644 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12645 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12647 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12649 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
12650 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
12652 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12653 tmp_buffer);
12654 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12656 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12658 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
12659 tmp_srv);
12660 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12662 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12664 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12665 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12667 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12669 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
12670 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
12671 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12672 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12674 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12677 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12678 tmp_buffer, stride, offset);
12679 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12681 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
12682 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
12683 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
12685 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
12686 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
12687 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
12688 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
12689 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
12690 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
12691 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
12692 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
12694 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
12695 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
12696 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
12697 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
12698 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12699 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12700 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
12701 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
12702 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
12703 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
12704 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
12705 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12707 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12709 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12710 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
12711 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
12712 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12713 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12715 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12717 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12718 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12720 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12723 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
12724 ok(!count, "Got unexpected scissor rect count %u.\n", count);
12725 memset(tmp_rect, 0x55, sizeof(tmp_rect));
12726 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12727 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
12728 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12730 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
12731 "Got unexpected scissor rect %s in slot %u.\n",
12732 wine_dbgstr_rect(&tmp_rect[i]), i);
12734 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12735 ok(!count, "Got unexpected viewport count %u.\n", count);
12736 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12737 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12738 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12739 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12741 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
12742 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
12743 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12744 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12745 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12747 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12748 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
12750 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12751 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12753 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
12756 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12757 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
12758 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12760 /* Cleanup. */
12762 ID3D11Predicate_Release(predicate);
12763 ID3D11RasterizerState_Release(rs_state);
12764 ID3D11DepthStencilView_Release(dsv);
12765 ID3D11Texture2D_Release(ds_texture);
12767 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12769 ID3D11RenderTargetView_Release(rtv[i]);
12770 ID3D11Texture2D_Release(rt_texture[i]);
12773 ID3D11DepthStencilState_Release(ds_state);
12774 ID3D11BlendState_Release(blend_state);
12775 ID3D11InputLayout_Release(input_layout);
12776 ID3D11VertexShader_Release(vs);
12777 ID3D11HullShader_Release(hs);
12778 ID3D11DomainShader_Release(ds);
12779 ID3D11GeometryShader_Release(gs);
12780 ID3D11PixelShader_Release(ps);
12781 ID3D11ComputeShader_Release(cs);
12783 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12785 ID3D11SamplerState_Release(sampler[i]);
12788 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12790 ID3D11ShaderResourceView_Release(srv[i]);
12793 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12795 ID3D11UnorderedAccessView_Release(cs_uav[i]);
12796 ID3D11Buffer_Release(cs_uav_buffer[i]);
12798 ID3D11UnorderedAccessView_Release(ps_uav);
12799 ID3D11Buffer_Release(ps_uav_buffer);
12801 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12803 ID3D11Buffer_Release(so_buffer[i]);
12806 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12808 ID3D11Buffer_Release(buffer[i]);
12811 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12813 ID3D11Buffer_Release(cb[i]);
12816 ID3D11DeviceContext_Release(context);
12817 refcount = ID3D11Device_Release(device);
12818 ok(!refcount, "Device has %u references left.\n", refcount);
12821 static void test_il_append_aligned(void)
12823 struct d3d11_test_context test_context;
12824 ID3D11InputLayout *input_layout;
12825 ID3D11DeviceContext *context;
12826 unsigned int stride, offset;
12827 ID3D11VertexShader *vs;
12828 ID3D11PixelShader *ps;
12829 ID3D11Device *device;
12830 ID3D11Buffer *vb[3];
12831 DWORD color;
12832 HRESULT hr;
12834 /* Semantic names are case-insensitive. */
12835 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12837 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
12838 D3D11_INPUT_PER_INSTANCE_DATA, 2},
12839 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
12840 D3D11_INPUT_PER_INSTANCE_DATA, 1},
12841 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
12842 D3D11_INPUT_PER_VERTEX_DATA, 0},
12843 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
12844 D3D11_INPUT_PER_INSTANCE_DATA, 1},
12845 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
12846 D3D11_INPUT_PER_INSTANCE_DATA, 2},
12848 static const DWORD vs_code[] =
12850 #if 0
12851 struct vs_in
12853 float4 position : POSITION;
12854 float2 color_xy : COLOR0;
12855 float2 color_zw : COLOR1;
12856 unsigned int instance_id : SV_INSTANCEID;
12859 struct vs_out
12861 float4 position : SV_POSITION;
12862 float2 color_xy : COLOR0;
12863 float2 color_zw : COLOR1;
12866 struct vs_out main(struct vs_in i)
12868 struct vs_out o;
12870 o.position = i.position;
12871 o.position.x += i.instance_id * 0.5;
12872 o.color_xy = i.color_xy;
12873 o.color_zw = i.color_zw;
12875 return o;
12877 #endif
12878 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
12879 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
12880 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
12881 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
12882 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
12883 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
12884 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
12885 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
12886 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
12887 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
12888 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
12889 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
12890 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
12891 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
12892 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
12893 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
12894 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
12896 static const DWORD ps_code[] =
12898 #if 0
12899 struct vs_out
12901 float4 position : SV_POSITION;
12902 float2 color_xy : COLOR0;
12903 float2 color_zw : COLOR1;
12906 float4 main(struct vs_out i) : SV_TARGET
12908 return float4(i.color_xy.xy, i.color_zw.xy);
12910 #endif
12911 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
12912 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
12913 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
12914 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
12915 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
12916 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
12917 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
12918 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12919 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12921 static const struct
12923 struct vec4 position;
12925 stream0[] =
12927 {{-1.0f, -1.0f, 0.0f, 1.0f}},
12928 {{-1.0f, 1.0f, 0.0f, 1.0f}},
12929 {{-0.5f, -1.0f, 0.0f, 1.0f}},
12930 {{-0.5f, 1.0f, 0.0f, 1.0f}},
12932 static const struct
12934 struct vec2 color2;
12935 struct vec2 color1;
12937 stream1[] =
12939 {{0.5f, 0.5f}, {0.0f, 1.0f}},
12940 {{0.5f, 0.5f}, {1.0f, 1.0f}},
12942 static const struct
12944 struct vec2 color3;
12945 struct vec2 color0;
12947 stream2[] =
12949 {{0.5f, 0.5f}, {1.0f, 0.0f}},
12950 {{0.5f, 0.5f}, {0.0f, 1.0f}},
12951 {{0.5f, 0.5f}, {0.0f, 0.0f}},
12952 {{0.5f, 0.5f}, {1.0f, 0.0f}},
12954 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
12956 if (!init_test_context(&test_context, NULL))
12957 return;
12959 device = test_context.device;
12960 context = test_context.immediate_context;
12962 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12963 vs_code, sizeof(vs_code), &input_layout);
12964 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12966 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
12967 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
12968 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
12970 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12971 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12972 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12973 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12975 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12976 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12977 offset = 0;
12978 stride = sizeof(*stream0);
12979 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
12980 stride = sizeof(*stream1);
12981 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
12982 stride = sizeof(*stream2);
12983 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
12984 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12985 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12987 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
12989 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
12991 color = get_texture_color(test_context.backbuffer, 80, 240);
12992 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
12993 color = get_texture_color(test_context.backbuffer, 240, 240);
12994 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
12995 color = get_texture_color(test_context.backbuffer, 400, 240);
12996 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
12997 color = get_texture_color(test_context.backbuffer, 560, 240);
12998 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
13000 ID3D11PixelShader_Release(ps);
13001 ID3D11VertexShader_Release(vs);
13002 ID3D11Buffer_Release(vb[2]);
13003 ID3D11Buffer_Release(vb[1]);
13004 ID3D11Buffer_Release(vb[0]);
13005 ID3D11InputLayout_Release(input_layout);
13006 release_test_context(&test_context);
13009 static void test_instanced_draw(void)
13011 struct d3d11_test_context test_context;
13012 D3D11_TEXTURE2D_DESC texture_desc;
13013 ID3D11InputLayout *input_layout;
13014 ID3D11RenderTargetView *rtvs[2];
13015 ID3D11Texture2D *render_target;
13016 ID3D11DeviceContext *context;
13017 struct resource_readback rb;
13018 unsigned int stride, offset;
13019 ID3D11Buffer *args_buffer;
13020 ID3D11VertexShader *vs;
13021 ID3D11PixelShader *ps;
13022 ID3D11Device *device;
13023 ID3D11Buffer *vb[4];
13024 unsigned int i;
13025 HRESULT hr;
13027 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13029 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
13030 D3D11_INPUT_PER_VERTEX_DATA, 0},
13031 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT,
13032 D3D11_INPUT_PER_INSTANCE_DATA, 1},
13033 {"color", 1, DXGI_FORMAT_R8_UNORM, 2, D3D11_APPEND_ALIGNED_ELEMENT,
13034 D3D10_INPUT_PER_INSTANCE_DATA, 0},
13035 {"color", 2, DXGI_FORMAT_R8_UNORM, 3, D3D11_APPEND_ALIGNED_ELEMENT,
13036 D3D10_INPUT_PER_INSTANCE_DATA, 2},
13037 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
13038 D3D11_INPUT_PER_INSTANCE_DATA, 1},
13040 static const DWORD vs_code[] =
13042 #if 0
13043 struct vs_in
13045 float4 position : Position;
13046 float r : color0;
13047 float g : color1;
13048 float b : color2;
13049 float v_offset : V_Offset;
13050 uint instance_id : SV_InstanceId;
13053 struct vs_out
13055 float4 position : SV_Position;
13056 float r : color0;
13057 float g : color1;
13058 float b : color2;
13059 uint instance_id : InstanceId;
13062 void main(vs_in i, out vs_out o)
13064 o.position = i.position;
13065 o.position.x += i.v_offset;
13066 o.r = i.r;
13067 o.g = i.g;
13068 o.b = i.b;
13069 o.instance_id = i.instance_id;
13071 #endif
13072 0x43425844, 0x036df42e, 0xff0da346, 0x7b23a14a, 0xc26ec9be, 0x00000001, 0x000002bc, 0x00000003,
13073 0x0000002c, 0x000000f4, 0x0000019c, 0x4e475349, 0x000000c0, 0x00000006, 0x00000008, 0x00000098,
13074 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a1, 0x00000000, 0x00000000,
13075 0x00000003, 0x00000001, 0x00000101, 0x000000a1, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
13076 0x00000101, 0x000000a1, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000a7,
13077 0x00000000, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000b0, 0x00000000, 0x00000008,
13078 0x00000001, 0x00000005, 0x00000101, 0x69736f50, 0x6e6f6974, 0x6c6f6300, 0x5600726f, 0x66664f5f,
13079 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e, 0xabab0064, 0x4e47534f, 0x000000a0, 0x00000005,
13080 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c,
13081 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000008c, 0x00000001, 0x00000000,
13082 0x00000003, 0x00000001, 0x00000d02, 0x0000008c, 0x00000002, 0x00000000, 0x00000003, 0x00000001,
13083 0x00000b04, 0x00000092, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
13084 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
13085 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
13086 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
13087 0x00101012, 0x00000004, 0x04000060, 0x00101012, 0x00000005, 0x00000008, 0x04000067, 0x001020f2,
13088 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065, 0x00102022, 0x00000001,
13089 0x03000065, 0x00102042, 0x00000001, 0x03000065, 0x00102012, 0x00000002, 0x07000000, 0x00102012,
13090 0x00000000, 0x0010100a, 0x00000000, 0x0010100a, 0x00000004, 0x05000036, 0x001020e2, 0x00000000,
13091 0x00101e56, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x05000036,
13092 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042, 0x00000001, 0x0010100a,
13093 0x00000003, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x0100003e,
13095 static const DWORD ps_code[] =
13097 #if 0
13098 struct vs_out
13100 float4 position : SV_Position;
13101 float r : color0;
13102 float g : color1;
13103 float b : color2;
13104 uint instance_id : InstanceId;
13107 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
13109 o0 = float4(i.r, i.g, i.b, 1.0f);
13110 o1 = i.instance_id;
13112 #endif
13113 0x43425844, 0xc9f9c86d, 0xa24d87aa, 0xff75d05b, 0xfbe0581a, 0x00000001, 0x000001b8, 0x00000003,
13114 0x0000002c, 0x000000d4, 0x00000120, 0x4e475349, 0x000000a0, 0x00000005, 0x00000008, 0x00000080,
13115 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
13116 0x00000003, 0x00000001, 0x00000101, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
13117 0x00000202, 0x0000008c, 0x00000002, 0x00000000, 0x00000003, 0x00000001, 0x00000404, 0x00000092,
13118 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
13119 0x6f6c6f63, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x4e47534f, 0x00000044, 0x00000002,
13120 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000038,
13121 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
13122 0x52444853, 0x00000090, 0x00000040, 0x00000024, 0x03001062, 0x00101012, 0x00000001, 0x03001062,
13123 0x00101022, 0x00000001, 0x03001062, 0x00101042, 0x00000001, 0x03000862, 0x00101012, 0x00000002,
13124 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072,
13125 0x00000000, 0x00101246, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
13126 0x05000036, 0x001020f2, 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
13128 static const struct vec4 stream0[] =
13130 {-1.00f, 0.0f, 0.0f, 1.0f},
13131 {-1.00f, 1.0f, 0.0f, 1.0f},
13132 {-0.75f, 0.0f, 0.0f, 1.0f},
13133 {-0.75f, 1.0f, 0.0f, 1.0f},
13134 /* indirect draws data */
13135 {-1.00f, -1.0f, 0.0f, 1.0f},
13136 {-1.00f, 0.0f, 0.0f, 1.0f},
13137 {-0.75f, -1.0f, 0.0f, 1.0f},
13138 {-0.75f, 0.0f, 0.0f, 1.0f},
13140 static const struct
13142 BYTE red;
13143 float v_offset;
13145 stream1[] =
13147 {0xf0, 0.00f},
13148 {0x80, 0.25f},
13149 {0x10, 0.50f},
13150 {0x40, 0.75f},
13152 {0xaa, 1.00f},
13153 {0xbb, 1.25f},
13154 {0xcc, 1.50f},
13155 {0x90, 1.75f},
13157 static const BYTE stream2[] = {0xf0, 0x80, 0x10, 0x40, 0xaa, 0xbb, 0xcc, 0x90};
13158 static const BYTE stream3[] = {0xf0, 0x80, 0x10, 0x40, 0xaa, 0xbb, 0xcc, 0x90};
13159 static const D3D11_DRAW_INSTANCED_INDIRECT_ARGS argument_data[] =
13161 {4, 4, 4, 0},
13162 {4, 4, 4, 4},
13164 static const struct
13166 RECT rect;
13167 unsigned int color;
13168 unsigned int instance_id;
13170 expected_results[] =
13172 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
13173 {{ 80, 0, 160, 240}, 0xfff0f080, 1},
13174 {{160, 0, 240, 240}, 0xff80f010, 2},
13175 {{240, 0, 320, 240}, 0xff80f040, 3},
13176 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
13177 {{400, 0, 480, 240}, 0xffaaaabb, 1},
13178 {{480, 0, 560, 240}, 0xffbbaacc, 2},
13179 {{560, 0, 640, 240}, 0xffbbaa90, 3},
13180 /* indirect draws results */
13181 {{ 0, 240, 80, 480}, 0xfff0f0f0, 0},
13182 {{ 80, 240, 160, 480}, 0xfff0f080, 1},
13183 {{160, 240, 240, 480}, 0xff80f010, 2},
13184 {{240, 240, 320, 480}, 0xff80f040, 3},
13185 {{320, 240, 400, 480}, 0xffaaaaaa, 0},
13186 {{400, 240, 480, 480}, 0xffaaaabb, 1},
13187 {{480, 240, 560, 480}, 0xffbbaacc, 2},
13188 {{560, 240, 640, 480}, 0xffbbaa90, 3},
13190 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13191 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13193 if (!init_test_context(&test_context, &feature_level))
13194 return;
13195 device = test_context.device;
13196 context = test_context.immediate_context;
13198 rtvs[0] = test_context.backbuffer_rtv;
13200 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13201 texture_desc.Format = DXGI_FORMAT_R32_UINT;
13202 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
13203 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13204 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtvs[1]);
13205 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13207 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13208 vs_code, sizeof(vs_code), &input_layout);
13209 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13211 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13212 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13213 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13214 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13216 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
13217 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
13218 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
13219 vb[3] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream3), stream3);
13221 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13222 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13223 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13224 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13225 offset = 0;
13226 stride = sizeof(*stream0);
13227 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
13228 stride = sizeof(*stream1);
13229 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
13230 stride = sizeof(*stream2);
13231 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
13232 stride = sizeof(*stream3);
13233 ID3D11DeviceContext_IASetVertexBuffers(context, 3, 1, &vb[3], &stride, &offset);
13235 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
13236 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[1], white);
13238 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
13239 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
13240 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 4);
13242 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
13243 sizeof(argument_data), argument_data);
13245 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, 0);
13246 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, sizeof(*argument_data));
13248 get_texture_readback(test_context.backbuffer, 0, &rb);
13249 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
13250 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
13251 release_resource_readback(&rb);
13253 get_texture_readback(render_target, 0, &rb);
13254 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
13255 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
13256 release_resource_readback(&rb);
13258 ID3D11Buffer_Release(vb[0]);
13259 ID3D11Buffer_Release(vb[1]);
13260 ID3D11Buffer_Release(vb[2]);
13261 ID3D11Buffer_Release(vb[3]);
13262 ID3D11Buffer_Release(args_buffer);
13263 ID3D11RenderTargetView_Release(rtvs[1]);
13264 ID3D11Texture2D_Release(render_target);
13265 ID3D11VertexShader_Release(vs);
13266 ID3D11PixelShader_Release(ps);
13267 ID3D11InputLayout_Release(input_layout);
13268 release_test_context(&test_context);
13271 static void test_vertex_id(void)
13273 static const DWORD vs_code[] =
13275 #if 0
13276 uint4 main(uint id : ID, uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID) : OUTPUT
13278 return uint4(id, instance_id, vertex_id, 0);
13280 #endif
13281 0x43425844, 0x5625197b, 0x588ccf8f, 0x48694905, 0x961d19ca, 0x00000001, 0x00000170, 0x00000003,
13282 0x0000002c, 0x000000a4, 0x000000d4, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
13283 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000101, 0x00000053, 0x00000000, 0x00000008,
13284 0x00000001, 0x00000001, 0x00000101, 0x00000061, 0x00000000, 0x00000006, 0x00000001, 0x00000002,
13285 0x00000101, 0x53004449, 0x6e495f56, 0x6e617473, 0x44496563, 0x5f565300, 0x74726556, 0x44497865,
13286 0xababab00, 0x4e47534f, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
13287 0x00000001, 0x00000000, 0x0000000f, 0x5054554f, 0xab005455, 0x52444853, 0x00000094, 0x00010040,
13288 0x00000025, 0x0300005f, 0x00101012, 0x00000000, 0x04000060, 0x00101012, 0x00000001, 0x00000008,
13289 0x04000060, 0x00101012, 0x00000002, 0x00000006, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
13290 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010100a,
13291 0x00000001, 0x05000036, 0x00102042, 0x00000000, 0x0010100a, 0x00000002, 0x05000036, 0x00102082,
13292 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
13294 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13296 {"ID", 0, DXGI_FORMAT_R32_UINT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
13298 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
13300 {0, "OUTPUT", 0, 0, 4, 0},
13302 static const unsigned int vertices[] =
13320 static const unsigned int indices[] =
13322 6, 7, 8,
13324 0, 1, 2,
13326 struct uvec4 expected_values[] =
13328 {0, 0, 0},
13329 {1, 0, 1},
13330 {2, 0, 2},
13331 {0, 1, 0},
13332 {1, 1, 1},
13333 {2, 1, 2},
13335 {3, 0, 0},
13336 {4, 0, 1},
13337 {5, 0, 2},
13339 {6, 0, 6},
13340 {7, 0, 7},
13341 {8, 0, 8},
13342 {6, 1, 6},
13343 {7, 1, 7},
13344 {8, 1, 8},
13346 {5, 0, 0},
13347 {6, 0, 1},
13348 {7, 0, 2},
13351 BOOL found_values[ARRAY_SIZE(expected_values)] = {0};
13352 BOOL used_values[ARRAY_SIZE(expected_values)] = {0};
13353 struct d3d11_test_context test_context;
13354 D3D11_QUERY_DATA_SO_STATISTICS data;
13355 ID3D11Buffer *vb, *ib, *so_buffer;
13356 ID3D11InputLayout *input_layout;
13357 ID3D11DeviceContext *context;
13358 D3D11_QUERY_DESC query_desc;
13359 struct resource_readback rb;
13360 unsigned int stride, offset;
13361 ID3D11Asynchronous *query;
13362 ID3D11GeometryShader *gs;
13363 ID3D11VertexShader *vs;
13364 ID3D11Device *device;
13365 unsigned int count;
13366 unsigned int i, j;
13367 HRESULT hr;
13369 if (!init_test_context(&test_context, NULL))
13370 return;
13371 device = test_context.device;
13372 context = test_context.immediate_context;
13374 query_desc.Query = D3D11_QUERY_SO_STATISTICS;
13375 query_desc.MiscFlags = 0;
13376 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
13377 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
13379 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13380 vs_code, sizeof(vs_code), &input_layout);
13381 ok(hr == S_OK, "Failed to create input layout, hr %#x.\n", hr);
13383 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13384 ok(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
13386 stride = 16;
13387 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
13388 so_declaration, ARRAY_SIZE(so_declaration), &stride, 1, 0, NULL, &gs);
13389 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
13391 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13392 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
13393 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
13395 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13396 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
13397 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13398 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
13399 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
13400 offset = 0;
13401 stride = sizeof(*vertices);
13402 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
13404 offset = 0;
13405 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
13407 ID3D11DeviceContext_Begin(context, query);
13409 ID3D11DeviceContext_DrawInstanced(context, 3, 2, 0, 0);
13410 ID3D11DeviceContext_DrawInstanced(context, 3, 1, 3, 16);
13412 ID3D11DeviceContext_DrawIndexedInstanced(context, 3, 2, 0, 0, 0);
13413 ID3D11DeviceContext_DrawIndexedInstanced(context, 3, 1, 3, 9, 7);
13415 ID3D11DeviceContext_End(context, query);
13417 get_query_data(context, query, &data, sizeof(data));
13418 count = data.NumPrimitivesWritten;
13419 ok(count == ARRAY_SIZE(expected_values), "Got unexpected value %u.\n", count);
13421 count = min(count, ARRAY_SIZE(used_values));
13422 get_buffer_readback(so_buffer, &rb);
13423 for (i = 0; i < ARRAY_SIZE(expected_values); ++i)
13425 for (j = 0; j < count; ++j)
13427 if (!used_values[j] && compare_uvec4(get_readback_uvec4(&rb, j, 0), &expected_values[i]))
13429 found_values[i] = TRUE;
13430 used_values[j] = TRUE;
13431 break;
13436 for (i = 0; i < count; ++i)
13438 const struct uvec4 *v = get_readback_uvec4(&rb, i, 0);
13439 ok(used_values[i], "Found unexpected value {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n", v->x, v->y, v->z, v->w);
13441 release_resource_readback(&rb);
13443 for (i = 0; i < ARRAY_SIZE(expected_values); ++i)
13445 ok(found_values[i], "Failed to find value {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n",
13446 expected_values[i].x, expected_values[i].y, expected_values[i].z, expected_values[i].w);
13449 ID3D11Asynchronous_Release(query);
13450 ID3D11Buffer_Release(so_buffer);
13451 ID3D11Buffer_Release(vb);
13452 ID3D11Buffer_Release(ib);
13453 ID3D11GeometryShader_Release(gs);
13454 ID3D11VertexShader_Release(vs);
13455 ID3D11InputLayout_Release(input_layout);
13456 release_test_context(&test_context);
13459 static void test_fragment_coords(void)
13461 struct d3d11_test_context test_context;
13462 ID3D11PixelShader *ps, *ps_frac;
13463 ID3D11DeviceContext *context;
13464 ID3D11Device *device;
13465 ID3D11Buffer *ps_cb;
13466 DWORD color;
13467 HRESULT hr;
13469 static const DWORD ps_code[] =
13471 #if 0
13472 float2 cutoff;
13474 float4 main(float4 position : SV_POSITION) : SV_TARGET
13476 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
13478 if (position.x > cutoff.x)
13479 ret.y = 1.0;
13480 if (position.y > cutoff.y)
13481 ret.z = 1.0;
13483 return ret;
13485 #endif
13486 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
13487 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13488 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13489 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13490 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
13491 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
13492 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
13493 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
13494 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
13495 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
13496 0x0100003e,
13498 static const DWORD ps_frac_code[] =
13500 #if 0
13501 float4 main(float4 position : SV_POSITION) : SV_TARGET
13503 return float4(frac(position.xy), 0.0, 1.0);
13505 #endif
13506 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
13507 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13508 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13509 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13510 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
13511 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13512 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
13513 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
13515 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13516 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
13518 if (!init_test_context(&test_context, NULL))
13519 return;
13521 device = test_context.device;
13522 context = test_context.immediate_context;
13524 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
13526 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13527 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13528 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
13529 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13531 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
13532 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13534 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13536 draw_quad(&test_context);
13538 color = get_texture_color(test_context.backbuffer, 319, 239);
13539 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
13540 color = get_texture_color(test_context.backbuffer, 320, 239);
13541 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13542 color = get_texture_color(test_context.backbuffer, 319, 240);
13543 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13544 color = get_texture_color(test_context.backbuffer, 320, 240);
13545 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
13547 ID3D11Buffer_Release(ps_cb);
13548 cutoff.x = 16.0f;
13549 cutoff.y = 16.0f;
13550 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
13551 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
13553 draw_quad(&test_context);
13555 color = get_texture_color(test_context.backbuffer, 14, 14);
13556 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
13557 color = get_texture_color(test_context.backbuffer, 18, 14);
13558 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13559 color = get_texture_color(test_context.backbuffer, 14, 18);
13560 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13561 color = get_texture_color(test_context.backbuffer, 18, 18);
13562 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
13564 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
13565 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13567 ID3D11DeviceContext_Draw(context, 4, 0);
13569 color = get_texture_color(test_context.backbuffer, 14, 14);
13570 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
13572 ID3D11Buffer_Release(ps_cb);
13573 ID3D11PixelShader_Release(ps_frac);
13574 ID3D11PixelShader_Release(ps);
13575 release_test_context(&test_context);
13578 static void test_initial_texture_data(void)
13580 ID3D11Texture2D *texture, *staging_texture;
13581 struct d3d11_test_context test_context;
13582 D3D11_SUBRESOURCE_DATA resource_data;
13583 D3D11_TEXTURE2D_DESC texture_desc;
13584 ID3D11SamplerState *sampler_state;
13585 ID3D11ShaderResourceView *ps_srv;
13586 D3D11_SAMPLER_DESC sampler_desc;
13587 ID3D11DeviceContext *context;
13588 struct resource_readback rb;
13589 ID3D11PixelShader *ps;
13590 ID3D11Device *device;
13591 unsigned int i, j;
13592 DWORD color;
13593 HRESULT hr;
13595 static const DWORD ps_code[] =
13597 #if 0
13598 Texture2D t;
13599 SamplerState s;
13601 float4 main(float4 position : SV_POSITION) : SV_Target
13603 float2 p;
13605 p.x = position.x / 640.0f;
13606 p.y = position.y / 480.0f;
13607 return t.Sample(s, p);
13609 #endif
13610 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13611 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13612 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13613 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13614 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13615 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13616 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13617 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13618 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13619 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13621 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13622 static const DWORD bitmap_data[] =
13624 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
13625 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
13626 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
13627 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
13630 if (!init_test_context(&test_context, NULL))
13631 return;
13633 device = test_context.device;
13634 context = test_context.immediate_context;
13636 texture_desc.Width = 4;
13637 texture_desc.Height = 4;
13638 texture_desc.MipLevels = 1;
13639 texture_desc.ArraySize = 1;
13640 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13641 texture_desc.SampleDesc.Count = 1;
13642 texture_desc.SampleDesc.Quality = 0;
13643 texture_desc.Usage = D3D11_USAGE_STAGING;
13644 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
13645 texture_desc.BindFlags = 0;
13646 texture_desc.MiscFlags = 0;
13648 resource_data.pSysMem = bitmap_data;
13649 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
13650 resource_data.SysMemSlicePitch = 0;
13652 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &staging_texture);
13653 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
13655 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13656 texture_desc.CPUAccessFlags = 0;
13657 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13658 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13659 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
13661 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)texture, (ID3D11Resource *)staging_texture);
13663 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
13664 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
13666 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
13667 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
13668 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
13669 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
13670 sampler_desc.MipLODBias = 0.0f;
13671 sampler_desc.MaxAnisotropy = 0;
13672 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
13673 sampler_desc.BorderColor[0] = 0.0f;
13674 sampler_desc.BorderColor[1] = 0.0f;
13675 sampler_desc.BorderColor[2] = 0.0f;
13676 sampler_desc.BorderColor[3] = 0.0f;
13677 sampler_desc.MinLOD = 0.0f;
13678 sampler_desc.MaxLOD = 0.0f;
13679 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
13680 ok(hr == S_OK, "Failed to create sampler state, hr %#x.\n", hr);
13682 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13683 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
13685 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
13686 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
13687 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13689 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13690 draw_quad(&test_context);
13691 get_texture_readback(test_context.backbuffer, 0, &rb);
13692 for (i = 0; i < 4; ++i)
13694 for (j = 0; j < 4; ++j)
13696 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13697 ok(compare_color(color, bitmap_data[j + i * 4], 1),
13698 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13699 color, j, i, bitmap_data[j + i * 4]);
13702 release_resource_readback(&rb);
13704 ID3D11PixelShader_Release(ps);
13705 ID3D11SamplerState_Release(sampler_state);
13706 ID3D11ShaderResourceView_Release(ps_srv);
13707 ID3D11Texture2D_Release(staging_texture);
13708 ID3D11Texture2D_Release(texture);
13709 release_test_context(&test_context);
13712 static void test_update_subresource(void)
13714 struct d3d11_test_context test_context;
13715 D3D11_SUBRESOURCE_DATA resource_data;
13716 D3D11_TEXTURE3D_DESC texture_desc_3d;
13717 D3D11_TEXTURE2D_DESC texture_desc;
13718 ID3D11SamplerState *sampler_state;
13719 ID3D11ShaderResourceView *ps_srv;
13720 D3D11_SAMPLER_DESC sampler_desc;
13721 ID3D11DeviceContext *context;
13722 struct resource_readback rb;
13723 ID3D11Texture3D *texture_3d;
13724 ID3D11Texture2D *texture;
13725 ID3D11PixelShader *ps;
13726 ID3D11Device *device;
13727 unsigned int i, j;
13728 D3D11_BOX box;
13729 DWORD color;
13730 HRESULT hr;
13732 static const DWORD ps_code[] =
13734 #if 0
13735 Texture2D t;
13736 SamplerState s;
13738 float4 main(float4 position : SV_POSITION) : SV_Target
13740 float2 p;
13742 p.x = position.x / 640.0f;
13743 p.y = position.y / 480.0f;
13744 return t.Sample(s, p);
13746 #endif
13747 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13748 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13749 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13750 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13751 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13752 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13753 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13754 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13755 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13756 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13758 static const DWORD ps_code_3d[] =
13760 #if 0
13761 Texture3D t;
13762 SamplerState s;
13764 float4 main(float4 position : SV_POSITION) : SV_Target
13766 float3 p1, p2;
13767 p2.x = p1.x = position.x / 640.0f;
13768 p2.y = p1.y = position.y / 480.0f;
13769 p1.z = 0.25;
13770 p2.z = 0.75;
13771 return 0.5 * (t.Sample(s, p1) + t.Sample(s, p2));
13773 #endif
13774 0x43425844, 0x4d466d63, 0xa3d10db1, 0xd6534470, 0x16d738ef, 0x00000001, 0x000001ec, 0x00000003,
13775 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13776 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13777 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13778 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000150, 0x00000040,
13779 0x00000054, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
13780 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13781 0x00000002, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13782 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3e800000,
13783 0x09000045, 0x001000f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
13784 0x00000000, 0x0a000038, 0x00100032, 0x00000001, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13785 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000001, 0x00004001, 0x3f400000,
13786 0x09000045, 0x001000f2, 0x00000001, 0x00100246, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
13787 0x00000000, 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
13788 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000,
13789 0x3f000000, 0x3f000000, 0x0100003e,
13791 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13792 static const DWORD initial_data[32] = {0};
13793 static const DWORD bitmap_data[] =
13795 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
13796 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
13797 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
13798 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
13800 static const DWORD expected_colors[] =
13802 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
13803 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
13804 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
13805 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
13807 static const DWORD bc7_data[] =
13809 0x3a7b944b, 0x982a5800, 0x9cab4983, 0xc6a09579,
13810 0x5f7f2bfe, 0xa95d98f2, 0x3bfb4c03, 0x8be16a41,
13811 0x8362e6c0, 0x358ed7a2, 0xec3e130b, 0x86cebc86,
13812 0xf045be66, 0x7a16507f, 0xfe9ccc9f, 0x3f103e16,
13813 0x84d466c5, 0xfaf5cb5a, 0x9b9e1859, 0x384589b0,
13814 0x9268b4b8, 0x212b3643, 0x813f853a, 0x4a2bd7c2,
13815 0x1809f3e0, 0xf646d5ef, 0x40e80679, 0x05791fe5,
13816 0x6604e7e5, 0x5c28b55d, 0x1ef211f5, 0x632d47f6,
13818 static const DWORD bc7_expected_colors[] =
13820 0xc1752752, 0xc39859a9, 0xff79c08e, 0xff63bf6c,
13821 0xbf7d2756, 0xb89f3d40, 0xffda3a77, 0xffd08099,
13822 0x415f1f37, 0x43671d3f, 0xffc64758, 0xff57a194,
13823 0x405a2032, 0x39422619, 0xff749b76, 0xffabb879,
13825 static const DWORD expected_colors_3d[] = { 0xffff8000, 0xffff8080, 0x80008000, 0xff8080ff };
13827 if (!init_test_context(&test_context, NULL))
13828 return;
13830 device = test_context.device;
13831 context = test_context.immediate_context;
13833 texture_desc.Width = 4;
13834 texture_desc.Height = 4;
13835 texture_desc.MipLevels = 1;
13836 texture_desc.ArraySize = 1;
13837 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13838 texture_desc.SampleDesc.Count = 1;
13839 texture_desc.SampleDesc.Quality = 0;
13840 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13841 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13842 texture_desc.CPUAccessFlags = 0;
13843 texture_desc.MiscFlags = 0;
13845 resource_data.pSysMem = initial_data;
13846 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
13847 resource_data.SysMemSlicePitch = 0;
13849 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
13850 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
13852 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
13853 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13855 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
13856 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
13857 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
13858 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
13859 sampler_desc.MipLODBias = 0.0f;
13860 sampler_desc.MaxAnisotropy = 0;
13861 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
13862 sampler_desc.BorderColor[0] = 0.0f;
13863 sampler_desc.BorderColor[1] = 0.0f;
13864 sampler_desc.BorderColor[2] = 0.0f;
13865 sampler_desc.BorderColor[3] = 0.0f;
13866 sampler_desc.MinLOD = 0.0f;
13867 sampler_desc.MaxLOD = 0.0f;
13869 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
13870 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
13872 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13873 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13875 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
13876 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
13877 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13879 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13880 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
13882 draw_quad(&test_context);
13883 check_texture_color(test_context.backbuffer, 0x00000000, 0);
13885 set_box(&box, 1, 1, 0, 3, 3, 1);
13886 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13887 bitmap_data, 4 * sizeof(*bitmap_data), 0);
13888 set_box(&box, 0, 3, 0, 3, 4, 1);
13889 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13890 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
13891 set_box(&box, 0, 0, 0, 4, 1, 1);
13892 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13893 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
13894 set_box(&box, 0, 1, 0, 1, 3, 1);
13895 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13896 &bitmap_data[2], sizeof(*bitmap_data), 0);
13897 set_box(&box, 4, 4, 0, 3, 1, 1);
13898 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13899 bitmap_data, sizeof(*bitmap_data), 0);
13900 set_box(&box, 0, 0, 0, 4, 4, 0);
13901 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13902 bitmap_data, 4 * sizeof(*bitmap_data), 0);
13903 draw_quad(&test_context);
13904 get_texture_readback(test_context.backbuffer, 0, &rb);
13905 for (i = 0; i < 4; ++i)
13907 for (j = 0; j < 4; ++j)
13909 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13910 ok(compare_color(color, expected_colors[j + i * 4], 1),
13911 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13912 color, j, i, expected_colors[j + i * 4]);
13915 release_resource_readback(&rb);
13917 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
13918 bitmap_data, 4 * sizeof(*bitmap_data), 0);
13919 draw_quad(&test_context);
13920 get_texture_readback(test_context.backbuffer, 0, &rb);
13921 for (i = 0; i < 4; ++i)
13923 for (j = 0; j < 4; ++j)
13925 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13926 ok(compare_color(color, bitmap_data[j + i * 4], 1),
13927 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13928 color, j, i, bitmap_data[j + i * 4]);
13931 release_resource_readback(&rb);
13933 ID3D11ShaderResourceView_Release(ps_srv);
13934 ID3D11Texture2D_Release(texture);
13935 ID3D11PixelShader_Release(ps);
13937 hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps);
13938 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13940 texture_desc_3d.Width = 2;
13941 texture_desc_3d.Height = 2;
13942 texture_desc_3d.Depth = 2;
13943 texture_desc_3d.MipLevels = 1;
13944 texture_desc_3d.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13945 texture_desc_3d.Usage = D3D11_USAGE_DEFAULT;
13946 texture_desc_3d.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13947 texture_desc_3d.CPUAccessFlags = 0;
13948 texture_desc_3d.MiscFlags = 0;
13950 resource_data.SysMemPitch = texture_desc_3d.Width * sizeof(*initial_data);
13951 resource_data.SysMemSlicePitch = texture_desc_3d.Width * texture_desc_3d.Height * sizeof(*initial_data);
13953 hr = ID3D11Device_CreateTexture3D(device, &texture_desc_3d, &resource_data, &texture_3d);
13954 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
13956 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture_3d, NULL, &ps_srv);
13957 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13959 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13960 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
13962 set_box(&box, 0, 0, 0, 1, 2, 1);
13963 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data, 8, 16);
13964 set_box(&box, 0, 0, 0, 1, 1, 2);
13965 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 4, 16, 32);
13966 set_box(&box, 1, 0, 0, 2, 1, 2);
13967 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 8, 4, 0);
13968 set_box(&box, 0, 0, 1, 2, 1, 2);
13969 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 2, 4, 5);
13970 set_box(&box, 0, 0, 1, 2, 1, 2);
13971 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 3, 12, 0);
13972 set_box(&box, 1, 1, 0, 2, 2, 2);
13973 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data, 0, 32);
13975 draw_quad(&test_context);
13976 get_texture_readback(test_context.backbuffer, 0, &rb);
13977 for (i = 0; i < 2; ++i)
13979 for (j = 0; j < 2; ++j)
13981 color = get_readback_color(&rb, 160 + j * 320, 120 + i * 240, 0);
13982 ok(compare_color(color, expected_colors_3d[j + i * 2], 1),
13983 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13984 color, j, i, expected_colors_3d[j + i * 2]);
13987 release_resource_readback(&rb);
13988 ID3D11ShaderResourceView_Release(ps_srv);
13989 ID3D11Texture3D_Release(texture_3d);
13991 texture_desc_3d.Width = 8;
13992 texture_desc_3d.Height = 8;
13993 texture_desc_3d.Depth = 2;
13994 texture_desc_3d.Format = DXGI_FORMAT_BC7_UNORM;
13996 resource_data.SysMemPitch = 32;
13997 resource_data.SysMemSlicePitch = 64;
13999 hr = ID3D11Device_CreateTexture3D(device, &texture_desc_3d, &resource_data, &texture_3d);
14000 if (FAILED(hr))
14002 skip("Failed to create BC7 3d texture, hr %#x.\n", hr);
14004 else
14006 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture_3d, NULL, &ps_srv);
14007 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14009 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14010 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14012 set_box(&box, 0, 0, 0, 8, 8, 2);
14013 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data, 32, 64);
14014 set_box(&box, 0, 0, 1, 8, 8, 2);
14015 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data, 16, 0);
14016 set_box(&box, 0, 0, 0, 4, 4, 1);
14017 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 8, 0, 0);
14018 set_box(&box, 4, 4, 0, 8, 8, 2);
14019 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 16, 0, 16);
14020 set_box(&box, 0, 4, 1, 8, 8, 2);
14021 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 1, 4, 32);
14022 set_box(&box, 4, 0, 0, 8, 4, 2);
14023 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 2, 0, 1);
14025 draw_quad(&test_context);
14026 get_texture_readback(test_context.backbuffer, 0, &rb);
14027 for (i = 0; i < 4; ++i)
14029 for (j = 0; j < 4; ++j)
14031 color = get_readback_color(&rb, 70 + j * 160, 50 + i * 120, 0);
14032 ok(compare_color(color, bc7_expected_colors[j + i * 4], 1),
14033 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14034 color, j, i, bc7_expected_colors[j + i * 4]);
14037 release_resource_readback(&rb);
14038 ID3D11ShaderResourceView_Release(ps_srv);
14039 ID3D11Texture3D_Release(texture_3d);
14042 ID3D11PixelShader_Release(ps);
14043 ID3D11SamplerState_Release(sampler_state);
14044 release_test_context(&test_context);
14047 static void test_copy_subresource_region(void)
14049 ID3D11Texture2D *dst_texture, *src_texture;
14050 struct d3d11_test_context test_context;
14051 ID3D11Buffer *dst_buffer, *src_buffer;
14052 D3D11_SUBRESOURCE_DATA resource_data;
14053 D3D11_TEXTURE2D_DESC texture_desc;
14054 ID3D11SamplerState *sampler_state;
14055 ID3D11ShaderResourceView *ps_srv;
14056 D3D11_SAMPLER_DESC sampler_desc;
14057 ID3D11DeviceContext1 *context1;
14058 ID3D11DeviceContext *context;
14059 struct vec4 float_colors[16];
14060 struct resource_readback rb;
14061 ID3D11PixelShader *ps;
14062 ID3D11Device *device;
14063 unsigned int i, j;
14064 D3D11_BOX box;
14065 DWORD color;
14066 HRESULT hr;
14068 static const DWORD ps_code[] =
14070 #if 0
14071 Texture2D t;
14072 SamplerState s;
14074 float4 main(float4 position : SV_POSITION) : SV_Target
14076 float2 p;
14078 p.x = position.x / 640.0f;
14079 p.y = position.y / 480.0f;
14080 return t.Sample(s, p);
14082 #endif
14083 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
14084 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14085 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14086 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14087 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
14088 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
14089 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14090 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
14091 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
14092 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
14094 static const DWORD ps_buffer_code[] =
14096 #if 0
14097 float4 buffer[16];
14099 float4 main(float4 position : SV_POSITION) : SV_TARGET
14101 float2 p = (float2)4;
14102 p *= float2(position.x / 640.0f, position.y / 480.0f);
14103 return buffer[(int)p.y * 4 + (int)p.x];
14105 #endif
14106 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
14107 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14108 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14109 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14110 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
14111 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
14112 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
14113 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
14114 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
14115 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
14116 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
14117 0x0010000a, 0x00000000, 0x0100003e,
14119 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
14120 static const DWORD initial_data[16] = {0};
14121 static const DWORD bitmap_data[] =
14123 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14124 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14125 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14126 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14128 static const DWORD expected_colors[] =
14130 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14131 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
14132 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
14133 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
14136 if (!init_test_context(&test_context, NULL))
14137 return;
14139 device = test_context.device;
14140 context = test_context.immediate_context;
14142 texture_desc.Width = 4;
14143 texture_desc.Height = 4;
14144 texture_desc.MipLevels = 1;
14145 texture_desc.ArraySize = 1;
14146 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14147 texture_desc.SampleDesc.Count = 1;
14148 texture_desc.SampleDesc.Quality = 0;
14149 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14150 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14151 texture_desc.CPUAccessFlags = 0;
14152 texture_desc.MiscFlags = 0;
14154 resource_data.pSysMem = initial_data;
14155 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
14156 resource_data.SysMemSlicePitch = 0;
14158 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
14159 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14161 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
14163 resource_data.pSysMem = bitmap_data;
14164 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
14165 resource_data.SysMemSlicePitch = 0;
14167 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
14168 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14170 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
14171 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14173 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14174 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14175 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14176 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14177 sampler_desc.MipLODBias = 0.0f;
14178 sampler_desc.MaxAnisotropy = 0;
14179 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14180 sampler_desc.BorderColor[0] = 0.0f;
14181 sampler_desc.BorderColor[1] = 0.0f;
14182 sampler_desc.BorderColor[2] = 0.0f;
14183 sampler_desc.BorderColor[3] = 0.0f;
14184 sampler_desc.MinLOD = 0.0f;
14185 sampler_desc.MaxLOD = 0.0f;
14187 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
14188 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14190 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14191 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14193 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14194 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14195 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14197 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14199 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14200 1, 1, 0, NULL, 0, &box);
14201 ID3D11DeviceContext_CopySubresourceRegion(context, NULL, 0,
14202 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14204 set_box(&box, 0, 0, 0, 2, 2, 1);
14205 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14206 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14207 set_box(&box, 1, 2, 0, 4, 3, 1);
14208 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14209 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
14210 set_box(&box, 0, 3, 0, 4, 4, 1);
14211 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14212 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14213 set_box(&box, 3, 0, 0, 4, 2, 1);
14214 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14215 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14216 set_box(&box, 3, 1, 0, 4, 2, 1);
14217 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14218 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
14219 set_box(&box, 0, 0, 0, 4, 4, 0);
14220 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14221 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14222 draw_quad(&test_context);
14223 get_texture_readback(test_context.backbuffer, 0, &rb);
14224 for (i = 0; i < 4; ++i)
14226 for (j = 0; j < 4; ++j)
14228 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14229 ok(compare_color(color, expected_colors[j + i * 4], 1),
14230 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14231 color, j, i, expected_colors[j + i * 4]);
14234 release_resource_readback(&rb);
14236 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14237 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
14238 draw_quad(&test_context);
14239 get_texture_readback(test_context.backbuffer, 0, &rb);
14240 for (i = 0; i < 4; ++i)
14242 for (j = 0; j < 4; ++j)
14244 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14245 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14246 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14247 color, j, i, bitmap_data[j + i * 4]);
14250 release_resource_readback(&rb);
14252 hr = ID3D11DeviceContext_QueryInterface(context, &IID_ID3D11DeviceContext1, (void **)&context1);
14253 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
14254 "Failed to query ID3D11DeviceContext1, hr %#x.\n", hr);
14256 if (SUCCEEDED(hr))
14258 ID3D11DeviceContext1_ClearRenderTargetView(context1, test_context.backbuffer_rtv, red);
14259 check_texture_color(test_context.backbuffer, 0x800000ff, 2);
14261 memset(float_colors, 0, sizeof(float_colors));
14262 for (i = 0; i < texture_desc.Width; ++i)
14263 ((unsigned int *)float_colors)[i] = 0x45454545;
14265 ID3D11DeviceContext1_UpdateSubresource1(context1, (ID3D11Resource *)dst_texture, 0, NULL,
14266 float_colors, 0, 0, 0);
14267 draw_quad(&test_context);
14268 check_texture_color(test_context.backbuffer, 0x45454545, 1);
14270 ID3D11DeviceContext1_CopySubresourceRegion1(context1, (ID3D11Resource *)dst_texture, 0,
14271 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL, 0);
14272 draw_quad(&test_context);
14274 get_texture_readback(test_context.backbuffer, 0, &rb);
14275 for (i = 0; i < 4; ++i)
14277 for (j = 0; j < 4; ++j)
14279 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14280 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14281 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14282 color, j, i, bitmap_data[j + i * 4]);
14285 release_resource_readback(&rb);
14287 ID3D11DeviceContext1_Release(context1);
14291 ID3D11PixelShader_Release(ps);
14292 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
14293 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14295 ID3D11ShaderResourceView_Release(ps_srv);
14296 ps_srv = NULL;
14298 ID3D11SamplerState_Release(sampler_state);
14299 sampler_state = NULL;
14301 ID3D11Texture2D_Release(dst_texture);
14302 ID3D11Texture2D_Release(src_texture);
14304 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14305 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14306 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14308 memset(float_colors, 0, sizeof(float_colors));
14309 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
14310 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
14312 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
14314 for (i = 0; i < 4; ++i)
14316 for (j = 0; j < 4; ++j)
14318 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
14319 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
14320 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
14321 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
14324 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
14325 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
14327 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
14328 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14329 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14330 draw_quad(&test_context);
14331 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14333 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
14334 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14335 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14336 draw_quad(&test_context);
14337 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14339 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
14340 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14341 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14342 draw_quad(&test_context);
14343 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14345 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
14346 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14347 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14348 draw_quad(&test_context);
14349 get_texture_readback(test_context.backbuffer, 0, &rb);
14350 for (i = 0; i < 4; ++i)
14352 for (j = 0; j < 4; ++j)
14354 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14355 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14356 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14357 color, j, i, bitmap_data[j + i * 4]);
14360 release_resource_readback(&rb);
14362 ID3D11Buffer_Release(dst_buffer);
14363 ID3D11Buffer_Release(src_buffer);
14364 ID3D11PixelShader_Release(ps);
14365 release_test_context(&test_context);
14368 static void test_copy_subresource_region_1d(void)
14370 D3D11_SUBRESOURCE_DATA resource_data[4];
14371 struct d3d11_test_context test_context;
14372 D3D11_TEXTURE1D_DESC texture1d_desc;
14373 D3D11_TEXTURE2D_DESC texture2d_desc;
14374 ID3D11DeviceContext *context;
14375 struct resource_readback rb;
14376 ID3D11Texture1D *texture1d;
14377 ID3D11Texture2D *texture2d;
14378 ID3D11Device *device;
14379 unsigned int i, j;
14380 D3D11_BOX box;
14381 DWORD color;
14382 HRESULT hr;
14384 static const DWORD bitmap_data[] =
14386 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14387 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14388 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14389 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14392 if (!init_test_context(&test_context, NULL))
14393 return;
14394 device = test_context.device;
14395 context = test_context.immediate_context;
14397 texture1d_desc.Width = 4;
14398 texture1d_desc.MipLevels = 1;
14399 texture1d_desc.ArraySize = 4;
14400 texture1d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14401 texture1d_desc.Usage = D3D11_USAGE_DEFAULT;
14402 texture1d_desc.BindFlags = 0;
14403 texture1d_desc.CPUAccessFlags = 0;
14404 texture1d_desc.MiscFlags = 0;
14406 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14408 resource_data[i].pSysMem = &bitmap_data[4 * i];
14409 resource_data[i].SysMemPitch = texture1d_desc.Width * sizeof(bitmap_data);
14410 resource_data[i].SysMemSlicePitch = 0;
14413 hr = ID3D11Device_CreateTexture1D(device, &texture1d_desc, resource_data, &texture1d);
14414 ok(hr == S_OK, "Failed to create 1d texture, hr %#x.\n", hr);
14416 texture2d_desc.Width = 4;
14417 texture2d_desc.Height = 4;
14418 texture2d_desc.MipLevels = 1;
14419 texture2d_desc.ArraySize = 1;
14420 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14421 texture2d_desc.SampleDesc.Count = 1;
14422 texture2d_desc.SampleDesc.Quality = 0;
14423 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
14424 texture2d_desc.BindFlags = 0;
14425 texture2d_desc.CPUAccessFlags = 0;
14426 texture2d_desc.MiscFlags = 0;
14428 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14429 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
14431 set_box(&box, 0, 0, 0, 4, 1, 1);
14432 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14434 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2d, 0,
14435 0, i, 0, (ID3D11Resource *)texture1d, i, &box);
14438 get_texture_readback(texture2d, 0, &rb);
14439 for (i = 0; i < 4; ++i)
14441 for (j = 0; j < 4; ++j)
14443 color = get_readback_color(&rb, j, i, 0);
14444 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14445 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14446 color, j, i, bitmap_data[j + i * 4]);
14449 release_resource_readback(&rb);
14451 get_texture1d_readback(texture1d, 0, &rb);
14452 for (i = 0; i < texture1d_desc.Width; ++i)
14454 color = get_readback_color(&rb, i, 0, 0);
14455 ok(compare_color(color, bitmap_data[i], 1),
14456 "Got color 0x%08x at %u, expected 0x%08x.\n",
14457 color, i, bitmap_data[i]);
14459 release_resource_readback(&rb);
14461 ID3D11Texture1D_Release(texture1d);
14462 ID3D11Texture2D_Release(texture2d);
14463 release_test_context(&test_context);
14466 static void test_copy_subresource_region_3d(void)
14468 ID3D11ShaderResourceView *dst_srv, *src_srv;
14469 ID3D11Texture3D *dst_texture, *src_texture;
14470 D3D11_SUBRESOURCE_DATA resource_data[4];
14471 struct d3d11_test_context test_context;
14472 D3D11_TEXTURE2D_DESC texture2d_desc;
14473 D3D11_TEXTURE3D_DESC texture3d_desc;
14474 ID3D11SamplerState *sampler_state;
14475 D3D11_SAMPLER_DESC sampler_desc;
14476 ID3D11DeviceContext *context;
14477 struct resource_readback rb;
14478 ID3D11Texture2D *texture2d;
14479 ID3D11PixelShader *ps;
14480 ID3D11Device *device;
14481 unsigned int i, j;
14482 DWORD data[4][16];
14483 D3D11_BOX box;
14484 DWORD color;
14485 HRESULT hr;
14487 static const DWORD ps_code[] =
14489 #if 0
14490 Texture3D t;
14491 SamplerState s;
14493 float4 main(float4 position : SV_POSITION) : SV_Target
14495 return t.Sample(s, position.xyz / float3(640, 480, 1));
14497 #endif
14498 0x43425844, 0x27b15ae8, 0xbebf46f7, 0x6cd88d8d, 0x5118de51, 0x00000001, 0x00000134, 0x00000003,
14499 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14500 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000070f, 0x505f5653, 0x5449534f, 0x004e4f49,
14501 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14502 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
14503 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
14504 0x04002064, 0x00101072, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14505 0x00000001, 0x0a000038, 0x00100072, 0x00000000, 0x00101246, 0x00000000, 0x00004002, 0x3acccccd,
14506 0x3b088889, 0x3f800000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
14507 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
14509 static const DWORD bitmap_data[] =
14511 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14512 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14513 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14514 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14517 if (!init_test_context(&test_context, NULL))
14518 return;
14519 device = test_context.device;
14520 context = test_context.immediate_context;
14522 texture3d_desc.Width = 4;
14523 texture3d_desc.Height = 4;
14524 texture3d_desc.Depth = 4;
14525 texture3d_desc.MipLevels = 1;
14526 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14527 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
14528 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14529 texture3d_desc.CPUAccessFlags = 0;
14530 texture3d_desc.MiscFlags = 0;
14532 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &src_texture);
14533 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
14534 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &dst_texture);
14535 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
14537 texture2d_desc.Width = 4;
14538 texture2d_desc.Height = 4;
14539 texture2d_desc.MipLevels = 1;
14540 texture2d_desc.ArraySize = 4;
14541 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14542 texture2d_desc.SampleDesc.Count = 1;
14543 texture2d_desc.SampleDesc.Quality = 0;
14544 texture2d_desc.Usage = D3D11_USAGE_IMMUTABLE;
14545 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14546 texture2d_desc.CPUAccessFlags = 0;
14547 texture2d_desc.MiscFlags = 0;
14549 for (i = 0; i < ARRAY_SIZE(*data); ++i)
14551 data[0][i] = 0xff0000ff;
14552 data[1][i] = bitmap_data[i];
14553 data[2][i] = 0xff00ff00;
14554 data[3][i] = 0xffff00ff;
14557 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14559 resource_data[i].pSysMem = data[i];
14560 resource_data[i].SysMemPitch = texture2d_desc.Width * sizeof(data[0][0]);
14561 resource_data[i].SysMemSlicePitch = 0;
14564 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, resource_data, &texture2d);
14565 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
14567 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)src_texture, NULL, &src_srv);
14568 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
14569 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &dst_srv);
14570 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
14572 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14573 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14574 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14575 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14576 sampler_desc.MipLODBias = 0.0f;
14577 sampler_desc.MaxAnisotropy = 0;
14578 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14579 sampler_desc.BorderColor[0] = 0.0f;
14580 sampler_desc.BorderColor[1] = 0.0f;
14581 sampler_desc.BorderColor[2] = 0.0f;
14582 sampler_desc.BorderColor[3] = 0.0f;
14583 sampler_desc.MinLOD = 0.0f;
14584 sampler_desc.MaxLOD = 0.0f;
14586 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
14587 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14589 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14590 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
14592 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &src_srv);
14593 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14594 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14596 set_box(&box, 0, 0, 0, 4, 4, 1);
14597 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14599 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
14600 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
14602 draw_quad(&test_context);
14603 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14604 draw_quad_z(&test_context, 0.25f);
14605 get_texture_readback(test_context.backbuffer, 0, &rb);
14606 for (i = 0; i < 4; ++i)
14608 for (j = 0; j < 4; ++j)
14610 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14611 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14612 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14613 color, j, i, bitmap_data[j + i * 4]);
14616 release_resource_readback(&rb);
14617 draw_quad_z(&test_context, 0.5f);
14618 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14619 draw_quad_z(&test_context, 1.0f);
14620 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
14622 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &dst_srv);
14624 set_box(&box, 0, 0, 0, 4, 4, 2);
14625 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14626 0, 0, 2, (ID3D11Resource *)src_texture, 0, &box);
14627 set_box(&box, 0, 0, 2, 4, 4, 4);
14628 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14629 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14631 set_box(&box, 0, 0, 0, 4, 4, 1);
14632 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14634 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
14635 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
14637 draw_quad(&test_context);
14638 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14639 draw_quad_z(&test_context, 0.25f);
14640 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
14641 draw_quad_z(&test_context, 0.5f);
14642 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14643 draw_quad_z(&test_context, 1.0f);
14644 get_texture_readback(test_context.backbuffer, 0, &rb);
14645 for (i = 0; i < 4; ++i)
14647 for (j = 0; j < 4; ++j)
14649 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14650 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14651 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14652 color, j, i, bitmap_data[j + i * 4]);
14655 release_resource_readback(&rb);
14657 ID3D11PixelShader_Release(ps);
14658 ID3D11SamplerState_Release(sampler_state);
14659 ID3D11ShaderResourceView_Release(dst_srv);
14660 ID3D11ShaderResourceView_Release(src_srv);
14661 ID3D11Texture2D_Release(texture2d);
14662 ID3D11Texture3D_Release(dst_texture);
14663 ID3D11Texture3D_Release(src_texture);
14664 release_test_context(&test_context);
14667 static void test_resource_map(void)
14669 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
14670 D3D11_TEXTURE3D_DESC texture3d_desc;
14671 D3D11_TEXTURE2D_DESC texture2d_desc;
14672 D3D11_BUFFER_DESC buffer_desc;
14673 ID3D11DeviceContext *context;
14674 ID3D11Texture3D *texture3d;
14675 ID3D11Texture2D *texture2d;
14676 ID3D11Buffer *buffer;
14677 ID3D11Device *device;
14678 ULONG refcount;
14679 HRESULT hr;
14680 DWORD data;
14682 if (!(device = create_device(NULL)))
14684 skip("Failed to create device.\n");
14685 return;
14688 ID3D11Device_GetImmediateContext(device, &context);
14690 buffer_desc.ByteWidth = 1024;
14691 buffer_desc.Usage = D3D11_USAGE_STAGING;
14692 buffer_desc.BindFlags = 0;
14693 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14694 buffer_desc.MiscFlags = 0;
14695 buffer_desc.StructureByteStride = 0;
14697 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14698 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14700 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14701 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14703 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14704 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14705 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
14706 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14707 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
14708 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14709 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
14711 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14712 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14713 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
14714 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14715 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
14716 data = *((DWORD *)mapped_subresource.pData);
14717 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14718 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
14720 refcount = ID3D11Buffer_Release(buffer);
14721 ok(!refcount, "Buffer has %u references left.\n", refcount);
14723 texture2d_desc.Width = 512;
14724 texture2d_desc.Height = 512;
14725 texture2d_desc.MipLevels = 1;
14726 texture2d_desc.ArraySize = 1;
14727 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14728 texture2d_desc.SampleDesc.Count = 1;
14729 texture2d_desc.SampleDesc.Quality = 0;
14730 texture2d_desc.Usage = D3D11_USAGE_STAGING;
14731 texture2d_desc.BindFlags = 0;
14732 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14733 texture2d_desc.MiscFlags = 0;
14735 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14736 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14738 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14739 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14741 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14742 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14743 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14744 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14745 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
14746 mapped_subresource.DepthPitch);
14747 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14748 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
14750 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14751 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14752 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14753 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14754 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
14755 mapped_subresource.DepthPitch);
14756 data = *((DWORD *)mapped_subresource.pData);
14757 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14758 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
14760 refcount = ID3D11Texture2D_Release(texture2d);
14761 ok(!refcount, "2D texture has %u references left.\n", refcount);
14763 texture3d_desc.Width = 64;
14764 texture3d_desc.Height = 64;
14765 texture3d_desc.Depth = 64;
14766 texture3d_desc.MipLevels = 1;
14767 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14768 texture3d_desc.Usage = D3D11_USAGE_STAGING;
14769 texture3d_desc.BindFlags = 0;
14770 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14771 texture3d_desc.MiscFlags = 0;
14773 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14774 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
14776 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14777 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14779 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14780 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14781 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14782 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14783 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
14784 mapped_subresource.DepthPitch);
14785 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14786 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
14788 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14789 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14790 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14791 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14792 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
14793 mapped_subresource.DepthPitch);
14794 data = *((DWORD *)mapped_subresource.pData);
14795 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14796 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
14798 refcount = ID3D11Texture3D_Release(texture3d);
14799 ok(!refcount, "3D texture has %u references left.\n", refcount);
14801 ID3D11DeviceContext_Release(context);
14803 refcount = ID3D11Device_Release(device);
14804 ok(!refcount, "Device has %u references left.\n", refcount);
14807 #define check_resource_cpu_access(a, b, c, d, e) check_resource_cpu_access_(__LINE__, a, b, c, d, e)
14808 static void check_resource_cpu_access_(unsigned int line, ID3D11DeviceContext *context,
14809 ID3D11Resource *resource, D3D11_USAGE usage, UINT bind_flags, UINT cpu_access)
14811 BOOL cpu_write = cpu_access & D3D11_CPU_ACCESS_WRITE;
14812 BOOL cpu_read = cpu_access & D3D11_CPU_ACCESS_READ;
14813 BOOL dynamic = usage == D3D11_USAGE_DYNAMIC;
14814 D3D11_MAPPED_SUBRESOURCE map_desc;
14815 HRESULT hr, expected_hr;
14816 ID3D11Device *device;
14818 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
14819 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ, 0, &map_desc);
14820 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
14821 if (SUCCEEDED(hr))
14822 ID3D11DeviceContext_Unmap(context, resource, 0);
14824 /* WRITE_DISCARD and WRITE_NO_OVERWRITE are the only allowed options for dynamic resources. */
14825 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
14826 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE, 0, &map_desc);
14827 todo_wine_if(dynamic && cpu_write)
14828 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
14829 if (SUCCEEDED(hr))
14830 ID3D11DeviceContext_Unmap(context, resource, 0);
14832 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
14833 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
14834 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
14835 if (SUCCEEDED(hr))
14836 ID3D11DeviceContext_Unmap(context, resource, 0);
14838 expected_hr = dynamic ? S_OK : E_INVALIDARG;
14839 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
14840 todo_wine_if(!dynamic && cpu_write)
14841 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
14842 if (SUCCEEDED(hr))
14843 ID3D11DeviceContext_Unmap(context, resource, 0);
14845 if (!dynamic)
14846 return;
14848 ID3D11DeviceContext_GetDevice(context, &device);
14850 /* WRITE_NO_OVERWRITE is supported only for buffers. */
14851 expected_hr = is_buffer(resource) ? S_OK : E_INVALIDARG;
14852 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
14853 /* D3D11.1 is required for constant and shader buffers. */
14854 todo_wine_if(expected_hr != S_OK)
14855 ok_(__FILE__, line)(hr == expected_hr
14856 || broken(bind_flags & (D3D11_BIND_CONSTANT_BUFFER | D3D11_BIND_SHADER_RESOURCE)),
14857 "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
14858 if (SUCCEEDED(hr))
14859 ID3D11DeviceContext_Unmap(context, resource, 0);
14861 ID3D11Device_Release(device);
14864 static void test_resource_access(const D3D_FEATURE_LEVEL feature_level)
14866 D3D11_TEXTURE2D_DESC texture_desc;
14867 struct device_desc device_desc;
14868 D3D11_BUFFER_DESC buffer_desc;
14869 ID3D11DeviceContext *context;
14870 D3D11_SUBRESOURCE_DATA data;
14871 ID3D11Resource *resource;
14872 BOOL required_cpu_access;
14873 BOOL cpu_write, cpu_read;
14874 HRESULT hr, expected_hr;
14875 UINT allowed_cpu_access;
14876 BOOL broken_validation;
14877 ID3D11Device *device;
14878 unsigned int i;
14879 ULONG refcount;
14881 static const struct
14883 D3D11_USAGE usage;
14884 UINT bind_flags;
14885 BOOL is_valid;
14886 UINT allowed_cpu_access;
14888 tests[] =
14890 /* Default resources cannot be written by CPU. */
14891 {D3D11_USAGE_DEFAULT, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
14892 {D3D11_USAGE_DEFAULT, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
14893 {D3D11_USAGE_DEFAULT, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
14894 {D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
14895 {D3D11_USAGE_DEFAULT, D3D11_BIND_STREAM_OUTPUT, TRUE, 0},
14896 {D3D11_USAGE_DEFAULT, D3D11_BIND_RENDER_TARGET, TRUE, 0},
14897 {D3D11_USAGE_DEFAULT, D3D11_BIND_DEPTH_STENCIL, TRUE, 0},
14898 {D3D11_USAGE_DEFAULT, D3D11_BIND_UNORDERED_ACCESS, TRUE, 0},
14900 /* Immutable resources cannot be written by CPU and GPU. */
14901 {D3D11_USAGE_IMMUTABLE, 0, FALSE, 0},
14902 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
14903 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
14904 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
14905 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
14906 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
14907 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_RENDER_TARGET, FALSE, 0},
14908 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
14909 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
14911 /* Dynamic resources cannot be written by GPU. */
14912 {D3D11_USAGE_DYNAMIC, 0, FALSE, D3D11_CPU_ACCESS_WRITE},
14913 {D3D11_USAGE_DYNAMIC, D3D11_BIND_VERTEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
14914 {D3D11_USAGE_DYNAMIC, D3D11_BIND_INDEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
14915 {D3D11_USAGE_DYNAMIC, D3D11_BIND_CONSTANT_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
14916 {D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE, TRUE, D3D11_CPU_ACCESS_WRITE},
14917 {D3D11_USAGE_DYNAMIC, D3D11_BIND_STREAM_OUTPUT, FALSE, D3D11_CPU_ACCESS_WRITE},
14918 {D3D11_USAGE_DYNAMIC, D3D11_BIND_RENDER_TARGET, FALSE, D3D11_CPU_ACCESS_WRITE},
14919 {D3D11_USAGE_DYNAMIC, D3D11_BIND_DEPTH_STENCIL, FALSE, D3D11_CPU_ACCESS_WRITE},
14920 {D3D11_USAGE_DYNAMIC, D3D11_BIND_UNORDERED_ACCESS, FALSE, D3D11_CPU_ACCESS_WRITE},
14922 /* Staging resources support only data transfer. */
14923 {D3D11_USAGE_STAGING, 0, TRUE, D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ},
14924 {D3D11_USAGE_STAGING, D3D11_BIND_VERTEX_BUFFER, FALSE, 0},
14925 {D3D11_USAGE_STAGING, D3D11_BIND_INDEX_BUFFER, FALSE, 0},
14926 {D3D11_USAGE_STAGING, D3D11_BIND_CONSTANT_BUFFER, FALSE, 0},
14927 {D3D11_USAGE_STAGING, D3D11_BIND_SHADER_RESOURCE, FALSE, 0},
14928 {D3D11_USAGE_STAGING, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
14929 {D3D11_USAGE_STAGING, D3D11_BIND_RENDER_TARGET, FALSE, 0},
14930 {D3D11_USAGE_STAGING, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
14931 {D3D11_USAGE_STAGING, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
14934 device_desc.feature_level = &feature_level;
14935 device_desc.flags = 0;
14936 if (!(device = create_device(&device_desc)))
14938 skip("Failed to create device for feature level %#x.\n", feature_level);
14939 return;
14941 ID3D11Device_GetImmediateContext(device, &context);
14943 data.SysMemPitch = 0;
14944 data.SysMemSlicePitch = 0;
14945 data.pSysMem = heap_alloc(10240);
14946 ok(!!data.pSysMem, "Failed to allocate memory.\n");
14948 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14950 switch (tests[i].bind_flags)
14952 case D3D11_BIND_DEPTH_STENCIL:
14953 continue;
14955 case D3D11_BIND_SHADER_RESOURCE:
14956 case D3D11_BIND_STREAM_OUTPUT:
14957 case D3D11_BIND_RENDER_TARGET:
14958 if (feature_level < D3D_FEATURE_LEVEL_10_0)
14959 continue;
14960 break;
14962 case D3D11_BIND_UNORDERED_ACCESS:
14963 if (feature_level < D3D_FEATURE_LEVEL_11_0)
14964 continue;
14965 break;
14967 default:
14968 break;
14971 allowed_cpu_access = tests[i].allowed_cpu_access;
14972 if (feature_level >= D3D_FEATURE_LEVEL_11_0 && is_d3d11_2_runtime(device)
14973 && tests[i].usage == D3D11_USAGE_DEFAULT
14974 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
14975 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS))
14976 allowed_cpu_access |= D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
14978 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
14979 cpu_write = allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
14980 cpu_read = allowed_cpu_access & D3D11_CPU_ACCESS_READ;
14982 buffer_desc.ByteWidth = 1024;
14983 buffer_desc.Usage = tests[i].usage;
14984 buffer_desc.BindFlags = tests[i].bind_flags;
14985 buffer_desc.MiscFlags = 0;
14986 buffer_desc.StructureByteStride = 0;
14988 buffer_desc.CPUAccessFlags = 0;
14989 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
14990 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
14991 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
14992 if (SUCCEEDED(hr))
14994 check_resource_cpu_access(context, resource,
14995 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
14996 ID3D11Resource_Release(resource);
14999 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
15000 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
15001 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15002 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15003 if (SUCCEEDED(hr))
15005 check_resource_cpu_access(context, resource,
15006 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15007 ID3D11Resource_Release(resource);
15010 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
15011 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
15012 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15013 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15014 if (SUCCEEDED(hr))
15016 check_resource_cpu_access(context, resource,
15017 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15018 ID3D11Resource_Release(resource);
15021 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
15022 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
15023 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15024 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15025 if (SUCCEEDED(hr))
15027 check_resource_cpu_access(context, resource,
15028 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15029 ID3D11Resource_Release(resource);
15033 data.SysMemPitch = 16;
15035 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15037 switch (tests[i].bind_flags)
15039 case D3D11_BIND_VERTEX_BUFFER:
15040 case D3D11_BIND_INDEX_BUFFER:
15041 case D3D11_BIND_CONSTANT_BUFFER:
15042 case D3D11_BIND_STREAM_OUTPUT:
15043 continue;
15045 case D3D11_BIND_UNORDERED_ACCESS:
15046 if (feature_level < D3D_FEATURE_LEVEL_11_0)
15047 continue;
15048 break;
15050 default:
15051 break;
15054 broken_validation = tests[i].usage == D3D11_USAGE_DEFAULT
15055 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
15056 || tests[i].bind_flags == D3D11_BIND_RENDER_TARGET
15057 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS);
15059 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
15060 cpu_write = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
15061 cpu_read = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_READ;
15063 texture_desc.Width = 4;
15064 texture_desc.Height = 4;
15065 texture_desc.MipLevels = 1;
15066 texture_desc.ArraySize = 1;
15067 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15068 texture_desc.SampleDesc.Count = 1;
15069 texture_desc.SampleDesc.Quality = 0;
15070 texture_desc.Usage = tests[i].usage;
15071 texture_desc.BindFlags = tests[i].bind_flags;
15072 texture_desc.MiscFlags = 0;
15073 if (tests[i].bind_flags == D3D11_BIND_DEPTH_STENCIL)
15074 texture_desc.Format = DXGI_FORMAT_D16_UNORM;
15076 texture_desc.CPUAccessFlags = 0;
15077 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
15078 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15079 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15080 if (SUCCEEDED(hr))
15082 check_resource_cpu_access(context, resource,
15083 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15084 ID3D11Resource_Release(resource);
15087 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
15088 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
15089 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15090 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15091 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15092 if (SUCCEEDED(hr))
15094 if (broken_validation)
15095 texture_desc.CPUAccessFlags = 0;
15096 check_resource_cpu_access(context, resource,
15097 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15098 ID3D11Resource_Release(resource);
15101 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
15102 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
15103 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15104 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15105 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15106 if (SUCCEEDED(hr))
15108 if (broken_validation)
15109 texture_desc.CPUAccessFlags = 0;
15110 check_resource_cpu_access(context, resource,
15111 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15112 ID3D11Resource_Release(resource);
15115 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
15116 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
15117 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15118 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15119 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15120 if (SUCCEEDED(hr))
15122 if (broken_validation)
15123 texture_desc.CPUAccessFlags = 0;
15124 check_resource_cpu_access(context, resource,
15125 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15126 ID3D11Resource_Release(resource);
15130 heap_free((void *)data.pSysMem);
15132 ID3D11DeviceContext_Release(context);
15133 refcount = ID3D11Device_Release(device);
15134 ok(!refcount, "Device has %u references left.\n", refcount);
15137 static void test_check_multisample_quality_levels(void)
15139 ID3D11Device *device;
15140 UINT quality_levels;
15141 ULONG refcount;
15142 HRESULT hr;
15144 if (!(device = create_device(NULL)))
15146 skip("Failed to create device.\n");
15147 return;
15150 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
15151 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
15152 if (!quality_levels)
15154 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
15155 goto done;
15158 quality_levels = 0xdeadbeef;
15159 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
15160 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15161 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15162 quality_levels = 0xdeadbeef;
15163 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
15164 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15165 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
15167 if (!enable_debug_layer)
15169 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
15170 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15171 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
15172 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15173 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
15174 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15177 quality_levels = 0xdeadbeef;
15178 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
15179 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15180 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15182 quality_levels = 0xdeadbeef;
15183 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
15184 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15185 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
15187 quality_levels = 0xdeadbeef;
15188 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
15189 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15190 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15192 /* We assume 15 samples multisampling is never supported in practice. */
15193 quality_levels = 0xdeadbeef;
15194 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
15195 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15196 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15197 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
15198 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15199 quality_levels = 0xdeadbeef;
15200 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
15201 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15202 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15203 quality_levels = 0xdeadbeef;
15204 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
15205 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15206 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15208 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
15209 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15210 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15212 done:
15213 refcount = ID3D11Device_Release(device);
15214 ok(!refcount, "Device has %u references left.\n", refcount);
15217 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
15219 DXGI_SWAP_CHAIN_DESC swapchain_desc;
15220 struct device_desc device_desc;
15221 IDXGISwapChain *swapchain;
15222 IDXGIDevice *dxgi_device;
15223 HRESULT hr, expected_hr;
15224 IDXGIAdapter *adapter;
15225 IDXGIFactory *factory;
15226 ID3D11Device *device;
15227 unsigned int i;
15228 ULONG refcount;
15230 swapchain_desc.BufferDesc.Width = 800;
15231 swapchain_desc.BufferDesc.Height = 600;
15232 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
15233 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
15234 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
15235 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
15236 swapchain_desc.SampleDesc.Count = 1;
15237 swapchain_desc.SampleDesc.Quality = 0;
15238 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
15239 swapchain_desc.BufferCount = 1;
15240 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
15241 swapchain_desc.Windowed = TRUE;
15242 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
15243 swapchain_desc.Flags = 0;
15245 device_desc.feature_level = &feature_level;
15246 device_desc.flags = 0;
15247 if (!(device = create_device(&device_desc)))
15249 skip("Failed to create device for feature level %#x.\n", feature_level);
15250 return;
15253 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
15254 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
15255 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
15256 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
15257 IDXGIDevice_Release(dxgi_device);
15258 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
15259 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
15260 IDXGIAdapter_Release(adapter);
15262 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15263 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
15264 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
15265 hr, feature_level);
15266 if (SUCCEEDED(hr))
15267 IDXGISwapChain_Release(swapchain);
15269 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
15271 DXGI_FORMAT format = display_format_support[i].format;
15272 BOOL todo = FALSE;
15274 if (display_format_support[i].fl_required <= feature_level)
15276 expected_hr = S_OK;
15277 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
15278 todo = TRUE;
15280 else if (!display_format_support[i].fl_optional
15281 || display_format_support[i].fl_optional > feature_level)
15283 expected_hr = E_INVALIDARG;
15284 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
15285 todo = TRUE;
15287 else
15289 continue;
15292 swapchain_desc.BufferDesc.Format = format;
15293 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
15294 todo_wine_if(todo)
15295 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
15296 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
15297 hr, expected_hr, feature_level, format);
15298 if (FAILED(hr))
15299 continue;
15300 refcount = IDXGISwapChain_Release(swapchain);
15301 ok(!refcount, "Swapchain has %u references left.\n", refcount);
15304 refcount = ID3D11Device_Release(device);
15305 ok(!refcount, "Device has %u references left.\n", refcount);
15306 refcount = IDXGIFactory_Release(factory);
15307 ok(!refcount, "Factory has %u references left.\n", refcount);
15308 DestroyWindow(swapchain_desc.OutputWindow);
15311 static void test_swapchain_views(void)
15313 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
15314 struct d3d11_test_context test_context;
15315 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15316 ID3D11ShaderResourceView *srv;
15317 ID3D11DeviceContext *context;
15318 ID3D11RenderTargetView *rtv;
15319 ID3D11Device *device;
15320 ULONG refcount;
15321 HRESULT hr;
15323 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
15325 if (!init_test_context(&test_context, NULL))
15326 return;
15328 device = test_context.device;
15329 context = test_context.immediate_context;
15331 refcount = get_refcount(test_context.backbuffer);
15332 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
15334 draw_color_quad(&test_context, &color);
15335 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
15337 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15338 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15339 U(rtv_desc).Texture2D.MipSlice = 0;
15340 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
15341 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15342 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15344 refcount = get_refcount(test_context.backbuffer);
15345 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
15347 draw_color_quad(&test_context, &color);
15348 check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
15350 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15351 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
15352 U(srv_desc).Texture2D.MostDetailedMip = 0;
15353 U(srv_desc).Texture2D.MipLevels = 1;
15354 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
15355 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15356 if (SUCCEEDED(hr))
15357 ID3D11ShaderResourceView_Release(srv);
15359 ID3D11RenderTargetView_Release(rtv);
15360 release_test_context(&test_context);
15363 static void test_swapchain_flip(void)
15365 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
15366 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
15367 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
15368 D3D11_TEXTURE2D_DESC texture_desc;
15369 ID3D11InputLayout *input_layout;
15370 ID3D11DeviceContext *context;
15371 unsigned int stride, offset;
15372 struct swapchain_desc desc;
15373 IDXGISwapChain *swapchain;
15374 ID3D11VertexShader *vs;
15375 ID3D11PixelShader *ps;
15376 ID3D11Device *device;
15377 ID3D11Buffer *vb;
15378 ULONG refcount;
15379 DWORD color;
15380 HWND window;
15381 HRESULT hr;
15382 RECT rect;
15384 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15386 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15388 static const DWORD vs_code[] =
15390 #if 0
15391 float4 main(float4 position : POSITION) : SV_POSITION
15393 return position;
15395 #endif
15396 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
15397 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15398 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
15399 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
15400 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
15401 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15402 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
15405 static const DWORD ps_code[] =
15407 #if 0
15408 Texture2D t0, t1;
15409 SamplerState s;
15411 float4 main(float4 position : SV_POSITION) : SV_Target
15413 float2 p;
15415 p.x = 0.5;
15416 p.y = 0.5;
15417 if (position.x < 320)
15418 return t0.Sample(s, p);
15419 return t1.Sample(s, p);
15421 #endif
15422 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
15423 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15424 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
15425 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15426 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
15427 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
15428 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
15429 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
15430 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
15431 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
15432 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
15433 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
15434 0x00000000, 0x0100003e,
15436 static const struct vec2 quad[] =
15438 {-1.0f, -1.0f},
15439 {-1.0f, 1.0f},
15440 { 1.0f, -1.0f},
15441 { 1.0f, 1.0f},
15443 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
15444 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15445 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
15447 if (!(device = create_device(NULL)))
15449 skip("Failed to create device, skipping tests.\n");
15450 return;
15452 SetRect(&rect, 0, 0, 640, 480);
15453 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
15454 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
15455 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
15456 desc.buffer_count = 3;
15457 desc.width = desc.height = 0;
15458 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
15459 desc.windowed = TRUE;
15460 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
15461 swapchain = create_swapchain(device, window, &desc);
15463 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
15464 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15465 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
15466 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15467 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
15468 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15470 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
15471 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15472 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
15473 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15474 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
15475 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15477 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
15478 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
15479 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
15480 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
15481 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
15483 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
15484 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
15485 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
15486 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
15487 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
15489 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
15490 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15491 if (SUCCEEDED(hr))
15492 ID3D11RenderTargetView_Release(offscreen_rtv);
15494 ID3D11Device_GetImmediateContext(device, &context);
15496 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
15497 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
15499 texture_desc.Width = 640;
15500 texture_desc.Height = 480;
15501 texture_desc.MipLevels = 1;
15502 texture_desc.ArraySize = 1;
15503 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15504 texture_desc.SampleDesc.Count = 1;
15505 texture_desc.SampleDesc.Quality = 0;
15506 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15507 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15508 texture_desc.CPUAccessFlags = 0;
15509 texture_desc.MiscFlags = 0;
15510 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
15511 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
15512 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
15513 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15514 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
15515 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
15517 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
15519 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15520 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15521 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15522 vs_code, sizeof(vs_code), &input_layout);
15523 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15524 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15525 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
15526 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15527 stride = sizeof(*quad);
15528 offset = 0;
15529 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15531 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15532 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15533 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15535 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
15537 ID3D11DeviceContext_Draw(context, 4, 0);
15538 color = get_texture_color(offscreen, 120, 240);
15539 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15541 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
15542 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
15543 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
15545 * What is this good for? I don't know. Ad-hoc tests suggest that
15546 * Present() always waits for the next V-sync interval, even if there are
15547 * still untouched buffers. Buffer 0 is the buffer that is shown on the
15548 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
15549 * rendering finishes before the V-sync interval is over. I haven't found
15550 * any productive use for more than one buffer. */
15551 IDXGISwapChain_Present(swapchain, 0, 0);
15553 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
15555 ID3D11DeviceContext_Draw(context, 4, 0);
15556 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
15557 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15558 /* Buffer 1 is still untouched. */
15560 color = get_texture_color(backbuffer_0, 320, 240); /* green */
15561 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15562 color = get_texture_color(backbuffer_2, 320, 240); /* red */
15563 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15565 IDXGISwapChain_Present(swapchain, 0, 0);
15567 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
15569 ID3D11DeviceContext_Draw(context, 4, 0);
15570 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
15571 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
15572 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
15573 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15575 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
15576 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
15577 color = get_texture_color(backbuffer_1, 320, 240); /* red */
15578 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15579 color = get_texture_color(backbuffer_2, 320, 240); /* green */
15580 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15582 ID3D11VertexShader_Release(vs);
15583 ID3D11PixelShader_Release(ps);
15584 ID3D11Buffer_Release(vb);
15585 ID3D11InputLayout_Release(input_layout);
15586 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
15587 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
15588 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
15589 ID3D11RenderTargetView_Release(offscreen_rtv);
15590 ID3D11Texture2D_Release(offscreen);
15591 ID3D11Texture2D_Release(backbuffer_0);
15592 ID3D11Texture2D_Release(backbuffer_1);
15593 ID3D11Texture2D_Release(backbuffer_2);
15594 IDXGISwapChain_Release(swapchain);
15596 ID3D11DeviceContext_Release(context);
15597 refcount = ID3D11Device_Release(device);
15598 ok(!refcount, "Device has %u references left.\n", refcount);
15599 DestroyWindow(window);
15602 static void test_clear_render_target_view_1d(void)
15604 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
15605 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15607 struct d3d11_test_context test_context;
15608 D3D11_TEXTURE1D_DESC texture_desc;
15609 ID3D11DeviceContext *context;
15610 ID3D11RenderTargetView *rtv;
15611 ID3D11Texture1D *texture;
15612 ID3D11Device *device;
15613 HRESULT hr;
15615 if (!init_test_context(&test_context, NULL))
15616 return;
15618 device = test_context.device;
15619 context = test_context.immediate_context;
15621 texture_desc.Width = 64;
15622 texture_desc.MipLevels = 1;
15623 texture_desc.ArraySize = 1;
15624 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15625 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15626 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15627 texture_desc.CPUAccessFlags = 0;
15628 texture_desc.MiscFlags = 0;
15629 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, NULL, &texture);
15630 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15632 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15633 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15635 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15636 check_texture1d_color(texture, 0xbf4c7f19, 1);
15638 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15639 check_texture1d_color(texture, 0x8000ff00, 1);
15641 ID3D11RenderTargetView_Release(rtv);
15642 ID3D11Texture1D_Release(texture);
15643 release_test_context(&test_context);
15646 static void test_clear_render_target_view_2d(void)
15648 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
15649 static const float clear_colour[] = {0.1f, 0.5f, 0.3f, 0.75f};
15650 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15651 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
15653 ID3D11RenderTargetView *rtv[3], *srgb_rtv;
15654 ID3D11Texture2D *texture, *srgb_texture;
15655 struct d3d11_test_context test_context;
15656 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15657 D3D11_TEXTURE2D_DESC texture_desc;
15658 ID3D11DeviceContext *context;
15659 struct resource_readback rb;
15660 ID3D11Device *device;
15661 unsigned int i, j;
15662 DWORD colour;
15663 HRESULT hr;
15665 if (!init_test_context(&test_context, NULL))
15666 return;
15668 device = test_context.device;
15669 context = test_context.immediate_context;
15671 texture_desc.Width = 640;
15672 texture_desc.Height = 480;
15673 texture_desc.MipLevels = 1;
15674 texture_desc.ArraySize = 1;
15675 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15676 texture_desc.SampleDesc.Count = 1;
15677 texture_desc.SampleDesc.Quality = 0;
15678 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15679 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15680 texture_desc.CPUAccessFlags = 0;
15681 texture_desc.MiscFlags = 0;
15682 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15683 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15685 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15686 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
15687 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15689 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv[0]);
15690 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15692 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
15693 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15695 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, clear_colour);
15696 check_texture_color(test_context.backbuffer, expected_color, 1);
15698 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], clear_colour);
15699 check_texture_color(texture, expected_color, 1);
15701 if (!enable_debug_layer)
15702 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
15703 check_texture_color(texture, expected_color, 1);
15705 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, clear_colour);
15706 check_texture_color(srgb_texture, expected_srgb_color, 1);
15708 ID3D11RenderTargetView_Release(srgb_rtv);
15709 ID3D11RenderTargetView_Release(rtv[0]);
15710 ID3D11Texture2D_Release(srgb_texture);
15711 ID3D11Texture2D_Release(texture);
15713 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15714 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15715 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15717 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15718 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15719 U(rtv_desc).Texture2D.MipSlice = 0;
15720 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
15721 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15723 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15724 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15725 U(rtv_desc).Texture2D.MipSlice = 0;
15726 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[0]);
15727 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15729 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], clear_colour);
15730 check_texture_color(texture, expected_color, 1);
15732 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, clear_colour);
15733 get_texture_readback(texture, 0, &rb);
15734 for (i = 0; i < 4; ++i)
15736 for (j = 0; j < 4; ++j)
15738 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
15739 colour = get_readback_color(&rb, 80 + i * 160, 60 + j * 120, 0);
15740 ok(compare_color(colour, expected_srgb_color, 1)
15741 || broken(compare_color(colour, expected_color, 1) && broken_device),
15742 "Got unexpected colour 0x%08x.\n", colour);
15745 release_resource_readback(&rb);
15747 ID3D11RenderTargetView_Release(srgb_rtv);
15748 ID3D11RenderTargetView_Release(rtv[0]);
15749 ID3D11Texture2D_Release(texture);
15751 texture_desc.Width = 16;
15752 texture_desc.Height = 16;
15753 texture_desc.ArraySize = 5;
15754 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15755 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15757 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
15758 U(rtv_desc).Texture2DArray.MipSlice = 0;
15759 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
15760 U(rtv_desc).Texture2DArray.ArraySize = 5;
15761 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[0]);
15762 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15764 U(rtv_desc).Texture2DArray.FirstArraySlice = 1;
15765 U(rtv_desc).Texture2DArray.ArraySize = 3;
15766 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[1]);
15767 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15769 U(rtv_desc).Texture2DArray.FirstArraySlice = 2;
15770 U(rtv_desc).Texture2DArray.ArraySize = 1;
15771 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[2]);
15772 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15774 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], blue);
15775 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[1], green);
15776 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[2], clear_colour);
15778 get_texture_readback(texture, 0, &rb);
15779 colour = get_readback_color(&rb, 8, 8, 0);
15780 ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
15781 release_resource_readback(&rb);
15783 get_texture_readback(texture, 1, &rb);
15784 colour = get_readback_color(&rb, 8, 8, 0);
15785 ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
15786 release_resource_readback(&rb);
15788 get_texture_readback(texture, 2, &rb);
15789 colour = get_readback_color(&rb, 8, 8, 0);
15790 ok(compare_color(colour, 0xbf4c7f19, 1), "Got unexpected colour 0x%08x.\n", colour);
15791 release_resource_readback(&rb);
15793 get_texture_readback(texture, 3, &rb);
15794 colour = get_readback_color(&rb, 8, 8, 0);
15795 ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
15796 release_resource_readback(&rb);
15798 get_texture_readback(texture, 4, &rb);
15799 colour = get_readback_color(&rb, 8, 8, 0);
15800 ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
15801 release_resource_readback(&rb);
15803 ID3D11RenderTargetView_Release(rtv[2]);
15804 ID3D11RenderTargetView_Release(rtv[1]);
15805 ID3D11RenderTargetView_Release(rtv[0]);
15806 ID3D11Texture2D_Release(texture);
15808 release_test_context(&test_context);
15811 static void test_clear_render_target_view_3d(void)
15813 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
15814 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15816 struct d3d11_test_context test_context;
15817 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15818 D3D11_TEXTURE3D_DESC texture_desc;
15819 ID3D11DeviceContext *context;
15820 ID3D11RenderTargetView *rtv;
15821 ID3D11Texture3D *texture;
15822 ID3D11Device *device;
15823 HRESULT hr;
15825 if (!init_test_context(&test_context, NULL))
15826 return;
15827 device = test_context.device;
15828 context = test_context.immediate_context;
15830 texture_desc.Width = 8;
15831 texture_desc.Height = 8;
15832 texture_desc.Depth = 4;
15833 texture_desc.MipLevels = 1;
15834 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15835 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15836 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15837 texture_desc.CPUAccessFlags = 0;
15838 texture_desc.MiscFlags = 0;
15839 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
15840 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15842 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15843 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15845 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15846 check_texture3d_color(texture, 0xbf4c7f19, 1);
15847 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15848 check_texture3d_color(texture, 0x8000ff00, 1);
15850 ID3D11RenderTargetView_Release(rtv);
15851 ID3D11Texture3D_Release(texture);
15853 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15854 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
15855 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15857 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15858 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
15859 U(rtv_desc).Texture3D.MipSlice = 0;
15860 U(rtv_desc).Texture3D.FirstWSlice = 0;
15861 U(rtv_desc).Texture3D.WSize = ~0u;
15862 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
15863 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15865 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15866 check_texture3d_color(texture, 0xbf95bc59, 1);
15867 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15868 check_texture3d_color(texture, 0x8000ff00, 1);
15870 ID3D11RenderTargetView_Release(rtv);
15871 ID3D11Texture3D_Release(texture);
15872 release_test_context(&test_context);
15875 static void test_clear_depth_stencil_view(void)
15877 D3D11_TEXTURE2D_DESC texture_desc;
15878 ID3D11Texture2D *depth_texture;
15879 ID3D11DeviceContext *context;
15880 ID3D11DepthStencilView *dsv;
15881 ID3D11Device *device;
15882 ULONG refcount;
15883 HRESULT hr;
15885 if (!(device = create_device(NULL)))
15887 skip("Failed to create device.\n");
15888 return;
15891 ID3D11Device_GetImmediateContext(device, &context);
15893 texture_desc.Width = 640;
15894 texture_desc.Height = 480;
15895 texture_desc.MipLevels = 1;
15896 texture_desc.ArraySize = 1;
15897 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
15898 texture_desc.SampleDesc.Count = 1;
15899 texture_desc.SampleDesc.Quality = 0;
15900 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15901 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
15902 texture_desc.CPUAccessFlags = 0;
15903 texture_desc.MiscFlags = 0;
15904 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
15905 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
15907 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
15908 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
15910 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
15911 check_texture_float(depth_texture, 1.0f, 0);
15913 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
15914 check_texture_float(depth_texture, 0.25f, 0);
15916 if (!enable_debug_layer)
15917 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
15918 check_texture_float(depth_texture, 0.25f, 0);
15920 ID3D11Texture2D_Release(depth_texture);
15921 ID3D11DepthStencilView_Release(dsv);
15923 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
15924 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
15925 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
15927 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
15928 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
15930 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
15931 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
15933 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
15934 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
15936 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
15937 check_texture_color(depth_texture, 0xffffffff, 0);
15939 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
15940 check_texture_color(depth_texture, 0x00000000, 0);
15942 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
15943 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
15945 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
15946 check_texture_color(depth_texture, 0xffffffff, 0);
15948 ID3D11Texture2D_Release(depth_texture);
15949 ID3D11DepthStencilView_Release(dsv);
15951 ID3D11DeviceContext_Release(context);
15953 refcount = ID3D11Device_Release(device);
15954 ok(!refcount, "Device has %u references left.\n", refcount);
15957 static unsigned int to_sint8(unsigned int x)
15959 union
15961 signed int s;
15962 unsigned int u;
15963 } bits;
15964 bits.u = x;
15965 return min(max(bits.s, -128), 127) & 0xff;
15968 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
15969 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
15971 unsigned int x = to_sint8(v->x);
15972 unsigned int y = to_sint8(v->y);
15973 unsigned int z = to_sint8(v->z);
15974 unsigned int w = to_sint8(v->w);
15975 DWORD expected[] =
15977 /* Windows 7 - Nvidia, WARP */
15978 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
15979 /* Windows 10 - AMD */
15980 x | y << 8 | z << 16 | w << 24,
15981 /* Windows 10 - Intel */
15982 x | x << 8 | x << 16 | x << 24,
15985 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
15986 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
15987 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
15990 static void test_clear_buffer_unordered_access_view(void)
15992 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
15993 ID3D11UnorderedAccessView *uav, *uav2;
15994 struct device_desc device_desc;
15995 D3D11_BUFFER_DESC buffer_desc;
15996 ID3D11DeviceContext *context;
15997 struct resource_readback rb;
15998 ID3D11Buffer *buffer;
15999 ID3D11Device *device;
16000 struct uvec4 uvec4;
16001 unsigned int i, x;
16002 ULONG refcount;
16003 HRESULT hr;
16004 RECT rect;
16006 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16007 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
16008 static const struct uvec4 uvec4_data[] =
16010 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
16012 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
16013 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
16014 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
16015 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
16016 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
16018 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
16019 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
16020 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
16021 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
16022 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
16023 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
16024 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
16026 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
16027 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
16028 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
16029 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
16030 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
16031 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
16032 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
16033 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
16034 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
16035 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
16037 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
16038 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
16039 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
16040 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
16041 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
16042 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
16043 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
16044 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
16045 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
16046 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
16048 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
16049 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
16050 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
16051 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
16052 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
16053 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
16054 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
16055 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
16056 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
16057 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
16059 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
16060 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
16061 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
16062 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
16063 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
16064 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
16065 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
16066 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
16067 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
16068 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
16071 device_desc.feature_level = &feature_level;
16072 device_desc.flags = 0;
16073 if (!(device = create_device(&device_desc)))
16075 skip("Failed to create device for feature level %#x.\n", feature_level);
16076 return;
16079 ID3D11Device_GetImmediateContext(device, &context);
16081 /* Structured buffer views */
16082 buffer_desc.ByteWidth = 64;
16083 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
16084 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16085 buffer_desc.CPUAccessFlags = 0;
16086 buffer_desc.MiscFlags = 0;
16087 buffer_desc.StructureByteStride = 0;
16088 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
16089 buffer_desc.StructureByteStride = 4;
16090 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16091 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16093 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
16094 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16096 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
16097 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16098 U(uav_desc).Buffer.FirstElement = 0;
16099 U(uav_desc).Buffer.NumElements = 4;
16100 U(uav_desc).Buffer.Flags = 0;
16101 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16102 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16104 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16106 uvec4 = uvec4_data[i];
16107 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16108 get_buffer_readback(buffer, &rb);
16109 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16110 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16111 release_resource_readback(&rb);
16113 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16114 get_buffer_readback(buffer, &rb);
16115 SetRect(&rect, 0, 0, U(uav_desc).Buffer.NumElements, 1);
16116 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16117 SetRect(&rect, U(uav_desc).Buffer.NumElements, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16118 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16119 release_resource_readback(&rb);
16122 ID3D11Buffer_Release(buffer);
16123 ID3D11UnorderedAccessView_Release(uav);
16124 ID3D11UnorderedAccessView_Release(uav2);
16126 /* Raw buffer views */
16127 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
16128 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16129 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16131 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
16132 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16133 U(uav_desc).Buffer.FirstElement = 0;
16134 U(uav_desc).Buffer.NumElements = 16;
16135 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
16136 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16137 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16138 U(uav_desc).Buffer.FirstElement = 8;
16139 U(uav_desc).Buffer.NumElements = 8;
16140 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16141 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16143 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16145 uvec4 = uvec4_data[i];
16146 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16147 get_buffer_readback(buffer, &rb);
16148 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16149 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16150 release_resource_readback(&rb);
16152 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16153 get_buffer_readback(buffer, &rb);
16154 SetRect(&rect, 0, 0, U(uav_desc).Buffer.FirstElement, 1);
16155 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16156 SetRect(&rect, U(uav_desc).Buffer.FirstElement, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16157 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16158 release_resource_readback(&rb);
16161 ID3D11Buffer_Release(buffer);
16162 ID3D11UnorderedAccessView_Release(uav);
16163 ID3D11UnorderedAccessView_Release(uav2);
16165 /* Typed buffer views */
16166 buffer_desc.MiscFlags = 0;
16167 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16168 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16170 uav_desc.Format = DXGI_FORMAT_R32_SINT;
16171 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16172 U(uav_desc).Buffer.FirstElement = 0;
16173 U(uav_desc).Buffer.NumElements = 16;
16174 U(uav_desc).Buffer.Flags = 0;
16175 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16176 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16177 U(uav_desc).Buffer.FirstElement = 9;
16178 U(uav_desc).Buffer.NumElements = 7;
16179 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16180 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16182 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16184 uvec4 = uvec4_data[i];
16185 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16186 get_buffer_readback(buffer, &rb);
16187 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16188 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16189 release_resource_readback(&rb);
16191 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16192 get_buffer_readback(buffer, &rb);
16193 SetRect(&rect, 0, 0, U(uav_desc).Buffer.FirstElement, 1);
16194 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16195 SetRect(&rect, U(uav_desc).Buffer.FirstElement, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16196 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16197 release_resource_readback(&rb);
16200 ID3D11UnorderedAccessView_Release(uav);
16201 ID3D11UnorderedAccessView_Release(uav2);
16203 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
16204 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16205 U(uav_desc).Buffer.FirstElement = 0;
16206 U(uav_desc).Buffer.NumElements = 4;
16207 U(uav_desc).Buffer.Flags = 0;
16208 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16209 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16210 U(uav_desc).Buffer.FirstElement = 2;
16211 U(uav_desc).Buffer.NumElements = 2;
16212 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16213 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16215 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16217 const struct uvec4 *data = NULL;
16218 BOOL all_match;
16220 uvec4 = uvec4_data[i];
16221 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16222 get_buffer_readback(buffer, &rb);
16223 for (x = 0, all_match = TRUE; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
16225 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
16226 data = get_readback_uvec4(&rb, x, 0);
16227 if (!(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result))))
16229 all_match = FALSE;
16230 break;
16233 ok(all_match, "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
16234 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, x);
16235 release_resource_readback(&rb);
16237 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16238 get_buffer_readback(buffer, &rb);
16239 for (x = 0, all_match = TRUE; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
16241 struct uvec4 broken_result;
16242 data = get_readback_uvec4(&rb, x, 0);
16243 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
16244 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
16245 if (!(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result))))
16247 all_match = FALSE;
16248 break;
16251 ok(all_match, "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
16252 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, x);
16253 release_resource_readback(&rb);
16256 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
16257 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16258 ID3D11UnorderedAccessView_Release(uav);
16259 ID3D11UnorderedAccessView_Release(uav2);
16261 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
16262 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16263 U(uav_desc).Buffer.FirstElement = 0;
16264 U(uav_desc).Buffer.NumElements = 16;
16265 U(uav_desc).Buffer.Flags = 0;
16266 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16267 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16268 U(uav_desc).Buffer.FirstElement = 8;
16269 U(uav_desc).Buffer.NumElements = 8;
16270 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16271 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16273 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16275 uvec4 = uvec4_data[i];
16276 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16277 get_buffer_readback(buffer, &rb);
16278 todo_wine check_rgba_sint8(get_readback_color(&rb, 0, 0, 0), &uvec4);
16279 todo_wine check_rgba_sint8(get_readback_color(&rb, 7, 0, 0), &uvec4);
16280 todo_wine check_rgba_sint8(get_readback_color(&rb, 15, 0, 0), &uvec4);
16281 release_resource_readback(&rb);
16283 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16284 get_buffer_readback(buffer, &rb);
16285 todo_wine check_rgba_sint8(get_readback_color(&rb, 0, 0, 0), &uvec4);
16286 todo_wine check_rgba_sint8(get_readback_color(&rb, U(uav_desc).Buffer.FirstElement - 1, 0, 0), &uvec4);
16287 todo_wine check_rgba_sint8(get_readback_color(&rb, U(uav_desc).Buffer.FirstElement, 0, 0), &fe_uvec4);
16288 release_resource_readback(&rb);
16291 ID3D11UnorderedAccessView_Release(uav);
16292 ID3D11UnorderedAccessView_Release(uav2);
16294 ID3D11Buffer_Release(buffer);
16296 ID3D11DeviceContext_Release(context);
16297 refcount = ID3D11Device_Release(device);
16298 ok(!refcount, "Device has %u references left.\n", refcount);
16301 static void test_initial_depth_stencil_state(void)
16303 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16304 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
16305 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16306 struct d3d11_test_context test_context;
16307 D3D11_TEXTURE2D_DESC texture_desc;
16308 ID3D11DeviceContext *context;
16309 ID3D11DepthStencilView *dsv;
16310 ID3D11Texture2D *texture;
16311 ID3D11Device *device;
16312 unsigned int count;
16313 D3D11_VIEWPORT vp;
16314 HRESULT hr;
16316 if (!init_test_context(&test_context, NULL))
16317 return;
16319 device = test_context.device;
16320 context = test_context.immediate_context;
16322 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16323 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
16324 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16325 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16326 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16328 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
16329 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16331 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
16333 count = 1;
16334 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
16336 /* check if depth function is D3D11_COMPARISON_LESS */
16337 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16338 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
16339 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.4f);
16340 draw_color_quad(&test_context, &green);
16341 draw_color_quad(&test_context, &red);
16342 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.6f, 0.6f);
16343 draw_color_quad(&test_context, &red);
16344 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16345 check_texture_float(texture, 0.4f, 1);
16347 ID3D11DepthStencilView_Release(dsv);
16348 ID3D11Texture2D_Release(texture);
16349 release_test_context(&test_context);
16352 static void test_draw_depth_only(void)
16354 struct d3d11_test_context test_context;
16355 ID3D11PixelShader *ps_color, *ps_depth;
16356 D3D11_TEXTURE2D_DESC texture_desc;
16357 ID3D11DeviceContext *context;
16358 ID3D11DepthStencilView *dsv;
16359 struct resource_readback rb;
16360 ID3D11Texture2D *texture;
16361 ID3D11Device *device;
16362 unsigned int i, j;
16363 struct vec4 depth;
16364 ID3D11Buffer *cb;
16365 HRESULT hr;
16367 static const DWORD ps_color_code[] =
16369 #if 0
16370 float4 main(float4 position : SV_POSITION) : SV_Target
16372 return float4(0.0, 1.0, 0.0, 1.0);
16374 #endif
16375 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
16376 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16377 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
16378 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16379 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
16380 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
16381 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
16383 static const DWORD ps_depth_code[] =
16385 #if 0
16386 float depth;
16388 float main() : SV_Depth
16390 return depth;
16392 #endif
16393 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
16394 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16395 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
16396 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
16397 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
16398 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
16401 if (!init_test_context(&test_context, NULL))
16402 return;
16404 device = test_context.device;
16405 context = test_context.immediate_context;
16407 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
16409 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16410 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
16411 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16412 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16413 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16415 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
16416 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16418 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
16419 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16420 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
16421 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16423 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16424 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
16425 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
16427 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16428 check_texture_float(texture, 1.0f, 1);
16429 draw_quad(&test_context);
16430 check_texture_float(texture, 0.0f, 1);
16432 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
16434 depth.x = 0.7f;
16435 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16436 draw_quad(&test_context);
16437 check_texture_float(texture, 0.0f, 1);
16438 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16439 check_texture_float(texture, 1.0f, 1);
16440 draw_quad(&test_context);
16441 check_texture_float(texture, 0.7f, 1);
16442 depth.x = 0.8f;
16443 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16444 draw_quad(&test_context);
16445 check_texture_float(texture, 0.7f, 1);
16446 depth.x = 0.5f;
16447 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16448 draw_quad(&test_context);
16449 check_texture_float(texture, 0.5f, 1);
16451 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16452 for (i = 0; i < 4; ++i)
16454 for (j = 0; j < 4; ++j)
16456 depth.x = 1.0f / 16.0f * (j + 4 * i);
16457 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16459 set_viewport(context, 160.0f * j, 120.0f * i, 160.0f, 120.0f, 0.0f, 1.0f);
16461 draw_quad(&test_context);
16464 get_texture_readback(texture, 0, &rb);
16465 for (i = 0; i < 4; ++i)
16467 for (j = 0; j < 4; ++j)
16469 float obtained_depth, expected_depth;
16471 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
16472 expected_depth = 1.0f / 16.0f * (j + 4 * i);
16473 ok(compare_float(obtained_depth, expected_depth, 1),
16474 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
16475 obtained_depth, j, i, expected_depth);
16478 release_resource_readback(&rb);
16480 ID3D11Buffer_Release(cb);
16481 ID3D11PixelShader_Release(ps_color);
16482 ID3D11PixelShader_Release(ps_depth);
16483 ID3D11DepthStencilView_Release(dsv);
16484 ID3D11Texture2D_Release(texture);
16485 release_test_context(&test_context);
16488 static void test_draw_uav_only(void)
16490 struct d3d11_test_context test_context;
16491 D3D11_TEXTURE2D_DESC texture_desc;
16492 ID3D11UnorderedAccessView *uav;
16493 ID3D11DeviceContext *context;
16494 ID3D11Texture2D *texture;
16495 ID3D11PixelShader *ps;
16496 ID3D11Device *device;
16497 HRESULT hr;
16499 static const DWORD ps_code[] =
16501 #if 0
16502 RWTexture2D<int> u;
16504 void main()
16506 InterlockedAdd(u[uint2(0, 0)], 1);
16508 #endif
16509 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
16510 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16511 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
16512 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
16513 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
16515 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16516 static const UINT values[4] = {0};
16518 if (!init_test_context(&test_context, &feature_level))
16519 return;
16521 device = test_context.device;
16522 context = test_context.immediate_context;
16524 texture_desc.Width = 1;
16525 texture_desc.Height = 1;
16526 texture_desc.MipLevels = 1;
16527 texture_desc.ArraySize = 1;
16528 texture_desc.Format = DXGI_FORMAT_R32_SINT;
16529 texture_desc.SampleDesc.Count = 1;
16530 texture_desc.SampleDesc.Quality = 0;
16531 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16532 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16533 texture_desc.CPUAccessFlags = 0;
16534 texture_desc.MiscFlags = 0;
16536 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16537 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16539 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
16540 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16542 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16543 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16545 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16546 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
16547 0, 1, &uav, NULL);
16549 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
16550 set_viewport(context, 0.0f, 0.0f, 10.0f, 10.0f, 0.0f, 0.0f);
16551 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
16552 draw_quad(&test_context);
16553 check_texture_color(texture, 100, 1);
16555 draw_quad(&test_context);
16556 draw_quad(&test_context);
16557 draw_quad(&test_context);
16558 draw_quad(&test_context);
16559 check_texture_color(texture, 500, 1);
16561 ID3D11PixelShader_Release(ps);
16562 ID3D11Texture2D_Release(texture);
16563 ID3D11UnorderedAccessView_Release(uav);
16564 release_test_context(&test_context);
16567 static void test_cb_relative_addressing(void)
16569 struct d3d11_test_context test_context;
16570 ID3D11Buffer *colors_cb, *index_cb;
16571 unsigned int i, index[4] = {0};
16572 ID3D11DeviceContext *context;
16573 ID3D11PixelShader *ps;
16574 ID3D11Device *device;
16575 HRESULT hr;
16577 static const DWORD vs_code[] =
16579 #if 0
16580 int color_index;
16582 cbuffer colors
16584 float4 colors[8];
16587 struct vs_in
16589 float4 position : POSITION;
16592 struct vs_out
16594 float4 position : SV_POSITION;
16595 float4 color : COLOR;
16598 vs_out main(const vs_in v)
16600 vs_out o;
16602 o.position = v.position;
16603 o.color = colors[color_index];
16605 return o;
16607 #endif
16608 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
16609 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16610 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
16611 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
16612 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
16613 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
16614 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
16615 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
16616 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
16617 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
16618 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
16619 0x0100003e,
16621 static const DWORD ps_code[] =
16623 #if 0
16624 struct ps_in
16626 float4 position : SV_POSITION;
16627 float4 color : COLOR;
16630 float4 main(const ps_in v) : SV_TARGET
16632 return v.color;
16634 #endif
16635 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
16636 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16637 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
16638 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
16639 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16640 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
16641 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16642 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
16644 static const struct
16646 float color[4];
16648 colors[10] =
16650 {{0.0f, 0.0f, 0.0f, 1.0f}},
16651 {{0.0f, 0.0f, 1.0f, 0.0f}},
16652 {{0.0f, 0.0f, 1.0f, 1.0f}},
16653 {{0.0f, 1.0f, 0.0f, 0.0f}},
16654 {{0.0f, 1.0f, 0.0f, 1.0f}},
16655 {{0.0f, 1.0f, 1.0f, 0.0f}},
16656 {{0.0f, 1.0f, 1.0f, 1.0f}},
16657 {{1.0f, 0.0f, 0.0f, 0.0f}},
16658 {{1.0f, 0.0f, 0.0f, 1.0f}},
16659 {{1.0f, 0.0f, 1.0f, 0.0f}},
16661 static const struct
16663 unsigned int index;
16664 DWORD expected;
16666 test_data[] =
16668 {0, 0xff000000},
16669 {1, 0x00ff0000},
16670 {2, 0xffff0000},
16671 {3, 0x0000ff00},
16672 {4, 0xff00ff00},
16673 {5, 0x00ffff00},
16674 {6, 0xffffff00},
16675 {7, 0x000000ff},
16677 {8, 0xff0000ff},
16678 {9, 0x00ff00ff},
16680 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
16681 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16683 if (!init_test_context(&test_context, &feature_level))
16684 return;
16686 device = test_context.device;
16687 context = test_context.immediate_context;
16689 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
16690 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
16692 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16693 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16695 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
16696 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
16697 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16699 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
16701 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
16703 index[0] = test_data[i].index;
16704 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
16706 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
16707 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
16710 ID3D11Buffer_Release(index_cb);
16711 ID3D11Buffer_Release(colors_cb);
16712 ID3D11PixelShader_Release(ps);
16714 release_test_context(&test_context);
16717 static void test_vs_input_relative_addressing(void)
16719 struct d3d11_test_context test_context;
16720 ID3D11DeviceContext *context;
16721 unsigned int offset, stride;
16722 unsigned int index[4] = {0};
16723 ID3D11PixelShader *ps;
16724 ID3D11Buffer *vb, *cb;
16725 ID3D11Device *device;
16726 unsigned int i;
16727 HRESULT hr;
16729 static const DWORD vs_code[] =
16731 #if 0
16732 struct vertex
16734 float4 position : POSITION;
16735 float4 colors[4] : COLOR;
16738 uint index;
16740 void main(vertex vin, out float4 position : SV_Position,
16741 out float4 color : COLOR)
16743 position = vin.position;
16744 color = vin.colors[index];
16746 #endif
16747 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
16748 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
16749 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
16750 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
16751 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
16752 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
16753 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
16754 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
16755 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
16756 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
16757 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
16758 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
16759 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
16760 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
16761 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
16762 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
16764 static const DWORD ps_code[] =
16766 #if 0
16767 struct vs_out
16769 float4 position : SV_POSITION;
16770 float4 color : COLOR;
16773 float4 main(struct vs_out i) : SV_TARGET
16775 return i.color;
16777 #endif
16778 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
16779 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16780 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
16781 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
16782 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16783 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
16784 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
16785 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
16787 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
16789 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
16790 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1},
16791 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D11_INPUT_PER_INSTANCE_DATA, 1},
16792 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D11_INPUT_PER_INSTANCE_DATA, 1},
16793 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D11_INPUT_PER_INSTANCE_DATA, 1},
16795 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
16796 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16798 if (!init_test_context(&test_context, NULL))
16799 return;
16800 device = test_context.device;
16801 context = test_context.immediate_context;
16803 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16804 vs_code, sizeof(vs_code), &test_context.input_layout);
16805 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
16807 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
16808 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
16810 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(colors), colors);
16811 stride = sizeof(colors);
16812 offset = 0;
16813 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
16815 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16816 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16817 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16819 for (i = 0; i < ARRAY_SIZE(colors); ++i)
16821 *index = i;
16822 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
16823 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16824 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
16825 check_texture_color(test_context.backbuffer, colors[i], 1);
16828 ID3D11Buffer_Release(cb);
16829 ID3D11Buffer_Release(vb);
16830 ID3D11PixelShader_Release(ps);
16831 release_test_context(&test_context);
16834 static void test_getdc(void)
16836 static const struct
16838 const char *name;
16839 DXGI_FORMAT format;
16840 BOOL getdc_supported;
16842 testdata[] =
16844 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
16845 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
16846 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
16847 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
16848 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
16849 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
16851 struct device_desc device_desc;
16852 D3D11_TEXTURE2D_DESC desc;
16853 ID3D11Texture2D *texture;
16854 IDXGISurface1 *surface;
16855 ID3D11Device *device;
16856 unsigned int i;
16857 ULONG refcount;
16858 HRESULT hr;
16859 HDC dc;
16861 device_desc.feature_level = NULL;
16862 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
16863 if (!(device = create_device(&device_desc)))
16865 skip("Failed to create device.\n");
16866 return;
16869 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
16870 desc.Width = 512;
16871 desc.Height = 512;
16872 desc.MipLevels = 1;
16873 desc.ArraySize = 1;
16874 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
16875 desc.SampleDesc.Count = 1;
16876 desc.SampleDesc.Quality = 0;
16877 desc.Usage = D3D11_USAGE_DEFAULT;
16878 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16879 desc.CPUAccessFlags = 0;
16880 desc.MiscFlags = 0;
16881 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16882 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16884 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
16885 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
16887 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
16888 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
16890 IDXGISurface1_Release(surface);
16891 ID3D11Texture2D_Release(texture);
16893 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
16894 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16895 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16897 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
16898 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
16900 hr = IDXGISurface1_ReleaseDC(surface, NULL);
16901 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
16903 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
16904 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
16906 hr = IDXGISurface1_ReleaseDC(surface, NULL);
16907 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
16909 IDXGISurface1_Release(surface);
16910 ID3D11Texture2D_Release(texture);
16912 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
16914 static const unsigned int bit_count = 32;
16915 unsigned int width_bytes;
16916 DIBSECTION dib;
16917 HBITMAP bitmap;
16918 DWORD type;
16919 int size;
16921 desc.Width = 64;
16922 desc.Height = 64;
16923 desc.MipLevels = 1;
16924 desc.ArraySize = 1;
16925 desc.Format = testdata[i].format;
16926 desc.SampleDesc.Count = 1;
16927 desc.SampleDesc.Quality = 0;
16928 desc.Usage = D3D11_USAGE_STAGING;
16929 desc.BindFlags = 0;
16930 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
16931 desc.MiscFlags = 0;
16933 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16934 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16935 ID3D11Texture2D_Release(texture);
16937 /* STAGING usage, requesting GDI compatibility mode. */
16938 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
16939 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16940 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
16942 desc.Usage = D3D11_USAGE_DEFAULT;
16943 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16944 desc.CPUAccessFlags = 0;
16945 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16946 if (testdata[i].getdc_supported)
16947 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
16948 else
16949 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
16951 if (FAILED(hr))
16952 continue;
16954 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
16955 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
16957 dc = (void *)0x1234;
16958 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
16959 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
16961 if (FAILED(hr))
16963 IDXGISurface1_Release(surface);
16964 ID3D11Texture2D_Release(texture);
16965 continue;
16968 type = GetObjectType(dc);
16969 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
16970 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
16971 type = GetObjectType(bitmap);
16972 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
16974 size = GetObjectA(bitmap, sizeof(dib), &dib);
16975 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
16976 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
16978 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
16979 dib.dsBm.bmType, testdata[i].name);
16980 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
16981 dib.dsBm.bmWidth, testdata[i].name);
16982 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
16983 dib.dsBm.bmHeight, testdata[i].name);
16984 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
16985 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
16986 dib.dsBm.bmWidthBytes, testdata[i].name);
16987 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
16988 dib.dsBm.bmPlanes, testdata[i].name);
16989 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
16990 dib.dsBm.bmBitsPixel, testdata[i].name);
16992 if (size == sizeof(dib))
16993 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
16994 dib.dsBm.bmBits, testdata[i].name);
16995 else
16996 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
16997 dib.dsBm.bmBits, testdata[i].name);
16999 if (size == sizeof(dib))
17001 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
17002 dib.dsBmih.biSize, testdata[i].name);
17003 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
17004 dib.dsBmih.biHeight, testdata[i].name);
17005 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
17006 dib.dsBmih.biHeight, testdata[i].name);
17007 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
17008 dib.dsBmih.biPlanes, testdata[i].name);
17009 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
17010 dib.dsBmih.biBitCount, testdata[i].name);
17011 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
17012 dib.dsBmih.biCompression, testdata[i].name);
17013 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
17014 dib.dsBmih.biSizeImage, testdata[i].name);
17015 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
17016 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
17017 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
17018 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
17019 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
17020 dib.dsBmih.biClrUsed, testdata[i].name);
17021 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
17022 dib.dsBmih.biClrImportant, testdata[i].name);
17023 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
17024 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
17025 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
17026 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
17027 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
17030 hr = IDXGISurface1_ReleaseDC(surface, NULL);
17031 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
17033 IDXGISurface1_Release(surface);
17034 ID3D11Texture2D_Release(texture);
17037 refcount = ID3D11Device_Release(device);
17038 ok(!refcount, "Device has %u references left.\n", refcount);
17041 static void test_shader_stage_input_output_matching(void)
17043 struct d3d11_test_context test_context;
17044 D3D11_TEXTURE2D_DESC texture_desc;
17045 ID3D11Texture2D *render_target;
17046 ID3D11RenderTargetView *rtv[2];
17047 ID3D11DeviceContext *context;
17048 ID3D11VertexShader *vs;
17049 ID3D11PixelShader *ps;
17050 ID3D11Device *device;
17051 HRESULT hr;
17053 static const DWORD vs_code[] =
17055 #if 0
17056 struct output
17058 float4 position : SV_PoSiTion;
17059 float4 color0 : COLOR0;
17060 float4 color1 : COLOR1;
17063 void main(uint id : SV_VertexID, out output o)
17065 float2 coords = float2((id << 1) & 2, id & 2);
17066 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
17067 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
17068 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
17070 #endif
17071 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
17072 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17073 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
17074 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
17075 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17076 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
17077 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
17078 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
17079 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
17080 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
17081 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
17082 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
17083 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
17084 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
17085 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
17086 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
17087 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
17088 0x0100003e,
17090 static const DWORD ps_code[] =
17092 #if 0
17093 struct input
17095 float4 position : SV_PoSiTiOn;
17096 float4 color1 : COLOR1;
17097 float4 color0 : COLOR0;
17100 struct output
17102 float4 target0 : SV_Target0;
17103 float4 target1 : SV_Target1;
17106 void main(const in input i, out output o)
17108 o.target0 = i.color0;
17109 o.target1 = i.color1;
17111 #endif
17112 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
17113 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
17114 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
17115 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
17116 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
17117 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
17118 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
17119 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
17120 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
17121 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
17122 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
17125 if (!init_test_context(&test_context, NULL))
17126 return;
17128 device = test_context.device;
17129 context = test_context.immediate_context;
17131 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17132 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17133 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17134 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17136 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17137 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
17138 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17140 rtv[0] = test_context.backbuffer_rtv;
17141 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
17142 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17144 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17145 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17146 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
17147 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
17148 ID3D11DeviceContext_Draw(context, 3, 0);
17150 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17151 check_texture_color(render_target, 0xff0000ff, 0);
17153 ID3D11RenderTargetView_Release(rtv[1]);
17154 ID3D11Texture2D_Release(render_target);
17155 ID3D11PixelShader_Release(ps);
17156 ID3D11VertexShader_Release(vs);
17157 release_test_context(&test_context);
17160 static void test_unbound_streams(void)
17162 struct d3d11_test_context test_context;
17163 ID3D11DeviceContext *context;
17164 ID3D11PixelShader *ps;
17165 ID3D11Device *device;
17166 HRESULT hr;
17168 static const DWORD vs_code[] =
17170 #if 0
17171 struct vs_ps
17173 float4 position : SV_POSITION;
17174 float4 color : COLOR0;
17177 vs_ps vs_main(float4 position : POSITION, float4 color : COLOR0)
17179 vs_ps result;
17180 result.position = position;
17181 result.color = color;
17182 result.color.w = 1.0;
17183 return result;
17185 #endif
17186 0x43425844, 0x4a9efaec, 0xe2c6cdf5, 0x15dd28a7, 0xae68e320, 0x00000001, 0x00000154, 0x00000003,
17187 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
17188 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
17189 0x00000003, 0x00000001, 0x0000070f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
17190 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
17191 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
17192 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x0000007c, 0x00010040, 0x0000001f,
17193 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101072, 0x00000001, 0x04000067, 0x001020f2,
17194 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
17195 0x00101e46, 0x00000000, 0x05000036, 0x00102072, 0x00000001, 0x00101246, 0x00000001, 0x05000036,
17196 0x00102082, 0x00000001, 0x00004001, 0x3f800000, 0x0100003e,
17199 static const DWORD ps_code[] =
17201 #if 0
17202 float4 ps_main(vs_ps input) : SV_TARGET
17204 return input.color;
17206 #endif
17207 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
17208 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17209 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17210 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
17211 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17212 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
17213 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
17214 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
17217 static const float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
17219 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17221 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17222 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
17225 if (!init_test_context(&test_context, NULL))
17226 return;
17228 device = test_context.device;
17229 context = test_context.immediate_context;
17231 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17232 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17234 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17235 vs_code, sizeof(vs_code), &test_context.input_layout);
17236 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17238 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17239 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17240 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
17241 check_texture_color(test_context.backbuffer, 0xff000000, 1);
17243 ID3D11PixelShader_Release(ps);
17244 release_test_context(&test_context);
17247 static void test_shader_interstage_interface(void)
17249 struct d3d11_test_context test_context;
17250 D3D11_TEXTURE2D_DESC texture_desc;
17251 ID3D11InputLayout *input_layout;
17252 ID3D11Texture2D *render_target;
17253 ID3D11DeviceContext *context;
17254 ID3D11RenderTargetView *rtv;
17255 ID3D11VertexShader *vs;
17256 ID3D11PixelShader *ps;
17257 ID3D11Device *device;
17258 UINT stride, offset;
17259 ID3D11Buffer *vb;
17260 unsigned int i;
17261 HRESULT hr;
17263 static const DWORD vs_code[] =
17265 #if 0
17266 struct vertex
17268 float4 position : SV_Position;
17269 float2 t0 : TEXCOORD0;
17270 nointerpolation float t1 : TEXCOORD1;
17271 uint t2 : TEXCOORD2;
17272 uint t3 : TEXCOORD3;
17273 float t4 : TEXCOORD4;
17276 void main(in vertex vin, out vertex vout)
17278 vout = vin;
17280 #endif
17281 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
17282 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
17283 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
17284 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
17285 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
17286 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
17287 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17288 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
17289 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
17290 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
17291 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
17292 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
17293 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
17294 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
17295 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
17296 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
17297 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
17298 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
17299 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
17300 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
17301 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
17302 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
17304 static const DWORD ps_code[] =
17306 #if 0
17307 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
17308 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
17309 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
17311 o.x = t0.y + t1;
17312 o.y = t2 + t3;
17313 o.z = t4;
17314 o.w = t0.x;
17316 #endif
17317 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
17318 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
17319 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
17320 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
17321 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
17322 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
17323 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17324 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
17325 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
17326 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
17327 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
17328 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
17329 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
17330 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
17331 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
17333 static const DWORD ps_partial_input_code[] =
17335 #if 0
17336 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
17337 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
17338 uint t3 : TEXCOORD3, out float4 o : SV_Target)
17340 o.x = t0.y + t1;
17341 o.y = t2 + t3;
17342 o.z = 0.0f;
17343 o.w = t0.x;
17345 #endif
17346 0x43425844, 0x5b1db356, 0xaa5a5e9d, 0xb916a081, 0x61e6dcb1, 0x00000001, 0x000001cc, 0x00000003,
17347 0x0000002c, 0x000000cc, 0x00000100, 0x4e475349, 0x00000098, 0x00000005, 0x00000008, 0x00000080,
17348 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
17349 0x00000003, 0x00000001, 0x00000303, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
17350 0x00000101, 0x0000008c, 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x0000008c,
17351 0x00000003, 0x00000000, 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
17352 0x43584554, 0x44524f4f, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17353 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
17354 0x52444853, 0x000000c4, 0x00000040, 0x00000031, 0x03001062, 0x00101032, 0x00000001, 0x03000862,
17355 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042, 0x00000002,
17356 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012, 0x00000000,
17357 0x0010102a, 0x00000002, 0x0010101a, 0x00000002, 0x05000056, 0x00102022, 0x00000000, 0x0010000a,
17358 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a, 0x00000002,
17359 0x05000036, 0x00102042, 0x00000000, 0x00004001, 0x00000000, 0x05000036, 0x00102082, 0x00000000,
17360 0x0010100a, 0x00000001, 0x0100003e,
17362 static const DWORD ps_single_input_code[] =
17364 #if 0
17365 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0, out float4 o : SV_Target)
17367 o.x = t0.x;
17368 o.y = t0.y;
17369 o.z = 1.0f;
17370 o.w = 2.0f;
17372 #endif
17373 0x43425844, 0x7cc601b6, 0xc65b8bdb, 0x54d0f606, 0x9cc74d3d, 0x00000001, 0x00000118, 0x00000003,
17374 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
17375 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17376 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17377 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
17378 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058,
17379 0x00000040, 0x00000016, 0x03001062, 0x00101032, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17380 0x05000036, 0x00102032, 0x00000000, 0x00101046, 0x00000001, 0x08000036, 0x001020c2, 0x00000000,
17381 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x40000000, 0x0100003e,
17383 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17385 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17386 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
17387 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
17388 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
17389 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
17390 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
17392 static const struct
17394 struct vec2 position;
17395 struct vec2 t0;
17396 float t1;
17397 unsigned int t2;
17398 unsigned int t3;
17399 float t4;
17401 quad[] =
17403 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17404 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17405 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17406 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17408 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17409 static const struct
17411 const DWORD *ps_code;
17412 size_t ps_size;
17413 struct vec4 expected_result;
17415 tests[] =
17417 {ps_code, sizeof(ps_code), {10.0f, 8.0f, 7.0f, 3.0f}},
17418 {ps_partial_input_code, sizeof(ps_partial_input_code), {10.0f, 8.0f, 0.0f, 3.0f}},
17419 {ps_single_input_code, sizeof(ps_single_input_code), {3.0f, 5.0f, 1.0f, 2.0f}},
17422 if (!init_test_context(&test_context, NULL))
17423 return;
17425 device = test_context.device;
17426 context = test_context.immediate_context;
17428 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17429 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17431 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17432 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17433 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
17434 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17436 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
17437 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17439 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17440 vs_code, sizeof(vs_code), &input_layout);
17441 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17443 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
17445 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
17447 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17448 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17449 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
17450 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
17451 offset = 0;
17452 stride = sizeof(*quad);
17453 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
17455 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17457 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_size, NULL, &ps);
17458 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
17459 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17460 ID3D11DeviceContext_Draw(context, 4, 0);
17461 check_texture_vec4(render_target, &tests[i].expected_result, 0);
17462 ID3D11PixelShader_Release(ps);
17465 ID3D11InputLayout_Release(input_layout);
17466 ID3D11RenderTargetView_Release(rtv);
17467 ID3D11Texture2D_Release(render_target);
17468 ID3D11VertexShader_Release(vs);
17469 ID3D11Buffer_Release(vb);
17470 release_test_context(&test_context);
17473 static void test_sm4_if_instruction(void)
17475 struct d3d11_test_context test_context;
17476 ID3D11PixelShader *ps_if_nz, *ps_if_z;
17477 ID3D11DeviceContext *context;
17478 ID3D11Device *device;
17479 unsigned int bits[4];
17480 DWORD expected_color;
17481 ID3D11Buffer *cb;
17482 unsigned int i;
17483 HRESULT hr;
17485 static const DWORD ps_if_nz_code[] =
17487 #if 0
17488 uint bits;
17490 float4 main() : SV_TARGET
17492 if (bits)
17493 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17494 else
17495 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17497 #endif
17498 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
17499 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17500 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17501 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
17502 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
17503 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17504 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17505 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17507 static const DWORD ps_if_z_code[] =
17509 #if 0
17510 uint bits;
17512 float4 main() : SV_TARGET
17514 if (!bits)
17515 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17516 else
17517 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17519 #endif
17520 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
17521 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17522 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17523 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
17524 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
17525 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17526 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17527 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17529 static unsigned int bit_patterns[] =
17531 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
17534 if (!init_test_context(&test_context, NULL))
17535 return;
17537 device = test_context.device;
17538 context = test_context.immediate_context;
17540 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
17541 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
17542 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
17543 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
17545 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
17546 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17548 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
17550 *bits = bit_patterns[i];
17551 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
17553 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
17554 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
17555 draw_quad(&test_context);
17556 check_texture_color(test_context.backbuffer, expected_color, 0);
17558 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
17559 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
17560 draw_quad(&test_context);
17561 check_texture_color(test_context.backbuffer, expected_color, 0);
17564 ID3D11Buffer_Release(cb);
17565 ID3D11PixelShader_Release(ps_if_z);
17566 ID3D11PixelShader_Release(ps_if_nz);
17567 release_test_context(&test_context);
17570 static void test_sm4_breakc_instruction(void)
17572 struct d3d11_test_context test_context;
17573 ID3D11DeviceContext *context;
17574 ID3D11PixelShader *ps;
17575 ID3D11Device *device;
17576 HRESULT hr;
17578 static const DWORD ps_breakc_nz_code[] =
17580 #if 0
17581 float4 main() : SV_TARGET
17583 uint counter = 0;
17585 for (uint i = 0; i < 255; ++i)
17586 ++counter;
17588 if (counter == 255)
17589 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17590 else
17591 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17593 #endif
17594 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
17595 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17596 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17597 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
17598 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
17599 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
17600 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
17601 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
17602 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
17603 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
17604 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
17605 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
17606 0x01000015, 0x0100003e,
17608 static const DWORD ps_breakc_z_code[] =
17610 #if 0
17611 float4 main() : SV_TARGET
17613 uint counter = 0;
17615 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
17616 ++counter;
17618 if (counter == 255)
17619 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17620 else
17621 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17623 #endif
17624 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
17625 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17626 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17627 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
17628 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
17629 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
17630 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
17631 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
17632 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
17633 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
17634 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
17635 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17636 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17637 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17640 if (!init_test_context(&test_context, NULL))
17641 return;
17643 device = test_context.device;
17644 context = test_context.immediate_context;
17646 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
17647 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
17648 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17649 draw_quad(&test_context);
17650 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17651 ID3D11PixelShader_Release(ps);
17653 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
17654 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
17655 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17656 draw_quad(&test_context);
17657 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17658 ID3D11PixelShader_Release(ps);
17660 release_test_context(&test_context);
17663 static void test_sm4_continuec_instruction(void)
17665 struct d3d11_test_context test_context;
17666 ID3D11DeviceContext *context;
17667 ID3D11PixelShader *ps;
17668 ID3D11Device *device;
17669 HRESULT hr;
17671 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
17672 * with a normal continue inside, the shaders have been compiled with
17673 * the /Gfa flag. */
17674 static const DWORD ps_continuec_nz_code[] =
17676 #if 0
17677 float4 main() : SV_TARGET
17679 uint counter = 0;
17680 int i = -1;
17682 while (i < 255) {
17683 ++i;
17685 if (i != 0)
17686 continue;
17688 ++counter;
17691 if (counter == 1)
17692 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17693 else
17694 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17696 #endif
17697 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
17698 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17699 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17700 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
17701 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
17702 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
17703 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
17704 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
17705 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
17706 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
17707 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
17708 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
17709 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
17710 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
17711 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
17712 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
17713 0x3f800000, 0x0100003e,
17716 static const DWORD ps_continuec_z_code[] =
17718 #if 0
17719 float4 main() : SV_TARGET
17721 uint counter = 0;
17722 int i = -1;
17724 while (i < 255) {
17725 ++i;
17727 if (i == 0)
17728 continue;
17730 ++counter;
17733 if (counter == 255)
17734 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17735 else
17736 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17738 #endif
17739 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
17740 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17741 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17742 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
17743 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
17744 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
17745 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
17746 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
17747 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
17748 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
17749 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
17750 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
17751 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
17752 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
17753 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
17756 if (!init_test_context(&test_context, NULL))
17757 return;
17759 device = test_context.device;
17760 context = test_context.immediate_context;
17762 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
17763 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
17764 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17765 draw_quad(&test_context);
17766 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17767 ID3D11PixelShader_Release(ps);
17769 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
17770 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
17771 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17772 draw_quad(&test_context);
17773 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17774 ID3D11PixelShader_Release(ps);
17776 release_test_context(&test_context);
17779 static void test_sm4_discard_instruction(void)
17781 ID3D11PixelShader *ps_discard_nz, *ps_discard_z;
17782 struct d3d11_test_context test_context;
17783 ID3D11DeviceContext *context;
17784 ID3D11Device *device;
17785 ID3D11Buffer *cb;
17786 unsigned int i;
17787 HRESULT hr;
17789 static const DWORD ps_discard_nz_code[] =
17791 #if 0
17792 uint data;
17794 float4 main() : SV_Target
17796 if (data)
17797 discard;
17798 return float4(0.0f, 0.5f, 0.0f, 1.0f);
17800 #endif
17801 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
17802 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17803 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17804 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
17805 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
17806 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17807 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
17809 static const DWORD ps_discard_z_code[] =
17811 #if 0
17812 uint data;
17814 float4 main() : SV_Target
17816 if (!data)
17817 discard;
17818 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17820 #endif
17821 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
17822 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17823 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17824 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
17825 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
17826 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17827 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
17829 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17830 static const struct uvec4 values[] =
17832 {0x0000000},
17833 {0x0000001},
17834 {0x8000000},
17835 {0xfffffff},
17838 if (!init_test_context(&test_context, NULL))
17839 return;
17841 device = test_context.device;
17842 context = test_context.immediate_context;
17844 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
17845 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17847 hr = ID3D11Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code),
17848 NULL, &ps_discard_nz);
17849 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
17850 hr = ID3D11Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code),
17851 NULL, &ps_discard_z);
17852 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
17854 for (i = 0; i < ARRAY_SIZE(values); ++i)
17856 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &values[i], 0, 0);
17858 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17859 ID3D11DeviceContext_PSSetShader(context, ps_discard_nz, NULL, 0);
17860 draw_quad(&test_context);
17861 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
17863 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17864 ID3D11DeviceContext_PSSetShader(context, ps_discard_z, NULL, 0);
17865 draw_quad(&test_context);
17866 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
17869 ID3D11Buffer_Release(cb);
17870 ID3D11PixelShader_Release(ps_discard_nz);
17871 ID3D11PixelShader_Release(ps_discard_z);
17872 release_test_context(&test_context);
17875 static void test_sm5_swapc_instruction(void)
17877 struct input
17879 struct uvec4 src0;
17880 struct uvec4 src1;
17881 struct uvec4 src2;
17884 struct d3d11_test_context test_context;
17885 D3D11_TEXTURE2D_DESC texture_desc;
17886 ID3D11DeviceContext *context;
17887 ID3D11RenderTargetView *rtv;
17888 ID3D11Texture2D *texture;
17889 ID3D11PixelShader *ps[6];
17890 ID3D11Device *device;
17891 ID3D11Buffer *cb;
17892 unsigned int i;
17893 HRESULT hr;
17895 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17896 static const DWORD ps_swapc0_code[] =
17898 #if 0
17899 ps_5_0
17900 dcl_globalFlags refactoringAllowed
17901 dcl_constantbuffer cb0[3], immediateIndexed
17902 dcl_output o0.xyzw
17903 dcl_temps 2
17904 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
17905 mov o0.xyzw, r0.xyzw
17907 #endif
17908 0x43425844, 0x9e089246, 0x9f8b5cbe, 0xbac66faf, 0xaef23488, 0x00000001, 0x000000f8, 0x00000003,
17909 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17910 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17911 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
17912 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
17913 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
17914 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
17915 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
17917 static const DWORD ps_swapc1_code[] =
17919 #if 0
17920 ps_5_0
17921 dcl_globalFlags refactoringAllowed
17922 dcl_constantbuffer cb0[3], immediateIndexed
17923 dcl_output o0.xyzw
17924 dcl_temps 2
17925 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
17926 mov o0.xyzw, r1.xyzw
17928 #endif
17929 0x43425844, 0xf2daed61, 0xede211f7, 0x7300dbea, 0x573ed49f, 0x00000001, 0x000000f8, 0x00000003,
17930 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17931 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17932 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
17933 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
17934 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
17935 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
17936 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
17938 static const DWORD ps_swapc2_code[] =
17940 #if 0
17941 ps_5_0
17942 dcl_globalFlags refactoringAllowed
17943 dcl_constantbuffer cb0[3], immediateIndexed
17944 dcl_output o0.xyzw
17945 dcl_temps 2
17946 mov r0.xyzw, cb0[1].xyzw
17947 mov r1.xyzw, cb0[2].xyzw
17948 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
17949 mov o0.xyzw, r0.xyzw
17951 #endif
17952 0x43425844, 0x230fcb22, 0x70d99148, 0x65814d89, 0x97473498, 0x00000001, 0x00000120, 0x00000003,
17953 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17954 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17955 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
17956 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
17957 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
17958 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
17959 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
17960 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
17962 static const DWORD ps_swapc3_code[] =
17964 #if 0
17965 ps_5_0
17966 dcl_globalFlags refactoringAllowed
17967 dcl_constantbuffer cb0[3], immediateIndexed
17968 dcl_output o0.xyzw
17969 dcl_temps 2
17970 mov r0.xyzw, cb0[1].xyzw
17971 mov r1.xyzw, cb0[2].xyzw
17972 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
17973 mov o0.xyzw, r1.xyzw
17975 #endif
17976 0x43425844, 0xce595d62, 0x98305541, 0xb04e74c8, 0xfc010f3a, 0x00000001, 0x00000120, 0x00000003,
17977 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17978 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17979 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
17980 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
17981 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
17982 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
17983 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
17984 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
17986 static const DWORD ps_swapc4_code[] =
17988 #if 0
17989 ps_5_0
17990 dcl_globalFlags refactoringAllowed
17991 dcl_constantbuffer cb0[3], immediateIndexed
17992 dcl_output o0.xyzw
17993 dcl_temps 2
17994 mov r0.xyzw, cb0[0].xyzw
17995 swapc r0.xyzw, r1.xyzw, r0.xyzw, cb0[1].xyzw, cb0[2].xyzw
17996 mov o0.xyzw, r0.xyzw
17998 #endif
17999 0x43425844, 0x72067c48, 0xb53572a0, 0x9dd9e0fd, 0x903e37e3, 0x00000001, 0x0000010c, 0x00000003,
18000 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18001 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18002 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
18003 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18004 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
18005 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000000, 0x00208e46,
18006 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
18007 0x00100e46, 0x00000000, 0x0100003e,
18009 static const DWORD ps_swapc5_code[] =
18011 #if 0
18012 ps_5_0
18013 dcl_globalFlags refactoringAllowed
18014 dcl_constantbuffer cb0[3], immediateIndexed
18015 dcl_output o0.xyzw
18016 dcl_temps 2
18017 mov r1.xyzw, cb0[0].xyzw
18018 swapc r0.xyzw, r1.xyzw, r1.xyzw, cb0[1].xyzw, cb0[2].xyzw
18019 mov o0.xyzw, r1.xyzw
18021 #endif
18022 0x43425844, 0x7078fb08, 0xdd24cd44, 0x469d3258, 0x9e33a0bc, 0x00000001, 0x0000010c, 0x00000003,
18023 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18024 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18025 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
18026 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18027 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000,
18028 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001, 0x00208e46,
18029 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
18030 0x00100e46, 0x00000001, 0x0100003e,
18032 static const struct
18034 struct input input;
18035 struct uvec4 dst0;
18036 struct uvec4 dst1;
18038 tests[] =
18041 {{0, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18042 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}
18045 {{1, 1, 1, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18046 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
18049 {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
18050 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18051 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
18054 {{1, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18055 {0xaaaa, 0xc0de, 0xcccc, 0xeeee}, {0xdead, 0xbbbb, 0xffff, 0xdddd},
18058 {{1, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18059 {0xaaaa, 0xc0de, 0xffff, 0xdddd}, {0xdead, 0xbbbb, 0xcccc, 0xeeee},
18062 {{1, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18063 {0xaaaa, 0xc0de, 0xffff, 0xeeee}, {0xdead, 0xbbbb, 0xcccc, 0xdddd}
18066 {{0, 1, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18067 {0xdead, 0xbbbb, 0xffff, 0xeeee}, {0xaaaa, 0xc0de, 0xcccc, 0xdddd}
18070 {{0, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18071 {0xdead, 0xc0de, 0xcccc, 0xeeee}, {0xaaaa, 0xbbbb, 0xffff, 0xdddd}
18074 {{0, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18075 {0xdead, 0xc0de, 0xffff, 0xdddd}, {0xaaaa, 0xbbbb, 0xcccc, 0xeeee},
18079 if (!init_test_context(&test_context, &feature_level))
18080 return;
18082 device = test_context.device;
18083 context = test_context.immediate_context;
18085 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18086 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
18087 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18088 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18090 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18091 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
18093 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18095 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct input), NULL);
18096 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18098 hr = ID3D11Device_CreatePixelShader(device, ps_swapc0_code, sizeof(ps_swapc0_code), NULL, &ps[0]);
18099 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18100 hr = ID3D11Device_CreatePixelShader(device, ps_swapc1_code, sizeof(ps_swapc1_code), NULL, &ps[1]);
18101 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18102 hr = ID3D11Device_CreatePixelShader(device, ps_swapc2_code, sizeof(ps_swapc2_code), NULL, &ps[2]);
18103 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18104 hr = ID3D11Device_CreatePixelShader(device, ps_swapc3_code, sizeof(ps_swapc3_code), NULL, &ps[3]);
18105 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18106 hr = ID3D11Device_CreatePixelShader(device, ps_swapc4_code, sizeof(ps_swapc4_code), NULL, &ps[4]);
18107 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18108 hr = ID3D11Device_CreatePixelShader(device, ps_swapc5_code, sizeof(ps_swapc5_code), NULL, &ps[5]);
18109 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18111 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18113 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &tests[i].input, 0, 0);
18115 ID3D11DeviceContext_PSSetShader(context, ps[0], NULL, 0);
18116 draw_quad(&test_context);
18117 check_texture_uvec4(texture, &tests[i].dst0);
18119 ID3D11DeviceContext_PSSetShader(context, ps[1], NULL, 0);
18120 draw_quad(&test_context);
18121 check_texture_uvec4(texture, &tests[i].dst1);
18123 ID3D11DeviceContext_PSSetShader(context, ps[2], NULL, 0);
18124 draw_quad(&test_context);
18125 check_texture_uvec4(texture, &tests[i].dst0);
18127 ID3D11DeviceContext_PSSetShader(context, ps[3], NULL, 0);
18128 draw_quad(&test_context);
18129 check_texture_uvec4(texture, &tests[i].dst1);
18131 ID3D11DeviceContext_PSSetShader(context, ps[4], NULL, 0);
18132 draw_quad(&test_context);
18133 check_texture_uvec4(texture, &tests[i].dst0);
18135 ID3D11DeviceContext_PSSetShader(context, ps[5], NULL, 0);
18136 draw_quad(&test_context);
18137 check_texture_uvec4(texture, &tests[i].dst1);
18140 for (i = 0; i < ARRAY_SIZE(ps); ++i)
18141 ID3D11PixelShader_Release(ps[i]);
18142 ID3D11RenderTargetView_Release(rtv);
18143 ID3D11Texture2D_Release(texture);
18144 ID3D11Buffer_Release(cb);
18145 release_test_context(&test_context);
18148 static void test_create_input_layout(void)
18150 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
18152 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18154 ULONG refcount, expected_refcount;
18155 ID3D11InputLayout *input_layout;
18156 ID3D11Device *device;
18157 unsigned int i;
18158 HRESULT hr;
18160 static const DWORD vs_code[] =
18162 #if 0
18163 float4 main(float4 position : POSITION) : SV_POSITION
18165 return position;
18167 #endif
18168 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
18169 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18170 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
18171 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
18172 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
18173 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18174 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
18176 static const DXGI_FORMAT vertex_formats[] =
18178 DXGI_FORMAT_R32G32_FLOAT,
18179 DXGI_FORMAT_R32G32_UINT,
18180 DXGI_FORMAT_R32G32_SINT,
18181 DXGI_FORMAT_R16G16_FLOAT,
18182 DXGI_FORMAT_R16G16_UINT,
18183 DXGI_FORMAT_R16G16_SINT,
18184 DXGI_FORMAT_R32_FLOAT,
18185 DXGI_FORMAT_R32_UINT,
18186 DXGI_FORMAT_R32_SINT,
18187 DXGI_FORMAT_R16_UINT,
18188 DXGI_FORMAT_R16_SINT,
18189 DXGI_FORMAT_R8G8_UNORM,
18190 DXGI_FORMAT_R8_UINT,
18191 DXGI_FORMAT_R8_SINT,
18194 if (!(device = create_device(NULL)))
18196 skip("Failed to create device.\n");
18197 return;
18200 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
18202 expected_refcount = get_refcount(device) + 1;
18203 layout_desc->Format = vertex_formats[i];
18204 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
18205 vs_code, sizeof(vs_code), &input_layout);
18206 ok(hr == S_OK, "Failed to create input layout for format %#x, hr %#x.\n",
18207 vertex_formats[i], hr);
18208 refcount = get_refcount(device);
18209 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
18210 refcount, expected_refcount);
18211 ID3D11InputLayout_Release(input_layout);
18214 refcount = ID3D11Device_Release(device);
18215 ok(!refcount, "Device has %u references left.\n", refcount);
18218 static void test_input_layout_alignment(void)
18220 ID3D11InputLayout *layout;
18221 ID3D11Device *device;
18222 unsigned int i;
18223 ULONG refcount;
18224 HRESULT hr;
18226 static const DWORD vs_code[] =
18228 #if 0
18229 float4 main(float4 position : POSITION) : SV_POSITION
18231 return position;
18233 #endif
18234 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
18235 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18236 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
18237 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
18238 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
18239 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18240 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
18243 static const struct
18245 D3D11_INPUT_ELEMENT_DESC elements[2];
18246 HRESULT hr;
18248 test_data[] =
18251 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18252 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18253 }, S_OK},
18255 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18256 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 1, D3D11_INPUT_PER_VERTEX_DATA, 0},
18257 }, E_INVALIDARG},
18259 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18260 {"COLOR", 0, DXGI_FORMAT_R8_UINT, 0, 1, D3D11_INPUT_PER_VERTEX_DATA, 0},
18261 }, S_OK},
18263 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18264 {"COLOR", 0, DXGI_FORMAT_R32_UINT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18265 }, E_INVALIDARG},
18267 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18268 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18269 }, E_INVALIDARG},
18271 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18272 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
18273 }, S_OK},
18275 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18276 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 17, D3D11_INPUT_PER_VERTEX_DATA, 0},
18277 }, E_INVALIDARG},
18279 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18280 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 18, D3D11_INPUT_PER_VERTEX_DATA, 0},
18281 }, E_INVALIDARG},
18283 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18284 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 19, D3D11_INPUT_PER_VERTEX_DATA, 0},
18285 }, E_INVALIDARG},
18287 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18288 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
18289 }, S_OK},
18292 if (!(device = create_device(NULL)))
18294 skip("Failed to create device.\n");
18295 return;
18298 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
18300 hr = ID3D11Device_CreateInputLayout(device, test_data[i].elements, 2, vs_code, sizeof(vs_code), &layout);
18301 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
18302 if (SUCCEEDED(hr))
18303 ID3D11InputLayout_Release(layout);
18306 refcount = ID3D11Device_Release(device);
18307 ok(!refcount, "Device has %u references left.\n", refcount);
18310 static void test_input_assembler(void)
18312 enum layout_id
18314 LAYOUT_FLOAT32,
18315 LAYOUT_UINT16,
18316 LAYOUT_SINT16,
18317 LAYOUT_UNORM16,
18318 LAYOUT_SNORM16,
18319 LAYOUT_UINT8,
18320 LAYOUT_SINT8,
18321 LAYOUT_UNORM8,
18322 LAYOUT_SNORM8,
18323 LAYOUT_UNORM10_2,
18324 LAYOUT_UINT10_2,
18326 LAYOUT_COUNT,
18329 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
18331 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18332 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18334 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
18335 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
18336 ID3D11Buffer *vb_position, *vb_attribute;
18337 struct d3d11_test_context test_context;
18338 D3D11_TEXTURE2D_DESC texture_desc;
18339 unsigned int i, j, stride, offset;
18340 ID3D11Texture2D *render_target;
18341 ID3D11DeviceContext *context;
18342 ID3D11RenderTargetView *rtv;
18343 ID3D11PixelShader *ps;
18344 ID3D11Device *device;
18345 HRESULT hr;
18347 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
18349 DXGI_FORMAT_R32G32B32A32_FLOAT,
18350 DXGI_FORMAT_R16G16B16A16_UINT,
18351 DXGI_FORMAT_R16G16B16A16_SINT,
18352 DXGI_FORMAT_R16G16B16A16_UNORM,
18353 DXGI_FORMAT_R16G16B16A16_SNORM,
18354 DXGI_FORMAT_R8G8B8A8_UINT,
18355 DXGI_FORMAT_R8G8B8A8_SINT,
18356 DXGI_FORMAT_R8G8B8A8_UNORM,
18357 DXGI_FORMAT_R8G8B8A8_SNORM,
18358 DXGI_FORMAT_R10G10B10A2_UNORM,
18359 DXGI_FORMAT_R10G10B10A2_UINT,
18361 static const struct vec2 quad[] =
18363 {-1.0f, -1.0f},
18364 {-1.0f, 1.0f},
18365 { 1.0f, -1.0f},
18366 { 1.0f, 1.0f},
18368 static const DWORD ps_code[] =
18370 #if 0
18371 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
18373 return color;
18375 #endif
18376 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
18377 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
18378 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
18379 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
18380 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18381 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
18382 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
18383 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
18385 static const DWORD vs_float_code[] =
18387 #if 0
18388 struct output
18390 float4 position : SV_Position;
18391 float4 color : COLOR;
18394 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
18396 o.position = position;
18397 o.color = color;
18399 #endif
18400 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
18401 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18402 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18403 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18404 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18405 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18406 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18407 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18408 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18409 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18410 0x0100003e,
18412 static const DWORD vs_uint_code[] =
18414 #if 0
18415 struct output
18417 float4 position : SV_Position;
18418 float4 color : COLOR;
18421 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
18423 o.position = position;
18424 o.color = color;
18426 #endif
18427 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
18428 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18429 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18430 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18431 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18432 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18433 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18434 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18435 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18436 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18437 0x0100003e,
18439 static const DWORD vs_sint_code[] =
18441 #if 0
18442 struct output
18444 float4 position : SV_Position;
18445 float4 color : COLOR;
18448 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
18450 o.position = position;
18451 o.color = color;
18453 #endif
18454 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
18455 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18456 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18457 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18458 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18459 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18460 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18461 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18462 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18463 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18464 0x0100003e,
18466 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
18467 static const unsigned short uint16_data[] = {6, 8, 55, 777};
18468 static const short sint16_data[] = {-1, 33, 8, -77};
18469 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
18470 static const short snorm16_data[] = {-32768, 0, 32767, 0};
18471 static const unsigned char uint8_data[] = {0, 64, 128, 255};
18472 static const signed char sint8_data[] = {-128, 0, 127, 64};
18473 static const unsigned int uint32_zero = 0;
18474 static const unsigned int uint32_max = 0xffffffff;
18475 static const unsigned int unorm10_2_data= 0xa00003ff;
18476 static const unsigned int g10_data = 0x000ffc00;
18477 static const unsigned int a2_data = 0xc0000000;
18478 static const struct
18480 enum layout_id layout_id;
18481 unsigned int stride;
18482 const void *data;
18483 struct vec4 expected_color;
18484 BOOL todo;
18486 tests[] =
18488 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
18489 {1.0f, 2.0f, 3.0f, 4.0f}},
18490 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
18491 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
18492 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
18493 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
18494 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
18495 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
18496 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
18497 {-1.0f, 0.0f, 1.0f, 0.0f}},
18498 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
18499 {0.0f, 0.0f, 0.0f, 0.0f}},
18500 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
18501 {255.0f, 255.0f, 255.0f, 255.0f}},
18502 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
18503 {0.0f, 64.0f, 128.0f, 255.0f}},
18504 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
18505 {0.0f, 0.0f, 0.0f, 0.0f}},
18506 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
18507 {-1.0f, -1.0f, -1.0f, -1.0f}},
18508 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
18509 {-128.0f, 0.0f, 127.0f, 64.0f}},
18510 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
18511 {0.0f, 0.0f, 0.0f, 0.0f}},
18512 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
18513 {1.0f, 1.0f, 1.0f, 1.0f}},
18514 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
18515 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
18516 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
18517 {0.0f, 0.0f, 0.0f, 0.0f}},
18518 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
18519 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
18520 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
18521 {0.0f, 0.0f, 0.0f, 0.0f}},
18522 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
18523 {1.0f, 1.0f, 1.0f, 1.0f}},
18524 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
18525 {0.0f, 1.0f, 0.0f, 0.0f}},
18526 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
18527 {0.0f, 0.0f, 0.0f, 1.0f}},
18528 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
18529 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
18530 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
18531 {0.0f, 0.0f, 0.0f, 0.0f}},
18532 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
18533 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
18534 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
18535 {0.0f, 1023.0f, 0.0f, 0.0f}},
18536 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
18537 {0.0f, 0.0f, 0.0f, 3.0f}},
18538 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
18539 {1023.0f, 0.0f, 512.0f, 2.0f}},
18542 if (!init_test_context(&test_context, NULL))
18543 return;
18545 device = test_context.device;
18546 context = test_context.immediate_context;
18548 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18549 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18551 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
18552 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
18553 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
18554 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
18555 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
18556 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
18558 for (i = 0; i < LAYOUT_COUNT; ++i)
18560 input_layout_desc[1].Format = layout_formats[i];
18561 input_layout[i] = NULL;
18562 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
18563 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
18564 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
18565 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
18568 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
18569 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
18571 texture_desc.Width = 640;
18572 texture_desc.Height = 480;
18573 texture_desc.MipLevels = 1;
18574 texture_desc.ArraySize = 1;
18575 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
18576 texture_desc.SampleDesc.Count = 1;
18577 texture_desc.SampleDesc.Quality = 0;
18578 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18579 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
18580 texture_desc.CPUAccessFlags = 0;
18581 texture_desc.MiscFlags = 0;
18583 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
18584 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
18586 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
18587 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18589 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
18590 offset = 0;
18591 stride = sizeof(*quad);
18592 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
18593 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18594 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18596 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18598 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
18600 if (tests[i].layout_id == LAYOUT_UINT10_2)
18601 continue;
18603 assert(tests[i].layout_id < LAYOUT_COUNT);
18604 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
18606 assert(4 * tests[i].stride <= 1024);
18607 box.right = tests[i].stride;
18608 for (j = 0; j < 4; ++j)
18610 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
18611 &box, tests[i].data, 0, 0);
18612 box.left += tests[i].stride;
18613 box.right += tests[i].stride;
18616 stride = tests[i].stride;
18617 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
18619 switch (layout_formats[tests[i].layout_id])
18621 case DXGI_FORMAT_R16G16B16A16_UINT:
18622 case DXGI_FORMAT_R10G10B10A2_UINT:
18623 case DXGI_FORMAT_R8G8B8A8_UINT:
18624 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
18625 break;
18626 case DXGI_FORMAT_R16G16B16A16_SINT:
18627 case DXGI_FORMAT_R8G8B8A8_SINT:
18628 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
18629 break;
18631 default:
18632 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
18633 /* Fall through. */
18634 case DXGI_FORMAT_R32G32B32A32_FLOAT:
18635 case DXGI_FORMAT_R16G16B16A16_UNORM:
18636 case DXGI_FORMAT_R16G16B16A16_SNORM:
18637 case DXGI_FORMAT_R10G10B10A2_UNORM:
18638 case DXGI_FORMAT_R8G8B8A8_UNORM:
18639 case DXGI_FORMAT_R8G8B8A8_SNORM:
18640 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
18641 break;
18644 ID3D11DeviceContext_Draw(context, 4, 0);
18645 check_texture_vec4(render_target, &tests[i].expected_color, 2);
18648 ID3D11Texture2D_Release(render_target);
18649 ID3D11RenderTargetView_Release(rtv);
18650 ID3D11Buffer_Release(vb_attribute);
18651 ID3D11Buffer_Release(vb_position);
18652 for (i = 0; i < LAYOUT_COUNT; ++i)
18654 if (input_layout[i])
18655 ID3D11InputLayout_Release(input_layout[i]);
18657 ID3D11PixelShader_Release(ps);
18658 ID3D11VertexShader_Release(vs_float);
18659 ID3D11VertexShader_Release(vs_uint);
18660 ID3D11VertexShader_Release(vs_sint);
18661 release_test_context(&test_context);
18664 static void test_null_sampler(void)
18666 struct d3d11_test_context test_context;
18667 D3D11_TEXTURE2D_DESC texture_desc;
18668 ID3D11ShaderResourceView *srv;
18669 ID3D11DeviceContext *context;
18670 ID3D11RenderTargetView *rtv;
18671 ID3D11SamplerState *sampler;
18672 ID3D11Texture2D *texture;
18673 ID3D11PixelShader *ps;
18674 ID3D11Device *device;
18675 HRESULT hr;
18677 static const DWORD ps_code[] =
18679 #if 0
18680 Texture2D t;
18681 SamplerState s;
18683 float4 main(float4 position : SV_POSITION) : SV_Target
18685 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
18687 #endif
18688 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
18689 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18690 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
18691 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18692 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
18693 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
18694 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
18695 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
18696 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
18697 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
18699 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
18701 if (!init_test_context(&test_context, NULL))
18702 return;
18704 device = test_context.device;
18705 context = test_context.immediate_context;
18707 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18708 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18710 texture_desc.Width = 64;
18711 texture_desc.Height = 64;
18712 texture_desc.MipLevels = 1;
18713 texture_desc.ArraySize = 1;
18714 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
18715 texture_desc.SampleDesc.Count = 1;
18716 texture_desc.SampleDesc.Quality = 0;
18717 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18718 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
18719 texture_desc.CPUAccessFlags = 0;
18720 texture_desc.MiscFlags = 0;
18722 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18723 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18725 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18726 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
18728 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
18729 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
18731 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
18733 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18734 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18735 sampler = NULL;
18736 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
18737 draw_quad(&test_context);
18738 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
18740 ID3D11ShaderResourceView_Release(srv);
18741 ID3D11RenderTargetView_Release(rtv);
18742 ID3D11Texture2D_Release(texture);
18743 ID3D11PixelShader_Release(ps);
18744 release_test_context(&test_context);
18747 static void test_check_feature_support(void)
18749 D3D11_FEATURE_DATA_THREADING threading[2];
18750 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
18751 D3D11_FEATURE_DATA_ARCHITECTURE_INFO archinfo;
18752 ID3D11Device *device;
18753 ULONG refcount;
18754 HRESULT hr;
18756 if (!(device = create_device(NULL)))
18758 skip("Failed to create device.\n");
18759 return;
18762 memset(threading, 0xef, sizeof(threading));
18764 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
18765 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18766 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
18767 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18768 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
18769 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18770 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
18771 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18772 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
18773 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18774 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
18775 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18777 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
18778 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
18779 ok(threading[0].DriverCommandLists == 0xefefefef,
18780 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
18781 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
18782 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
18783 ok(threading[1].DriverCommandLists == 0xefefefef,
18784 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
18786 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
18787 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18788 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
18789 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
18790 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
18791 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
18793 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
18794 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18795 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
18796 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18797 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
18798 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18799 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
18800 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18801 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
18802 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18803 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
18804 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18806 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
18807 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18808 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
18810 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo));
18811 ok(hr == S_OK || broken(hr == E_INVALIDARG) /* Not available on all Windows versions. */,
18812 "Got unexpected hr %#x.\n", hr);
18813 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo)*2);
18814 ok(hr == E_INVALIDARG /* Not available on all Windows versions but they will return E_INVALIDARG anyways. */,
18815 "Got unexpected hr %#x.\n", hr);
18817 refcount = ID3D11Device_Release(device);
18818 ok(!refcount, "Device has %u references left.\n", refcount);
18821 static void test_create_unordered_access_view(void)
18823 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18824 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18825 D3D11_TEXTURE3D_DESC texture3d_desc;
18826 D3D11_TEXTURE2D_DESC texture2d_desc;
18827 ULONG refcount, expected_refcount;
18828 D3D11_SUBRESOURCE_DATA data = {0};
18829 ID3D11UnorderedAccessView *uav;
18830 struct device_desc device_desc;
18831 D3D11_BUFFER_DESC buffer_desc;
18832 ID3D11Device *device, *tmp;
18833 ID3D11Texture3D *texture3d;
18834 ID3D11Texture2D *texture2d;
18835 ID3D11Resource *texture;
18836 ID3D11Buffer *buffer;
18837 unsigned int i;
18838 HRESULT hr;
18840 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
18841 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
18842 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
18843 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
18844 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
18845 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
18846 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
18847 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
18848 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
18849 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
18850 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
18851 static const struct
18853 struct
18855 unsigned int miplevel_count;
18856 unsigned int depth_or_array_size;
18857 DXGI_FORMAT format;
18858 } texture;
18859 struct uav_desc uav_desc;
18860 struct uav_desc expected_uav_desc;
18862 tests[] =
18864 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
18865 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
18866 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
18867 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
18868 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
18869 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
18870 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
18871 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
18872 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
18873 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
18874 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
18875 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
18876 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
18877 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
18878 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
18879 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
18880 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
18881 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
18882 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
18883 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
18884 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
18885 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
18886 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
18887 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
18888 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
18889 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
18890 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
18891 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
18892 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
18893 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
18894 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
18895 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
18896 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
18897 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
18898 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
18899 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
18901 static const struct
18903 struct
18905 D3D11_UAV_DIMENSION dimension;
18906 unsigned int miplevel_count;
18907 unsigned int depth_or_array_size;
18908 DXGI_FORMAT format;
18909 } texture;
18910 struct uav_desc uav_desc;
18912 invalid_desc_tests[] =
18914 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
18915 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
18916 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
18917 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
18918 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
18919 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
18920 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
18921 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
18922 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
18923 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
18924 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
18925 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
18926 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
18927 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
18928 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
18929 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
18930 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
18931 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
18932 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
18933 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
18934 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
18935 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
18936 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
18937 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
18938 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
18939 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
18940 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
18941 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
18942 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
18943 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
18944 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
18945 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
18946 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
18947 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
18948 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
18949 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
18950 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
18952 #undef FMT_UNKNOWN
18953 #undef RGBA8_UNORM
18954 #undef RGBA8_SRGB
18955 #undef RGBA8_UINT
18956 #undef RGBA8_TL
18957 #undef DIM_UNKNOWN
18958 #undef TEX_1D
18959 #undef TEX_1D_ARRAY
18960 #undef TEX_2D
18961 #undef TEX_2D_ARRAY
18962 #undef TEX_3D
18964 device_desc.feature_level = &feature_level;
18965 device_desc.flags = 0;
18966 if (!(device = create_device(&device_desc)))
18968 skip("Failed to create device.\n");
18969 return;
18972 buffer_desc.ByteWidth = 1024;
18973 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18974 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
18975 buffer_desc.CPUAccessFlags = 0;
18976 buffer_desc.MiscFlags = 0;
18977 buffer_desc.StructureByteStride = 0;
18979 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
18980 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18982 expected_refcount = get_refcount(device) + 1;
18983 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
18984 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
18985 refcount = get_refcount(device);
18986 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
18987 tmp = NULL;
18988 expected_refcount = refcount + 1;
18989 ID3D11Buffer_GetDevice(buffer, &tmp);
18990 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
18991 refcount = get_refcount(device);
18992 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
18993 ID3D11Device_Release(tmp);
18995 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
18996 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
18997 U(uav_desc).Buffer.FirstElement = 0;
18998 U(uav_desc).Buffer.NumElements = 64;
18999 U(uav_desc).Buffer.Flags = 0;
19001 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19002 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19004 expected_refcount = get_refcount(device) + 1;
19005 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19006 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19007 refcount = get_refcount(device);
19008 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
19009 tmp = NULL;
19010 expected_refcount = refcount + 1;
19011 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
19012 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
19013 refcount = get_refcount(device);
19014 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
19015 ID3D11Device_Release(tmp);
19017 ID3D11UnorderedAccessView_Release(uav);
19018 ID3D11Buffer_Release(buffer);
19020 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19021 buffer_desc.StructureByteStride = 4;
19023 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19024 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19026 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19027 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19029 memset(&uav_desc, 0, sizeof(uav_desc));
19030 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
19032 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
19033 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
19034 uav_desc.ViewDimension);
19035 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
19036 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
19037 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
19039 ID3D11UnorderedAccessView_Release(uav);
19040 ID3D11Buffer_Release(buffer);
19042 /* Without D3D11_BIND_UNORDERED_ACCESS. */
19043 buffer = create_buffer(device, 0, 1024, NULL);
19045 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19046 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19047 U(uav_desc).Buffer.FirstElement = 0;
19048 U(uav_desc).Buffer.NumElements = 64;
19049 U(uav_desc).Buffer.Flags = 0;
19051 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19052 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19054 ID3D11Buffer_Release(buffer);
19056 texture2d_desc.Width = 512;
19057 texture2d_desc.Height = 512;
19058 texture2d_desc.SampleDesc.Count = 1;
19059 texture2d_desc.SampleDesc.Quality = 0;
19060 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
19061 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19062 texture2d_desc.CPUAccessFlags = 0;
19063 texture2d_desc.MiscFlags = 0;
19065 texture3d_desc.Width = 64;
19066 texture3d_desc.Height = 64;
19067 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
19068 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19069 texture3d_desc.CPUAccessFlags = 0;
19070 texture3d_desc.MiscFlags = 0;
19072 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19074 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
19076 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
19078 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
19079 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
19080 texture2d_desc.Format = tests[i].texture.format;
19082 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
19083 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
19084 texture = (ID3D11Resource *)texture2d;
19086 else
19088 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
19089 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
19090 texture3d_desc.Format = tests[i].texture.format;
19092 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
19093 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
19094 texture = (ID3D11Resource *)texture3d;
19097 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
19099 current_desc = NULL;
19101 else
19103 current_desc = &uav_desc;
19104 get_uav_desc(current_desc, &tests[i].uav_desc);
19107 expected_refcount = get_refcount(texture);
19108 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
19109 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
19110 refcount = get_refcount(texture);
19111 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
19113 memset(&uav_desc, 0, sizeof(uav_desc));
19114 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
19115 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
19117 ID3D11UnorderedAccessView_Release(uav);
19118 ID3D11Resource_Release(texture);
19121 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
19123 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
19124 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
19126 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
19128 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
19129 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
19130 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
19132 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
19133 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
19134 texture = (ID3D11Resource *)texture2d;
19136 else
19138 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
19139 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
19140 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
19142 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
19143 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
19144 texture = (ID3D11Resource *)texture3d;
19147 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
19148 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
19149 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
19151 ID3D11Resource_Release(texture);
19154 refcount = ID3D11Device_Release(device);
19155 ok(!refcount, "Device has %u references left.\n", refcount);
19158 static void test_immediate_constant_buffer(void)
19160 struct d3d11_test_context test_context;
19161 D3D11_TEXTURE2D_DESC texture_desc;
19162 ID3D11DeviceContext *context;
19163 ID3D11RenderTargetView *rtv;
19164 unsigned int index[4] = {0};
19165 ID3D11Texture2D *texture;
19166 ID3D11PixelShader *ps;
19167 ID3D11Device *device;
19168 ID3D11Buffer *cb;
19169 unsigned int i;
19170 HRESULT hr;
19172 static const DWORD ps_code[] =
19174 #if 0
19175 uint index;
19177 static const int int_array[6] =
19179 310, 111, 212, -513, -318, 0,
19182 static const uint uint_array[6] =
19184 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
19187 static const float float_array[6] =
19189 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
19192 float4 main() : SV_Target
19194 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
19196 #endif
19197 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
19198 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19199 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19200 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
19201 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
19202 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
19203 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
19204 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
19205 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19206 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
19207 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
19208 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
19209 0x0100003e,
19211 static struct vec4 expected_result[] =
19213 { 310.0f, 2.0f, 76.00f, 1.0f},
19214 { 111.0f, 7.0f, 83.50f, 1.0f},
19215 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
19216 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
19217 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
19218 { 0.0f, 0.0f, 0.0f, 1.0f},
19221 if (!init_test_context(&test_context, NULL))
19222 return;
19224 device = test_context.device;
19225 context = test_context.immediate_context;
19227 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19228 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19229 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19231 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
19232 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19234 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19235 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19236 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19237 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19239 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19240 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19241 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19243 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
19245 *index = i;
19246 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
19248 draw_quad(&test_context);
19249 check_texture_vec4(texture, &expected_result[i], 0);
19252 ID3D11Buffer_Release(cb);
19253 ID3D11PixelShader_Release(ps);
19254 ID3D11Texture2D_Release(texture);
19255 ID3D11RenderTargetView_Release(rtv);
19256 release_test_context(&test_context);
19259 static void test_fp_specials(void)
19261 struct d3d11_test_context test_context;
19262 D3D11_TEXTURE2D_DESC texture_desc;
19263 ID3D11DeviceContext *context;
19264 ID3D11RenderTargetView *rtv;
19265 ID3D11Texture2D *texture;
19266 ID3D11PixelShader *ps;
19267 ID3D11Device *device;
19268 HRESULT hr;
19270 static const DWORD ps_code[] =
19272 #if 0
19273 float4 main() : SV_Target
19275 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
19277 #endif
19278 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
19279 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19280 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19281 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
19282 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
19283 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
19285 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
19287 if (!init_test_context(&test_context, NULL))
19288 return;
19290 device = test_context.device;
19291 context = test_context.immediate_context;
19293 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19294 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19295 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19297 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19298 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19299 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19300 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19302 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19303 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19305 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19307 draw_quad(&test_context);
19308 check_texture_uvec4(texture, &expected_result);
19310 ID3D11PixelShader_Release(ps);
19311 ID3D11Texture2D_Release(texture);
19312 ID3D11RenderTargetView_Release(rtv);
19313 release_test_context(&test_context);
19316 static void test_uint_shader_instructions(void)
19318 struct shader
19320 const DWORD *code;
19321 size_t size;
19322 D3D_FEATURE_LEVEL required_feature_level;
19325 struct d3d11_test_context test_context;
19326 D3D11_TEXTURE2D_DESC texture_desc;
19327 D3D_FEATURE_LEVEL feature_level;
19328 ID3D11DeviceContext *context;
19329 ID3D11RenderTargetView *rtv;
19330 ID3D11Texture2D *texture;
19331 ID3D11PixelShader *ps;
19332 ID3D11Device *device;
19333 ID3D11Buffer *cb;
19334 unsigned int i;
19335 HRESULT hr;
19337 static const DWORD ps_bfi_code[] =
19339 #if 0
19340 uint bits, offset, insert, base;
19342 uint4 main() : SV_Target
19344 uint mask = ((1 << bits) - 1) << offset;
19345 return ((insert << offset) & mask) | (base & ~mask);
19347 #endif
19348 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
19349 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19350 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19351 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
19352 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19353 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
19354 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
19356 static const DWORD ps_bfi2_code[] =
19358 #if 0
19359 ps_5_0
19360 dcl_globalFlags refactoringAllowed
19361 dcl_constantbuffer cb0[1], immediateIndexed
19362 dcl_output o0.xyzw
19363 dcl_temps 1
19364 mov r0.xyzw, cb0[0].xyzw
19365 bfi r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz, r0.wwww
19366 mov o0.xyzw, r0.xyzw
19368 #endif
19369 0x43425844, 0x900f86b6, 0x73f4dabf, 0xea1b1106, 0x591ac790, 0x00000001, 0x00000104, 0x00000003,
19370 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19371 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19372 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000008c, 0x00000050, 0x00000023,
19373 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19374 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19375 0x0b00008c, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19376 0x00000000, 0x00100ff6, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
19377 0x0100003e,
19379 static const DWORD ps_ibfe_code[] =
19381 #if 0
19382 ps_5_0
19383 dcl_globalFlags refactoringAllowed
19384 dcl_constantbuffer cb0[1], immediateIndexed
19385 dcl_output o0.xyzw
19386 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
19388 #endif
19389 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
19390 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19391 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19392 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
19393 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19394 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
19395 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
19397 static const DWORD ps_ibfe2_code[] =
19399 #if 0
19400 ps_5_0
19401 dcl_globalFlags refactoringAllowed
19402 dcl_constantbuffer cb0[1], immediateIndexed
19403 dcl_output o0.xyzw
19404 dcl_temps 1
19405 mov r0.xyzw, cb0[0].xyzw
19406 ibfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
19407 mov o0.xyzw, r0.xyzw
19409 #endif
19410 0x43425844, 0x347a9c0e, 0x3eff39a4, 0x3dd41cc5, 0xff87ec8d, 0x00000001, 0x000000fc, 0x00000003,
19411 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19412 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19413 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
19414 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19415 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19416 0x0900008b, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19417 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19419 static const DWORD ps_ubfe_code[] =
19421 #if 0
19422 uint u;
19424 uint4 main() : SV_Target
19426 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
19428 #endif
19429 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
19430 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19431 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19432 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
19433 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19434 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
19435 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
19436 0x0100003e,
19438 static const DWORD ps_ubfe2_code[] =
19440 #if 0
19441 ps_5_0
19442 dcl_globalFlags refactoringAllowed
19443 dcl_constantbuffer cb0[1], immediateIndexed
19444 dcl_output o0.xyzw
19445 dcl_temps 1
19446 mov r0.xyzw, cb0[0].xyzw
19447 ubfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
19448 mov o0.xyzw, r0.xyzw
19450 #endif
19451 0x43425844, 0xf377b7fc, 0x1e4cb9e7, 0xb9b1020d, 0xde484388, 0x00000001, 0x000000fc, 0x00000003,
19452 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19453 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19454 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
19455 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19456 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19457 0x0900008a, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19458 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19460 static const DWORD ps_bfrev_code[] =
19462 #if 0
19463 uint bits;
19465 uint4 main() : SV_Target
19467 return uint4(reversebits(bits), reversebits(reversebits(bits)),
19468 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
19470 #endif
19471 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
19472 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19473 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19474 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
19475 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19476 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
19477 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
19478 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
19479 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
19480 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
19481 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
19483 static const DWORD ps_bits_code[] =
19485 #if 0
19486 uint u;
19487 int i;
19489 uint4 main() : SV_Target
19491 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
19493 #endif
19494 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
19495 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19496 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19497 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
19498 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19499 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
19500 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
19501 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
19502 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
19503 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
19504 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
19505 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
19506 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
19507 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
19509 static const DWORD ps_ftou_code[] =
19511 #if 0
19512 float f;
19514 uint4 main() : SV_Target
19516 return uint4(f, -f, 0, 0);
19518 #endif
19519 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
19520 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19521 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19522 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
19523 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
19524 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
19525 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
19526 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
19528 static const DWORD ps_f16tof32_code[] =
19530 #if 0
19531 uint4 hf;
19533 uint4 main() : SV_Target
19535 return f16tof32(hf);
19537 #endif
19538 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
19539 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19540 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19541 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
19542 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19543 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19544 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19546 static const DWORD ps_f32tof16_code[] =
19548 #if 0
19549 float4 f;
19551 uint4 main() : SV_Target
19553 return f32tof16(f);
19555 #endif
19556 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
19557 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19558 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19559 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
19560 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19561 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
19563 static const DWORD ps_not_code[] =
19565 #if 0
19566 uint2 bits;
19568 uint4 main() : SV_Target
19570 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
19572 #endif
19573 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
19574 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19575 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19576 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
19577 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
19578 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
19579 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
19580 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
19582 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
19583 static const struct shader ps_bfi2 = {ps_bfi2_code, sizeof(ps_bfi2_code), D3D_FEATURE_LEVEL_11_0};
19584 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
19585 static const struct shader ps_ibfe2 = {ps_ibfe2_code, sizeof(ps_ibfe2_code), D3D_FEATURE_LEVEL_11_0};
19586 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
19587 static const struct shader ps_ubfe2 = {ps_ubfe2_code, sizeof(ps_ubfe2_code), D3D_FEATURE_LEVEL_11_0};
19588 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
19589 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
19590 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
19591 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
19592 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
19593 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
19594 static const struct
19596 const struct shader *ps;
19597 unsigned int bits[4];
19598 struct uvec4 expected_result;
19600 tests[] =
19602 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
19603 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
19604 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19605 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19606 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19607 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19608 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
19609 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
19610 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
19611 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
19612 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
19613 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
19614 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
19615 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
19616 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
19617 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
19618 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
19619 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
19620 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
19622 {&ps_bfi2, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19623 {&ps_bfi2, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19624 {&ps_bfi2, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19625 {&ps_bfi2, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19627 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19628 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19629 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19630 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19631 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
19632 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
19633 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19634 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19635 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
19636 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19637 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19638 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19639 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19640 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19641 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19642 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19643 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19644 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19645 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
19646 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
19647 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19648 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19649 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19650 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19651 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19652 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19654 {&ps_ibfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19656 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19657 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
19658 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
19659 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
19660 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
19661 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19662 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
19664 {&ps_ubfe2, { 4, 4, 0x7fffffff}, {0x0000000f, 0x0000000f, 0x0000000f, 0x0000000f}},
19665 {&ps_ubfe2, {23, 8, 0xffffffff}, {0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff}},
19666 {&ps_ubfe2, {30, 1, 0xffffffff}, {0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff}},
19667 {&ps_ubfe2, {15, 15, 0x7fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19668 {&ps_ubfe2, {15, 15, 0xffff00ff}, {0x00007ffe, 0x00007ffe, 0x00007ffe, 0x00007ffe}},
19669 {&ps_ubfe2, {16, 15, 0xffffffff}, {0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff}},
19670 {&ps_ubfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19671 {&ps_ubfe2, {20, 15, 0xffffffff}, {0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff}},
19672 {&ps_ubfe2, {31, 31, 0xffffffff}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
19673 {&ps_ubfe2, {31, 31, 0x80000000}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
19674 {&ps_ubfe2, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19676 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
19677 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
19678 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
19680 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
19681 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
19682 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
19683 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
19684 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
19685 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
19686 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
19687 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
19688 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
19689 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
19690 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
19691 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
19693 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
19694 {&ps_ftou, {BITS_NAN}, { 0, 0}},
19695 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
19696 {&ps_ftou, {BITS_INF}, {~0u, 0}},
19697 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
19698 {&ps_ftou, {BITS_1_0}, { 1, 0}},
19700 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
19701 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
19702 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
19703 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
19705 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
19707 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
19708 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
19711 if (!init_test_context(&test_context, NULL))
19712 return;
19714 device = test_context.device;
19715 context = test_context.immediate_context;
19716 feature_level = ID3D11Device_GetFeatureLevel(device);
19718 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
19719 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19721 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19722 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
19723 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19724 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19726 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19727 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19729 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19731 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19733 if (feature_level < tests[i].ps->required_feature_level)
19734 continue;
19736 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
19737 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19738 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19740 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
19742 draw_quad(&test_context);
19743 check_texture_uvec4(texture, &tests[i].expected_result);
19745 ID3D11PixelShader_Release(ps);
19748 ID3D11Buffer_Release(cb);
19749 ID3D11Texture2D_Release(texture);
19750 ID3D11RenderTargetView_Release(rtv);
19751 release_test_context(&test_context);
19754 static void test_index_buffer_offset(void)
19756 ID3D11Buffer *vb, *ib, *so_buffer, *args_buffer;
19757 struct d3d11_test_context test_context;
19758 ID3D11InputLayout *input_layout;
19759 ID3D11DeviceContext *context;
19760 struct resource_readback rb;
19761 ID3D11GeometryShader *gs;
19762 const struct vec4 *data;
19763 ID3D11VertexShader *vs;
19764 ID3D11Device *device;
19765 UINT stride, offset;
19766 unsigned int i;
19767 HRESULT hr;
19769 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19770 static const DWORD vs_code[] =
19772 #if 0
19773 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
19774 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
19776 out_position = position;
19777 out_attrib = attrib;
19779 #endif
19780 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
19781 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19782 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19783 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
19784 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19785 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19786 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
19787 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
19788 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
19789 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
19790 0x0100003e,
19792 static const DWORD gs_code[] =
19794 #if 0
19795 struct vertex
19797 float4 position : SV_POSITION;
19798 float4 attrib : ATTRIB;
19801 [maxvertexcount(1)]
19802 void main(point vertex input[1], inout PointStream<vertex> output)
19804 output.Append(input[0]);
19805 output.RestartStrip();
19807 #endif
19808 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
19809 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19810 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19811 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
19812 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19813 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19814 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
19815 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
19816 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
19817 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
19818 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
19819 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
19821 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
19823 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
19824 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
19826 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
19828 {0, "SV_Position", 0, 0, 4, 0},
19829 {0, "ATTRIB", 0, 0, 4, 0},
19831 static const struct
19833 struct vec4 position;
19834 struct vec4 attrib;
19836 vertices[] =
19838 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
19839 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
19840 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
19841 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
19843 static const unsigned int indices[] =
19845 0, 1, 2, 3,
19846 3, 2, 1, 0,
19847 1, 3, 2, 0,
19849 static const struct vec4 expected_data[] =
19851 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
19852 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
19853 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
19854 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
19856 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
19857 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
19858 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
19859 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
19861 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
19862 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
19863 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
19864 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
19866 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
19867 static const D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS argument_data[] =
19869 {4, 1, 0, 0, 0},
19872 if (!init_test_context(&test_context, &feature_level))
19873 return;
19875 device = test_context.device;
19876 context = test_context.immediate_context;
19878 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
19879 vs_code, sizeof(vs_code), &input_layout);
19880 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
19882 stride = 32;
19883 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
19884 so_declaration, ARRAY_SIZE(so_declaration),
19885 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
19886 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
19888 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
19889 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
19891 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
19892 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
19893 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
19895 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
19896 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
19898 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
19899 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
19900 stride = sizeof(*vertices);
19901 offset = 0;
19902 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
19904 offset = 0;
19905 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
19907 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
19908 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
19910 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
19911 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
19913 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
19914 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
19916 get_buffer_readback(so_buffer, &rb);
19917 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
19919 data = get_readback_vec4(&rb, i, 0);
19920 ok(compare_vec4(data, &expected_data[i], 0)
19921 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
19922 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
19923 data->x, data->y, data->z, data->w, i);
19925 release_resource_readback(&rb);
19927 /* indirect draws */
19928 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
19929 sizeof(argument_data), argument_data);
19931 offset = 0;
19932 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
19934 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
19935 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
19937 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
19938 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
19940 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
19941 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
19943 get_buffer_readback(so_buffer, &rb);
19944 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
19946 data = get_readback_vec4(&rb, i, 0);
19947 todo_wine_if(i >= 8 && i != 20 && i != 21)
19948 ok(compare_vec4(data, &expected_data[i], 0)
19949 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
19950 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
19951 data->x, data->y, data->z, data->w, i);
19953 release_resource_readback(&rb);
19955 ID3D11Buffer_Release(so_buffer);
19956 ID3D11Buffer_Release(args_buffer);
19957 ID3D11Buffer_Release(ib);
19958 ID3D11Buffer_Release(vb);
19959 ID3D11VertexShader_Release(vs);
19960 ID3D11GeometryShader_Release(gs);
19961 ID3D11InputLayout_Release(input_layout);
19962 release_test_context(&test_context);
19965 static void test_face_culling(void)
19967 struct d3d11_test_context test_context;
19968 D3D11_RASTERIZER_DESC rasterizer_desc;
19969 ID3D11RasterizerState *state;
19970 ID3D11DeviceContext *context;
19971 ID3D11Buffer *cw_vb, *ccw_vb;
19972 ID3D11Device *device;
19973 BOOL broken_warp;
19974 unsigned int i;
19975 HRESULT hr;
19977 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
19978 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
19979 static const DWORD ps_code[] =
19981 #if 0
19982 float4 main(uint front : SV_IsFrontFace) : SV_Target
19984 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
19986 #endif
19987 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
19988 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
19989 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
19990 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
19991 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
19992 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
19993 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
19994 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
19995 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
19996 0x3f800000, 0x0100003e,
19998 static const struct vec3 ccw_quad[] =
20000 {-1.0f, 1.0f, 0.0f},
20001 {-1.0f, -1.0f, 0.0f},
20002 { 1.0f, 1.0f, 0.0f},
20003 { 1.0f, -1.0f, 0.0f},
20005 static const struct
20007 D3D11_CULL_MODE cull_mode;
20008 BOOL front_ccw;
20009 BOOL expected_cw;
20010 BOOL expected_ccw;
20012 tests[] =
20014 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
20015 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
20016 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
20017 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
20018 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
20019 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
20022 if (!init_test_context(&test_context, NULL))
20023 return;
20025 device = test_context.device;
20026 context = test_context.immediate_context;
20028 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20029 draw_color_quad(&test_context, &green);
20030 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20032 cw_vb = test_context.vb;
20033 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
20035 test_context.vb = ccw_vb;
20036 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20037 draw_color_quad(&test_context, &green);
20038 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
20040 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
20041 rasterizer_desc.CullMode = D3D11_CULL_BACK;
20042 rasterizer_desc.FrontCounterClockwise = FALSE;
20043 rasterizer_desc.DepthBias = 0;
20044 rasterizer_desc.DepthBiasClamp = 0.0f;
20045 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
20046 rasterizer_desc.DepthClipEnable = TRUE;
20047 rasterizer_desc.ScissorEnable = FALSE;
20048 rasterizer_desc.MultisampleEnable = FALSE;
20049 rasterizer_desc.AntialiasedLineEnable = FALSE;
20051 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20053 rasterizer_desc.CullMode = tests[i].cull_mode;
20054 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
20055 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20056 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
20058 ID3D11DeviceContext_RSSetState(context, state);
20060 test_context.vb = cw_vb;
20061 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20062 draw_color_quad(&test_context, &green);
20063 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
20065 test_context.vb = ccw_vb;
20066 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20067 draw_color_quad(&test_context, &green);
20068 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
20070 ID3D11RasterizerState_Release(state);
20073 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0;
20075 /* Test SV_IsFrontFace. */
20076 ID3D11PixelShader_Release(test_context.ps);
20077 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
20078 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20080 rasterizer_desc.CullMode = D3D11_CULL_NONE;
20081 rasterizer_desc.FrontCounterClockwise = FALSE;
20082 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20083 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20084 ID3D11DeviceContext_RSSetState(context, state);
20086 test_context.vb = cw_vb;
20087 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20088 draw_color_quad(&test_context, &green);
20089 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20090 test_context.vb = ccw_vb;
20091 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20092 draw_color_quad(&test_context, &green);
20093 if (!broken_warp)
20094 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
20095 else
20096 win_skip("Broken WARP.\n");
20098 ID3D11RasterizerState_Release(state);
20100 rasterizer_desc.CullMode = D3D11_CULL_NONE;
20101 rasterizer_desc.FrontCounterClockwise = TRUE;
20102 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20103 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20104 ID3D11DeviceContext_RSSetState(context, state);
20106 test_context.vb = cw_vb;
20107 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20108 draw_color_quad(&test_context, &green);
20109 if (!broken_warp)
20110 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
20111 else
20112 win_skip("Broken WARP.\n");
20113 test_context.vb = ccw_vb;
20114 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20115 draw_color_quad(&test_context, &green);
20116 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20118 ID3D11RasterizerState_Release(state);
20120 test_context.vb = cw_vb;
20121 ID3D11Buffer_Release(ccw_vb);
20122 release_test_context(&test_context);
20125 static void test_line_antialiasing_blending(void)
20127 ID3D11RasterizerState *rasterizer_state;
20128 struct d3d11_test_context test_context;
20129 D3D11_RASTERIZER_DESC rasterizer_desc;
20130 ID3D11BlendState *blend_state;
20131 ID3D11DeviceContext *context;
20132 D3D11_BLEND_DESC blend_desc;
20133 ID3D11Device *device;
20134 HRESULT hr;
20136 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
20137 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
20139 if (!init_test_context(&test_context, NULL))
20140 return;
20142 device = test_context.device;
20143 context = test_context.immediate_context;
20145 memset(&blend_desc, 0, sizeof(blend_desc));
20146 blend_desc.AlphaToCoverageEnable = FALSE;
20147 blend_desc.IndependentBlendEnable = FALSE;
20148 blend_desc.RenderTarget[0].BlendEnable = TRUE;
20149 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
20150 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
20151 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
20152 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
20153 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
20154 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
20155 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
20157 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
20158 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
20159 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
20161 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20162 draw_color_quad(&test_context, &green);
20163 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
20165 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20166 draw_color_quad(&test_context, &red);
20167 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
20169 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
20170 ID3D11BlendState_Release(blend_state);
20172 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20173 draw_color_quad(&test_context, &green);
20174 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
20176 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20177 draw_color_quad(&test_context, &red);
20178 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
20180 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
20181 rasterizer_desc.CullMode = D3D11_CULL_BACK;
20182 rasterizer_desc.FrontCounterClockwise = FALSE;
20183 rasterizer_desc.DepthBias = 0;
20184 rasterizer_desc.DepthBiasClamp = 0.0f;
20185 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
20186 rasterizer_desc.DepthClipEnable = TRUE;
20187 rasterizer_desc.ScissorEnable = FALSE;
20188 rasterizer_desc.MultisampleEnable = FALSE;
20189 rasterizer_desc.AntialiasedLineEnable = TRUE;
20191 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
20192 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20193 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
20195 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20196 draw_color_quad(&test_context, &green);
20197 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
20199 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20200 draw_color_quad(&test_context, &red);
20201 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
20203 ID3D11RasterizerState_Release(rasterizer_state);
20204 release_test_context(&test_context);
20207 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
20208 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
20209 const char *feature_name)
20211 unsigned int i;
20213 for (i = 0; i < format_count; ++i)
20215 DXGI_FORMAT format = formats[i].format;
20216 unsigned int supported = format_support[format] & feature_flag;
20218 if (formats[i].fl_required <= feature_level)
20220 todo_wine ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
20221 format, feature_name, feature_level, format_support[format]);
20222 continue;
20225 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
20227 if (supported)
20228 trace("Optional format %#x - %s supported, feature level %#x.\n",
20229 format, feature_name, feature_level);
20230 continue;
20233 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
20234 format, feature_name, feature_level, format_support[format]);
20238 static void test_format_support(const D3D_FEATURE_LEVEL feature_level)
20240 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
20241 struct device_desc device_desc;
20242 ID3D11Device *device;
20243 DXGI_FORMAT format;
20244 ULONG refcount;
20245 UINT support;
20246 HRESULT hr;
20248 static const struct format_support index_buffers[] =
20250 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
20251 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
20254 device_desc.feature_level = &feature_level;
20255 device_desc.flags = 0;
20256 if (!(device = create_device(&device_desc)))
20258 skip("Failed to create device for feature level %#x.\n", feature_level);
20259 return;
20262 support = 0xdeadbeef;
20263 hr = ID3D11Device_CheckFormatSupport(device, ~0u, &support);
20264 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
20265 ok(!support, "Got unexpected format support %#x.\n", support);
20267 memset(format_support, 0, sizeof(format_support));
20268 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
20270 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
20271 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
20272 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
20273 format, hr, format_support[format]);
20274 if (format_support[format] & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN)
20276 ok(format_support[format] & D3D11_FORMAT_SUPPORT_TEXTURE2D,
20277 "Got unexpected format support %#x for format %#x", format_support[format], format);
20281 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
20283 if (feature_level < D3D_FEATURE_LEVEL_10_0)
20285 /* SHADER_SAMPLE_COMPARISON is never advertised as supported on feature level 9. */
20286 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON),
20287 "Unexpected SHADER_SAMPLE_COMPARISON for format %#x, feature level %#x.\n",
20288 format, feature_level);
20289 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_BUFFER),
20290 "Unexpected BUFFER for format %#x, feature level %#x.\n",
20291 format, feature_level);
20293 if (feature_level < D3D_FEATURE_LEVEL_10_1)
20295 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER),
20296 "Unexpected SHADER_GATHER for format %#x, feature level %#x.\n",
20297 format, feature_level);
20298 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON),
20299 "Unexpected SHADER_GATHER_COMPARISON for format %#x, feature level %#x.\n",
20300 format, feature_level);
20304 ok(format_support[DXGI_FORMAT_R8G8B8A8_UNORM] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE,
20305 "SHADER_SAMPLE is not supported for R8G8B8A8_UNORM.\n");
20306 todo_wine
20307 ok(!(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE),
20308 "SHADER_SAMPLE is supported for R32G32B32A32_UINT.\n");
20309 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
20311 ok(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_LOAD,
20312 "SHADER_LOAD is not supported for R32G32B32A32_UINT.\n");
20315 check_format_support(format_support, feature_level,
20316 index_buffers, ARRAY_SIZE(index_buffers),
20317 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
20319 check_format_support(format_support, feature_level,
20320 display_format_support, ARRAY_SIZE(display_format_support),
20321 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
20323 refcount = ID3D11Device_Release(device);
20324 ok(!refcount, "Device has %u references left.\n", refcount);
20327 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
20329 struct d3d11_test_context test_context;
20330 D3D11_SUBRESOURCE_DATA resource_data;
20331 D3D11_TEXTURE2D_DESC texture_desc;
20332 ID3D11ShaderResourceView *srv;
20333 ID3D11DeviceContext *context;
20334 ID3D11Texture2D *texture;
20335 ID3D11PixelShader *ps;
20336 ID3D11Device *device;
20337 HRESULT hr;
20339 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
20340 static const DWORD ps_code[] =
20342 #if 0
20343 float4 main() : SV_TARGET
20345 return float4(1.0f, 0.0f, 0.0f, 0.5f);
20347 #endif
20348 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
20349 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
20350 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
20351 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
20352 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
20353 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
20354 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
20355 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
20356 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
20357 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
20358 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
20359 0x45475241, 0xabab0054,
20361 static const DWORD ps_texture_code[] =
20363 #if 0
20364 Texture2D t;
20365 SamplerState s;
20367 float4 main() : SV_TARGET
20369 return t.Sample(s, (float2)0);
20371 #endif
20372 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
20373 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
20374 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
20375 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
20376 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
20377 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
20378 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
20379 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
20380 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
20381 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
20382 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
20383 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
20384 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
20385 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20386 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
20388 static const DWORD texture_data[] = {0xffffff00};
20390 if (!init_test_context(&test_context, &feature_level))
20391 return;
20393 device = test_context.device;
20394 context = test_context.immediate_context;
20396 texture_desc.Width = 1;
20397 texture_desc.Height = 1;
20398 texture_desc.MipLevels = 0;
20399 texture_desc.ArraySize = 1;
20400 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20401 texture_desc.SampleDesc.Count = 1;
20402 texture_desc.SampleDesc.Quality = 0;
20403 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20404 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20405 texture_desc.CPUAccessFlags = 0;
20406 texture_desc.MiscFlags = 0;
20407 resource_data.pSysMem = texture_data;
20408 resource_data.SysMemPitch = sizeof(texture_data);
20409 resource_data.SysMemSlicePitch = 0;
20410 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20411 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
20412 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
20413 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20415 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20416 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
20417 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20418 draw_quad(&test_context);
20419 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
20420 ID3D11PixelShader_Release(ps);
20422 draw_color_quad(&test_context, &color);
20423 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
20425 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
20426 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
20427 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20428 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20429 draw_quad(&test_context);
20430 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
20431 ID3D11PixelShader_Release(ps);
20433 ID3D11ShaderResourceView_Release(srv);
20434 ID3D11Texture2D_Release(texture);
20435 release_test_context(&test_context);
20438 static void queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
20439 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
20441 static const D3D_FEATURE_LEVEL feature_levels[] =
20443 D3D_FEATURE_LEVEL_11_1,
20444 D3D_FEATURE_LEVEL_11_0,
20445 D3D_FEATURE_LEVEL_10_1,
20446 D3D_FEATURE_LEVEL_10_0,
20447 D3D_FEATURE_LEVEL_9_3,
20448 D3D_FEATURE_LEVEL_9_2,
20449 D3D_FEATURE_LEVEL_9_1
20451 unsigned int i;
20453 assert(begin <= end);
20454 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
20456 if (begin <= feature_levels[i] && feature_levels[i] <= end)
20457 queue_test_fl(test_func, feature_levels[i]);
20461 static void queue_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
20463 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
20464 D3D_FEATURE_LEVEL_11_1, test_func);
20467 static void queue_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
20469 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
20470 D3D_FEATURE_LEVEL_9_3, test_func);
20473 static void test_ddy(void)
20475 static const struct
20477 struct vec4 position;
20478 unsigned int color;
20480 quad[] =
20482 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
20483 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
20484 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
20485 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
20487 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
20489 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
20490 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
20492 #if 0
20493 struct vs_data
20495 float4 pos : SV_POSITION;
20496 float4 color : COLOR;
20499 void main(in struct vs_data vs_input, out struct vs_data vs_output)
20501 vs_output.pos = vs_input.pos;
20502 vs_output.color = vs_input.color;
20504 #endif
20505 static const DWORD vs_code[] =
20507 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
20508 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20509 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
20510 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20511 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
20512 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
20513 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
20514 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
20515 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
20516 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
20517 0x0100003e,
20519 #if 0
20520 struct ps_data
20522 float4 pos : SV_POSITION;
20523 float4 color : COLOR;
20526 float4 main(struct ps_data ps_input) : SV_Target
20528 return ddy(ps_input.color) * 240.0 + 0.5;
20530 #endif
20531 static const DWORD ps_code_ddy[] =
20533 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
20534 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20535 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20536 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20537 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20538 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
20539 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
20540 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
20541 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
20542 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20544 #if 0
20545 struct ps_data
20547 float4 pos : SV_POSITION;
20548 float4 color : COLOR;
20551 float4 main(struct ps_data ps_input) : SV_Target
20553 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
20555 #endif
20556 static const DWORD ps_code_ddy_coarse[] =
20558 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
20559 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20560 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20561 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20562 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20563 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
20564 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
20565 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
20566 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
20567 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20569 #if 0
20570 struct ps_data
20572 float4 pos : SV_POSITION;
20573 float4 color : COLOR;
20576 float4 main(struct ps_data ps_input) : SV_Target
20578 return ddy_fine(ps_input.color) * 240.0 + 0.5;
20580 #endif
20581 static const DWORD ps_code_ddy_fine[] =
20583 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
20584 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20585 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20586 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20587 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20588 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
20589 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
20590 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
20591 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
20592 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20594 static const struct
20596 D3D_FEATURE_LEVEL min_feature_level;
20597 const DWORD *ps_code;
20598 unsigned int ps_code_size;
20600 tests[] =
20602 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
20603 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
20604 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
20606 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
20607 struct d3d11_test_context test_context;
20608 D3D11_TEXTURE2D_DESC texture_desc;
20609 D3D_FEATURE_LEVEL feature_level;
20610 ID3D11InputLayout *input_layout;
20611 ID3D11DeviceContext *context;
20612 unsigned int stride, offset;
20613 struct resource_readback rb;
20614 ID3D11RenderTargetView *rtv;
20615 ID3D11Texture2D *texture;
20616 ID3D11VertexShader *vs;
20617 ID3D11PixelShader *ps;
20618 ID3D11Device *device;
20619 ID3D11Buffer *vb;
20620 unsigned int i;
20621 DWORD color;
20622 HRESULT hr;
20624 if (!init_test_context(&test_context, NULL))
20625 return;
20627 device = test_context.device;
20628 context = test_context.immediate_context;
20629 feature_level = ID3D11Device_GetFeatureLevel(device);
20631 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
20632 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
20633 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20635 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
20636 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
20638 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
20639 vs_code, sizeof(vs_code), &input_layout);
20640 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
20642 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
20644 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
20645 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
20647 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
20648 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
20649 stride = sizeof(*quad);
20650 offset = 0;
20651 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
20652 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
20654 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20656 if (feature_level < tests[i].min_feature_level)
20658 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
20659 feature_level, tests[i].min_feature_level);
20660 continue;
20663 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
20664 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20666 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20668 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20669 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
20670 ID3D11DeviceContext_Draw(context, 4, 0);
20672 get_texture_readback(texture, 0, &rb);
20673 color = get_readback_color(&rb, 320, 190, 0);
20674 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20675 color = get_readback_color(&rb, 255, 240, 0);
20676 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20677 color = get_readback_color(&rb, 320, 240, 0);
20678 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20679 color = get_readback_color(&rb, 385, 240, 0);
20680 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20681 color = get_readback_color(&rb, 320, 290, 0);
20682 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20683 release_resource_readback(&rb);
20685 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
20686 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
20687 ID3D11DeviceContext_Draw(context, 4, 0);
20689 get_texture_readback(test_context.backbuffer, 0, &rb);
20690 color = get_readback_color(&rb, 320, 190, 0);
20691 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20692 color = get_readback_color(&rb, 255, 240, 0);
20693 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20694 color = get_readback_color(&rb, 320, 240, 0);
20695 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20696 color = get_readback_color(&rb, 385, 240, 0);
20697 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20698 color = get_readback_color(&rb, 320, 290, 0);
20699 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20700 release_resource_readback(&rb);
20702 ID3D11PixelShader_Release(ps);
20705 ID3D11VertexShader_Release(vs);
20706 ID3D11Buffer_Release(vb);
20707 ID3D11InputLayout_Release(input_layout);
20708 ID3D11Texture2D_Release(texture);
20709 ID3D11RenderTargetView_Release(rtv);
20710 release_test_context(&test_context);
20713 static void test_shader_input_registers_limits(void)
20715 struct d3d11_test_context test_context;
20716 D3D11_SUBRESOURCE_DATA resource_data;
20717 D3D11_TEXTURE2D_DESC texture_desc;
20718 D3D11_SAMPLER_DESC sampler_desc;
20719 ID3D11ShaderResourceView *srv;
20720 ID3D11DeviceContext *context;
20721 ID3D11SamplerState *sampler;
20722 ID3D11Texture2D *texture;
20723 ID3D11PixelShader *ps;
20724 ID3D11Device *device;
20725 HRESULT hr;
20727 static const DWORD ps_last_register_code[] =
20729 #if 0
20730 Texture2D t : register(t127);
20731 SamplerState s : register(s15);
20733 void main(out float4 target : SV_Target)
20735 target = t.Sample(s, float2(0, 0));
20737 #endif
20738 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
20739 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20740 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
20741 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
20742 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
20743 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
20744 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
20746 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
20747 static const DWORD texture_data[] = {0xff00ff00};
20749 if (!init_test_context(&test_context, NULL))
20750 return;
20752 device = test_context.device;
20753 context = test_context.immediate_context;
20755 texture_desc.Width = 1;
20756 texture_desc.Height = 1;
20757 texture_desc.MipLevels = 0;
20758 texture_desc.ArraySize = 1;
20759 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20760 texture_desc.SampleDesc.Count = 1;
20761 texture_desc.SampleDesc.Quality = 0;
20762 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20763 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20764 texture_desc.CPUAccessFlags = 0;
20765 texture_desc.MiscFlags = 0;
20767 resource_data.pSysMem = texture_data;
20768 resource_data.SysMemPitch = sizeof(texture_data);
20769 resource_data.SysMemSlicePitch = 0;
20771 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20772 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
20774 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
20775 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20777 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
20778 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
20779 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
20780 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
20781 sampler_desc.MipLODBias = 0.0f;
20782 sampler_desc.MaxAnisotropy = 0;
20783 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
20784 sampler_desc.BorderColor[0] = 0.0f;
20785 sampler_desc.BorderColor[1] = 0.0f;
20786 sampler_desc.BorderColor[2] = 0.0f;
20787 sampler_desc.BorderColor[3] = 0.0f;
20788 sampler_desc.MinLOD = 0.0f;
20789 sampler_desc.MaxLOD = 0.0f;
20791 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
20792 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
20794 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
20795 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20796 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20798 ID3D11DeviceContext_PSSetShaderResources(context,
20799 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
20800 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
20801 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
20802 draw_quad(&test_context);
20803 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
20805 ID3D11PixelShader_Release(ps);
20806 ID3D11SamplerState_Release(sampler);
20807 ID3D11ShaderResourceView_Release(srv);
20808 ID3D11Texture2D_Release(texture);
20809 release_test_context(&test_context);
20812 static void test_unbind_shader_resource_view(void)
20814 struct d3d11_test_context test_context;
20815 D3D11_SUBRESOURCE_DATA resource_data;
20816 ID3D11ShaderResourceView *srv, *srv2;
20817 D3D11_TEXTURE2D_DESC texture_desc;
20818 ID3D11DeviceContext *context;
20819 ID3D11Texture2D *texture;
20820 ID3D11PixelShader *ps;
20821 ID3D11Device *device;
20822 HRESULT hr;
20824 static const DWORD ps_code[] =
20826 #if 0
20827 Texture2D t0;
20828 Texture2D t1;
20829 SamplerState s;
20831 float4 main() : SV_Target
20833 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
20835 #endif
20836 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
20837 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20838 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
20839 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
20840 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
20841 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
20842 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
20843 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
20844 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
20845 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
20846 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
20847 0x3f800000, 0x0100003e,
20849 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
20850 static const DWORD texture_data[] = {0xff00ff00};
20852 if (!init_test_context(&test_context, NULL))
20853 return;
20855 device = test_context.device;
20856 context = test_context.immediate_context;
20858 texture_desc.Width = 1;
20859 texture_desc.Height = 1;
20860 texture_desc.MipLevels = 0;
20861 texture_desc.ArraySize = 1;
20862 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20863 texture_desc.SampleDesc.Count = 1;
20864 texture_desc.SampleDesc.Quality = 0;
20865 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20866 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20867 texture_desc.CPUAccessFlags = 0;
20868 texture_desc.MiscFlags = 0;
20870 resource_data.pSysMem = texture_data;
20871 resource_data.SysMemPitch = sizeof(texture_data);
20872 resource_data.SysMemSlicePitch = 0;
20874 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20875 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
20876 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
20877 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20878 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20879 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20880 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20882 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20883 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
20884 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
20885 draw_quad(&test_context);
20886 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
20888 srv2 = NULL;
20889 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
20890 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
20891 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
20892 draw_quad(&test_context);
20893 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
20895 ID3D11PixelShader_Release(ps);
20896 ID3D11ShaderResourceView_Release(srv);
20897 ID3D11Texture2D_Release(texture);
20898 release_test_context(&test_context);
20901 static void test_stencil_separate(void)
20903 struct d3d11_test_context test_context;
20904 D3D11_TEXTURE2D_DESC texture_desc;
20905 D3D11_DEPTH_STENCIL_DESC ds_desc;
20906 ID3D11DepthStencilState *ds_state;
20907 ID3D11DepthStencilView *ds_view;
20908 D3D11_RASTERIZER_DESC rs_desc;
20909 ID3D11DeviceContext *context;
20910 ID3D11RasterizerState *rs;
20911 ID3D11Texture2D *texture;
20912 ID3D11Device *device;
20913 HRESULT hr;
20915 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
20916 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
20917 static const struct vec3 ccw_quad[] =
20919 {-1.0f, -1.0f, 0.0f},
20920 { 1.0f, -1.0f, 0.0f},
20921 {-1.0f, 1.0f, 0.0f},
20922 { 1.0f, 1.0f, 0.0f},
20925 if (!init_test_context(&test_context, NULL))
20926 return;
20928 device = test_context.device;
20929 context = test_context.immediate_context;
20931 texture_desc.Width = 640;
20932 texture_desc.Height = 480;
20933 texture_desc.MipLevels = 1;
20934 texture_desc.ArraySize = 1;
20935 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
20936 texture_desc.SampleDesc.Count = 1;
20937 texture_desc.SampleDesc.Quality = 0;
20938 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20939 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
20940 texture_desc.CPUAccessFlags = 0;
20941 texture_desc.MiscFlags = 0;
20942 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
20943 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20944 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
20945 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
20947 ds_desc.DepthEnable = TRUE;
20948 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
20949 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
20950 ds_desc.StencilEnable = TRUE;
20951 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
20952 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
20953 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
20954 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
20955 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
20956 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
20957 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
20958 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
20959 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
20960 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
20961 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
20962 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
20964 rs_desc.FillMode = D3D11_FILL_SOLID;
20965 rs_desc.CullMode = D3D11_CULL_NONE;
20966 rs_desc.FrontCounterClockwise = FALSE;
20967 rs_desc.DepthBias = 0;
20968 rs_desc.DepthBiasClamp = 0.0f;
20969 rs_desc.SlopeScaledDepthBias = 0.0f;
20970 rs_desc.DepthClipEnable = TRUE;
20971 rs_desc.ScissorEnable = FALSE;
20972 rs_desc.MultisampleEnable = FALSE;
20973 rs_desc.AntialiasedLineEnable = FALSE;
20974 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
20975 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20977 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
20978 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
20979 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
20980 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
20981 ID3D11DeviceContext_RSSetState(context, rs);
20983 draw_color_quad(&test_context, &green);
20984 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
20986 ID3D11Buffer_Release(test_context.vb);
20987 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
20989 draw_color_quad(&test_context, &green);
20990 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
20992 ID3D11RasterizerState_Release(rs);
20993 rs_desc.FrontCounterClockwise = TRUE;
20994 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
20995 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20996 ID3D11DeviceContext_RSSetState(context, rs);
20998 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
20999 draw_color_quad(&test_context, &green);
21000 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
21002 ID3D11DepthStencilState_Release(ds_state);
21003 ID3D11DepthStencilView_Release(ds_view);
21004 ID3D11RasterizerState_Release(rs);
21005 ID3D11Texture2D_Release(texture);
21006 release_test_context(&test_context);
21009 static void test_uav_load(void)
21011 struct shader
21013 const DWORD *code;
21014 size_t size;
21016 struct texture
21018 UINT width;
21019 UINT height;
21020 UINT miplevel_count;
21021 UINT array_size;
21022 DXGI_FORMAT format;
21023 D3D11_SUBRESOURCE_DATA data[3];
21026 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
21027 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21028 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
21029 struct d3d11_test_context test_context;
21030 const struct texture *current_texture;
21031 ID3D11Texture2D *texture, *rt_texture;
21032 D3D11_TEXTURE2D_DESC texture_desc;
21033 const struct shader *current_ps;
21034 ID3D11UnorderedAccessView *uav;
21035 ID3D11DeviceContext *context;
21036 struct resource_readback rb;
21037 ID3D11PixelShader *ps;
21038 ID3D11Device *device;
21039 unsigned int i, x, y;
21040 ID3D11Buffer *cb;
21041 HRESULT hr;
21043 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
21044 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21045 static const DWORD ps_ld_2d_float_code[] =
21047 #if 0
21048 RWTexture2D<float> u;
21050 float main(float4 position : SV_Position) : SV_Target
21052 float2 s;
21053 u.GetDimensions(s.x, s.y);
21054 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21056 #endif
21057 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
21058 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21059 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21060 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21061 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21062 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
21063 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21064 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21065 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21066 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21067 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21068 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21069 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21071 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
21072 static const DWORD ps_ld_2d_uint_code[] =
21074 #if 0
21075 RWTexture2D<uint> u;
21077 uint main(float4 position : SV_Position) : SV_Target
21079 float2 s;
21080 u.GetDimensions(s.x, s.y);
21081 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21083 #endif
21084 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
21085 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21086 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21087 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
21088 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21089 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
21090 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21091 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21092 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21093 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21094 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21095 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21096 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21098 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
21099 static const DWORD ps_ld_2d_int_code[] =
21101 #if 0
21102 RWTexture2D<int> u;
21104 int main(float4 position : SV_Position) : SV_Target
21106 float2 s;
21107 u.GetDimensions(s.x, s.y);
21108 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21110 #endif
21111 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
21112 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21113 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21114 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
21115 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21116 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
21117 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21118 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21119 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21120 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21121 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21122 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21123 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21125 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
21126 static const DWORD ps_ld_2d_uint_arr_code[] =
21128 #if 0
21129 RWTexture2DArray<uint> u;
21131 uint layer;
21133 uint main(float4 position : SV_Position) : SV_Target
21135 float3 s;
21136 u.GetDimensions(s.x, s.y, s.z);
21137 s.z = layer;
21138 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
21140 #endif
21141 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
21142 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21143 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21144 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
21145 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
21146 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
21147 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
21148 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
21149 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
21150 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
21151 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
21152 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
21153 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
21154 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21156 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
21157 static const float float_data[] =
21159 0.50f, 0.25f, 1.00f, 0.00f,
21160 -1.00f, -2.00f, -3.00f, -4.00f,
21161 -0.50f, -0.25f, -1.00f, -0.00f,
21162 1.00f, 2.00f, 3.00f, 4.00f,
21164 static const unsigned int uint_data[] =
21166 0x00, 0x10, 0x20, 0x30,
21167 0x40, 0x50, 0x60, 0x70,
21168 0x80, 0x90, 0xa0, 0xb0,
21169 0xc0, 0xd0, 0xe0, 0xf0,
21171 static const unsigned int uint_data2[] =
21173 0xffff, 0xffff, 0xffff, 0xffff,
21174 0xffff, 0xc000, 0xc000, 0xffff,
21175 0xffff, 0xc000, 0xc000, 0xffff,
21176 0xffff, 0xffff, 0xffff, 0xffff,
21178 static const unsigned int uint_data3[] =
21180 0xaa, 0xaa, 0xcc, 0xcc,
21181 0xaa, 0xaa, 0xdd, 0xdd,
21182 0xbb, 0xbb, 0xee, 0xee,
21183 0xbb, 0xbb, 0xff, 0xff,
21185 static const int int_data[] =
21187 -1, 0x10, 0x20, 0x30,
21188 0x40, 0x50, 0x60, -777,
21189 -666, 0x90, -555, 0xb0,
21190 0xc0, 0xd0, 0xe0, -101,
21192 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
21193 {{float_data, 4 * sizeof(*float_data), 0}}};
21194 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
21195 {{uint_data, 4 * sizeof(*uint_data), 0}}};
21196 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
21197 {{uint_data, 4 * sizeof(*uint_data), 0},
21198 {uint_data2, 4 * sizeof(*uint_data2), 0},
21199 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
21200 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
21201 {{int_data, 4 * sizeof(*int_data), 0}}};
21203 static const struct test
21205 const struct shader *ps;
21206 const struct texture *texture;
21207 struct uav_desc uav_desc;
21208 struct uvec4 constant;
21209 const DWORD *expected_colors;
21211 tests[] =
21213 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
21214 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
21215 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
21216 #define R32_UINT DXGI_FORMAT_R32_UINT
21217 #define R32_SINT DXGI_FORMAT_R32_SINT
21218 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {0}, (const DWORD *)float_data},
21219 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {0}, (const DWORD *)uint_data},
21220 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {0}, (const DWORD *)int_data},
21221 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
21222 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
21223 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
21224 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
21225 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
21226 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
21227 #undef TEX_2D
21228 #undef TEX_2D_ARRAY
21229 #undef R32_FLOAT
21230 #undef R32_UINT
21231 #undef R32_SINT
21234 if (!init_test_context(&test_context, &feature_level))
21235 return;
21237 device = test_context.device;
21238 context = test_context.immediate_context;
21240 texture_desc.Width = 640;
21241 texture_desc.Height = 480;
21242 texture_desc.MipLevels = 1;
21243 texture_desc.ArraySize = 1;
21244 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
21245 texture_desc.SampleDesc.Count = 1;
21246 texture_desc.SampleDesc.Quality = 0;
21247 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21248 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21249 texture_desc.CPUAccessFlags = 0;
21250 texture_desc.MiscFlags = 0;
21251 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
21252 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21254 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
21255 U(rtv_desc).Texture2D.MipSlice = 0;
21257 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
21258 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
21259 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21261 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
21262 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
21263 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21265 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
21266 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
21267 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21269 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21271 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
21272 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21274 ps = NULL;
21275 uav = NULL;
21276 texture = NULL;
21277 current_ps = NULL;
21278 current_texture = NULL;
21279 for (i = 0; i < ARRAY_SIZE(tests); ++i)
21281 const struct test *test = &tests[i];
21282 ID3D11RenderTargetView *current_rtv;
21284 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21285 NULL, &test->constant, 0, 0);
21287 if (current_ps != test->ps)
21289 if (ps)
21290 ID3D11PixelShader_Release(ps);
21292 current_ps = test->ps;
21294 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
21295 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
21297 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21300 if (current_texture != test->texture)
21302 if (texture)
21303 ID3D11Texture2D_Release(texture);
21305 current_texture = test->texture;
21307 texture_desc.Width = current_texture->width;
21308 texture_desc.Height = current_texture->height;
21309 texture_desc.MipLevels = current_texture->miplevel_count;
21310 texture_desc.ArraySize = current_texture->array_size;
21311 texture_desc.Format = current_texture->format;
21313 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
21314 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
21317 if (uav)
21318 ID3D11UnorderedAccessView_Release(uav);
21320 get_uav_desc(&uav_desc, &test->uav_desc);
21321 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
21322 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
21324 switch (uav_desc.Format)
21326 case DXGI_FORMAT_R32_FLOAT:
21327 current_rtv = rtv_float;
21328 break;
21329 case DXGI_FORMAT_R32_UINT:
21330 current_rtv = rtv_uint;
21331 break;
21332 case DXGI_FORMAT_R32_SINT:
21333 current_rtv = rtv_sint;
21334 break;
21335 default:
21336 trace("Unhandled format %#x.\n", uav_desc.Format);
21337 current_rtv = NULL;
21338 break;
21341 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
21343 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
21344 1, 1, &uav, NULL);
21346 draw_quad(&test_context);
21348 get_texture_readback(rt_texture, 0, &rb);
21349 for (y = 0; y < 4; ++y)
21351 for (x = 0; x < 4; ++x)
21353 DWORD expected = test->expected_colors[y * 4 + x];
21354 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
21355 ok(compare_color(color, expected, 0),
21356 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
21357 i, color, expected, x, y);
21360 release_resource_readback(&rb);
21362 ID3D11PixelShader_Release(ps);
21363 ID3D11Texture2D_Release(texture);
21364 ID3D11UnorderedAccessView_Release(uav);
21366 ID3D11Buffer_Release(cb);
21367 ID3D11RenderTargetView_Release(rtv_float);
21368 ID3D11RenderTargetView_Release(rtv_sint);
21369 ID3D11RenderTargetView_Release(rtv_uint);
21370 ID3D11Texture2D_Release(rt_texture);
21371 release_test_context(&test_context);
21374 static void test_cs_uav_store(void)
21376 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21377 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21378 static const float zero[4] = {0.0f};
21379 D3D11_TEXTURE2D_DESC texture_desc;
21380 ID3D11UnorderedAccessView *uav;
21381 struct device_desc device_desc;
21382 ID3D11DeviceContext *context;
21383 struct vec4 input = {1.0f};
21384 ID3D11Texture2D *texture;
21385 ID3D11ComputeShader *cs;
21386 ID3D11Device *device;
21387 ID3D11Buffer *cb;
21388 ULONG refcount;
21389 HRESULT hr;
21390 RECT rect;
21392 static const DWORD cs_1_thread_code[] =
21394 #if 0
21395 RWTexture2D<float> u;
21397 float value;
21399 [numthreads(1, 1, 1)]
21400 void main()
21402 uint x, y, width, height;
21403 u.GetDimensions(width, height);
21404 for (y = 0; y < height; ++y)
21406 for (x = 0; x < width; ++x)
21407 u[uint2(x, y)] = value;
21410 #endif
21411 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
21412 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21413 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
21414 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21415 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
21416 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
21417 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
21418 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
21419 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
21420 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
21421 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
21422 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
21423 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
21424 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
21425 0x01000016, 0x0100003e,
21427 static const DWORD cs_1_group_code[] =
21429 #if 0
21430 RWTexture2D<float> u;
21432 float value;
21434 [numthreads(16, 16, 1)]
21435 void main(uint3 threadID : SV_GroupThreadID)
21437 uint2 count, size ;
21438 u.GetDimensions(size.x, size.y);
21439 count = size / (uint2)16;
21440 for (uint y = 0; y < count.y; ++y)
21441 for (uint x = 0; x < count.x; ++x)
21442 u[count * threadID.xy + uint2(x, y)] = value;
21444 #endif
21445 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
21446 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21447 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
21448 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21449 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
21450 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
21451 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
21452 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
21453 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
21454 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
21455 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
21456 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
21457 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
21458 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
21459 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
21460 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
21461 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
21463 static const DWORD cs_1_store_code[] =
21465 #if 0
21466 RWTexture2D<float> u;
21468 float value;
21470 [numthreads(1, 1, 1)]
21471 void main(uint3 groupID : SV_GroupID)
21473 u[groupID.xy] = value;
21475 #endif
21476 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
21477 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21478 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21479 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21480 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
21481 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
21483 static const DWORD cs_dispatch_id_code[] =
21485 #if 0
21486 RWTexture2D<float> u;
21488 float value;
21490 [numthreads(4, 4, 1)]
21491 void main(uint3 id : SV_DispatchThreadID)
21493 u[id.xy] = value;
21495 #endif
21496 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
21497 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21498 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21499 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21500 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
21501 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
21503 static const DWORD cs_group_index_code[] =
21505 #if 0
21506 RWTexture2D<float> u;
21508 float value;
21510 [numthreads(32, 1, 1)]
21511 void main(uint index : SV_GroupIndex)
21513 uint2 size;
21514 u.GetDimensions(size.x, size.y);
21515 uint count = size.x * size.y / 32;
21516 index *= count;
21517 for (uint i = 0; i < count; ++i, ++index)
21518 u[uint2(index % size.x, index / size.x)] = value;
21520 #endif
21521 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
21522 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21523 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
21524 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21525 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
21526 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
21527 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
21528 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
21529 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
21530 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
21531 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
21532 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
21533 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
21534 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
21535 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
21536 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
21539 device_desc.feature_level = &feature_level;
21540 device_desc.flags = 0;
21541 if (!(device = create_device(&device_desc)))
21543 skip("Failed to create device for feature level %#x.\n", feature_level);
21544 return;
21547 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
21549 texture_desc.Width = 64;
21550 texture_desc.Height = 64;
21551 texture_desc.MipLevels = 1;
21552 texture_desc.ArraySize = 1;
21553 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
21554 texture_desc.SampleDesc.Count = 1;
21555 texture_desc.SampleDesc.Quality = 0;
21556 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21557 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21558 texture_desc.CPUAccessFlags = 0;
21559 texture_desc.MiscFlags = 0;
21561 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21562 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21564 uav_desc.Format = texture_desc.Format;
21565 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
21566 U(uav_desc).Texture2D.MipSlice = 0;
21568 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
21569 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21571 ID3D11Device_GetImmediateContext(device, &context);
21573 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
21574 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21576 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
21577 check_texture_float(texture, 0.0f, 2);
21579 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
21580 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21581 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21583 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21584 check_texture_float(texture, 1.0f, 2);
21586 input.x = 0.5f;
21587 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21588 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21589 check_texture_float(texture, 0.5f, 2);
21591 ID3D11ComputeShader_Release(cs);
21593 input.x = 2.0f;
21594 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21595 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
21596 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21597 check_texture_float(texture, 0.5f, 2);
21599 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
21600 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21601 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21603 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21604 check_texture_float(texture, 2.0f, 2);
21606 input.x = 4.0f;
21607 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21608 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21609 check_texture_float(texture, 4.0f, 2);
21611 ID3D11ComputeShader_Release(cs);
21613 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
21614 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21615 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21617 input.x = 1.0f;
21618 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21619 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
21620 check_texture_float(texture, 1.0f, 2);
21622 input.x = 0.5f;
21623 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21624 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
21625 SetRect(&rect, 0, 0, 16, 32);
21626 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
21627 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
21628 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21629 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
21630 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21632 ID3D11ComputeShader_Release(cs);
21634 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
21635 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21636 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21638 input.x = 0.6f;
21639 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21640 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
21641 SetRect(&rect, 0, 0, 60, 60);
21642 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
21643 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
21644 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21645 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
21646 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21648 input.x = 0.7f;
21649 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21650 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
21651 check_texture_float(texture, 0.7f, 2);
21653 ID3D11ComputeShader_Release(cs);
21655 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
21656 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21657 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21659 input.x = 0.3f;
21660 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21661 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21662 check_texture_float(texture, 0.3f, 2);
21664 input.x = 0.1f;
21665 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21666 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
21667 check_texture_float(texture, 0.1f, 2);
21669 ID3D11ComputeShader_Release(cs);
21671 ID3D11Buffer_Release(cb);
21672 ID3D11Texture2D_Release(texture);
21673 ID3D11UnorderedAccessView_Release(uav);
21674 ID3D11DeviceContext_Release(context);
21675 refcount = ID3D11Device_Release(device);
21676 ok(!refcount, "Device has %u references left.\n", refcount);
21679 static void test_uav_store_immediate_constant(void)
21681 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21682 struct d3d11_test_context test_context;
21683 D3D11_TEXTURE2D_DESC texture_desc;
21684 ID3D11UnorderedAccessView *uav;
21685 ID3D11DeviceContext *context;
21686 struct resource_readback rb;
21687 ID3D11Texture2D *texture;
21688 ID3D11ComputeShader *cs;
21689 unsigned int uint_data;
21690 ID3D11Device *device;
21691 ID3D11Buffer *buffer;
21692 float float_data;
21693 int int_data;
21694 HRESULT hr;
21696 static const DWORD cs_store_int_code[] =
21698 #if 0
21699 RWBuffer<int> u;
21701 [numthreads(1, 1, 1)]
21702 void main()
21704 u[0] = 42;
21706 #endif
21707 0x43425844, 0x7246d785, 0x3f4ccbd6, 0x6a7cdbc0, 0xe2b58c72, 0x00000001, 0x000000b8, 0x00000003,
21708 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21709 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21710 0x0400089c, 0x0011e000, 0x00000000, 0x00003333, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
21711 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21712 0x00004002, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, 0x0100003e,
21714 static const DWORD cs_store_float_code[] =
21716 #if 0
21717 RWBuffer<float> u;
21719 [numthreads(1, 1, 1)]
21720 void main()
21722 u[0] = 1.0;
21724 #endif
21725 0x43425844, 0x525eea68, 0xc4cd5716, 0xc588f9c4, 0x0da27c5a, 0x00000001, 0x000000b8, 0x00000003,
21726 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21727 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21728 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
21729 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21730 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
21732 static const DWORD cs_store_unorm_code[] =
21734 #if 0
21735 RWTexture2D<unorm float> u;
21737 [numthreads(1, 1, 1)]
21738 void main()
21740 u[uint2(0, 0)] = 0.5f;
21742 #endif
21743 0x43425844, 0x3623f1de, 0xe847109e, 0x8e3da13f, 0xb6787b06, 0x00000001, 0x000000b8, 0x00000003,
21744 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21745 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21746 0x0400189c, 0x0011e000, 0x00000000, 0x00001111, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
21747 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21748 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
21750 static const DWORD cs_store_snorm_code[] =
21752 #if 0
21753 RWTexture2D<snorm float> u;
21755 [numthreads(1, 1, 1)]
21756 void main()
21758 u[uint2(0, 0)] = -0.5f;
21760 #endif
21761 0x43425844, 0xce5397fc, 0x7464bc06, 0xc79aa56c, 0x881bd7ef, 0x00000001, 0x000000b8, 0x00000003,
21762 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21763 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21764 0x0400189c, 0x0011e000, 0x00000000, 0x00002222, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
21765 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21766 0x00004002, 0xbf000000, 0xbf000000, 0xbf000000, 0xbf000000, 0x0100003e,
21768 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21769 static const unsigned int zero[4] = {0};
21771 if (!init_test_context(&test_context, &feature_level))
21772 return;
21774 device = test_context.device;
21775 context = test_context.immediate_context;
21777 buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
21779 uav_desc.Format = DXGI_FORMAT_R32_SINT;
21780 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
21781 U(uav_desc).Buffer.FirstElement = 0;
21782 U(uav_desc).Buffer.NumElements = 1;
21783 U(uav_desc).Buffer.Flags = 0;
21784 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
21785 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21786 hr = ID3D11Device_CreateComputeShader(device, cs_store_int_code, sizeof(cs_store_int_code), NULL, &cs);
21787 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21789 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
21790 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21791 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21792 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21793 get_buffer_readback(buffer, &rb);
21794 int_data = get_readback_color(&rb, 0, 0, 0);
21795 ok(int_data == 42, "Got unexpected value %u.\n", int_data);
21796 release_resource_readback(&rb);
21798 ID3D11ComputeShader_Release(cs);
21799 ID3D11UnorderedAccessView_Release(uav);
21800 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
21801 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
21802 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21803 hr = ID3D11Device_CreateComputeShader(device, cs_store_float_code, sizeof(cs_store_float_code), NULL, &cs);
21804 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21806 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
21807 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21808 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21809 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21810 get_buffer_readback(buffer, &rb);
21811 float_data = get_readback_float(&rb, 0, 0);
21812 ok(float_data == 1.0f, "Got unexpected value %.8e.\n", float_data);
21813 release_resource_readback(&rb);
21815 texture_desc.Width = 64;
21816 texture_desc.Height = 64;
21817 texture_desc.MipLevels = 1;
21818 texture_desc.ArraySize = 1;
21819 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
21820 texture_desc.SampleDesc.Count = 1;
21821 texture_desc.SampleDesc.Quality = 0;
21822 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21823 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21824 texture_desc.CPUAccessFlags = 0;
21825 texture_desc.MiscFlags = 0;
21826 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21827 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
21828 ID3D11UnorderedAccessView_Release(uav);
21829 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
21830 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
21832 ID3D11ComputeShader_Release(cs);
21833 hr = ID3D11Device_CreateComputeShader(device, cs_store_unorm_code, sizeof(cs_store_unorm_code), NULL, &cs);
21834 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
21835 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
21836 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21837 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21838 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21839 get_texture_readback(texture, 0, &rb);
21840 uint_data = get_readback_color(&rb, 0, 0, 0);
21841 ok(compare_color(uint_data, 0x80808080, 1), "Got unexpected color 0x%08x.\n", uint_data);
21842 release_resource_readback(&rb);
21844 ID3D11Texture2D_Release(texture);
21845 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_SNORM;
21846 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21847 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
21848 ID3D11UnorderedAccessView_Release(uav);
21849 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
21850 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
21852 ID3D11ComputeShader_Release(cs);
21853 hr = ID3D11Device_CreateComputeShader(device, cs_store_snorm_code, sizeof(cs_store_snorm_code), NULL, &cs);
21854 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
21855 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
21856 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21857 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21858 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21859 get_texture_readback(texture, 0, &rb);
21860 uint_data = get_readback_color(&rb, 0, 0, 0);
21861 ok(compare_color(uint_data, 0xc0c0c0c0, 1), "Got unexpected color 0x%08x.\n", uint_data);
21862 release_resource_readback(&rb);
21864 ID3D11Buffer_Release(buffer);
21865 ID3D11Texture2D_Release(texture);
21866 ID3D11ComputeShader_Release(cs);
21867 ID3D11UnorderedAccessView_Release(uav);
21868 release_test_context(&test_context);
21871 static void test_ps_cs_uav_binding(void)
21873 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21874 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
21875 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21876 ID3D11Texture2D *cs_texture, *ps_texture;
21877 struct d3d11_test_context test_context;
21878 static const float zero[4] = {0.0f};
21879 D3D11_TEXTURE2D_DESC texture_desc;
21880 ID3D11DeviceContext *context;
21881 ID3D11Buffer *cs_cb, *ps_cb;
21882 struct vec4 input = {1.0f};
21883 ID3D11ComputeShader *cs;
21884 ID3D11PixelShader *ps;
21885 ID3D11Device *device;
21886 HRESULT hr;
21888 static const DWORD cs_code[] =
21890 #if 0
21891 RWTexture2D<float> u;
21893 float value;
21895 [numthreads(1, 1, 1)]
21896 void main()
21898 uint x, y, width, height;
21899 u.GetDimensions(width, height);
21900 for (y = 0; y < height; ++y)
21902 for (x = 0; x < width; ++x)
21903 u[uint2(x, y)] = value;
21906 #endif
21907 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
21908 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21909 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
21910 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21911 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
21912 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
21913 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
21914 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
21915 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
21916 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
21917 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
21918 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
21919 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
21920 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
21921 0x01000016, 0x0100003e,
21923 static const DWORD ps_code[] =
21925 #if 0
21926 RWTexture2D<float> u : register(u1);
21928 float value;
21930 void main()
21932 uint x, y, width, height;
21933 u.GetDimensions(width, height);
21934 for (y = 0; y < height; ++y)
21936 for (x = 0; x < width; ++x)
21937 u[uint2(x, y)] = value;
21940 #endif
21941 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
21942 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21943 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
21944 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
21945 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
21946 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
21947 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
21948 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
21949 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
21950 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
21951 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
21952 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
21953 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
21954 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
21957 if (!init_test_context(&test_context, &feature_level))
21958 return;
21960 device = test_context.device;
21961 context = test_context.immediate_context;
21963 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
21964 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
21966 texture_desc.Width = 64;
21967 texture_desc.Height = 64;
21968 texture_desc.MipLevels = 1;
21969 texture_desc.ArraySize = 1;
21970 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
21971 texture_desc.SampleDesc.Count = 1;
21972 texture_desc.SampleDesc.Quality = 0;
21973 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21974 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21975 texture_desc.CPUAccessFlags = 0;
21976 texture_desc.MiscFlags = 0;
21977 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
21978 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21979 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
21980 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21982 uav_desc.Format = texture_desc.Format;
21983 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
21984 U(uav_desc).Texture2D.MipSlice = 0;
21985 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
21986 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21987 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
21988 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21990 ID3D11Device_GetImmediateContext(device, &context);
21992 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
21993 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
21994 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
21995 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
21996 0, NULL, NULL, 1, 1, &ps_uav, NULL);
21998 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
21999 check_texture_float(cs_texture, 0.0f, 2);
22000 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
22001 check_texture_float(ps_texture, 0.0f, 2);
22003 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
22004 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22005 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22006 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22007 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22008 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22010 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22011 check_texture_float(cs_texture, 1.0f, 2);
22012 check_texture_float(ps_texture, 0.0f, 2);
22013 draw_quad(&test_context);
22014 check_texture_float(cs_texture, 1.0f, 2);
22015 check_texture_float(ps_texture, 1.0f, 2);
22017 input.x = 0.5f;
22018 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
22019 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22020 check_texture_float(cs_texture, 0.5f, 2);
22021 check_texture_float(ps_texture, 1.0f, 2);
22022 input.x = 2.0f;
22023 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
22024 draw_quad(&test_context);
22025 check_texture_float(cs_texture, 0.5f, 2);
22026 check_texture_float(ps_texture, 2.0f, 2);
22028 input.x = 8.0f;
22029 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
22030 input.x = 4.0f;
22031 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
22032 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22033 check_texture_float(cs_texture, 8.0f, 2);
22034 check_texture_float(ps_texture, 2.0f, 2);
22035 draw_quad(&test_context);
22036 check_texture_float(cs_texture, 8.0f, 2);
22037 check_texture_float(ps_texture, 4.0f, 2);
22039 ID3D11ComputeShader_Release(cs);
22040 ID3D11PixelShader_Release(ps);
22041 ID3D11Buffer_Release(cs_cb);
22042 ID3D11Buffer_Release(ps_cb);
22043 ID3D11Texture2D_Release(cs_texture);
22044 ID3D11Texture2D_Release(ps_texture);
22045 ID3D11UnorderedAccessView_Release(cs_uav);
22046 ID3D11UnorderedAccessView_Release(ps_uav);
22047 ID3D11DeviceContext_Release(context);
22048 release_test_context(&test_context);
22051 static void test_atomic_instructions(void)
22053 ID3D11UnorderedAccessView *in_uav, *out_uav;
22054 ID3D11Buffer *cb, *in_buffer, *out_buffer;
22055 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22056 struct d3d11_test_context test_context;
22057 struct resource_readback rb, out_rb;
22058 D3D11_BUFFER_DESC buffer_desc;
22059 ID3D11DeviceContext *context;
22060 ID3D11ComputeShader *cs;
22061 ID3D11PixelShader *ps;
22062 ID3D11Device *device;
22063 unsigned int i, j;
22064 HRESULT hr;
22066 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22067 static const unsigned int zero[4] = {0, 0, 0, 0};
22068 static const DWORD ps_atomics_code[] =
22070 #if 0
22071 RWByteAddressBuffer u;
22073 uint4 v;
22074 int4 i;
22076 void main()
22078 u.InterlockedAnd(0 * 4, v.x);
22079 u.InterlockedCompareStore(1 * 4, v.y, v.x);
22080 u.InterlockedAdd(2 * 4, v.x);
22081 u.InterlockedOr(3 * 4, v.x);
22082 u.InterlockedMax(4 * 4, i.x);
22083 u.InterlockedMin(5 * 4, i.x);
22084 u.InterlockedMax(6 * 4, v.x);
22085 u.InterlockedMin(7 * 4, v.x);
22086 u.InterlockedXor(8 * 4, v.x);
22088 #endif
22089 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
22090 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22091 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
22092 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
22093 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
22094 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
22095 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
22096 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
22097 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
22098 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
22099 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
22100 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
22101 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
22102 0x00000000, 0x00000000, 0x0100003e,
22104 static const DWORD cs_atomics_code[] =
22106 #if 0
22107 RWByteAddressBuffer u;
22108 RWByteAddressBuffer u2;
22110 uint4 v;
22111 int4 i;
22113 [numthreads(1, 1, 1)]
22114 void main()
22116 uint r;
22117 u.InterlockedAnd(0 * 4, v.x, r);
22118 u2.Store(0 * 4, r);
22119 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
22120 u2.Store(1 * 4, r);
22121 u.InterlockedAdd(2 * 4, v.x, r);
22122 u2.Store(2 * 4, r);
22123 u.InterlockedOr(3 * 4, v.x, r);
22124 u2.Store(3 * 4, r);
22125 u.InterlockedMax(4 * 4, i.x, r);
22126 u2.Store(4 * 4, r);
22127 u.InterlockedMin(5 * 4, i.x, r);
22128 u2.Store(5 * 4, r);
22129 u.InterlockedMax(6 * 4, v.x, r);
22130 u2.Store(6 * 4, r);
22131 u.InterlockedMin(7 * 4, v.x, r);
22132 u2.Store(7 * 4, r);
22133 u.InterlockedXor(8 * 4, v.x, r);
22134 u2.Store(8 * 4, r);
22136 #endif
22137 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
22138 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22139 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
22140 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
22141 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22142 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
22143 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
22144 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
22145 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
22146 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
22147 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
22148 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
22149 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
22150 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
22151 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
22152 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
22153 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
22154 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
22155 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
22156 0x0010000a, 0x00000000, 0x0100003e,
22159 static const char * const instructions[] =
22161 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
22162 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
22164 static const char * const imm_instructions[] =
22166 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
22167 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
22169 static const struct test
22171 struct uvec4 v;
22172 struct ivec4 i;
22173 unsigned int input[ARRAY_SIZE(instructions)];
22174 unsigned int expected_result[ARRAY_SIZE(instructions)];
22176 tests[] =
22178 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
22179 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
22182 if (!init_test_context(&test_context, &feature_level))
22183 return;
22185 device = test_context.device;
22186 context = test_context.immediate_context;
22188 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
22189 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22190 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
22192 buffer_desc.ByteWidth = sizeof(tests->input);
22193 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
22194 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22195 buffer_desc.CPUAccessFlags = 0;
22196 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
22197 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
22198 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22199 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
22200 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22202 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
22203 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
22204 U(uav_desc).Buffer.FirstElement = 0;
22205 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
22206 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
22207 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
22208 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22209 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
22210 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22212 set_viewport(context, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f);
22214 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
22215 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22216 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22218 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
22219 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22220 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22222 for (i = 0; i < ARRAY_SIZE(tests); ++i)
22224 const struct test *test = &tests[i];
22226 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22227 NULL, &test->v, 0, 0);
22229 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
22230 NULL, test->input, 0, 0);
22232 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
22233 0, 1, &in_uav, NULL);
22235 draw_quad(&test_context);
22236 get_buffer_readback(in_buffer, &rb);
22237 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
22239 unsigned int value = get_readback_color(&rb, j, 0, 0);
22240 unsigned int expected = test->expected_result[j];
22242 todo_wine_if(expected != test->input[j]
22243 && (!strcmp(instructions[j], "atomic_imax")
22244 || !strcmp(instructions[j], "atomic_imin")))
22245 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
22246 "with inputs (%u, %u), (%d), %#x (%d).\n",
22247 i, value, value, expected, expected, instructions[j],
22248 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
22250 release_resource_readback(&rb);
22252 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
22253 NULL, test->input, 0, 0);
22254 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
22256 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
22257 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
22259 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22260 get_buffer_readback(in_buffer, &rb);
22261 get_buffer_readback(out_buffer, &out_rb);
22262 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
22264 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
22265 || !strcmp(imm_instructions[j], "imm_atomic_imin");
22266 unsigned int out_value = get_readback_color(&out_rb, j, 0, 0);
22267 unsigned int value = get_readback_color(&rb, j, 0, 0);
22268 unsigned int expected = test->expected_result[j];
22270 todo_wine_if(expected != test->input[j] && todo_instruction)
22271 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
22272 "with inputs (%u, %u), (%d), %#x (%d).\n",
22273 i, value, value, expected, expected, imm_instructions[j],
22274 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
22276 todo_wine_if(todo_instruction && out_value != test->input[j])
22277 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
22278 out_value, test->input[j], imm_instructions[j]);
22280 release_resource_readback(&out_rb);
22281 release_resource_readback(&rb);
22284 ID3D11Buffer_Release(cb);
22285 ID3D11Buffer_Release(in_buffer);
22286 ID3D11Buffer_Release(out_buffer);
22287 ID3D11ComputeShader_Release(cs);
22288 ID3D11PixelShader_Release(ps);
22289 ID3D11UnorderedAccessView_Release(in_uav);
22290 ID3D11UnorderedAccessView_Release(out_uav);
22291 release_test_context(&test_context);
22294 static void test_sm4_ret_instruction(void)
22296 struct d3d11_test_context test_context;
22297 ID3D11DeviceContext *context;
22298 ID3D11PixelShader *ps;
22299 struct uvec4 constant;
22300 ID3D11Device *device;
22301 ID3D11Buffer *cb;
22302 HRESULT hr;
22304 static const DWORD ps_code[] =
22306 #if 0
22307 uint c;
22309 float4 main() : SV_TARGET
22311 if (c == 1)
22312 return float4(1, 0, 0, 1);
22313 if (c == 2)
22314 return float4(0, 1, 0, 1);
22315 if (c == 3)
22316 return float4(0, 0, 1, 1);
22317 return float4(1, 1, 1, 1);
22319 #endif
22320 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
22321 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22322 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22323 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
22324 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
22325 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
22326 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
22327 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
22328 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
22329 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
22330 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
22331 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
22332 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
22333 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
22334 0x0100003e,
22337 if (!init_test_context(&test_context, NULL))
22338 return;
22340 device = test_context.device;
22341 context = test_context.immediate_context;
22343 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22344 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
22345 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22346 memset(&constant, 0, sizeof(constant));
22347 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
22348 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22350 draw_quad(&test_context);
22351 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22353 constant.x = 1;
22354 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22355 draw_quad(&test_context);
22356 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
22358 constant.x = 2;
22359 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22360 draw_quad(&test_context);
22361 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
22363 constant.x = 3;
22364 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22365 draw_quad(&test_context);
22366 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
22368 constant.x = 4;
22369 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22370 draw_quad(&test_context);
22371 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22373 ID3D11Buffer_Release(cb);
22374 ID3D11PixelShader_Release(ps);
22375 release_test_context(&test_context);
22378 static void test_primitive_restart(void)
22380 struct d3d11_test_context test_context;
22381 ID3D11Buffer *ib32, *ib16, *vb;
22382 ID3D11DeviceContext *context;
22383 unsigned int stride, offset;
22384 ID3D11InputLayout *layout;
22385 ID3D11VertexShader *vs;
22386 ID3D11PixelShader *ps;
22387 ID3D11Device *device;
22388 unsigned int i;
22389 HRESULT hr;
22390 RECT rect;
22392 static const DWORD ps_code[] =
22394 #if 0
22395 struct vs_out
22397 float4 position : SV_Position;
22398 float4 color : color;
22401 float4 main(vs_out input) : SV_TARGET
22403 return input.color;
22405 #endif
22406 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
22407 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22408 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
22409 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
22410 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
22411 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
22412 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
22413 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
22415 static const DWORD vs_code[] =
22417 #if 0
22418 struct vs_out
22420 float4 position : SV_Position;
22421 float4 color : color;
22424 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
22426 output.position = position;
22427 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
22429 #endif
22430 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
22431 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
22432 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
22433 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
22434 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
22435 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
22436 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
22437 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
22438 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
22439 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
22440 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
22441 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
22442 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
22444 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
22446 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
22448 static const struct vec2 vertices[] =
22450 {-1.00f, -1.0f},
22451 {-1.00f, 1.0f},
22452 {-0.25f, -1.0f},
22453 {-0.25f, 1.0f},
22454 { 0.25f, -1.0f},
22455 { 0.25f, 1.0f},
22456 { 1.00f, -1.0f},
22457 { 1.00f, 1.0f},
22459 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
22460 static const unsigned short indices16[] =
22462 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
22464 static const unsigned int indices32[] =
22466 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
22469 if (!init_test_context(&test_context, NULL))
22470 return;
22472 device = test_context.device;
22473 context = test_context.immediate_context;
22475 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
22476 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
22477 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22478 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
22480 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
22481 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
22483 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
22484 vs_code, sizeof(vs_code), &layout);
22485 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
22487 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
22489 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
22490 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22492 ID3D11DeviceContext_IASetInputLayout(context, layout);
22493 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
22494 stride = sizeof(*vertices);
22495 offset = 0;
22496 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
22498 for (i = 0; i < 2; ++i)
22500 if (!i)
22501 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
22502 else
22503 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
22505 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
22506 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
22507 SetRect(&rect, 0, 0, 240, 480);
22508 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
22509 SetRect(&rect, 240, 0, 400, 480);
22510 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
22511 SetRect(&rect, 400, 0, 640, 480);
22512 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
22515 ID3D11Buffer_Release(ib16);
22516 ID3D11Buffer_Release(ib32);
22517 ID3D11Buffer_Release(vb);
22518 ID3D11InputLayout_Release(layout);
22519 ID3D11PixelShader_Release(ps);
22520 ID3D11VertexShader_Release(vs);
22521 release_test_context(&test_context);
22524 static void test_resinfo_instruction(void)
22526 struct shader
22528 const DWORD *code;
22529 size_t size;
22532 struct d3d11_test_context test_context;
22533 D3D11_TEXTURE3D_DESC texture3d_desc;
22534 D3D11_TEXTURE2D_DESC texture_desc;
22535 const struct shader *current_ps;
22536 D3D_FEATURE_LEVEL feature_level;
22537 ID3D11ShaderResourceView *srv;
22538 ID3D11DeviceContext *context;
22539 ID3D11Texture2D *rtv_texture;
22540 ID3D11RenderTargetView *rtv;
22541 ID3D11Resource *texture;
22542 struct uvec4 constant;
22543 ID3D11PixelShader *ps;
22544 ID3D11Device *device;
22545 unsigned int i, type;
22546 ID3D11Buffer *cb;
22547 HRESULT hr;
22549 static const DWORD ps_2d_code[] =
22551 #if 0
22552 Texture2D t;
22554 uint type;
22555 uint level;
22557 float4 main() : SV_TARGET
22559 if (!type)
22561 float width, height, miplevels;
22562 t.GetDimensions(level, width, height, miplevels);
22563 return float4(width, height, miplevels, 0);
22565 else
22567 uint width, height, miplevels;
22568 t.GetDimensions(level, width, height, miplevels);
22569 return float4(width, height, miplevels, 0);
22572 #endif
22573 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
22574 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22575 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22576 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
22577 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
22578 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22579 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22580 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
22581 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
22582 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
22583 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
22584 0x01000015, 0x0100003e,
22586 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
22587 static const DWORD ps_2d_array_code[] =
22589 #if 0
22590 Texture2DArray t;
22592 uint type;
22593 uint level;
22595 float4 main() : SV_TARGET
22597 if (!type)
22599 float width, height, elements, miplevels;
22600 t.GetDimensions(level, width, height, elements, miplevels);
22601 return float4(width, height, elements, miplevels);
22603 else
22605 uint width, height, elements, miplevels;
22606 t.GetDimensions(level, width, height, elements, miplevels);
22607 return float4(width, height, elements, miplevels);
22610 #endif
22611 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
22612 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22613 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22614 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
22615 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
22616 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22617 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22618 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
22619 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
22620 0x0100003e, 0x01000015, 0x0100003e,
22622 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
22623 static const DWORD ps_3d_code[] =
22625 #if 0
22626 Texture3D t;
22628 uint type;
22629 uint level;
22631 float4 main() : SV_TARGET
22633 if (!type)
22635 float width, height, depth, miplevels;
22636 t.GetDimensions(level, width, height, depth, miplevels);
22637 return float4(width, height, depth, miplevels);
22639 else
22641 uint width, height, depth, miplevels;
22642 t.GetDimensions(level, width, height, depth, miplevels);
22643 return float4(width, height, depth, miplevels);
22646 #endif
22647 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
22648 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22649 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22650 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
22651 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
22652 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22653 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22654 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
22655 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
22656 0x0100003e, 0x01000015, 0x0100003e,
22658 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
22659 static const DWORD ps_cube_code[] =
22661 #if 0
22662 TextureCube t;
22664 uint type;
22665 uint level;
22667 float4 main() : SV_TARGET
22669 if (!type)
22671 float width, height, miplevels;
22672 t.GetDimensions(level, width, height, miplevels);
22673 return float4(width, height, miplevels, 0);
22675 else
22677 uint width, height, miplevels;
22678 t.GetDimensions(level, width, height, miplevels);
22679 return float4(width, height, miplevels, 0);
22682 #endif
22683 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
22684 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22685 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22686 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
22687 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
22688 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22689 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22690 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
22691 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
22692 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
22693 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
22694 0x01000015, 0x0100003e,
22696 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
22697 static const DWORD ps_cube_array_code[] =
22699 #if 0
22700 TextureCubeArray t;
22702 uint type;
22703 uint level;
22705 float4 main() : SV_TARGET
22707 if (!type)
22709 float width, height, elements, miplevels;
22710 t.GetDimensions(level, width, height, elements, miplevels);
22711 return float4(width, height, miplevels, 0);
22713 else
22715 uint width, height, elements, miplevels;
22716 t.GetDimensions(level, width, height, elements, miplevels);
22717 return float4(width, height, miplevels, 0);
22720 #endif
22721 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
22722 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22723 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22724 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
22725 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
22726 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
22727 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
22728 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
22729 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
22730 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
22731 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
22732 0x0100003e, 0x01000015, 0x0100003e,
22734 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
22735 static const struct ps_test
22737 const struct shader *ps;
22738 struct
22740 unsigned int width;
22741 unsigned int height;
22742 unsigned int depth;
22743 unsigned int miplevel_count;
22744 unsigned int array_size;
22745 unsigned int cube_count;
22746 } texture_desc;
22747 unsigned int miplevel;
22748 struct vec4 expected_result;
22750 ps_tests[] =
22752 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
22753 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
22754 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
22755 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
22757 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
22758 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
22759 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
22760 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
22762 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
22763 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
22764 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
22765 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
22766 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
22767 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
22768 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
22769 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
22770 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
22772 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
22773 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
22774 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
22775 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
22776 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
22778 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
22779 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
22780 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
22783 if (!init_test_context(&test_context, NULL))
22784 return;
22786 device = test_context.device;
22787 context = test_context.immediate_context;
22788 feature_level = ID3D11Device_GetFeatureLevel(device);
22790 texture_desc.Width = 64;
22791 texture_desc.Height = 64;
22792 texture_desc.MipLevels = 1;
22793 texture_desc.ArraySize = 1;
22794 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
22795 texture_desc.SampleDesc.Count = 1;
22796 texture_desc.SampleDesc.Quality = 0;
22797 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22798 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
22799 texture_desc.CPUAccessFlags = 0;
22800 texture_desc.MiscFlags = 0;
22801 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
22802 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22803 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
22804 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
22806 memset(&constant, 0, sizeof(constant));
22807 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
22809 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
22810 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22812 ps = NULL;
22813 current_ps = NULL;
22814 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
22816 const struct ps_test *test = &ps_tests[i];
22818 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
22820 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
22821 continue;
22824 if (current_ps != test->ps)
22826 if (ps)
22827 ID3D11PixelShader_Release(ps);
22829 current_ps = test->ps;
22831 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
22832 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
22833 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22836 if (test->texture_desc.depth != 1)
22838 texture3d_desc.Width = test->texture_desc.width;
22839 texture3d_desc.Height = test->texture_desc.height;
22840 texture3d_desc.Depth = test->texture_desc.depth;
22841 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
22842 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
22843 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
22844 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22845 texture3d_desc.CPUAccessFlags = 0;
22846 texture3d_desc.MiscFlags = 0;
22847 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
22848 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
22850 else
22852 texture_desc.Width = test->texture_desc.width;
22853 texture_desc.Height = test->texture_desc.height;
22854 texture_desc.MipLevels = test->texture_desc.miplevel_count;
22855 texture_desc.ArraySize = test->texture_desc.array_size;
22856 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
22857 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22858 texture_desc.MiscFlags = 0;
22859 if (test->texture_desc.cube_count)
22860 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
22861 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
22862 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
22865 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
22866 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
22867 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
22869 for (type = 0; type < 2; ++type)
22871 constant.x = type;
22872 constant.y = test->miplevel;
22873 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22875 draw_quad(&test_context);
22876 check_texture_vec4(rtv_texture, &test->expected_result, 0);
22879 ID3D11Resource_Release(texture);
22880 ID3D11ShaderResourceView_Release(srv);
22882 ID3D11PixelShader_Release(ps);
22884 ID3D11Buffer_Release(cb);
22885 ID3D11RenderTargetView_Release(rtv);
22886 ID3D11Texture2D_Release(rtv_texture);
22887 release_test_context(&test_context);
22890 static void test_sm5_bufinfo_instruction(void)
22892 struct shader
22894 const DWORD *code;
22895 size_t size;
22898 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22899 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
22900 struct d3d11_test_context test_context;
22901 D3D11_TEXTURE2D_DESC texture_desc;
22902 const struct shader *current_ps;
22903 ID3D11UnorderedAccessView *uav;
22904 ID3D11ShaderResourceView *srv;
22905 D3D11_BUFFER_DESC buffer_desc;
22906 ID3D11DeviceContext *context;
22907 ID3D11RenderTargetView *rtv;
22908 ID3D11Texture2D *texture;
22909 ID3D11PixelShader *ps;
22910 ID3D11Buffer *buffer;
22911 ID3D11Device *device;
22912 unsigned int i;
22913 HRESULT hr;
22915 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22916 static const DWORD ps_uav_structured_code[] =
22918 #if 0
22919 struct s
22921 uint4 u;
22922 bool b;
22925 RWStructuredBuffer<s> b;
22927 uint4 main(void) : SV_Target
22929 uint count, stride;
22930 b.GetDimensions(count, stride);
22931 return uint4(count, stride, 0, 1);
22933 #endif
22934 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
22935 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22936 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
22937 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
22938 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
22939 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
22940 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
22941 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
22943 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
22944 static const DWORD ps_uav_structured32_code[] =
22946 #if 0
22947 struct s
22949 uint4 u;
22950 bool4 b;
22953 RWStructuredBuffer<s> b;
22955 uint4 main(void) : SV_Target
22957 uint count, stride;
22958 b.GetDimensions(count, stride);
22959 return uint4(count, stride, 0, 1);
22961 #endif
22962 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
22963 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22964 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
22965 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
22966 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
22967 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
22968 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
22969 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
22971 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
22972 static const DWORD ps_srv_structured_code[] =
22974 #if 0
22975 StructuredBuffer<bool> b;
22977 uint4 main(void) : SV_Target
22979 uint count, stride;
22980 b.GetDimensions(count, stride);
22981 return uint4(count, stride, 0, 1);
22983 #endif
22984 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
22985 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22986 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
22987 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
22988 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
22989 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
22990 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
22991 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
22993 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
22994 static const DWORD ps_uav_raw_code[] =
22996 #if 0
22997 RWByteAddressBuffer b;
22999 uint4 main(void) : SV_Target
23001 uint width;
23002 b.GetDimensions(width);
23003 return width;
23005 #endif
23006 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
23007 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23008 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23009 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
23010 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
23011 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
23012 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23014 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
23015 static const DWORD ps_srv_raw_code[] =
23017 #if 0
23018 ByteAddressBuffer b;
23020 uint4 main(void) : SV_Target
23022 uint width;
23023 b.GetDimensions(width);
23024 return width;
23026 #endif
23027 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
23028 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23029 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23030 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
23031 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
23032 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
23033 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23035 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
23036 static const DWORD ps_uav_typed_code[] =
23038 #if 0
23039 RWBuffer<float> b;
23041 uint4 main(void) : SV_Target
23043 uint width;
23044 b.GetDimensions(width);
23045 return width;
23047 #endif
23048 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
23049 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23050 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23051 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
23052 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23053 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
23054 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23056 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
23057 static const DWORD ps_srv_typed_code[] =
23059 #if 0
23060 Buffer<float> b;
23062 uint4 main(void) : SV_Target
23064 uint width;
23065 b.GetDimensions(width);
23066 return width;
23068 #endif
23069 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
23070 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23071 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23072 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
23073 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23074 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
23075 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23077 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
23078 static const struct test
23080 const struct shader *ps;
23081 BOOL uav;
23082 unsigned int buffer_size;
23083 unsigned int buffer_misc_flags;
23084 unsigned int buffer_structure_byte_stride;
23085 DXGI_FORMAT view_format;
23086 unsigned int view_element_idx;
23087 unsigned int view_element_count;
23088 struct uvec4 expected_result;
23090 tests[] =
23092 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
23093 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
23094 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
23095 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
23096 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
23097 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
23098 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
23099 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
23100 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
23101 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
23102 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
23103 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
23104 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
23105 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
23106 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
23107 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
23108 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
23109 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
23110 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
23111 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
23112 #undef RAW
23113 #undef STRUCTURED
23116 if (!init_test_context(&test_context, &feature_level))
23117 return;
23119 device = test_context.device;
23120 context = test_context.immediate_context;
23122 texture_desc.Width = 64;
23123 texture_desc.Height = 64;
23124 texture_desc.MipLevels = 1;
23125 texture_desc.ArraySize = 1;
23126 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
23127 texture_desc.SampleDesc.Count = 1;
23128 texture_desc.SampleDesc.Quality = 0;
23129 texture_desc.Usage = D3D11_USAGE_DEFAULT;
23130 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23131 texture_desc.CPUAccessFlags = 0;
23132 texture_desc.MiscFlags = 0;
23133 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23134 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
23135 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23136 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
23138 ps = NULL;
23139 current_ps = NULL;
23140 for (i = 0; i < ARRAY_SIZE(tests); ++i)
23142 const struct test *test = &tests[i];
23144 if (current_ps != test->ps)
23146 if (ps)
23147 ID3D11PixelShader_Release(ps);
23149 current_ps = test->ps;
23151 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
23152 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
23153 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23156 buffer_desc.ByteWidth = test->buffer_size;
23157 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23158 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
23159 buffer_desc.CPUAccessFlags = 0;
23160 buffer_desc.MiscFlags = test->buffer_misc_flags;
23161 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
23162 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
23163 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
23165 if (test->uav)
23167 uav_desc.Format = test->view_format;
23168 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
23169 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
23170 U(uav_desc).Buffer.NumElements = test->view_element_count;
23171 U(uav_desc).Buffer.Flags = 0;
23172 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
23173 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
23174 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
23175 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
23176 srv = NULL;
23178 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
23179 1, 1, &uav, NULL);
23181 else
23183 srv_desc.Format = test->view_format;
23184 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
23185 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
23186 U(srv_desc).BufferEx.NumElements = test->view_element_count;
23187 U(srv_desc).BufferEx.Flags = 0;
23188 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
23189 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
23190 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
23191 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
23192 uav = NULL;
23194 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23195 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23198 draw_quad(&test_context);
23199 check_texture_uvec4(texture, &test->expected_result);
23201 if (srv)
23202 ID3D11ShaderResourceView_Release(srv);
23203 if (uav)
23204 ID3D11UnorderedAccessView_Release(uav);
23205 ID3D11Buffer_Release(buffer);
23207 ID3D11PixelShader_Release(ps);
23209 ID3D11RenderTargetView_Release(rtv);
23210 ID3D11Texture2D_Release(texture);
23211 release_test_context(&test_context);
23214 static void test_sampleinfo_instruction(void)
23216 ID3D11Texture2D *float_rt_texture, *uint_rt_texture;
23217 ID3D11RenderTargetView *float_rtv, *uint_rtv, *rtv;
23218 ID3D11PixelShader *ps_float, *ps_uint, *ps_rt;
23219 ID3D11Texture2D *texture, *readback_texture;
23220 struct d3d11_test_context test_context;
23221 unsigned int sample_count, quality;
23222 D3D11_TEXTURE2D_DESC texture_desc;
23223 ID3D11RenderTargetView *rtvs[2];
23224 ID3D11ShaderResourceView *srv;
23225 ID3D11DeviceContext *context;
23226 struct uvec4 expected_uint;
23227 struct vec4 expected_float;
23228 ID3D11Device *device;
23229 HRESULT hr;
23231 static const DWORD ps_uint_code[] =
23233 #if 0
23234 Texture2DMS<float> t;
23236 uint4 main() : SV_Target1
23238 uint width, height, sample_count;
23239 t.GetDimensions(width, height, sample_count);
23240 return sample_count;
23242 #endif
23243 0x43425844, 0x4342ad12, 0x19addd8c, 0x5cb87c48, 0xe604a242, 0x00000001, 0x000000d4, 0x00000003,
23244 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23245 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
23246 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
23247 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000001,
23248 0x02000068, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a, 0x00000000, 0x05000036,
23249 0x001020f2, 0x00000001, 0x00100006, 0x00000000, 0x0100003e,
23251 static const DWORD ps_float_code[] =
23253 #if 0
23254 Texture2DMS<float> t;
23256 float4 main() : SV_Target
23258 uint width, height, sample_count;
23259 t.GetDimensions(width, height, sample_count);
23260 return sample_count;
23262 #endif
23263 0x43425844, 0x2b8aea46, 0x34ceda6f, 0xf98d222b, 0x235ebc0b, 0x00000001, 0x000000b8, 0x00000003,
23264 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23265 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23266 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000040, 0x00000050, 0x00000010,
23267 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23268 0x0500006f, 0x001020f2, 0x00000000, 0x0010700a, 0x00000000, 0x0100003e,
23270 static const DWORD ps_rt_code[] =
23272 #if 0
23273 float4 main() : SV_Target
23275 return GetRenderTargetSampleCount();
23277 #endif
23278 0x43425844, 0x74404d37, 0xad6f88e4, 0xb006ea57, 0xf07d9e2a, 0x00000001, 0x000000a4, 0x00000003,
23279 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23280 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23281 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000002c, 0x00000050, 0x0000000b,
23282 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x0400006f, 0x001020f2, 0x00000000, 0x0000e00a,
23283 0x0100003e,
23285 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23287 if (!init_test_context(&test_context, &feature_level))
23288 return;
23290 device = test_context.device;
23291 context = test_context.immediate_context;
23293 texture_desc.Width = 64;
23294 texture_desc.Height = 64;
23295 texture_desc.MipLevels = 1;
23296 texture_desc.ArraySize = 1;
23297 texture_desc.SampleDesc.Count = 1;
23298 texture_desc.SampleDesc.Quality = 0;
23299 texture_desc.Usage = D3D11_USAGE_DEFAULT;
23300 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23301 texture_desc.CPUAccessFlags = 0;
23302 texture_desc.MiscFlags = 0;
23304 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
23305 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &float_rt_texture);
23306 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23307 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)float_rt_texture, NULL, &float_rtv);
23308 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
23309 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
23310 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &uint_rt_texture);
23311 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23312 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)uint_rt_texture, NULL, &uint_rtv);
23313 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
23315 rtvs[0] = float_rtv;
23316 rtvs[1] = uint_rtv;
23317 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
23319 hr = ID3D11Device_CreatePixelShader(device, ps_float_code, sizeof(ps_float_code), NULL, &ps_float);
23320 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23321 hr = ID3D11Device_CreatePixelShader(device, ps_uint_code, sizeof(ps_uint_code), NULL, &ps_uint);
23322 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23324 for (sample_count = 2; sample_count <= 8; sample_count *= 2)
23326 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
23327 texture_desc.SampleDesc.Count = sample_count;
23328 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
23330 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
23331 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
23332 if (!quality)
23334 skip("Sample count %u not supported.\n", sample_count);
23335 continue;
23338 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23339 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
23340 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
23341 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
23342 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23344 ID3D11DeviceContext_PSSetShader(context, ps_float, NULL, 0);
23345 draw_quad(&test_context);
23346 ID3D11DeviceContext_PSSetShader(context, ps_uint, NULL, 0);
23347 draw_quad(&test_context);
23349 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
23350 check_texture_vec4(float_rt_texture, &expected_float, 0);
23351 expected_uint.x = expected_uint.y = expected_uint.z = expected_uint.w = sample_count;
23352 check_texture_uvec4(uint_rt_texture, &expected_uint);
23354 ID3D11Texture2D_Release(texture);
23355 ID3D11ShaderResourceView_Release(srv);
23358 hr = ID3D11Device_CreatePixelShader(device, ps_rt_code, sizeof(ps_rt_code), NULL, &ps_rt);
23359 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23360 for (sample_count = 1; sample_count <= 8; sample_count *= 2)
23362 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
23363 texture_desc.SampleDesc.Count = sample_count;
23364 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23366 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
23367 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
23368 if (!quality)
23370 skip("Sample count %u not supported.\n", sample_count);
23371 continue;
23374 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23375 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
23376 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23377 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
23378 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23380 /* Some drivers (AMD Radeon HD 6310) return stale sample counts if we
23381 * don't rebind the pixel shader between runs with different sample
23382 * counts. */
23383 ID3D11DeviceContext_PSSetShader(context, NULL, NULL, 0);
23384 ID3D11DeviceContext_PSSetShader(context, ps_rt, NULL, 0);
23385 draw_quad(&test_context);
23387 if (sample_count != 1)
23389 texture_desc.SampleDesc.Count = 1;
23390 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
23391 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23392 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
23393 (ID3D11Resource *)texture, 0, texture_desc.Format);
23395 else
23397 readback_texture = texture;
23398 ID3D11Texture2D_AddRef(readback_texture);
23401 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
23402 check_texture_vec4(readback_texture, &expected_float, 0);
23404 ID3D11Texture2D_Release(readback_texture);
23405 ID3D11Texture2D_Release(texture);
23406 ID3D11RenderTargetView_Release(rtv);
23409 ID3D11RenderTargetView_Release(float_rtv);
23410 ID3D11RenderTargetView_Release(uint_rtv);
23411 ID3D11Texture2D_Release(float_rt_texture);
23412 ID3D11Texture2D_Release(uint_rt_texture);
23413 ID3D11PixelShader_Release(ps_float);
23414 ID3D11PixelShader_Release(ps_uint);
23415 ID3D11PixelShader_Release(ps_rt);
23416 release_test_context(&test_context);
23419 static void test_render_target_device_mismatch(void)
23421 struct d3d11_test_context test_context;
23422 struct device_desc device_desc = {0};
23423 ID3D11DeviceContext *context;
23424 ID3D11RenderTargetView *rtv;
23425 ID3D11Device *device;
23426 ULONG refcount;
23428 if (!init_test_context(&test_context, NULL))
23429 return;
23431 device = create_device(&device_desc);
23432 ok(!!device, "Failed to create device.\n");
23434 ID3D11Device_GetImmediateContext(device, &context);
23436 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
23437 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
23438 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
23439 if (!enable_debug_layer)
23441 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
23442 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
23443 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
23444 ID3D11RenderTargetView_Release(rtv);
23447 rtv = NULL;
23448 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23450 ID3D11DeviceContext_Release(context);
23451 refcount = ID3D11Device_Release(device);
23452 ok(!refcount, "Device has %u references left.\n", refcount);
23453 release_test_context(&test_context);
23456 static void test_buffer_srv(void)
23458 struct shader
23460 const DWORD *code;
23461 size_t size;
23462 BOOL requires_raw_and_structured_buffers;
23464 struct buffer
23466 unsigned int byte_count;
23467 unsigned int data_offset;
23468 const void *data;
23469 unsigned int structure_byte_stride;
23472 BOOL raw_and_structured_buffers_supported;
23473 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
23474 struct d3d11_test_context test_context;
23475 D3D11_SUBRESOURCE_DATA resource_data;
23476 const struct buffer *current_buffer;
23477 const struct shader *current_shader;
23478 ID3D11ShaderResourceView *srv;
23479 D3D11_BUFFER_DESC buffer_desc;
23480 ID3D11DeviceContext *context;
23481 DWORD color, expected_color;
23482 struct resource_readback rb;
23483 ID3D11Buffer *cb, *buffer;
23484 ID3D11PixelShader *ps;
23485 ID3D11Device *device;
23486 unsigned int i, x, y;
23487 struct vec4 cb_size;
23488 HRESULT hr;
23490 static const DWORD ps_float4_code[] =
23492 #if 0
23493 Buffer<float4> b;
23495 float2 size;
23497 float4 main(float4 position : SV_POSITION) : SV_Target
23499 float2 p;
23500 int2 coords;
23501 p.x = position.x / 640.0f;
23502 p.y = position.y / 480.0f;
23503 coords = int2(p.x * size.x, p.y * size.y);
23504 return b.Load(coords.y * size.x + coords.x);
23506 #endif
23507 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
23508 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
23509 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
23510 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
23511 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
23512 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
23513 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
23514 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
23515 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
23516 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
23517 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
23518 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
23519 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
23521 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
23522 static const DWORD ps_structured_code[] =
23524 #if 0
23525 StructuredBuffer<float4> b;
23527 float2 size;
23529 float4 main(float4 position : SV_POSITION) : SV_Target
23531 float2 p;
23532 int2 coords;
23533 p.x = position.x / 640.0f;
23534 p.y = position.y / 480.0f;
23535 coords = int2(p.x * size.x, p.y * size.y);
23536 return b[coords.y * size.x + coords.x];
23538 #endif
23539 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
23540 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
23541 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
23542 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
23543 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
23544 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
23545 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
23546 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
23547 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
23548 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
23549 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
23550 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
23551 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
23552 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
23554 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
23555 static const DWORD rgba16[] =
23557 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
23558 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
23559 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
23560 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
23562 static const DWORD rgba4[] =
23564 0xffffffff, 0xff0000ff,
23565 0xff000000, 0xff00ff00,
23567 static const BYTE r4[] =
23569 0xde, 0xad,
23570 0xba, 0xbe,
23572 static const struct vec4 rgba_float[] =
23574 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
23575 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
23577 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
23578 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
23579 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
23580 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
23581 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
23582 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
23583 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
23584 &rgba_float, sizeof(*rgba_float)};
23585 static const DWORD rgba16_colors2x2[] =
23587 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
23588 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
23589 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
23590 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
23592 static const DWORD rgba16_colors1x1[] =
23594 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23595 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23596 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23597 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23599 static const DWORD rgba4_colors[] =
23601 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
23602 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
23603 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
23604 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
23606 static const DWORD r4_colors[] =
23608 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
23609 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
23610 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
23611 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
23613 static const DWORD zero_colors[16] = {0};
23614 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
23616 static const struct test
23618 const struct shader *shader;
23619 const struct buffer *buffer;
23620 DXGI_FORMAT srv_format;
23621 unsigned int srv_first_element;
23622 unsigned int srv_element_count;
23623 struct vec2 size;
23624 const DWORD *expected_colors;
23626 tests[] =
23628 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
23629 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
23630 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
23631 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
23632 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
23633 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
23634 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
23635 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
23636 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
23637 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
23638 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
23641 if (!init_test_context(&test_context, NULL))
23642 return;
23644 device = test_context.device;
23645 context = test_context.immediate_context;
23646 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
23647 || check_compute_shaders_via_sm4_support(device);
23649 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
23650 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
23652 buffer_desc.ByteWidth = 256;
23653 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23654 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23655 buffer_desc.CPUAccessFlags = 0;
23656 buffer_desc.MiscFlags = 0;
23657 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
23658 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23659 srv_desc.Format = DXGI_FORMAT_R8_UNORM;
23660 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
23661 U(srv_desc).Buffer.FirstElement = 0;
23662 U(srv_desc).Buffer.NumElements = 0;
23663 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
23664 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
23665 ID3D11Buffer_Release(buffer);
23667 ps = NULL;
23668 srv = NULL;
23669 buffer = NULL;
23670 current_shader = NULL;
23671 current_buffer = NULL;
23672 for (i = 0; i < ARRAY_SIZE(tests); ++i)
23674 const struct test *test = &tests[i];
23676 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
23678 skip("Test %u: Raw and structured buffers are not supported.\n", i);
23679 continue;
23681 /* Structured buffer views with an offset don't seem to work on WARP. */
23682 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
23683 && is_warp_device(device))
23685 skip("Test %u: Broken WARP.\n", i);
23686 continue;
23689 if (current_shader != test->shader)
23691 if (ps)
23692 ID3D11PixelShader_Release(ps);
23694 current_shader = test->shader;
23696 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
23697 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
23698 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23701 if (current_buffer != test->buffer)
23703 if (buffer)
23704 ID3D11Buffer_Release(buffer);
23706 current_buffer = test->buffer;
23707 if (current_buffer)
23709 BYTE *data = NULL;
23711 buffer_desc.ByteWidth = current_buffer->byte_count;
23712 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23713 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23714 buffer_desc.CPUAccessFlags = 0;
23715 buffer_desc.MiscFlags = 0;
23716 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
23717 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
23718 resource_data.SysMemPitch = 0;
23719 resource_data.SysMemSlicePitch = 0;
23720 if (current_buffer->data_offset)
23722 data = heap_alloc_zero(current_buffer->byte_count);
23723 ok(!!data, "Failed to allocate memory.\n");
23724 memcpy(data + current_buffer->data_offset, current_buffer->data,
23725 current_buffer->byte_count - current_buffer->data_offset);
23726 resource_data.pSysMem = data;
23728 else
23730 resource_data.pSysMem = current_buffer->data;
23732 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
23733 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
23734 heap_free(data);
23736 else
23738 buffer = NULL;
23742 if (srv)
23743 ID3D11ShaderResourceView_Release(srv);
23744 if (current_buffer)
23746 srv_desc.Format = test->srv_format;
23747 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
23748 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
23749 U(srv_desc).Buffer.NumElements = test->srv_element_count;
23750 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
23751 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
23753 else
23755 srv = NULL;
23757 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23759 cb_size.x = test->size.x;
23760 cb_size.y = test->size.y;
23761 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
23763 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
23764 draw_quad(&test_context);
23766 get_texture_readback(test_context.backbuffer, 0, &rb);
23767 for (y = 0; y < 4; ++y)
23769 for (x = 0; x < 4; ++x)
23771 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
23772 expected_color = test->expected_colors[y * 4 + x];
23773 ok(compare_color(color, expected_color, 1),
23774 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
23775 i, color, expected_color, x, y);
23778 release_resource_readback(&rb);
23780 if (srv)
23781 ID3D11ShaderResourceView_Release(srv);
23782 if (buffer)
23783 ID3D11Buffer_Release(buffer);
23785 ID3D11Buffer_Release(cb);
23786 ID3D11PixelShader_Release(ps);
23787 release_test_context(&test_context);
23790 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
23792 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
23793 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
23794 struct d3d11_test_context test_context;
23795 D3D11_SUBRESOURCE_DATA resource_data;
23796 D3D11_TEXTURE2D_DESC texture_desc;
23797 ID3D11UnorderedAccessView *uav;
23798 ID3D11ShaderResourceView *srv;
23799 D3D11_BUFFER_DESC buffer_desc;
23800 ID3D11Buffer *cb, *raw_buffer;
23801 ID3D11DeviceContext *context;
23802 struct resource_readback rb;
23803 ID3D11RenderTargetView *rtv;
23804 ID3D11Texture2D *texture;
23805 ID3D11ComputeShader *cs;
23806 ID3D11PixelShader *ps;
23807 ID3D11Device *device;
23808 unsigned int i, data;
23809 struct uvec4 offset;
23810 HRESULT hr;
23812 static const unsigned int buffer_data[] =
23814 0xffffffff, 0x00000000,
23816 static const DWORD ps_code[] =
23818 #if 0
23819 ByteAddressBuffer buffer;
23821 uint offset;
23823 uint main() : SV_Target0
23825 return buffer.Load(offset);
23827 #endif
23828 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
23829 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
23830 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
23831 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
23832 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
23833 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
23834 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
23835 0x00000000,
23837 static const DWORD cs_code[] =
23839 #if 0
23840 RWByteAddressBuffer buffer;
23842 uint2 input;
23844 [numthreads(1, 1, 1)]
23845 void main()
23847 buffer.Store(input.x, input.y);
23849 #endif
23850 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
23851 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23852 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
23853 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
23854 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
23855 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
23857 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
23859 if (!init_test_context(&test_context, &feature_level))
23860 return;
23862 device = test_context.device;
23863 context = test_context.immediate_context;
23865 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
23867 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
23868 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
23869 if (SUCCEEDED(hr))
23870 ID3D11PixelShader_Release(ps);
23871 skip("Raw buffers are not supported.\n");
23872 release_test_context(&test_context);
23873 return;
23876 if (is_intel_device(device))
23878 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
23879 * This test checks what happens when offsets are not properly aligned.
23880 * The behavior seems to be undefined on Intel hardware. */
23881 win_skip("Skipping the test on Intel hardware.\n");
23882 release_test_context(&test_context);
23883 return;
23886 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
23887 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
23889 memset(&offset, 0, sizeof(offset));
23890 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
23892 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
23893 texture_desc.Format = DXGI_FORMAT_R32_UINT;
23894 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23895 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
23896 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23897 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
23899 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23901 buffer_desc.ByteWidth = sizeof(buffer_data);
23902 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23903 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23904 buffer_desc.CPUAccessFlags = 0;
23905 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
23906 resource_data.pSysMem = buffer_data;
23907 resource_data.SysMemPitch = 0;
23908 resource_data.SysMemSlicePitch = 0;
23909 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
23910 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23912 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
23913 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
23914 U(srv_desc).BufferEx.FirstElement = 0;
23915 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
23916 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
23917 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
23918 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
23920 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23921 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
23922 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23924 offset.x = 0;
23925 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23926 NULL, &offset, 0, 0);
23927 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23928 draw_quad(&test_context);
23929 check_texture_color(texture, buffer_data[0], 0);
23930 offset.x = 1;
23931 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23932 NULL, &offset, 0, 0);
23933 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23934 draw_quad(&test_context);
23935 check_texture_color(texture, buffer_data[0], 0);
23936 offset.x = 2;
23937 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23938 NULL, &offset, 0, 0);
23939 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23940 draw_quad(&test_context);
23941 check_texture_color(texture, buffer_data[0], 0);
23942 offset.x = 3;
23943 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23944 NULL, &offset, 0, 0);
23945 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23946 draw_quad(&test_context);
23947 check_texture_color(texture, buffer_data[0], 0);
23949 offset.x = 4;
23950 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23951 NULL, &offset, 0, 0);
23952 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23953 draw_quad(&test_context);
23954 check_texture_color(texture, buffer_data[1], 0);
23955 offset.x = 7;
23956 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23957 NULL, &offset, 0, 0);
23958 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23959 draw_quad(&test_context);
23960 check_texture_color(texture, buffer_data[1], 0);
23962 if (feature_level < D3D_FEATURE_LEVEL_11_0)
23964 skip("Feature level 11_0 required for unaligned UAV test.\n");
23965 goto done;
23968 ID3D11Buffer_Release(raw_buffer);
23969 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
23970 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
23971 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23973 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
23974 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
23975 U(uav_desc).Buffer.FirstElement = 0;
23976 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
23977 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
23978 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
23979 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
23981 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
23982 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
23984 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
23985 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
23986 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
23988 offset.x = 0;
23989 offset.y = 0xffffffff;
23990 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23991 NULL, &offset, 0, 0);
23992 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
23993 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
23994 get_buffer_readback(raw_buffer, &rb);
23995 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
23997 data = get_readback_color(&rb, i, 0, 0);
23998 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24000 release_resource_readback(&rb);
24002 offset.x = 1;
24003 offset.y = 0xffffffff;
24004 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24005 NULL, &offset, 0, 0);
24006 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24007 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24008 get_buffer_readback(raw_buffer, &rb);
24009 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24011 data = get_readback_color(&rb, i, 0, 0);
24012 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24014 release_resource_readback(&rb);
24016 offset.x = 2;
24017 offset.y = 0xffffffff;
24018 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24019 NULL, &offset, 0, 0);
24020 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24021 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24022 get_buffer_readback(raw_buffer, &rb);
24023 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24025 data = get_readback_color(&rb, i, 0, 0);
24026 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24028 release_resource_readback(&rb);
24030 offset.x = 3;
24031 offset.y = 0xffffffff;
24032 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24033 NULL, &offset, 0, 0);
24034 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24035 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24036 get_buffer_readback(raw_buffer, &rb);
24037 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24039 data = get_readback_color(&rb, i, 0, 0);
24040 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24042 release_resource_readback(&rb);
24044 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24045 offset.x = 3;
24046 offset.y = 0xffff;
24047 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24048 NULL, &offset, 0, 0);
24049 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24050 offset.x = 4;
24051 offset.y = 0xa;
24052 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24053 NULL, &offset, 0, 0);
24054 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24055 get_buffer_readback(raw_buffer, &rb);
24056 data = get_readback_color(&rb, 0, 0, 0);
24057 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
24058 data = get_readback_color(&rb, 1, 0, 0);
24059 ok(data == 0xa, "Got unexpected result %#x.\n", data);
24060 release_resource_readback(&rb);
24062 ID3D11ComputeShader_Release(cs);
24063 ID3D11UnorderedAccessView_Release(uav);
24065 done:
24066 ID3D11Buffer_Release(cb);
24067 ID3D11Buffer_Release(raw_buffer);
24068 ID3D11PixelShader_Release(ps);
24069 ID3D11RenderTargetView_Release(rtv);
24070 ID3D11ShaderResourceView_Release(srv);
24071 ID3D11Texture2D_Release(texture);
24072 release_test_context(&test_context);
24075 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
24076 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
24078 D3D11_MAPPED_SUBRESOURCE map_desc;
24079 unsigned int counter;
24081 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
24083 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
24084 D3D11_MAP_READ, 0, &map_desc)))
24085 return 0xdeadbeef;
24086 counter = *(unsigned int *)map_desc.pData;
24087 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
24088 return counter;
24091 static int compare_id(const void *a, const void *b)
24093 return *(int *)a - *(int *)b;
24096 static void test_uav_counters(void)
24098 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
24099 ID3D11ComputeShader *cs_producer, *cs_consumer;
24100 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24101 struct d3d11_test_context test_context;
24102 ID3D11UnorderedAccessView *uav, *uav2;
24103 unsigned int data, id[128], i;
24104 D3D11_BUFFER_DESC buffer_desc;
24105 ID3D11DeviceContext *context;
24106 struct resource_readback rb;
24107 ID3D11Device *device;
24108 D3D11_BOX box;
24109 HRESULT hr;
24111 static const DWORD cs_producer_code[] =
24113 #if 0
24114 RWStructuredBuffer<uint> u;
24116 [numthreads(4, 1, 1)]
24117 void main(uint3 dispatch_id : SV_DispatchThreadID)
24119 uint counter = u.IncrementCounter();
24120 u[counter] = dispatch_id.x;
24122 #endif
24123 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
24124 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24125 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
24126 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
24127 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
24128 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
24129 0x0002000a, 0x0100003e,
24131 static const DWORD cs_consumer_code[] =
24133 #if 0
24134 RWStructuredBuffer<uint> u;
24135 RWStructuredBuffer<uint> u2;
24137 [numthreads(4, 1, 1)]
24138 void main()
24140 uint counter = u.DecrementCounter();
24141 u2[counter] = u[counter];
24143 #endif
24144 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
24145 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24146 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
24147 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
24148 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
24149 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
24150 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
24151 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
24153 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24155 if (!init_test_context(&test_context, &feature_level))
24156 return;
24158 device = test_context.device;
24159 context = test_context.immediate_context;
24161 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
24162 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24163 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
24164 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24166 memset(&buffer_desc, 0, sizeof(buffer_desc));
24167 buffer_desc.ByteWidth = sizeof(unsigned int);
24168 buffer_desc.Usage = D3D11_USAGE_STAGING;
24169 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
24170 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
24171 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24173 buffer_desc.ByteWidth = 1024;
24174 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24175 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24176 buffer_desc.CPUAccessFlags = 0;
24177 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24178 buffer_desc.StructureByteStride = sizeof(unsigned int);
24179 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24180 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24181 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
24182 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24183 U(uav_desc).Buffer.FirstElement = 0;
24184 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
24185 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
24186 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24187 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24188 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
24189 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24190 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
24191 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24193 data = read_uav_counter(context, staging_buffer, uav);
24194 ok(!data, "Got unexpected initial value %u.\n", data);
24195 data = 8;
24196 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24197 data = read_uav_counter(context, staging_buffer, uav);
24198 ok(data == 8, "Got unexpected value %u.\n", data);
24199 data = ~0u;
24200 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24201 data = read_uav_counter(context, staging_buffer, uav);
24202 ok(data == 8, "Got unexpected value %u.\n", data);
24203 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24204 data = read_uav_counter(context, staging_buffer, uav);
24205 ok(data == 8, "Got unexpected value %u.\n", data);
24207 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
24208 data = 0;
24209 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24210 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
24211 data = read_uav_counter(context, staging_buffer, uav);
24212 ok(!data, "Got unexpected value %u.\n", data);
24214 /* produce */
24215 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
24216 data = read_uav_counter(context, staging_buffer, uav);
24217 ok(data == 64, "Got unexpected value %u.\n", data);
24218 get_buffer_readback(buffer, &rb);
24219 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
24220 release_resource_readback(&rb);
24221 qsort(id, 64, sizeof(*id), compare_id);
24222 for (i = 0; i < 64; ++i)
24224 if (id[i] != i)
24225 break;
24227 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
24229 /* consume */
24230 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
24231 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
24232 data = read_uav_counter(context, staging_buffer, uav);
24233 ok(!data, "Got unexpected value %u.\n", data);
24234 get_buffer_readback(buffer2, &rb);
24235 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
24236 release_resource_readback(&rb);
24237 qsort(id, 64, sizeof(*id), compare_id);
24238 for (i = 0; i < 64; ++i)
24240 if (id[i] != i)
24241 break;
24243 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
24245 /* produce on CPU */
24246 for (i = 0; i < 8; ++i)
24247 id[i] = 0xdeadbeef;
24248 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
24249 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
24250 data = 8;
24251 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24252 data = read_uav_counter(context, staging_buffer, uav);
24253 ok(data == 8, "Got unexpected value %u.\n", data);
24255 /* consume */
24256 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24257 data = read_uav_counter(context, staging_buffer, uav);
24258 ok(data == 4, "Got unexpected value %u.\n", data);
24259 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24260 data = read_uav_counter(context, staging_buffer, uav);
24261 ok(!data, "Got unexpected value %u.\n", data);
24262 get_buffer_readback(buffer2, &rb);
24263 for (i = 0; i < 8; ++i)
24265 data = get_readback_color(&rb, i, 0, 0);
24266 ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
24268 release_resource_readback(&rb);
24270 ID3D11Buffer_Release(buffer);
24271 ID3D11Buffer_Release(buffer2);
24272 ID3D11Buffer_Release(staging_buffer);
24273 ID3D11ComputeShader_Release(cs_producer);
24274 ID3D11ComputeShader_Release(cs_consumer);
24275 ID3D11UnorderedAccessView_Release(uav);
24276 ID3D11UnorderedAccessView_Release(uav2);
24277 release_test_context(&test_context);
24280 static void test_dispatch_indirect(void)
24282 struct stats
24284 unsigned int dispatch_count;
24285 unsigned int thread_count;
24286 unsigned int max_x;
24287 unsigned int max_y;
24288 unsigned int max_z;
24291 ID3D11Buffer *append_buffer, *stats_buffer, *args_buffer, *staging_buffer;
24292 ID3D11UnorderedAccessView *uav, *stats_uav;
24293 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24294 ID3D11ComputeShader *cs_append, *cs_stats;
24295 struct d3d11_test_context test_context;
24296 D3D11_BUFFER_DESC buffer_desc;
24297 ID3D11DeviceContext *context;
24298 struct resource_readback rb;
24299 ID3D11Device *device;
24300 unsigned int data, i;
24301 struct stats *stats;
24302 HRESULT hr;
24304 static const DWORD cs_append_code[] =
24306 #if 0
24307 struct dispatch_args
24309 uint x, y, z;
24312 AppendStructuredBuffer<dispatch_args> u;
24314 [numthreads(1, 1, 1)]
24315 void main()
24317 dispatch_args args = {4, 2, 1};
24318 u.Append(args);
24319 args.y = 1;
24320 u.Append(args);
24321 args.x = 3;
24322 u.Append(args);
24324 #endif
24325 0x43425844, 0x954de75a, 0x8bb1b78b, 0x84ded464, 0x9d9532b7, 0x00000001, 0x00000158, 0x00000003,
24326 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24327 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000104, 0x00050050, 0x00000041, 0x0100086a,
24328 0x0400009e, 0x0011e000, 0x00000000, 0x0000000c, 0x02000068, 0x00000001, 0x0400009b, 0x00000001,
24329 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x0c0000a8,
24330 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002, 0x00000004,
24331 0x00000002, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000,
24332 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002,
24333 0x00000004, 0x00000001, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
24334 0x00000000, 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
24335 0x00004002, 0x00000003, 0x00000001, 0x00000001, 0x00000000, 0x0100003e,
24337 static const DWORD cs_stats_code[] =
24339 #if 0
24340 struct stats
24342 uint dispatch_count;
24343 uint thread_count;
24344 uint max_x;
24345 uint max_y;
24346 uint max_z;
24349 RWStructuredBuffer<stats> u;
24351 [numthreads(1, 1, 1)]
24352 void main(uint3 id : SV_DispatchThreadID)
24354 if (all(!id))
24355 InterlockedAdd(u[0].dispatch_count, 1);
24356 InterlockedAdd(u[0].thread_count, 1);
24357 InterlockedMax(u[0].max_x, id.x);
24358 InterlockedMax(u[0].max_y, id.y);
24359 InterlockedMax(u[0].max_z, id.z);
24361 #endif
24362 0x43425844, 0xbd3f2e4e, 0xb0f61ff7, 0xa8e10584, 0x2f61aec9, 0x00000001, 0x000001bc, 0x00000003,
24363 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24364 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000168, 0x00050050, 0x0000005a, 0x0100086a,
24365 0x0400009e, 0x0011e000, 0x00000000, 0x00000014, 0x0200005f, 0x00020072, 0x02000068, 0x00000001,
24366 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x09000020, 0x00100072, 0x00000000, 0x00020246,
24367 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000001, 0x00100012, 0x00000000,
24368 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00100012, 0x00000000, 0x0010002a,
24369 0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x0a0000ad, 0x0011e000,
24370 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001,
24371 0x01000015, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000,
24372 0x00000000, 0x00004001, 0x00000001, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002, 0x00000000,
24373 0x00000008, 0x00000000, 0x00000000, 0x0002000a, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002,
24374 0x00000000, 0x0000000c, 0x00000000, 0x00000000, 0x0002001a, 0x090000b0, 0x0011e000, 0x00000000,
24375 0x00004002, 0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x0002002a, 0x0100003e,
24377 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24378 static const unsigned int zero[4] = {0, 0, 0, 0};
24380 if (!init_test_context(&test_context, &feature_level))
24381 return;
24383 device = test_context.device;
24384 context = test_context.immediate_context;
24386 hr = ID3D11Device_CreateComputeShader(device, cs_append_code, sizeof(cs_append_code), NULL, &cs_append);
24387 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24388 hr = ID3D11Device_CreateComputeShader(device, cs_stats_code, sizeof(cs_stats_code), NULL, &cs_stats);
24389 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24391 memset(&buffer_desc, 0, sizeof(buffer_desc));
24392 buffer_desc.ByteWidth = sizeof(unsigned int);
24393 buffer_desc.Usage = D3D11_USAGE_STAGING;
24394 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
24395 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
24396 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24398 buffer_desc.ByteWidth = 60;
24399 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24400 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24401 buffer_desc.CPUAccessFlags = 0;
24402 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24403 buffer_desc.StructureByteStride = 3 * sizeof(unsigned int);
24404 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &append_buffer);
24405 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24406 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
24407 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24408 U(uav_desc).Buffer.FirstElement = 0;
24409 U(uav_desc).Buffer.NumElements = 5;
24410 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
24411 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)append_buffer, &uav_desc, &uav);
24412 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24414 /* We use a separate buffer because D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
24415 * and D3D11_RESOURCE_MISC_BUFFER_STRUCTURED are mutually exclusive flags.
24417 buffer_desc.BindFlags = 0;
24418 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
24419 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &args_buffer);
24420 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24422 buffer_desc.ByteWidth = sizeof(*stats);
24423 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24424 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24425 buffer_desc.StructureByteStride = sizeof(*stats);
24426 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &stats_buffer);
24427 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24428 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)stats_buffer, NULL, &stats_uav);
24429 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24431 data = read_uav_counter(context, staging_buffer, uav);
24432 ok(!data, "Got unexpected initial value %u.\n", data);
24433 data = 8;
24434 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24435 data = read_uav_counter(context, staging_buffer, uav);
24436 ok(data == 8, "Got unexpected value %u.\n", data);
24438 ID3D11DeviceContext_CSSetShader(context, cs_append, NULL, 0);
24439 data = 0;
24440 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24441 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24442 data = read_uav_counter(context, staging_buffer, uav);
24443 ok(data == 3, "Got unexpected value %u.\n", data);
24444 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)args_buffer, (ID3D11Resource *)append_buffer);
24446 ID3D11DeviceContext_CSSetShader(context, cs_stats, NULL, 0);
24447 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, stats_uav, zero);
24448 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &stats_uav, NULL);
24449 data = read_uav_counter(context, staging_buffer, uav);
24450 for (i = 0; i < data; ++i)
24451 ID3D11DeviceContext_DispatchIndirect(context, args_buffer, i * 3 * sizeof(unsigned int));
24452 get_buffer_readback(stats_buffer, &rb);
24453 stats = rb.map_desc.pData;
24454 ok(stats->dispatch_count == 3, "Got unexpected dispatch count %u.\n", stats->dispatch_count);
24455 ok(stats->thread_count == 15, "Got unexpected thread count %u.\n", stats->thread_count);
24456 ok(stats->max_x == 3, "Got unexpected max x %u.\n", stats->max_x);
24457 ok(stats->max_y == 1, "Got unexpected max y %u.\n", stats->max_y);
24458 ok(stats->max_z == 0, "Got unexpected max z %u.\n", stats->max_z);
24459 release_resource_readback(&rb);
24461 ID3D11Buffer_Release(append_buffer);
24462 ID3D11Buffer_Release(args_buffer);
24463 ID3D11Buffer_Release(staging_buffer);
24464 ID3D11Buffer_Release(stats_buffer);
24465 ID3D11ComputeShader_Release(cs_append);
24466 ID3D11ComputeShader_Release(cs_stats);
24467 ID3D11UnorderedAccessView_Release(uav);
24468 ID3D11UnorderedAccessView_Release(stats_uav);
24469 release_test_context(&test_context);
24472 static void test_compute_shader_registers(void)
24474 struct data
24476 unsigned int group_id[3];
24477 unsigned int group_index;
24478 unsigned int dispatch_id[3];
24479 unsigned int thread_id[3];
24482 struct d3d11_test_context test_context;
24483 unsigned int i, x, y, group_x, group_y;
24484 ID3D11UnorderedAccessView *uav;
24485 D3D11_BUFFER_DESC buffer_desc;
24486 ID3D11DeviceContext *context;
24487 struct resource_readback rb;
24488 ID3D11Buffer *cb, *buffer;
24489 struct uvec4 dimensions;
24490 ID3D11ComputeShader *cs;
24491 const struct data *data;
24492 ID3D11Device *device;
24493 HRESULT hr;
24495 static const DWORD cs_code[] =
24497 #if 0
24498 struct data
24500 uint3 group_id;
24501 uint group_index;
24502 uint3 dispatch_id;
24503 uint3 group_thread_id;
24506 RWStructuredBuffer<data> u;
24508 uint2 dim;
24510 [numthreads(3, 2, 1)]
24511 void main(uint3 group_id : SV_GroupID,
24512 uint group_index : SV_GroupIndex,
24513 uint3 dispatch_id : SV_DispatchThreadID,
24514 uint3 group_thread_id : SV_GroupThreadID)
24516 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
24517 u[i].group_id = group_id;
24518 u[i].group_index = group_index;
24519 u[i].dispatch_id = dispatch_id;
24520 u[i].group_thread_id = group_thread_id;
24522 #endif
24523 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
24524 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24525 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
24526 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
24527 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
24528 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
24529 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
24530 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
24531 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
24532 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
24533 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
24534 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
24535 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
24536 0x0100003e,
24538 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24540 if (!init_test_context(&test_context, &feature_level))
24541 return;
24543 device = test_context.device;
24544 context = test_context.immediate_context;
24546 buffer_desc.ByteWidth = 10240;
24547 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24548 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24549 buffer_desc.CPUAccessFlags = 0;
24550 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24551 buffer_desc.StructureByteStride = 40;
24552 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
24553 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24554 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24555 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
24556 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24558 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
24560 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
24561 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24563 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24564 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
24565 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24567 dimensions.x = 2;
24568 dimensions.y = 3;
24569 dimensions.z = 1;
24570 dimensions.w = 0;
24571 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24572 NULL, &dimensions, 0, 0);
24573 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
24575 get_buffer_readback(buffer, &rb);
24576 i = 0;
24577 data = rb.map_desc.pData;
24578 for (y = 0; y < dimensions.y; ++y)
24580 for (group_y = 0; group_y < 2; ++group_y)
24582 for (x = 0; x < dimensions.x; ++x)
24584 for (group_x = 0; group_x < 3; ++group_x)
24586 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
24587 const unsigned int group_index = group_y * 3 + group_x;
24588 const struct data *d = &data[i];
24590 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
24591 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
24592 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
24593 i, x, y, group_x, group_y);
24594 ok(d->group_index == group_index,
24595 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
24596 d->group_index, group_index, i, x, y, group_x, group_y);
24597 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
24598 && !d->dispatch_id[2],
24599 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
24600 "at %u (%u, %u, %u, %u).\n",
24601 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
24602 dispatch_id[0], dispatch_id[1], 0,
24603 i, x, y, group_x, group_y);
24604 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
24605 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
24606 "at %u (%u, %u, %u, %u).\n",
24607 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
24608 i, x, y, group_x, group_y);
24609 ++i;
24614 release_resource_readback(&rb);
24616 ID3D11Buffer_Release(cb);
24617 ID3D11Buffer_Release(buffer);
24618 ID3D11ComputeShader_Release(cs);
24619 ID3D11UnorderedAccessView_Release(uav);
24620 release_test_context(&test_context);
24623 static void test_tgsm(void)
24625 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24626 struct d3d11_test_context test_context;
24627 ID3D11UnorderedAccessView *uav, *uav2;
24628 struct resource_readback rb, rb2;
24629 unsigned int i, data, expected;
24630 ID3D11Buffer *buffer, *buffer2;
24631 D3D11_BUFFER_DESC buffer_desc;
24632 ID3D11DeviceContext *context;
24633 ID3D11ComputeShader *cs;
24634 ID3D11Device *device;
24635 float float_data;
24636 HRESULT hr;
24638 static const DWORD raw_tgsm_code[] =
24640 #if 0
24641 RWByteAddressBuffer u;
24642 groupshared uint m;
24644 [numthreads(32, 1, 1)]
24645 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
24647 if (!local_idx)
24648 m = group_id.x;
24649 GroupMemoryBarrierWithGroupSync();
24650 InterlockedAdd(m, group_id.x);
24651 GroupMemoryBarrierWithGroupSync();
24652 if (!local_idx)
24653 u.Store(4 * group_id.x, m);
24655 #endif
24656 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
24657 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24658 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
24659 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
24660 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
24661 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
24662 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
24663 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
24664 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
24665 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
24666 0x01000015, 0x0100003e,
24668 static const DWORD structured_tgsm_code[] =
24670 #if 0
24671 #define GROUP_SIZE 32
24673 RWByteAddressBuffer u;
24674 RWByteAddressBuffer u2;
24675 groupshared uint m[GROUP_SIZE];
24677 [numthreads(GROUP_SIZE, 1, 1)]
24678 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
24680 uint sum, original, i;
24682 if (!local_idx)
24684 for (i = 0; i < GROUP_SIZE; ++i)
24685 m[i] = 2 * group_id.x;
24687 GroupMemoryBarrierWithGroupSync();
24688 InterlockedAdd(m[local_idx], 1);
24689 GroupMemoryBarrierWithGroupSync();
24690 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
24691 u.InterlockedExchange(4 * group_id.x, sum, original);
24692 u2.Store(4 * group_id.x, original);
24694 #endif
24695 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
24696 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24697 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
24698 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
24699 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
24700 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
24701 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
24702 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
24703 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
24704 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
24705 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
24706 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
24707 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
24708 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
24709 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
24710 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
24711 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
24712 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
24713 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
24714 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
24715 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
24716 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
24718 static const DWORD structured_tgsm_float_code[] =
24720 #if 0
24721 #define GROUP_SIZE 32
24723 struct data
24725 float f;
24726 uint u;
24729 RWBuffer<float> u;
24730 RWBuffer<uint> u2;
24731 groupshared data m[GROUP_SIZE];
24733 [numthreads(GROUP_SIZE, 1, 1)]
24734 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
24735 uint thread_id : SV_DispatchThreadID)
24737 uint i;
24738 if (!local_idx)
24740 for (i = 0; i < GROUP_SIZE; ++i)
24742 m[i].f = group_id.x;
24743 m[i].u = group_id.x;
24746 GroupMemoryBarrierWithGroupSync();
24747 for (i = 0; i < local_idx; ++i)
24749 m[local_idx].f += group_id.x;
24750 m[local_idx].u += group_id.x;
24752 u[thread_id.x] = m[local_idx].f;
24753 u2[thread_id.x] = m[local_idx].u;
24755 #endif
24756 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
24757 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24758 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
24759 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
24760 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
24761 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
24762 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
24763 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
24764 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
24765 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
24766 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
24767 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
24768 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
24769 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
24770 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
24771 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
24772 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
24773 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
24774 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
24775 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
24776 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
24777 0x00100556, 0x00000000, 0x0100003e,
24779 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24780 static const unsigned int zero[4] = {0};
24782 if (!init_test_context(&test_context, &feature_level))
24783 return;
24785 device = test_context.device;
24786 context = test_context.immediate_context;
24788 buffer_desc.ByteWidth = 1024;
24789 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24790 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24791 buffer_desc.CPUAccessFlags = 0;
24792 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
24793 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24794 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24796 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
24797 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24798 U(uav_desc).Buffer.FirstElement = 0;
24799 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
24800 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
24801 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24802 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24804 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
24805 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24807 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24808 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24810 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
24811 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
24812 get_buffer_readback(buffer, &rb);
24813 for (i = 0; i < 64; ++i)
24815 data = get_readback_color(&rb, i, 0, 0);
24816 expected = 33 * i;
24817 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
24819 release_resource_readback(&rb);
24821 ID3D11Buffer_Release(buffer);
24822 ID3D11ComputeShader_Release(cs);
24823 ID3D11UnorderedAccessView_Release(uav);
24825 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24826 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24827 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24828 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24829 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
24830 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24831 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
24832 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24833 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
24834 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24836 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24837 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24838 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
24840 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
24841 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
24842 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
24843 get_buffer_readback(buffer, &rb);
24844 get_buffer_readback(buffer2, &rb2);
24845 for (i = 0; i < 32; ++i)
24847 expected = 64 * i + 32;
24848 data = get_readback_color(&rb, i, 0, 0);
24849 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
24850 data = get_readback_color(&rb2, i, 0, 0);
24851 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
24853 release_resource_readback(&rb);
24854 release_resource_readback(&rb2);
24856 ID3D11Buffer_Release(buffer);
24857 ID3D11Buffer_Release(buffer2);
24858 ID3D11ComputeShader_Release(cs);
24859 ID3D11UnorderedAccessView_Release(uav);
24860 ID3D11UnorderedAccessView_Release(uav2);
24862 buffer_desc.MiscFlags = 0;
24863 U(uav_desc).Buffer.Flags = 0;
24864 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24865 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24866 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
24867 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24868 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24869 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
24870 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24871 uav_desc.Format = DXGI_FORMAT_R32_UINT;
24872 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
24873 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24874 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
24875 sizeof(structured_tgsm_float_code), NULL, &cs);
24876 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24878 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24879 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24880 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
24882 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
24883 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
24884 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
24885 get_buffer_readback(buffer, &rb);
24886 get_buffer_readback(buffer2, &rb2);
24887 for (i = 0; i < 96; ++i)
24889 expected = (i % 32 + 1) * (i / 32);
24890 float_data = get_readback_float(&rb, i, 0);
24891 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
24892 data = get_readback_color(&rb2, i, 0, 0);
24893 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
24895 release_resource_readback(&rb);
24896 release_resource_readback(&rb2);
24898 ID3D11Buffer_Release(buffer);
24899 ID3D11Buffer_Release(buffer2);
24900 ID3D11ComputeShader_Release(cs);
24901 ID3D11UnorderedAccessView_Release(uav);
24902 ID3D11UnorderedAccessView_Release(uav2);
24903 release_test_context(&test_context);
24906 static void test_geometry_shader(void)
24908 static const struct
24910 struct vec4 position;
24911 unsigned int color;
24913 vertex[] =
24915 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
24917 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
24919 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
24920 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
24922 #if 0
24923 struct vs_data
24925 float4 pos : SV_POSITION;
24926 float4 color : COLOR;
24929 void main(in struct vs_data vs_input, out struct vs_data vs_output)
24931 vs_output.pos = vs_input.pos;
24932 vs_output.color = vs_input.color;
24934 #endif
24935 static const DWORD vs_code[] =
24937 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
24938 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
24939 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
24940 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
24941 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
24942 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
24943 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
24944 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
24945 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
24946 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
24947 0x0100003e,
24949 #if 0
24950 struct gs_data
24952 float4 pos : SV_POSITION;
24953 float4 color : COLOR;
24956 [maxvertexcount(4)]
24957 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
24959 float offset = 0.2 * vin[0].pos.w;
24960 gs_data v;
24962 v.color = vin[0].color;
24964 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
24965 vout.Append(v);
24966 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
24967 vout.Append(v);
24968 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
24969 vout.Append(v);
24970 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
24971 vout.Append(v);
24973 #endif
24974 static const DWORD gs_code[] =
24976 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
24977 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
24978 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
24979 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
24980 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
24981 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
24982 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
24983 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
24984 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
24985 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
24986 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
24987 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
24988 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
24989 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
24990 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
24991 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
24992 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
24993 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
24994 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
24995 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
24996 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
24997 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
24998 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
24999 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
25000 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
25001 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
25002 0x00000001, 0x01000013, 0x0100003e,
25004 static const DWORD gs_5_0_code[] =
25006 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
25007 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25008 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
25009 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25010 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
25011 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
25012 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
25013 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
25014 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
25015 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25016 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
25017 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
25018 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
25019 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
25020 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25021 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
25022 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
25023 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
25024 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
25025 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
25026 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
25027 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
25028 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
25029 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
25030 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
25031 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
25032 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
25033 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
25034 0x0100003e,
25036 #if 0
25037 struct ps_data
25039 float4 pos : SV_POSITION;
25040 float4 color : COLOR;
25043 float4 main(struct ps_data ps_input) : SV_Target
25045 return ps_input.color;
25047 #endif
25048 static const DWORD ps_code[] =
25050 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
25051 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25052 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
25053 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25054 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
25055 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
25056 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
25057 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
25059 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
25060 struct d3d11_test_context test_context;
25061 ID3D11InputLayout *input_layout;
25062 ID3D11DeviceContext *context;
25063 unsigned int stride, offset;
25064 struct resource_readback rb;
25065 ID3D11GeometryShader *gs;
25066 ID3D11VertexShader *vs;
25067 ID3D11PixelShader *ps;
25068 ID3D11Device *device;
25069 ID3D11Buffer *vb;
25070 DWORD color;
25071 HRESULT hr;
25073 if (!init_test_context(&test_context, NULL))
25074 return;
25076 device = test_context.device;
25077 context = test_context.immediate_context;
25079 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
25080 vs_code, sizeof(vs_code), &input_layout);
25081 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
25083 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
25085 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
25086 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
25087 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
25088 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
25089 else
25090 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
25091 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
25092 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
25093 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25095 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
25096 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
25097 stride = sizeof(*vertex);
25098 offset = 0;
25099 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
25100 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
25101 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
25102 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25104 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
25105 ID3D11DeviceContext_Draw(context, 1, 0);
25107 get_texture_readback(test_context.backbuffer, 0, &rb);
25108 color = get_readback_color(&rb, 320, 190, 0);
25109 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25110 color = get_readback_color(&rb, 255, 240, 0);
25111 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25112 color = get_readback_color(&rb, 320, 240, 0);
25113 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
25114 color = get_readback_color(&rb, 385, 240, 0);
25115 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25116 color = get_readback_color(&rb, 320, 290, 0);
25117 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25118 release_resource_readback(&rb);
25120 ID3D11PixelShader_Release(ps);
25121 ID3D11GeometryShader_Release(gs);
25122 ID3D11VertexShader_Release(vs);
25123 ID3D11Buffer_Release(vb);
25124 ID3D11InputLayout_Release(input_layout);
25125 release_test_context(&test_context);
25128 struct triangle
25130 struct vec4 v[3];
25133 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
25134 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
25135 const struct triangle *triangles, unsigned int triangle_count)
25137 const struct triangle *current, *expected;
25138 struct resource_readback rb;
25139 unsigned int i, j, offset;
25140 BOOL all_match = TRUE;
25142 get_buffer_readback(buffer, &rb);
25144 for (i = 0; i < triangle_count; ++i)
25146 current = get_readback_data(&rb, i, 0, 0, sizeof(*current));
25147 expected = &triangles[i];
25149 offset = ~0u;
25150 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
25152 if (compare_vec4(&current->v[0], &expected->v[j], 0))
25154 offset = j;
25155 break;
25159 if (offset == ~0u)
25161 all_match = FALSE;
25162 break;
25165 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
25167 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
25169 all_match = FALSE;
25170 break;
25173 if (!all_match)
25174 break;
25177 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
25178 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
25179 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
25180 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
25181 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
25182 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
25183 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
25184 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
25185 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
25186 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
25188 release_resource_readback(&rb);
25191 static void test_quad_tessellation(void)
25193 #if 0
25194 struct point_data
25196 float4 position : SV_POSITION;
25199 struct patch_constant_data
25201 float edges[4] : SV_TessFactor;
25202 float inside[2] : SV_InsideTessFactor;
25205 float4 tess_factors;
25206 float2 inside_tess_factors;
25208 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
25210 patch_constant_data output;
25212 output.edges[0] = tess_factors.x;
25213 output.edges[1] = tess_factors.y;
25214 output.edges[2] = tess_factors.z;
25215 output.edges[3] = tess_factors.w;
25216 output.inside[0] = inside_tess_factors.x;
25217 output.inside[1] = inside_tess_factors.y;
25219 return output;
25222 [domain("quad")]
25223 [outputcontrolpoints(4)]
25224 [outputtopology("triangle_ccw")]
25225 [partitioning("integer")]
25226 [patchconstantfunc("patch_constant")]
25227 point_data hs_main(InputPatch<point_data, 4> input,
25228 uint i : SV_OutputControlPointID)
25230 return input[i];
25233 [domain("quad")]
25234 point_data ds_main(patch_constant_data input,
25235 float2 tess_coord : SV_DomainLocation,
25236 const OutputPatch<point_data, 4> patch)
25238 point_data output;
25240 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
25241 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
25242 output.position = lerp(a, b, tess_coord.y);
25244 return output;
25246 #endif
25247 static const DWORD hs_quad_ccw_code[] =
25249 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
25250 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25251 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25252 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
25253 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
25254 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
25255 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
25256 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
25257 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
25258 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
25259 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
25260 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
25261 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
25262 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
25263 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
25264 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25265 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
25266 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
25267 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25268 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
25269 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
25270 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
25272 static const DWORD ds_quad_code[] =
25274 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
25275 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25276 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25277 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
25278 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
25279 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
25280 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
25281 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
25282 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
25283 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
25284 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
25285 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
25286 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25287 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
25288 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
25289 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
25290 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
25291 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
25292 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
25293 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
25294 0x0100003e,
25296 #if 0
25298 [outputtopology("triangle_cw")]
25300 #endif
25301 static const DWORD hs_quad_cw_code[] =
25303 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
25304 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25305 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25306 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
25307 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
25308 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
25309 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
25310 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
25311 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
25312 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
25313 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
25314 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
25315 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
25316 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
25317 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
25318 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25319 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
25320 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
25321 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25322 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
25323 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
25324 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
25326 #if 0
25327 struct point_data
25329 float4 pos : SV_POSITION;
25332 [maxvertexcount(3)]
25333 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
25335 for (uint i = 0; i < 3; ++i)
25336 vout.Append(vin[i]);
25338 #endif
25339 static const DWORD gs_code[] =
25341 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
25342 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
25343 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
25344 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
25345 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
25346 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
25347 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
25348 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
25349 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
25350 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
25351 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
25352 0x0100003e,
25354 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
25356 {0, "SV_POSITION", 0, 0, 4, 0},
25358 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25359 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
25360 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
25361 static const BYTE zero_data[1024];
25362 static const struct triangle expected_quad_ccw[] =
25364 {{{-1.0f, -1.0f, 0.0f, 1.0f},
25365 { 1.0f, -1.0f, 0.0f, 1.0f},
25366 {-1.0f, 1.0f, 0.0f, 1.0f}}},
25367 {{{-1.0f, 1.0f, 0.0f, 1.0f},
25368 { 1.0f, -1.0f, 0.0f, 1.0f},
25369 { 1.0f, 1.0f, 0.0f, 1.0f}}},
25370 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
25371 { 0.0f, 0.0f, 0.0f, 0.0f},
25372 { 0.0f, 0.0f, 0.0f, 0.0f}}},
25374 static const struct triangle expected_quad_cw[] =
25376 {{{-1.0f, -1.0f, 0.0f, 1.0f},
25377 {-1.0f, 1.0f, 0.0f, 1.0f},
25378 { 1.0f, -1.0f, 0.0f, 1.0f}}},
25379 {{{-1.0f, 1.0f, 0.0f, 1.0f},
25380 { 1.0f, 1.0f, 0.0f, 1.0f},
25381 { 1.0f, -1.0f, 0.0f, 1.0f}}},
25382 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
25383 { 0.0f, 0.0f, 0.0f, 0.0f},
25384 { 0.0f, 0.0f, 0.0f, 0.0f}}},
25386 struct
25388 float tess_factors[4];
25389 float inside_tess_factors[2];
25390 DWORD padding[2];
25391 } constant;
25393 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
25394 struct d3d11_test_context test_context;
25395 ID3D11DeviceContext *context;
25396 ID3D11Buffer *cb, *so_buffer;
25397 D3D11_QUERY_DESC query_desc;
25398 ID3D11Asynchronous *query;
25399 ID3D11GeometryShader *gs;
25400 ID3D11DomainShader *ds;
25401 const UINT offset = 0;
25402 ID3D11HullShader *hs;
25403 ID3D11Device *device;
25404 unsigned int i;
25405 HRESULT hr;
25407 if (!init_test_context(&test_context, &feature_level))
25408 return;
25410 device = test_context.device;
25411 context = test_context.immediate_context;
25413 draw_color_quad(&test_context, &white);
25414 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25416 set_quad_color(&test_context, &green);
25417 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
25419 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
25420 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
25421 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
25422 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
25423 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
25425 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
25426 constant.tess_factors[i] = 1.0f;
25427 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
25428 constant.inside_tess_factors[i] = 1.0f;
25429 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
25430 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
25431 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
25432 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
25433 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
25434 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
25435 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
25436 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
25438 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25439 ID3D11DeviceContext_Draw(context, 4, 0);
25440 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25441 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
25442 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
25444 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
25446 ID3D11HullShader_Release(hs);
25447 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
25448 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
25449 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
25451 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25452 ID3D11DeviceContext_Draw(context, 4, 0);
25453 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
25454 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
25455 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
25457 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
25459 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25460 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
25461 query_desc.MiscFlags = 0;
25462 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
25463 ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
25464 ID3D11DeviceContext_Begin(context, query);
25466 set_quad_color(&test_context, &white);
25467 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
25468 constant.tess_factors[i] = 2.0f;
25469 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25470 ID3D11DeviceContext_Draw(context, 4, 0);
25471 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25473 set_quad_color(&test_context, &green);
25474 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
25475 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25476 ID3D11DeviceContext_Draw(context, 4, 0);
25477 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25479 ID3D11DeviceContext_End(context, query);
25480 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
25481 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
25482 (unsigned int)so_statistics.NumPrimitivesWritten);
25483 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
25484 (unsigned int)so_statistics.PrimitivesStorageNeeded);
25485 ID3D11DeviceContext_Begin(context, query);
25487 constant.tess_factors[0] = 5.0f;
25488 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25489 ID3D11DeviceContext_Draw(context, 4, 0);
25490 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
25492 ID3D11DeviceContext_End(context, query);
25493 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
25494 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
25495 (unsigned int)so_statistics.NumPrimitivesWritten);
25496 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
25497 (unsigned int)so_statistics.PrimitivesStorageNeeded);
25498 ID3D11Asynchronous_Release(query);
25500 ID3D11Buffer_Release(so_buffer);
25501 ID3D11GeometryShader_Release(gs);
25502 ID3D11DomainShader_Release(ds);
25503 ID3D11HullShader_Release(hs);
25504 ID3D11Buffer_Release(cb);
25505 release_test_context(&test_context);
25508 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
25509 static void check_so_desc_(unsigned int line, ID3D11Device *device,
25510 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
25511 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
25512 unsigned int rasterizer_stream)
25514 ID3D11GeometryShader *gs;
25515 HRESULT hr;
25517 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
25518 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
25519 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
25520 if (SUCCEEDED(hr))
25521 ID3D11GeometryShader_Release(gs);
25524 #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)
25525 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
25526 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
25527 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
25528 unsigned int rasterizer_stream)
25530 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
25531 HRESULT hr;
25533 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
25534 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
25535 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
25536 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
25537 if (SUCCEEDED(hr))
25538 ID3D11GeometryShader_Release(gs);
25541 static void test_stream_output(void)
25543 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
25544 struct d3d11_test_context test_context;
25545 unsigned int i, count;
25546 ID3D11Device *device;
25548 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25549 static const DWORD vs_code[] =
25551 #if 0
25552 struct data
25554 float4 position : SV_Position;
25555 float4 attrib1 : ATTRIB1;
25556 float3 attrib2 : attrib2;
25557 float2 attrib3 : ATTriB3;
25558 float attrib4 : ATTRIB4;
25561 void main(in data i, out data o)
25563 o = i;
25565 #endif
25566 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
25567 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
25568 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
25569 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
25570 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
25571 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
25572 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
25573 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
25574 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
25575 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
25576 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
25577 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
25578 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
25579 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
25580 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25581 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
25582 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
25583 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
25584 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
25585 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
25587 static const DWORD gs_code[] =
25589 #if 0
25590 struct data
25592 float4 position : SV_Position;
25593 float4 attrib1 : ATTRIB1;
25594 float3 attrib2 : attrib2;
25595 float2 attrib3 : ATTriB3;
25596 float attrib4 : ATTRIB4;
25599 [maxvertexcount(1)]
25600 void main(point data i[1], inout PointStream<data> o)
25602 o.Append(i[0]);
25604 #endif
25605 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
25606 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
25607 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
25608 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
25609 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
25610 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
25611 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
25612 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
25613 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
25614 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
25615 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
25616 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
25617 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
25618 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
25619 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
25620 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25621 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
25622 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
25623 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25624 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
25625 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
25627 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
25629 {0, "SV_Position", 0, 0, 4, 0},
25631 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
25633 {0, "SV_Position", 0, 0, 4, 0},
25634 {0, NULL, 0, 0, 0, 0},
25636 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
25638 /* SemanticName and SemanticIndex */
25640 {0, "sv_position", 0, 0, 4, 0},
25641 {0, "attrib", 1, 0, 4, 0},
25644 {0, "sv_position", 0, 0, 4, 0},
25645 {0, "ATTRIB", 1, 0, 4, 0},
25647 /* Gaps */
25649 {0, "SV_POSITION", 0, 0, 4, 0},
25650 {0, NULL, 0, 0, 8, 0},
25651 {0, "ATTRIB", 1, 0, 4, 0},
25654 {0, "SV_POSITION", 0, 0, 4, 0},
25655 {0, NULL, 0, 0, 4, 0},
25656 {0, NULL, 0, 0, 4, 0},
25657 {0, "ATTRIB", 1, 0, 4, 0},
25659 /* ComponentCount */
25661 {0, "ATTRIB", 1, 0, 4, 0},
25664 {0, "ATTRIB", 2, 0, 3, 0},
25667 {0, "ATTRIB", 3, 0, 2, 0},
25670 {0, "ATTRIB", 4, 0, 1, 0},
25672 /* ComponentIndex */
25674 {0, "ATTRIB", 1, 1, 3, 0},
25677 {0, "ATTRIB", 1, 2, 2, 0},
25680 {0, "ATTRIB", 1, 3, 1, 0},
25683 {0, "ATTRIB", 3, 1, 1, 0},
25685 /* OutputSlot */
25687 {0, "attrib", 1, 0, 4, 0},
25690 {0, "attrib", 1, 0, 4, 1},
25693 {0, "attrib", 1, 0, 4, 2},
25696 {0, "attrib", 1, 0, 4, 3},
25699 {0, "attrib", 1, 0, 4, 0},
25700 {0, "attrib", 2, 0, 3, 1},
25701 {0, NULL, 0, 0, 1, 1},
25702 {0, "attrib", 3, 0, 2, 2},
25703 {0, NULL, 0, 0, 2, 2},
25704 {0, "attrib", 4, 0, 1, 3},
25705 {0, NULL, 0, 0, 7, 3},
25708 {0, "attrib", 1, 0, 4, 0},
25709 {0, "attrib", 2, 0, 3, 1},
25710 {0, NULL, 0, 0, 1, 1},
25711 {0, "attrib", 3, 0, 2, 2},
25712 {0, NULL, 0, 0, 1, 2},
25713 {0, NULL, 0, 0, 1, 2},
25714 {0, "attrib", 4, 0, 1, 3},
25715 {0, NULL, 0, 0, 3, 3},
25716 {0, NULL, 0, 0, 1, 3},
25717 {0, NULL, 0, 0, 1, 3},
25718 {0, NULL, 0, 0, 1, 3},
25719 {0, NULL, 0, 0, 1, 3},
25722 {0, "attrib", 1, 0, 4, 0},
25723 {0, "attrib", 2, 0, 3, 0},
25724 {0, "attrib", 3, 0, 2, 0},
25725 {0, NULL, 0, 0, 1, 0},
25726 {0, "attrib", 4, 0, 1, 0},
25729 {0, "attrib", 1, 0, 4, 0},
25730 {0, "attrib", 2, 0, 3, 0},
25731 {0, "attrib", 3, 0, 2, 3},
25732 {0, NULL, 0, 0, 1, 3},
25733 {0, "attrib", 4, 0, 1, 3},
25735 /* Multiple occurrences of the same output */
25737 {0, "ATTRIB", 1, 0, 2, 0},
25738 {0, "ATTRIB", 1, 2, 2, 1},
25741 {0, "ATTRIB", 1, 0, 1, 0},
25742 {0, "ATTRIB", 1, 1, 3, 0},
25745 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
25747 /* SemanticName and SemanticIndex */
25749 {0, "SV_Position", 0, 0, 4, 0},
25750 {0, "ATTRIB", 0, 0, 4, 0},
25753 {0, "sv_position", 0, 0, 4, 0},
25754 {0, "ATTRIB_", 1, 0, 4, 0},
25756 /* Gaps */
25758 {0, "SV_POSITION", 0, 0, 4, 0},
25759 {0, NULL, 0, 1, 8, 0},
25760 {0, "ATTRIB", 1, 0, 4, 0},
25763 {0, "SV_POSITION", 0, 0, 4, 0},
25764 {0, NULL, 1, 0, 8, 0},
25765 {0, "ATTRIB", 1, 0, 4, 0},
25767 /* Buffer stride */
25769 {0, "SV_POSITION", 0, 0, 4, 0},
25770 {0, NULL, 0, 0, 8, 0},
25771 {0, NULL, 0, 0, 8, 0},
25772 {0, "ATTRIB", 1, 0, 4, 0},
25774 /* ComponentCount */
25776 {0, "ATTRIB", 2, 0, 5, 0},
25779 {0, "ATTRIB", 2, 0, 4, 0},
25782 {0, "ATTRIB", 3, 0, 3, 0},
25785 {0, "ATTRIB", 4, 0, 2, 0},
25787 /* ComponentIndex */
25789 {0, "ATTRIB", 1, 1, 4, 0},
25792 {0, "ATTRIB", 1, 2, 3, 0},
25795 {0, "ATTRIB", 1, 3, 2, 0},
25798 {0, "ATTRIB", 1, 4, 0, 0},
25801 {0, "ATTRIB", 1, 4, 1, 0},
25804 {0, "ATTRIB", 3, 2, 1, 0},
25807 {0, "ATTRIB", 3, 2, 0, 0},
25809 /* OutputSlot */
25811 {0, "attrib", 1, 0, 4, 4},
25814 {0, "attrib", 1, 0, 4, 4},
25817 {0, "attrib", 1, 0, 4, 4},
25820 {0, "attrib", 1, 0, 4, 4},
25823 {0, "attrib", 1, 0, 4, 0},
25824 {0, "attrib", 2, 0, 3, 1},
25825 {0, NULL, 0, 0, 1, 1},
25826 {0, "attrib", 3, 0, 2, 2},
25827 {0, NULL, 0, 0, 2, 2},
25828 {0, "attrib", 4, 0, 1, 3},
25829 {0, NULL, 0, 0, 3, 4},
25832 {0, "attrib", 1, 0, 4, 0},
25833 {0, "attrib", 2, 0, 3, 0},
25834 {0, "attrib", 3, 0, 2, 0},
25835 {0, NULL, 0, 0, 1, 0},
25836 {0, "attrib", 4, 0, 1, 0},
25837 {0, NULL, 0, 0, 3, 3},
25838 {0, NULL, 0, 0, 1, 3},
25839 {0, NULL, 0, 0, 1, 3},
25840 {0, NULL, 0, 0, 1, 3},
25841 {0, NULL, 0, 0, 1, 3},
25844 {0, "attrib", 1, 0, 4, 0},
25845 {0, NULL, 0, 0, 3, 1},
25846 {0, NULL, 0, 0, 1, 1},
25847 {0, NULL, 0, 0, 1, 2},
25848 {0, "attrib", 2, 0, 3, 3},
25849 {0, NULL, 0, 0, 1, 3},
25852 {0, "attrib", 2, 0, 3, 3},
25853 {0, NULL, 0, 0, 3, 1},
25854 {0, NULL, 0, 0, 1, 3},
25855 {0, "attrib", 1, 0, 4, 0},
25856 {0, NULL, 0, 0, 1, 2},
25857 {0, NULL, 0, 0, 1, 1},
25859 /* Stream */
25861 {1, "attrib", 1, 0, 4, 0},
25864 {4, "attrib", 1, 0, 4, 0},
25866 /* Multiple occurrences of the same output */
25868 {0, "ATTRIB", 1, 0, 4, 0},
25869 {0, "ATTRIB", 1, 0, 4, 1},
25872 {0, "ATTRIB", 1, 0, 4, 0},
25873 {0, "ATTRIB", 1, 0, 3, 0},
25877 if (!init_test_context(&test_context, &feature_level))
25878 return;
25880 device = test_context.device;
25882 for (i = 0; i < ARRAY_SIZE(stride); ++i)
25883 stride[i] = 64;
25885 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25886 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25887 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25888 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25889 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25890 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25892 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
25893 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25894 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
25895 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25897 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
25898 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25899 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
25900 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
25901 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25903 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
25904 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25905 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
25906 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25908 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
25910 unsigned int max_output_slot = 0;
25911 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
25913 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
25914 max_output_slot = max(max_output_slot, e->OutputSlot);
25915 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
25916 break;
25919 /* Buffer strides are required for all buffers. */
25920 if (!max_output_slot)
25922 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25923 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25924 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25925 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25926 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25927 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
25928 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25929 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
25930 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25931 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
25933 else
25935 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25936 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25937 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25938 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
25942 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
25944 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
25946 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
25947 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
25948 break;
25951 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
25952 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25953 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
25954 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
25955 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
25956 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
25957 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
25958 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
25961 /* Buffer strides */
25962 stride[1] = 63;
25963 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25964 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
25965 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25966 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
25967 stride[1] = 1;
25968 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25969 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
25970 stride[0] = 0;
25971 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25972 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25974 /* Rasterizer stream */
25975 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
25976 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
25977 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25978 NULL, 0, D3D11_SO_STREAM_COUNT);
25980 release_test_context(&test_context);
25983 static void test_fl10_stream_output_desc(void)
25985 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
25986 struct d3d11_test_context test_context;
25987 unsigned int i, count;
25988 ID3D11Device *device;
25990 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
25991 static const DWORD vs_code[] =
25993 #if 0
25994 struct data
25996 float4 position : SV_Position;
25997 float4 attrib1 : ATTRIB1;
25998 float3 attrib2 : attrib2;
25999 float2 attrib3 : ATTriB3;
26000 float attrib4 : ATTRIB4;
26003 void main(in data i, out data o)
26005 o = i;
26007 #endif
26008 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
26009 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
26010 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
26011 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26012 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
26013 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
26014 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
26015 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26016 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
26017 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
26018 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
26019 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
26020 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
26021 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
26022 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
26023 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
26024 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
26025 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
26026 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
26027 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
26029 static const DWORD gs_code[] =
26031 #if 0
26032 struct data
26034 float4 position : SV_Position;
26035 float4 attrib1 : ATTRIB1;
26036 float3 attrib2 : attrib2;
26037 float2 attrib3 : ATTriB3;
26038 float attrib4 : ATTRIB4;
26041 [maxvertexcount(1)]
26042 void main(point data i[1], inout PointStream<data> o)
26044 o.Append(i[0]);
26046 #endif
26047 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
26048 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
26049 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
26050 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26051 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
26052 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
26053 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
26054 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26055 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
26056 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
26057 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
26058 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
26059 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
26060 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
26061 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
26062 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
26063 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
26064 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
26065 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
26066 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
26067 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
26069 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26071 {0, "SV_Position", 0, 0, 4, 0},
26073 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
26075 {0, "SV_Position", 0, 0, 4, 0},
26076 {0, NULL, 0, 0, 0, 0},
26078 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
26080 /* Gaps */
26082 {0, "SV_POSITION", 0, 0, 4, 0},
26083 {0, NULL, 0, 0, 8, 0},
26084 {0, "ATTRIB", 1, 0, 4, 0},
26087 {0, "SV_POSITION", 0, 0, 4, 0},
26088 {0, NULL, 0, 0, 4, 0},
26089 {0, NULL, 0, 0, 4, 0},
26090 {0, "ATTRIB", 1, 0, 4, 0},
26092 /* OutputSlot */
26094 {0, "attrib", 1, 0, 4, 0},
26095 {0, "attrib", 2, 0, 3, 0},
26096 {0, "attrib", 3, 0, 2, 0},
26097 {0, "attrib", 4, 0, 1, 0},
26100 {0, "attrib", 1, 0, 4, 0},
26101 {0, "attrib", 2, 0, 3, 1},
26102 {0, "attrib", 3, 0, 2, 2},
26103 {0, "attrib", 4, 0, 1, 3},
26106 {0, "attrib", 1, 0, 4, 0},
26107 {0, "attrib", 2, 0, 3, 3},
26110 {0, "attrib", 1, 0, 4, 0},
26111 {0, "attrib", 2, 0, 3, 0},
26112 {0, "attrib", 3, 0, 2, 0},
26113 {0, NULL, 0, 0, 1, 0},
26114 {0, "attrib", 4, 0, 1, 0},
26116 /* Multiple occurrences of the same output */
26118 {0, "ATTRIB", 1, 0, 2, 0},
26119 {0, "ATTRIB", 1, 2, 2, 1},
26122 {0, "ATTRIB", 1, 0, 1, 0},
26123 {0, "ATTRIB", 1, 1, 3, 0},
26126 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
26128 /* OutputSlot */
26130 {0, "attrib", 1, 0, 4, 0},
26131 {0, NULL, 0, 0, 4, 0},
26132 {0, "attrib", 4, 0, 1, 3},
26135 {0, "attrib", 1, 0, 4, 0},
26136 {0, NULL, 0, 0, 4, 0},
26137 {0, NULL, 0, 0, 4, 0},
26138 {0, "attrib", 4, 0, 1, 3},
26141 {0, "attrib", 1, 0, 4, 0},
26142 {0, "attrib", 2, 0, 3, 0},
26143 {0, "attrib", 3, 0, 2, 0},
26144 {0, "attrib", 4, 0, 1, 1},
26147 {0, "attrib", 1, 0, 4, 0},
26148 {0, "attrib", 2, 0, 3, 0},
26149 {0, "attrib", 3, 0, 2, 3},
26150 {0, NULL, 0, 0, 1, 3},
26151 {0, "attrib", 4, 0, 1, 3},
26154 {0, "attrib", 1, 0, 4, 0},
26155 {0, "attrib", 1, 0, 3, 1},
26156 {0, "attrib", 1, 0, 2, 2},
26157 {0, "attrib", 1, 0, 1, 3},
26158 {0, NULL, 0, 0, 3, 3},
26162 if (!init_test_context(&test_context, &feature_level))
26163 return;
26165 device = test_context.device;
26167 for (i = 0; i < ARRAY_SIZE(stride); ++i)
26168 stride[i] = 64;
26170 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
26171 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
26172 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26173 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
26175 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26176 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
26178 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
26179 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
26180 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
26181 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
26182 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
26184 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
26185 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
26187 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
26189 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
26191 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
26192 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26193 break;
26196 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
26199 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
26201 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
26203 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
26204 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26205 break;
26208 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26209 stride, 1, 0);
26210 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26211 stride, 2, 0);
26212 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26213 stride, 3, 0);
26214 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26215 stride, 4, 0);
26218 /* Buffer strides */
26219 stride[1] = 63;
26220 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26221 &stride[1], 1, 0);
26222 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26223 stride, 2, 0);
26224 stride[0] = 0;
26225 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26226 stride, 1, 0);
26228 /* Rasterizer stream */
26229 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26230 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26231 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
26232 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26233 NULL, 0, i);
26234 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26236 release_test_context(&test_context);
26239 static void test_stream_output_resume(void)
26241 struct d3d11_test_context test_context;
26242 ID3D11Buffer *cb, *so_buffer, *buffer;
26243 unsigned int i, j, idx, offset;
26244 ID3D11DeviceContext *context;
26245 struct resource_readback rb;
26246 ID3D11GeometryShader *gs;
26247 const struct vec4 *data;
26248 ID3D11Device *device;
26249 HRESULT hr;
26251 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26252 static const DWORD gs_code[] =
26254 #if 0
26255 float4 constant;
26257 struct vertex
26259 float4 position : SV_POSITION;
26262 struct element
26264 float4 position : SV_POSITION;
26265 float4 so_output : so_output;
26268 [maxvertexcount(3)]
26269 void main(triangle vertex input[3], inout PointStream<element> output)
26271 element o;
26272 o.so_output = constant;
26273 o.position = input[0].position;
26274 output.Append(o);
26275 o.position = input[1].position;
26276 output.Append(o);
26277 o.position = input[2].position;
26278 output.Append(o);
26280 #endif
26281 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
26282 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26283 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
26284 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
26285 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
26286 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
26287 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
26288 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
26289 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
26290 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
26291 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
26292 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
26293 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
26294 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
26296 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26298 {0, "so_output", 0, 0, 4, 0},
26300 static const struct vec4 constants[] =
26302 {0.5f, 0.250f, 0.0f, 0.0f},
26303 {0.0f, 0.125f, 0.0f, 1.0f},
26304 {1.0f, 1.000f, 1.0f, 0.0f}
26306 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
26307 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
26308 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
26310 if (!init_test_context(&test_context, &feature_level))
26311 return;
26313 device = test_context.device;
26314 context = test_context.immediate_context;
26316 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
26317 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
26318 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
26320 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
26321 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26323 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26324 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
26326 offset = 0;
26327 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
26329 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
26330 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26332 draw_color_quad(&test_context, &red);
26333 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26335 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26336 draw_color_quad(&test_context, &green);
26337 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26339 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
26340 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26341 draw_color_quad(&test_context, &red);
26342 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26344 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26345 draw_color_quad(&test_context, &red);
26346 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
26348 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
26349 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26350 draw_color_quad(&test_context, &white);
26351 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
26353 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26354 draw_color_quad(&test_context, &green);
26355 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26357 buffer = NULL;
26358 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
26359 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26360 draw_color_quad(&test_context, &white);
26361 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26363 idx = 0;
26364 get_buffer_readback(so_buffer, &rb);
26365 for (i = 0; i < ARRAY_SIZE(constants); ++i)
26367 for (j = 0; j < 6; ++j) /* 2 triangles */
26369 data = get_readback_vec4(&rb, idx++, 0);
26370 ok(compare_vec4(data, &constants[i], 0),
26371 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
26372 data->x, data->y, data->z, data->w, idx, i, j);
26375 release_resource_readback(&rb);
26377 ID3D11Buffer_Release(cb);
26378 ID3D11Buffer_Release(so_buffer);
26379 ID3D11GeometryShader_Release(gs);
26380 release_test_context(&test_context);
26383 static void test_stream_output_components(void)
26385 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
26386 struct d3d11_test_context test_context;
26387 ID3D11InputLayout *input_layout[2];
26388 ID3D11Buffer *vb[2], *so_buffer;
26389 ID3D11DeviceContext *context;
26390 struct resource_readback rb;
26391 unsigned int stride, offset;
26392 ID3D11GeometryShader *gs;
26393 ID3D11VertexShader *vs;
26394 ID3D11PixelShader *ps;
26395 ID3D11Device *device;
26396 const float *result;
26397 unsigned int i, j;
26398 HRESULT hr;
26400 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26401 static const DWORD vs_code[] =
26403 #if 0
26404 struct vertex
26406 float4 position : POSITION;
26407 float4 color : COLOR;
26408 float4 color2 : COLOR2;
26411 void main(in vertex i, out vertex o)
26413 o = i;
26415 #endif
26416 0x43425844, 0x95991b76, 0x4898640b, 0xe36ad9d6, 0xfbfe78b4, 0x00000001, 0x00000194, 0x00000003,
26417 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26418 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26419 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26420 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26421 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26422 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
26423 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26424 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
26425 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
26426 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
26427 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
26428 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
26430 static const DWORD gs_code[] =
26432 #if 0
26433 struct vertex
26435 float4 position : POSITION;
26436 float4 color : COLOR;
26437 float4 color2 : COLOR2;
26440 [maxvertexcount(1)]
26441 void main(point vertex input[1], inout PointStream<vertex> output)
26443 output.Append(input[0]);
26445 #endif
26446 0x43425844, 0x218f7d27, 0x555fa7f1, 0x282c545f, 0x3989c843, 0x00000001, 0x000001c0, 0x00000003,
26447 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26448 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26449 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26450 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26451 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26452 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
26453 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26454 0x000000bc, 0x00020040, 0x0000002f, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x0400005f,
26455 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000002, 0x0100085d,
26456 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x03000065,
26457 0x001020f2, 0x00000002, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
26458 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001,
26459 0x06000036, 0x001020f2, 0x00000002, 0x00201e46, 0x00000000, 0x00000002, 0x01000013, 0x0100003e,
26461 static const DWORD ps_code[] =
26463 #if 0
26464 float4 main(float4 position : SV_Position,
26465 float2 texcoord : TEXCOORD) : SV_Target
26467 return float4(position.xy, texcoord);
26469 #endif
26470 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
26471 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
26472 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
26473 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
26474 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
26475 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
26476 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
26477 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
26478 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
26480 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
26482 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26483 {"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26484 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
26486 static const D3D11_INPUT_ELEMENT_DESC layout_desc2[] =
26488 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26489 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26490 {"COLOR", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
26492 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26494 {0, "POSITION", 0, 0, 4, 0},
26495 {0, "COLOR", 0, 0, 3, 0},
26496 {0, "COLOR", 2, 0, 2, 0},
26498 static const D3D11_SO_DECLARATION_ENTRY so_declaration2[] =
26500 {0, "POSITION", 0, 0, 1, 0},
26501 {0, "POSITION", 0, 1, 1, 0},
26502 {0, "POSITION", 0, 2, 1, 0},
26503 {0, "POSITION", 0, 3, 1, 0},
26504 {0, "COLOR", 0, 0, 1, 0},
26505 {0, "COLOR", 0, 1, 1, 0},
26506 {0, "COLOR", 0, 2, 1, 0},
26507 {0, "COLOR", 2, 0, 1, 0},
26508 {0, "COLOR", 2, 1, 1, 0},
26510 static const D3D11_SO_DECLARATION_ENTRY so_declaration3[] =
26512 {0, "COLOR", 0, 2, 2, 0},
26513 {0, "COLOR", 2, 3, 1, 0},
26515 static const struct
26517 struct vec4 position;
26518 struct vec3 color;
26519 struct vec2 color2;
26521 vb_data[] =
26523 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},
26524 {{-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
26525 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.5f, 0.4f}},
26526 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.1f, 0.6f}},
26528 static const struct
26530 struct vec4 position;
26531 struct vec4 color;
26532 struct vec4 color2;
26534 vb_data2[] =
26536 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
26537 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
26538 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
26539 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
26541 static const unsigned int vb_stride[] = {sizeof(*vb_data), sizeof(*vb_data2)};
26542 static const float expected_data[] =
26544 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f,
26545 -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
26546 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.4f,
26547 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.1f, 0.6f,
26549 static const float expected_data2[] =
26551 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
26552 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
26553 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
26554 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
26556 static const float expected_data3[] =
26558 3.0f, 4.0f, 8.0f, 1.2f, 1.3f, 1.7f, 2.0f, 2.1f, 2.5f, 2.7f, 2.8f, 3.2f,
26560 static const struct
26562 BOOL with_ps;
26563 unsigned int vb_idx;
26564 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
26565 unsigned int so_entry_count;
26566 const float *expected_data;
26567 unsigned int expected_data_size;
26569 tests[] =
26571 {TRUE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
26572 {TRUE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
26573 {TRUE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
26574 {TRUE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
26575 {TRUE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
26577 {FALSE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
26578 {FALSE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
26579 {FALSE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
26580 {FALSE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
26581 {FALSE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
26584 if (!init_test_context(&test_context, &feature_level))
26585 return;
26587 device = test_context.device;
26588 context = test_context.immediate_context;
26590 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
26591 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data2), vb_data2);
26593 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
26594 vs_code, sizeof(vs_code), &input_layout[0]);
26595 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26596 hr = ID3D11Device_CreateInputLayout(device, layout_desc2, ARRAY_SIZE(layout_desc2),
26597 vs_code, sizeof(vs_code), &input_layout[1]);
26598 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26600 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
26601 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
26602 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
26603 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
26605 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
26606 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
26608 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26610 gs = NULL;
26611 current_so_declaration = NULL;
26612 for (i = 0; i < ARRAY_SIZE(tests); ++i)
26614 ID3D11DeviceContext_PSSetShader(context, tests[i].with_ps ? ps : NULL, NULL, 0);
26616 if (current_so_declaration != tests[i].so_declaration)
26618 if (gs)
26619 ID3D11GeometryShader_Release(gs);
26621 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
26622 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
26623 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
26624 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
26625 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26626 current_so_declaration = tests[i].so_declaration;
26629 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].vb_idx]);
26630 stride = vb_stride[tests[i].vb_idx];
26631 offset = 0;
26632 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[tests[i].vb_idx], &stride, &offset);
26634 offset = 0;
26635 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
26637 ID3D11DeviceContext_Draw(context, 4, 0);
26639 get_buffer_readback(so_buffer, &rb);
26640 result = rb.map_desc.pData;
26641 for (j = 0; j < tests[i].expected_data_size; ++j)
26643 float expected_value = tests[i].expected_data[j];
26644 ok(compare_float(result[j], expected_value, 2),
26645 "Test %u: Got %.8e, expected %.8e at %u.\n",
26646 i, result[j], expected_value, j);
26648 release_resource_readback(&rb);
26651 for (i = 0; i < ARRAY_SIZE(vb); ++i)
26652 ID3D11Buffer_Release(vb[i]);
26653 ID3D11Buffer_Release(so_buffer);
26654 ID3D11VertexShader_Release(vs);
26655 ID3D11GeometryShader_Release(gs);
26656 ID3D11PixelShader_Release(ps);
26657 for (i = 0; i < ARRAY_SIZE(input_layout); ++i)
26658 ID3D11InputLayout_Release(input_layout[i]);
26659 release_test_context(&test_context);
26662 static void test_stream_output_vs(void)
26664 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
26665 struct d3d11_test_context test_context;
26666 ID3D11InputLayout *input_layout;
26667 ID3D11Buffer *vb, *so_buffer;
26668 ID3D11DeviceContext *context;
26669 struct resource_readback rb;
26670 ID3D11GeometryShader *gs;
26671 ID3D11VertexShader *vs;
26672 ID3D11Device *device;
26673 const float *result;
26674 unsigned int offset;
26675 unsigned int i, j;
26676 HRESULT hr;
26678 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26679 static const DWORD vs_code[] =
26681 #if 0
26682 struct vertex
26684 float4 position : POSITION;
26685 float4 color0 : COLOR0;
26686 float4 color1 : COLOR1;
26689 vertex main(in vertex i)
26691 return i;
26693 #endif
26694 0x43425844, 0xa67e993e, 0x1632c139, 0x02a7725f, 0xfb0221cd, 0x00000001, 0x00000194, 0x00000003,
26695 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26696 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26697 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
26698 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26699 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26700 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000001, 0x00000000,
26701 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26702 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
26703 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
26704 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
26705 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
26706 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
26708 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
26710 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26711 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26712 {"COLOR", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
26714 static const D3D11_SO_DECLARATION_ENTRY all_so_decl[] =
26716 {0, "POSITION", 0, 0, 4, 0},
26717 {0, "COLOR", 0, 0, 3, 0},
26718 {0, "COLOR", 1, 0, 2, 0},
26720 static const D3D11_SO_DECLARATION_ENTRY position_so_decl[] =
26722 {0, "POSITION", 0, 0, 4, 0},
26724 static const D3D11_SO_DECLARATION_ENTRY position2_so_decl[] =
26726 {0, "POSITION", 0, 0, 2, 0},
26728 static const struct
26730 struct vec4 position;
26731 struct vec4 color0;
26732 struct vec4 color1;
26734 vb_data[] =
26736 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
26737 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
26738 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
26739 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
26741 static const unsigned int vb_stride[] = {sizeof(*vb_data)};
26742 static const float expected_data[] =
26744 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
26745 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
26746 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
26747 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
26749 static const float expected_data2[] =
26751 -1.0f, -1.0f, 0.0f, 1.0f,
26752 -1.0f, 1.0f, 0.0f, 1.0f,
26753 1.0f, -1.0f, 0.0f, 1.0f,
26754 1.0f, 1.0f, 0.0f, 1.0f,
26756 static const float expected_data3[] =
26758 -1.0f, -1.0f,
26759 -1.0f, 1.0f,
26760 1.0f, -1.0f,
26761 1.0f, 1.0f,
26763 static const struct
26765 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
26766 unsigned int so_entry_count;
26767 const float *expected_data;
26768 unsigned int expected_data_size;
26770 tests[] =
26772 {all_so_decl, ARRAY_SIZE(all_so_decl), expected_data, ARRAY_SIZE(expected_data)},
26773 {position_so_decl, ARRAY_SIZE(position_so_decl), expected_data2, ARRAY_SIZE(expected_data2)},
26774 {position2_so_decl, ARRAY_SIZE(position2_so_decl), expected_data3, ARRAY_SIZE(expected_data3)},
26777 if (!init_test_context(&test_context, &feature_level))
26778 return;
26780 device = test_context.device;
26781 context = test_context.immediate_context;
26783 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
26785 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
26786 vs_code, sizeof(vs_code), &input_layout);
26787 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26789 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
26790 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
26792 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26794 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
26795 offset = 0;
26796 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, vb_stride, &offset);
26797 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
26799 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
26801 gs = NULL;
26802 current_so_declaration = NULL;
26803 for (i = 0; i < ARRAY_SIZE(tests); ++i)
26805 if (current_so_declaration != tests[i].so_declaration)
26807 if (gs)
26808 ID3D11GeometryShader_Release(gs);
26810 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
26811 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
26812 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
26813 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
26814 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26815 current_so_declaration = tests[i].so_declaration;
26818 offset = 0;
26819 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
26821 ID3D11DeviceContext_Draw(context, 4, 0);
26823 get_buffer_readback(so_buffer, &rb);
26824 result = rb.map_desc.pData;
26825 for (j = 0; j < tests[i].expected_data_size; ++j)
26827 float expected_value = tests[i].expected_data[j];
26828 ok(compare_float(result[j], expected_value, 2),
26829 "Test %u: Got %.8e, expected %.8e at %u.\n",
26830 i, result[j], expected_value, j);
26832 release_resource_readback(&rb);
26835 ID3D11Buffer_Release(vb);
26836 ID3D11Buffer_Release(so_buffer);
26837 ID3D11VertexShader_Release(vs);
26838 ID3D11GeometryShader_Release(gs);
26839 ID3D11InputLayout_Release(input_layout);
26840 release_test_context(&test_context);
26843 static void test_gather(void)
26845 struct
26847 int width, height;
26848 int offset_x, offset_y;
26849 } constant;
26850 struct d3d11_test_context test_context;
26851 D3D11_TEXTURE2D_DESC texture_desc;
26852 ID3D11ShaderResourceView *srv;
26853 ID3D11Texture2D *texture, *rt;
26854 ID3D11DeviceContext *context;
26855 ID3D11RenderTargetView *rtv;
26856 struct resource_readback rb;
26857 ID3D11PixelShader *ps;
26858 ID3D11Device *device;
26859 unsigned int x, y;
26860 ID3D11Buffer *cb;
26861 HRESULT hr;
26863 static const DWORD gather4_code[] =
26865 #if 0
26866 SamplerState s;
26867 Texture2D<float4> t;
26869 int2 size;
26871 float4 main(float4 position : SV_Position) : SV_Target
26873 return t.Gather(s, position.xy / size);
26875 #endif
26876 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
26877 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26878 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26879 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26880 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
26881 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
26882 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
26883 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
26884 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
26885 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
26886 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
26888 static const DWORD gather4_offset_code[] =
26890 #if 0
26891 SamplerState s;
26892 Texture2D<float4> t;
26894 int2 size;
26896 float4 main(float4 position : SV_Position) : SV_Target
26898 return t.Gather(s, position.xy / size, int2(1, 1));
26900 #endif
26901 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
26902 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26903 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26904 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26905 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
26906 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
26907 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
26908 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
26909 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
26910 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
26911 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
26913 static const DWORD gather4_green_code[] =
26915 #if 0
26916 SamplerState s;
26917 Texture2D<float4> t;
26919 int2 size;
26921 float4 main(float4 position : SV_Position) : SV_Target
26923 return t.GatherGreen(s, position.xy / size);
26925 #endif
26926 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
26927 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26928 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26929 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26930 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
26931 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
26932 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
26933 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
26934 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
26935 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
26936 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
26938 static const DWORD gather4_po_code[] =
26940 #if 0
26941 SamplerState s;
26942 Texture2D<float4> t;
26944 int2 size;
26945 int2 offset;
26947 float4 main(float4 position : SV_Position) : SV_Target
26949 return t.Gather(s, position.xy / size, offset);
26951 #endif
26952 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
26953 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26954 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26955 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26956 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
26957 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
26958 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
26959 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
26960 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
26961 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
26962 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
26963 0x00000000, 0x0100003e,
26965 static const struct vec4 texture_data[] =
26967 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
26968 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
26969 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
26970 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
26972 static const struct vec4 expected_gather4[] =
26974 {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},
26975 {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},
26976 {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},
26977 {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},
26979 static const struct vec4 expected_gather4_offset[] =
26981 {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},
26982 {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},
26983 {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},
26984 {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},
26986 static const struct vec4 expected_gather4_green[] =
26988 {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},
26989 {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},
26990 {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},
26991 {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},
26993 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
26994 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
26996 if (!init_test_context(&test_context, NULL))
26997 return;
26999 device = test_context.device;
27000 context = test_context.immediate_context;
27002 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
27004 skip("Shader model 4.1 required for gather4 instruction.\n");
27005 release_test_context(&test_context);
27006 return;
27009 texture_desc.Width = 4;
27010 texture_desc.Height = 4;
27011 texture_desc.MipLevels = 1;
27012 texture_desc.ArraySize = 1;
27013 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27014 texture_desc.SampleDesc.Count = 1;
27015 texture_desc.SampleDesc.Quality = 0;
27016 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27017 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27018 texture_desc.CPUAccessFlags = 0;
27019 texture_desc.MiscFlags = 0;
27020 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27021 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27022 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27023 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27024 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27026 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
27027 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
27028 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27029 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
27030 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
27031 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
27033 constant.width = texture_desc.Width;
27034 constant.height = texture_desc.Height;
27035 constant.offset_x = 1;
27036 constant.offset_y = 1;
27037 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
27038 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
27040 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
27041 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27042 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27044 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27045 draw_quad(&test_context);
27046 get_texture_readback(rt, 0, &rb);
27047 for (y = 0; y < texture_desc.Height; ++y)
27049 for (x = 0; x < texture_desc.Width; ++x)
27051 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
27052 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27053 ok(compare_vec4(got, expected, 0),
27054 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27055 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27058 release_resource_readback(&rb);
27060 ID3D11PixelShader_Release(ps);
27061 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
27062 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27063 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27065 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27066 draw_quad(&test_context);
27067 get_texture_readback(rt, 0, &rb);
27068 for (y = 0; y < texture_desc.Height; ++y)
27070 for (x = 0; x < texture_desc.Width; ++x)
27072 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
27073 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27074 ok(compare_vec4(got, expected, 0),
27075 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27076 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27079 release_resource_readback(&rb);
27081 ID3D11PixelShader_Release(ps);
27083 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
27085 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
27086 goto done;
27089 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
27090 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27091 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27093 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27094 draw_quad(&test_context);
27095 get_texture_readback(rt, 0, &rb);
27096 for (y = 0; y < texture_desc.Height; ++y)
27098 for (x = 0; x < texture_desc.Width; ++x)
27100 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
27101 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27102 ok(compare_vec4(got, expected, 0),
27103 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27104 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27107 release_resource_readback(&rb);
27109 ID3D11PixelShader_Release(ps);
27110 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
27111 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27112 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27114 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27115 draw_quad(&test_context);
27116 get_texture_readback(rt, 0, &rb);
27117 for (y = 0; y < texture_desc.Height; ++y)
27119 for (x = 0; x < texture_desc.Width; ++x)
27121 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
27122 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27123 ok(compare_vec4(got, expected, 0),
27124 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27125 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27128 release_resource_readback(&rb);
27130 constant.offset_x = 0;
27131 constant.offset_y = 0;
27132 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
27133 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27134 draw_quad(&test_context);
27135 get_texture_readback(rt, 0, &rb);
27136 for (y = 0; y < texture_desc.Height; ++y)
27138 for (x = 0; x < texture_desc.Width; ++x)
27140 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
27141 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27142 ok(compare_vec4(got, expected, 0),
27143 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27144 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27147 release_resource_readback(&rb);
27149 ID3D11PixelShader_Release(ps);
27151 done:
27152 ID3D11Buffer_Release(cb);
27153 ID3D11Texture2D_Release(rt);
27154 ID3D11Texture2D_Release(texture);
27155 ID3D11RenderTargetView_Release(rtv);
27156 ID3D11ShaderResourceView_Release(srv);
27157 release_test_context(&test_context);
27160 static void test_gather_c(void)
27162 struct
27164 int width, height;
27165 int offset_x, offset_y;
27166 float compare_value;
27167 int padding[3];
27168 } constant;
27169 struct d3d11_test_context test_context;
27170 D3D11_TEXTURE2D_DESC texture_desc;
27171 D3D11_SAMPLER_DESC sampler_desc;
27172 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
27173 ID3D11ShaderResourceView *srv;
27174 ID3D11Texture2D *texture, *rt;
27175 ID3D11DeviceContext *context;
27176 ID3D11SamplerState *sampler;
27177 ID3D11RenderTargetView *rtv;
27178 struct resource_readback rb;
27179 ID3D11PixelShader *ps;
27180 ID3D11Device *device;
27181 unsigned int x, y;
27182 ID3D11Buffer *cb;
27183 HRESULT hr;
27185 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27186 static const DWORD gather4_c_code[] =
27188 #if 0
27189 SamplerComparisonState s;
27190 Texture2D<float4> t;
27192 int2 size;
27193 int2 offset;
27194 float compare;
27196 float4 main(float4 position : SV_Position) : SV_Target
27198 return t.GatherCmp(s, position.xy / size, compare);
27200 #endif
27201 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
27202 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27203 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27204 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27205 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
27206 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
27207 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27208 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27209 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27210 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27211 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
27212 0x00000001, 0x0100003e,
27214 static const DWORD gather4_po_c_code[] =
27216 #if 0
27217 SamplerComparisonState s;
27218 Texture2D<float4> t;
27220 int2 size;
27221 int2 offset;
27222 float compare;
27224 float4 main(float4 position : SV_Position) : SV_Target
27226 return t.GatherCmp(s, position.xy / size, compare, offset);
27228 #endif
27229 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
27230 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27231 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27232 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27233 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
27234 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
27235 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27236 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27237 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27238 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27239 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
27240 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
27242 static const float texture_data[] =
27244 0.00f, 0.10f, 0.20f, 0.30f,
27245 0.40f, 0.50f, 0.60f, 0.70f,
27246 0.80f, 0.90f, 0.05f, 0.15f,
27247 0.25f, 0.35f, 0.45f, 0.55f,
27249 static const struct vec4 expected_gather4_c[] =
27251 {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},
27252 {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},
27253 {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},
27254 {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},
27256 static const struct vec4 expected_gather4_po_c[] =
27258 {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},
27259 {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},
27260 {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},
27261 {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},
27263 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
27264 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
27266 if (!init_test_context(&test_context, &feature_level))
27267 return;
27269 device = test_context.device;
27270 context = test_context.immediate_context;
27272 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
27273 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
27274 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
27275 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
27276 sampler_desc.MipLODBias = 0.0f;
27277 sampler_desc.MaxAnisotropy = 0;
27278 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
27279 sampler_desc.BorderColor[0] = 0.0f;
27280 sampler_desc.BorderColor[1] = 0.0f;
27281 sampler_desc.BorderColor[2] = 0.0f;
27282 sampler_desc.BorderColor[3] = 0.0f;
27283 sampler_desc.MinLOD = 0.0f;
27284 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
27286 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
27287 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
27288 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
27290 texture_desc.Width = 4;
27291 texture_desc.Height = 4;
27292 texture_desc.MipLevels = 1;
27293 texture_desc.ArraySize = 1;
27294 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27295 texture_desc.SampleDesc.Count = 1;
27296 texture_desc.SampleDesc.Quality = 0;
27297 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27298 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27299 texture_desc.CPUAccessFlags = 0;
27300 texture_desc.MiscFlags = 0;
27301 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27302 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27303 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27304 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27305 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27307 constant.width = texture_desc.Width;
27308 constant.height = texture_desc.Height;
27309 constant.offset_x = 1;
27310 constant.offset_y = 1;
27311 constant.compare_value = 0.5f;
27312 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
27313 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
27315 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
27316 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
27317 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
27318 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27320 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
27321 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
27322 U(srv_desc).Texture2D.MostDetailedMip = 0;
27323 U(srv_desc).Texture2D.MipLevels = 1;
27324 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
27325 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
27326 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
27328 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
27329 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27330 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27332 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27333 draw_quad(&test_context);
27334 get_texture_readback(rt, 0, &rb);
27335 for (y = 0; y < texture_desc.Height; ++y)
27337 for (x = 0; x < texture_desc.Width; ++x)
27339 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
27340 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27341 ok(compare_vec4(got, expected, 0),
27342 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27343 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27346 release_resource_readback(&rb);
27347 ID3D11PixelShader_Release(ps);
27349 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
27350 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27351 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27353 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27354 draw_quad(&test_context);
27355 get_texture_readback(rt, 0, &rb);
27356 for (y = 0; y < texture_desc.Height; ++y)
27358 for (x = 0; x < texture_desc.Width; ++x)
27360 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
27361 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27362 ok(compare_vec4(got, expected, 0),
27363 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27364 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27367 release_resource_readback(&rb);
27368 ID3D11PixelShader_Release(ps);
27370 ID3D11ShaderResourceView_Release(srv);
27371 ID3D11Texture2D_Release(texture);
27373 ID3D11Buffer_Release(cb);
27374 ID3D11Texture2D_Release(rt);
27375 ID3D11RenderTargetView_Release(rtv);
27376 ID3D11SamplerState_Release(sampler);
27377 release_test_context(&test_context);
27380 static float clamp_depth_bias(float bias, float clamp)
27382 if (clamp > 0.0f)
27383 return min(bias, clamp);
27384 if (clamp < 0.0f)
27385 return max(bias, clamp);
27386 return bias;
27389 static void test_depth_bias(void)
27391 struct vec3 vertices[] =
27393 {-1.0f, -1.0f, 0.5f},
27394 {-1.0f, 1.0f, 0.5f},
27395 { 1.0f, -1.0f, 0.5f},
27396 { 1.0f, 1.0f, 0.5f},
27398 struct d3d11_test_context test_context;
27399 D3D11_RASTERIZER_DESC rasterizer_desc;
27400 struct swapchain_desc swapchain_desc;
27401 D3D11_TEXTURE2D_DESC texture_desc;
27402 ID3D11DeviceContext *context;
27403 double m, bias, depth, data;
27404 struct resource_readback rb;
27405 ID3D11DepthStencilView *dsv;
27406 unsigned int expected_value;
27407 ID3D11RasterizerState *rs;
27408 ID3D11Texture2D *texture;
27409 unsigned int format_idx;
27410 unsigned int y, i, j, k;
27411 unsigned int shift = 0;
27412 ID3D11Device *device;
27413 float *depth_values;
27414 DXGI_FORMAT format;
27415 const UINT32 *u32;
27416 const UINT16 *u16;
27417 UINT32 u32_value;
27418 HRESULT hr;
27420 static const struct
27422 float z;
27423 float exponent;
27425 quads[] =
27427 {0.125f, -3.0f},
27428 {0.250f, -2.0f},
27429 {0.500f, -1.0f},
27430 {1.000f, 0.0f},
27432 static const int bias_tests[] =
27434 -10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
27435 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000,
27437 static const float bias_clamp_tests[] =
27439 0.0f, -1e-5f, 1e-5f,
27441 static const float quad_slopes[] =
27443 0.0f, 0.5f, 1.0f
27445 static const float slope_scaled_bias_tests[] =
27447 0.0f, 0.5f, 1.0f, 2.0f, 128.0f, 1000.0f, 10000.0f,
27449 static const DXGI_FORMAT formats[] =
27451 DXGI_FORMAT_D32_FLOAT,
27452 DXGI_FORMAT_D24_UNORM_S8_UINT,
27453 DXGI_FORMAT_D16_UNORM,
27456 swapchain_desc.windowed = TRUE;
27457 swapchain_desc.buffer_count = 1;
27458 swapchain_desc.width = 200;
27459 swapchain_desc.height = 200;
27460 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
27461 swapchain_desc.flags = 0;
27462 if (!init_test_context_ext(&test_context, NULL, &swapchain_desc))
27463 return;
27465 device = test_context.device;
27466 context = test_context.immediate_context;
27468 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
27469 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
27470 rasterizer_desc.CullMode = D3D11_CULL_NONE;
27471 rasterizer_desc.FrontCounterClockwise = FALSE;
27472 rasterizer_desc.DepthBias = 0;
27473 rasterizer_desc.DepthBiasClamp = 0.0f;
27474 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
27475 rasterizer_desc.DepthClipEnable = TRUE;
27477 depth_values = heap_calloc(swapchain_desc.height, sizeof(*depth_values));
27478 ok(!!depth_values, "Failed to allocate memory.\n");
27480 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
27482 format = formats[format_idx];
27484 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
27485 texture_desc.Format = format;
27486 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
27487 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
27488 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27489 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
27490 ok(SUCCEEDED(hr), "Failed to create render depth stencil view, hr %#x.\n", hr);
27491 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
27492 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
27493 draw_quad_z(&test_context, 1.0f);
27494 switch (format)
27496 case DXGI_FORMAT_D32_FLOAT:
27497 check_texture_float(texture, 1.0f, 0);
27498 break;
27499 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27500 /* FIXME: Depth/stencil byte order is reversed in wined3d. */
27501 shift = get_texture_color(texture, 0, 0) == 0xffffff ? 0 : 8;
27502 todo_wine
27503 check_texture_color(texture, 0xffffff, 1);
27504 break;
27505 case DXGI_FORMAT_D16_UNORM:
27506 get_texture_readback(texture, 0, &rb);
27507 check_readback_data_u16(&rb, NULL, 0xffffu, 0);
27508 release_resource_readback(&rb);
27509 break;
27510 default:
27511 trace("Unhandled format %#x.\n", format);
27512 break;
27514 draw_quad(&test_context);
27516 /* DepthBias */
27517 for (i = 0; i < ARRAY_SIZE(quads); ++i)
27519 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
27520 vertices[j].z = quads[i].z;
27521 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
27522 0, NULL, vertices, 0, 0);
27524 for (j = 0; j < ARRAY_SIZE(bias_tests); ++j)
27526 rasterizer_desc.DepthBias = bias_tests[j];
27528 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
27530 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
27531 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
27532 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
27533 ID3D11DeviceContext_RSSetState(context, rs);
27534 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27535 draw_quad(&test_context);
27536 switch (format)
27538 case DXGI_FORMAT_D32_FLOAT:
27539 bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f);
27540 bias = clamp_depth_bias(bias, rasterizer_desc.DepthBiasClamp);
27541 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27543 check_texture_float(texture, depth, 2);
27544 break;
27545 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27546 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 16777215.0f,
27547 rasterizer_desc.DepthBiasClamp);
27548 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27550 get_texture_readback(texture, 0, &rb);
27551 check_readback_data_u24(&rb, NULL, shift, depth * 16777215.0f + 0.5f, 1);
27552 release_resource_readback(&rb);
27553 break;
27554 case DXGI_FORMAT_D16_UNORM:
27555 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 65535.0f,
27556 rasterizer_desc.DepthBiasClamp);
27557 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27559 get_texture_readback(texture, 0, &rb);
27560 check_readback_data_u16(&rb, NULL, depth * 65535.0f + 0.5f, 1);
27561 release_resource_readback(&rb);
27562 break;
27563 default:
27564 break;
27566 ID3D11RasterizerState_Release(rs);
27571 /* SlopeScaledDepthBias */
27572 rasterizer_desc.DepthBias = 0;
27573 for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i)
27575 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
27576 vertices[j].z = j == 1 || j == 3 ? 0.0f : quad_slopes[i];
27577 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
27578 0, NULL, vertices, 0, 0);
27580 ID3D11DeviceContext_RSSetState(context, NULL);
27581 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27582 draw_quad(&test_context);
27583 get_texture_readback(texture, 0, &rb);
27584 for (y = 0; y < texture_desc.Height; ++y)
27586 switch (format)
27588 case DXGI_FORMAT_D32_FLOAT:
27589 depth_values[y] = get_readback_float(&rb, 0, y);
27590 break;
27591 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27592 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
27593 u32_value = *u32 >> shift;
27594 depth_values[y] = u32_value / 16777215.0f;
27595 break;
27596 case DXGI_FORMAT_D16_UNORM:
27597 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
27598 depth_values[y] = *u16 / 65535.0f;
27599 break;
27600 default:
27601 break;
27604 release_resource_readback(&rb);
27606 for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j)
27608 rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j];
27610 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
27612 BOOL all_match = TRUE;
27613 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
27614 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
27615 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
27616 ID3D11DeviceContext_RSSetState(context, rs);
27617 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27618 draw_quad(&test_context);
27620 m = quad_slopes[i] / texture_desc.Height;
27621 bias = clamp_depth_bias(rasterizer_desc.SlopeScaledDepthBias * m, rasterizer_desc.DepthBiasClamp);
27622 get_texture_readback(texture, 0, &rb);
27623 for (y = 0; y < texture_desc.Height && all_match; ++y)
27625 depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
27626 switch (format)
27628 case DXGI_FORMAT_D32_FLOAT:
27629 data = get_readback_float(&rb, 0, y);
27630 all_match = compare_float(data, depth, 64);
27631 ok(all_match,
27632 "Got depth %.8e, expected %.8e.\n", data, depth);
27633 break;
27634 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27635 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
27636 u32_value = *u32 >> shift;
27637 expected_value = depth * 16777215.0f + 0.5f;
27638 all_match = compare_uint(u32_value, expected_value, 3);
27639 ok(all_match,
27640 "Got value %#x (%.8e), expected %#x (%.8e).\n",
27641 u32_value, u32_value / 16777215.0f,
27642 expected_value, expected_value / 16777215.0f);
27643 break;
27644 case DXGI_FORMAT_D16_UNORM:
27645 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
27646 expected_value = depth * 65535.0f + 0.5f;
27647 all_match = compare_uint(*u16, expected_value, 1);
27648 ok(all_match,
27649 "Got value %#x (%.8e), expected %#x (%.8e).\n",
27650 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
27651 break;
27652 default:
27653 break;
27656 release_resource_readback(&rb);
27657 ID3D11RasterizerState_Release(rs);
27662 ID3D11Texture2D_Release(texture);
27663 ID3D11DepthStencilView_Release(dsv);
27666 heap_free(depth_values);
27667 release_test_context(&test_context);
27670 static void test_fractional_viewports(void)
27672 struct d3d11_test_context test_context;
27673 D3D11_TEXTURE2D_DESC texture_desc;
27674 ID3D11InputLayout *input_layout;
27675 ID3D11DeviceContext *context;
27676 struct resource_readback rb;
27677 ID3D11RenderTargetView *rtv;
27678 ID3D11VertexShader *vs;
27679 ID3D11PixelShader *ps;
27680 unsigned int i, x, y;
27681 ID3D11Device *device;
27682 ID3D11Texture2D *rt;
27683 UINT offset, stride;
27684 ID3D11Buffer *vb;
27685 HRESULT hr;
27687 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27688 static const DWORD vs_code[] =
27690 #if 0
27691 void main(in float4 in_position : POSITION,
27692 in float2 in_texcoord : TEXCOORD,
27693 out float4 position : SV_Position,
27694 out float2 texcoord : TEXCOORD)
27696 position = in_position;
27697 texcoord = in_texcoord;
27699 #endif
27700 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
27701 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
27702 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
27703 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
27704 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
27705 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
27706 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
27707 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
27708 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
27709 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
27710 0x00000001, 0x0100003e,
27712 static const DWORD ps_code[] =
27714 #if 0
27715 float4 main(float4 position : SV_Position,
27716 float2 texcoord : TEXCOORD) : SV_Target
27718 return float4(position.xy, texcoord);
27720 #endif
27721 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
27722 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
27723 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
27724 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
27725 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
27726 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
27727 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
27728 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
27729 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
27731 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
27733 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
27734 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
27736 static const struct
27738 struct vec2 position;
27739 struct vec2 texcoord;
27741 quad[] =
27743 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
27744 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
27745 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
27746 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
27748 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
27749 static const float viewport_offsets[] =
27751 0.0f, 1.0f / 2.0f, 1.0f / 4.0f, 1.0f / 8.0f, 1.0f / 16.0f, 1.0f / 32.0f,
27752 1.0f / 64.0f, 1.0f / 128.0f, 1.0f / 256.0f, 63.0f / 128.0f,
27755 if (!init_test_context(&test_context, &feature_level))
27756 return;
27757 device = test_context.device;
27758 context = test_context.immediate_context;
27760 texture_desc.Width = 4;
27761 texture_desc.Height = 4;
27762 texture_desc.MipLevels = 1;
27763 texture_desc.ArraySize = 1;
27764 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27765 texture_desc.SampleDesc.Count = 1;
27766 texture_desc.SampleDesc.Quality = 0;
27767 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27768 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27769 texture_desc.CPUAccessFlags = 0;
27770 texture_desc.MiscFlags = 0;
27771 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27772 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27773 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27774 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27775 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27777 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
27778 vs_code, sizeof(vs_code), &input_layout);
27779 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
27780 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
27782 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
27783 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
27784 stride = sizeof(*quad);
27785 offset = 0;
27786 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
27788 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
27789 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
27790 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
27792 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
27793 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27794 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27796 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
27798 set_viewport(context, viewport_offsets[i], viewport_offsets[i],
27799 texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
27800 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
27801 ID3D11DeviceContext_Draw(context, 4, 0);
27802 get_texture_readback(rt, 0, &rb);
27803 for (y = 0; y < texture_desc.Height; ++y)
27805 for (x = 0; x < texture_desc.Width; ++x)
27807 const struct vec4 *v = get_readback_vec4(&rb, x, y);
27808 struct vec4 expected = {x + 0.5f, y + 0.5f,
27809 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
27810 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
27811 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
27812 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
27813 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
27814 todo_wine
27815 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
27816 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
27817 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
27820 release_resource_readback(&rb);
27823 ID3D11InputLayout_Release(input_layout);
27824 ID3D11Buffer_Release(vb);
27825 ID3D11VertexShader_Release(vs);
27826 ID3D11PixelShader_Release(ps);
27827 ID3D11RenderTargetView_Release(rtv);
27828 ID3D11Texture2D_Release(rt);
27829 release_test_context(&test_context);
27832 static void test_negative_viewports(const D3D_FEATURE_LEVEL feature_level)
27834 struct d3d11_test_context test_context;
27835 ID3D11DeviceContext *context;
27836 BOOL quirk;
27837 RECT rect;
27839 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
27840 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
27842 if (!init_test_context(&test_context, &feature_level))
27843 return;
27844 context = test_context.immediate_context;
27846 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
27847 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27848 draw_color_quad(&test_context, &green);
27849 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
27851 set_viewport(context, -0.0f, -0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
27852 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27853 draw_color_quad(&test_context, &green);
27854 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
27856 /* For feature levels greater than or equal to 11_0, a negative top left
27857 * corner shifts the bottom right corner by a whole integer. It seems that
27858 * floor() is used to round viewport corners to integers.
27860 quirk = feature_level >= D3D_FEATURE_LEVEL_11_0;
27862 set_viewport(context, -0.4f, -0.4f, 640.0f, 480.0f, 0.0f, 1.0f);
27863 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27864 draw_color_quad(&test_context, &green);
27865 SetRect(&rect, 0, 0, 639, 479);
27866 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
27867 SetRect(&rect, 639, 479, 640, 480);
27868 todo_wine_if(quirk)
27869 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
27871 set_viewport(context, -1.0f / 128.0f, -1.0 / 128.0f, 640.0f, 480.0f, 0.0f, 1.0f);
27872 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27873 draw_color_quad(&test_context, &green);
27874 SetRect(&rect, 0, 0, 639, 479);
27875 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
27876 SetRect(&rect, 639, 479, 640, 480);
27877 todo_wine_if(quirk)
27878 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
27880 release_test_context(&test_context);
27883 static void test_early_depth_stencil(void)
27885 ID3D11DepthStencilState *depth_stencil_state;
27886 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
27887 ID3D11Texture2D *texture, *depth_texture;
27888 struct d3d11_test_context test_context;
27889 D3D11_TEXTURE2D_DESC texture_desc;
27890 ID3D11UnorderedAccessView *uav;
27891 ID3D11DeviceContext *context;
27892 ID3D11DepthStencilView *dsv;
27893 ID3D11PixelShader *ps;
27894 ID3D11Device *device;
27895 HRESULT hr;
27897 static const DWORD ps_code[] =
27899 #if 0
27900 RWTexture2D<int> u;
27902 [earlydepthstencil]
27903 float4 main() : SV_Target
27905 InterlockedAdd(u[uint2(0, 0)], 1);
27906 return float4(1.0f, 1.0f, 1.0f, 1.0f);
27908 #endif
27909 0x43425844, 0xda4325ad, 0xc01d3815, 0xfd610cc9, 0x8ed1e351, 0x00000001, 0x000000ec, 0x00000003,
27910 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
27911 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
27912 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000074, 0x00000050, 0x0000001d,
27913 0x0100286a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x03000065, 0x001020f2, 0x00000000,
27914 0x0a0000ad, 0x0011e000, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
27915 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
27916 0x3f800000, 0x3f800000, 0x0100003e,
27918 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27919 static const UINT values[4] = {0};
27921 if (!init_test_context(&test_context, &feature_level))
27922 return;
27924 device = test_context.device;
27925 context = test_context.immediate_context;
27927 depth_stencil_desc.DepthEnable = TRUE;
27928 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
27929 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
27930 depth_stencil_desc.StencilEnable = FALSE;
27931 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
27932 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
27934 texture_desc.Width = 1;
27935 texture_desc.Height = 1;
27936 texture_desc.MipLevels = 1;
27937 texture_desc.ArraySize = 1;
27938 texture_desc.Format = DXGI_FORMAT_R32_SINT;
27939 texture_desc.SampleDesc.Count = 1;
27940 texture_desc.SampleDesc.Quality = 0;
27941 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27942 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
27943 texture_desc.CPUAccessFlags = 0;
27944 texture_desc.MiscFlags = 0;
27945 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
27946 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27947 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
27948 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
27950 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
27951 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
27952 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27953 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
27954 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
27955 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27956 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
27957 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
27959 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
27960 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27961 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27963 set_viewport(context, 0.0f, 0.0f, 1.0f, 100.0f, 0.5f, 0.5f);
27964 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
27965 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
27966 1, &test_context.backbuffer_rtv, dsv, 1, 1, &uav, NULL);
27968 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
27970 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
27971 draw_quad(&test_context);
27972 check_texture_color(texture, 100, 1);
27973 draw_quad(&test_context);
27974 check_texture_color(texture, 200, 1);
27975 check_texture_float(depth_texture, 0.6f, 1);
27977 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.3f, 0);
27978 draw_quad(&test_context);
27979 draw_quad(&test_context);
27980 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.55f, 0);
27981 draw_quad(&test_context);
27982 check_texture_color(texture, 300, 1);
27984 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
27985 draw_quad(&test_context);
27986 check_texture_color(texture, 400, 1);
27987 check_texture_float(depth_texture, 0.5f, 1);
27989 ID3D11Texture2D_Release(depth_texture);
27990 ID3D11DepthStencilView_Release(dsv);
27991 ID3D11DepthStencilState_Release(depth_stencil_state);
27992 ID3D11PixelShader_Release(ps);
27993 ID3D11Texture2D_Release(texture);
27994 ID3D11UnorderedAccessView_Release(uav);
27995 release_test_context(&test_context);
27998 static void test_conservative_depth_output(void)
28000 struct shader
28002 const DWORD *code;
28003 size_t size;
28006 ID3D11DepthStencilState *depth_stencil_state;
28007 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
28008 struct d3d11_test_context test_context;
28009 const struct shader *current_shader;
28010 D3D11_TEXTURE2D_DESC texture_desc;
28011 ID3D11DeviceContext *context;
28012 ID3D11DepthStencilView *dsv;
28013 ID3D11Texture2D *texture;
28014 ID3D11PixelShader *ps;
28015 DWORD expected_color;
28016 float expected_depth;
28017 ID3D11Device *device;
28018 struct vec4 ps_depth;
28019 ID3D11Buffer *cb;
28020 unsigned int i;
28021 HRESULT hr;
28023 static const DWORD ps_depth_le_code[] =
28025 #if 0
28026 float depth;
28028 float4 main(out float out_depth : SV_DepthLessEqual) : SV_Target0
28030 out_depth = depth;
28031 return float4(0.0f, 1.0f, 0.f, 1.0f);
28033 #endif
28034 0x43425844, 0x045c8d00, 0xc49e2ebe, 0x76f6022a, 0xf6996ecc, 0x00000001, 0x00000108, 0x00000003,
28035 0x0000002c, 0x0000003c, 0x00000098, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28036 0x00000054, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28037 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
28038 0x65677261, 0x56530074, 0x7065445f, 0x654c6874, 0x71457373, 0x006c6175, 0x58454853, 0x00000068,
28039 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065,
28040 0x001020f2, 0x00000000, 0x02000065, 0x00027001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
28041 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00027001, 0x0020800a, 0x00000000,
28042 0x00000000, 0x0100003e,
28044 static const struct shader ps_depth_le = {ps_depth_le_code, sizeof(ps_depth_le_code)};
28045 static const DWORD ps_depth_ge_code[] =
28047 #if 0
28048 float depth;
28050 float4 main(out float out_depth : SV_DepthGreaterEqual) : SV_Target0
28052 out_depth = depth;
28053 return float4(0.0f, 1.0f, 0.f, 1.0f);
28055 #endif
28056 0x43425844, 0xd17af83e, 0xa32c01cc, 0x0d8e9665, 0xe6dc17c2, 0x00000001, 0x0000010c, 0x00000003,
28057 0x0000002c, 0x0000003c, 0x0000009c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28058 0x00000058, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28059 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
28060 0x65677261, 0x56530074, 0x7065445f, 0x72476874, 0x65746165, 0x75714572, 0xab006c61, 0x58454853,
28061 0x00000068, 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
28062 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x00026001, 0x08000036, 0x001020f2, 0x00000000,
28063 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00026001, 0x0020800a,
28064 0x00000000, 0x00000000, 0x0100003e,
28066 static const struct shader ps_depth_ge = {ps_depth_ge_code, sizeof(ps_depth_ge_code)};
28067 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
28068 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28069 static const struct
28071 const struct shader *ps;
28072 float vs_depth;
28073 float ps_depth;
28074 BOOL passes_depth_test;
28076 tests[] =
28078 {&ps_depth_le, 0.7f, 0.7f, TRUE},
28079 {&ps_depth_le, 0.7f, 0.4f, FALSE},
28080 {&ps_depth_le, 0.4f, 0.4f, FALSE},
28081 /* {&ps_depth_le, 0.4f, 0.6f, FALSE}, undefined result */
28082 {&ps_depth_ge, 0.7f, 0.7f, TRUE},
28083 /* {&ps_depth_ge, 0.7f, 0.4f, TRUE}, undefined result */
28084 {&ps_depth_ge, 0.4f, 0.4f, FALSE},
28085 {&ps_depth_ge, 0.4f, 0.6f, TRUE},
28088 if (!init_test_context(&test_context, &feature_level))
28089 return;
28091 device = test_context.device;
28092 context = test_context.immediate_context;
28094 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_depth), NULL);
28096 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28097 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
28098 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28099 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
28100 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
28101 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28102 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
28103 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
28105 depth_stencil_desc.DepthEnable = TRUE;
28106 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
28107 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_GREATER_EQUAL;
28108 depth_stencil_desc.StencilEnable = FALSE;
28109 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
28110 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
28112 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
28113 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
28114 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
28116 ps = NULL;
28117 current_shader = NULL;
28118 for (i = 0; i < ARRAY_SIZE(tests); ++i)
28120 if (current_shader != tests[i].ps)
28122 if (ps)
28123 ID3D11PixelShader_Release(ps);
28125 current_shader = tests[i].ps;
28126 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
28127 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
28128 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
28131 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28132 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
28133 ps_depth.x = tests[i].ps_depth;
28134 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_depth, 0, 0);
28135 draw_quad_z(&test_context, tests[i].vs_depth);
28137 expected_color = tests[i].passes_depth_test ? 0xff00ff00 : 0xffffffff;
28138 expected_depth = tests[i].passes_depth_test ? max(tests[i].vs_depth, tests[i].ps_depth) : 0.5f;
28139 check_texture_color(test_context.backbuffer, expected_color, 0);
28140 check_texture_float(texture, expected_depth, 1);
28143 ID3D11Buffer_Release(cb);
28144 ID3D11PixelShader_Release(ps);
28145 ID3D11DepthStencilView_Release(dsv);
28146 ID3D11DepthStencilState_Release(depth_stencil_state);
28147 ID3D11Texture2D_Release(texture);
28148 release_test_context(&test_context);
28151 static void test_format_compatibility(void)
28153 ID3D11Texture2D *dst_texture, *src_texture;
28154 D3D11_SUBRESOURCE_DATA resource_data;
28155 D3D11_TEXTURE2D_DESC texture_desc;
28156 ID3D11DeviceContext *context;
28157 struct resource_readback rb;
28158 DWORD colour, expected;
28159 ID3D11Device *device;
28160 unsigned int i, j;
28161 ULONG refcount;
28162 HRESULT hr;
28164 static const struct
28166 DXGI_FORMAT src_format;
28167 DXGI_FORMAT dst_format;
28168 size_t texel_size;
28169 BOOL success;
28171 test_data[] =
28173 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
28174 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
28175 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
28176 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
28177 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
28178 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
28179 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
28180 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
28181 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
28182 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
28183 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
28184 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
28185 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
28186 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
28187 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
28188 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_TYPELESS, 4, TRUE},
28189 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_FLOAT, 4, TRUE},
28190 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_UINT, 4, TRUE},
28191 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_SINT, 4, TRUE},
28192 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, FALSE},
28193 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_B8G8R8A8_TYPELESS, 4, FALSE},
28194 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R16G16_TYPELESS, 4, FALSE},
28195 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
28196 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
28197 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
28198 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
28200 static const DWORD initial_data[16] = {0};
28201 static const DWORD bitmap_data[] =
28203 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28204 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28205 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28206 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28209 if (!(device = create_device(NULL)))
28211 skip("Failed to create device.\n");
28212 return;
28214 ID3D11Device_GetImmediateContext(device, &context);
28216 texture_desc.Height = 4;
28217 texture_desc.MipLevels = 1;
28218 texture_desc.ArraySize = 1;
28219 texture_desc.SampleDesc.Count = 1;
28220 texture_desc.SampleDesc.Quality = 0;
28221 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
28222 texture_desc.CPUAccessFlags = 0;
28223 texture_desc.MiscFlags = 0;
28225 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
28227 unsigned int x, y, texel_dwords;
28228 BOOL broken = FALSE;
28229 D3D11_BOX box;
28231 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
28232 texture_desc.Format = test_data[i].src_format;
28233 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
28235 resource_data.pSysMem = bitmap_data;
28236 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
28237 resource_data.SysMemSlicePitch = 0;
28239 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
28240 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
28242 texture_desc.Format = test_data[i].dst_format;
28243 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28245 resource_data.pSysMem = initial_data;
28247 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
28248 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
28250 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
28251 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0, 1, 1, 0,
28252 (ID3D11Resource *)src_texture, 0, &box);
28254 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
28255 get_texture_readback(dst_texture, 0, &rb);
28256 colour = get_readback_color(&rb, 0, 0, 0);
28257 if (test_data[i].src_format == DXGI_FORMAT_R9G9B9E5_SHAREDEXP && colour == bitmap_data[0])
28259 win_skip("Broken destination offset for %#x -> %#x copy.\n",
28260 test_data[i].src_format, test_data[i].dst_format);
28261 broken = TRUE;
28263 for (j = 0; j < ARRAY_SIZE(bitmap_data) && !broken; ++j)
28265 x = j % 4;
28266 y = j / 4;
28267 colour = get_readback_color(&rb, x, y, 0);
28268 expected = test_data[i].success && x >= texel_dwords && y
28269 ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
28270 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
28271 i, colour, x, y, expected);
28273 release_resource_readback(&rb);
28275 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
28277 get_texture_readback(dst_texture, 0, &rb);
28278 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
28280 x = j % 4;
28281 y = j / 4;
28282 colour = get_readback_color(&rb, x, y, 0);
28283 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
28284 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
28285 i, colour, x, y, expected);
28287 release_resource_readback(&rb);
28289 ID3D11Texture2D_Release(dst_texture);
28290 ID3D11Texture2D_Release(src_texture);
28293 ID3D11DeviceContext_Release(context);
28294 refcount = ID3D11Device_Release(device);
28295 ok(!refcount, "Device has %u references left.\n", refcount);
28298 static void test_compressed_format_compatibility(const D3D_FEATURE_LEVEL feature_level)
28300 const struct format_info *src_format, *dst_format;
28301 unsigned int row_block_count, row_count, i, j, k;
28302 ID3D11Texture2D *src_texture, *dst_texture;
28303 BOOL supported, broken_dst_offset = FALSE;
28304 D3D11_SUBRESOURCE_DATA resource_data;
28305 D3D11_TEXTURE2D_DESC texture_desc;
28306 ID3D11DeviceContext *context;
28307 unsigned int block_idx, x, y;
28308 struct resource_readback rb;
28309 DWORD colour, expected;
28310 ID3D11Device *device;
28311 UINT format_support;
28312 const BYTE *row;
28313 ULONG refcount;
28314 D3D11_BOX box;
28315 HRESULT hr;
28316 const struct device_desc device_desc =
28318 .feature_level = &feature_level,
28321 static const struct format_info
28323 DXGI_FORMAT id;
28324 size_t block_size;
28325 size_t block_edge;
28326 BOOL supported;
28327 BOOL skip_if_broken;
28329 formats[] =
28331 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 16, 1, TRUE},
28332 {DXGI_FORMAT_R32G32B32A32_FLOAT, 16, 1, TRUE},
28333 {DXGI_FORMAT_R32G32B32A32_UINT, 16, 1, TRUE},
28334 {DXGI_FORMAT_R32G32B32A32_SINT, 16, 1, TRUE},
28336 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 8, 1, TRUE},
28337 {DXGI_FORMAT_R16G16B16A16_FLOAT, 8, 1, TRUE},
28338 {DXGI_FORMAT_R16G16B16A16_UNORM, 8, 1, TRUE},
28339 {DXGI_FORMAT_R16G16B16A16_UINT, 8, 1, TRUE},
28340 {DXGI_FORMAT_R16G16B16A16_SNORM, 8, 1, TRUE},
28341 {DXGI_FORMAT_R16G16B16A16_SINT, 8, 1, TRUE},
28343 {DXGI_FORMAT_R32G32_TYPELESS, 8, 1, TRUE},
28344 {DXGI_FORMAT_R32G32_FLOAT, 8, 1, TRUE},
28345 {DXGI_FORMAT_R32G32_UINT, 8, 1, TRUE},
28346 {DXGI_FORMAT_R32G32_SINT, 8, 1, TRUE},
28348 {DXGI_FORMAT_R32_TYPELESS, 4, 1, TRUE},
28349 {DXGI_FORMAT_R32_FLOAT, 4, 1, TRUE},
28350 {DXGI_FORMAT_R32_UINT, 4, 1, TRUE},
28351 {DXGI_FORMAT_R32_SINT, 4, 1, TRUE},
28353 {DXGI_FORMAT_R32G8X24_TYPELESS, 8, 1},
28354 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 4, 1},
28355 {DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, 1},
28356 {DXGI_FORMAT_R16G16_TYPELESS, 4, 1},
28357 {DXGI_FORMAT_R24G8_TYPELESS, 4, 1},
28358 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 4, 1},
28359 {DXGI_FORMAT_B8G8R8A8_TYPELESS, 4, 1},
28360 {DXGI_FORMAT_R8G8_TYPELESS, 2, 1},
28361 {DXGI_FORMAT_R16_TYPELESS, 2, 1},
28362 {DXGI_FORMAT_R8_TYPELESS, 1, 1},
28364 {DXGI_FORMAT_BC1_TYPELESS, 8, 4},
28365 {DXGI_FORMAT_BC1_UNORM, 8, 4},
28366 {DXGI_FORMAT_BC1_UNORM_SRGB, 8, 4},
28368 {DXGI_FORMAT_BC2_TYPELESS, 16, 4},
28369 {DXGI_FORMAT_BC2_UNORM, 16, 4},
28370 {DXGI_FORMAT_BC2_UNORM_SRGB, 16, 4},
28372 {DXGI_FORMAT_BC3_TYPELESS, 16, 4},
28373 {DXGI_FORMAT_BC3_UNORM, 16, 4},
28374 {DXGI_FORMAT_BC3_UNORM_SRGB, 16, 4},
28376 {DXGI_FORMAT_BC4_TYPELESS, 8, 4},
28377 {DXGI_FORMAT_BC4_UNORM, 8, 4},
28378 {DXGI_FORMAT_BC4_SNORM, 8, 4},
28380 {DXGI_FORMAT_BC5_TYPELESS, 16, 4},
28381 {DXGI_FORMAT_BC5_UNORM, 16, 4},
28382 {DXGI_FORMAT_BC5_SNORM, 16, 4},
28384 {DXGI_FORMAT_BC6H_TYPELESS, 16, 4, FALSE, TRUE},
28385 {DXGI_FORMAT_BC6H_UF16, 16, 4, FALSE, TRUE},
28386 {DXGI_FORMAT_BC6H_SF16, 16, 4, FALSE, TRUE},
28388 {DXGI_FORMAT_BC7_TYPELESS, 16, 4, FALSE, TRUE},
28389 {DXGI_FORMAT_BC7_UNORM, 16, 4, FALSE, TRUE},
28390 {DXGI_FORMAT_BC7_UNORM_SRGB, 16, 4, FALSE, TRUE},
28393 static const DWORD initial_data[64] = {0};
28394 static const DWORD texture_data[] =
28396 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28397 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28398 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28399 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28401 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28402 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28403 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28404 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28406 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
28407 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
28408 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
28409 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
28411 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
28412 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
28413 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
28414 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
28417 if (!(device = create_device(&device_desc)))
28419 skip("Failed to create device for feature level %#x.\n", feature_level);
28420 return;
28422 ID3D11Device_GetImmediateContext(device, &context);
28424 row_block_count = 4;
28426 texture_desc.MipLevels = 1;
28427 texture_desc.ArraySize = 1;
28428 texture_desc.SampleDesc.Count = 1;
28429 texture_desc.SampleDesc.Quality = 0;
28430 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
28431 texture_desc.CPUAccessFlags = 0;
28432 texture_desc.MiscFlags = 0;
28434 resource_data.SysMemSlicePitch = 0;
28436 for (i = 0; i < ARRAY_SIZE(formats); ++i)
28438 src_format = &formats[i];
28439 row_count = sizeof(texture_data) / (row_block_count * src_format->block_size);
28440 texture_desc.Width = row_block_count * src_format->block_edge;
28441 texture_desc.Height = row_count * src_format->block_edge;
28442 texture_desc.Format = src_format->id;
28443 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
28445 resource_data.pSysMem = texture_data;
28446 resource_data.SysMemPitch = row_block_count * src_format->block_size;
28448 hr = ID3D11Device_CheckFormatSupport(device, src_format->id, &format_support);
28449 if (hr == E_FAIL || !(format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
28450 continue;
28452 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
28453 ok(hr == S_OK, "Source format %#x: Got unexpected hr %#x.\n", src_format->id, hr);
28455 for (j = 0; j < ARRAY_SIZE(formats); ++j)
28457 dst_format = &formats[j];
28459 if ((src_format->block_edge == 1 && dst_format->block_edge == 1)
28460 || (src_format->block_edge != 1 && dst_format->block_edge != 1))
28461 continue;
28463 hr = ID3D11Device_CheckFormatSupport(device, dst_format->id, &format_support);
28464 if (hr == E_FAIL || !(format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
28465 continue;
28467 supported = ((src_format->block_edge != 1 && dst_format->supported)
28468 || (src_format->supported && dst_format->block_edge != 1))
28469 && src_format->block_size == dst_format->block_size
28470 && feature_level >= D3D_FEATURE_LEVEL_10_1;
28472 /* These cause the device to be removed on some versions of Windows. */
28473 if (supported && broken_dst_offset && (src_format->skip_if_broken || dst_format->skip_if_broken))
28475 win_skip("Skipping %#x -> %#x tests because of broken destination offset.\n",
28476 src_format->id, dst_format->id);
28477 continue;
28480 row_count = sizeof(initial_data) / (row_block_count * dst_format->block_size);
28481 texture_desc.Width = row_block_count * dst_format->block_edge;
28482 texture_desc.Height = row_count * dst_format->block_edge;
28483 texture_desc.Format = dst_format->id;
28484 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28486 resource_data.pSysMem = initial_data;
28487 resource_data.SysMemPitch = row_block_count * dst_format->block_size;
28489 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
28490 ok(hr == S_OK, "%#x -> %#x: Got unexpected hr %#x.\n", src_format->id, dst_format->id, hr);
28492 if (supported && broken_dst_offset)
28494 win_skip("Skipping %#x -> %#x CopySubresourceRegion() test because of broken destination offset.\n",
28495 src_format->id, dst_format->id);
28497 else
28499 set_box(&box, 0, 0, 0, src_format->block_edge, src_format->block_edge, 1);
28500 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
28501 dst_format->block_edge, dst_format->block_edge, 0, (ID3D11Resource *)src_texture, 0, &box);
28502 get_texture_readback(dst_texture, 0, &rb);
28503 colour = get_readback_color(&rb, 0, 0, 0);
28504 if (supported && colour == texture_data[0])
28506 win_skip("Detected broken destination offset for %#x -> %#x copy.\n",
28507 src_format->id, dst_format->id);
28508 broken_dst_offset = TRUE;
28510 for (k = 0; k < ARRAY_SIZE(texture_data) && (!supported || !broken_dst_offset); ++k)
28512 block_idx = (k * sizeof(colour)) / dst_format->block_size;
28513 x = block_idx % row_block_count;
28514 y = block_idx / row_block_count;
28516 row = rb.map_desc.pData;
28517 row += y * rb.map_desc.RowPitch;
28518 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
28520 if (supported && x == 1 && y == 1)
28521 expected = texture_data[k - ((row_block_count + 1) * dst_format->block_size) / sizeof(colour)];
28522 else
28523 expected = initial_data[k];
28524 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
28525 src_format->id, dst_format->id, colour, k, expected);
28526 if (colour != expected)
28527 break;
28529 release_resource_readback(&rb);
28532 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
28533 get_texture_readback(dst_texture, 0, &rb);
28534 for (k = 0; k < ARRAY_SIZE(texture_data); ++k)
28536 block_idx = (k * sizeof(colour)) / dst_format->block_size;
28537 y = block_idx / row_block_count;
28539 row = rb.map_desc.pData;
28540 row += y * rb.map_desc.RowPitch;
28541 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
28543 if (supported)
28544 expected = texture_data[k];
28545 else
28546 expected = initial_data[k];
28547 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
28548 src_format->id, dst_format->id, colour, k, expected);
28549 if (colour != expected)
28550 break;
28552 release_resource_readback(&rb);
28554 ID3D11Texture2D_Release(dst_texture);
28557 ID3D11Texture2D_Release(src_texture);
28560 ID3D11DeviceContext_Release(context);
28561 refcount = ID3D11Device_Release(device);
28562 ok(!refcount, "Device has %u references left.\n", refcount);
28565 static void check_clip_distance(struct d3d11_test_context *test_context, ID3D11Buffer *vb)
28567 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28568 struct vertex
28570 float clip_distance0;
28571 float clip_distance1;
28574 ID3D11DeviceContext *context = test_context->immediate_context;
28575 struct resource_readback rb;
28576 struct vertex vertices[4];
28577 unsigned int i;
28578 RECT rect;
28580 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28581 vertices[i].clip_distance0 = 1.0f;
28582 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28583 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28584 ID3D11DeviceContext_Draw(context, 4, 0);
28585 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
28587 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28588 vertices[i].clip_distance0 = 0.0f;
28589 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28590 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28591 ID3D11DeviceContext_Draw(context, 4, 0);
28592 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
28594 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28595 vertices[i].clip_distance0 = -1.0f;
28596 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28597 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28598 ID3D11DeviceContext_Draw(context, 4, 0);
28599 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
28601 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28602 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
28603 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28604 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28605 ID3D11DeviceContext_Draw(context, 4, 0);
28606 get_texture_readback(test_context->backbuffer, 0, &rb);
28607 SetRect(&rect, 0, 0, 320, 480);
28608 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
28609 SetRect(&rect, 320, 0, 320, 480);
28610 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28611 release_resource_readback(&rb);
28613 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28614 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
28615 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28616 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28617 ID3D11DeviceContext_Draw(context, 4, 0);
28618 get_texture_readback(test_context->backbuffer, 0, &rb);
28619 SetRect(&rect, 0, 0, 640, 240);
28620 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
28621 SetRect(&rect, 0, 240, 640, 240);
28622 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28623 release_resource_readback(&rb);
28626 static void test_clip_distance(void)
28628 struct d3d11_test_context test_context;
28629 ID3D11Buffer *vs_cb, *tess_cb, *gs_cb;
28630 D3D_FEATURE_LEVEL feature_level;
28631 ID3D11DomainShader *ds = NULL;
28632 ID3D11DeviceContext *context;
28633 struct resource_readback rb;
28634 unsigned int offset, stride;
28635 ID3D11HullShader *hs = NULL;
28636 ID3D11GeometryShader *gs;
28637 ID3D11Device *device;
28638 ID3D11Buffer *vb;
28639 unsigned int i;
28640 HRESULT hr;
28641 RECT rect;
28643 static const DWORD vs_code[] =
28645 #if 0
28646 bool use_constant;
28647 float clip_distance;
28649 struct input
28651 float4 position : POSITION;
28652 float distance0 : CLIP_DISTANCE0;
28653 float distance1 : CLIP_DISTANCE1;
28656 struct vertex
28658 float4 position : SV_POSITION;
28659 float user_clip : CLIP_DISTANCE;
28660 float clip : SV_ClipDistance;
28663 void main(input vin, out vertex vertex)
28665 vertex.position = vin.position;
28666 vertex.user_clip = vin.distance0;
28667 vertex.clip = vin.distance0;
28668 if (use_constant)
28669 vertex.clip = clip_distance;
28671 #endif
28672 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
28673 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
28674 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
28675 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
28676 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
28677 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
28678 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
28679 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
28680 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
28681 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
28682 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
28683 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
28684 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
28685 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
28686 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
28688 static const DWORD vs_multiple_code[] =
28690 #if 0
28691 bool use_constant;
28692 float clip_distance0;
28693 float clip_distance1;
28695 struct input
28697 float4 position : POSITION;
28698 float distance0 : CLIP_DISTANCE0;
28699 float distance1 : CLIP_DISTANCE1;
28702 struct vertex
28704 float4 position : SV_POSITION;
28705 float user_clip : CLIP_DISTANCE;
28706 float2 clip : SV_ClipDistance;
28709 void main(input vin, out vertex vertex)
28711 vertex.position = vin.position;
28712 vertex.user_clip = vin.distance0;
28713 vertex.clip.x = vin.distance0;
28714 if (use_constant)
28715 vertex.clip.x = clip_distance0;
28716 vertex.clip.y = vin.distance1;
28717 if (use_constant)
28718 vertex.clip.y = clip_distance1;
28720 #endif
28721 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
28722 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
28723 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
28724 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
28725 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
28726 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
28727 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
28728 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
28729 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
28730 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
28731 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
28732 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
28733 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
28734 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
28735 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
28736 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
28737 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
28739 #if 0
28740 bool use_constant;
28741 float clip_distance0;
28742 float clip_distance1;
28743 float tessellation_factor;
28745 struct vertex
28747 float4 position : SV_POSITION;
28748 float user_clip : CLIP_DISTANCE;
28749 float clip : SV_ClipDistance;
28752 struct patch_constant_data
28754 float edges[4] : SV_TessFactor;
28755 float inside[2] : SV_InsideTessFactor;
28758 patch_constant_data patch_constant()
28760 patch_constant_data output;
28762 output.edges[0] = tessellation_factor;
28763 output.edges[1] = tessellation_factor;
28764 output.edges[2] = tessellation_factor;
28765 output.edges[3] = tessellation_factor;
28766 output.inside[0] = tessellation_factor;
28767 output.inside[1] = tessellation_factor;
28769 return output;
28772 [domain("quad")]
28773 [outputcontrolpoints(4)]
28774 [outputtopology("triangle_cw")]
28775 [partitioning("pow2")]
28776 [patchconstantfunc("patch_constant")]
28777 vertex hs_main(InputPatch<vertex, 4> input,
28778 uint i : SV_OutputControlPointID)
28780 vertex o;
28781 o.position = input[i].position;
28782 o.user_clip = input[i].user_clip;
28783 o.clip = input[i].user_clip;
28784 return o;
28787 float4 interpolate_vec(float4 a, float4 b, float4 c, float4 d, float2 tess_coord)
28789 float4 e = lerp(a, b, tess_coord.x);
28790 float4 f = lerp(c, d, tess_coord.x);
28791 return lerp(e, f, tess_coord.y);
28794 float interpolate(float a, float b, float c, float d, float2 tess_coord)
28796 float e = lerp(a, b, tess_coord.x);
28797 float f = lerp(c, d, tess_coord.x);
28798 return lerp(e, f, tess_coord.y);
28801 [domain("quad")]
28802 vertex ds_main(patch_constant_data input,
28803 float2 tess_coord : SV_DomainLocation,
28804 const OutputPatch<vertex, 4> patch)
28806 vertex output;
28808 output.position = interpolate_vec(patch[0].position, patch[1].position,
28809 patch[2].position, patch[3].position, tess_coord);
28810 output.user_clip = interpolate(patch[0].user_clip, patch[1].user_clip,
28811 patch[2].user_clip, patch[3].user_clip, tess_coord);
28812 output.clip = interpolate(patch[0].clip, patch[1].clip,
28813 patch[2].clip, patch[3].clip, tess_coord);
28814 if (use_constant)
28815 output.clip = clip_distance0;
28817 return output;
28819 #endif
28820 static const DWORD hs_code[] =
28822 0x43425844, 0x5a6d7564, 0x5f30a6c9, 0x2cf3b848, 0x5b4c6dca, 0x00000001, 0x00000414, 0x00000004,
28823 0x00000030, 0x000000b4, 0x00000138, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
28824 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
28825 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
28826 0x00000002, 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
28827 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003,
28828 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c,
28829 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002,
28830 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f,
28831 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc,
28832 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
28833 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
28834 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
28835 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
28836 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
28837 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
28838 0x00000210, 0x00030050, 0x00000084, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01001096,
28839 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x01000072, 0x0200005f,
28840 0x00016000, 0x0400005f, 0x002010f2, 0x00000004, 0x00000000, 0x0400005f, 0x00201012, 0x00000004,
28841 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
28842 0x00102012, 0x00000002, 0x02000068, 0x00000001, 0x04000036, 0x00100012, 0x00000000, 0x00016001,
28843 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x07000036,
28844 0x00102012, 0x00000001, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x07000036, 0x00102012,
28845 0x00000002, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x0100003e, 0x01000073, 0x02000099,
28846 0x00000004, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x0000000b, 0x04000067,
28847 0x00102012, 0x00000001, 0x0000000c, 0x04000067, 0x00102012, 0x00000002, 0x0000000d, 0x04000067,
28848 0x00102012, 0x00000003, 0x0000000e, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000000,
28849 0x00000004, 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, 0x00902012, 0x0010000a,
28850 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002,
28851 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000004, 0x0000000f, 0x04000067, 0x00102012,
28852 0x00000005, 0x00000010, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000004, 0x00000002,
28853 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x08000036, 0x00d02012, 0x00000004, 0x0010000a,
28854 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e,
28856 static const DWORD ds_code[] =
28858 0x43425844, 0xc54dc020, 0x063a9622, 0x6f649eb9, 0xceb1dd36, 0x00000001, 0x0000054c, 0x00000004,
28859 0x00000030, 0x000000b4, 0x00000178, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
28860 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
28861 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
28862 0x00000002, 0x00000101, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
28863 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc, 0x00000006,
28864 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000001, 0x00000098,
28865 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000001, 0x00000098, 0x00000002, 0x0000000b,
28866 0x00000003, 0x00000002, 0x00000001, 0x00000098, 0x00000003, 0x0000000b, 0x00000003, 0x00000003,
28867 0x00000001, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000001, 0x000000a6,
28868 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
28869 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000007c,
28870 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
28871 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000,
28872 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43,
28873 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x58454853,
28874 0x00000348, 0x00040050, 0x000000d2, 0x01002093, 0x01001895, 0x0100086a, 0x04000059, 0x00208e46,
28875 0x00000000, 0x00000001, 0x0200005f, 0x0001c032, 0x0400005f, 0x002190f2, 0x00000004, 0x00000000,
28876 0x0400005f, 0x00219012, 0x00000004, 0x00000001, 0x0400005f, 0x00219012, 0x00000004, 0x00000002,
28877 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067,
28878 0x00102012, 0x00000002, 0x00000002, 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000,
28879 0x80219e46, 0x00000041, 0x00000002, 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032,
28880 0x001000f2, 0x00000000, 0x0001c006, 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000,
28881 0x0a000000, 0x001000f2, 0x00000001, 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46,
28882 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001,
28883 0x00219e46, 0x00000000, 0x00000000, 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
28884 0x80100e46, 0x00000041, 0x00000001, 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46,
28885 0x00000000, 0x00100e46, 0x00000001, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041,
28886 0x00000002, 0x00000001, 0x0021900a, 0x00000003, 0x00000001, 0x09000032, 0x00100012, 0x00000000,
28887 0x0001c00a, 0x0010000a, 0x00000000, 0x0021900a, 0x00000002, 0x00000001, 0x0a000000, 0x00100022,
28888 0x00000000, 0x8021900a, 0x00000041, 0x00000000, 0x00000001, 0x0021900a, 0x00000001, 0x00000001,
28889 0x09000032, 0x00100022, 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000,
28890 0x00000001, 0x08000000, 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a,
28891 0x00000000, 0x08000032, 0x00102012, 0x00000001, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a,
28892 0x00000000, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041, 0x00000002, 0x00000002,
28893 0x0021900a, 0x00000003, 0x00000002, 0x09000032, 0x00100012, 0x00000000, 0x0001c00a, 0x0010000a,
28894 0x00000000, 0x0021900a, 0x00000002, 0x00000002, 0x0a000000, 0x00100022, 0x00000000, 0x8021900a,
28895 0x00000041, 0x00000000, 0x00000002, 0x0021900a, 0x00000001, 0x00000002, 0x09000032, 0x00100022,
28896 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000, 0x00000002, 0x08000000,
28897 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a, 0x00000000, 0x08000032,
28898 0x00100012, 0x00000000, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000, 0x0b000037,
28899 0x00102012, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
28900 0x0010000a, 0x00000000, 0x0100003e,
28902 static const DWORD gs_code[] =
28904 #if 0
28905 bool use_constant;
28906 float clip_distance;
28908 struct vertex
28910 float4 position : SV_POSITION;
28911 float user_clip : CLIP_DISTANCE;
28912 float clip : SV_ClipDistance;
28915 [maxvertexcount(3)]
28916 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
28918 vertex o;
28919 o = input[0];
28920 o.clip = input[0].user_clip;
28921 if (use_constant)
28922 o.clip = clip_distance;
28923 output.Append(o);
28924 o = input[1];
28925 o.clip = input[1].user_clip;
28926 if (use_constant)
28927 o.clip = clip_distance;
28928 output.Append(o);
28929 o = input[2];
28930 o.clip = input[2].user_clip;
28931 if (use_constant)
28932 o.clip = clip_distance;
28933 output.Append(o);
28935 #endif
28936 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
28937 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
28938 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
28939 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
28940 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
28941 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
28942 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
28943 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
28944 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
28945 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
28946 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
28947 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
28948 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
28949 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
28950 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
28951 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
28952 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
28953 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
28954 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
28955 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
28956 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
28957 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
28958 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
28959 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
28960 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
28961 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
28963 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
28965 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
28966 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
28967 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
28969 struct
28971 float clip_distance0;
28972 float clip_distance1;
28974 vertices[] =
28976 {1.0f, 1.0f},
28977 {1.0f, 1.0f},
28978 {1.0f, 1.0f},
28979 {1.0f, 1.0f},
28981 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28982 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
28983 struct
28985 BOOL use_constant;
28986 float clip_distance0;
28987 float clip_distance1;
28988 float tessellation_factor;
28989 } cb_data;
28991 if (!init_test_context(&test_context, NULL))
28992 return;
28993 device = test_context.device;
28994 context = test_context.immediate_context;
28995 feature_level = ID3D11Device_GetFeatureLevel(device);
28997 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
28998 vs_code, sizeof(vs_code), &test_context.input_layout);
28999 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
29001 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
29002 stride = sizeof(*vertices);
29003 offset = 0;
29004 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
29006 memset(&cb_data, 0, sizeof(cb_data));
29007 cb_data.tessellation_factor = 1.0f;
29008 vs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29009 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &vs_cb);
29010 tess_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29011 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &tess_cb);
29012 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, 1, &tess_cb);
29013 gs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29014 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &gs_cb);
29016 /* vertex shader */
29017 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29018 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29019 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29021 check_clip_distance(&test_context, vb);
29023 cb_data.use_constant = TRUE;
29024 cb_data.clip_distance0 = -1.0f;
29025 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29027 /* tessellation shaders */
29028 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
29030 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
29032 hr = ID3D11Device_CreateHullShader(device, hs_code, sizeof(hs_code), NULL, &hs);
29033 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
29034 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
29035 hr = ID3D11Device_CreateDomainShader(device, ds_code, sizeof(ds_code), NULL, &ds);
29036 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
29037 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
29039 check_clip_distance(&test_context, vb);
29041 cb_data.use_constant = FALSE;
29042 cb_data.tessellation_factor = 2.0f;
29043 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
29045 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29046 vertices[i].clip_distance0 = 1.0f;
29047 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29048 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29049 ID3D11DeviceContext_Draw(context, 4, 0);
29050 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29052 cb_data.use_constant = TRUE;
29053 cb_data.clip_distance0 = -1.0f;
29054 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
29056 else
29058 skip("Tessellation shaders are not supported.\n");
29061 /* geometry shader */
29062 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
29063 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
29064 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
29066 check_clip_distance(&test_context, vb);
29068 cb_data.use_constant = TRUE;
29069 cb_data.clip_distance0 = 1.0f;
29070 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
29071 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29072 ID3D11DeviceContext_Draw(context, 4, 0);
29073 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29075 /* multiple clip distances */
29076 ID3D11DeviceContext_HSSetShader(context, NULL, NULL, 0);
29077 ID3D11DeviceContext_DSSetShader(context, NULL, NULL, 0);
29078 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
29080 cb_data.use_constant = FALSE;
29081 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29083 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29084 vertices[i].clip_distance0 = 1.0f;
29085 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29086 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29087 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29088 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29090 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29092 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
29093 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
29095 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29096 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29097 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29098 get_texture_readback(test_context.backbuffer, 0, &rb);
29099 SetRect(&rect, 0, 0, 320, 240);
29100 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
29101 SetRect(&rect, 0, 240, 320, 480);
29102 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29103 SetRect(&rect, 320, 0, 640, 480);
29104 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29105 release_resource_readback(&rb);
29107 cb_data.use_constant = TRUE;
29108 cb_data.clip_distance0 = 0.0f;
29109 cb_data.clip_distance1 = 0.0f;
29110 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29111 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29112 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29113 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29115 if (hs)
29116 ID3D11HullShader_Release(hs);
29117 if (ds)
29118 ID3D11DomainShader_Release(ds);
29119 ID3D11GeometryShader_Release(gs);
29120 ID3D11Buffer_Release(vb);
29121 ID3D11Buffer_Release(vs_cb);
29122 ID3D11Buffer_Release(tess_cb);
29123 ID3D11Buffer_Release(gs_cb);
29124 release_test_context(&test_context);
29127 static void test_combined_clip_and_cull_distances(void)
29129 struct d3d11_test_context test_context;
29130 ID3D11DeviceContext *context;
29131 struct resource_readback rb;
29132 unsigned int offset, stride;
29133 ID3D11Device *device;
29134 unsigned int i, j, k;
29135 ID3D11Buffer *vb;
29136 HRESULT hr;
29138 static const DWORD vs_code[] =
29140 #if 0
29141 struct input
29143 float4 position : POSITION;
29144 float clip0 : CLIP_DISTANCE0;
29145 float clip1 : CLIP_DISTANCE1;
29146 float clip2 : CLIP_DISTANCE2;
29147 float clip3 : CLIP_DISTANCE3;
29148 float cull0 : CULL_DISTANCE0;
29149 float cull1 : CULL_DISTANCE1;
29150 float cull2 : CULL_DISTANCE2;
29151 float cull3 : CULL_DISTANCE3;
29154 struct vertex
29156 float4 position : SV_Position;
29157 float3 clip0 : SV_ClipDistance1;
29158 float3 cull0 : SV_CullDistance1;
29159 float clip1 : SV_ClipDistance2;
29160 float cull1 : SV_CullDistance2;
29163 void main(input vin, out vertex vertex)
29165 vertex.position = vin.position;
29166 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
29167 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
29168 vertex.clip1 = vin.clip3;
29169 vertex.cull1 = vin.cull3;
29171 #endif
29172 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
29173 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
29174 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
29175 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
29176 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
29177 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
29178 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
29179 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
29180 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
29181 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
29182 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
29183 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
29184 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
29185 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
29186 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
29187 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
29188 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
29189 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
29190 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
29191 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
29192 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
29193 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
29194 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
29195 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
29196 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
29197 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
29198 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
29199 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
29201 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
29203 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29204 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29205 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
29206 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
29207 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
29208 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
29209 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
29210 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
29211 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
29213 struct
29215 float clip_distance[4];
29216 float cull_distance[4];
29218 vertices[4] =
29220 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29221 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29222 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29223 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29225 static const struct test
29227 float vertices[4];
29228 BOOL triangle_visible[2];
29230 cull_distance_tests[] =
29232 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29233 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29234 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29235 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29236 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
29237 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29238 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
29239 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29240 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
29242 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
29243 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29244 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29245 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
29246 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
29248 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
29250 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29251 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
29253 if (!init_test_context(&test_context, NULL))
29254 return;
29255 device = test_context.device;
29256 context = test_context.immediate_context;
29258 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
29259 vs_code, sizeof(vs_code), &test_context.input_layout);
29260 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
29262 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
29263 stride = sizeof(*vertices);
29264 offset = 0;
29265 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
29267 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29268 draw_color_quad(&test_context, &green);
29269 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29271 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
29273 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
29275 const struct test *test = &cull_distance_tests[j];
29276 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
29277 unsigned int color;
29279 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
29280 vertices[k].cull_distance[i] = test->vertices[k];
29281 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29283 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29284 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29286 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
29287 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
29289 if (expected_color[0] == expected_color[1])
29291 check_texture_color(test_context.backbuffer, *expected_color, 1);
29293 else
29295 get_texture_readback(test_context.backbuffer, 0, &rb);
29296 color = get_readback_color(&rb, 160, 240, 0);
29297 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
29298 color = get_readback_color(&rb, 480, 240, 0);
29299 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
29300 release_resource_readback(&rb);
29304 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29305 vertices[j].cull_distance[i] = 1.0f;
29308 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
29310 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29311 vertices[j].clip_distance[i] = -1.0f;
29312 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29314 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29315 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29316 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
29318 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29319 vertices[j].clip_distance[i] = 1.0f;
29322 memset(vertices, 0, sizeof(vertices));
29323 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29324 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29325 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29326 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29328 ID3D11Buffer_Release(vb);
29329 release_test_context(&test_context);
29332 static void test_generate_mips(void)
29334 static const DWORD ps_code[] =
29336 #if 0
29337 Texture2D t;
29338 SamplerState s;
29340 float4 main(float4 position : SV_POSITION) : SV_Target
29342 float2 p;
29344 p.x = position.x / 640.0f;
29345 p.y = position.y / 480.0f;
29346 return t.Sample(s, p);
29348 #endif
29349 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
29350 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29351 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
29352 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
29353 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
29354 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
29355 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
29356 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
29357 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
29358 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
29360 static const DWORD ps_code_3d[] =
29362 #if 0
29363 Texture3D t;
29364 SamplerState s;
29366 float4 main(float4 position : SV_POSITION) : SV_Target
29368 float3 p;
29370 p.x = position.x / 640.0f;
29371 p.y = position.y / 480.0f;
29372 p.z = 0.5f;
29373 return t.Sample(s, p);
29375 #endif
29376 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003,
29377 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29378 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
29379 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
29380 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040,
29381 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
29382 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
29383 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
29384 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000,
29385 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
29386 0x00000000, 0x0100003e,
29388 static const struct
29390 D3D11_RESOURCE_DIMENSION dim;
29391 D3D11_SRV_DIMENSION srv_dim;
29392 unsigned int array_size;
29394 resource_types[] =
29396 {D3D11_RESOURCE_DIMENSION_BUFFER, D3D11_SRV_DIMENSION_BUFFER, 1},
29397 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2D, 1},
29398 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2DARRAY, 4},
29399 {D3D11_RESOURCE_DIMENSION_TEXTURE3D, D3D11_SRV_DIMENSION_TEXTURE3D, 1},
29401 static const struct
29403 DXGI_FORMAT texture_format;
29404 UINT bind_flags;
29405 UINT misc_flags;
29406 BOOL null_srv;
29407 UINT base_level;
29408 BOOL expected_creation;
29409 BOOL expected_mips;
29411 tests[] =
29413 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
29414 0, TRUE, FALSE},
29415 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
29416 0, TRUE, FALSE},
29417 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
29418 0, TRUE, FALSE},
29419 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
29420 0, TRUE, FALSE},
29421 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29422 0, FALSE, FALSE},
29423 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29424 0, FALSE, FALSE},
29425 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29426 0, TRUE, TRUE},
29427 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29428 1, TRUE, TRUE},
29429 {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29430 1, TRUE, TRUE},
29431 {DXGI_FORMAT_R8G8B8A8_UINT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, TRUE,
29432 1, TRUE, FALSE},
29434 static const struct
29436 POINT pos;
29437 DWORD color;
29439 expected[] =
29441 {{200, 200}, 0xffff0000},
29442 {{280, 200}, 0xffff0000},
29443 {{360, 200}, 0xff00ff00},
29444 {{440, 200}, 0xff00ff00},
29445 {{200, 270}, 0xff0000ff},
29446 {{280, 270}, 0xff0000ff},
29447 {{360, 270}, 0xff000000},
29448 {{440, 270}, 0xff000000},
29450 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
29451 static const RECT r1 = {8, 8, 16, 16};
29452 static const RECT r2 = {16, 8, 24, 16};
29453 static const RECT r3 = {8, 16, 16, 24};
29454 static const RECT r4 = {16, 16, 24, 24};
29455 DWORD *data, *zero_data, color, expected_color;
29456 ID3D11ShaderResourceView *srv, *srv_sampling;
29457 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
29458 struct d3d11_test_context test_context;
29459 D3D11_TEXTURE2D_DESC texture2d_desc;
29460 D3D11_TEXTURE3D_DESC texture3d_desc;
29461 ID3D11SamplerState *sampler_state;
29462 D3D11_SAMPLER_DESC sampler_desc;
29463 D3D11_BUFFER_DESC buffer_desc;
29464 unsigned int i, j, k, x, y, z;
29465 ID3D11PixelShader *ps, *ps_3d;
29466 ID3D11DeviceContext *context;
29467 struct resource_readback rb;
29468 ID3D11Resource *resource;
29469 ID3D11Device *device;
29470 HRESULT hr;
29472 if (!init_test_context(&test_context, NULL))
29473 return;
29475 device = test_context.device;
29476 context = test_context.immediate_context;
29478 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
29479 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29481 hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps_3d);
29482 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29484 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
29485 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
29486 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
29487 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
29488 sampler_desc.MipLODBias = 0.0f;
29489 sampler_desc.MaxAnisotropy = 0;
29490 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
29491 sampler_desc.BorderColor[0] = 0.0f;
29492 sampler_desc.BorderColor[1] = 0.0f;
29493 sampler_desc.BorderColor[2] = 0.0f;
29494 sampler_desc.BorderColor[3] = 0.0f;
29495 sampler_desc.MinLOD = 0.0f;
29496 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
29498 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
29499 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
29500 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
29502 data = heap_alloc(sizeof(*data) * 32 * 32 * 32);
29504 for (z = 0; z < 32; ++z)
29506 for (y = 0; y < 32; ++y)
29508 for (x = 0; x < 32; ++x)
29510 DWORD *dst = &data[z * 32 * 32 + y * 32 + x];
29511 POINT pt;
29513 pt.x = x;
29514 pt.y = y;
29515 if (PtInRect(&r1, pt))
29516 *dst = 0xffff0000;
29517 else if (PtInRect(&r2, pt))
29518 *dst = 0xff00ff00;
29519 else if (PtInRect(&r3, pt))
29520 *dst = 0xff0000ff;
29521 else if (PtInRect(&r4, pt))
29522 *dst = 0xff000000;
29523 else
29524 *dst = 0xffffffff;
29529 zero_data = heap_alloc_zero(sizeof(*zero_data) * 16 * 16 * 16);
29531 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
29533 for (j = 0; j < ARRAY_SIZE(tests); ++j)
29535 unsigned int base_multiplier = 1u << tests[j].base_level;
29537 if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT)
29539 /* Testing this format seems to break the WARP device. */
29540 skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n");
29541 continue;
29544 switch (resource_types[i].dim)
29546 case D3D11_RESOURCE_DIMENSION_BUFFER:
29547 buffer_desc.ByteWidth = 32 * base_multiplier;
29548 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
29549 buffer_desc.BindFlags = tests[j].bind_flags;
29550 buffer_desc.CPUAccessFlags = 0;
29551 buffer_desc.MiscFlags = tests[j].misc_flags;
29552 buffer_desc.StructureByteStride = 0;
29554 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL,
29555 (ID3D11Buffer **)&resource);
29556 break;
29557 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
29558 texture2d_desc.Width = 32 * base_multiplier;
29559 texture2d_desc.Height = 32 * base_multiplier;
29560 texture2d_desc.MipLevels = 0;
29561 texture2d_desc.ArraySize = resource_types[i].array_size;
29562 texture2d_desc.Format = tests[j].texture_format;
29563 texture2d_desc.SampleDesc.Count = 1;
29564 texture2d_desc.SampleDesc.Quality = 0;
29565 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
29566 texture2d_desc.BindFlags = tests[j].bind_flags;
29567 texture2d_desc.CPUAccessFlags = 0;
29568 texture2d_desc.MiscFlags = tests[j].misc_flags;
29570 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL,
29571 (ID3D11Texture2D **)&resource);
29572 break;
29573 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
29574 texture3d_desc.Width = 32 * base_multiplier;
29575 texture3d_desc.Height = 32 * base_multiplier;
29576 texture3d_desc.Depth = 32 * base_multiplier;
29577 texture3d_desc.MipLevels = 0;
29578 texture3d_desc.Format = tests[j].texture_format;
29579 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
29580 texture3d_desc.BindFlags = tests[j].bind_flags;
29581 texture3d_desc.CPUAccessFlags = 0;
29582 texture3d_desc.MiscFlags = tests[j].misc_flags;
29584 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL,
29585 (ID3D11Texture3D **)&resource);
29586 break;
29587 default:
29588 break;
29590 if (tests[j].expected_creation && (resource_types[i].dim != D3D11_RESOURCE_DIMENSION_BUFFER
29591 || !(tests[j].misc_flags & D3D11_RESOURCE_MISC_GENERATE_MIPS)))
29593 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr);
29595 else
29597 ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded "
29598 "to create resource, hr %#x.\n", i, j, hr);
29599 continue;
29602 if (tests[j].null_srv)
29604 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
29606 else
29608 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29609 srv_desc.ViewDimension = resource_types[i].srv_dim;
29610 switch (resource_types[i].srv_dim)
29612 case D3D11_SRV_DIMENSION_BUFFER:
29613 srv_desc.Buffer.ElementOffset = 0;
29614 srv_desc.Buffer.ElementWidth = 0;
29615 break;
29616 case D3D11_SRV_DIMENSION_TEXTURE2D:
29617 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level;
29618 srv_desc.Texture2D.MipLevels = ~0u;
29619 break;
29620 case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
29621 srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level;
29622 srv_desc.Texture2DArray.MipLevels = ~0u;
29623 srv_desc.Texture2DArray.FirstArraySlice = 0;
29624 srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size;
29625 break;
29626 case D3D11_SRV_DIMENSION_TEXTURE3D:
29627 srv_desc.Texture3D.MostDetailedMip = tests[j].base_level;
29628 srv_desc.Texture3D.MipLevels = ~0u;
29629 break;
29630 default:
29631 break;
29633 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
29635 if (resource_types[i].dim == D3D11_RESOURCE_DIMENSION_BUFFER)
29637 ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, "
29638 "hr %#x.\n", j, hr);
29639 ID3D11Resource_Release(resource);
29640 continue;
29642 else
29644 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create "
29645 "shader resource view, hr %#x.\n", i, j, hr);
29648 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level,
29649 NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
29650 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level + 1,
29651 NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16);
29653 ID3D11DeviceContext_GenerateMips(context, srv);
29655 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
29657 srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT
29658 ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
29659 srv_desc.ViewDimension = resource_types[i].dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D
29660 ? D3D11_SRV_DIMENSION_TEXTURE3D : D3D11_SRV_DIMENSION_TEXTURE2D;
29661 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1;
29662 srv_desc.Texture2D.MipLevels = ~0u;
29663 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
29664 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, "
29665 "hr %#x.\n", i, j, hr);
29666 ID3D11DeviceContext_PSSetShader(context, resource_types[i].dim
29667 == D3D11_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps, NULL, 0);
29668 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
29670 draw_quad(&test_context);
29672 get_texture_readback(test_context.backbuffer, 0, &rb);
29673 for (k = 0; k < ARRAY_SIZE(expected); ++k)
29675 color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y, 0);
29676 expected_color = tests[j].expected_mips ? expected[k].color : 0;
29677 ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) "
29678 "has color %08x, expected %08x.\n",
29679 i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color);
29681 release_resource_readback(&rb);
29683 ID3D11ShaderResourceView_Release(srv_sampling);
29684 ID3D11ShaderResourceView_Release(srv);
29685 ID3D11Resource_Release(resource);
29689 /* Test the effect of sRGB views. */
29690 for (y = 0; y < 32; ++y)
29692 for (x = 0; x < 32; ++x)
29694 DWORD *dst = &data[y * 32 + x];
29696 *dst = (x + y) % 2 * 0xffffffff;
29699 texture2d_desc.Width = 32;
29700 texture2d_desc.Height = 32;
29701 texture2d_desc.MipLevels = 0;
29702 texture2d_desc.ArraySize = 1;
29703 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
29704 texture2d_desc.SampleDesc.Count = 1;
29705 texture2d_desc.SampleDesc.Quality = 0;
29706 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
29707 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
29708 texture2d_desc.CPUAccessFlags = 0;
29709 texture2d_desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
29711 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D11Texture2D **)&resource);
29712 ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr);
29713 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
29714 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
29715 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
29716 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29717 srv_desc.Texture2D.MostDetailedMip = 0;
29718 srv_desc.Texture2D.MipLevels = ~0u;
29719 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
29720 ID3D11DeviceContext_UpdateSubresource(context, resource,
29721 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
29723 ID3D11DeviceContext_GenerateMips(context, srv);
29725 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
29727 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29728 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29729 srv_desc.Texture2D.MostDetailedMip = 1;
29730 srv_desc.Texture2D.MipLevels = ~0u;
29731 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
29732 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
29733 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29734 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
29736 draw_quad(&test_context);
29738 get_texture_readback(test_context.backbuffer, 0, &rb);
29739 color = get_readback_color(&rb, 320, 240, 0);
29740 ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */
29741 "Unexpected color %08x.\n", color);
29742 release_resource_readback(&rb);
29744 ID3D11ShaderResourceView_Release(srv_sampling);
29745 ID3D11ShaderResourceView_Release(srv);
29747 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29748 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29749 srv_desc.Texture2D.MostDetailedMip = 0;
29750 srv_desc.Texture2D.MipLevels = ~0u;
29751 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
29752 ID3D11DeviceContext_UpdateSubresource(context, resource,
29753 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
29755 ID3D11DeviceContext_GenerateMips(context, srv);
29757 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
29759 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29760 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29761 srv_desc.Texture2D.MostDetailedMip = 1;
29762 srv_desc.Texture2D.MipLevels = ~0u;
29763 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
29764 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
29765 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29766 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
29768 draw_quad(&test_context);
29770 get_texture_readback(test_context.backbuffer, 0, &rb);
29771 check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1);
29772 release_resource_readback(&rb);
29774 ID3D11ShaderResourceView_Release(srv_sampling);
29775 ID3D11ShaderResourceView_Release(srv);
29777 ID3D11Resource_Release(resource);
29779 heap_free(zero_data);
29780 heap_free(data);
29782 ID3D11SamplerState_Release(sampler_state);
29783 ID3D11PixelShader_Release(ps_3d);
29784 ID3D11PixelShader_Release(ps);
29785 release_test_context(&test_context);
29788 static void test_alpha_to_coverage(void)
29790 struct ps_cb
29792 struct vec2 top;
29793 struct vec2 bottom;
29794 float alpha[2];
29795 float padding[2];
29798 struct d3d11_test_context test_context;
29799 ID3D11Texture2D *render_targets[3];
29800 D3D11_TEXTURE2D_DESC texture_desc;
29801 ID3D11Texture2D *readback_texture;
29802 ID3D11RenderTargetView *rtvs[3];
29803 ID3D11BlendState *blend_state;
29804 ID3D11DeviceContext *context;
29805 D3D11_BLEND_DESC blend_desc;
29806 struct resource_readback rb;
29807 UINT quality_level_count;
29808 ID3D11PixelShader *ps;
29809 struct ps_cb cb_data;
29810 ID3D11Device *device;
29811 ID3D11Buffer *cb;
29812 unsigned int i;
29813 HRESULT hr;
29814 RECT rect;
29816 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29817 static const DWORD ps_code[] =
29819 #if 0
29820 float2 top;
29821 float2 bottom;
29822 float alpha1;
29823 float alpha2;
29825 void main(float4 position : SV_Position,
29826 out float4 target0 : SV_Target0,
29827 out float4 target1 : SV_Target1,
29828 out float4 target2 : SV_Target2)
29830 float alpha = all(top <= position.xy) && all(position.xy <= bottom) ? 1.0f : 0.0f;
29831 target0 = float4(0.0f, 1.0f, 0.0f, alpha);
29832 target1 = float4(0.0f, 0.0f, 1.0f, alpha1);
29833 target2 = float4(0.0f, 1.0f, 0.0f, alpha2);
29835 #endif
29836 0x43425844, 0x771ff802, 0xca927279, 0x5bdd75ae, 0xf53cb31b, 0x00000001, 0x00000264, 0x00000003,
29837 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29838 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
29839 0x4e47534f, 0x0000005c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003,
29840 0x00000000, 0x0000000f, 0x00000050, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
29841 0x00000050, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x545f5653, 0x65677261,
29842 0xabab0074, 0x52444853, 0x00000198, 0x00000040, 0x00000066, 0x04000059, 0x00208e46, 0x00000000,
29843 0x00000002, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
29844 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001,
29845 0x0800001d, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00208046, 0x00000000, 0x00000000,
29846 0x07000001, 0x00100012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0800001d,
29847 0x00100062, 0x00000000, 0x00208ba6, 0x00000000, 0x00000000, 0x00101106, 0x00000000, 0x07000001,
29848 0x00100022, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x07000001, 0x00100012,
29849 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00102082, 0x00000000,
29850 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x08000036, 0x00102072, 0x00000000, 0x00004002,
29851 0x00000000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x00102072, 0x00000001, 0x00004002,
29852 0x00000000, 0x00000000, 0x3f800000, 0x00000000, 0x06000036, 0x00102082, 0x00000001, 0x0020800a,
29853 0x00000000, 0x00000001, 0x08000036, 0x00102072, 0x00000002, 0x00004002, 0x00000000, 0x3f800000,
29854 0x00000000, 0x00000000, 0x06000036, 0x00102082, 0x00000002, 0x0020801a, 0x00000000, 0x00000001,
29855 0x0100003e,
29857 static const DWORD colors[] = {0xff00ff00, 0xbfff0000, 0x8000ff00};
29859 if (!init_test_context(&test_context, NULL))
29860 return;
29861 device = test_context.device;
29862 context = test_context.immediate_context;
29864 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
29865 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29866 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29868 memset(&blend_desc, 0, sizeof(blend_desc));
29869 blend_desc.AlphaToCoverageEnable = TRUE;
29870 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
29871 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
29872 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
29873 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
29875 render_targets[0] = test_context.backbuffer;
29876 rtvs[0] = test_context.backbuffer_rtv;
29877 for (i = 1; i < ARRAY_SIZE(render_targets); ++i)
29879 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29880 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
29881 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29882 hr = ID3D11Device_CreateRenderTargetView(device,
29883 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
29884 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
29886 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
29888 cb_data.top.x = cb_data.top.y = 0.0f;
29889 cb_data.bottom.x = cb_data.bottom.y = 200.0f;
29890 cb_data.alpha[0] = 0.75;
29891 cb_data.alpha[1] = 0.5f;
29892 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29893 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
29895 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
29896 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
29897 draw_quad(&test_context);
29898 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
29900 DWORD expected_color;
29902 assert(i < ARRAY_SIZE(colors));
29903 expected_color = colors[i];
29904 get_texture_readback(render_targets[i], 0, &rb);
29905 SetRect(&rect, 0, 0, 200, 200);
29906 check_readback_data_color(&rb, &rect, expected_color, 1);
29907 SetRect(&rect, 200, 0, 640, 200);
29908 todo_wine
29909 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29910 SetRect(&rect, 0, 200, 640, 480);
29911 todo_wine
29912 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29913 release_resource_readback(&rb);
29915 if (i > 0)
29916 ID3D11Texture2D_Release(render_targets[i]);
29917 render_targets[i] = NULL;
29920 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29921 texture_desc.Format = DXGI_FORMAT_R16G16_UNORM;
29922 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[0]);
29923 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29924 hr = ID3D11Device_CreateRenderTargetView(device,
29925 (ID3D11Resource *)render_targets[0], NULL, &rtvs[0]);
29926 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
29927 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
29929 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
29930 draw_quad(&test_context);
29931 get_texture_readback(render_targets[0], 0, &rb);
29932 SetRect(&rect, 0, 0, 200, 200);
29933 check_readback_data_color(&rb, &rect, 0xffff0000, 1);
29934 SetRect(&rect, 200, 0, 640, 200);
29935 todo_wine
29936 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29937 SetRect(&rect, 0, 200, 640, 480);
29938 todo_wine
29939 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29940 release_resource_readback(&rb);
29942 ID3D11Texture2D_Release(render_targets[0]);
29943 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
29944 ID3D11RenderTargetView_Release(rtvs[i]);
29946 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29947 hr = ID3D11Device_CheckMultisampleQualityLevels(device,
29948 texture_desc.Format, 4, &quality_level_count);
29949 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
29950 if (!quality_level_count)
29952 skip("4xMSAA not supported.\n");
29953 goto done;
29955 texture_desc.SampleDesc.Count = 4;
29956 texture_desc.SampleDesc.Quality = 0;
29958 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
29960 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
29961 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29962 hr = ID3D11Device_CreateRenderTargetView(device,
29963 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
29964 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
29966 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
29968 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
29969 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
29970 draw_quad(&test_context);
29971 texture_desc.SampleDesc.Count = 1;
29972 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
29973 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29974 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
29976 DWORD expected_color;
29978 assert(i < ARRAY_SIZE(colors));
29979 expected_color = colors[i];
29981 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
29982 (ID3D11Resource *)render_targets[i], 0, texture_desc.Format);
29984 get_texture_readback(readback_texture, 0, &rb);
29985 SetRect(&rect, 0, 0, 200, 200);
29986 check_readback_data_color(&rb, &rect, expected_color, 1);
29987 SetRect(&rect, 200, 0, 640, 200);
29988 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29989 SetRect(&rect, 0, 200, 640, 480);
29990 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29991 release_resource_readback(&rb);
29993 ID3D11Texture2D_Release(readback_texture);
29995 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
29997 ID3D11Texture2D_Release(render_targets[i]);
29998 ID3D11RenderTargetView_Release(rtvs[i]);
30001 done:
30002 ID3D11Buffer_Release(cb);
30003 ID3D11PixelShader_Release(ps);
30004 ID3D11BlendState_Release(blend_state);
30005 release_test_context(&test_context);
30008 static void test_unbound_multisample_texture(void)
30010 struct d3d11_test_context test_context;
30011 ID3D11DeviceContext *context;
30012 ID3D11PixelShader *ps;
30013 struct uvec4 cb_data;
30014 ID3D11Device *device;
30015 ID3D11Buffer *cb;
30016 unsigned int i;
30017 HRESULT hr;
30019 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30020 static const DWORD ps_code[] =
30022 #if 0
30023 Texture2DMS<float4, 4> t;
30025 uint sample_index;
30027 float4 main(float4 position : SV_Position) : SV_Target
30029 float3 p;
30030 t.GetDimensions(p.x, p.y, p.z);
30031 p *= float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
30032 /* sample index must be a literal */
30033 switch (sample_index)
30035 case 1: return t.Load(int2(p.xy), 1);
30036 case 2: return t.Load(int2(p.xy), 2);
30037 case 3: return t.Load(int2(p.xy), 3);
30038 default: return t.Load(int2(p.xy), 0);
30041 #endif
30042 0x43425844, 0x03d62416, 0x1914ee8b, 0xccd08d68, 0x27f42136, 0x00000001, 0x000002f8, 0x00000003,
30043 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30044 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
30045 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
30046 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000025c, 0x00000040,
30047 0x00000097, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04042058, 0x00107000, 0x00000000,
30048 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
30049 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46,
30050 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000,
30051 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
30052 0x00000000, 0x00000000, 0x0400004c, 0x0020800a, 0x00000000, 0x00000000, 0x03000006, 0x00004001,
30053 0x00000001, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000, 0x08000036, 0x001000c2,
30054 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0900002e, 0x001020f2,
30055 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
30056 0x03000006, 0x00004001, 0x00000002, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000,
30057 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
30058 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001,
30059 0x00000002, 0x0100003e, 0x03000006, 0x00004001, 0x00000003, 0x0500001b, 0x00100032, 0x00000001,
30060 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000,
30061 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46,
30062 0x00000000, 0x00004001, 0x00000003, 0x0100003e, 0x0100000a, 0x0500001b, 0x00100032, 0x00000000,
30063 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
30064 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46,
30065 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000017, 0x0100003e,
30068 if (!init_test_context(&test_context, NULL))
30069 return;
30070 device = test_context.device;
30071 context = test_context.immediate_context;
30073 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30074 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30075 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30077 memset(&cb_data, 0, sizeof(cb_data));
30078 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
30079 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30081 for (i = 0; i < 4; ++i)
30083 cb_data.x = i;
30084 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_data, 0, 0);
30085 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
30086 draw_quad(&test_context);
30087 check_texture_color(test_context.backbuffer, 0x00000000, 1);
30090 ID3D11Buffer_Release(cb);
30091 ID3D11PixelShader_Release(ps);
30092 release_test_context(&test_context);
30095 static void test_multiple_viewports(void)
30097 struct
30099 unsigned int draw_id;
30100 unsigned int padding[3];
30101 } constant;
30102 D3D11_VIEWPORT vp[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE + 1];
30103 struct d3d11_test_context test_context;
30104 D3D11_TEXTURE2D_DESC texture_desc;
30105 ID3D11DeviceContext *context;
30106 ID3D11RenderTargetView *rtv;
30107 ID3D11Texture2D *texture;
30108 ID3D11GeometryShader *gs;
30109 ID3D11PixelShader *ps;
30110 ID3D11Device *device;
30111 ID3D11Buffer *cb;
30112 HRESULT hr;
30114 static const DWORD gs_code[] =
30116 #if 0
30117 struct gs_in
30119 float4 pos : SV_Position;
30122 struct gs_out
30124 float4 pos : SV_Position;
30125 uint viewport : SV_ViewportArrayIndex;
30128 [maxvertexcount(6)]
30129 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
30131 gs_out o;
30132 for (uint instance_id = 0; instance_id < 2; ++instance_id)
30134 o.viewport = instance_id;
30135 for (uint i = 0; i < 3; ++i)
30137 o.pos = vin[i].pos;
30138 vout.Append(o);
30140 vout.RestartStrip();
30143 #endif
30144 0x43425844, 0xabbb660f, 0x0729bf23, 0x14a9a104, 0x1b454917, 0x00000001, 0x0000021c, 0x00000003,
30145 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30146 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
30147 0x4e47534f, 0x0000005c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
30148 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005, 0x00000001, 0x00000001, 0x00000e01,
30149 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569, 0x4174726f, 0x79617272, 0x65646e49,
30150 0xabab0078, 0x52444853, 0x00000150, 0x00020040, 0x00000054, 0x05000061, 0x002010f2, 0x00000003,
30151 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
30152 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000005, 0x0200005e, 0x00000006,
30153 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
30154 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x03040003, 0x0010001a, 0x00000000,
30155 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
30156 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000,
30157 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036,
30158 0x00102012, 0x00000001, 0x0010000a, 0x00000000, 0x01000013, 0x0700001e, 0x00100022, 0x00000000,
30159 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012,
30160 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
30162 static const DWORD ps_code[] =
30164 #if 0
30165 uint draw_id;
30167 float4 main(in float4 pos : SV_Position,
30168 in uint viewport : SV_ViewportArrayIndex) : SV_Target
30170 return float4(viewport, draw_id, 0, 0);
30172 #endif
30173 0x43425844, 0x77334c0f, 0x5df3ca7a, 0xc53c00db, 0x3e6e5750, 0x00000001, 0x00000150, 0x00000003,
30174 0x0000002c, 0x00000090, 0x000000c4, 0x4e475349, 0x0000005c, 0x00000002, 0x00000008, 0x00000038,
30175 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005,
30176 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569,
30177 0x4174726f, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
30178 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261,
30179 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46, 0x00000000,
30180 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000005, 0x03000065, 0x001020f2, 0x00000000,
30181 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022, 0x00000000,
30182 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000,
30183 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
30185 static const struct vec4 expected_values[] =
30187 {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},
30188 {0.0f, 5.0f}, {0.5f, 0.5f}, {1.0f, 5.0f}, {0.5f, 0.5f},
30190 static const float clear_color[] = {0.5f, 0.5f, 0.0f, 0.0f};
30191 ID3D11RasterizerState *rasterizer_state;
30192 D3D11_RASTERIZER_DESC rasterizer_desc;
30193 unsigned int count, i;
30194 D3D11_RECT rects[2];
30195 RECT rect;
30196 int width;
30198 if (!init_test_context(&test_context, NULL))
30199 return;
30201 device = test_context.device;
30202 context = test_context.immediate_context;
30204 memset(&constant, 0, sizeof(constant));
30205 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
30206 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30208 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
30209 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
30210 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
30212 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30213 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
30214 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30216 texture_desc.Width = 32;
30217 texture_desc.Height = 32;
30218 texture_desc.MipLevels = 1;
30219 texture_desc.ArraySize = 1;
30220 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
30221 texture_desc.SampleDesc.Count = 1;
30222 texture_desc.SampleDesc.Quality = 0;
30223 texture_desc.Usage = D3D11_USAGE_DEFAULT;
30224 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
30225 texture_desc.CPUAccessFlags = 0;
30226 texture_desc.MiscFlags = 0;
30227 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30228 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30230 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
30231 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
30232 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30234 width = texture_desc.Width / 2;
30236 vp[0].TopLeftX = 0.0f;
30237 vp[0].TopLeftY = 0.0f;
30238 vp[0].Width = width;
30239 vp[0].Height = texture_desc.Height;
30240 vp[0].MinDepth = 0.0f;
30241 vp[0].MaxDepth = 1.0f;
30243 vp[1] = vp[0];
30244 vp[1].TopLeftX = width;
30245 vp[1].Width = width;
30246 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
30248 count = enable_debug_layer ? ARRAY_SIZE(vp) - 1 : ARRAY_SIZE(vp);
30249 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
30250 ok(count == 2, "Unexpected viewport count %d.\n", count);
30252 constant.draw_id = 0;
30253 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30254 draw_quad(&test_context);
30255 constant.draw_id = 1;
30256 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30257 draw_quad(&test_context);
30259 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
30260 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[0], 1);
30261 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30262 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[1], 1);
30264 /* One viewport. */
30265 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30266 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
30267 constant.draw_id = 2;
30268 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30269 draw_quad(&test_context);
30270 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
30271 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[2], 1);
30272 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30273 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[3], 1);
30275 /* Reset viewports. */
30276 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30277 ID3D11DeviceContext_RSSetViewports(context, 0, NULL);
30278 constant.draw_id = 3;
30279 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30280 draw_quad(&test_context);
30281 check_texture_sub_resource_vec4(texture, 0, NULL, &expected_values[4], 1);
30283 /* Two viewports, only first scissor rectangle set. */
30284 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
30285 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
30286 rasterizer_desc.CullMode = D3D11_CULL_BACK;
30287 rasterizer_desc.DepthClipEnable = TRUE;
30288 rasterizer_desc.ScissorEnable = TRUE;
30289 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
30290 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
30292 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
30293 ID3D11RasterizerState_Release(rasterizer_state);
30295 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30296 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
30298 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
30299 memset(&rects[1], 0, sizeof(*rects));
30300 ID3D11DeviceContext_RSSetScissorRects(context, 1, rects);
30301 constant.draw_id = 4;
30302 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30303 draw_quad(&test_context);
30305 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
30306 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[5], 1);
30307 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
30308 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[6], 1);
30309 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30310 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[7], 1);
30312 /* Set both rectangles. */
30313 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
30314 SetRect(&rects[1], width, 0, 2 * width, texture_desc.Height / 2);
30315 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30316 ID3D11DeviceContext_RSSetScissorRects(context, 2, rects);
30317 constant.draw_id = 5;
30318 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30319 draw_quad(&test_context);
30321 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
30322 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[8], 1);
30323 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
30324 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[9], 1);
30326 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height / 2 - 1);
30327 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[10], 1);
30328 SetRect(&rect, width, texture_desc.Height / 2, 2 * width - 1, texture_desc.Height - 1);
30329 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[11], 1);
30331 if (enable_debug_layer)
30332 goto done;
30334 /* Viewport count exceeding maximum value. */
30335 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
30337 vp[0].TopLeftX = 1.0f;
30338 vp[0].TopLeftY = 0.0f;
30339 vp[0].Width = width;
30340 vp[0].Height = texture_desc.Height;
30341 vp[0].MinDepth = 0.0f;
30342 vp[0].MaxDepth = 1.0f;
30343 for (i = 1; i < ARRAY_SIZE(vp); ++i)
30345 vp[i] = vp[0];
30347 ID3D11DeviceContext_RSSetViewports(context, ARRAY_SIZE(vp), vp);
30349 count = ARRAY_SIZE(vp);
30350 memset(vp, 0, sizeof(vp));
30351 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
30352 ok(count == 1, "Unexpected viewport count %d.\n", count);
30353 ok(vp[0].TopLeftX == 0.0f && vp[0].Width == width, "Unexpected viewport.\n");
30355 done:
30356 ID3D11RenderTargetView_Release(rtv);
30357 ID3D11Texture2D_Release(texture);
30359 ID3D11Buffer_Release(cb);
30360 ID3D11GeometryShader_Release(gs);
30361 ID3D11PixelShader_Release(ps);
30362 release_test_context(&test_context);
30365 static void test_multisample_resolve(void)
30367 struct d3d11_test_context test_context;
30368 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
30369 ID3D11Texture2D *texture, *ms_texture;
30370 D3D11_TEXTURE2D_DESC texture_desc;
30371 ID3D11DeviceContext *context;
30372 ID3D11RenderTargetView *rtv;
30373 ID3D11Device *device;
30374 unsigned int i;
30375 HRESULT hr;
30377 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30378 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
30379 static const struct vec4 color = {0.25f, 0.5f, 0.75f, 1.0f};
30380 static const struct
30382 DXGI_FORMAT src_format;
30383 DXGI_FORMAT dst_format;
30384 DXGI_FORMAT format;
30386 DXGI_FORMAT rtv_format;
30388 const struct vec4 *color;
30389 DWORD expected_color;
30391 BOOL todo;
30393 tests[] =
30395 {DXGI_FORMAT_R8G8B8A8_UNORM,
30396 DXGI_FORMAT_R8G8B8A8_UNORM,
30397 DXGI_FORMAT_R8G8B8A8_UNORM,
30398 DXGI_FORMAT_R8G8B8A8_UNORM,
30399 &green, 0xff80ff80},
30400 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30401 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30402 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30403 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30404 &green, 0xffbcffbc},
30405 {DXGI_FORMAT_R8G8B8A8_UNORM,
30406 DXGI_FORMAT_R8G8B8A8_UNORM,
30407 DXGI_FORMAT_R8G8B8A8_UNORM,
30408 DXGI_FORMAT_R8G8B8A8_UNORM,
30409 &color, 0xffdfc0a0},
30410 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30411 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30412 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30413 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30414 &color, 0xfff1e1cf},
30416 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30417 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30418 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30419 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30420 &green, 0xffbcffbc},
30421 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30422 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30423 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30424 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30425 &green, 0xffbcffbc},
30426 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30427 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30428 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30429 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30430 &color, 0xfff1e1cf},
30431 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30432 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30433 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30434 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30435 &color, 0xfff1e1cf},
30437 {DXGI_FORMAT_R8G8B8A8_UNORM,
30438 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30439 DXGI_FORMAT_R8G8B8A8_UNORM,
30440 DXGI_FORMAT_R8G8B8A8_UNORM,
30441 &green, 0xff80ff80},
30442 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30443 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30444 DXGI_FORMAT_R8G8B8A8_UNORM,
30445 DXGI_FORMAT_R8G8B8A8_UNORM,
30446 &green, 0xff80ff80},
30447 {DXGI_FORMAT_R8G8B8A8_UNORM,
30448 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30449 DXGI_FORMAT_R8G8B8A8_UNORM,
30450 DXGI_FORMAT_R8G8B8A8_UNORM,
30451 &color, 0xffdfc0a0},
30452 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30453 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30454 DXGI_FORMAT_R8G8B8A8_UNORM,
30455 DXGI_FORMAT_R8G8B8A8_UNORM,
30456 &color, 0xffdfc0a0},
30458 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30459 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30460 DXGI_FORMAT_R8G8B8A8_UNORM,
30461 DXGI_FORMAT_R8G8B8A8_UNORM,
30462 &green, 0xff80ff80},
30463 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30464 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30465 DXGI_FORMAT_R8G8B8A8_UNORM,
30466 DXGI_FORMAT_R8G8B8A8_UNORM,
30467 &color, 0xffdfc0a0},
30468 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30469 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30470 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30471 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30472 &green, 0xffbcffbc},
30473 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30474 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30475 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30476 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30477 &color, 0xfff1e1cf},
30478 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30479 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30480 DXGI_FORMAT_R8G8B8A8_UNORM,
30481 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30482 &green, 0xff80ff80},
30483 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30484 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30485 DXGI_FORMAT_R8G8B8A8_UNORM,
30486 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30487 &color, 0xfff0dec4},
30488 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30489 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30490 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30491 DXGI_FORMAT_R8G8B8A8_UNORM,
30492 &green, 0xffbcffbc, TRUE},
30493 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30494 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30495 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30496 DXGI_FORMAT_R8G8B8A8_UNORM,
30497 &color, 0xffe2cdc0, TRUE},
30500 if (!init_test_context(&test_context, NULL))
30501 return;
30502 device = test_context.device;
30503 context = test_context.immediate_context;
30505 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &i);
30506 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
30507 if (!i)
30509 skip("4xMSAA not supported.\n");
30510 release_test_context(&test_context);
30511 return;
30514 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, 3);
30516 for (i = 0; i < ARRAY_SIZE(tests); ++i)
30518 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30519 texture_desc.Format = tests[i].dst_format;
30520 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30521 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30523 texture_desc.Format = tests[i].src_format;
30524 texture_desc.SampleDesc.Count = 4;
30525 texture_desc.SampleDesc.Quality = 0;
30526 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ms_texture);
30527 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30528 rtv_desc.Format = tests[i].rtv_format;
30529 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
30530 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)ms_texture, &rtv_desc, &rtv);
30531 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
30533 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30534 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
30535 draw_color_quad(&test_context, tests[i].color);
30536 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)texture, 0,
30537 (ID3D11Resource *)ms_texture, 0, tests[i].format);
30539 /* Found broken on AMD Radeon HD 6310 */
30540 if (!broken(is_amd_device(device) && tests[i].format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB))
30541 todo_wine_if(tests[i].todo) check_texture_color(texture, tests[i].expected_color, 2);
30543 ID3D11RenderTargetView_Release(rtv);
30544 ID3D11Texture2D_Release(ms_texture);
30545 ID3D11Texture2D_Release(texture);
30548 release_test_context(&test_context);
30551 static void test_sample_shading(void)
30553 struct shader
30555 const DWORD *code;
30556 size_t size;
30559 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
30560 struct d3d11_test_context test_context;
30561 struct swapchain_desc swapchain_desc;
30562 D3D11_TEXTURE2D_DESC texture_desc;
30563 ID3D11UnorderedAccessView *uav;
30564 D3D11_BUFFER_DESC buffer_desc;
30565 ID3D11ShaderResourceView *srv;
30566 ID3D11DeviceContext *context;
30567 ID3D11RenderTargetView *rtv;
30568 struct resource_readback rb;
30569 ID3D11Buffer *buffer, *cb;
30570 ID3D11Texture2D *texture;
30571 struct uvec4 ps_constant;
30572 ID3D11PixelShader *ps;
30573 ID3D11Device *device;
30574 unsigned int data;
30575 unsigned int i;
30576 HRESULT hr;
30578 static const DWORD ps_unused_sample_index_code[] =
30580 #if 0
30581 RWByteAddressBuffer u;
30583 float4 main(uint id : SV_SampleIndex) : SV_Target
30585 u.InterlockedAdd(0, 1);
30586 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30588 #endif
30589 0x43425844, 0x41e4574b, 0x1e6441d6, 0x5e756375, 0xacd5dc27, 0x00000001, 0x00000104, 0x00000003,
30590 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30591 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000001, 0x535f5653, 0x6c706d61, 0x646e4965,
30592 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30593 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064,
30594 0x00000050, 0x00000019, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2,
30595 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
30596 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
30597 0x0100003e,
30599 static const struct shader ps_unused_sample_index
30600 = {ps_unused_sample_index_code, sizeof(ps_unused_sample_index_code)};
30601 static const DWORD ps_sample_index_code[] =
30603 #if 0
30604 RWByteAddressBuffer u;
30606 float4 main(uint id : SV_SampleIndex) : SV_Target
30608 u.InterlockedAdd(0, 1);
30609 u.InterlockedAdd(4, id);
30610 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30612 #endif
30613 0x43425844, 0x943ab9ed, 0x91520b4a, 0xb75df9d0, 0x692cd3e6, 0x00000001, 0x00000130, 0x00000003,
30614 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30615 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
30616 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30617 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000090,
30618 0x00000050, 0x00000024, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
30619 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001,
30620 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
30621 0x00000004, 0x0010100a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
30622 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30624 static const struct shader ps_sample_index = {ps_sample_index_code, sizeof(ps_sample_index_code)};
30625 static const DWORD ps_samplepos_code[] =
30627 #if 0
30628 Texture2DMS<float> t;
30629 RWByteAddressBuffer u;
30631 float4 main() : SV_Target
30633 float2 sample_position = t.GetSamplePosition(0);
30634 u.InterlockedAdd(0, 1);
30635 u.InterlockedAdd(4, sample_position.x + sample_position.y);
30636 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30638 #endif
30639 0x43425844, 0x9ec7f344, 0x588f5863, 0x436c0531, 0x69dc54bb, 0x00000001, 0x00000160, 0x00000003,
30640 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
30641 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
30642 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e8, 0x00000050, 0x0000003a,
30643 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
30644 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
30645 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
30646 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
30647 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
30648 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
30649 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30651 static const struct shader ps_samplepos = {ps_samplepos_code, sizeof(ps_samplepos_code)};
30652 static const DWORD ps_samplepos_rasterizer_code[] =
30654 #if 0
30655 RWByteAddressBuffer u;
30657 float4 main() : SV_Target
30659 float2 sample_position = GetRenderTargetSamplePosition(0);
30660 u.InterlockedAdd(0, 1);
30661 u.InterlockedAdd(4, sample_position.x + sample_position.y);
30662 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30664 #endif
30665 0x43425844, 0xe31795d9, 0x4e9951da, 0xc1713913, 0xfb12da31, 0x00000001, 0x00000148, 0x00000003,
30666 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
30667 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
30668 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d0, 0x00000050, 0x00000034,
30669 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
30670 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
30671 0x0600006e, 0x00100032, 0x00000000, 0x0000e046, 0x00004001, 0x00000000, 0x07000000, 0x00100012,
30672 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
30673 0x0010000a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
30674 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
30675 0x3f800000, 0x0100003e,
30677 static const struct shader ps_samplepos_rasterizer
30678 = {ps_samplepos_rasterizer_code, sizeof(ps_samplepos_rasterizer_code)};
30679 static const DWORD ps_samplepos_indexed_code[] =
30681 #if 0
30682 RWByteAddressBuffer u;
30684 float4 main(uint id : SV_SampleIndex) : SV_Target
30686 float2 sample_position = GetRenderTargetSamplePosition(id);
30687 u.InterlockedAdd(0, 1);
30688 u.InterlockedAdd(4, sample_position.x + sample_position.y);
30689 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30691 #endif
30692 0x43425844, 0x4b501464, 0x0cd4f636, 0x36428677, 0x6db6b4fb, 0x00000001, 0x00000180, 0x00000003,
30693 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30694 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
30695 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30696 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e0,
30697 0x00000050, 0x00000038, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
30698 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad,
30699 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0600006e, 0x00100032,
30700 0x00000000, 0x0000e046, 0x0010100a, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
30701 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
30702 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
30703 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30705 static const struct shader ps_samplepos_indexed
30706 = {ps_samplepos_indexed_code, sizeof(ps_samplepos_indexed_code)};
30707 static const DWORD ps_sampleinfo_code[] =
30709 #if 0
30710 Texture2DMS<float> t;
30711 RWByteAddressBuffer u;
30713 float4 main() : SV_Target
30715 uint width, height, sample_count;
30716 t.GetDimensions(width, height, sample_count);
30717 u.InterlockedAdd(0, 1);
30718 u.InterlockedAdd(4, sample_count);
30719 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30721 #endif
30722 0x43425844, 0x4e4f4065, 0x20d88902, 0xd4750e8c, 0x652b8c04, 0x00000001, 0x00000124, 0x00000003,
30723 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
30724 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
30725 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050, 0x0000002b,
30726 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
30727 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
30728 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a,
30729 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000,
30730 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
30731 0x0100003e,
30733 static const struct shader ps_sampleinfo = {ps_sampleinfo_code, sizeof(ps_sampleinfo_code)};
30734 static const DWORD ps_sampleinfo_rasterizer_code[] =
30736 #if 0
30737 RWByteAddressBuffer u;
30739 float4 main() : SV_Target
30741 uint sample_count = GetRenderTargetSampleCount();
30742 u.InterlockedAdd(0, 1);
30743 u.InterlockedAdd(4, sample_count);
30744 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30746 #endif
30747 0x43425844, 0xfbbd8619, 0x9c2654c8, 0xb385363a, 0x4aacd10f, 0x00000001, 0x00000110, 0x00000003,
30748 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
30749 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
30750 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000098, 0x00000050, 0x00000026,
30751 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
30752 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
30753 0x0400086f, 0x00100012, 0x00000000, 0x0000e00a, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
30754 0x00000004, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
30755 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30757 static const struct shader ps_sampleinfo_rasterizer
30758 = {ps_sampleinfo_rasterizer_code, sizeof(ps_sampleinfo_rasterizer_code)};
30759 static const DWORD ps_sample_code[] =
30761 #if 0
30762 RWByteAddressBuffer u;
30764 float4 main(sample float4 position : SV_Position) : SV_Target
30766 u.InterlockedAdd(0, 1);
30767 u.InterlockedAdd(4, position.x);
30768 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30770 #endif
30771 0x43425844, 0x46ecbadb, 0xedccbea6, 0x236d7923, 0x0c356c8c, 0x00000001, 0x00000148, 0x00000003,
30772 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30773 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x7469736f, 0x006e6f69,
30774 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
30775 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050,
30776 0x0000002b, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04003864, 0x00101012, 0x00000000,
30777 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000,
30778 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500001c, 0x00100012, 0x00000000,
30779 0x0010100a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
30780 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
30781 0x3f800000, 0x0100003e,
30783 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
30784 static const DWORD ps_color_code[] =
30786 #if 0
30787 float4 main(uint id : SV_SampleIndex) : SV_Target
30789 switch (id)
30791 case 0: return float4(1.0f, 0.0f, 0.0f, 1.0f);
30792 case 1: return float4(0.0f, 1.0f, 0.0f, 1.0f);
30793 case 2: return float4(0.0f, 0.0f, 1.0f, 1.0f);
30794 default: return float4(0.0f, 0.0f, 0.0f, 1.0f);
30797 #endif
30798 0x43425844, 0x94c35f48, 0x04c6b0f7, 0x407d8214, 0xc24f01e5, 0x00000001, 0x00000194, 0x00000003,
30799 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30800 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
30801 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30802 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f4,
30803 0x00000050, 0x0000003d, 0x0100086a, 0x04000863, 0x00101012, 0x00000000, 0x0000000a, 0x03000065,
30804 0x001020f2, 0x00000000, 0x0300004c, 0x0010100a, 0x00000000, 0x03000006, 0x00004001, 0x00000000,
30805 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
30806 0x0100003e, 0x03000006, 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
30807 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x03000006, 0x00004001, 0x00000002,
30808 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000,
30809 0x0100003e, 0x0100000a, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
30810 0x00000000, 0x3f800000, 0x0100003e, 0x01000017, 0x0100003e,
30812 static const DWORD ps_resolve_code[] =
30814 #if 0
30815 Texture2DMS<float4> t;
30817 uint sample;
30818 uint rt_size;
30820 float4 main(float4 position : SV_Position) : SV_Target
30822 float3 p;
30823 t.GetDimensions(p.x, p.y, p.z);
30824 p *= float3(position.x / rt_size, position.y / rt_size, 0);
30825 return t.Load((int2)p.xy, sample);
30827 #endif
30828 0x43425844, 0x68a4590b, 0xc1ec3070, 0x1b957c43, 0x0c080741, 0x00000001, 0x000001c8, 0x00000003,
30829 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30830 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
30831 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
30832 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000012c, 0x00000050,
30833 0x0000004b, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002058, 0x00107000,
30834 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
30835 0x00000000, 0x02000068, 0x00000001, 0x06000056, 0x00100012, 0x00000000, 0x0020801a, 0x00000000,
30836 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00100006, 0x00000000,
30837 0x8900003d, 0x80000102, 0x00155543, 0x001000c2, 0x00000000, 0x00004001, 0x00000000, 0x001074e6,
30838 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000,
30839 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000,
30840 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8c00002e, 0x80000102, 0x00155543,
30841 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0020800a, 0x00000000,
30842 0x00000000, 0x0100003e,
30844 static const struct
30846 const struct shader *ps;
30847 BOOL sample_shading;
30848 BOOL todo;
30849 BOOL broken;
30851 tests[] =
30853 {&ps_unused_sample_index, FALSE, FALSE, TRUE /* broken on Nvidia */},
30854 {&ps_sample_index, TRUE},
30855 {&ps_samplepos, FALSE},
30856 {&ps_samplepos_rasterizer, FALSE},
30857 {&ps_samplepos_indexed, TRUE, TRUE},
30858 {&ps_sampleinfo, FALSE},
30859 {&ps_sampleinfo_rasterizer, FALSE},
30860 {&ps_sample, TRUE, TRUE, TRUE /* broken on Intel */},
30862 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
30863 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30864 static const unsigned int zero[4] = {0};
30866 swapchain_desc.windowed = TRUE;
30867 swapchain_desc.buffer_count = 1;
30868 swapchain_desc.width = 32;
30869 swapchain_desc.height = 32;
30870 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
30871 swapchain_desc.flags = 0;
30872 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
30873 return;
30874 device = test_context.device;
30875 context = test_context.immediate_context;
30877 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30878 texture_desc.SampleDesc.Count = 4;
30879 texture_desc.SampleDesc.Quality = 0;
30880 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
30881 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30882 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30883 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
30884 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
30885 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
30886 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
30888 buffer_desc.ByteWidth = 1024;
30889 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
30890 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
30891 buffer_desc.CPUAccessFlags = 0;
30892 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
30893 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
30894 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
30895 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
30896 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
30897 U(uav_desc).Buffer.FirstElement = 0;
30898 U(uav_desc).Buffer.NumElements = 256;
30899 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
30900 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
30901 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
30903 for (i = 0; i < ARRAY_SIZE(tests); ++i)
30905 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
30906 ok(hr == S_OK, "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
30907 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30909 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
30910 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
30911 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
30912 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
30913 draw_quad(&test_context);
30914 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
30915 get_buffer_readback(buffer, &rb);
30916 data = get_readback_color(&rb, 0, 0, 0);
30917 ok(1024 <= data && data <= 1056, "Test %u: Got unexpected value %u.\n", i, data);
30918 release_resource_readback(&rb);
30920 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
30921 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
30922 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
30923 1, &rtv, NULL, 1, 1, &uav, NULL);
30924 draw_quad(&test_context);
30925 get_buffer_readback(buffer, &rb);
30926 data = get_readback_color(&rb, 0, 0, 0);
30927 todo_wine_if(tests[i].todo)
30929 if (tests[i].sample_shading)
30931 ok(4096 <= data || broken(tests[i].broken && data >= 1024),
30932 "Test %u: Got unexpected value %u.\n", i, data);
30934 else
30936 ok((1024 <= data && data <= 1056) || broken(tests[i].broken && data >= 4096),
30937 "Test %u: Got unexpected value %u.\n", i, data);
30940 release_resource_readback(&rb);
30942 ID3D11PixelShader_Release(ps);
30945 if (is_warp_device(device))
30947 skip("Sample shading tests fail on WARP.\n");
30948 goto done;
30951 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps);
30952 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30953 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30954 ID3D11PixelShader_Release(ps);
30956 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
30957 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30958 draw_quad(&test_context);
30959 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
30960 (ID3D11Resource *)texture, 0, texture_desc.Format);
30961 check_texture_color(test_context.backbuffer, 0xff404040, 2);
30963 hr = ID3D11Device_CreatePixelShader(device, ps_resolve_code, sizeof(ps_resolve_code), NULL, &ps);
30964 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30965 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30966 ID3D11PixelShader_Release(ps);
30967 ps_constant.x = 0;
30968 ps_constant.y = texture_desc.Width;
30969 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
30970 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30972 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
30973 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
30974 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
30975 draw_quad(&test_context);
30976 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
30977 ps_constant.x = 1;
30978 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
30979 draw_quad(&test_context);
30980 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
30981 ps_constant.x = 2;
30982 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
30983 draw_quad(&test_context);
30984 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
30985 ps_constant.x = 3;
30986 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
30987 draw_quad(&test_context);
30988 check_texture_color(test_context.backbuffer, 0xff000000, 0);
30990 ID3D11Buffer_Release(cb);
30991 done:
30992 ID3D11Buffer_Release(buffer);
30993 ID3D11UnorderedAccessView_Release(uav);
30994 ID3D11RenderTargetView_Release(rtv);
30995 ID3D11ShaderResourceView_Release(srv);
30996 ID3D11Texture2D_Release(texture);
30997 release_test_context(&test_context);
31000 static void test_sample_mask(void)
31002 static const DWORD ps_code[] =
31004 #if 0
31005 float4 main(in float4 pos : SV_Position, out uint sample_mask : SV_Coverage) : SV_Target
31007 sample_mask = 0x5;
31008 return float4(1.0, 1.0, 1.0, 1.0);
31010 #endif
31011 0x43425844, 0x196779a9, 0xda85988a, 0xb7f0a0b6, 0xb30dd6ba, 0x00000001, 0x00000114, 0x00000003,
31012 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31013 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
31014 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
31015 0x00000000, 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000001, 0xffffffff, 0x00000e01,
31016 0x545f5653, 0x65677261, 0x56530074, 0x766f435f, 0x67617265, 0xabab0065, 0x58454853, 0x00000054,
31017 0x00000050, 0x00000015, 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x0000f000,
31018 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
31019 0x04000036, 0x0000f001, 0x00004001, 0x00000005, 0x0100003e,
31021 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
31022 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
31023 struct d3d11_test_context test_context;
31024 D3D11_TEXTURE2D_DESC texture_desc;
31025 ID3D11DeviceContext *context;
31026 ID3D11RenderTargetView *rtv;
31027 ID3D11Texture2D *texture;
31028 ID3D11PixelShader *ps;
31029 ID3D11Device *device;
31030 UINT quality_levels;
31031 HRESULT hr;
31033 if (!init_test_context(&test_context, &feature_level))
31034 return;
31035 device = test_context.device;
31036 context = test_context.immediate_context;
31038 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &quality_levels);
31039 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
31040 if (!quality_levels)
31042 skip("4xMSAA not supported.\n");
31043 release_test_context(&test_context);
31044 return;
31047 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31048 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31049 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31051 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31052 texture_desc.SampleDesc.Count = 4;
31053 texture_desc.SampleDesc.Quality = 0;
31054 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31055 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31056 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
31057 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
31059 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
31060 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31061 draw_quad(&test_context);
31062 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
31063 (ID3D11Resource *)texture, 0, texture_desc.Format);
31064 check_texture_color(test_context.backbuffer, 0x7f7f7f7f, 1);
31066 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, 0xb);
31067 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31068 draw_quad(&test_context);
31069 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
31070 (ID3D11Resource *)texture, 0, texture_desc.Format);
31071 check_texture_color(test_context.backbuffer, 0x3f3f3f3f, 1);
31073 ID3D11RenderTargetView_Release(rtv);
31074 ID3D11Texture2D_Release(texture);
31075 ID3D11PixelShader_Release(ps);
31076 release_test_context(&test_context);
31079 static void test_depth_clip(void)
31081 struct d3d11_test_context test_context;
31082 D3D11_TEXTURE2D_DESC texture_desc;
31083 D3D11_RASTERIZER_DESC rs_desc;
31084 ID3D11DeviceContext *context;
31085 ID3D11DepthStencilView *dsv;
31086 ID3D11RasterizerState *rs;
31087 ID3D11Texture2D *texture;
31088 ID3D11Device *device;
31089 unsigned int count;
31090 D3D11_VIEWPORT vp;
31091 HRESULT hr;
31093 if (!init_test_context(&test_context, NULL))
31094 return;
31095 device = test_context.device;
31096 context = test_context.immediate_context;
31098 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31099 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
31100 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
31102 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31103 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
31104 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
31105 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
31106 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
31108 count = 1;
31109 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
31111 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
31112 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
31113 draw_quad_z(&test_context, 2.0f);
31114 check_texture_float(texture, 1.0f, 1);
31115 draw_quad_z(&test_context, 0.5f);
31116 check_texture_float(texture, 0.5f, 1);
31117 draw_quad_z(&test_context, -1.0f);
31118 check_texture_float(texture, 0.5f, 1);
31120 rs_desc.FillMode = D3D11_FILL_SOLID;
31121 rs_desc.CullMode = D3D11_CULL_BACK;
31122 rs_desc.FrontCounterClockwise = FALSE;
31123 rs_desc.DepthBias = 0;
31124 rs_desc.DepthBiasClamp = 0.0f;
31125 rs_desc.SlopeScaledDepthBias = 0.0f;
31126 rs_desc.DepthClipEnable = FALSE;
31127 rs_desc.ScissorEnable = FALSE;
31128 rs_desc.MultisampleEnable = FALSE;
31129 rs_desc.AntialiasedLineEnable = FALSE;
31130 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
31131 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
31133 ID3D11DeviceContext_RSSetState(context, rs);
31135 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
31136 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
31137 draw_quad_z(&test_context, 2.0f);
31138 check_texture_float(texture, 0.6f, 1);
31139 draw_quad_z(&test_context, 0.5f);
31140 check_texture_float(texture, 0.5f, 1);
31141 draw_quad_z(&test_context, -1.0f);
31142 check_texture_float(texture, 0.4f, 1);
31144 ID3D11DepthStencilView_Release(dsv);
31145 ID3D11Texture2D_Release(texture);
31146 ID3D11RasterizerState_Release(rs);
31147 release_test_context(&test_context);
31150 static void test_staging_buffers(void)
31152 struct d3d11_test_context test_context;
31153 ID3D11Buffer *dst_buffer, *src_buffer;
31154 D3D11_SUBRESOURCE_DATA resource_data;
31155 D3D11_BUFFER_DESC buffer_desc;
31156 ID3D11DeviceContext *context;
31157 struct resource_readback rb;
31158 float data[16], value;
31159 ID3D11Device *device;
31160 unsigned int i;
31161 HRESULT hr;
31163 if (!init_test_context(&test_context, NULL))
31164 return;
31165 device = test_context.device;
31166 context = test_context.immediate_context;
31168 buffer_desc.ByteWidth = sizeof(data);
31169 buffer_desc.Usage = D3D11_USAGE_STAGING;
31170 buffer_desc.BindFlags = 0;
31171 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
31172 buffer_desc.MiscFlags = 0;
31173 buffer_desc.StructureByteStride = 0;
31175 for (i = 0; i < ARRAY_SIZE(data); ++i)
31176 data[i] = i;
31177 resource_data.pSysMem = data;
31178 resource_data.SysMemPitch = 0;
31179 resource_data.SysMemSlicePitch = 0;
31181 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &src_buffer);
31182 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31184 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
31185 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
31186 buffer_desc.CPUAccessFlags = 0;
31187 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &dst_buffer);
31188 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31190 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
31191 get_buffer_readback(dst_buffer, &rb);
31192 for (i = 0; i < ARRAY_SIZE(data); ++i)
31194 value = get_readback_float(&rb, i, 0);
31195 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
31197 release_resource_readback(&rb);
31199 for (i = 0; i < ARRAY_SIZE(data); ++i)
31200 data[i] = 2 * i;
31201 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, NULL, data, 0, 0);
31202 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
31203 get_buffer_readback(dst_buffer, &rb);
31204 for (i = 0; i < ARRAY_SIZE(data); ++i)
31206 value = get_readback_float(&rb, i, 0);
31207 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
31209 release_resource_readback(&rb);
31211 ID3D11Buffer_Release(dst_buffer);
31212 ID3D11Buffer_Release(src_buffer);
31213 release_test_context(&test_context);
31216 static void test_render_a8(void)
31218 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
31219 struct d3d11_test_context test_context;
31220 D3D11_TEXTURE2D_DESC texture_desc;
31221 ID3D11DeviceContext *context;
31222 ID3D11RenderTargetView *rtv;
31223 struct resource_readback rb;
31224 ID3D11Texture2D *texture;
31225 ID3D11PixelShader *ps;
31226 ID3D11Device *device;
31227 unsigned int i;
31228 HRESULT hr;
31230 static const DWORD ps_code[] =
31232 #if 0
31233 void main(out float4 target : SV_Target)
31235 target = float4(0.0f, 0.25f, 0.5f, 1.0f);
31237 #endif
31238 0x43425844, 0x8a06129f, 0x3041bde2, 0x09389749, 0xb339ba8b, 0x00000001, 0x000000b0, 0x00000003,
31239 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31240 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31241 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
31242 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31243 0x3e800000, 0x3f000000, 0x3f800000, 0x0100003e,
31246 if (!init_test_context(&test_context, NULL))
31247 return;
31248 device = test_context.device;
31249 context = test_context.immediate_context;
31251 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31252 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31253 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31255 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31256 texture_desc.Format = DXGI_FORMAT_A8_UNORM;
31257 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31258 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31259 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
31260 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
31262 for (i = 0; i < 2; ++i)
31264 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31265 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
31266 draw_quad(&test_context);
31267 get_texture_readback(texture, 0, &rb);
31268 check_readback_data_u8(&rb, NULL, 0xff, 0);
31269 release_resource_readback(&rb);
31271 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
31272 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
31273 draw_quad(&test_context);
31274 check_texture_sub_resource_color(test_context.backbuffer, 0, NULL, 0xff7f4000, 1);
31277 ID3D11PixelShader_Release(ps);
31278 ID3D11Texture2D_Release(texture);
31279 ID3D11RenderTargetView_Release(rtv);
31280 release_test_context(&test_context);
31283 static void test_standard_pattern(void)
31285 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
31286 struct d3d11_test_context test_context;
31287 struct swapchain_desc swapchain_desc;
31288 D3D11_TEXTURE2D_DESC texture_desc;
31289 ID3D11UnorderedAccessView *uav;
31290 D3D11_BUFFER_DESC buffer_desc;
31291 ID3D11ShaderResourceView *srv;
31292 ID3D11DeviceContext *context;
31293 struct resource_readback rb;
31294 ID3D11Texture2D *texture;
31295 ID3D11PixelShader *ps;
31296 ID3D11Buffer *buffer;
31297 ID3D11Device *device;
31298 unsigned int i;
31299 HRESULT hr;
31301 static const DWORD ps_samplepos[] =
31303 #if 0
31304 Texture2DMS<float> t;
31305 RWByteAddressBuffer u;
31307 float4 main() : SV_Target
31309 u.Store2(0, asuint(t.GetSamplePosition(0)));
31310 u.Store2(8, asuint(t.GetSamplePosition(1)));
31311 u.Store2(16, asuint(t.GetSamplePosition(2)));
31312 u.Store2(24, asuint(t.GetSamplePosition(3)));
31313 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31315 #endif
31316 0x43425844, 0xa1db77e8, 0x804d8862, 0x0e3c213d, 0x2703dec6, 0x00000001, 0x00000190, 0x00000003,
31317 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31318 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31319 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000118, 0x00000050, 0x00000046,
31320 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
31321 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0800006e, 0x00100032, 0x00000000,
31322 0x00107046, 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x0800006e, 0x001000c2, 0x00000000,
31323 0x00107406, 0x00000000, 0x00004001, 0x00000001, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001,
31324 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
31325 0x00000000, 0x00004001, 0x00000002, 0x00000000, 0x0800006e, 0x001000c2, 0x00000000, 0x00107406,
31326 0x00000000, 0x00004001, 0x00000003, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001,
31327 0x00000010, 0x00100e46, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31328 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e
31330 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
31331 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
31332 static const unsigned int zero[4] = {0};
31333 static const float standard_pos4[] =
31335 -2 / 16.0f, -6 / 16.0f,
31336 6 / 16.0f, -2 / 16.0f,
31337 -6 / 16.0f, 2 / 16.0f,
31338 2 / 16.0f, 6 / 16.0f,
31341 swapchain_desc.windowed = TRUE;
31342 swapchain_desc.buffer_count = 1;
31343 swapchain_desc.width = 32;
31344 swapchain_desc.height = 32;
31345 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
31346 swapchain_desc.flags = 0;
31347 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
31348 return;
31349 device = test_context.device;
31350 context = test_context.immediate_context;
31352 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31353 texture_desc.SampleDesc.Count = 4;
31354 texture_desc.SampleDesc.Quality = D3D11_STANDARD_MULTISAMPLE_PATTERN;
31355 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
31356 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31357 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31358 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
31359 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
31361 buffer_desc.ByteWidth = 1024;
31362 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
31363 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
31364 buffer_desc.CPUAccessFlags = 0;
31365 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
31366 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
31367 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31368 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
31369 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
31370 U(uav_desc).Buffer.FirstElement = 0;
31371 U(uav_desc).Buffer.NumElements = 256;
31372 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
31373 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
31374 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
31376 hr = ID3D11Device_CreatePixelShader(device, ps_samplepos, sizeof(ps_samplepos), NULL, &ps);
31377 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31378 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31380 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
31381 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
31382 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
31383 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
31384 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31385 draw_quad(&test_context);
31386 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
31387 get_buffer_readback(buffer, &rb);
31388 for (i = 0; i < ARRAY_SIZE(standard_pos4); ++i)
31390 float data = get_readback_float(&rb, i, 0);
31391 /* Wine does not support GetSamplePosition. */
31392 todo_wine ok(data == standard_pos4[i], "Got sample position %.8e, expected %.8e.\n", data, standard_pos4[i]);
31394 release_resource_readback(&rb);
31396 ID3D11PixelShader_Release(ps);
31397 ID3D11Buffer_Release(buffer);
31398 ID3D11UnorderedAccessView_Release(uav);
31399 ID3D11ShaderResourceView_Release(srv);
31400 ID3D11Texture2D_Release(texture);
31401 release_test_context(&test_context);
31404 static void test_desktop_window(void)
31406 ID3D11RenderTargetView *backbuffer_rtv;
31407 DXGI_SWAP_CHAIN_DESC swapchain_desc;
31408 ID3D11DeviceContext *context;
31409 ID3D11Texture2D *backbuffer;
31410 IDXGISwapChain *swapchain;
31411 IDXGIDevice *dxgi_device;
31412 IDXGIAdapter *adapter;
31413 IDXGIFactory *factory;
31414 ID3D11Device *device;
31415 ULONG refcount;
31416 HRESULT hr;
31418 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
31420 if (!(device = create_device(NULL)))
31422 skip("Failed to create device.\n");
31423 return;
31426 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
31427 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
31428 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
31429 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
31430 IDXGIDevice_Release(dxgi_device);
31431 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
31432 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
31433 IDXGIAdapter_Release(adapter);
31435 swapchain_desc.BufferDesc.Width = 640;
31436 swapchain_desc.BufferDesc.Height = 480;
31437 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
31438 swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
31439 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31440 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
31441 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
31442 swapchain_desc.SampleDesc.Count = 1;
31443 swapchain_desc.SampleDesc.Quality = 0;
31444 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
31445 swapchain_desc.BufferCount = 1;
31446 swapchain_desc.OutputWindow = GetDesktopWindow();
31447 swapchain_desc.Windowed = TRUE;
31448 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
31449 swapchain_desc.Flags = 0;
31451 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
31452 ok(hr == S_OK || broken(hr == DXGI_ERROR_INVALID_CALL) /* Not available on all Windows versions. */,
31453 "Failed to create swapchain, hr %#x.\n", hr);
31454 IDXGIFactory_Release(factory);
31455 if (FAILED(hr))
31457 ID3D11Device_Release(device);
31458 return;
31461 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
31462 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
31464 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &backbuffer_rtv);
31465 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
31467 ID3D11Device_GetImmediateContext(device, &context);
31469 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
31470 check_texture_color(backbuffer, 0xff0000ff, 1);
31472 hr = IDXGISwapChain_Present(swapchain, 0, 0);
31473 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31475 ID3D11RenderTargetView_Release(backbuffer_rtv);
31476 ID3D11Texture2D_Release(backbuffer);
31477 IDXGISwapChain_Release(swapchain);
31478 ID3D11DeviceContext_Release(context);
31479 refcount = ID3D11Device_Release(device);
31480 ok(!refcount, "Device has %u references left.\n", refcount);
31483 static void test_sample_attached_rtv(void)
31485 ID3D11ShaderResourceView *srv, *srv2, *srv_test, *srv_ds;
31486 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc, srvds_desc;
31487 ID3D11Texture2D *texture, *texture2, *dstexture;
31488 ID3D11RenderTargetView *rtv, *rtv2, *rtvs[2];
31489 D3D11_DEPTH_STENCIL_VIEW_DESC dsview_desc;
31490 struct d3d11_test_context test_context;
31491 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
31492 D3D11_TEXTURE2D_DESC texture_desc;
31493 D3D_FEATURE_LEVEL feature_level;
31494 D3D11_SAMPLER_DESC sampler_desc;
31495 ID3D11DepthStencilView *dsview;
31496 ID3D11BlendState *blend_state;
31497 ID3D11DeviceContext *context;
31498 D3D11_BLEND_DESC blend_desc;
31499 ID3D11SamplerState *sampler;
31500 struct resource_readback rb;
31501 ID3D11PixelShader *ps;
31502 ID3D11Device *device;
31503 unsigned int x, y;
31504 unsigned int i;
31505 D3D11_BOX box;
31506 DWORD color;
31507 HRESULT hr;
31509 static const DWORD ps_ld_code[] =
31511 #if 0
31512 Texture2D t;
31514 struct PS_OUTPUT
31516 float4 color0: SV_Target0;
31517 float4 color1: SV_Target1;
31520 PS_OUTPUT main(float4 position : SV_POSITION)
31522 PS_OUTPUT output;
31523 float3 p;
31525 t.GetDimensions(0, p.x, p.y, p.z);
31526 p.z = 0;
31527 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
31528 output.color0 = output.color1 = t.Load(int3(p)) + float4(0.25, 0.25, 0.25, 0.25);
31529 return output;
31531 #endif
31532 0x43425844, 0x08dd0517, 0x07d7e538, 0x4cad261f, 0xa2ae5942, 0x00000001, 0x00000200, 0x00000003,
31533 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31534 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
31535 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
31536 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
31537 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000014c, 0x00000040, 0x00000053, 0x04001858,
31538 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
31539 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0700003d,
31540 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032,
31541 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000,
31542 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
31543 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0500001b,
31544 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46,
31545 0x00000000, 0x00107e46, 0x00000000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
31546 0x00004002, 0x3e800000, 0x3e800000, 0x3e800000, 0x3e800000, 0x05000036, 0x001020f2, 0x00000000,
31547 0x00100e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00100e46, 0x00000000, 0x0100003e,
31549 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
31550 static const struct
31552 DXGI_FORMAT texture_format, dsv_format, srv_format;
31553 UINT dsv_flags;
31554 BOOL srv_bind_allowed;
31556 ds_tests[] =
31558 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
31559 0, FALSE},
31560 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
31561 D3D11_DSV_READ_ONLY_DEPTH, TRUE},
31562 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_X24_TYPELESS_G8_UINT,
31563 D3D11_DSV_READ_ONLY_DEPTH, FALSE},
31564 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_X24_TYPELESS_G8_UINT,
31565 D3D11_DSV_READ_ONLY_STENCIL, TRUE},
31566 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT,
31567 0, FALSE},
31568 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT,
31569 D3D11_DSV_READ_ONLY_DEPTH, TRUE},
31572 if (!init_test_context(&test_context, NULL))
31573 return;
31575 device = test_context.device;
31576 context = test_context.immediate_context;
31578 feature_level = ID3D11Device_GetFeatureLevel(device);
31580 texture_desc.SampleDesc.Count = 1;
31581 texture_desc.SampleDesc.Quality = 0;
31582 texture_desc.Usage = D3D11_USAGE_DEFAULT;
31583 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
31584 texture_desc.CPUAccessFlags = 0;
31585 texture_desc.MiscFlags = 0;
31587 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
31588 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
31589 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
31590 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
31591 sampler_desc.MipLODBias = 0.0f;
31592 sampler_desc.MaxAnisotropy = 0;
31593 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
31594 sampler_desc.BorderColor[0] = 0.0f;
31595 sampler_desc.BorderColor[1] = 0.0f;
31596 sampler_desc.BorderColor[2] = 0.0f;
31597 sampler_desc.BorderColor[3] = 0.0f;
31598 sampler_desc.MinLOD = 0.0f;
31599 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
31601 hr = ID3D11Device_CreatePixelShader(device, ps_ld_code, sizeof(ps_ld_code), NULL, &ps);
31602 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31604 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31606 texture_desc.Width = 64;
31607 texture_desc.Height = 64;
31608 texture_desc.MipLevels = 2;
31609 texture_desc.ArraySize = 1;
31610 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31612 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31613 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31615 texture_desc.Width = 640;
31616 texture_desc.Height = 480;
31617 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture2);
31618 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31620 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
31621 sampler_desc.MipLODBias = 0.0f;
31622 sampler_desc.MinLOD = 0.0f;
31623 sampler_desc.MaxLOD = 0.0f;
31625 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
31626 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31628 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
31630 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
31632 memset(&rtv_desc, 0, sizeof(rtv_desc));
31633 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31634 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
31635 U(rtv_desc).Texture2D.MipSlice = 0;
31637 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv);
31638 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31639 U(rtv_desc).Texture2D.MipSlice = 1;
31640 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv2);
31641 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31643 rtvs[0] = test_context.backbuffer_rtv;
31644 rtvs[1] = rtv;
31646 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31648 memset(&srv_desc, 0, sizeof(srv_desc));
31649 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31650 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
31651 U(srv_desc).Texture2D.MipLevels = 1;
31653 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
31654 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31655 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31657 draw_quad(&test_context);
31659 set_box(&box, 0, 0, 0, 320, 240, 1);
31660 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2, 1, 0, 0, 0, (ID3D11Resource *)texture2, 0, &box);
31662 get_texture_readback(texture2, 0, &rb);
31663 for (y = 0; y < 4; ++y)
31665 for (x = 0; x < 4; ++x)
31667 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31668 ok(compare_color(color, 0x40404040, 2),
31669 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31672 release_resource_readback(&rb);
31673 get_texture_readback(texture2, 1, &rb);
31674 for (y = 0; y < 4; ++y)
31676 for (x = 0; x < 4; ++x)
31678 color = get_readback_color(&rb, 40 + x * 80, 30 + y * 60, 0);
31679 ok(compare_color(color, 0x40404040, 2),
31680 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31683 release_resource_readback(&rb);
31685 ID3D11ShaderResourceView_Release(srv);
31686 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31688 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
31690 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv);
31691 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31693 U(srv_desc).Texture2D.MostDetailedMip = 1;
31694 U(srv_desc).Texture2D.MipLevels = 1;
31695 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv2);
31696 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31698 memset(&blend_desc, 0, sizeof(blend_desc));
31699 blend_desc.IndependentBlendEnable = TRUE;
31700 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
31701 blend_desc.RenderTarget[1].RenderTargetWriteMask = 0;
31702 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
31703 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31704 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
31705 ID3D11BlendState_Release(blend_state);
31707 /* SRV does not get bound if resource is attached as render target, even if write mask is 0. */
31708 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31709 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31710 ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
31712 blend_desc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
31713 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
31714 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31715 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
31716 ID3D11BlendState_Release(blend_state);
31718 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
31720 draw_quad(&test_context);
31721 draw_quad(&test_context);
31723 get_texture_readback(test_context.backbuffer, 0, &rb);
31724 for (y = 0; y < 4; ++y)
31726 for (x = 0; x < 4; ++x)
31728 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31729 ok(compare_color(color, 0x40404040, 2),
31730 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31733 release_resource_readback(&rb);
31735 get_texture_readback(texture2, 0, &rb);
31736 for (y = 0; y < 4; ++y)
31738 for (x = 0; x < 4; ++x)
31740 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31741 ok(compare_color(color, 0x40404040, 2),
31742 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31745 release_resource_readback(&rb);
31747 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
31748 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31749 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31750 ok(!!srv_test, "Unexpected SRV %p.\n", srv_test);
31751 ID3D11ShaderResourceView_Release(srv_test);
31753 draw_quad(&test_context);
31754 get_texture_readback(test_context.backbuffer, 0, &rb);
31755 for (y = 0; y < 4; ++y)
31757 for (x = 0; x < 4; ++x)
31759 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31760 ok(compare_color(color, 0x80808080, 2),
31761 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31764 release_resource_readback(&rb);
31766 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31768 /* SRV is reset when the same resource is set as render target. */
31769 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31770 ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
31772 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
31773 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31774 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31775 ok(!!srv_test, "Unexpected SRV %p.\n", srv_test);
31776 ID3D11ShaderResourceView_Release(srv_test);
31778 draw_quad(&test_context);
31779 get_texture_readback(test_context.backbuffer, 0, &rb);
31780 for (y = 0; y < 4; ++y)
31782 for (x = 0; x < 4; ++x)
31784 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31785 ok(compare_color(color, 0x80808080, 2),
31786 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31789 release_resource_readback(&rb);
31791 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
31792 memset(&dsview_desc, 0, sizeof(dsview_desc));
31793 dsview_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
31795 memset(&srvds_desc, 0, sizeof(srvds_desc));
31796 srvds_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
31797 U(srvds_desc).Texture2D.MipLevels = 1;
31799 for (i = 0; i < ARRAY_SIZE(ds_tests); ++i)
31801 if (ds_tests[i].dsv_flags && feature_level < D3D_FEATURE_LEVEL_11_0)
31803 static unsigned int skip_once;
31805 if (!skip_once++)
31806 skip("Read only depths or stencils are not supported.\n");
31808 continue;
31811 texture_desc.Format = ds_tests[i].texture_format;
31812 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &dstexture);
31813 ok(hr == S_OK, "Test %u, got unexpected hr %#x.\n", i, hr);
31814 dsview_desc.Format = ds_tests[i].dsv_format;
31815 dsview_desc.Flags = ds_tests[i].dsv_flags;
31816 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)dstexture, &dsview_desc, &dsview);
31817 ok(hr == S_OK, "Test %u, got unexpected hr %#x.\n", i, hr);
31819 srvds_desc.Format = ds_tests[i].srv_format;
31820 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dstexture, &srvds_desc, &srv_ds);
31821 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31823 ID3D11DeviceContext_OMSetRenderTargets(context, 1, rtvs, NULL);
31824 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_ds);
31825 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31826 ok(!!srv_test, "Test %u, unexpected SRV %p.\n", i, srv_test);
31827 ID3D11ShaderResourceView_Release(srv_test);
31829 ID3D11DeviceContext_OMSetRenderTargets(context, 1, rtvs, dsview);
31830 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31831 ok(!!srv_test == ds_tests[i].srv_bind_allowed, "Test %u, unexpected SRV %p.\n", i, srv_test);
31832 if (srv_test)
31833 ID3D11ShaderResourceView_Release(srv_test);
31835 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_ds);
31836 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31837 ok(!!srv_test == ds_tests[i].srv_bind_allowed, "Test %u, unexpected SRV %p.\n", i, srv_test);
31838 if (srv_test)
31839 ID3D11ShaderResourceView_Release(srv_test);
31841 ID3D11Texture2D_Release(dstexture);
31842 ID3D11DepthStencilView_Release(dsview);
31843 ID3D11ShaderResourceView_Release(srv_ds);
31846 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31848 ID3D11RenderTargetView_Release(rtv2);
31849 ID3D11RenderTargetView_Release(rtv);
31850 ID3D11ShaderResourceView_Release(srv2);
31851 ID3D11ShaderResourceView_Release(srv);
31852 ID3D11SamplerState_Release(sampler);
31853 ID3D11PixelShader_Release(ps);
31854 ID3D11Texture2D_Release(texture2);
31855 ID3D11Texture2D_Release(texture);
31856 ID3D11SamplerState_Release(sampler);
31858 release_test_context(&test_context);
31861 static void test_color_mask(void)
31863 struct d3d11_test_context test_context;
31864 D3D11_TEXTURE2D_DESC texture_desc;
31865 ID3D11RenderTargetView *rtvs[8];
31866 ID3D11BlendState *blend_state;
31867 ID3D11DeviceContext *context;
31868 struct resource_readback rb;
31869 D3D11_BLEND_DESC blend_desc;
31870 ID3D11Texture2D *rts[8];
31871 ID3D11PixelShader *ps;
31872 ID3D11Device *device;
31873 unsigned int i;
31874 DWORD color;
31875 HRESULT hr;
31877 static const DWORD expected_colors[] =
31878 {0xff000080, 0xff0080ff, 0xff8000ff, 0x80808080, 0x800000ff, 0xff008080, 0x800080ff, 0xff0000ff};
31880 static const DWORD ps_code[] =
31882 #if 0
31883 void main(float4 position : SV_Position,
31884 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
31885 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
31886 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
31887 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
31889 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.5f, 0.5f, 0.5f, 0.5f);
31891 #endif
31892 0x43425844, 0x7b1ab233, 0xdbe32d3b, 0x77084cc5, 0xe874d2b5, 0x00000001, 0x000002b0, 0x00000003,
31893 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31894 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
31895 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
31896 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
31897 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
31898 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
31899 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
31900 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
31901 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
31902 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
31903 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
31904 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
31905 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000,
31906 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000,
31907 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3f000000,
31908 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3f000000,
31909 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3f000000,
31910 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3f000000,
31911 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3f000000,
31912 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3f000000,
31913 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
31916 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
31918 if (!init_test_context(&test_context, NULL))
31919 return;
31921 device = test_context.device;
31922 context = test_context.immediate_context;
31924 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31925 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31926 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31928 memset(&blend_desc, 0, sizeof(blend_desc));
31929 blend_desc.IndependentBlendEnable = TRUE;
31930 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED;
31931 blend_desc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN;
31932 blend_desc.RenderTarget[2].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_BLUE;
31933 blend_desc.RenderTarget[3].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
31934 blend_desc.RenderTarget[4].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALPHA;
31935 blend_desc.RenderTarget[5].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED | D3D11_COLOR_WRITE_ENABLE_GREEN;
31936 blend_desc.RenderTarget[6].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN | D3D11_COLOR_WRITE_ENABLE_ALPHA;
31937 blend_desc.RenderTarget[7].RenderTargetWriteMask = 0;
31939 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
31940 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
31941 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
31942 ID3D11BlendState_Release(blend_state);
31944 for (i = 0; i < 8; ++i)
31946 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31947 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
31948 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
31950 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
31951 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
31954 ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
31956 for (i = 0; i < 8; ++i)
31957 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], red);
31958 draw_quad(&test_context);
31960 for (i = 0; i < 8; ++i)
31962 get_texture_readback(rts[i], 0, &rb);
31963 color = get_readback_color(&rb, 320, 240, 0);
31964 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
31965 release_resource_readback(&rb);
31968 blend_desc.IndependentBlendEnable = FALSE;
31969 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
31970 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
31971 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
31972 ID3D11BlendState_Release(blend_state);
31974 for (i = 0; i < 8; ++i)
31975 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], red);
31976 draw_quad(&test_context);
31978 for (i = 0; i < 8; ++i)
31980 get_texture_readback(rts[i], 0, &rb);
31981 color = get_readback_color(&rb, 320, 240, 0);
31982 ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
31983 release_resource_readback(&rb);
31985 ID3D11Texture2D_Release(rts[i]);
31986 ID3D11RenderTargetView_Release(rtvs[i]);
31989 ID3D11PixelShader_Release(ps);
31990 release_test_context(&test_context);
31993 static void test_independent_blend(void)
31995 struct d3d11_test_context test_context;
31996 D3D11_TEXTURE2D_DESC texture_desc;
31997 ID3D11RenderTargetView *rtvs[8];
31998 ID3D11BlendState *blend_state;
31999 ID3D11DeviceContext *context;
32000 struct resource_readback rb;
32001 ID3D11Texture2D *rts[8];
32002 ID3D11PixelShader *ps;
32003 ID3D11Device *device;
32004 unsigned int i;
32005 DWORD color;
32006 HRESULT hr;
32008 static const DWORD ps_code[] =
32010 #if 0
32011 void main(float4 position : SV_Position,
32012 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
32013 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
32014 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
32015 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
32017 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.1f, 0.2f, 0.3f, 0.4f);
32019 #endif
32020 0x43425844, 0xb3dca7dc, 0x4a31f0f1, 0x747569cb, 0xae7af5ce, 0x00000001, 0x000002b0, 0x00000003,
32021 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
32022 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
32023 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
32024 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
32025 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
32026 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
32027 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
32028 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
32029 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
32030 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
32031 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
32032 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
32033 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3dcccccd,
32034 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3dcccccd,
32035 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3dcccccd,
32036 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3dcccccd,
32037 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3dcccccd,
32038 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3dcccccd,
32039 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3dcccccd,
32040 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3dcccccd,
32041 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x0100003e,
32044 D3D11_BLEND_DESC blend_desc =
32046 .IndependentBlendEnable = TRUE,
32047 .RenderTarget =
32049 {TRUE, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD,
32050 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32051 {TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
32052 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32053 {TRUE, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_OP_ADD,
32054 D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32055 {TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
32056 D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN, D3D11_COLOR_WRITE_ENABLE_ALL},
32057 {TRUE, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_OP_ADD,
32058 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32059 {TRUE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_BLEND_FACTOR, D3D11_BLEND_OP_SUBTRACT,
32060 D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_REV_SUBTRACT, D3D11_COLOR_WRITE_ENABLE_ALL},
32061 {FALSE, 0, 0, 0, 0, 0, 0, D3D11_COLOR_WRITE_ENABLE_ALL},
32062 {TRUE, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_OP_ADD,
32063 D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_DEST_ALPHA, D3D11_BLEND_OP_SUBTRACT,
32064 D3D11_COLOR_WRITE_ENABLE_ALL},
32068 static const DWORD expected_colors[] =
32069 {0x66426e1c, 0xb34c3319, 0xa6214a05, 0x66333319, 0xb34c4829, 0x4d19000a, 0x664c3319, 0x081f3305};
32071 static const float clear_color[] = {0.1f, 0.5f, 0.2f, 0.7f};
32072 static const float blend_factor[] = {0.8f, 0.4f, 0.6f, 0.2f};
32074 if (!init_test_context(&test_context, NULL))
32075 return;
32077 device = test_context.device;
32078 context = test_context.immediate_context;
32080 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
32081 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
32082 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32084 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32085 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32086 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
32087 ID3D11BlendState_Release(blend_state);
32089 for (i = 0; i < 8; ++i)
32091 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32092 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
32093 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
32095 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
32096 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
32099 ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
32101 for (i = 0; i < 8; ++i)
32102 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
32103 draw_quad(&test_context);
32105 for (i = 0; i < 8; ++i)
32107 get_texture_readback(rts[i], 0, &rb);
32108 color = get_readback_color(&rb, 320, 240, 0);
32109 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32110 release_resource_readback(&rb);
32113 blend_desc.IndependentBlendEnable = FALSE;
32114 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32115 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32116 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
32117 ID3D11BlendState_Release(blend_state);
32119 for (i = 0; i < 8; ++i)
32120 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
32121 draw_quad(&test_context);
32123 for (i = 0; i < 8; ++i)
32125 get_texture_readback(rts[i], 0, &rb);
32126 color = get_readback_color(&rb, 320, 240, 0);
32127 ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32128 release_resource_readback(&rb);
32130 ID3D11Texture2D_Release(rts[i]);
32131 ID3D11RenderTargetView_Release(rtvs[i]);
32134 ID3D11PixelShader_Release(ps);
32135 release_test_context(&test_context);
32138 static void test_dual_source_blend(void)
32140 struct d3d11_test_context test_context;
32141 ID3D11BlendState *blend_state;
32142 ID3D11DeviceContext *context;
32143 ID3D11PixelShader *ps;
32144 ID3D11Device *device;
32145 DWORD color;
32146 HRESULT hr;
32148 static const DWORD ps_code[] =
32150 #if 0
32151 void main(float4 position : SV_Position,
32152 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1)
32154 t0 = float4(0.5, 0.5, 0.0, 1.0);
32155 t1 = float4(0.0, 0.5, 0.5, 0.0);
32157 #endif
32158 0x43425844, 0x87120d01, 0xa0014738, 0x3a32d86c, 0x9d757441, 0x00000001, 0x00000118, 0x00000003,
32159 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
32160 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
32161 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
32162 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
32163 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03000065,
32164 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x08000036, 0x001020f2, 0x00000000,
32165 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001,
32166 0x00004002, 0x00000000, 0x3f000000, 0x3f000000, 0x00000000, 0x0100003e
32169 static const D3D11_BLEND_DESC blend_desc =
32171 .RenderTarget[0].BlendEnable = TRUE,
32172 .RenderTarget[0].SrcBlend = D3D11_BLEND_SRC1_COLOR,
32173 .RenderTarget[0].DestBlend = D3D11_BLEND_SRC1_COLOR,
32174 .RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD,
32175 .RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE,
32176 .RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO,
32177 .RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD,
32178 .RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL,
32181 static const float clear_color[] = {0.7f, 0.0f, 1.0f, 1.0f};
32183 if (!init_test_context(&test_context, NULL))
32184 return;
32186 device = test_context.device;
32187 context = test_context.immediate_context;
32189 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
32190 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
32191 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32193 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32194 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32195 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32196 ID3D11BlendState_Release(blend_state);
32198 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, clear_color);
32199 draw_quad(&test_context);
32201 color = get_texture_color(test_context.backbuffer, 320, 240);
32202 ok(compare_color(color, 0x80804000, 1), "Got unexpected color 0x%08x.\n", color);
32204 ID3D11PixelShader_Release(ps);
32205 release_test_context(&test_context);
32208 static void test_deferred_context_state(void)
32210 ID3D11Buffer *green_buffer, *blue_buffer, *ret_buffer;
32211 ID3D11DeviceContext *immediate, *deferred;
32212 struct d3d11_test_context test_context;
32213 ID3D11CommandList *list1, *list2;
32214 ID3D11Device *device;
32215 HRESULT hr;
32217 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32218 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
32220 if (!init_test_context(&test_context, NULL))
32221 return;
32223 device = test_context.device;
32224 immediate = test_context.immediate_context;
32226 green_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(green), &green);
32227 blue_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(blue), &blue);
32228 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32230 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32231 todo_wine ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32232 if (hr != S_OK)
32234 ID3D11Buffer_Release(blue_buffer);
32235 ID3D11Buffer_Release(green_buffer);
32236 release_test_context(&test_context);
32237 return;
32240 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32241 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32243 ID3D11DeviceContext_PSSetConstantBuffers(deferred, 0, 1, &blue_buffer);
32245 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32246 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32247 ID3D11Buffer_Release(ret_buffer);
32249 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32250 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32252 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32253 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32254 ID3D11Buffer_Release(ret_buffer);
32256 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list2);
32257 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32259 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32260 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32262 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32263 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32264 ID3D11DeviceContext_PSGetConstantBuffers(immediate, 0, 1, &ret_buffer);
32265 ok(ret_buffer == green_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32266 ID3D11Buffer_Release(ret_buffer);
32268 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32269 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
32270 ID3D11DeviceContext_PSGetConstantBuffers(immediate, 0, 1, &ret_buffer);
32271 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32273 ID3D11CommandList_Release(list2);
32274 ID3D11CommandList_Release(list1);
32275 ID3D11DeviceContext_Release(deferred);
32276 ID3D11Buffer_Release(blue_buffer);
32277 ID3D11Buffer_Release(green_buffer);
32278 release_test_context(&test_context);
32281 static void test_deferred_context_swap_state(void)
32283 ID3D11DeviceContext1 *immediate, *deferred;
32284 ID3DDeviceContextState *state, *prev_state;
32285 ID3D11Buffer *green_buffer, *ret_buffer;
32286 struct d3d11_test_context test_context;
32287 D3D_FEATURE_LEVEL feature_level;
32288 ID3D11Device1 *device;
32289 HRESULT hr;
32291 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32293 if (!init_test_context(&test_context, NULL))
32294 return;
32296 if (FAILED(ID3D11Device_QueryInterface(test_context.device, &IID_ID3D11Device1, (void **)&device)))
32298 skip("ID3D11Device1 is not available.\n");
32299 release_test_context(&test_context);
32300 return;
32303 ID3D11Device1_GetImmediateContext1(device, &immediate);
32305 green_buffer = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(green), &green);
32306 ID3D11DeviceContext1_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32308 hr = ID3D11Device1_CreateDeferredContext1(device, 0, &deferred);
32309 todo_wine ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32310 if (hr != S_OK)
32311 goto out;
32313 feature_level = ID3D11Device1_GetFeatureLevel(device);
32314 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
32315 &IID_ID3D11Device1, NULL, &state);
32316 ok(hr == S_OK, "Failed to create device context state, hr %#x.\n", hr);
32318 prev_state = (void *)0xdeadbeef;
32319 ID3D11DeviceContext1_SwapDeviceContextState(deferred, NULL, &prev_state);
32320 ok(!prev_state, "Got state %p.\n", prev_state);
32322 prev_state = (void *)0xdeadbeef;
32323 ID3D11DeviceContext1_SwapDeviceContextState(deferred, state, &prev_state);
32324 ok(!prev_state, "Got state %p.\n", prev_state);
32326 ID3D11DeviceContext1_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32327 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32329 ID3DDeviceContextState_Release(state);
32330 ID3D11DeviceContext1_Release(deferred);
32332 out:
32333 ID3D11Buffer_Release(green_buffer);
32334 ID3D11DeviceContext1_Release(immediate);
32335 ID3D11Device1_Release(device);
32336 release_test_context(&test_context);
32339 static void test_deferred_context_rendering(void)
32341 ID3D11DeviceContext *immediate, *deferred;
32342 struct d3d11_test_context test_context;
32343 D3D11_TEXTURE2D_DESC texture_desc;
32344 ID3D11CommandList *list1, *list2;
32345 ID3D11RenderTargetView *rtv;
32346 ID3D11Texture2D *texture;
32347 ID3D11Device *device;
32348 DWORD color;
32349 HRESULT hr;
32351 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
32352 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32353 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
32355 if (!init_test_context(&test_context, NULL))
32356 return;
32358 device = test_context.device;
32359 immediate = test_context.immediate_context;
32361 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
32363 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32364 todo_wine ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32365 if (hr != S_OK)
32367 release_test_context(&test_context);
32368 return;
32371 ID3D11DeviceContext_ClearRenderTargetView(deferred, test_context.backbuffer_rtv, green);
32373 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32374 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32376 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32377 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32379 color = get_texture_color(test_context.backbuffer, 320, 240);
32380 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32382 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32383 color = get_texture_color(test_context.backbuffer, 320, 240);
32384 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32386 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
32387 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32388 color = get_texture_color(test_context.backbuffer, 320, 240);
32389 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32391 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
32392 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, TRUE);
32393 color = get_texture_color(test_context.backbuffer, 320, 240);
32394 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32396 ID3D11CommandList_Release(list2);
32398 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, TRUE);
32399 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32400 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32402 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
32403 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, TRUE);
32404 color = get_texture_color(test_context.backbuffer, 320, 240);
32405 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32407 ID3D11CommandList_Release(list2);
32408 ID3D11CommandList_Release(list1);
32409 ID3D11DeviceContext_Release(deferred);
32411 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32412 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
32413 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
32414 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
32415 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32417 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
32418 ID3D11DeviceContext_ClearRenderTargetView(immediate, rtv, green);
32420 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32421 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32423 ID3D11DeviceContext_CopyResource(deferred, (ID3D11Resource *)test_context.backbuffer, (ID3D11Resource *)texture);
32425 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32426 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32428 ID3D11DeviceContext_ClearRenderTargetView(immediate, rtv, blue);
32429 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32430 color = get_texture_color(test_context.backbuffer, 320, 240);
32431 ok(color == 0xffff0000, "Got unexpected color %#08x.\n", color);
32433 ID3D11CommandList_Release(list1);
32434 ID3D11DeviceContext_Release(deferred);
32436 ID3D11RenderTargetView_Release(rtv);
32437 ID3D11Texture2D_Release(texture);
32438 release_test_context(&test_context);
32441 START_TEST(d3d11)
32443 unsigned int argc, i;
32444 char **argv;
32446 use_mt = !getenv("WINETEST_NO_MT_D3D");
32448 argc = winetest_get_mainargs(&argv);
32449 for (i = 2; i < argc; ++i)
32451 if (!strcmp(argv[i], "--validate"))
32452 enable_debug_layer = TRUE;
32453 else if (!strcmp(argv[i], "--warp"))
32454 use_warp_adapter = TRUE;
32455 else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
32456 use_adapter_idx = atoi(argv[++i]);
32457 else if (!strcmp(argv[i], "--single"))
32458 use_mt = FALSE;
32461 print_adapter_info();
32463 queue_test(test_create_device);
32464 queue_for_each_feature_level(test_device_interfaces);
32465 queue_test(test_immediate_context);
32466 queue_test(test_create_deferred_context);
32467 queue_test(test_create_texture1d);
32468 queue_test(test_texture1d_interfaces);
32469 queue_test(test_create_texture2d);
32470 queue_test(test_texture2d_interfaces);
32471 queue_test(test_create_texture3d);
32472 queue_test(test_texture3d_interfaces);
32473 queue_test(test_create_buffer);
32474 queue_test(test_create_depthstencil_view);
32475 queue_test(test_depthstencil_view_interfaces);
32476 queue_test(test_create_rendertarget_view);
32477 queue_test(test_create_shader_resource_view);
32478 queue_for_each_feature_level(test_create_shader);
32479 queue_test(test_create_sampler_state);
32480 queue_test(test_create_blend_state);
32481 queue_test(test_create_depthstencil_state);
32482 queue_test(test_create_rasterizer_state);
32483 queue_test(test_create_query);
32484 queue_test(test_occlusion_query);
32485 queue_test(test_pipeline_statistics_query);
32486 queue_test(test_timestamp_query);
32487 queue_test(test_so_statistics_query);
32488 queue_test(test_device_removed_reason);
32489 queue_test(test_private_data);
32490 queue_for_each_feature_level(test_state_refcounting);
32491 queue_test(test_device_context_state);
32492 queue_test(test_blend);
32493 queue_test(test_texture1d);
32494 queue_test(test_texture);
32495 queue_test(test_cube_maps);
32496 queue_test(test_depth_stencil_sampling);
32497 queue_test(test_sample_c_lz);
32498 queue_test(test_multiple_render_targets);
32499 queue_test(test_render_target_views);
32500 queue_test(test_layered_rendering);
32501 queue_test(test_scissor);
32502 queue_test(test_clear_state);
32503 queue_test(test_il_append_aligned);
32504 queue_test(test_instanced_draw);
32505 queue_test(test_vertex_id);
32506 queue_test(test_fragment_coords);
32507 queue_test(test_initial_texture_data);
32508 queue_test(test_update_subresource);
32509 queue_test(test_copy_subresource_region);
32510 queue_test(test_copy_subresource_region_1d);
32511 queue_test(test_copy_subresource_region_3d);
32512 queue_test(test_resource_map);
32513 queue_for_each_feature_level(test_resource_access);
32514 queue_test(test_check_multisample_quality_levels);
32515 queue_for_each_feature_level(test_swapchain_formats);
32516 queue_test(test_swapchain_views);
32517 queue_test(test_swapchain_flip);
32518 queue_test(test_clear_render_target_view_1d);
32519 queue_test(test_clear_render_target_view_2d);
32520 queue_test(test_clear_render_target_view_3d);
32521 queue_test(test_clear_depth_stencil_view);
32522 queue_test(test_clear_buffer_unordered_access_view);
32523 queue_test(test_initial_depth_stencil_state);
32524 queue_test(test_draw_depth_only);
32525 queue_test(test_draw_uav_only);
32526 queue_test(test_cb_relative_addressing);
32527 queue_test(test_vs_input_relative_addressing);
32528 queue_test(test_getdc);
32529 queue_test(test_shader_stage_input_output_matching);
32530 queue_test(test_shader_interstage_interface);
32531 queue_test(test_sm4_if_instruction);
32532 queue_test(test_sm4_breakc_instruction);
32533 queue_test(test_sm4_continuec_instruction);
32534 queue_test(test_sm4_discard_instruction);
32535 queue_test(test_sm5_swapc_instruction);
32536 queue_test(test_create_input_layout);
32537 queue_test(test_input_layout_alignment);
32538 queue_test(test_input_assembler);
32539 queue_test(test_null_sampler);
32540 queue_test(test_check_feature_support);
32541 queue_test(test_create_unordered_access_view);
32542 queue_test(test_immediate_constant_buffer);
32543 queue_test(test_fp_specials);
32544 queue_test(test_uint_shader_instructions);
32545 queue_test(test_index_buffer_offset);
32546 queue_test(test_face_culling);
32547 queue_test(test_line_antialiasing_blending);
32548 queue_for_each_feature_level(test_format_support);
32549 queue_for_each_9_x_feature_level(test_fl9_draw);
32550 queue_test(test_ddy);
32551 queue_test(test_shader_input_registers_limits);
32552 queue_test(test_unbind_shader_resource_view);
32553 queue_test(test_stencil_separate);
32554 queue_test(test_uav_load);
32555 queue_test(test_cs_uav_store);
32556 queue_test(test_uav_store_immediate_constant);
32557 queue_test(test_ps_cs_uav_binding);
32558 queue_test(test_atomic_instructions);
32559 queue_test(test_sm4_ret_instruction);
32560 queue_test(test_primitive_restart);
32561 queue_test(test_resinfo_instruction);
32562 queue_test(test_sm5_bufinfo_instruction);
32563 queue_test(test_sampleinfo_instruction);
32564 queue_test(test_render_target_device_mismatch);
32565 queue_test(test_buffer_srv);
32566 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
32567 test_unaligned_raw_buffer_access);
32568 queue_test(test_uav_counters);
32569 queue_test(test_dispatch_indirect);
32570 queue_test(test_compute_shader_registers);
32571 queue_test(test_tgsm);
32572 queue_test(test_geometry_shader);
32573 queue_test(test_quad_tessellation);
32574 queue_test(test_stream_output);
32575 queue_test(test_fl10_stream_output_desc);
32576 queue_test(test_stream_output_resume);
32577 queue_test(test_stream_output_components);
32578 queue_test(test_stream_output_vs);
32579 queue_test(test_gather);
32580 queue_test(test_gather_c);
32581 queue_test(test_depth_bias);
32582 queue_test(test_fractional_viewports);
32583 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0, test_negative_viewports);
32584 queue_test(test_early_depth_stencil);
32585 queue_test(test_conservative_depth_output);
32586 queue_test(test_format_compatibility);
32587 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
32588 test_compressed_format_compatibility);
32589 queue_test(test_clip_distance);
32590 queue_test(test_combined_clip_and_cull_distances);
32591 queue_test(test_generate_mips);
32592 queue_test(test_alpha_to_coverage);
32593 queue_test(test_unbound_multisample_texture);
32594 queue_test(test_multiple_viewports);
32595 queue_test(test_multisample_resolve);
32596 queue_test(test_sample_shading);
32597 queue_test(test_sample_mask);
32598 queue_test(test_depth_clip);
32599 queue_test(test_staging_buffers);
32600 queue_test(test_render_a8);
32601 queue_test(test_standard_pattern);
32602 queue_test(test_desktop_window);
32603 queue_test(test_sample_attached_rtv);
32604 queue_test(test_color_mask);
32605 queue_test(test_independent_blend);
32606 queue_test(test_dual_source_blend);
32607 queue_test(test_deferred_context_state);
32608 queue_test(test_deferred_context_swap_state);
32609 queue_test(test_deferred_context_rendering);
32610 queue_test(test_unbound_streams);
32612 run_queued_tests();