wined3d: Reject raw blits between depth/stencil and colour resources in the GLSL...
[wine.git] / dlls / d3d11 / tests / d3d11.c
blobd412f430b605007cbd521f1169ab44b0a8a10fda
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 set_viewport(immediate_context, -1.0f, 0.0f, 641, 480, 0.0f, 1.0f);
11554 SetRect(&scissor_rect, -1, 0, 640, 480);
11555 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
11556 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
11557 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
11558 draw_color_quad(&test_context, &green);
11559 color = get_texture_color(test_context.backbuffer, 320, 60);
11560 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11561 color = get_texture_color(test_context.backbuffer, 80, 240);
11562 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11563 color = get_texture_color(test_context.backbuffer, 320, 240);
11564 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11565 color = get_texture_color(test_context.backbuffer, 560, 240);
11566 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11567 color = get_texture_color(test_context.backbuffer, 320, 420);
11568 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11570 ID3D11RasterizerState_Release(rs);
11571 release_test_context(&test_context);
11574 static void test_clear_state(void)
11576 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11577 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11579 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11581 #if 0
11582 float4 main(float4 pos : POSITION) : POSITION
11584 return pos;
11586 #endif
11587 static const DWORD simple_vs[] =
11589 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
11590 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11591 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11592 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11593 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
11594 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
11595 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11597 #if 0
11598 struct data
11600 float4 position : SV_Position;
11603 struct patch_constant_data
11605 float edges[3] : SV_TessFactor;
11606 float inside : SV_InsideTessFactor;
11609 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
11611 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
11612 output.inside = 1.0f;
11615 [domain("tri")]
11616 [outputcontrolpoints(3)]
11617 [partitioning("integer")]
11618 [outputtopology("triangle_ccw")]
11619 [patchconstantfunc("patch_constant")]
11620 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
11622 return input[i];
11625 [domain("tri")]
11626 void ds_main(patch_constant_data input,
11627 float3 tess_coord : SV_DomainLocation,
11628 const OutputPatch<data, 3> patch,
11629 out data output)
11631 output.position = tess_coord.x * patch[0].position
11632 + tess_coord.y * patch[1].position
11633 + tess_coord.z * patch[2].position;
11635 #endif
11636 static const DWORD simple_hs[] =
11638 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
11639 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11640 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
11641 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11642 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
11643 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
11644 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
11645 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
11646 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
11647 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
11648 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
11649 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
11650 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
11651 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
11652 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
11653 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
11654 0x00004001, 0x3f800000, 0x0100003e,
11656 static const DWORD simple_ds[] =
11658 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
11659 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11660 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
11661 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
11662 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
11663 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
11664 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
11665 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
11666 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
11667 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
11668 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
11669 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
11670 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
11671 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
11672 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
11674 #if 0
11675 struct gs_out
11677 float4 pos : SV_POSITION;
11680 [maxvertexcount(4)]
11681 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
11683 float offset = 0.1 * vin[0].w;
11684 gs_out v;
11686 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
11687 vout.Append(v);
11688 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
11689 vout.Append(v);
11690 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
11691 vout.Append(v);
11692 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
11693 vout.Append(v);
11695 #endif
11696 static const DWORD simple_gs[] =
11698 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
11699 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11700 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11701 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
11702 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
11703 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
11704 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
11705 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
11706 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
11707 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
11708 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
11709 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
11710 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
11711 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
11712 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
11713 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
11714 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
11715 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
11717 #if 0
11718 float4 main(float4 color : COLOR) : SV_TARGET
11720 return color;
11722 #endif
11723 static const DWORD simple_ps[] =
11725 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
11726 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
11727 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
11728 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11729 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11730 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
11731 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11733 #if 0
11734 [numthreads(1, 1, 1)]
11735 void main() { }
11736 #endif
11737 static const DWORD simple_cs[] =
11739 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
11740 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11741 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
11742 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
11745 D3D11_VIEWPORT tmp_viewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
11746 ID3D11ShaderResourceView *tmp_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
11747 ID3D11ShaderResourceView *srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
11748 ID3D11RenderTargetView *tmp_rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11749 RECT tmp_rect[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
11750 ID3D11SamplerState *tmp_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
11751 ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11752 ID3D11Texture2D *rt_texture[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11753 ID3D11Buffer *cb[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
11754 ID3D11Buffer *tmp_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11755 ID3D11SamplerState *sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
11756 ID3D11UnorderedAccessView *tmp_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
11757 ID3D11UnorderedAccessView *cs_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
11758 ID3D11Buffer *buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11759 ID3D11Buffer *cs_uav_buffer[D3D11_PS_CS_UAV_REGISTER_COUNT];
11760 UINT offset[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11761 UINT stride[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11762 ID3D11Buffer *so_buffer[D3D11_SO_BUFFER_SLOT_COUNT];
11763 ID3D11InputLayout *tmp_input_layout, *input_layout;
11764 ID3D11DepthStencilState *tmp_ds_state, *ds_state;
11765 ID3D11BlendState *tmp_blend_state, *blend_state;
11766 ID3D11RasterizerState *tmp_rs_state, *rs_state;
11767 ID3D11Predicate *tmp_predicate, *predicate;
11768 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
11769 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
11770 ID3D11DepthStencilView *tmp_dsv, *dsv;
11771 ID3D11UnorderedAccessView *ps_uav;
11772 D3D11_PRIMITIVE_TOPOLOGY topology;
11773 D3D11_TEXTURE2D_DESC texture_desc;
11774 ID3D11GeometryShader *tmp_gs, *gs;
11775 ID3D11ComputeShader *tmp_cs, *cs;
11776 D3D11_DEPTH_STENCIL_DESC ds_desc;
11777 ID3D11VertexShader *tmp_vs, *vs;
11778 ID3D11DomainShader *tmp_ds, *ds;
11779 D3D11_SAMPLER_DESC sampler_desc;
11780 D3D11_QUERY_DESC predicate_desc;
11781 struct device_desc device_desc;
11782 ID3D11PixelShader *tmp_ps, *ps;
11783 ID3D11HullShader *tmp_hs, *hs;
11784 D3D11_RASTERIZER_DESC rs_desc;
11785 ID3D11DeviceContext *context;
11786 D3D11_BLEND_DESC blend_desc;
11787 ID3D11Texture2D *ds_texture;
11788 ID3D11Buffer *ps_uav_buffer;
11789 float blend_factor[4];
11790 ID3D11Device *device;
11791 BOOL predicate_value;
11792 UINT instance_count;
11793 DXGI_FORMAT format;
11794 UINT sample_mask;
11795 UINT stencil_ref;
11796 ULONG refcount;
11797 UINT count, i;
11798 HRESULT hr;
11800 device_desc.feature_level = &feature_level;
11801 device_desc.flags = 0;
11802 if (!(device = create_device(&device_desc)))
11804 skip("Failed to create device.\n");
11805 return;
11808 ID3D11Device_GetImmediateContext(device, &context);
11810 /* Verify the initial state after device creation. */
11812 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11813 tmp_buffer);
11814 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11816 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11818 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11819 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11821 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11823 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11824 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11826 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11828 instance_count = 100;
11829 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, &instance_count);
11830 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
11831 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11833 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11834 tmp_buffer);
11835 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11837 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11839 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11840 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11842 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11844 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11845 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11847 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11849 instance_count = 100;
11850 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, &instance_count);
11851 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
11852 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11854 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11855 tmp_buffer);
11856 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11858 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11860 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11861 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11863 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11865 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11866 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11868 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11870 instance_count = 100;
11871 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, &instance_count);
11872 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
11873 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11875 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11876 tmp_buffer);
11877 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11879 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11881 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11882 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11884 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11886 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11887 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11889 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11891 instance_count = 100;
11892 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, &instance_count);
11893 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
11894 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11896 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11897 tmp_buffer);
11898 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11900 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11902 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
11903 tmp_srv);
11904 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11906 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11908 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11909 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11911 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11913 instance_count = 100;
11914 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, &instance_count);
11915 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
11916 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11918 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11919 tmp_buffer);
11920 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11922 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11924 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
11925 tmp_srv);
11926 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11928 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11930 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11931 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11933 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11935 instance_count = 100;
11936 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, &instance_count);
11937 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
11938 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11939 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
11940 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
11942 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
11945 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
11946 tmp_buffer, stride, offset);
11947 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
11949 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
11950 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
11951 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
11953 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
11954 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
11955 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
11956 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
11957 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
11958 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
11959 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
11960 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
11962 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
11963 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
11964 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
11965 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
11966 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
11967 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
11968 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
11969 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
11970 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
11971 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
11972 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
11973 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
11975 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
11977 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
11978 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
11979 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
11980 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
11981 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
11983 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
11985 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
11986 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
11988 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
11991 if (!enable_debug_layer)
11993 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
11994 ok(!count, "Got unexpected scissor rect count %u.\n", count);
11996 memset(tmp_rect, 0x55, sizeof(tmp_rect));
11997 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
11998 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
11999 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12001 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
12002 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
12004 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12005 ok(!count, "Got unexpected viewport count %u.\n", count);
12006 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12007 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12008 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12009 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12011 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
12012 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
12013 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12014 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12015 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12017 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12018 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
12020 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12021 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12023 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
12026 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12027 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
12028 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12030 /* Create resources. */
12032 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12033 cb[i] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 1024, NULL);
12035 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12037 buffer[i] = create_buffer(device,
12038 D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE,
12039 1024, NULL);
12041 stride[i] = (i + 1) * 4;
12042 offset[i] = (i + 1) * 16;
12045 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12046 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
12048 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12049 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
12050 U(srv_desc).Buffer.ElementOffset = 0;
12051 U(srv_desc).Buffer.ElementWidth = 64;
12053 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12055 hr = ID3D11Device_CreateShaderResourceView(device,
12056 (ID3D11Resource *)buffer[i % D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
12057 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12060 uav_desc.Format = DXGI_FORMAT_R32_UINT;
12061 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
12062 U(uav_desc).Buffer.FirstElement = 0;
12063 U(uav_desc).Buffer.NumElements = 8;
12064 U(uav_desc).Buffer.Flags = 0;
12066 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12068 cs_uav_buffer[i] = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
12069 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_uav_buffer[i],
12070 &uav_desc, &cs_uav[i]);
12071 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12074 ps_uav_buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
12075 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_uav_buffer,
12076 &uav_desc, &ps_uav);
12077 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12079 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
12080 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
12081 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
12082 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
12083 sampler_desc.MipLODBias = 0.0f;
12084 sampler_desc.MaxAnisotropy = 16;
12085 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
12086 sampler_desc.BorderColor[0] = 0.0f;
12087 sampler_desc.BorderColor[1] = 0.0f;
12088 sampler_desc.BorderColor[2] = 0.0f;
12089 sampler_desc.BorderColor[3] = 0.0f;
12090 sampler_desc.MinLOD = 0.0f;
12091 sampler_desc.MaxLOD = 16.0f;
12093 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12095 sampler_desc.MinLOD = (float)i;
12097 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
12098 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
12101 hr = ID3D11Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
12102 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12104 hr = ID3D11Device_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
12105 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
12107 hr = ID3D11Device_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
12108 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
12110 hr = ID3D11Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
12111 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
12113 hr = ID3D11Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
12114 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12116 hr = ID3D11Device_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
12117 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
12119 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12120 simple_vs, sizeof(simple_vs), &input_layout);
12121 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12123 memset(&blend_desc, 0, sizeof(blend_desc));
12124 blend_desc.AlphaToCoverageEnable = FALSE;
12125 blend_desc.IndependentBlendEnable = FALSE;
12126 blend_desc.RenderTarget[0].BlendEnable = TRUE;
12127 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
12128 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
12129 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
12130 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
12131 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
12132 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
12133 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
12135 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
12136 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
12138 ds_desc.DepthEnable = TRUE;
12139 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
12140 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
12141 ds_desc.StencilEnable = FALSE;
12142 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
12143 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
12144 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
12145 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
12146 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
12147 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
12148 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
12149 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
12150 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
12151 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
12153 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
12154 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
12156 texture_desc.Width = 512;
12157 texture_desc.Height = 512;
12158 texture_desc.MipLevels = 1;
12159 texture_desc.ArraySize = 1;
12160 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12161 texture_desc.SampleDesc.Count = 1;
12162 texture_desc.SampleDesc.Quality = 0;
12163 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12164 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12165 texture_desc.CPUAccessFlags = 0;
12166 texture_desc.MiscFlags = 0;
12168 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12170 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
12171 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12174 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
12175 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
12177 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
12178 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12180 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12182 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture[i], NULL, &rtv[i]);
12183 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12186 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)ds_texture, NULL, &dsv);
12187 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
12189 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12191 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
12193 tmp_viewport[i].TopLeftX = i * 3;
12194 tmp_viewport[i].TopLeftY = i * 4;
12195 tmp_viewport[i].Width = 3;
12196 tmp_viewport[i].Height = 4;
12197 tmp_viewport[i].MinDepth = i * 0.01f;
12198 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
12201 rs_desc.FillMode = D3D11_FILL_SOLID;
12202 rs_desc.CullMode = D3D11_CULL_BACK;
12203 rs_desc.FrontCounterClockwise = FALSE;
12204 rs_desc.DepthBias = 0;
12205 rs_desc.DepthBiasClamp = 0.0f;
12206 rs_desc.SlopeScaledDepthBias = 0.0f;
12207 rs_desc.DepthClipEnable = TRUE;
12208 rs_desc.ScissorEnable = FALSE;
12209 rs_desc.MultisampleEnable = FALSE;
12210 rs_desc.AntialiasedLineEnable = FALSE;
12212 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs_state);
12213 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12215 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
12216 predicate_desc.MiscFlags = 0;
12218 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
12219 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
12221 /* Setup state. */
12223 /* Some versions of Windows AMD drivers hang while the device is being
12224 * released, if the total number of used resource slots exceeds some limit.
12225 * Do not use all constant buffers slots in order to not trigger this
12226 * driver bug. */
12227 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb[0]);
12228 ID3D11DeviceContext_VSSetConstantBuffers(context, 7, 1, &cb[7]);
12229 ID3D11DeviceContext_VSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12230 ID3D11DeviceContext_VSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12231 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12233 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb[0]);
12234 ID3D11DeviceContext_HSSetConstantBuffers(context, 7, 1, &cb[7]);
12235 ID3D11DeviceContext_HSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12236 ID3D11DeviceContext_HSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12237 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
12239 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12240 ID3D11DeviceContext_DSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12241 ID3D11DeviceContext_DSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12242 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
12244 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12245 ID3D11DeviceContext_GSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12246 ID3D11DeviceContext_GSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12247 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
12249 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12250 ID3D11DeviceContext_PSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12251 ID3D11DeviceContext_PSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12252 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12254 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12255 ID3D11DeviceContext_CSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12256 ID3D11DeviceContext_CSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12257 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
12258 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, cs_uav, NULL);
12260 ID3D11DeviceContext_IASetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12261 buffer, stride, offset);
12262 ID3D11DeviceContext_IASetIndexBuffer(context, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
12263 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12264 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12266 blend_factor[0] = 0.1f;
12267 blend_factor[1] = 0.2f;
12268 blend_factor[2] = 0.3f;
12269 blend_factor[3] = 0.4f;
12270 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, 0xff00ff00);
12271 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 3);
12272 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
12273 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, rtv, dsv,
12274 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, 1, &ps_uav, NULL);
12276 ID3D11DeviceContext_RSSetScissorRects(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12277 tmp_rect);
12278 ID3D11DeviceContext_RSSetViewports(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12279 tmp_viewport);
12280 ID3D11DeviceContext_RSSetState(context, rs_state);
12282 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
12284 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
12286 /* Verify the set state. */
12288 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12289 tmp_buffer);
12290 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12292 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
12293 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12294 tmp_buffer[i], i, expected_cb);
12295 if (tmp_buffer[i])
12296 ID3D11Buffer_Release(tmp_buffer[i]);
12298 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12299 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12301 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12302 tmp_srv[i], i, srv[i]);
12303 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12305 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12306 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12308 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12309 tmp_sampler[i], i, sampler[i]);
12310 ID3D11SamplerState_Release(tmp_sampler[i]);
12312 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
12313 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
12314 ID3D11VertexShader_Release(tmp_vs);
12316 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12317 tmp_buffer);
12318 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12320 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
12321 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12322 tmp_buffer[i], i, expected_cb);
12323 if (tmp_buffer[i])
12324 ID3D11Buffer_Release(tmp_buffer[i]);
12326 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12327 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12329 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12330 tmp_srv[i], i, srv[i]);
12331 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12333 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12334 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12336 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12337 tmp_sampler[i], i, sampler[i]);
12338 ID3D11SamplerState_Release(tmp_sampler[i]);
12340 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
12341 ok(tmp_hs == hs, "Got unexpected hull shader %p, expected %p.\n", tmp_hs, hs);
12342 ID3D11HullShader_Release(tmp_hs);
12344 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12345 tmp_buffer);
12346 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12348 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12349 tmp_buffer[i], i, cb[i]);
12350 ID3D11Buffer_Release(tmp_buffer[i]);
12352 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12353 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12355 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12356 tmp_srv[i], i, srv[i]);
12357 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12359 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12360 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12362 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12363 tmp_sampler[i], i, sampler[i]);
12364 ID3D11SamplerState_Release(tmp_sampler[i]);
12366 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
12367 ok(tmp_ds == ds, "Got unexpected domain shader %p, expected %p.\n", tmp_ds, ds);
12368 ID3D11DomainShader_Release(tmp_ds);
12370 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12371 tmp_buffer);
12372 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12374 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12375 tmp_buffer[i], i, cb[i]);
12376 ID3D11Buffer_Release(tmp_buffer[i]);
12378 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12379 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12381 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12382 tmp_srv[i], i, srv[i]);
12383 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12385 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12386 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12388 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12389 tmp_sampler[i], i, sampler[i]);
12390 ID3D11SamplerState_Release(tmp_sampler[i]);
12392 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
12393 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
12394 ID3D11GeometryShader_Release(tmp_gs);
12396 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12397 tmp_buffer);
12398 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12400 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12401 tmp_buffer[i], i, cb[i]);
12402 ID3D11Buffer_Release(tmp_buffer[i]);
12404 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12405 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12407 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12408 tmp_srv[i], i, srv[i]);
12409 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12411 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12412 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12414 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12415 tmp_sampler[i], i, sampler[i]);
12416 ID3D11SamplerState_Release(tmp_sampler[i]);
12418 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
12419 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
12420 ID3D11PixelShader_Release(tmp_ps);
12422 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12423 tmp_buffer);
12424 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12426 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12427 tmp_buffer[i], i, cb[i]);
12428 ID3D11Buffer_Release(tmp_buffer[i]);
12430 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12431 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12433 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12434 tmp_srv[i], i, srv[i]);
12435 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12437 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12438 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12440 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12441 tmp_sampler[i], i, sampler[i]);
12442 ID3D11SamplerState_Release(tmp_sampler[i]);
12444 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
12445 ok(tmp_cs == cs, "Got unexpected compute shader %p, expected %p.\n", tmp_cs, cs);
12446 ID3D11ComputeShader_Release(tmp_cs);
12447 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12448 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12450 ok(tmp_uav[i] == cs_uav[i], "Got unexpected unordered access view %p in slot %u, expected %p.\n",
12451 tmp_uav[i], i, cs_uav[i]);
12452 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
12455 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12456 tmp_buffer, stride, offset);
12457 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12459 todo_wine_if(i >= D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
12461 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
12462 tmp_buffer[i], i, buffer[i]);
12463 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
12464 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
12466 if (tmp_buffer[i])
12467 ID3D11Buffer_Release(tmp_buffer[i]);
12469 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
12470 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
12471 ID3D11Buffer_Release(tmp_buffer[0]);
12472 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
12473 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
12474 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
12475 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
12476 tmp_input_layout, input_layout);
12477 ID3D11InputLayout_Release(tmp_input_layout);
12478 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
12479 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
12481 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
12482 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
12483 ID3D11BlendState_Release(tmp_blend_state);
12484 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
12485 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
12486 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12487 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12488 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
12489 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
12490 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
12491 ID3D11DepthStencilState_Release(tmp_ds_state);
12492 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
12493 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
12494 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
12496 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
12497 tmp_rtv[i], i, rtv[i]);
12498 ID3D11RenderTargetView_Release(tmp_rtv[i]);
12500 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12501 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
12502 ID3D11DepthStencilView_Release(tmp_dsv);
12503 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
12504 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
12505 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12506 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
12508 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
12509 tmp_rtv[i], i, rtv[i]);
12510 ID3D11RenderTargetView_Release(tmp_rtv[i]);
12512 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12513 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
12514 ID3D11DepthStencilView_Release(tmp_dsv);
12515 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT - 1; ++i)
12517 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12519 ok(tmp_uav[i] == ps_uav, "Got unexpected unordered access view %p in slot %u, expected %p.\n",
12520 tmp_uav[i], i, ps_uav);
12521 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
12523 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
12524 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12525 "Got unexpected scissor rect count %u.\n", count);
12526 memset(tmp_rect, 0x55, sizeof(tmp_rect));
12527 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
12528 for (i = 0; i < count; ++i)
12530 ok(tmp_rect[i].left == i
12531 && tmp_rect[i].top == i * 2
12532 && tmp_rect[i].right == i + 1
12533 && tmp_rect[i].bottom == (i + 1) * 2,
12534 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
12536 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12537 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12538 "Got unexpected viewport count %u.\n", count);
12539 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12540 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12541 for (i = 0; i < count; ++i)
12543 ok(tmp_viewport[i].TopLeftX == i * 3
12544 && tmp_viewport[i].TopLeftY == i * 4
12545 && tmp_viewport[i].Width == 3
12546 && tmp_viewport[i].Height == 4
12547 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
12548 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
12549 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12550 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12551 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12553 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12554 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
12555 ID3D11RasterizerState_Release(tmp_rs_state);
12557 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12558 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12560 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
12561 tmp_buffer[i], i, so_buffer[i]);
12562 ID3D11Buffer_Release(tmp_buffer[i]);
12565 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12566 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
12567 ID3D11Predicate_Release(tmp_predicate);
12568 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12570 /* Verify ClearState(). */
12572 ID3D11DeviceContext_ClearState(context);
12574 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12575 tmp_buffer);
12576 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12578 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12580 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12581 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12583 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12585 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12586 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12588 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12590 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
12591 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
12593 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12594 tmp_buffer);
12595 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12597 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12599 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12600 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12602 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12604 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12605 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12607 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12609 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
12610 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
12612 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12613 tmp_buffer);
12614 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12616 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12618 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12619 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12621 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12623 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12624 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12626 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12628 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
12629 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
12631 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12632 tmp_buffer);
12633 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12635 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12637 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12638 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12640 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12642 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12643 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12645 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12647 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
12648 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
12650 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12651 tmp_buffer);
12652 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12654 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12656 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12657 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12659 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12661 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12662 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12664 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12666 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
12667 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
12669 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12670 tmp_buffer);
12671 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12673 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12675 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
12676 tmp_srv);
12677 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12679 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12681 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12682 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12684 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12686 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
12687 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
12688 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12689 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12691 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12694 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12695 tmp_buffer, stride, offset);
12696 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12698 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
12699 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
12700 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
12702 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
12703 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
12704 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
12705 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
12706 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
12707 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
12708 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
12709 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
12711 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
12712 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
12713 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
12714 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
12715 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12716 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12717 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
12718 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
12719 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
12720 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
12721 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
12722 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12724 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12726 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12727 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
12728 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
12729 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12730 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12732 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12734 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12735 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12737 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12740 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
12741 ok(!count, "Got unexpected scissor rect count %u.\n", count);
12742 memset(tmp_rect, 0x55, sizeof(tmp_rect));
12743 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12744 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
12745 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12747 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
12748 "Got unexpected scissor rect %s in slot %u.\n",
12749 wine_dbgstr_rect(&tmp_rect[i]), i);
12751 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12752 ok(!count, "Got unexpected viewport count %u.\n", count);
12753 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12754 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12755 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12756 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12758 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
12759 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
12760 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12761 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12762 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12764 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12765 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
12767 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12768 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12770 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
12773 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12774 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
12775 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12777 /* Cleanup. */
12779 ID3D11Predicate_Release(predicate);
12780 ID3D11RasterizerState_Release(rs_state);
12781 ID3D11DepthStencilView_Release(dsv);
12782 ID3D11Texture2D_Release(ds_texture);
12784 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12786 ID3D11RenderTargetView_Release(rtv[i]);
12787 ID3D11Texture2D_Release(rt_texture[i]);
12790 ID3D11DepthStencilState_Release(ds_state);
12791 ID3D11BlendState_Release(blend_state);
12792 ID3D11InputLayout_Release(input_layout);
12793 ID3D11VertexShader_Release(vs);
12794 ID3D11HullShader_Release(hs);
12795 ID3D11DomainShader_Release(ds);
12796 ID3D11GeometryShader_Release(gs);
12797 ID3D11PixelShader_Release(ps);
12798 ID3D11ComputeShader_Release(cs);
12800 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12802 ID3D11SamplerState_Release(sampler[i]);
12805 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12807 ID3D11ShaderResourceView_Release(srv[i]);
12810 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12812 ID3D11UnorderedAccessView_Release(cs_uav[i]);
12813 ID3D11Buffer_Release(cs_uav_buffer[i]);
12815 ID3D11UnorderedAccessView_Release(ps_uav);
12816 ID3D11Buffer_Release(ps_uav_buffer);
12818 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12820 ID3D11Buffer_Release(so_buffer[i]);
12823 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12825 ID3D11Buffer_Release(buffer[i]);
12828 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12830 ID3D11Buffer_Release(cb[i]);
12833 ID3D11DeviceContext_Release(context);
12834 refcount = ID3D11Device_Release(device);
12835 ok(!refcount, "Device has %u references left.\n", refcount);
12838 static void test_il_append_aligned(void)
12840 struct d3d11_test_context test_context;
12841 ID3D11InputLayout *input_layout;
12842 ID3D11DeviceContext *context;
12843 unsigned int stride, offset;
12844 ID3D11VertexShader *vs;
12845 ID3D11PixelShader *ps;
12846 ID3D11Device *device;
12847 ID3D11Buffer *vb[3];
12848 DWORD color;
12849 HRESULT hr;
12851 /* Semantic names are case-insensitive. */
12852 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12854 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
12855 D3D11_INPUT_PER_INSTANCE_DATA, 2},
12856 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
12857 D3D11_INPUT_PER_INSTANCE_DATA, 1},
12858 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
12859 D3D11_INPUT_PER_VERTEX_DATA, 0},
12860 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
12861 D3D11_INPUT_PER_INSTANCE_DATA, 1},
12862 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
12863 D3D11_INPUT_PER_INSTANCE_DATA, 2},
12865 static const DWORD vs_code[] =
12867 #if 0
12868 struct vs_in
12870 float4 position : POSITION;
12871 float2 color_xy : COLOR0;
12872 float2 color_zw : COLOR1;
12873 unsigned int instance_id : SV_INSTANCEID;
12876 struct vs_out
12878 float4 position : SV_POSITION;
12879 float2 color_xy : COLOR0;
12880 float2 color_zw : COLOR1;
12883 struct vs_out main(struct vs_in i)
12885 struct vs_out o;
12887 o.position = i.position;
12888 o.position.x += i.instance_id * 0.5;
12889 o.color_xy = i.color_xy;
12890 o.color_zw = i.color_zw;
12892 return o;
12894 #endif
12895 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
12896 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
12897 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
12898 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
12899 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
12900 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
12901 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
12902 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
12903 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
12904 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
12905 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
12906 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
12907 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
12908 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
12909 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
12910 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
12911 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
12913 static const DWORD ps_code[] =
12915 #if 0
12916 struct vs_out
12918 float4 position : SV_POSITION;
12919 float2 color_xy : COLOR0;
12920 float2 color_zw : COLOR1;
12923 float4 main(struct vs_out i) : SV_TARGET
12925 return float4(i.color_xy.xy, i.color_zw.xy);
12927 #endif
12928 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
12929 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
12930 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
12931 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
12932 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
12933 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
12934 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
12935 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12936 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12938 static const struct
12940 struct vec4 position;
12942 stream0[] =
12944 {{-1.0f, -1.0f, 0.0f, 1.0f}},
12945 {{-1.0f, 1.0f, 0.0f, 1.0f}},
12946 {{-0.5f, -1.0f, 0.0f, 1.0f}},
12947 {{-0.5f, 1.0f, 0.0f, 1.0f}},
12949 static const struct
12951 struct vec2 color2;
12952 struct vec2 color1;
12954 stream1[] =
12956 {{0.5f, 0.5f}, {0.0f, 1.0f}},
12957 {{0.5f, 0.5f}, {1.0f, 1.0f}},
12959 static const struct
12961 struct vec2 color3;
12962 struct vec2 color0;
12964 stream2[] =
12966 {{0.5f, 0.5f}, {1.0f, 0.0f}},
12967 {{0.5f, 0.5f}, {0.0f, 1.0f}},
12968 {{0.5f, 0.5f}, {0.0f, 0.0f}},
12969 {{0.5f, 0.5f}, {1.0f, 0.0f}},
12971 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
12973 if (!init_test_context(&test_context, NULL))
12974 return;
12976 device = test_context.device;
12977 context = test_context.immediate_context;
12979 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12980 vs_code, sizeof(vs_code), &input_layout);
12981 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12983 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
12984 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
12985 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
12987 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12988 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12989 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12990 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12992 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12993 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12994 offset = 0;
12995 stride = sizeof(*stream0);
12996 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
12997 stride = sizeof(*stream1);
12998 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
12999 stride = sizeof(*stream2);
13000 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
13001 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13002 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13004 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13006 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
13008 color = get_texture_color(test_context.backbuffer, 80, 240);
13009 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
13010 color = get_texture_color(test_context.backbuffer, 240, 240);
13011 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13012 color = get_texture_color(test_context.backbuffer, 400, 240);
13013 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13014 color = get_texture_color(test_context.backbuffer, 560, 240);
13015 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
13017 ID3D11PixelShader_Release(ps);
13018 ID3D11VertexShader_Release(vs);
13019 ID3D11Buffer_Release(vb[2]);
13020 ID3D11Buffer_Release(vb[1]);
13021 ID3D11Buffer_Release(vb[0]);
13022 ID3D11InputLayout_Release(input_layout);
13023 release_test_context(&test_context);
13026 static void test_instanced_draw(void)
13028 struct d3d11_test_context test_context;
13029 D3D11_TEXTURE2D_DESC texture_desc;
13030 ID3D11InputLayout *input_layout;
13031 ID3D11RenderTargetView *rtvs[2];
13032 ID3D11Texture2D *render_target;
13033 ID3D11DeviceContext *context;
13034 struct resource_readback rb;
13035 unsigned int stride, offset;
13036 ID3D11Buffer *args_buffer;
13037 ID3D11VertexShader *vs;
13038 ID3D11PixelShader *ps;
13039 ID3D11Device *device;
13040 ID3D11Buffer *vb[4];
13041 unsigned int i;
13042 HRESULT hr;
13044 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13046 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
13047 D3D11_INPUT_PER_VERTEX_DATA, 0},
13048 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT,
13049 D3D11_INPUT_PER_INSTANCE_DATA, 1},
13050 {"color", 1, DXGI_FORMAT_R8_UNORM, 2, D3D11_APPEND_ALIGNED_ELEMENT,
13051 D3D10_INPUT_PER_INSTANCE_DATA, 0},
13052 {"color", 2, DXGI_FORMAT_R8_UNORM, 3, D3D11_APPEND_ALIGNED_ELEMENT,
13053 D3D10_INPUT_PER_INSTANCE_DATA, 2},
13054 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
13055 D3D11_INPUT_PER_INSTANCE_DATA, 1},
13057 static const DWORD vs_code[] =
13059 #if 0
13060 struct vs_in
13062 float4 position : Position;
13063 float r : color0;
13064 float g : color1;
13065 float b : color2;
13066 float v_offset : V_Offset;
13067 uint instance_id : SV_InstanceId;
13070 struct vs_out
13072 float4 position : SV_Position;
13073 float r : color0;
13074 float g : color1;
13075 float b : color2;
13076 uint instance_id : InstanceId;
13079 void main(vs_in i, out vs_out o)
13081 o.position = i.position;
13082 o.position.x += i.v_offset;
13083 o.r = i.r;
13084 o.g = i.g;
13085 o.b = i.b;
13086 o.instance_id = i.instance_id;
13088 #endif
13089 0x43425844, 0x036df42e, 0xff0da346, 0x7b23a14a, 0xc26ec9be, 0x00000001, 0x000002bc, 0x00000003,
13090 0x0000002c, 0x000000f4, 0x0000019c, 0x4e475349, 0x000000c0, 0x00000006, 0x00000008, 0x00000098,
13091 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a1, 0x00000000, 0x00000000,
13092 0x00000003, 0x00000001, 0x00000101, 0x000000a1, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
13093 0x00000101, 0x000000a1, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000a7,
13094 0x00000000, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000b0, 0x00000000, 0x00000008,
13095 0x00000001, 0x00000005, 0x00000101, 0x69736f50, 0x6e6f6974, 0x6c6f6300, 0x5600726f, 0x66664f5f,
13096 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e, 0xabab0064, 0x4e47534f, 0x000000a0, 0x00000005,
13097 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c,
13098 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000008c, 0x00000001, 0x00000000,
13099 0x00000003, 0x00000001, 0x00000d02, 0x0000008c, 0x00000002, 0x00000000, 0x00000003, 0x00000001,
13100 0x00000b04, 0x00000092, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
13101 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
13102 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
13103 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
13104 0x00101012, 0x00000004, 0x04000060, 0x00101012, 0x00000005, 0x00000008, 0x04000067, 0x001020f2,
13105 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065, 0x00102022, 0x00000001,
13106 0x03000065, 0x00102042, 0x00000001, 0x03000065, 0x00102012, 0x00000002, 0x07000000, 0x00102012,
13107 0x00000000, 0x0010100a, 0x00000000, 0x0010100a, 0x00000004, 0x05000036, 0x001020e2, 0x00000000,
13108 0x00101e56, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x05000036,
13109 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042, 0x00000001, 0x0010100a,
13110 0x00000003, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x0100003e,
13112 static const DWORD ps_code[] =
13114 #if 0
13115 struct vs_out
13117 float4 position : SV_Position;
13118 float r : color0;
13119 float g : color1;
13120 float b : color2;
13121 uint instance_id : InstanceId;
13124 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
13126 o0 = float4(i.r, i.g, i.b, 1.0f);
13127 o1 = i.instance_id;
13129 #endif
13130 0x43425844, 0xc9f9c86d, 0xa24d87aa, 0xff75d05b, 0xfbe0581a, 0x00000001, 0x000001b8, 0x00000003,
13131 0x0000002c, 0x000000d4, 0x00000120, 0x4e475349, 0x000000a0, 0x00000005, 0x00000008, 0x00000080,
13132 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
13133 0x00000003, 0x00000001, 0x00000101, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
13134 0x00000202, 0x0000008c, 0x00000002, 0x00000000, 0x00000003, 0x00000001, 0x00000404, 0x00000092,
13135 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
13136 0x6f6c6f63, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x4e47534f, 0x00000044, 0x00000002,
13137 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000038,
13138 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
13139 0x52444853, 0x00000090, 0x00000040, 0x00000024, 0x03001062, 0x00101012, 0x00000001, 0x03001062,
13140 0x00101022, 0x00000001, 0x03001062, 0x00101042, 0x00000001, 0x03000862, 0x00101012, 0x00000002,
13141 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072,
13142 0x00000000, 0x00101246, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
13143 0x05000036, 0x001020f2, 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
13145 static const struct vec4 stream0[] =
13147 {-1.00f, 0.0f, 0.0f, 1.0f},
13148 {-1.00f, 1.0f, 0.0f, 1.0f},
13149 {-0.75f, 0.0f, 0.0f, 1.0f},
13150 {-0.75f, 1.0f, 0.0f, 1.0f},
13151 /* indirect draws data */
13152 {-1.00f, -1.0f, 0.0f, 1.0f},
13153 {-1.00f, 0.0f, 0.0f, 1.0f},
13154 {-0.75f, -1.0f, 0.0f, 1.0f},
13155 {-0.75f, 0.0f, 0.0f, 1.0f},
13157 static const struct
13159 BYTE red;
13160 float v_offset;
13162 stream1[] =
13164 {0xf0, 0.00f},
13165 {0x80, 0.25f},
13166 {0x10, 0.50f},
13167 {0x40, 0.75f},
13169 {0xaa, 1.00f},
13170 {0xbb, 1.25f},
13171 {0xcc, 1.50f},
13172 {0x90, 1.75f},
13174 static const BYTE stream2[] = {0xf0, 0x80, 0x10, 0x40, 0xaa, 0xbb, 0xcc, 0x90};
13175 static const BYTE stream3[] = {0xf0, 0x80, 0x10, 0x40, 0xaa, 0xbb, 0xcc, 0x90};
13176 static const D3D11_DRAW_INSTANCED_INDIRECT_ARGS argument_data[] =
13178 {4, 4, 4, 0},
13179 {4, 4, 4, 4},
13181 static const struct
13183 RECT rect;
13184 unsigned int color;
13185 unsigned int instance_id;
13187 expected_results[] =
13189 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
13190 {{ 80, 0, 160, 240}, 0xfff0f080, 1},
13191 {{160, 0, 240, 240}, 0xff80f010, 2},
13192 {{240, 0, 320, 240}, 0xff80f040, 3},
13193 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
13194 {{400, 0, 480, 240}, 0xffaaaabb, 1},
13195 {{480, 0, 560, 240}, 0xffbbaacc, 2},
13196 {{560, 0, 640, 240}, 0xffbbaa90, 3},
13197 /* indirect draws results */
13198 {{ 0, 240, 80, 480}, 0xfff0f0f0, 0},
13199 {{ 80, 240, 160, 480}, 0xfff0f080, 1},
13200 {{160, 240, 240, 480}, 0xff80f010, 2},
13201 {{240, 240, 320, 480}, 0xff80f040, 3},
13202 {{320, 240, 400, 480}, 0xffaaaaaa, 0},
13203 {{400, 240, 480, 480}, 0xffaaaabb, 1},
13204 {{480, 240, 560, 480}, 0xffbbaacc, 2},
13205 {{560, 240, 640, 480}, 0xffbbaa90, 3},
13207 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13208 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13210 if (!init_test_context(&test_context, &feature_level))
13211 return;
13212 device = test_context.device;
13213 context = test_context.immediate_context;
13215 rtvs[0] = test_context.backbuffer_rtv;
13217 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13218 texture_desc.Format = DXGI_FORMAT_R32_UINT;
13219 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
13220 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13221 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtvs[1]);
13222 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13224 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13225 vs_code, sizeof(vs_code), &input_layout);
13226 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13228 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13229 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13230 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13231 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13233 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
13234 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
13235 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
13236 vb[3] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream3), stream3);
13238 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13239 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13240 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13241 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13242 offset = 0;
13243 stride = sizeof(*stream0);
13244 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
13245 stride = sizeof(*stream1);
13246 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
13247 stride = sizeof(*stream2);
13248 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
13249 stride = sizeof(*stream3);
13250 ID3D11DeviceContext_IASetVertexBuffers(context, 3, 1, &vb[3], &stride, &offset);
13252 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
13253 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[1], white);
13255 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
13256 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
13257 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 4);
13259 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
13260 sizeof(argument_data), argument_data);
13262 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, 0);
13263 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, sizeof(*argument_data));
13265 get_texture_readback(test_context.backbuffer, 0, &rb);
13266 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
13267 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
13268 release_resource_readback(&rb);
13270 get_texture_readback(render_target, 0, &rb);
13271 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
13272 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
13273 release_resource_readback(&rb);
13275 ID3D11Buffer_Release(vb[0]);
13276 ID3D11Buffer_Release(vb[1]);
13277 ID3D11Buffer_Release(vb[2]);
13278 ID3D11Buffer_Release(vb[3]);
13279 ID3D11Buffer_Release(args_buffer);
13280 ID3D11RenderTargetView_Release(rtvs[1]);
13281 ID3D11Texture2D_Release(render_target);
13282 ID3D11VertexShader_Release(vs);
13283 ID3D11PixelShader_Release(ps);
13284 ID3D11InputLayout_Release(input_layout);
13285 release_test_context(&test_context);
13288 static void test_vertex_id(void)
13290 static const DWORD vs_code[] =
13292 #if 0
13293 uint4 main(uint id : ID, uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID) : OUTPUT
13295 return uint4(id, instance_id, vertex_id, 0);
13297 #endif
13298 0x43425844, 0x5625197b, 0x588ccf8f, 0x48694905, 0x961d19ca, 0x00000001, 0x00000170, 0x00000003,
13299 0x0000002c, 0x000000a4, 0x000000d4, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
13300 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000101, 0x00000053, 0x00000000, 0x00000008,
13301 0x00000001, 0x00000001, 0x00000101, 0x00000061, 0x00000000, 0x00000006, 0x00000001, 0x00000002,
13302 0x00000101, 0x53004449, 0x6e495f56, 0x6e617473, 0x44496563, 0x5f565300, 0x74726556, 0x44497865,
13303 0xababab00, 0x4e47534f, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
13304 0x00000001, 0x00000000, 0x0000000f, 0x5054554f, 0xab005455, 0x52444853, 0x00000094, 0x00010040,
13305 0x00000025, 0x0300005f, 0x00101012, 0x00000000, 0x04000060, 0x00101012, 0x00000001, 0x00000008,
13306 0x04000060, 0x00101012, 0x00000002, 0x00000006, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
13307 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010100a,
13308 0x00000001, 0x05000036, 0x00102042, 0x00000000, 0x0010100a, 0x00000002, 0x05000036, 0x00102082,
13309 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
13311 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13313 {"ID", 0, DXGI_FORMAT_R32_UINT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
13315 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
13317 {0, "OUTPUT", 0, 0, 4, 0},
13319 static const unsigned int vertices[] =
13337 static const unsigned int indices[] =
13339 6, 7, 8,
13341 0, 1, 2,
13343 struct uvec4 expected_values[] =
13345 {0, 0, 0},
13346 {1, 0, 1},
13347 {2, 0, 2},
13348 {0, 1, 0},
13349 {1, 1, 1},
13350 {2, 1, 2},
13352 {3, 0, 0},
13353 {4, 0, 1},
13354 {5, 0, 2},
13356 {6, 0, 6},
13357 {7, 0, 7},
13358 {8, 0, 8},
13359 {6, 1, 6},
13360 {7, 1, 7},
13361 {8, 1, 8},
13363 {5, 0, 0},
13364 {6, 0, 1},
13365 {7, 0, 2},
13368 BOOL found_values[ARRAY_SIZE(expected_values)] = {0};
13369 BOOL used_values[ARRAY_SIZE(expected_values)] = {0};
13370 struct d3d11_test_context test_context;
13371 D3D11_QUERY_DATA_SO_STATISTICS data;
13372 ID3D11Buffer *vb, *ib, *so_buffer;
13373 ID3D11InputLayout *input_layout;
13374 ID3D11DeviceContext *context;
13375 D3D11_QUERY_DESC query_desc;
13376 struct resource_readback rb;
13377 unsigned int stride, offset;
13378 ID3D11Asynchronous *query;
13379 ID3D11GeometryShader *gs;
13380 ID3D11VertexShader *vs;
13381 ID3D11Device *device;
13382 unsigned int count;
13383 unsigned int i, j;
13384 HRESULT hr;
13386 if (!init_test_context(&test_context, NULL))
13387 return;
13388 device = test_context.device;
13389 context = test_context.immediate_context;
13391 query_desc.Query = D3D11_QUERY_SO_STATISTICS;
13392 query_desc.MiscFlags = 0;
13393 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
13394 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
13396 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13397 vs_code, sizeof(vs_code), &input_layout);
13398 ok(hr == S_OK, "Failed to create input layout, hr %#x.\n", hr);
13400 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13401 ok(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
13403 stride = 16;
13404 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
13405 so_declaration, ARRAY_SIZE(so_declaration), &stride, 1, 0, NULL, &gs);
13406 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
13408 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13409 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
13410 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
13412 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13413 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
13414 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13415 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
13416 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
13417 offset = 0;
13418 stride = sizeof(*vertices);
13419 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
13421 offset = 0;
13422 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
13424 ID3D11DeviceContext_Begin(context, query);
13426 ID3D11DeviceContext_DrawInstanced(context, 3, 2, 0, 0);
13427 ID3D11DeviceContext_DrawInstanced(context, 3, 1, 3, 16);
13429 ID3D11DeviceContext_DrawIndexedInstanced(context, 3, 2, 0, 0, 0);
13430 ID3D11DeviceContext_DrawIndexedInstanced(context, 3, 1, 3, 9, 7);
13432 ID3D11DeviceContext_End(context, query);
13434 get_query_data(context, query, &data, sizeof(data));
13435 count = data.NumPrimitivesWritten;
13436 ok(count == ARRAY_SIZE(expected_values), "Got unexpected value %u.\n", count);
13438 count = min(count, ARRAY_SIZE(used_values));
13439 get_buffer_readback(so_buffer, &rb);
13440 for (i = 0; i < ARRAY_SIZE(expected_values); ++i)
13442 for (j = 0; j < count; ++j)
13444 if (!used_values[j] && compare_uvec4(get_readback_uvec4(&rb, j, 0), &expected_values[i]))
13446 found_values[i] = TRUE;
13447 used_values[j] = TRUE;
13448 break;
13453 for (i = 0; i < count; ++i)
13455 const struct uvec4 *v = get_readback_uvec4(&rb, i, 0);
13456 ok(used_values[i], "Found unexpected value {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n", v->x, v->y, v->z, v->w);
13458 release_resource_readback(&rb);
13460 for (i = 0; i < ARRAY_SIZE(expected_values); ++i)
13462 ok(found_values[i], "Failed to find value {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n",
13463 expected_values[i].x, expected_values[i].y, expected_values[i].z, expected_values[i].w);
13466 ID3D11Asynchronous_Release(query);
13467 ID3D11Buffer_Release(so_buffer);
13468 ID3D11Buffer_Release(vb);
13469 ID3D11Buffer_Release(ib);
13470 ID3D11GeometryShader_Release(gs);
13471 ID3D11VertexShader_Release(vs);
13472 ID3D11InputLayout_Release(input_layout);
13473 release_test_context(&test_context);
13476 static void test_fragment_coords(void)
13478 struct d3d11_test_context test_context;
13479 ID3D11PixelShader *ps, *ps_frac;
13480 ID3D11DeviceContext *context;
13481 ID3D11Device *device;
13482 ID3D11Buffer *ps_cb;
13483 DWORD color;
13484 HRESULT hr;
13486 static const DWORD ps_code[] =
13488 #if 0
13489 float2 cutoff;
13491 float4 main(float4 position : SV_POSITION) : SV_TARGET
13493 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
13495 if (position.x > cutoff.x)
13496 ret.y = 1.0;
13497 if (position.y > cutoff.y)
13498 ret.z = 1.0;
13500 return ret;
13502 #endif
13503 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
13504 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13505 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13506 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13507 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
13508 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
13509 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
13510 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
13511 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
13512 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
13513 0x0100003e,
13515 static const DWORD ps_frac_code[] =
13517 #if 0
13518 float4 main(float4 position : SV_POSITION) : SV_TARGET
13520 return float4(frac(position.xy), 0.0, 1.0);
13522 #endif
13523 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
13524 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13525 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13526 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13527 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
13528 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13529 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
13530 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
13532 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13533 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
13535 if (!init_test_context(&test_context, NULL))
13536 return;
13538 device = test_context.device;
13539 context = test_context.immediate_context;
13541 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
13543 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13544 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13545 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
13546 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13548 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
13549 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13551 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13553 draw_quad(&test_context);
13555 color = get_texture_color(test_context.backbuffer, 319, 239);
13556 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
13557 color = get_texture_color(test_context.backbuffer, 320, 239);
13558 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13559 color = get_texture_color(test_context.backbuffer, 319, 240);
13560 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13561 color = get_texture_color(test_context.backbuffer, 320, 240);
13562 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
13564 ID3D11Buffer_Release(ps_cb);
13565 cutoff.x = 16.0f;
13566 cutoff.y = 16.0f;
13567 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
13568 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
13570 draw_quad(&test_context);
13572 color = get_texture_color(test_context.backbuffer, 14, 14);
13573 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
13574 color = get_texture_color(test_context.backbuffer, 18, 14);
13575 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13576 color = get_texture_color(test_context.backbuffer, 14, 18);
13577 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13578 color = get_texture_color(test_context.backbuffer, 18, 18);
13579 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
13581 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
13582 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13584 ID3D11DeviceContext_Draw(context, 4, 0);
13586 color = get_texture_color(test_context.backbuffer, 14, 14);
13587 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
13589 ID3D11Buffer_Release(ps_cb);
13590 ID3D11PixelShader_Release(ps_frac);
13591 ID3D11PixelShader_Release(ps);
13592 release_test_context(&test_context);
13595 static void test_initial_texture_data(void)
13597 ID3D11Texture2D *texture, *staging_texture;
13598 struct d3d11_test_context test_context;
13599 D3D11_SUBRESOURCE_DATA resource_data;
13600 D3D11_TEXTURE2D_DESC texture_desc;
13601 ID3D11SamplerState *sampler_state;
13602 ID3D11ShaderResourceView *ps_srv;
13603 D3D11_SAMPLER_DESC sampler_desc;
13604 ID3D11DeviceContext *context;
13605 struct resource_readback rb;
13606 ID3D11PixelShader *ps;
13607 ID3D11Device *device;
13608 unsigned int i, j;
13609 DWORD color;
13610 HRESULT hr;
13612 static const DWORD ps_code[] =
13614 #if 0
13615 Texture2D t;
13616 SamplerState s;
13618 float4 main(float4 position : SV_POSITION) : SV_Target
13620 float2 p;
13622 p.x = position.x / 640.0f;
13623 p.y = position.y / 480.0f;
13624 return t.Sample(s, p);
13626 #endif
13627 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13628 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13629 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13630 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13631 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13632 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13633 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13634 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13635 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13636 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13638 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13639 static const DWORD bitmap_data[] =
13641 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
13642 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
13643 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
13644 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
13647 if (!init_test_context(&test_context, NULL))
13648 return;
13650 device = test_context.device;
13651 context = test_context.immediate_context;
13653 texture_desc.Width = 4;
13654 texture_desc.Height = 4;
13655 texture_desc.MipLevels = 1;
13656 texture_desc.ArraySize = 1;
13657 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13658 texture_desc.SampleDesc.Count = 1;
13659 texture_desc.SampleDesc.Quality = 0;
13660 texture_desc.Usage = D3D11_USAGE_STAGING;
13661 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
13662 texture_desc.BindFlags = 0;
13663 texture_desc.MiscFlags = 0;
13665 resource_data.pSysMem = bitmap_data;
13666 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
13667 resource_data.SysMemSlicePitch = 0;
13669 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &staging_texture);
13670 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
13672 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13673 texture_desc.CPUAccessFlags = 0;
13674 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13675 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13676 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
13678 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)texture, (ID3D11Resource *)staging_texture);
13680 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
13681 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
13683 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
13684 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
13685 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
13686 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
13687 sampler_desc.MipLODBias = 0.0f;
13688 sampler_desc.MaxAnisotropy = 0;
13689 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
13690 sampler_desc.BorderColor[0] = 0.0f;
13691 sampler_desc.BorderColor[1] = 0.0f;
13692 sampler_desc.BorderColor[2] = 0.0f;
13693 sampler_desc.BorderColor[3] = 0.0f;
13694 sampler_desc.MinLOD = 0.0f;
13695 sampler_desc.MaxLOD = 0.0f;
13696 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
13697 ok(hr == S_OK, "Failed to create sampler state, hr %#x.\n", hr);
13699 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13700 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
13702 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
13703 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
13704 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13706 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13707 draw_quad(&test_context);
13708 get_texture_readback(test_context.backbuffer, 0, &rb);
13709 for (i = 0; i < 4; ++i)
13711 for (j = 0; j < 4; ++j)
13713 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13714 ok(compare_color(color, bitmap_data[j + i * 4], 1),
13715 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13716 color, j, i, bitmap_data[j + i * 4]);
13719 release_resource_readback(&rb);
13721 ID3D11PixelShader_Release(ps);
13722 ID3D11SamplerState_Release(sampler_state);
13723 ID3D11ShaderResourceView_Release(ps_srv);
13724 ID3D11Texture2D_Release(staging_texture);
13725 ID3D11Texture2D_Release(texture);
13726 release_test_context(&test_context);
13729 static void test_update_subresource(void)
13731 struct d3d11_test_context test_context;
13732 D3D11_SUBRESOURCE_DATA resource_data;
13733 D3D11_TEXTURE3D_DESC texture_desc_3d;
13734 D3D11_TEXTURE2D_DESC texture_desc;
13735 ID3D11SamplerState *sampler_state;
13736 ID3D11ShaderResourceView *ps_srv;
13737 D3D11_SAMPLER_DESC sampler_desc;
13738 ID3D11DeviceContext *context;
13739 struct resource_readback rb;
13740 ID3D11Texture3D *texture_3d;
13741 ID3D11Texture2D *texture;
13742 ID3D11PixelShader *ps;
13743 ID3D11Device *device;
13744 unsigned int i, j;
13745 D3D11_BOX box;
13746 DWORD color;
13747 HRESULT hr;
13749 static const DWORD ps_code[] =
13751 #if 0
13752 Texture2D t;
13753 SamplerState s;
13755 float4 main(float4 position : SV_POSITION) : SV_Target
13757 float2 p;
13759 p.x = position.x / 640.0f;
13760 p.y = position.y / 480.0f;
13761 return t.Sample(s, p);
13763 #endif
13764 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13765 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13766 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13767 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13768 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13769 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13770 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13771 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13772 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13773 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13775 static const DWORD ps_code_3d[] =
13777 #if 0
13778 Texture3D t;
13779 SamplerState s;
13781 float4 main(float4 position : SV_POSITION) : SV_Target
13783 float3 p1, p2;
13784 p2.x = p1.x = position.x / 640.0f;
13785 p2.y = p1.y = position.y / 480.0f;
13786 p1.z = 0.25;
13787 p2.z = 0.75;
13788 return 0.5 * (t.Sample(s, p1) + t.Sample(s, p2));
13790 #endif
13791 0x43425844, 0x4d466d63, 0xa3d10db1, 0xd6534470, 0x16d738ef, 0x00000001, 0x000001ec, 0x00000003,
13792 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13793 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13794 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13795 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000150, 0x00000040,
13796 0x00000054, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
13797 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13798 0x00000002, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13799 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3e800000,
13800 0x09000045, 0x001000f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
13801 0x00000000, 0x0a000038, 0x00100032, 0x00000001, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13802 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000001, 0x00004001, 0x3f400000,
13803 0x09000045, 0x001000f2, 0x00000001, 0x00100246, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
13804 0x00000000, 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
13805 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000,
13806 0x3f000000, 0x3f000000, 0x0100003e,
13808 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13809 static const DWORD initial_data[32] = {0};
13810 static const DWORD bitmap_data[] =
13812 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
13813 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
13814 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
13815 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
13817 static const DWORD expected_colors[] =
13819 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
13820 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
13821 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
13822 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
13824 static const DWORD bc7_data[] =
13826 0x3a7b944b, 0x982a5800, 0x9cab4983, 0xc6a09579,
13827 0x5f7f2bfe, 0xa95d98f2, 0x3bfb4c03, 0x8be16a41,
13828 0x8362e6c0, 0x358ed7a2, 0xec3e130b, 0x86cebc86,
13829 0xf045be66, 0x7a16507f, 0xfe9ccc9f, 0x3f103e16,
13830 0x84d466c5, 0xfaf5cb5a, 0x9b9e1859, 0x384589b0,
13831 0x9268b4b8, 0x212b3643, 0x813f853a, 0x4a2bd7c2,
13832 0x1809f3e0, 0xf646d5ef, 0x40e80679, 0x05791fe5,
13833 0x6604e7e5, 0x5c28b55d, 0x1ef211f5, 0x632d47f6,
13835 static const DWORD bc7_expected_colors[] =
13837 0xc1752752, 0xc39859a9, 0xff79c08e, 0xff63bf6c,
13838 0xbf7d2756, 0xb89f3d40, 0xffda3a77, 0xffd08099,
13839 0x415f1f37, 0x43671d3f, 0xffc64758, 0xff57a194,
13840 0x405a2032, 0x39422619, 0xff749b76, 0xffabb879,
13842 static const DWORD expected_colors_3d[] = { 0xffff8000, 0xffff8080, 0x80008000, 0xff8080ff };
13844 if (!init_test_context(&test_context, NULL))
13845 return;
13847 device = test_context.device;
13848 context = test_context.immediate_context;
13850 texture_desc.Width = 4;
13851 texture_desc.Height = 4;
13852 texture_desc.MipLevels = 1;
13853 texture_desc.ArraySize = 1;
13854 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13855 texture_desc.SampleDesc.Count = 1;
13856 texture_desc.SampleDesc.Quality = 0;
13857 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13858 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13859 texture_desc.CPUAccessFlags = 0;
13860 texture_desc.MiscFlags = 0;
13862 resource_data.pSysMem = initial_data;
13863 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
13864 resource_data.SysMemSlicePitch = 0;
13866 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
13867 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
13869 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
13870 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13872 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
13873 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
13874 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
13875 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
13876 sampler_desc.MipLODBias = 0.0f;
13877 sampler_desc.MaxAnisotropy = 0;
13878 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
13879 sampler_desc.BorderColor[0] = 0.0f;
13880 sampler_desc.BorderColor[1] = 0.0f;
13881 sampler_desc.BorderColor[2] = 0.0f;
13882 sampler_desc.BorderColor[3] = 0.0f;
13883 sampler_desc.MinLOD = 0.0f;
13884 sampler_desc.MaxLOD = 0.0f;
13886 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
13887 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
13889 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13890 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13892 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
13893 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
13894 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13896 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13897 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
13899 draw_quad(&test_context);
13900 check_texture_color(test_context.backbuffer, 0x00000000, 0);
13902 set_box(&box, 1, 1, 0, 3, 3, 1);
13903 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13904 bitmap_data, 4 * sizeof(*bitmap_data), 0);
13905 set_box(&box, 0, 3, 0, 3, 4, 1);
13906 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13907 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
13908 set_box(&box, 0, 0, 0, 4, 1, 1);
13909 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13910 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
13911 set_box(&box, 0, 1, 0, 1, 3, 1);
13912 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13913 &bitmap_data[2], sizeof(*bitmap_data), 0);
13914 set_box(&box, 4, 4, 0, 3, 1, 1);
13915 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13916 bitmap_data, sizeof(*bitmap_data), 0);
13917 set_box(&box, 0, 0, 0, 4, 4, 0);
13918 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13919 bitmap_data, 4 * sizeof(*bitmap_data), 0);
13920 draw_quad(&test_context);
13921 get_texture_readback(test_context.backbuffer, 0, &rb);
13922 for (i = 0; i < 4; ++i)
13924 for (j = 0; j < 4; ++j)
13926 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13927 ok(compare_color(color, expected_colors[j + i * 4], 1),
13928 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13929 color, j, i, expected_colors[j + i * 4]);
13932 release_resource_readback(&rb);
13934 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
13935 bitmap_data, 4 * sizeof(*bitmap_data), 0);
13936 draw_quad(&test_context);
13937 get_texture_readback(test_context.backbuffer, 0, &rb);
13938 for (i = 0; i < 4; ++i)
13940 for (j = 0; j < 4; ++j)
13942 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13943 ok(compare_color(color, bitmap_data[j + i * 4], 1),
13944 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13945 color, j, i, bitmap_data[j + i * 4]);
13948 release_resource_readback(&rb);
13950 ID3D11ShaderResourceView_Release(ps_srv);
13951 ID3D11Texture2D_Release(texture);
13952 ID3D11PixelShader_Release(ps);
13954 hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps);
13955 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13957 texture_desc_3d.Width = 2;
13958 texture_desc_3d.Height = 2;
13959 texture_desc_3d.Depth = 2;
13960 texture_desc_3d.MipLevels = 1;
13961 texture_desc_3d.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13962 texture_desc_3d.Usage = D3D11_USAGE_DEFAULT;
13963 texture_desc_3d.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13964 texture_desc_3d.CPUAccessFlags = 0;
13965 texture_desc_3d.MiscFlags = 0;
13967 resource_data.SysMemPitch = texture_desc_3d.Width * sizeof(*initial_data);
13968 resource_data.SysMemSlicePitch = texture_desc_3d.Width * texture_desc_3d.Height * sizeof(*initial_data);
13970 hr = ID3D11Device_CreateTexture3D(device, &texture_desc_3d, &resource_data, &texture_3d);
13971 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
13973 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture_3d, NULL, &ps_srv);
13974 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13976 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13977 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
13979 set_box(&box, 0, 0, 0, 1, 2, 1);
13980 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data, 8, 16);
13981 set_box(&box, 0, 0, 0, 1, 1, 2);
13982 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 4, 16, 32);
13983 set_box(&box, 1, 0, 0, 2, 1, 2);
13984 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 8, 4, 0);
13985 set_box(&box, 0, 0, 1, 2, 1, 2);
13986 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 2, 4, 5);
13987 set_box(&box, 0, 0, 1, 2, 1, 2);
13988 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 3, 12, 0);
13989 set_box(&box, 1, 1, 0, 2, 2, 2);
13990 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data, 0, 32);
13992 draw_quad(&test_context);
13993 get_texture_readback(test_context.backbuffer, 0, &rb);
13994 for (i = 0; i < 2; ++i)
13996 for (j = 0; j < 2; ++j)
13998 color = get_readback_color(&rb, 160 + j * 320, 120 + i * 240, 0);
13999 ok(compare_color(color, expected_colors_3d[j + i * 2], 1),
14000 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14001 color, j, i, expected_colors_3d[j + i * 2]);
14004 release_resource_readback(&rb);
14005 ID3D11ShaderResourceView_Release(ps_srv);
14006 ID3D11Texture3D_Release(texture_3d);
14008 texture_desc_3d.Width = 8;
14009 texture_desc_3d.Height = 8;
14010 texture_desc_3d.Depth = 2;
14011 texture_desc_3d.Format = DXGI_FORMAT_BC7_UNORM;
14013 resource_data.SysMemPitch = 32;
14014 resource_data.SysMemSlicePitch = 64;
14016 hr = ID3D11Device_CreateTexture3D(device, &texture_desc_3d, &resource_data, &texture_3d);
14017 if (FAILED(hr))
14019 skip("Failed to create BC7 3d texture, hr %#x.\n", hr);
14021 else
14023 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture_3d, NULL, &ps_srv);
14024 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14026 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14027 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14029 set_box(&box, 0, 0, 0, 8, 8, 2);
14030 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data, 32, 64);
14031 set_box(&box, 0, 0, 1, 8, 8, 2);
14032 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data, 16, 0);
14033 set_box(&box, 0, 0, 0, 4, 4, 1);
14034 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 8, 0, 0);
14035 set_box(&box, 4, 4, 0, 8, 8, 2);
14036 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 16, 0, 16);
14037 set_box(&box, 0, 4, 1, 8, 8, 2);
14038 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 1, 4, 32);
14039 set_box(&box, 4, 0, 0, 8, 4, 2);
14040 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 2, 0, 1);
14042 draw_quad(&test_context);
14043 get_texture_readback(test_context.backbuffer, 0, &rb);
14044 for (i = 0; i < 4; ++i)
14046 for (j = 0; j < 4; ++j)
14048 color = get_readback_color(&rb, 70 + j * 160, 50 + i * 120, 0);
14049 ok(compare_color(color, bc7_expected_colors[j + i * 4], 1),
14050 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14051 color, j, i, bc7_expected_colors[j + i * 4]);
14054 release_resource_readback(&rb);
14055 ID3D11ShaderResourceView_Release(ps_srv);
14056 ID3D11Texture3D_Release(texture_3d);
14059 ID3D11PixelShader_Release(ps);
14060 ID3D11SamplerState_Release(sampler_state);
14061 release_test_context(&test_context);
14064 static void test_copy_subresource_region(void)
14066 ID3D11Texture2D *dst_texture, *src_texture;
14067 struct d3d11_test_context test_context;
14068 ID3D11Buffer *dst_buffer, *src_buffer;
14069 D3D11_SUBRESOURCE_DATA resource_data;
14070 D3D11_TEXTURE2D_DESC texture_desc;
14071 ID3D11SamplerState *sampler_state;
14072 ID3D11ShaderResourceView *ps_srv;
14073 D3D11_SAMPLER_DESC sampler_desc;
14074 ID3D11DeviceContext1 *context1;
14075 ID3D11DeviceContext *context;
14076 struct vec4 float_colors[16];
14077 struct resource_readback rb;
14078 ID3D11PixelShader *ps;
14079 ID3D11Device *device;
14080 unsigned int i, j;
14081 D3D11_BOX box;
14082 DWORD color;
14083 HRESULT hr;
14085 static const DWORD ps_code[] =
14087 #if 0
14088 Texture2D t;
14089 SamplerState s;
14091 float4 main(float4 position : SV_POSITION) : SV_Target
14093 float2 p;
14095 p.x = position.x / 640.0f;
14096 p.y = position.y / 480.0f;
14097 return t.Sample(s, p);
14099 #endif
14100 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
14101 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14102 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14103 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14104 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
14105 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
14106 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14107 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
14108 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
14109 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
14111 static const DWORD ps_buffer_code[] =
14113 #if 0
14114 float4 buffer[16];
14116 float4 main(float4 position : SV_POSITION) : SV_TARGET
14118 float2 p = (float2)4;
14119 p *= float2(position.x / 640.0f, position.y / 480.0f);
14120 return buffer[(int)p.y * 4 + (int)p.x];
14122 #endif
14123 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
14124 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14125 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14126 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14127 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
14128 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
14129 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
14130 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
14131 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
14132 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
14133 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
14134 0x0010000a, 0x00000000, 0x0100003e,
14136 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
14137 static const DWORD initial_data[16] = {0};
14138 static const DWORD bitmap_data[] =
14140 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14141 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14142 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14143 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14145 static const DWORD expected_colors[] =
14147 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14148 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
14149 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
14150 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
14153 if (!init_test_context(&test_context, NULL))
14154 return;
14156 device = test_context.device;
14157 context = test_context.immediate_context;
14159 texture_desc.Width = 4;
14160 texture_desc.Height = 4;
14161 texture_desc.MipLevels = 1;
14162 texture_desc.ArraySize = 1;
14163 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14164 texture_desc.SampleDesc.Count = 1;
14165 texture_desc.SampleDesc.Quality = 0;
14166 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14167 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14168 texture_desc.CPUAccessFlags = 0;
14169 texture_desc.MiscFlags = 0;
14171 resource_data.pSysMem = initial_data;
14172 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
14173 resource_data.SysMemSlicePitch = 0;
14175 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
14176 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14178 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
14180 resource_data.pSysMem = bitmap_data;
14181 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
14182 resource_data.SysMemSlicePitch = 0;
14184 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
14185 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14187 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
14188 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14190 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14191 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14192 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14193 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14194 sampler_desc.MipLODBias = 0.0f;
14195 sampler_desc.MaxAnisotropy = 0;
14196 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14197 sampler_desc.BorderColor[0] = 0.0f;
14198 sampler_desc.BorderColor[1] = 0.0f;
14199 sampler_desc.BorderColor[2] = 0.0f;
14200 sampler_desc.BorderColor[3] = 0.0f;
14201 sampler_desc.MinLOD = 0.0f;
14202 sampler_desc.MaxLOD = 0.0f;
14204 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
14205 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14207 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14208 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14210 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14211 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14212 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14214 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14216 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14217 1, 1, 0, NULL, 0, &box);
14218 ID3D11DeviceContext_CopySubresourceRegion(context, NULL, 0,
14219 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14221 set_box(&box, 0, 0, 0, 2, 2, 1);
14222 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14223 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14224 set_box(&box, 1, 2, 0, 4, 3, 1);
14225 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14226 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
14227 set_box(&box, 0, 3, 0, 4, 4, 1);
14228 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14229 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14230 set_box(&box, 3, 0, 0, 4, 2, 1);
14231 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14232 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14233 set_box(&box, 3, 1, 0, 4, 2, 1);
14234 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14235 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
14236 set_box(&box, 0, 0, 0, 4, 4, 0);
14237 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14238 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14239 draw_quad(&test_context);
14240 get_texture_readback(test_context.backbuffer, 0, &rb);
14241 for (i = 0; i < 4; ++i)
14243 for (j = 0; j < 4; ++j)
14245 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14246 ok(compare_color(color, expected_colors[j + i * 4], 1),
14247 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14248 color, j, i, expected_colors[j + i * 4]);
14251 release_resource_readback(&rb);
14253 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14254 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
14255 draw_quad(&test_context);
14256 get_texture_readback(test_context.backbuffer, 0, &rb);
14257 for (i = 0; i < 4; ++i)
14259 for (j = 0; j < 4; ++j)
14261 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14262 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14263 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14264 color, j, i, bitmap_data[j + i * 4]);
14267 release_resource_readback(&rb);
14269 hr = ID3D11DeviceContext_QueryInterface(context, &IID_ID3D11DeviceContext1, (void **)&context1);
14270 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
14271 "Failed to query ID3D11DeviceContext1, hr %#x.\n", hr);
14273 if (SUCCEEDED(hr))
14275 ID3D11DeviceContext1_ClearRenderTargetView(context1, test_context.backbuffer_rtv, red);
14276 check_texture_color(test_context.backbuffer, 0x800000ff, 2);
14278 memset(float_colors, 0, sizeof(float_colors));
14279 for (i = 0; i < texture_desc.Width; ++i)
14280 ((unsigned int *)float_colors)[i] = 0x45454545;
14282 ID3D11DeviceContext1_UpdateSubresource1(context1, (ID3D11Resource *)dst_texture, 0, NULL,
14283 float_colors, 0, 0, 0);
14284 draw_quad(&test_context);
14285 check_texture_color(test_context.backbuffer, 0x45454545, 1);
14287 ID3D11DeviceContext1_CopySubresourceRegion1(context1, (ID3D11Resource *)dst_texture, 0,
14288 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL, 0);
14289 draw_quad(&test_context);
14291 get_texture_readback(test_context.backbuffer, 0, &rb);
14292 for (i = 0; i < 4; ++i)
14294 for (j = 0; j < 4; ++j)
14296 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14297 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14298 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14299 color, j, i, bitmap_data[j + i * 4]);
14302 release_resource_readback(&rb);
14304 ID3D11DeviceContext1_Release(context1);
14308 ID3D11PixelShader_Release(ps);
14309 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
14310 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14312 ID3D11ShaderResourceView_Release(ps_srv);
14313 ps_srv = NULL;
14315 ID3D11SamplerState_Release(sampler_state);
14316 sampler_state = NULL;
14318 ID3D11Texture2D_Release(dst_texture);
14319 ID3D11Texture2D_Release(src_texture);
14321 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14322 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14323 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14325 memset(float_colors, 0, sizeof(float_colors));
14326 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
14327 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
14329 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
14331 for (i = 0; i < 4; ++i)
14333 for (j = 0; j < 4; ++j)
14335 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
14336 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
14337 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
14338 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
14341 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
14342 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
14344 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
14345 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14346 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14347 draw_quad(&test_context);
14348 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14350 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
14351 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14352 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14353 draw_quad(&test_context);
14354 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14356 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
14357 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14358 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14359 draw_quad(&test_context);
14360 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14362 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
14363 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14364 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14365 draw_quad(&test_context);
14366 get_texture_readback(test_context.backbuffer, 0, &rb);
14367 for (i = 0; i < 4; ++i)
14369 for (j = 0; j < 4; ++j)
14371 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14372 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14373 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14374 color, j, i, bitmap_data[j + i * 4]);
14377 release_resource_readback(&rb);
14379 ID3D11Buffer_Release(dst_buffer);
14380 ID3D11Buffer_Release(src_buffer);
14381 ID3D11PixelShader_Release(ps);
14382 release_test_context(&test_context);
14385 static void test_copy_subresource_region_1d(void)
14387 D3D11_SUBRESOURCE_DATA resource_data[4];
14388 struct d3d11_test_context test_context;
14389 D3D11_TEXTURE1D_DESC texture1d_desc;
14390 D3D11_TEXTURE2D_DESC texture2d_desc;
14391 ID3D11DeviceContext *context;
14392 struct resource_readback rb;
14393 ID3D11Texture1D *texture1d;
14394 ID3D11Texture2D *texture2d;
14395 ID3D11Device *device;
14396 unsigned int i, j;
14397 D3D11_BOX box;
14398 DWORD color;
14399 HRESULT hr;
14401 static const DWORD bitmap_data[] =
14403 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14404 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14405 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14406 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14409 if (!init_test_context(&test_context, NULL))
14410 return;
14411 device = test_context.device;
14412 context = test_context.immediate_context;
14414 texture1d_desc.Width = 4;
14415 texture1d_desc.MipLevels = 1;
14416 texture1d_desc.ArraySize = 4;
14417 texture1d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14418 texture1d_desc.Usage = D3D11_USAGE_DEFAULT;
14419 texture1d_desc.BindFlags = 0;
14420 texture1d_desc.CPUAccessFlags = 0;
14421 texture1d_desc.MiscFlags = 0;
14423 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14425 resource_data[i].pSysMem = &bitmap_data[4 * i];
14426 resource_data[i].SysMemPitch = texture1d_desc.Width * sizeof(bitmap_data);
14427 resource_data[i].SysMemSlicePitch = 0;
14430 hr = ID3D11Device_CreateTexture1D(device, &texture1d_desc, resource_data, &texture1d);
14431 ok(hr == S_OK, "Failed to create 1d texture, hr %#x.\n", hr);
14433 texture2d_desc.Width = 4;
14434 texture2d_desc.Height = 4;
14435 texture2d_desc.MipLevels = 1;
14436 texture2d_desc.ArraySize = 1;
14437 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14438 texture2d_desc.SampleDesc.Count = 1;
14439 texture2d_desc.SampleDesc.Quality = 0;
14440 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
14441 texture2d_desc.BindFlags = 0;
14442 texture2d_desc.CPUAccessFlags = 0;
14443 texture2d_desc.MiscFlags = 0;
14445 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14446 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
14448 set_box(&box, 0, 0, 0, 4, 1, 1);
14449 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14451 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2d, 0,
14452 0, i, 0, (ID3D11Resource *)texture1d, i, &box);
14455 get_texture_readback(texture2d, 0, &rb);
14456 for (i = 0; i < 4; ++i)
14458 for (j = 0; j < 4; ++j)
14460 color = get_readback_color(&rb, j, i, 0);
14461 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14462 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14463 color, j, i, bitmap_data[j + i * 4]);
14466 release_resource_readback(&rb);
14468 get_texture1d_readback(texture1d, 0, &rb);
14469 for (i = 0; i < texture1d_desc.Width; ++i)
14471 color = get_readback_color(&rb, i, 0, 0);
14472 ok(compare_color(color, bitmap_data[i], 1),
14473 "Got color 0x%08x at %u, expected 0x%08x.\n",
14474 color, i, bitmap_data[i]);
14476 release_resource_readback(&rb);
14478 ID3D11Texture1D_Release(texture1d);
14479 ID3D11Texture2D_Release(texture2d);
14480 release_test_context(&test_context);
14483 static void test_copy_subresource_region_3d(void)
14485 ID3D11ShaderResourceView *dst_srv, *src_srv;
14486 ID3D11Texture3D *dst_texture, *src_texture;
14487 D3D11_SUBRESOURCE_DATA resource_data[4];
14488 struct d3d11_test_context test_context;
14489 D3D11_TEXTURE2D_DESC texture2d_desc;
14490 D3D11_TEXTURE3D_DESC texture3d_desc;
14491 ID3D11SamplerState *sampler_state;
14492 D3D11_SAMPLER_DESC sampler_desc;
14493 ID3D11DeviceContext *context;
14494 struct resource_readback rb;
14495 ID3D11Texture2D *texture2d;
14496 ID3D11PixelShader *ps;
14497 ID3D11Device *device;
14498 unsigned int i, j;
14499 DWORD data[4][16];
14500 D3D11_BOX box;
14501 DWORD color;
14502 HRESULT hr;
14504 static const DWORD ps_code[] =
14506 #if 0
14507 Texture3D t;
14508 SamplerState s;
14510 float4 main(float4 position : SV_POSITION) : SV_Target
14512 return t.Sample(s, position.xyz / float3(640, 480, 1));
14514 #endif
14515 0x43425844, 0x27b15ae8, 0xbebf46f7, 0x6cd88d8d, 0x5118de51, 0x00000001, 0x00000134, 0x00000003,
14516 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14517 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000070f, 0x505f5653, 0x5449534f, 0x004e4f49,
14518 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14519 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
14520 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
14521 0x04002064, 0x00101072, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14522 0x00000001, 0x0a000038, 0x00100072, 0x00000000, 0x00101246, 0x00000000, 0x00004002, 0x3acccccd,
14523 0x3b088889, 0x3f800000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
14524 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
14526 static const DWORD bitmap_data[] =
14528 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14529 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14530 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14531 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14534 if (!init_test_context(&test_context, NULL))
14535 return;
14536 device = test_context.device;
14537 context = test_context.immediate_context;
14539 texture3d_desc.Width = 4;
14540 texture3d_desc.Height = 4;
14541 texture3d_desc.Depth = 4;
14542 texture3d_desc.MipLevels = 1;
14543 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14544 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
14545 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14546 texture3d_desc.CPUAccessFlags = 0;
14547 texture3d_desc.MiscFlags = 0;
14549 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &src_texture);
14550 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
14551 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &dst_texture);
14552 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
14554 texture2d_desc.Width = 4;
14555 texture2d_desc.Height = 4;
14556 texture2d_desc.MipLevels = 1;
14557 texture2d_desc.ArraySize = 4;
14558 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14559 texture2d_desc.SampleDesc.Count = 1;
14560 texture2d_desc.SampleDesc.Quality = 0;
14561 texture2d_desc.Usage = D3D11_USAGE_IMMUTABLE;
14562 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14563 texture2d_desc.CPUAccessFlags = 0;
14564 texture2d_desc.MiscFlags = 0;
14566 for (i = 0; i < ARRAY_SIZE(*data); ++i)
14568 data[0][i] = 0xff0000ff;
14569 data[1][i] = bitmap_data[i];
14570 data[2][i] = 0xff00ff00;
14571 data[3][i] = 0xffff00ff;
14574 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14576 resource_data[i].pSysMem = data[i];
14577 resource_data[i].SysMemPitch = texture2d_desc.Width * sizeof(data[0][0]);
14578 resource_data[i].SysMemSlicePitch = 0;
14581 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, resource_data, &texture2d);
14582 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
14584 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)src_texture, NULL, &src_srv);
14585 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
14586 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &dst_srv);
14587 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
14589 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14590 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14591 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14592 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14593 sampler_desc.MipLODBias = 0.0f;
14594 sampler_desc.MaxAnisotropy = 0;
14595 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14596 sampler_desc.BorderColor[0] = 0.0f;
14597 sampler_desc.BorderColor[1] = 0.0f;
14598 sampler_desc.BorderColor[2] = 0.0f;
14599 sampler_desc.BorderColor[3] = 0.0f;
14600 sampler_desc.MinLOD = 0.0f;
14601 sampler_desc.MaxLOD = 0.0f;
14603 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
14604 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14606 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14607 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
14609 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &src_srv);
14610 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14611 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14613 set_box(&box, 0, 0, 0, 4, 4, 1);
14614 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14616 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
14617 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
14619 draw_quad(&test_context);
14620 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14621 draw_quad_z(&test_context, 0.25f);
14622 get_texture_readback(test_context.backbuffer, 0, &rb);
14623 for (i = 0; i < 4; ++i)
14625 for (j = 0; j < 4; ++j)
14627 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14628 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14629 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14630 color, j, i, bitmap_data[j + i * 4]);
14633 release_resource_readback(&rb);
14634 draw_quad_z(&test_context, 0.5f);
14635 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14636 draw_quad_z(&test_context, 1.0f);
14637 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
14639 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &dst_srv);
14641 set_box(&box, 0, 0, 0, 4, 4, 2);
14642 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14643 0, 0, 2, (ID3D11Resource *)src_texture, 0, &box);
14644 set_box(&box, 0, 0, 2, 4, 4, 4);
14645 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14646 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14648 set_box(&box, 0, 0, 0, 4, 4, 1);
14649 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14651 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
14652 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
14654 draw_quad(&test_context);
14655 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14656 draw_quad_z(&test_context, 0.25f);
14657 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
14658 draw_quad_z(&test_context, 0.5f);
14659 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14660 draw_quad_z(&test_context, 1.0f);
14661 get_texture_readback(test_context.backbuffer, 0, &rb);
14662 for (i = 0; i < 4; ++i)
14664 for (j = 0; j < 4; ++j)
14666 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14667 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14668 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14669 color, j, i, bitmap_data[j + i * 4]);
14672 release_resource_readback(&rb);
14674 ID3D11PixelShader_Release(ps);
14675 ID3D11SamplerState_Release(sampler_state);
14676 ID3D11ShaderResourceView_Release(dst_srv);
14677 ID3D11ShaderResourceView_Release(src_srv);
14678 ID3D11Texture2D_Release(texture2d);
14679 ID3D11Texture3D_Release(dst_texture);
14680 ID3D11Texture3D_Release(src_texture);
14681 release_test_context(&test_context);
14684 static void test_resource_map(void)
14686 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
14687 D3D11_TEXTURE3D_DESC texture3d_desc;
14688 D3D11_TEXTURE2D_DESC texture2d_desc;
14689 D3D11_BUFFER_DESC buffer_desc;
14690 ID3D11DeviceContext *context;
14691 ID3D11Texture3D *texture3d;
14692 ID3D11Texture2D *texture2d;
14693 ID3D11Buffer *buffer;
14694 ID3D11Device *device;
14695 ULONG refcount;
14696 HRESULT hr;
14697 DWORD data;
14699 if (!(device = create_device(NULL)))
14701 skip("Failed to create device.\n");
14702 return;
14705 ID3D11Device_GetImmediateContext(device, &context);
14707 buffer_desc.ByteWidth = 1024;
14708 buffer_desc.Usage = D3D11_USAGE_STAGING;
14709 buffer_desc.BindFlags = 0;
14710 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14711 buffer_desc.MiscFlags = 0;
14712 buffer_desc.StructureByteStride = 0;
14714 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14715 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14717 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14718 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14720 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14721 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14722 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
14723 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14724 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
14725 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14726 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
14728 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14729 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14730 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
14731 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14732 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
14733 data = *((DWORD *)mapped_subresource.pData);
14734 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14735 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
14737 refcount = ID3D11Buffer_Release(buffer);
14738 ok(!refcount, "Buffer has %u references left.\n", refcount);
14740 texture2d_desc.Width = 512;
14741 texture2d_desc.Height = 512;
14742 texture2d_desc.MipLevels = 1;
14743 texture2d_desc.ArraySize = 1;
14744 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14745 texture2d_desc.SampleDesc.Count = 1;
14746 texture2d_desc.SampleDesc.Quality = 0;
14747 texture2d_desc.Usage = D3D11_USAGE_STAGING;
14748 texture2d_desc.BindFlags = 0;
14749 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14750 texture2d_desc.MiscFlags = 0;
14752 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14753 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14755 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14756 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14758 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14759 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14760 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14761 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14762 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
14763 mapped_subresource.DepthPitch);
14764 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14765 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
14767 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14768 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14769 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14770 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14771 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
14772 mapped_subresource.DepthPitch);
14773 data = *((DWORD *)mapped_subresource.pData);
14774 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14775 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
14777 refcount = ID3D11Texture2D_Release(texture2d);
14778 ok(!refcount, "2D texture has %u references left.\n", refcount);
14780 texture3d_desc.Width = 64;
14781 texture3d_desc.Height = 64;
14782 texture3d_desc.Depth = 64;
14783 texture3d_desc.MipLevels = 1;
14784 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14785 texture3d_desc.Usage = D3D11_USAGE_STAGING;
14786 texture3d_desc.BindFlags = 0;
14787 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14788 texture3d_desc.MiscFlags = 0;
14790 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14791 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
14793 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14794 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14796 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14797 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14798 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14799 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14800 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
14801 mapped_subresource.DepthPitch);
14802 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14803 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
14805 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14806 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14807 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14808 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14809 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
14810 mapped_subresource.DepthPitch);
14811 data = *((DWORD *)mapped_subresource.pData);
14812 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14813 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
14815 refcount = ID3D11Texture3D_Release(texture3d);
14816 ok(!refcount, "3D texture has %u references left.\n", refcount);
14818 ID3D11DeviceContext_Release(context);
14820 refcount = ID3D11Device_Release(device);
14821 ok(!refcount, "Device has %u references left.\n", refcount);
14824 #define check_resource_cpu_access(a, b, c, d, e) check_resource_cpu_access_(__LINE__, a, b, c, d, e)
14825 static void check_resource_cpu_access_(unsigned int line, ID3D11DeviceContext *context,
14826 ID3D11Resource *resource, D3D11_USAGE usage, UINT bind_flags, UINT cpu_access)
14828 BOOL cpu_write = cpu_access & D3D11_CPU_ACCESS_WRITE;
14829 BOOL cpu_read = cpu_access & D3D11_CPU_ACCESS_READ;
14830 BOOL dynamic = usage == D3D11_USAGE_DYNAMIC;
14831 D3D11_MAPPED_SUBRESOURCE map_desc;
14832 HRESULT hr, expected_hr;
14833 ID3D11Device *device;
14835 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
14836 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ, 0, &map_desc);
14837 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
14838 if (SUCCEEDED(hr))
14839 ID3D11DeviceContext_Unmap(context, resource, 0);
14841 /* WRITE_DISCARD and WRITE_NO_OVERWRITE are the only allowed options for dynamic resources. */
14842 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
14843 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE, 0, &map_desc);
14844 todo_wine_if(dynamic && cpu_write)
14845 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
14846 if (SUCCEEDED(hr))
14847 ID3D11DeviceContext_Unmap(context, resource, 0);
14849 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
14850 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
14851 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
14852 if (SUCCEEDED(hr))
14853 ID3D11DeviceContext_Unmap(context, resource, 0);
14855 expected_hr = dynamic ? S_OK : E_INVALIDARG;
14856 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
14857 todo_wine_if(!dynamic && cpu_write)
14858 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
14859 if (SUCCEEDED(hr))
14860 ID3D11DeviceContext_Unmap(context, resource, 0);
14862 if (!dynamic)
14863 return;
14865 ID3D11DeviceContext_GetDevice(context, &device);
14867 /* WRITE_NO_OVERWRITE is supported only for buffers. */
14868 expected_hr = is_buffer(resource) ? S_OK : E_INVALIDARG;
14869 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
14870 /* D3D11.1 is required for constant and shader buffers. */
14871 todo_wine_if(expected_hr != S_OK)
14872 ok_(__FILE__, line)(hr == expected_hr
14873 || broken(bind_flags & (D3D11_BIND_CONSTANT_BUFFER | D3D11_BIND_SHADER_RESOURCE)),
14874 "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
14875 if (SUCCEEDED(hr))
14876 ID3D11DeviceContext_Unmap(context, resource, 0);
14878 ID3D11Device_Release(device);
14881 static void test_resource_access(const D3D_FEATURE_LEVEL feature_level)
14883 D3D11_TEXTURE2D_DESC texture_desc;
14884 struct device_desc device_desc;
14885 D3D11_BUFFER_DESC buffer_desc;
14886 ID3D11DeviceContext *context;
14887 D3D11_SUBRESOURCE_DATA data;
14888 ID3D11Resource *resource;
14889 BOOL required_cpu_access;
14890 BOOL cpu_write, cpu_read;
14891 HRESULT hr, expected_hr;
14892 UINT allowed_cpu_access;
14893 BOOL broken_validation;
14894 ID3D11Device *device;
14895 unsigned int i;
14896 ULONG refcount;
14898 static const struct
14900 D3D11_USAGE usage;
14901 UINT bind_flags;
14902 BOOL is_valid;
14903 UINT allowed_cpu_access;
14905 tests[] =
14907 /* Default resources cannot be written by CPU. */
14908 {D3D11_USAGE_DEFAULT, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
14909 {D3D11_USAGE_DEFAULT, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
14910 {D3D11_USAGE_DEFAULT, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
14911 {D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
14912 {D3D11_USAGE_DEFAULT, D3D11_BIND_STREAM_OUTPUT, TRUE, 0},
14913 {D3D11_USAGE_DEFAULT, D3D11_BIND_RENDER_TARGET, TRUE, 0},
14914 {D3D11_USAGE_DEFAULT, D3D11_BIND_DEPTH_STENCIL, TRUE, 0},
14915 {D3D11_USAGE_DEFAULT, D3D11_BIND_UNORDERED_ACCESS, TRUE, 0},
14917 /* Immutable resources cannot be written by CPU and GPU. */
14918 {D3D11_USAGE_IMMUTABLE, 0, FALSE, 0},
14919 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
14920 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
14921 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
14922 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
14923 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
14924 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_RENDER_TARGET, FALSE, 0},
14925 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
14926 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
14928 /* Dynamic resources cannot be written by GPU. */
14929 {D3D11_USAGE_DYNAMIC, 0, FALSE, D3D11_CPU_ACCESS_WRITE},
14930 {D3D11_USAGE_DYNAMIC, D3D11_BIND_VERTEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
14931 {D3D11_USAGE_DYNAMIC, D3D11_BIND_INDEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
14932 {D3D11_USAGE_DYNAMIC, D3D11_BIND_CONSTANT_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
14933 {D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE, TRUE, D3D11_CPU_ACCESS_WRITE},
14934 {D3D11_USAGE_DYNAMIC, D3D11_BIND_STREAM_OUTPUT, FALSE, D3D11_CPU_ACCESS_WRITE},
14935 {D3D11_USAGE_DYNAMIC, D3D11_BIND_RENDER_TARGET, FALSE, D3D11_CPU_ACCESS_WRITE},
14936 {D3D11_USAGE_DYNAMIC, D3D11_BIND_DEPTH_STENCIL, FALSE, D3D11_CPU_ACCESS_WRITE},
14937 {D3D11_USAGE_DYNAMIC, D3D11_BIND_UNORDERED_ACCESS, FALSE, D3D11_CPU_ACCESS_WRITE},
14939 /* Staging resources support only data transfer. */
14940 {D3D11_USAGE_STAGING, 0, TRUE, D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ},
14941 {D3D11_USAGE_STAGING, D3D11_BIND_VERTEX_BUFFER, FALSE, 0},
14942 {D3D11_USAGE_STAGING, D3D11_BIND_INDEX_BUFFER, FALSE, 0},
14943 {D3D11_USAGE_STAGING, D3D11_BIND_CONSTANT_BUFFER, FALSE, 0},
14944 {D3D11_USAGE_STAGING, D3D11_BIND_SHADER_RESOURCE, FALSE, 0},
14945 {D3D11_USAGE_STAGING, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
14946 {D3D11_USAGE_STAGING, D3D11_BIND_RENDER_TARGET, FALSE, 0},
14947 {D3D11_USAGE_STAGING, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
14948 {D3D11_USAGE_STAGING, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
14951 device_desc.feature_level = &feature_level;
14952 device_desc.flags = 0;
14953 if (!(device = create_device(&device_desc)))
14955 skip("Failed to create device for feature level %#x.\n", feature_level);
14956 return;
14958 ID3D11Device_GetImmediateContext(device, &context);
14960 data.SysMemPitch = 0;
14961 data.SysMemSlicePitch = 0;
14962 data.pSysMem = heap_alloc(10240);
14963 ok(!!data.pSysMem, "Failed to allocate memory.\n");
14965 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14967 switch (tests[i].bind_flags)
14969 case D3D11_BIND_DEPTH_STENCIL:
14970 continue;
14972 case D3D11_BIND_SHADER_RESOURCE:
14973 case D3D11_BIND_STREAM_OUTPUT:
14974 case D3D11_BIND_RENDER_TARGET:
14975 if (feature_level < D3D_FEATURE_LEVEL_10_0)
14976 continue;
14977 break;
14979 case D3D11_BIND_UNORDERED_ACCESS:
14980 if (feature_level < D3D_FEATURE_LEVEL_11_0)
14981 continue;
14982 break;
14984 default:
14985 break;
14988 allowed_cpu_access = tests[i].allowed_cpu_access;
14989 if (feature_level >= D3D_FEATURE_LEVEL_11_0 && is_d3d11_2_runtime(device)
14990 && tests[i].usage == D3D11_USAGE_DEFAULT
14991 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
14992 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS))
14993 allowed_cpu_access |= D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
14995 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
14996 cpu_write = allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
14997 cpu_read = allowed_cpu_access & D3D11_CPU_ACCESS_READ;
14999 buffer_desc.ByteWidth = 1024;
15000 buffer_desc.Usage = tests[i].usage;
15001 buffer_desc.BindFlags = tests[i].bind_flags;
15002 buffer_desc.MiscFlags = 0;
15003 buffer_desc.StructureByteStride = 0;
15005 buffer_desc.CPUAccessFlags = 0;
15006 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
15007 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15008 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15009 if (SUCCEEDED(hr))
15011 check_resource_cpu_access(context, resource,
15012 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15013 ID3D11Resource_Release(resource);
15016 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
15017 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
15018 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15019 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15020 if (SUCCEEDED(hr))
15022 check_resource_cpu_access(context, resource,
15023 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15024 ID3D11Resource_Release(resource);
15027 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
15028 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
15029 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15030 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15031 if (SUCCEEDED(hr))
15033 check_resource_cpu_access(context, resource,
15034 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15035 ID3D11Resource_Release(resource);
15038 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
15039 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
15040 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15041 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15042 if (SUCCEEDED(hr))
15044 check_resource_cpu_access(context, resource,
15045 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15046 ID3D11Resource_Release(resource);
15050 data.SysMemPitch = 16;
15052 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15054 switch (tests[i].bind_flags)
15056 case D3D11_BIND_VERTEX_BUFFER:
15057 case D3D11_BIND_INDEX_BUFFER:
15058 case D3D11_BIND_CONSTANT_BUFFER:
15059 case D3D11_BIND_STREAM_OUTPUT:
15060 continue;
15062 case D3D11_BIND_UNORDERED_ACCESS:
15063 if (feature_level < D3D_FEATURE_LEVEL_11_0)
15064 continue;
15065 break;
15067 default:
15068 break;
15071 broken_validation = tests[i].usage == D3D11_USAGE_DEFAULT
15072 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
15073 || tests[i].bind_flags == D3D11_BIND_RENDER_TARGET
15074 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS);
15076 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
15077 cpu_write = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
15078 cpu_read = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_READ;
15080 texture_desc.Width = 4;
15081 texture_desc.Height = 4;
15082 texture_desc.MipLevels = 1;
15083 texture_desc.ArraySize = 1;
15084 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15085 texture_desc.SampleDesc.Count = 1;
15086 texture_desc.SampleDesc.Quality = 0;
15087 texture_desc.Usage = tests[i].usage;
15088 texture_desc.BindFlags = tests[i].bind_flags;
15089 texture_desc.MiscFlags = 0;
15090 if (tests[i].bind_flags == D3D11_BIND_DEPTH_STENCIL)
15091 texture_desc.Format = DXGI_FORMAT_D16_UNORM;
15093 texture_desc.CPUAccessFlags = 0;
15094 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
15095 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15096 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15097 if (SUCCEEDED(hr))
15099 check_resource_cpu_access(context, resource,
15100 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15101 ID3D11Resource_Release(resource);
15104 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
15105 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
15106 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15107 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15108 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15109 if (SUCCEEDED(hr))
15111 if (broken_validation)
15112 texture_desc.CPUAccessFlags = 0;
15113 check_resource_cpu_access(context, resource,
15114 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15115 ID3D11Resource_Release(resource);
15118 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
15119 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
15120 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15121 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15122 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15123 if (SUCCEEDED(hr))
15125 if (broken_validation)
15126 texture_desc.CPUAccessFlags = 0;
15127 check_resource_cpu_access(context, resource,
15128 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15129 ID3D11Resource_Release(resource);
15132 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
15133 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
15134 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15135 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15136 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15137 if (SUCCEEDED(hr))
15139 if (broken_validation)
15140 texture_desc.CPUAccessFlags = 0;
15141 check_resource_cpu_access(context, resource,
15142 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15143 ID3D11Resource_Release(resource);
15147 heap_free((void *)data.pSysMem);
15149 ID3D11DeviceContext_Release(context);
15150 refcount = ID3D11Device_Release(device);
15151 ok(!refcount, "Device has %u references left.\n", refcount);
15154 static void test_check_multisample_quality_levels(void)
15156 ID3D11Device *device;
15157 UINT quality_levels;
15158 ULONG refcount;
15159 HRESULT hr;
15161 if (!(device = create_device(NULL)))
15163 skip("Failed to create device.\n");
15164 return;
15167 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
15168 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
15169 if (!quality_levels)
15171 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
15172 goto done;
15175 quality_levels = 0xdeadbeef;
15176 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
15177 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15178 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15179 quality_levels = 0xdeadbeef;
15180 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
15181 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15182 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
15184 if (!enable_debug_layer)
15186 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
15187 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15188 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
15189 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15190 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
15191 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15194 quality_levels = 0xdeadbeef;
15195 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
15196 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15197 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15199 quality_levels = 0xdeadbeef;
15200 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
15201 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15202 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
15204 quality_levels = 0xdeadbeef;
15205 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
15206 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15207 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15209 /* We assume 15 samples multisampling is never supported in practice. */
15210 quality_levels = 0xdeadbeef;
15211 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
15212 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15213 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15214 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
15215 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15216 quality_levels = 0xdeadbeef;
15217 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
15218 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15219 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15220 quality_levels = 0xdeadbeef;
15221 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
15222 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15223 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15225 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
15226 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15227 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15229 done:
15230 refcount = ID3D11Device_Release(device);
15231 ok(!refcount, "Device has %u references left.\n", refcount);
15234 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
15236 DXGI_SWAP_CHAIN_DESC swapchain_desc;
15237 struct device_desc device_desc;
15238 IDXGISwapChain *swapchain;
15239 IDXGIDevice *dxgi_device;
15240 HRESULT hr, expected_hr;
15241 IDXGIAdapter *adapter;
15242 IDXGIFactory *factory;
15243 ID3D11Device *device;
15244 unsigned int i;
15245 ULONG refcount;
15247 swapchain_desc.BufferDesc.Width = 800;
15248 swapchain_desc.BufferDesc.Height = 600;
15249 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
15250 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
15251 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
15252 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
15253 swapchain_desc.SampleDesc.Count = 1;
15254 swapchain_desc.SampleDesc.Quality = 0;
15255 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
15256 swapchain_desc.BufferCount = 1;
15257 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
15258 swapchain_desc.Windowed = TRUE;
15259 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
15260 swapchain_desc.Flags = 0;
15262 device_desc.feature_level = &feature_level;
15263 device_desc.flags = 0;
15264 if (!(device = create_device(&device_desc)))
15266 skip("Failed to create device for feature level %#x.\n", feature_level);
15267 return;
15270 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
15271 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
15272 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
15273 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
15274 IDXGIDevice_Release(dxgi_device);
15275 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
15276 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
15277 IDXGIAdapter_Release(adapter);
15279 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15280 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
15281 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
15282 hr, feature_level);
15283 if (SUCCEEDED(hr))
15284 IDXGISwapChain_Release(swapchain);
15286 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
15288 DXGI_FORMAT format = display_format_support[i].format;
15289 BOOL todo = FALSE;
15291 if (display_format_support[i].fl_required <= feature_level)
15293 expected_hr = S_OK;
15294 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
15295 todo = TRUE;
15297 else if (!display_format_support[i].fl_optional
15298 || display_format_support[i].fl_optional > feature_level)
15300 expected_hr = E_INVALIDARG;
15301 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
15302 todo = TRUE;
15304 else
15306 continue;
15309 swapchain_desc.BufferDesc.Format = format;
15310 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
15311 todo_wine_if(todo)
15312 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
15313 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
15314 hr, expected_hr, feature_level, format);
15315 if (FAILED(hr))
15316 continue;
15317 refcount = IDXGISwapChain_Release(swapchain);
15318 ok(!refcount, "Swapchain has %u references left.\n", refcount);
15321 refcount = ID3D11Device_Release(device);
15322 ok(!refcount, "Device has %u references left.\n", refcount);
15323 refcount = IDXGIFactory_Release(factory);
15324 ok(!refcount, "Factory has %u references left.\n", refcount);
15325 DestroyWindow(swapchain_desc.OutputWindow);
15328 static void test_swapchain_views(void)
15330 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
15331 struct d3d11_test_context test_context;
15332 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15333 ID3D11ShaderResourceView *srv;
15334 ID3D11DeviceContext *context;
15335 ID3D11RenderTargetView *rtv;
15336 ID3D11Device *device;
15337 ULONG refcount;
15338 HRESULT hr;
15340 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
15342 if (!init_test_context(&test_context, NULL))
15343 return;
15345 device = test_context.device;
15346 context = test_context.immediate_context;
15348 refcount = get_refcount(test_context.backbuffer);
15349 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
15351 draw_color_quad(&test_context, &color);
15352 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
15354 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15355 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15356 U(rtv_desc).Texture2D.MipSlice = 0;
15357 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
15358 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15359 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15361 refcount = get_refcount(test_context.backbuffer);
15362 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
15364 draw_color_quad(&test_context, &color);
15365 check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
15367 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15368 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
15369 U(srv_desc).Texture2D.MostDetailedMip = 0;
15370 U(srv_desc).Texture2D.MipLevels = 1;
15371 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
15372 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15373 if (SUCCEEDED(hr))
15374 ID3D11ShaderResourceView_Release(srv);
15376 ID3D11RenderTargetView_Release(rtv);
15377 release_test_context(&test_context);
15380 static void test_swapchain_flip(void)
15382 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
15383 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
15384 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
15385 D3D11_TEXTURE2D_DESC texture_desc;
15386 ID3D11InputLayout *input_layout;
15387 ID3D11DeviceContext *context;
15388 unsigned int stride, offset;
15389 struct swapchain_desc desc;
15390 IDXGISwapChain *swapchain;
15391 ID3D11VertexShader *vs;
15392 ID3D11PixelShader *ps;
15393 ID3D11Device *device;
15394 ID3D11Buffer *vb;
15395 ULONG refcount;
15396 DWORD color;
15397 HWND window;
15398 HRESULT hr;
15399 RECT rect;
15401 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15403 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15405 static const DWORD vs_code[] =
15407 #if 0
15408 float4 main(float4 position : POSITION) : SV_POSITION
15410 return position;
15412 #endif
15413 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
15414 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15415 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
15416 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
15417 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
15418 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15419 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
15422 static const DWORD ps_code[] =
15424 #if 0
15425 Texture2D t0, t1;
15426 SamplerState s;
15428 float4 main(float4 position : SV_POSITION) : SV_Target
15430 float2 p;
15432 p.x = 0.5;
15433 p.y = 0.5;
15434 if (position.x < 320)
15435 return t0.Sample(s, p);
15436 return t1.Sample(s, p);
15438 #endif
15439 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
15440 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15441 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
15442 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15443 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
15444 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
15445 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
15446 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
15447 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
15448 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
15449 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
15450 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
15451 0x00000000, 0x0100003e,
15453 static const struct vec2 quad[] =
15455 {-1.0f, -1.0f},
15456 {-1.0f, 1.0f},
15457 { 1.0f, -1.0f},
15458 { 1.0f, 1.0f},
15460 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
15461 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15462 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
15464 if (!(device = create_device(NULL)))
15466 skip("Failed to create device, skipping tests.\n");
15467 return;
15469 SetRect(&rect, 0, 0, 640, 480);
15470 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
15471 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
15472 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
15473 desc.buffer_count = 3;
15474 desc.width = desc.height = 0;
15475 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
15476 desc.windowed = TRUE;
15477 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
15478 swapchain = create_swapchain(device, window, &desc);
15480 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
15481 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15482 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
15483 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15484 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
15485 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15487 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
15488 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15489 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
15490 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15491 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
15492 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15494 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
15495 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
15496 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
15497 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
15498 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
15500 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
15501 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
15502 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
15503 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
15504 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
15506 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
15507 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15508 if (SUCCEEDED(hr))
15509 ID3D11RenderTargetView_Release(offscreen_rtv);
15511 ID3D11Device_GetImmediateContext(device, &context);
15513 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
15514 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
15516 texture_desc.Width = 640;
15517 texture_desc.Height = 480;
15518 texture_desc.MipLevels = 1;
15519 texture_desc.ArraySize = 1;
15520 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15521 texture_desc.SampleDesc.Count = 1;
15522 texture_desc.SampleDesc.Quality = 0;
15523 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15524 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15525 texture_desc.CPUAccessFlags = 0;
15526 texture_desc.MiscFlags = 0;
15527 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
15528 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
15529 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
15530 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15531 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
15532 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
15534 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
15536 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15537 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15538 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15539 vs_code, sizeof(vs_code), &input_layout);
15540 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15541 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15542 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
15543 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15544 stride = sizeof(*quad);
15545 offset = 0;
15546 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15548 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15549 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15550 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15552 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
15554 ID3D11DeviceContext_Draw(context, 4, 0);
15555 color = get_texture_color(offscreen, 120, 240);
15556 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15558 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
15559 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
15560 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
15562 * What is this good for? I don't know. Ad-hoc tests suggest that
15563 * Present() always waits for the next V-sync interval, even if there are
15564 * still untouched buffers. Buffer 0 is the buffer that is shown on the
15565 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
15566 * rendering finishes before the V-sync interval is over. I haven't found
15567 * any productive use for more than one buffer. */
15568 IDXGISwapChain_Present(swapchain, 0, 0);
15570 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
15572 ID3D11DeviceContext_Draw(context, 4, 0);
15573 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
15574 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15575 /* Buffer 1 is still untouched. */
15577 color = get_texture_color(backbuffer_0, 320, 240); /* green */
15578 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15579 color = get_texture_color(backbuffer_2, 320, 240); /* red */
15580 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15582 IDXGISwapChain_Present(swapchain, 0, 0);
15584 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
15586 ID3D11DeviceContext_Draw(context, 4, 0);
15587 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
15588 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
15589 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
15590 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15592 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
15593 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
15594 color = get_texture_color(backbuffer_1, 320, 240); /* red */
15595 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15596 color = get_texture_color(backbuffer_2, 320, 240); /* green */
15597 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15599 ID3D11VertexShader_Release(vs);
15600 ID3D11PixelShader_Release(ps);
15601 ID3D11Buffer_Release(vb);
15602 ID3D11InputLayout_Release(input_layout);
15603 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
15604 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
15605 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
15606 ID3D11RenderTargetView_Release(offscreen_rtv);
15607 ID3D11Texture2D_Release(offscreen);
15608 ID3D11Texture2D_Release(backbuffer_0);
15609 ID3D11Texture2D_Release(backbuffer_1);
15610 ID3D11Texture2D_Release(backbuffer_2);
15611 IDXGISwapChain_Release(swapchain);
15613 ID3D11DeviceContext_Release(context);
15614 refcount = ID3D11Device_Release(device);
15615 ok(!refcount, "Device has %u references left.\n", refcount);
15616 DestroyWindow(window);
15619 static void test_clear_render_target_view_1d(void)
15621 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
15622 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15624 struct d3d11_test_context test_context;
15625 D3D11_TEXTURE1D_DESC texture_desc;
15626 ID3D11DeviceContext *context;
15627 ID3D11RenderTargetView *rtv;
15628 ID3D11Texture1D *texture;
15629 ID3D11Device *device;
15630 HRESULT hr;
15632 if (!init_test_context(&test_context, NULL))
15633 return;
15635 device = test_context.device;
15636 context = test_context.immediate_context;
15638 texture_desc.Width = 64;
15639 texture_desc.MipLevels = 1;
15640 texture_desc.ArraySize = 1;
15641 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15642 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15643 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15644 texture_desc.CPUAccessFlags = 0;
15645 texture_desc.MiscFlags = 0;
15646 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, NULL, &texture);
15647 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15649 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15650 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15652 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15653 check_texture1d_color(texture, 0xbf4c7f19, 1);
15655 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15656 check_texture1d_color(texture, 0x8000ff00, 1);
15658 ID3D11RenderTargetView_Release(rtv);
15659 ID3D11Texture1D_Release(texture);
15660 release_test_context(&test_context);
15663 static void test_clear_render_target_view_2d(void)
15665 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
15666 static const float clear_colour[] = {0.1f, 0.5f, 0.3f, 0.75f};
15667 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15668 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
15670 ID3D11RenderTargetView *rtv[3], *srgb_rtv;
15671 ID3D11Texture2D *texture, *srgb_texture;
15672 struct d3d11_test_context test_context;
15673 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15674 D3D11_TEXTURE2D_DESC texture_desc;
15675 ID3D11DeviceContext *context;
15676 struct resource_readback rb;
15677 ID3D11Device *device;
15678 unsigned int i, j;
15679 DWORD colour;
15680 HRESULT hr;
15682 if (!init_test_context(&test_context, NULL))
15683 return;
15685 device = test_context.device;
15686 context = test_context.immediate_context;
15688 texture_desc.Width = 640;
15689 texture_desc.Height = 480;
15690 texture_desc.MipLevels = 1;
15691 texture_desc.ArraySize = 1;
15692 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15693 texture_desc.SampleDesc.Count = 1;
15694 texture_desc.SampleDesc.Quality = 0;
15695 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15696 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15697 texture_desc.CPUAccessFlags = 0;
15698 texture_desc.MiscFlags = 0;
15699 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15700 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15702 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15703 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
15704 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15706 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv[0]);
15707 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15709 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
15710 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15712 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, clear_colour);
15713 check_texture_color(test_context.backbuffer, expected_color, 1);
15715 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], clear_colour);
15716 check_texture_color(texture, expected_color, 1);
15718 if (!enable_debug_layer)
15719 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
15720 check_texture_color(texture, expected_color, 1);
15722 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, clear_colour);
15723 check_texture_color(srgb_texture, expected_srgb_color, 1);
15725 ID3D11RenderTargetView_Release(srgb_rtv);
15726 ID3D11RenderTargetView_Release(rtv[0]);
15727 ID3D11Texture2D_Release(srgb_texture);
15728 ID3D11Texture2D_Release(texture);
15730 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15731 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15732 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15734 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15735 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15736 U(rtv_desc).Texture2D.MipSlice = 0;
15737 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
15738 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15740 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15741 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15742 U(rtv_desc).Texture2D.MipSlice = 0;
15743 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[0]);
15744 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15746 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], clear_colour);
15747 check_texture_color(texture, expected_color, 1);
15749 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, clear_colour);
15750 get_texture_readback(texture, 0, &rb);
15751 for (i = 0; i < 4; ++i)
15753 for (j = 0; j < 4; ++j)
15755 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
15756 colour = get_readback_color(&rb, 80 + i * 160, 60 + j * 120, 0);
15757 ok(compare_color(colour, expected_srgb_color, 1)
15758 || broken(compare_color(colour, expected_color, 1) && broken_device),
15759 "Got unexpected colour 0x%08x.\n", colour);
15762 release_resource_readback(&rb);
15764 ID3D11RenderTargetView_Release(srgb_rtv);
15765 ID3D11RenderTargetView_Release(rtv[0]);
15766 ID3D11Texture2D_Release(texture);
15768 texture_desc.Width = 16;
15769 texture_desc.Height = 16;
15770 texture_desc.ArraySize = 5;
15771 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15772 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15774 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
15775 U(rtv_desc).Texture2DArray.MipSlice = 0;
15776 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
15777 U(rtv_desc).Texture2DArray.ArraySize = 5;
15778 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[0]);
15779 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15781 U(rtv_desc).Texture2DArray.FirstArraySlice = 1;
15782 U(rtv_desc).Texture2DArray.ArraySize = 3;
15783 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[1]);
15784 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15786 U(rtv_desc).Texture2DArray.FirstArraySlice = 2;
15787 U(rtv_desc).Texture2DArray.ArraySize = 1;
15788 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[2]);
15789 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15791 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], blue);
15792 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[1], green);
15793 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[2], clear_colour);
15795 get_texture_readback(texture, 0, &rb);
15796 colour = get_readback_color(&rb, 8, 8, 0);
15797 ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
15798 release_resource_readback(&rb);
15800 get_texture_readback(texture, 1, &rb);
15801 colour = get_readback_color(&rb, 8, 8, 0);
15802 ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
15803 release_resource_readback(&rb);
15805 get_texture_readback(texture, 2, &rb);
15806 colour = get_readback_color(&rb, 8, 8, 0);
15807 ok(compare_color(colour, 0xbf4c7f19, 1), "Got unexpected colour 0x%08x.\n", colour);
15808 release_resource_readback(&rb);
15810 get_texture_readback(texture, 3, &rb);
15811 colour = get_readback_color(&rb, 8, 8, 0);
15812 ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
15813 release_resource_readback(&rb);
15815 get_texture_readback(texture, 4, &rb);
15816 colour = get_readback_color(&rb, 8, 8, 0);
15817 ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
15818 release_resource_readback(&rb);
15820 ID3D11RenderTargetView_Release(rtv[2]);
15821 ID3D11RenderTargetView_Release(rtv[1]);
15822 ID3D11RenderTargetView_Release(rtv[0]);
15823 ID3D11Texture2D_Release(texture);
15825 release_test_context(&test_context);
15828 static void test_clear_render_target_view_3d(void)
15830 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
15831 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15833 struct d3d11_test_context test_context;
15834 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15835 D3D11_TEXTURE3D_DESC texture_desc;
15836 ID3D11DeviceContext *context;
15837 ID3D11RenderTargetView *rtv;
15838 ID3D11Texture3D *texture;
15839 ID3D11Device *device;
15840 HRESULT hr;
15842 if (!init_test_context(&test_context, NULL))
15843 return;
15844 device = test_context.device;
15845 context = test_context.immediate_context;
15847 texture_desc.Width = 8;
15848 texture_desc.Height = 8;
15849 texture_desc.Depth = 4;
15850 texture_desc.MipLevels = 1;
15851 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15852 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15853 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15854 texture_desc.CPUAccessFlags = 0;
15855 texture_desc.MiscFlags = 0;
15856 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
15857 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15859 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15860 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15862 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15863 check_texture3d_color(texture, 0xbf4c7f19, 1);
15864 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15865 check_texture3d_color(texture, 0x8000ff00, 1);
15867 ID3D11RenderTargetView_Release(rtv);
15868 ID3D11Texture3D_Release(texture);
15870 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15871 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
15872 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15874 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15875 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
15876 U(rtv_desc).Texture3D.MipSlice = 0;
15877 U(rtv_desc).Texture3D.FirstWSlice = 0;
15878 U(rtv_desc).Texture3D.WSize = ~0u;
15879 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
15880 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15882 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15883 check_texture3d_color(texture, 0xbf95bc59, 1);
15884 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15885 check_texture3d_color(texture, 0x8000ff00, 1);
15887 ID3D11RenderTargetView_Release(rtv);
15888 ID3D11Texture3D_Release(texture);
15889 release_test_context(&test_context);
15892 static void test_clear_depth_stencil_view(void)
15894 D3D11_TEXTURE2D_DESC texture_desc;
15895 ID3D11Texture2D *depth_texture;
15896 ID3D11DeviceContext *context;
15897 ID3D11DepthStencilView *dsv;
15898 ID3D11Device *device;
15899 ULONG refcount;
15900 HRESULT hr;
15902 if (!(device = create_device(NULL)))
15904 skip("Failed to create device.\n");
15905 return;
15908 ID3D11Device_GetImmediateContext(device, &context);
15910 texture_desc.Width = 640;
15911 texture_desc.Height = 480;
15912 texture_desc.MipLevels = 1;
15913 texture_desc.ArraySize = 1;
15914 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
15915 texture_desc.SampleDesc.Count = 1;
15916 texture_desc.SampleDesc.Quality = 0;
15917 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15918 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
15919 texture_desc.CPUAccessFlags = 0;
15920 texture_desc.MiscFlags = 0;
15921 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
15922 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
15924 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
15925 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
15927 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
15928 check_texture_float(depth_texture, 1.0f, 0);
15930 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
15931 check_texture_float(depth_texture, 0.25f, 0);
15933 if (!enable_debug_layer)
15934 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
15935 check_texture_float(depth_texture, 0.25f, 0);
15937 ID3D11Texture2D_Release(depth_texture);
15938 ID3D11DepthStencilView_Release(dsv);
15940 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
15941 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
15942 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
15944 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
15945 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
15947 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
15948 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
15950 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
15951 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
15953 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
15954 check_texture_color(depth_texture, 0xffffffff, 0);
15956 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
15957 check_texture_color(depth_texture, 0x00000000, 0);
15959 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
15960 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
15962 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
15963 check_texture_color(depth_texture, 0xffffffff, 0);
15965 ID3D11Texture2D_Release(depth_texture);
15966 ID3D11DepthStencilView_Release(dsv);
15968 ID3D11DeviceContext_Release(context);
15970 refcount = ID3D11Device_Release(device);
15971 ok(!refcount, "Device has %u references left.\n", refcount);
15974 static unsigned int to_sint8(unsigned int x)
15976 union
15978 signed int s;
15979 unsigned int u;
15980 } bits;
15981 bits.u = x;
15982 return min(max(bits.s, -128), 127) & 0xff;
15985 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
15986 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
15988 unsigned int x = to_sint8(v->x);
15989 unsigned int y = to_sint8(v->y);
15990 unsigned int z = to_sint8(v->z);
15991 unsigned int w = to_sint8(v->w);
15992 DWORD expected[] =
15994 /* Windows 7 - Nvidia, WARP */
15995 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
15996 /* Windows 10 - AMD */
15997 x | y << 8 | z << 16 | w << 24,
15998 /* Windows 10 - Intel */
15999 x | x << 8 | x << 16 | x << 24,
16002 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
16003 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
16004 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
16007 static void test_clear_buffer_unordered_access_view(void)
16009 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16010 ID3D11UnorderedAccessView *uav, *uav2;
16011 struct device_desc device_desc;
16012 D3D11_BUFFER_DESC buffer_desc;
16013 ID3D11DeviceContext *context;
16014 struct resource_readback rb;
16015 ID3D11Buffer *buffer;
16016 ID3D11Device *device;
16017 struct uvec4 uvec4;
16018 unsigned int i, x;
16019 ULONG refcount;
16020 HRESULT hr;
16021 RECT rect;
16023 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16024 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
16025 static const struct uvec4 uvec4_data[] =
16027 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
16029 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
16030 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
16031 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
16032 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
16033 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
16035 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
16036 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
16037 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
16038 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
16039 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
16040 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
16041 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
16043 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
16044 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
16045 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
16046 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
16047 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
16048 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
16049 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
16050 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
16051 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
16052 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
16054 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
16055 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
16056 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
16057 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
16058 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
16059 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
16060 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
16061 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
16062 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
16063 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
16065 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
16066 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
16067 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
16068 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
16069 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
16070 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
16071 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
16072 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
16073 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
16074 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
16076 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
16077 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
16078 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
16079 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
16080 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
16081 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
16082 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
16083 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
16084 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
16085 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
16088 device_desc.feature_level = &feature_level;
16089 device_desc.flags = 0;
16090 if (!(device = create_device(&device_desc)))
16092 skip("Failed to create device for feature level %#x.\n", feature_level);
16093 return;
16096 ID3D11Device_GetImmediateContext(device, &context);
16098 /* Structured buffer views */
16099 buffer_desc.ByteWidth = 64;
16100 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
16101 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16102 buffer_desc.CPUAccessFlags = 0;
16103 buffer_desc.MiscFlags = 0;
16104 buffer_desc.StructureByteStride = 0;
16105 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
16106 buffer_desc.StructureByteStride = 4;
16107 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16108 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16110 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
16111 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16113 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
16114 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16115 U(uav_desc).Buffer.FirstElement = 0;
16116 U(uav_desc).Buffer.NumElements = 4;
16117 U(uav_desc).Buffer.Flags = 0;
16118 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16119 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16121 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16123 uvec4 = uvec4_data[i];
16124 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16125 get_buffer_readback(buffer, &rb);
16126 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16127 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16128 release_resource_readback(&rb);
16130 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16131 get_buffer_readback(buffer, &rb);
16132 SetRect(&rect, 0, 0, U(uav_desc).Buffer.NumElements, 1);
16133 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16134 SetRect(&rect, U(uav_desc).Buffer.NumElements, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16135 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16136 release_resource_readback(&rb);
16139 ID3D11Buffer_Release(buffer);
16140 ID3D11UnorderedAccessView_Release(uav);
16141 ID3D11UnorderedAccessView_Release(uav2);
16143 /* Raw buffer views */
16144 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
16145 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16146 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16148 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
16149 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16150 U(uav_desc).Buffer.FirstElement = 0;
16151 U(uav_desc).Buffer.NumElements = 16;
16152 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
16153 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16154 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16155 U(uav_desc).Buffer.FirstElement = 8;
16156 U(uav_desc).Buffer.NumElements = 8;
16157 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16158 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16160 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16162 uvec4 = uvec4_data[i];
16163 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16164 get_buffer_readback(buffer, &rb);
16165 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16166 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16167 release_resource_readback(&rb);
16169 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16170 get_buffer_readback(buffer, &rb);
16171 SetRect(&rect, 0, 0, U(uav_desc).Buffer.FirstElement, 1);
16172 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16173 SetRect(&rect, U(uav_desc).Buffer.FirstElement, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16174 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16175 release_resource_readback(&rb);
16178 ID3D11Buffer_Release(buffer);
16179 ID3D11UnorderedAccessView_Release(uav);
16180 ID3D11UnorderedAccessView_Release(uav2);
16182 /* Typed buffer views */
16183 buffer_desc.MiscFlags = 0;
16184 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16185 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16187 uav_desc.Format = DXGI_FORMAT_R32_SINT;
16188 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16189 U(uav_desc).Buffer.FirstElement = 0;
16190 U(uav_desc).Buffer.NumElements = 16;
16191 U(uav_desc).Buffer.Flags = 0;
16192 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16193 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16194 U(uav_desc).Buffer.FirstElement = 9;
16195 U(uav_desc).Buffer.NumElements = 7;
16196 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16197 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16199 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16201 uvec4 = uvec4_data[i];
16202 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16203 get_buffer_readback(buffer, &rb);
16204 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16205 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16206 release_resource_readback(&rb);
16208 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16209 get_buffer_readback(buffer, &rb);
16210 SetRect(&rect, 0, 0, U(uav_desc).Buffer.FirstElement, 1);
16211 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16212 SetRect(&rect, U(uav_desc).Buffer.FirstElement, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16213 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16214 release_resource_readback(&rb);
16217 ID3D11UnorderedAccessView_Release(uav);
16218 ID3D11UnorderedAccessView_Release(uav2);
16220 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
16221 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16222 U(uav_desc).Buffer.FirstElement = 0;
16223 U(uav_desc).Buffer.NumElements = 4;
16224 U(uav_desc).Buffer.Flags = 0;
16225 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16226 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16227 U(uav_desc).Buffer.FirstElement = 2;
16228 U(uav_desc).Buffer.NumElements = 2;
16229 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16230 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16232 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16234 const struct uvec4 *data = NULL;
16235 BOOL all_match;
16237 uvec4 = uvec4_data[i];
16238 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16239 get_buffer_readback(buffer, &rb);
16240 for (x = 0, all_match = TRUE; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
16242 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
16243 data = get_readback_uvec4(&rb, x, 0);
16244 if (!(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result))))
16246 all_match = FALSE;
16247 break;
16250 ok(all_match, "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
16251 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, x);
16252 release_resource_readback(&rb);
16254 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16255 get_buffer_readback(buffer, &rb);
16256 for (x = 0, all_match = TRUE; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
16258 struct uvec4 broken_result;
16259 data = get_readback_uvec4(&rb, x, 0);
16260 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
16261 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
16262 if (!(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result))))
16264 all_match = FALSE;
16265 break;
16268 ok(all_match, "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
16269 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, x);
16270 release_resource_readback(&rb);
16273 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
16274 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16275 ID3D11UnorderedAccessView_Release(uav);
16276 ID3D11UnorderedAccessView_Release(uav2);
16278 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
16279 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16280 U(uav_desc).Buffer.FirstElement = 0;
16281 U(uav_desc).Buffer.NumElements = 16;
16282 U(uav_desc).Buffer.Flags = 0;
16283 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16284 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16285 U(uav_desc).Buffer.FirstElement = 8;
16286 U(uav_desc).Buffer.NumElements = 8;
16287 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16288 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16290 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16292 uvec4 = uvec4_data[i];
16293 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16294 get_buffer_readback(buffer, &rb);
16295 todo_wine check_rgba_sint8(get_readback_color(&rb, 0, 0, 0), &uvec4);
16296 todo_wine check_rgba_sint8(get_readback_color(&rb, 7, 0, 0), &uvec4);
16297 todo_wine check_rgba_sint8(get_readback_color(&rb, 15, 0, 0), &uvec4);
16298 release_resource_readback(&rb);
16300 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16301 get_buffer_readback(buffer, &rb);
16302 todo_wine check_rgba_sint8(get_readback_color(&rb, 0, 0, 0), &uvec4);
16303 todo_wine check_rgba_sint8(get_readback_color(&rb, U(uav_desc).Buffer.FirstElement - 1, 0, 0), &uvec4);
16304 todo_wine check_rgba_sint8(get_readback_color(&rb, U(uav_desc).Buffer.FirstElement, 0, 0), &fe_uvec4);
16305 release_resource_readback(&rb);
16308 ID3D11UnorderedAccessView_Release(uav);
16309 ID3D11UnorderedAccessView_Release(uav2);
16311 ID3D11Buffer_Release(buffer);
16313 ID3D11DeviceContext_Release(context);
16314 refcount = ID3D11Device_Release(device);
16315 ok(!refcount, "Device has %u references left.\n", refcount);
16318 static void test_initial_depth_stencil_state(void)
16320 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16321 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
16322 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16323 struct d3d11_test_context test_context;
16324 D3D11_TEXTURE2D_DESC texture_desc;
16325 ID3D11DeviceContext *context;
16326 ID3D11DepthStencilView *dsv;
16327 ID3D11Texture2D *texture;
16328 ID3D11Device *device;
16329 unsigned int count;
16330 D3D11_VIEWPORT vp;
16331 HRESULT hr;
16333 if (!init_test_context(&test_context, NULL))
16334 return;
16336 device = test_context.device;
16337 context = test_context.immediate_context;
16339 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16340 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
16341 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16342 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16343 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16345 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
16346 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16348 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
16350 count = 1;
16351 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
16353 /* check if depth function is D3D11_COMPARISON_LESS */
16354 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16355 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
16356 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.4f);
16357 draw_color_quad(&test_context, &green);
16358 draw_color_quad(&test_context, &red);
16359 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.6f, 0.6f);
16360 draw_color_quad(&test_context, &red);
16361 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16362 check_texture_float(texture, 0.4f, 1);
16364 ID3D11DepthStencilView_Release(dsv);
16365 ID3D11Texture2D_Release(texture);
16366 release_test_context(&test_context);
16369 static void test_draw_depth_only(void)
16371 struct d3d11_test_context test_context;
16372 ID3D11PixelShader *ps_color, *ps_depth;
16373 D3D11_TEXTURE2D_DESC texture_desc;
16374 ID3D11DeviceContext *context;
16375 ID3D11DepthStencilView *dsv;
16376 struct resource_readback rb;
16377 ID3D11Texture2D *texture;
16378 ID3D11Device *device;
16379 unsigned int i, j;
16380 struct vec4 depth;
16381 ID3D11Buffer *cb;
16382 HRESULT hr;
16384 static const DWORD ps_color_code[] =
16386 #if 0
16387 float4 main(float4 position : SV_POSITION) : SV_Target
16389 return float4(0.0, 1.0, 0.0, 1.0);
16391 #endif
16392 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
16393 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16394 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
16395 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16396 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
16397 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
16398 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
16400 static const DWORD ps_depth_code[] =
16402 #if 0
16403 float depth;
16405 float main() : SV_Depth
16407 return depth;
16409 #endif
16410 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
16411 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16412 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
16413 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
16414 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
16415 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
16418 if (!init_test_context(&test_context, NULL))
16419 return;
16421 device = test_context.device;
16422 context = test_context.immediate_context;
16424 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
16426 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16427 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
16428 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16429 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16430 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16432 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
16433 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16435 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
16436 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16437 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
16438 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16440 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16441 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
16442 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
16444 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16445 check_texture_float(texture, 1.0f, 1);
16446 draw_quad(&test_context);
16447 check_texture_float(texture, 0.0f, 1);
16449 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
16451 depth.x = 0.7f;
16452 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16453 draw_quad(&test_context);
16454 check_texture_float(texture, 0.0f, 1);
16455 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16456 check_texture_float(texture, 1.0f, 1);
16457 draw_quad(&test_context);
16458 check_texture_float(texture, 0.7f, 1);
16459 depth.x = 0.8f;
16460 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16461 draw_quad(&test_context);
16462 check_texture_float(texture, 0.7f, 1);
16463 depth.x = 0.5f;
16464 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16465 draw_quad(&test_context);
16466 check_texture_float(texture, 0.5f, 1);
16468 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16469 for (i = 0; i < 4; ++i)
16471 for (j = 0; j < 4; ++j)
16473 depth.x = 1.0f / 16.0f * (j + 4 * i);
16474 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16476 set_viewport(context, 160.0f * j, 120.0f * i, 160.0f, 120.0f, 0.0f, 1.0f);
16478 draw_quad(&test_context);
16481 get_texture_readback(texture, 0, &rb);
16482 for (i = 0; i < 4; ++i)
16484 for (j = 0; j < 4; ++j)
16486 float obtained_depth, expected_depth;
16488 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
16489 expected_depth = 1.0f / 16.0f * (j + 4 * i);
16490 ok(compare_float(obtained_depth, expected_depth, 1),
16491 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
16492 obtained_depth, j, i, expected_depth);
16495 release_resource_readback(&rb);
16497 ID3D11Buffer_Release(cb);
16498 ID3D11PixelShader_Release(ps_color);
16499 ID3D11PixelShader_Release(ps_depth);
16500 ID3D11DepthStencilView_Release(dsv);
16501 ID3D11Texture2D_Release(texture);
16502 release_test_context(&test_context);
16505 static void test_draw_uav_only(void)
16507 struct d3d11_test_context test_context;
16508 D3D11_TEXTURE2D_DESC texture_desc;
16509 ID3D11UnorderedAccessView *uav;
16510 ID3D11DeviceContext *context;
16511 ID3D11Texture2D *texture;
16512 ID3D11PixelShader *ps;
16513 ID3D11Device *device;
16514 HRESULT hr;
16516 static const DWORD ps_code[] =
16518 #if 0
16519 RWTexture2D<int> u;
16521 void main()
16523 InterlockedAdd(u[uint2(0, 0)], 1);
16525 #endif
16526 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
16527 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16528 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
16529 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
16530 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
16532 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16533 static const UINT values[4] = {0};
16535 if (!init_test_context(&test_context, &feature_level))
16536 return;
16538 device = test_context.device;
16539 context = test_context.immediate_context;
16541 texture_desc.Width = 1;
16542 texture_desc.Height = 1;
16543 texture_desc.MipLevels = 1;
16544 texture_desc.ArraySize = 1;
16545 texture_desc.Format = DXGI_FORMAT_R32_SINT;
16546 texture_desc.SampleDesc.Count = 1;
16547 texture_desc.SampleDesc.Quality = 0;
16548 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16549 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16550 texture_desc.CPUAccessFlags = 0;
16551 texture_desc.MiscFlags = 0;
16553 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16554 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16556 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
16557 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16559 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16560 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16562 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16563 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
16564 0, 1, &uav, NULL);
16566 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
16567 set_viewport(context, 0.0f, 0.0f, 10.0f, 10.0f, 0.0f, 0.0f);
16568 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
16569 draw_quad(&test_context);
16570 check_texture_color(texture, 100, 1);
16572 draw_quad(&test_context);
16573 draw_quad(&test_context);
16574 draw_quad(&test_context);
16575 draw_quad(&test_context);
16576 check_texture_color(texture, 500, 1);
16578 ID3D11PixelShader_Release(ps);
16579 ID3D11Texture2D_Release(texture);
16580 ID3D11UnorderedAccessView_Release(uav);
16581 release_test_context(&test_context);
16584 static void test_cb_relative_addressing(void)
16586 struct d3d11_test_context test_context;
16587 ID3D11Buffer *colors_cb, *index_cb;
16588 unsigned int i, index[4] = {0};
16589 ID3D11DeviceContext *context;
16590 ID3D11PixelShader *ps;
16591 ID3D11Device *device;
16592 HRESULT hr;
16594 static const DWORD vs_code[] =
16596 #if 0
16597 int color_index;
16599 cbuffer colors
16601 float4 colors[8];
16604 struct vs_in
16606 float4 position : POSITION;
16609 struct vs_out
16611 float4 position : SV_POSITION;
16612 float4 color : COLOR;
16615 vs_out main(const vs_in v)
16617 vs_out o;
16619 o.position = v.position;
16620 o.color = colors[color_index];
16622 return o;
16624 #endif
16625 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
16626 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16627 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
16628 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
16629 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
16630 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
16631 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
16632 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
16633 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
16634 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
16635 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
16636 0x0100003e,
16638 static const DWORD ps_code[] =
16640 #if 0
16641 struct ps_in
16643 float4 position : SV_POSITION;
16644 float4 color : COLOR;
16647 float4 main(const ps_in v) : SV_TARGET
16649 return v.color;
16651 #endif
16652 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
16653 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16654 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
16655 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
16656 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16657 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
16658 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16659 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
16661 static const struct
16663 float color[4];
16665 colors[10] =
16667 {{0.0f, 0.0f, 0.0f, 1.0f}},
16668 {{0.0f, 0.0f, 1.0f, 0.0f}},
16669 {{0.0f, 0.0f, 1.0f, 1.0f}},
16670 {{0.0f, 1.0f, 0.0f, 0.0f}},
16671 {{0.0f, 1.0f, 0.0f, 1.0f}},
16672 {{0.0f, 1.0f, 1.0f, 0.0f}},
16673 {{0.0f, 1.0f, 1.0f, 1.0f}},
16674 {{1.0f, 0.0f, 0.0f, 0.0f}},
16675 {{1.0f, 0.0f, 0.0f, 1.0f}},
16676 {{1.0f, 0.0f, 1.0f, 0.0f}},
16678 static const struct
16680 unsigned int index;
16681 DWORD expected;
16683 test_data[] =
16685 {0, 0xff000000},
16686 {1, 0x00ff0000},
16687 {2, 0xffff0000},
16688 {3, 0x0000ff00},
16689 {4, 0xff00ff00},
16690 {5, 0x00ffff00},
16691 {6, 0xffffff00},
16692 {7, 0x000000ff},
16694 {8, 0xff0000ff},
16695 {9, 0x00ff00ff},
16697 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
16698 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16700 if (!init_test_context(&test_context, &feature_level))
16701 return;
16703 device = test_context.device;
16704 context = test_context.immediate_context;
16706 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
16707 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
16709 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16710 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16712 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
16713 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
16714 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16716 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
16718 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
16720 index[0] = test_data[i].index;
16721 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
16723 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
16724 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
16727 ID3D11Buffer_Release(index_cb);
16728 ID3D11Buffer_Release(colors_cb);
16729 ID3D11PixelShader_Release(ps);
16731 release_test_context(&test_context);
16734 static void test_vs_input_relative_addressing(void)
16736 struct d3d11_test_context test_context;
16737 ID3D11DeviceContext *context;
16738 unsigned int offset, stride;
16739 unsigned int index[4] = {0};
16740 ID3D11PixelShader *ps;
16741 ID3D11Buffer *vb, *cb;
16742 ID3D11Device *device;
16743 unsigned int i;
16744 HRESULT hr;
16746 static const DWORD vs_code[] =
16748 #if 0
16749 struct vertex
16751 float4 position : POSITION;
16752 float4 colors[4] : COLOR;
16755 uint index;
16757 void main(vertex vin, out float4 position : SV_Position,
16758 out float4 color : COLOR)
16760 position = vin.position;
16761 color = vin.colors[index];
16763 #endif
16764 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
16765 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
16766 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
16767 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
16768 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
16769 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
16770 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
16771 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
16772 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
16773 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
16774 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
16775 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
16776 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
16777 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
16778 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
16779 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
16781 static const DWORD ps_code[] =
16783 #if 0
16784 struct vs_out
16786 float4 position : SV_POSITION;
16787 float4 color : COLOR;
16790 float4 main(struct vs_out i) : SV_TARGET
16792 return i.color;
16794 #endif
16795 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
16796 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16797 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
16798 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
16799 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16800 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
16801 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
16802 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
16804 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
16806 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
16807 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1},
16808 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D11_INPUT_PER_INSTANCE_DATA, 1},
16809 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D11_INPUT_PER_INSTANCE_DATA, 1},
16810 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D11_INPUT_PER_INSTANCE_DATA, 1},
16812 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
16813 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16815 if (!init_test_context(&test_context, NULL))
16816 return;
16817 device = test_context.device;
16818 context = test_context.immediate_context;
16820 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16821 vs_code, sizeof(vs_code), &test_context.input_layout);
16822 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
16824 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
16825 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
16827 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(colors), colors);
16828 stride = sizeof(colors);
16829 offset = 0;
16830 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
16832 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16833 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16834 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16836 for (i = 0; i < ARRAY_SIZE(colors); ++i)
16838 *index = i;
16839 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
16840 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16841 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
16842 check_texture_color(test_context.backbuffer, colors[i], 1);
16845 ID3D11Buffer_Release(cb);
16846 ID3D11Buffer_Release(vb);
16847 ID3D11PixelShader_Release(ps);
16848 release_test_context(&test_context);
16851 static void test_getdc(void)
16853 static const struct
16855 const char *name;
16856 DXGI_FORMAT format;
16857 BOOL getdc_supported;
16859 testdata[] =
16861 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
16862 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
16863 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
16864 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
16865 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
16866 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
16868 struct device_desc device_desc;
16869 D3D11_TEXTURE2D_DESC desc;
16870 ID3D11Texture2D *texture;
16871 IDXGISurface1 *surface;
16872 ID3D11Device *device;
16873 unsigned int i;
16874 ULONG refcount;
16875 HRESULT hr;
16876 HDC dc;
16878 device_desc.feature_level = NULL;
16879 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
16880 if (!(device = create_device(&device_desc)))
16882 skip("Failed to create device.\n");
16883 return;
16886 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
16887 desc.Width = 512;
16888 desc.Height = 512;
16889 desc.MipLevels = 1;
16890 desc.ArraySize = 1;
16891 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
16892 desc.SampleDesc.Count = 1;
16893 desc.SampleDesc.Quality = 0;
16894 desc.Usage = D3D11_USAGE_DEFAULT;
16895 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16896 desc.CPUAccessFlags = 0;
16897 desc.MiscFlags = 0;
16898 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16899 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16901 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
16902 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
16904 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
16905 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
16907 IDXGISurface1_Release(surface);
16908 ID3D11Texture2D_Release(texture);
16910 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
16911 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16912 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16914 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
16915 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
16917 hr = IDXGISurface1_ReleaseDC(surface, NULL);
16918 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
16920 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
16921 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
16923 hr = IDXGISurface1_ReleaseDC(surface, NULL);
16924 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
16926 IDXGISurface1_Release(surface);
16927 ID3D11Texture2D_Release(texture);
16929 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
16931 static const unsigned int bit_count = 32;
16932 unsigned int width_bytes;
16933 DIBSECTION dib;
16934 HBITMAP bitmap;
16935 DWORD type;
16936 int size;
16938 desc.Width = 64;
16939 desc.Height = 64;
16940 desc.MipLevels = 1;
16941 desc.ArraySize = 1;
16942 desc.Format = testdata[i].format;
16943 desc.SampleDesc.Count = 1;
16944 desc.SampleDesc.Quality = 0;
16945 desc.Usage = D3D11_USAGE_STAGING;
16946 desc.BindFlags = 0;
16947 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
16948 desc.MiscFlags = 0;
16950 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16951 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16952 ID3D11Texture2D_Release(texture);
16954 /* STAGING usage, requesting GDI compatibility mode. */
16955 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
16956 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16957 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
16959 desc.Usage = D3D11_USAGE_DEFAULT;
16960 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16961 desc.CPUAccessFlags = 0;
16962 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16963 if (testdata[i].getdc_supported)
16964 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
16965 else
16966 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
16968 if (FAILED(hr))
16969 continue;
16971 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
16972 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
16974 dc = (void *)0x1234;
16975 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
16976 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
16978 if (FAILED(hr))
16980 IDXGISurface1_Release(surface);
16981 ID3D11Texture2D_Release(texture);
16982 continue;
16985 type = GetObjectType(dc);
16986 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
16987 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
16988 type = GetObjectType(bitmap);
16989 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
16991 size = GetObjectA(bitmap, sizeof(dib), &dib);
16992 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
16993 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
16995 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
16996 dib.dsBm.bmType, testdata[i].name);
16997 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
16998 dib.dsBm.bmWidth, testdata[i].name);
16999 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
17000 dib.dsBm.bmHeight, testdata[i].name);
17001 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
17002 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
17003 dib.dsBm.bmWidthBytes, testdata[i].name);
17004 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
17005 dib.dsBm.bmPlanes, testdata[i].name);
17006 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
17007 dib.dsBm.bmBitsPixel, testdata[i].name);
17009 if (size == sizeof(dib))
17010 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
17011 dib.dsBm.bmBits, testdata[i].name);
17012 else
17013 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
17014 dib.dsBm.bmBits, testdata[i].name);
17016 if (size == sizeof(dib))
17018 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
17019 dib.dsBmih.biSize, testdata[i].name);
17020 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
17021 dib.dsBmih.biHeight, testdata[i].name);
17022 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
17023 dib.dsBmih.biHeight, testdata[i].name);
17024 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
17025 dib.dsBmih.biPlanes, testdata[i].name);
17026 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
17027 dib.dsBmih.biBitCount, testdata[i].name);
17028 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
17029 dib.dsBmih.biCompression, testdata[i].name);
17030 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
17031 dib.dsBmih.biSizeImage, testdata[i].name);
17032 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
17033 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
17034 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
17035 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
17036 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
17037 dib.dsBmih.biClrUsed, testdata[i].name);
17038 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
17039 dib.dsBmih.biClrImportant, testdata[i].name);
17040 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
17041 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
17042 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
17043 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
17044 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
17047 hr = IDXGISurface1_ReleaseDC(surface, NULL);
17048 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
17050 IDXGISurface1_Release(surface);
17051 ID3D11Texture2D_Release(texture);
17054 refcount = ID3D11Device_Release(device);
17055 ok(!refcount, "Device has %u references left.\n", refcount);
17058 static void test_shader_stage_input_output_matching(void)
17060 struct d3d11_test_context test_context;
17061 D3D11_TEXTURE2D_DESC texture_desc;
17062 ID3D11Texture2D *render_target;
17063 ID3D11RenderTargetView *rtv[2];
17064 ID3D11DeviceContext *context;
17065 ID3D11VertexShader *vs;
17066 ID3D11PixelShader *ps;
17067 ID3D11Device *device;
17068 HRESULT hr;
17070 static const DWORD vs_code[] =
17072 #if 0
17073 struct output
17075 float4 position : SV_PoSiTion;
17076 float4 color0 : COLOR0;
17077 float4 color1 : COLOR1;
17080 void main(uint id : SV_VertexID, out output o)
17082 float2 coords = float2((id << 1) & 2, id & 2);
17083 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
17084 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
17085 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
17087 #endif
17088 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
17089 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17090 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
17091 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
17092 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17093 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
17094 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
17095 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
17096 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
17097 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
17098 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
17099 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
17100 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
17101 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
17102 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
17103 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
17104 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
17105 0x0100003e,
17107 static const DWORD ps_code[] =
17109 #if 0
17110 struct input
17112 float4 position : SV_PoSiTiOn;
17113 float4 color1 : COLOR1;
17114 float4 color0 : COLOR0;
17117 struct output
17119 float4 target0 : SV_Target0;
17120 float4 target1 : SV_Target1;
17123 void main(const in input i, out output o)
17125 o.target0 = i.color0;
17126 o.target1 = i.color1;
17128 #endif
17129 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
17130 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
17131 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
17132 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
17133 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
17134 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
17135 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
17136 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
17137 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
17138 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
17139 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
17142 if (!init_test_context(&test_context, NULL))
17143 return;
17145 device = test_context.device;
17146 context = test_context.immediate_context;
17148 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17149 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17150 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17151 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17153 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17154 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
17155 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17157 rtv[0] = test_context.backbuffer_rtv;
17158 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
17159 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17161 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17162 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17163 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
17164 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
17165 ID3D11DeviceContext_Draw(context, 3, 0);
17167 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17168 check_texture_color(render_target, 0xff0000ff, 0);
17170 ID3D11RenderTargetView_Release(rtv[1]);
17171 ID3D11Texture2D_Release(render_target);
17172 ID3D11PixelShader_Release(ps);
17173 ID3D11VertexShader_Release(vs);
17174 release_test_context(&test_context);
17177 static void test_unbound_streams(void)
17179 struct d3d11_test_context test_context;
17180 ID3D11DeviceContext *context;
17181 ID3D11PixelShader *ps;
17182 ID3D11Device *device;
17183 HRESULT hr;
17185 static const DWORD vs_code[] =
17187 #if 0
17188 struct vs_ps
17190 float4 position : SV_POSITION;
17191 float4 color : COLOR0;
17194 vs_ps vs_main(float4 position : POSITION, float4 color : COLOR0)
17196 vs_ps result;
17197 result.position = position;
17198 result.color = color;
17199 result.color.w = 1.0;
17200 return result;
17202 #endif
17203 0x43425844, 0x4a9efaec, 0xe2c6cdf5, 0x15dd28a7, 0xae68e320, 0x00000001, 0x00000154, 0x00000003,
17204 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
17205 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
17206 0x00000003, 0x00000001, 0x0000070f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
17207 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
17208 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
17209 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x0000007c, 0x00010040, 0x0000001f,
17210 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101072, 0x00000001, 0x04000067, 0x001020f2,
17211 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
17212 0x00101e46, 0x00000000, 0x05000036, 0x00102072, 0x00000001, 0x00101246, 0x00000001, 0x05000036,
17213 0x00102082, 0x00000001, 0x00004001, 0x3f800000, 0x0100003e,
17216 static const DWORD ps_code[] =
17218 #if 0
17219 float4 ps_main(vs_ps input) : SV_TARGET
17221 return input.color;
17223 #endif
17224 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
17225 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17226 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17227 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
17228 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17229 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
17230 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
17231 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
17234 static const float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
17236 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17238 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17239 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
17242 if (!init_test_context(&test_context, NULL))
17243 return;
17245 device = test_context.device;
17246 context = test_context.immediate_context;
17248 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17249 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17251 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17252 vs_code, sizeof(vs_code), &test_context.input_layout);
17253 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17255 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17256 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17257 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
17258 check_texture_color(test_context.backbuffer, 0xff000000, 1);
17260 ID3D11PixelShader_Release(ps);
17261 release_test_context(&test_context);
17264 static void test_shader_interstage_interface(void)
17266 struct d3d11_test_context test_context;
17267 D3D11_TEXTURE2D_DESC texture_desc;
17268 ID3D11InputLayout *input_layout;
17269 ID3D11Texture2D *render_target;
17270 ID3D11DeviceContext *context;
17271 ID3D11RenderTargetView *rtv;
17272 ID3D11VertexShader *vs;
17273 ID3D11PixelShader *ps;
17274 ID3D11Device *device;
17275 UINT stride, offset;
17276 ID3D11Buffer *vb;
17277 unsigned int i;
17278 HRESULT hr;
17280 static const DWORD vs_code[] =
17282 #if 0
17283 struct vertex
17285 float4 position : SV_Position;
17286 float2 t0 : TEXCOORD0;
17287 nointerpolation float t1 : TEXCOORD1;
17288 uint t2 : TEXCOORD2;
17289 uint t3 : TEXCOORD3;
17290 float t4 : TEXCOORD4;
17293 void main(in vertex vin, out vertex vout)
17295 vout = vin;
17297 #endif
17298 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
17299 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
17300 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
17301 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
17302 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
17303 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
17304 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17305 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
17306 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
17307 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
17308 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
17309 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
17310 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
17311 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
17312 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
17313 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
17314 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
17315 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
17316 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
17317 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
17318 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
17319 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
17321 static const DWORD ps_code[] =
17323 #if 0
17324 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
17325 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
17326 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
17328 o.x = t0.y + t1;
17329 o.y = t2 + t3;
17330 o.z = t4;
17331 o.w = t0.x;
17333 #endif
17334 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
17335 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
17336 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
17337 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
17338 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
17339 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
17340 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17341 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
17342 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
17343 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
17344 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
17345 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
17346 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
17347 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
17348 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
17350 static const DWORD ps_partial_input_code[] =
17352 #if 0
17353 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
17354 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
17355 uint t3 : TEXCOORD3, out float4 o : SV_Target)
17357 o.x = t0.y + t1;
17358 o.y = t2 + t3;
17359 o.z = 0.0f;
17360 o.w = t0.x;
17362 #endif
17363 0x43425844, 0x5b1db356, 0xaa5a5e9d, 0xb916a081, 0x61e6dcb1, 0x00000001, 0x000001cc, 0x00000003,
17364 0x0000002c, 0x000000cc, 0x00000100, 0x4e475349, 0x00000098, 0x00000005, 0x00000008, 0x00000080,
17365 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
17366 0x00000003, 0x00000001, 0x00000303, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
17367 0x00000101, 0x0000008c, 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x0000008c,
17368 0x00000003, 0x00000000, 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
17369 0x43584554, 0x44524f4f, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17370 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
17371 0x52444853, 0x000000c4, 0x00000040, 0x00000031, 0x03001062, 0x00101032, 0x00000001, 0x03000862,
17372 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042, 0x00000002,
17373 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012, 0x00000000,
17374 0x0010102a, 0x00000002, 0x0010101a, 0x00000002, 0x05000056, 0x00102022, 0x00000000, 0x0010000a,
17375 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a, 0x00000002,
17376 0x05000036, 0x00102042, 0x00000000, 0x00004001, 0x00000000, 0x05000036, 0x00102082, 0x00000000,
17377 0x0010100a, 0x00000001, 0x0100003e,
17379 static const DWORD ps_single_input_code[] =
17381 #if 0
17382 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0, out float4 o : SV_Target)
17384 o.x = t0.x;
17385 o.y = t0.y;
17386 o.z = 1.0f;
17387 o.w = 2.0f;
17389 #endif
17390 0x43425844, 0x7cc601b6, 0xc65b8bdb, 0x54d0f606, 0x9cc74d3d, 0x00000001, 0x00000118, 0x00000003,
17391 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
17392 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17393 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17394 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
17395 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058,
17396 0x00000040, 0x00000016, 0x03001062, 0x00101032, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17397 0x05000036, 0x00102032, 0x00000000, 0x00101046, 0x00000001, 0x08000036, 0x001020c2, 0x00000000,
17398 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x40000000, 0x0100003e,
17400 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17402 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17403 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
17404 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
17405 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
17406 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
17407 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
17409 static const struct
17411 struct vec2 position;
17412 struct vec2 t0;
17413 float t1;
17414 unsigned int t2;
17415 unsigned int t3;
17416 float t4;
17418 quad[] =
17420 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17421 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17422 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17423 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17425 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17426 static const struct
17428 const DWORD *ps_code;
17429 size_t ps_size;
17430 struct vec4 expected_result;
17432 tests[] =
17434 {ps_code, sizeof(ps_code), {10.0f, 8.0f, 7.0f, 3.0f}},
17435 {ps_partial_input_code, sizeof(ps_partial_input_code), {10.0f, 8.0f, 0.0f, 3.0f}},
17436 {ps_single_input_code, sizeof(ps_single_input_code), {3.0f, 5.0f, 1.0f, 2.0f}},
17439 if (!init_test_context(&test_context, NULL))
17440 return;
17442 device = test_context.device;
17443 context = test_context.immediate_context;
17445 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17446 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17448 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17449 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17450 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
17451 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17453 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
17454 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17456 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17457 vs_code, sizeof(vs_code), &input_layout);
17458 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17460 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
17462 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
17464 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17465 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17466 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
17467 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
17468 offset = 0;
17469 stride = sizeof(*quad);
17470 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
17472 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17474 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_size, NULL, &ps);
17475 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
17476 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17477 ID3D11DeviceContext_Draw(context, 4, 0);
17478 check_texture_vec4(render_target, &tests[i].expected_result, 0);
17479 ID3D11PixelShader_Release(ps);
17482 ID3D11InputLayout_Release(input_layout);
17483 ID3D11RenderTargetView_Release(rtv);
17484 ID3D11Texture2D_Release(render_target);
17485 ID3D11VertexShader_Release(vs);
17486 ID3D11Buffer_Release(vb);
17487 release_test_context(&test_context);
17490 static void test_sm4_if_instruction(void)
17492 struct d3d11_test_context test_context;
17493 ID3D11PixelShader *ps_if_nz, *ps_if_z;
17494 ID3D11DeviceContext *context;
17495 ID3D11Device *device;
17496 unsigned int bits[4];
17497 DWORD expected_color;
17498 ID3D11Buffer *cb;
17499 unsigned int i;
17500 HRESULT hr;
17502 static const DWORD ps_if_nz_code[] =
17504 #if 0
17505 uint bits;
17507 float4 main() : SV_TARGET
17509 if (bits)
17510 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17511 else
17512 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17514 #endif
17515 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
17516 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17517 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17518 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
17519 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
17520 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17521 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17522 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17524 static const DWORD ps_if_z_code[] =
17526 #if 0
17527 uint bits;
17529 float4 main() : SV_TARGET
17531 if (!bits)
17532 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17533 else
17534 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17536 #endif
17537 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
17538 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17539 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17540 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
17541 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
17542 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17543 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17544 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17546 static unsigned int bit_patterns[] =
17548 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
17551 if (!init_test_context(&test_context, NULL))
17552 return;
17554 device = test_context.device;
17555 context = test_context.immediate_context;
17557 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
17558 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
17559 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
17560 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
17562 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
17563 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17565 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
17567 *bits = bit_patterns[i];
17568 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
17570 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
17571 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
17572 draw_quad(&test_context);
17573 check_texture_color(test_context.backbuffer, expected_color, 0);
17575 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
17576 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
17577 draw_quad(&test_context);
17578 check_texture_color(test_context.backbuffer, expected_color, 0);
17581 ID3D11Buffer_Release(cb);
17582 ID3D11PixelShader_Release(ps_if_z);
17583 ID3D11PixelShader_Release(ps_if_nz);
17584 release_test_context(&test_context);
17587 static void test_sm4_breakc_instruction(void)
17589 struct d3d11_test_context test_context;
17590 ID3D11DeviceContext *context;
17591 ID3D11PixelShader *ps;
17592 ID3D11Device *device;
17593 HRESULT hr;
17595 static const DWORD ps_breakc_nz_code[] =
17597 #if 0
17598 float4 main() : SV_TARGET
17600 uint counter = 0;
17602 for (uint i = 0; i < 255; ++i)
17603 ++counter;
17605 if (counter == 255)
17606 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17607 else
17608 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17610 #endif
17611 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
17612 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17613 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17614 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
17615 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
17616 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
17617 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
17618 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
17619 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
17620 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
17621 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
17622 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
17623 0x01000015, 0x0100003e,
17625 static const DWORD ps_breakc_z_code[] =
17627 #if 0
17628 float4 main() : SV_TARGET
17630 uint counter = 0;
17632 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
17633 ++counter;
17635 if (counter == 255)
17636 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17637 else
17638 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17640 #endif
17641 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
17642 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17643 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17644 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
17645 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
17646 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
17647 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
17648 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
17649 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
17650 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
17651 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
17652 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17653 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17654 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17657 if (!init_test_context(&test_context, NULL))
17658 return;
17660 device = test_context.device;
17661 context = test_context.immediate_context;
17663 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
17664 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
17665 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17666 draw_quad(&test_context);
17667 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17668 ID3D11PixelShader_Release(ps);
17670 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
17671 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
17672 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17673 draw_quad(&test_context);
17674 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17675 ID3D11PixelShader_Release(ps);
17677 release_test_context(&test_context);
17680 static void test_sm4_continuec_instruction(void)
17682 struct d3d11_test_context test_context;
17683 ID3D11DeviceContext *context;
17684 ID3D11PixelShader *ps;
17685 ID3D11Device *device;
17686 HRESULT hr;
17688 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
17689 * with a normal continue inside, the shaders have been compiled with
17690 * the /Gfa flag. */
17691 static const DWORD ps_continuec_nz_code[] =
17693 #if 0
17694 float4 main() : SV_TARGET
17696 uint counter = 0;
17697 int i = -1;
17699 while (i < 255) {
17700 ++i;
17702 if (i != 0)
17703 continue;
17705 ++counter;
17708 if (counter == 1)
17709 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17710 else
17711 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17713 #endif
17714 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
17715 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17716 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17717 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
17718 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
17719 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
17720 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
17721 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
17722 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
17723 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
17724 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
17725 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
17726 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
17727 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
17728 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
17729 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
17730 0x3f800000, 0x0100003e,
17733 static const DWORD ps_continuec_z_code[] =
17735 #if 0
17736 float4 main() : SV_TARGET
17738 uint counter = 0;
17739 int i = -1;
17741 while (i < 255) {
17742 ++i;
17744 if (i == 0)
17745 continue;
17747 ++counter;
17750 if (counter == 255)
17751 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17752 else
17753 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17755 #endif
17756 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
17757 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17758 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17759 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
17760 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
17761 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
17762 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
17763 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
17764 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
17765 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
17766 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
17767 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
17768 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
17769 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
17770 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
17773 if (!init_test_context(&test_context, NULL))
17774 return;
17776 device = test_context.device;
17777 context = test_context.immediate_context;
17779 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
17780 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
17781 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17782 draw_quad(&test_context);
17783 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17784 ID3D11PixelShader_Release(ps);
17786 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
17787 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
17788 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17789 draw_quad(&test_context);
17790 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17791 ID3D11PixelShader_Release(ps);
17793 release_test_context(&test_context);
17796 static void test_sm4_discard_instruction(void)
17798 ID3D11PixelShader *ps_discard_nz, *ps_discard_z;
17799 struct d3d11_test_context test_context;
17800 ID3D11DeviceContext *context;
17801 ID3D11Device *device;
17802 ID3D11Buffer *cb;
17803 unsigned int i;
17804 HRESULT hr;
17806 static const DWORD ps_discard_nz_code[] =
17808 #if 0
17809 uint data;
17811 float4 main() : SV_Target
17813 if (data)
17814 discard;
17815 return float4(0.0f, 0.5f, 0.0f, 1.0f);
17817 #endif
17818 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
17819 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17820 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17821 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
17822 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
17823 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17824 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
17826 static const DWORD ps_discard_z_code[] =
17828 #if 0
17829 uint data;
17831 float4 main() : SV_Target
17833 if (!data)
17834 discard;
17835 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17837 #endif
17838 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
17839 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17840 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17841 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
17842 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
17843 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17844 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
17846 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17847 static const struct uvec4 values[] =
17849 {0x0000000},
17850 {0x0000001},
17851 {0x8000000},
17852 {0xfffffff},
17855 if (!init_test_context(&test_context, NULL))
17856 return;
17858 device = test_context.device;
17859 context = test_context.immediate_context;
17861 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
17862 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17864 hr = ID3D11Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code),
17865 NULL, &ps_discard_nz);
17866 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
17867 hr = ID3D11Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code),
17868 NULL, &ps_discard_z);
17869 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
17871 for (i = 0; i < ARRAY_SIZE(values); ++i)
17873 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &values[i], 0, 0);
17875 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17876 ID3D11DeviceContext_PSSetShader(context, ps_discard_nz, NULL, 0);
17877 draw_quad(&test_context);
17878 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
17880 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17881 ID3D11DeviceContext_PSSetShader(context, ps_discard_z, NULL, 0);
17882 draw_quad(&test_context);
17883 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
17886 ID3D11Buffer_Release(cb);
17887 ID3D11PixelShader_Release(ps_discard_nz);
17888 ID3D11PixelShader_Release(ps_discard_z);
17889 release_test_context(&test_context);
17892 static void test_sm5_swapc_instruction(void)
17894 struct input
17896 struct uvec4 src0;
17897 struct uvec4 src1;
17898 struct uvec4 src2;
17901 struct d3d11_test_context test_context;
17902 D3D11_TEXTURE2D_DESC texture_desc;
17903 ID3D11DeviceContext *context;
17904 ID3D11RenderTargetView *rtv;
17905 ID3D11Texture2D *texture;
17906 ID3D11PixelShader *ps[6];
17907 ID3D11Device *device;
17908 ID3D11Buffer *cb;
17909 unsigned int i;
17910 HRESULT hr;
17912 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17913 static const DWORD ps_swapc0_code[] =
17915 #if 0
17916 ps_5_0
17917 dcl_globalFlags refactoringAllowed
17918 dcl_constantbuffer cb0[3], immediateIndexed
17919 dcl_output o0.xyzw
17920 dcl_temps 2
17921 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
17922 mov o0.xyzw, r0.xyzw
17924 #endif
17925 0x43425844, 0x9e089246, 0x9f8b5cbe, 0xbac66faf, 0xaef23488, 0x00000001, 0x000000f8, 0x00000003,
17926 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17927 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17928 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
17929 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
17930 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
17931 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
17932 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
17934 static const DWORD ps_swapc1_code[] =
17936 #if 0
17937 ps_5_0
17938 dcl_globalFlags refactoringAllowed
17939 dcl_constantbuffer cb0[3], immediateIndexed
17940 dcl_output o0.xyzw
17941 dcl_temps 2
17942 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
17943 mov o0.xyzw, r1.xyzw
17945 #endif
17946 0x43425844, 0xf2daed61, 0xede211f7, 0x7300dbea, 0x573ed49f, 0x00000001, 0x000000f8, 0x00000003,
17947 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17948 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17949 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
17950 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
17951 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
17952 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
17953 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
17955 static const DWORD ps_swapc2_code[] =
17957 #if 0
17958 ps_5_0
17959 dcl_globalFlags refactoringAllowed
17960 dcl_constantbuffer cb0[3], immediateIndexed
17961 dcl_output o0.xyzw
17962 dcl_temps 2
17963 mov r0.xyzw, cb0[1].xyzw
17964 mov r1.xyzw, cb0[2].xyzw
17965 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
17966 mov o0.xyzw, r0.xyzw
17968 #endif
17969 0x43425844, 0x230fcb22, 0x70d99148, 0x65814d89, 0x97473498, 0x00000001, 0x00000120, 0x00000003,
17970 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17971 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17972 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
17973 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
17974 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
17975 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
17976 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
17977 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
17979 static const DWORD ps_swapc3_code[] =
17981 #if 0
17982 ps_5_0
17983 dcl_globalFlags refactoringAllowed
17984 dcl_constantbuffer cb0[3], immediateIndexed
17985 dcl_output o0.xyzw
17986 dcl_temps 2
17987 mov r0.xyzw, cb0[1].xyzw
17988 mov r1.xyzw, cb0[2].xyzw
17989 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
17990 mov o0.xyzw, r1.xyzw
17992 #endif
17993 0x43425844, 0xce595d62, 0x98305541, 0xb04e74c8, 0xfc010f3a, 0x00000001, 0x00000120, 0x00000003,
17994 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17995 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17996 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
17997 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
17998 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
17999 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
18000 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
18001 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
18003 static const DWORD ps_swapc4_code[] =
18005 #if 0
18006 ps_5_0
18007 dcl_globalFlags refactoringAllowed
18008 dcl_constantbuffer cb0[3], immediateIndexed
18009 dcl_output o0.xyzw
18010 dcl_temps 2
18011 mov r0.xyzw, cb0[0].xyzw
18012 swapc r0.xyzw, r1.xyzw, r0.xyzw, cb0[1].xyzw, cb0[2].xyzw
18013 mov o0.xyzw, r0.xyzw
18015 #endif
18016 0x43425844, 0x72067c48, 0xb53572a0, 0x9dd9e0fd, 0x903e37e3, 0x00000001, 0x0000010c, 0x00000003,
18017 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18018 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18019 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
18020 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18021 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
18022 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000000, 0x00208e46,
18023 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
18024 0x00100e46, 0x00000000, 0x0100003e,
18026 static const DWORD ps_swapc5_code[] =
18028 #if 0
18029 ps_5_0
18030 dcl_globalFlags refactoringAllowed
18031 dcl_constantbuffer cb0[3], immediateIndexed
18032 dcl_output o0.xyzw
18033 dcl_temps 2
18034 mov r1.xyzw, cb0[0].xyzw
18035 swapc r0.xyzw, r1.xyzw, r1.xyzw, cb0[1].xyzw, cb0[2].xyzw
18036 mov o0.xyzw, r1.xyzw
18038 #endif
18039 0x43425844, 0x7078fb08, 0xdd24cd44, 0x469d3258, 0x9e33a0bc, 0x00000001, 0x0000010c, 0x00000003,
18040 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18041 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18042 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
18043 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18044 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000,
18045 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001, 0x00208e46,
18046 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
18047 0x00100e46, 0x00000001, 0x0100003e,
18049 static const struct
18051 struct input input;
18052 struct uvec4 dst0;
18053 struct uvec4 dst1;
18055 tests[] =
18058 {{0, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18059 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}
18062 {{1, 1, 1, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18063 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
18066 {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
18067 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18068 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
18071 {{1, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18072 {0xaaaa, 0xc0de, 0xcccc, 0xeeee}, {0xdead, 0xbbbb, 0xffff, 0xdddd},
18075 {{1, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18076 {0xaaaa, 0xc0de, 0xffff, 0xdddd}, {0xdead, 0xbbbb, 0xcccc, 0xeeee},
18079 {{1, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18080 {0xaaaa, 0xc0de, 0xffff, 0xeeee}, {0xdead, 0xbbbb, 0xcccc, 0xdddd}
18083 {{0, 1, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18084 {0xdead, 0xbbbb, 0xffff, 0xeeee}, {0xaaaa, 0xc0de, 0xcccc, 0xdddd}
18087 {{0, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18088 {0xdead, 0xc0de, 0xcccc, 0xeeee}, {0xaaaa, 0xbbbb, 0xffff, 0xdddd}
18091 {{0, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18092 {0xdead, 0xc0de, 0xffff, 0xdddd}, {0xaaaa, 0xbbbb, 0xcccc, 0xeeee},
18096 if (!init_test_context(&test_context, &feature_level))
18097 return;
18099 device = test_context.device;
18100 context = test_context.immediate_context;
18102 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18103 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
18104 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18105 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18107 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18108 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
18110 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18112 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct input), NULL);
18113 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18115 hr = ID3D11Device_CreatePixelShader(device, ps_swapc0_code, sizeof(ps_swapc0_code), NULL, &ps[0]);
18116 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18117 hr = ID3D11Device_CreatePixelShader(device, ps_swapc1_code, sizeof(ps_swapc1_code), NULL, &ps[1]);
18118 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18119 hr = ID3D11Device_CreatePixelShader(device, ps_swapc2_code, sizeof(ps_swapc2_code), NULL, &ps[2]);
18120 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18121 hr = ID3D11Device_CreatePixelShader(device, ps_swapc3_code, sizeof(ps_swapc3_code), NULL, &ps[3]);
18122 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18123 hr = ID3D11Device_CreatePixelShader(device, ps_swapc4_code, sizeof(ps_swapc4_code), NULL, &ps[4]);
18124 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18125 hr = ID3D11Device_CreatePixelShader(device, ps_swapc5_code, sizeof(ps_swapc5_code), NULL, &ps[5]);
18126 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18128 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18130 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &tests[i].input, 0, 0);
18132 ID3D11DeviceContext_PSSetShader(context, ps[0], NULL, 0);
18133 draw_quad(&test_context);
18134 check_texture_uvec4(texture, &tests[i].dst0);
18136 ID3D11DeviceContext_PSSetShader(context, ps[1], NULL, 0);
18137 draw_quad(&test_context);
18138 check_texture_uvec4(texture, &tests[i].dst1);
18140 ID3D11DeviceContext_PSSetShader(context, ps[2], NULL, 0);
18141 draw_quad(&test_context);
18142 check_texture_uvec4(texture, &tests[i].dst0);
18144 ID3D11DeviceContext_PSSetShader(context, ps[3], NULL, 0);
18145 draw_quad(&test_context);
18146 check_texture_uvec4(texture, &tests[i].dst1);
18148 ID3D11DeviceContext_PSSetShader(context, ps[4], NULL, 0);
18149 draw_quad(&test_context);
18150 check_texture_uvec4(texture, &tests[i].dst0);
18152 ID3D11DeviceContext_PSSetShader(context, ps[5], NULL, 0);
18153 draw_quad(&test_context);
18154 check_texture_uvec4(texture, &tests[i].dst1);
18157 for (i = 0; i < ARRAY_SIZE(ps); ++i)
18158 ID3D11PixelShader_Release(ps[i]);
18159 ID3D11RenderTargetView_Release(rtv);
18160 ID3D11Texture2D_Release(texture);
18161 ID3D11Buffer_Release(cb);
18162 release_test_context(&test_context);
18165 static void test_create_input_layout(void)
18167 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
18169 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18171 ULONG refcount, expected_refcount;
18172 ID3D11InputLayout *input_layout;
18173 ID3D11Device *device;
18174 unsigned int i;
18175 HRESULT hr;
18177 static const DWORD vs_code[] =
18179 #if 0
18180 float4 main(float4 position : POSITION) : SV_POSITION
18182 return position;
18184 #endif
18185 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
18186 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18187 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
18188 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
18189 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
18190 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18191 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
18193 static const DXGI_FORMAT vertex_formats[] =
18195 DXGI_FORMAT_R32G32_FLOAT,
18196 DXGI_FORMAT_R32G32_UINT,
18197 DXGI_FORMAT_R32G32_SINT,
18198 DXGI_FORMAT_R16G16_FLOAT,
18199 DXGI_FORMAT_R16G16_UINT,
18200 DXGI_FORMAT_R16G16_SINT,
18201 DXGI_FORMAT_R32_FLOAT,
18202 DXGI_FORMAT_R32_UINT,
18203 DXGI_FORMAT_R32_SINT,
18204 DXGI_FORMAT_R16_UINT,
18205 DXGI_FORMAT_R16_SINT,
18206 DXGI_FORMAT_R8G8_UNORM,
18207 DXGI_FORMAT_R8_UINT,
18208 DXGI_FORMAT_R8_SINT,
18211 if (!(device = create_device(NULL)))
18213 skip("Failed to create device.\n");
18214 return;
18217 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
18219 expected_refcount = get_refcount(device) + 1;
18220 layout_desc->Format = vertex_formats[i];
18221 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
18222 vs_code, sizeof(vs_code), &input_layout);
18223 ok(hr == S_OK, "Failed to create input layout for format %#x, hr %#x.\n",
18224 vertex_formats[i], hr);
18225 refcount = get_refcount(device);
18226 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
18227 refcount, expected_refcount);
18228 ID3D11InputLayout_Release(input_layout);
18231 refcount = ID3D11Device_Release(device);
18232 ok(!refcount, "Device has %u references left.\n", refcount);
18235 static void test_input_layout_alignment(void)
18237 ID3D11InputLayout *layout;
18238 ID3D11Device *device;
18239 unsigned int i;
18240 ULONG refcount;
18241 HRESULT hr;
18243 static const DWORD vs_code[] =
18245 #if 0
18246 float4 main(float4 position : POSITION) : SV_POSITION
18248 return position;
18250 #endif
18251 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
18252 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18253 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
18254 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
18255 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
18256 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18257 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
18260 static const struct
18262 D3D11_INPUT_ELEMENT_DESC elements[2];
18263 HRESULT hr;
18265 test_data[] =
18268 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18269 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18270 }, S_OK},
18272 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18273 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 1, D3D11_INPUT_PER_VERTEX_DATA, 0},
18274 }, E_INVALIDARG},
18276 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18277 {"COLOR", 0, DXGI_FORMAT_R8_UINT, 0, 1, D3D11_INPUT_PER_VERTEX_DATA, 0},
18278 }, S_OK},
18280 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18281 {"COLOR", 0, DXGI_FORMAT_R32_UINT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18282 }, E_INVALIDARG},
18284 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18285 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18286 }, E_INVALIDARG},
18288 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18289 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
18290 }, S_OK},
18292 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18293 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 17, D3D11_INPUT_PER_VERTEX_DATA, 0},
18294 }, E_INVALIDARG},
18296 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18297 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 18, D3D11_INPUT_PER_VERTEX_DATA, 0},
18298 }, E_INVALIDARG},
18300 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18301 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 19, D3D11_INPUT_PER_VERTEX_DATA, 0},
18302 }, E_INVALIDARG},
18304 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18305 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
18306 }, S_OK},
18309 if (!(device = create_device(NULL)))
18311 skip("Failed to create device.\n");
18312 return;
18315 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
18317 hr = ID3D11Device_CreateInputLayout(device, test_data[i].elements, 2, vs_code, sizeof(vs_code), &layout);
18318 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
18319 if (SUCCEEDED(hr))
18320 ID3D11InputLayout_Release(layout);
18323 refcount = ID3D11Device_Release(device);
18324 ok(!refcount, "Device has %u references left.\n", refcount);
18327 static void test_input_assembler(void)
18329 enum layout_id
18331 LAYOUT_FLOAT32,
18332 LAYOUT_UINT16,
18333 LAYOUT_SINT16,
18334 LAYOUT_UNORM16,
18335 LAYOUT_SNORM16,
18336 LAYOUT_UINT8,
18337 LAYOUT_SINT8,
18338 LAYOUT_UNORM8,
18339 LAYOUT_SNORM8,
18340 LAYOUT_UNORM10_2,
18341 LAYOUT_UINT10_2,
18343 LAYOUT_COUNT,
18346 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
18348 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18349 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18351 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
18352 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
18353 ID3D11Buffer *vb_position, *vb_attribute;
18354 struct d3d11_test_context test_context;
18355 D3D11_TEXTURE2D_DESC texture_desc;
18356 unsigned int i, j, stride, offset;
18357 ID3D11Texture2D *render_target;
18358 ID3D11DeviceContext *context;
18359 ID3D11RenderTargetView *rtv;
18360 ID3D11PixelShader *ps;
18361 ID3D11Device *device;
18362 HRESULT hr;
18364 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
18366 DXGI_FORMAT_R32G32B32A32_FLOAT,
18367 DXGI_FORMAT_R16G16B16A16_UINT,
18368 DXGI_FORMAT_R16G16B16A16_SINT,
18369 DXGI_FORMAT_R16G16B16A16_UNORM,
18370 DXGI_FORMAT_R16G16B16A16_SNORM,
18371 DXGI_FORMAT_R8G8B8A8_UINT,
18372 DXGI_FORMAT_R8G8B8A8_SINT,
18373 DXGI_FORMAT_R8G8B8A8_UNORM,
18374 DXGI_FORMAT_R8G8B8A8_SNORM,
18375 DXGI_FORMAT_R10G10B10A2_UNORM,
18376 DXGI_FORMAT_R10G10B10A2_UINT,
18378 static const struct vec2 quad[] =
18380 {-1.0f, -1.0f},
18381 {-1.0f, 1.0f},
18382 { 1.0f, -1.0f},
18383 { 1.0f, 1.0f},
18385 static const DWORD ps_code[] =
18387 #if 0
18388 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
18390 return color;
18392 #endif
18393 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
18394 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
18395 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
18396 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
18397 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18398 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
18399 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
18400 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
18402 static const DWORD vs_float_code[] =
18404 #if 0
18405 struct output
18407 float4 position : SV_Position;
18408 float4 color : COLOR;
18411 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
18413 o.position = position;
18414 o.color = color;
18416 #endif
18417 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
18418 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18419 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18420 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18421 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18422 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18423 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18424 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18425 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18426 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18427 0x0100003e,
18429 static const DWORD vs_uint_code[] =
18431 #if 0
18432 struct output
18434 float4 position : SV_Position;
18435 float4 color : COLOR;
18438 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
18440 o.position = position;
18441 o.color = color;
18443 #endif
18444 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
18445 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18446 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18447 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18448 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18449 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18450 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18451 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18452 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18453 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18454 0x0100003e,
18456 static const DWORD vs_sint_code[] =
18458 #if 0
18459 struct output
18461 float4 position : SV_Position;
18462 float4 color : COLOR;
18465 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
18467 o.position = position;
18468 o.color = color;
18470 #endif
18471 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
18472 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18473 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18474 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18475 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18476 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18477 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18478 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18479 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18480 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18481 0x0100003e,
18483 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
18484 static const unsigned short uint16_data[] = {6, 8, 55, 777};
18485 static const short sint16_data[] = {-1, 33, 8, -77};
18486 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
18487 static const short snorm16_data[] = {-32768, 0, 32767, 0};
18488 static const unsigned char uint8_data[] = {0, 64, 128, 255};
18489 static const signed char sint8_data[] = {-128, 0, 127, 64};
18490 static const unsigned int uint32_zero = 0;
18491 static const unsigned int uint32_max = 0xffffffff;
18492 static const unsigned int unorm10_2_data= 0xa00003ff;
18493 static const unsigned int g10_data = 0x000ffc00;
18494 static const unsigned int a2_data = 0xc0000000;
18495 static const struct
18497 enum layout_id layout_id;
18498 unsigned int stride;
18499 const void *data;
18500 struct vec4 expected_color;
18501 BOOL todo;
18503 tests[] =
18505 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
18506 {1.0f, 2.0f, 3.0f, 4.0f}},
18507 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
18508 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
18509 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
18510 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
18511 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
18512 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
18513 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
18514 {-1.0f, 0.0f, 1.0f, 0.0f}},
18515 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
18516 {0.0f, 0.0f, 0.0f, 0.0f}},
18517 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
18518 {255.0f, 255.0f, 255.0f, 255.0f}},
18519 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
18520 {0.0f, 64.0f, 128.0f, 255.0f}},
18521 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
18522 {0.0f, 0.0f, 0.0f, 0.0f}},
18523 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
18524 {-1.0f, -1.0f, -1.0f, -1.0f}},
18525 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
18526 {-128.0f, 0.0f, 127.0f, 64.0f}},
18527 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
18528 {0.0f, 0.0f, 0.0f, 0.0f}},
18529 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
18530 {1.0f, 1.0f, 1.0f, 1.0f}},
18531 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
18532 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
18533 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
18534 {0.0f, 0.0f, 0.0f, 0.0f}},
18535 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
18536 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
18537 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
18538 {0.0f, 0.0f, 0.0f, 0.0f}},
18539 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
18540 {1.0f, 1.0f, 1.0f, 1.0f}},
18541 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
18542 {0.0f, 1.0f, 0.0f, 0.0f}},
18543 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
18544 {0.0f, 0.0f, 0.0f, 1.0f}},
18545 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
18546 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
18547 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
18548 {0.0f, 0.0f, 0.0f, 0.0f}},
18549 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
18550 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
18551 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
18552 {0.0f, 1023.0f, 0.0f, 0.0f}},
18553 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
18554 {0.0f, 0.0f, 0.0f, 3.0f}},
18555 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
18556 {1023.0f, 0.0f, 512.0f, 2.0f}},
18559 if (!init_test_context(&test_context, NULL))
18560 return;
18562 device = test_context.device;
18563 context = test_context.immediate_context;
18565 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18566 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18568 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
18569 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
18570 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
18571 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
18572 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
18573 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
18575 for (i = 0; i < LAYOUT_COUNT; ++i)
18577 input_layout_desc[1].Format = layout_formats[i];
18578 input_layout[i] = NULL;
18579 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
18580 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
18581 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
18582 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
18585 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
18586 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
18588 texture_desc.Width = 640;
18589 texture_desc.Height = 480;
18590 texture_desc.MipLevels = 1;
18591 texture_desc.ArraySize = 1;
18592 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
18593 texture_desc.SampleDesc.Count = 1;
18594 texture_desc.SampleDesc.Quality = 0;
18595 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18596 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
18597 texture_desc.CPUAccessFlags = 0;
18598 texture_desc.MiscFlags = 0;
18600 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
18601 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
18603 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
18604 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18606 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
18607 offset = 0;
18608 stride = sizeof(*quad);
18609 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
18610 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18611 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18613 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18615 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
18617 if (tests[i].layout_id == LAYOUT_UINT10_2)
18618 continue;
18620 assert(tests[i].layout_id < LAYOUT_COUNT);
18621 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
18623 assert(4 * tests[i].stride <= 1024);
18624 box.right = tests[i].stride;
18625 for (j = 0; j < 4; ++j)
18627 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
18628 &box, tests[i].data, 0, 0);
18629 box.left += tests[i].stride;
18630 box.right += tests[i].stride;
18633 stride = tests[i].stride;
18634 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
18636 switch (layout_formats[tests[i].layout_id])
18638 case DXGI_FORMAT_R16G16B16A16_UINT:
18639 case DXGI_FORMAT_R10G10B10A2_UINT:
18640 case DXGI_FORMAT_R8G8B8A8_UINT:
18641 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
18642 break;
18643 case DXGI_FORMAT_R16G16B16A16_SINT:
18644 case DXGI_FORMAT_R8G8B8A8_SINT:
18645 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
18646 break;
18648 default:
18649 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
18650 /* Fall through. */
18651 case DXGI_FORMAT_R32G32B32A32_FLOAT:
18652 case DXGI_FORMAT_R16G16B16A16_UNORM:
18653 case DXGI_FORMAT_R16G16B16A16_SNORM:
18654 case DXGI_FORMAT_R10G10B10A2_UNORM:
18655 case DXGI_FORMAT_R8G8B8A8_UNORM:
18656 case DXGI_FORMAT_R8G8B8A8_SNORM:
18657 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
18658 break;
18661 ID3D11DeviceContext_Draw(context, 4, 0);
18662 check_texture_vec4(render_target, &tests[i].expected_color, 2);
18665 ID3D11Texture2D_Release(render_target);
18666 ID3D11RenderTargetView_Release(rtv);
18667 ID3D11Buffer_Release(vb_attribute);
18668 ID3D11Buffer_Release(vb_position);
18669 for (i = 0; i < LAYOUT_COUNT; ++i)
18671 if (input_layout[i])
18672 ID3D11InputLayout_Release(input_layout[i]);
18674 ID3D11PixelShader_Release(ps);
18675 ID3D11VertexShader_Release(vs_float);
18676 ID3D11VertexShader_Release(vs_uint);
18677 ID3D11VertexShader_Release(vs_sint);
18678 release_test_context(&test_context);
18681 static void test_null_sampler(void)
18683 struct d3d11_test_context test_context;
18684 D3D11_TEXTURE2D_DESC texture_desc;
18685 ID3D11ShaderResourceView *srv;
18686 ID3D11DeviceContext *context;
18687 ID3D11RenderTargetView *rtv;
18688 ID3D11SamplerState *sampler;
18689 ID3D11Texture2D *texture;
18690 ID3D11PixelShader *ps;
18691 ID3D11Device *device;
18692 HRESULT hr;
18694 static const DWORD ps_code[] =
18696 #if 0
18697 Texture2D t;
18698 SamplerState s;
18700 float4 main(float4 position : SV_POSITION) : SV_Target
18702 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
18704 #endif
18705 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
18706 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18707 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
18708 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18709 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
18710 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
18711 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
18712 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
18713 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
18714 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
18716 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
18718 if (!init_test_context(&test_context, NULL))
18719 return;
18721 device = test_context.device;
18722 context = test_context.immediate_context;
18724 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18725 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18727 texture_desc.Width = 64;
18728 texture_desc.Height = 64;
18729 texture_desc.MipLevels = 1;
18730 texture_desc.ArraySize = 1;
18731 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
18732 texture_desc.SampleDesc.Count = 1;
18733 texture_desc.SampleDesc.Quality = 0;
18734 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18735 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
18736 texture_desc.CPUAccessFlags = 0;
18737 texture_desc.MiscFlags = 0;
18739 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18740 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18742 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18743 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
18745 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
18746 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
18748 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
18750 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18751 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18752 sampler = NULL;
18753 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
18754 draw_quad(&test_context);
18755 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
18757 ID3D11ShaderResourceView_Release(srv);
18758 ID3D11RenderTargetView_Release(rtv);
18759 ID3D11Texture2D_Release(texture);
18760 ID3D11PixelShader_Release(ps);
18761 release_test_context(&test_context);
18764 static void test_check_feature_support(void)
18766 D3D11_FEATURE_DATA_THREADING threading[2];
18767 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
18768 D3D11_FEATURE_DATA_ARCHITECTURE_INFO archinfo;
18769 ID3D11Device *device;
18770 ULONG refcount;
18771 HRESULT hr;
18773 if (!(device = create_device(NULL)))
18775 skip("Failed to create device.\n");
18776 return;
18779 memset(threading, 0xef, sizeof(threading));
18781 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
18782 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18783 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
18784 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18785 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
18786 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18787 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
18788 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18789 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
18790 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18791 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
18792 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18794 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
18795 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
18796 ok(threading[0].DriverCommandLists == 0xefefefef,
18797 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
18798 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
18799 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
18800 ok(threading[1].DriverCommandLists == 0xefefefef,
18801 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
18803 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
18804 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18805 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
18806 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
18807 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
18808 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
18810 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
18811 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18812 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
18813 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18814 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
18815 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18816 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
18817 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18818 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
18819 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18820 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
18821 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18823 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
18824 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18825 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
18827 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo));
18828 ok(hr == S_OK || broken(hr == E_INVALIDARG) /* Not available on all Windows versions. */,
18829 "Got unexpected hr %#x.\n", hr);
18830 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo)*2);
18831 ok(hr == E_INVALIDARG /* Not available on all Windows versions but they will return E_INVALIDARG anyways. */,
18832 "Got unexpected hr %#x.\n", hr);
18834 refcount = ID3D11Device_Release(device);
18835 ok(!refcount, "Device has %u references left.\n", refcount);
18838 static void test_create_unordered_access_view(void)
18840 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18841 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18842 D3D11_TEXTURE3D_DESC texture3d_desc;
18843 D3D11_TEXTURE2D_DESC texture2d_desc;
18844 ULONG refcount, expected_refcount;
18845 D3D11_SUBRESOURCE_DATA data = {0};
18846 ID3D11UnorderedAccessView *uav;
18847 struct device_desc device_desc;
18848 D3D11_BUFFER_DESC buffer_desc;
18849 ID3D11Device *device, *tmp;
18850 ID3D11Texture3D *texture3d;
18851 ID3D11Texture2D *texture2d;
18852 ID3D11Resource *texture;
18853 ID3D11Buffer *buffer;
18854 unsigned int i;
18855 HRESULT hr;
18857 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
18858 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
18859 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
18860 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
18861 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
18862 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
18863 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
18864 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
18865 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
18866 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
18867 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
18868 static const struct
18870 struct
18872 unsigned int miplevel_count;
18873 unsigned int depth_or_array_size;
18874 DXGI_FORMAT format;
18875 } texture;
18876 struct uav_desc uav_desc;
18877 struct uav_desc expected_uav_desc;
18879 tests[] =
18881 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
18882 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
18883 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
18884 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
18885 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
18886 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
18887 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
18888 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
18889 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
18890 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
18891 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
18892 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
18893 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
18894 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
18895 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
18896 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
18897 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
18898 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
18899 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
18900 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
18901 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
18902 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
18903 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
18904 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
18905 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
18906 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
18907 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
18908 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
18909 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
18910 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
18911 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
18912 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
18913 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
18914 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
18915 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
18916 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
18918 static const struct
18920 struct
18922 D3D11_UAV_DIMENSION dimension;
18923 unsigned int miplevel_count;
18924 unsigned int depth_or_array_size;
18925 DXGI_FORMAT format;
18926 } texture;
18927 struct uav_desc uav_desc;
18929 invalid_desc_tests[] =
18931 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
18932 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
18933 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
18934 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
18935 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
18936 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
18937 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
18938 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
18939 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
18940 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
18941 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
18942 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
18943 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
18944 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
18945 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
18946 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
18947 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
18948 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
18949 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
18950 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
18951 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
18952 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
18953 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
18954 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
18955 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
18956 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
18957 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
18958 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
18959 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
18960 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
18961 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
18962 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
18963 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
18964 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
18965 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
18966 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
18967 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
18969 #undef FMT_UNKNOWN
18970 #undef RGBA8_UNORM
18971 #undef RGBA8_SRGB
18972 #undef RGBA8_UINT
18973 #undef RGBA8_TL
18974 #undef DIM_UNKNOWN
18975 #undef TEX_1D
18976 #undef TEX_1D_ARRAY
18977 #undef TEX_2D
18978 #undef TEX_2D_ARRAY
18979 #undef TEX_3D
18981 device_desc.feature_level = &feature_level;
18982 device_desc.flags = 0;
18983 if (!(device = create_device(&device_desc)))
18985 skip("Failed to create device.\n");
18986 return;
18989 buffer_desc.ByteWidth = 1024;
18990 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18991 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
18992 buffer_desc.CPUAccessFlags = 0;
18993 buffer_desc.MiscFlags = 0;
18994 buffer_desc.StructureByteStride = 0;
18996 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
18997 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18999 expected_refcount = get_refcount(device) + 1;
19000 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19001 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19002 refcount = get_refcount(device);
19003 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
19004 tmp = NULL;
19005 expected_refcount = refcount + 1;
19006 ID3D11Buffer_GetDevice(buffer, &tmp);
19007 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
19008 refcount = get_refcount(device);
19009 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
19010 ID3D11Device_Release(tmp);
19012 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19013 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19014 U(uav_desc).Buffer.FirstElement = 0;
19015 U(uav_desc).Buffer.NumElements = 64;
19016 U(uav_desc).Buffer.Flags = 0;
19018 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19019 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19021 expected_refcount = get_refcount(device) + 1;
19022 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19023 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19024 refcount = get_refcount(device);
19025 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
19026 tmp = NULL;
19027 expected_refcount = refcount + 1;
19028 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
19029 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
19030 refcount = get_refcount(device);
19031 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
19032 ID3D11Device_Release(tmp);
19034 ID3D11UnorderedAccessView_Release(uav);
19035 ID3D11Buffer_Release(buffer);
19037 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19038 buffer_desc.StructureByteStride = 4;
19040 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19041 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19043 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19044 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19046 memset(&uav_desc, 0, sizeof(uav_desc));
19047 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
19049 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
19050 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
19051 uav_desc.ViewDimension);
19052 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
19053 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
19054 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
19056 ID3D11UnorderedAccessView_Release(uav);
19057 ID3D11Buffer_Release(buffer);
19059 /* Without D3D11_BIND_UNORDERED_ACCESS. */
19060 buffer = create_buffer(device, 0, 1024, NULL);
19062 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19063 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19064 U(uav_desc).Buffer.FirstElement = 0;
19065 U(uav_desc).Buffer.NumElements = 64;
19066 U(uav_desc).Buffer.Flags = 0;
19068 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19069 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19071 ID3D11Buffer_Release(buffer);
19073 texture2d_desc.Width = 512;
19074 texture2d_desc.Height = 512;
19075 texture2d_desc.SampleDesc.Count = 1;
19076 texture2d_desc.SampleDesc.Quality = 0;
19077 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
19078 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19079 texture2d_desc.CPUAccessFlags = 0;
19080 texture2d_desc.MiscFlags = 0;
19082 texture3d_desc.Width = 64;
19083 texture3d_desc.Height = 64;
19084 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
19085 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19086 texture3d_desc.CPUAccessFlags = 0;
19087 texture3d_desc.MiscFlags = 0;
19089 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19091 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
19093 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
19095 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
19096 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
19097 texture2d_desc.Format = tests[i].texture.format;
19099 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
19100 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
19101 texture = (ID3D11Resource *)texture2d;
19103 else
19105 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
19106 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
19107 texture3d_desc.Format = tests[i].texture.format;
19109 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
19110 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
19111 texture = (ID3D11Resource *)texture3d;
19114 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
19116 current_desc = NULL;
19118 else
19120 current_desc = &uav_desc;
19121 get_uav_desc(current_desc, &tests[i].uav_desc);
19124 expected_refcount = get_refcount(texture);
19125 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
19126 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
19127 refcount = get_refcount(texture);
19128 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
19130 memset(&uav_desc, 0, sizeof(uav_desc));
19131 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
19132 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
19134 ID3D11UnorderedAccessView_Release(uav);
19135 ID3D11Resource_Release(texture);
19138 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
19140 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
19141 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
19143 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
19145 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
19146 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
19147 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
19149 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
19150 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
19151 texture = (ID3D11Resource *)texture2d;
19153 else
19155 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
19156 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
19157 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
19159 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
19160 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
19161 texture = (ID3D11Resource *)texture3d;
19164 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
19165 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
19166 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
19168 ID3D11Resource_Release(texture);
19171 refcount = ID3D11Device_Release(device);
19172 ok(!refcount, "Device has %u references left.\n", refcount);
19175 static void test_immediate_constant_buffer(void)
19177 struct d3d11_test_context test_context;
19178 D3D11_TEXTURE2D_DESC texture_desc;
19179 ID3D11DeviceContext *context;
19180 ID3D11RenderTargetView *rtv;
19181 unsigned int index[4] = {0};
19182 ID3D11Texture2D *texture;
19183 ID3D11PixelShader *ps;
19184 ID3D11Device *device;
19185 ID3D11Buffer *cb;
19186 unsigned int i;
19187 HRESULT hr;
19189 static const DWORD ps_code[] =
19191 #if 0
19192 uint index;
19194 static const int int_array[6] =
19196 310, 111, 212, -513, -318, 0,
19199 static const uint uint_array[6] =
19201 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
19204 static const float float_array[6] =
19206 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
19209 float4 main() : SV_Target
19211 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
19213 #endif
19214 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
19215 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19216 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19217 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
19218 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
19219 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
19220 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
19221 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
19222 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19223 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
19224 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
19225 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
19226 0x0100003e,
19228 static struct vec4 expected_result[] =
19230 { 310.0f, 2.0f, 76.00f, 1.0f},
19231 { 111.0f, 7.0f, 83.50f, 1.0f},
19232 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
19233 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
19234 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
19235 { 0.0f, 0.0f, 0.0f, 1.0f},
19238 if (!init_test_context(&test_context, NULL))
19239 return;
19241 device = test_context.device;
19242 context = test_context.immediate_context;
19244 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19245 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19246 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19248 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
19249 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19251 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19252 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19253 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19254 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19256 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19257 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19258 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19260 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
19262 *index = i;
19263 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
19265 draw_quad(&test_context);
19266 check_texture_vec4(texture, &expected_result[i], 0);
19269 ID3D11Buffer_Release(cb);
19270 ID3D11PixelShader_Release(ps);
19271 ID3D11Texture2D_Release(texture);
19272 ID3D11RenderTargetView_Release(rtv);
19273 release_test_context(&test_context);
19276 static void test_fp_specials(void)
19278 struct d3d11_test_context test_context;
19279 D3D11_TEXTURE2D_DESC texture_desc;
19280 ID3D11DeviceContext *context;
19281 ID3D11RenderTargetView *rtv;
19282 ID3D11Texture2D *texture;
19283 ID3D11PixelShader *ps;
19284 ID3D11Device *device;
19285 HRESULT hr;
19287 static const DWORD ps_code[] =
19289 #if 0
19290 float4 main() : SV_Target
19292 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
19294 #endif
19295 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
19296 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19297 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19298 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
19299 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
19300 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
19302 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
19304 if (!init_test_context(&test_context, NULL))
19305 return;
19307 device = test_context.device;
19308 context = test_context.immediate_context;
19310 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19311 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19312 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19314 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19315 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19316 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19317 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19319 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19320 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19322 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19324 draw_quad(&test_context);
19325 check_texture_uvec4(texture, &expected_result);
19327 ID3D11PixelShader_Release(ps);
19328 ID3D11Texture2D_Release(texture);
19329 ID3D11RenderTargetView_Release(rtv);
19330 release_test_context(&test_context);
19333 static void test_uint_shader_instructions(void)
19335 struct shader
19337 const DWORD *code;
19338 size_t size;
19339 D3D_FEATURE_LEVEL required_feature_level;
19342 struct d3d11_test_context test_context;
19343 D3D11_TEXTURE2D_DESC texture_desc;
19344 D3D_FEATURE_LEVEL feature_level;
19345 ID3D11DeviceContext *context;
19346 ID3D11RenderTargetView *rtv;
19347 ID3D11Texture2D *texture;
19348 ID3D11PixelShader *ps;
19349 ID3D11Device *device;
19350 ID3D11Buffer *cb;
19351 unsigned int i;
19352 HRESULT hr;
19354 static const DWORD ps_bfi_code[] =
19356 #if 0
19357 uint bits, offset, insert, base;
19359 uint4 main() : SV_Target
19361 uint mask = ((1 << bits) - 1) << offset;
19362 return ((insert << offset) & mask) | (base & ~mask);
19364 #endif
19365 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
19366 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19367 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19368 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
19369 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19370 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
19371 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
19373 static const DWORD ps_bfi2_code[] =
19375 #if 0
19376 ps_5_0
19377 dcl_globalFlags refactoringAllowed
19378 dcl_constantbuffer cb0[1], immediateIndexed
19379 dcl_output o0.xyzw
19380 dcl_temps 1
19381 mov r0.xyzw, cb0[0].xyzw
19382 bfi r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz, r0.wwww
19383 mov o0.xyzw, r0.xyzw
19385 #endif
19386 0x43425844, 0x900f86b6, 0x73f4dabf, 0xea1b1106, 0x591ac790, 0x00000001, 0x00000104, 0x00000003,
19387 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19388 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19389 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000008c, 0x00000050, 0x00000023,
19390 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19391 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19392 0x0b00008c, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19393 0x00000000, 0x00100ff6, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
19394 0x0100003e,
19396 static const DWORD ps_ibfe_code[] =
19398 #if 0
19399 ps_5_0
19400 dcl_globalFlags refactoringAllowed
19401 dcl_constantbuffer cb0[1], immediateIndexed
19402 dcl_output o0.xyzw
19403 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
19405 #endif
19406 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
19407 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19408 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19409 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
19410 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19411 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
19412 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
19414 static const DWORD ps_ibfe2_code[] =
19416 #if 0
19417 ps_5_0
19418 dcl_globalFlags refactoringAllowed
19419 dcl_constantbuffer cb0[1], immediateIndexed
19420 dcl_output o0.xyzw
19421 dcl_temps 1
19422 mov r0.xyzw, cb0[0].xyzw
19423 ibfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
19424 mov o0.xyzw, r0.xyzw
19426 #endif
19427 0x43425844, 0x347a9c0e, 0x3eff39a4, 0x3dd41cc5, 0xff87ec8d, 0x00000001, 0x000000fc, 0x00000003,
19428 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19429 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19430 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
19431 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19432 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19433 0x0900008b, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19434 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19436 static const DWORD ps_ubfe_code[] =
19438 #if 0
19439 uint u;
19441 uint4 main() : SV_Target
19443 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
19445 #endif
19446 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
19447 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19448 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19449 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
19450 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19451 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
19452 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
19453 0x0100003e,
19455 static const DWORD ps_ubfe2_code[] =
19457 #if 0
19458 ps_5_0
19459 dcl_globalFlags refactoringAllowed
19460 dcl_constantbuffer cb0[1], immediateIndexed
19461 dcl_output o0.xyzw
19462 dcl_temps 1
19463 mov r0.xyzw, cb0[0].xyzw
19464 ubfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
19465 mov o0.xyzw, r0.xyzw
19467 #endif
19468 0x43425844, 0xf377b7fc, 0x1e4cb9e7, 0xb9b1020d, 0xde484388, 0x00000001, 0x000000fc, 0x00000003,
19469 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19470 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19471 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
19472 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19473 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19474 0x0900008a, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19475 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19477 static const DWORD ps_bfrev_code[] =
19479 #if 0
19480 uint bits;
19482 uint4 main() : SV_Target
19484 return uint4(reversebits(bits), reversebits(reversebits(bits)),
19485 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
19487 #endif
19488 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
19489 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19490 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19491 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
19492 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19493 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
19494 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
19495 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
19496 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
19497 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
19498 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
19500 static const DWORD ps_bits_code[] =
19502 #if 0
19503 uint u;
19504 int i;
19506 uint4 main() : SV_Target
19508 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
19510 #endif
19511 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
19512 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19513 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19514 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
19515 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19516 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
19517 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
19518 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
19519 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
19520 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
19521 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
19522 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
19523 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
19524 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
19526 static const DWORD ps_ftou_code[] =
19528 #if 0
19529 float f;
19531 uint4 main() : SV_Target
19533 return uint4(f, -f, 0, 0);
19535 #endif
19536 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
19537 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19538 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19539 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
19540 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
19541 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
19542 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
19543 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
19545 static const DWORD ps_f16tof32_code[] =
19547 #if 0
19548 uint4 hf;
19550 uint4 main() : SV_Target
19552 return f16tof32(hf);
19554 #endif
19555 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
19556 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19557 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19558 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
19559 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19560 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19561 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19563 static const DWORD ps_f32tof16_code[] =
19565 #if 0
19566 float4 f;
19568 uint4 main() : SV_Target
19570 return f32tof16(f);
19572 #endif
19573 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
19574 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19575 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19576 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
19577 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19578 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
19580 static const DWORD ps_not_code[] =
19582 #if 0
19583 uint2 bits;
19585 uint4 main() : SV_Target
19587 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
19589 #endif
19590 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
19591 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19592 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19593 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
19594 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
19595 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
19596 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
19597 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
19599 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
19600 static const struct shader ps_bfi2 = {ps_bfi2_code, sizeof(ps_bfi2_code), D3D_FEATURE_LEVEL_11_0};
19601 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
19602 static const struct shader ps_ibfe2 = {ps_ibfe2_code, sizeof(ps_ibfe2_code), D3D_FEATURE_LEVEL_11_0};
19603 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
19604 static const struct shader ps_ubfe2 = {ps_ubfe2_code, sizeof(ps_ubfe2_code), D3D_FEATURE_LEVEL_11_0};
19605 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
19606 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
19607 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
19608 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
19609 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
19610 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
19611 static const struct
19613 const struct shader *ps;
19614 unsigned int bits[4];
19615 struct uvec4 expected_result;
19617 tests[] =
19619 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
19620 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
19621 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19622 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19623 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19624 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19625 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
19626 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
19627 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
19628 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
19629 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
19630 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
19631 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
19632 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
19633 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
19634 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
19635 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
19636 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
19637 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
19639 {&ps_bfi2, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19640 {&ps_bfi2, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19641 {&ps_bfi2, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19642 {&ps_bfi2, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19644 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19645 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19646 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19647 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19648 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
19649 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
19650 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19651 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19652 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
19653 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19654 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19655 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19656 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19657 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19658 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19659 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19660 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19661 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19662 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
19663 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
19664 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19665 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19666 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19667 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19668 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19669 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19671 {&ps_ibfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19673 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19674 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
19675 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
19676 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
19677 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
19678 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19679 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
19681 {&ps_ubfe2, { 4, 4, 0x7fffffff}, {0x0000000f, 0x0000000f, 0x0000000f, 0x0000000f}},
19682 {&ps_ubfe2, {23, 8, 0xffffffff}, {0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff}},
19683 {&ps_ubfe2, {30, 1, 0xffffffff}, {0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff}},
19684 {&ps_ubfe2, {15, 15, 0x7fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19685 {&ps_ubfe2, {15, 15, 0xffff00ff}, {0x00007ffe, 0x00007ffe, 0x00007ffe, 0x00007ffe}},
19686 {&ps_ubfe2, {16, 15, 0xffffffff}, {0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff}},
19687 {&ps_ubfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19688 {&ps_ubfe2, {20, 15, 0xffffffff}, {0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff}},
19689 {&ps_ubfe2, {31, 31, 0xffffffff}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
19690 {&ps_ubfe2, {31, 31, 0x80000000}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
19691 {&ps_ubfe2, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19693 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
19694 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
19695 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
19697 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
19698 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
19699 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
19700 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
19701 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
19702 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
19703 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
19704 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
19705 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
19706 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
19707 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
19708 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
19710 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
19711 {&ps_ftou, {BITS_NAN}, { 0, 0}},
19712 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
19713 {&ps_ftou, {BITS_INF}, {~0u, 0}},
19714 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
19715 {&ps_ftou, {BITS_1_0}, { 1, 0}},
19717 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
19718 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
19719 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
19720 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
19722 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
19724 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
19725 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
19728 if (!init_test_context(&test_context, NULL))
19729 return;
19731 device = test_context.device;
19732 context = test_context.immediate_context;
19733 feature_level = ID3D11Device_GetFeatureLevel(device);
19735 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
19736 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19738 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19739 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
19740 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19741 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19743 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19744 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19746 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19748 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19750 if (feature_level < tests[i].ps->required_feature_level)
19751 continue;
19753 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
19754 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19755 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19757 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
19759 draw_quad(&test_context);
19760 check_texture_uvec4(texture, &tests[i].expected_result);
19762 ID3D11PixelShader_Release(ps);
19765 ID3D11Buffer_Release(cb);
19766 ID3D11Texture2D_Release(texture);
19767 ID3D11RenderTargetView_Release(rtv);
19768 release_test_context(&test_context);
19771 static void test_index_buffer_offset(void)
19773 ID3D11Buffer *vb, *ib, *so_buffer, *args_buffer;
19774 struct d3d11_test_context test_context;
19775 ID3D11InputLayout *input_layout;
19776 ID3D11DeviceContext *context;
19777 struct resource_readback rb;
19778 ID3D11GeometryShader *gs;
19779 const struct vec4 *data;
19780 ID3D11VertexShader *vs;
19781 ID3D11Device *device;
19782 UINT stride, offset;
19783 unsigned int i;
19784 HRESULT hr;
19786 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19787 static const DWORD vs_code[] =
19789 #if 0
19790 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
19791 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
19793 out_position = position;
19794 out_attrib = attrib;
19796 #endif
19797 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
19798 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19799 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19800 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
19801 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19802 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19803 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
19804 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
19805 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
19806 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
19807 0x0100003e,
19809 static const DWORD gs_code[] =
19811 #if 0
19812 struct vertex
19814 float4 position : SV_POSITION;
19815 float4 attrib : ATTRIB;
19818 [maxvertexcount(1)]
19819 void main(point vertex input[1], inout PointStream<vertex> output)
19821 output.Append(input[0]);
19822 output.RestartStrip();
19824 #endif
19825 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
19826 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19827 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19828 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
19829 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19830 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19831 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
19832 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
19833 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
19834 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
19835 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
19836 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
19838 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
19840 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
19841 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
19843 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
19845 {0, "SV_Position", 0, 0, 4, 0},
19846 {0, "ATTRIB", 0, 0, 4, 0},
19848 static const struct
19850 struct vec4 position;
19851 struct vec4 attrib;
19853 vertices[] =
19855 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
19856 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
19857 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
19858 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
19860 static const unsigned int indices[] =
19862 0, 1, 2, 3,
19863 3, 2, 1, 0,
19864 1, 3, 2, 0,
19866 static const struct vec4 expected_data[] =
19868 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
19869 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
19870 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
19871 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
19873 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
19874 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
19875 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
19876 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
19878 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
19879 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
19880 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
19881 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
19883 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
19884 static const D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS argument_data[] =
19886 {4, 1, 0, 0, 0},
19889 if (!init_test_context(&test_context, &feature_level))
19890 return;
19892 device = test_context.device;
19893 context = test_context.immediate_context;
19895 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
19896 vs_code, sizeof(vs_code), &input_layout);
19897 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
19899 stride = 32;
19900 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
19901 so_declaration, ARRAY_SIZE(so_declaration),
19902 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
19903 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
19905 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
19906 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
19908 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
19909 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
19910 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
19912 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
19913 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
19915 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
19916 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
19917 stride = sizeof(*vertices);
19918 offset = 0;
19919 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
19921 offset = 0;
19922 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
19924 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
19925 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
19927 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
19928 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
19930 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
19931 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
19933 get_buffer_readback(so_buffer, &rb);
19934 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
19936 data = get_readback_vec4(&rb, i, 0);
19937 ok(compare_vec4(data, &expected_data[i], 0)
19938 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
19939 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
19940 data->x, data->y, data->z, data->w, i);
19942 release_resource_readback(&rb);
19944 /* indirect draws */
19945 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
19946 sizeof(argument_data), argument_data);
19948 offset = 0;
19949 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
19951 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
19952 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
19954 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
19955 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
19957 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
19958 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
19960 get_buffer_readback(so_buffer, &rb);
19961 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
19963 data = get_readback_vec4(&rb, i, 0);
19964 todo_wine_if(i >= 8 && i != 20 && i != 21)
19965 ok(compare_vec4(data, &expected_data[i], 0)
19966 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
19967 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
19968 data->x, data->y, data->z, data->w, i);
19970 release_resource_readback(&rb);
19972 ID3D11Buffer_Release(so_buffer);
19973 ID3D11Buffer_Release(args_buffer);
19974 ID3D11Buffer_Release(ib);
19975 ID3D11Buffer_Release(vb);
19976 ID3D11VertexShader_Release(vs);
19977 ID3D11GeometryShader_Release(gs);
19978 ID3D11InputLayout_Release(input_layout);
19979 release_test_context(&test_context);
19982 static void test_face_culling(void)
19984 struct d3d11_test_context test_context;
19985 D3D11_RASTERIZER_DESC rasterizer_desc;
19986 ID3D11RasterizerState *state;
19987 ID3D11DeviceContext *context;
19988 ID3D11Buffer *cw_vb, *ccw_vb;
19989 ID3D11Device *device;
19990 BOOL broken_warp;
19991 unsigned int i;
19992 HRESULT hr;
19994 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
19995 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
19996 static const DWORD ps_code[] =
19998 #if 0
19999 float4 main(uint front : SV_IsFrontFace) : SV_Target
20001 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
20003 #endif
20004 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
20005 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
20006 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
20007 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20008 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
20009 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
20010 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
20011 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
20012 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
20013 0x3f800000, 0x0100003e,
20015 static const struct vec3 ccw_quad[] =
20017 {-1.0f, 1.0f, 0.0f},
20018 {-1.0f, -1.0f, 0.0f},
20019 { 1.0f, 1.0f, 0.0f},
20020 { 1.0f, -1.0f, 0.0f},
20022 static const struct
20024 D3D11_CULL_MODE cull_mode;
20025 BOOL front_ccw;
20026 BOOL expected_cw;
20027 BOOL expected_ccw;
20029 tests[] =
20031 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
20032 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
20033 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
20034 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
20035 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
20036 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
20039 if (!init_test_context(&test_context, NULL))
20040 return;
20042 device = test_context.device;
20043 context = test_context.immediate_context;
20045 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20046 draw_color_quad(&test_context, &green);
20047 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20049 cw_vb = test_context.vb;
20050 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
20052 test_context.vb = ccw_vb;
20053 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20054 draw_color_quad(&test_context, &green);
20055 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
20057 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
20058 rasterizer_desc.CullMode = D3D11_CULL_BACK;
20059 rasterizer_desc.FrontCounterClockwise = FALSE;
20060 rasterizer_desc.DepthBias = 0;
20061 rasterizer_desc.DepthBiasClamp = 0.0f;
20062 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
20063 rasterizer_desc.DepthClipEnable = TRUE;
20064 rasterizer_desc.ScissorEnable = FALSE;
20065 rasterizer_desc.MultisampleEnable = FALSE;
20066 rasterizer_desc.AntialiasedLineEnable = FALSE;
20068 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20070 rasterizer_desc.CullMode = tests[i].cull_mode;
20071 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
20072 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20073 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
20075 ID3D11DeviceContext_RSSetState(context, state);
20077 test_context.vb = cw_vb;
20078 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20079 draw_color_quad(&test_context, &green);
20080 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
20082 test_context.vb = ccw_vb;
20083 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20084 draw_color_quad(&test_context, &green);
20085 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
20087 ID3D11RasterizerState_Release(state);
20090 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0;
20092 /* Test SV_IsFrontFace. */
20093 ID3D11PixelShader_Release(test_context.ps);
20094 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
20095 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20097 rasterizer_desc.CullMode = D3D11_CULL_NONE;
20098 rasterizer_desc.FrontCounterClockwise = FALSE;
20099 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20100 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20101 ID3D11DeviceContext_RSSetState(context, state);
20103 test_context.vb = cw_vb;
20104 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20105 draw_color_quad(&test_context, &green);
20106 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20107 test_context.vb = ccw_vb;
20108 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20109 draw_color_quad(&test_context, &green);
20110 if (!broken_warp)
20111 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
20112 else
20113 win_skip("Broken WARP.\n");
20115 ID3D11RasterizerState_Release(state);
20117 rasterizer_desc.CullMode = D3D11_CULL_NONE;
20118 rasterizer_desc.FrontCounterClockwise = TRUE;
20119 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20120 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20121 ID3D11DeviceContext_RSSetState(context, state);
20123 test_context.vb = cw_vb;
20124 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20125 draw_color_quad(&test_context, &green);
20126 if (!broken_warp)
20127 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
20128 else
20129 win_skip("Broken WARP.\n");
20130 test_context.vb = ccw_vb;
20131 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20132 draw_color_quad(&test_context, &green);
20133 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20135 ID3D11RasterizerState_Release(state);
20137 test_context.vb = cw_vb;
20138 ID3D11Buffer_Release(ccw_vb);
20139 release_test_context(&test_context);
20142 static void test_line_antialiasing_blending(void)
20144 ID3D11RasterizerState *rasterizer_state;
20145 struct d3d11_test_context test_context;
20146 D3D11_RASTERIZER_DESC rasterizer_desc;
20147 ID3D11BlendState *blend_state;
20148 ID3D11DeviceContext *context;
20149 D3D11_BLEND_DESC blend_desc;
20150 ID3D11Device *device;
20151 HRESULT hr;
20153 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
20154 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
20156 if (!init_test_context(&test_context, NULL))
20157 return;
20159 device = test_context.device;
20160 context = test_context.immediate_context;
20162 memset(&blend_desc, 0, sizeof(blend_desc));
20163 blend_desc.AlphaToCoverageEnable = FALSE;
20164 blend_desc.IndependentBlendEnable = FALSE;
20165 blend_desc.RenderTarget[0].BlendEnable = TRUE;
20166 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
20167 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
20168 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
20169 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
20170 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
20171 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
20172 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
20174 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
20175 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
20176 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
20178 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20179 draw_color_quad(&test_context, &green);
20180 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
20182 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20183 draw_color_quad(&test_context, &red);
20184 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
20186 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
20187 ID3D11BlendState_Release(blend_state);
20189 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20190 draw_color_quad(&test_context, &green);
20191 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
20193 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20194 draw_color_quad(&test_context, &red);
20195 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
20197 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
20198 rasterizer_desc.CullMode = D3D11_CULL_BACK;
20199 rasterizer_desc.FrontCounterClockwise = FALSE;
20200 rasterizer_desc.DepthBias = 0;
20201 rasterizer_desc.DepthBiasClamp = 0.0f;
20202 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
20203 rasterizer_desc.DepthClipEnable = TRUE;
20204 rasterizer_desc.ScissorEnable = FALSE;
20205 rasterizer_desc.MultisampleEnable = FALSE;
20206 rasterizer_desc.AntialiasedLineEnable = TRUE;
20208 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
20209 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20210 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
20212 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20213 draw_color_quad(&test_context, &green);
20214 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
20216 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20217 draw_color_quad(&test_context, &red);
20218 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
20220 ID3D11RasterizerState_Release(rasterizer_state);
20221 release_test_context(&test_context);
20224 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
20225 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
20226 const char *feature_name)
20228 unsigned int i;
20230 for (i = 0; i < format_count; ++i)
20232 DXGI_FORMAT format = formats[i].format;
20233 unsigned int supported = format_support[format] & feature_flag;
20235 if (formats[i].fl_required <= feature_level)
20237 todo_wine ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
20238 format, feature_name, feature_level, format_support[format]);
20239 continue;
20242 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
20244 if (supported)
20245 trace("Optional format %#x - %s supported, feature level %#x.\n",
20246 format, feature_name, feature_level);
20247 continue;
20250 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
20251 format, feature_name, feature_level, format_support[format]);
20255 static void test_format_support(const D3D_FEATURE_LEVEL feature_level)
20257 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
20258 struct device_desc device_desc;
20259 ID3D11Device *device;
20260 DXGI_FORMAT format;
20261 ULONG refcount;
20262 UINT support;
20263 HRESULT hr;
20265 static const struct format_support index_buffers[] =
20267 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
20268 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
20271 device_desc.feature_level = &feature_level;
20272 device_desc.flags = 0;
20273 if (!(device = create_device(&device_desc)))
20275 skip("Failed to create device for feature level %#x.\n", feature_level);
20276 return;
20279 support = 0xdeadbeef;
20280 hr = ID3D11Device_CheckFormatSupport(device, ~0u, &support);
20281 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
20282 ok(!support, "Got unexpected format support %#x.\n", support);
20284 memset(format_support, 0, sizeof(format_support));
20285 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
20287 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
20288 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
20289 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
20290 format, hr, format_support[format]);
20291 if (format_support[format] & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN)
20293 ok(format_support[format] & D3D11_FORMAT_SUPPORT_TEXTURE2D,
20294 "Got unexpected format support %#x for format %#x", format_support[format], format);
20298 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
20300 if (feature_level < D3D_FEATURE_LEVEL_10_0)
20302 /* SHADER_SAMPLE_COMPARISON is never advertised as supported on feature level 9. */
20303 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON),
20304 "Unexpected SHADER_SAMPLE_COMPARISON for format %#x, feature level %#x.\n",
20305 format, feature_level);
20306 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_BUFFER),
20307 "Unexpected BUFFER for format %#x, feature level %#x.\n",
20308 format, feature_level);
20310 if (feature_level < D3D_FEATURE_LEVEL_10_1)
20312 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER),
20313 "Unexpected SHADER_GATHER for format %#x, feature level %#x.\n",
20314 format, feature_level);
20315 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON),
20316 "Unexpected SHADER_GATHER_COMPARISON for format %#x, feature level %#x.\n",
20317 format, feature_level);
20321 ok(format_support[DXGI_FORMAT_R8G8B8A8_UNORM] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE,
20322 "SHADER_SAMPLE is not supported for R8G8B8A8_UNORM.\n");
20323 todo_wine
20324 ok(!(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE),
20325 "SHADER_SAMPLE is supported for R32G32B32A32_UINT.\n");
20326 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
20328 ok(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_LOAD,
20329 "SHADER_LOAD is not supported for R32G32B32A32_UINT.\n");
20332 check_format_support(format_support, feature_level,
20333 index_buffers, ARRAY_SIZE(index_buffers),
20334 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
20336 check_format_support(format_support, feature_level,
20337 display_format_support, ARRAY_SIZE(display_format_support),
20338 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
20340 refcount = ID3D11Device_Release(device);
20341 ok(!refcount, "Device has %u references left.\n", refcount);
20344 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
20346 struct d3d11_test_context test_context;
20347 D3D11_SUBRESOURCE_DATA resource_data;
20348 D3D11_TEXTURE2D_DESC texture_desc;
20349 ID3D11ShaderResourceView *srv;
20350 ID3D11DeviceContext *context;
20351 ID3D11Texture2D *texture;
20352 ID3D11PixelShader *ps;
20353 ID3D11Device *device;
20354 HRESULT hr;
20356 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
20357 static const DWORD ps_code[] =
20359 #if 0
20360 float4 main() : SV_TARGET
20362 return float4(1.0f, 0.0f, 0.0f, 0.5f);
20364 #endif
20365 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
20366 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
20367 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
20368 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
20369 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
20370 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
20371 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
20372 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
20373 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
20374 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
20375 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
20376 0x45475241, 0xabab0054,
20378 static const DWORD ps_texture_code[] =
20380 #if 0
20381 Texture2D t;
20382 SamplerState s;
20384 float4 main() : SV_TARGET
20386 return t.Sample(s, (float2)0);
20388 #endif
20389 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
20390 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
20391 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
20392 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
20393 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
20394 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
20395 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
20396 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
20397 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
20398 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
20399 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
20400 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
20401 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
20402 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20403 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
20405 static const DWORD texture_data[] = {0xffffff00};
20407 if (!init_test_context(&test_context, &feature_level))
20408 return;
20410 device = test_context.device;
20411 context = test_context.immediate_context;
20413 texture_desc.Width = 1;
20414 texture_desc.Height = 1;
20415 texture_desc.MipLevels = 0;
20416 texture_desc.ArraySize = 1;
20417 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20418 texture_desc.SampleDesc.Count = 1;
20419 texture_desc.SampleDesc.Quality = 0;
20420 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20421 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20422 texture_desc.CPUAccessFlags = 0;
20423 texture_desc.MiscFlags = 0;
20424 resource_data.pSysMem = texture_data;
20425 resource_data.SysMemPitch = sizeof(texture_data);
20426 resource_data.SysMemSlicePitch = 0;
20427 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20428 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
20429 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
20430 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20432 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20433 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
20434 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20435 draw_quad(&test_context);
20436 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
20437 ID3D11PixelShader_Release(ps);
20439 draw_color_quad(&test_context, &color);
20440 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
20442 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
20443 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
20444 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20445 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20446 draw_quad(&test_context);
20447 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
20448 ID3D11PixelShader_Release(ps);
20450 ID3D11ShaderResourceView_Release(srv);
20451 ID3D11Texture2D_Release(texture);
20452 release_test_context(&test_context);
20455 static void queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
20456 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
20458 static const D3D_FEATURE_LEVEL feature_levels[] =
20460 D3D_FEATURE_LEVEL_11_1,
20461 D3D_FEATURE_LEVEL_11_0,
20462 D3D_FEATURE_LEVEL_10_1,
20463 D3D_FEATURE_LEVEL_10_0,
20464 D3D_FEATURE_LEVEL_9_3,
20465 D3D_FEATURE_LEVEL_9_2,
20466 D3D_FEATURE_LEVEL_9_1
20468 unsigned int i;
20470 assert(begin <= end);
20471 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
20473 if (begin <= feature_levels[i] && feature_levels[i] <= end)
20474 queue_test_fl(test_func, feature_levels[i]);
20478 static void queue_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
20480 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
20481 D3D_FEATURE_LEVEL_11_1, test_func);
20484 static void queue_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
20486 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
20487 D3D_FEATURE_LEVEL_9_3, test_func);
20490 static void test_ddy(void)
20492 static const struct
20494 struct vec4 position;
20495 unsigned int color;
20497 quad[] =
20499 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
20500 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
20501 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
20502 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
20504 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
20506 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
20507 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
20509 #if 0
20510 struct vs_data
20512 float4 pos : SV_POSITION;
20513 float4 color : COLOR;
20516 void main(in struct vs_data vs_input, out struct vs_data vs_output)
20518 vs_output.pos = vs_input.pos;
20519 vs_output.color = vs_input.color;
20521 #endif
20522 static const DWORD vs_code[] =
20524 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
20525 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20526 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
20527 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20528 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
20529 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
20530 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
20531 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
20532 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
20533 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
20534 0x0100003e,
20536 #if 0
20537 struct ps_data
20539 float4 pos : SV_POSITION;
20540 float4 color : COLOR;
20543 float4 main(struct ps_data ps_input) : SV_Target
20545 return ddy(ps_input.color) * 240.0 + 0.5;
20547 #endif
20548 static const DWORD ps_code_ddy[] =
20550 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
20551 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20552 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20553 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20554 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20555 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
20556 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
20557 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
20558 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
20559 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20561 #if 0
20562 struct ps_data
20564 float4 pos : SV_POSITION;
20565 float4 color : COLOR;
20568 float4 main(struct ps_data ps_input) : SV_Target
20570 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
20572 #endif
20573 static const DWORD ps_code_ddy_coarse[] =
20575 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
20576 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20577 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20578 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20579 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20580 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
20581 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
20582 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
20583 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
20584 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20586 #if 0
20587 struct ps_data
20589 float4 pos : SV_POSITION;
20590 float4 color : COLOR;
20593 float4 main(struct ps_data ps_input) : SV_Target
20595 return ddy_fine(ps_input.color) * 240.0 + 0.5;
20597 #endif
20598 static const DWORD ps_code_ddy_fine[] =
20600 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
20601 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20602 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20603 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20604 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20605 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
20606 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
20607 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
20608 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
20609 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20611 static const struct
20613 D3D_FEATURE_LEVEL min_feature_level;
20614 const DWORD *ps_code;
20615 unsigned int ps_code_size;
20617 tests[] =
20619 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
20620 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
20621 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
20623 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
20624 struct d3d11_test_context test_context;
20625 D3D11_TEXTURE2D_DESC texture_desc;
20626 D3D_FEATURE_LEVEL feature_level;
20627 ID3D11InputLayout *input_layout;
20628 ID3D11DeviceContext *context;
20629 unsigned int stride, offset;
20630 struct resource_readback rb;
20631 ID3D11RenderTargetView *rtv;
20632 ID3D11Texture2D *texture;
20633 ID3D11VertexShader *vs;
20634 ID3D11PixelShader *ps;
20635 ID3D11Device *device;
20636 ID3D11Buffer *vb;
20637 unsigned int i;
20638 DWORD color;
20639 HRESULT hr;
20641 if (!init_test_context(&test_context, NULL))
20642 return;
20644 device = test_context.device;
20645 context = test_context.immediate_context;
20646 feature_level = ID3D11Device_GetFeatureLevel(device);
20648 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
20649 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
20650 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20652 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
20653 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
20655 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
20656 vs_code, sizeof(vs_code), &input_layout);
20657 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
20659 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
20661 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
20662 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
20664 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
20665 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
20666 stride = sizeof(*quad);
20667 offset = 0;
20668 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
20669 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
20671 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20673 if (feature_level < tests[i].min_feature_level)
20675 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
20676 feature_level, tests[i].min_feature_level);
20677 continue;
20680 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
20681 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20683 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20685 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20686 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
20687 ID3D11DeviceContext_Draw(context, 4, 0);
20689 get_texture_readback(texture, 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 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
20703 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
20704 ID3D11DeviceContext_Draw(context, 4, 0);
20706 get_texture_readback(test_context.backbuffer, 0, &rb);
20707 color = get_readback_color(&rb, 320, 190, 0);
20708 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20709 color = get_readback_color(&rb, 255, 240, 0);
20710 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20711 color = get_readback_color(&rb, 320, 240, 0);
20712 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20713 color = get_readback_color(&rb, 385, 240, 0);
20714 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20715 color = get_readback_color(&rb, 320, 290, 0);
20716 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20717 release_resource_readback(&rb);
20719 ID3D11PixelShader_Release(ps);
20722 ID3D11VertexShader_Release(vs);
20723 ID3D11Buffer_Release(vb);
20724 ID3D11InputLayout_Release(input_layout);
20725 ID3D11Texture2D_Release(texture);
20726 ID3D11RenderTargetView_Release(rtv);
20727 release_test_context(&test_context);
20730 static void test_shader_input_registers_limits(void)
20732 struct d3d11_test_context test_context;
20733 D3D11_SUBRESOURCE_DATA resource_data;
20734 D3D11_TEXTURE2D_DESC texture_desc;
20735 D3D11_SAMPLER_DESC sampler_desc;
20736 ID3D11ShaderResourceView *srv;
20737 ID3D11DeviceContext *context;
20738 ID3D11SamplerState *sampler;
20739 ID3D11Texture2D *texture;
20740 ID3D11PixelShader *ps;
20741 ID3D11Device *device;
20742 HRESULT hr;
20744 static const DWORD ps_last_register_code[] =
20746 #if 0
20747 Texture2D t : register(t127);
20748 SamplerState s : register(s15);
20750 void main(out float4 target : SV_Target)
20752 target = t.Sample(s, float2(0, 0));
20754 #endif
20755 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
20756 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20757 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
20758 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
20759 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
20760 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
20761 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
20763 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
20764 static const DWORD texture_data[] = {0xff00ff00};
20766 if (!init_test_context(&test_context, NULL))
20767 return;
20769 device = test_context.device;
20770 context = test_context.immediate_context;
20772 texture_desc.Width = 1;
20773 texture_desc.Height = 1;
20774 texture_desc.MipLevels = 0;
20775 texture_desc.ArraySize = 1;
20776 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20777 texture_desc.SampleDesc.Count = 1;
20778 texture_desc.SampleDesc.Quality = 0;
20779 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20780 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20781 texture_desc.CPUAccessFlags = 0;
20782 texture_desc.MiscFlags = 0;
20784 resource_data.pSysMem = texture_data;
20785 resource_data.SysMemPitch = sizeof(texture_data);
20786 resource_data.SysMemSlicePitch = 0;
20788 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20789 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
20791 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
20792 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20794 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
20795 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
20796 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
20797 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
20798 sampler_desc.MipLODBias = 0.0f;
20799 sampler_desc.MaxAnisotropy = 0;
20800 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
20801 sampler_desc.BorderColor[0] = 0.0f;
20802 sampler_desc.BorderColor[1] = 0.0f;
20803 sampler_desc.BorderColor[2] = 0.0f;
20804 sampler_desc.BorderColor[3] = 0.0f;
20805 sampler_desc.MinLOD = 0.0f;
20806 sampler_desc.MaxLOD = 0.0f;
20808 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
20809 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
20811 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
20812 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20813 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20815 ID3D11DeviceContext_PSSetShaderResources(context,
20816 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
20817 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
20818 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
20819 draw_quad(&test_context);
20820 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
20822 ID3D11PixelShader_Release(ps);
20823 ID3D11SamplerState_Release(sampler);
20824 ID3D11ShaderResourceView_Release(srv);
20825 ID3D11Texture2D_Release(texture);
20826 release_test_context(&test_context);
20829 static void test_unbind_shader_resource_view(void)
20831 struct d3d11_test_context test_context;
20832 D3D11_SUBRESOURCE_DATA resource_data;
20833 ID3D11ShaderResourceView *srv, *srv2;
20834 D3D11_TEXTURE2D_DESC texture_desc;
20835 ID3D11DeviceContext *context;
20836 ID3D11Texture2D *texture;
20837 ID3D11PixelShader *ps;
20838 ID3D11Device *device;
20839 HRESULT hr;
20841 static const DWORD ps_code[] =
20843 #if 0
20844 Texture2D t0;
20845 Texture2D t1;
20846 SamplerState s;
20848 float4 main() : SV_Target
20850 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
20852 #endif
20853 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
20854 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20855 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
20856 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
20857 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
20858 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
20859 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
20860 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
20861 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
20862 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
20863 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
20864 0x3f800000, 0x0100003e,
20866 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
20867 static const DWORD texture_data[] = {0xff00ff00};
20869 if (!init_test_context(&test_context, NULL))
20870 return;
20872 device = test_context.device;
20873 context = test_context.immediate_context;
20875 texture_desc.Width = 1;
20876 texture_desc.Height = 1;
20877 texture_desc.MipLevels = 0;
20878 texture_desc.ArraySize = 1;
20879 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20880 texture_desc.SampleDesc.Count = 1;
20881 texture_desc.SampleDesc.Quality = 0;
20882 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20883 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20884 texture_desc.CPUAccessFlags = 0;
20885 texture_desc.MiscFlags = 0;
20887 resource_data.pSysMem = texture_data;
20888 resource_data.SysMemPitch = sizeof(texture_data);
20889 resource_data.SysMemSlicePitch = 0;
20891 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20892 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
20893 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
20894 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20895 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20896 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20897 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20899 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20900 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
20901 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
20902 draw_quad(&test_context);
20903 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
20905 srv2 = NULL;
20906 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
20907 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
20908 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
20909 draw_quad(&test_context);
20910 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
20912 ID3D11PixelShader_Release(ps);
20913 ID3D11ShaderResourceView_Release(srv);
20914 ID3D11Texture2D_Release(texture);
20915 release_test_context(&test_context);
20918 static void test_stencil_separate(void)
20920 struct d3d11_test_context test_context;
20921 D3D11_TEXTURE2D_DESC texture_desc;
20922 D3D11_DEPTH_STENCIL_DESC ds_desc;
20923 ID3D11DepthStencilState *ds_state;
20924 ID3D11DepthStencilView *ds_view;
20925 D3D11_RASTERIZER_DESC rs_desc;
20926 ID3D11DeviceContext *context;
20927 ID3D11RasterizerState *rs;
20928 ID3D11Texture2D *texture;
20929 ID3D11Device *device;
20930 HRESULT hr;
20932 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
20933 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
20934 static const struct vec3 ccw_quad[] =
20936 {-1.0f, -1.0f, 0.0f},
20937 { 1.0f, -1.0f, 0.0f},
20938 {-1.0f, 1.0f, 0.0f},
20939 { 1.0f, 1.0f, 0.0f},
20942 if (!init_test_context(&test_context, NULL))
20943 return;
20945 device = test_context.device;
20946 context = test_context.immediate_context;
20948 texture_desc.Width = 640;
20949 texture_desc.Height = 480;
20950 texture_desc.MipLevels = 1;
20951 texture_desc.ArraySize = 1;
20952 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
20953 texture_desc.SampleDesc.Count = 1;
20954 texture_desc.SampleDesc.Quality = 0;
20955 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20956 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
20957 texture_desc.CPUAccessFlags = 0;
20958 texture_desc.MiscFlags = 0;
20959 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
20960 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20961 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
20962 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
20964 ds_desc.DepthEnable = TRUE;
20965 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
20966 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
20967 ds_desc.StencilEnable = TRUE;
20968 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
20969 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
20970 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
20971 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
20972 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
20973 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
20974 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
20975 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
20976 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
20977 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
20978 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
20979 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
20981 rs_desc.FillMode = D3D11_FILL_SOLID;
20982 rs_desc.CullMode = D3D11_CULL_NONE;
20983 rs_desc.FrontCounterClockwise = FALSE;
20984 rs_desc.DepthBias = 0;
20985 rs_desc.DepthBiasClamp = 0.0f;
20986 rs_desc.SlopeScaledDepthBias = 0.0f;
20987 rs_desc.DepthClipEnable = TRUE;
20988 rs_desc.ScissorEnable = FALSE;
20989 rs_desc.MultisampleEnable = FALSE;
20990 rs_desc.AntialiasedLineEnable = FALSE;
20991 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
20992 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20994 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
20995 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
20996 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
20997 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
20998 ID3D11DeviceContext_RSSetState(context, rs);
21000 draw_color_quad(&test_context, &green);
21001 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
21003 ID3D11Buffer_Release(test_context.vb);
21004 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
21006 draw_color_quad(&test_context, &green);
21007 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
21009 ID3D11RasterizerState_Release(rs);
21010 rs_desc.FrontCounterClockwise = TRUE;
21011 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
21012 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
21013 ID3D11DeviceContext_RSSetState(context, rs);
21015 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
21016 draw_color_quad(&test_context, &green);
21017 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
21019 ID3D11DepthStencilState_Release(ds_state);
21020 ID3D11DepthStencilView_Release(ds_view);
21021 ID3D11RasterizerState_Release(rs);
21022 ID3D11Texture2D_Release(texture);
21023 release_test_context(&test_context);
21026 static void test_uav_load(void)
21028 struct shader
21030 const DWORD *code;
21031 size_t size;
21033 struct texture
21035 UINT width;
21036 UINT height;
21037 UINT miplevel_count;
21038 UINT array_size;
21039 DXGI_FORMAT format;
21040 D3D11_SUBRESOURCE_DATA data[3];
21043 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
21044 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21045 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
21046 struct d3d11_test_context test_context;
21047 const struct texture *current_texture;
21048 ID3D11Texture2D *texture, *rt_texture;
21049 D3D11_TEXTURE2D_DESC texture_desc;
21050 const struct shader *current_ps;
21051 ID3D11UnorderedAccessView *uav;
21052 ID3D11DeviceContext *context;
21053 struct resource_readback rb;
21054 ID3D11PixelShader *ps;
21055 ID3D11Device *device;
21056 unsigned int i, x, y;
21057 ID3D11Buffer *cb;
21058 HRESULT hr;
21060 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
21061 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21062 static const DWORD ps_ld_2d_float_code[] =
21064 #if 0
21065 RWTexture2D<float> u;
21067 float main(float4 position : SV_Position) : SV_Target
21069 float2 s;
21070 u.GetDimensions(s.x, s.y);
21071 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21073 #endif
21074 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
21075 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21076 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21077 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21078 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21079 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
21080 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21081 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21082 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21083 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21084 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21085 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21086 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21088 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
21089 static const DWORD ps_ld_2d_uint_code[] =
21091 #if 0
21092 RWTexture2D<uint> u;
21094 uint main(float4 position : SV_Position) : SV_Target
21096 float2 s;
21097 u.GetDimensions(s.x, s.y);
21098 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21100 #endif
21101 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
21102 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21103 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21104 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
21105 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21106 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
21107 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21108 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21109 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21110 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21111 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21112 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21113 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21115 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
21116 static const DWORD ps_ld_2d_int_code[] =
21118 #if 0
21119 RWTexture2D<int> u;
21121 int main(float4 position : SV_Position) : SV_Target
21123 float2 s;
21124 u.GetDimensions(s.x, s.y);
21125 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21127 #endif
21128 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
21129 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21130 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21131 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
21132 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21133 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
21134 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21135 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21136 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21137 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21138 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21139 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21140 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21142 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
21143 static const DWORD ps_ld_2d_uint_arr_code[] =
21145 #if 0
21146 RWTexture2DArray<uint> u;
21148 uint layer;
21150 uint main(float4 position : SV_Position) : SV_Target
21152 float3 s;
21153 u.GetDimensions(s.x, s.y, s.z);
21154 s.z = layer;
21155 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
21157 #endif
21158 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
21159 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21160 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21161 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
21162 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
21163 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
21164 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
21165 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
21166 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
21167 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
21168 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
21169 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
21170 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
21171 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21173 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
21174 static const float float_data[] =
21176 0.50f, 0.25f, 1.00f, 0.00f,
21177 -1.00f, -2.00f, -3.00f, -4.00f,
21178 -0.50f, -0.25f, -1.00f, -0.00f,
21179 1.00f, 2.00f, 3.00f, 4.00f,
21181 static const unsigned int uint_data[] =
21183 0x00, 0x10, 0x20, 0x30,
21184 0x40, 0x50, 0x60, 0x70,
21185 0x80, 0x90, 0xa0, 0xb0,
21186 0xc0, 0xd0, 0xe0, 0xf0,
21188 static const unsigned int uint_data2[] =
21190 0xffff, 0xffff, 0xffff, 0xffff,
21191 0xffff, 0xc000, 0xc000, 0xffff,
21192 0xffff, 0xc000, 0xc000, 0xffff,
21193 0xffff, 0xffff, 0xffff, 0xffff,
21195 static const unsigned int uint_data3[] =
21197 0xaa, 0xaa, 0xcc, 0xcc,
21198 0xaa, 0xaa, 0xdd, 0xdd,
21199 0xbb, 0xbb, 0xee, 0xee,
21200 0xbb, 0xbb, 0xff, 0xff,
21202 static const int int_data[] =
21204 -1, 0x10, 0x20, 0x30,
21205 0x40, 0x50, 0x60, -777,
21206 -666, 0x90, -555, 0xb0,
21207 0xc0, 0xd0, 0xe0, -101,
21209 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
21210 {{float_data, 4 * sizeof(*float_data), 0}}};
21211 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
21212 {{uint_data, 4 * sizeof(*uint_data), 0}}};
21213 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
21214 {{uint_data, 4 * sizeof(*uint_data), 0},
21215 {uint_data2, 4 * sizeof(*uint_data2), 0},
21216 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
21217 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
21218 {{int_data, 4 * sizeof(*int_data), 0}}};
21220 static const struct test
21222 const struct shader *ps;
21223 const struct texture *texture;
21224 struct uav_desc uav_desc;
21225 struct uvec4 constant;
21226 const DWORD *expected_colors;
21228 tests[] =
21230 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
21231 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
21232 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
21233 #define R32_UINT DXGI_FORMAT_R32_UINT
21234 #define R32_SINT DXGI_FORMAT_R32_SINT
21235 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {0}, (const DWORD *)float_data},
21236 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {0}, (const DWORD *)uint_data},
21237 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {0}, (const DWORD *)int_data},
21238 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
21239 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
21240 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
21241 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
21242 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
21243 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
21244 #undef TEX_2D
21245 #undef TEX_2D_ARRAY
21246 #undef R32_FLOAT
21247 #undef R32_UINT
21248 #undef R32_SINT
21251 if (!init_test_context(&test_context, &feature_level))
21252 return;
21254 device = test_context.device;
21255 context = test_context.immediate_context;
21257 texture_desc.Width = 640;
21258 texture_desc.Height = 480;
21259 texture_desc.MipLevels = 1;
21260 texture_desc.ArraySize = 1;
21261 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
21262 texture_desc.SampleDesc.Count = 1;
21263 texture_desc.SampleDesc.Quality = 0;
21264 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21265 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21266 texture_desc.CPUAccessFlags = 0;
21267 texture_desc.MiscFlags = 0;
21268 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
21269 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21271 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
21272 U(rtv_desc).Texture2D.MipSlice = 0;
21274 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
21275 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
21276 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21278 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
21279 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
21280 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21282 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
21283 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
21284 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21286 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21288 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
21289 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21291 ps = NULL;
21292 uav = NULL;
21293 texture = NULL;
21294 current_ps = NULL;
21295 current_texture = NULL;
21296 for (i = 0; i < ARRAY_SIZE(tests); ++i)
21298 const struct test *test = &tests[i];
21299 ID3D11RenderTargetView *current_rtv;
21301 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21302 NULL, &test->constant, 0, 0);
21304 if (current_ps != test->ps)
21306 if (ps)
21307 ID3D11PixelShader_Release(ps);
21309 current_ps = test->ps;
21311 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
21312 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
21314 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21317 if (current_texture != test->texture)
21319 if (texture)
21320 ID3D11Texture2D_Release(texture);
21322 current_texture = test->texture;
21324 texture_desc.Width = current_texture->width;
21325 texture_desc.Height = current_texture->height;
21326 texture_desc.MipLevels = current_texture->miplevel_count;
21327 texture_desc.ArraySize = current_texture->array_size;
21328 texture_desc.Format = current_texture->format;
21330 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
21331 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
21334 if (uav)
21335 ID3D11UnorderedAccessView_Release(uav);
21337 get_uav_desc(&uav_desc, &test->uav_desc);
21338 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
21339 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
21341 switch (uav_desc.Format)
21343 case DXGI_FORMAT_R32_FLOAT:
21344 current_rtv = rtv_float;
21345 break;
21346 case DXGI_FORMAT_R32_UINT:
21347 current_rtv = rtv_uint;
21348 break;
21349 case DXGI_FORMAT_R32_SINT:
21350 current_rtv = rtv_sint;
21351 break;
21352 default:
21353 trace("Unhandled format %#x.\n", uav_desc.Format);
21354 current_rtv = NULL;
21355 break;
21358 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
21360 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
21361 1, 1, &uav, NULL);
21363 draw_quad(&test_context);
21365 get_texture_readback(rt_texture, 0, &rb);
21366 for (y = 0; y < 4; ++y)
21368 for (x = 0; x < 4; ++x)
21370 DWORD expected = test->expected_colors[y * 4 + x];
21371 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
21372 ok(compare_color(color, expected, 0),
21373 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
21374 i, color, expected, x, y);
21377 release_resource_readback(&rb);
21379 ID3D11PixelShader_Release(ps);
21380 ID3D11Texture2D_Release(texture);
21381 ID3D11UnorderedAccessView_Release(uav);
21383 ID3D11Buffer_Release(cb);
21384 ID3D11RenderTargetView_Release(rtv_float);
21385 ID3D11RenderTargetView_Release(rtv_sint);
21386 ID3D11RenderTargetView_Release(rtv_uint);
21387 ID3D11Texture2D_Release(rt_texture);
21388 release_test_context(&test_context);
21391 static void test_cs_uav_store(void)
21393 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21394 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21395 static const float zero[4] = {0.0f};
21396 D3D11_TEXTURE2D_DESC texture_desc;
21397 ID3D11UnorderedAccessView *uav;
21398 struct device_desc device_desc;
21399 ID3D11DeviceContext *context;
21400 struct vec4 input = {1.0f};
21401 ID3D11Texture2D *texture;
21402 ID3D11ComputeShader *cs;
21403 ID3D11Device *device;
21404 ID3D11Buffer *cb;
21405 ULONG refcount;
21406 HRESULT hr;
21407 RECT rect;
21409 static const DWORD cs_1_thread_code[] =
21411 #if 0
21412 RWTexture2D<float> u;
21414 float value;
21416 [numthreads(1, 1, 1)]
21417 void main()
21419 uint x, y, width, height;
21420 u.GetDimensions(width, height);
21421 for (y = 0; y < height; ++y)
21423 for (x = 0; x < width; ++x)
21424 u[uint2(x, y)] = value;
21427 #endif
21428 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
21429 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21430 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
21431 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21432 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
21433 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
21434 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
21435 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
21436 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
21437 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
21438 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
21439 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
21440 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
21441 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
21442 0x01000016, 0x0100003e,
21444 static const DWORD cs_1_group_code[] =
21446 #if 0
21447 RWTexture2D<float> u;
21449 float value;
21451 [numthreads(16, 16, 1)]
21452 void main(uint3 threadID : SV_GroupThreadID)
21454 uint2 count, size ;
21455 u.GetDimensions(size.x, size.y);
21456 count = size / (uint2)16;
21457 for (uint y = 0; y < count.y; ++y)
21458 for (uint x = 0; x < count.x; ++x)
21459 u[count * threadID.xy + uint2(x, y)] = value;
21461 #endif
21462 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
21463 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21464 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
21465 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21466 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
21467 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
21468 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
21469 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
21470 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
21471 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
21472 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
21473 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
21474 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
21475 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
21476 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
21477 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
21478 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
21480 static const DWORD cs_1_store_code[] =
21482 #if 0
21483 RWTexture2D<float> u;
21485 float value;
21487 [numthreads(1, 1, 1)]
21488 void main(uint3 groupID : SV_GroupID)
21490 u[groupID.xy] = value;
21492 #endif
21493 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
21494 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21495 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21496 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21497 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
21498 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
21500 static const DWORD cs_dispatch_id_code[] =
21502 #if 0
21503 RWTexture2D<float> u;
21505 float value;
21507 [numthreads(4, 4, 1)]
21508 void main(uint3 id : SV_DispatchThreadID)
21510 u[id.xy] = value;
21512 #endif
21513 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
21514 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21515 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21516 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21517 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
21518 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
21520 static const DWORD cs_group_index_code[] =
21522 #if 0
21523 RWTexture2D<float> u;
21525 float value;
21527 [numthreads(32, 1, 1)]
21528 void main(uint index : SV_GroupIndex)
21530 uint2 size;
21531 u.GetDimensions(size.x, size.y);
21532 uint count = size.x * size.y / 32;
21533 index *= count;
21534 for (uint i = 0; i < count; ++i, ++index)
21535 u[uint2(index % size.x, index / size.x)] = value;
21537 #endif
21538 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
21539 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21540 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
21541 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21542 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
21543 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
21544 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
21545 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
21546 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
21547 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
21548 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
21549 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
21550 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
21551 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
21552 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
21553 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
21556 device_desc.feature_level = &feature_level;
21557 device_desc.flags = 0;
21558 if (!(device = create_device(&device_desc)))
21560 skip("Failed to create device for feature level %#x.\n", feature_level);
21561 return;
21564 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
21566 texture_desc.Width = 64;
21567 texture_desc.Height = 64;
21568 texture_desc.MipLevels = 1;
21569 texture_desc.ArraySize = 1;
21570 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
21571 texture_desc.SampleDesc.Count = 1;
21572 texture_desc.SampleDesc.Quality = 0;
21573 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21574 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21575 texture_desc.CPUAccessFlags = 0;
21576 texture_desc.MiscFlags = 0;
21578 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21579 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21581 uav_desc.Format = texture_desc.Format;
21582 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
21583 U(uav_desc).Texture2D.MipSlice = 0;
21585 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
21586 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21588 ID3D11Device_GetImmediateContext(device, &context);
21590 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
21591 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21593 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
21594 check_texture_float(texture, 0.0f, 2);
21596 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
21597 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21598 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21600 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21601 check_texture_float(texture, 1.0f, 2);
21603 input.x = 0.5f;
21604 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21605 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21606 check_texture_float(texture, 0.5f, 2);
21608 ID3D11ComputeShader_Release(cs);
21610 input.x = 2.0f;
21611 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21612 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
21613 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21614 check_texture_float(texture, 0.5f, 2);
21616 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
21617 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21618 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21620 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21621 check_texture_float(texture, 2.0f, 2);
21623 input.x = 4.0f;
21624 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21625 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21626 check_texture_float(texture, 4.0f, 2);
21628 ID3D11ComputeShader_Release(cs);
21630 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
21631 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21632 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21634 input.x = 1.0f;
21635 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21636 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
21637 check_texture_float(texture, 1.0f, 2);
21639 input.x = 0.5f;
21640 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21641 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
21642 SetRect(&rect, 0, 0, 16, 32);
21643 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
21644 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
21645 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21646 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
21647 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21649 ID3D11ComputeShader_Release(cs);
21651 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
21652 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21653 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21655 input.x = 0.6f;
21656 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21657 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
21658 SetRect(&rect, 0, 0, 60, 60);
21659 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
21660 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
21661 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21662 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
21663 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21665 input.x = 0.7f;
21666 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21667 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
21668 check_texture_float(texture, 0.7f, 2);
21670 ID3D11ComputeShader_Release(cs);
21672 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
21673 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21674 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21676 input.x = 0.3f;
21677 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21678 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21679 check_texture_float(texture, 0.3f, 2);
21681 input.x = 0.1f;
21682 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21683 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
21684 check_texture_float(texture, 0.1f, 2);
21686 ID3D11ComputeShader_Release(cs);
21688 ID3D11Buffer_Release(cb);
21689 ID3D11Texture2D_Release(texture);
21690 ID3D11UnorderedAccessView_Release(uav);
21691 ID3D11DeviceContext_Release(context);
21692 refcount = ID3D11Device_Release(device);
21693 ok(!refcount, "Device has %u references left.\n", refcount);
21696 static void test_uav_store_immediate_constant(void)
21698 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21699 struct d3d11_test_context test_context;
21700 D3D11_TEXTURE2D_DESC texture_desc;
21701 ID3D11UnorderedAccessView *uav;
21702 ID3D11DeviceContext *context;
21703 struct resource_readback rb;
21704 ID3D11Texture2D *texture;
21705 ID3D11ComputeShader *cs;
21706 unsigned int uint_data;
21707 ID3D11Device *device;
21708 ID3D11Buffer *buffer;
21709 float float_data;
21710 int int_data;
21711 HRESULT hr;
21713 static const DWORD cs_store_int_code[] =
21715 #if 0
21716 RWBuffer<int> u;
21718 [numthreads(1, 1, 1)]
21719 void main()
21721 u[0] = 42;
21723 #endif
21724 0x43425844, 0x7246d785, 0x3f4ccbd6, 0x6a7cdbc0, 0xe2b58c72, 0x00000001, 0x000000b8, 0x00000003,
21725 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21726 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21727 0x0400089c, 0x0011e000, 0x00000000, 0x00003333, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
21728 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21729 0x00004002, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, 0x0100003e,
21731 static const DWORD cs_store_float_code[] =
21733 #if 0
21734 RWBuffer<float> u;
21736 [numthreads(1, 1, 1)]
21737 void main()
21739 u[0] = 1.0;
21741 #endif
21742 0x43425844, 0x525eea68, 0xc4cd5716, 0xc588f9c4, 0x0da27c5a, 0x00000001, 0x000000b8, 0x00000003,
21743 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21744 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21745 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
21746 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21747 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
21749 static const DWORD cs_store_unorm_code[] =
21751 #if 0
21752 RWTexture2D<unorm float> u;
21754 [numthreads(1, 1, 1)]
21755 void main()
21757 u[uint2(0, 0)] = 0.5f;
21759 #endif
21760 0x43425844, 0x3623f1de, 0xe847109e, 0x8e3da13f, 0xb6787b06, 0x00000001, 0x000000b8, 0x00000003,
21761 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21762 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21763 0x0400189c, 0x0011e000, 0x00000000, 0x00001111, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
21764 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21765 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
21767 static const DWORD cs_store_snorm_code[] =
21769 #if 0
21770 RWTexture2D<snorm float> u;
21772 [numthreads(1, 1, 1)]
21773 void main()
21775 u[uint2(0, 0)] = -0.5f;
21777 #endif
21778 0x43425844, 0xce5397fc, 0x7464bc06, 0xc79aa56c, 0x881bd7ef, 0x00000001, 0x000000b8, 0x00000003,
21779 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21780 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21781 0x0400189c, 0x0011e000, 0x00000000, 0x00002222, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
21782 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21783 0x00004002, 0xbf000000, 0xbf000000, 0xbf000000, 0xbf000000, 0x0100003e,
21785 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21786 static const unsigned int zero[4] = {0};
21788 if (!init_test_context(&test_context, &feature_level))
21789 return;
21791 device = test_context.device;
21792 context = test_context.immediate_context;
21794 buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
21796 uav_desc.Format = DXGI_FORMAT_R32_SINT;
21797 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
21798 U(uav_desc).Buffer.FirstElement = 0;
21799 U(uav_desc).Buffer.NumElements = 1;
21800 U(uav_desc).Buffer.Flags = 0;
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_int_code, sizeof(cs_store_int_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 int_data = get_readback_color(&rb, 0, 0, 0);
21812 ok(int_data == 42, "Got unexpected value %u.\n", int_data);
21813 release_resource_readback(&rb);
21815 ID3D11ComputeShader_Release(cs);
21816 ID3D11UnorderedAccessView_Release(uav);
21817 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
21818 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
21819 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21820 hr = ID3D11Device_CreateComputeShader(device, cs_store_float_code, sizeof(cs_store_float_code), NULL, &cs);
21821 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21823 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
21824 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21825 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21826 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21827 get_buffer_readback(buffer, &rb);
21828 float_data = get_readback_float(&rb, 0, 0);
21829 ok(float_data == 1.0f, "Got unexpected value %.8e.\n", float_data);
21830 release_resource_readback(&rb);
21832 texture_desc.Width = 64;
21833 texture_desc.Height = 64;
21834 texture_desc.MipLevels = 1;
21835 texture_desc.ArraySize = 1;
21836 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
21837 texture_desc.SampleDesc.Count = 1;
21838 texture_desc.SampleDesc.Quality = 0;
21839 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21840 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21841 texture_desc.CPUAccessFlags = 0;
21842 texture_desc.MiscFlags = 0;
21843 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21844 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
21845 ID3D11UnorderedAccessView_Release(uav);
21846 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
21847 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
21849 ID3D11ComputeShader_Release(cs);
21850 hr = ID3D11Device_CreateComputeShader(device, cs_store_unorm_code, sizeof(cs_store_unorm_code), NULL, &cs);
21851 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
21852 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
21853 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21854 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21855 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21856 get_texture_readback(texture, 0, &rb);
21857 uint_data = get_readback_color(&rb, 0, 0, 0);
21858 ok(compare_color(uint_data, 0x80808080, 1), "Got unexpected color 0x%08x.\n", uint_data);
21859 release_resource_readback(&rb);
21861 ID3D11Texture2D_Release(texture);
21862 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_SNORM;
21863 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21864 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
21865 ID3D11UnorderedAccessView_Release(uav);
21866 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
21867 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
21869 ID3D11ComputeShader_Release(cs);
21870 hr = ID3D11Device_CreateComputeShader(device, cs_store_snorm_code, sizeof(cs_store_snorm_code), NULL, &cs);
21871 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
21872 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
21873 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21874 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21875 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21876 get_texture_readback(texture, 0, &rb);
21877 uint_data = get_readback_color(&rb, 0, 0, 0);
21878 ok(compare_color(uint_data, 0xc0c0c0c0, 1), "Got unexpected color 0x%08x.\n", uint_data);
21879 release_resource_readback(&rb);
21881 ID3D11Buffer_Release(buffer);
21882 ID3D11Texture2D_Release(texture);
21883 ID3D11ComputeShader_Release(cs);
21884 ID3D11UnorderedAccessView_Release(uav);
21885 release_test_context(&test_context);
21888 static void test_ps_cs_uav_binding(void)
21890 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21891 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
21892 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21893 ID3D11Texture2D *cs_texture, *ps_texture;
21894 struct d3d11_test_context test_context;
21895 static const float zero[4] = {0.0f};
21896 D3D11_TEXTURE2D_DESC texture_desc;
21897 ID3D11DeviceContext *context;
21898 ID3D11Buffer *cs_cb, *ps_cb;
21899 struct vec4 input = {1.0f};
21900 ID3D11ComputeShader *cs;
21901 ID3D11PixelShader *ps;
21902 ID3D11Device *device;
21903 HRESULT hr;
21905 static const DWORD cs_code[] =
21907 #if 0
21908 RWTexture2D<float> u;
21910 float value;
21912 [numthreads(1, 1, 1)]
21913 void main()
21915 uint x, y, width, height;
21916 u.GetDimensions(width, height);
21917 for (y = 0; y < height; ++y)
21919 for (x = 0; x < width; ++x)
21920 u[uint2(x, y)] = value;
21923 #endif
21924 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
21925 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21926 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
21927 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21928 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
21929 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
21930 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
21931 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
21932 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
21933 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
21934 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
21935 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
21936 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
21937 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
21938 0x01000016, 0x0100003e,
21940 static const DWORD ps_code[] =
21942 #if 0
21943 RWTexture2D<float> u : register(u1);
21945 float value;
21947 void main()
21949 uint x, y, width, height;
21950 u.GetDimensions(width, height);
21951 for (y = 0; y < height; ++y)
21953 for (x = 0; x < width; ++x)
21954 u[uint2(x, y)] = value;
21957 #endif
21958 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
21959 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21960 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
21961 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
21962 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
21963 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
21964 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
21965 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
21966 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
21967 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
21968 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
21969 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
21970 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
21971 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
21974 if (!init_test_context(&test_context, &feature_level))
21975 return;
21977 device = test_context.device;
21978 context = test_context.immediate_context;
21980 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
21981 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
21983 texture_desc.Width = 64;
21984 texture_desc.Height = 64;
21985 texture_desc.MipLevels = 1;
21986 texture_desc.ArraySize = 1;
21987 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
21988 texture_desc.SampleDesc.Count = 1;
21989 texture_desc.SampleDesc.Quality = 0;
21990 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21991 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21992 texture_desc.CPUAccessFlags = 0;
21993 texture_desc.MiscFlags = 0;
21994 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
21995 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21996 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
21997 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21999 uav_desc.Format = texture_desc.Format;
22000 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
22001 U(uav_desc).Texture2D.MipSlice = 0;
22002 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
22003 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22004 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
22005 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22007 ID3D11Device_GetImmediateContext(device, &context);
22009 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
22010 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
22011 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
22012 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
22013 0, NULL, NULL, 1, 1, &ps_uav, NULL);
22015 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
22016 check_texture_float(cs_texture, 0.0f, 2);
22017 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
22018 check_texture_float(ps_texture, 0.0f, 2);
22020 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
22021 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22022 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22023 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22024 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22025 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22027 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22028 check_texture_float(cs_texture, 1.0f, 2);
22029 check_texture_float(ps_texture, 0.0f, 2);
22030 draw_quad(&test_context);
22031 check_texture_float(cs_texture, 1.0f, 2);
22032 check_texture_float(ps_texture, 1.0f, 2);
22034 input.x = 0.5f;
22035 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
22036 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22037 check_texture_float(cs_texture, 0.5f, 2);
22038 check_texture_float(ps_texture, 1.0f, 2);
22039 input.x = 2.0f;
22040 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
22041 draw_quad(&test_context);
22042 check_texture_float(cs_texture, 0.5f, 2);
22043 check_texture_float(ps_texture, 2.0f, 2);
22045 input.x = 8.0f;
22046 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
22047 input.x = 4.0f;
22048 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
22049 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22050 check_texture_float(cs_texture, 8.0f, 2);
22051 check_texture_float(ps_texture, 2.0f, 2);
22052 draw_quad(&test_context);
22053 check_texture_float(cs_texture, 8.0f, 2);
22054 check_texture_float(ps_texture, 4.0f, 2);
22056 ID3D11ComputeShader_Release(cs);
22057 ID3D11PixelShader_Release(ps);
22058 ID3D11Buffer_Release(cs_cb);
22059 ID3D11Buffer_Release(ps_cb);
22060 ID3D11Texture2D_Release(cs_texture);
22061 ID3D11Texture2D_Release(ps_texture);
22062 ID3D11UnorderedAccessView_Release(cs_uav);
22063 ID3D11UnorderedAccessView_Release(ps_uav);
22064 ID3D11DeviceContext_Release(context);
22065 release_test_context(&test_context);
22068 static void test_atomic_instructions(void)
22070 ID3D11UnorderedAccessView *in_uav, *out_uav;
22071 ID3D11Buffer *cb, *in_buffer, *out_buffer;
22072 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22073 struct d3d11_test_context test_context;
22074 struct resource_readback rb, out_rb;
22075 D3D11_BUFFER_DESC buffer_desc;
22076 ID3D11DeviceContext *context;
22077 ID3D11ComputeShader *cs;
22078 ID3D11PixelShader *ps;
22079 ID3D11Device *device;
22080 unsigned int i, j;
22081 HRESULT hr;
22083 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22084 static const unsigned int zero[4] = {0, 0, 0, 0};
22085 static const DWORD ps_atomics_code[] =
22087 #if 0
22088 RWByteAddressBuffer u;
22090 uint4 v;
22091 int4 i;
22093 void main()
22095 u.InterlockedAnd(0 * 4, v.x);
22096 u.InterlockedCompareStore(1 * 4, v.y, v.x);
22097 u.InterlockedAdd(2 * 4, v.x);
22098 u.InterlockedOr(3 * 4, v.x);
22099 u.InterlockedMax(4 * 4, i.x);
22100 u.InterlockedMin(5 * 4, i.x);
22101 u.InterlockedMax(6 * 4, v.x);
22102 u.InterlockedMin(7 * 4, v.x);
22103 u.InterlockedXor(8 * 4, v.x);
22105 #endif
22106 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
22107 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22108 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
22109 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
22110 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
22111 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
22112 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
22113 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
22114 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
22115 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
22116 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
22117 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
22118 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
22119 0x00000000, 0x00000000, 0x0100003e,
22121 static const DWORD cs_atomics_code[] =
22123 #if 0
22124 RWByteAddressBuffer u;
22125 RWByteAddressBuffer u2;
22127 uint4 v;
22128 int4 i;
22130 [numthreads(1, 1, 1)]
22131 void main()
22133 uint r;
22134 u.InterlockedAnd(0 * 4, v.x, r);
22135 u2.Store(0 * 4, r);
22136 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
22137 u2.Store(1 * 4, r);
22138 u.InterlockedAdd(2 * 4, v.x, r);
22139 u2.Store(2 * 4, r);
22140 u.InterlockedOr(3 * 4, v.x, r);
22141 u2.Store(3 * 4, r);
22142 u.InterlockedMax(4 * 4, i.x, r);
22143 u2.Store(4 * 4, r);
22144 u.InterlockedMin(5 * 4, i.x, r);
22145 u2.Store(5 * 4, r);
22146 u.InterlockedMax(6 * 4, v.x, r);
22147 u2.Store(6 * 4, r);
22148 u.InterlockedMin(7 * 4, v.x, r);
22149 u2.Store(7 * 4, r);
22150 u.InterlockedXor(8 * 4, v.x, r);
22151 u2.Store(8 * 4, r);
22153 #endif
22154 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
22155 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22156 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
22157 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
22158 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22159 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
22160 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
22161 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
22162 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
22163 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
22164 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
22165 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
22166 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
22167 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
22168 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
22169 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
22170 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
22171 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
22172 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
22173 0x0010000a, 0x00000000, 0x0100003e,
22176 static const char * const instructions[] =
22178 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
22179 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
22181 static const char * const imm_instructions[] =
22183 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
22184 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
22186 static const struct test
22188 struct uvec4 v;
22189 struct ivec4 i;
22190 unsigned int input[ARRAY_SIZE(instructions)];
22191 unsigned int expected_result[ARRAY_SIZE(instructions)];
22193 tests[] =
22195 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
22196 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
22199 if (!init_test_context(&test_context, &feature_level))
22200 return;
22202 device = test_context.device;
22203 context = test_context.immediate_context;
22205 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
22206 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22207 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
22209 buffer_desc.ByteWidth = sizeof(tests->input);
22210 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
22211 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22212 buffer_desc.CPUAccessFlags = 0;
22213 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
22214 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
22215 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22216 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
22217 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22219 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
22220 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
22221 U(uav_desc).Buffer.FirstElement = 0;
22222 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
22223 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
22224 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
22225 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22226 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
22227 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22229 set_viewport(context, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f);
22231 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
22232 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22233 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22235 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
22236 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22237 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22239 for (i = 0; i < ARRAY_SIZE(tests); ++i)
22241 const struct test *test = &tests[i];
22243 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22244 NULL, &test->v, 0, 0);
22246 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
22247 NULL, test->input, 0, 0);
22249 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
22250 0, 1, &in_uav, NULL);
22252 draw_quad(&test_context);
22253 get_buffer_readback(in_buffer, &rb);
22254 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
22256 unsigned int value = get_readback_color(&rb, j, 0, 0);
22257 unsigned int expected = test->expected_result[j];
22259 todo_wine_if(expected != test->input[j]
22260 && (!strcmp(instructions[j], "atomic_imax")
22261 || !strcmp(instructions[j], "atomic_imin")))
22262 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
22263 "with inputs (%u, %u), (%d), %#x (%d).\n",
22264 i, value, value, expected, expected, instructions[j],
22265 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
22267 release_resource_readback(&rb);
22269 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
22270 NULL, test->input, 0, 0);
22271 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
22273 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
22274 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
22276 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22277 get_buffer_readback(in_buffer, &rb);
22278 get_buffer_readback(out_buffer, &out_rb);
22279 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
22281 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
22282 || !strcmp(imm_instructions[j], "imm_atomic_imin");
22283 unsigned int out_value = get_readback_color(&out_rb, j, 0, 0);
22284 unsigned int value = get_readback_color(&rb, j, 0, 0);
22285 unsigned int expected = test->expected_result[j];
22287 todo_wine_if(expected != test->input[j] && todo_instruction)
22288 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
22289 "with inputs (%u, %u), (%d), %#x (%d).\n",
22290 i, value, value, expected, expected, imm_instructions[j],
22291 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
22293 todo_wine_if(todo_instruction && out_value != test->input[j])
22294 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
22295 out_value, test->input[j], imm_instructions[j]);
22297 release_resource_readback(&out_rb);
22298 release_resource_readback(&rb);
22301 ID3D11Buffer_Release(cb);
22302 ID3D11Buffer_Release(in_buffer);
22303 ID3D11Buffer_Release(out_buffer);
22304 ID3D11ComputeShader_Release(cs);
22305 ID3D11PixelShader_Release(ps);
22306 ID3D11UnorderedAccessView_Release(in_uav);
22307 ID3D11UnorderedAccessView_Release(out_uav);
22308 release_test_context(&test_context);
22311 static void test_sm4_ret_instruction(void)
22313 struct d3d11_test_context test_context;
22314 ID3D11DeviceContext *context;
22315 ID3D11PixelShader *ps;
22316 struct uvec4 constant;
22317 ID3D11Device *device;
22318 ID3D11Buffer *cb;
22319 HRESULT hr;
22321 static const DWORD ps_code[] =
22323 #if 0
22324 uint c;
22326 float4 main() : SV_TARGET
22328 if (c == 1)
22329 return float4(1, 0, 0, 1);
22330 if (c == 2)
22331 return float4(0, 1, 0, 1);
22332 if (c == 3)
22333 return float4(0, 0, 1, 1);
22334 return float4(1, 1, 1, 1);
22336 #endif
22337 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
22338 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22339 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22340 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
22341 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
22342 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
22343 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
22344 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
22345 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
22346 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
22347 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
22348 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
22349 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
22350 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
22351 0x0100003e,
22354 if (!init_test_context(&test_context, NULL))
22355 return;
22357 device = test_context.device;
22358 context = test_context.immediate_context;
22360 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22361 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
22362 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22363 memset(&constant, 0, sizeof(constant));
22364 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
22365 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22367 draw_quad(&test_context);
22368 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22370 constant.x = 1;
22371 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22372 draw_quad(&test_context);
22373 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
22375 constant.x = 2;
22376 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22377 draw_quad(&test_context);
22378 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
22380 constant.x = 3;
22381 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22382 draw_quad(&test_context);
22383 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
22385 constant.x = 4;
22386 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22387 draw_quad(&test_context);
22388 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22390 ID3D11Buffer_Release(cb);
22391 ID3D11PixelShader_Release(ps);
22392 release_test_context(&test_context);
22395 static void test_primitive_restart(void)
22397 struct d3d11_test_context test_context;
22398 ID3D11Buffer *ib32, *ib16, *vb;
22399 ID3D11DeviceContext *context;
22400 unsigned int stride, offset;
22401 ID3D11InputLayout *layout;
22402 ID3D11VertexShader *vs;
22403 ID3D11PixelShader *ps;
22404 ID3D11Device *device;
22405 unsigned int i;
22406 HRESULT hr;
22407 RECT rect;
22409 static const DWORD ps_code[] =
22411 #if 0
22412 struct vs_out
22414 float4 position : SV_Position;
22415 float4 color : color;
22418 float4 main(vs_out input) : SV_TARGET
22420 return input.color;
22422 #endif
22423 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
22424 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22425 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
22426 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
22427 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
22428 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
22429 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
22430 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
22432 static const DWORD vs_code[] =
22434 #if 0
22435 struct vs_out
22437 float4 position : SV_Position;
22438 float4 color : color;
22441 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
22443 output.position = position;
22444 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
22446 #endif
22447 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
22448 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
22449 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
22450 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
22451 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
22452 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
22453 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
22454 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
22455 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
22456 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
22457 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
22458 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
22459 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
22461 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
22463 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
22465 static const struct vec2 vertices[] =
22467 {-1.00f, -1.0f},
22468 {-1.00f, 1.0f},
22469 {-0.25f, -1.0f},
22470 {-0.25f, 1.0f},
22471 { 0.25f, -1.0f},
22472 { 0.25f, 1.0f},
22473 { 1.00f, -1.0f},
22474 { 1.00f, 1.0f},
22476 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
22477 static const unsigned short indices16[] =
22479 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
22481 static const unsigned int indices32[] =
22483 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
22486 if (!init_test_context(&test_context, NULL))
22487 return;
22489 device = test_context.device;
22490 context = test_context.immediate_context;
22492 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
22493 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
22494 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22495 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
22497 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
22498 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
22500 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
22501 vs_code, sizeof(vs_code), &layout);
22502 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
22504 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
22506 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
22507 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22509 ID3D11DeviceContext_IASetInputLayout(context, layout);
22510 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
22511 stride = sizeof(*vertices);
22512 offset = 0;
22513 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
22515 for (i = 0; i < 2; ++i)
22517 if (!i)
22518 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
22519 else
22520 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
22522 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
22523 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
22524 SetRect(&rect, 0, 0, 240, 480);
22525 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
22526 SetRect(&rect, 240, 0, 400, 480);
22527 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
22528 SetRect(&rect, 400, 0, 640, 480);
22529 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
22532 ID3D11Buffer_Release(ib16);
22533 ID3D11Buffer_Release(ib32);
22534 ID3D11Buffer_Release(vb);
22535 ID3D11InputLayout_Release(layout);
22536 ID3D11PixelShader_Release(ps);
22537 ID3D11VertexShader_Release(vs);
22538 release_test_context(&test_context);
22541 static void test_resinfo_instruction(void)
22543 struct shader
22545 const DWORD *code;
22546 size_t size;
22549 struct d3d11_test_context test_context;
22550 D3D11_TEXTURE3D_DESC texture3d_desc;
22551 D3D11_TEXTURE2D_DESC texture_desc;
22552 const struct shader *current_ps;
22553 D3D_FEATURE_LEVEL feature_level;
22554 ID3D11ShaderResourceView *srv;
22555 ID3D11DeviceContext *context;
22556 ID3D11Texture2D *rtv_texture;
22557 ID3D11RenderTargetView *rtv;
22558 ID3D11Resource *texture;
22559 struct uvec4 constant;
22560 ID3D11PixelShader *ps;
22561 ID3D11Device *device;
22562 unsigned int i, type;
22563 ID3D11Buffer *cb;
22564 HRESULT hr;
22566 static const DWORD ps_2d_code[] =
22568 #if 0
22569 Texture2D t;
22571 uint type;
22572 uint level;
22574 float4 main() : SV_TARGET
22576 if (!type)
22578 float width, height, miplevels;
22579 t.GetDimensions(level, width, height, miplevels);
22580 return float4(width, height, miplevels, 0);
22582 else
22584 uint width, height, miplevels;
22585 t.GetDimensions(level, width, height, miplevels);
22586 return float4(width, height, miplevels, 0);
22589 #endif
22590 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
22591 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22592 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22593 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
22594 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
22595 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22596 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22597 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
22598 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
22599 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
22600 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
22601 0x01000015, 0x0100003e,
22603 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
22604 static const DWORD ps_2d_array_code[] =
22606 #if 0
22607 Texture2DArray t;
22609 uint type;
22610 uint level;
22612 float4 main() : SV_TARGET
22614 if (!type)
22616 float width, height, elements, miplevels;
22617 t.GetDimensions(level, width, height, elements, miplevels);
22618 return float4(width, height, elements, miplevels);
22620 else
22622 uint width, height, elements, miplevels;
22623 t.GetDimensions(level, width, height, elements, miplevels);
22624 return float4(width, height, elements, miplevels);
22627 #endif
22628 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
22629 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22630 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22631 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
22632 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
22633 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22634 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22635 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
22636 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
22637 0x0100003e, 0x01000015, 0x0100003e,
22639 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
22640 static const DWORD ps_3d_code[] =
22642 #if 0
22643 Texture3D t;
22645 uint type;
22646 uint level;
22648 float4 main() : SV_TARGET
22650 if (!type)
22652 float width, height, depth, miplevels;
22653 t.GetDimensions(level, width, height, depth, miplevels);
22654 return float4(width, height, depth, miplevels);
22656 else
22658 uint width, height, depth, miplevels;
22659 t.GetDimensions(level, width, height, depth, miplevels);
22660 return float4(width, height, depth, miplevels);
22663 #endif
22664 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
22665 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22666 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22667 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
22668 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
22669 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22670 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22671 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
22672 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
22673 0x0100003e, 0x01000015, 0x0100003e,
22675 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
22676 static const DWORD ps_cube_code[] =
22678 #if 0
22679 TextureCube t;
22681 uint type;
22682 uint level;
22684 float4 main() : SV_TARGET
22686 if (!type)
22688 float width, height, miplevels;
22689 t.GetDimensions(level, width, height, miplevels);
22690 return float4(width, height, miplevels, 0);
22692 else
22694 uint width, height, miplevels;
22695 t.GetDimensions(level, width, height, miplevels);
22696 return float4(width, height, miplevels, 0);
22699 #endif
22700 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
22701 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22702 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22703 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
22704 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
22705 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22706 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22707 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
22708 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
22709 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
22710 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
22711 0x01000015, 0x0100003e,
22713 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
22714 static const DWORD ps_cube_array_code[] =
22716 #if 0
22717 TextureCubeArray t;
22719 uint type;
22720 uint level;
22722 float4 main() : SV_TARGET
22724 if (!type)
22726 float width, height, elements, miplevels;
22727 t.GetDimensions(level, width, height, elements, miplevels);
22728 return float4(width, height, miplevels, 0);
22730 else
22732 uint width, height, elements, miplevels;
22733 t.GetDimensions(level, width, height, elements, miplevels);
22734 return float4(width, height, miplevels, 0);
22737 #endif
22738 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
22739 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22740 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22741 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
22742 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
22743 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
22744 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
22745 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
22746 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
22747 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
22748 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
22749 0x0100003e, 0x01000015, 0x0100003e,
22751 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
22752 static const struct ps_test
22754 const struct shader *ps;
22755 struct
22757 unsigned int width;
22758 unsigned int height;
22759 unsigned int depth;
22760 unsigned int miplevel_count;
22761 unsigned int array_size;
22762 unsigned int cube_count;
22763 } texture_desc;
22764 unsigned int miplevel;
22765 struct vec4 expected_result;
22767 ps_tests[] =
22769 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
22770 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
22771 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
22772 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
22774 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
22775 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
22776 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
22777 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
22779 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
22780 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
22781 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
22782 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
22783 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
22784 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
22785 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
22786 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
22787 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
22789 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
22790 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
22791 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
22792 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
22793 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
22795 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
22796 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
22797 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
22800 if (!init_test_context(&test_context, NULL))
22801 return;
22803 device = test_context.device;
22804 context = test_context.immediate_context;
22805 feature_level = ID3D11Device_GetFeatureLevel(device);
22807 texture_desc.Width = 64;
22808 texture_desc.Height = 64;
22809 texture_desc.MipLevels = 1;
22810 texture_desc.ArraySize = 1;
22811 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
22812 texture_desc.SampleDesc.Count = 1;
22813 texture_desc.SampleDesc.Quality = 0;
22814 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22815 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
22816 texture_desc.CPUAccessFlags = 0;
22817 texture_desc.MiscFlags = 0;
22818 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
22819 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22820 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
22821 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
22823 memset(&constant, 0, sizeof(constant));
22824 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
22826 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
22827 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22829 ps = NULL;
22830 current_ps = NULL;
22831 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
22833 const struct ps_test *test = &ps_tests[i];
22835 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
22837 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
22838 continue;
22841 if (current_ps != test->ps)
22843 if (ps)
22844 ID3D11PixelShader_Release(ps);
22846 current_ps = test->ps;
22848 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
22849 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
22850 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22853 if (test->texture_desc.depth != 1)
22855 texture3d_desc.Width = test->texture_desc.width;
22856 texture3d_desc.Height = test->texture_desc.height;
22857 texture3d_desc.Depth = test->texture_desc.depth;
22858 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
22859 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
22860 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
22861 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22862 texture3d_desc.CPUAccessFlags = 0;
22863 texture3d_desc.MiscFlags = 0;
22864 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
22865 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
22867 else
22869 texture_desc.Width = test->texture_desc.width;
22870 texture_desc.Height = test->texture_desc.height;
22871 texture_desc.MipLevels = test->texture_desc.miplevel_count;
22872 texture_desc.ArraySize = test->texture_desc.array_size;
22873 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
22874 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22875 texture_desc.MiscFlags = 0;
22876 if (test->texture_desc.cube_count)
22877 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
22878 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
22879 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
22882 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
22883 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
22884 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
22886 for (type = 0; type < 2; ++type)
22888 constant.x = type;
22889 constant.y = test->miplevel;
22890 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22892 draw_quad(&test_context);
22893 check_texture_vec4(rtv_texture, &test->expected_result, 0);
22896 ID3D11Resource_Release(texture);
22897 ID3D11ShaderResourceView_Release(srv);
22899 ID3D11PixelShader_Release(ps);
22901 ID3D11Buffer_Release(cb);
22902 ID3D11RenderTargetView_Release(rtv);
22903 ID3D11Texture2D_Release(rtv_texture);
22904 release_test_context(&test_context);
22907 static void test_sm5_bufinfo_instruction(void)
22909 struct shader
22911 const DWORD *code;
22912 size_t size;
22915 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22916 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
22917 struct d3d11_test_context test_context;
22918 D3D11_TEXTURE2D_DESC texture_desc;
22919 const struct shader *current_ps;
22920 ID3D11UnorderedAccessView *uav;
22921 ID3D11ShaderResourceView *srv;
22922 D3D11_BUFFER_DESC buffer_desc;
22923 ID3D11DeviceContext *context;
22924 ID3D11RenderTargetView *rtv;
22925 ID3D11Texture2D *texture;
22926 ID3D11PixelShader *ps;
22927 ID3D11Buffer *buffer;
22928 ID3D11Device *device;
22929 unsigned int i;
22930 HRESULT hr;
22932 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22933 static const DWORD ps_uav_structured_code[] =
22935 #if 0
22936 struct s
22938 uint4 u;
22939 bool b;
22942 RWStructuredBuffer<s> b;
22944 uint4 main(void) : SV_Target
22946 uint count, stride;
22947 b.GetDimensions(count, stride);
22948 return uint4(count, stride, 0, 1);
22950 #endif
22951 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
22952 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22953 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
22954 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
22955 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
22956 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
22957 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
22958 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
22960 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
22961 static const DWORD ps_uav_structured32_code[] =
22963 #if 0
22964 struct s
22966 uint4 u;
22967 bool4 b;
22970 RWStructuredBuffer<s> b;
22972 uint4 main(void) : SV_Target
22974 uint count, stride;
22975 b.GetDimensions(count, stride);
22976 return uint4(count, stride, 0, 1);
22978 #endif
22979 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
22980 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22981 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
22982 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
22983 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
22984 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
22985 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
22986 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
22988 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
22989 static const DWORD ps_srv_structured_code[] =
22991 #if 0
22992 StructuredBuffer<bool> b;
22994 uint4 main(void) : SV_Target
22996 uint count, stride;
22997 b.GetDimensions(count, stride);
22998 return uint4(count, stride, 0, 1);
23000 #endif
23001 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
23002 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23003 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23004 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
23005 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
23006 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
23007 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
23008 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
23010 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
23011 static const DWORD ps_uav_raw_code[] =
23013 #if 0
23014 RWByteAddressBuffer b;
23016 uint4 main(void) : SV_Target
23018 uint width;
23019 b.GetDimensions(width);
23020 return width;
23022 #endif
23023 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
23024 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23025 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23026 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
23027 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
23028 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
23029 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23031 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
23032 static const DWORD ps_srv_raw_code[] =
23034 #if 0
23035 ByteAddressBuffer b;
23037 uint4 main(void) : SV_Target
23039 uint width;
23040 b.GetDimensions(width);
23041 return width;
23043 #endif
23044 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
23045 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23046 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23047 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
23048 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
23049 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
23050 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23052 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
23053 static const DWORD ps_uav_typed_code[] =
23055 #if 0
23056 RWBuffer<float> b;
23058 uint4 main(void) : SV_Target
23060 uint width;
23061 b.GetDimensions(width);
23062 return width;
23064 #endif
23065 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
23066 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23067 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23068 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
23069 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23070 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
23071 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23073 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
23074 static const DWORD ps_srv_typed_code[] =
23076 #if 0
23077 Buffer<float> b;
23079 uint4 main(void) : SV_Target
23081 uint width;
23082 b.GetDimensions(width);
23083 return width;
23085 #endif
23086 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
23087 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23088 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23089 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
23090 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23091 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
23092 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23094 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
23095 static const struct test
23097 const struct shader *ps;
23098 BOOL uav;
23099 unsigned int buffer_size;
23100 unsigned int buffer_misc_flags;
23101 unsigned int buffer_structure_byte_stride;
23102 DXGI_FORMAT view_format;
23103 unsigned int view_element_idx;
23104 unsigned int view_element_count;
23105 struct uvec4 expected_result;
23107 tests[] =
23109 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
23110 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
23111 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
23112 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
23113 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
23114 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
23115 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
23116 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
23117 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
23118 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
23119 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
23120 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
23121 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
23122 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
23123 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
23124 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
23125 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
23126 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
23127 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
23128 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
23129 #undef RAW
23130 #undef STRUCTURED
23133 if (!init_test_context(&test_context, &feature_level))
23134 return;
23136 device = test_context.device;
23137 context = test_context.immediate_context;
23139 texture_desc.Width = 64;
23140 texture_desc.Height = 64;
23141 texture_desc.MipLevels = 1;
23142 texture_desc.ArraySize = 1;
23143 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
23144 texture_desc.SampleDesc.Count = 1;
23145 texture_desc.SampleDesc.Quality = 0;
23146 texture_desc.Usage = D3D11_USAGE_DEFAULT;
23147 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23148 texture_desc.CPUAccessFlags = 0;
23149 texture_desc.MiscFlags = 0;
23150 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23151 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
23152 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23153 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
23155 ps = NULL;
23156 current_ps = NULL;
23157 for (i = 0; i < ARRAY_SIZE(tests); ++i)
23159 const struct test *test = &tests[i];
23161 if (current_ps != test->ps)
23163 if (ps)
23164 ID3D11PixelShader_Release(ps);
23166 current_ps = test->ps;
23168 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
23169 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
23170 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23173 buffer_desc.ByteWidth = test->buffer_size;
23174 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23175 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
23176 buffer_desc.CPUAccessFlags = 0;
23177 buffer_desc.MiscFlags = test->buffer_misc_flags;
23178 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
23179 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
23180 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
23182 if (test->uav)
23184 uav_desc.Format = test->view_format;
23185 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
23186 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
23187 U(uav_desc).Buffer.NumElements = test->view_element_count;
23188 U(uav_desc).Buffer.Flags = 0;
23189 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
23190 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
23191 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
23192 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
23193 srv = NULL;
23195 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
23196 1, 1, &uav, NULL);
23198 else
23200 srv_desc.Format = test->view_format;
23201 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
23202 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
23203 U(srv_desc).BufferEx.NumElements = test->view_element_count;
23204 U(srv_desc).BufferEx.Flags = 0;
23205 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
23206 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
23207 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
23208 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
23209 uav = NULL;
23211 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23212 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23215 draw_quad(&test_context);
23216 check_texture_uvec4(texture, &test->expected_result);
23218 if (srv)
23219 ID3D11ShaderResourceView_Release(srv);
23220 if (uav)
23221 ID3D11UnorderedAccessView_Release(uav);
23222 ID3D11Buffer_Release(buffer);
23224 ID3D11PixelShader_Release(ps);
23226 ID3D11RenderTargetView_Release(rtv);
23227 ID3D11Texture2D_Release(texture);
23228 release_test_context(&test_context);
23231 static void test_sampleinfo_instruction(void)
23233 ID3D11Texture2D *float_rt_texture, *uint_rt_texture;
23234 ID3D11RenderTargetView *float_rtv, *uint_rtv, *rtv;
23235 ID3D11PixelShader *ps_float, *ps_uint, *ps_rt;
23236 ID3D11Texture2D *texture, *readback_texture;
23237 struct d3d11_test_context test_context;
23238 unsigned int sample_count, quality;
23239 D3D11_TEXTURE2D_DESC texture_desc;
23240 ID3D11RenderTargetView *rtvs[2];
23241 ID3D11ShaderResourceView *srv;
23242 ID3D11DeviceContext *context;
23243 struct uvec4 expected_uint;
23244 struct vec4 expected_float;
23245 ID3D11Device *device;
23246 HRESULT hr;
23248 static const DWORD ps_uint_code[] =
23250 #if 0
23251 Texture2DMS<float> t;
23253 uint4 main() : SV_Target1
23255 uint width, height, sample_count;
23256 t.GetDimensions(width, height, sample_count);
23257 return sample_count;
23259 #endif
23260 0x43425844, 0x4342ad12, 0x19addd8c, 0x5cb87c48, 0xe604a242, 0x00000001, 0x000000d4, 0x00000003,
23261 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23262 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
23263 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
23264 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000001,
23265 0x02000068, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a, 0x00000000, 0x05000036,
23266 0x001020f2, 0x00000001, 0x00100006, 0x00000000, 0x0100003e,
23268 static const DWORD ps_float_code[] =
23270 #if 0
23271 Texture2DMS<float> t;
23273 float4 main() : SV_Target
23275 uint width, height, sample_count;
23276 t.GetDimensions(width, height, sample_count);
23277 return sample_count;
23279 #endif
23280 0x43425844, 0x2b8aea46, 0x34ceda6f, 0xf98d222b, 0x235ebc0b, 0x00000001, 0x000000b8, 0x00000003,
23281 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23282 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23283 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000040, 0x00000050, 0x00000010,
23284 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23285 0x0500006f, 0x001020f2, 0x00000000, 0x0010700a, 0x00000000, 0x0100003e,
23287 static const DWORD ps_rt_code[] =
23289 #if 0
23290 float4 main() : SV_Target
23292 return GetRenderTargetSampleCount();
23294 #endif
23295 0x43425844, 0x74404d37, 0xad6f88e4, 0xb006ea57, 0xf07d9e2a, 0x00000001, 0x000000a4, 0x00000003,
23296 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23297 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23298 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000002c, 0x00000050, 0x0000000b,
23299 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x0400006f, 0x001020f2, 0x00000000, 0x0000e00a,
23300 0x0100003e,
23302 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23304 if (!init_test_context(&test_context, &feature_level))
23305 return;
23307 device = test_context.device;
23308 context = test_context.immediate_context;
23310 texture_desc.Width = 64;
23311 texture_desc.Height = 64;
23312 texture_desc.MipLevels = 1;
23313 texture_desc.ArraySize = 1;
23314 texture_desc.SampleDesc.Count = 1;
23315 texture_desc.SampleDesc.Quality = 0;
23316 texture_desc.Usage = D3D11_USAGE_DEFAULT;
23317 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23318 texture_desc.CPUAccessFlags = 0;
23319 texture_desc.MiscFlags = 0;
23321 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
23322 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &float_rt_texture);
23323 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23324 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)float_rt_texture, NULL, &float_rtv);
23325 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
23326 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
23327 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &uint_rt_texture);
23328 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23329 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)uint_rt_texture, NULL, &uint_rtv);
23330 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
23332 rtvs[0] = float_rtv;
23333 rtvs[1] = uint_rtv;
23334 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
23336 hr = ID3D11Device_CreatePixelShader(device, ps_float_code, sizeof(ps_float_code), NULL, &ps_float);
23337 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23338 hr = ID3D11Device_CreatePixelShader(device, ps_uint_code, sizeof(ps_uint_code), NULL, &ps_uint);
23339 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23341 for (sample_count = 2; sample_count <= 8; sample_count *= 2)
23343 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
23344 texture_desc.SampleDesc.Count = sample_count;
23345 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
23347 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
23348 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
23349 if (!quality)
23351 skip("Sample count %u not supported.\n", sample_count);
23352 continue;
23355 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23356 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
23357 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
23358 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
23359 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23361 ID3D11DeviceContext_PSSetShader(context, ps_float, NULL, 0);
23362 draw_quad(&test_context);
23363 ID3D11DeviceContext_PSSetShader(context, ps_uint, NULL, 0);
23364 draw_quad(&test_context);
23366 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
23367 check_texture_vec4(float_rt_texture, &expected_float, 0);
23368 expected_uint.x = expected_uint.y = expected_uint.z = expected_uint.w = sample_count;
23369 check_texture_uvec4(uint_rt_texture, &expected_uint);
23371 ID3D11Texture2D_Release(texture);
23372 ID3D11ShaderResourceView_Release(srv);
23375 hr = ID3D11Device_CreatePixelShader(device, ps_rt_code, sizeof(ps_rt_code), NULL, &ps_rt);
23376 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23377 for (sample_count = 1; sample_count <= 8; sample_count *= 2)
23379 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
23380 texture_desc.SampleDesc.Count = sample_count;
23381 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23383 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
23384 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
23385 if (!quality)
23387 skip("Sample count %u not supported.\n", sample_count);
23388 continue;
23391 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23392 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
23393 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23394 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
23395 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23397 /* Some drivers (AMD Radeon HD 6310) return stale sample counts if we
23398 * don't rebind the pixel shader between runs with different sample
23399 * counts. */
23400 ID3D11DeviceContext_PSSetShader(context, NULL, NULL, 0);
23401 ID3D11DeviceContext_PSSetShader(context, ps_rt, NULL, 0);
23402 draw_quad(&test_context);
23404 if (sample_count != 1)
23406 texture_desc.SampleDesc.Count = 1;
23407 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
23408 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23409 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
23410 (ID3D11Resource *)texture, 0, texture_desc.Format);
23412 else
23414 readback_texture = texture;
23415 ID3D11Texture2D_AddRef(readback_texture);
23418 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
23419 check_texture_vec4(readback_texture, &expected_float, 0);
23421 ID3D11Texture2D_Release(readback_texture);
23422 ID3D11Texture2D_Release(texture);
23423 ID3D11RenderTargetView_Release(rtv);
23426 ID3D11RenderTargetView_Release(float_rtv);
23427 ID3D11RenderTargetView_Release(uint_rtv);
23428 ID3D11Texture2D_Release(float_rt_texture);
23429 ID3D11Texture2D_Release(uint_rt_texture);
23430 ID3D11PixelShader_Release(ps_float);
23431 ID3D11PixelShader_Release(ps_uint);
23432 ID3D11PixelShader_Release(ps_rt);
23433 release_test_context(&test_context);
23436 static void test_render_target_device_mismatch(void)
23438 struct d3d11_test_context test_context;
23439 struct device_desc device_desc = {0};
23440 ID3D11DeviceContext *context;
23441 ID3D11RenderTargetView *rtv;
23442 ID3D11Device *device;
23443 ULONG refcount;
23445 if (!init_test_context(&test_context, NULL))
23446 return;
23448 device = create_device(&device_desc);
23449 ok(!!device, "Failed to create device.\n");
23451 ID3D11Device_GetImmediateContext(device, &context);
23453 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
23454 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
23455 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
23456 if (!enable_debug_layer)
23458 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
23459 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
23460 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
23461 ID3D11RenderTargetView_Release(rtv);
23464 rtv = NULL;
23465 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23467 ID3D11DeviceContext_Release(context);
23468 refcount = ID3D11Device_Release(device);
23469 ok(!refcount, "Device has %u references left.\n", refcount);
23470 release_test_context(&test_context);
23473 static void test_buffer_srv(void)
23475 struct shader
23477 const DWORD *code;
23478 size_t size;
23479 BOOL requires_raw_and_structured_buffers;
23481 struct buffer
23483 unsigned int byte_count;
23484 unsigned int data_offset;
23485 const void *data;
23486 unsigned int structure_byte_stride;
23489 BOOL raw_and_structured_buffers_supported;
23490 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
23491 struct d3d11_test_context test_context;
23492 D3D11_SUBRESOURCE_DATA resource_data;
23493 const struct buffer *current_buffer;
23494 const struct shader *current_shader;
23495 ID3D11ShaderResourceView *srv;
23496 D3D11_BUFFER_DESC buffer_desc;
23497 ID3D11DeviceContext *context;
23498 DWORD color, expected_color;
23499 struct resource_readback rb;
23500 ID3D11Buffer *cb, *buffer;
23501 ID3D11PixelShader *ps;
23502 ID3D11Device *device;
23503 unsigned int i, x, y;
23504 struct vec4 cb_size;
23505 HRESULT hr;
23507 static const DWORD ps_float4_code[] =
23509 #if 0
23510 Buffer<float4> b;
23512 float2 size;
23514 float4 main(float4 position : SV_POSITION) : SV_Target
23516 float2 p;
23517 int2 coords;
23518 p.x = position.x / 640.0f;
23519 p.y = position.y / 480.0f;
23520 coords = int2(p.x * size.x, p.y * size.y);
23521 return b.Load(coords.y * size.x + coords.x);
23523 #endif
23524 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
23525 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
23526 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
23527 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
23528 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
23529 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
23530 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
23531 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
23532 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
23533 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
23534 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
23535 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
23536 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
23538 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
23539 static const DWORD ps_structured_code[] =
23541 #if 0
23542 StructuredBuffer<float4> b;
23544 float2 size;
23546 float4 main(float4 position : SV_POSITION) : SV_Target
23548 float2 p;
23549 int2 coords;
23550 p.x = position.x / 640.0f;
23551 p.y = position.y / 480.0f;
23552 coords = int2(p.x * size.x, p.y * size.y);
23553 return b[coords.y * size.x + coords.x];
23555 #endif
23556 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
23557 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
23558 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
23559 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
23560 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
23561 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
23562 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
23563 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
23564 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
23565 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
23566 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
23567 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
23568 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
23569 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
23571 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
23572 static const DWORD rgba16[] =
23574 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
23575 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
23576 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
23577 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
23579 static const DWORD rgba4[] =
23581 0xffffffff, 0xff0000ff,
23582 0xff000000, 0xff00ff00,
23584 static const BYTE r4[] =
23586 0xde, 0xad,
23587 0xba, 0xbe,
23589 static const struct vec4 rgba_float[] =
23591 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
23592 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
23594 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
23595 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
23596 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
23597 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
23598 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
23599 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
23600 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
23601 &rgba_float, sizeof(*rgba_float)};
23602 static const DWORD rgba16_colors2x2[] =
23604 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
23605 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
23606 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
23607 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
23609 static const DWORD rgba16_colors1x1[] =
23611 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23612 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23613 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23614 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23616 static const DWORD rgba4_colors[] =
23618 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
23619 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
23620 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
23621 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
23623 static const DWORD r4_colors[] =
23625 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
23626 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
23627 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
23628 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
23630 static const DWORD zero_colors[16] = {0};
23631 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
23633 static const struct test
23635 const struct shader *shader;
23636 const struct buffer *buffer;
23637 DXGI_FORMAT srv_format;
23638 unsigned int srv_first_element;
23639 unsigned int srv_element_count;
23640 struct vec2 size;
23641 const DWORD *expected_colors;
23643 tests[] =
23645 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
23646 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
23647 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
23648 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
23649 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
23650 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
23651 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
23652 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
23653 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
23654 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
23655 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
23658 if (!init_test_context(&test_context, NULL))
23659 return;
23661 device = test_context.device;
23662 context = test_context.immediate_context;
23663 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
23664 || check_compute_shaders_via_sm4_support(device);
23666 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
23667 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
23669 buffer_desc.ByteWidth = 256;
23670 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23671 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23672 buffer_desc.CPUAccessFlags = 0;
23673 buffer_desc.MiscFlags = 0;
23674 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
23675 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23676 srv_desc.Format = DXGI_FORMAT_R8_UNORM;
23677 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
23678 U(srv_desc).Buffer.FirstElement = 0;
23679 U(srv_desc).Buffer.NumElements = 0;
23680 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
23681 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
23682 ID3D11Buffer_Release(buffer);
23684 ps = NULL;
23685 srv = NULL;
23686 buffer = NULL;
23687 current_shader = NULL;
23688 current_buffer = NULL;
23689 for (i = 0; i < ARRAY_SIZE(tests); ++i)
23691 const struct test *test = &tests[i];
23693 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
23695 skip("Test %u: Raw and structured buffers are not supported.\n", i);
23696 continue;
23698 /* Structured buffer views with an offset don't seem to work on WARP. */
23699 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
23700 && is_warp_device(device))
23702 skip("Test %u: Broken WARP.\n", i);
23703 continue;
23706 if (current_shader != test->shader)
23708 if (ps)
23709 ID3D11PixelShader_Release(ps);
23711 current_shader = test->shader;
23713 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
23714 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
23715 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23718 if (current_buffer != test->buffer)
23720 if (buffer)
23721 ID3D11Buffer_Release(buffer);
23723 current_buffer = test->buffer;
23724 if (current_buffer)
23726 BYTE *data = NULL;
23728 buffer_desc.ByteWidth = current_buffer->byte_count;
23729 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23730 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23731 buffer_desc.CPUAccessFlags = 0;
23732 buffer_desc.MiscFlags = 0;
23733 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
23734 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
23735 resource_data.SysMemPitch = 0;
23736 resource_data.SysMemSlicePitch = 0;
23737 if (current_buffer->data_offset)
23739 data = heap_alloc_zero(current_buffer->byte_count);
23740 ok(!!data, "Failed to allocate memory.\n");
23741 memcpy(data + current_buffer->data_offset, current_buffer->data,
23742 current_buffer->byte_count - current_buffer->data_offset);
23743 resource_data.pSysMem = data;
23745 else
23747 resource_data.pSysMem = current_buffer->data;
23749 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
23750 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
23751 heap_free(data);
23753 else
23755 buffer = NULL;
23759 if (srv)
23760 ID3D11ShaderResourceView_Release(srv);
23761 if (current_buffer)
23763 srv_desc.Format = test->srv_format;
23764 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
23765 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
23766 U(srv_desc).Buffer.NumElements = test->srv_element_count;
23767 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
23768 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
23770 else
23772 srv = NULL;
23774 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23776 cb_size.x = test->size.x;
23777 cb_size.y = test->size.y;
23778 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
23780 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
23781 draw_quad(&test_context);
23783 get_texture_readback(test_context.backbuffer, 0, &rb);
23784 for (y = 0; y < 4; ++y)
23786 for (x = 0; x < 4; ++x)
23788 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
23789 expected_color = test->expected_colors[y * 4 + x];
23790 ok(compare_color(color, expected_color, 1),
23791 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
23792 i, color, expected_color, x, y);
23795 release_resource_readback(&rb);
23797 if (srv)
23798 ID3D11ShaderResourceView_Release(srv);
23799 if (buffer)
23800 ID3D11Buffer_Release(buffer);
23802 ID3D11Buffer_Release(cb);
23803 ID3D11PixelShader_Release(ps);
23804 release_test_context(&test_context);
23807 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
23809 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
23810 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
23811 struct d3d11_test_context test_context;
23812 D3D11_SUBRESOURCE_DATA resource_data;
23813 D3D11_TEXTURE2D_DESC texture_desc;
23814 ID3D11UnorderedAccessView *uav;
23815 ID3D11ShaderResourceView *srv;
23816 D3D11_BUFFER_DESC buffer_desc;
23817 ID3D11Buffer *cb, *raw_buffer;
23818 ID3D11DeviceContext *context;
23819 struct resource_readback rb;
23820 ID3D11RenderTargetView *rtv;
23821 ID3D11Texture2D *texture;
23822 ID3D11ComputeShader *cs;
23823 ID3D11PixelShader *ps;
23824 ID3D11Device *device;
23825 unsigned int i, data;
23826 struct uvec4 offset;
23827 HRESULT hr;
23829 static const unsigned int buffer_data[] =
23831 0xffffffff, 0x00000000,
23833 static const DWORD ps_code[] =
23835 #if 0
23836 ByteAddressBuffer buffer;
23838 uint offset;
23840 uint main() : SV_Target0
23842 return buffer.Load(offset);
23844 #endif
23845 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
23846 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
23847 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
23848 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
23849 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
23850 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
23851 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
23852 0x00000000,
23854 static const DWORD cs_code[] =
23856 #if 0
23857 RWByteAddressBuffer buffer;
23859 uint2 input;
23861 [numthreads(1, 1, 1)]
23862 void main()
23864 buffer.Store(input.x, input.y);
23866 #endif
23867 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
23868 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23869 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
23870 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
23871 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
23872 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
23874 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
23876 if (!init_test_context(&test_context, &feature_level))
23877 return;
23879 device = test_context.device;
23880 context = test_context.immediate_context;
23882 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
23884 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
23885 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
23886 if (SUCCEEDED(hr))
23887 ID3D11PixelShader_Release(ps);
23888 skip("Raw buffers are not supported.\n");
23889 release_test_context(&test_context);
23890 return;
23893 if (is_intel_device(device))
23895 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
23896 * This test checks what happens when offsets are not properly aligned.
23897 * The behavior seems to be undefined on Intel hardware. */
23898 win_skip("Skipping the test on Intel hardware.\n");
23899 release_test_context(&test_context);
23900 return;
23903 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
23904 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
23906 memset(&offset, 0, sizeof(offset));
23907 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
23909 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
23910 texture_desc.Format = DXGI_FORMAT_R32_UINT;
23911 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23912 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
23913 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23914 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
23916 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23918 buffer_desc.ByteWidth = sizeof(buffer_data);
23919 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23920 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23921 buffer_desc.CPUAccessFlags = 0;
23922 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
23923 resource_data.pSysMem = buffer_data;
23924 resource_data.SysMemPitch = 0;
23925 resource_data.SysMemSlicePitch = 0;
23926 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
23927 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23929 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
23930 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
23931 U(srv_desc).BufferEx.FirstElement = 0;
23932 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
23933 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
23934 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
23935 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
23937 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23938 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
23939 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23941 offset.x = 0;
23942 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23943 NULL, &offset, 0, 0);
23944 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23945 draw_quad(&test_context);
23946 check_texture_color(texture, buffer_data[0], 0);
23947 offset.x = 1;
23948 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23949 NULL, &offset, 0, 0);
23950 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23951 draw_quad(&test_context);
23952 check_texture_color(texture, buffer_data[0], 0);
23953 offset.x = 2;
23954 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23955 NULL, &offset, 0, 0);
23956 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23957 draw_quad(&test_context);
23958 check_texture_color(texture, buffer_data[0], 0);
23959 offset.x = 3;
23960 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23961 NULL, &offset, 0, 0);
23962 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23963 draw_quad(&test_context);
23964 check_texture_color(texture, buffer_data[0], 0);
23966 offset.x = 4;
23967 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23968 NULL, &offset, 0, 0);
23969 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23970 draw_quad(&test_context);
23971 check_texture_color(texture, buffer_data[1], 0);
23972 offset.x = 7;
23973 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23974 NULL, &offset, 0, 0);
23975 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23976 draw_quad(&test_context);
23977 check_texture_color(texture, buffer_data[1], 0);
23979 if (feature_level < D3D_FEATURE_LEVEL_11_0)
23981 skip("Feature level 11_0 required for unaligned UAV test.\n");
23982 goto done;
23985 ID3D11Buffer_Release(raw_buffer);
23986 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
23987 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
23988 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23990 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
23991 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
23992 U(uav_desc).Buffer.FirstElement = 0;
23993 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
23994 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
23995 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
23996 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
23998 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
23999 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24001 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24002 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
24003 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24005 offset.x = 0;
24006 offset.y = 0xffffffff;
24007 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24008 NULL, &offset, 0, 0);
24009 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24010 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24011 get_buffer_readback(raw_buffer, &rb);
24012 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24014 data = get_readback_color(&rb, i, 0, 0);
24015 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24017 release_resource_readback(&rb);
24019 offset.x = 1;
24020 offset.y = 0xffffffff;
24021 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24022 NULL, &offset, 0, 0);
24023 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24024 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24025 get_buffer_readback(raw_buffer, &rb);
24026 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24028 data = get_readback_color(&rb, i, 0, 0);
24029 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24031 release_resource_readback(&rb);
24033 offset.x = 2;
24034 offset.y = 0xffffffff;
24035 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24036 NULL, &offset, 0, 0);
24037 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24038 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24039 get_buffer_readback(raw_buffer, &rb);
24040 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24042 data = get_readback_color(&rb, i, 0, 0);
24043 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24045 release_resource_readback(&rb);
24047 offset.x = 3;
24048 offset.y = 0xffffffff;
24049 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24050 NULL, &offset, 0, 0);
24051 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24052 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24053 get_buffer_readback(raw_buffer, &rb);
24054 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24056 data = get_readback_color(&rb, i, 0, 0);
24057 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24059 release_resource_readback(&rb);
24061 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24062 offset.x = 3;
24063 offset.y = 0xffff;
24064 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24065 NULL, &offset, 0, 0);
24066 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24067 offset.x = 4;
24068 offset.y = 0xa;
24069 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24070 NULL, &offset, 0, 0);
24071 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24072 get_buffer_readback(raw_buffer, &rb);
24073 data = get_readback_color(&rb, 0, 0, 0);
24074 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
24075 data = get_readback_color(&rb, 1, 0, 0);
24076 ok(data == 0xa, "Got unexpected result %#x.\n", data);
24077 release_resource_readback(&rb);
24079 ID3D11ComputeShader_Release(cs);
24080 ID3D11UnorderedAccessView_Release(uav);
24082 done:
24083 ID3D11Buffer_Release(cb);
24084 ID3D11Buffer_Release(raw_buffer);
24085 ID3D11PixelShader_Release(ps);
24086 ID3D11RenderTargetView_Release(rtv);
24087 ID3D11ShaderResourceView_Release(srv);
24088 ID3D11Texture2D_Release(texture);
24089 release_test_context(&test_context);
24092 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
24093 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
24095 D3D11_MAPPED_SUBRESOURCE map_desc;
24096 unsigned int counter;
24098 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
24100 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
24101 D3D11_MAP_READ, 0, &map_desc)))
24102 return 0xdeadbeef;
24103 counter = *(unsigned int *)map_desc.pData;
24104 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
24105 return counter;
24108 static int compare_id(const void *a, const void *b)
24110 return *(int *)a - *(int *)b;
24113 static void test_uav_counters(void)
24115 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
24116 ID3D11ComputeShader *cs_producer, *cs_consumer;
24117 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24118 struct d3d11_test_context test_context;
24119 ID3D11UnorderedAccessView *uav, *uav2;
24120 unsigned int data, id[128], i;
24121 D3D11_BUFFER_DESC buffer_desc;
24122 ID3D11DeviceContext *context;
24123 struct resource_readback rb;
24124 ID3D11Device *device;
24125 D3D11_BOX box;
24126 HRESULT hr;
24128 static const DWORD cs_producer_code[] =
24130 #if 0
24131 RWStructuredBuffer<uint> u;
24133 [numthreads(4, 1, 1)]
24134 void main(uint3 dispatch_id : SV_DispatchThreadID)
24136 uint counter = u.IncrementCounter();
24137 u[counter] = dispatch_id.x;
24139 #endif
24140 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
24141 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24142 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
24143 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
24144 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
24145 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
24146 0x0002000a, 0x0100003e,
24148 static const DWORD cs_consumer_code[] =
24150 #if 0
24151 RWStructuredBuffer<uint> u;
24152 RWStructuredBuffer<uint> u2;
24154 [numthreads(4, 1, 1)]
24155 void main()
24157 uint counter = u.DecrementCounter();
24158 u2[counter] = u[counter];
24160 #endif
24161 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
24162 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24163 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
24164 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
24165 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
24166 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
24167 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
24168 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
24170 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24172 if (!init_test_context(&test_context, &feature_level))
24173 return;
24175 device = test_context.device;
24176 context = test_context.immediate_context;
24178 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
24179 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24180 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
24181 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24183 memset(&buffer_desc, 0, sizeof(buffer_desc));
24184 buffer_desc.ByteWidth = sizeof(unsigned int);
24185 buffer_desc.Usage = D3D11_USAGE_STAGING;
24186 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
24187 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
24188 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24190 buffer_desc.ByteWidth = 1024;
24191 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24192 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24193 buffer_desc.CPUAccessFlags = 0;
24194 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24195 buffer_desc.StructureByteStride = sizeof(unsigned int);
24196 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24197 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24198 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
24199 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24200 U(uav_desc).Buffer.FirstElement = 0;
24201 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
24202 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
24203 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24204 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24205 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
24206 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24207 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
24208 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24210 data = read_uav_counter(context, staging_buffer, uav);
24211 ok(!data, "Got unexpected initial value %u.\n", data);
24212 data = 8;
24213 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24214 data = read_uav_counter(context, staging_buffer, uav);
24215 ok(data == 8, "Got unexpected value %u.\n", data);
24216 data = ~0u;
24217 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24218 data = read_uav_counter(context, staging_buffer, uav);
24219 ok(data == 8, "Got unexpected value %u.\n", data);
24220 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24221 data = read_uav_counter(context, staging_buffer, uav);
24222 ok(data == 8, "Got unexpected value %u.\n", data);
24224 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
24225 data = 0;
24226 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24227 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
24228 data = read_uav_counter(context, staging_buffer, uav);
24229 ok(!data, "Got unexpected value %u.\n", data);
24231 /* produce */
24232 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
24233 data = read_uav_counter(context, staging_buffer, uav);
24234 ok(data == 64, "Got unexpected value %u.\n", data);
24235 get_buffer_readback(buffer, &rb);
24236 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
24237 release_resource_readback(&rb);
24238 qsort(id, 64, sizeof(*id), compare_id);
24239 for (i = 0; i < 64; ++i)
24241 if (id[i] != i)
24242 break;
24244 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
24246 /* consume */
24247 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
24248 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
24249 data = read_uav_counter(context, staging_buffer, uav);
24250 ok(!data, "Got unexpected value %u.\n", data);
24251 get_buffer_readback(buffer2, &rb);
24252 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
24253 release_resource_readback(&rb);
24254 qsort(id, 64, sizeof(*id), compare_id);
24255 for (i = 0; i < 64; ++i)
24257 if (id[i] != i)
24258 break;
24260 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
24262 /* produce on CPU */
24263 for (i = 0; i < 8; ++i)
24264 id[i] = 0xdeadbeef;
24265 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
24266 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
24267 data = 8;
24268 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24269 data = read_uav_counter(context, staging_buffer, uav);
24270 ok(data == 8, "Got unexpected value %u.\n", data);
24272 /* consume */
24273 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24274 data = read_uav_counter(context, staging_buffer, uav);
24275 ok(data == 4, "Got unexpected value %u.\n", data);
24276 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24277 data = read_uav_counter(context, staging_buffer, uav);
24278 ok(!data, "Got unexpected value %u.\n", data);
24279 get_buffer_readback(buffer2, &rb);
24280 for (i = 0; i < 8; ++i)
24282 data = get_readback_color(&rb, i, 0, 0);
24283 ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
24285 release_resource_readback(&rb);
24287 ID3D11Buffer_Release(buffer);
24288 ID3D11Buffer_Release(buffer2);
24289 ID3D11Buffer_Release(staging_buffer);
24290 ID3D11ComputeShader_Release(cs_producer);
24291 ID3D11ComputeShader_Release(cs_consumer);
24292 ID3D11UnorderedAccessView_Release(uav);
24293 ID3D11UnorderedAccessView_Release(uav2);
24294 release_test_context(&test_context);
24297 static void test_dispatch_indirect(void)
24299 struct stats
24301 unsigned int dispatch_count;
24302 unsigned int thread_count;
24303 unsigned int max_x;
24304 unsigned int max_y;
24305 unsigned int max_z;
24308 ID3D11Buffer *append_buffer, *stats_buffer, *args_buffer, *staging_buffer;
24309 ID3D11UnorderedAccessView *uav, *stats_uav;
24310 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24311 ID3D11ComputeShader *cs_append, *cs_stats;
24312 struct d3d11_test_context test_context;
24313 D3D11_BUFFER_DESC buffer_desc;
24314 ID3D11DeviceContext *context;
24315 struct resource_readback rb;
24316 ID3D11Device *device;
24317 unsigned int data, i;
24318 struct stats *stats;
24319 HRESULT hr;
24321 static const DWORD cs_append_code[] =
24323 #if 0
24324 struct dispatch_args
24326 uint x, y, z;
24329 AppendStructuredBuffer<dispatch_args> u;
24331 [numthreads(1, 1, 1)]
24332 void main()
24334 dispatch_args args = {4, 2, 1};
24335 u.Append(args);
24336 args.y = 1;
24337 u.Append(args);
24338 args.x = 3;
24339 u.Append(args);
24341 #endif
24342 0x43425844, 0x954de75a, 0x8bb1b78b, 0x84ded464, 0x9d9532b7, 0x00000001, 0x00000158, 0x00000003,
24343 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24344 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000104, 0x00050050, 0x00000041, 0x0100086a,
24345 0x0400009e, 0x0011e000, 0x00000000, 0x0000000c, 0x02000068, 0x00000001, 0x0400009b, 0x00000001,
24346 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x0c0000a8,
24347 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002, 0x00000004,
24348 0x00000002, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000,
24349 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002,
24350 0x00000004, 0x00000001, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
24351 0x00000000, 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
24352 0x00004002, 0x00000003, 0x00000001, 0x00000001, 0x00000000, 0x0100003e,
24354 static const DWORD cs_stats_code[] =
24356 #if 0
24357 struct stats
24359 uint dispatch_count;
24360 uint thread_count;
24361 uint max_x;
24362 uint max_y;
24363 uint max_z;
24366 RWStructuredBuffer<stats> u;
24368 [numthreads(1, 1, 1)]
24369 void main(uint3 id : SV_DispatchThreadID)
24371 if (all(!id))
24372 InterlockedAdd(u[0].dispatch_count, 1);
24373 InterlockedAdd(u[0].thread_count, 1);
24374 InterlockedMax(u[0].max_x, id.x);
24375 InterlockedMax(u[0].max_y, id.y);
24376 InterlockedMax(u[0].max_z, id.z);
24378 #endif
24379 0x43425844, 0xbd3f2e4e, 0xb0f61ff7, 0xa8e10584, 0x2f61aec9, 0x00000001, 0x000001bc, 0x00000003,
24380 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24381 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000168, 0x00050050, 0x0000005a, 0x0100086a,
24382 0x0400009e, 0x0011e000, 0x00000000, 0x00000014, 0x0200005f, 0x00020072, 0x02000068, 0x00000001,
24383 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x09000020, 0x00100072, 0x00000000, 0x00020246,
24384 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000001, 0x00100012, 0x00000000,
24385 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00100012, 0x00000000, 0x0010002a,
24386 0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x0a0000ad, 0x0011e000,
24387 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001,
24388 0x01000015, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000,
24389 0x00000000, 0x00004001, 0x00000001, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002, 0x00000000,
24390 0x00000008, 0x00000000, 0x00000000, 0x0002000a, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002,
24391 0x00000000, 0x0000000c, 0x00000000, 0x00000000, 0x0002001a, 0x090000b0, 0x0011e000, 0x00000000,
24392 0x00004002, 0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x0002002a, 0x0100003e,
24394 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24395 static const unsigned int zero[4] = {0, 0, 0, 0};
24397 if (!init_test_context(&test_context, &feature_level))
24398 return;
24400 device = test_context.device;
24401 context = test_context.immediate_context;
24403 hr = ID3D11Device_CreateComputeShader(device, cs_append_code, sizeof(cs_append_code), NULL, &cs_append);
24404 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24405 hr = ID3D11Device_CreateComputeShader(device, cs_stats_code, sizeof(cs_stats_code), NULL, &cs_stats);
24406 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24408 memset(&buffer_desc, 0, sizeof(buffer_desc));
24409 buffer_desc.ByteWidth = sizeof(unsigned int);
24410 buffer_desc.Usage = D3D11_USAGE_STAGING;
24411 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
24412 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
24413 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24415 buffer_desc.ByteWidth = 60;
24416 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24417 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24418 buffer_desc.CPUAccessFlags = 0;
24419 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24420 buffer_desc.StructureByteStride = 3 * sizeof(unsigned int);
24421 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &append_buffer);
24422 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24423 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
24424 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24425 U(uav_desc).Buffer.FirstElement = 0;
24426 U(uav_desc).Buffer.NumElements = 5;
24427 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
24428 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)append_buffer, &uav_desc, &uav);
24429 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24431 /* We use a separate buffer because D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
24432 * and D3D11_RESOURCE_MISC_BUFFER_STRUCTURED are mutually exclusive flags.
24434 buffer_desc.BindFlags = 0;
24435 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
24436 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &args_buffer);
24437 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24439 buffer_desc.ByteWidth = sizeof(*stats);
24440 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24441 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24442 buffer_desc.StructureByteStride = sizeof(*stats);
24443 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &stats_buffer);
24444 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24445 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)stats_buffer, NULL, &stats_uav);
24446 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24448 data = read_uav_counter(context, staging_buffer, uav);
24449 ok(!data, "Got unexpected initial value %u.\n", data);
24450 data = 8;
24451 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24452 data = read_uav_counter(context, staging_buffer, uav);
24453 ok(data == 8, "Got unexpected value %u.\n", data);
24455 ID3D11DeviceContext_CSSetShader(context, cs_append, NULL, 0);
24456 data = 0;
24457 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24458 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24459 data = read_uav_counter(context, staging_buffer, uav);
24460 ok(data == 3, "Got unexpected value %u.\n", data);
24461 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)args_buffer, (ID3D11Resource *)append_buffer);
24463 ID3D11DeviceContext_CSSetShader(context, cs_stats, NULL, 0);
24464 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, stats_uav, zero);
24465 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &stats_uav, NULL);
24466 data = read_uav_counter(context, staging_buffer, uav);
24467 for (i = 0; i < data; ++i)
24468 ID3D11DeviceContext_DispatchIndirect(context, args_buffer, i * 3 * sizeof(unsigned int));
24469 get_buffer_readback(stats_buffer, &rb);
24470 stats = rb.map_desc.pData;
24471 ok(stats->dispatch_count == 3, "Got unexpected dispatch count %u.\n", stats->dispatch_count);
24472 ok(stats->thread_count == 15, "Got unexpected thread count %u.\n", stats->thread_count);
24473 ok(stats->max_x == 3, "Got unexpected max x %u.\n", stats->max_x);
24474 ok(stats->max_y == 1, "Got unexpected max y %u.\n", stats->max_y);
24475 ok(stats->max_z == 0, "Got unexpected max z %u.\n", stats->max_z);
24476 release_resource_readback(&rb);
24478 ID3D11Buffer_Release(append_buffer);
24479 ID3D11Buffer_Release(args_buffer);
24480 ID3D11Buffer_Release(staging_buffer);
24481 ID3D11Buffer_Release(stats_buffer);
24482 ID3D11ComputeShader_Release(cs_append);
24483 ID3D11ComputeShader_Release(cs_stats);
24484 ID3D11UnorderedAccessView_Release(uav);
24485 ID3D11UnorderedAccessView_Release(stats_uav);
24486 release_test_context(&test_context);
24489 static void test_compute_shader_registers(void)
24491 struct data
24493 unsigned int group_id[3];
24494 unsigned int group_index;
24495 unsigned int dispatch_id[3];
24496 unsigned int thread_id[3];
24499 struct d3d11_test_context test_context;
24500 unsigned int i, x, y, group_x, group_y;
24501 ID3D11UnorderedAccessView *uav;
24502 D3D11_BUFFER_DESC buffer_desc;
24503 ID3D11DeviceContext *context;
24504 struct resource_readback rb;
24505 ID3D11Buffer *cb, *buffer;
24506 struct uvec4 dimensions;
24507 ID3D11ComputeShader *cs;
24508 const struct data *data;
24509 ID3D11Device *device;
24510 HRESULT hr;
24512 static const DWORD cs_code[] =
24514 #if 0
24515 struct data
24517 uint3 group_id;
24518 uint group_index;
24519 uint3 dispatch_id;
24520 uint3 group_thread_id;
24523 RWStructuredBuffer<data> u;
24525 uint2 dim;
24527 [numthreads(3, 2, 1)]
24528 void main(uint3 group_id : SV_GroupID,
24529 uint group_index : SV_GroupIndex,
24530 uint3 dispatch_id : SV_DispatchThreadID,
24531 uint3 group_thread_id : SV_GroupThreadID)
24533 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
24534 u[i].group_id = group_id;
24535 u[i].group_index = group_index;
24536 u[i].dispatch_id = dispatch_id;
24537 u[i].group_thread_id = group_thread_id;
24539 #endif
24540 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
24541 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24542 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
24543 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
24544 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
24545 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
24546 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
24547 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
24548 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
24549 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
24550 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
24551 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
24552 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
24553 0x0100003e,
24555 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24557 if (!init_test_context(&test_context, &feature_level))
24558 return;
24560 device = test_context.device;
24561 context = test_context.immediate_context;
24563 buffer_desc.ByteWidth = 10240;
24564 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24565 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24566 buffer_desc.CPUAccessFlags = 0;
24567 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24568 buffer_desc.StructureByteStride = 40;
24569 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
24570 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24571 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24572 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
24573 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24575 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
24577 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
24578 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24580 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24581 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
24582 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24584 dimensions.x = 2;
24585 dimensions.y = 3;
24586 dimensions.z = 1;
24587 dimensions.w = 0;
24588 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24589 NULL, &dimensions, 0, 0);
24590 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
24592 get_buffer_readback(buffer, &rb);
24593 i = 0;
24594 data = rb.map_desc.pData;
24595 for (y = 0; y < dimensions.y; ++y)
24597 for (group_y = 0; group_y < 2; ++group_y)
24599 for (x = 0; x < dimensions.x; ++x)
24601 for (group_x = 0; group_x < 3; ++group_x)
24603 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
24604 const unsigned int group_index = group_y * 3 + group_x;
24605 const struct data *d = &data[i];
24607 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
24608 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
24609 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
24610 i, x, y, group_x, group_y);
24611 ok(d->group_index == group_index,
24612 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
24613 d->group_index, group_index, i, x, y, group_x, group_y);
24614 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
24615 && !d->dispatch_id[2],
24616 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
24617 "at %u (%u, %u, %u, %u).\n",
24618 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
24619 dispatch_id[0], dispatch_id[1], 0,
24620 i, x, y, group_x, group_y);
24621 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
24622 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
24623 "at %u (%u, %u, %u, %u).\n",
24624 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
24625 i, x, y, group_x, group_y);
24626 ++i;
24631 release_resource_readback(&rb);
24633 ID3D11Buffer_Release(cb);
24634 ID3D11Buffer_Release(buffer);
24635 ID3D11ComputeShader_Release(cs);
24636 ID3D11UnorderedAccessView_Release(uav);
24637 release_test_context(&test_context);
24640 static void test_tgsm(void)
24642 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24643 struct d3d11_test_context test_context;
24644 ID3D11UnorderedAccessView *uav, *uav2;
24645 struct resource_readback rb, rb2;
24646 unsigned int i, data, expected;
24647 ID3D11Buffer *buffer, *buffer2;
24648 D3D11_BUFFER_DESC buffer_desc;
24649 ID3D11DeviceContext *context;
24650 ID3D11ComputeShader *cs;
24651 ID3D11Device *device;
24652 float float_data;
24653 HRESULT hr;
24655 static const DWORD raw_tgsm_code[] =
24657 #if 0
24658 RWByteAddressBuffer u;
24659 groupshared uint m;
24661 [numthreads(32, 1, 1)]
24662 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
24664 if (!local_idx)
24665 m = group_id.x;
24666 GroupMemoryBarrierWithGroupSync();
24667 InterlockedAdd(m, group_id.x);
24668 GroupMemoryBarrierWithGroupSync();
24669 if (!local_idx)
24670 u.Store(4 * group_id.x, m);
24672 #endif
24673 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
24674 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24675 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
24676 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
24677 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
24678 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
24679 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
24680 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
24681 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
24682 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
24683 0x01000015, 0x0100003e,
24685 static const DWORD structured_tgsm_code[] =
24687 #if 0
24688 #define GROUP_SIZE 32
24690 RWByteAddressBuffer u;
24691 RWByteAddressBuffer u2;
24692 groupshared uint m[GROUP_SIZE];
24694 [numthreads(GROUP_SIZE, 1, 1)]
24695 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
24697 uint sum, original, i;
24699 if (!local_idx)
24701 for (i = 0; i < GROUP_SIZE; ++i)
24702 m[i] = 2 * group_id.x;
24704 GroupMemoryBarrierWithGroupSync();
24705 InterlockedAdd(m[local_idx], 1);
24706 GroupMemoryBarrierWithGroupSync();
24707 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
24708 u.InterlockedExchange(4 * group_id.x, sum, original);
24709 u2.Store(4 * group_id.x, original);
24711 #endif
24712 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
24713 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24714 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
24715 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
24716 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
24717 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
24718 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
24719 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
24720 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
24721 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
24722 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
24723 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
24724 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
24725 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
24726 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
24727 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
24728 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
24729 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
24730 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
24731 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
24732 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
24733 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
24735 static const DWORD structured_tgsm_float_code[] =
24737 #if 0
24738 #define GROUP_SIZE 32
24740 struct data
24742 float f;
24743 uint u;
24746 RWBuffer<float> u;
24747 RWBuffer<uint> u2;
24748 groupshared data m[GROUP_SIZE];
24750 [numthreads(GROUP_SIZE, 1, 1)]
24751 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
24752 uint thread_id : SV_DispatchThreadID)
24754 uint i;
24755 if (!local_idx)
24757 for (i = 0; i < GROUP_SIZE; ++i)
24759 m[i].f = group_id.x;
24760 m[i].u = group_id.x;
24763 GroupMemoryBarrierWithGroupSync();
24764 for (i = 0; i < local_idx; ++i)
24766 m[local_idx].f += group_id.x;
24767 m[local_idx].u += group_id.x;
24769 u[thread_id.x] = m[local_idx].f;
24770 u2[thread_id.x] = m[local_idx].u;
24772 #endif
24773 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
24774 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24775 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
24776 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
24777 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
24778 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
24779 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
24780 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
24781 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
24782 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
24783 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
24784 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
24785 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
24786 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
24787 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
24788 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
24789 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
24790 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
24791 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
24792 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
24793 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
24794 0x00100556, 0x00000000, 0x0100003e,
24796 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24797 static const unsigned int zero[4] = {0};
24799 if (!init_test_context(&test_context, &feature_level))
24800 return;
24802 device = test_context.device;
24803 context = test_context.immediate_context;
24805 buffer_desc.ByteWidth = 1024;
24806 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24807 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24808 buffer_desc.CPUAccessFlags = 0;
24809 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
24810 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24811 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24813 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
24814 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24815 U(uav_desc).Buffer.FirstElement = 0;
24816 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
24817 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
24818 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24819 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24821 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
24822 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24824 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24825 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24827 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
24828 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
24829 get_buffer_readback(buffer, &rb);
24830 for (i = 0; i < 64; ++i)
24832 data = get_readback_color(&rb, i, 0, 0);
24833 expected = 33 * i;
24834 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
24836 release_resource_readback(&rb);
24838 ID3D11Buffer_Release(buffer);
24839 ID3D11ComputeShader_Release(cs);
24840 ID3D11UnorderedAccessView_Release(uav);
24842 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24843 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24844 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24845 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24846 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
24847 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24848 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
24849 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24850 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
24851 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24853 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24854 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24855 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
24857 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
24858 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
24859 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
24860 get_buffer_readback(buffer, &rb);
24861 get_buffer_readback(buffer2, &rb2);
24862 for (i = 0; i < 32; ++i)
24864 expected = 64 * i + 32;
24865 data = get_readback_color(&rb, i, 0, 0);
24866 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
24867 data = get_readback_color(&rb2, i, 0, 0);
24868 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
24870 release_resource_readback(&rb);
24871 release_resource_readback(&rb2);
24873 ID3D11Buffer_Release(buffer);
24874 ID3D11Buffer_Release(buffer2);
24875 ID3D11ComputeShader_Release(cs);
24876 ID3D11UnorderedAccessView_Release(uav);
24877 ID3D11UnorderedAccessView_Release(uav2);
24879 buffer_desc.MiscFlags = 0;
24880 U(uav_desc).Buffer.Flags = 0;
24881 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24882 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24883 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
24884 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24885 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24886 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
24887 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24888 uav_desc.Format = DXGI_FORMAT_R32_UINT;
24889 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
24890 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24891 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
24892 sizeof(structured_tgsm_float_code), NULL, &cs);
24893 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24895 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24896 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24897 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
24899 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
24900 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
24901 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
24902 get_buffer_readback(buffer, &rb);
24903 get_buffer_readback(buffer2, &rb2);
24904 for (i = 0; i < 96; ++i)
24906 expected = (i % 32 + 1) * (i / 32);
24907 float_data = get_readback_float(&rb, i, 0);
24908 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
24909 data = get_readback_color(&rb2, i, 0, 0);
24910 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
24912 release_resource_readback(&rb);
24913 release_resource_readback(&rb2);
24915 ID3D11Buffer_Release(buffer);
24916 ID3D11Buffer_Release(buffer2);
24917 ID3D11ComputeShader_Release(cs);
24918 ID3D11UnorderedAccessView_Release(uav);
24919 ID3D11UnorderedAccessView_Release(uav2);
24920 release_test_context(&test_context);
24923 static void test_geometry_shader(void)
24925 static const struct
24927 struct vec4 position;
24928 unsigned int color;
24930 vertex[] =
24932 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
24934 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
24936 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
24937 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
24939 #if 0
24940 struct vs_data
24942 float4 pos : SV_POSITION;
24943 float4 color : COLOR;
24946 void main(in struct vs_data vs_input, out struct vs_data vs_output)
24948 vs_output.pos = vs_input.pos;
24949 vs_output.color = vs_input.color;
24951 #endif
24952 static const DWORD vs_code[] =
24954 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
24955 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
24956 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
24957 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
24958 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
24959 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
24960 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
24961 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
24962 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
24963 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
24964 0x0100003e,
24966 #if 0
24967 struct gs_data
24969 float4 pos : SV_POSITION;
24970 float4 color : COLOR;
24973 [maxvertexcount(4)]
24974 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
24976 float offset = 0.2 * vin[0].pos.w;
24977 gs_data v;
24979 v.color = vin[0].color;
24981 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
24982 vout.Append(v);
24983 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
24984 vout.Append(v);
24985 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
24986 vout.Append(v);
24987 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
24988 vout.Append(v);
24990 #endif
24991 static const DWORD gs_code[] =
24993 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
24994 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
24995 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
24996 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
24997 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
24998 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
24999 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
25000 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
25001 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
25002 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
25003 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
25004 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
25005 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
25006 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
25007 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
25008 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
25009 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
25010 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
25011 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
25012 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
25013 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
25014 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
25015 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25016 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
25017 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
25018 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
25019 0x00000001, 0x01000013, 0x0100003e,
25021 static const DWORD gs_5_0_code[] =
25023 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
25024 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25025 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
25026 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25027 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
25028 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
25029 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
25030 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
25031 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
25032 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25033 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
25034 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
25035 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
25036 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
25037 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25038 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
25039 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
25040 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
25041 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
25042 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
25043 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
25044 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
25045 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
25046 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
25047 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
25048 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
25049 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
25050 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
25051 0x0100003e,
25053 #if 0
25054 struct ps_data
25056 float4 pos : SV_POSITION;
25057 float4 color : COLOR;
25060 float4 main(struct ps_data ps_input) : SV_Target
25062 return ps_input.color;
25064 #endif
25065 static const DWORD ps_code[] =
25067 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
25068 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25069 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
25070 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25071 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
25072 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
25073 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
25074 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
25076 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
25077 struct d3d11_test_context test_context;
25078 ID3D11InputLayout *input_layout;
25079 ID3D11DeviceContext *context;
25080 unsigned int stride, offset;
25081 struct resource_readback rb;
25082 ID3D11GeometryShader *gs;
25083 ID3D11VertexShader *vs;
25084 ID3D11PixelShader *ps;
25085 ID3D11Device *device;
25086 ID3D11Buffer *vb;
25087 DWORD color;
25088 HRESULT hr;
25090 if (!init_test_context(&test_context, NULL))
25091 return;
25093 device = test_context.device;
25094 context = test_context.immediate_context;
25096 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
25097 vs_code, sizeof(vs_code), &input_layout);
25098 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
25100 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
25102 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
25103 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
25104 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
25105 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
25106 else
25107 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
25108 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
25109 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
25110 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25112 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
25113 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
25114 stride = sizeof(*vertex);
25115 offset = 0;
25116 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
25117 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
25118 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
25119 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25121 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
25122 ID3D11DeviceContext_Draw(context, 1, 0);
25124 get_texture_readback(test_context.backbuffer, 0, &rb);
25125 color = get_readback_color(&rb, 320, 190, 0);
25126 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25127 color = get_readback_color(&rb, 255, 240, 0);
25128 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25129 color = get_readback_color(&rb, 320, 240, 0);
25130 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
25131 color = get_readback_color(&rb, 385, 240, 0);
25132 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25133 color = get_readback_color(&rb, 320, 290, 0);
25134 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25135 release_resource_readback(&rb);
25137 ID3D11PixelShader_Release(ps);
25138 ID3D11GeometryShader_Release(gs);
25139 ID3D11VertexShader_Release(vs);
25140 ID3D11Buffer_Release(vb);
25141 ID3D11InputLayout_Release(input_layout);
25142 release_test_context(&test_context);
25145 struct triangle
25147 struct vec4 v[3];
25150 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
25151 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
25152 const struct triangle *triangles, unsigned int triangle_count)
25154 const struct triangle *current, *expected;
25155 struct resource_readback rb;
25156 unsigned int i, j, offset;
25157 BOOL all_match = TRUE;
25159 get_buffer_readback(buffer, &rb);
25161 for (i = 0; i < triangle_count; ++i)
25163 current = get_readback_data(&rb, i, 0, 0, sizeof(*current));
25164 expected = &triangles[i];
25166 offset = ~0u;
25167 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
25169 if (compare_vec4(&current->v[0], &expected->v[j], 0))
25171 offset = j;
25172 break;
25176 if (offset == ~0u)
25178 all_match = FALSE;
25179 break;
25182 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
25184 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
25186 all_match = FALSE;
25187 break;
25190 if (!all_match)
25191 break;
25194 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
25195 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
25196 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
25197 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
25198 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
25199 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
25200 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
25201 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
25202 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
25203 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
25205 release_resource_readback(&rb);
25208 static void test_quad_tessellation(void)
25210 #if 0
25211 struct point_data
25213 float4 position : SV_POSITION;
25216 struct patch_constant_data
25218 float edges[4] : SV_TessFactor;
25219 float inside[2] : SV_InsideTessFactor;
25222 float4 tess_factors;
25223 float2 inside_tess_factors;
25225 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
25227 patch_constant_data output;
25229 output.edges[0] = tess_factors.x;
25230 output.edges[1] = tess_factors.y;
25231 output.edges[2] = tess_factors.z;
25232 output.edges[3] = tess_factors.w;
25233 output.inside[0] = inside_tess_factors.x;
25234 output.inside[1] = inside_tess_factors.y;
25236 return output;
25239 [domain("quad")]
25240 [outputcontrolpoints(4)]
25241 [outputtopology("triangle_ccw")]
25242 [partitioning("integer")]
25243 [patchconstantfunc("patch_constant")]
25244 point_data hs_main(InputPatch<point_data, 4> input,
25245 uint i : SV_OutputControlPointID)
25247 return input[i];
25250 [domain("quad")]
25251 point_data ds_main(patch_constant_data input,
25252 float2 tess_coord : SV_DomainLocation,
25253 const OutputPatch<point_data, 4> patch)
25255 point_data output;
25257 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
25258 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
25259 output.position = lerp(a, b, tess_coord.y);
25261 return output;
25263 #endif
25264 static const DWORD hs_quad_ccw_code[] =
25266 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
25267 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25268 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25269 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
25270 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
25271 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
25272 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
25273 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
25274 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
25275 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
25276 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
25277 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
25278 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
25279 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
25280 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
25281 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25282 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
25283 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
25284 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25285 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
25286 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
25287 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
25289 static const DWORD ds_quad_code[] =
25291 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
25292 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25293 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25294 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
25295 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
25296 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
25297 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
25298 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
25299 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
25300 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
25301 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
25302 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
25303 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25304 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
25305 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
25306 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
25307 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
25308 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
25309 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
25310 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
25311 0x0100003e,
25313 #if 0
25315 [outputtopology("triangle_cw")]
25317 #endif
25318 static const DWORD hs_quad_cw_code[] =
25320 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
25321 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25322 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25323 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
25324 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
25325 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
25326 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
25327 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
25328 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
25329 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
25330 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
25331 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
25332 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
25333 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
25334 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
25335 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25336 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
25337 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
25338 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25339 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
25340 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
25341 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
25343 #if 0
25344 struct point_data
25346 float4 pos : SV_POSITION;
25349 [maxvertexcount(3)]
25350 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
25352 for (uint i = 0; i < 3; ++i)
25353 vout.Append(vin[i]);
25355 #endif
25356 static const DWORD gs_code[] =
25358 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
25359 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
25360 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
25361 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
25362 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
25363 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
25364 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
25365 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
25366 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
25367 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
25368 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
25369 0x0100003e,
25371 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
25373 {0, "SV_POSITION", 0, 0, 4, 0},
25375 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25376 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
25377 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
25378 static const BYTE zero_data[1024];
25379 static const struct triangle expected_quad_ccw[] =
25381 {{{-1.0f, -1.0f, 0.0f, 1.0f},
25382 { 1.0f, -1.0f, 0.0f, 1.0f},
25383 {-1.0f, 1.0f, 0.0f, 1.0f}}},
25384 {{{-1.0f, 1.0f, 0.0f, 1.0f},
25385 { 1.0f, -1.0f, 0.0f, 1.0f},
25386 { 1.0f, 1.0f, 0.0f, 1.0f}}},
25387 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
25388 { 0.0f, 0.0f, 0.0f, 0.0f},
25389 { 0.0f, 0.0f, 0.0f, 0.0f}}},
25391 static const struct triangle expected_quad_cw[] =
25393 {{{-1.0f, -1.0f, 0.0f, 1.0f},
25394 {-1.0f, 1.0f, 0.0f, 1.0f},
25395 { 1.0f, -1.0f, 0.0f, 1.0f}}},
25396 {{{-1.0f, 1.0f, 0.0f, 1.0f},
25397 { 1.0f, 1.0f, 0.0f, 1.0f},
25398 { 1.0f, -1.0f, 0.0f, 1.0f}}},
25399 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
25400 { 0.0f, 0.0f, 0.0f, 0.0f},
25401 { 0.0f, 0.0f, 0.0f, 0.0f}}},
25403 struct
25405 float tess_factors[4];
25406 float inside_tess_factors[2];
25407 DWORD padding[2];
25408 } constant;
25410 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
25411 struct d3d11_test_context test_context;
25412 ID3D11DeviceContext *context;
25413 ID3D11Buffer *cb, *so_buffer;
25414 D3D11_QUERY_DESC query_desc;
25415 ID3D11Asynchronous *query;
25416 ID3D11GeometryShader *gs;
25417 ID3D11DomainShader *ds;
25418 const UINT offset = 0;
25419 ID3D11HullShader *hs;
25420 ID3D11Device *device;
25421 unsigned int i;
25422 HRESULT hr;
25424 if (!init_test_context(&test_context, &feature_level))
25425 return;
25427 device = test_context.device;
25428 context = test_context.immediate_context;
25430 draw_color_quad(&test_context, &white);
25431 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25433 set_quad_color(&test_context, &green);
25434 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
25436 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
25437 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
25438 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
25439 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
25440 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
25442 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
25443 constant.tess_factors[i] = 1.0f;
25444 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
25445 constant.inside_tess_factors[i] = 1.0f;
25446 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
25447 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
25448 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
25449 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
25450 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
25451 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
25452 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
25453 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
25455 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25456 ID3D11DeviceContext_Draw(context, 4, 0);
25457 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25458 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
25459 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
25461 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
25463 ID3D11HullShader_Release(hs);
25464 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
25465 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
25466 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
25468 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25469 ID3D11DeviceContext_Draw(context, 4, 0);
25470 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
25471 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
25472 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
25474 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
25476 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25477 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
25478 query_desc.MiscFlags = 0;
25479 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
25480 ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
25481 ID3D11DeviceContext_Begin(context, query);
25483 set_quad_color(&test_context, &white);
25484 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
25485 constant.tess_factors[i] = 2.0f;
25486 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25487 ID3D11DeviceContext_Draw(context, 4, 0);
25488 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25490 set_quad_color(&test_context, &green);
25491 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
25492 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25493 ID3D11DeviceContext_Draw(context, 4, 0);
25494 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25496 ID3D11DeviceContext_End(context, query);
25497 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
25498 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
25499 (unsigned int)so_statistics.NumPrimitivesWritten);
25500 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
25501 (unsigned int)so_statistics.PrimitivesStorageNeeded);
25502 ID3D11DeviceContext_Begin(context, query);
25504 constant.tess_factors[0] = 5.0f;
25505 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25506 ID3D11DeviceContext_Draw(context, 4, 0);
25507 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
25509 ID3D11DeviceContext_End(context, query);
25510 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
25511 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
25512 (unsigned int)so_statistics.NumPrimitivesWritten);
25513 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
25514 (unsigned int)so_statistics.PrimitivesStorageNeeded);
25515 ID3D11Asynchronous_Release(query);
25517 ID3D11Buffer_Release(so_buffer);
25518 ID3D11GeometryShader_Release(gs);
25519 ID3D11DomainShader_Release(ds);
25520 ID3D11HullShader_Release(hs);
25521 ID3D11Buffer_Release(cb);
25522 release_test_context(&test_context);
25525 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
25526 static void check_so_desc_(unsigned int line, ID3D11Device *device,
25527 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
25528 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
25529 unsigned int rasterizer_stream)
25531 ID3D11GeometryShader *gs;
25532 HRESULT hr;
25534 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
25535 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
25536 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
25537 if (SUCCEEDED(hr))
25538 ID3D11GeometryShader_Release(gs);
25541 #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)
25542 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
25543 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
25544 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
25545 unsigned int rasterizer_stream)
25547 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
25548 HRESULT hr;
25550 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
25551 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
25552 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
25553 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
25554 if (SUCCEEDED(hr))
25555 ID3D11GeometryShader_Release(gs);
25558 static void test_stream_output(void)
25560 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
25561 struct d3d11_test_context test_context;
25562 unsigned int i, count;
25563 ID3D11Device *device;
25565 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25566 static const DWORD vs_code[] =
25568 #if 0
25569 struct data
25571 float4 position : SV_Position;
25572 float4 attrib1 : ATTRIB1;
25573 float3 attrib2 : attrib2;
25574 float2 attrib3 : ATTriB3;
25575 float attrib4 : ATTRIB4;
25578 void main(in data i, out data o)
25580 o = i;
25582 #endif
25583 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
25584 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
25585 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
25586 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
25587 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
25588 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
25589 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
25590 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
25591 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
25592 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
25593 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
25594 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
25595 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
25596 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
25597 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25598 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
25599 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
25600 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
25601 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
25602 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
25604 static const DWORD gs_code[] =
25606 #if 0
25607 struct data
25609 float4 position : SV_Position;
25610 float4 attrib1 : ATTRIB1;
25611 float3 attrib2 : attrib2;
25612 float2 attrib3 : ATTriB3;
25613 float attrib4 : ATTRIB4;
25616 [maxvertexcount(1)]
25617 void main(point data i[1], inout PointStream<data> o)
25619 o.Append(i[0]);
25621 #endif
25622 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
25623 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
25624 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
25625 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
25626 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
25627 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
25628 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
25629 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
25630 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
25631 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
25632 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
25633 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
25634 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
25635 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
25636 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
25637 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25638 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
25639 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
25640 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25641 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
25642 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
25644 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
25646 {0, "SV_Position", 0, 0, 4, 0},
25648 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
25650 {0, "SV_Position", 0, 0, 4, 0},
25651 {0, NULL, 0, 0, 0, 0},
25653 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
25655 /* SemanticName and SemanticIndex */
25657 {0, "sv_position", 0, 0, 4, 0},
25658 {0, "attrib", 1, 0, 4, 0},
25661 {0, "sv_position", 0, 0, 4, 0},
25662 {0, "ATTRIB", 1, 0, 4, 0},
25664 /* Gaps */
25666 {0, "SV_POSITION", 0, 0, 4, 0},
25667 {0, NULL, 0, 0, 8, 0},
25668 {0, "ATTRIB", 1, 0, 4, 0},
25671 {0, "SV_POSITION", 0, 0, 4, 0},
25672 {0, NULL, 0, 0, 4, 0},
25673 {0, NULL, 0, 0, 4, 0},
25674 {0, "ATTRIB", 1, 0, 4, 0},
25676 /* ComponentCount */
25678 {0, "ATTRIB", 1, 0, 4, 0},
25681 {0, "ATTRIB", 2, 0, 3, 0},
25684 {0, "ATTRIB", 3, 0, 2, 0},
25687 {0, "ATTRIB", 4, 0, 1, 0},
25689 /* ComponentIndex */
25691 {0, "ATTRIB", 1, 1, 3, 0},
25694 {0, "ATTRIB", 1, 2, 2, 0},
25697 {0, "ATTRIB", 1, 3, 1, 0},
25700 {0, "ATTRIB", 3, 1, 1, 0},
25702 /* OutputSlot */
25704 {0, "attrib", 1, 0, 4, 0},
25707 {0, "attrib", 1, 0, 4, 1},
25710 {0, "attrib", 1, 0, 4, 2},
25713 {0, "attrib", 1, 0, 4, 3},
25716 {0, "attrib", 1, 0, 4, 0},
25717 {0, "attrib", 2, 0, 3, 1},
25718 {0, NULL, 0, 0, 1, 1},
25719 {0, "attrib", 3, 0, 2, 2},
25720 {0, NULL, 0, 0, 2, 2},
25721 {0, "attrib", 4, 0, 1, 3},
25722 {0, NULL, 0, 0, 7, 3},
25725 {0, "attrib", 1, 0, 4, 0},
25726 {0, "attrib", 2, 0, 3, 1},
25727 {0, NULL, 0, 0, 1, 1},
25728 {0, "attrib", 3, 0, 2, 2},
25729 {0, NULL, 0, 0, 1, 2},
25730 {0, NULL, 0, 0, 1, 2},
25731 {0, "attrib", 4, 0, 1, 3},
25732 {0, NULL, 0, 0, 3, 3},
25733 {0, NULL, 0, 0, 1, 3},
25734 {0, NULL, 0, 0, 1, 3},
25735 {0, NULL, 0, 0, 1, 3},
25736 {0, NULL, 0, 0, 1, 3},
25739 {0, "attrib", 1, 0, 4, 0},
25740 {0, "attrib", 2, 0, 3, 0},
25741 {0, "attrib", 3, 0, 2, 0},
25742 {0, NULL, 0, 0, 1, 0},
25743 {0, "attrib", 4, 0, 1, 0},
25746 {0, "attrib", 1, 0, 4, 0},
25747 {0, "attrib", 2, 0, 3, 0},
25748 {0, "attrib", 3, 0, 2, 3},
25749 {0, NULL, 0, 0, 1, 3},
25750 {0, "attrib", 4, 0, 1, 3},
25752 /* Multiple occurrences of the same output */
25754 {0, "ATTRIB", 1, 0, 2, 0},
25755 {0, "ATTRIB", 1, 2, 2, 1},
25758 {0, "ATTRIB", 1, 0, 1, 0},
25759 {0, "ATTRIB", 1, 1, 3, 0},
25762 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
25764 /* SemanticName and SemanticIndex */
25766 {0, "SV_Position", 0, 0, 4, 0},
25767 {0, "ATTRIB", 0, 0, 4, 0},
25770 {0, "sv_position", 0, 0, 4, 0},
25771 {0, "ATTRIB_", 1, 0, 4, 0},
25773 /* Gaps */
25775 {0, "SV_POSITION", 0, 0, 4, 0},
25776 {0, NULL, 0, 1, 8, 0},
25777 {0, "ATTRIB", 1, 0, 4, 0},
25780 {0, "SV_POSITION", 0, 0, 4, 0},
25781 {0, NULL, 1, 0, 8, 0},
25782 {0, "ATTRIB", 1, 0, 4, 0},
25784 /* Buffer stride */
25786 {0, "SV_POSITION", 0, 0, 4, 0},
25787 {0, NULL, 0, 0, 8, 0},
25788 {0, NULL, 0, 0, 8, 0},
25789 {0, "ATTRIB", 1, 0, 4, 0},
25791 /* ComponentCount */
25793 {0, "ATTRIB", 2, 0, 5, 0},
25796 {0, "ATTRIB", 2, 0, 4, 0},
25799 {0, "ATTRIB", 3, 0, 3, 0},
25802 {0, "ATTRIB", 4, 0, 2, 0},
25804 /* ComponentIndex */
25806 {0, "ATTRIB", 1, 1, 4, 0},
25809 {0, "ATTRIB", 1, 2, 3, 0},
25812 {0, "ATTRIB", 1, 3, 2, 0},
25815 {0, "ATTRIB", 1, 4, 0, 0},
25818 {0, "ATTRIB", 1, 4, 1, 0},
25821 {0, "ATTRIB", 3, 2, 1, 0},
25824 {0, "ATTRIB", 3, 2, 0, 0},
25826 /* OutputSlot */
25828 {0, "attrib", 1, 0, 4, 4},
25831 {0, "attrib", 1, 0, 4, 4},
25834 {0, "attrib", 1, 0, 4, 4},
25837 {0, "attrib", 1, 0, 4, 4},
25840 {0, "attrib", 1, 0, 4, 0},
25841 {0, "attrib", 2, 0, 3, 1},
25842 {0, NULL, 0, 0, 1, 1},
25843 {0, "attrib", 3, 0, 2, 2},
25844 {0, NULL, 0, 0, 2, 2},
25845 {0, "attrib", 4, 0, 1, 3},
25846 {0, NULL, 0, 0, 3, 4},
25849 {0, "attrib", 1, 0, 4, 0},
25850 {0, "attrib", 2, 0, 3, 0},
25851 {0, "attrib", 3, 0, 2, 0},
25852 {0, NULL, 0, 0, 1, 0},
25853 {0, "attrib", 4, 0, 1, 0},
25854 {0, NULL, 0, 0, 3, 3},
25855 {0, NULL, 0, 0, 1, 3},
25856 {0, NULL, 0, 0, 1, 3},
25857 {0, NULL, 0, 0, 1, 3},
25858 {0, NULL, 0, 0, 1, 3},
25861 {0, "attrib", 1, 0, 4, 0},
25862 {0, NULL, 0, 0, 3, 1},
25863 {0, NULL, 0, 0, 1, 1},
25864 {0, NULL, 0, 0, 1, 2},
25865 {0, "attrib", 2, 0, 3, 3},
25866 {0, NULL, 0, 0, 1, 3},
25869 {0, "attrib", 2, 0, 3, 3},
25870 {0, NULL, 0, 0, 3, 1},
25871 {0, NULL, 0, 0, 1, 3},
25872 {0, "attrib", 1, 0, 4, 0},
25873 {0, NULL, 0, 0, 1, 2},
25874 {0, NULL, 0, 0, 1, 1},
25876 /* Stream */
25878 {1, "attrib", 1, 0, 4, 0},
25881 {4, "attrib", 1, 0, 4, 0},
25883 /* Multiple occurrences of the same output */
25885 {0, "ATTRIB", 1, 0, 4, 0},
25886 {0, "ATTRIB", 1, 0, 4, 1},
25889 {0, "ATTRIB", 1, 0, 4, 0},
25890 {0, "ATTRIB", 1, 0, 3, 0},
25894 if (!init_test_context(&test_context, &feature_level))
25895 return;
25897 device = test_context.device;
25899 for (i = 0; i < ARRAY_SIZE(stride); ++i)
25900 stride[i] = 64;
25902 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25903 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25904 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25905 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25906 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25907 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25909 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
25910 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25911 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
25912 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25914 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
25915 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25916 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
25917 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
25918 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25920 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
25921 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25922 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
25923 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25925 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
25927 unsigned int max_output_slot = 0;
25928 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
25930 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
25931 max_output_slot = max(max_output_slot, e->OutputSlot);
25932 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
25933 break;
25936 /* Buffer strides are required for all buffers. */
25937 if (!max_output_slot)
25939 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25940 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25941 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25942 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25943 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25944 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
25945 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25946 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
25947 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25948 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
25950 else
25952 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25953 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25954 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25955 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
25959 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
25961 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
25963 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
25964 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
25965 break;
25968 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
25969 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25970 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
25971 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
25972 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
25973 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
25974 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
25975 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
25978 /* Buffer strides */
25979 stride[1] = 63;
25980 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25981 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
25982 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25983 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
25984 stride[1] = 1;
25985 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25986 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
25987 stride[0] = 0;
25988 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25989 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25991 /* Rasterizer stream */
25992 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
25993 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
25994 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25995 NULL, 0, D3D11_SO_STREAM_COUNT);
25997 release_test_context(&test_context);
26000 static void test_fl10_stream_output_desc(void)
26002 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
26003 struct d3d11_test_context test_context;
26004 unsigned int i, count;
26005 ID3D11Device *device;
26007 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
26008 static const DWORD vs_code[] =
26010 #if 0
26011 struct data
26013 float4 position : SV_Position;
26014 float4 attrib1 : ATTRIB1;
26015 float3 attrib2 : attrib2;
26016 float2 attrib3 : ATTriB3;
26017 float attrib4 : ATTRIB4;
26020 void main(in data i, out data o)
26022 o = i;
26024 #endif
26025 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
26026 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
26027 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
26028 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26029 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
26030 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
26031 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
26032 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26033 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
26034 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
26035 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
26036 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
26037 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
26038 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
26039 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
26040 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
26041 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
26042 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
26043 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
26044 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
26046 static const DWORD gs_code[] =
26048 #if 0
26049 struct data
26051 float4 position : SV_Position;
26052 float4 attrib1 : ATTRIB1;
26053 float3 attrib2 : attrib2;
26054 float2 attrib3 : ATTriB3;
26055 float attrib4 : ATTRIB4;
26058 [maxvertexcount(1)]
26059 void main(point data i[1], inout PointStream<data> o)
26061 o.Append(i[0]);
26063 #endif
26064 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
26065 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
26066 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
26067 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26068 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
26069 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
26070 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
26071 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26072 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
26073 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
26074 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
26075 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
26076 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
26077 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
26078 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
26079 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
26080 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
26081 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
26082 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
26083 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
26084 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
26086 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26088 {0, "SV_Position", 0, 0, 4, 0},
26090 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
26092 {0, "SV_Position", 0, 0, 4, 0},
26093 {0, NULL, 0, 0, 0, 0},
26095 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
26097 /* Gaps */
26099 {0, "SV_POSITION", 0, 0, 4, 0},
26100 {0, NULL, 0, 0, 8, 0},
26101 {0, "ATTRIB", 1, 0, 4, 0},
26104 {0, "SV_POSITION", 0, 0, 4, 0},
26105 {0, NULL, 0, 0, 4, 0},
26106 {0, NULL, 0, 0, 4, 0},
26107 {0, "ATTRIB", 1, 0, 4, 0},
26109 /* OutputSlot */
26111 {0, "attrib", 1, 0, 4, 0},
26112 {0, "attrib", 2, 0, 3, 0},
26113 {0, "attrib", 3, 0, 2, 0},
26114 {0, "attrib", 4, 0, 1, 0},
26117 {0, "attrib", 1, 0, 4, 0},
26118 {0, "attrib", 2, 0, 3, 1},
26119 {0, "attrib", 3, 0, 2, 2},
26120 {0, "attrib", 4, 0, 1, 3},
26123 {0, "attrib", 1, 0, 4, 0},
26124 {0, "attrib", 2, 0, 3, 3},
26127 {0, "attrib", 1, 0, 4, 0},
26128 {0, "attrib", 2, 0, 3, 0},
26129 {0, "attrib", 3, 0, 2, 0},
26130 {0, NULL, 0, 0, 1, 0},
26131 {0, "attrib", 4, 0, 1, 0},
26133 /* Multiple occurrences of the same output */
26135 {0, "ATTRIB", 1, 0, 2, 0},
26136 {0, "ATTRIB", 1, 2, 2, 1},
26139 {0, "ATTRIB", 1, 0, 1, 0},
26140 {0, "ATTRIB", 1, 1, 3, 0},
26143 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
26145 /* OutputSlot */
26147 {0, "attrib", 1, 0, 4, 0},
26148 {0, NULL, 0, 0, 4, 0},
26149 {0, "attrib", 4, 0, 1, 3},
26152 {0, "attrib", 1, 0, 4, 0},
26153 {0, NULL, 0, 0, 4, 0},
26154 {0, NULL, 0, 0, 4, 0},
26155 {0, "attrib", 4, 0, 1, 3},
26158 {0, "attrib", 1, 0, 4, 0},
26159 {0, "attrib", 2, 0, 3, 0},
26160 {0, "attrib", 3, 0, 2, 0},
26161 {0, "attrib", 4, 0, 1, 1},
26164 {0, "attrib", 1, 0, 4, 0},
26165 {0, "attrib", 2, 0, 3, 0},
26166 {0, "attrib", 3, 0, 2, 3},
26167 {0, NULL, 0, 0, 1, 3},
26168 {0, "attrib", 4, 0, 1, 3},
26171 {0, "attrib", 1, 0, 4, 0},
26172 {0, "attrib", 1, 0, 3, 1},
26173 {0, "attrib", 1, 0, 2, 2},
26174 {0, "attrib", 1, 0, 1, 3},
26175 {0, NULL, 0, 0, 3, 3},
26179 if (!init_test_context(&test_context, &feature_level))
26180 return;
26182 device = test_context.device;
26184 for (i = 0; i < ARRAY_SIZE(stride); ++i)
26185 stride[i] = 64;
26187 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
26188 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
26189 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26190 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
26192 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26193 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
26195 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
26196 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
26197 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
26198 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
26199 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
26201 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
26202 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
26204 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
26206 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
26208 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
26209 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26210 break;
26213 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
26216 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
26218 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
26220 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
26221 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26222 break;
26225 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26226 stride, 1, 0);
26227 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26228 stride, 2, 0);
26229 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26230 stride, 3, 0);
26231 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26232 stride, 4, 0);
26235 /* Buffer strides */
26236 stride[1] = 63;
26237 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26238 &stride[1], 1, 0);
26239 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26240 stride, 2, 0);
26241 stride[0] = 0;
26242 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26243 stride, 1, 0);
26245 /* Rasterizer stream */
26246 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26247 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26248 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
26249 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26250 NULL, 0, i);
26251 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26253 release_test_context(&test_context);
26256 static void test_stream_output_resume(void)
26258 struct d3d11_test_context test_context;
26259 ID3D11Buffer *cb, *so_buffer, *buffer;
26260 unsigned int i, j, idx, offset;
26261 ID3D11DeviceContext *context;
26262 struct resource_readback rb;
26263 ID3D11GeometryShader *gs;
26264 const struct vec4 *data;
26265 ID3D11Device *device;
26266 HRESULT hr;
26268 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26269 static const DWORD gs_code[] =
26271 #if 0
26272 float4 constant;
26274 struct vertex
26276 float4 position : SV_POSITION;
26279 struct element
26281 float4 position : SV_POSITION;
26282 float4 so_output : so_output;
26285 [maxvertexcount(3)]
26286 void main(triangle vertex input[3], inout PointStream<element> output)
26288 element o;
26289 o.so_output = constant;
26290 o.position = input[0].position;
26291 output.Append(o);
26292 o.position = input[1].position;
26293 output.Append(o);
26294 o.position = input[2].position;
26295 output.Append(o);
26297 #endif
26298 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
26299 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26300 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
26301 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
26302 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
26303 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
26304 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
26305 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
26306 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
26307 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
26308 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
26309 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
26310 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
26311 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
26313 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26315 {0, "so_output", 0, 0, 4, 0},
26317 static const struct vec4 constants[] =
26319 {0.5f, 0.250f, 0.0f, 0.0f},
26320 {0.0f, 0.125f, 0.0f, 1.0f},
26321 {1.0f, 1.000f, 1.0f, 0.0f}
26323 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
26324 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
26325 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
26327 if (!init_test_context(&test_context, &feature_level))
26328 return;
26330 device = test_context.device;
26331 context = test_context.immediate_context;
26333 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
26334 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
26335 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
26337 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
26338 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26340 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26341 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
26343 offset = 0;
26344 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
26346 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
26347 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26349 draw_color_quad(&test_context, &red);
26350 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26352 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26353 draw_color_quad(&test_context, &green);
26354 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26356 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
26357 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26358 draw_color_quad(&test_context, &red);
26359 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26361 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26362 draw_color_quad(&test_context, &red);
26363 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
26365 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
26366 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26367 draw_color_quad(&test_context, &white);
26368 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
26370 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26371 draw_color_quad(&test_context, &green);
26372 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26374 buffer = NULL;
26375 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
26376 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26377 draw_color_quad(&test_context, &white);
26378 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26380 idx = 0;
26381 get_buffer_readback(so_buffer, &rb);
26382 for (i = 0; i < ARRAY_SIZE(constants); ++i)
26384 for (j = 0; j < 6; ++j) /* 2 triangles */
26386 data = get_readback_vec4(&rb, idx++, 0);
26387 ok(compare_vec4(data, &constants[i], 0),
26388 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
26389 data->x, data->y, data->z, data->w, idx, i, j);
26392 release_resource_readback(&rb);
26394 ID3D11Buffer_Release(cb);
26395 ID3D11Buffer_Release(so_buffer);
26396 ID3D11GeometryShader_Release(gs);
26397 release_test_context(&test_context);
26400 static void test_stream_output_components(void)
26402 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
26403 struct d3d11_test_context test_context;
26404 ID3D11InputLayout *input_layout[2];
26405 ID3D11Buffer *vb[2], *so_buffer;
26406 ID3D11DeviceContext *context;
26407 struct resource_readback rb;
26408 unsigned int stride, offset;
26409 ID3D11GeometryShader *gs;
26410 ID3D11VertexShader *vs;
26411 ID3D11PixelShader *ps;
26412 ID3D11Device *device;
26413 const float *result;
26414 unsigned int i, j;
26415 HRESULT hr;
26417 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26418 static const DWORD vs_code[] =
26420 #if 0
26421 struct vertex
26423 float4 position : POSITION;
26424 float4 color : COLOR;
26425 float4 color2 : COLOR2;
26428 void main(in vertex i, out vertex o)
26430 o = i;
26432 #endif
26433 0x43425844, 0x95991b76, 0x4898640b, 0xe36ad9d6, 0xfbfe78b4, 0x00000001, 0x00000194, 0x00000003,
26434 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26435 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26436 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26437 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26438 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26439 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
26440 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26441 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
26442 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
26443 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
26444 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
26445 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
26447 static const DWORD gs_code[] =
26449 #if 0
26450 struct vertex
26452 float4 position : POSITION;
26453 float4 color : COLOR;
26454 float4 color2 : COLOR2;
26457 [maxvertexcount(1)]
26458 void main(point vertex input[1], inout PointStream<vertex> output)
26460 output.Append(input[0]);
26462 #endif
26463 0x43425844, 0x218f7d27, 0x555fa7f1, 0x282c545f, 0x3989c843, 0x00000001, 0x000001c0, 0x00000003,
26464 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26465 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26466 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26467 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26468 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26469 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
26470 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26471 0x000000bc, 0x00020040, 0x0000002f, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x0400005f,
26472 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000002, 0x0100085d,
26473 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x03000065,
26474 0x001020f2, 0x00000002, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
26475 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001,
26476 0x06000036, 0x001020f2, 0x00000002, 0x00201e46, 0x00000000, 0x00000002, 0x01000013, 0x0100003e,
26478 static const DWORD ps_code[] =
26480 #if 0
26481 float4 main(float4 position : SV_Position,
26482 float2 texcoord : TEXCOORD) : SV_Target
26484 return float4(position.xy, texcoord);
26486 #endif
26487 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
26488 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
26489 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
26490 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
26491 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
26492 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
26493 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
26494 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
26495 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
26497 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
26499 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26500 {"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26501 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
26503 static const D3D11_INPUT_ELEMENT_DESC layout_desc2[] =
26505 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26506 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26507 {"COLOR", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
26509 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26511 {0, "POSITION", 0, 0, 4, 0},
26512 {0, "COLOR", 0, 0, 3, 0},
26513 {0, "COLOR", 2, 0, 2, 0},
26515 static const D3D11_SO_DECLARATION_ENTRY so_declaration2[] =
26517 {0, "POSITION", 0, 0, 1, 0},
26518 {0, "POSITION", 0, 1, 1, 0},
26519 {0, "POSITION", 0, 2, 1, 0},
26520 {0, "POSITION", 0, 3, 1, 0},
26521 {0, "COLOR", 0, 0, 1, 0},
26522 {0, "COLOR", 0, 1, 1, 0},
26523 {0, "COLOR", 0, 2, 1, 0},
26524 {0, "COLOR", 2, 0, 1, 0},
26525 {0, "COLOR", 2, 1, 1, 0},
26527 static const D3D11_SO_DECLARATION_ENTRY so_declaration3[] =
26529 {0, "COLOR", 0, 2, 2, 0},
26530 {0, "COLOR", 2, 3, 1, 0},
26532 static const struct
26534 struct vec4 position;
26535 struct vec3 color;
26536 struct vec2 color2;
26538 vb_data[] =
26540 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},
26541 {{-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
26542 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.5f, 0.4f}},
26543 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.1f, 0.6f}},
26545 static const struct
26547 struct vec4 position;
26548 struct vec4 color;
26549 struct vec4 color2;
26551 vb_data2[] =
26553 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
26554 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
26555 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
26556 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
26558 static const unsigned int vb_stride[] = {sizeof(*vb_data), sizeof(*vb_data2)};
26559 static const float expected_data[] =
26561 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f,
26562 -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
26563 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.4f,
26564 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.1f, 0.6f,
26566 static const float expected_data2[] =
26568 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
26569 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
26570 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
26571 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
26573 static const float expected_data3[] =
26575 3.0f, 4.0f, 8.0f, 1.2f, 1.3f, 1.7f, 2.0f, 2.1f, 2.5f, 2.7f, 2.8f, 3.2f,
26577 static const struct
26579 BOOL with_ps;
26580 unsigned int vb_idx;
26581 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
26582 unsigned int so_entry_count;
26583 const float *expected_data;
26584 unsigned int expected_data_size;
26586 tests[] =
26588 {TRUE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
26589 {TRUE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
26590 {TRUE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
26591 {TRUE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
26592 {TRUE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
26594 {FALSE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
26595 {FALSE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
26596 {FALSE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
26597 {FALSE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
26598 {FALSE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
26601 if (!init_test_context(&test_context, &feature_level))
26602 return;
26604 device = test_context.device;
26605 context = test_context.immediate_context;
26607 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
26608 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data2), vb_data2);
26610 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
26611 vs_code, sizeof(vs_code), &input_layout[0]);
26612 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26613 hr = ID3D11Device_CreateInputLayout(device, layout_desc2, ARRAY_SIZE(layout_desc2),
26614 vs_code, sizeof(vs_code), &input_layout[1]);
26615 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26617 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
26618 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
26619 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
26620 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
26622 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
26623 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
26625 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26627 gs = NULL;
26628 current_so_declaration = NULL;
26629 for (i = 0; i < ARRAY_SIZE(tests); ++i)
26631 ID3D11DeviceContext_PSSetShader(context, tests[i].with_ps ? ps : NULL, NULL, 0);
26633 if (current_so_declaration != tests[i].so_declaration)
26635 if (gs)
26636 ID3D11GeometryShader_Release(gs);
26638 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
26639 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
26640 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
26641 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
26642 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26643 current_so_declaration = tests[i].so_declaration;
26646 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].vb_idx]);
26647 stride = vb_stride[tests[i].vb_idx];
26648 offset = 0;
26649 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[tests[i].vb_idx], &stride, &offset);
26651 offset = 0;
26652 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
26654 ID3D11DeviceContext_Draw(context, 4, 0);
26656 get_buffer_readback(so_buffer, &rb);
26657 result = rb.map_desc.pData;
26658 for (j = 0; j < tests[i].expected_data_size; ++j)
26660 float expected_value = tests[i].expected_data[j];
26661 ok(compare_float(result[j], expected_value, 2),
26662 "Test %u: Got %.8e, expected %.8e at %u.\n",
26663 i, result[j], expected_value, j);
26665 release_resource_readback(&rb);
26668 for (i = 0; i < ARRAY_SIZE(vb); ++i)
26669 ID3D11Buffer_Release(vb[i]);
26670 ID3D11Buffer_Release(so_buffer);
26671 ID3D11VertexShader_Release(vs);
26672 ID3D11GeometryShader_Release(gs);
26673 ID3D11PixelShader_Release(ps);
26674 for (i = 0; i < ARRAY_SIZE(input_layout); ++i)
26675 ID3D11InputLayout_Release(input_layout[i]);
26676 release_test_context(&test_context);
26679 static void test_stream_output_vs(void)
26681 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
26682 struct d3d11_test_context test_context;
26683 ID3D11InputLayout *input_layout;
26684 ID3D11Buffer *vb, *so_buffer;
26685 ID3D11DeviceContext *context;
26686 struct resource_readback rb;
26687 ID3D11GeometryShader *gs;
26688 ID3D11VertexShader *vs;
26689 ID3D11Device *device;
26690 const float *result;
26691 unsigned int offset;
26692 unsigned int i, j;
26693 HRESULT hr;
26695 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26696 static const DWORD vs_code[] =
26698 #if 0
26699 struct vertex
26701 float4 position : POSITION;
26702 float4 color0 : COLOR0;
26703 float4 color1 : COLOR1;
26706 vertex main(in vertex i)
26708 return i;
26710 #endif
26711 0x43425844, 0xa67e993e, 0x1632c139, 0x02a7725f, 0xfb0221cd, 0x00000001, 0x00000194, 0x00000003,
26712 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26713 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26714 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
26715 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26716 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26717 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000001, 0x00000000,
26718 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26719 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
26720 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
26721 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
26722 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
26723 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
26725 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
26727 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26728 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26729 {"COLOR", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
26731 static const D3D11_SO_DECLARATION_ENTRY all_so_decl[] =
26733 {0, "POSITION", 0, 0, 4, 0},
26734 {0, "COLOR", 0, 0, 3, 0},
26735 {0, "COLOR", 1, 0, 2, 0},
26737 static const D3D11_SO_DECLARATION_ENTRY position_so_decl[] =
26739 {0, "POSITION", 0, 0, 4, 0},
26741 static const D3D11_SO_DECLARATION_ENTRY position2_so_decl[] =
26743 {0, "POSITION", 0, 0, 2, 0},
26745 static const struct
26747 struct vec4 position;
26748 struct vec4 color0;
26749 struct vec4 color1;
26751 vb_data[] =
26753 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
26754 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
26755 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
26756 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
26758 static const unsigned int vb_stride[] = {sizeof(*vb_data)};
26759 static const float expected_data[] =
26761 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
26762 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
26763 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
26764 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
26766 static const float expected_data2[] =
26768 -1.0f, -1.0f, 0.0f, 1.0f,
26769 -1.0f, 1.0f, 0.0f, 1.0f,
26770 1.0f, -1.0f, 0.0f, 1.0f,
26771 1.0f, 1.0f, 0.0f, 1.0f,
26773 static const float expected_data3[] =
26775 -1.0f, -1.0f,
26776 -1.0f, 1.0f,
26777 1.0f, -1.0f,
26778 1.0f, 1.0f,
26780 static const struct
26782 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
26783 unsigned int so_entry_count;
26784 const float *expected_data;
26785 unsigned int expected_data_size;
26787 tests[] =
26789 {all_so_decl, ARRAY_SIZE(all_so_decl), expected_data, ARRAY_SIZE(expected_data)},
26790 {position_so_decl, ARRAY_SIZE(position_so_decl), expected_data2, ARRAY_SIZE(expected_data2)},
26791 {position2_so_decl, ARRAY_SIZE(position2_so_decl), expected_data3, ARRAY_SIZE(expected_data3)},
26794 if (!init_test_context(&test_context, &feature_level))
26795 return;
26797 device = test_context.device;
26798 context = test_context.immediate_context;
26800 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
26802 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
26803 vs_code, sizeof(vs_code), &input_layout);
26804 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26806 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
26807 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
26809 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26811 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
26812 offset = 0;
26813 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, vb_stride, &offset);
26814 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
26816 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
26818 gs = NULL;
26819 current_so_declaration = NULL;
26820 for (i = 0; i < ARRAY_SIZE(tests); ++i)
26822 if (current_so_declaration != tests[i].so_declaration)
26824 if (gs)
26825 ID3D11GeometryShader_Release(gs);
26827 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
26828 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
26829 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
26830 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
26831 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26832 current_so_declaration = tests[i].so_declaration;
26835 offset = 0;
26836 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
26838 ID3D11DeviceContext_Draw(context, 4, 0);
26840 get_buffer_readback(so_buffer, &rb);
26841 result = rb.map_desc.pData;
26842 for (j = 0; j < tests[i].expected_data_size; ++j)
26844 float expected_value = tests[i].expected_data[j];
26845 ok(compare_float(result[j], expected_value, 2),
26846 "Test %u: Got %.8e, expected %.8e at %u.\n",
26847 i, result[j], expected_value, j);
26849 release_resource_readback(&rb);
26852 ID3D11Buffer_Release(vb);
26853 ID3D11Buffer_Release(so_buffer);
26854 ID3D11VertexShader_Release(vs);
26855 ID3D11GeometryShader_Release(gs);
26856 ID3D11InputLayout_Release(input_layout);
26857 release_test_context(&test_context);
26860 static void test_gather(void)
26862 struct
26864 int width, height;
26865 int offset_x, offset_y;
26866 } constant;
26867 struct d3d11_test_context test_context;
26868 D3D11_TEXTURE2D_DESC texture_desc;
26869 ID3D11ShaderResourceView *srv;
26870 ID3D11Texture2D *texture, *rt;
26871 ID3D11DeviceContext *context;
26872 ID3D11RenderTargetView *rtv;
26873 struct resource_readback rb;
26874 ID3D11PixelShader *ps;
26875 ID3D11Device *device;
26876 unsigned int x, y;
26877 ID3D11Buffer *cb;
26878 HRESULT hr;
26880 static const DWORD gather4_code[] =
26882 #if 0
26883 SamplerState s;
26884 Texture2D<float4> t;
26886 int2 size;
26888 float4 main(float4 position : SV_Position) : SV_Target
26890 return t.Gather(s, position.xy / size);
26892 #endif
26893 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
26894 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26895 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26896 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26897 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
26898 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
26899 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
26900 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
26901 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
26902 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
26903 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
26905 static const DWORD gather4_offset_code[] =
26907 #if 0
26908 SamplerState s;
26909 Texture2D<float4> t;
26911 int2 size;
26913 float4 main(float4 position : SV_Position) : SV_Target
26915 return t.Gather(s, position.xy / size, int2(1, 1));
26917 #endif
26918 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
26919 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26920 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26921 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26922 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
26923 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
26924 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
26925 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
26926 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
26927 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
26928 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
26930 static const DWORD gather4_green_code[] =
26932 #if 0
26933 SamplerState s;
26934 Texture2D<float4> t;
26936 int2 size;
26938 float4 main(float4 position : SV_Position) : SV_Target
26940 return t.GatherGreen(s, position.xy / size);
26942 #endif
26943 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
26944 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26945 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26946 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26947 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
26948 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
26949 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
26950 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
26951 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
26952 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
26953 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
26955 static const DWORD gather4_po_code[] =
26957 #if 0
26958 SamplerState s;
26959 Texture2D<float4> t;
26961 int2 size;
26962 int2 offset;
26964 float4 main(float4 position : SV_Position) : SV_Target
26966 return t.Gather(s, position.xy / size, offset);
26968 #endif
26969 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
26970 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26971 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26972 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26973 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
26974 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
26975 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
26976 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
26977 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
26978 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
26979 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
26980 0x00000000, 0x0100003e,
26982 static const struct vec4 texture_data[] =
26984 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
26985 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
26986 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
26987 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
26989 static const struct vec4 expected_gather4[] =
26991 {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},
26992 {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},
26993 {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},
26994 {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},
26996 static const struct vec4 expected_gather4_offset[] =
26998 {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},
26999 {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},
27000 {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},
27001 {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},
27003 static const struct vec4 expected_gather4_green[] =
27005 {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},
27006 {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},
27007 {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},
27008 {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},
27010 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
27011 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
27013 if (!init_test_context(&test_context, NULL))
27014 return;
27016 device = test_context.device;
27017 context = test_context.immediate_context;
27019 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
27021 skip("Shader model 4.1 required for gather4 instruction.\n");
27022 release_test_context(&test_context);
27023 return;
27026 texture_desc.Width = 4;
27027 texture_desc.Height = 4;
27028 texture_desc.MipLevels = 1;
27029 texture_desc.ArraySize = 1;
27030 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27031 texture_desc.SampleDesc.Count = 1;
27032 texture_desc.SampleDesc.Quality = 0;
27033 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27034 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27035 texture_desc.CPUAccessFlags = 0;
27036 texture_desc.MiscFlags = 0;
27037 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27038 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27039 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27040 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27041 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27043 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
27044 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
27045 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27046 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
27047 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
27048 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
27050 constant.width = texture_desc.Width;
27051 constant.height = texture_desc.Height;
27052 constant.offset_x = 1;
27053 constant.offset_y = 1;
27054 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
27055 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
27057 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
27058 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27059 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27061 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27062 draw_quad(&test_context);
27063 get_texture_readback(rt, 0, &rb);
27064 for (y = 0; y < texture_desc.Height; ++y)
27066 for (x = 0; x < texture_desc.Width; ++x)
27068 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
27069 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27070 ok(compare_vec4(got, expected, 0),
27071 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27072 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27075 release_resource_readback(&rb);
27077 ID3D11PixelShader_Release(ps);
27078 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
27079 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27080 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27082 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27083 draw_quad(&test_context);
27084 get_texture_readback(rt, 0, &rb);
27085 for (y = 0; y < texture_desc.Height; ++y)
27087 for (x = 0; x < texture_desc.Width; ++x)
27089 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
27090 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27091 ok(compare_vec4(got, expected, 0),
27092 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27093 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27096 release_resource_readback(&rb);
27098 ID3D11PixelShader_Release(ps);
27100 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
27102 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
27103 goto done;
27106 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
27107 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27108 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27110 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27111 draw_quad(&test_context);
27112 get_texture_readback(rt, 0, &rb);
27113 for (y = 0; y < texture_desc.Height; ++y)
27115 for (x = 0; x < texture_desc.Width; ++x)
27117 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
27118 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27119 ok(compare_vec4(got, expected, 0),
27120 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27121 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27124 release_resource_readback(&rb);
27126 ID3D11PixelShader_Release(ps);
27127 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
27128 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27129 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27131 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27132 draw_quad(&test_context);
27133 get_texture_readback(rt, 0, &rb);
27134 for (y = 0; y < texture_desc.Height; ++y)
27136 for (x = 0; x < texture_desc.Width; ++x)
27138 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
27139 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27140 ok(compare_vec4(got, expected, 0),
27141 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27142 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27145 release_resource_readback(&rb);
27147 constant.offset_x = 0;
27148 constant.offset_y = 0;
27149 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
27150 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27151 draw_quad(&test_context);
27152 get_texture_readback(rt, 0, &rb);
27153 for (y = 0; y < texture_desc.Height; ++y)
27155 for (x = 0; x < texture_desc.Width; ++x)
27157 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
27158 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27159 ok(compare_vec4(got, expected, 0),
27160 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27161 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27164 release_resource_readback(&rb);
27166 ID3D11PixelShader_Release(ps);
27168 done:
27169 ID3D11Buffer_Release(cb);
27170 ID3D11Texture2D_Release(rt);
27171 ID3D11Texture2D_Release(texture);
27172 ID3D11RenderTargetView_Release(rtv);
27173 ID3D11ShaderResourceView_Release(srv);
27174 release_test_context(&test_context);
27177 static void test_gather_c(void)
27179 struct
27181 int width, height;
27182 int offset_x, offset_y;
27183 float compare_value;
27184 int padding[3];
27185 } constant;
27186 struct d3d11_test_context test_context;
27187 D3D11_TEXTURE2D_DESC texture_desc;
27188 D3D11_SAMPLER_DESC sampler_desc;
27189 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
27190 ID3D11ShaderResourceView *srv;
27191 ID3D11Texture2D *texture, *rt;
27192 ID3D11DeviceContext *context;
27193 ID3D11SamplerState *sampler;
27194 ID3D11RenderTargetView *rtv;
27195 struct resource_readback rb;
27196 ID3D11PixelShader *ps;
27197 ID3D11Device *device;
27198 unsigned int x, y;
27199 ID3D11Buffer *cb;
27200 HRESULT hr;
27202 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27203 static const DWORD gather4_c_code[] =
27205 #if 0
27206 SamplerComparisonState s;
27207 Texture2D<float4> t;
27209 int2 size;
27210 int2 offset;
27211 float compare;
27213 float4 main(float4 position : SV_Position) : SV_Target
27215 return t.GatherCmp(s, position.xy / size, compare);
27217 #endif
27218 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
27219 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27220 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27221 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27222 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
27223 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
27224 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27225 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27226 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27227 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27228 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
27229 0x00000001, 0x0100003e,
27231 static const DWORD gather4_po_c_code[] =
27233 #if 0
27234 SamplerComparisonState s;
27235 Texture2D<float4> t;
27237 int2 size;
27238 int2 offset;
27239 float compare;
27241 float4 main(float4 position : SV_Position) : SV_Target
27243 return t.GatherCmp(s, position.xy / size, compare, offset);
27245 #endif
27246 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
27247 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27248 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27249 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27250 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
27251 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
27252 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27253 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27254 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27255 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27256 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
27257 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
27259 static const float texture_data[] =
27261 0.00f, 0.10f, 0.20f, 0.30f,
27262 0.40f, 0.50f, 0.60f, 0.70f,
27263 0.80f, 0.90f, 0.05f, 0.15f,
27264 0.25f, 0.35f, 0.45f, 0.55f,
27266 static const struct vec4 expected_gather4_c[] =
27268 {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},
27269 {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},
27270 {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},
27271 {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},
27273 static const struct vec4 expected_gather4_po_c[] =
27275 {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},
27276 {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},
27277 {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},
27278 {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},
27280 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
27281 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
27283 if (!init_test_context(&test_context, &feature_level))
27284 return;
27286 device = test_context.device;
27287 context = test_context.immediate_context;
27289 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
27290 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
27291 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
27292 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
27293 sampler_desc.MipLODBias = 0.0f;
27294 sampler_desc.MaxAnisotropy = 0;
27295 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
27296 sampler_desc.BorderColor[0] = 0.0f;
27297 sampler_desc.BorderColor[1] = 0.0f;
27298 sampler_desc.BorderColor[2] = 0.0f;
27299 sampler_desc.BorderColor[3] = 0.0f;
27300 sampler_desc.MinLOD = 0.0f;
27301 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
27303 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
27304 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
27305 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
27307 texture_desc.Width = 4;
27308 texture_desc.Height = 4;
27309 texture_desc.MipLevels = 1;
27310 texture_desc.ArraySize = 1;
27311 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27312 texture_desc.SampleDesc.Count = 1;
27313 texture_desc.SampleDesc.Quality = 0;
27314 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27315 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27316 texture_desc.CPUAccessFlags = 0;
27317 texture_desc.MiscFlags = 0;
27318 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27319 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27320 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27321 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27322 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27324 constant.width = texture_desc.Width;
27325 constant.height = texture_desc.Height;
27326 constant.offset_x = 1;
27327 constant.offset_y = 1;
27328 constant.compare_value = 0.5f;
27329 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
27330 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
27332 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
27333 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
27334 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
27335 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27337 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
27338 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
27339 U(srv_desc).Texture2D.MostDetailedMip = 0;
27340 U(srv_desc).Texture2D.MipLevels = 1;
27341 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
27342 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
27343 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
27345 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
27346 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27347 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27349 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27350 draw_quad(&test_context);
27351 get_texture_readback(rt, 0, &rb);
27352 for (y = 0; y < texture_desc.Height; ++y)
27354 for (x = 0; x < texture_desc.Width; ++x)
27356 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
27357 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27358 ok(compare_vec4(got, expected, 0),
27359 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27360 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27363 release_resource_readback(&rb);
27364 ID3D11PixelShader_Release(ps);
27366 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
27367 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27368 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27370 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27371 draw_quad(&test_context);
27372 get_texture_readback(rt, 0, &rb);
27373 for (y = 0; y < texture_desc.Height; ++y)
27375 for (x = 0; x < texture_desc.Width; ++x)
27377 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
27378 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27379 ok(compare_vec4(got, expected, 0),
27380 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27381 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27384 release_resource_readback(&rb);
27385 ID3D11PixelShader_Release(ps);
27387 ID3D11ShaderResourceView_Release(srv);
27388 ID3D11Texture2D_Release(texture);
27390 ID3D11Buffer_Release(cb);
27391 ID3D11Texture2D_Release(rt);
27392 ID3D11RenderTargetView_Release(rtv);
27393 ID3D11SamplerState_Release(sampler);
27394 release_test_context(&test_context);
27397 static float clamp_depth_bias(float bias, float clamp)
27399 if (clamp > 0.0f)
27400 return min(bias, clamp);
27401 if (clamp < 0.0f)
27402 return max(bias, clamp);
27403 return bias;
27406 static void test_depth_bias(void)
27408 struct vec3 vertices[] =
27410 {-1.0f, -1.0f, 0.5f},
27411 {-1.0f, 1.0f, 0.5f},
27412 { 1.0f, -1.0f, 0.5f},
27413 { 1.0f, 1.0f, 0.5f},
27415 struct d3d11_test_context test_context;
27416 D3D11_RASTERIZER_DESC rasterizer_desc;
27417 struct swapchain_desc swapchain_desc;
27418 D3D11_TEXTURE2D_DESC texture_desc;
27419 ID3D11DeviceContext *context;
27420 double m, bias, depth, data;
27421 struct resource_readback rb;
27422 ID3D11DepthStencilView *dsv;
27423 unsigned int expected_value;
27424 ID3D11RasterizerState *rs;
27425 ID3D11Texture2D *texture;
27426 unsigned int format_idx;
27427 unsigned int y, i, j, k;
27428 unsigned int shift = 0;
27429 ID3D11Device *device;
27430 float *depth_values;
27431 DXGI_FORMAT format;
27432 const UINT32 *u32;
27433 const UINT16 *u16;
27434 UINT32 u32_value;
27435 HRESULT hr;
27437 static const struct
27439 float z;
27440 float exponent;
27442 quads[] =
27444 {0.125f, -3.0f},
27445 {0.250f, -2.0f},
27446 {0.500f, -1.0f},
27447 {1.000f, 0.0f},
27449 static const int bias_tests[] =
27451 -10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
27452 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000,
27454 static const float bias_clamp_tests[] =
27456 0.0f, -1e-5f, 1e-5f,
27458 static const float quad_slopes[] =
27460 0.0f, 0.5f, 1.0f
27462 static const float slope_scaled_bias_tests[] =
27464 0.0f, 0.5f, 1.0f, 2.0f, 128.0f, 1000.0f, 10000.0f,
27466 static const DXGI_FORMAT formats[] =
27468 DXGI_FORMAT_D32_FLOAT,
27469 DXGI_FORMAT_D24_UNORM_S8_UINT,
27470 DXGI_FORMAT_D16_UNORM,
27473 swapchain_desc.windowed = TRUE;
27474 swapchain_desc.buffer_count = 1;
27475 swapchain_desc.width = 200;
27476 swapchain_desc.height = 200;
27477 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
27478 swapchain_desc.flags = 0;
27479 if (!init_test_context_ext(&test_context, NULL, &swapchain_desc))
27480 return;
27482 device = test_context.device;
27483 context = test_context.immediate_context;
27485 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
27486 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
27487 rasterizer_desc.CullMode = D3D11_CULL_NONE;
27488 rasterizer_desc.FrontCounterClockwise = FALSE;
27489 rasterizer_desc.DepthBias = 0;
27490 rasterizer_desc.DepthBiasClamp = 0.0f;
27491 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
27492 rasterizer_desc.DepthClipEnable = TRUE;
27494 depth_values = heap_calloc(swapchain_desc.height, sizeof(*depth_values));
27495 ok(!!depth_values, "Failed to allocate memory.\n");
27497 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
27499 format = formats[format_idx];
27501 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
27502 texture_desc.Format = format;
27503 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
27504 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
27505 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27506 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
27507 ok(SUCCEEDED(hr), "Failed to create render depth stencil view, hr %#x.\n", hr);
27508 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
27509 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
27510 draw_quad_z(&test_context, 1.0f);
27511 switch (format)
27513 case DXGI_FORMAT_D32_FLOAT:
27514 check_texture_float(texture, 1.0f, 0);
27515 break;
27516 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27517 /* FIXME: Depth/stencil byte order is reversed in wined3d. */
27518 shift = get_texture_color(texture, 0, 0) == 0xffffff ? 0 : 8;
27519 todo_wine
27520 check_texture_color(texture, 0xffffff, 1);
27521 break;
27522 case DXGI_FORMAT_D16_UNORM:
27523 get_texture_readback(texture, 0, &rb);
27524 check_readback_data_u16(&rb, NULL, 0xffffu, 0);
27525 release_resource_readback(&rb);
27526 break;
27527 default:
27528 trace("Unhandled format %#x.\n", format);
27529 break;
27531 draw_quad(&test_context);
27533 /* DepthBias */
27534 for (i = 0; i < ARRAY_SIZE(quads); ++i)
27536 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
27537 vertices[j].z = quads[i].z;
27538 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
27539 0, NULL, vertices, 0, 0);
27541 for (j = 0; j < ARRAY_SIZE(bias_tests); ++j)
27543 rasterizer_desc.DepthBias = bias_tests[j];
27545 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
27547 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
27548 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
27549 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
27550 ID3D11DeviceContext_RSSetState(context, rs);
27551 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27552 draw_quad(&test_context);
27553 switch (format)
27555 case DXGI_FORMAT_D32_FLOAT:
27556 bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f);
27557 bias = clamp_depth_bias(bias, rasterizer_desc.DepthBiasClamp);
27558 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27560 check_texture_float(texture, depth, 2);
27561 break;
27562 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27563 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 16777215.0f,
27564 rasterizer_desc.DepthBiasClamp);
27565 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27567 get_texture_readback(texture, 0, &rb);
27568 check_readback_data_u24(&rb, NULL, shift, depth * 16777215.0f + 0.5f, 1);
27569 release_resource_readback(&rb);
27570 break;
27571 case DXGI_FORMAT_D16_UNORM:
27572 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 65535.0f,
27573 rasterizer_desc.DepthBiasClamp);
27574 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27576 get_texture_readback(texture, 0, &rb);
27577 check_readback_data_u16(&rb, NULL, depth * 65535.0f + 0.5f, 1);
27578 release_resource_readback(&rb);
27579 break;
27580 default:
27581 break;
27583 ID3D11RasterizerState_Release(rs);
27588 /* SlopeScaledDepthBias */
27589 rasterizer_desc.DepthBias = 0;
27590 for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i)
27592 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
27593 vertices[j].z = j == 1 || j == 3 ? 0.0f : quad_slopes[i];
27594 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
27595 0, NULL, vertices, 0, 0);
27597 ID3D11DeviceContext_RSSetState(context, NULL);
27598 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27599 draw_quad(&test_context);
27600 get_texture_readback(texture, 0, &rb);
27601 for (y = 0; y < texture_desc.Height; ++y)
27603 switch (format)
27605 case DXGI_FORMAT_D32_FLOAT:
27606 depth_values[y] = get_readback_float(&rb, 0, y);
27607 break;
27608 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27609 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
27610 u32_value = *u32 >> shift;
27611 depth_values[y] = u32_value / 16777215.0f;
27612 break;
27613 case DXGI_FORMAT_D16_UNORM:
27614 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
27615 depth_values[y] = *u16 / 65535.0f;
27616 break;
27617 default:
27618 break;
27621 release_resource_readback(&rb);
27623 for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j)
27625 rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j];
27627 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
27629 BOOL all_match = TRUE;
27630 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
27631 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
27632 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
27633 ID3D11DeviceContext_RSSetState(context, rs);
27634 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27635 draw_quad(&test_context);
27637 m = quad_slopes[i] / texture_desc.Height;
27638 bias = clamp_depth_bias(rasterizer_desc.SlopeScaledDepthBias * m, rasterizer_desc.DepthBiasClamp);
27639 get_texture_readback(texture, 0, &rb);
27640 for (y = 0; y < texture_desc.Height && all_match; ++y)
27642 depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
27643 switch (format)
27645 case DXGI_FORMAT_D32_FLOAT:
27646 data = get_readback_float(&rb, 0, y);
27647 all_match = compare_float(data, depth, 64);
27648 ok(all_match,
27649 "Got depth %.8e, expected %.8e.\n", data, depth);
27650 break;
27651 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27652 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
27653 u32_value = *u32 >> shift;
27654 expected_value = depth * 16777215.0f + 0.5f;
27655 all_match = compare_uint(u32_value, expected_value, 3);
27656 ok(all_match,
27657 "Got value %#x (%.8e), expected %#x (%.8e).\n",
27658 u32_value, u32_value / 16777215.0f,
27659 expected_value, expected_value / 16777215.0f);
27660 break;
27661 case DXGI_FORMAT_D16_UNORM:
27662 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
27663 expected_value = depth * 65535.0f + 0.5f;
27664 all_match = compare_uint(*u16, expected_value, 1);
27665 ok(all_match,
27666 "Got value %#x (%.8e), expected %#x (%.8e).\n",
27667 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
27668 break;
27669 default:
27670 break;
27673 release_resource_readback(&rb);
27674 ID3D11RasterizerState_Release(rs);
27679 ID3D11Texture2D_Release(texture);
27680 ID3D11DepthStencilView_Release(dsv);
27683 heap_free(depth_values);
27684 release_test_context(&test_context);
27687 static void test_fractional_viewports(void)
27689 struct d3d11_test_context test_context;
27690 D3D11_TEXTURE2D_DESC texture_desc;
27691 ID3D11InputLayout *input_layout;
27692 ID3D11DeviceContext *context;
27693 struct resource_readback rb;
27694 ID3D11RenderTargetView *rtv;
27695 ID3D11VertexShader *vs;
27696 ID3D11PixelShader *ps;
27697 unsigned int i, x, y;
27698 ID3D11Device *device;
27699 ID3D11Texture2D *rt;
27700 UINT offset, stride;
27701 ID3D11Buffer *vb;
27702 HRESULT hr;
27704 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27705 static const DWORD vs_code[] =
27707 #if 0
27708 void main(in float4 in_position : POSITION,
27709 in float2 in_texcoord : TEXCOORD,
27710 out float4 position : SV_Position,
27711 out float2 texcoord : TEXCOORD)
27713 position = in_position;
27714 texcoord = in_texcoord;
27716 #endif
27717 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
27718 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
27719 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
27720 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
27721 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
27722 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
27723 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
27724 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
27725 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
27726 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
27727 0x00000001, 0x0100003e,
27729 static const DWORD ps_code[] =
27731 #if 0
27732 float4 main(float4 position : SV_Position,
27733 float2 texcoord : TEXCOORD) : SV_Target
27735 return float4(position.xy, texcoord);
27737 #endif
27738 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
27739 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
27740 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
27741 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
27742 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
27743 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
27744 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
27745 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
27746 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
27748 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
27750 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
27751 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
27753 static const struct
27755 struct vec2 position;
27756 struct vec2 texcoord;
27758 quad[] =
27760 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
27761 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
27762 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
27763 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
27765 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
27766 static const float viewport_offsets[] =
27768 0.0f, 1.0f / 2.0f, 1.0f / 4.0f, 1.0f / 8.0f, 1.0f / 16.0f, 1.0f / 32.0f,
27769 1.0f / 64.0f, 1.0f / 128.0f, 1.0f / 256.0f, 63.0f / 128.0f,
27772 if (!init_test_context(&test_context, &feature_level))
27773 return;
27774 device = test_context.device;
27775 context = test_context.immediate_context;
27777 texture_desc.Width = 4;
27778 texture_desc.Height = 4;
27779 texture_desc.MipLevels = 1;
27780 texture_desc.ArraySize = 1;
27781 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27782 texture_desc.SampleDesc.Count = 1;
27783 texture_desc.SampleDesc.Quality = 0;
27784 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27785 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27786 texture_desc.CPUAccessFlags = 0;
27787 texture_desc.MiscFlags = 0;
27788 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27789 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27790 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27791 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27792 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27794 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
27795 vs_code, sizeof(vs_code), &input_layout);
27796 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
27797 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
27799 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
27800 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
27801 stride = sizeof(*quad);
27802 offset = 0;
27803 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
27805 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
27806 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
27807 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
27809 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
27810 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27811 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27813 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
27815 set_viewport(context, viewport_offsets[i], viewport_offsets[i],
27816 texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
27817 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
27818 ID3D11DeviceContext_Draw(context, 4, 0);
27819 get_texture_readback(rt, 0, &rb);
27820 for (y = 0; y < texture_desc.Height; ++y)
27822 for (x = 0; x < texture_desc.Width; ++x)
27824 const struct vec4 *v = get_readback_vec4(&rb, x, y);
27825 struct vec4 expected = {x + 0.5f, y + 0.5f,
27826 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
27827 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
27828 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
27829 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
27830 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
27831 todo_wine
27832 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
27833 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
27834 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
27837 release_resource_readback(&rb);
27840 ID3D11InputLayout_Release(input_layout);
27841 ID3D11Buffer_Release(vb);
27842 ID3D11VertexShader_Release(vs);
27843 ID3D11PixelShader_Release(ps);
27844 ID3D11RenderTargetView_Release(rtv);
27845 ID3D11Texture2D_Release(rt);
27846 release_test_context(&test_context);
27849 static void test_negative_viewports(const D3D_FEATURE_LEVEL feature_level)
27851 struct d3d11_test_context test_context;
27852 ID3D11DeviceContext *context;
27853 BOOL quirk;
27854 RECT rect;
27856 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
27857 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
27859 if (!init_test_context(&test_context, &feature_level))
27860 return;
27861 context = test_context.immediate_context;
27863 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
27864 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27865 draw_color_quad(&test_context, &green);
27866 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
27868 set_viewport(context, -0.0f, -0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
27869 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27870 draw_color_quad(&test_context, &green);
27871 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
27873 /* For feature levels greater than or equal to 11_0, a negative top left
27874 * corner shifts the bottom right corner by a whole integer. It seems that
27875 * floor() is used to round viewport corners to integers.
27877 quirk = feature_level >= D3D_FEATURE_LEVEL_11_0;
27879 set_viewport(context, -0.4f, -0.4f, 640.0f, 480.0f, 0.0f, 1.0f);
27880 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27881 draw_color_quad(&test_context, &green);
27882 SetRect(&rect, 0, 0, 639, 479);
27883 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
27884 SetRect(&rect, 639, 479, 640, 480);
27885 todo_wine_if(quirk)
27886 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
27888 set_viewport(context, -1.0f / 128.0f, -1.0 / 128.0f, 640.0f, 480.0f, 0.0f, 1.0f);
27889 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27890 draw_color_quad(&test_context, &green);
27891 SetRect(&rect, 0, 0, 639, 479);
27892 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
27893 SetRect(&rect, 639, 479, 640, 480);
27894 todo_wine_if(quirk)
27895 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
27897 release_test_context(&test_context);
27900 static void test_early_depth_stencil(void)
27902 ID3D11DepthStencilState *depth_stencil_state;
27903 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
27904 ID3D11Texture2D *texture, *depth_texture;
27905 struct d3d11_test_context test_context;
27906 D3D11_TEXTURE2D_DESC texture_desc;
27907 ID3D11UnorderedAccessView *uav;
27908 ID3D11DeviceContext *context;
27909 ID3D11DepthStencilView *dsv;
27910 ID3D11PixelShader *ps;
27911 ID3D11Device *device;
27912 HRESULT hr;
27914 static const DWORD ps_code[] =
27916 #if 0
27917 RWTexture2D<int> u;
27919 [earlydepthstencil]
27920 float4 main() : SV_Target
27922 InterlockedAdd(u[uint2(0, 0)], 1);
27923 return float4(1.0f, 1.0f, 1.0f, 1.0f);
27925 #endif
27926 0x43425844, 0xda4325ad, 0xc01d3815, 0xfd610cc9, 0x8ed1e351, 0x00000001, 0x000000ec, 0x00000003,
27927 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
27928 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
27929 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000074, 0x00000050, 0x0000001d,
27930 0x0100286a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x03000065, 0x001020f2, 0x00000000,
27931 0x0a0000ad, 0x0011e000, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
27932 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
27933 0x3f800000, 0x3f800000, 0x0100003e,
27935 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27936 static const UINT values[4] = {0};
27938 if (!init_test_context(&test_context, &feature_level))
27939 return;
27941 device = test_context.device;
27942 context = test_context.immediate_context;
27944 depth_stencil_desc.DepthEnable = TRUE;
27945 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
27946 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
27947 depth_stencil_desc.StencilEnable = FALSE;
27948 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
27949 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
27951 texture_desc.Width = 1;
27952 texture_desc.Height = 1;
27953 texture_desc.MipLevels = 1;
27954 texture_desc.ArraySize = 1;
27955 texture_desc.Format = DXGI_FORMAT_R32_SINT;
27956 texture_desc.SampleDesc.Count = 1;
27957 texture_desc.SampleDesc.Quality = 0;
27958 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27959 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
27960 texture_desc.CPUAccessFlags = 0;
27961 texture_desc.MiscFlags = 0;
27962 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
27963 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27964 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
27965 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
27967 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
27968 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
27969 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27970 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
27971 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
27972 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27973 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
27974 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
27976 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
27977 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27978 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27980 set_viewport(context, 0.0f, 0.0f, 1.0f, 100.0f, 0.5f, 0.5f);
27981 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
27982 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
27983 1, &test_context.backbuffer_rtv, dsv, 1, 1, &uav, NULL);
27985 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
27987 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
27988 draw_quad(&test_context);
27989 check_texture_color(texture, 100, 1);
27990 draw_quad(&test_context);
27991 check_texture_color(texture, 200, 1);
27992 check_texture_float(depth_texture, 0.6f, 1);
27994 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.3f, 0);
27995 draw_quad(&test_context);
27996 draw_quad(&test_context);
27997 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.55f, 0);
27998 draw_quad(&test_context);
27999 check_texture_color(texture, 300, 1);
28001 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
28002 draw_quad(&test_context);
28003 check_texture_color(texture, 400, 1);
28004 check_texture_float(depth_texture, 0.5f, 1);
28006 ID3D11Texture2D_Release(depth_texture);
28007 ID3D11DepthStencilView_Release(dsv);
28008 ID3D11DepthStencilState_Release(depth_stencil_state);
28009 ID3D11PixelShader_Release(ps);
28010 ID3D11Texture2D_Release(texture);
28011 ID3D11UnorderedAccessView_Release(uav);
28012 release_test_context(&test_context);
28015 static void test_conservative_depth_output(void)
28017 struct shader
28019 const DWORD *code;
28020 size_t size;
28023 ID3D11DepthStencilState *depth_stencil_state;
28024 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
28025 struct d3d11_test_context test_context;
28026 const struct shader *current_shader;
28027 D3D11_TEXTURE2D_DESC texture_desc;
28028 ID3D11DeviceContext *context;
28029 ID3D11DepthStencilView *dsv;
28030 ID3D11Texture2D *texture;
28031 ID3D11PixelShader *ps;
28032 DWORD expected_color;
28033 float expected_depth;
28034 ID3D11Device *device;
28035 struct vec4 ps_depth;
28036 ID3D11Buffer *cb;
28037 unsigned int i;
28038 HRESULT hr;
28040 static const DWORD ps_depth_le_code[] =
28042 #if 0
28043 float depth;
28045 float4 main(out float out_depth : SV_DepthLessEqual) : SV_Target0
28047 out_depth = depth;
28048 return float4(0.0f, 1.0f, 0.f, 1.0f);
28050 #endif
28051 0x43425844, 0x045c8d00, 0xc49e2ebe, 0x76f6022a, 0xf6996ecc, 0x00000001, 0x00000108, 0x00000003,
28052 0x0000002c, 0x0000003c, 0x00000098, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28053 0x00000054, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28054 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
28055 0x65677261, 0x56530074, 0x7065445f, 0x654c6874, 0x71457373, 0x006c6175, 0x58454853, 0x00000068,
28056 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065,
28057 0x001020f2, 0x00000000, 0x02000065, 0x00027001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
28058 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00027001, 0x0020800a, 0x00000000,
28059 0x00000000, 0x0100003e,
28061 static const struct shader ps_depth_le = {ps_depth_le_code, sizeof(ps_depth_le_code)};
28062 static const DWORD ps_depth_ge_code[] =
28064 #if 0
28065 float depth;
28067 float4 main(out float out_depth : SV_DepthGreaterEqual) : SV_Target0
28069 out_depth = depth;
28070 return float4(0.0f, 1.0f, 0.f, 1.0f);
28072 #endif
28073 0x43425844, 0xd17af83e, 0xa32c01cc, 0x0d8e9665, 0xe6dc17c2, 0x00000001, 0x0000010c, 0x00000003,
28074 0x0000002c, 0x0000003c, 0x0000009c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28075 0x00000058, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28076 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
28077 0x65677261, 0x56530074, 0x7065445f, 0x72476874, 0x65746165, 0x75714572, 0xab006c61, 0x58454853,
28078 0x00000068, 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
28079 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x00026001, 0x08000036, 0x001020f2, 0x00000000,
28080 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00026001, 0x0020800a,
28081 0x00000000, 0x00000000, 0x0100003e,
28083 static const struct shader ps_depth_ge = {ps_depth_ge_code, sizeof(ps_depth_ge_code)};
28084 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
28085 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28086 static const struct
28088 const struct shader *ps;
28089 float vs_depth;
28090 float ps_depth;
28091 BOOL passes_depth_test;
28093 tests[] =
28095 {&ps_depth_le, 0.7f, 0.7f, TRUE},
28096 {&ps_depth_le, 0.7f, 0.4f, FALSE},
28097 {&ps_depth_le, 0.4f, 0.4f, FALSE},
28098 /* {&ps_depth_le, 0.4f, 0.6f, FALSE}, undefined result */
28099 {&ps_depth_ge, 0.7f, 0.7f, TRUE},
28100 /* {&ps_depth_ge, 0.7f, 0.4f, TRUE}, undefined result */
28101 {&ps_depth_ge, 0.4f, 0.4f, FALSE},
28102 {&ps_depth_ge, 0.4f, 0.6f, TRUE},
28105 if (!init_test_context(&test_context, &feature_level))
28106 return;
28108 device = test_context.device;
28109 context = test_context.immediate_context;
28111 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_depth), NULL);
28113 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28114 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
28115 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28116 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
28117 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
28118 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28119 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
28120 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
28122 depth_stencil_desc.DepthEnable = TRUE;
28123 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
28124 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_GREATER_EQUAL;
28125 depth_stencil_desc.StencilEnable = FALSE;
28126 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
28127 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
28129 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
28130 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
28131 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
28133 ps = NULL;
28134 current_shader = NULL;
28135 for (i = 0; i < ARRAY_SIZE(tests); ++i)
28137 if (current_shader != tests[i].ps)
28139 if (ps)
28140 ID3D11PixelShader_Release(ps);
28142 current_shader = tests[i].ps;
28143 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
28144 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
28145 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
28148 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28149 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
28150 ps_depth.x = tests[i].ps_depth;
28151 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_depth, 0, 0);
28152 draw_quad_z(&test_context, tests[i].vs_depth);
28154 expected_color = tests[i].passes_depth_test ? 0xff00ff00 : 0xffffffff;
28155 expected_depth = tests[i].passes_depth_test ? max(tests[i].vs_depth, tests[i].ps_depth) : 0.5f;
28156 check_texture_color(test_context.backbuffer, expected_color, 0);
28157 check_texture_float(texture, expected_depth, 1);
28160 ID3D11Buffer_Release(cb);
28161 ID3D11PixelShader_Release(ps);
28162 ID3D11DepthStencilView_Release(dsv);
28163 ID3D11DepthStencilState_Release(depth_stencil_state);
28164 ID3D11Texture2D_Release(texture);
28165 release_test_context(&test_context);
28168 static void test_format_compatibility(void)
28170 ID3D11Texture2D *dst_texture, *src_texture;
28171 D3D11_SUBRESOURCE_DATA resource_data;
28172 D3D11_TEXTURE2D_DESC texture_desc;
28173 ID3D11DeviceContext *context;
28174 struct resource_readback rb;
28175 DWORD colour, expected;
28176 ID3D11Device *device;
28177 unsigned int i, j;
28178 ULONG refcount;
28179 HRESULT hr;
28181 static const struct
28183 DXGI_FORMAT src_format;
28184 DXGI_FORMAT dst_format;
28185 size_t texel_size;
28186 BOOL success;
28187 BOOL src_ds;
28188 BOOL dst_ds;
28190 test_data[] =
28192 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
28193 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
28194 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
28195 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
28196 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
28197 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
28198 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
28199 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
28200 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
28201 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
28202 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
28203 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
28204 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
28205 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
28206 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
28207 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_TYPELESS, 4, TRUE},
28208 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_FLOAT, 4, TRUE},
28209 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_UINT, 4, TRUE},
28210 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_SINT, 4, TRUE},
28211 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, FALSE},
28212 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_B8G8R8A8_TYPELESS, 4, FALSE},
28213 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R16G16_TYPELESS, 4, FALSE},
28214 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
28215 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
28216 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
28217 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
28218 {DXGI_FORMAT_D16_UNORM, DXGI_FORMAT_R16_UNORM, 2, TRUE, TRUE},
28219 {DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_D16_UNORM, 2, TRUE, FALSE, TRUE},
28220 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_TYPELESS, 2, TRUE, TRUE},
28221 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_TYPELESS, 2, TRUE, FALSE, TRUE},
28223 static const DWORD initial_data[16] = {0};
28224 static const DWORD bitmap_data[] =
28226 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28227 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28228 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28229 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28232 if (!(device = create_device(NULL)))
28234 skip("Failed to create device.\n");
28235 return;
28237 ID3D11Device_GetImmediateContext(device, &context);
28239 texture_desc.Height = 4;
28240 texture_desc.MipLevels = 1;
28241 texture_desc.ArraySize = 1;
28242 texture_desc.SampleDesc.Count = 1;
28243 texture_desc.SampleDesc.Quality = 0;
28244 texture_desc.CPUAccessFlags = 0;
28245 texture_desc.MiscFlags = 0;
28247 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
28249 unsigned int x, y, texel_dwords;
28250 BOOL broken = FALSE;
28251 D3D11_BOX box;
28253 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
28254 texture_desc.Format = test_data[i].src_format;
28255 texture_desc.Usage = test_data[i].src_ds ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE;
28256 texture_desc.BindFlags = test_data[i].src_ds ? D3D11_BIND_DEPTH_STENCIL : D3D11_BIND_SHADER_RESOURCE;
28258 resource_data.pSysMem = bitmap_data;
28259 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
28260 resource_data.SysMemSlicePitch = 0;
28262 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
28263 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
28265 texture_desc.Format = test_data[i].dst_format;
28266 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28267 texture_desc.BindFlags = test_data[i].dst_ds ? D3D11_BIND_DEPTH_STENCIL : D3D11_BIND_SHADER_RESOURCE;
28269 resource_data.pSysMem = initial_data;
28271 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
28272 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
28274 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
28275 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0, 1, 1, 0,
28276 (ID3D11Resource *)src_texture, 0, &box);
28278 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
28279 get_texture_readback(dst_texture, 0, &rb);
28280 colour = get_readback_color(&rb, 0, 0, 0);
28281 if (test_data[i].src_format == DXGI_FORMAT_R9G9B9E5_SHAREDEXP && colour == bitmap_data[0])
28283 win_skip("Broken destination offset for %#x -> %#x copy.\n",
28284 test_data[i].src_format, test_data[i].dst_format);
28285 broken = TRUE;
28287 for (j = 0; j < ARRAY_SIZE(bitmap_data) && !broken; ++j)
28289 x = j % 4;
28290 y = j / 4;
28291 colour = get_readback_color(&rb, x, y, 0);
28292 expected = test_data[i].success && !test_data[i].src_ds && !test_data[i].dst_ds
28293 && x >= texel_dwords && y ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
28294 todo_wine_if((test_data[i].src_ds || test_data[i].dst_ds) && colour)
28295 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
28296 i, colour, x, y, expected);
28298 release_resource_readback(&rb);
28300 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
28302 get_texture_readback(dst_texture, 0, &rb);
28303 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
28305 x = j % 4;
28306 y = j / 4;
28307 colour = get_readback_color(&rb, x, y, 0);
28308 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
28309 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
28310 i, colour, x, y, expected);
28312 release_resource_readback(&rb);
28314 ID3D11Texture2D_Release(dst_texture);
28315 ID3D11Texture2D_Release(src_texture);
28318 ID3D11DeviceContext_Release(context);
28319 refcount = ID3D11Device_Release(device);
28320 ok(!refcount, "Device has %u references left.\n", refcount);
28323 static void test_compressed_format_compatibility(const D3D_FEATURE_LEVEL feature_level)
28325 const struct format_info *src_format, *dst_format;
28326 unsigned int row_block_count, row_count, i, j, k;
28327 ID3D11Texture2D *src_texture, *dst_texture;
28328 BOOL supported, broken_dst_offset = FALSE;
28329 D3D11_SUBRESOURCE_DATA resource_data;
28330 D3D11_TEXTURE2D_DESC texture_desc;
28331 ID3D11DeviceContext *context;
28332 unsigned int block_idx, x, y;
28333 struct resource_readback rb;
28334 DWORD colour, expected;
28335 ID3D11Device *device;
28336 UINT format_support;
28337 const BYTE *row;
28338 ULONG refcount;
28339 D3D11_BOX box;
28340 HRESULT hr;
28341 const struct device_desc device_desc =
28343 .feature_level = &feature_level,
28346 static const struct format_info
28348 DXGI_FORMAT id;
28349 size_t block_size;
28350 size_t block_edge;
28351 BOOL supported;
28352 BOOL skip_if_broken;
28354 formats[] =
28356 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 16, 1, TRUE},
28357 {DXGI_FORMAT_R32G32B32A32_FLOAT, 16, 1, TRUE},
28358 {DXGI_FORMAT_R32G32B32A32_UINT, 16, 1, TRUE},
28359 {DXGI_FORMAT_R32G32B32A32_SINT, 16, 1, TRUE},
28361 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 8, 1, TRUE},
28362 {DXGI_FORMAT_R16G16B16A16_FLOAT, 8, 1, TRUE},
28363 {DXGI_FORMAT_R16G16B16A16_UNORM, 8, 1, TRUE},
28364 {DXGI_FORMAT_R16G16B16A16_UINT, 8, 1, TRUE},
28365 {DXGI_FORMAT_R16G16B16A16_SNORM, 8, 1, TRUE},
28366 {DXGI_FORMAT_R16G16B16A16_SINT, 8, 1, TRUE},
28368 {DXGI_FORMAT_R32G32_TYPELESS, 8, 1, TRUE},
28369 {DXGI_FORMAT_R32G32_FLOAT, 8, 1, TRUE},
28370 {DXGI_FORMAT_R32G32_UINT, 8, 1, TRUE},
28371 {DXGI_FORMAT_R32G32_SINT, 8, 1, TRUE},
28373 {DXGI_FORMAT_R32_TYPELESS, 4, 1, TRUE},
28374 {DXGI_FORMAT_R32_FLOAT, 4, 1, TRUE},
28375 {DXGI_FORMAT_R32_UINT, 4, 1, TRUE},
28376 {DXGI_FORMAT_R32_SINT, 4, 1, TRUE},
28378 {DXGI_FORMAT_R32G8X24_TYPELESS, 8, 1},
28379 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 4, 1},
28380 {DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, 1},
28381 {DXGI_FORMAT_R16G16_TYPELESS, 4, 1},
28382 {DXGI_FORMAT_R24G8_TYPELESS, 4, 1},
28383 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 4, 1},
28384 {DXGI_FORMAT_B8G8R8A8_TYPELESS, 4, 1},
28385 {DXGI_FORMAT_R8G8_TYPELESS, 2, 1},
28386 {DXGI_FORMAT_R16_TYPELESS, 2, 1},
28387 {DXGI_FORMAT_R8_TYPELESS, 1, 1},
28389 {DXGI_FORMAT_BC1_TYPELESS, 8, 4},
28390 {DXGI_FORMAT_BC1_UNORM, 8, 4},
28391 {DXGI_FORMAT_BC1_UNORM_SRGB, 8, 4},
28393 {DXGI_FORMAT_BC2_TYPELESS, 16, 4},
28394 {DXGI_FORMAT_BC2_UNORM, 16, 4},
28395 {DXGI_FORMAT_BC2_UNORM_SRGB, 16, 4},
28397 {DXGI_FORMAT_BC3_TYPELESS, 16, 4},
28398 {DXGI_FORMAT_BC3_UNORM, 16, 4},
28399 {DXGI_FORMAT_BC3_UNORM_SRGB, 16, 4},
28401 {DXGI_FORMAT_BC4_TYPELESS, 8, 4},
28402 {DXGI_FORMAT_BC4_UNORM, 8, 4},
28403 {DXGI_FORMAT_BC4_SNORM, 8, 4},
28405 {DXGI_FORMAT_BC5_TYPELESS, 16, 4},
28406 {DXGI_FORMAT_BC5_UNORM, 16, 4},
28407 {DXGI_FORMAT_BC5_SNORM, 16, 4},
28409 {DXGI_FORMAT_BC6H_TYPELESS, 16, 4, FALSE, TRUE},
28410 {DXGI_FORMAT_BC6H_UF16, 16, 4, FALSE, TRUE},
28411 {DXGI_FORMAT_BC6H_SF16, 16, 4, FALSE, TRUE},
28413 {DXGI_FORMAT_BC7_TYPELESS, 16, 4, FALSE, TRUE},
28414 {DXGI_FORMAT_BC7_UNORM, 16, 4, FALSE, TRUE},
28415 {DXGI_FORMAT_BC7_UNORM_SRGB, 16, 4, FALSE, TRUE},
28418 static const DWORD initial_data[64] = {0};
28419 static const DWORD texture_data[] =
28421 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28422 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28423 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28424 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28426 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28427 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28428 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28429 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28431 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
28432 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
28433 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
28434 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
28436 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
28437 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
28438 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
28439 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
28442 if (!(device = create_device(&device_desc)))
28444 skip("Failed to create device for feature level %#x.\n", feature_level);
28445 return;
28447 ID3D11Device_GetImmediateContext(device, &context);
28449 row_block_count = 4;
28451 texture_desc.MipLevels = 1;
28452 texture_desc.ArraySize = 1;
28453 texture_desc.SampleDesc.Count = 1;
28454 texture_desc.SampleDesc.Quality = 0;
28455 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
28456 texture_desc.CPUAccessFlags = 0;
28457 texture_desc.MiscFlags = 0;
28459 resource_data.SysMemSlicePitch = 0;
28461 for (i = 0; i < ARRAY_SIZE(formats); ++i)
28463 src_format = &formats[i];
28464 row_count = sizeof(texture_data) / (row_block_count * src_format->block_size);
28465 texture_desc.Width = row_block_count * src_format->block_edge;
28466 texture_desc.Height = row_count * src_format->block_edge;
28467 texture_desc.Format = src_format->id;
28468 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
28470 resource_data.pSysMem = texture_data;
28471 resource_data.SysMemPitch = row_block_count * src_format->block_size;
28473 hr = ID3D11Device_CheckFormatSupport(device, src_format->id, &format_support);
28474 if (hr == E_FAIL || !(format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
28475 continue;
28477 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
28478 ok(hr == S_OK, "Source format %#x: Got unexpected hr %#x.\n", src_format->id, hr);
28480 for (j = 0; j < ARRAY_SIZE(formats); ++j)
28482 dst_format = &formats[j];
28484 if ((src_format->block_edge == 1 && dst_format->block_edge == 1)
28485 || (src_format->block_edge != 1 && dst_format->block_edge != 1))
28486 continue;
28488 hr = ID3D11Device_CheckFormatSupport(device, dst_format->id, &format_support);
28489 if (hr == E_FAIL || !(format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
28490 continue;
28492 supported = ((src_format->block_edge != 1 && dst_format->supported)
28493 || (src_format->supported && dst_format->block_edge != 1))
28494 && src_format->block_size == dst_format->block_size
28495 && feature_level >= D3D_FEATURE_LEVEL_10_1;
28497 /* These cause the device to be removed on some versions of Windows. */
28498 if (supported && broken_dst_offset && (src_format->skip_if_broken || dst_format->skip_if_broken))
28500 win_skip("Skipping %#x -> %#x tests because of broken destination offset.\n",
28501 src_format->id, dst_format->id);
28502 continue;
28505 row_count = sizeof(initial_data) / (row_block_count * dst_format->block_size);
28506 texture_desc.Width = row_block_count * dst_format->block_edge;
28507 texture_desc.Height = row_count * dst_format->block_edge;
28508 texture_desc.Format = dst_format->id;
28509 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28511 resource_data.pSysMem = initial_data;
28512 resource_data.SysMemPitch = row_block_count * dst_format->block_size;
28514 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
28515 ok(hr == S_OK, "%#x -> %#x: Got unexpected hr %#x.\n", src_format->id, dst_format->id, hr);
28517 if (supported && broken_dst_offset)
28519 win_skip("Skipping %#x -> %#x CopySubresourceRegion() test because of broken destination offset.\n",
28520 src_format->id, dst_format->id);
28522 else
28524 set_box(&box, 0, 0, 0, src_format->block_edge, src_format->block_edge, 1);
28525 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
28526 dst_format->block_edge, dst_format->block_edge, 0, (ID3D11Resource *)src_texture, 0, &box);
28527 get_texture_readback(dst_texture, 0, &rb);
28528 colour = get_readback_color(&rb, 0, 0, 0);
28529 if (supported && colour == texture_data[0])
28531 win_skip("Detected broken destination offset for %#x -> %#x copy.\n",
28532 src_format->id, dst_format->id);
28533 broken_dst_offset = TRUE;
28535 for (k = 0; k < ARRAY_SIZE(texture_data) && (!supported || !broken_dst_offset); ++k)
28537 block_idx = (k * sizeof(colour)) / dst_format->block_size;
28538 x = block_idx % row_block_count;
28539 y = block_idx / row_block_count;
28541 row = rb.map_desc.pData;
28542 row += y * rb.map_desc.RowPitch;
28543 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
28545 if (supported && x == 1 && y == 1)
28546 expected = texture_data[k - ((row_block_count + 1) * dst_format->block_size) / sizeof(colour)];
28547 else
28548 expected = initial_data[k];
28549 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
28550 src_format->id, dst_format->id, colour, k, expected);
28551 if (colour != expected)
28552 break;
28554 release_resource_readback(&rb);
28557 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
28558 get_texture_readback(dst_texture, 0, &rb);
28559 for (k = 0; k < ARRAY_SIZE(texture_data); ++k)
28561 block_idx = (k * sizeof(colour)) / dst_format->block_size;
28562 y = block_idx / row_block_count;
28564 row = rb.map_desc.pData;
28565 row += y * rb.map_desc.RowPitch;
28566 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
28568 if (supported)
28569 expected = texture_data[k];
28570 else
28571 expected = initial_data[k];
28572 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
28573 src_format->id, dst_format->id, colour, k, expected);
28574 if (colour != expected)
28575 break;
28577 release_resource_readback(&rb);
28579 ID3D11Texture2D_Release(dst_texture);
28582 ID3D11Texture2D_Release(src_texture);
28585 ID3D11DeviceContext_Release(context);
28586 refcount = ID3D11Device_Release(device);
28587 ok(!refcount, "Device has %u references left.\n", refcount);
28590 static void check_clip_distance(struct d3d11_test_context *test_context, ID3D11Buffer *vb)
28592 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28593 struct vertex
28595 float clip_distance0;
28596 float clip_distance1;
28599 ID3D11DeviceContext *context = test_context->immediate_context;
28600 struct resource_readback rb;
28601 struct vertex vertices[4];
28602 unsigned int i;
28603 RECT rect;
28605 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28606 vertices[i].clip_distance0 = 1.0f;
28607 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28608 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28609 ID3D11DeviceContext_Draw(context, 4, 0);
28610 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
28612 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28613 vertices[i].clip_distance0 = 0.0f;
28614 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28615 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28616 ID3D11DeviceContext_Draw(context, 4, 0);
28617 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
28619 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28620 vertices[i].clip_distance0 = -1.0f;
28621 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28622 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28623 ID3D11DeviceContext_Draw(context, 4, 0);
28624 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
28626 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28627 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
28628 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28629 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28630 ID3D11DeviceContext_Draw(context, 4, 0);
28631 get_texture_readback(test_context->backbuffer, 0, &rb);
28632 SetRect(&rect, 0, 0, 320, 480);
28633 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
28634 SetRect(&rect, 320, 0, 320, 480);
28635 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28636 release_resource_readback(&rb);
28638 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28639 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
28640 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28641 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28642 ID3D11DeviceContext_Draw(context, 4, 0);
28643 get_texture_readback(test_context->backbuffer, 0, &rb);
28644 SetRect(&rect, 0, 0, 640, 240);
28645 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
28646 SetRect(&rect, 0, 240, 640, 240);
28647 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28648 release_resource_readback(&rb);
28651 static void test_clip_distance(void)
28653 struct d3d11_test_context test_context;
28654 ID3D11Buffer *vs_cb, *tess_cb, *gs_cb;
28655 D3D_FEATURE_LEVEL feature_level;
28656 ID3D11DomainShader *ds = NULL;
28657 ID3D11DeviceContext *context;
28658 struct resource_readback rb;
28659 unsigned int offset, stride;
28660 ID3D11HullShader *hs = NULL;
28661 ID3D11GeometryShader *gs;
28662 ID3D11Device *device;
28663 ID3D11Buffer *vb;
28664 unsigned int i;
28665 HRESULT hr;
28666 RECT rect;
28668 static const DWORD vs_code[] =
28670 #if 0
28671 bool use_constant;
28672 float clip_distance;
28674 struct input
28676 float4 position : POSITION;
28677 float distance0 : CLIP_DISTANCE0;
28678 float distance1 : CLIP_DISTANCE1;
28681 struct vertex
28683 float4 position : SV_POSITION;
28684 float user_clip : CLIP_DISTANCE;
28685 float clip : SV_ClipDistance;
28688 void main(input vin, out vertex vertex)
28690 vertex.position = vin.position;
28691 vertex.user_clip = vin.distance0;
28692 vertex.clip = vin.distance0;
28693 if (use_constant)
28694 vertex.clip = clip_distance;
28696 #endif
28697 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
28698 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
28699 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
28700 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
28701 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
28702 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
28703 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
28704 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
28705 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
28706 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
28707 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
28708 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
28709 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
28710 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
28711 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
28713 static const DWORD vs_multiple_code[] =
28715 #if 0
28716 bool use_constant;
28717 float clip_distance0;
28718 float clip_distance1;
28720 struct input
28722 float4 position : POSITION;
28723 float distance0 : CLIP_DISTANCE0;
28724 float distance1 : CLIP_DISTANCE1;
28727 struct vertex
28729 float4 position : SV_POSITION;
28730 float user_clip : CLIP_DISTANCE;
28731 float2 clip : SV_ClipDistance;
28734 void main(input vin, out vertex vertex)
28736 vertex.position = vin.position;
28737 vertex.user_clip = vin.distance0;
28738 vertex.clip.x = vin.distance0;
28739 if (use_constant)
28740 vertex.clip.x = clip_distance0;
28741 vertex.clip.y = vin.distance1;
28742 if (use_constant)
28743 vertex.clip.y = clip_distance1;
28745 #endif
28746 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
28747 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
28748 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
28749 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
28750 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
28751 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
28752 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
28753 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
28754 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
28755 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
28756 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
28757 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
28758 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
28759 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
28760 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
28761 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
28762 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
28764 #if 0
28765 bool use_constant;
28766 float clip_distance0;
28767 float clip_distance1;
28768 float tessellation_factor;
28770 struct vertex
28772 float4 position : SV_POSITION;
28773 float user_clip : CLIP_DISTANCE;
28774 float clip : SV_ClipDistance;
28777 struct patch_constant_data
28779 float edges[4] : SV_TessFactor;
28780 float inside[2] : SV_InsideTessFactor;
28783 patch_constant_data patch_constant()
28785 patch_constant_data output;
28787 output.edges[0] = tessellation_factor;
28788 output.edges[1] = tessellation_factor;
28789 output.edges[2] = tessellation_factor;
28790 output.edges[3] = tessellation_factor;
28791 output.inside[0] = tessellation_factor;
28792 output.inside[1] = tessellation_factor;
28794 return output;
28797 [domain("quad")]
28798 [outputcontrolpoints(4)]
28799 [outputtopology("triangle_cw")]
28800 [partitioning("pow2")]
28801 [patchconstantfunc("patch_constant")]
28802 vertex hs_main(InputPatch<vertex, 4> input,
28803 uint i : SV_OutputControlPointID)
28805 vertex o;
28806 o.position = input[i].position;
28807 o.user_clip = input[i].user_clip;
28808 o.clip = input[i].user_clip;
28809 return o;
28812 float4 interpolate_vec(float4 a, float4 b, float4 c, float4 d, float2 tess_coord)
28814 float4 e = lerp(a, b, tess_coord.x);
28815 float4 f = lerp(c, d, tess_coord.x);
28816 return lerp(e, f, tess_coord.y);
28819 float interpolate(float a, float b, float c, float d, float2 tess_coord)
28821 float e = lerp(a, b, tess_coord.x);
28822 float f = lerp(c, d, tess_coord.x);
28823 return lerp(e, f, tess_coord.y);
28826 [domain("quad")]
28827 vertex ds_main(patch_constant_data input,
28828 float2 tess_coord : SV_DomainLocation,
28829 const OutputPatch<vertex, 4> patch)
28831 vertex output;
28833 output.position = interpolate_vec(patch[0].position, patch[1].position,
28834 patch[2].position, patch[3].position, tess_coord);
28835 output.user_clip = interpolate(patch[0].user_clip, patch[1].user_clip,
28836 patch[2].user_clip, patch[3].user_clip, tess_coord);
28837 output.clip = interpolate(patch[0].clip, patch[1].clip,
28838 patch[2].clip, patch[3].clip, tess_coord);
28839 if (use_constant)
28840 output.clip = clip_distance0;
28842 return output;
28844 #endif
28845 static const DWORD hs_code[] =
28847 0x43425844, 0x5a6d7564, 0x5f30a6c9, 0x2cf3b848, 0x5b4c6dca, 0x00000001, 0x00000414, 0x00000004,
28848 0x00000030, 0x000000b4, 0x00000138, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
28849 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
28850 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
28851 0x00000002, 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
28852 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003,
28853 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c,
28854 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002,
28855 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f,
28856 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc,
28857 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
28858 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
28859 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
28860 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
28861 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
28862 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
28863 0x00000210, 0x00030050, 0x00000084, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01001096,
28864 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x01000072, 0x0200005f,
28865 0x00016000, 0x0400005f, 0x002010f2, 0x00000004, 0x00000000, 0x0400005f, 0x00201012, 0x00000004,
28866 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
28867 0x00102012, 0x00000002, 0x02000068, 0x00000001, 0x04000036, 0x00100012, 0x00000000, 0x00016001,
28868 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x07000036,
28869 0x00102012, 0x00000001, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x07000036, 0x00102012,
28870 0x00000002, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x0100003e, 0x01000073, 0x02000099,
28871 0x00000004, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x0000000b, 0x04000067,
28872 0x00102012, 0x00000001, 0x0000000c, 0x04000067, 0x00102012, 0x00000002, 0x0000000d, 0x04000067,
28873 0x00102012, 0x00000003, 0x0000000e, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000000,
28874 0x00000004, 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, 0x00902012, 0x0010000a,
28875 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002,
28876 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000004, 0x0000000f, 0x04000067, 0x00102012,
28877 0x00000005, 0x00000010, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000004, 0x00000002,
28878 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x08000036, 0x00d02012, 0x00000004, 0x0010000a,
28879 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e,
28881 static const DWORD ds_code[] =
28883 0x43425844, 0xc54dc020, 0x063a9622, 0x6f649eb9, 0xceb1dd36, 0x00000001, 0x0000054c, 0x00000004,
28884 0x00000030, 0x000000b4, 0x00000178, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
28885 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
28886 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
28887 0x00000002, 0x00000101, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
28888 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc, 0x00000006,
28889 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000001, 0x00000098,
28890 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000001, 0x00000098, 0x00000002, 0x0000000b,
28891 0x00000003, 0x00000002, 0x00000001, 0x00000098, 0x00000003, 0x0000000b, 0x00000003, 0x00000003,
28892 0x00000001, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000001, 0x000000a6,
28893 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
28894 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000007c,
28895 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
28896 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000,
28897 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43,
28898 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x58454853,
28899 0x00000348, 0x00040050, 0x000000d2, 0x01002093, 0x01001895, 0x0100086a, 0x04000059, 0x00208e46,
28900 0x00000000, 0x00000001, 0x0200005f, 0x0001c032, 0x0400005f, 0x002190f2, 0x00000004, 0x00000000,
28901 0x0400005f, 0x00219012, 0x00000004, 0x00000001, 0x0400005f, 0x00219012, 0x00000004, 0x00000002,
28902 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067,
28903 0x00102012, 0x00000002, 0x00000002, 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000,
28904 0x80219e46, 0x00000041, 0x00000002, 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032,
28905 0x001000f2, 0x00000000, 0x0001c006, 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000,
28906 0x0a000000, 0x001000f2, 0x00000001, 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46,
28907 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001,
28908 0x00219e46, 0x00000000, 0x00000000, 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
28909 0x80100e46, 0x00000041, 0x00000001, 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46,
28910 0x00000000, 0x00100e46, 0x00000001, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041,
28911 0x00000002, 0x00000001, 0x0021900a, 0x00000003, 0x00000001, 0x09000032, 0x00100012, 0x00000000,
28912 0x0001c00a, 0x0010000a, 0x00000000, 0x0021900a, 0x00000002, 0x00000001, 0x0a000000, 0x00100022,
28913 0x00000000, 0x8021900a, 0x00000041, 0x00000000, 0x00000001, 0x0021900a, 0x00000001, 0x00000001,
28914 0x09000032, 0x00100022, 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000,
28915 0x00000001, 0x08000000, 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a,
28916 0x00000000, 0x08000032, 0x00102012, 0x00000001, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a,
28917 0x00000000, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041, 0x00000002, 0x00000002,
28918 0x0021900a, 0x00000003, 0x00000002, 0x09000032, 0x00100012, 0x00000000, 0x0001c00a, 0x0010000a,
28919 0x00000000, 0x0021900a, 0x00000002, 0x00000002, 0x0a000000, 0x00100022, 0x00000000, 0x8021900a,
28920 0x00000041, 0x00000000, 0x00000002, 0x0021900a, 0x00000001, 0x00000002, 0x09000032, 0x00100022,
28921 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000, 0x00000002, 0x08000000,
28922 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a, 0x00000000, 0x08000032,
28923 0x00100012, 0x00000000, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000, 0x0b000037,
28924 0x00102012, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
28925 0x0010000a, 0x00000000, 0x0100003e,
28927 static const DWORD gs_code[] =
28929 #if 0
28930 bool use_constant;
28931 float clip_distance;
28933 struct vertex
28935 float4 position : SV_POSITION;
28936 float user_clip : CLIP_DISTANCE;
28937 float clip : SV_ClipDistance;
28940 [maxvertexcount(3)]
28941 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
28943 vertex o;
28944 o = input[0];
28945 o.clip = input[0].user_clip;
28946 if (use_constant)
28947 o.clip = clip_distance;
28948 output.Append(o);
28949 o = input[1];
28950 o.clip = input[1].user_clip;
28951 if (use_constant)
28952 o.clip = clip_distance;
28953 output.Append(o);
28954 o = input[2];
28955 o.clip = input[2].user_clip;
28956 if (use_constant)
28957 o.clip = clip_distance;
28958 output.Append(o);
28960 #endif
28961 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
28962 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
28963 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
28964 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
28965 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
28966 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
28967 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
28968 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
28969 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
28970 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
28971 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
28972 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
28973 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
28974 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
28975 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
28976 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
28977 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
28978 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
28979 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
28980 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
28981 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
28982 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
28983 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
28984 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
28985 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
28986 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
28988 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
28990 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
28991 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
28992 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
28994 struct
28996 float clip_distance0;
28997 float clip_distance1;
28999 vertices[] =
29001 {1.0f, 1.0f},
29002 {1.0f, 1.0f},
29003 {1.0f, 1.0f},
29004 {1.0f, 1.0f},
29006 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29007 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
29008 struct
29010 BOOL use_constant;
29011 float clip_distance0;
29012 float clip_distance1;
29013 float tessellation_factor;
29014 } cb_data;
29016 if (!init_test_context(&test_context, NULL))
29017 return;
29018 device = test_context.device;
29019 context = test_context.immediate_context;
29020 feature_level = ID3D11Device_GetFeatureLevel(device);
29022 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
29023 vs_code, sizeof(vs_code), &test_context.input_layout);
29024 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
29026 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
29027 stride = sizeof(*vertices);
29028 offset = 0;
29029 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
29031 memset(&cb_data, 0, sizeof(cb_data));
29032 cb_data.tessellation_factor = 1.0f;
29033 vs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29034 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &vs_cb);
29035 tess_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29036 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &tess_cb);
29037 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, 1, &tess_cb);
29038 gs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29039 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &gs_cb);
29041 /* vertex shader */
29042 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29043 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29044 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29046 check_clip_distance(&test_context, vb);
29048 cb_data.use_constant = TRUE;
29049 cb_data.clip_distance0 = -1.0f;
29050 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29052 /* tessellation shaders */
29053 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
29055 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
29057 hr = ID3D11Device_CreateHullShader(device, hs_code, sizeof(hs_code), NULL, &hs);
29058 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
29059 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
29060 hr = ID3D11Device_CreateDomainShader(device, ds_code, sizeof(ds_code), NULL, &ds);
29061 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
29062 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
29064 check_clip_distance(&test_context, vb);
29066 cb_data.use_constant = FALSE;
29067 cb_data.tessellation_factor = 2.0f;
29068 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
29070 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29071 vertices[i].clip_distance0 = 1.0f;
29072 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29073 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29074 ID3D11DeviceContext_Draw(context, 4, 0);
29075 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29077 cb_data.use_constant = TRUE;
29078 cb_data.clip_distance0 = -1.0f;
29079 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
29081 else
29083 skip("Tessellation shaders are not supported.\n");
29086 /* geometry shader */
29087 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
29088 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
29089 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
29091 check_clip_distance(&test_context, vb);
29093 cb_data.use_constant = TRUE;
29094 cb_data.clip_distance0 = 1.0f;
29095 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
29096 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29097 ID3D11DeviceContext_Draw(context, 4, 0);
29098 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29100 /* multiple clip distances */
29101 ID3D11DeviceContext_HSSetShader(context, NULL, NULL, 0);
29102 ID3D11DeviceContext_DSSetShader(context, NULL, NULL, 0);
29103 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
29105 cb_data.use_constant = FALSE;
29106 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29108 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29109 vertices[i].clip_distance0 = 1.0f;
29110 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 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 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29117 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
29118 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
29120 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29121 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29122 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29123 get_texture_readback(test_context.backbuffer, 0, &rb);
29124 SetRect(&rect, 0, 0, 320, 240);
29125 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
29126 SetRect(&rect, 0, 240, 320, 480);
29127 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29128 SetRect(&rect, 320, 0, 640, 480);
29129 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29130 release_resource_readback(&rb);
29132 cb_data.use_constant = TRUE;
29133 cb_data.clip_distance0 = 0.0f;
29134 cb_data.clip_distance1 = 0.0f;
29135 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29136 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29137 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29138 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29140 if (hs)
29141 ID3D11HullShader_Release(hs);
29142 if (ds)
29143 ID3D11DomainShader_Release(ds);
29144 ID3D11GeometryShader_Release(gs);
29145 ID3D11Buffer_Release(vb);
29146 ID3D11Buffer_Release(vs_cb);
29147 ID3D11Buffer_Release(tess_cb);
29148 ID3D11Buffer_Release(gs_cb);
29149 release_test_context(&test_context);
29152 static void test_combined_clip_and_cull_distances(void)
29154 struct d3d11_test_context test_context;
29155 ID3D11DeviceContext *context;
29156 struct resource_readback rb;
29157 unsigned int offset, stride;
29158 ID3D11Device *device;
29159 unsigned int i, j, k;
29160 ID3D11Buffer *vb;
29161 HRESULT hr;
29163 static const DWORD vs_code[] =
29165 #if 0
29166 struct input
29168 float4 position : POSITION;
29169 float clip0 : CLIP_DISTANCE0;
29170 float clip1 : CLIP_DISTANCE1;
29171 float clip2 : CLIP_DISTANCE2;
29172 float clip3 : CLIP_DISTANCE3;
29173 float cull0 : CULL_DISTANCE0;
29174 float cull1 : CULL_DISTANCE1;
29175 float cull2 : CULL_DISTANCE2;
29176 float cull3 : CULL_DISTANCE3;
29179 struct vertex
29181 float4 position : SV_Position;
29182 float3 clip0 : SV_ClipDistance1;
29183 float3 cull0 : SV_CullDistance1;
29184 float clip1 : SV_ClipDistance2;
29185 float cull1 : SV_CullDistance2;
29188 void main(input vin, out vertex vertex)
29190 vertex.position = vin.position;
29191 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
29192 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
29193 vertex.clip1 = vin.clip3;
29194 vertex.cull1 = vin.cull3;
29196 #endif
29197 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
29198 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
29199 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
29200 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
29201 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
29202 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
29203 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
29204 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
29205 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
29206 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
29207 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
29208 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
29209 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
29210 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
29211 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
29212 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
29213 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
29214 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
29215 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
29216 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
29217 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
29218 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
29219 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
29220 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
29221 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
29222 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
29223 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
29224 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
29226 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
29228 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29229 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29230 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
29231 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
29232 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
29233 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
29234 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
29235 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
29236 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
29238 struct
29240 float clip_distance[4];
29241 float cull_distance[4];
29243 vertices[4] =
29245 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29246 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29247 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29248 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29250 static const struct test
29252 float vertices[4];
29253 BOOL triangle_visible[2];
29255 cull_distance_tests[] =
29257 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29258 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29259 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29260 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29261 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
29262 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29263 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
29264 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29265 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
29267 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
29268 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29269 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29270 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
29271 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
29273 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
29275 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29276 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
29278 if (!init_test_context(&test_context, NULL))
29279 return;
29280 device = test_context.device;
29281 context = test_context.immediate_context;
29283 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
29284 vs_code, sizeof(vs_code), &test_context.input_layout);
29285 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
29287 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
29288 stride = sizeof(*vertices);
29289 offset = 0;
29290 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
29292 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29293 draw_color_quad(&test_context, &green);
29294 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29296 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
29298 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
29300 const struct test *test = &cull_distance_tests[j];
29301 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
29302 unsigned int color;
29304 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
29305 vertices[k].cull_distance[i] = test->vertices[k];
29306 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29308 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29309 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29311 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
29312 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
29314 if (expected_color[0] == expected_color[1])
29316 check_texture_color(test_context.backbuffer, *expected_color, 1);
29318 else
29320 get_texture_readback(test_context.backbuffer, 0, &rb);
29321 color = get_readback_color(&rb, 160, 240, 0);
29322 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
29323 color = get_readback_color(&rb, 480, 240, 0);
29324 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
29325 release_resource_readback(&rb);
29329 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29330 vertices[j].cull_distance[i] = 1.0f;
29333 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
29335 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29336 vertices[j].clip_distance[i] = -1.0f;
29337 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29339 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29340 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29341 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
29343 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29344 vertices[j].clip_distance[i] = 1.0f;
29347 memset(vertices, 0, sizeof(vertices));
29348 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29349 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29350 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29351 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29353 ID3D11Buffer_Release(vb);
29354 release_test_context(&test_context);
29357 static void test_generate_mips(void)
29359 static const DWORD ps_code[] =
29361 #if 0
29362 Texture2D t;
29363 SamplerState s;
29365 float4 main(float4 position : SV_POSITION) : SV_Target
29367 float2 p;
29369 p.x = position.x / 640.0f;
29370 p.y = position.y / 480.0f;
29371 return t.Sample(s, p);
29373 #endif
29374 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
29375 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29376 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
29377 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
29378 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
29379 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
29380 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
29381 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
29382 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
29383 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
29385 static const DWORD ps_code_3d[] =
29387 #if 0
29388 Texture3D t;
29389 SamplerState s;
29391 float4 main(float4 position : SV_POSITION) : SV_Target
29393 float3 p;
29395 p.x = position.x / 640.0f;
29396 p.y = position.y / 480.0f;
29397 p.z = 0.5f;
29398 return t.Sample(s, p);
29400 #endif
29401 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003,
29402 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29403 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
29404 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
29405 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040,
29406 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
29407 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
29408 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
29409 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000,
29410 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
29411 0x00000000, 0x0100003e,
29413 static const struct
29415 D3D11_RESOURCE_DIMENSION dim;
29416 D3D11_SRV_DIMENSION srv_dim;
29417 unsigned int array_size;
29419 resource_types[] =
29421 {D3D11_RESOURCE_DIMENSION_BUFFER, D3D11_SRV_DIMENSION_BUFFER, 1},
29422 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2D, 1},
29423 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2DARRAY, 4},
29424 {D3D11_RESOURCE_DIMENSION_TEXTURE3D, D3D11_SRV_DIMENSION_TEXTURE3D, 1},
29426 static const struct
29428 DXGI_FORMAT texture_format;
29429 UINT bind_flags;
29430 UINT misc_flags;
29431 BOOL null_srv;
29432 UINT base_level;
29433 BOOL expected_creation;
29434 BOOL expected_mips;
29436 tests[] =
29438 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
29439 0, TRUE, FALSE},
29440 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
29441 0, TRUE, FALSE},
29442 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
29443 0, TRUE, FALSE},
29444 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
29445 0, TRUE, FALSE},
29446 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29447 0, FALSE, FALSE},
29448 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29449 0, FALSE, FALSE},
29450 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29451 0, TRUE, TRUE},
29452 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29453 1, TRUE, TRUE},
29454 {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29455 1, TRUE, TRUE},
29456 {DXGI_FORMAT_R8G8B8A8_UINT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, TRUE,
29457 1, TRUE, FALSE},
29459 static const struct
29461 POINT pos;
29462 DWORD color;
29464 expected[] =
29466 {{200, 200}, 0xffff0000},
29467 {{280, 200}, 0xffff0000},
29468 {{360, 200}, 0xff00ff00},
29469 {{440, 200}, 0xff00ff00},
29470 {{200, 270}, 0xff0000ff},
29471 {{280, 270}, 0xff0000ff},
29472 {{360, 270}, 0xff000000},
29473 {{440, 270}, 0xff000000},
29475 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
29476 static const RECT r1 = {8, 8, 16, 16};
29477 static const RECT r2 = {16, 8, 24, 16};
29478 static const RECT r3 = {8, 16, 16, 24};
29479 static const RECT r4 = {16, 16, 24, 24};
29480 DWORD *data, *zero_data, color, expected_color;
29481 ID3D11ShaderResourceView *srv, *srv_sampling;
29482 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
29483 struct d3d11_test_context test_context;
29484 D3D11_TEXTURE2D_DESC texture2d_desc;
29485 D3D11_TEXTURE3D_DESC texture3d_desc;
29486 ID3D11SamplerState *sampler_state;
29487 D3D11_SAMPLER_DESC sampler_desc;
29488 D3D11_BUFFER_DESC buffer_desc;
29489 unsigned int i, j, k, x, y, z;
29490 ID3D11PixelShader *ps, *ps_3d;
29491 ID3D11DeviceContext *context;
29492 struct resource_readback rb;
29493 ID3D11Resource *resource;
29494 ID3D11Device *device;
29495 HRESULT hr;
29497 if (!init_test_context(&test_context, NULL))
29498 return;
29500 device = test_context.device;
29501 context = test_context.immediate_context;
29503 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
29504 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29506 hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps_3d);
29507 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29509 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
29510 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
29511 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
29512 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
29513 sampler_desc.MipLODBias = 0.0f;
29514 sampler_desc.MaxAnisotropy = 0;
29515 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
29516 sampler_desc.BorderColor[0] = 0.0f;
29517 sampler_desc.BorderColor[1] = 0.0f;
29518 sampler_desc.BorderColor[2] = 0.0f;
29519 sampler_desc.BorderColor[3] = 0.0f;
29520 sampler_desc.MinLOD = 0.0f;
29521 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
29523 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
29524 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
29525 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
29527 data = heap_alloc(sizeof(*data) * 32 * 32 * 32);
29529 for (z = 0; z < 32; ++z)
29531 for (y = 0; y < 32; ++y)
29533 for (x = 0; x < 32; ++x)
29535 DWORD *dst = &data[z * 32 * 32 + y * 32 + x];
29536 POINT pt;
29538 pt.x = x;
29539 pt.y = y;
29540 if (PtInRect(&r1, pt))
29541 *dst = 0xffff0000;
29542 else if (PtInRect(&r2, pt))
29543 *dst = 0xff00ff00;
29544 else if (PtInRect(&r3, pt))
29545 *dst = 0xff0000ff;
29546 else if (PtInRect(&r4, pt))
29547 *dst = 0xff000000;
29548 else
29549 *dst = 0xffffffff;
29554 zero_data = heap_alloc_zero(sizeof(*zero_data) * 16 * 16 * 16);
29556 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
29558 for (j = 0; j < ARRAY_SIZE(tests); ++j)
29560 unsigned int base_multiplier = 1u << tests[j].base_level;
29562 if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT)
29564 /* Testing this format seems to break the WARP device. */
29565 skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n");
29566 continue;
29569 switch (resource_types[i].dim)
29571 case D3D11_RESOURCE_DIMENSION_BUFFER:
29572 buffer_desc.ByteWidth = 32 * base_multiplier;
29573 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
29574 buffer_desc.BindFlags = tests[j].bind_flags;
29575 buffer_desc.CPUAccessFlags = 0;
29576 buffer_desc.MiscFlags = tests[j].misc_flags;
29577 buffer_desc.StructureByteStride = 0;
29579 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL,
29580 (ID3D11Buffer **)&resource);
29581 break;
29582 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
29583 texture2d_desc.Width = 32 * base_multiplier;
29584 texture2d_desc.Height = 32 * base_multiplier;
29585 texture2d_desc.MipLevels = 0;
29586 texture2d_desc.ArraySize = resource_types[i].array_size;
29587 texture2d_desc.Format = tests[j].texture_format;
29588 texture2d_desc.SampleDesc.Count = 1;
29589 texture2d_desc.SampleDesc.Quality = 0;
29590 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
29591 texture2d_desc.BindFlags = tests[j].bind_flags;
29592 texture2d_desc.CPUAccessFlags = 0;
29593 texture2d_desc.MiscFlags = tests[j].misc_flags;
29595 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL,
29596 (ID3D11Texture2D **)&resource);
29597 break;
29598 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
29599 texture3d_desc.Width = 32 * base_multiplier;
29600 texture3d_desc.Height = 32 * base_multiplier;
29601 texture3d_desc.Depth = 32 * base_multiplier;
29602 texture3d_desc.MipLevels = 0;
29603 texture3d_desc.Format = tests[j].texture_format;
29604 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
29605 texture3d_desc.BindFlags = tests[j].bind_flags;
29606 texture3d_desc.CPUAccessFlags = 0;
29607 texture3d_desc.MiscFlags = tests[j].misc_flags;
29609 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL,
29610 (ID3D11Texture3D **)&resource);
29611 break;
29612 default:
29613 break;
29615 if (tests[j].expected_creation && (resource_types[i].dim != D3D11_RESOURCE_DIMENSION_BUFFER
29616 || !(tests[j].misc_flags & D3D11_RESOURCE_MISC_GENERATE_MIPS)))
29618 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr);
29620 else
29622 ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded "
29623 "to create resource, hr %#x.\n", i, j, hr);
29624 continue;
29627 if (tests[j].null_srv)
29629 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
29631 else
29633 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29634 srv_desc.ViewDimension = resource_types[i].srv_dim;
29635 switch (resource_types[i].srv_dim)
29637 case D3D11_SRV_DIMENSION_BUFFER:
29638 srv_desc.Buffer.ElementOffset = 0;
29639 srv_desc.Buffer.ElementWidth = 0;
29640 break;
29641 case D3D11_SRV_DIMENSION_TEXTURE2D:
29642 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level;
29643 srv_desc.Texture2D.MipLevels = ~0u;
29644 break;
29645 case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
29646 srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level;
29647 srv_desc.Texture2DArray.MipLevels = ~0u;
29648 srv_desc.Texture2DArray.FirstArraySlice = 0;
29649 srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size;
29650 break;
29651 case D3D11_SRV_DIMENSION_TEXTURE3D:
29652 srv_desc.Texture3D.MostDetailedMip = tests[j].base_level;
29653 srv_desc.Texture3D.MipLevels = ~0u;
29654 break;
29655 default:
29656 break;
29658 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
29660 if (resource_types[i].dim == D3D11_RESOURCE_DIMENSION_BUFFER)
29662 ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, "
29663 "hr %#x.\n", j, hr);
29664 ID3D11Resource_Release(resource);
29665 continue;
29667 else
29669 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create "
29670 "shader resource view, hr %#x.\n", i, j, hr);
29673 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level,
29674 NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
29675 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level + 1,
29676 NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16);
29678 ID3D11DeviceContext_GenerateMips(context, srv);
29680 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
29682 srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT
29683 ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
29684 srv_desc.ViewDimension = resource_types[i].dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D
29685 ? D3D11_SRV_DIMENSION_TEXTURE3D : D3D11_SRV_DIMENSION_TEXTURE2D;
29686 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1;
29687 srv_desc.Texture2D.MipLevels = ~0u;
29688 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
29689 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, "
29690 "hr %#x.\n", i, j, hr);
29691 ID3D11DeviceContext_PSSetShader(context, resource_types[i].dim
29692 == D3D11_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps, NULL, 0);
29693 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
29695 draw_quad(&test_context);
29697 get_texture_readback(test_context.backbuffer, 0, &rb);
29698 for (k = 0; k < ARRAY_SIZE(expected); ++k)
29700 color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y, 0);
29701 expected_color = tests[j].expected_mips ? expected[k].color : 0;
29702 ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) "
29703 "has color %08x, expected %08x.\n",
29704 i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color);
29706 release_resource_readback(&rb);
29708 ID3D11ShaderResourceView_Release(srv_sampling);
29709 ID3D11ShaderResourceView_Release(srv);
29710 ID3D11Resource_Release(resource);
29714 /* Test the effect of sRGB views. */
29715 for (y = 0; y < 32; ++y)
29717 for (x = 0; x < 32; ++x)
29719 DWORD *dst = &data[y * 32 + x];
29721 *dst = (x + y) % 2 * 0xffffffff;
29724 texture2d_desc.Width = 32;
29725 texture2d_desc.Height = 32;
29726 texture2d_desc.MipLevels = 0;
29727 texture2d_desc.ArraySize = 1;
29728 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
29729 texture2d_desc.SampleDesc.Count = 1;
29730 texture2d_desc.SampleDesc.Quality = 0;
29731 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
29732 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
29733 texture2d_desc.CPUAccessFlags = 0;
29734 texture2d_desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
29736 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D11Texture2D **)&resource);
29737 ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr);
29738 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
29739 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
29740 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
29741 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29742 srv_desc.Texture2D.MostDetailedMip = 0;
29743 srv_desc.Texture2D.MipLevels = ~0u;
29744 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
29745 ID3D11DeviceContext_UpdateSubresource(context, resource,
29746 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
29748 ID3D11DeviceContext_GenerateMips(context, srv);
29750 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
29752 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29753 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29754 srv_desc.Texture2D.MostDetailedMip = 1;
29755 srv_desc.Texture2D.MipLevels = ~0u;
29756 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
29757 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
29758 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29759 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
29761 draw_quad(&test_context);
29763 get_texture_readback(test_context.backbuffer, 0, &rb);
29764 color = get_readback_color(&rb, 320, 240, 0);
29765 ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */
29766 "Unexpected color %08x.\n", color);
29767 release_resource_readback(&rb);
29769 ID3D11ShaderResourceView_Release(srv_sampling);
29770 ID3D11ShaderResourceView_Release(srv);
29772 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29773 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29774 srv_desc.Texture2D.MostDetailedMip = 0;
29775 srv_desc.Texture2D.MipLevels = ~0u;
29776 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
29777 ID3D11DeviceContext_UpdateSubresource(context, resource,
29778 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
29780 ID3D11DeviceContext_GenerateMips(context, srv);
29782 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
29784 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29785 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29786 srv_desc.Texture2D.MostDetailedMip = 1;
29787 srv_desc.Texture2D.MipLevels = ~0u;
29788 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
29789 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
29790 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29791 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
29793 draw_quad(&test_context);
29795 get_texture_readback(test_context.backbuffer, 0, &rb);
29796 check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1);
29797 release_resource_readback(&rb);
29799 ID3D11ShaderResourceView_Release(srv_sampling);
29800 ID3D11ShaderResourceView_Release(srv);
29802 ID3D11Resource_Release(resource);
29804 heap_free(zero_data);
29805 heap_free(data);
29807 ID3D11SamplerState_Release(sampler_state);
29808 ID3D11PixelShader_Release(ps_3d);
29809 ID3D11PixelShader_Release(ps);
29810 release_test_context(&test_context);
29813 static void test_alpha_to_coverage(void)
29815 struct ps_cb
29817 struct vec2 top;
29818 struct vec2 bottom;
29819 float alpha[2];
29820 float padding[2];
29823 struct d3d11_test_context test_context;
29824 ID3D11Texture2D *render_targets[3];
29825 D3D11_TEXTURE2D_DESC texture_desc;
29826 ID3D11Texture2D *readback_texture;
29827 ID3D11RenderTargetView *rtvs[3];
29828 ID3D11BlendState *blend_state;
29829 ID3D11DeviceContext *context;
29830 D3D11_BLEND_DESC blend_desc;
29831 struct resource_readback rb;
29832 UINT quality_level_count;
29833 ID3D11PixelShader *ps;
29834 struct ps_cb cb_data;
29835 ID3D11Device *device;
29836 ID3D11Buffer *cb;
29837 unsigned int i;
29838 HRESULT hr;
29839 RECT rect;
29841 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29842 static const DWORD ps_code[] =
29844 #if 0
29845 float2 top;
29846 float2 bottom;
29847 float alpha1;
29848 float alpha2;
29850 void main(float4 position : SV_Position,
29851 out float4 target0 : SV_Target0,
29852 out float4 target1 : SV_Target1,
29853 out float4 target2 : SV_Target2)
29855 float alpha = all(top <= position.xy) && all(position.xy <= bottom) ? 1.0f : 0.0f;
29856 target0 = float4(0.0f, 1.0f, 0.0f, alpha);
29857 target1 = float4(0.0f, 0.0f, 1.0f, alpha1);
29858 target2 = float4(0.0f, 1.0f, 0.0f, alpha2);
29860 #endif
29861 0x43425844, 0x771ff802, 0xca927279, 0x5bdd75ae, 0xf53cb31b, 0x00000001, 0x00000264, 0x00000003,
29862 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29863 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
29864 0x4e47534f, 0x0000005c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003,
29865 0x00000000, 0x0000000f, 0x00000050, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
29866 0x00000050, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x545f5653, 0x65677261,
29867 0xabab0074, 0x52444853, 0x00000198, 0x00000040, 0x00000066, 0x04000059, 0x00208e46, 0x00000000,
29868 0x00000002, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
29869 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001,
29870 0x0800001d, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00208046, 0x00000000, 0x00000000,
29871 0x07000001, 0x00100012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0800001d,
29872 0x00100062, 0x00000000, 0x00208ba6, 0x00000000, 0x00000000, 0x00101106, 0x00000000, 0x07000001,
29873 0x00100022, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x07000001, 0x00100012,
29874 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00102082, 0x00000000,
29875 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x08000036, 0x00102072, 0x00000000, 0x00004002,
29876 0x00000000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x00102072, 0x00000001, 0x00004002,
29877 0x00000000, 0x00000000, 0x3f800000, 0x00000000, 0x06000036, 0x00102082, 0x00000001, 0x0020800a,
29878 0x00000000, 0x00000001, 0x08000036, 0x00102072, 0x00000002, 0x00004002, 0x00000000, 0x3f800000,
29879 0x00000000, 0x00000000, 0x06000036, 0x00102082, 0x00000002, 0x0020801a, 0x00000000, 0x00000001,
29880 0x0100003e,
29882 static const DWORD colors[] = {0xff00ff00, 0xbfff0000, 0x8000ff00};
29884 if (!init_test_context(&test_context, NULL))
29885 return;
29886 device = test_context.device;
29887 context = test_context.immediate_context;
29889 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
29890 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29891 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29893 memset(&blend_desc, 0, sizeof(blend_desc));
29894 blend_desc.AlphaToCoverageEnable = TRUE;
29895 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
29896 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
29897 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
29898 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
29900 render_targets[0] = test_context.backbuffer;
29901 rtvs[0] = test_context.backbuffer_rtv;
29902 for (i = 1; i < ARRAY_SIZE(render_targets); ++i)
29904 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29905 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
29906 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29907 hr = ID3D11Device_CreateRenderTargetView(device,
29908 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
29909 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
29911 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
29913 cb_data.top.x = cb_data.top.y = 0.0f;
29914 cb_data.bottom.x = cb_data.bottom.y = 200.0f;
29915 cb_data.alpha[0] = 0.75;
29916 cb_data.alpha[1] = 0.5f;
29917 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29918 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
29920 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
29921 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
29922 draw_quad(&test_context);
29923 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
29925 DWORD expected_color;
29927 assert(i < ARRAY_SIZE(colors));
29928 expected_color = colors[i];
29929 get_texture_readback(render_targets[i], 0, &rb);
29930 SetRect(&rect, 0, 0, 200, 200);
29931 check_readback_data_color(&rb, &rect, expected_color, 1);
29932 SetRect(&rect, 200, 0, 640, 200);
29933 todo_wine
29934 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29935 SetRect(&rect, 0, 200, 640, 480);
29936 todo_wine
29937 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29938 release_resource_readback(&rb);
29940 if (i > 0)
29941 ID3D11Texture2D_Release(render_targets[i]);
29942 render_targets[i] = NULL;
29945 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29946 texture_desc.Format = DXGI_FORMAT_R16G16_UNORM;
29947 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[0]);
29948 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29949 hr = ID3D11Device_CreateRenderTargetView(device,
29950 (ID3D11Resource *)render_targets[0], NULL, &rtvs[0]);
29951 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
29952 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
29954 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
29955 draw_quad(&test_context);
29956 get_texture_readback(render_targets[0], 0, &rb);
29957 SetRect(&rect, 0, 0, 200, 200);
29958 check_readback_data_color(&rb, &rect, 0xffff0000, 1);
29959 SetRect(&rect, 200, 0, 640, 200);
29960 todo_wine
29961 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29962 SetRect(&rect, 0, 200, 640, 480);
29963 todo_wine
29964 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29965 release_resource_readback(&rb);
29967 ID3D11Texture2D_Release(render_targets[0]);
29968 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
29969 ID3D11RenderTargetView_Release(rtvs[i]);
29971 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29972 hr = ID3D11Device_CheckMultisampleQualityLevels(device,
29973 texture_desc.Format, 4, &quality_level_count);
29974 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
29975 if (!quality_level_count)
29977 skip("4xMSAA not supported.\n");
29978 goto done;
29980 texture_desc.SampleDesc.Count = 4;
29981 texture_desc.SampleDesc.Quality = 0;
29983 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
29985 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
29986 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29987 hr = ID3D11Device_CreateRenderTargetView(device,
29988 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
29989 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
29991 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
29993 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
29994 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
29995 draw_quad(&test_context);
29996 texture_desc.SampleDesc.Count = 1;
29997 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
29998 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29999 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
30001 DWORD expected_color;
30003 assert(i < ARRAY_SIZE(colors));
30004 expected_color = colors[i];
30006 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
30007 (ID3D11Resource *)render_targets[i], 0, texture_desc.Format);
30009 get_texture_readback(readback_texture, 0, &rb);
30010 SetRect(&rect, 0, 0, 200, 200);
30011 check_readback_data_color(&rb, &rect, expected_color, 1);
30012 SetRect(&rect, 200, 0, 640, 200);
30013 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30014 SetRect(&rect, 0, 200, 640, 480);
30015 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30016 release_resource_readback(&rb);
30018 ID3D11Texture2D_Release(readback_texture);
30020 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
30022 ID3D11Texture2D_Release(render_targets[i]);
30023 ID3D11RenderTargetView_Release(rtvs[i]);
30026 done:
30027 ID3D11Buffer_Release(cb);
30028 ID3D11PixelShader_Release(ps);
30029 ID3D11BlendState_Release(blend_state);
30030 release_test_context(&test_context);
30033 static void test_unbound_multisample_texture(void)
30035 struct d3d11_test_context test_context;
30036 ID3D11DeviceContext *context;
30037 ID3D11PixelShader *ps;
30038 struct uvec4 cb_data;
30039 ID3D11Device *device;
30040 ID3D11Buffer *cb;
30041 unsigned int i;
30042 HRESULT hr;
30044 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30045 static const DWORD ps_code[] =
30047 #if 0
30048 Texture2DMS<float4, 4> t;
30050 uint sample_index;
30052 float4 main(float4 position : SV_Position) : SV_Target
30054 float3 p;
30055 t.GetDimensions(p.x, p.y, p.z);
30056 p *= float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
30057 /* sample index must be a literal */
30058 switch (sample_index)
30060 case 1: return t.Load(int2(p.xy), 1);
30061 case 2: return t.Load(int2(p.xy), 2);
30062 case 3: return t.Load(int2(p.xy), 3);
30063 default: return t.Load(int2(p.xy), 0);
30066 #endif
30067 0x43425844, 0x03d62416, 0x1914ee8b, 0xccd08d68, 0x27f42136, 0x00000001, 0x000002f8, 0x00000003,
30068 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30069 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
30070 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
30071 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000025c, 0x00000040,
30072 0x00000097, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04042058, 0x00107000, 0x00000000,
30073 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
30074 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46,
30075 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000,
30076 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
30077 0x00000000, 0x00000000, 0x0400004c, 0x0020800a, 0x00000000, 0x00000000, 0x03000006, 0x00004001,
30078 0x00000001, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000, 0x08000036, 0x001000c2,
30079 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0900002e, 0x001020f2,
30080 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
30081 0x03000006, 0x00004001, 0x00000002, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000,
30082 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
30083 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001,
30084 0x00000002, 0x0100003e, 0x03000006, 0x00004001, 0x00000003, 0x0500001b, 0x00100032, 0x00000001,
30085 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000,
30086 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46,
30087 0x00000000, 0x00004001, 0x00000003, 0x0100003e, 0x0100000a, 0x0500001b, 0x00100032, 0x00000000,
30088 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
30089 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46,
30090 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000017, 0x0100003e,
30093 if (!init_test_context(&test_context, NULL))
30094 return;
30095 device = test_context.device;
30096 context = test_context.immediate_context;
30098 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30099 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30100 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30102 memset(&cb_data, 0, sizeof(cb_data));
30103 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
30104 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30106 for (i = 0; i < 4; ++i)
30108 cb_data.x = i;
30109 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_data, 0, 0);
30110 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
30111 draw_quad(&test_context);
30112 check_texture_color(test_context.backbuffer, 0x00000000, 1);
30115 ID3D11Buffer_Release(cb);
30116 ID3D11PixelShader_Release(ps);
30117 release_test_context(&test_context);
30120 static void test_multiple_viewports(void)
30122 struct
30124 unsigned int draw_id;
30125 unsigned int padding[3];
30126 } constant;
30127 D3D11_VIEWPORT vp[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE + 1];
30128 struct d3d11_test_context test_context;
30129 D3D11_TEXTURE2D_DESC texture_desc;
30130 ID3D11DeviceContext *context;
30131 ID3D11RenderTargetView *rtv;
30132 ID3D11Texture2D *texture;
30133 ID3D11GeometryShader *gs;
30134 ID3D11PixelShader *ps;
30135 ID3D11Device *device;
30136 ID3D11Buffer *cb;
30137 HRESULT hr;
30139 static const DWORD gs_code[] =
30141 #if 0
30142 struct gs_in
30144 float4 pos : SV_Position;
30147 struct gs_out
30149 float4 pos : SV_Position;
30150 uint viewport : SV_ViewportArrayIndex;
30153 [maxvertexcount(6)]
30154 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
30156 gs_out o;
30157 for (uint instance_id = 0; instance_id < 2; ++instance_id)
30159 o.viewport = instance_id;
30160 for (uint i = 0; i < 3; ++i)
30162 o.pos = vin[i].pos;
30163 vout.Append(o);
30165 vout.RestartStrip();
30168 #endif
30169 0x43425844, 0xabbb660f, 0x0729bf23, 0x14a9a104, 0x1b454917, 0x00000001, 0x0000021c, 0x00000003,
30170 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30171 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
30172 0x4e47534f, 0x0000005c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
30173 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005, 0x00000001, 0x00000001, 0x00000e01,
30174 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569, 0x4174726f, 0x79617272, 0x65646e49,
30175 0xabab0078, 0x52444853, 0x00000150, 0x00020040, 0x00000054, 0x05000061, 0x002010f2, 0x00000003,
30176 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
30177 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000005, 0x0200005e, 0x00000006,
30178 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
30179 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x03040003, 0x0010001a, 0x00000000,
30180 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
30181 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000,
30182 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036,
30183 0x00102012, 0x00000001, 0x0010000a, 0x00000000, 0x01000013, 0x0700001e, 0x00100022, 0x00000000,
30184 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012,
30185 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
30187 static const DWORD ps_code[] =
30189 #if 0
30190 uint draw_id;
30192 float4 main(in float4 pos : SV_Position,
30193 in uint viewport : SV_ViewportArrayIndex) : SV_Target
30195 return float4(viewport, draw_id, 0, 0);
30197 #endif
30198 0x43425844, 0x77334c0f, 0x5df3ca7a, 0xc53c00db, 0x3e6e5750, 0x00000001, 0x00000150, 0x00000003,
30199 0x0000002c, 0x00000090, 0x000000c4, 0x4e475349, 0x0000005c, 0x00000002, 0x00000008, 0x00000038,
30200 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005,
30201 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569,
30202 0x4174726f, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
30203 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261,
30204 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46, 0x00000000,
30205 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000005, 0x03000065, 0x001020f2, 0x00000000,
30206 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022, 0x00000000,
30207 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000,
30208 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
30210 static const struct vec4 expected_values[] =
30212 {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},
30213 {0.0f, 5.0f}, {0.5f, 0.5f}, {1.0f, 5.0f}, {0.5f, 0.5f},
30215 static const float clear_color[] = {0.5f, 0.5f, 0.0f, 0.0f};
30216 ID3D11RasterizerState *rasterizer_state;
30217 D3D11_RASTERIZER_DESC rasterizer_desc;
30218 unsigned int count, i;
30219 D3D11_RECT rects[2];
30220 RECT rect;
30221 int width;
30223 if (!init_test_context(&test_context, NULL))
30224 return;
30226 device = test_context.device;
30227 context = test_context.immediate_context;
30229 memset(&constant, 0, sizeof(constant));
30230 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
30231 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30233 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
30234 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
30235 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
30237 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30238 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
30239 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30241 texture_desc.Width = 32;
30242 texture_desc.Height = 32;
30243 texture_desc.MipLevels = 1;
30244 texture_desc.ArraySize = 1;
30245 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
30246 texture_desc.SampleDesc.Count = 1;
30247 texture_desc.SampleDesc.Quality = 0;
30248 texture_desc.Usage = D3D11_USAGE_DEFAULT;
30249 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
30250 texture_desc.CPUAccessFlags = 0;
30251 texture_desc.MiscFlags = 0;
30252 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30253 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30255 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
30256 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
30257 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30259 width = texture_desc.Width / 2;
30261 vp[0].TopLeftX = 0.0f;
30262 vp[0].TopLeftY = 0.0f;
30263 vp[0].Width = width;
30264 vp[0].Height = texture_desc.Height;
30265 vp[0].MinDepth = 0.0f;
30266 vp[0].MaxDepth = 1.0f;
30268 vp[1] = vp[0];
30269 vp[1].TopLeftX = width;
30270 vp[1].Width = width;
30271 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
30273 count = enable_debug_layer ? ARRAY_SIZE(vp) - 1 : ARRAY_SIZE(vp);
30274 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
30275 ok(count == 2, "Unexpected viewport count %d.\n", count);
30277 constant.draw_id = 0;
30278 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30279 draw_quad(&test_context);
30280 constant.draw_id = 1;
30281 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30282 draw_quad(&test_context);
30284 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
30285 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[0], 1);
30286 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30287 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[1], 1);
30289 /* One viewport. */
30290 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30291 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
30292 constant.draw_id = 2;
30293 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30294 draw_quad(&test_context);
30295 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
30296 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[2], 1);
30297 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30298 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[3], 1);
30300 /* Reset viewports. */
30301 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30302 ID3D11DeviceContext_RSSetViewports(context, 0, NULL);
30303 constant.draw_id = 3;
30304 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30305 draw_quad(&test_context);
30306 check_texture_sub_resource_vec4(texture, 0, NULL, &expected_values[4], 1);
30308 /* Two viewports, only first scissor rectangle set. */
30309 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
30310 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
30311 rasterizer_desc.CullMode = D3D11_CULL_BACK;
30312 rasterizer_desc.DepthClipEnable = TRUE;
30313 rasterizer_desc.ScissorEnable = TRUE;
30314 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
30315 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
30317 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
30318 ID3D11RasterizerState_Release(rasterizer_state);
30320 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30321 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
30323 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
30324 memset(&rects[1], 0, sizeof(*rects));
30325 ID3D11DeviceContext_RSSetScissorRects(context, 1, rects);
30326 constant.draw_id = 4;
30327 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30328 draw_quad(&test_context);
30330 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
30331 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[5], 1);
30332 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
30333 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[6], 1);
30334 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30335 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[7], 1);
30337 /* Set both rectangles. */
30338 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
30339 SetRect(&rects[1], width, 0, 2 * width, texture_desc.Height / 2);
30340 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30341 ID3D11DeviceContext_RSSetScissorRects(context, 2, rects);
30342 constant.draw_id = 5;
30343 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30344 draw_quad(&test_context);
30346 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
30347 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[8], 1);
30348 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
30349 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[9], 1);
30351 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height / 2 - 1);
30352 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[10], 1);
30353 SetRect(&rect, width, texture_desc.Height / 2, 2 * width - 1, texture_desc.Height - 1);
30354 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[11], 1);
30356 if (enable_debug_layer)
30357 goto done;
30359 /* Viewport count exceeding maximum value. */
30360 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
30362 vp[0].TopLeftX = 1.0f;
30363 vp[0].TopLeftY = 0.0f;
30364 vp[0].Width = width;
30365 vp[0].Height = texture_desc.Height;
30366 vp[0].MinDepth = 0.0f;
30367 vp[0].MaxDepth = 1.0f;
30368 for (i = 1; i < ARRAY_SIZE(vp); ++i)
30370 vp[i] = vp[0];
30372 ID3D11DeviceContext_RSSetViewports(context, ARRAY_SIZE(vp), vp);
30374 count = ARRAY_SIZE(vp);
30375 memset(vp, 0, sizeof(vp));
30376 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
30377 ok(count == 1, "Unexpected viewport count %d.\n", count);
30378 ok(vp[0].TopLeftX == 0.0f && vp[0].Width == width, "Unexpected viewport.\n");
30380 done:
30381 ID3D11RenderTargetView_Release(rtv);
30382 ID3D11Texture2D_Release(texture);
30384 ID3D11Buffer_Release(cb);
30385 ID3D11GeometryShader_Release(gs);
30386 ID3D11PixelShader_Release(ps);
30387 release_test_context(&test_context);
30390 static void test_multisample_resolve(void)
30392 struct d3d11_test_context test_context;
30393 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
30394 ID3D11Texture2D *texture, *ms_texture;
30395 D3D11_TEXTURE2D_DESC texture_desc;
30396 ID3D11DeviceContext *context;
30397 ID3D11RenderTargetView *rtv;
30398 ID3D11Device *device;
30399 unsigned int i;
30400 HRESULT hr;
30402 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30403 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
30404 static const struct vec4 color = {0.25f, 0.5f, 0.75f, 1.0f};
30405 static const struct
30407 DXGI_FORMAT src_format;
30408 DXGI_FORMAT dst_format;
30409 DXGI_FORMAT format;
30411 DXGI_FORMAT rtv_format;
30413 const struct vec4 *color;
30414 DWORD expected_color;
30416 BOOL todo;
30418 tests[] =
30420 {DXGI_FORMAT_R8G8B8A8_UNORM,
30421 DXGI_FORMAT_R8G8B8A8_UNORM,
30422 DXGI_FORMAT_R8G8B8A8_UNORM,
30423 DXGI_FORMAT_R8G8B8A8_UNORM,
30424 &green, 0xff80ff80},
30425 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30426 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30427 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30428 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30429 &green, 0xffbcffbc},
30430 {DXGI_FORMAT_R8G8B8A8_UNORM,
30431 DXGI_FORMAT_R8G8B8A8_UNORM,
30432 DXGI_FORMAT_R8G8B8A8_UNORM,
30433 DXGI_FORMAT_R8G8B8A8_UNORM,
30434 &color, 0xffdfc0a0},
30435 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30436 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30437 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30438 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30439 &color, 0xfff1e1cf},
30441 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30442 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30443 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30444 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30445 &green, 0xffbcffbc},
30446 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30447 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30448 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30449 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30450 &green, 0xffbcffbc},
30451 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30452 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30453 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30454 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30455 &color, 0xfff1e1cf},
30456 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30457 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30458 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30459 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30460 &color, 0xfff1e1cf},
30462 {DXGI_FORMAT_R8G8B8A8_UNORM,
30463 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30464 DXGI_FORMAT_R8G8B8A8_UNORM,
30465 DXGI_FORMAT_R8G8B8A8_UNORM,
30466 &green, 0xff80ff80},
30467 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30468 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30469 DXGI_FORMAT_R8G8B8A8_UNORM,
30470 DXGI_FORMAT_R8G8B8A8_UNORM,
30471 &green, 0xff80ff80},
30472 {DXGI_FORMAT_R8G8B8A8_UNORM,
30473 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30474 DXGI_FORMAT_R8G8B8A8_UNORM,
30475 DXGI_FORMAT_R8G8B8A8_UNORM,
30476 &color, 0xffdfc0a0},
30477 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30478 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30479 DXGI_FORMAT_R8G8B8A8_UNORM,
30480 DXGI_FORMAT_R8G8B8A8_UNORM,
30481 &color, 0xffdfc0a0},
30483 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30484 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30485 DXGI_FORMAT_R8G8B8A8_UNORM,
30486 DXGI_FORMAT_R8G8B8A8_UNORM,
30487 &green, 0xff80ff80},
30488 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30489 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30490 DXGI_FORMAT_R8G8B8A8_UNORM,
30491 DXGI_FORMAT_R8G8B8A8_UNORM,
30492 &color, 0xffdfc0a0},
30493 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30494 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30495 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30496 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30497 &green, 0xffbcffbc},
30498 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30499 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30500 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30501 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30502 &color, 0xfff1e1cf},
30503 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30504 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30505 DXGI_FORMAT_R8G8B8A8_UNORM,
30506 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30507 &green, 0xff80ff80},
30508 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30509 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30510 DXGI_FORMAT_R8G8B8A8_UNORM,
30511 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30512 &color, 0xfff0dec4},
30513 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30514 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30515 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30516 DXGI_FORMAT_R8G8B8A8_UNORM,
30517 &green, 0xffbcffbc, TRUE},
30518 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30519 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30520 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30521 DXGI_FORMAT_R8G8B8A8_UNORM,
30522 &color, 0xffe2cdc0, TRUE},
30525 if (!init_test_context(&test_context, NULL))
30526 return;
30527 device = test_context.device;
30528 context = test_context.immediate_context;
30530 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &i);
30531 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
30532 if (!i)
30534 skip("4xMSAA not supported.\n");
30535 release_test_context(&test_context);
30536 return;
30539 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, 3);
30541 for (i = 0; i < ARRAY_SIZE(tests); ++i)
30543 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30544 texture_desc.Format = tests[i].dst_format;
30545 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30546 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30548 texture_desc.Format = tests[i].src_format;
30549 texture_desc.SampleDesc.Count = 4;
30550 texture_desc.SampleDesc.Quality = 0;
30551 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ms_texture);
30552 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30553 rtv_desc.Format = tests[i].rtv_format;
30554 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
30555 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)ms_texture, &rtv_desc, &rtv);
30556 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
30558 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30559 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
30560 draw_color_quad(&test_context, tests[i].color);
30561 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)texture, 0,
30562 (ID3D11Resource *)ms_texture, 0, tests[i].format);
30564 /* Found broken on AMD Radeon HD 6310 */
30565 if (!broken(is_amd_device(device) && tests[i].format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB))
30566 todo_wine_if(tests[i].todo) check_texture_color(texture, tests[i].expected_color, 2);
30568 ID3D11RenderTargetView_Release(rtv);
30569 ID3D11Texture2D_Release(ms_texture);
30570 ID3D11Texture2D_Release(texture);
30573 release_test_context(&test_context);
30576 static void test_sample_shading(void)
30578 struct shader
30580 const DWORD *code;
30581 size_t size;
30584 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
30585 struct d3d11_test_context test_context;
30586 struct swapchain_desc swapchain_desc;
30587 D3D11_TEXTURE2D_DESC texture_desc;
30588 ID3D11UnorderedAccessView *uav;
30589 D3D11_BUFFER_DESC buffer_desc;
30590 ID3D11ShaderResourceView *srv;
30591 ID3D11DeviceContext *context;
30592 ID3D11RenderTargetView *rtv;
30593 struct resource_readback rb;
30594 ID3D11Buffer *buffer, *cb;
30595 ID3D11Texture2D *texture;
30596 struct uvec4 ps_constant;
30597 ID3D11PixelShader *ps;
30598 ID3D11Device *device;
30599 unsigned int data;
30600 unsigned int i;
30601 HRESULT hr;
30603 static const DWORD ps_unused_sample_index_code[] =
30605 #if 0
30606 RWByteAddressBuffer u;
30608 float4 main(uint id : SV_SampleIndex) : SV_Target
30610 u.InterlockedAdd(0, 1);
30611 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30613 #endif
30614 0x43425844, 0x41e4574b, 0x1e6441d6, 0x5e756375, 0xacd5dc27, 0x00000001, 0x00000104, 0x00000003,
30615 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30616 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000001, 0x535f5653, 0x6c706d61, 0x646e4965,
30617 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30618 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064,
30619 0x00000050, 0x00000019, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2,
30620 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
30621 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
30622 0x0100003e,
30624 static const struct shader ps_unused_sample_index
30625 = {ps_unused_sample_index_code, sizeof(ps_unused_sample_index_code)};
30626 static const DWORD ps_sample_index_code[] =
30628 #if 0
30629 RWByteAddressBuffer u;
30631 float4 main(uint id : SV_SampleIndex) : SV_Target
30633 u.InterlockedAdd(0, 1);
30634 u.InterlockedAdd(4, id);
30635 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30637 #endif
30638 0x43425844, 0x943ab9ed, 0x91520b4a, 0xb75df9d0, 0x692cd3e6, 0x00000001, 0x00000130, 0x00000003,
30639 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30640 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
30641 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30642 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000090,
30643 0x00000050, 0x00000024, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
30644 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001,
30645 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
30646 0x00000004, 0x0010100a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
30647 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30649 static const struct shader ps_sample_index = {ps_sample_index_code, sizeof(ps_sample_index_code)};
30650 static const DWORD ps_samplepos_code[] =
30652 #if 0
30653 Texture2DMS<float> t;
30654 RWByteAddressBuffer u;
30656 float4 main() : SV_Target
30658 float2 sample_position = t.GetSamplePosition(0);
30659 u.InterlockedAdd(0, 1);
30660 u.InterlockedAdd(4, sample_position.x + sample_position.y);
30661 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30663 #endif
30664 0x43425844, 0x9ec7f344, 0x588f5863, 0x436c0531, 0x69dc54bb, 0x00000001, 0x00000160, 0x00000003,
30665 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
30666 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
30667 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e8, 0x00000050, 0x0000003a,
30668 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
30669 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
30670 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
30671 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
30672 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
30673 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
30674 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30676 static const struct shader ps_samplepos = {ps_samplepos_code, sizeof(ps_samplepos_code)};
30677 static const DWORD ps_samplepos_rasterizer_code[] =
30679 #if 0
30680 RWByteAddressBuffer u;
30682 float4 main() : SV_Target
30684 float2 sample_position = GetRenderTargetSamplePosition(0);
30685 u.InterlockedAdd(0, 1);
30686 u.InterlockedAdd(4, sample_position.x + sample_position.y);
30687 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30689 #endif
30690 0x43425844, 0xe31795d9, 0x4e9951da, 0xc1713913, 0xfb12da31, 0x00000001, 0x00000148, 0x00000003,
30691 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
30692 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
30693 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d0, 0x00000050, 0x00000034,
30694 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
30695 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
30696 0x0600006e, 0x00100032, 0x00000000, 0x0000e046, 0x00004001, 0x00000000, 0x07000000, 0x00100012,
30697 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
30698 0x0010000a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
30699 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
30700 0x3f800000, 0x0100003e,
30702 static const struct shader ps_samplepos_rasterizer
30703 = {ps_samplepos_rasterizer_code, sizeof(ps_samplepos_rasterizer_code)};
30704 static const DWORD ps_samplepos_indexed_code[] =
30706 #if 0
30707 RWByteAddressBuffer u;
30709 float4 main(uint id : SV_SampleIndex) : SV_Target
30711 float2 sample_position = GetRenderTargetSamplePosition(id);
30712 u.InterlockedAdd(0, 1);
30713 u.InterlockedAdd(4, sample_position.x + sample_position.y);
30714 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30716 #endif
30717 0x43425844, 0x4b501464, 0x0cd4f636, 0x36428677, 0x6db6b4fb, 0x00000001, 0x00000180, 0x00000003,
30718 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30719 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
30720 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30721 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e0,
30722 0x00000050, 0x00000038, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
30723 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad,
30724 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0600006e, 0x00100032,
30725 0x00000000, 0x0000e046, 0x0010100a, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
30726 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
30727 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
30728 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30730 static const struct shader ps_samplepos_indexed
30731 = {ps_samplepos_indexed_code, sizeof(ps_samplepos_indexed_code)};
30732 static const DWORD ps_sampleinfo_code[] =
30734 #if 0
30735 Texture2DMS<float> t;
30736 RWByteAddressBuffer u;
30738 float4 main() : SV_Target
30740 uint width, height, sample_count;
30741 t.GetDimensions(width, height, sample_count);
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, 0x4e4f4065, 0x20d88902, 0xd4750e8c, 0x652b8c04, 0x00000001, 0x00000124, 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, 0x000000ac, 0x00000050, 0x0000002b,
30751 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
30752 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
30753 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a,
30754 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000,
30755 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
30756 0x0100003e,
30758 static const struct shader ps_sampleinfo = {ps_sampleinfo_code, sizeof(ps_sampleinfo_code)};
30759 static const DWORD ps_sampleinfo_rasterizer_code[] =
30761 #if 0
30762 RWByteAddressBuffer u;
30764 float4 main() : SV_Target
30766 uint sample_count = GetRenderTargetSampleCount();
30767 u.InterlockedAdd(0, 1);
30768 u.InterlockedAdd(4, sample_count);
30769 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30771 #endif
30772 0x43425844, 0xfbbd8619, 0x9c2654c8, 0xb385363a, 0x4aacd10f, 0x00000001, 0x00000110, 0x00000003,
30773 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
30774 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
30775 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000098, 0x00000050, 0x00000026,
30776 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
30777 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
30778 0x0400086f, 0x00100012, 0x00000000, 0x0000e00a, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
30779 0x00000004, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
30780 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30782 static const struct shader ps_sampleinfo_rasterizer
30783 = {ps_sampleinfo_rasterizer_code, sizeof(ps_sampleinfo_rasterizer_code)};
30784 static const DWORD ps_sample_code[] =
30786 #if 0
30787 RWByteAddressBuffer u;
30789 float4 main(sample float4 position : SV_Position) : SV_Target
30791 u.InterlockedAdd(0, 1);
30792 u.InterlockedAdd(4, position.x);
30793 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30795 #endif
30796 0x43425844, 0x46ecbadb, 0xedccbea6, 0x236d7923, 0x0c356c8c, 0x00000001, 0x00000148, 0x00000003,
30797 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30798 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x7469736f, 0x006e6f69,
30799 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
30800 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050,
30801 0x0000002b, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04003864, 0x00101012, 0x00000000,
30802 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000,
30803 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500001c, 0x00100012, 0x00000000,
30804 0x0010100a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
30805 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
30806 0x3f800000, 0x0100003e,
30808 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
30809 static const DWORD ps_color_code[] =
30811 #if 0
30812 float4 main(uint id : SV_SampleIndex) : SV_Target
30814 switch (id)
30816 case 0: return float4(1.0f, 0.0f, 0.0f, 1.0f);
30817 case 1: return float4(0.0f, 1.0f, 0.0f, 1.0f);
30818 case 2: return float4(0.0f, 0.0f, 1.0f, 1.0f);
30819 default: return float4(0.0f, 0.0f, 0.0f, 1.0f);
30822 #endif
30823 0x43425844, 0x94c35f48, 0x04c6b0f7, 0x407d8214, 0xc24f01e5, 0x00000001, 0x00000194, 0x00000003,
30824 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30825 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
30826 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30827 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f4,
30828 0x00000050, 0x0000003d, 0x0100086a, 0x04000863, 0x00101012, 0x00000000, 0x0000000a, 0x03000065,
30829 0x001020f2, 0x00000000, 0x0300004c, 0x0010100a, 0x00000000, 0x03000006, 0x00004001, 0x00000000,
30830 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
30831 0x0100003e, 0x03000006, 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
30832 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x03000006, 0x00004001, 0x00000002,
30833 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000,
30834 0x0100003e, 0x0100000a, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
30835 0x00000000, 0x3f800000, 0x0100003e, 0x01000017, 0x0100003e,
30837 static const DWORD ps_resolve_code[] =
30839 #if 0
30840 Texture2DMS<float4> t;
30842 uint sample;
30843 uint rt_size;
30845 float4 main(float4 position : SV_Position) : SV_Target
30847 float3 p;
30848 t.GetDimensions(p.x, p.y, p.z);
30849 p *= float3(position.x / rt_size, position.y / rt_size, 0);
30850 return t.Load((int2)p.xy, sample);
30852 #endif
30853 0x43425844, 0x68a4590b, 0xc1ec3070, 0x1b957c43, 0x0c080741, 0x00000001, 0x000001c8, 0x00000003,
30854 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30855 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
30856 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
30857 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000012c, 0x00000050,
30858 0x0000004b, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002058, 0x00107000,
30859 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
30860 0x00000000, 0x02000068, 0x00000001, 0x06000056, 0x00100012, 0x00000000, 0x0020801a, 0x00000000,
30861 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00100006, 0x00000000,
30862 0x8900003d, 0x80000102, 0x00155543, 0x001000c2, 0x00000000, 0x00004001, 0x00000000, 0x001074e6,
30863 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000,
30864 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000,
30865 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8c00002e, 0x80000102, 0x00155543,
30866 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0020800a, 0x00000000,
30867 0x00000000, 0x0100003e,
30869 static const struct
30871 const struct shader *ps;
30872 BOOL sample_shading;
30873 BOOL todo;
30874 BOOL broken;
30876 tests[] =
30878 {&ps_unused_sample_index, FALSE, FALSE, TRUE /* broken on Nvidia */},
30879 {&ps_sample_index, TRUE},
30880 {&ps_samplepos, FALSE},
30881 {&ps_samplepos_rasterizer, FALSE},
30882 {&ps_samplepos_indexed, TRUE, TRUE},
30883 {&ps_sampleinfo, FALSE},
30884 {&ps_sampleinfo_rasterizer, FALSE},
30885 {&ps_sample, TRUE, TRUE, TRUE /* broken on Intel */},
30887 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
30888 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30889 static const unsigned int zero[4] = {0};
30891 swapchain_desc.windowed = TRUE;
30892 swapchain_desc.buffer_count = 1;
30893 swapchain_desc.width = 32;
30894 swapchain_desc.height = 32;
30895 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
30896 swapchain_desc.flags = 0;
30897 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
30898 return;
30899 device = test_context.device;
30900 context = test_context.immediate_context;
30902 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30903 texture_desc.SampleDesc.Count = 4;
30904 texture_desc.SampleDesc.Quality = 0;
30905 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
30906 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30907 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30908 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
30909 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
30910 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
30911 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
30913 buffer_desc.ByteWidth = 1024;
30914 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
30915 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
30916 buffer_desc.CPUAccessFlags = 0;
30917 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
30918 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
30919 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
30920 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
30921 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
30922 U(uav_desc).Buffer.FirstElement = 0;
30923 U(uav_desc).Buffer.NumElements = 256;
30924 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
30925 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
30926 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
30928 for (i = 0; i < ARRAY_SIZE(tests); ++i)
30930 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
30931 ok(hr == S_OK, "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
30932 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30934 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
30935 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
30936 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
30937 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
30938 draw_quad(&test_context);
30939 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
30940 get_buffer_readback(buffer, &rb);
30941 data = get_readback_color(&rb, 0, 0, 0);
30942 ok(1024 <= data && data <= 1056, "Test %u: Got unexpected value %u.\n", i, data);
30943 release_resource_readback(&rb);
30945 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
30946 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
30947 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
30948 1, &rtv, NULL, 1, 1, &uav, NULL);
30949 draw_quad(&test_context);
30950 get_buffer_readback(buffer, &rb);
30951 data = get_readback_color(&rb, 0, 0, 0);
30952 todo_wine_if(tests[i].todo)
30954 if (tests[i].sample_shading)
30956 ok(4096 <= data || broken(tests[i].broken && data >= 1024),
30957 "Test %u: Got unexpected value %u.\n", i, data);
30959 else
30961 ok((1024 <= data && data <= 1056) || broken(tests[i].broken && data >= 4096),
30962 "Test %u: Got unexpected value %u.\n", i, data);
30965 release_resource_readback(&rb);
30967 ID3D11PixelShader_Release(ps);
30970 if (is_warp_device(device))
30972 skip("Sample shading tests fail on WARP.\n");
30973 goto done;
30976 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps);
30977 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30978 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30979 ID3D11PixelShader_Release(ps);
30981 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
30982 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30983 draw_quad(&test_context);
30984 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
30985 (ID3D11Resource *)texture, 0, texture_desc.Format);
30986 check_texture_color(test_context.backbuffer, 0xff404040, 2);
30988 hr = ID3D11Device_CreatePixelShader(device, ps_resolve_code, sizeof(ps_resolve_code), NULL, &ps);
30989 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30990 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30991 ID3D11PixelShader_Release(ps);
30992 ps_constant.x = 0;
30993 ps_constant.y = texture_desc.Width;
30994 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
30995 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30997 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
30998 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
30999 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31000 draw_quad(&test_context);
31001 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
31002 ps_constant.x = 1;
31003 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
31004 draw_quad(&test_context);
31005 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
31006 ps_constant.x = 2;
31007 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
31008 draw_quad(&test_context);
31009 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
31010 ps_constant.x = 3;
31011 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
31012 draw_quad(&test_context);
31013 check_texture_color(test_context.backbuffer, 0xff000000, 0);
31015 ID3D11Buffer_Release(cb);
31016 done:
31017 ID3D11Buffer_Release(buffer);
31018 ID3D11UnorderedAccessView_Release(uav);
31019 ID3D11RenderTargetView_Release(rtv);
31020 ID3D11ShaderResourceView_Release(srv);
31021 ID3D11Texture2D_Release(texture);
31022 release_test_context(&test_context);
31025 static void test_sample_mask(void)
31027 static const DWORD ps_code[] =
31029 #if 0
31030 float4 main(in float4 pos : SV_Position, out uint sample_mask : SV_Coverage) : SV_Target
31032 sample_mask = 0x5;
31033 return float4(1.0, 1.0, 1.0, 1.0);
31035 #endif
31036 0x43425844, 0x196779a9, 0xda85988a, 0xb7f0a0b6, 0xb30dd6ba, 0x00000001, 0x00000114, 0x00000003,
31037 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31038 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
31039 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
31040 0x00000000, 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000001, 0xffffffff, 0x00000e01,
31041 0x545f5653, 0x65677261, 0x56530074, 0x766f435f, 0x67617265, 0xabab0065, 0x58454853, 0x00000054,
31042 0x00000050, 0x00000015, 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x0000f000,
31043 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
31044 0x04000036, 0x0000f001, 0x00004001, 0x00000005, 0x0100003e,
31046 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
31047 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
31048 struct d3d11_test_context test_context;
31049 D3D11_TEXTURE2D_DESC texture_desc;
31050 ID3D11DeviceContext *context;
31051 ID3D11RenderTargetView *rtv;
31052 ID3D11Texture2D *texture;
31053 ID3D11PixelShader *ps;
31054 ID3D11Device *device;
31055 UINT quality_levels;
31056 HRESULT hr;
31058 if (!init_test_context(&test_context, &feature_level))
31059 return;
31060 device = test_context.device;
31061 context = test_context.immediate_context;
31063 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &quality_levels);
31064 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
31065 if (!quality_levels)
31067 skip("4xMSAA not supported.\n");
31068 release_test_context(&test_context);
31069 return;
31072 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31073 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31074 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31076 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31077 texture_desc.SampleDesc.Count = 4;
31078 texture_desc.SampleDesc.Quality = 0;
31079 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31080 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31081 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
31082 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
31084 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
31085 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31086 draw_quad(&test_context);
31087 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
31088 (ID3D11Resource *)texture, 0, texture_desc.Format);
31089 check_texture_color(test_context.backbuffer, 0x7f7f7f7f, 1);
31091 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, 0xb);
31092 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31093 draw_quad(&test_context);
31094 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
31095 (ID3D11Resource *)texture, 0, texture_desc.Format);
31096 check_texture_color(test_context.backbuffer, 0x3f3f3f3f, 1);
31098 ID3D11RenderTargetView_Release(rtv);
31099 ID3D11Texture2D_Release(texture);
31100 ID3D11PixelShader_Release(ps);
31101 release_test_context(&test_context);
31104 static void test_depth_clip(void)
31106 struct d3d11_test_context test_context;
31107 D3D11_TEXTURE2D_DESC texture_desc;
31108 D3D11_RASTERIZER_DESC rs_desc;
31109 ID3D11DeviceContext *context;
31110 ID3D11DepthStencilView *dsv;
31111 ID3D11RasterizerState *rs;
31112 ID3D11Texture2D *texture;
31113 ID3D11Device *device;
31114 unsigned int count;
31115 D3D11_VIEWPORT vp;
31116 HRESULT hr;
31118 if (!init_test_context(&test_context, NULL))
31119 return;
31120 device = test_context.device;
31121 context = test_context.immediate_context;
31123 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31124 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
31125 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
31127 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31128 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
31129 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
31130 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
31131 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
31133 count = 1;
31134 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
31136 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
31137 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
31138 draw_quad_z(&test_context, 2.0f);
31139 check_texture_float(texture, 1.0f, 1);
31140 draw_quad_z(&test_context, 0.5f);
31141 check_texture_float(texture, 0.5f, 1);
31142 draw_quad_z(&test_context, -1.0f);
31143 check_texture_float(texture, 0.5f, 1);
31145 rs_desc.FillMode = D3D11_FILL_SOLID;
31146 rs_desc.CullMode = D3D11_CULL_BACK;
31147 rs_desc.FrontCounterClockwise = FALSE;
31148 rs_desc.DepthBias = 0;
31149 rs_desc.DepthBiasClamp = 0.0f;
31150 rs_desc.SlopeScaledDepthBias = 0.0f;
31151 rs_desc.DepthClipEnable = FALSE;
31152 rs_desc.ScissorEnable = FALSE;
31153 rs_desc.MultisampleEnable = FALSE;
31154 rs_desc.AntialiasedLineEnable = FALSE;
31155 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
31156 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
31158 ID3D11DeviceContext_RSSetState(context, rs);
31160 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
31161 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
31162 draw_quad_z(&test_context, 2.0f);
31163 check_texture_float(texture, 0.6f, 1);
31164 draw_quad_z(&test_context, 0.5f);
31165 check_texture_float(texture, 0.5f, 1);
31166 draw_quad_z(&test_context, -1.0f);
31167 check_texture_float(texture, 0.4f, 1);
31169 ID3D11DepthStencilView_Release(dsv);
31170 ID3D11Texture2D_Release(texture);
31171 ID3D11RasterizerState_Release(rs);
31172 release_test_context(&test_context);
31175 static void test_staging_buffers(void)
31177 struct d3d11_test_context test_context;
31178 ID3D11Buffer *dst_buffer, *src_buffer;
31179 D3D11_SUBRESOURCE_DATA resource_data;
31180 D3D11_BUFFER_DESC buffer_desc;
31181 ID3D11DeviceContext *context;
31182 struct resource_readback rb;
31183 float data[16], value;
31184 ID3D11Device *device;
31185 unsigned int i;
31186 HRESULT hr;
31188 if (!init_test_context(&test_context, NULL))
31189 return;
31190 device = test_context.device;
31191 context = test_context.immediate_context;
31193 buffer_desc.ByteWidth = sizeof(data);
31194 buffer_desc.Usage = D3D11_USAGE_STAGING;
31195 buffer_desc.BindFlags = 0;
31196 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
31197 buffer_desc.MiscFlags = 0;
31198 buffer_desc.StructureByteStride = 0;
31200 for (i = 0; i < ARRAY_SIZE(data); ++i)
31201 data[i] = i;
31202 resource_data.pSysMem = data;
31203 resource_data.SysMemPitch = 0;
31204 resource_data.SysMemSlicePitch = 0;
31206 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &src_buffer);
31207 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31209 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
31210 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
31211 buffer_desc.CPUAccessFlags = 0;
31212 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &dst_buffer);
31213 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31215 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
31216 get_buffer_readback(dst_buffer, &rb);
31217 for (i = 0; i < ARRAY_SIZE(data); ++i)
31219 value = get_readback_float(&rb, i, 0);
31220 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
31222 release_resource_readback(&rb);
31224 for (i = 0; i < ARRAY_SIZE(data); ++i)
31225 data[i] = 2 * i;
31226 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, NULL, data, 0, 0);
31227 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
31228 get_buffer_readback(dst_buffer, &rb);
31229 for (i = 0; i < ARRAY_SIZE(data); ++i)
31231 value = get_readback_float(&rb, i, 0);
31232 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
31234 release_resource_readback(&rb);
31236 ID3D11Buffer_Release(dst_buffer);
31237 ID3D11Buffer_Release(src_buffer);
31238 release_test_context(&test_context);
31241 static void test_render_a8(void)
31243 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
31244 struct d3d11_test_context test_context;
31245 D3D11_TEXTURE2D_DESC texture_desc;
31246 ID3D11DeviceContext *context;
31247 ID3D11RenderTargetView *rtv;
31248 struct resource_readback rb;
31249 ID3D11Texture2D *texture;
31250 ID3D11PixelShader *ps;
31251 ID3D11Device *device;
31252 unsigned int i;
31253 HRESULT hr;
31255 static const DWORD ps_code[] =
31257 #if 0
31258 void main(out float4 target : SV_Target)
31260 target = float4(0.0f, 0.25f, 0.5f, 1.0f);
31262 #endif
31263 0x43425844, 0x8a06129f, 0x3041bde2, 0x09389749, 0xb339ba8b, 0x00000001, 0x000000b0, 0x00000003,
31264 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31265 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31266 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
31267 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31268 0x3e800000, 0x3f000000, 0x3f800000, 0x0100003e,
31271 if (!init_test_context(&test_context, NULL))
31272 return;
31273 device = test_context.device;
31274 context = test_context.immediate_context;
31276 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31277 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31278 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31280 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31281 texture_desc.Format = DXGI_FORMAT_A8_UNORM;
31282 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31283 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31284 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
31285 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
31287 for (i = 0; i < 2; ++i)
31289 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31290 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
31291 draw_quad(&test_context);
31292 get_texture_readback(texture, 0, &rb);
31293 check_readback_data_u8(&rb, NULL, 0xff, 0);
31294 release_resource_readback(&rb);
31296 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
31297 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
31298 draw_quad(&test_context);
31299 check_texture_sub_resource_color(test_context.backbuffer, 0, NULL, 0xff7f4000, 1);
31302 ID3D11PixelShader_Release(ps);
31303 ID3D11Texture2D_Release(texture);
31304 ID3D11RenderTargetView_Release(rtv);
31305 release_test_context(&test_context);
31308 static void test_standard_pattern(void)
31310 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
31311 struct d3d11_test_context test_context;
31312 struct swapchain_desc swapchain_desc;
31313 D3D11_TEXTURE2D_DESC texture_desc;
31314 ID3D11UnorderedAccessView *uav;
31315 D3D11_BUFFER_DESC buffer_desc;
31316 ID3D11ShaderResourceView *srv;
31317 ID3D11DeviceContext *context;
31318 struct resource_readback rb;
31319 ID3D11Texture2D *texture;
31320 ID3D11PixelShader *ps;
31321 ID3D11Buffer *buffer;
31322 ID3D11Device *device;
31323 unsigned int i;
31324 HRESULT hr;
31326 static const DWORD ps_samplepos[] =
31328 #if 0
31329 Texture2DMS<float> t;
31330 RWByteAddressBuffer u;
31332 float4 main() : SV_Target
31334 u.Store2(0, asuint(t.GetSamplePosition(0)));
31335 u.Store2(8, asuint(t.GetSamplePosition(1)));
31336 u.Store2(16, asuint(t.GetSamplePosition(2)));
31337 u.Store2(24, asuint(t.GetSamplePosition(3)));
31338 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31340 #endif
31341 0x43425844, 0xa1db77e8, 0x804d8862, 0x0e3c213d, 0x2703dec6, 0x00000001, 0x00000190, 0x00000003,
31342 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31343 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31344 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000118, 0x00000050, 0x00000046,
31345 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
31346 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0800006e, 0x00100032, 0x00000000,
31347 0x00107046, 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x0800006e, 0x001000c2, 0x00000000,
31348 0x00107406, 0x00000000, 0x00004001, 0x00000001, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001,
31349 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
31350 0x00000000, 0x00004001, 0x00000002, 0x00000000, 0x0800006e, 0x001000c2, 0x00000000, 0x00107406,
31351 0x00000000, 0x00004001, 0x00000003, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001,
31352 0x00000010, 0x00100e46, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31353 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e
31355 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
31356 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
31357 static const unsigned int zero[4] = {0};
31358 static const float standard_pos4[] =
31360 -2 / 16.0f, -6 / 16.0f,
31361 6 / 16.0f, -2 / 16.0f,
31362 -6 / 16.0f, 2 / 16.0f,
31363 2 / 16.0f, 6 / 16.0f,
31366 swapchain_desc.windowed = TRUE;
31367 swapchain_desc.buffer_count = 1;
31368 swapchain_desc.width = 32;
31369 swapchain_desc.height = 32;
31370 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
31371 swapchain_desc.flags = 0;
31372 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
31373 return;
31374 device = test_context.device;
31375 context = test_context.immediate_context;
31377 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31378 texture_desc.SampleDesc.Count = 4;
31379 texture_desc.SampleDesc.Quality = D3D11_STANDARD_MULTISAMPLE_PATTERN;
31380 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
31381 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31382 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31383 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
31384 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
31386 buffer_desc.ByteWidth = 1024;
31387 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
31388 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
31389 buffer_desc.CPUAccessFlags = 0;
31390 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
31391 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
31392 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31393 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
31394 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
31395 U(uav_desc).Buffer.FirstElement = 0;
31396 U(uav_desc).Buffer.NumElements = 256;
31397 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
31398 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
31399 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
31401 hr = ID3D11Device_CreatePixelShader(device, ps_samplepos, sizeof(ps_samplepos), NULL, &ps);
31402 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31403 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31405 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
31406 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
31407 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
31408 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
31409 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31410 draw_quad(&test_context);
31411 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
31412 get_buffer_readback(buffer, &rb);
31413 for (i = 0; i < ARRAY_SIZE(standard_pos4); ++i)
31415 float data = get_readback_float(&rb, i, 0);
31416 /* Wine does not support GetSamplePosition. */
31417 todo_wine ok(data == standard_pos4[i], "Got sample position %.8e, expected %.8e.\n", data, standard_pos4[i]);
31419 release_resource_readback(&rb);
31421 ID3D11PixelShader_Release(ps);
31422 ID3D11Buffer_Release(buffer);
31423 ID3D11UnorderedAccessView_Release(uav);
31424 ID3D11ShaderResourceView_Release(srv);
31425 ID3D11Texture2D_Release(texture);
31426 release_test_context(&test_context);
31429 static void test_desktop_window(void)
31431 ID3D11RenderTargetView *backbuffer_rtv;
31432 DXGI_SWAP_CHAIN_DESC swapchain_desc;
31433 ID3D11DeviceContext *context;
31434 ID3D11Texture2D *backbuffer;
31435 IDXGISwapChain *swapchain;
31436 IDXGIDevice *dxgi_device;
31437 IDXGIAdapter *adapter;
31438 IDXGIFactory *factory;
31439 ID3D11Device *device;
31440 ULONG refcount;
31441 HRESULT hr;
31443 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
31445 if (!(device = create_device(NULL)))
31447 skip("Failed to create device.\n");
31448 return;
31451 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
31452 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
31453 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
31454 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
31455 IDXGIDevice_Release(dxgi_device);
31456 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
31457 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
31458 IDXGIAdapter_Release(adapter);
31460 swapchain_desc.BufferDesc.Width = 640;
31461 swapchain_desc.BufferDesc.Height = 480;
31462 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
31463 swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
31464 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31465 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
31466 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
31467 swapchain_desc.SampleDesc.Count = 1;
31468 swapchain_desc.SampleDesc.Quality = 0;
31469 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
31470 swapchain_desc.BufferCount = 1;
31471 swapchain_desc.OutputWindow = GetDesktopWindow();
31472 swapchain_desc.Windowed = TRUE;
31473 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
31474 swapchain_desc.Flags = 0;
31476 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
31477 ok(hr == S_OK || broken(hr == DXGI_ERROR_INVALID_CALL) /* Not available on all Windows versions. */,
31478 "Failed to create swapchain, hr %#x.\n", hr);
31479 IDXGIFactory_Release(factory);
31480 if (FAILED(hr))
31482 ID3D11Device_Release(device);
31483 return;
31486 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
31487 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
31489 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &backbuffer_rtv);
31490 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
31492 ID3D11Device_GetImmediateContext(device, &context);
31494 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
31495 check_texture_color(backbuffer, 0xff0000ff, 1);
31497 hr = IDXGISwapChain_Present(swapchain, 0, 0);
31498 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31500 ID3D11RenderTargetView_Release(backbuffer_rtv);
31501 ID3D11Texture2D_Release(backbuffer);
31502 IDXGISwapChain_Release(swapchain);
31503 ID3D11DeviceContext_Release(context);
31504 refcount = ID3D11Device_Release(device);
31505 ok(!refcount, "Device has %u references left.\n", refcount);
31508 static void test_sample_attached_rtv(void)
31510 ID3D11ShaderResourceView *srv, *srv2, *srv_test, *srv_ds;
31511 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc, srvds_desc;
31512 ID3D11Texture2D *texture, *texture2, *dstexture;
31513 ID3D11RenderTargetView *rtv, *rtv2, *rtvs[2];
31514 D3D11_DEPTH_STENCIL_VIEW_DESC dsview_desc;
31515 struct d3d11_test_context test_context;
31516 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
31517 D3D11_TEXTURE2D_DESC texture_desc;
31518 D3D_FEATURE_LEVEL feature_level;
31519 D3D11_SAMPLER_DESC sampler_desc;
31520 ID3D11DepthStencilView *dsview;
31521 ID3D11BlendState *blend_state;
31522 ID3D11DeviceContext *context;
31523 D3D11_BLEND_DESC blend_desc;
31524 ID3D11SamplerState *sampler;
31525 struct resource_readback rb;
31526 ID3D11PixelShader *ps;
31527 ID3D11Device *device;
31528 unsigned int x, y;
31529 unsigned int i;
31530 D3D11_BOX box;
31531 DWORD color;
31532 HRESULT hr;
31534 static const DWORD ps_ld_code[] =
31536 #if 0
31537 Texture2D t;
31539 struct PS_OUTPUT
31541 float4 color0: SV_Target0;
31542 float4 color1: SV_Target1;
31545 PS_OUTPUT main(float4 position : SV_POSITION)
31547 PS_OUTPUT output;
31548 float3 p;
31550 t.GetDimensions(0, p.x, p.y, p.z);
31551 p.z = 0;
31552 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
31553 output.color0 = output.color1 = t.Load(int3(p)) + float4(0.25, 0.25, 0.25, 0.25);
31554 return output;
31556 #endif
31557 0x43425844, 0x08dd0517, 0x07d7e538, 0x4cad261f, 0xa2ae5942, 0x00000001, 0x00000200, 0x00000003,
31558 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31559 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
31560 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
31561 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
31562 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000014c, 0x00000040, 0x00000053, 0x04001858,
31563 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
31564 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0700003d,
31565 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032,
31566 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000,
31567 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
31568 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0500001b,
31569 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46,
31570 0x00000000, 0x00107e46, 0x00000000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
31571 0x00004002, 0x3e800000, 0x3e800000, 0x3e800000, 0x3e800000, 0x05000036, 0x001020f2, 0x00000000,
31572 0x00100e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00100e46, 0x00000000, 0x0100003e,
31574 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
31575 static const struct
31577 DXGI_FORMAT texture_format, dsv_format, srv_format;
31578 UINT dsv_flags;
31579 BOOL srv_bind_allowed;
31581 ds_tests[] =
31583 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
31584 0, FALSE},
31585 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
31586 D3D11_DSV_READ_ONLY_DEPTH, TRUE},
31587 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_X24_TYPELESS_G8_UINT,
31588 D3D11_DSV_READ_ONLY_DEPTH, FALSE},
31589 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_X24_TYPELESS_G8_UINT,
31590 D3D11_DSV_READ_ONLY_STENCIL, TRUE},
31591 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT,
31592 0, FALSE},
31593 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT,
31594 D3D11_DSV_READ_ONLY_DEPTH, TRUE},
31597 if (!init_test_context(&test_context, NULL))
31598 return;
31600 device = test_context.device;
31601 context = test_context.immediate_context;
31603 feature_level = ID3D11Device_GetFeatureLevel(device);
31605 texture_desc.SampleDesc.Count = 1;
31606 texture_desc.SampleDesc.Quality = 0;
31607 texture_desc.Usage = D3D11_USAGE_DEFAULT;
31608 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
31609 texture_desc.CPUAccessFlags = 0;
31610 texture_desc.MiscFlags = 0;
31612 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
31613 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
31614 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
31615 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
31616 sampler_desc.MipLODBias = 0.0f;
31617 sampler_desc.MaxAnisotropy = 0;
31618 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
31619 sampler_desc.BorderColor[0] = 0.0f;
31620 sampler_desc.BorderColor[1] = 0.0f;
31621 sampler_desc.BorderColor[2] = 0.0f;
31622 sampler_desc.BorderColor[3] = 0.0f;
31623 sampler_desc.MinLOD = 0.0f;
31624 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
31626 hr = ID3D11Device_CreatePixelShader(device, ps_ld_code, sizeof(ps_ld_code), NULL, &ps);
31627 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31629 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31631 texture_desc.Width = 64;
31632 texture_desc.Height = 64;
31633 texture_desc.MipLevels = 2;
31634 texture_desc.ArraySize = 1;
31635 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31637 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31638 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31640 texture_desc.Width = 640;
31641 texture_desc.Height = 480;
31642 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture2);
31643 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31645 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
31646 sampler_desc.MipLODBias = 0.0f;
31647 sampler_desc.MinLOD = 0.0f;
31648 sampler_desc.MaxLOD = 0.0f;
31650 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
31651 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31653 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
31655 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
31657 memset(&rtv_desc, 0, sizeof(rtv_desc));
31658 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31659 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
31660 U(rtv_desc).Texture2D.MipSlice = 0;
31662 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv);
31663 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31664 U(rtv_desc).Texture2D.MipSlice = 1;
31665 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv2);
31666 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31668 rtvs[0] = test_context.backbuffer_rtv;
31669 rtvs[1] = rtv;
31671 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31673 memset(&srv_desc, 0, sizeof(srv_desc));
31674 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31675 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
31676 U(srv_desc).Texture2D.MipLevels = 1;
31678 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
31679 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31680 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31682 draw_quad(&test_context);
31684 set_box(&box, 0, 0, 0, 320, 240, 1);
31685 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2, 1, 0, 0, 0, (ID3D11Resource *)texture2, 0, &box);
31687 get_texture_readback(texture2, 0, &rb);
31688 for (y = 0; y < 4; ++y)
31690 for (x = 0; x < 4; ++x)
31692 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31693 ok(compare_color(color, 0x40404040, 2),
31694 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31697 release_resource_readback(&rb);
31698 get_texture_readback(texture2, 1, &rb);
31699 for (y = 0; y < 4; ++y)
31701 for (x = 0; x < 4; ++x)
31703 color = get_readback_color(&rb, 40 + x * 80, 30 + y * 60, 0);
31704 ok(compare_color(color, 0x40404040, 2),
31705 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31708 release_resource_readback(&rb);
31710 ID3D11ShaderResourceView_Release(srv);
31711 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31713 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
31715 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv);
31716 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31718 U(srv_desc).Texture2D.MostDetailedMip = 1;
31719 U(srv_desc).Texture2D.MipLevels = 1;
31720 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv2);
31721 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31723 memset(&blend_desc, 0, sizeof(blend_desc));
31724 blend_desc.IndependentBlendEnable = TRUE;
31725 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
31726 blend_desc.RenderTarget[1].RenderTargetWriteMask = 0;
31727 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
31728 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31729 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
31730 ID3D11BlendState_Release(blend_state);
31732 /* SRV does not get bound if resource is attached as render target, even if write mask is 0. */
31733 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31734 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31735 ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
31737 blend_desc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
31738 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
31739 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31740 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
31741 ID3D11BlendState_Release(blend_state);
31743 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
31745 draw_quad(&test_context);
31746 draw_quad(&test_context);
31748 get_texture_readback(test_context.backbuffer, 0, &rb);
31749 for (y = 0; y < 4; ++y)
31751 for (x = 0; x < 4; ++x)
31753 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31754 ok(compare_color(color, 0x40404040, 2),
31755 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31758 release_resource_readback(&rb);
31760 get_texture_readback(texture2, 0, &rb);
31761 for (y = 0; y < 4; ++y)
31763 for (x = 0; x < 4; ++x)
31765 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31766 ok(compare_color(color, 0x40404040, 2),
31767 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31770 release_resource_readback(&rb);
31772 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
31773 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
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 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31793 /* SRV is reset when the same resource is set as render target. */
31794 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31795 ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
31797 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
31798 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31799 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31800 ok(!!srv_test, "Unexpected SRV %p.\n", srv_test);
31801 ID3D11ShaderResourceView_Release(srv_test);
31803 draw_quad(&test_context);
31804 get_texture_readback(test_context.backbuffer, 0, &rb);
31805 for (y = 0; y < 4; ++y)
31807 for (x = 0; x < 4; ++x)
31809 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31810 ok(compare_color(color, 0x80808080, 2),
31811 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31814 release_resource_readback(&rb);
31816 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
31817 memset(&dsview_desc, 0, sizeof(dsview_desc));
31818 dsview_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
31820 memset(&srvds_desc, 0, sizeof(srvds_desc));
31821 srvds_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
31822 U(srvds_desc).Texture2D.MipLevels = 1;
31824 for (i = 0; i < ARRAY_SIZE(ds_tests); ++i)
31826 if (ds_tests[i].dsv_flags && feature_level < D3D_FEATURE_LEVEL_11_0)
31828 static unsigned int skip_once;
31830 if (!skip_once++)
31831 skip("Read only depths or stencils are not supported.\n");
31833 continue;
31836 texture_desc.Format = ds_tests[i].texture_format;
31837 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &dstexture);
31838 ok(hr == S_OK, "Test %u, got unexpected hr %#x.\n", i, hr);
31839 dsview_desc.Format = ds_tests[i].dsv_format;
31840 dsview_desc.Flags = ds_tests[i].dsv_flags;
31841 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)dstexture, &dsview_desc, &dsview);
31842 ok(hr == S_OK, "Test %u, got unexpected hr %#x.\n", i, hr);
31844 srvds_desc.Format = ds_tests[i].srv_format;
31845 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dstexture, &srvds_desc, &srv_ds);
31846 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31848 ID3D11DeviceContext_OMSetRenderTargets(context, 1, rtvs, NULL);
31849 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_ds);
31850 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31851 ok(!!srv_test, "Test %u, unexpected SRV %p.\n", i, srv_test);
31852 ID3D11ShaderResourceView_Release(srv_test);
31854 ID3D11DeviceContext_OMSetRenderTargets(context, 1, rtvs, dsview);
31855 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31856 ok(!!srv_test == ds_tests[i].srv_bind_allowed, "Test %u, unexpected SRV %p.\n", i, srv_test);
31857 if (srv_test)
31858 ID3D11ShaderResourceView_Release(srv_test);
31860 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_ds);
31861 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31862 ok(!!srv_test == ds_tests[i].srv_bind_allowed, "Test %u, unexpected SRV %p.\n", i, srv_test);
31863 if (srv_test)
31864 ID3D11ShaderResourceView_Release(srv_test);
31866 ID3D11Texture2D_Release(dstexture);
31867 ID3D11DepthStencilView_Release(dsview);
31868 ID3D11ShaderResourceView_Release(srv_ds);
31871 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31873 ID3D11RenderTargetView_Release(rtv2);
31874 ID3D11RenderTargetView_Release(rtv);
31875 ID3D11ShaderResourceView_Release(srv2);
31876 ID3D11ShaderResourceView_Release(srv);
31877 ID3D11SamplerState_Release(sampler);
31878 ID3D11PixelShader_Release(ps);
31879 ID3D11Texture2D_Release(texture2);
31880 ID3D11Texture2D_Release(texture);
31881 ID3D11SamplerState_Release(sampler);
31883 release_test_context(&test_context);
31886 static void test_color_mask(void)
31888 struct d3d11_test_context test_context;
31889 D3D11_TEXTURE2D_DESC texture_desc;
31890 ID3D11RenderTargetView *rtvs[8];
31891 ID3D11BlendState *blend_state;
31892 ID3D11DeviceContext *context;
31893 struct resource_readback rb;
31894 D3D11_BLEND_DESC blend_desc;
31895 ID3D11Texture2D *rts[8];
31896 ID3D11PixelShader *ps;
31897 ID3D11Device *device;
31898 unsigned int i;
31899 DWORD color;
31900 HRESULT hr;
31902 static const DWORD expected_colors[] =
31903 {0xff000080, 0xff0080ff, 0xff8000ff, 0x80808080, 0x800000ff, 0xff008080, 0x800080ff, 0xff0000ff};
31905 static const DWORD ps_code[] =
31907 #if 0
31908 void main(float4 position : SV_Position,
31909 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
31910 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
31911 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
31912 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
31914 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.5f, 0.5f, 0.5f, 0.5f);
31916 #endif
31917 0x43425844, 0x7b1ab233, 0xdbe32d3b, 0x77084cc5, 0xe874d2b5, 0x00000001, 0x000002b0, 0x00000003,
31918 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31919 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
31920 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
31921 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
31922 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
31923 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
31924 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
31925 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
31926 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
31927 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
31928 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
31929 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
31930 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000,
31931 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000,
31932 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3f000000,
31933 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3f000000,
31934 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3f000000,
31935 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3f000000,
31936 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3f000000,
31937 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3f000000,
31938 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
31941 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
31943 if (!init_test_context(&test_context, NULL))
31944 return;
31946 device = test_context.device;
31947 context = test_context.immediate_context;
31949 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31950 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31951 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31953 memset(&blend_desc, 0, sizeof(blend_desc));
31954 blend_desc.IndependentBlendEnable = TRUE;
31955 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED;
31956 blend_desc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN;
31957 blend_desc.RenderTarget[2].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_BLUE;
31958 blend_desc.RenderTarget[3].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
31959 blend_desc.RenderTarget[4].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALPHA;
31960 blend_desc.RenderTarget[5].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED | D3D11_COLOR_WRITE_ENABLE_GREEN;
31961 blend_desc.RenderTarget[6].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN | D3D11_COLOR_WRITE_ENABLE_ALPHA;
31962 blend_desc.RenderTarget[7].RenderTargetWriteMask = 0;
31964 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
31965 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
31966 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
31967 ID3D11BlendState_Release(blend_state);
31969 for (i = 0; i < 8; ++i)
31971 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31972 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
31973 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
31975 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
31976 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
31979 ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
31981 for (i = 0; i < 8; ++i)
31982 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], red);
31983 draw_quad(&test_context);
31985 for (i = 0; i < 8; ++i)
31987 get_texture_readback(rts[i], 0, &rb);
31988 color = get_readback_color(&rb, 320, 240, 0);
31989 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
31990 release_resource_readback(&rb);
31993 blend_desc.IndependentBlendEnable = FALSE;
31994 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
31995 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
31996 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
31997 ID3D11BlendState_Release(blend_state);
31999 for (i = 0; i < 8; ++i)
32000 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], red);
32001 draw_quad(&test_context);
32003 for (i = 0; i < 8; ++i)
32005 get_texture_readback(rts[i], 0, &rb);
32006 color = get_readback_color(&rb, 320, 240, 0);
32007 ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32008 release_resource_readback(&rb);
32010 ID3D11Texture2D_Release(rts[i]);
32011 ID3D11RenderTargetView_Release(rtvs[i]);
32014 ID3D11PixelShader_Release(ps);
32015 release_test_context(&test_context);
32018 static void test_independent_blend(void)
32020 struct d3d11_test_context test_context;
32021 D3D11_TEXTURE2D_DESC texture_desc;
32022 ID3D11RenderTargetView *rtvs[8];
32023 ID3D11BlendState *blend_state;
32024 ID3D11DeviceContext *context;
32025 struct resource_readback rb;
32026 ID3D11Texture2D *rts[8];
32027 ID3D11PixelShader *ps;
32028 ID3D11Device *device;
32029 unsigned int i;
32030 DWORD color;
32031 HRESULT hr;
32033 static const DWORD ps_code[] =
32035 #if 0
32036 void main(float4 position : SV_Position,
32037 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
32038 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
32039 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
32040 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
32042 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.1f, 0.2f, 0.3f, 0.4f);
32044 #endif
32045 0x43425844, 0xb3dca7dc, 0x4a31f0f1, 0x747569cb, 0xae7af5ce, 0x00000001, 0x000002b0, 0x00000003,
32046 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
32047 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
32048 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
32049 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
32050 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
32051 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
32052 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
32053 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
32054 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
32055 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
32056 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
32057 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
32058 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3dcccccd,
32059 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3dcccccd,
32060 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3dcccccd,
32061 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3dcccccd,
32062 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3dcccccd,
32063 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3dcccccd,
32064 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3dcccccd,
32065 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3dcccccd,
32066 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x0100003e,
32069 D3D11_BLEND_DESC blend_desc =
32071 .IndependentBlendEnable = TRUE,
32072 .RenderTarget =
32074 {TRUE, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD,
32075 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32076 {TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
32077 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32078 {TRUE, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_OP_ADD,
32079 D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32080 {TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
32081 D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN, D3D11_COLOR_WRITE_ENABLE_ALL},
32082 {TRUE, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_OP_ADD,
32083 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32084 {TRUE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_BLEND_FACTOR, D3D11_BLEND_OP_SUBTRACT,
32085 D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_REV_SUBTRACT, D3D11_COLOR_WRITE_ENABLE_ALL},
32086 {FALSE, 0, 0, 0, 0, 0, 0, D3D11_COLOR_WRITE_ENABLE_ALL},
32087 {TRUE, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_OP_ADD,
32088 D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_DEST_ALPHA, D3D11_BLEND_OP_SUBTRACT,
32089 D3D11_COLOR_WRITE_ENABLE_ALL},
32093 static const DWORD expected_colors[] =
32094 {0x66426e1c, 0xb34c3319, 0xa6214a05, 0x66333319, 0xb34c4829, 0x4d19000a, 0x664c3319, 0x081f3305};
32096 static const float clear_color[] = {0.1f, 0.5f, 0.2f, 0.7f};
32097 static const float blend_factor[] = {0.8f, 0.4f, 0.6f, 0.2f};
32099 if (!init_test_context(&test_context, NULL))
32100 return;
32102 device = test_context.device;
32103 context = test_context.immediate_context;
32105 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
32106 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
32107 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32109 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32110 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32111 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
32112 ID3D11BlendState_Release(blend_state);
32114 for (i = 0; i < 8; ++i)
32116 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32117 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
32118 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
32120 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
32121 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
32124 ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
32126 for (i = 0; i < 8; ++i)
32127 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
32128 draw_quad(&test_context);
32130 for (i = 0; i < 8; ++i)
32132 get_texture_readback(rts[i], 0, &rb);
32133 color = get_readback_color(&rb, 320, 240, 0);
32134 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32135 release_resource_readback(&rb);
32138 blend_desc.IndependentBlendEnable = FALSE;
32139 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32140 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32141 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
32142 ID3D11BlendState_Release(blend_state);
32144 for (i = 0; i < 8; ++i)
32145 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
32146 draw_quad(&test_context);
32148 for (i = 0; i < 8; ++i)
32150 get_texture_readback(rts[i], 0, &rb);
32151 color = get_readback_color(&rb, 320, 240, 0);
32152 ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32153 release_resource_readback(&rb);
32155 ID3D11Texture2D_Release(rts[i]);
32156 ID3D11RenderTargetView_Release(rtvs[i]);
32159 ID3D11PixelShader_Release(ps);
32160 release_test_context(&test_context);
32163 static void test_dual_source_blend(void)
32165 struct d3d11_test_context test_context;
32166 ID3D11BlendState *blend_state;
32167 ID3D11DeviceContext *context;
32168 ID3D11PixelShader *ps;
32169 ID3D11Device *device;
32170 DWORD color;
32171 HRESULT hr;
32173 static const DWORD ps_code[] =
32175 #if 0
32176 void main(float4 position : SV_Position,
32177 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1)
32179 t0 = float4(0.5, 0.5, 0.0, 1.0);
32180 t1 = float4(0.0, 0.5, 0.5, 0.0);
32182 #endif
32183 0x43425844, 0x87120d01, 0xa0014738, 0x3a32d86c, 0x9d757441, 0x00000001, 0x00000118, 0x00000003,
32184 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
32185 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
32186 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
32187 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
32188 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03000065,
32189 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x08000036, 0x001020f2, 0x00000000,
32190 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001,
32191 0x00004002, 0x00000000, 0x3f000000, 0x3f000000, 0x00000000, 0x0100003e
32194 static const D3D11_BLEND_DESC blend_desc =
32196 .RenderTarget[0].BlendEnable = TRUE,
32197 .RenderTarget[0].SrcBlend = D3D11_BLEND_SRC1_COLOR,
32198 .RenderTarget[0].DestBlend = D3D11_BLEND_SRC1_COLOR,
32199 .RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD,
32200 .RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE,
32201 .RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO,
32202 .RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD,
32203 .RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL,
32206 static const float clear_color[] = {0.7f, 0.0f, 1.0f, 1.0f};
32208 if (!init_test_context(&test_context, NULL))
32209 return;
32211 device = test_context.device;
32212 context = test_context.immediate_context;
32214 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
32215 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
32216 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32218 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32219 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32220 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32221 ID3D11BlendState_Release(blend_state);
32223 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, clear_color);
32224 draw_quad(&test_context);
32226 color = get_texture_color(test_context.backbuffer, 320, 240);
32227 ok(compare_color(color, 0x80804000, 1), "Got unexpected color 0x%08x.\n", color);
32229 ID3D11PixelShader_Release(ps);
32230 release_test_context(&test_context);
32233 static void test_deferred_context_state(void)
32235 ID3D11Buffer *green_buffer, *blue_buffer, *ret_buffer;
32236 ID3D11DeviceContext *immediate, *deferred;
32237 ID3D11ShaderResourceView *srv, *ret_srv;
32238 struct d3d11_test_context test_context;
32239 ID3D11RenderTargetView *rtv, *ret_rtv;
32240 D3D11_TEXTURE2D_DESC texture_desc;
32241 ID3D11CommandList *list1, *list2;
32242 ID3D11Texture2D *texture;
32243 ID3D11Device *device;
32244 HRESULT hr;
32246 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32247 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
32249 if (!init_test_context(&test_context, NULL))
32250 return;
32252 device = test_context.device;
32253 immediate = test_context.immediate_context;
32255 green_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(green), &green);
32256 blue_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(blue), &blue);
32257 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32259 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32260 todo_wine ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32261 if (hr != S_OK)
32263 ID3D11Buffer_Release(blue_buffer);
32264 ID3D11Buffer_Release(green_buffer);
32265 release_test_context(&test_context);
32266 return;
32269 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32270 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32272 ID3D11DeviceContext_PSSetConstantBuffers(deferred, 0, 1, &blue_buffer);
32274 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32275 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32276 ID3D11Buffer_Release(ret_buffer);
32278 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32279 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32281 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32282 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32283 ID3D11Buffer_Release(ret_buffer);
32285 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list2);
32286 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32288 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32289 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32291 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32292 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32293 ID3D11DeviceContext_PSGetConstantBuffers(immediate, 0, 1, &ret_buffer);
32294 ok(ret_buffer == green_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32295 ID3D11Buffer_Release(ret_buffer);
32297 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32298 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
32299 ID3D11DeviceContext_PSGetConstantBuffers(immediate, 0, 1, &ret_buffer);
32300 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32302 /* Test unbinding an SRV when using the same resource as RTV. */
32304 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32305 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
32306 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
32307 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
32308 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
32309 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32310 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
32311 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32313 ID3D11DeviceContext_PSSetShaderResources(deferred, 0, 1, &srv);
32314 ID3D11DeviceContext_PSGetShaderResources(deferred, 0, 1, &ret_srv);
32315 ok(ret_srv == srv, "Got unexpected SRV %p.\n", ret_srv);
32316 ID3D11ShaderResourceView_Release(ret_srv);
32318 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &rtv, NULL);
32319 ID3D11DeviceContext_OMGetRenderTargets(deferred, 1, &ret_rtv, NULL);
32320 ok(ret_rtv == rtv, "Got unexpected RTV %p.\n", ret_rtv);
32321 ID3D11RenderTargetView_Release(ret_rtv);
32322 ID3D11DeviceContext_PSGetShaderResources(deferred, 0, 1, &ret_srv);
32323 ok(!ret_srv, "Got unexpected SRV %p.\n", ret_srv);
32325 ID3D11ShaderResourceView_Release(srv);
32326 ID3D11RenderTargetView_Release(rtv);
32327 ID3D11Texture2D_Release(texture);
32328 ID3D11CommandList_Release(list2);
32329 ID3D11CommandList_Release(list1);
32330 ID3D11DeviceContext_Release(deferred);
32331 ID3D11Buffer_Release(blue_buffer);
32332 ID3D11Buffer_Release(green_buffer);
32333 release_test_context(&test_context);
32336 static void test_deferred_context_swap_state(void)
32338 ID3D11DeviceContext1 *immediate, *deferred;
32339 ID3DDeviceContextState *state, *prev_state;
32340 ID3D11Buffer *green_buffer, *ret_buffer;
32341 struct d3d11_test_context test_context;
32342 D3D_FEATURE_LEVEL feature_level;
32343 ID3D11Device1 *device;
32344 HRESULT hr;
32346 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32348 if (!init_test_context(&test_context, NULL))
32349 return;
32351 if (FAILED(ID3D11Device_QueryInterface(test_context.device, &IID_ID3D11Device1, (void **)&device)))
32353 skip("ID3D11Device1 is not available.\n");
32354 release_test_context(&test_context);
32355 return;
32358 ID3D11Device1_GetImmediateContext1(device, &immediate);
32360 green_buffer = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(green), &green);
32361 ID3D11DeviceContext1_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32363 hr = ID3D11Device1_CreateDeferredContext1(device, 0, &deferred);
32364 todo_wine ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32365 if (hr != S_OK)
32366 goto out;
32368 feature_level = ID3D11Device1_GetFeatureLevel(device);
32369 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
32370 &IID_ID3D11Device1, NULL, &state);
32371 ok(hr == S_OK, "Failed to create device context state, hr %#x.\n", hr);
32373 prev_state = (void *)0xdeadbeef;
32374 ID3D11DeviceContext1_SwapDeviceContextState(deferred, NULL, &prev_state);
32375 ok(!prev_state, "Got state %p.\n", prev_state);
32377 prev_state = (void *)0xdeadbeef;
32378 ID3D11DeviceContext1_SwapDeviceContextState(deferred, state, &prev_state);
32379 ok(!prev_state, "Got state %p.\n", prev_state);
32381 ID3D11DeviceContext1_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32382 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32384 ID3DDeviceContextState_Release(state);
32385 ID3D11DeviceContext1_Release(deferred);
32387 out:
32388 ID3D11Buffer_Release(green_buffer);
32389 ID3D11DeviceContext1_Release(immediate);
32390 ID3D11Device1_Release(device);
32391 release_test_context(&test_context);
32394 static void test_deferred_context_rendering(void)
32396 ID3D11DeviceContext *immediate, *deferred;
32397 struct d3d11_test_context test_context;
32398 D3D11_TEXTURE2D_DESC texture_desc;
32399 ID3D11CommandList *list1, *list2;
32400 ID3D11RenderTargetView *rtv;
32401 ID3D11Texture2D *texture;
32402 ID3D11Device *device;
32403 DWORD color;
32404 HRESULT hr;
32406 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
32407 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32408 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
32410 if (!init_test_context(&test_context, NULL))
32411 return;
32413 device = test_context.device;
32414 immediate = test_context.immediate_context;
32416 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
32418 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32419 todo_wine ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32420 if (hr != S_OK)
32422 release_test_context(&test_context);
32423 return;
32426 ID3D11DeviceContext_ClearRenderTargetView(deferred, test_context.backbuffer_rtv, green);
32428 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32429 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32431 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32432 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32434 color = get_texture_color(test_context.backbuffer, 320, 240);
32435 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32437 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32438 color = get_texture_color(test_context.backbuffer, 320, 240);
32439 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32441 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
32442 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32443 color = get_texture_color(test_context.backbuffer, 320, 240);
32444 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32446 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
32447 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, TRUE);
32448 color = get_texture_color(test_context.backbuffer, 320, 240);
32449 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32451 ID3D11CommandList_Release(list2);
32453 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, TRUE);
32454 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32455 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32457 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
32458 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, TRUE);
32459 color = get_texture_color(test_context.backbuffer, 320, 240);
32460 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32462 ID3D11CommandList_Release(list2);
32463 ID3D11CommandList_Release(list1);
32464 ID3D11DeviceContext_Release(deferred);
32466 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32467 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
32468 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
32469 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
32470 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32472 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, white);
32473 ID3D11DeviceContext_ClearRenderTargetView(immediate, rtv, green);
32475 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32476 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32478 ID3D11DeviceContext_CopyResource(deferred, (ID3D11Resource *)test_context.backbuffer, (ID3D11Resource *)texture);
32480 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32481 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32483 ID3D11DeviceContext_ClearRenderTargetView(immediate, rtv, blue);
32484 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32485 color = get_texture_color(test_context.backbuffer, 320, 240);
32486 ok(color == 0xffff0000, "Got unexpected color %#08x.\n", color);
32488 ID3D11CommandList_Release(list1);
32489 ID3D11DeviceContext_Release(deferred);
32491 ID3D11RenderTargetView_Release(rtv);
32492 ID3D11Texture2D_Release(texture);
32493 release_test_context(&test_context);
32496 START_TEST(d3d11)
32498 unsigned int argc, i;
32499 char **argv;
32501 use_mt = !getenv("WINETEST_NO_MT_D3D");
32503 argc = winetest_get_mainargs(&argv);
32504 for (i = 2; i < argc; ++i)
32506 if (!strcmp(argv[i], "--validate"))
32507 enable_debug_layer = TRUE;
32508 else if (!strcmp(argv[i], "--warp"))
32509 use_warp_adapter = TRUE;
32510 else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
32511 use_adapter_idx = atoi(argv[++i]);
32512 else if (!strcmp(argv[i], "--single"))
32513 use_mt = FALSE;
32516 print_adapter_info();
32518 queue_test(test_create_device);
32519 queue_for_each_feature_level(test_device_interfaces);
32520 queue_test(test_immediate_context);
32521 queue_test(test_create_deferred_context);
32522 queue_test(test_create_texture1d);
32523 queue_test(test_texture1d_interfaces);
32524 queue_test(test_create_texture2d);
32525 queue_test(test_texture2d_interfaces);
32526 queue_test(test_create_texture3d);
32527 queue_test(test_texture3d_interfaces);
32528 queue_test(test_create_buffer);
32529 queue_test(test_create_depthstencil_view);
32530 queue_test(test_depthstencil_view_interfaces);
32531 queue_test(test_create_rendertarget_view);
32532 queue_test(test_create_shader_resource_view);
32533 queue_for_each_feature_level(test_create_shader);
32534 queue_test(test_create_sampler_state);
32535 queue_test(test_create_blend_state);
32536 queue_test(test_create_depthstencil_state);
32537 queue_test(test_create_rasterizer_state);
32538 queue_test(test_create_query);
32539 queue_test(test_occlusion_query);
32540 queue_test(test_pipeline_statistics_query);
32541 queue_test(test_timestamp_query);
32542 queue_test(test_so_statistics_query);
32543 queue_test(test_device_removed_reason);
32544 queue_test(test_private_data);
32545 queue_for_each_feature_level(test_state_refcounting);
32546 queue_test(test_device_context_state);
32547 queue_test(test_blend);
32548 queue_test(test_texture1d);
32549 queue_test(test_texture);
32550 queue_test(test_cube_maps);
32551 queue_test(test_depth_stencil_sampling);
32552 queue_test(test_sample_c_lz);
32553 queue_test(test_multiple_render_targets);
32554 queue_test(test_render_target_views);
32555 queue_test(test_layered_rendering);
32556 queue_test(test_scissor);
32557 queue_test(test_clear_state);
32558 queue_test(test_il_append_aligned);
32559 queue_test(test_instanced_draw);
32560 queue_test(test_vertex_id);
32561 queue_test(test_fragment_coords);
32562 queue_test(test_initial_texture_data);
32563 queue_test(test_update_subresource);
32564 queue_test(test_copy_subresource_region);
32565 queue_test(test_copy_subresource_region_1d);
32566 queue_test(test_copy_subresource_region_3d);
32567 queue_test(test_resource_map);
32568 queue_for_each_feature_level(test_resource_access);
32569 queue_test(test_check_multisample_quality_levels);
32570 queue_for_each_feature_level(test_swapchain_formats);
32571 queue_test(test_swapchain_views);
32572 queue_test(test_swapchain_flip);
32573 queue_test(test_clear_render_target_view_1d);
32574 queue_test(test_clear_render_target_view_2d);
32575 queue_test(test_clear_render_target_view_3d);
32576 queue_test(test_clear_depth_stencil_view);
32577 queue_test(test_clear_buffer_unordered_access_view);
32578 queue_test(test_initial_depth_stencil_state);
32579 queue_test(test_draw_depth_only);
32580 queue_test(test_draw_uav_only);
32581 queue_test(test_cb_relative_addressing);
32582 queue_test(test_vs_input_relative_addressing);
32583 queue_test(test_getdc);
32584 queue_test(test_shader_stage_input_output_matching);
32585 queue_test(test_shader_interstage_interface);
32586 queue_test(test_sm4_if_instruction);
32587 queue_test(test_sm4_breakc_instruction);
32588 queue_test(test_sm4_continuec_instruction);
32589 queue_test(test_sm4_discard_instruction);
32590 queue_test(test_sm5_swapc_instruction);
32591 queue_test(test_create_input_layout);
32592 queue_test(test_input_layout_alignment);
32593 queue_test(test_input_assembler);
32594 queue_test(test_null_sampler);
32595 queue_test(test_check_feature_support);
32596 queue_test(test_create_unordered_access_view);
32597 queue_test(test_immediate_constant_buffer);
32598 queue_test(test_fp_specials);
32599 queue_test(test_uint_shader_instructions);
32600 queue_test(test_index_buffer_offset);
32601 queue_test(test_face_culling);
32602 queue_test(test_line_antialiasing_blending);
32603 queue_for_each_feature_level(test_format_support);
32604 queue_for_each_9_x_feature_level(test_fl9_draw);
32605 queue_test(test_ddy);
32606 queue_test(test_shader_input_registers_limits);
32607 queue_test(test_unbind_shader_resource_view);
32608 queue_test(test_stencil_separate);
32609 queue_test(test_uav_load);
32610 queue_test(test_cs_uav_store);
32611 queue_test(test_uav_store_immediate_constant);
32612 queue_test(test_ps_cs_uav_binding);
32613 queue_test(test_atomic_instructions);
32614 queue_test(test_sm4_ret_instruction);
32615 queue_test(test_primitive_restart);
32616 queue_test(test_resinfo_instruction);
32617 queue_test(test_sm5_bufinfo_instruction);
32618 queue_test(test_sampleinfo_instruction);
32619 queue_test(test_render_target_device_mismatch);
32620 queue_test(test_buffer_srv);
32621 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
32622 test_unaligned_raw_buffer_access);
32623 queue_test(test_uav_counters);
32624 queue_test(test_dispatch_indirect);
32625 queue_test(test_compute_shader_registers);
32626 queue_test(test_tgsm);
32627 queue_test(test_geometry_shader);
32628 queue_test(test_quad_tessellation);
32629 queue_test(test_stream_output);
32630 queue_test(test_fl10_stream_output_desc);
32631 queue_test(test_stream_output_resume);
32632 queue_test(test_stream_output_components);
32633 queue_test(test_stream_output_vs);
32634 queue_test(test_gather);
32635 queue_test(test_gather_c);
32636 queue_test(test_depth_bias);
32637 queue_test(test_fractional_viewports);
32638 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0, test_negative_viewports);
32639 queue_test(test_early_depth_stencil);
32640 queue_test(test_conservative_depth_output);
32641 queue_test(test_format_compatibility);
32642 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
32643 test_compressed_format_compatibility);
32644 queue_test(test_clip_distance);
32645 queue_test(test_combined_clip_and_cull_distances);
32646 queue_test(test_generate_mips);
32647 queue_test(test_alpha_to_coverage);
32648 queue_test(test_unbound_multisample_texture);
32649 queue_test(test_multiple_viewports);
32650 queue_test(test_multisample_resolve);
32651 queue_test(test_sample_shading);
32652 queue_test(test_sample_mask);
32653 queue_test(test_depth_clip);
32654 queue_test(test_staging_buffers);
32655 queue_test(test_render_a8);
32656 queue_test(test_standard_pattern);
32657 queue_test(test_desktop_window);
32658 queue_test(test_sample_attached_rtv);
32659 queue_test(test_color_mask);
32660 queue_test(test_independent_blend);
32661 queue_test(test_dual_source_blend);
32662 queue_test(test_deferred_context_state);
32663 queue_test(test_deferred_context_swap_state);
32664 queue_test(test_deferred_context_rendering);
32665 queue_test(test_unbound_streams);
32667 run_queued_tests();