d3d11: Forbid map types other than DISCARD and NOOVERWRITE on a deferred context.
[wine.git] / dlls / d3d11 / tests / d3d11.c
blob6d5141ea90d9bdf2d45ea776a4132be8bc9eb595
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
3 * Copyright 2015 Józef Kucia for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <assert.h>
21 #include <float.h>
22 #include <limits.h>
23 #include <math.h>
24 #include <stdlib.h>
25 #define COBJMACROS
26 #include "initguid.h"
27 #include "d3d11_4.h"
28 #include "wine/heap.h"
29 #include "wine/test.h"
31 #define BITS_NNAN 0xffc00000
32 #define BITS_NAN 0x7fc00000
33 #define BITS_NINF 0xff800000
34 #define BITS_INF 0x7f800000
35 #define BITS_N1_0 0xbf800000
36 #define BITS_1_0 0x3f800000
38 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
40 static unsigned int use_adapter_idx;
41 static BOOL enable_debug_layer;
42 static BOOL use_warp_adapter;
43 static BOOL use_mt = TRUE;
45 static struct test_entry
47 union
49 void (*test)(void);
50 void (*test_fl)(D3D_FEATURE_LEVEL fl);
51 } u;
52 D3D_FEATURE_LEVEL fl;
53 } *mt_tests;
54 size_t mt_tests_size, mt_test_count;
56 struct format_support
58 DXGI_FORMAT format;
59 D3D_FEATURE_LEVEL fl_required;
60 D3D_FEATURE_LEVEL fl_optional;
63 static const struct format_support display_format_support[] =
65 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
66 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
67 {DXGI_FORMAT_B8G8R8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
68 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
69 {DXGI_FORMAT_R16G16B16A16_FLOAT, D3D_FEATURE_LEVEL_10_0},
70 {DXGI_FORMAT_R10G10B10A2_UNORM, D3D_FEATURE_LEVEL_10_0},
71 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0},
74 struct vec2
76 float x, y;
79 struct vec3
81 float x, y, z;
84 struct vec4
86 float x, y, z, w;
89 struct ivec4
91 int x, y, z, w;
94 struct uvec4
96 unsigned int x, y, z, w;
99 struct device_desc
101 const D3D_FEATURE_LEVEL *feature_level;
102 UINT flags;
105 struct resource_desc
107 D3D11_RESOURCE_DIMENSION dimension;
108 unsigned int width;
109 unsigned int height;
110 unsigned int depth_or_array_size;
111 unsigned int level_count;
112 DXGI_FORMAT format;
113 DXGI_SAMPLE_DESC sample_desc;
114 D3D11_USAGE usage;
115 unsigned int bind_flags;
116 unsigned int cpu_access_flags;
117 unsigned int misc_flags;
118 unsigned int structure_byte_stride;
121 struct swapchain_desc
123 BOOL windowed;
124 unsigned buffer_count;
125 unsigned int width, height;
126 DXGI_SWAP_EFFECT swap_effect;
127 DWORD flags;
130 static void queue_test_entry(const struct test_entry *t)
132 if (mt_test_count >= mt_tests_size)
134 mt_tests_size = max(16, mt_tests_size * 2);
135 mt_tests = heap_realloc(mt_tests, mt_tests_size * sizeof(*t));
137 mt_tests[mt_test_count++] = *t;
140 static void queue_test_fl(void (*test)(const D3D_FEATURE_LEVEL fl), D3D_FEATURE_LEVEL fl)
142 struct test_entry t;
144 t.u.test_fl = test;
145 t.fl = fl;
146 queue_test_entry(&t);
149 static void queue_test(void (*test)(void))
151 struct test_entry t;
153 t.u.test = test;
154 t.fl = 0;
155 queue_test_entry(&t);
158 static void run_mt_test(const struct test_entry *t)
160 if (t->fl)
161 t->u.test_fl(t->fl);
162 else
163 t->u.test();
166 static DWORD WINAPI thread_func(void *ctx)
168 LONG *i = ctx, j;
170 while (*i < mt_test_count)
172 j = *i;
173 if (InterlockedCompareExchange(i, j + 1, j) == j)
174 run_mt_test(&mt_tests[j]);
177 return 0;
180 static void run_queued_tests(void)
182 unsigned int thread_count, i;
183 HANDLE *threads;
184 SYSTEM_INFO si;
185 LONG test_idx;
187 if (!use_mt)
189 for (i = 0; i < mt_test_count; ++i)
191 run_mt_test(&mt_tests[i]);
194 return;
197 GetSystemInfo(&si);
198 thread_count = si.dwNumberOfProcessors;
199 threads = heap_calloc(thread_count, sizeof(*threads));
200 for (i = 0, test_idx = 0; i < thread_count; ++i)
202 threads[i] = CreateThread(NULL, 0, thread_func, &test_idx, 0, NULL);
203 ok(!!threads[i], "Failed to create thread %u.\n", i);
205 WaitForMultipleObjects(thread_count, threads, TRUE, INFINITE);
206 for (i = 0; i < thread_count; ++i)
208 CloseHandle(threads[i]);
210 heap_free(threads);
213 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
215 box->left = left;
216 box->top = top;
217 box->front = front;
218 box->right = right;
219 box->bottom = bottom;
220 box->back = back;
223 static ULONG get_refcount(void *iface)
225 IUnknown *unknown = iface;
226 IUnknown_AddRef(unknown);
227 return IUnknown_Release(unknown);
230 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
231 static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOOL supported, BOOL is_broken)
233 HRESULT hr, expected_hr, broken_hr;
234 IUnknown *unknown = iface, *out;
236 if (supported)
238 expected_hr = S_OK;
239 broken_hr = E_NOINTERFACE;
241 else
243 expected_hr = E_NOINTERFACE;
244 broken_hr = S_OK;
247 hr = IUnknown_QueryInterface(unknown, riid, (void **)&out);
248 ok_(__FILE__, line)(hr == expected_hr || broken(is_broken && hr == broken_hr),
249 "Got hr %#x, expected %#x.\n", hr, expected_hr);
250 if (SUCCEEDED(hr))
251 IUnknown_Release(out);
252 return hr;
255 static BOOL compare_float(float f, float g, unsigned int ulps)
257 int x = *(int *)&f;
258 int y = *(int *)&g;
260 if (x < 0)
261 x = INT_MIN - x;
262 if (y < 0)
263 y = INT_MIN - y;
265 if (abs(x - y) > ulps)
266 return FALSE;
268 return TRUE;
271 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
273 return compare_float(v1->x, v2->x, ulps)
274 && compare_float(v1->y, v2->y, ulps)
275 && compare_float(v1->z, v2->z, ulps)
276 && compare_float(v1->w, v2->w, ulps);
279 static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
281 unsigned int diff = x > y ? x - y : y - x;
283 return diff <= max_diff;
286 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
288 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
291 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
293 return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
294 && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
295 && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
296 && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
299 static char const *debugstr_viewport(D3D11_VIEWPORT *vp)
301 if (!vp) return "(null)";
302 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}",
303 vp->TopLeftX, vp->TopLeftY, vp->Width, vp->Height, vp->MinDepth, vp->MaxDepth);
306 struct srv_desc
308 DXGI_FORMAT format;
309 D3D11_SRV_DIMENSION dimension;
310 unsigned int miplevel_idx;
311 unsigned int miplevel_count;
312 unsigned int layer_idx;
313 unsigned int layer_count;
316 static void get_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *d3d11_desc, const struct srv_desc *desc)
318 d3d11_desc->Format = desc->format;
319 d3d11_desc->ViewDimension = desc->dimension;
320 if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1D)
322 U(*d3d11_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
323 U(*d3d11_desc).Texture1D.MipLevels = desc->miplevel_count;
325 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
327 U(*d3d11_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
328 U(*d3d11_desc).Texture1DArray.MipLevels = desc->miplevel_count;
329 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
330 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
332 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
334 U(*d3d11_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
335 U(*d3d11_desc).Texture2D.MipLevels = desc->miplevel_count;
337 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
339 U(*d3d11_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
340 U(*d3d11_desc).Texture2DArray.MipLevels = desc->miplevel_count;
341 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
342 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
344 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
346 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
347 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
349 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE3D)
351 U(*d3d11_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
352 U(*d3d11_desc).Texture3D.MipLevels = desc->miplevel_count;
354 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
356 U(*d3d11_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
357 U(*d3d11_desc).TextureCube.MipLevels = desc->miplevel_count;
359 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
361 U(*d3d11_desc).TextureCubeArray.MostDetailedMip = desc->miplevel_idx;
362 U(*d3d11_desc).TextureCubeArray.MipLevels = desc->miplevel_count;
363 U(*d3d11_desc).TextureCubeArray.First2DArrayFace = desc->layer_idx;
364 U(*d3d11_desc).TextureCubeArray.NumCubes = desc->layer_count;
366 else if (desc->dimension != D3D11_SRV_DIMENSION_UNKNOWN
367 && desc->dimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
369 trace("Unhandled view dimension %#x.\n", desc->dimension);
373 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
374 static void check_srv_desc_(unsigned int line, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
375 const struct srv_desc *expected_desc)
377 ok_(__FILE__, line)(desc->Format == expected_desc->format,
378 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
379 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
380 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
382 if (desc->ViewDimension != expected_desc->dimension)
383 return;
385 if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D)
387 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
388 "Got MostDetailedMip %u, expected %u.\n",
389 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
390 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
391 "Got MipLevels %u, expected %u.\n",
392 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
394 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
396 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
397 "Got MostDetailedMip %u, expected %u.\n",
398 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
399 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
400 "Got MipLevels %u, expected %u.\n",
401 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
402 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
403 "Got FirstArraySlice %u, expected %u.\n",
404 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
405 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
406 "Got ArraySize %u, expected %u.\n",
407 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
409 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
411 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
412 "Got FirstArraySlice %u, expected %u.\n",
413 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
414 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
415 "Got ArraySize %u, expected %u.\n",
416 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
418 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
420 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
421 "Got MostDetailedMip %u, expected %u.\n",
422 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
423 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
424 "Got MipLevels %u, expected %u.\n",
425 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
427 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
429 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
430 "Got MostDetailedMip %u, expected %u.\n",
431 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
432 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
433 "Got MipLevels %u, expected %u.\n",
434 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
436 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
438 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MostDetailedMip == expected_desc->miplevel_idx,
439 "Got MostDetailedMip %u, expected %u.\n",
440 U(*desc).TextureCubeArray.MostDetailedMip, expected_desc->miplevel_idx);
441 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MipLevels == expected_desc->miplevel_count,
442 "Got MipLevels %u, expected %u.\n",
443 U(*desc).TextureCubeArray.MipLevels, expected_desc->miplevel_count);
444 ok_(__FILE__, line)(U(*desc).TextureCubeArray.First2DArrayFace == expected_desc->layer_idx,
445 "Got First2DArrayFace %u, expected %u.\n",
446 U(*desc).TextureCubeArray.First2DArrayFace, expected_desc->layer_idx);
447 ok_(__FILE__, line)(U(*desc).TextureCubeArray.NumCubes == expected_desc->layer_count,
448 "Got NumCubes %u, expected %u.\n",
449 U(*desc).TextureCubeArray.NumCubes, expected_desc->layer_count);
451 else if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
453 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
457 struct rtv_desc
459 DXGI_FORMAT format;
460 D3D11_RTV_DIMENSION dimension;
461 unsigned int miplevel_idx;
462 unsigned int layer_idx;
463 unsigned int layer_count;
466 static void get_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *d3d11_desc, const struct rtv_desc *desc)
468 d3d11_desc->Format = desc->format;
469 d3d11_desc->ViewDimension = desc->dimension;
470 if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1D)
472 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
474 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1DARRAY)
476 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
477 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
478 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
480 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
482 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
484 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
486 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
487 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
488 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
490 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
492 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
493 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
495 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE3D)
497 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
498 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
499 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
501 else if (desc->dimension != D3D11_RTV_DIMENSION_UNKNOWN
502 && desc->dimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
504 trace("Unhandled view dimension %#x.\n", desc->dimension);
508 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
509 static void check_rtv_desc_(unsigned int line, const D3D11_RENDER_TARGET_VIEW_DESC *desc,
510 const struct rtv_desc *expected_desc)
512 ok_(__FILE__, line)(desc->Format == expected_desc->format,
513 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
514 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
515 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
517 if (desc->ViewDimension != expected_desc->dimension)
518 return;
520 if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D)
522 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
523 "Got MipSlice %u, expected %u.\n",
524 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
526 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
528 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
529 "Got MipSlice %u, expected %u.\n",
530 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
531 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
532 "Got FirstArraySlice %u, expected %u.\n",
533 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
534 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
535 "Got ArraySize %u, expected %u.\n",
536 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
538 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
540 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
541 "Got FirstArraySlice %u, expected %u.\n",
542 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
543 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
544 "Got ArraySize %u, expected %u.\n",
545 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
547 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE3D)
549 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
550 "Got MipSlice %u, expected %u.\n",
551 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
552 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
553 "Got FirstWSlice %u, expected %u.\n",
554 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
555 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
556 "Got WSize %u, expected %u.\n",
557 U(*desc).Texture3D.WSize, expected_desc->layer_count);
559 else if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
561 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
565 struct dsv_desc
567 DXGI_FORMAT format;
568 D3D11_DSV_DIMENSION dimension;
569 unsigned int miplevel_idx;
570 unsigned int layer_idx;
571 unsigned int layer_count;
574 static void get_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *d3d11_desc, const struct dsv_desc *desc)
576 d3d11_desc->Format = desc->format;
577 d3d11_desc->ViewDimension = desc->dimension;
578 d3d11_desc->Flags = 0;
579 if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1D)
581 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
583 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1DARRAY)
585 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
586 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
587 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
589 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2D)
591 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
593 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
595 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
596 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
597 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
599 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
601 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
602 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
604 else if (desc->dimension != D3D11_DSV_DIMENSION_UNKNOWN
605 && desc->dimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
607 trace("Unhandled view dimension %#x.\n", desc->dimension);
611 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
612 static void check_dsv_desc_(unsigned int line, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc,
613 const struct dsv_desc *expected_desc)
615 ok_(__FILE__, line)(desc->Format == expected_desc->format,
616 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
617 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
618 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
620 if (desc->ViewDimension != expected_desc->dimension)
621 return;
623 if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D)
625 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
626 "Got MipSlice %u, expected %u.\n",
627 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
629 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
631 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
632 "Got MipSlice %u, expected %u.\n",
633 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
634 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
635 "Got FirstArraySlice %u, expected %u.\n",
636 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
637 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
638 "Got ArraySize %u, expected %u.\n",
639 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
641 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
643 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
644 "Got FirstArraySlice %u, expected %u.\n",
645 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
646 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
647 "Got ArraySize %u, expected %u.\n",
648 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
650 else if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
652 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
656 struct uav_desc
658 DXGI_FORMAT format;
659 D3D11_UAV_DIMENSION dimension;
660 unsigned int miplevel_idx;
661 unsigned int layer_idx;
662 unsigned int layer_count;
665 static void get_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC *d3d11_desc, const struct uav_desc *desc)
667 d3d11_desc->Format = desc->format;
668 d3d11_desc->ViewDimension = desc->dimension;
669 if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1D)
671 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
673 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
675 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
676 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
677 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
679 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2D)
681 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
683 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
685 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
686 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
687 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
689 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE3D)
691 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
692 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
693 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
695 else if (desc->dimension != D3D11_UAV_DIMENSION_UNKNOWN)
697 trace("Unhandled view dimension %#x.\n", desc->dimension);
701 #define check_uav_desc(a, b) check_uav_desc_(__LINE__, a, b)
702 static void check_uav_desc_(unsigned int line, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc,
703 const struct uav_desc *expected_desc)
705 ok_(__FILE__, line)(desc->Format == expected_desc->format,
706 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
707 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
708 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
710 if (desc->ViewDimension != expected_desc->dimension)
711 return;
713 if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D)
715 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
716 "Got MipSlice %u, expected %u.\n",
717 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
719 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
721 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
722 "Got MipSlice %u, expected %u.\n",
723 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
724 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
725 "Got FirstArraySlice %u, expected %u.\n",
726 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
727 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
728 "Got ArraySize %u, expected %u.\n",
729 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
731 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
733 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
734 "Got MipSlice %u, expected %u.\n",
735 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
736 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
737 "Got FirstWSlice %u, expected %u.\n",
738 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
739 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
740 "Got WSize %u, expected %u.\n",
741 U(*desc).Texture3D.WSize, expected_desc->layer_count);
743 else
745 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
749 static void set_viewport(ID3D11DeviceContext *context, float x, float y,
750 float width, float height, float min_depth, float max_depth)
752 D3D11_VIEWPORT vp;
754 vp.TopLeftX = x;
755 vp.TopLeftY = y;
756 vp.Width = width;
757 vp.Height = height;
758 vp.MinDepth = min_depth;
759 vp.MaxDepth = max_depth;
761 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
764 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, 0, c, d)
765 #define create_buffer_misc(a, b, c, d, e) create_buffer_(__LINE__, a, b, c, d, e)
766 static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
767 unsigned int bind_flags, unsigned int misc_flags, unsigned int size, const void *data)
769 D3D11_SUBRESOURCE_DATA resource_data;
770 D3D11_BUFFER_DESC buffer_desc;
771 ID3D11Buffer *buffer;
772 HRESULT hr;
774 buffer_desc.ByteWidth = size;
775 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
776 buffer_desc.BindFlags = bind_flags;
777 buffer_desc.CPUAccessFlags = 0;
778 buffer_desc.MiscFlags = misc_flags;
779 buffer_desc.StructureByteStride = 0;
781 resource_data.pSysMem = data;
782 resource_data.SysMemPitch = 0;
783 resource_data.SysMemSlicePitch = 0;
785 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
786 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
787 return buffer;
790 static HRESULT create_resource(ID3D11Device *device, const struct resource_desc *desc,
791 const D3D11_SUBRESOURCE_DATA *data, ID3D11Resource **resource)
793 D3D11_TEXTURE1D_DESC texture1d_desc;
794 D3D11_TEXTURE2D_DESC texture2d_desc;
795 D3D11_TEXTURE3D_DESC texture3d_desc;
796 D3D11_BUFFER_DESC buffer_desc;
798 switch (desc->dimension)
800 case D3D11_RESOURCE_DIMENSION_BUFFER:
801 buffer_desc.ByteWidth = desc->width;
802 buffer_desc.Usage = desc->usage;
803 buffer_desc.BindFlags = desc->bind_flags;
804 buffer_desc.CPUAccessFlags = desc->cpu_access_flags;
805 buffer_desc.MiscFlags = desc->misc_flags;
806 buffer_desc.StructureByteStride = desc->structure_byte_stride;
807 return ID3D11Device_CreateBuffer(device, &buffer_desc, data, (ID3D11Buffer **)resource);
809 case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
810 texture1d_desc.Width = desc->width;
811 texture1d_desc.MipLevels = desc->level_count;
812 texture1d_desc.ArraySize = desc->depth_or_array_size;
813 texture1d_desc.Format = desc->format;
814 texture1d_desc.Usage = desc->usage;
815 texture1d_desc.BindFlags = desc->bind_flags;
816 texture1d_desc.CPUAccessFlags = desc->cpu_access_flags;
817 texture1d_desc.MiscFlags = desc->misc_flags;
818 return ID3D11Device_CreateTexture1D(device, &texture1d_desc, data, (ID3D11Texture1D **)resource);
820 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
821 texture2d_desc.Width = desc->width;
822 texture2d_desc.Height = desc->height;
823 texture2d_desc.MipLevels = desc->level_count;
824 texture2d_desc.ArraySize = desc->depth_or_array_size;
825 texture2d_desc.Format = desc->format;
826 texture2d_desc.SampleDesc = desc->sample_desc;
827 texture2d_desc.Usage = desc->usage;
828 texture2d_desc.BindFlags = desc->bind_flags;
829 texture2d_desc.CPUAccessFlags = desc->cpu_access_flags;
830 texture2d_desc.MiscFlags = desc->misc_flags;
831 return ID3D11Device_CreateTexture2D(device, &texture2d_desc, data, (ID3D11Texture2D **)resource);
833 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
834 texture3d_desc.Width = desc->width;
835 texture3d_desc.Height = desc->height;
836 texture3d_desc.Depth = desc->depth_or_array_size;
837 texture3d_desc.MipLevels = desc->level_count;
838 texture3d_desc.Format = desc->format;
839 texture3d_desc.Usage = desc->usage;
840 texture3d_desc.BindFlags = desc->bind_flags;
841 texture3d_desc.CPUAccessFlags = desc->cpu_access_flags;
842 texture3d_desc.MiscFlags = desc->misc_flags;
843 return ID3D11Device_CreateTexture3D(device, &texture3d_desc, data, (ID3D11Texture3D **)resource);
845 default:
846 return E_INVALIDARG;
850 struct resource_readback
852 ID3D11Resource *resource;
853 D3D11_MAPPED_SUBRESOURCE map_desc;
854 ID3D11DeviceContext *immediate_context;
855 unsigned int width, height, depth, sub_resource_idx;
858 static void init_resource_readback(ID3D11Resource *resource, ID3D11Resource *readback_resource,
859 unsigned int width, unsigned int height, unsigned int depth, unsigned int sub_resource_idx,
860 ID3D11Device *device, struct resource_readback *rb)
862 HRESULT hr;
864 rb->resource = readback_resource;
865 rb->width = width;
866 rb->height = height;
867 rb->depth = depth;
868 rb->sub_resource_idx = sub_resource_idx;
870 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
872 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, resource);
873 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context,
874 rb->resource, sub_resource_idx, D3D11_MAP_READ, 0, &rb->map_desc)))
876 trace("Failed to map resource, hr %#x.\n", hr);
877 ID3D11Resource_Release(rb->resource);
878 rb->resource = NULL;
879 ID3D11DeviceContext_Release(rb->immediate_context);
880 rb->immediate_context = NULL;
884 static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
886 D3D11_BUFFER_DESC buffer_desc;
887 ID3D11Resource *rb_buffer;
888 ID3D11Device *device;
889 HRESULT hr;
891 memset(rb, 0, sizeof(*rb));
893 ID3D11Buffer_GetDevice(buffer, &device);
895 ID3D11Buffer_GetDesc(buffer, &buffer_desc);
896 buffer_desc.Usage = D3D11_USAGE_STAGING;
897 buffer_desc.BindFlags = 0;
898 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
899 buffer_desc.MiscFlags = 0;
900 buffer_desc.StructureByteStride = 0;
901 if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb_buffer)))
903 trace("Failed to create staging buffer, hr %#x.\n", hr);
904 ID3D11Device_Release(device);
905 return;
908 init_resource_readback((ID3D11Resource *)buffer, rb_buffer,
909 buffer_desc.ByteWidth, 1, 1, 0, device, rb);
911 ID3D11Device_Release(device);
914 static void get_texture1d_readback(ID3D11Texture1D *texture, unsigned int sub_resource_idx,
915 struct resource_readback *rb)
917 D3D11_TEXTURE1D_DESC texture_desc;
918 ID3D11Resource *rb_texture;
919 unsigned int miplevel;
920 ID3D11Device *device;
921 HRESULT hr;
923 memset(rb, 0, sizeof(*rb));
925 ID3D11Texture1D_GetDevice(texture, &device);
927 ID3D11Texture1D_GetDesc(texture, &texture_desc);
928 texture_desc.Usage = D3D11_USAGE_STAGING;
929 texture_desc.BindFlags = 0;
930 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
931 texture_desc.MiscFlags = 0;
932 if (FAILED(hr = ID3D11Device_CreateTexture1D(device, &texture_desc, NULL, (ID3D11Texture1D **)&rb_texture)))
934 trace("Failed to create texture, hr %#x.\n", hr);
935 ID3D11Device_Release(device);
936 return;
939 miplevel = sub_resource_idx % texture_desc.MipLevels;
940 init_resource_readback((ID3D11Resource *)texture, rb_texture,
941 max(1, texture_desc.Width >> miplevel), 1, 1, sub_resource_idx, device, rb);
943 ID3D11Device_Release(device);
946 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
947 struct resource_readback *rb)
949 D3D11_TEXTURE2D_DESC texture_desc;
950 ID3D11Resource *rb_texture;
951 unsigned int miplevel;
952 ID3D11Device *device;
953 HRESULT hr;
955 memset(rb, 0, sizeof(*rb));
957 ID3D11Texture2D_GetDevice(texture, &device);
959 ID3D11Texture2D_GetDesc(texture, &texture_desc);
960 texture_desc.Usage = D3D11_USAGE_STAGING;
961 texture_desc.BindFlags = 0;
962 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
963 texture_desc.MiscFlags = 0;
964 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb_texture)))
966 trace("Failed to create texture, hr %#x.\n", hr);
967 ID3D11Device_Release(device);
968 return;
971 miplevel = sub_resource_idx % texture_desc.MipLevels;
972 init_resource_readback((ID3D11Resource *)texture, rb_texture,
973 max(1, texture_desc.Width >> miplevel),
974 max(1, texture_desc.Height >> miplevel),
975 1, sub_resource_idx, device, rb);
977 ID3D11Device_Release(device);
980 static void get_texture3d_readback(ID3D11Texture3D *texture, unsigned int sub_resource_idx,
981 struct resource_readback *rb)
983 D3D11_TEXTURE3D_DESC texture_desc;
984 ID3D11Resource *rb_texture;
985 unsigned int miplevel;
986 ID3D11Device *device;
987 HRESULT hr;
989 memset(rb, 0, sizeof(*rb));
991 ID3D11Texture3D_GetDevice(texture, &device);
993 ID3D11Texture3D_GetDesc(texture, &texture_desc);
994 texture_desc.Usage = D3D11_USAGE_STAGING;
995 texture_desc.BindFlags = 0;
996 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
997 texture_desc.MiscFlags = 0;
998 if (FAILED(hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, (ID3D11Texture3D **)&rb_texture)))
1000 trace("Failed to create texture, hr %#x.\n", hr);
1001 ID3D11Device_Release(device);
1002 return;
1005 miplevel = sub_resource_idx % texture_desc.MipLevels;
1006 init_resource_readback((ID3D11Resource *)texture, rb_texture,
1007 max(1, texture_desc.Width >> miplevel),
1008 max(1, texture_desc.Height >> miplevel),
1009 max(1, texture_desc.Depth >> miplevel),
1010 sub_resource_idx, device, rb);
1012 ID3D11Device_Release(device);
1015 static void get_resource_readback(ID3D11Resource *resource,
1016 unsigned int sub_resource_idx, struct resource_readback *rb)
1018 D3D11_RESOURCE_DIMENSION d;
1020 ID3D11Resource_GetType(resource, &d);
1021 switch (d)
1023 case D3D11_RESOURCE_DIMENSION_BUFFER:
1024 get_buffer_readback((ID3D11Buffer *)resource, rb);
1025 return;
1027 case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
1028 get_texture1d_readback((ID3D11Texture1D *)resource, sub_resource_idx, rb);
1029 return;
1031 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
1032 get_texture_readback((ID3D11Texture2D *)resource, sub_resource_idx, rb);
1033 return;
1035 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
1036 get_texture3d_readback((ID3D11Texture3D *)resource, sub_resource_idx, rb);
1037 return;
1039 default:
1040 memset(rb, 0, sizeof(*rb));
1041 return;
1045 static void *get_readback_data(struct resource_readback *rb,
1046 unsigned int x, unsigned int y, unsigned int z, unsigned byte_width)
1048 return (BYTE *)rb->map_desc.pData + z * rb->map_desc.DepthPitch + y * rb->map_desc.RowPitch + x * byte_width;
1051 static BYTE get_readback_u8(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
1053 return *(BYTE *)get_readback_data(rb, x, y, z, sizeof(BYTE));
1056 static WORD get_readback_u16(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
1058 return *(WORD *)get_readback_data(rb, x, y, z, sizeof(WORD));
1061 static DWORD get_readback_u32(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
1063 return *(DWORD *)get_readback_data(rb, x, y, z, sizeof(DWORD));
1066 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
1068 return get_readback_u32(rb, x, y, z);
1071 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
1073 return *(float *)get_readback_data(rb, x, y, 0, sizeof(float));
1076 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
1078 return get_readback_data(rb, x, y, 0, sizeof(struct vec4));
1081 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
1083 return get_readback_data(rb, x, y, 0, sizeof(struct uvec4));
1086 static void release_resource_readback(struct resource_readback *rb)
1088 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
1089 ID3D11Resource_Release(rb->resource);
1090 ID3D11DeviceContext_Release(rb->immediate_context);
1093 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
1095 struct resource_readback rb;
1096 DWORD color;
1098 get_texture_readback(texture, 0, &rb);
1099 color = get_readback_color(&rb, x, y, 0);
1100 release_resource_readback(&rb);
1102 return color;
1105 #define check_readback_data_u8(a, b, c, d) check_readback_data_u8_(__LINE__, a, b, c, d)
1106 static void check_readback_data_u8_(unsigned int line, struct resource_readback *rb,
1107 const RECT *rect, BYTE expected_value, BYTE max_diff)
1109 unsigned int x = 0, y = 0, z = 0;
1110 BOOL all_match = FALSE;
1111 RECT default_rect;
1112 BYTE value = 0;
1114 if (!rect)
1116 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1117 rect = &default_rect;
1120 for (z = 0; z < rb->depth; ++z)
1122 for (y = rect->top; y < rect->bottom; ++y)
1124 for (x = rect->left; x < rect->right; ++x)
1126 value = get_readback_u8(rb, x, y, z);
1127 if (!compare_uint(value, expected_value, max_diff))
1128 goto done;
1132 all_match = TRUE;
1134 done:
1135 ok_(__FILE__, line)(all_match,
1136 "Got 0x%02x, expected 0x%02x at (%u, %u, %u), sub-resource %u.\n",
1137 value, expected_value, x, y, z, rb->sub_resource_idx);
1140 #define check_readback_data_u16(a, b, c, d) check_readback_data_u16_(__LINE__, a, b, c, d)
1141 static void check_readback_data_u16_(unsigned int line, struct resource_readback *rb,
1142 const RECT *rect, WORD expected_value, BYTE max_diff)
1144 unsigned int x = 0, y = 0, z = 0;
1145 BOOL all_match = FALSE;
1146 RECT default_rect;
1147 WORD value = 0;
1149 if (!rect)
1151 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1152 rect = &default_rect;
1155 for (z = 0; z < rb->depth; ++z)
1157 for (y = rect->top; y < rect->bottom; ++y)
1159 for (x = rect->left; x < rect->right; ++x)
1161 value = get_readback_u16(rb, x, y, z);
1162 if (!compare_uint(value, expected_value, max_diff))
1163 goto done;
1167 all_match = TRUE;
1169 done:
1170 ok_(__FILE__, line)(all_match,
1171 "Got 0x%04x, expected 0x%04x at (%u, %u, %u), sub-resource %u.\n",
1172 value, expected_value, x, y, z, rb->sub_resource_idx);
1175 #define check_readback_data_u24(a, b, c, d, e) check_readback_data_u24_(__LINE__, a, b, c, d, e)
1176 static void check_readback_data_u24_(unsigned int line, struct resource_readback *rb,
1177 const RECT *rect, unsigned int shift, DWORD expected_value, BYTE max_diff)
1179 unsigned int x = 0, y = 0, z = 0;
1180 BOOL all_match = FALSE;
1181 RECT default_rect;
1182 DWORD value = 0;
1184 if (!rect)
1186 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1187 rect = &default_rect;
1190 for (z = 0; z < rb->depth; ++z)
1192 for (y = rect->top; y < rect->bottom; ++y)
1194 for (x = rect->left; x < rect->right; ++x)
1196 value = get_readback_u32(rb, x, y, z) >> shift;
1197 if (!compare_uint(value, expected_value, max_diff))
1198 goto done;
1202 all_match = TRUE;
1204 done:
1205 ok_(__FILE__, line)(all_match,
1206 "Got 0x%06x, expected 0x%06x at (%u, %u, %u), sub-resource %u.\n",
1207 value, expected_value, x, y, z, rb->sub_resource_idx);
1210 #define check_readback_data_color(a, b, c, d) check_readback_data_color_(__LINE__, a, b, c, d)
1211 static void check_readback_data_color_(unsigned int line, struct resource_readback *rb,
1212 const RECT *rect, DWORD expected_color, BYTE max_diff)
1214 unsigned int x = 0, y = 0, z = 0;
1215 BOOL all_match = FALSE;
1216 RECT default_rect;
1217 DWORD color = 0;
1219 if (!rect)
1221 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1222 rect = &default_rect;
1225 for (z = 0; z < rb->depth; ++z)
1227 for (y = rect->top; y < rect->bottom; ++y)
1229 for (x = rect->left; x < rect->right; ++x)
1231 color = get_readback_color(rb, x, y, z);
1232 if (!compare_color(color, expected_color, max_diff))
1233 goto done;
1237 all_match = TRUE;
1239 done:
1240 ok_(__FILE__, line)(all_match,
1241 "Got 0x%08x, expected 0x%08x at (%u, %u, %u), sub-resource %u.\n",
1242 color, expected_color, x, y, z, rb->sub_resource_idx);
1245 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
1246 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
1247 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1249 struct resource_readback rb;
1251 get_texture_readback(texture, sub_resource_idx, &rb);
1252 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1253 release_resource_readback(&rb);
1256 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
1257 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
1258 DWORD expected_color, BYTE max_diff)
1260 unsigned int sub_resource_idx, sub_resource_count;
1261 D3D11_TEXTURE2D_DESC texture_desc;
1263 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1264 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1265 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1266 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1269 #define check_texture1d_sub_resource_color(a, b, c, d, e) check_texture1d_sub_resource_color_(__LINE__, a, b, c, d, e)
1270 static void check_texture1d_sub_resource_color_(unsigned int line, ID3D11Texture1D *texture,
1271 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1273 struct resource_readback rb;
1275 get_texture1d_readback(texture, sub_resource_idx, &rb);
1276 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1277 release_resource_readback(&rb);
1280 #define check_texture1d_color(t, c, d) check_texture1d_color_(__LINE__, t, c, d)
1281 static void check_texture1d_color_(unsigned int line, ID3D11Texture1D *texture,
1282 DWORD expected_color, BYTE max_diff)
1284 unsigned int sub_resource_idx, sub_resource_count;
1285 D3D11_TEXTURE1D_DESC texture_desc;
1287 ID3D11Texture1D_GetDesc(texture, &texture_desc);
1288 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1289 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1290 check_texture1d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1293 #define check_texture3d_sub_resource_color(a, b, c, d, e) check_texture3d_sub_resource_color_(__LINE__, a, b, c, d, e)
1294 static void check_texture3d_sub_resource_color_(unsigned int line, ID3D11Texture3D *texture,
1295 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1297 struct resource_readback rb;
1299 get_texture3d_readback(texture, sub_resource_idx, &rb);
1300 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1301 release_resource_readback(&rb);
1304 #define check_texture3d_color(t, c, d) check_texture3d_color_(__LINE__, t, c, d)
1305 static void check_texture3d_color_(unsigned int line, ID3D11Texture3D *texture,
1306 DWORD expected_color, BYTE max_diff)
1308 unsigned int sub_resource_idx, sub_resource_count;
1309 D3D11_TEXTURE3D_DESC texture_desc;
1311 ID3D11Texture3D_GetDesc(texture, &texture_desc);
1312 sub_resource_count = texture_desc.MipLevels;
1313 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1314 check_texture3d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1317 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
1318 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
1319 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
1321 struct resource_readback rb;
1322 unsigned int x = 0, y = 0;
1323 BOOL all_match = TRUE;
1324 float value = 0.0f;
1325 RECT default_rect;
1327 get_texture_readback(texture, sub_resource_idx, &rb);
1328 if (!rect)
1330 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1331 rect = &default_rect;
1333 for (y = rect->top; y < rect->bottom; ++y)
1335 for (x = rect->left; x < rect->right; ++x)
1337 value = get_readback_float(&rb, x, y);
1338 if (!compare_float(value, expected_value, max_diff))
1340 all_match = FALSE;
1341 break;
1344 if (!all_match)
1345 break;
1347 release_resource_readback(&rb);
1348 ok_(__FILE__, line)(all_match,
1349 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
1350 value, expected_value, x, y, sub_resource_idx);
1353 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
1354 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
1355 float expected_value, BYTE max_diff)
1357 unsigned int sub_resource_idx, sub_resource_count;
1358 D3D11_TEXTURE2D_DESC texture_desc;
1360 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1361 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1362 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1363 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1366 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
1367 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
1368 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
1370 struct resource_readback rb;
1371 unsigned int x = 0, y = 0;
1372 struct vec4 value = {0};
1373 BOOL all_match = TRUE;
1374 RECT default_rect;
1376 get_texture_readback(texture, sub_resource_idx, &rb);
1377 if (!rect)
1379 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1380 rect = &default_rect;
1382 for (y = rect->top; y < rect->bottom; ++y)
1384 for (x = rect->left; x < rect->right; ++x)
1386 value = *get_readback_vec4(&rb, x, y);
1387 if (!compare_vec4(&value, expected_value, max_diff))
1389 all_match = FALSE;
1390 break;
1393 if (!all_match)
1394 break;
1396 release_resource_readback(&rb);
1397 ok_(__FILE__, line)(all_match,
1398 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
1399 value.x, value.y, value.z, value.w,
1400 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1401 x, y, sub_resource_idx);
1404 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
1405 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
1406 const struct vec4 *expected_value, BYTE max_diff)
1408 unsigned int sub_resource_idx, sub_resource_count;
1409 D3D11_TEXTURE2D_DESC texture_desc;
1411 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1412 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1413 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1414 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1417 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
1418 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
1419 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
1421 struct resource_readback rb;
1422 unsigned int x = 0, y = 0;
1423 struct uvec4 value = {0};
1424 BOOL all_match = TRUE;
1425 RECT default_rect;
1427 get_texture_readback(texture, sub_resource_idx, &rb);
1428 if (!rect)
1430 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1431 rect = &default_rect;
1433 for (y = rect->top; y < rect->bottom; ++y)
1435 for (x = rect->left; x < rect->right; ++x)
1437 value = *get_readback_uvec4(&rb, x, y);
1438 if (!compare_uvec4(&value, expected_value))
1440 all_match = FALSE;
1441 break;
1444 if (!all_match)
1445 break;
1447 release_resource_readback(&rb);
1448 ok_(__FILE__, line)(all_match,
1449 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
1450 "at (%u, %u), sub-resource %u.\n",
1451 value.x, value.y, value.z, value.w,
1452 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1453 x, y, sub_resource_idx);
1456 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
1457 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
1458 const struct uvec4 *expected_value)
1460 unsigned int sub_resource_idx, sub_resource_count;
1461 D3D11_TEXTURE2D_DESC texture_desc;
1463 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1464 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1465 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1466 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
1469 static IDXGIAdapter *create_adapter(void)
1471 IDXGIFactory4 *factory4;
1472 IDXGIFactory *factory;
1473 IDXGIAdapter *adapter;
1474 HRESULT hr;
1476 if (!use_warp_adapter && !use_adapter_idx)
1477 return NULL;
1479 if (FAILED(hr = CreateDXGIFactory1(&IID_IDXGIFactory, (void **)&factory)))
1481 trace("Failed to create IDXGIFactory, hr %#x.\n", hr);
1482 return NULL;
1485 adapter = NULL;
1486 if (use_warp_adapter)
1488 if (SUCCEEDED(hr = IDXGIFactory_QueryInterface(factory, &IID_IDXGIFactory4, (void **)&factory4)))
1490 hr = IDXGIFactory4_EnumWarpAdapter(factory4, &IID_IDXGIAdapter, (void **)&adapter);
1491 IDXGIFactory4_Release(factory4);
1493 else
1495 trace("Failed to get IDXGIFactory4, hr %#x.\n", hr);
1498 else
1500 hr = IDXGIFactory_EnumAdapters(factory, use_adapter_idx, &adapter);
1502 IDXGIFactory_Release(factory);
1503 if (FAILED(hr))
1504 trace("Failed to get adapter, hr %#x.\n", hr);
1505 return adapter;
1508 static ID3D11Device *create_device(const struct device_desc *desc)
1510 static const D3D_FEATURE_LEVEL default_feature_level[] =
1512 D3D_FEATURE_LEVEL_11_0,
1513 D3D_FEATURE_LEVEL_10_1,
1514 D3D_FEATURE_LEVEL_10_0,
1516 const D3D_FEATURE_LEVEL *feature_level;
1517 UINT flags = desc ? desc->flags : 0;
1518 unsigned int feature_level_count;
1519 IDXGIAdapter *adapter;
1520 ID3D11Device *device;
1521 HRESULT hr;
1523 if (desc && desc->feature_level)
1525 feature_level = desc->feature_level;
1526 feature_level_count = 1;
1528 else
1530 feature_level = default_feature_level;
1531 feature_level_count = ARRAY_SIZE(default_feature_level);
1534 if (enable_debug_layer)
1535 flags |= D3D11_CREATE_DEVICE_DEBUG;
1537 if ((adapter = create_adapter()))
1539 hr = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags,
1540 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL);
1541 IDXGIAdapter_Release(adapter);
1542 return SUCCEEDED(hr) ? device : NULL;
1545 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags,
1546 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1547 return device;
1548 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags,
1549 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1550 return device;
1551 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags,
1552 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1553 return device;
1555 return NULL;
1558 static void get_device_adapter_desc(ID3D11Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1560 IDXGIDevice *dxgi_device;
1561 IDXGIAdapter *adapter;
1562 HRESULT hr;
1564 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1565 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1566 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1567 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1568 IDXGIDevice_Release(dxgi_device);
1569 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1570 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1571 IDXGIAdapter_Release(adapter);
1574 static void print_adapter_info(void)
1576 DXGI_ADAPTER_DESC adapter_desc;
1577 ID3D11Device *device;
1579 if (!(device = create_device(NULL)))
1580 return;
1582 get_device_adapter_desc(device, &adapter_desc);
1583 trace("Adapter: %s, %04x:%04x.\n", wine_dbgstr_w(adapter_desc.Description),
1584 adapter_desc.VendorId, adapter_desc.DeviceId);
1585 ID3D11Device_Release(device);
1588 static BOOL is_warp_device(ID3D11Device *device)
1590 DXGI_ADAPTER_DESC adapter_desc;
1591 get_device_adapter_desc(device, &adapter_desc);
1592 return !adapter_desc.SubSysId && !adapter_desc.Revision
1593 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1594 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1597 static BOOL is_vendor_device(ID3D11Device *device, unsigned int vendor_id)
1599 DXGI_ADAPTER_DESC adapter_desc;
1601 if (!strcmp(winetest_platform, "wine"))
1602 return FALSE;
1604 get_device_adapter_desc(device, &adapter_desc);
1605 return adapter_desc.VendorId == vendor_id;
1608 static BOOL is_amd_device(ID3D11Device *device)
1610 return is_vendor_device(device, 0x1002);
1613 static BOOL is_intel_device(ID3D11Device *device)
1615 return is_vendor_device(device, 0x8086);
1618 static BOOL is_nvidia_device(ID3D11Device *device)
1620 return is_vendor_device(device, 0x10de);
1623 static BOOL is_d3d11_2_runtime(ID3D11Device *device)
1625 ID3D11Device2 *device2;
1626 HRESULT hr;
1628 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11Device2, (void **)&device2);
1629 if (SUCCEEDED(hr))
1630 ID3D11Device2_Release(device2);
1631 return hr == S_OK;
1634 static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device)
1636 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
1638 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1639 D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options))))
1640 return FALSE;
1641 return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
1644 static BOOL check_viewport_array_index_from_any_shader_support(ID3D11Device *device)
1646 D3D11_FEATURE_DATA_D3D11_OPTIONS3 options;
1648 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1649 D3D11_FEATURE_D3D11_OPTIONS3, &options, sizeof(options))))
1650 return FALSE;
1651 return options.VPAndRTArrayIndexFromAnyShaderFeedingRasterizer;
1654 static BOOL is_buffer(ID3D11Resource *resource)
1656 D3D11_RESOURCE_DIMENSION dimension;
1657 ID3D11Resource_GetType(resource, &dimension);
1658 return dimension == D3D11_RESOURCE_DIMENSION_BUFFER;
1661 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window,
1662 const struct swapchain_desc *swapchain_desc)
1664 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1665 IDXGISwapChain *swapchain;
1666 IDXGIDevice *dxgi_device;
1667 IDXGIAdapter *adapter;
1668 IDXGIFactory *factory;
1669 HRESULT hr;
1671 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1672 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1673 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1674 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1675 IDXGIDevice_Release(dxgi_device);
1676 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1677 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1678 IDXGIAdapter_Release(adapter);
1680 dxgi_desc.BufferDesc.Width = 640;
1681 dxgi_desc.BufferDesc.Height = 480;
1682 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1683 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1684 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1685 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1686 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1687 dxgi_desc.SampleDesc.Count = 1;
1688 dxgi_desc.SampleDesc.Quality = 0;
1689 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1690 dxgi_desc.BufferCount = 1;
1691 dxgi_desc.OutputWindow = window;
1692 dxgi_desc.Windowed = TRUE;
1693 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1694 dxgi_desc.Flags = 0;
1696 if (swapchain_desc)
1698 dxgi_desc.Windowed = swapchain_desc->windowed;
1699 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1700 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1701 if (swapchain_desc->width)
1702 dxgi_desc.BufferDesc.Width = swapchain_desc->width;
1703 if (swapchain_desc->height)
1704 dxgi_desc.BufferDesc.Height = swapchain_desc->height;
1706 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1707 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1710 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1711 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1712 IDXGIFactory_Release(factory);
1714 return swapchain;
1717 struct d3d11_test_context
1719 ID3D11Device *device;
1720 HWND window;
1721 IDXGISwapChain *swapchain;
1722 ID3D11Texture2D *backbuffer;
1723 ID3D11RenderTargetView *backbuffer_rtv;
1724 ID3D11DeviceContext *immediate_context;
1726 ID3D11InputLayout *input_layout;
1727 ID3D11VertexShader *vs;
1728 const DWORD *vs_code;
1729 ID3D11Buffer *vs_cb;
1730 ID3D11Buffer *vb;
1732 ID3D11PixelShader *ps;
1733 ID3D11Buffer *ps_cb;
1736 #define init_test_context(a, b) init_test_context_(__LINE__, a, b, NULL)
1737 #define init_test_context_ext(a, b, c) init_test_context_(__LINE__, a, b, c)
1738 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1739 const D3D_FEATURE_LEVEL *feature_level, const struct swapchain_desc *swapchain_desc)
1741 unsigned int rt_width, rt_height;
1742 struct device_desc device_desc;
1743 HRESULT hr;
1744 RECT rect;
1746 memset(context, 0, sizeof(*context));
1748 device_desc.feature_level = feature_level;
1749 device_desc.flags = 0;
1750 if (!(context->device = create_device(&device_desc)))
1752 skip_(__FILE__, line)("Failed to create device.\n");
1753 return FALSE;
1756 rt_width = swapchain_desc && swapchain_desc->width ? swapchain_desc->width : 640;
1757 rt_height = swapchain_desc && swapchain_desc->height ? swapchain_desc->height : 480;
1758 SetRect(&rect, 0, 0, rt_width, rt_height);
1759 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1760 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1761 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1762 context->swapchain = create_swapchain(context->device, context->window, swapchain_desc);
1763 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1764 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1766 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1767 NULL, &context->backbuffer_rtv);
1768 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1770 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1772 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1774 set_viewport(context->immediate_context, 0.0f, 0.0f, rt_width, rt_height, 0.0f, 1.0f);
1776 return TRUE;
1779 #define release_test_context(context) release_test_context_(__LINE__, context)
1780 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1782 ULONG ref;
1784 if (context->input_layout)
1785 ID3D11InputLayout_Release(context->input_layout);
1786 if (context->vs)
1787 ID3D11VertexShader_Release(context->vs);
1788 if (context->vs_cb)
1789 ID3D11Buffer_Release(context->vs_cb);
1790 if (context->vb)
1791 ID3D11Buffer_Release(context->vb);
1792 if (context->ps)
1793 ID3D11PixelShader_Release(context->ps);
1794 if (context->ps_cb)
1795 ID3D11Buffer_Release(context->ps_cb);
1797 ID3D11DeviceContext_Release(context->immediate_context);
1798 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1799 ID3D11Texture2D_Release(context->backbuffer);
1800 IDXGISwapChain_Release(context->swapchain);
1801 DestroyWindow(context->window);
1803 ref = ID3D11Device_Release(context->device);
1804 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1807 #define draw_quad(context) draw_quad_vs_(__LINE__, context, NULL, 0)
1808 #define draw_quad_vs(a, b, c) draw_quad_vs_(__LINE__, a, b, c)
1809 static void draw_quad_vs_(unsigned int line, struct d3d11_test_context *context,
1810 const DWORD *vs_code, size_t vs_code_size)
1812 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1814 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1816 static const DWORD default_vs_code[] =
1818 #if 0
1819 float4 main(float4 position : POSITION) : SV_POSITION
1821 return position;
1823 #endif
1824 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1825 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1826 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1827 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1828 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1829 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1830 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1831 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1832 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1833 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1834 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1835 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1836 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1837 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1838 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1840 static const struct vec3 quad[] =
1842 {-1.0f, -1.0f, 0.0f},
1843 {-1.0f, 1.0f, 0.0f},
1844 { 1.0f, -1.0f, 0.0f},
1845 { 1.0f, 1.0f, 0.0f},
1848 ID3D11Device *device = context->device;
1849 unsigned int stride, offset;
1850 HRESULT hr;
1852 if (!vs_code)
1854 vs_code = default_vs_code;
1855 vs_code_size = sizeof(default_vs_code);
1858 if (!context->input_layout)
1860 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1861 vs_code, vs_code_size, &context->input_layout);
1862 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1865 if (context->vs_code != vs_code)
1867 if (context->vs)
1868 ID3D11VertexShader_Release(context->vs);
1870 hr = ID3D11Device_CreateVertexShader(device, vs_code, vs_code_size, NULL, &context->vs);
1871 ok_(__FILE__, line)(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
1873 context->vs_code = vs_code;
1876 if (!context->vb)
1877 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1879 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1880 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1881 stride = sizeof(*quad);
1882 offset = 0;
1883 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1884 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1886 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1889 #define draw_quad_z(context, z) draw_quad_z_(__LINE__, context, z)
1890 static void draw_quad_z_(unsigned int line, struct d3d11_test_context *context, float z)
1892 static const DWORD vs_code[] =
1894 #if 0
1895 float depth;
1897 void main(float4 in_position : POSITION, out float4 out_position : SV_Position)
1899 out_position = in_position;
1900 out_position.z = depth;
1902 #endif
1903 0x43425844, 0x22d7ff76, 0xd53b167c, 0x1b49ccf1, 0xbebfec39, 0x00000001, 0x00000100, 0x00000003,
1904 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1905 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000b0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1906 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1907 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x00000064, 0x00010040,
1908 0x00000019, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010b2, 0x00000000,
1909 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, 0x001020b2, 0x00000000, 0x00101c46,
1910 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
1913 struct vec4 data = {z};
1915 if (!context->vs_cb)
1916 context->vs_cb = create_buffer(context->device, D3D11_BIND_CONSTANT_BUFFER, sizeof(data), NULL);
1918 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1919 (ID3D11Resource *)context->vs_cb, 0, NULL, &data, 0, 0);
1921 ID3D11DeviceContext_VSSetConstantBuffers(context->immediate_context, 0, 1, &context->vs_cb);
1922 draw_quad_vs_(__LINE__, context, vs_code, sizeof(vs_code));
1925 static void set_quad_color(struct d3d11_test_context *context, const struct vec4 *color)
1927 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1928 (ID3D11Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1931 #define draw_color_quad(a, b) draw_color_quad_(__LINE__, a, b, NULL, 0)
1932 #define draw_color_quad_vs(a, b, c, d) draw_color_quad_(__LINE__, a, b, c, d)
1933 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context,
1934 const struct vec4 *color, const DWORD *vs_code, size_t vs_code_size)
1936 static const DWORD ps_color_code[] =
1938 #if 0
1939 float4 color;
1941 float4 main() : SV_TARGET
1943 return color;
1945 #endif
1946 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1947 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1948 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1949 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1950 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1951 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1952 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1953 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1954 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1955 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1956 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1959 ID3D11Device *device = context->device;
1960 HRESULT hr;
1962 if (!context->ps)
1964 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1965 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1968 if (!context->ps_cb)
1969 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1971 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1972 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1974 set_quad_color(context, color);
1976 draw_quad_vs_(line, context, vs_code, vs_code_size);
1979 static void test_create_device(void)
1981 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1983 D3D_FEATURE_LEVEL_11_0,
1984 D3D_FEATURE_LEVEL_10_1,
1985 D3D_FEATURE_LEVEL_10_0,
1986 D3D_FEATURE_LEVEL_9_3,
1987 D3D_FEATURE_LEVEL_9_2,
1988 D3D_FEATURE_LEVEL_9_1,
1990 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1991 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1992 ID3D11DeviceContext *immediate_context;
1993 IDXGISwapChain *swapchain;
1994 ID3D11Device *device;
1995 ULONG refcount;
1996 HWND window;
1997 HRESULT hr;
1999 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2000 &device, NULL, NULL)))
2002 skip("Failed to create HAL device.\n");
2003 if ((device = create_device(NULL)))
2005 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
2006 ID3D11Device_Release(device);
2008 return;
2011 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
2012 trace("Feature level %#x.\n", supported_feature_level);
2013 ID3D11Device_Release(device);
2015 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
2016 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2018 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
2019 &feature_level, NULL);
2020 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2021 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2022 feature_level, supported_feature_level);
2024 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
2025 ARRAY_SIZE(default_feature_levels), D3D11_SDK_VERSION, NULL, &feature_level, NULL);
2026 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2027 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2028 feature_level, supported_feature_level);
2030 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
2031 &immediate_context);
2032 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2034 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
2035 refcount = get_refcount(immediate_context);
2036 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
2038 ID3D11DeviceContext_GetDevice(immediate_context, &device);
2039 refcount = ID3D11Device_Release(device);
2040 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
2042 refcount = ID3D11DeviceContext_Release(immediate_context);
2043 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
2045 device = (ID3D11Device *)0xdeadbeef;
2046 feature_level = 0xdeadbeef;
2047 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
2048 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2049 &device, &feature_level, &immediate_context);
2050 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
2051 ok(!device, "Got unexpected device pointer %p.\n", device);
2052 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
2053 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
2055 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
2057 swapchain_desc.BufferDesc.Width = 800;
2058 swapchain_desc.BufferDesc.Height = 600;
2059 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
2060 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
2061 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2062 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
2063 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
2064 swapchain_desc.SampleDesc.Count = 1;
2065 swapchain_desc.SampleDesc.Quality = 0;
2066 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
2067 swapchain_desc.BufferCount = 1;
2068 swapchain_desc.OutputWindow = window;
2069 swapchain_desc.Windowed = TRUE;
2070 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
2071 swapchain_desc.Flags = 0;
2073 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2074 &swapchain_desc, NULL, NULL, NULL, NULL);
2075 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2077 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2078 &swapchain_desc, NULL, NULL, &feature_level, NULL);
2079 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2080 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2081 feature_level, supported_feature_level);
2083 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2084 &swapchain_desc, &swapchain, &device, NULL, NULL);
2085 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2087 check_interface(swapchain, &IID_IDXGISwapChain1, TRUE, FALSE);
2089 memset(&obtained_desc, 0, sizeof(obtained_desc));
2090 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
2091 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
2092 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
2093 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
2094 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
2095 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
2096 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
2097 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
2098 obtained_desc.BufferDesc.RefreshRate.Numerator);
2099 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
2100 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
2101 obtained_desc.BufferDesc.RefreshRate.Denominator);
2102 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
2103 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
2104 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
2105 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
2106 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
2107 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
2108 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
2109 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
2110 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
2111 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
2112 ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
2113 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
2114 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
2115 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
2116 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
2117 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
2118 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
2119 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
2120 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
2121 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
2122 ok(obtained_desc.Flags == swapchain_desc.Flags,
2123 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
2125 refcount = IDXGISwapChain_Release(swapchain);
2126 ok(!refcount, "Swapchain has %u references left.\n", refcount);
2128 feature_level = ID3D11Device_GetFeatureLevel(device);
2129 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2130 feature_level, supported_feature_level);
2132 refcount = ID3D11Device_Release(device);
2133 ok(!refcount, "Device has %u references left.\n", refcount);
2135 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2136 NULL, NULL, &device, NULL, NULL);
2137 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2138 ID3D11Device_Release(device);
2140 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2141 NULL, NULL, NULL, NULL, NULL);
2142 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2144 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2145 NULL, NULL, NULL, &feature_level, NULL);
2146 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2147 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2148 feature_level, supported_feature_level);
2150 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2151 NULL, NULL, NULL, NULL, &immediate_context);
2152 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2153 ID3D11DeviceContext_Release(immediate_context);
2155 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2156 &swapchain_desc, NULL, NULL, NULL, NULL);
2157 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2159 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2160 &swapchain_desc, &swapchain, NULL, NULL, NULL);
2161 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2162 IDXGISwapChain_Release(swapchain);
2164 swapchain_desc.OutputWindow = NULL;
2165 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2166 &swapchain_desc, NULL, NULL, NULL, NULL);
2167 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2168 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2169 &swapchain_desc, NULL, &device, NULL, NULL);
2170 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2171 ID3D11Device_Release(device);
2173 swapchain = (IDXGISwapChain *)0xdeadbeef;
2174 device = (ID3D11Device *)0xdeadbeef;
2175 feature_level = 0xdeadbeef;
2176 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
2177 swapchain_desc.OutputWindow = NULL;
2178 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2179 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
2180 ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2181 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
2182 ok(!device, "Got unexpected device pointer %p.\n", device);
2183 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
2184 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
2186 swapchain = (IDXGISwapChain *)0xdeadbeef;
2187 device = (ID3D11Device *)0xdeadbeef;
2188 feature_level = 0xdeadbeef;
2189 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
2190 swapchain_desc.OutputWindow = window;
2191 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
2192 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2193 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
2194 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2195 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
2196 ok(!device, "Got unexpected device pointer %p.\n", device);
2197 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
2198 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
2200 DestroyWindow(window);
2203 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
2205 struct device_desc device_desc;
2206 IDXGIAdapter *dxgi_adapter;
2207 IDXGIDevice *dxgi_device;
2208 ID3D11Device *device;
2209 IUnknown *iface;
2210 ULONG refcount;
2211 HRESULT hr;
2213 device_desc.feature_level = &feature_level;
2214 device_desc.flags = 0;
2215 if (!(device = create_device(&device_desc)))
2217 skip("Failed to create device for feature level %#x.\n", feature_level);
2218 return;
2221 check_interface(device, &IID_IUnknown, TRUE, FALSE);
2222 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
2223 check_interface(device, &IID_IDXGIDevice, TRUE, FALSE);
2224 check_interface(device, &IID_IDXGIDevice1, TRUE, FALSE);
2225 check_interface(device, &IID_ID3D10Multithread, TRUE, TRUE); /* Not available on all Windows versions. */
2226 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
2227 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
2228 check_interface(device, &IID_ID3D11InfoQueue, enable_debug_layer, FALSE);
2230 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
2231 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
2232 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
2233 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
2234 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
2235 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
2236 IUnknown_Release(iface);
2237 IDXGIAdapter_Release(dxgi_adapter);
2238 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
2239 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
2240 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
2241 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
2242 IUnknown_Release(iface);
2243 IDXGIAdapter_Release(dxgi_adapter);
2244 IDXGIDevice_Release(dxgi_device);
2246 refcount = ID3D11Device_Release(device);
2247 ok(!refcount, "Device has %u references left.\n", refcount);
2249 device_desc.feature_level = &feature_level;
2250 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
2251 if (!(device = create_device(&device_desc)))
2253 skip("Failed to create debug device for feature level %#x.\n", feature_level);
2254 return;
2257 todo_wine check_interface(device, &IID_ID3D11InfoQueue, TRUE, FALSE);
2259 refcount = ID3D11Device_Release(device);
2260 ok(!refcount, "Device has %u references left.\n", refcount);
2263 static void test_immediate_context(void)
2265 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
2266 ULONG expected_refcount, refcount;
2267 ID3D11CommandList *command_list;
2268 ID3D11Multithread *multithread;
2269 ID3D11Buffer *buffer[2];
2270 ID3D11Device *device;
2271 unsigned int flags;
2272 BOOL enabled;
2273 HRESULT hr;
2275 static const unsigned int buffer_contents[] =
2277 0x11111111, 0x22222222, 0x33333333, 0x44444444,
2278 0x55555555, 0x66666666, 0x77777777, 0x88888888,
2281 if (!(device = create_device(NULL)))
2283 skip("Failed to create device.\n");
2284 return;
2287 expected_refcount = get_refcount(device) + 1;
2288 ID3D11Device_GetImmediateContext(device, &immediate_context);
2289 refcount = get_refcount(device);
2290 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
2291 previous_immediate_context = immediate_context;
2293 ID3D11Device_GetImmediateContext(device, &immediate_context);
2294 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
2295 refcount = get_refcount(device);
2296 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
2298 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
2299 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2300 refcount = ID3D11DeviceContext_Release(immediate_context);
2301 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2303 ID3D11Device_GetImmediateContext(device, &immediate_context);
2304 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
2305 refcount = ID3D11DeviceContext_Release(immediate_context);
2306 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2308 ID3D11Device_GetImmediateContext(device, &immediate_context);
2309 expected_refcount = get_refcount(immediate_context) + 1;
2310 hr = ID3D11DeviceContext_QueryInterface(immediate_context, &IID_ID3D11Multithread, (void **)&multithread);
2311 if (hr == E_NOINTERFACE)
2313 win_skip("ID3D11Multithread is not supported.\n");
2314 goto done;
2316 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2318 refcount = get_refcount(immediate_context);
2319 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2321 expected_refcount = refcount;
2322 refcount = get_refcount(multithread);
2323 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2325 enabled = ID3D11Multithread_GetMultithreadProtected(multithread);
2326 todo_wine ok(!enabled, "Multithread protection is %#x.\n", enabled);
2328 ID3D11Multithread_Release(multithread);
2330 ID3D11Device_GetImmediateContext(device, &immediate_context);
2332 flags = ID3D11DeviceContext_GetContextFlags(immediate_context);
2333 ok(!flags, "Got unexpected flags %#x.\n", flags);
2335 hr = ID3D11DeviceContext_FinishCommandList(immediate_context, FALSE, &command_list);
2336 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
2338 buffer[0] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 16, &buffer_contents[0]);
2339 buffer[1] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 16, &buffer_contents[4]);
2341 ID3D11DeviceContext_CopyResource(immediate_context, (ID3D11Resource *)buffer[1], (ID3D11Resource *)buffer[0]);
2343 hr = ID3D11DeviceContext_FinishCommandList(immediate_context, FALSE, &command_list);
2344 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
2346 ID3D11Buffer_Release(buffer[1]);
2347 ID3D11Buffer_Release(buffer[0]);
2348 ID3D11DeviceContext_Release(immediate_context);
2350 done:
2351 refcount = ID3D11DeviceContext_Release(immediate_context);
2352 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2353 refcount = ID3D11Device_Release(device);
2354 ok(!refcount, "Device has %u references left.\n", refcount);
2357 static void test_create_deferred_context(void)
2359 ULONG refcount, expected_refcount;
2360 struct device_desc device_desc;
2361 ID3D11DeviceContext *context;
2362 ID3D11Device *device;
2363 HRESULT hr;
2365 device_desc.feature_level = NULL;
2366 device_desc.flags = D3D11_CREATE_DEVICE_SINGLETHREADED;
2367 if (!(device = create_device(&device_desc)))
2369 skip("Failed to create single-threaded device.\n");
2370 return;
2373 hr = ID3D11Device_CreateDeferredContext(device, 0, &context);
2374 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Failed to create deferred context, hr %#x.\n", hr);
2375 if (hr == S_OK)
2376 ID3D11DeviceContext_Release(context);
2378 refcount = ID3D11Device_Release(device);
2379 ok(!refcount, "Device has %u references left.\n", refcount);
2381 if (!(device = create_device(NULL)))
2383 skip("Failed to create device.\n");
2384 return;
2387 expected_refcount = get_refcount(device) + 1;
2388 hr = ID3D11Device_CreateDeferredContext(device, 0, &context);
2389 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
2390 refcount = get_refcount(device);
2391 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2392 refcount = get_refcount(context);
2393 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2395 check_interface(context, &IID_IUnknown, TRUE, FALSE);
2396 check_interface(context, &IID_ID3D11DeviceChild, TRUE, FALSE);
2397 check_interface(context, &IID_ID3D11DeviceContext, TRUE, FALSE);
2398 check_interface(context, &IID_ID3D11Multithread, FALSE, FALSE);
2400 refcount = ID3D11DeviceContext_Release(context);
2401 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2403 refcount = ID3D11Device_Release(device);
2404 ok(!refcount, "Device has %u references left.\n", refcount);
2407 static void test_create_texture1d(void)
2409 ULONG refcount, expected_refcount;
2410 D3D11_SUBRESOURCE_DATA data = {0};
2411 ID3D11Device *device, *tmp;
2412 D3D11_TEXTURE1D_DESC desc;
2413 ID3D11Texture1D *texture;
2414 unsigned int i;
2415 HRESULT hr;
2417 if (!(device = create_device(NULL)))
2419 skip("Failed to create device.\n");
2420 return;
2423 desc.Width = 512;
2424 desc.MipLevels = 1;
2425 desc.ArraySize = 1;
2426 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2427 desc.Usage = D3D11_USAGE_DEFAULT;
2428 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2429 desc.CPUAccessFlags = 0;
2430 desc.MiscFlags = 0;
2432 hr = ID3D11Device_CreateTexture1D(device, &desc, &data, &texture);
2433 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2435 expected_refcount = get_refcount(device) + 1;
2436 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2437 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2438 refcount = get_refcount(device);
2439 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2440 tmp = NULL;
2441 expected_refcount = refcount + 1;
2442 ID3D11Texture1D_GetDevice(texture, &tmp);
2443 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2444 refcount = get_refcount(device);
2445 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2446 ID3D11Device_Release(tmp);
2448 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2449 ID3D11Texture1D_Release(texture);
2451 desc.MipLevels = 0;
2452 expected_refcount = get_refcount(device) + 1;
2453 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2454 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2455 refcount = get_refcount(device);
2456 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2457 tmp = NULL;
2458 expected_refcount = refcount + 1;
2459 ID3D11Texture1D_GetDevice(texture, &tmp);
2460 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2461 refcount = get_refcount(device);
2462 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2463 ID3D11Device_Release(tmp);
2465 ID3D11Texture1D_GetDesc(texture, &desc);
2466 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2467 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2468 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2469 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2470 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2471 ok(desc.BindFlags == D3D11_BIND_SHADER_RESOURCE, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
2472 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
2473 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
2475 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2476 ID3D11Texture1D_Release(texture);
2478 desc.MipLevels = 1;
2479 desc.ArraySize = 2;
2480 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2481 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2483 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2484 ID3D11Texture1D_Release(texture);
2486 for (i = 0; i < 4; ++i)
2488 desc.ArraySize = i;
2489 desc.Format = DXGI_FORMAT_R32G32B32A32_TYPELESS;
2490 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2491 desc.MiscFlags = 0;
2492 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2493 ok(hr == (i ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2494 if (SUCCEEDED(hr))
2495 ID3D11Texture1D_Release(texture);
2498 refcount = ID3D11Device_Release(device);
2499 ok(!refcount, "Device has %u references left.\n", refcount);
2502 static void test_texture1d_interfaces(void)
2504 ID3D10Texture1D *d3d10_texture;
2505 D3D11_TEXTURE1D_DESC desc;
2506 ID3D11Texture1D *texture;
2507 ID3D11Device *device;
2508 unsigned int i;
2509 ULONG refcount;
2510 HRESULT hr;
2512 static const struct test
2514 BOOL implements_d3d10_interfaces;
2515 UINT bind_flags;
2516 UINT misc_flags;
2517 UINT expected_bind_flags;
2518 UINT expected_misc_flags;
2520 desc_conversion_tests[] =
2523 TRUE,
2524 D3D11_BIND_SHADER_RESOURCE, 0,
2525 D3D10_BIND_SHADER_RESOURCE, 0
2528 TRUE,
2529 D3D11_BIND_UNORDERED_ACCESS, 0,
2530 D3D11_BIND_UNORDERED_ACCESS, 0
2533 FALSE,
2534 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2535 0, 0
2538 TRUE,
2539 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2540 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2544 if (!(device = create_device(NULL)))
2546 skip("Failed to create ID3D11Device, skipping tests.\n");
2547 return;
2550 desc.Width = 512;
2551 desc.MipLevels = 0;
2552 desc.ArraySize = 1;
2553 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2554 desc.Usage = D3D11_USAGE_DEFAULT;
2555 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2556 desc.CPUAccessFlags = 0;
2557 desc.MiscFlags = 0;
2559 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2560 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2561 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2562 hr = check_interface(texture, &IID_ID3D10Texture1D, TRUE, TRUE); /* Not available on all Windows versions. */
2563 ID3D11Texture1D_Release(texture);
2564 if (FAILED(hr))
2566 win_skip("1D textures do not implement ID3D10Texture1D, skipping tests.\n");
2567 ID3D11Device_Release(device);
2568 return;
2571 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2573 const struct test *current = &desc_conversion_tests[i];
2574 D3D10_TEXTURE1D_DESC d3d10_desc;
2575 ID3D10Device *d3d10_device;
2577 desc.Width = 512;
2578 desc.MipLevels = 1;
2579 desc.ArraySize = 1;
2580 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2581 desc.Usage = D3D11_USAGE_DEFAULT;
2582 desc.BindFlags = current->bind_flags;
2583 desc.CPUAccessFlags = 0;
2584 desc.MiscFlags = current->misc_flags;
2586 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2587 /* Shared resources are not supported by REF and WARP devices. */
2588 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2589 "Test %u: Failed to create a 1d texture, hr %#x.\n", i, hr);
2590 if (FAILED(hr))
2592 win_skip("Failed to create ID3D11Texture1D, skipping test %u.\n", i);
2593 continue;
2596 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2598 hr = ID3D11Texture1D_QueryInterface(texture, &IID_ID3D10Texture1D, (void **)&d3d10_texture);
2599 ID3D11Texture1D_Release(texture);
2601 if (current->implements_d3d10_interfaces)
2603 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture1D.\n", i);
2605 else
2607 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture1D.\n", i);
2608 if (SUCCEEDED(hr)) ID3D10Texture1D_Release(d3d10_texture);
2609 continue;
2612 ID3D10Texture1D_GetDesc(d3d10_texture, &d3d10_desc);
2614 ok(d3d10_desc.Width == desc.Width,
2615 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2616 ok(d3d10_desc.MipLevels == desc.MipLevels,
2617 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2618 ok(d3d10_desc.ArraySize == desc.ArraySize,
2619 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2620 ok(d3d10_desc.Format == desc.Format,
2621 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2622 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2623 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2624 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2625 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2626 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2627 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2629 d3d10_device = (ID3D10Device *)0xdeadbeef;
2630 ID3D10Texture1D_GetDevice(d3d10_texture, &d3d10_device);
2631 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2632 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2634 ID3D10Texture1D_Release(d3d10_texture);
2637 refcount = ID3D11Device_Release(device);
2638 ok(!refcount, "Device has %u references left.\n", refcount);
2641 static void test_create_texture2d(void)
2643 ULONG refcount, expected_refcount;
2644 D3D11_SUBRESOURCE_DATA data = {0};
2645 D3D_FEATURE_LEVEL feature_level;
2646 ID3D11Device *device, *tmp;
2647 D3D11_TEXTURE2D_DESC desc;
2648 ID3D11Texture2D *texture;
2649 UINT quality_level_count;
2650 unsigned int i;
2651 HRESULT hr;
2653 static const struct
2655 DXGI_FORMAT format;
2656 UINT array_size;
2657 D3D11_BIND_FLAG bind_flags;
2658 UINT misc_flags;
2659 BOOL succeeds;
2660 BOOL todo;
2662 tests[] =
2664 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
2665 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
2666 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
2667 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
2668 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2669 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2670 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2671 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2672 FALSE, FALSE},
2673 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2674 FALSE, FALSE},
2675 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2676 FALSE, FALSE},
2677 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2678 TRUE, FALSE},
2679 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2680 TRUE, FALSE},
2681 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2682 TRUE, FALSE},
2683 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2684 TRUE, FALSE},
2685 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2686 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2687 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2688 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2689 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2690 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2691 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2692 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2693 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2694 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2695 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2696 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2697 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2698 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2699 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2700 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2701 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2702 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2703 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2704 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
2705 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2706 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2707 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
2708 TRUE, FALSE},
2709 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2710 TRUE, FALSE},
2711 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2712 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
2713 FALSE, TRUE},
2714 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2715 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
2716 FALSE, TRUE},
2717 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
2718 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
2719 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
2720 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2721 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2722 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2723 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2724 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2725 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2726 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2727 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2728 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2729 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2730 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2731 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2732 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2733 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2734 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2735 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2736 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2737 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2738 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2739 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
2740 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2741 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
2742 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
2743 FALSE, TRUE},
2744 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2745 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2746 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2747 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2748 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2751 if (!(device = create_device(NULL)))
2753 skip("Failed to create device.\n");
2754 return;
2757 feature_level = ID3D11Device_GetFeatureLevel(device);
2759 desc.Width = 512;
2760 desc.Height = 512;
2761 desc.MipLevels = 1;
2762 desc.ArraySize = 1;
2763 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2764 desc.SampleDesc.Count = 1;
2765 desc.SampleDesc.Quality = 0;
2766 desc.Usage = D3D11_USAGE_DEFAULT;
2767 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2768 desc.CPUAccessFlags = 0;
2769 desc.MiscFlags = 0;
2771 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
2772 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2774 expected_refcount = get_refcount(device) + 1;
2775 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2776 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2777 refcount = get_refcount(device);
2778 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2779 tmp = NULL;
2780 expected_refcount = refcount + 1;
2781 ID3D11Texture2D_GetDevice(texture, &tmp);
2782 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2783 refcount = get_refcount(device);
2784 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2785 ID3D11Device_Release(tmp);
2787 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2788 ID3D11Texture2D_Release(texture);
2790 desc.MipLevels = 0;
2791 expected_refcount = get_refcount(device) + 1;
2792 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2793 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2794 refcount = get_refcount(device);
2795 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2796 tmp = NULL;
2797 expected_refcount = refcount + 1;
2798 ID3D11Texture2D_GetDevice(texture, &tmp);
2799 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2800 refcount = get_refcount(device);
2801 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2802 ID3D11Device_Release(tmp);
2804 ID3D11Texture2D_GetDesc(texture, &desc);
2805 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2806 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
2807 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2808 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2809 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2810 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
2811 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
2812 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2813 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
2814 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
2815 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
2817 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2818 ID3D11Texture2D_Release(texture);
2820 desc.MipLevels = 1;
2821 desc.ArraySize = 2;
2822 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2823 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2825 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2826 ID3D11Texture2D_Release(texture);
2828 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
2829 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
2830 desc.ArraySize = 1;
2831 desc.SampleDesc.Count = 2;
2832 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2833 if (quality_level_count)
2835 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
2836 ID3D11Texture2D_Release(texture);
2837 desc.SampleDesc.Quality = quality_level_count;
2838 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2840 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2842 /* We assume 15 samples multisampling is never supported in practice. */
2843 desc.SampleDesc.Count = 15;
2844 desc.SampleDesc.Quality = 0;
2845 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2846 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2848 desc.SampleDesc.Count = 1;
2849 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2851 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
2852 BOOL todo = tests[i].todo;
2854 if (feature_level < D3D_FEATURE_LEVEL_10_1
2855 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
2856 && tests[i].array_size > 6)
2858 expected_hr = E_INVALIDARG;
2859 todo = TRUE;
2862 desc.ArraySize = tests[i].array_size;
2863 desc.Format = tests[i].format;
2864 desc.BindFlags = tests[i].bind_flags;
2865 desc.MiscFlags = tests[i].misc_flags;
2866 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2868 todo_wine_if(todo)
2869 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
2870 i, hr, desc.Format);
2872 if (SUCCEEDED(hr))
2873 ID3D11Texture2D_Release(texture);
2876 refcount = ID3D11Device_Release(device);
2877 ok(!refcount, "Device has %u references left.\n", refcount);
2880 static void test_texture2d_interfaces(void)
2882 ID3D10Texture2D *d3d10_texture;
2883 D3D11_TEXTURE2D_DESC desc;
2884 ID3D11Texture2D *texture;
2885 ID3D11Device *device;
2886 unsigned int i;
2887 ULONG refcount;
2888 HRESULT hr;
2890 static const struct test
2892 BOOL implements_d3d10_interfaces;
2893 UINT bind_flags;
2894 UINT misc_flags;
2895 UINT expected_bind_flags;
2896 UINT expected_misc_flags;
2898 desc_conversion_tests[] =
2901 TRUE,
2902 D3D11_BIND_SHADER_RESOURCE, 0,
2903 D3D10_BIND_SHADER_RESOURCE, 0
2906 TRUE,
2907 D3D11_BIND_UNORDERED_ACCESS, 0,
2908 D3D11_BIND_UNORDERED_ACCESS, 0
2911 FALSE,
2912 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2913 0, 0
2916 TRUE,
2917 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2918 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2921 TRUE,
2922 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
2923 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2927 if (!(device = create_device(NULL)))
2929 skip("Failed to create ID3D11Device, skipping tests.\n");
2930 return;
2933 desc.Width = 512;
2934 desc.Height = 512;
2935 desc.MipLevels = 0;
2936 desc.ArraySize = 1;
2937 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2938 desc.SampleDesc.Count = 1;
2939 desc.SampleDesc.Quality = 0;
2940 desc.Usage = D3D11_USAGE_DEFAULT;
2941 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2942 desc.CPUAccessFlags = 0;
2943 desc.MiscFlags = 0;
2945 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2946 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2947 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2948 hr = check_interface(texture, &IID_ID3D10Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
2949 ID3D11Texture2D_Release(texture);
2950 if (FAILED(hr))
2952 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
2953 ID3D11Device_Release(device);
2954 return;
2957 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2959 const struct test *current = &desc_conversion_tests[i];
2960 D3D10_TEXTURE2D_DESC d3d10_desc;
2961 ID3D10Device *d3d10_device;
2963 desc.Width = 512;
2964 desc.Height = 512;
2965 desc.MipLevels = 1;
2966 desc.ArraySize = 1;
2967 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2968 desc.SampleDesc.Count = 1;
2969 desc.SampleDesc.Quality = 0;
2970 desc.Usage = D3D11_USAGE_DEFAULT;
2971 desc.BindFlags = current->bind_flags;
2972 desc.CPUAccessFlags = 0;
2973 desc.MiscFlags = current->misc_flags;
2975 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2976 /* Shared resources are not supported by REF and WARP devices. */
2977 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2978 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2979 if (FAILED(hr))
2981 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
2982 continue;
2985 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2987 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2988 ID3D11Texture2D_Release(texture);
2990 if (current->implements_d3d10_interfaces)
2992 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2994 else
2996 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2997 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2998 continue;
3001 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
3003 ok(d3d10_desc.Width == desc.Width,
3004 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
3005 ok(d3d10_desc.Height == desc.Height,
3006 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
3007 ok(d3d10_desc.MipLevels == desc.MipLevels,
3008 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
3009 ok(d3d10_desc.ArraySize == desc.ArraySize,
3010 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
3011 ok(d3d10_desc.Format == desc.Format,
3012 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
3013 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
3014 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
3015 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
3016 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
3017 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3018 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3019 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3020 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3021 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3022 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3023 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3024 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3026 d3d10_device = (ID3D10Device *)0xdeadbeef;
3027 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
3028 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3029 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3031 ID3D10Texture2D_Release(d3d10_texture);
3034 refcount = ID3D11Device_Release(device);
3035 ok(!refcount, "Device has %u references left.\n", refcount);
3038 static void test_create_texture3d(void)
3040 ULONG refcount, expected_refcount;
3041 D3D11_SUBRESOURCE_DATA data = {0};
3042 ID3D11Device *device, *tmp;
3043 D3D11_TEXTURE3D_DESC desc;
3044 ID3D11Texture3D *texture;
3045 unsigned int i;
3046 HRESULT hr;
3048 static const struct
3050 DXGI_FORMAT format;
3051 D3D11_BIND_FLAG bind_flags;
3052 BOOL succeeds;
3053 BOOL todo;
3055 tests[] =
3057 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
3058 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
3059 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
3060 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
3061 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
3062 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
3063 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
3064 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
3065 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
3066 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
3067 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
3068 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
3071 if (!(device = create_device(NULL)))
3073 skip("Failed to create ID3D11Device, skipping tests.\n");
3074 return;
3077 desc.Width = 64;
3078 desc.Height = 64;
3079 desc.Depth = 64;
3080 desc.MipLevels = 1;
3081 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3082 desc.Usage = D3D11_USAGE_DEFAULT;
3083 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3084 desc.CPUAccessFlags = 0;
3085 desc.MiscFlags = 0;
3087 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
3088 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3090 expected_refcount = get_refcount(device) + 1;
3091 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3092 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
3093 refcount = get_refcount(device);
3094 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3095 tmp = NULL;
3096 expected_refcount = refcount + 1;
3097 ID3D11Texture3D_GetDevice(texture, &tmp);
3098 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3099 refcount = get_refcount(device);
3100 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3101 ID3D11Device_Release(tmp);
3103 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3104 ID3D11Texture3D_Release(texture);
3106 desc.MipLevels = 0;
3107 expected_refcount = get_refcount(device) + 1;
3108 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3109 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
3110 refcount = get_refcount(device);
3111 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3112 tmp = NULL;
3113 expected_refcount = refcount + 1;
3114 ID3D11Texture3D_GetDevice(texture, &tmp);
3115 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3116 refcount = get_refcount(device);
3117 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3118 ID3D11Device_Release(tmp);
3120 ID3D11Texture3D_GetDesc(texture, &desc);
3121 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
3122 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
3123 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
3124 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
3125 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
3126 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
3127 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
3128 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
3129 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
3131 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3132 ID3D11Texture3D_Release(texture);
3134 desc.MipLevels = 1;
3135 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3137 desc.Format = tests[i].format;
3138 desc.BindFlags = tests[i].bind_flags;
3139 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3141 todo_wine_if(tests[i].todo)
3142 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
3144 if (SUCCEEDED(hr))
3145 ID3D11Texture3D_Release(texture);
3148 refcount = ID3D11Device_Release(device);
3149 ok(!refcount, "Device has %u references left.\n", refcount);
3152 static void test_texture3d_interfaces(void)
3154 ID3D10Texture3D *d3d10_texture;
3155 D3D11_TEXTURE3D_DESC desc;
3156 ID3D11Texture3D *texture;
3157 ID3D11Device *device;
3158 unsigned int i;
3159 ULONG refcount;
3160 HRESULT hr;
3162 static const struct test
3164 BOOL implements_d3d10_interfaces;
3165 UINT bind_flags;
3166 UINT misc_flags;
3167 UINT expected_bind_flags;
3168 UINT expected_misc_flags;
3170 desc_conversion_tests[] =
3173 TRUE,
3174 D3D11_BIND_SHADER_RESOURCE, 0,
3175 D3D10_BIND_SHADER_RESOURCE, 0
3178 TRUE,
3179 D3D11_BIND_UNORDERED_ACCESS, 0,
3180 D3D11_BIND_UNORDERED_ACCESS, 0
3183 FALSE,
3184 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
3185 0, 0
3188 TRUE,
3189 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
3190 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
3194 if (!(device = create_device(NULL)))
3196 skip("Failed to create ID3D11Device.\n");
3197 return;
3200 desc.Width = 64;
3201 desc.Height = 64;
3202 desc.Depth = 64;
3203 desc.MipLevels = 0;
3204 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3205 desc.Usage = D3D11_USAGE_DEFAULT;
3206 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3207 desc.CPUAccessFlags = 0;
3208 desc.MiscFlags = 0;
3210 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3211 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
3212 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3213 hr = check_interface(texture, &IID_ID3D10Texture3D, TRUE, TRUE); /* Not available on all Windows versions. */
3214 ID3D11Texture3D_Release(texture);
3215 if (FAILED(hr))
3217 win_skip("3D textures do not implement ID3D10Texture3D.\n");
3218 ID3D11Device_Release(device);
3219 return;
3222 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
3224 const struct test *current = &desc_conversion_tests[i];
3225 D3D10_TEXTURE3D_DESC d3d10_desc;
3226 ID3D10Device *d3d10_device;
3228 desc.Width = 64;
3229 desc.Height = 64;
3230 desc.Depth = 64;
3231 desc.MipLevels = 1;
3232 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3233 desc.Usage = D3D11_USAGE_DEFAULT;
3234 desc.BindFlags = current->bind_flags;
3235 desc.CPUAccessFlags = 0;
3236 desc.MiscFlags = current->misc_flags;
3238 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3239 /* Shared resources are not supported by REF and WARP devices. */
3240 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
3241 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
3242 if (FAILED(hr))
3244 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
3245 continue;
3248 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3250 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
3251 ID3D11Texture3D_Release(texture);
3253 if (current->implements_d3d10_interfaces)
3255 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
3257 else
3259 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
3260 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
3261 continue;
3264 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
3266 ok(d3d10_desc.Width == desc.Width,
3267 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
3268 ok(d3d10_desc.Height == desc.Height,
3269 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
3270 ok(d3d10_desc.Depth == desc.Depth,
3271 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
3272 ok(d3d10_desc.MipLevels == desc.MipLevels,
3273 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
3274 ok(d3d10_desc.Format == desc.Format,
3275 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
3276 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3277 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3278 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3279 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3280 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3281 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3282 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3283 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3285 d3d10_device = (ID3D10Device *)0xdeadbeef;
3286 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
3287 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3288 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3290 ID3D10Texture3D_Release(d3d10_texture);
3293 refcount = ID3D11Device_Release(device);
3294 ok(!refcount, "Device has %u references left.\n", refcount);
3297 static void test_create_buffer(void)
3299 ID3D10Buffer *d3d10_buffer;
3300 HRESULT expected_hr, hr;
3301 D3D11_BUFFER_DESC desc;
3302 ID3D11Buffer *buffer;
3303 ID3D11Device *device;
3304 unsigned int i;
3305 ULONG refcount;
3307 static const struct test
3309 BOOL succeeds;
3310 BOOL implements_d3d10_interfaces;
3311 UINT bind_flags;
3312 UINT misc_flags;
3313 UINT structure_stride;
3314 UINT expected_bind_flags;
3315 UINT expected_misc_flags;
3317 tests[] =
3320 TRUE, TRUE,
3321 D3D11_BIND_VERTEX_BUFFER, 0, 0,
3322 D3D10_BIND_VERTEX_BUFFER, 0
3325 TRUE, TRUE,
3326 D3D11_BIND_INDEX_BUFFER, 0, 0,
3327 D3D10_BIND_INDEX_BUFFER, 0
3330 TRUE, TRUE,
3331 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
3332 D3D10_BIND_CONSTANT_BUFFER, 0
3335 TRUE, TRUE,
3336 D3D11_BIND_SHADER_RESOURCE, 0, 0,
3337 D3D10_BIND_SHADER_RESOURCE, 0
3340 TRUE, TRUE,
3341 D3D11_BIND_STREAM_OUTPUT, 0, 0,
3342 D3D10_BIND_STREAM_OUTPUT, 0
3345 TRUE, TRUE,
3346 D3D11_BIND_RENDER_TARGET, 0, 0,
3347 D3D10_BIND_RENDER_TARGET, 0
3350 TRUE, TRUE,
3351 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
3352 D3D11_BIND_UNORDERED_ACCESS, 0
3355 TRUE, TRUE,
3356 0, D3D11_RESOURCE_MISC_SHARED, 0,
3357 0, D3D10_RESOURCE_MISC_SHARED
3360 TRUE, TRUE,
3361 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
3362 0, 0
3365 FALSE, FALSE,
3366 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3369 FALSE, FALSE,
3370 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3373 FALSE, FALSE,
3374 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3377 TRUE, TRUE,
3378 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3379 D3D10_BIND_SHADER_RESOURCE, 0
3382 FALSE, FALSE,
3383 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3386 FALSE, FALSE,
3387 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3390 TRUE, TRUE,
3391 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3392 D3D11_BIND_UNORDERED_ACCESS, 0
3395 FALSE, FALSE,
3396 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3398 /* Structured buffers do not implement ID3D10Buffer. */
3400 TRUE, FALSE,
3401 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3404 TRUE, FALSE,
3405 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3408 FALSE, FALSE,
3409 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
3412 FALSE, FALSE,
3413 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
3416 FALSE, FALSE,
3417 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
3420 FALSE, FALSE,
3421 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
3424 FALSE, FALSE,
3425 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
3428 TRUE, FALSE,
3429 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
3432 FALSE, FALSE,
3433 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
3436 TRUE, FALSE,
3437 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
3440 TRUE, FALSE,
3441 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
3444 FALSE, FALSE,
3445 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
3448 TRUE, FALSE,
3449 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
3452 TRUE, TRUE,
3453 0, 0, 513,
3454 0, 0
3457 TRUE, TRUE,
3458 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
3459 D3D10_BIND_CONSTANT_BUFFER, 0
3462 TRUE, TRUE,
3463 D3D11_BIND_SHADER_RESOURCE, 0, 513,
3464 D3D10_BIND_SHADER_RESOURCE, 0
3467 TRUE, TRUE,
3468 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
3469 D3D11_BIND_UNORDERED_ACCESS, 0
3472 FALSE, FALSE,
3473 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3476 FALSE, FALSE,
3477 D3D11_BIND_SHADER_RESOURCE,
3478 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3481 TRUE, TRUE,
3482 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
3483 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
3487 if (!(device = create_device(NULL)))
3489 skip("Failed to create ID3D11Device.\n");
3490 return;
3493 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
3494 hr = check_interface(buffer, &IID_ID3D10Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
3495 ID3D11Buffer_Release(buffer);
3496 if (FAILED(hr))
3498 win_skip("Buffers do not implement ID3D10Buffer.\n");
3499 ID3D11Device_Release(device);
3500 return;
3503 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3505 const struct test *current = &tests[i];
3506 D3D11_BUFFER_DESC obtained_desc;
3507 D3D10_BUFFER_DESC d3d10_desc;
3508 ID3D10Device *d3d10_device;
3510 desc.ByteWidth = 1024;
3511 desc.Usage = D3D11_USAGE_DEFAULT;
3512 desc.BindFlags = current->bind_flags;
3513 desc.CPUAccessFlags = 0;
3514 desc.MiscFlags = current->misc_flags;
3515 desc.StructureByteStride = current->structure_stride;
3517 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
3518 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
3519 /* Shared resources are not supported by REF and WARP devices. */
3520 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
3521 i, hr, expected_hr);
3522 if (FAILED(hr))
3524 if (hr == E_OUTOFMEMORY)
3525 win_skip("Failed to create a buffer, skipping test %u.\n", i);
3526 continue;
3529 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
3530 desc.StructureByteStride = 0;
3532 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
3534 ok(obtained_desc.ByteWidth == desc.ByteWidth,
3535 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
3536 ok(obtained_desc.Usage == desc.Usage,
3537 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
3538 ok(obtained_desc.BindFlags == desc.BindFlags,
3539 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
3540 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
3541 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
3542 ok(obtained_desc.MiscFlags == desc.MiscFlags,
3543 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
3544 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
3545 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
3547 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
3548 ID3D11Buffer_Release(buffer);
3550 if (current->implements_d3d10_interfaces)
3552 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
3554 else
3556 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
3557 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
3558 continue;
3561 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
3563 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
3564 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
3565 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3566 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3567 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3568 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3569 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3570 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3571 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3572 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3574 d3d10_device = (ID3D10Device *)0xdeadbeef;
3575 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
3576 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3577 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3579 ID3D10Buffer_Release(d3d10_buffer);
3582 memset(&desc, 0, sizeof(desc));
3583 desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
3584 for (i = 0; i <= 32; ++i)
3586 desc.ByteWidth = i;
3587 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
3588 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
3589 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
3590 if (SUCCEEDED(hr))
3591 ID3D11Buffer_Release(buffer);
3594 refcount = ID3D11Device_Release(device);
3595 ok(!refcount, "Device has %u references left.\n", refcount);
3598 static void test_create_depthstencil_view(void)
3600 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
3601 D3D11_TEXTURE2D_DESC texture_desc;
3602 ULONG refcount, expected_refcount;
3603 ID3D11DepthStencilView *dsview;
3604 ID3D11Device *device, *tmp;
3605 ID3D11Texture2D *texture;
3606 unsigned int i;
3607 HRESULT hr;
3609 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3610 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
3611 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
3612 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
3613 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
3614 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
3615 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
3616 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
3617 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
3618 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
3619 static const struct
3621 struct
3623 unsigned int miplevel_count;
3624 unsigned int array_size;
3625 DXGI_FORMAT format;
3626 } texture;
3627 struct dsv_desc dsv_desc;
3628 struct dsv_desc expected_dsv_desc;
3630 tests[] =
3632 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
3633 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
3634 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3635 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
3636 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
3637 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3638 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3639 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3640 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3641 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3642 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
3643 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
3644 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
3645 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
3646 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
3647 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
3648 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
3649 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3650 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3651 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3652 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3653 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3654 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3655 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3656 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3657 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
3658 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
3660 static const struct
3662 struct
3664 unsigned int miplevel_count;
3665 unsigned int array_size;
3666 DXGI_FORMAT format;
3667 } texture;
3668 struct dsv_desc dsv_desc;
3670 invalid_desc_tests[] =
3672 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
3673 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
3674 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
3675 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
3676 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
3677 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3678 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
3679 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
3680 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
3681 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
3682 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
3683 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
3684 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
3686 #undef FMT_UNKNOWN
3687 #undef D24S8
3688 #undef R24G8_TL
3689 #undef DIM_UNKNOWN
3690 #undef TEX_1D
3691 #undef TEX_1D_ARRAY
3692 #undef TEX_2D
3693 #undef TEX_2D_ARRAY
3694 #undef TEX_2DMS
3695 #undef TEX_2DMS_ARR
3697 if (!(device = create_device(NULL)))
3699 skip("Failed to create device.\n");
3700 return;
3703 texture_desc.Width = 512;
3704 texture_desc.Height = 512;
3705 texture_desc.MipLevels = 1;
3706 texture_desc.ArraySize = 1;
3707 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
3708 texture_desc.SampleDesc.Count = 1;
3709 texture_desc.SampleDesc.Quality = 0;
3710 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3711 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3712 texture_desc.CPUAccessFlags = 0;
3713 texture_desc.MiscFlags = 0;
3715 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3716 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
3718 expected_refcount = get_refcount(device) + 1;
3719 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
3720 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
3721 refcount = get_refcount(device);
3722 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3723 tmp = NULL;
3724 expected_refcount = refcount + 1;
3725 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
3726 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3727 refcount = get_refcount(device);
3728 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3729 ID3D11Device_Release(tmp);
3731 memset(&dsv_desc, 0, sizeof(dsv_desc));
3732 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
3733 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
3734 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
3735 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
3736 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
3737 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
3739 ID3D11DepthStencilView_Release(dsview);
3740 ID3D11Texture2D_Release(texture);
3742 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3744 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
3746 texture_desc.MipLevels = tests[i].texture.miplevel_count;
3747 texture_desc.ArraySize = tests[i].texture.array_size;
3748 texture_desc.Format = tests[i].texture.format;
3750 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3751 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3753 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
3755 current_desc = NULL;
3757 else
3759 current_desc = &dsv_desc;
3760 get_dsv_desc(current_desc, &tests[i].dsv_desc);
3763 expected_refcount = get_refcount(texture);
3764 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
3765 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
3766 refcount = get_refcount(texture);
3767 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3769 /* Not available on all Windows versions. */
3770 check_interface(dsview, &IID_ID3D10DepthStencilView, TRUE, TRUE);
3772 memset(&dsv_desc, 0, sizeof(dsv_desc));
3773 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
3774 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
3776 ID3D11DepthStencilView_Release(dsview);
3777 ID3D11Texture2D_Release(texture);
3780 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3782 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3783 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
3784 texture_desc.Format = invalid_desc_tests[i].texture.format;
3786 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3787 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3789 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
3790 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
3791 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3793 ID3D11Texture2D_Release(texture);
3796 refcount = ID3D11Device_Release(device);
3797 ok(!refcount, "Device has %u references left.\n", refcount);
3800 static void test_depthstencil_view_interfaces(void)
3802 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
3803 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
3804 ID3D10DepthStencilView *d3d10_dsview;
3805 D3D11_TEXTURE2D_DESC texture_desc;
3806 ID3D11DepthStencilView *dsview;
3807 ID3D11Texture2D *texture;
3808 ID3D11Device *device;
3809 ULONG refcount;
3810 HRESULT hr;
3812 if (!(device = create_device(NULL)))
3814 skip("Failed to create device.\n");
3815 return;
3818 texture_desc.Width = 512;
3819 texture_desc.Height = 512;
3820 texture_desc.MipLevels = 1;
3821 texture_desc.ArraySize = 1;
3822 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
3823 texture_desc.SampleDesc.Count = 1;
3824 texture_desc.SampleDesc.Quality = 0;
3825 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3826 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3827 texture_desc.CPUAccessFlags = 0;
3828 texture_desc.MiscFlags = 0;
3830 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3831 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
3833 dsv_desc.Format = texture_desc.Format;
3834 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
3835 dsv_desc.Flags = 0;
3836 U(dsv_desc).Texture2D.MipSlice = 0;
3838 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
3839 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
3841 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
3842 ID3D11DepthStencilView_Release(dsview);
3843 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3844 "Depth stencil view should implement ID3D10DepthStencilView.\n");
3846 if (FAILED(hr))
3848 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
3849 goto done;
3852 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
3853 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
3854 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
3855 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
3856 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
3857 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
3859 ID3D10DepthStencilView_Release(d3d10_dsview);
3861 done:
3862 ID3D11Texture2D_Release(texture);
3864 refcount = ID3D11Device_Release(device);
3865 ok(!refcount, "Device has %u references left.\n", refcount);
3868 static void test_create_rendertarget_view(void)
3870 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
3871 D3D11_TEXTURE3D_DESC texture3d_desc;
3872 D3D11_TEXTURE2D_DESC texture2d_desc;
3873 D3D11_SUBRESOURCE_DATA data = {0};
3874 ULONG refcount, expected_refcount;
3875 D3D11_BUFFER_DESC buffer_desc;
3876 ID3D11RenderTargetView *rtview;
3877 ID3D11Device *device, *tmp;
3878 ID3D11Texture3D *texture3d;
3879 ID3D11Texture2D *texture2d;
3880 ID3D11Resource *texture;
3881 ID3D11Buffer *buffer;
3882 unsigned int i;
3883 HRESULT hr;
3885 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3886 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3887 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3888 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
3889 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
3890 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
3891 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
3892 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
3893 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
3894 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
3895 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
3896 static const struct
3898 struct
3900 unsigned int miplevel_count;
3901 unsigned int depth_or_array_size;
3902 DXGI_FORMAT format;
3903 } texture;
3904 struct rtv_desc rtv_desc;
3905 struct rtv_desc expected_rtv_desc;
3907 tests[] =
3909 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
3910 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
3911 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3912 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
3913 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
3914 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3915 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3916 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3917 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3918 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3919 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
3920 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
3921 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
3922 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
3923 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
3924 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
3925 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
3926 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3927 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3928 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3929 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3930 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3931 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3932 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3933 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3934 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3935 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3936 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3937 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3938 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3939 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3940 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3941 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
3942 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
3943 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
3944 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
3945 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3946 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3947 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
3948 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
3949 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
3950 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
3951 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
3952 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
3954 static const struct
3956 struct
3958 D3D11_RTV_DIMENSION dimension;
3959 unsigned int miplevel_count;
3960 unsigned int depth_or_array_size;
3961 DXGI_FORMAT format;
3962 } texture;
3963 struct rtv_desc rtv_desc;
3965 invalid_desc_tests[] =
3967 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3968 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3969 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3970 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3971 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
3972 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
3973 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
3974 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3975 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
3976 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
3977 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
3978 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
3979 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
3980 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
3981 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
3982 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3983 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3984 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3985 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3986 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3987 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3988 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3989 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3990 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
3991 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3992 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3993 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3994 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3995 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3996 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3997 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3998 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3999 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
4000 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
4001 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
4003 #undef FMT_UNKNOWN
4004 #undef RGBA8_UNORM
4005 #undef RGBA8_TL
4006 #undef DIM_UNKNOWN
4007 #undef TEX_1D
4008 #undef TEX_1D_ARRAY
4009 #undef TEX_2D
4010 #undef TEX_2D_ARRAY
4011 #undef TEX_2DMS
4012 #undef TEX_2DMS_ARR
4013 #undef TEX_3D
4015 if (!(device = create_device(NULL)))
4017 skip("Failed to create device.\n");
4018 return;
4021 buffer_desc.ByteWidth = 1024;
4022 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4023 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4024 buffer_desc.CPUAccessFlags = 0;
4025 buffer_desc.MiscFlags = 0;
4026 buffer_desc.StructureByteStride = 0;
4028 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
4029 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4031 expected_refcount = get_refcount(device) + 1;
4032 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
4033 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
4034 refcount = get_refcount(device);
4035 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4036 tmp = NULL;
4037 expected_refcount = refcount + 1;
4038 ID3D11Buffer_GetDevice(buffer, &tmp);
4039 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4040 refcount = get_refcount(device);
4041 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4042 ID3D11Device_Release(tmp);
4044 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4045 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
4046 U1(U(rtv_desc).Buffer).ElementOffset = 0;
4047 U2(U(rtv_desc).Buffer).ElementWidth = 64;
4049 if (!enable_debug_layer)
4051 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
4052 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4055 expected_refcount = get_refcount(device) + 1;
4056 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
4057 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
4058 refcount = get_refcount(device);
4059 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4060 tmp = NULL;
4061 expected_refcount = refcount + 1;
4062 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
4063 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4064 refcount = get_refcount(device);
4065 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4066 ID3D11Device_Release(tmp);
4068 /* Not available on all Windows versions. */
4069 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
4071 ID3D11RenderTargetView_Release(rtview);
4072 ID3D11Buffer_Release(buffer);
4074 texture2d_desc.Width = 512;
4075 texture2d_desc.Height = 512;
4076 texture2d_desc.SampleDesc.Count = 1;
4077 texture2d_desc.SampleDesc.Quality = 0;
4078 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
4079 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4080 texture2d_desc.CPUAccessFlags = 0;
4081 texture2d_desc.MiscFlags = 0;
4083 texture3d_desc.Width = 64;
4084 texture3d_desc.Height = 64;
4085 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
4086 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
4087 texture3d_desc.CPUAccessFlags = 0;
4088 texture3d_desc.MiscFlags = 0;
4090 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4092 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
4094 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
4096 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
4097 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
4098 texture2d_desc.Format = tests[i].texture.format;
4100 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4101 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4102 texture = (ID3D11Resource *)texture2d;
4104 else
4106 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
4107 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
4108 texture3d_desc.Format = tests[i].texture.format;
4110 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4111 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4112 texture = (ID3D11Resource *)texture3d;
4115 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
4117 current_desc = NULL;
4119 else
4121 current_desc = &rtv_desc;
4122 get_rtv_desc(current_desc, &tests[i].rtv_desc);
4125 expected_refcount = get_refcount(texture);
4126 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
4127 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
4128 refcount = get_refcount(texture);
4129 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
4131 /* Not available on all Windows versions. */
4132 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
4134 memset(&rtv_desc, 0, sizeof(rtv_desc));
4135 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
4136 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
4138 ID3D11RenderTargetView_Release(rtview);
4139 ID3D11Resource_Release(texture);
4142 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
4144 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
4145 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
4147 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
4149 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4150 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
4151 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
4153 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4154 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4155 texture = (ID3D11Resource *)texture2d;
4157 else
4159 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4160 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
4161 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
4163 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4164 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4165 texture = (ID3D11Resource *)texture3d;
4168 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
4169 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
4170 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
4172 ID3D11Resource_Release(texture);
4175 refcount = ID3D11Device_Release(device);
4176 ok(!refcount, "Device has %u references left.\n", refcount);
4179 static void test_create_shader_resource_view(void)
4181 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
4182 D3D11_TEXTURE3D_DESC texture3d_desc;
4183 D3D11_TEXTURE2D_DESC texture2d_desc;
4184 ULONG refcount, expected_refcount;
4185 ID3D11ShaderResourceView *srview;
4186 D3D_FEATURE_LEVEL feature_level;
4187 D3D11_BUFFER_DESC buffer_desc;
4188 ID3D11Device *device, *tmp;
4189 ID3D11Texture3D *texture3d;
4190 ID3D11Texture2D *texture2d;
4191 ID3D11Resource *texture;
4192 ID3D11Buffer *buffer;
4193 unsigned int i;
4194 HRESULT hr;
4196 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
4197 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
4198 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
4199 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
4200 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
4201 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
4202 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
4203 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
4204 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
4205 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
4206 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
4207 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
4208 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
4209 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
4210 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
4211 static const struct
4213 struct
4215 unsigned int miplevel_count;
4216 unsigned int depth_or_array_size;
4217 DXGI_FORMAT format;
4218 } texture;
4219 struct srv_desc srv_desc;
4220 struct srv_desc expected_srv_desc;
4222 tests[] =
4224 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4225 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4226 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4227 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4228 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4229 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4230 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
4231 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
4232 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
4233 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
4234 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
4235 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
4236 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
4237 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
4238 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
4239 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4240 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4241 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4242 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4243 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4244 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4245 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4246 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4247 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
4248 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
4249 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4250 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4251 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4252 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
4253 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4254 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4255 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4256 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4257 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4258 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
4259 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
4260 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4261 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
4262 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4263 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4264 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4265 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4266 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4267 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4268 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4269 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
4270 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
4271 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
4273 static const struct
4275 struct
4277 D3D11_SRV_DIMENSION dimension;
4278 unsigned int miplevel_count;
4279 unsigned int depth_or_array_size;
4280 DXGI_FORMAT format;
4281 } texture;
4282 struct srv_desc srv_desc;
4284 invalid_desc_tests[] =
4286 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
4287 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
4288 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4289 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4290 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4291 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
4292 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
4293 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
4294 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
4295 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
4296 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
4297 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
4298 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
4299 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
4300 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
4301 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
4302 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
4303 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
4304 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
4305 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
4306 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
4307 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
4308 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4309 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
4310 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
4311 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
4312 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
4313 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
4314 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
4315 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
4316 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
4317 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
4318 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
4319 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
4320 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4321 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4322 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 1}},
4323 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4324 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 1}},
4325 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4326 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4327 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4328 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4329 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4330 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
4331 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4332 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4333 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4334 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4335 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
4336 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
4337 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
4338 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
4339 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
4340 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
4341 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
4343 #undef FMT_UNKNOWN
4344 #undef RGBA8_UNORM
4345 #undef RGBA8_SRGB
4346 #undef RGBA8_UINT
4347 #undef RGBA8_TL
4348 #undef DIM_UNKNOWN
4349 #undef TEX_1D
4350 #undef TEX_1D_ARRAY
4351 #undef TEX_2D
4352 #undef TEX_2D_ARRAY
4353 #undef TEX_2DMS
4354 #undef TEX_2DMS_ARR
4355 #undef TEX_3D
4356 #undef TEX_CUBE
4357 #undef CUBE_ARRAY
4359 if (!(device = create_device(NULL)))
4361 skip("Failed to create device.\n");
4362 return;
4364 feature_level = ID3D11Device_GetFeatureLevel(device);
4366 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
4368 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
4369 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4371 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4372 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
4373 U1(U(srv_desc).Buffer).ElementOffset = 0;
4374 U2(U(srv_desc).Buffer).ElementWidth = 64;
4376 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
4377 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4379 expected_refcount = get_refcount(device) + 1;
4380 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
4381 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
4382 refcount = get_refcount(device);
4383 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4384 tmp = NULL;
4385 expected_refcount = refcount + 1;
4386 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
4387 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4388 refcount = get_refcount(device);
4389 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4390 ID3D11Device_Release(tmp);
4392 /* Not available on all Windows versions. */
4393 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
4394 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
4396 ID3D11ShaderResourceView_Release(srview);
4397 ID3D11Buffer_Release(buffer);
4399 /* Without D3D11_BIND_SHADER_RESOURCE. */
4400 buffer = create_buffer(device, 0, 1024, NULL);
4402 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
4403 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4405 ID3D11Buffer_Release(buffer);
4407 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
4409 buffer_desc.ByteWidth = 1024;
4410 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4411 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4412 buffer_desc.CPUAccessFlags = 0;
4413 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
4414 buffer_desc.StructureByteStride = 4;
4416 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
4417 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
4419 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
4420 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
4422 memset(&srv_desc, 0, sizeof(srv_desc));
4423 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
4425 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
4426 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
4427 srv_desc.ViewDimension);
4428 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
4429 U1(U(srv_desc).Buffer).FirstElement);
4430 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
4431 U2(U(srv_desc).Buffer).NumElements);
4433 ID3D11ShaderResourceView_Release(srview);
4434 ID3D11Buffer_Release(buffer);
4436 else
4438 skip("Structured buffers require feature level 11_0.\n");
4441 texture2d_desc.Width = 512;
4442 texture2d_desc.Height = 512;
4443 texture2d_desc.SampleDesc.Count = 1;
4444 texture2d_desc.SampleDesc.Quality = 0;
4445 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
4446 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4447 texture2d_desc.CPUAccessFlags = 0;
4449 texture3d_desc.Width = 64;
4450 texture3d_desc.Height = 64;
4451 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
4452 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4453 texture3d_desc.CPUAccessFlags = 0;
4454 texture3d_desc.MiscFlags = 0;
4456 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4458 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
4460 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
4462 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
4463 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
4464 texture2d_desc.Format = tests[i].texture.format;
4465 texture2d_desc.MiscFlags = 0;
4467 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
4468 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4469 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
4471 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
4472 && (texture2d_desc.ArraySize != 6
4473 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4474 && feature_level < D3D_FEATURE_LEVEL_10_1)
4476 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
4477 continue;
4480 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4481 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4482 texture = (ID3D11Resource *)texture2d;
4484 else
4486 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
4487 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
4488 texture3d_desc.Format = tests[i].texture.format;
4490 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4491 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4492 texture = (ID3D11Resource *)texture3d;
4495 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
4497 current_desc = NULL;
4499 else
4501 current_desc = &srv_desc;
4502 get_srv_desc(current_desc, &tests[i].srv_desc);
4505 expected_refcount = get_refcount(texture);
4506 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
4507 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
4508 refcount = get_refcount(texture);
4509 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
4511 /* Not available on all Windows versions. */
4512 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
4513 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
4515 memset(&srv_desc, 0, sizeof(srv_desc));
4516 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
4517 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
4519 ID3D11ShaderResourceView_Release(srview);
4520 ID3D11Resource_Release(texture);
4523 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
4525 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
4526 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
4528 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
4530 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4531 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
4532 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
4533 texture2d_desc.MiscFlags = 0;
4535 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
4536 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4537 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
4539 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
4540 && feature_level < D3D_FEATURE_LEVEL_10_1)
4542 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
4543 continue;
4546 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4547 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4548 texture = (ID3D11Resource *)texture2d;
4550 else
4552 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4553 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
4554 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
4556 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4557 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4558 texture = (ID3D11Resource *)texture3d;
4561 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
4562 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
4563 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
4565 ID3D11Resource_Release(texture);
4568 refcount = ID3D11Device_Release(device);
4569 ok(!refcount, "Device has %u references left.\n", refcount);
4572 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
4574 #if 0
4575 float4 light;
4576 float4x4 mat;
4578 struct input
4580 float4 position : POSITION;
4581 float3 normal : NORMAL;
4584 struct output
4586 float4 position : POSITION;
4587 float4 diffuse : COLOR;
4590 output main(const input v)
4592 output o;
4594 o.position = mul(v.position, mat);
4595 o.diffuse = dot((float3)light, v.normal);
4597 return o;
4599 #endif
4600 static const DWORD vs_4_1[] =
4602 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
4603 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
4604 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
4605 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
4606 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4607 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
4608 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
4609 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
4610 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
4611 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
4612 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
4613 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
4614 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
4615 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
4616 0x0100003e,
4618 static const DWORD vs_4_0[] =
4620 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
4621 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
4622 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
4623 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
4624 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
4625 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
4626 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
4627 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
4628 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
4629 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
4630 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
4631 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
4632 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
4633 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
4634 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
4635 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
4637 static const DWORD vs_3_0[] =
4639 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
4640 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
4641 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
4642 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
4643 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
4644 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
4645 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
4646 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
4647 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
4648 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
4649 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
4650 0x0000ffff,
4652 static const DWORD vs_2_0[] =
4654 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
4655 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
4656 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
4657 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
4658 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
4659 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
4660 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
4661 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
4662 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
4663 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
4664 0x90e40001, 0x0000ffff,
4667 #if 0
4668 float4 main(const float4 color : COLOR) : SV_TARGET
4670 float4 o;
4672 o = color;
4674 return o;
4676 #endif
4677 static const DWORD ps_4_1[] =
4679 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
4680 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4681 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4682 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4683 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
4684 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4685 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4687 static const DWORD ps_4_0[] =
4689 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
4690 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4691 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4692 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4693 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4694 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4695 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4697 static const DWORD ps_4_0_level_9_0[] =
4699 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
4700 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
4701 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
4702 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
4703 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
4704 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
4705 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
4706 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
4707 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4708 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
4709 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
4710 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4711 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
4712 0xabab0054,
4714 static const DWORD ps_4_0_level_9_1[] =
4716 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
4717 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
4718 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
4719 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
4720 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4721 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4722 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
4723 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4724 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
4725 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
4726 0x45475241, 0xabab0054,
4728 static const DWORD ps_4_0_level_9_3[] =
4730 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
4731 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
4732 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
4733 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
4734 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4735 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4736 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
4737 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4738 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
4739 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
4740 0x45475241, 0xabab0054,
4743 #if 0
4744 struct gs_out
4746 float4 pos : SV_POSITION;
4749 [maxvertexcount(4)]
4750 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
4752 float offset = 0.1 * vin[0].w;
4753 gs_out v;
4755 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
4756 vout.Append(v);
4757 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
4758 vout.Append(v);
4759 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
4760 vout.Append(v);
4761 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
4762 vout.Append(v);
4764 #endif
4765 static const DWORD gs_4_1[] =
4767 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
4768 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4769 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4770 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4771 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
4772 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
4773 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
4774 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
4775 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
4776 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
4777 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
4778 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4779 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
4780 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4781 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
4782 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
4783 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
4784 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4786 static const DWORD gs_4_0[] =
4788 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
4789 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4790 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4791 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4792 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
4793 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
4794 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
4795 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4796 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
4797 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4798 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
4799 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
4800 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
4801 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
4802 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
4803 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4804 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
4805 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4808 ULONG refcount, expected_refcount;
4809 struct device_desc device_desc;
4810 ID3D11Device *device, *tmp;
4811 ID3D11GeometryShader *gs;
4812 ID3D11VertexShader *vs;
4813 ID3D11PixelShader *ps;
4814 HRESULT hr;
4816 device_desc.feature_level = &feature_level;
4817 device_desc.flags = 0;
4818 if (!(device = create_device(&device_desc)))
4820 skip("Failed to create device for feature level %#x.\n", feature_level);
4821 return;
4824 /* level_9 shaders */
4825 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
4826 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4827 ID3D11PixelShader_Release(ps);
4829 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
4830 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4831 ID3D11PixelShader_Release(ps);
4833 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
4834 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4835 ID3D11PixelShader_Release(ps);
4837 /* vertex shader */
4838 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
4839 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4841 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
4842 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4844 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
4845 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
4846 hr, feature_level);
4848 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4849 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
4850 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4851 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4852 else
4853 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4855 refcount = get_refcount(device);
4856 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4857 refcount, expected_refcount);
4858 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4860 tmp = NULL;
4861 expected_refcount = refcount + 1;
4862 ID3D11VertexShader_GetDevice(vs, &tmp);
4863 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4864 refcount = get_refcount(device);
4865 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4866 refcount, expected_refcount);
4867 ID3D11Device_Release(tmp);
4869 /* Not available on all Windows versions. */
4870 check_interface(vs, &IID_ID3D10VertexShader, TRUE, TRUE);
4872 refcount = ID3D11VertexShader_Release(vs);
4873 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
4876 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
4877 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4879 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
4880 hr, feature_level);
4881 refcount = ID3D11VertexShader_Release(vs);
4882 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
4884 else
4886 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4887 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
4888 hr, feature_level);
4889 if (SUCCEEDED(hr))
4890 ID3D11VertexShader_Release(vs);
4893 /* pixel shader */
4894 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4895 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
4896 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4897 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4898 else
4899 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4901 refcount = get_refcount(device);
4902 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4903 refcount, expected_refcount);
4904 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4906 tmp = NULL;
4907 expected_refcount = refcount + 1;
4908 ID3D11PixelShader_GetDevice(ps, &tmp);
4909 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4910 refcount = get_refcount(device);
4911 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4912 refcount, expected_refcount);
4913 ID3D11Device_Release(tmp);
4915 /* Not available on all Windows versions. */
4916 check_interface(ps, &IID_ID3D10PixelShader, TRUE, TRUE);
4918 refcount = ID3D11PixelShader_Release(ps);
4919 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
4922 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
4923 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4925 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
4926 hr, feature_level);
4927 refcount = ID3D11PixelShader_Release(ps);
4928 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
4930 else
4932 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4933 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4934 if (SUCCEEDED(hr))
4935 ID3D11PixelShader_Release(ps);
4938 /* geometry shader */
4939 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4940 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
4941 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4942 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4943 else
4944 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4946 refcount = get_refcount(device);
4947 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4948 refcount, expected_refcount);
4949 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4951 tmp = NULL;
4952 expected_refcount = refcount + 1;
4953 ID3D11GeometryShader_GetDevice(gs, &tmp);
4954 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4955 refcount = get_refcount(device);
4956 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4957 refcount, expected_refcount);
4958 ID3D11Device_Release(tmp);
4960 /* Not available on all Windows versions. */
4961 check_interface(gs, &IID_ID3D10GeometryShader, TRUE, TRUE);
4963 refcount = ID3D11GeometryShader_Release(gs);
4964 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4967 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
4968 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4970 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4971 hr, feature_level);
4972 refcount = ID3D11GeometryShader_Release(gs);
4973 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4975 else
4977 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4978 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4979 hr, feature_level);
4980 if (SUCCEEDED(hr))
4981 ID3D11GeometryShader_Release(gs);
4984 refcount = ID3D11Device_Release(device);
4985 ok(!refcount, "Device has %u references left.\n", refcount);
4988 static void test_create_sampler_state(void)
4990 static const struct test
4992 D3D11_FILTER filter;
4993 D3D10_FILTER expected_filter;
4995 desc_conversion_tests[] =
4997 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
4998 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
4999 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
5000 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
5001 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
5002 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
5003 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
5004 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
5005 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
5006 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
5007 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
5009 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
5010 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
5012 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
5013 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
5015 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
5016 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
5018 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
5019 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
5020 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
5023 ID3D11SamplerState *sampler_state1, *sampler_state2;
5024 ID3D10SamplerState *d3d10_sampler_state;
5025 ULONG refcount, expected_refcount;
5026 ID3D11Device *device, *tmp;
5027 D3D11_SAMPLER_DESC desc;
5028 unsigned int i;
5029 HRESULT hr;
5031 if (!(device = create_device(NULL)))
5033 skip("Failed to create device.\n");
5034 return;
5037 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
5038 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5040 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
5041 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5042 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5043 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
5044 desc.MipLODBias = 0.0f;
5045 desc.MaxAnisotropy = 16;
5046 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
5047 desc.BorderColor[0] = 0.0f;
5048 desc.BorderColor[1] = 1.0f;
5049 desc.BorderColor[2] = 0.0f;
5050 desc.BorderColor[3] = 1.0f;
5051 desc.MinLOD = 0.0f;
5052 desc.MaxLOD = 16.0f;
5054 expected_refcount = get_refcount(device) + 1;
5055 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
5056 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5057 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
5058 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
5059 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
5060 refcount = get_refcount(device);
5061 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5062 tmp = NULL;
5063 expected_refcount = refcount + 1;
5064 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
5065 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5066 refcount = get_refcount(device);
5067 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5068 ID3D11Device_Release(tmp);
5070 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
5071 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
5072 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
5073 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
5074 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
5075 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
5076 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
5077 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
5078 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
5079 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
5080 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
5081 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
5082 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
5084 refcount = ID3D11SamplerState_Release(sampler_state2);
5085 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5086 refcount = ID3D11SamplerState_Release(sampler_state1);
5087 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5089 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
5091 const struct test *current = &desc_conversion_tests[i];
5092 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
5094 desc.Filter = current->filter;
5095 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
5096 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
5097 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
5098 desc.MipLODBias = 0.0f;
5099 desc.MaxAnisotropy = 16;
5100 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
5101 desc.BorderColor[0] = 0.0f;
5102 desc.BorderColor[1] = 1.0f;
5103 desc.BorderColor[2] = 0.0f;
5104 desc.BorderColor[3] = 1.0f;
5105 desc.MinLOD = 0.0f;
5106 desc.MaxLOD = 16.0f;
5108 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
5109 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
5111 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
5112 (void **)&d3d10_sampler_state);
5113 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5114 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
5115 if (FAILED(hr))
5117 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
5118 ID3D11SamplerState_Release(sampler_state1);
5119 break;
5122 memcpy(&expected_desc, &desc, sizeof(expected_desc));
5123 expected_desc.Filter = current->expected_filter;
5124 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
5125 expected_desc.MaxAnisotropy = 0;
5126 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
5127 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
5129 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
5130 ok(d3d10_desc.Filter == expected_desc.Filter,
5131 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
5132 ok(d3d10_desc.AddressU == expected_desc.AddressU,
5133 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
5134 ok(d3d10_desc.AddressV == expected_desc.AddressV,
5135 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
5136 ok(d3d10_desc.AddressW == expected_desc.AddressW,
5137 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
5138 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
5139 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
5140 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
5141 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
5142 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
5143 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
5144 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
5145 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
5146 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
5147 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
5148 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
5149 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
5150 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
5151 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
5152 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
5153 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
5154 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
5156 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
5157 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
5158 refcount = ID3D11SamplerState_Release(sampler_state1);
5159 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
5162 refcount = ID3D11Device_Release(device);
5163 ok(!refcount, "Device has %u references left.\n", refcount);
5166 static void test_create_blend_state(void)
5168 static const D3D11_BLEND_DESC desc_conversion_tests[] =
5171 FALSE, FALSE,
5174 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5175 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
5180 FALSE, TRUE,
5183 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5184 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5187 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5188 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
5191 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5192 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5195 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5196 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
5199 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5200 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5203 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5204 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5207 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5208 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5211 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5212 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5217 FALSE, TRUE,
5220 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5221 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5224 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
5225 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5228 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
5229 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5232 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5233 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5236 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
5237 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5240 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
5241 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5244 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5245 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5248 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5249 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5255 ID3D11BlendState *blend_state1, *blend_state2;
5256 D3D11_BLEND_DESC desc, obtained_desc;
5257 ID3D10BlendState *d3d10_blend_state;
5258 D3D10_BLEND_DESC d3d10_blend_desc;
5259 ULONG refcount, expected_refcount;
5260 ID3D11Device *device, *tmp;
5261 unsigned int i, j;
5262 HRESULT hr;
5264 if (!(device = create_device(NULL)))
5266 skip("Failed to create device.\n");
5267 return;
5270 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
5271 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5273 memset(&desc, 0, sizeof(desc));
5274 desc.AlphaToCoverageEnable = FALSE;
5275 desc.IndependentBlendEnable = FALSE;
5276 desc.RenderTarget[0].BlendEnable = FALSE;
5277 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5279 expected_refcount = get_refcount(device) + 1;
5280 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
5281 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5282 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
5283 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5284 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
5285 refcount = get_refcount(device);
5286 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5287 tmp = NULL;
5288 expected_refcount = refcount + 1;
5289 ID3D11BlendState_GetDevice(blend_state1, &tmp);
5290 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5291 refcount = get_refcount(device);
5292 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5293 ID3D11Device_Release(tmp);
5295 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
5296 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
5297 obtained_desc.AlphaToCoverageEnable);
5298 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
5299 obtained_desc.IndependentBlendEnable);
5300 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5302 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
5303 "Got unexpected blend enable %#x for render target %u.\n",
5304 obtained_desc.RenderTarget[i].BlendEnable, i);
5305 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
5306 "Got unexpected src blend %u for render target %u.\n",
5307 obtained_desc.RenderTarget[i].SrcBlend, i);
5308 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
5309 "Got unexpected dest blend %u for render target %u.\n",
5310 obtained_desc.RenderTarget[i].DestBlend, i);
5311 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
5312 "Got unexpected blend op %u for render target %u.\n",
5313 obtained_desc.RenderTarget[i].BlendOp, i);
5314 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
5315 "Got unexpected src blend alpha %u for render target %u.\n",
5316 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
5317 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
5318 "Got unexpected dest blend alpha %u for render target %u.\n",
5319 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
5320 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
5321 "Got unexpected blend op alpha %u for render target %u.\n",
5322 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
5323 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
5324 "Got unexpected render target write mask %#x for render target %u.\n",
5325 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
5328 /* Not available on all Windows versions. */
5329 check_interface(blend_state1, &IID_ID3D10BlendState, TRUE, TRUE);
5330 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
5332 refcount = ID3D11BlendState_Release(blend_state1);
5333 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5334 refcount = ID3D11BlendState_Release(blend_state2);
5335 ok(!refcount, "Blend state has %u references left.\n", refcount);
5337 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
5339 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
5341 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
5342 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5344 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
5345 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5346 "Blend state should implement ID3D10BlendState.\n");
5347 if (FAILED(hr))
5349 win_skip("Blend state does not implement ID3D10BlendState.\n");
5350 ID3D11BlendState_Release(blend_state1);
5351 break;
5354 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
5355 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
5356 "Got unexpected alpha to coverage enable %#x for test %u.\n",
5357 d3d10_blend_desc.AlphaToCoverageEnable, i);
5358 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
5359 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
5360 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
5361 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
5362 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
5363 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
5364 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
5365 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
5366 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
5367 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
5368 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
5369 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
5370 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
5372 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
5373 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
5374 "Got unexpected blend enable %#x for test %u, render target %u.\n",
5375 d3d10_blend_desc.BlendEnable[j], i, j);
5376 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
5377 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
5378 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
5381 ID3D10BlendState_Release(d3d10_blend_state);
5383 refcount = ID3D11BlendState_Release(blend_state1);
5384 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5387 refcount = ID3D11Device_Release(device);
5388 ok(!refcount, "Device has %u references left.\n", refcount);
5391 static void test_create_depthstencil_state(void)
5393 ID3D11DepthStencilState *ds_state1, *ds_state2;
5394 ULONG refcount, expected_refcount;
5395 D3D11_DEPTH_STENCIL_DESC ds_desc;
5396 ID3D11Device *device, *tmp;
5397 HRESULT hr;
5399 if (!(device = create_device(NULL)))
5401 skip("Failed to create device.\n");
5402 return;
5405 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
5406 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5408 ds_desc.DepthEnable = TRUE;
5409 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
5410 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
5411 ds_desc.StencilEnable = FALSE;
5412 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
5413 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
5414 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
5415 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
5416 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
5417 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
5418 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
5419 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
5420 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
5421 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
5423 expected_refcount = get_refcount(device) + 1;
5424 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
5425 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5426 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
5427 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5428 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
5429 refcount = get_refcount(device);
5430 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5431 tmp = NULL;
5432 expected_refcount = refcount + 1;
5433 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
5434 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5435 refcount = get_refcount(device);
5436 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5437 ID3D11Device_Release(tmp);
5439 /* Not available on all Windows versions. */
5440 check_interface(ds_state1, &IID_ID3D10DepthStencilState, TRUE, TRUE);
5442 refcount = ID3D11DepthStencilState_Release(ds_state2);
5443 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5444 refcount = ID3D11DepthStencilState_Release(ds_state1);
5445 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5447 ds_desc.DepthEnable = FALSE;
5448 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
5449 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
5450 ds_desc.StencilEnable = FALSE;
5451 ds_desc.StencilReadMask = 0;
5452 ds_desc.StencilWriteMask = 0;
5453 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
5454 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
5455 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
5456 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
5457 ds_desc.BackFace = ds_desc.FrontFace;
5459 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
5460 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5462 memset(&ds_desc, 0, sizeof(ds_desc));
5463 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
5464 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
5465 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
5466 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
5467 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
5468 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
5469 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
5470 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
5471 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
5472 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
5473 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
5474 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
5475 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
5476 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
5477 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
5478 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
5479 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
5480 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
5481 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
5482 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
5483 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
5484 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
5485 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
5486 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
5487 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
5488 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
5490 ID3D11DepthStencilState_Release(ds_state1);
5492 refcount = ID3D11Device_Release(device);
5493 ok(!refcount, "Device has %u references left.\n", refcount);
5496 static void test_create_rasterizer_state(void)
5498 ID3D11RasterizerState *rast_state1, *rast_state2;
5499 ID3D10RasterizerState *d3d10_rast_state;
5500 ULONG refcount, expected_refcount;
5501 D3D10_RASTERIZER_DESC d3d10_desc;
5502 D3D11_RASTERIZER_DESC desc;
5503 ID3D11Device *device, *tmp;
5504 HRESULT hr;
5506 if (!(device = create_device(NULL)))
5508 skip("Failed to create device.\n");
5509 return;
5512 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
5513 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5515 desc.FillMode = D3D11_FILL_SOLID;
5516 desc.CullMode = D3D11_CULL_BACK;
5517 desc.FrontCounterClockwise = FALSE;
5518 desc.DepthBias = 0;
5519 desc.DepthBiasClamp = 0.0f;
5520 desc.SlopeScaledDepthBias = 0.0f;
5521 desc.DepthClipEnable = TRUE;
5522 desc.ScissorEnable = FALSE;
5523 desc.MultisampleEnable = FALSE;
5524 desc.AntialiasedLineEnable = FALSE;
5526 expected_refcount = get_refcount(device) + 1;
5527 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
5528 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5529 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
5530 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5531 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
5532 refcount = get_refcount(device);
5533 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5534 tmp = NULL;
5535 expected_refcount = refcount + 1;
5536 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
5537 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5538 refcount = get_refcount(device);
5539 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5540 ID3D11Device_Release(tmp);
5542 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
5543 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5544 "Rasterizer state should implement ID3D10RasterizerState.\n");
5545 if (SUCCEEDED(hr))
5547 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
5548 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
5549 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
5550 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
5551 d3d10_desc.FrontCounterClockwise);
5552 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
5553 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
5554 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
5555 d3d10_desc.SlopeScaledDepthBias);
5556 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
5557 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
5558 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
5559 d3d10_desc.MultisampleEnable);
5560 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
5561 d3d10_desc.AntialiasedLineEnable);
5563 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
5564 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5567 refcount = ID3D11RasterizerState_Release(rast_state2);
5568 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5569 refcount = ID3D11RasterizerState_Release(rast_state1);
5570 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5572 refcount = ID3D11Device_Release(device);
5573 ok(!refcount, "Device has %u references left.\n", refcount);
5576 static void test_create_query(void)
5578 static const struct
5580 D3D11_QUERY query;
5581 D3D_FEATURE_LEVEL required_feature_level;
5582 BOOL is_predicate;
5583 BOOL can_use_create_predicate;
5584 BOOL todo;
5586 tests[] =
5588 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5589 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5590 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5591 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5592 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5593 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
5594 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5595 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
5596 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5597 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5598 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5599 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5600 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5601 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5602 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5603 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5606 ULONG refcount, expected_refcount;
5607 D3D_FEATURE_LEVEL feature_level;
5608 D3D11_QUERY_DESC query_desc;
5609 ID3D11Predicate *predicate;
5610 ID3D11Device *device, *tmp;
5611 HRESULT hr, expected_hr;
5612 ID3D11Query *query;
5613 unsigned int i;
5615 if (!(device = create_device(NULL)))
5617 skip("Failed to create device.\n");
5618 return;
5620 feature_level = ID3D11Device_GetFeatureLevel(device);
5622 hr = ID3D11Device_CreateQuery(device, NULL, &query);
5623 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5624 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
5625 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5627 for (i = 0; i < ARRAY_SIZE(tests); ++i)
5629 if (tests[i].required_feature_level > feature_level)
5631 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
5632 continue;
5635 query_desc.Query = tests[i].query;
5636 query_desc.MiscFlags = 0;
5638 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
5639 todo_wine_if(tests[i].todo)
5640 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5642 query_desc.Query = tests[i].query;
5643 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
5644 todo_wine_if(tests[i].todo)
5645 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5646 if (FAILED(hr))
5647 continue;
5649 check_interface(query, &IID_ID3D11Predicate, tests[i].is_predicate, FALSE);
5650 ID3D11Query_Release(query);
5652 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
5653 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
5654 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5656 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
5657 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
5658 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5659 if (SUCCEEDED(hr))
5660 ID3D11Predicate_Release(predicate);
5663 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
5664 expected_refcount = get_refcount(device) + 1;
5665 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
5666 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5667 refcount = get_refcount(device);
5668 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5669 tmp = NULL;
5670 expected_refcount = refcount + 1;
5671 ID3D11Predicate_GetDevice(predicate, &tmp);
5672 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5673 refcount = get_refcount(device);
5674 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5675 ID3D11Device_Release(tmp);
5676 /* Not available on all Windows versions. */
5677 check_interface(predicate, &IID_ID3D10Predicate, TRUE, TRUE);
5678 ID3D11Predicate_Release(predicate);
5680 refcount = ID3D11Device_Release(device);
5681 ok(!refcount, "Device has %u references left.\n", refcount);
5684 #define get_query_data(a, b, c, d) get_query_data_(__LINE__, a, b, c, d)
5685 static void get_query_data_(unsigned int line, ID3D11DeviceContext *context,
5686 ID3D11Asynchronous *query, void *data, unsigned int data_size)
5688 unsigned int i;
5689 HRESULT hr;
5691 for (i = 0; i < 500; ++i)
5693 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
5694 break;
5695 Sleep(10);
5697 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5698 memset(data, 0xff, data_size);
5699 hr = ID3D11DeviceContext_GetData(context, query, data, data_size, 0);
5700 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5703 static void test_occlusion_query(void)
5705 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5706 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5708 struct d3d11_test_context test_context;
5709 D3D11_TEXTURE2D_DESC texture_desc;
5710 ID3D11DeviceContext *context;
5711 ID3D11RenderTargetView *rtv;
5712 D3D11_QUERY_DESC query_desc;
5713 ID3D11Asynchronous *query;
5714 unsigned int data_size, i;
5715 ID3D11Texture2D *texture;
5716 ID3D11Device *device;
5717 union
5719 UINT64 uint;
5720 DWORD dword[2];
5721 } data;
5722 HRESULT hr;
5724 if (!init_test_context(&test_context, NULL))
5725 return;
5727 device = test_context.device;
5728 context = test_context.immediate_context;
5730 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5732 query_desc.Query = D3D11_QUERY_OCCLUSION;
5733 query_desc.MiscFlags = 0;
5734 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5735 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5736 data_size = ID3D11Asynchronous_GetDataSize(query);
5737 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
5739 memset(&data, 0xff, sizeof(data));
5740 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5741 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5742 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5743 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5744 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5745 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5747 ID3D11DeviceContext_End(context, query);
5748 ID3D11DeviceContext_Begin(context, query);
5749 ID3D11DeviceContext_Begin(context, query);
5751 memset(&data, 0xff, sizeof(data));
5752 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5753 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5754 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5755 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5756 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5757 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5759 draw_color_quad(&test_context, &red);
5761 ID3D11DeviceContext_End(context, query);
5762 get_query_data(context, query, &data, sizeof(data));
5763 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5765 memset(&data, 0xff, sizeof(data));
5766 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
5767 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5768 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
5769 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5770 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
5771 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5772 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
5773 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5774 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5775 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5777 memset(&data, 0xff, sizeof(data));
5778 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
5779 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5780 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5781 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5783 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
5784 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5785 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
5786 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5788 ID3D11DeviceContext_Begin(context, query);
5789 ID3D11DeviceContext_End(context, query);
5790 ID3D11DeviceContext_End(context, query);
5792 get_query_data(context, query, &data, sizeof(data));
5793 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5794 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5795 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5797 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
5798 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
5799 texture_desc.MipLevels = 1;
5800 texture_desc.ArraySize = 1;
5801 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
5802 texture_desc.SampleDesc.Count = 1;
5803 texture_desc.SampleDesc.Quality = 0;
5804 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5805 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5806 texture_desc.CPUAccessFlags = 0;
5807 texture_desc.MiscFlags = 0;
5808 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5809 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5810 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5811 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5813 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
5814 set_viewport(context, 0.0f, 0.0f, texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
5816 ID3D11DeviceContext_Begin(context, query);
5817 for (i = 0; i < 100; i++)
5818 draw_color_quad(&test_context, &red);
5819 ID3D11DeviceContext_End(context, query);
5821 get_query_data(context, query, &data, sizeof(data));
5822 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
5823 || (data.dword[0] == 0xffffffff && !data.dword[1])
5824 || broken(!data.uint),
5825 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5826 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5827 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5829 ID3D11Asynchronous_Release(query);
5831 /* The following test exercises a code path in wined3d. A wined3d context
5832 * associated with the query is destroyed when the swapchain is released. */
5833 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5834 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5836 set_viewport(context, 0.0f, 0.0f, 64.0f, 64.0f, 0.0f, 1.0f);
5837 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5838 ID3D11DeviceContext_Begin(context, query);
5839 draw_color_quad(&test_context, &red);
5840 ID3D11DeviceContext_End(context, query);
5842 ID3D11RenderTargetView_Release(test_context.backbuffer_rtv);
5843 ID3D11Texture2D_Release(test_context.backbuffer);
5844 IDXGISwapChain_Release(test_context.swapchain);
5845 test_context.swapchain = create_swapchain(device, test_context.window, NULL);
5846 hr = IDXGISwapChain_GetBuffer(test_context.swapchain, 0, &IID_ID3D11Texture2D,
5847 (void **)&test_context.backbuffer);
5848 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
5849 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer,
5850 NULL, &test_context.backbuffer_rtv);
5851 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5852 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
5853 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5855 get_query_data(context, query, &data, sizeof(data));
5856 /* This test occasionally succeeds with CSMT enabled because of a race condition. */
5857 if (0)
5858 todo_wine ok(data.dword[0] == 0x1000 && !data.dword[1],
5859 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5861 ID3D11Asynchronous_Release(query);
5862 ID3D11RenderTargetView_Release(rtv);
5863 ID3D11Texture2D_Release(texture);
5864 release_test_context(&test_context);
5867 static void test_pipeline_statistics_query(void)
5869 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5870 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5872 D3D11_QUERY_DATA_PIPELINE_STATISTICS data;
5873 struct d3d11_test_context test_context;
5874 ID3D11DeviceContext *context;
5875 D3D11_QUERY_DESC query_desc;
5876 ID3D11Asynchronous *query;
5877 unsigned int data_size;
5878 ID3D11Device *device;
5879 HRESULT hr;
5881 if (!init_test_context(&test_context, NULL))
5882 return;
5884 device = test_context.device;
5885 context = test_context.immediate_context;
5887 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5889 query_desc.Query = D3D11_QUERY_PIPELINE_STATISTICS;
5890 query_desc.MiscFlags = 0;
5891 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5892 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5893 data_size = ID3D11Asynchronous_GetDataSize(query);
5894 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
5896 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5897 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5898 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5899 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5901 ID3D11DeviceContext_End(context, query);
5902 ID3D11DeviceContext_Begin(context, query);
5903 ID3D11DeviceContext_Begin(context, query);
5905 memset(&data, 0xff, sizeof(data));
5906 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5907 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5908 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5909 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5910 ok(data.IAVertices == ~(UINT64)0, "Data was modified.\n");
5912 draw_quad(&test_context);
5914 ID3D11DeviceContext_End(context, query);
5915 get_query_data(context, query, &data, sizeof(data));
5916 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5917 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5918 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5919 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5920 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5921 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5922 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5923 todo_wine
5924 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5925 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5926 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5927 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5929 ID3D11DeviceContext_Begin(context, query);
5930 draw_color_quad(&test_context, &red);
5931 ID3D11DeviceContext_End(context, query);
5932 get_query_data(context, query, &data, sizeof(data));
5933 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5934 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5935 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5936 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5937 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5938 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5939 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5940 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5941 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5942 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5943 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5945 ID3D11Asynchronous_Release(query);
5946 release_test_context(&test_context);
5949 static void test_timestamp_query(void)
5951 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5953 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
5954 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
5955 struct d3d11_test_context test_context;
5956 ID3D11DeviceContext *context;
5957 D3D11_QUERY_DESC query_desc;
5958 unsigned int data_size;
5959 ID3D11Device *device;
5960 UINT64 timestamp;
5961 HRESULT hr;
5963 if (!init_test_context(&test_context, NULL))
5964 return;
5966 device = test_context.device;
5967 context = test_context.immediate_context;
5969 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5970 query_desc.MiscFlags = 0;
5971 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5972 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5973 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
5974 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
5976 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
5977 query_desc.MiscFlags = 0;
5978 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
5979 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5980 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
5981 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
5983 disjoint.Frequency = 0xdeadbeef;
5984 disjoint.Disjoint = 0xdeadbeef;
5985 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5986 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5987 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5988 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5989 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5990 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5992 /* Test a TIMESTAMP_DISJOINT query. */
5993 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5995 disjoint.Frequency = 0xdeadbeef;
5996 disjoint.Disjoint = 0xdeadbeef;
5997 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5998 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5999 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
6000 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6001 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
6002 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
6004 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
6005 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
6006 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
6007 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
6009 prev_disjoint = disjoint;
6011 disjoint.Frequency = 0xdeadbeef;
6012 disjoint.Disjoint = 0xff;
6013 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
6014 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6015 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
6016 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6017 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
6018 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6019 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
6020 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6021 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
6022 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
6024 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
6025 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6026 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
6027 D3D11_ASYNC_GETDATA_DONOTFLUSH);
6028 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6029 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
6030 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
6032 memset(&timestamp, 0xff, sizeof(timestamp));
6033 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
6034 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6035 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
6036 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6037 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
6039 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
6040 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
6042 memset(&timestamp, 0xff, sizeof(timestamp));
6043 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
6044 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6045 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
6047 draw_color_quad(&test_context, &red);
6049 ID3D11DeviceContext_End(context, timestamp_query);
6050 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
6052 timestamp = 0xdeadbeef;
6053 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
6054 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6055 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
6057 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
6058 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6059 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
6061 timestamp = 0xdeadbeef;
6062 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
6063 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6064 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
6065 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6066 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
6067 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6068 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
6069 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6070 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
6072 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
6073 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
6074 disjoint.Frequency = 0xdeadbeef;
6075 disjoint.Disjoint = 0xff;
6076 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
6077 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6078 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
6079 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
6081 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
6082 ID3D11Asynchronous_Release(timestamp_query);
6083 query_desc.Query = D3D11_QUERY_TIMESTAMP;
6084 query_desc.MiscFlags = 0;
6085 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
6086 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6088 draw_color_quad(&test_context, &red);
6090 ID3D11DeviceContext_End(context, timestamp_query);
6091 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
6093 ID3D11Asynchronous_Release(timestamp_query);
6094 ID3D11Asynchronous_Release(timestamp_disjoint_query);
6095 release_test_context(&test_context);
6098 static void test_so_statistics_query(void)
6100 struct d3d11_test_context test_context;
6101 D3D11_QUERY_DATA_SO_STATISTICS data;
6102 ID3D11DeviceContext *context;
6103 unsigned int vertex_count[4];
6104 D3D11_QUERY_DESC query_desc;
6105 ID3D11Buffer *so_buffer[4];
6106 ID3D11Asynchronous *query;
6107 ID3D11GeometryShader *gs;
6108 ID3D11VertexShader *vs;
6109 unsigned int data_size;
6110 ID3D11Device *device;
6111 ID3D11Buffer *cb;
6112 unsigned int i;
6113 HRESULT hr;
6115 static const DWORD vs_code[] =
6117 #if 0
6118 float4 main(uint id : SV_VertexID) : custom
6120 return (float4)id;
6122 #endif
6123 0x43425844, 0x8b0e47b9, 0x6efc9512, 0xd55ca6ff, 0x487c5ef2, 0x00000001, 0x000000d4, 0x00000003,
6124 0x0000002c, 0x00000060, 0x00000090, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6125 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
6126 0x4e47534f, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6127 0x00000000, 0x0000000f, 0x74737563, 0xab006d6f, 0x52444853, 0x0000003c, 0x00010040, 0x0000000f,
6128 0x04000060, 0x00101012, 0x00000000, 0x00000006, 0x03000065, 0x001020f2, 0x00000000, 0x05000056,
6129 0x001020f2, 0x00000000, 0x00101006, 0x00000000, 0x0100003e,
6131 static const DWORD gs_code[] =
6133 #if 0
6134 struct vertex
6136 float4 data : custom;
6139 uint4 vertex_count;
6141 [maxvertexcount(32)]
6142 void main(point vertex input[1], uint id : SV_PrimitiveID,
6143 inout PointStream<vertex> output0,
6144 inout PointStream<vertex> output1,
6145 inout PointStream<vertex> output2,
6146 inout PointStream<vertex> output3)
6148 if (id < vertex_count.x)
6149 output0.Append(input[0]);
6150 if (id < vertex_count.y)
6151 output1.Append(input[0]);
6152 if (id < vertex_count.z)
6153 output2.Append(input[0]);
6154 if (id < vertex_count.w)
6155 output3.Append(input[0]);
6157 #endif
6158 0x43425844, 0xd616829d, 0x4355ce2a, 0xd71909e5, 0xdc916d4c, 0x00000001, 0x000002bc, 0x00000003,
6159 0x0000002c, 0x00000084, 0x0000010c, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
6160 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000003f, 0x00000000, 0x00000007,
6161 0x00000001, 0xffffffff, 0x00000101, 0x74737563, 0x53006d6f, 0x72505f56, 0x74696d69, 0x49657669,
6162 0xabab0044, 0x3547534f, 0x00000080, 0x00000004, 0x00000008, 0x00000000, 0x00000078, 0x00000000,
6163 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000001, 0x00000078, 0x00000000, 0x00000000,
6164 0x00000003, 0x00000000, 0x0000000f, 0x00000002, 0x00000078, 0x00000000, 0x00000000, 0x00000003,
6165 0x00000000, 0x0000000f, 0x00000003, 0x00000078, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
6166 0x0000000f, 0x74737563, 0xab006d6f, 0x58454853, 0x000001a8, 0x00020050, 0x0000006a, 0x0100086a,
6167 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000,
6168 0x0200005f, 0x0000b000, 0x02000068, 0x00000001, 0x0100085d, 0x0300008f, 0x00110000, 0x00000000,
6169 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000001, 0x0100085c,
6170 0x03000065, 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000002, 0x0100085c, 0x03000065,
6171 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000003, 0x0100085c, 0x03000065, 0x001020f2,
6172 0x00000000, 0x0200005e, 0x00000020, 0x0700004f, 0x001000f2, 0x00000000, 0x0000b001, 0x00208e46,
6173 0x00000000, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000,
6174 0x00201e46, 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x01000015, 0x0304001f,
6175 0x0010001a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000, 0x00000000,
6176 0x03000075, 0x00110000, 0x00000001, 0x01000015, 0x0304001f, 0x0010002a, 0x00000000, 0x06000036,
6177 0x001020f2, 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000002,
6178 0x01000015, 0x0304001f, 0x0010003a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
6179 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000003, 0x01000015, 0x0100003e,
6181 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
6183 {0, "custom", 0, 0, 4, 0},
6184 {1, "custom", 0, 0, 4, 1},
6185 {2, "custom", 0, 0, 4, 2},
6186 {3, "custom", 0, 0, 4, 3},
6188 static const unsigned int offset[4] = {0};
6190 static const struct
6192 D3D11_QUERY query;
6193 D3D_FEATURE_LEVEL feature_level;
6195 tests[] =
6197 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0},
6198 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0},
6199 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0},
6200 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0},
6201 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0},
6204 if (!init_test_context(&test_context, NULL))
6205 return;
6207 device = test_context.device;
6208 context = test_context.immediate_context;
6210 for (i = 0; i < ARRAY_SIZE(tests); ++i)
6212 if (ID3D11Device_GetFeatureLevel(device) < tests[i].feature_level)
6214 skip("Feature level %#x is required.\n", tests[i].feature_level);
6215 continue;
6218 query_desc.Query = tests[i].query;
6219 query_desc.MiscFlags = 0;
6220 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
6221 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6222 data_size = ID3D11Asynchronous_GetDataSize(query);
6223 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
6225 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
6226 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6227 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
6228 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6230 ID3D11DeviceContext_End(context, query);
6231 ID3D11DeviceContext_Begin(context, query);
6232 ID3D11DeviceContext_Begin(context, query);
6234 memset(&data, 0xff, sizeof(data));
6235 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
6236 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6237 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
6238 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6239 ok(data.NumPrimitivesWritten == ~(UINT64)0, "Data was modified.\n");
6240 ok(data.PrimitivesStorageNeeded == ~(UINT64)0, "Data was modified.\n");
6242 draw_quad(&test_context);
6244 ID3D11DeviceContext_End(context, query);
6245 get_query_data(context, query, &data, sizeof(data));
6246 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
6247 (unsigned int)data.NumPrimitivesWritten);
6248 todo_wine_if(query_desc.Query == D3D11_QUERY_SO_STATISTICS || query_desc.Query == D3D11_QUERY_SO_STATISTICS_STREAM0)
6249 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
6250 (unsigned int)data.PrimitivesStorageNeeded);
6252 ID3D11DeviceContext_Begin(context, query);
6253 draw_quad(&test_context);
6254 ID3D11DeviceContext_End(context, query);
6255 get_query_data(context, query, &data, sizeof(data));
6256 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
6257 (unsigned int)data.NumPrimitivesWritten);
6258 todo_wine_if(query_desc.Query == D3D11_QUERY_SO_STATISTICS || query_desc.Query == D3D11_QUERY_SO_STATISTICS_STREAM0)
6259 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
6260 (unsigned int)data.PrimitivesStorageNeeded);
6262 ID3D11Asynchronous_Release(query);
6265 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
6267 skip("Vertex streams are not supported.\n");
6268 goto done;
6271 /* multiple vertex streams */
6272 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
6273 ok(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
6274 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
6276 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
6277 so_declaration, ARRAY_SIZE(so_declaration),
6278 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
6279 todo_wine
6280 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
6281 if (FAILED(hr))
6283 ID3D11VertexShader_Release(vs);
6284 goto done;
6286 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
6288 for (i = 0; i < ARRAY_SIZE(vertex_count); ++i)
6289 vertex_count[i] = 5;
6290 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(vertex_count), vertex_count);
6291 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
6293 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
6295 query_desc.Query = D3D11_QUERY_SO_STATISTICS;
6296 query_desc.MiscFlags = 0;
6297 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
6298 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6300 ID3D11DeviceContext_Begin(context, query);
6301 ID3D11DeviceContext_Draw(context, 5, 0);
6302 ID3D11DeviceContext_End(context, query);
6304 memset(&data, 0xff, sizeof(data));
6305 get_query_data(context, query, &data, sizeof(data));
6306 ok(!data.NumPrimitivesWritten, "Got unexpected primitives written %u.\n",
6307 (unsigned int)data.NumPrimitivesWritten);
6308 ok(data.PrimitivesStorageNeeded == 5, "Got unexpected primitives storage needed %u.\n",
6309 (unsigned int)data.PrimitivesStorageNeeded);
6311 for (i = 0; i < ARRAY_SIZE(so_buffer); ++i)
6312 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(struct vec4) * 10, NULL);
6314 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6315 ID3D11DeviceContext_Begin(context, query);
6316 ID3D11DeviceContext_Draw(context, 16, 0);
6317 ID3D11DeviceContext_End(context, query);
6318 memset(&data, 0xff, sizeof(data));
6319 get_query_data(context, query, &data, sizeof(data));
6320 ok(data.NumPrimitivesWritten == 5, "Got unexpected primitives written %u.\n",
6321 (unsigned int)data.NumPrimitivesWritten);
6322 ok(data.PrimitivesStorageNeeded == 5, "Got unexpected primitives storage needed %u.\n",
6323 (unsigned int)data.PrimitivesStorageNeeded);
6325 vertex_count[0] = 3;
6326 vertex_count[1] = 6;
6327 vertex_count[2] = 4;
6328 vertex_count[3] = 12;
6329 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, vertex_count, 0, 0);
6331 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6332 ID3D11DeviceContext_Begin(context, query);
6333 ID3D11DeviceContext_Draw(context, 32, 0);
6334 ID3D11DeviceContext_End(context, query);
6335 memset(&data, 0xff, sizeof(data));
6336 get_query_data(context, query, &data, sizeof(data));
6337 ok(data.NumPrimitivesWritten == 3, "Got unexpected primitives written %u.\n",
6338 (unsigned int)data.NumPrimitivesWritten);
6339 ok(data.PrimitivesStorageNeeded == 3, "Got unexpected primitives storage needed %u.\n",
6340 (unsigned int)data.PrimitivesStorageNeeded);
6342 vertex_count[0] = 16;
6343 vertex_count[1] = 6;
6344 vertex_count[2] = 4;
6345 vertex_count[3] = 12;
6346 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, vertex_count, 0, 0);
6348 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6349 ID3D11DeviceContext_Begin(context, query);
6350 ID3D11DeviceContext_Draw(context, 32, 0);
6351 ID3D11DeviceContext_End(context, query);
6352 memset(&data, 0xff, sizeof(data));
6353 get_query_data(context, query, &data, sizeof(data));
6354 ok(data.NumPrimitivesWritten == 10, "Got unexpected primitives written %u.\n",
6355 (unsigned int)data.NumPrimitivesWritten);
6356 ok(data.PrimitivesStorageNeeded == 16, "Got unexpected primitives storage needed %u.\n",
6357 (unsigned int)data.PrimitivesStorageNeeded);
6359 ID3D11Asynchronous_Release(query);
6361 for (i = 0; i < ARRAY_SIZE(so_buffer); ++i)
6362 ID3D11Buffer_Release(so_buffer[i]);
6363 ID3D11Buffer_Release(cb);
6364 ID3D11GeometryShader_Release(gs);
6365 ID3D11VertexShader_Release(vs);
6367 done:
6368 release_test_context(&test_context);
6371 static void test_device_removed_reason(void)
6373 ID3D11Device *device;
6374 ULONG refcount;
6375 HRESULT hr;
6377 if (!(device = create_device(NULL)))
6379 skip("Failed to create device.\n");
6380 return;
6383 hr = ID3D11Device_GetDeviceRemovedReason(device);
6384 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6385 hr = ID3D11Device_GetDeviceRemovedReason(device);
6386 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6388 refcount = ID3D11Device_Release(device);
6389 ok(!refcount, "Device has %u references left.\n", refcount);
6392 static void test_private_data(void)
6394 ULONG refcount, expected_refcount;
6395 D3D11_TEXTURE2D_DESC texture_desc;
6396 ID3D10Texture2D *d3d10_texture;
6397 ID3D11Device *test_object;
6398 ID3D11Texture2D *texture;
6399 IDXGIDevice *dxgi_device;
6400 IDXGISurface *surface;
6401 ID3D11Device *device;
6402 IUnknown *ptr;
6403 HRESULT hr;
6404 UINT size;
6406 static const GUID test_guid =
6407 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
6408 static const GUID test_guid2 =
6409 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
6410 static const DWORD data[] = {1, 2, 3, 4};
6412 if (!(device = create_device(NULL)))
6414 skip("Failed to create device.\n");
6415 return;
6418 test_object = create_device(NULL);
6420 texture_desc.Width = 512;
6421 texture_desc.Height = 512;
6422 texture_desc.MipLevels = 1;
6423 texture_desc.ArraySize = 1;
6424 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6425 texture_desc.SampleDesc.Count = 1;
6426 texture_desc.SampleDesc.Quality = 0;
6427 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6428 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6429 texture_desc.CPUAccessFlags = 0;
6430 texture_desc.MiscFlags = 0;
6432 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6433 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6434 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
6435 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
6437 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
6438 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6439 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6440 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6441 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6442 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6443 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6444 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6446 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6447 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6448 size = sizeof(ptr) * 2;
6449 ptr = (IUnknown *)0xdeadbeef;
6450 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6451 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6452 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6453 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6455 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
6456 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
6457 size = sizeof(ptr) * 2;
6458 ptr = (IUnknown *)0xdeadbeef;
6459 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
6460 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6461 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6462 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6463 IDXGIDevice_Release(dxgi_device);
6465 refcount = get_refcount(test_object);
6466 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6467 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6468 expected_refcount = refcount + 1;
6469 refcount = get_refcount(test_object);
6470 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6471 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6472 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6473 refcount = get_refcount(test_object);
6474 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6476 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6477 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6478 --expected_refcount;
6479 refcount = get_refcount(test_object);
6480 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6482 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6483 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6484 size = sizeof(data);
6485 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
6486 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6487 refcount = get_refcount(test_object);
6488 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6489 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
6490 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6491 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
6492 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6494 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6495 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6496 ++expected_refcount;
6497 size = 2 * sizeof(ptr);
6498 ptr = NULL;
6499 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6500 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6501 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
6502 ++expected_refcount;
6503 refcount = get_refcount(test_object);
6504 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6505 IUnknown_Release(ptr);
6506 --expected_refcount;
6508 ptr = (IUnknown *)0xdeadbeef;
6509 size = 1;
6510 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
6511 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6512 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6513 size = 2 * sizeof(ptr);
6514 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
6515 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6516 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6517 refcount = get_refcount(test_object);
6518 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6520 size = 1;
6521 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6522 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
6523 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6524 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6525 if (!enable_debug_layer)
6527 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
6528 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6529 size = 0xdeadbabe;
6530 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
6531 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
6532 ok(size == 0, "Got unexpected size %u.\n", size);
6533 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6534 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
6535 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6536 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6539 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
6540 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6541 ptr = NULL;
6542 size = sizeof(ptr);
6543 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
6544 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6545 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6546 IUnknown_Release(ptr);
6548 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
6549 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
6550 "Texture should implement ID3D10Texture2D.\n");
6551 if (SUCCEEDED(hr))
6553 ptr = NULL;
6554 size = sizeof(ptr);
6555 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
6556 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6557 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6558 IUnknown_Release(ptr);
6559 ID3D10Texture2D_Release(d3d10_texture);
6562 IDXGISurface_Release(surface);
6563 ID3D11Texture2D_Release(texture);
6564 refcount = ID3D11Device_Release(device);
6565 ok(!refcount, "Device has %u references left.\n", refcount);
6566 refcount = ID3D11Device_Release(test_object);
6567 ok(!refcount, "Test object has %u references left.\n", refcount);
6570 static void test_state_refcounting(const D3D_FEATURE_LEVEL feature_level)
6572 ID3D11RasterizerState *rasterizer_state, *tmp_rasterizer_state;
6573 ID3D11Predicate *predicate, *tmp_predicate;
6574 ID3D11SamplerState *sampler, *tmp_sampler;
6575 ID3D11ShaderResourceView *srv, *tmp_srv;
6576 ID3D11RenderTargetView *rtv, *tmp_rtv;
6577 D3D11_RASTERIZER_DESC rasterizer_desc;
6578 D3D11_TEXTURE2D_DESC texture_desc;
6579 D3D11_QUERY_DESC predicate_desc;
6580 D3D11_SAMPLER_DESC sampler_desc;
6581 struct device_desc device_desc;
6582 ID3D11DeviceContext *context;
6583 ID3D11Texture2D *texture;
6584 ID3D11Device *device;
6585 ULONG refcount;
6586 HRESULT hr;
6588 device_desc.feature_level = &feature_level;
6589 device_desc.flags = 0;
6590 if (!(device = create_device(&device_desc)))
6592 skip("Failed to create device for feature level %#x.\n", feature_level);
6593 return;
6596 ID3D11Device_GetImmediateContext(device, &context);
6598 /* ID3D11SamplerState */
6599 memset(&sampler_desc, 0, sizeof(sampler_desc));
6600 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
6601 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
6602 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
6603 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
6604 sampler_desc.MaxLOD = FLT_MAX;
6605 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6606 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6608 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
6609 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6610 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6611 ID3D11SamplerState_Release(tmp_sampler);
6613 tmp_sampler = sampler;
6614 refcount = get_refcount(sampler);
6615 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
6616 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6617 refcount = ID3D11SamplerState_Release(sampler);
6618 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6619 sampler = NULL;
6620 ID3D11DeviceContext_PSGetSamplers(context, 0, 1, &sampler);
6621 ok(sampler == tmp_sampler, "Got sampler %p, expected %p.\n", sampler, tmp_sampler);
6622 refcount = ID3D11SamplerState_Release(sampler);
6623 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6625 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
6626 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6627 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6628 refcount = ID3D11SamplerState_Release(tmp_sampler);
6629 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6631 /* ID3D11RasterizerState */
6632 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
6633 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
6634 rasterizer_desc.CullMode = D3D11_CULL_BACK;
6635 rasterizer_desc.DepthClipEnable = TRUE;
6636 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
6637 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
6639 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
6640 refcount = ID3D11RasterizerState_Release(rasterizer_state);
6641 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6642 ID3D11DeviceContext_RSGetState(context, &tmp_rasterizer_state);
6643 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
6644 tmp_rasterizer_state, rasterizer_state);
6645 refcount = ID3D11RasterizerState_Release(tmp_rasterizer_state);
6646 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6648 /* ID3D11ShaderResourceView */
6649 memset(&texture_desc, 0, sizeof(texture_desc));
6650 texture_desc.Width = 32;
6651 texture_desc.Height = 32;
6652 texture_desc.MipLevels = 1;
6653 texture_desc.ArraySize = 1;
6654 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6655 texture_desc.SampleDesc.Count = 1;
6656 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6657 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6658 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6659 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6660 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6661 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
6662 ID3D11Texture2D_Release(texture);
6664 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6665 refcount = ID3D11ShaderResourceView_Release(srv);
6666 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6667 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &tmp_srv);
6668 ok(tmp_srv == srv, "Got SRV %p, expected %p.\n", tmp_srv, srv);
6669 refcount = ID3D11ShaderResourceView_Release(tmp_srv);
6670 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6672 /* ID3D11RenderTargetView */
6673 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6674 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6675 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6676 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
6677 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
6678 ID3D11Texture2D_Release(texture);
6680 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6681 refcount = ID3D11RenderTargetView_Release(rtv);
6682 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6683 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &tmp_rtv, NULL);
6684 ok(tmp_rtv == rtv, "Got RTV %p, expected %p.\n", tmp_rtv, rtv);
6685 refcount = ID3D11RenderTargetView_Release(tmp_rtv);
6686 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6688 /* ID3D11Predicate */
6689 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
6691 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
6692 predicate_desc.MiscFlags = 0;
6693 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
6694 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
6696 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
6697 refcount = ID3D11Predicate_Release(predicate);
6698 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6699 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, NULL);
6700 ok(tmp_predicate == predicate, "Got predicate %p, expected %p.\n", tmp_predicate, predicate);
6701 refcount = ID3D11Predicate_Release(tmp_predicate);
6702 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6705 ID3D11DeviceContext_Release(context);
6706 refcount = ID3D11Device_Release(device);
6707 ok(!refcount, "Device has %u references left.\n", refcount);
6710 static void test_device_context_state(void)
6712 static const GUID test_guid =
6713 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
6714 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
6716 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
6718 static const float custom_blend_factor[] = {0.1f, 0.2f, 0.3f, 0.4f};
6719 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
6720 #if 0
6721 float4 main(float4 pos : POSITION) : POSITION
6723 return pos;
6725 #endif
6726 static const DWORD simple_vs[] =
6728 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
6729 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6730 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6731 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6732 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
6733 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
6734 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6736 #if 0
6737 struct data
6739 float4 position : SV_Position;
6742 struct patch_constant_data
6744 float edges[3] : SV_TessFactor;
6745 float inside : SV_InsideTessFactor;
6748 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
6750 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
6751 output.inside = 1.0f;
6754 [domain("tri")]
6755 [outputcontrolpoints(3)]
6756 [partitioning("integer")]
6757 [outputtopology("triangle_ccw")]
6758 [patchconstantfunc("patch_constant")]
6759 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
6761 return input[i];
6764 [domain("tri")]
6765 void ds_main(patch_constant_data input,
6766 float3 tess_coord : SV_DomainLocation,
6767 const OutputPatch<data, 3> patch,
6768 out data output)
6770 output.position = tess_coord.x * patch[0].position
6771 + tess_coord.y * patch[1].position
6772 + tess_coord.z * patch[2].position;
6774 #endif
6775 static const DWORD simple_hs[] =
6777 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
6778 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
6779 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
6780 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
6781 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
6782 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
6783 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
6784 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
6785 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
6786 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
6787 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
6788 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
6789 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
6790 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
6791 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
6792 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
6793 0x00004001, 0x3f800000, 0x0100003e,
6795 static const DWORD simple_ds[] =
6797 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
6798 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
6799 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
6800 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
6801 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
6802 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
6803 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
6804 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
6805 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
6806 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
6807 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
6808 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
6809 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
6810 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
6811 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
6813 #if 0
6814 struct gs_out
6816 float4 pos : SV_POSITION;
6819 [maxvertexcount(4)]
6820 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
6822 float offset = 0.1 * vin[0].w;
6823 gs_out v;
6825 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
6826 vout.Append(v);
6827 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
6828 vout.Append(v);
6829 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
6830 vout.Append(v);
6831 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
6832 vout.Append(v);
6834 #endif
6835 static const DWORD simple_gs[] =
6837 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
6838 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6839 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6840 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
6841 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
6842 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
6843 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
6844 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
6845 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
6846 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
6847 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
6848 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
6849 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
6850 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
6851 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
6852 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
6853 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
6854 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
6856 #if 0
6857 float4 main(float4 color : COLOR) : SV_TARGET
6859 return color;
6861 #endif
6862 static const DWORD simple_ps[] =
6864 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
6865 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
6866 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
6867 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
6868 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
6869 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
6870 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6872 #if 0
6873 [numthreads(1, 1, 1)]
6874 void main() { }
6875 #endif
6876 static const DWORD simple_cs[] =
6878 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
6879 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
6880 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
6881 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
6883 static const struct vec4 constant = {1.257f, 1.885f, 2.513f, 3.770f};
6885 ID3DDeviceContextState *context_state, *previous_context_state, *tmp_context_state, *context_state2;
6886 UINT ib_offset, vb_offset, vb_stride, so_offset, offset, stride, sample_mask, stencil_ref, count;
6887 ID3D11Buffer *cb, *srvb, *uavb, *ib, *vb, *sob, *tmp_cb, *tmp_ib, *tmp_vb, *tmp_sob;
6888 D3D_FEATURE_LEVEL feature_level, selected_feature_level;
6889 ID3D11UnorderedAccessView *tmp_uav, *uav, *ps_uav;
6890 ID3D11Device *d3d11_device, *d3d11_device2;
6891 ID3D11SamplerState *sampler, *tmp_sampler;
6892 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
6893 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
6894 ID3D11DeviceContext1 *context, *context2;
6895 ID3D11ShaderResourceView *tmp_srv, *srv;
6896 D3D11_DEVICE_CONTEXT_TYPE context_type;
6897 ID3D11DepthStencilState *tmp_dss, *dss;
6898 ID3D11RenderTargetView *tmp_rtv, *rtv;
6899 ID3D11DepthStencilView *tmp_dsv, *dsv;
6900 ID3D11VertexShader *tmp_vs, *vs, *vs2;
6901 ID3D11RasterizerState *tmp_rs, *rs;
6902 D3D11_TEXTURE2D_DESC texture_desc;
6903 ID3D11GeometryShader *tmp_gs, *gs;
6904 enum D3D_PRIMITIVE_TOPOLOGY topo;
6905 ID3D11ComputeShader *tmp_cs, *cs;
6906 D3D11_DEPTH_STENCIL_DESC ds_desc;
6907 ID3D11Predicate *tmp_pred, *pred;
6908 ID3D11DomainShader *tmp_ds, *ds;
6909 D3D11_SAMPLER_DESC sampler_desc;
6910 D3D11_QUERY_DESC predicate_desc;
6911 ID3D11Device1 *device, *device2;
6912 ID3D11InputLayout *il, *tmp_il;
6913 ID3D11PixelShader *tmp_ps, *ps;
6914 D3D11_RASTERIZER_DESC rs_desc;
6915 ID3D11BlendState *tmp_bs, *bs;
6916 ID3D11HullShader *tmp_hs, *hs;
6917 D3D11_VIEWPORT tmp_vp[2], vp;
6918 D3D11_RECT tmp_rect[2], rect;
6919 D3D11_BLEND_DESC blend_desc;
6920 ID3D11Texture2D *texture;
6921 enum DXGI_FORMAT format;
6922 float blend_factor[4];
6923 DWORD data_size;
6924 BOOL pred_value;
6925 ULONG refcount;
6926 char data[64];
6927 HRESULT hr;
6929 if (!(d3d11_device = create_device(NULL)))
6931 skip("Failed to create device.\n");
6932 return;
6935 hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Device1, (void **)&device);
6936 ID3D11Device_Release(d3d11_device);
6937 if (FAILED(hr))
6939 skip("ID3D11Device1 is not available.\n");
6940 return;
6943 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
6944 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
6946 feature_level = ID3D11Device1_GetFeatureLevel(device);
6947 context = NULL;
6948 ID3D11Device1_GetImmediateContext1(device, &context);
6949 ok(!!context, "Failed to get immediate context.\n");
6951 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
6952 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
6953 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
6954 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
6955 sampler_desc.MipLODBias = 0.0f;
6956 sampler_desc.MaxAnisotropy = 0;
6957 sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
6958 sampler_desc.BorderColor[0] = 0.0f;
6959 sampler_desc.BorderColor[1] = 1.0f;
6960 sampler_desc.BorderColor[2] = 0.0f;
6961 sampler_desc.BorderColor[3] = 1.0f;
6962 sampler_desc.MinLOD = 0.0f;
6963 sampler_desc.MaxLOD = 16.0f;
6964 hr = ID3D11Device1_CreateSamplerState(device, &sampler_desc, &sampler);
6965 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6967 feature_level = min(feature_level, D3D_FEATURE_LEVEL_11_1);
6969 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level,
6970 1, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, NULL);
6971 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6973 selected_feature_level = 0xc0de0000;
6974 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1,
6975 D3D11_SDK_VERSION, &IID_ID3D11Device1, &selected_feature_level, NULL);
6976 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6977 ok(selected_feature_level == feature_level, "Got unexpected feature level %#x, expected %#x.\n",
6978 selected_feature_level, feature_level);
6980 selected_feature_level = 0xc0de0000;
6981 context_state = (void *)0xc0de0001;
6982 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 0,
6983 D3D11_SDK_VERSION, &IID_ID3D11Device1, &selected_feature_level, &context_state);
6984 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6985 ok(!selected_feature_level, "Got unexpected feature level %#x.\n", selected_feature_level);
6986 ok(!context_state, "Got unexpected context state %p.\n", context_state);
6988 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level,
6989 0, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, NULL);
6990 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6992 hr = ID3D11Device1_CreateDeviceContextState(device, 0, NULL,
6993 0, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, NULL);
6994 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6996 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level,
6997 1, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, &context_state);
6998 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6999 refcount = get_refcount(context_state);
7000 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
7002 context_type = ID3D11DeviceContext1_GetType(context);
7003 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7005 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
7006 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
7007 check_interface(device, &IID_ID3D11Device, TRUE, FALSE);
7008 check_interface(device, &IID_ID3D11Device1, TRUE, FALSE);
7010 cb = create_buffer((ID3D11Device *)device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), NULL);
7011 srvb = create_buffer((ID3D11Device *)device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
7012 uavb = create_buffer((ID3D11Device *)device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
7013 ib = create_buffer((ID3D11Device *)device, D3D11_BIND_INDEX_BUFFER, 1024, NULL);
7014 vb = create_buffer((ID3D11Device *)device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
7015 sob = create_buffer((ID3D11Device *)device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
7017 hr = ID3D11Device1_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
7018 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7020 hr = ID3D11Device1_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
7021 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
7023 hr = ID3D11Device1_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
7024 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
7026 if (feature_level < D3D_FEATURE_LEVEL_11_0) hs = NULL;
7027 else
7029 hr = ID3D11Device1_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
7030 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
7033 if (feature_level < D3D_FEATURE_LEVEL_11_0) ds = NULL;
7034 else
7036 hr = ID3D11Device1_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
7037 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
7040 if (feature_level < D3D_FEATURE_LEVEL_11_0) cs = NULL;
7041 else
7043 hr = ID3D11Device1_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
7044 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
7047 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
7048 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
7049 U(srv_desc).Buffer.ElementOffset = 0;
7050 U(srv_desc).Buffer.ElementWidth = 64;
7051 hr = ID3D11Device1_CreateShaderResourceView(device, (ID3D11Resource *)srvb, &srv_desc, &srv);
7052 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
7053 ID3D11Buffer_Release(srvb);
7055 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
7056 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
7057 U(uav_desc).Buffer.FirstElement = 0;
7058 U(uav_desc).Buffer.NumElements = 4;
7059 U(uav_desc).Buffer.Flags = 0;
7060 hr = ID3D11Device1_CreateUnorderedAccessView(device, (ID3D11Resource *)uavb, &uav_desc, &uav);
7061 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
7062 ID3D11Buffer_Release(uavb);
7064 uavb = create_buffer((ID3D11Device *)device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
7065 hr = ID3D11Device1_CreateUnorderedAccessView(device, (ID3D11Resource *)uavb, &uav_desc, &ps_uav);
7066 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
7067 ID3D11Buffer_Release(uavb);
7069 hr = ID3D11Device1_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
7070 simple_vs, sizeof(simple_vs), &il);
7071 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
7073 ib_offset = 16;
7074 vb_offset = 16;
7075 vb_stride = 16;
7076 so_offset = 16;
7078 texture_desc.Width = 512;
7079 texture_desc.Height = 512;
7080 texture_desc.MipLevels = 1;
7081 texture_desc.ArraySize = 1;
7082 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
7083 texture_desc.SampleDesc.Count = 1;
7084 texture_desc.SampleDesc.Quality = 0;
7085 texture_desc.Usage = D3D11_USAGE_DEFAULT;
7086 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
7087 texture_desc.CPUAccessFlags = 0;
7088 texture_desc.MiscFlags = 0;
7089 hr = ID3D11Device1_CreateTexture2D(device, &texture_desc, NULL, &texture);
7090 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7091 hr = ID3D11Device1_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
7092 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
7093 ID3D11Texture2D_Release(texture);
7095 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
7096 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
7097 hr = ID3D11Device1_CreateTexture2D(device, &texture_desc, NULL, &texture);
7098 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
7099 hr = ID3D11Device1_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
7100 ok(SUCCEEDED(hr), "Failed to create depth/stencil view, hr %#x.\n", hr);
7101 ID3D11Texture2D_Release(texture);
7103 memset(&blend_desc, 0, sizeof(blend_desc));
7104 blend_desc.RenderTarget[0].BlendEnable = TRUE;
7105 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
7106 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
7107 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
7108 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
7109 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
7110 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
7111 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
7112 hr = ID3D11Device1_CreateBlendState(device, &blend_desc, &bs);
7113 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
7115 ds_desc.DepthEnable = TRUE;
7116 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
7117 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
7118 ds_desc.StencilEnable = FALSE;
7119 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
7120 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
7121 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
7122 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
7123 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
7124 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
7125 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
7126 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
7127 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
7128 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
7129 hr = ID3D11Device1_CreateDepthStencilState(device, &ds_desc, &dss);
7130 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
7132 rs_desc.FillMode = D3D11_FILL_SOLID;
7133 rs_desc.CullMode = D3D11_CULL_BACK;
7134 rs_desc.FrontCounterClockwise = FALSE;
7135 rs_desc.DepthBias = 0;
7136 rs_desc.DepthBiasClamp = 0.0f;
7137 rs_desc.SlopeScaledDepthBias = 0.0f;
7138 rs_desc.DepthClipEnable = TRUE;
7139 rs_desc.ScissorEnable = TRUE;
7140 rs_desc.MultisampleEnable = FALSE;
7141 rs_desc.AntialiasedLineEnable = FALSE;
7142 hr = ID3D11Device1_CreateRasterizerState(device, &rs_desc, &rs);
7143 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
7145 SetRect(&rect, 0, 0, 1, 2);
7146 vp.TopLeftX = 0;
7147 vp.TopLeftY = 0;
7148 vp.Width = 3;
7149 vp.Height = 4;
7150 vp.MinDepth = 0.f;
7151 vp.MaxDepth = 0.01f;
7153 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
7154 predicate_desc.MiscFlags = 0;
7155 ID3D11Device1_CreatePredicate(device, &predicate_desc, &pred);
7157 ID3D11DeviceContext1_VSSetConstantBuffers(context, 0, 1, &cb);
7158 ID3D11DeviceContext1_VSSetSamplers(context, 0, 1, &sampler);
7159 ID3D11DeviceContext1_VSSetShader(context, vs, NULL, 0);
7160 ID3D11DeviceContext1_VSSetShaderResources(context, 0, 1, &srv);
7161 refcount = get_refcount(vs);
7162 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7164 ID3D11DeviceContext1_GSSetConstantBuffers(context, 0, 1, &cb);
7165 ID3D11DeviceContext1_GSSetSamplers(context, 0, 1, &sampler);
7166 ID3D11DeviceContext1_GSSetShader(context, gs, NULL, 0);
7167 ID3D11DeviceContext1_GSSetShaderResources(context, 0, 1, &srv);
7169 ID3D11DeviceContext1_PSSetConstantBuffers(context, 0, 1, &cb);
7170 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
7171 ID3D11DeviceContext1_PSSetShader(context, ps, NULL, 0);
7172 ID3D11DeviceContext1_PSSetShaderResources(context, 0, 1, &srv);
7174 ID3D11DeviceContext1_HSSetConstantBuffers(context, 0, 1, &cb);
7175 ID3D11DeviceContext1_HSSetSamplers(context, 0, 1, &sampler);
7176 ID3D11DeviceContext1_HSSetShader(context, hs, NULL, 0);
7177 ID3D11DeviceContext1_HSSetShaderResources(context, 0, 1, &srv);
7179 ID3D11DeviceContext1_DSSetConstantBuffers(context, 0, 1, &cb);
7180 ID3D11DeviceContext1_DSSetSamplers(context, 0, 1, &sampler);
7181 ID3D11DeviceContext1_DSSetShader(context, ds, NULL, 0);
7182 ID3D11DeviceContext1_DSSetShaderResources(context, 0, 1, &srv);
7184 ID3D11DeviceContext1_CSSetConstantBuffers(context, 0, 1, &cb);
7185 ID3D11DeviceContext1_CSSetSamplers(context, 0, 1, &sampler);
7186 ID3D11DeviceContext1_CSSetShader(context, cs, NULL, 0);
7187 ID3D11DeviceContext1_CSSetShaderResources(context, 0, 1, &srv);
7188 ID3D11DeviceContext1_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
7190 ID3D11DeviceContext1_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7191 ID3D11DeviceContext1_IASetInputLayout(context, il);
7192 ID3D11DeviceContext1_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, ib_offset);
7193 ID3D11DeviceContext1_IASetVertexBuffers(context, 0, 1, &vb, &vb_stride, &vb_offset);
7195 ID3D11DeviceContext1_OMSetBlendState(context, bs, custom_blend_factor, 0xff00ff00);
7196 ID3D11DeviceContext1_OMSetDepthStencilState(context, dss, 3);
7197 ID3D11DeviceContext1_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, dsv, 1, 1, &ps_uav, NULL);
7199 ID3D11DeviceContext1_RSSetScissorRects(context, 1, &rect);
7200 ID3D11DeviceContext1_RSSetViewports(context, 1, &vp);
7201 ID3D11DeviceContext1_RSSetState(context, rs);
7203 ID3D11DeviceContext1_SOSetTargets(context, 1, &sob, &so_offset);
7204 ID3D11DeviceContext1_SetPredication(context, pred, TRUE);
7206 previous_context_state = (ID3DDeviceContextState *)0xdeadbeef;
7207 ID3D11DeviceContext1_SwapDeviceContextState(context, NULL, &previous_context_state);
7208 ok(previous_context_state == NULL, "Got unexpected state pointer.\n");
7209 previous_context_state = NULL;
7210 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
7211 ok(previous_context_state != NULL, "Failed to get previous context state\n");
7212 refcount = get_refcount(vs);
7213 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7215 hr = ID3DDeviceContextState_SetPrivateData(context_state, &test_guid, sizeof(constant), &constant);
7216 ok(hr == S_OK, "Failed to set private data, hr %#x.\n", hr);
7217 refcount = ID3DDeviceContextState_Release(context_state);
7218 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7219 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
7220 data_size = sizeof(data);
7221 memset(data, 0xa5, sizeof(data));
7222 hr = ID3DDeviceContextState_GetPrivateData(context_state, &test_guid, &data_size, data);
7223 ok(hr == S_OK, "Failed to get private data, hr %#x.\n", hr);
7224 ok(data_size == sizeof(constant), "Got private data size %x, expected %x.\n", data_size, sizeof(constant));
7225 ok(!memcmp(data, &constant, sizeof(constant)), "Got unexpected private data.\n");
7226 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, NULL);
7228 context_type = ID3D11DeviceContext1_GetType(context);
7229 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7231 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7232 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7233 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7234 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7235 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7236 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7237 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7238 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7239 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7240 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7241 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7242 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7244 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7245 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7246 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7247 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7248 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7249 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7250 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7251 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7252 ok(!tmp_gs, "Got unexpected shader %p.\n", tmp_gs);
7253 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7254 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7255 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7257 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7258 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7259 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7260 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7261 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7262 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7263 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7264 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7265 ok(!tmp_ps, "Got unexpected shader %p.\n", tmp_ps);
7266 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7267 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7268 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7270 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7271 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7272 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7273 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7274 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7275 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7276 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7277 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7278 if (hs) ok(!tmp_hs, "Got unexpected shader %p.\n", tmp_hs);
7279 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7280 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7281 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7283 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7284 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7285 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7286 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7287 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7288 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7289 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7290 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7291 if (ds) ok(!tmp_ds, "Got unexpected shader %p.\n", tmp_ds);
7292 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7293 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7294 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7296 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7297 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7298 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7299 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7300 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7301 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7302 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7303 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7304 if (cs) ok(!tmp_cs, "Got unexpected shader %p.\n", tmp_cs);
7305 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7306 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7307 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7308 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7309 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7310 ok(!tmp_uav, "Got unexpected uav %p.\n", tmp_uav);
7312 topo = 0xdeadbeef;
7313 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7314 ok(topo == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected topology %#x.\n", topo);
7315 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7316 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7317 ok(!tmp_il, "Got unexpected input layout %p.\n", tmp_il);
7318 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7319 format = 0xdeadbeef;
7320 offset = 0xdeadbeef;
7321 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7322 ok(!tmp_ib, "Got unexpected input buffer %p.\n", tmp_ib);
7323 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected input buffer format %#x.\n", format);
7324 ok(offset == 0, "Got unexpected input buffer offset %#x.\n", offset);
7325 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7326 stride = 0xdeadbeef;
7327 offset = 0xdeadbeef;
7328 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7329 ok(!tmp_vb, "Got unexpected vertex buffer %p.\n", tmp_vb);
7330 ok(stride == 0, "Got unexpected vertex buffer stride %#x.\n", stride);
7331 ok(offset == 0, "Got unexpected vertex buffer offset %#x.\n", offset);
7333 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7334 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7335 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7336 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7337 ok(!tmp_rtv, "Got unexpected rendertarget view %p.\n", tmp_rtv);
7338 ok(!tmp_dsv, "Got unexpected depth/stencil view %p.\n", tmp_dsv);
7339 ok(!tmp_uav, "Got unexpected unordered access view %p.\n", tmp_uav);
7340 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7341 memset(blend_factor, 0xcd, sizeof(blend_factor));
7342 sample_mask = 0xdeadbeef;
7343 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7344 ok(!tmp_bs, "Got unexpected blend state %p.\n", tmp_bs);
7345 ok(!memcmp(blend_factor, default_blend_factor, sizeof(blend_factor)),
7346 "Got unexpected blend factor %f,%f,%f,%f.\n",
7347 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
7348 ok(sample_mask == ~0, "Got unexpected sample mask %#x.\n", sample_mask);
7349 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7350 stencil_ref = 0xdeadbeef;
7351 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7352 ok(!tmp_dss, "Got unexpected depth/stencil state %p.\n", tmp_dss);
7353 ok(stencil_ref == 0, "Got unexpected stencil ref %#x.\n", stencil_ref);
7355 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7356 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7357 ok(!tmp_rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7358 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7359 count = 2;
7360 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7361 ok(count == 0, "Got unexpected viewport count %u.\n", count);
7362 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7363 count = 2;
7364 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7365 ok(count == 0, "Got unexpected scissor rect count %u.\n", count);
7367 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7368 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7369 ok(!tmp_sob, "Got unexpected stream output buffer %p.\n", tmp_sob);
7371 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7372 pred_value = 0xdeadbeef;
7373 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7374 ok(!tmp_pred, "Got unexpected predicate %p.\n", tmp_pred);
7375 ok(!pred_value, "Got unexpected predicate value %d.\n", pred_value);
7377 /* updating the device context should also update the device context state */
7378 hr = ID3D11Device1_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs2);
7379 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7380 ID3D11DeviceContext1_VSSetShader(context, vs2, NULL, 0);
7381 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &tmp_context_state);
7382 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7383 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7384 ok(tmp_context_state == context_state, "Got unexpected state pointer.\n");
7385 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7386 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7387 ok(tmp_vs == vs2, "Got shader %p, expected %p.\n", tmp_vs, vs2);
7388 refcount = ID3D11VertexShader_Release(tmp_vs);
7389 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7391 /* context states may be used with other devices instances too */
7392 d3d11_device2 = create_device(NULL);
7393 ok(!!d3d11_device2, "Failed to create device.\n");
7394 hr = ID3D11Device_QueryInterface(d3d11_device2, &IID_ID3D11Device1, (void **)&device2);
7395 ok(SUCCEEDED(hr), "Failed to query device interface, hr %#x.\n", hr);
7396 ID3D11Device_Release(d3d11_device2);
7397 ID3D11Device1_GetImmediateContext1(device2, &context2);
7398 ok(!!context2, "Failed to get immediate context.\n");
7400 /* but they track a distinct state on each context */
7401 ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, &tmp_context_state);
7402 ok(!!tmp_context_state, "Failed to get context state.\n");
7403 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7404 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7405 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7407 /* updating context2 vertex shader doesn't update other contexts using the same state */
7408 ID3D11DeviceContext1_VSSetShader(context2, vs, NULL, 0);
7409 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7410 ok(tmp_vs == vs2, "Got shader %p, expected %p.\n", tmp_vs, vs2);
7411 refcount = ID3D11VertexShader_Release(tmp_vs);
7412 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7414 ID3D11DeviceContext1_SwapDeviceContextState(context2, tmp_context_state, &context_state2);
7415 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7416 ok(refcount == 0, "Got refcount %u, expected 1.\n", refcount);
7417 refcount = ID3DDeviceContextState_Release(context_state2);
7418 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7419 ok(context_state2 == context_state, "Got unexpected state pointer.\n");
7421 /* swapping the default state on context2 effectively clears the vertex shader */
7422 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7423 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7424 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7426 ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, &tmp_context_state);
7427 ok(!!tmp_context_state, "Failed to get context state.\n");
7428 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7429 ok(refcount == 0, "Got refcount %u, expected 1.\n", refcount);
7431 /* clearing the vertex shader on context doesn't have side effect on context2 */
7432 ID3D11DeviceContext1_VSSetShader(context, NULL, NULL, 0);
7433 refcount = ID3D11VertexShader_Release(vs2);
7434 ok(refcount == 0, "Got refcount %u, expected 0.\n", refcount);
7435 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7436 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7437 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7438 refcount = ID3D11VertexShader_Release(tmp_vs);
7439 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7441 /* even after swapping it again */
7442 ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, NULL);
7443 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7444 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7445 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7446 refcount = ID3D11VertexShader_Release(tmp_vs);
7447 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7449 /* swapping the initial state on context2 doesn't have side effect on context either */
7450 ID3D11DeviceContext1_SwapDeviceContextState(context2, previous_context_state, NULL);
7451 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7452 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7453 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7455 refcount = ID3D11DeviceContext1_Release(context2);
7456 ok(refcount == 0, "Got refcount %u, expected 0.\n", refcount);
7457 refcount = ID3D11Device1_Release(device2);
7458 ok(refcount == 0, "Got refcount %u, expected 0.\n", refcount);
7460 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &tmp_context_state);
7461 refcount = ID3DDeviceContextState_Release(previous_context_state);
7462 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7463 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7464 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7465 refcount = ID3DDeviceContextState_Release(context_state);
7466 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7467 ok(tmp_context_state == context_state, "Got unexpected state pointer.\n");
7468 refcount = get_refcount(vs);
7469 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7471 /* ID3DDeviceContextState retains the previous state. */
7473 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7474 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7475 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7476 ID3D11SamplerState_Release(tmp_sampler);
7477 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7478 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7479 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7480 ID3D11Buffer_Release(tmp_cb);
7481 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7482 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7483 ok(tmp_ps == ps, "Got shader %p, expected %p.\n", tmp_ps, ps);
7484 ID3D11PixelShader_Release(tmp_ps);
7485 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7486 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7487 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7488 ID3D11ShaderResourceView_Release(tmp_srv);
7490 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7491 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7492 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7493 ID3D11SamplerState_Release(tmp_sampler);
7494 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7495 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7496 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7497 ID3D11Buffer_Release(tmp_cb);
7498 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7499 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7500 ok(tmp_cs == cs, "Got shader %p, expected %p.\n", tmp_cs, cs);
7501 if (cs) ID3D11ComputeShader_Release(tmp_cs);
7502 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7503 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7504 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7505 ID3D11ShaderResourceView_Release(tmp_srv);
7506 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7507 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7508 ok(tmp_uav == uav, "Got uav %p, expected %p.\n", tmp_uav, uav);
7509 ID3D11UnorderedAccessView_Release(tmp_uav);
7511 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7512 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7513 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7514 ID3D11SamplerState_Release(tmp_sampler);
7515 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7516 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7517 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7518 ID3D11Buffer_Release(tmp_cb);
7519 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7520 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7521 ok(tmp_ds == ds, "Got shader %p, expected %p.\n", tmp_ds, ds);
7522 if (ds) ID3D11DomainShader_Release(tmp_ds);
7523 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7524 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7525 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7526 ID3D11ShaderResourceView_Release(tmp_srv);
7528 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7529 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7530 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7531 ID3D11SamplerState_Release(tmp_sampler);
7532 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7533 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7534 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7535 ID3D11Buffer_Release(tmp_cb);
7536 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7537 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7538 ok(tmp_gs == gs, "Got shader %p, expected %p.\n", tmp_gs, gs);
7539 ID3D11GeometryShader_Release(tmp_gs);
7540 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7541 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7542 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7543 ID3D11ShaderResourceView_Release(tmp_srv);
7545 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7546 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7547 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7548 ID3D11SamplerState_Release(tmp_sampler);
7549 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7550 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7551 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7552 ID3D11Buffer_Release(tmp_cb);
7553 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7554 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7555 ok(tmp_hs == hs, "Got shader %p, expected %p.\n", tmp_hs, hs);
7556 if (hs) ID3D11HullShader_Release(tmp_hs);
7557 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7558 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7559 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7560 ID3D11ShaderResourceView_Release(tmp_srv);
7562 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7563 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7564 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7565 ID3D11SamplerState_Release(tmp_sampler);
7566 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7567 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7568 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7569 ID3D11Buffer_Release(tmp_cb);
7570 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7571 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7572 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7573 ID3D11VertexShader_Release(tmp_vs);
7574 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7575 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7576 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7577 ID3D11ShaderResourceView_Release(tmp_srv);
7579 topo = 0xdeadbeef;
7580 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7581 ok(topo == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got topology %#x, expected %#x.\n", topo, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7582 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7583 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7584 ok(tmp_il == il, "Got input layout %p, expected %p.\n", tmp_il, il);
7585 ID3D11InputLayout_Release(tmp_il);
7586 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7587 format = 0xdeadbeef;
7588 offset = 0xdeadbeef;
7589 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7590 ok(tmp_ib == ib, "Got input buffer %p, expected %p.\n", tmp_ib, ib);
7591 ID3D11Buffer_Release(tmp_ib);
7592 ok(format == DXGI_FORMAT_R32_UINT, "Got input buffer format %#x, expected %#x.\n", format, DXGI_FORMAT_R32_UINT);
7593 ok(offset == 16, "Got input buffer offset %#x, expected 16.\n", offset);
7594 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7595 stride = 0xdeadbeef;
7596 offset = 0xdeadbeef;
7597 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7598 ok(tmp_vb == vb, "Got vertex buffer %p, expected %p.\n", tmp_vb, vb);
7599 ID3D11Buffer_Release(tmp_vb);
7600 ok(stride == 16, "Got vertex buffer stride %#x, expected 16.\n", stride);
7601 ok(offset == 16, "Got vertex buffer offset %#x, expected 16.\n", offset);
7603 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7604 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7605 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7606 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7607 ok(tmp_rtv == rtv, "Got rendertarget view %p, expected %p.\n", tmp_rtv, rtv);
7608 ID3D11RenderTargetView_Release(tmp_rtv);
7609 ok(tmp_dsv == dsv, "Got depth/stencil view %p, expected %p.\n", tmp_dsv, dsv);
7610 ID3D11DepthStencilView_Release(tmp_dsv);
7611 ok(tmp_uav == ps_uav, "Got unordered access view %p, expected %p.\n", tmp_uav, ps_uav);
7612 ID3D11UnorderedAccessView_Release(tmp_uav);
7613 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7614 memset(blend_factor, 0xcd, sizeof(blend_factor));
7615 sample_mask = 0xdeadbeef;
7616 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7617 ok(tmp_bs == bs, "Got blend state %p, expected %p.\n", tmp_bs, bs);
7618 ID3D11BlendState_Release(tmp_bs);
7619 ok(!memcmp(blend_factor, custom_blend_factor, sizeof(blend_factor)),
7620 "Got blend factor %f,%f,%f,%f, expected %f,%f,%f,%f.\n",
7621 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3],
7622 custom_blend_factor[0], custom_blend_factor[1], custom_blend_factor[2], custom_blend_factor[3]);
7623 ok(sample_mask == 0xff00ff00, "Got sample mask %#x, expected %#x.\n", sample_mask, 0xff00ff00);
7624 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7625 stencil_ref = 0xdeadbeef;
7626 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7627 ok(tmp_dss == dss, "Got depth/stencil state %p, expected %p.\n", tmp_dss, dss);
7628 ID3D11DepthStencilState_Release(tmp_dss);
7629 ok(stencil_ref == 3, "Got stencil ref %#x, expected 3.\n", stencil_ref);
7631 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7632 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7633 ok(tmp_rs == rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7634 ID3D11RasterizerState_Release(tmp_rs);
7635 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7636 count = 2;
7637 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7638 ok(count == 1, "Got viewport count %u, expected 1.\n", count);
7639 ok(!memcmp(tmp_vp, &vp, sizeof(vp)), "Got viewport %s, expected %s.\n",
7640 debugstr_viewport(tmp_vp), debugstr_viewport(&vp));
7641 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7642 count = 2;
7643 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7644 ok(count == 1, "Got scissor rect count %u, expected 1.\n", count);
7645 ok(!memcmp(tmp_rect, &rect, sizeof(rect)), "Got scissor rect %s, expected %s.\n",
7646 wine_dbgstr_rect(tmp_rect), wine_dbgstr_rect(&rect));
7648 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7649 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7650 ok(tmp_sob == sob, "Got stream output buffer %p, expected %p.\n", tmp_sob, sob);
7651 ID3D11Buffer_Release(tmp_sob);
7653 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7654 pred_value = 0xdeadbeef;
7655 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7656 ok(tmp_pred == pred, "Got predicate %p, expected %p.\n", tmp_pred, pred);
7657 ID3D11Predicate_Release(tmp_pred);
7658 ok(pred_value == TRUE, "Got predicate value %#x, expected TRUE.\n", pred_value);
7660 feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1);
7661 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
7662 &IID_ID3D10Device, NULL, &context_state);
7663 ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr);
7664 refcount = get_refcount(context_state);
7665 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7667 context_type = ID3D11DeviceContext1_GetType(context);
7668 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7670 /* Enable ID3D10Device behavior. */
7671 previous_context_state = NULL;
7672 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
7673 refcount = ID3DDeviceContextState_Release(context_state);
7674 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7675 ok(previous_context_state != NULL, "Failed to get previous context state\n");
7677 context_type = ID3D11DeviceContext1_GetType(context);
7678 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7680 ID3D11DeviceContext1_VSSetConstantBuffers(context, 0, 1, &cb);
7681 ID3D11DeviceContext1_VSSetSamplers(context, 0, 1, &sampler);
7682 ID3D11DeviceContext1_VSSetShader(context, vs, NULL, 0);
7683 ID3D11DeviceContext1_VSSetShaderResources(context, 0, 1, &srv);
7685 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7686 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7687 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7688 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7689 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7690 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7691 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7692 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7693 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7694 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7695 todo_wine ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7696 if (tmp_vs && tmp_vs != (ID3D11VertexShader *)0xdeadbeef) ID3D11VertexShader_Release(tmp_vs);
7697 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7698 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7699 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7700 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7702 ID3D11DeviceContext1_GSSetConstantBuffers(context, 0, 1, &cb);
7703 ID3D11DeviceContext1_GSSetSamplers(context, 0, 1, &sampler);
7704 ID3D11DeviceContext1_GSSetShader(context, gs, NULL, 0);
7705 ID3D11DeviceContext1_GSSetShaderResources(context, 0, 1, &srv);
7707 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7708 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7709 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7710 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7711 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7712 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7713 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7714 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7715 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7716 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7717 todo_wine ok(!tmp_gs, "Got unexpected shader %p.\n", tmp_gs);
7718 if (tmp_gs && tmp_gs != (ID3D11GeometryShader *)0xdeadbeef) ID3D11GeometryShader_Release(tmp_gs);
7719 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7720 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7721 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7722 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7724 ID3D11DeviceContext1_PSSetConstantBuffers(context, 0, 1, &cb);
7725 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
7726 ID3D11DeviceContext1_PSSetShader(context, ps, NULL, 0);
7727 ID3D11DeviceContext1_PSSetShaderResources(context, 0, 1, &srv);
7729 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7730 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7731 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7732 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7733 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7734 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7735 todo_wine ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler);
7736 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7737 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7738 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7739 todo_wine ok(!tmp_ps, "Got unexpected shader %p.\n", tmp_ps);
7740 if (tmp_ps && tmp_ps != (ID3D11PixelShader *)0xdeadbeef) ID3D11PixelShader_Release(tmp_ps);
7741 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7742 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7743 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7744 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7746 ID3D11DeviceContext1_HSSetConstantBuffers(context, 0, 1, &cb);
7747 ID3D11DeviceContext1_HSSetSamplers(context, 0, 1, &sampler);
7748 ID3D11DeviceContext1_HSSetShader(context, hs, NULL, 0);
7749 ID3D11DeviceContext1_HSSetShaderResources(context, 0, 1, &srv);
7751 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7752 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7753 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7754 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7755 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7756 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7757 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7758 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7759 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7760 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7761 if (hs) todo_wine ok(!tmp_hs, "Got unexpected shader %p.\n", tmp_hs);
7762 if (tmp_hs && tmp_hs != (ID3D11HullShader *)0xdeadbeef) ID3D11HullShader_Release(tmp_hs);
7763 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7764 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7765 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7766 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7768 ID3D11DeviceContext1_DSSetConstantBuffers(context, 0, 1, &cb);
7769 ID3D11DeviceContext1_DSSetSamplers(context, 0, 1, &sampler);
7770 ID3D11DeviceContext1_DSSetShader(context, ds, NULL, 0);
7771 ID3D11DeviceContext1_DSSetShaderResources(context, 0, 1, &srv);
7773 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7774 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7775 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7776 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7777 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7778 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7779 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7780 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7781 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7782 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7783 if (ds) todo_wine ok(!tmp_ds, "Got unexpected shader %p.\n", tmp_ds);
7784 if (tmp_ds && tmp_ds != (ID3D11DomainShader *)0xdeadbeef) ID3D11DomainShader_Release(tmp_ds);
7785 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7786 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7787 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7788 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7790 ID3D11DeviceContext1_CSSetConstantBuffers(context, 0, 1, &cb);
7791 ID3D11DeviceContext1_CSSetSamplers(context, 0, 1, &sampler);
7792 ID3D11DeviceContext1_CSSetShader(context, cs, NULL, 0);
7793 ID3D11DeviceContext1_CSSetShaderResources(context, 0, 1, &srv);
7794 ID3D11DeviceContext1_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
7796 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7797 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7798 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7799 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7800 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7801 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7802 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7803 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7804 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7805 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7806 if (cs) todo_wine ok(!tmp_cs, "Got unexpected shader %p.\n", tmp_cs);
7807 if (tmp_cs && tmp_cs != (ID3D11ComputeShader *)0xdeadbeef) ID3D11ComputeShader_Release(tmp_cs);
7808 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7809 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7810 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7811 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7812 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7813 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7814 todo_wine ok(!tmp_uav, "Got unexpected uav %p.\n", tmp_uav);
7815 if (tmp_uav && tmp_uav != (ID3D11UnorderedAccessView *)0xdeadbeef) ID3D11UnorderedAccessView_Release(tmp_uav);
7817 ID3D11DeviceContext1_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7818 ID3D11DeviceContext1_IASetInputLayout(context, il);
7819 ID3D11DeviceContext1_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, ib_offset);
7820 ID3D11DeviceContext1_IASetVertexBuffers(context, 0, 1, &vb, &vb_stride, &vb_offset);
7822 topo = 0xdeadbeef;
7823 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7824 todo_wine ok(topo == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected topology %#x.\n", topo);
7825 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7826 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7827 todo_wine ok(!tmp_il, "Got unexpected input layout %p.\n", tmp_il);
7828 if (tmp_il) ID3D11InputLayout_Release(tmp_il);
7829 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7830 format = 0xdeadbeef;
7831 offset = 0xdeadbeef;
7832 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7833 todo_wine ok(!tmp_ib, "Got unexpected input buffer %p.\n", tmp_ib);
7834 if (tmp_ib) ID3D11Buffer_Release(tmp_ib);
7835 todo_wine ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected input buffer format %#x.\n", format);
7836 todo_wine ok(offset == 0, "Got unexpected input buffer offset %#x.\n", offset);
7837 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7838 stride = 0xdeadbeef;
7839 offset = 0xdeadbeef;
7840 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7841 todo_wine ok(!tmp_vb, "Got unexpected vertex buffer %p.\n", tmp_vb);
7842 if (tmp_vb) ID3D11Buffer_Release(tmp_vb);
7843 todo_wine ok(stride == 0, "Got unexpected vertex buffer stride %#x.\n", stride);
7844 todo_wine ok(offset == 0, "Got unexpected vertex buffer offset %#x.\n", offset);
7846 ID3D11DeviceContext1_OMSetBlendState(context, bs, custom_blend_factor, 0xff00ff00);
7847 ID3D11DeviceContext1_OMSetDepthStencilState(context, dss, 3);
7848 ID3D11DeviceContext1_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, dsv, 1, 1, &ps_uav, NULL);
7850 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7851 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7852 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7853 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7854 todo_wine ok(!tmp_rtv, "Got unexpected rendertarget view %p.\n", tmp_rtv);
7855 if (tmp_rtv) ID3D11RenderTargetView_Release(tmp_rtv);
7856 todo_wine ok(!tmp_dsv, "Got unexpected depth/stencil view %p.\n", tmp_dsv);
7857 if (tmp_dsv) ID3D11DepthStencilView_Release(tmp_dsv);
7858 todo_wine ok(!tmp_uav, "Got unexpected unordered access view %p.\n", tmp_uav);
7859 if (tmp_uav) ID3D11UnorderedAccessView_Release(tmp_uav);
7860 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7861 memset(blend_factor, 0xcd, sizeof(blend_factor));
7862 sample_mask = 0xdeadbeef;
7863 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7864 todo_wine ok(!tmp_bs, "Got unexpected blend state %p.\n", tmp_bs);
7865 if (tmp_bs) ID3D11BlendState_Release(tmp_bs);
7866 todo_wine ok(!memcmp(blend_factor, default_blend_factor, sizeof(blend_factor)),
7867 "Got unexpected blend factor %f,%f,%f,%f.\n",
7868 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
7869 todo_wine ok(sample_mask == ~0, "Got unexpected sample mask %#x.\n", sample_mask);
7870 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7871 stencil_ref = 0xdeadbeef;
7872 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7873 todo_wine ok(!tmp_dss, "Got unexpected depth/stencil state %p.\n", tmp_dss);
7874 if (tmp_dss) ID3D11DepthStencilState_Release(tmp_dss);
7875 todo_wine ok(stencil_ref == 0, "Got unexpected stencil ref %#x.\n", stencil_ref);
7877 ID3D11DeviceContext1_RSSetScissorRects(context, 1, &rect);
7878 ID3D11DeviceContext1_RSSetViewports(context, 1, &vp);
7879 ID3D11DeviceContext1_RSSetState(context, rs);
7881 ID3D11DeviceContext1_SOSetTargets(context, 1, &sob, &so_offset);
7882 ID3D11DeviceContext1_SetPredication(context, pred, TRUE);
7884 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7885 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7886 todo_wine ok(!tmp_rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7887 if (tmp_rs) ID3D11RasterizerState_Release(tmp_rs);
7888 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7889 count = 2;
7890 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7891 todo_wine ok(count == 0, "Got unexpected viewport count %u.\n", count);
7892 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7893 count = 2;
7894 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7895 todo_wine ok(count == 0, "Got unexpected scissor rect count %u.\n", count);
7897 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7898 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7899 todo_wine ok(!tmp_sob, "Got unexpected stream output buffer %p.\n", tmp_sob);
7900 if (tmp_sob) ID3D11Buffer_Release(tmp_sob);
7902 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7903 pred_value = 0xdeadbeef;
7904 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7905 todo_wine ok(!tmp_pred, "Got unexpected predicate %p.\n", tmp_pred);
7906 if (tmp_pred) ID3D11Predicate_Release(tmp_pred);
7907 todo_wine ok(!pred_value, "Got unexpected predicate value %d.\n", pred_value);
7909 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
7910 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
7912 context_state = NULL;
7913 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
7914 refcount = ID3DDeviceContextState_Release(context_state);
7915 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7916 refcount = ID3DDeviceContextState_Release(previous_context_state);
7917 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7919 /* ID3DDeviceContextState retains the previous state. */
7921 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7922 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7923 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7924 ID3D11SamplerState_Release(tmp_sampler);
7925 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7926 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7927 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7928 ID3D11Buffer_Release(tmp_cb);
7929 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7930 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7931 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7932 ID3D11VertexShader_Release(tmp_vs);
7933 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7934 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7935 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7936 ID3D11ShaderResourceView_Release(tmp_srv);
7938 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7939 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7940 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7941 ID3D11SamplerState_Release(tmp_sampler);
7942 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7943 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7944 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7945 ID3D11Buffer_Release(tmp_cb);
7946 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7947 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7948 ok(tmp_gs == gs, "Got shader %p, expected %p.\n", tmp_gs, gs);
7949 ID3D11GeometryShader_Release(tmp_gs);
7950 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7951 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7952 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7953 ID3D11ShaderResourceView_Release(tmp_srv);
7955 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7956 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7957 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7958 ID3D11SamplerState_Release(tmp_sampler);
7959 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7960 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7961 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7962 ID3D11Buffer_Release(tmp_cb);
7963 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7964 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7965 ok(tmp_ps == ps, "Got shader %p, expected %p.\n", tmp_ps, ps);
7966 ID3D11PixelShader_Release(tmp_ps);
7967 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7968 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7969 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7970 ID3D11ShaderResourceView_Release(tmp_srv);
7972 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7973 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7974 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7975 ID3D11SamplerState_Release(tmp_sampler);
7976 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7977 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7978 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7979 ID3D11Buffer_Release(tmp_cb);
7980 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7981 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7982 ok(tmp_hs == hs, "Got shader %p, expected %p.\n", tmp_hs, hs);
7983 if (hs) ID3D11HullShader_Release(tmp_hs);
7984 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7985 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7986 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7987 ID3D11ShaderResourceView_Release(tmp_srv);
7989 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7990 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7991 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7992 ID3D11SamplerState_Release(tmp_sampler);
7993 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7994 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7995 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7996 ID3D11Buffer_Release(tmp_cb);
7997 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7998 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7999 ok(tmp_ds == ds, "Got shader %p, expected %p.\n", tmp_ds, ds);
8000 if (ds) ID3D11DomainShader_Release(tmp_ds);
8001 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
8002 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
8003 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
8004 ID3D11ShaderResourceView_Release(tmp_srv);
8006 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
8007 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
8008 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
8009 ID3D11SamplerState_Release(tmp_sampler);
8010 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
8011 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
8012 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
8013 ID3D11Buffer_Release(tmp_cb);
8014 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
8015 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
8016 ok(tmp_cs == cs, "Got shader %p, expected %p.\n", tmp_cs, cs);
8017 if (cs) ID3D11ComputeShader_Release(tmp_cs);
8018 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
8019 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
8020 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
8021 ID3D11ShaderResourceView_Release(tmp_srv);
8022 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
8023 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
8024 ok(tmp_uav == uav, "Got uav %p, expected %p.\n", tmp_uav, uav);
8025 ID3D11UnorderedAccessView_Release(tmp_uav);
8027 topo = 0xdeadbeef;
8028 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
8029 ok(topo == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got topology %#x, expected %#x.\n", topo, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8030 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
8031 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
8032 ok(tmp_il == il, "Got input layout %p, expected %p.\n", tmp_il, il);
8033 ID3D11InputLayout_Release(tmp_il);
8034 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
8035 format = 0xdeadbeef;
8036 offset = 0xdeadbeef;
8037 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
8038 ok(tmp_ib == ib, "Got input buffer %p, expected %p.\n", tmp_ib, ib);
8039 ID3D11Buffer_Release(tmp_ib);
8040 ok(format == DXGI_FORMAT_R32_UINT, "Got input buffer format %#x, expected %#x.\n", format, DXGI_FORMAT_R32_UINT);
8041 ok(offset == 16, "Got input buffer offset %#x, expected 16.\n", offset);
8042 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
8043 stride = 0xdeadbeef;
8044 offset = 0xdeadbeef;
8045 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
8046 ok(tmp_vb == vb, "Got vertex buffer %p, expected %p.\n", tmp_vb, vb);
8047 ID3D11Buffer_Release(tmp_vb);
8048 ok(stride == 16, "Got vertex buffer stride %#x, expected 16.\n", stride);
8049 ok(offset == 16, "Got vertex buffer offset %#x, expected 16.\n", offset);
8051 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
8052 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
8053 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
8054 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
8055 ok(tmp_rtv == rtv, "Got rendertarget view %p, expected %p.\n", tmp_rtv, rtv);
8056 ID3D11RenderTargetView_Release(tmp_rtv);
8057 ok(tmp_dsv == dsv, "Got depth/stencil view %p, expected %p.\n", tmp_dsv, dsv);
8058 ID3D11DepthStencilView_Release(tmp_dsv);
8059 ok(tmp_uav == ps_uav, "Got unordered access view %p, expected %p.\n", tmp_uav, ps_uav);
8060 ID3D11UnorderedAccessView_Release(tmp_uav);
8061 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
8062 memset(blend_factor, 0xcd, sizeof(blend_factor));
8063 sample_mask = 0xdeadbeef;
8064 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
8065 ok(tmp_bs == bs, "Got blend state %p, expected %p.\n", tmp_bs, bs);
8066 ID3D11BlendState_Release(tmp_bs);
8067 ok(!memcmp(blend_factor, custom_blend_factor, sizeof(blend_factor)),
8068 "Got blend factor %f,%f,%f,%f, expected %f,%f,%f,%f.\n",
8069 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3],
8070 custom_blend_factor[0], custom_blend_factor[1], custom_blend_factor[2], custom_blend_factor[3]);
8071 ok(sample_mask == 0xff00ff00, "Got sample mask %#x, expected %#x.\n", sample_mask, 0xff00ff00);
8072 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
8073 stencil_ref = 0xdeadbeef;
8074 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
8075 ok(tmp_dss == dss, "Got depth/stencil state %p, expected %p.\n", tmp_dss, dss);
8076 ID3D11DepthStencilState_Release(tmp_dss);
8077 ok(stencil_ref == 3, "Got stencil ref %#x, expected 3.\n", stencil_ref);
8079 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
8080 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
8081 ok(tmp_rs == rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
8082 ID3D11RasterizerState_Release(tmp_rs);
8083 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
8084 count = 2;
8085 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
8086 ok(count == 1, "Got viewport count %u, expected 1.\n", count);
8087 ok(!memcmp(tmp_vp, &vp, sizeof(vp)), "Got viewport %s, expected %s.\n",
8088 debugstr_viewport(tmp_vp), debugstr_viewport(&vp));
8089 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
8090 count = 2;
8091 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
8092 ok(count == 1, "Got scissor rect count %u, expected 1.\n", count);
8093 ok(!memcmp(tmp_rect, &rect, sizeof(rect)), "Got scissor rect %s, expected %s.\n",
8094 wine_dbgstr_rect(tmp_rect), wine_dbgstr_rect(&rect));
8096 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
8097 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
8098 ok(tmp_sob == sob, "Got stream output buffer %p, expected %p.\n", tmp_sob, sob);
8099 ID3D11Buffer_Release(tmp_sob);
8101 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
8102 pred_value = 0xdeadbeef;
8103 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
8104 ok(tmp_pred == pred, "Got predicate %p, expected %p.\n", tmp_pred, pred);
8105 ID3D11Predicate_Release(tmp_pred);
8106 ok(pred_value == TRUE, "Got predicate value %#x, expected TRUE.\n", pred_value);
8108 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
8109 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
8111 ID3D11Predicate_Release(pred);
8112 ID3D11Buffer_Release(sob);
8113 ID3D11RasterizerState_Release(rs);
8114 ID3D11BlendState_Release(bs);
8115 ID3D11DepthStencilState_Release(dss);
8116 ID3D11DepthStencilView_Release(dsv);
8117 ID3D11RenderTargetView_Release(rtv);
8118 ID3D11UnorderedAccessView_Release(ps_uav);
8119 ID3D11InputLayout_Release(il);
8120 ID3D11Buffer_Release(ib);
8121 ID3D11Buffer_Release(vb);
8122 if (cs) ID3D11ComputeShader_Release(cs);
8123 if (ds) ID3D11DomainShader_Release(ds);
8124 if (hs) ID3D11HullShader_Release(hs);
8125 ID3D11PixelShader_Release(ps);
8126 ID3D11GeometryShader_Release(gs);
8127 ID3D11VertexShader_Release(vs);
8128 ID3D11Buffer_Release(cb);
8129 ID3D11ShaderResourceView_Release(srv);
8130 ID3D11UnorderedAccessView_Release(uav);
8131 ID3D11SamplerState_Release(sampler);
8132 ID3D11DeviceContext1_Release(context);
8133 refcount = ID3D11Device1_Release(device);
8134 ok(!refcount, "Device has %u references left.\n", refcount);
8137 static void test_blend(void)
8139 ID3D11BlendState *src_blend, *dst_blend, *dst_blend_factor;
8140 struct d3d11_test_context test_context;
8141 ID3D11RenderTargetView *offscreen_rtv;
8142 D3D11_TEXTURE2D_DESC texture_desc;
8143 ID3D11InputLayout *input_layout;
8144 ID3D11DeviceContext *context;
8145 D3D11_BLEND_DESC blend_desc;
8146 unsigned int stride, offset;
8147 ID3D11Texture2D *offscreen;
8148 ID3D11VertexShader *vs;
8149 ID3D11PixelShader *ps;
8150 ID3D11Device *device;
8151 ID3D11Buffer *vb;
8152 DWORD color;
8153 HRESULT hr;
8155 static const DWORD vs_code[] =
8157 #if 0
8158 struct vs_out
8160 float4 position : SV_POSITION;
8161 float4 color : COLOR;
8164 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
8166 struct vs_out o;
8168 o.position = position;
8169 o.color = color;
8171 return o;
8173 #endif
8174 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
8175 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
8176 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8177 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
8178 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
8179 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
8180 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
8181 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
8182 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
8183 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
8185 static const DWORD ps_code[] =
8187 #if 0
8188 struct vs_out
8190 float4 position : SV_POSITION;
8191 float4 color : COLOR;
8194 float4 main(struct vs_out i) : SV_TARGET
8196 return i.color;
8198 #endif
8199 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
8200 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8201 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
8202 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
8203 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8204 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
8205 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
8206 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8208 static const struct
8210 struct vec3 position;
8211 DWORD diffuse;
8213 quads[] =
8215 /* quad1 */
8216 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
8217 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
8218 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
8219 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
8220 /* quad2 */
8221 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
8222 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
8223 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
8224 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
8226 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8228 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8229 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
8231 static const float blend_factor[] = {0.3f, 0.4f, 0.8f, 0.9f};
8232 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8234 if (!init_test_context(&test_context, NULL))
8235 return;
8237 device = test_context.device;
8238 context = test_context.immediate_context;
8240 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8241 vs_code, sizeof(vs_code), &input_layout);
8242 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8244 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
8246 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
8247 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8248 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8249 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8251 memset(&blend_desc, 0, sizeof(blend_desc));
8252 blend_desc.RenderTarget[0].BlendEnable = TRUE;
8253 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
8254 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
8255 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
8256 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
8257 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
8258 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
8259 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
8261 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
8262 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8264 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
8265 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
8266 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
8267 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
8269 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
8270 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8272 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_BLEND_FACTOR;
8273 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_BLEND_FACTOR;
8274 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
8275 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
8277 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend_factor);
8278 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8280 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
8281 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8282 stride = sizeof(*quads);
8283 offset = 0;
8284 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
8285 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
8286 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8288 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8290 ID3D11DeviceContext_OMSetBlendState(context, src_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8291 ID3D11DeviceContext_Draw(context, 4, 0);
8292 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8293 ID3D11DeviceContext_Draw(context, 4, 4);
8295 color = get_texture_color(test_context.backbuffer, 320, 360);
8296 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
8297 color = get_texture_color(test_context.backbuffer, 320, 120);
8298 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
8300 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8302 ID3D11DeviceContext_OMSetBlendState(context, dst_blend_factor, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
8303 ID3D11DeviceContext_Draw(context, 4, 0);
8304 ID3D11DeviceContext_Draw(context, 4, 4);
8306 color = get_texture_color(test_context.backbuffer, 320, 360);
8307 ok(compare_color(color, 0x600066b3, 1), "Got unexpected color 0x%08x.\n", color);
8308 color = get_texture_color(test_context.backbuffer, 320, 120);
8309 ok(compare_color(color, 0xa0cc00b3, 1), "Got unexpected color 0x%08x.\n", color);
8311 texture_desc.Width = 128;
8312 texture_desc.Height = 128;
8313 texture_desc.MipLevels = 1;
8314 texture_desc.ArraySize = 1;
8315 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
8316 texture_desc.SampleDesc.Count = 1;
8317 texture_desc.SampleDesc.Quality = 0;
8318 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8319 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
8320 texture_desc.CPUAccessFlags = 0;
8321 texture_desc.MiscFlags = 0;
8323 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
8324 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
8326 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
8327 goto done;
8330 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
8331 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8333 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
8335 set_viewport(context, 0.0f, 0.0f, 128.0f, 128.0f, 0.0f, 1.0f);
8337 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
8339 ID3D11DeviceContext_OMSetBlendState(context, src_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8340 ID3D11DeviceContext_Draw(context, 4, 0);
8341 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8342 ID3D11DeviceContext_Draw(context, 4, 4);
8344 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
8345 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
8346 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
8347 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
8349 ID3D11RenderTargetView_Release(offscreen_rtv);
8350 ID3D11Texture2D_Release(offscreen);
8351 done:
8352 ID3D11BlendState_Release(dst_blend_factor);
8353 ID3D11BlendState_Release(dst_blend);
8354 ID3D11BlendState_Release(src_blend);
8355 ID3D11PixelShader_Release(ps);
8356 ID3D11VertexShader_Release(vs);
8357 ID3D11Buffer_Release(vb);
8358 ID3D11InputLayout_Release(input_layout);
8359 release_test_context(&test_context);
8362 static void test_texture1d(void)
8364 struct shader
8366 const DWORD *code;
8367 size_t size;
8369 struct texture
8371 UINT width;
8372 UINT miplevel_count;
8373 UINT array_size;
8374 DXGI_FORMAT format;
8375 D3D11_SUBRESOURCE_DATA data[3];
8378 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8379 struct d3d11_test_context test_context;
8380 const struct texture *current_texture;
8381 D3D11_TEXTURE1D_DESC texture_desc;
8382 D3D11_SAMPLER_DESC sampler_desc;
8383 const struct shader *current_ps;
8384 D3D_FEATURE_LEVEL feature_level;
8385 ID3D11ShaderResourceView *srv;
8386 ID3D11DeviceContext *context;
8387 ID3D11SamplerState *sampler;
8388 struct resource_readback rb;
8389 ID3D11Texture1D *texture;
8390 struct vec4 ps_constant;
8391 ID3D11PixelShader *ps;
8392 ID3D11Device *device;
8393 unsigned int i, x;
8394 ID3D11Buffer *cb;
8395 DWORD color;
8396 HRESULT hr;
8398 static const DWORD ps_ld_code[] =
8400 #if 0
8401 Texture1D t;
8403 float miplevel;
8405 float4 main(float4 position : SV_POSITION) : SV_TARGET
8407 float2 p;
8408 t.GetDimensions(miplevel, p.x, p.y);
8409 p.y = miplevel;
8410 p *= float2(position.x / 640.0f, 1.0f);
8411 return t.Load(int2(p));
8413 #endif
8414 0x43425844, 0x7b0c6359, 0x598178f6, 0xef2ddbdb, 0x88fc794c, 0x00000001, 0x000001ac, 0x00000003,
8415 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8416 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8417 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8418 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
8419 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001058, 0x00107000, 0x00000000,
8420 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8421 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
8422 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
8423 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000e2,
8424 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
8425 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
8426 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
8427 0x00107e46, 0x00000000, 0x0100003e,
8429 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
8430 static const DWORD ps_ld_sint8_code[] =
8432 #if 0
8433 Texture1D<int4> t;
8435 float4 main(float4 position : SV_POSITION) : SV_TARGET
8437 float2 p, s;
8438 int4 c;
8440 p = float2(position.x / 640.0f, 0.0f);
8441 t.GetDimensions(0, s.x, s.y);
8442 p *= s;
8444 c = t.Load(int2(p));
8445 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
8447 #endif
8448 0x43425844, 0x65a13d1e, 0x8a0bfc92, 0xa2f2708a, 0x0bafafb6, 0x00000001, 0x00000234, 0x00000003,
8449 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8450 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8451 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8452 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000198, 0x00000040,
8453 0x00000066, 0x04001058, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101012, 0x00000000,
8454 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8455 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
8456 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
8457 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
8458 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8459 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0500002b,
8460 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
8461 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204, 0x3c010204, 0x0a000034, 0x001000f2,
8462 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000, 0xbf800000, 0xbf800000, 0xbf800000,
8463 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
8464 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002,
8465 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
8467 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
8468 static const DWORD ps_ld_uint8_code[] =
8470 #if 0
8471 Texture1D<uint4> t;
8473 float4 main(float4 position : SV_POSITION) : SV_TARGET
8475 float2 p, s;
8477 p = float2(position.x / 640.0f, 0.0f);
8478 t.GetDimensions(0, s.x, s.y);
8479 p *= s;
8481 return t.Load(int2(p)) / (float4)255;
8483 #endif
8484 0x43425844, 0x35186c1f, 0x55bad4fd, 0xb7c97a57, 0x99c060e7, 0x00000001, 0x000001bc, 0x00000003,
8485 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8486 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8487 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8488 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000120, 0x00000040,
8489 0x00000048, 0x04001058, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101012, 0x00000000,
8490 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8491 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
8492 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
8493 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
8494 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8495 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x05000056,
8496 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46,
8497 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081, 0x3b808081, 0x0100003e,
8499 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
8500 static DWORD ps_ld_array_code[] =
8502 #if 0
8503 Texture1DArray t;
8505 float miplevel;
8507 float4 main(float4 position : SV_POSITION) : SV_TARGET
8509 float3 p;
8510 t.GetDimensions(miplevel, p.x, p.y, p.z);
8511 p.y = 1;
8512 p.z = miplevel;
8513 p *= float3(position.x / 640.0f, 1.0f, 1.0f);
8514 return t.Load(int3(p));
8516 #endif
8517 0x43425844, 0xbfccadc4, 0xc00ff13d, 0x2ba75365, 0xf747cbee, 0x00000001, 0x000001c0, 0x00000003,
8518 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8519 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8520 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8521 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000124, 0x00000040,
8522 0x00000049, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003858, 0x00107000, 0x00000000,
8523 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8524 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
8525 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
8526 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000c2,
8527 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x00100072, 0x00000000, 0x00100386,
8528 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x00000000, 0x0500001b, 0x001000d2,
8529 0x00000000, 0x00100906, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000001,
8530 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
8532 static const struct shader ps_ld_array = {ps_ld_array_code, sizeof(ps_ld_array_code)};
8534 static const DWORD rgba_level_0[] =
8536 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8538 static const DWORD rgba_level_1[] =
8540 0xffffffff, 0xff0000ff,
8542 static const DWORD rgba_level_2[] =
8544 0xffff0000,
8546 static const DWORD srgb_data[] =
8548 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
8550 static const DWORD r32_uint[] =
8552 0, 1, 2, 3,
8554 static const DWORD r9g9b9e5_data[] =
8556 0x80000100, 0x80020000, 0x84000000, 0x84000100,
8558 static const DWORD array_data0[] =
8560 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8562 static const DWORD array_data1[] =
8564 0x00ffff00, 0xff000000, 0x00ff0000, 0x000000ff,
8566 static const DWORD array_data2[] =
8568 0x000000ff, 0xffff00ff, 0x0000ff00, 0xff000000,
8570 static const struct texture rgba_texture =
8572 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
8574 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
8575 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
8576 {rgba_level_2, sizeof(*rgba_level_2), 0},
8579 static const struct texture srgb_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
8580 {{srgb_data, 4 * sizeof(*srgb_data)}}};
8581 static const struct texture sint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
8582 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
8583 static const struct texture uint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
8584 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
8585 static const struct texture r32u_typeless = {4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
8586 {{r32_uint, 4 * sizeof(*r32_uint)}}};
8587 static const struct texture r9g9b9e5_texture = {4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
8588 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
8589 static const struct texture array_texture = {4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
8591 {array_data0, 4 * sizeof(*array_data0)},
8592 {array_data1, 4 * sizeof(*array_data1)},
8593 {array_data2, 4 * sizeof(*array_data2)},
8597 static const DWORD level_1_colors[] =
8599 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
8601 static const DWORD level_2_colors[] =
8603 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
8605 static const DWORD srgb_colors[] =
8607 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
8609 static const DWORD sint8_colors[] =
8611 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
8613 static const DWORD r32u_colors[4] =
8615 0x01000000, 0x01000001, 0x01000002, 0x01000003,
8617 static const DWORD r9g9b9e5_colors[4] =
8619 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
8621 static const DWORD zero_colors[4] = {0};
8622 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8623 static const struct texture_test
8625 const struct shader *ps;
8626 const struct texture *texture;
8627 D3D11_FILTER filter;
8628 float lod_bias;
8629 float min_lod;
8630 float max_lod;
8631 float ps_constant;
8632 const DWORD *expected_colors;
8634 texture_tests[] =
8636 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
8637 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
8638 #define MIP_MAX D3D11_FLOAT32_MAX
8639 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
8640 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
8641 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
8642 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
8643 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
8644 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
8645 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
8646 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
8647 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
8648 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
8649 {&ps_ld_array, &array_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, array_data1},
8651 #undef POINT
8652 #undef POINT_LINEAR
8653 #undef MIP_MAX
8654 static const struct srv_test
8656 const struct shader *ps;
8657 const struct texture *texture;
8658 struct srv_desc srv_desc;
8659 float ps_constant;
8660 const DWORD *expected_colors;
8662 srv_tests[] =
8664 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
8665 #define R32_UINT DXGI_FORMAT_R32_UINT
8666 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_1D, 0, 1}, 0.0f, r32u_colors},
8667 #undef TEX_1D
8668 #undef R32_UINT
8669 #undef FMT_UNKNOWN
8672 if (!init_test_context(&test_context, NULL))
8673 return;
8675 device = test_context.device;
8676 context = test_context.immediate_context;
8677 feature_level = ID3D11Device_GetFeatureLevel(device);
8679 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
8681 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8683 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8684 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
8685 texture_desc.CPUAccessFlags = 0;
8686 texture_desc.MiscFlags = 0;
8688 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8689 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8690 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8691 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8692 sampler_desc.MipLODBias = 0.0f;
8693 sampler_desc.MaxAnisotropy = 0;
8694 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8695 sampler_desc.BorderColor[0] = 0.0f;
8696 sampler_desc.BorderColor[1] = 0.0f;
8697 sampler_desc.BorderColor[2] = 0.0f;
8698 sampler_desc.BorderColor[3] = 0.0f;
8699 sampler_desc.MinLOD = 0.0f;
8700 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
8702 ps = NULL;
8703 srv = NULL;
8704 sampler = NULL;
8705 texture = NULL;
8706 current_ps = NULL;
8707 current_texture = NULL;
8708 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
8710 const struct texture_test *test = &texture_tests[i];
8712 if (current_ps != test->ps)
8714 if (ps)
8715 ID3D11PixelShader_Release(ps);
8717 current_ps = test->ps;
8719 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
8720 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
8722 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8725 if (current_texture != test->texture)
8727 if (texture)
8728 ID3D11Texture1D_Release(texture);
8729 if (srv)
8730 ID3D11ShaderResourceView_Release(srv);
8732 current_texture = test->texture;
8734 if (current_texture)
8736 texture_desc.Width = current_texture->width;
8737 texture_desc.MipLevels = current_texture->miplevel_count;
8738 texture_desc.ArraySize = current_texture->array_size;
8739 texture_desc.Format = current_texture->format;
8741 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
8742 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
8744 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
8745 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
8747 else
8749 texture = NULL;
8750 srv = NULL;
8753 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8756 if (!sampler || (sampler_desc.Filter != test->filter
8757 || sampler_desc.MipLODBias != test->lod_bias
8758 || sampler_desc.MinLOD != test->min_lod
8759 || sampler_desc.MaxLOD != test->max_lod))
8761 if (sampler)
8762 ID3D11SamplerState_Release(sampler);
8764 sampler_desc.Filter = test->filter;
8765 sampler_desc.MipLODBias = test->lod_bias;
8766 sampler_desc.MinLOD = test->min_lod;
8767 sampler_desc.MaxLOD = test->max_lod;
8769 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
8770 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
8772 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8775 ps_constant.x = test->ps_constant;
8776 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
8778 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8780 draw_quad(&test_context);
8782 get_texture_readback(test_context.backbuffer, 0, &rb);
8783 for (x = 0; x < 4; ++x)
8785 color = get_readback_color(&rb, 80 + x * 160, 0, 0);
8786 ok(compare_color(color, test->expected_colors[x], 2),
8787 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
8789 release_resource_readback(&rb);
8791 if (srv)
8792 ID3D11ShaderResourceView_Release(srv);
8793 ID3D11SamplerState_Release(sampler);
8794 if (texture)
8795 ID3D11Texture1D_Release(texture);
8796 ID3D11PixelShader_Release(ps);
8798 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
8800 win_skip("SRV tests are broken on WARP.\n");
8801 ID3D11Buffer_Release(cb);
8802 release_test_context(&test_context);
8803 return;
8806 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8807 sampler_desc.MipLODBias = 0.0f;
8808 sampler_desc.MinLOD = 0.0f;
8809 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
8811 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
8812 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8814 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8816 ps = NULL;
8817 srv = NULL;
8818 texture = NULL;
8819 current_ps = NULL;
8820 current_texture = NULL;
8821 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
8823 const struct srv_test *test = &srv_tests[i];
8825 if (current_ps != test->ps)
8827 if (ps)
8828 ID3D11PixelShader_Release(ps);
8830 current_ps = test->ps;
8832 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
8833 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
8835 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8838 if (current_texture != test->texture)
8840 if (texture)
8841 ID3D11Texture1D_Release(texture);
8843 current_texture = test->texture;
8845 texture_desc.Width = current_texture->width;
8846 texture_desc.MipLevels = current_texture->miplevel_count;
8847 texture_desc.ArraySize = current_texture->array_size;
8848 texture_desc.Format = current_texture->format;
8850 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
8851 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
8854 if (srv)
8855 ID3D11ShaderResourceView_Release(srv);
8857 get_srv_desc(&srv_desc, &test->srv_desc);
8858 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
8859 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
8861 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8863 ps_constant.x = test->ps_constant;
8864 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
8866 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8868 draw_quad(&test_context);
8870 get_texture_readback(test_context.backbuffer, 0, &rb);
8871 for (x = 0; x < 4; ++x)
8873 color = get_readback_color(&rb, 80 + x * 160, 0, 0);
8874 ok(compare_color(color, test->expected_colors[x], 1),
8875 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
8877 release_resource_readback(&rb);
8879 ID3D11PixelShader_Release(ps);
8880 ID3D11Texture1D_Release(texture);
8881 ID3D11ShaderResourceView_Release(srv);
8882 ID3D11SamplerState_Release(sampler);
8884 ID3D11Buffer_Release(cb);
8885 release_test_context(&test_context);
8888 static void test_texture(void)
8890 struct shader
8892 const DWORD *code;
8893 size_t size;
8895 struct texture
8897 UINT width;
8898 UINT height;
8899 UINT miplevel_count;
8900 UINT array_size;
8901 DXGI_FORMAT format;
8902 D3D11_SUBRESOURCE_DATA data[3];
8905 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8906 struct d3d11_test_context test_context;
8907 const struct texture *current_texture;
8908 D3D11_TEXTURE2D_DESC texture_desc;
8909 D3D11_SAMPLER_DESC sampler_desc;
8910 const struct shader *current_ps;
8911 D3D_FEATURE_LEVEL feature_level;
8912 ID3D11ShaderResourceView *srv;
8913 ID3D11DeviceContext *context;
8914 ID3D11SamplerState *sampler;
8915 struct resource_readback rb;
8916 ID3D11Texture2D *texture;
8917 struct vec4 ps_constant;
8918 ID3D11PixelShader *ps;
8919 ID3D11Device *device;
8920 unsigned int i, x, y;
8921 ID3D11Buffer *cb;
8922 DWORD color;
8923 HRESULT hr;
8925 static const DWORD ps_ld_code[] =
8927 #if 0
8928 Texture2D t;
8930 float miplevel;
8932 float4 main(float4 position : SV_POSITION) : SV_TARGET
8934 float3 p;
8935 t.GetDimensions(miplevel, p.x, p.y, p.z);
8936 p.z = miplevel;
8937 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
8938 return t.Load(int3(p));
8940 #endif
8941 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
8942 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8943 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8944 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8945 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
8946 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
8947 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8948 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
8949 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
8950 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
8951 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
8952 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
8953 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
8954 0x00107e46, 0x00000000, 0x0100003e,
8956 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
8957 static const DWORD ps_ld_sint8_code[] =
8959 #if 0
8960 Texture2D<int4> t;
8962 float4 main(float4 position : SV_POSITION) : SV_TARGET
8964 float3 p, s;
8965 int4 c;
8967 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
8968 t.GetDimensions(0, s.x, s.y, s.z);
8969 p *= s;
8971 c = t.Load(int3(p));
8972 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
8974 #endif
8975 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
8976 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8977 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8978 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8979 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
8980 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
8981 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8982 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
8983 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
8984 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
8985 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
8986 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8987 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
8988 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
8989 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
8990 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8991 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
8992 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
8994 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
8995 static const DWORD ps_ld_uint8_code[] =
8997 #if 0
8998 Texture2D<uint4> t;
9000 float4 main(float4 position : SV_POSITION) : SV_TARGET
9002 float3 p, s;
9004 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
9005 t.GetDimensions(0, s.x, s.y, s.z);
9006 p *= s;
9008 return t.Load(int3(p)) / (float4)255;
9010 #endif
9011 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
9012 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9013 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9014 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9015 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
9016 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
9017 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
9018 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
9019 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
9020 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
9021 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
9022 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
9023 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
9024 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
9025 0x3b808081, 0x0100003e,
9027 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
9028 static const DWORD ps_sample_code[] =
9030 #if 0
9031 Texture2D t;
9032 SamplerState s;
9034 float4 main(float4 position : SV_POSITION) : SV_Target
9036 float2 p;
9038 p.x = position.x / 640.0f;
9039 p.y = position.y / 480.0f;
9040 return t.Sample(s, p);
9042 #endif
9043 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
9044 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9045 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9046 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9047 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
9048 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
9049 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
9050 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9051 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
9052 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9054 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
9055 static const DWORD ps_sample_b_code[] =
9057 #if 0
9058 Texture2D t;
9059 SamplerState s;
9061 float bias;
9063 float4 main(float4 position : SV_POSITION) : SV_Target
9065 float2 p;
9067 p.x = position.x / 640.0f;
9068 p.y = position.y / 480.0f;
9069 return t.SampleBias(s, p, bias);
9071 #endif
9072 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
9073 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9074 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9075 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9076 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
9077 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9078 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9079 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
9080 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
9081 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
9082 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
9084 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
9085 static const DWORD ps_sample_l_code[] =
9087 #if 0
9088 Texture2D t;
9089 SamplerState s;
9091 float level;
9093 float4 main(float4 position : SV_POSITION) : SV_Target
9095 float2 p;
9097 p.x = position.x / 640.0f;
9098 p.y = position.y / 480.0f;
9099 return t.SampleLevel(s, p, level);
9101 #endif
9102 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
9103 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9104 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9105 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9106 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
9107 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9108 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9109 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
9110 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
9111 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
9112 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
9114 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
9115 static const DWORD ps_sample_2d_array_code[] =
9117 #if 0
9118 Texture2DArray t;
9119 SamplerState s;
9121 float layer;
9123 float4 main(float4 position : SV_POSITION) : SV_TARGET
9125 float3 d;
9126 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
9127 t.GetDimensions(d.x, d.y, d.z);
9128 d.z = layer;
9129 return t.Sample(s, p * d);
9131 #endif
9132 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
9133 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9134 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9135 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9136 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
9137 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9138 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9139 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
9140 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
9141 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
9142 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
9143 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
9144 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9146 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
9147 static const DWORD red_data[] =
9149 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9150 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9151 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9152 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9154 static const DWORD green_data[] =
9156 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9157 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9158 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9159 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9161 static const DWORD blue_data[] =
9163 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9164 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9165 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9166 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9168 static const DWORD rgba_level_0[] =
9170 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9171 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9172 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9173 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9175 static const DWORD rgba_level_1[] =
9177 0xffffffff, 0xff0000ff,
9178 0xff000000, 0xff00ff00,
9180 static const DWORD rgba_level_2[] =
9182 0xffff0000,
9184 static const DWORD srgb_data[] =
9186 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
9187 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
9188 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
9189 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
9191 static const WORD r8g8_data[] =
9193 0x0000, 0xffff, 0x0000, 0x7fff,
9194 0x0203, 0xff10, 0x0b0c, 0x8000,
9195 0xc4de, 0xfff0, 0xfdfe, 0x5a6f,
9196 0xff00, 0xffc8, 0x00aa, 0xdd5b,
9198 static const BYTE a8_data[] =
9200 0x00, 0x10, 0x20, 0x30,
9201 0x40, 0x50, 0x60, 0x70,
9202 0x80, 0x90, 0xa0, 0xb0,
9203 0xc0, 0xd0, 0xe0, 0xf0,
9205 static const BYTE bc1_data[] =
9207 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
9208 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
9209 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
9210 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
9212 static const BYTE bc2_data[] =
9214 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
9215 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
9216 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
9217 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
9219 static const BYTE bc3_data[] =
9221 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
9222 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
9223 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
9224 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
9226 static const BYTE bc4_data[] =
9228 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
9229 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
9230 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
9231 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
9233 static const BYTE bc5_data[] =
9235 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
9236 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
9237 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
9238 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
9240 static const BYTE bc6h_u_data[] =
9242 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9243 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9244 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9245 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9247 static const BYTE bc6h_s_data[] =
9249 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9250 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9251 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9252 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9254 static const BYTE bc7_data[] =
9256 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9257 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9258 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9259 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
9261 static const float r32_float[] =
9263 0.0f, 1.0f, 0.5f, 0.50f,
9264 1.0f, 0.0f, 0.0f, 0.75f,
9265 0.0f, 1.0f, 0.5f, 0.25f,
9266 1.0f, 0.0f, 0.0f, 0.75f,
9268 static const DWORD r32_uint[] =
9270 0, 1, 2, 3,
9271 100, 200, 255, 128,
9272 40, 30, 20, 10,
9273 250, 210, 155, 190,
9275 static const DWORD r9g9b9e5_data[] =
9277 0x80000100, 0x80020000, 0x84000000, 0x84000100,
9278 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
9279 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
9280 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
9282 static const struct texture rgba_texture =
9284 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
9286 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
9287 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
9288 {rgba_level_2, sizeof(*rgba_level_2), 0},
9291 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
9292 {{srgb_data, 4 * sizeof(*srgb_data)}}};
9293 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
9294 {{srgb_data, 4 * sizeof(*srgb_data)}}};
9295 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
9296 {{a8_data, 4 * sizeof(*a8_data)}}};
9297 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
9298 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
9299 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
9300 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
9301 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
9302 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
9303 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
9304 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
9305 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
9306 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
9307 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
9308 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
9309 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
9310 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
9311 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
9312 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
9313 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
9314 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
9315 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
9316 static const struct texture array_2d_texture =
9318 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
9320 {red_data, 6 * sizeof(*red_data)},
9321 {green_data, 4 * sizeof(*green_data)},
9322 {blue_data, 5 * sizeof(*blue_data)},
9325 static const struct texture r32f_float = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
9326 {{r32_float, 4 * sizeof(*r32_float)}}};
9327 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
9328 {{r32_float, 4 * sizeof(*r32_float)}}};
9329 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
9330 {{r32_uint, 4 * sizeof(*r32_uint)}}};
9331 static const struct texture r8g8_snorm = {4, 4, 1, 1, DXGI_FORMAT_R8G8_SNORM,
9332 {{r8g8_data, 4 * sizeof(*r8g8_data)}}};
9333 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
9334 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
9335 static const DWORD red_colors[] =
9337 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9338 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9339 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9340 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9342 static const DWORD blue_colors[] =
9344 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9345 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9346 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9347 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9349 static const DWORD level_1_colors[] =
9351 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
9352 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
9353 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
9354 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
9356 static const DWORD lerp_1_2_colors[] =
9358 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
9359 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
9360 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
9361 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
9363 static const DWORD level_2_colors[] =
9365 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9366 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9367 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9368 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9370 static const DWORD srgb_colors[] =
9372 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
9373 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
9374 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
9375 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
9377 static const DWORD a8_colors[] =
9379 0x00000000, 0x10000000, 0x20000000, 0x30000000,
9380 0x40000000, 0x50000000, 0x60000000, 0x70000000,
9381 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
9382 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
9384 static const DWORD bc_colors[] =
9386 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
9387 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
9388 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
9389 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
9391 static const DWORD bc4_colors[] =
9393 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
9394 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
9395 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
9396 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
9398 static const DWORD bc5_colors[] =
9400 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
9401 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
9402 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
9403 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
9405 static const DWORD bc7_colors[] =
9407 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
9408 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
9409 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
9410 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
9412 static const DWORD sint8_colors[] =
9414 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
9415 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
9416 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
9417 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
9419 static const DWORD snorm_colors[] =
9421 0xff000000, 0xff000000, 0xff000000, 0xff00ff00,
9422 0xff000406, 0xff000020, 0xff001618, 0xff000000,
9423 0xff000000, 0xff000000, 0xff000000, 0xff00b5df,
9424 0xff000000, 0xff000000, 0xff000000, 0xff0000b7,
9426 static const DWORD r32f_colors[] =
9428 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
9429 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
9430 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
9431 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
9433 static const DWORD r32u_colors[16] =
9435 0x01000000, 0x01000001, 0x01000002, 0x01000003,
9436 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
9437 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
9438 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
9440 static const DWORD r9g9b9e5_colors[16] =
9442 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
9443 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
9444 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
9445 0xff000033, 0xff003300, 0xff330000, 0xff333333,
9447 static const DWORD zero_colors[4 * 4] = {0};
9448 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9450 static const struct texture_test
9452 const struct shader *ps;
9453 const struct texture *texture;
9454 D3D11_FILTER filter;
9455 float lod_bias;
9456 float min_lod;
9457 float max_lod;
9458 float ps_constant;
9459 const DWORD *expected_colors;
9461 texture_tests[] =
9463 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
9464 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
9465 #define MIP_MAX D3D11_FLOAT32_MAX
9466 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
9467 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
9468 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
9469 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
9470 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
9471 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9472 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9473 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9474 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9475 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9476 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9477 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9478 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9479 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9480 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
9481 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
9482 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9483 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9484 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9485 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9486 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
9487 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9488 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9489 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
9490 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
9491 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9492 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9493 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9494 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
9495 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
9496 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9497 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9498 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9499 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9500 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
9501 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9502 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9503 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
9504 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
9505 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
9506 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
9507 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9508 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9509 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9510 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
9511 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
9512 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
9513 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
9514 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
9515 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
9516 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
9517 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
9518 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
9519 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9520 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9521 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9522 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
9523 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
9524 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9525 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
9526 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
9527 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
9528 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
9529 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
9530 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
9531 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
9532 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
9533 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
9534 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
9535 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
9536 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
9537 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
9538 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
9539 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
9540 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
9541 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
9542 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
9543 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
9544 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
9545 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
9546 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
9547 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
9548 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
9549 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
9550 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
9551 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
9552 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
9553 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
9554 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
9555 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
9556 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
9557 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
9558 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
9559 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
9560 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
9561 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
9562 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
9563 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
9564 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
9565 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9566 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9567 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
9568 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9569 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
9570 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
9571 #undef POINT
9572 #undef POINT_LINEAR
9573 #undef MIP_MAX
9575 static const struct srv_test
9577 const struct shader *ps;
9578 const struct texture *texture;
9579 struct srv_desc srv_desc;
9580 float ps_constant;
9581 const DWORD *expected_colors;
9583 srv_tests[] =
9585 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
9586 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
9587 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
9588 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
9589 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
9590 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
9591 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
9592 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
9593 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
9594 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
9595 #define R8G8_SNORM DXGI_FORMAT_R8G8_SNORM
9596 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
9597 #define R32_UINT DXGI_FORMAT_R32_UINT
9598 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
9599 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
9600 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
9601 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
9602 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
9603 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
9604 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
9605 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
9606 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
9607 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
9608 {&ps_sample, &r32f_float, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
9609 {&ps_sample, &r8g8_snorm, {R8G8_SNORM, TEX_2D, 0, 1}, 0.0f, snorm_colors},
9610 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
9611 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
9612 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
9613 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
9614 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
9615 #undef TEX_2D
9616 #undef TEX_2D_ARRAY
9617 #undef BC1_UNORM
9618 #undef BC1_UNORM_SRGB
9619 #undef BC2_UNORM
9620 #undef BC2_UNORM_SRGB
9621 #undef BC3_UNORM
9622 #undef BC3_UNORM_SRGB
9623 #undef R8G8B8A8_UNORM_SRGB
9624 #undef R8G8B8A8_UNORM
9625 #undef R8G8_SNORM
9626 #undef R32_FLOAT
9627 #undef R32_UINT
9628 #undef FMT_UNKNOWN
9631 if (!init_test_context(&test_context, NULL))
9632 return;
9634 device = test_context.device;
9635 context = test_context.immediate_context;
9636 feature_level = ID3D11Device_GetFeatureLevel(device);
9638 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
9640 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9642 texture_desc.SampleDesc.Count = 1;
9643 texture_desc.SampleDesc.Quality = 0;
9644 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9645 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
9646 texture_desc.CPUAccessFlags = 0;
9647 texture_desc.MiscFlags = 0;
9649 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9650 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
9651 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
9652 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
9653 sampler_desc.MipLODBias = 0.0f;
9654 sampler_desc.MaxAnisotropy = 0;
9655 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
9656 sampler_desc.BorderColor[0] = 0.0f;
9657 sampler_desc.BorderColor[1] = 0.0f;
9658 sampler_desc.BorderColor[2] = 0.0f;
9659 sampler_desc.BorderColor[3] = 0.0f;
9660 sampler_desc.MinLOD = 0.0f;
9661 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
9663 ps = NULL;
9664 srv = NULL;
9665 sampler = NULL;
9666 texture = NULL;
9667 current_ps = NULL;
9668 current_texture = NULL;
9669 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
9671 const struct texture_test *test = &texture_tests[i];
9673 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
9674 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
9675 && feature_level < D3D_FEATURE_LEVEL_11_0)
9677 skip("Feature level >= 11.0 is required for BC7 tests.\n");
9678 continue;
9681 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
9682 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
9683 && feature_level < D3D_FEATURE_LEVEL_11_0)
9685 skip("Feature level >= 11.0 is required for BC6H tests.\n");
9686 continue;
9689 if (current_ps != test->ps)
9691 if (ps)
9692 ID3D11PixelShader_Release(ps);
9694 current_ps = test->ps;
9696 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
9697 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
9699 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9702 if (current_texture != test->texture)
9704 if (texture)
9705 ID3D11Texture2D_Release(texture);
9706 if (srv)
9707 ID3D11ShaderResourceView_Release(srv);
9709 current_texture = test->texture;
9711 if (current_texture)
9713 texture_desc.Width = current_texture->width;
9714 texture_desc.Height = current_texture->height;
9715 texture_desc.MipLevels = current_texture->miplevel_count;
9716 texture_desc.ArraySize = current_texture->array_size;
9717 texture_desc.Format = current_texture->format;
9719 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
9720 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9722 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
9723 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
9725 else
9727 texture = NULL;
9728 srv = NULL;
9731 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
9734 if (!sampler || (sampler_desc.Filter != test->filter
9735 || sampler_desc.MipLODBias != test->lod_bias
9736 || sampler_desc.MinLOD != test->min_lod
9737 || sampler_desc.MaxLOD != test->max_lod))
9739 if (sampler)
9740 ID3D11SamplerState_Release(sampler);
9742 sampler_desc.Filter = test->filter;
9743 sampler_desc.MipLODBias = test->lod_bias;
9744 sampler_desc.MinLOD = test->min_lod;
9745 sampler_desc.MaxLOD = test->max_lod;
9747 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
9748 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
9750 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9753 ps_constant.x = test->ps_constant;
9754 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
9756 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9758 draw_quad(&test_context);
9760 get_texture_readback(test_context.backbuffer, 0, &rb);
9761 for (y = 0; y < 4; ++y)
9763 for (x = 0; x < 4; ++x)
9765 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
9766 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
9767 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
9770 release_resource_readback(&rb);
9772 if (srv)
9773 ID3D11ShaderResourceView_Release(srv);
9774 ID3D11SamplerState_Release(sampler);
9775 if (texture)
9776 ID3D11Texture2D_Release(texture);
9777 ID3D11PixelShader_Release(ps);
9779 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
9781 win_skip("SRV tests are broken on WARP.\n");
9782 ID3D11Buffer_Release(cb);
9783 release_test_context(&test_context);
9784 return;
9787 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9788 sampler_desc.MipLODBias = 0.0f;
9789 sampler_desc.MinLOD = 0.0f;
9790 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
9792 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
9793 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9795 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9797 ps = NULL;
9798 srv = NULL;
9799 texture = NULL;
9800 current_ps = NULL;
9801 current_texture = NULL;
9802 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
9804 const struct srv_test *test = &srv_tests[i];
9806 if (current_ps != test->ps)
9808 if (ps)
9809 ID3D11PixelShader_Release(ps);
9811 current_ps = test->ps;
9813 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
9814 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
9816 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9819 if (current_texture != test->texture)
9821 if (texture)
9822 ID3D11Texture2D_Release(texture);
9824 current_texture = test->texture;
9826 texture_desc.Width = current_texture->width;
9827 texture_desc.Height = current_texture->height;
9828 texture_desc.MipLevels = current_texture->miplevel_count;
9829 texture_desc.ArraySize = current_texture->array_size;
9830 texture_desc.Format = current_texture->format;
9832 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
9833 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9836 if (srv)
9837 ID3D11ShaderResourceView_Release(srv);
9839 get_srv_desc(&srv_desc, &test->srv_desc);
9840 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
9841 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
9843 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
9845 ps_constant.x = test->ps_constant;
9846 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
9848 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9850 draw_quad(&test_context);
9852 get_texture_readback(test_context.backbuffer, 0, &rb);
9853 for (y = 0; y < 4; ++y)
9855 for (x = 0; x < 4; ++x)
9857 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
9858 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
9859 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
9862 release_resource_readback(&rb);
9864 ID3D11PixelShader_Release(ps);
9865 ID3D11Texture2D_Release(texture);
9866 ID3D11ShaderResourceView_Release(srv);
9867 ID3D11SamplerState_Release(sampler);
9869 ID3D11Buffer_Release(cb);
9870 release_test_context(&test_context);
9873 static void test_cube_maps(void)
9875 struct shader
9877 const DWORD *code;
9878 size_t size;
9881 unsigned int i, j, sub_resource_idx, sub_resource_count;
9882 struct d3d11_test_context test_context;
9883 D3D11_TEXTURE2D_DESC texture_desc;
9884 const struct shader *current_ps;
9885 D3D_FEATURE_LEVEL feature_level;
9886 ID3D11ShaderResourceView *srv;
9887 ID3D11DeviceContext *context;
9888 ID3D11Texture2D *rtv_texture;
9889 ID3D11RenderTargetView *rtv;
9890 struct vec4 expected_result;
9891 ID3D11Resource *texture;
9892 ID3D11PixelShader *ps;
9893 ID3D11Device *device;
9894 float data[64 * 64];
9895 ID3D11Buffer *cb;
9896 HRESULT hr;
9897 RECT rect;
9898 struct
9900 unsigned int face;
9901 unsigned int level;
9902 unsigned int cube;
9903 unsigned int padding;
9904 } constant;
9906 static const DWORD ps_cube_code[] =
9908 #if 0
9909 TextureCube t;
9910 SamplerState s;
9912 uint face;
9913 uint level;
9915 float4 main(float4 position : SV_POSITION) : SV_Target
9917 float2 p;
9918 p.x = position.x / 640.0f;
9919 p.y = position.y / 480.0f;
9921 float3 coord;
9922 switch (face)
9924 case 0:
9925 coord = float3(1.0f, p.x, p.y);
9926 break;
9927 case 1:
9928 coord = float3(-1.0f, p.x, p.y);
9929 break;
9930 case 2:
9931 coord = float3(p.x, 1.0f, p.y);
9932 break;
9933 case 3:
9934 coord = float3(p.x, -1.0f, p.y);
9935 break;
9936 case 4:
9937 coord = float3(p.x, p.y, 1.0f);
9938 break;
9939 case 5:
9940 default:
9941 coord = float3(p.x, p.y, -1.0f);
9942 break;
9944 return t.SampleLevel(s, coord, level);
9946 #endif
9947 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
9948 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9949 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9950 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9951 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
9952 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9953 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9954 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
9955 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
9956 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
9957 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
9958 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
9959 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
9960 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
9961 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
9962 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
9963 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
9964 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
9965 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
9966 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
9967 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9968 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
9969 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
9970 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
9971 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
9973 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
9974 static const DWORD ps_cube_array_code[] =
9976 #if 0
9977 TextureCubeArray t;
9978 SamplerState s;
9980 uint face;
9981 uint level;
9982 uint cube;
9984 float4 main(float4 position : SV_POSITION) : SV_Target
9986 float2 p;
9987 p.x = position.x / 640.0f;
9988 p.y = position.y / 480.0f;
9990 float3 coord;
9991 switch (face)
9993 case 0:
9994 coord = float3(1.0f, p.x, p.y);
9995 break;
9996 case 1:
9997 coord = float3(-1.0f, p.x, p.y);
9998 break;
9999 case 2:
10000 coord = float3(p.x, 1.0f, p.y);
10001 break;
10002 case 3:
10003 coord = float3(p.x, -1.0f, p.y);
10004 break;
10005 case 4:
10006 coord = float3(p.x, p.y, 1.0f);
10007 break;
10008 case 5:
10009 default:
10010 coord = float3(p.x, p.y, -1.0f);
10011 break;
10013 return t.SampleLevel(s, float4(coord, cube), level);
10015 #endif
10016 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
10017 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10018 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
10019 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10020 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
10021 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
10022 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
10023 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
10024 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
10025 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
10026 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
10027 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
10028 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
10029 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
10030 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
10031 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
10032 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
10033 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
10034 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10035 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
10036 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
10037 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
10038 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
10039 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
10040 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
10041 0x00000001, 0x0100003e,
10043 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
10044 static const struct ps_test
10046 const struct shader *ps;
10047 unsigned int miplevel_count;
10048 unsigned int array_size;
10050 ps_tests[] =
10052 {&ps_cube, 1, 6},
10053 {&ps_cube, 2, 6},
10054 {&ps_cube, 3, 6},
10055 {&ps_cube, 0, 6},
10057 {&ps_cube_array, 1, 12},
10058 {&ps_cube_array, 2, 12},
10059 {&ps_cube_array, 3, 12},
10060 {&ps_cube_array, 0, 12},
10063 if (!init_test_context(&test_context, NULL))
10064 return;
10066 device = test_context.device;
10067 context = test_context.immediate_context;
10068 feature_level = ID3D11Device_GetFeatureLevel(device);
10070 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10071 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
10072 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
10073 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10074 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
10075 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10077 memset(&constant, 0, sizeof(constant));
10078 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
10080 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10081 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10083 ps = NULL;
10084 current_ps = NULL;
10085 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
10087 const struct ps_test *test = &ps_tests[i];
10089 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
10091 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
10092 continue;
10095 if (current_ps != test->ps)
10097 if (ps)
10098 ID3D11PixelShader_Release(ps);
10100 current_ps = test->ps;
10102 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
10103 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
10104 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10107 if (!test->miplevel_count)
10109 srv = NULL;
10110 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10112 memset(&expected_result, 0, sizeof(expected_result));
10114 memset(&constant, 0, sizeof(constant));
10115 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10116 draw_quad(&test_context);
10117 check_texture_vec4(rtv_texture, &expected_result, 0);
10118 constant.level = 1;
10119 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10120 draw_quad(&test_context);
10121 check_texture_vec4(rtv_texture, &expected_result, 0);
10122 continue;
10125 texture_desc.Width = 64;
10126 texture_desc.Height = 64;
10127 texture_desc.MipLevels = test->miplevel_count;
10128 texture_desc.ArraySize = test->array_size;
10129 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
10130 texture_desc.SampleDesc.Count = 1;
10131 texture_desc.SampleDesc.Quality = 0;
10132 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10133 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
10134 texture_desc.CPUAccessFlags = 0;
10135 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
10136 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
10137 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
10139 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
10140 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
10141 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10143 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
10144 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
10146 for (j = 0; j < ARRAY_SIZE(data); ++j)
10147 data[j] = sub_resource_idx;
10148 ID3D11DeviceContext_UpdateSubresource(context, texture, sub_resource_idx, NULL, data,
10149 texture_desc.Width * sizeof(*data), 0);
10152 expected_result.y = expected_result.z = 0.0f;
10153 expected_result.w = 1.0f;
10154 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
10156 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
10157 constant.level = sub_resource_idx % texture_desc.MipLevels;
10158 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
10159 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10161 draw_quad(&test_context);
10162 expected_result.x = sub_resource_idx;
10163 /* Avoid testing values affected by seamless cube map filtering. */
10164 SetRect(&rect, 100, 100, 540, 380);
10165 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
10168 ID3D11Resource_Release(texture);
10169 ID3D11ShaderResourceView_Release(srv);
10171 ID3D11PixelShader_Release(ps);
10173 ID3D11Buffer_Release(cb);
10174 ID3D11RenderTargetView_Release(rtv);
10175 ID3D11Texture2D_Release(rtv_texture);
10176 release_test_context(&test_context);
10179 static void test_depth_stencil_sampling(void)
10181 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
10182 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
10183 ID3D11SamplerState *cmp_sampler, *sampler;
10184 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10185 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
10186 struct d3d11_test_context test_context;
10187 ID3D11Texture2D *texture, *rt_texture;
10188 D3D11_TEXTURE2D_DESC texture_desc;
10189 D3D11_SAMPLER_DESC sampler_desc;
10190 ID3D11DeviceContext *context;
10191 ID3D11DepthStencilView *dsv;
10192 ID3D11RenderTargetView *rtv;
10193 struct vec4 ps_constant;
10194 ID3D11Device *device;
10195 ID3D11Buffer *cb;
10196 unsigned int i;
10197 HRESULT hr;
10199 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
10200 static const DWORD ps_compare_code[] =
10202 #if 0
10203 Texture2D t;
10204 SamplerComparisonState s;
10206 float ref;
10208 float4 main(float4 position : SV_Position) : SV_Target
10210 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
10212 #endif
10213 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
10214 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10215 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10216 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10217 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
10218 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
10219 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
10220 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
10221 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
10222 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
10223 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
10224 0x0100003e,
10226 static const DWORD ps_sample_code[] =
10228 #if 0
10229 Texture2D t;
10230 SamplerState s;
10232 float4 main(float4 position : SV_Position) : SV_Target
10234 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
10236 #endif
10237 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
10238 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10239 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10240 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10241 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
10242 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10243 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10244 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10245 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
10246 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
10248 static const DWORD ps_stencil_code[] =
10250 #if 0
10251 Texture2D<uint4> t;
10253 float4 main(float4 position : SV_Position) : SV_Target
10255 float2 s;
10256 t.GetDimensions(s.x, s.y);
10257 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
10259 #endif
10260 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
10261 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10262 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10263 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10264 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
10265 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
10266 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
10267 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
10268 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
10269 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
10270 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
10271 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
10272 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
10274 static const DWORD ps_depth_stencil_code[] =
10276 #if 0
10277 SamplerState samp;
10278 Texture2D depth_tex;
10279 Texture2D<uint4> stencil_tex;
10281 float main(float4 position: SV_Position) : SV_Target
10283 float2 s, p;
10284 float depth, stencil;
10285 depth_tex.GetDimensions(s.x, s.y);
10286 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
10287 depth = depth_tex.Sample(samp, p).r;
10288 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
10289 return depth + stencil;
10291 #endif
10292 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
10293 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10294 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10295 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10296 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
10297 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10298 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
10299 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
10300 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
10301 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
10302 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
10303 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
10304 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
10305 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
10306 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
10307 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
10309 static const struct test
10311 DXGI_FORMAT typeless_format;
10312 DXGI_FORMAT dsv_format;
10313 DXGI_FORMAT depth_view_format;
10314 DXGI_FORMAT stencil_view_format;
10316 tests[] =
10318 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
10319 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
10320 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
10321 DXGI_FORMAT_R32_FLOAT},
10322 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
10323 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
10324 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
10325 DXGI_FORMAT_R16_UNORM},
10328 if (!init_test_context(&test_context, NULL))
10329 return;
10331 device = test_context.device;
10332 context = test_context.immediate_context;
10334 if (is_amd_device(device))
10336 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
10337 win_skip("Some AMD drivers have a bug affecting the test.\n");
10338 release_test_context(&test_context);
10339 return;
10342 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
10343 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10344 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10345 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10346 sampler_desc.MipLODBias = 0.0f;
10347 sampler_desc.MaxAnisotropy = 0;
10348 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
10349 sampler_desc.BorderColor[0] = 0.0f;
10350 sampler_desc.BorderColor[1] = 0.0f;
10351 sampler_desc.BorderColor[2] = 0.0f;
10352 sampler_desc.BorderColor[3] = 0.0f;
10353 sampler_desc.MinLOD = 0.0f;
10354 sampler_desc.MaxLOD = 0.0f;
10355 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
10356 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10358 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
10359 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
10360 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
10361 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10363 texture_desc.Width = 640;
10364 texture_desc.Height = 480;
10365 texture_desc.MipLevels = 1;
10366 texture_desc.ArraySize = 1;
10367 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
10368 texture_desc.SampleDesc.Count = 1;
10369 texture_desc.SampleDesc.Quality = 0;
10370 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10371 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10372 texture_desc.CPUAccessFlags = 0;
10373 texture_desc.MiscFlags = 0;
10374 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
10375 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10376 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
10377 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
10378 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10380 memset(&ps_constant, 0, sizeof(ps_constant));
10381 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
10382 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10384 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
10385 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10386 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
10387 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10388 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
10389 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10390 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
10391 &ps_depth_stencil);
10392 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10394 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10396 texture_desc.Format = tests[i].typeless_format;
10397 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
10398 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10399 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
10400 texture_desc.Format, hr);
10402 dsv_desc.Format = tests[i].dsv_format;
10403 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
10404 dsv_desc.Flags = 0;
10405 U(dsv_desc).Texture2D.MipSlice = 0;
10406 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10407 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
10408 dsv_desc.Format, hr);
10410 srv_desc.Format = tests[i].depth_view_format;
10411 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
10412 U(srv_desc).Texture2D.MostDetailedMip = 0;
10413 U(srv_desc).Texture2D.MipLevels = 1;
10414 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
10415 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
10416 srv_desc.Format, hr);
10418 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
10419 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
10420 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
10422 ps_constant.x = 0.5f;
10423 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10424 NULL, &ps_constant, 0, 0);
10426 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10427 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10428 draw_quad(&test_context);
10429 check_texture_float(rt_texture, 0.0f, 2);
10431 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
10432 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10433 draw_quad(&test_context);
10434 check_texture_float(rt_texture, 1.0f, 2);
10436 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
10437 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10438 draw_quad(&test_context);
10439 check_texture_float(rt_texture, 0.0f, 2);
10441 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
10442 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10443 draw_quad(&test_context);
10444 check_texture_float(rt_texture, 0.0f, 2);
10446 ps_constant.x = 0.7f;
10447 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10448 NULL, &ps_constant, 0, 0);
10450 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10451 draw_quad(&test_context);
10452 check_texture_float(rt_texture, 1.0f, 2);
10454 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
10455 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10457 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10458 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10459 draw_quad(&test_context);
10460 check_texture_float(rt_texture, 1.0f, 2);
10462 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
10463 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10464 draw_quad(&test_context);
10465 check_texture_float(rt_texture, 0.2f, 2);
10467 if (!tests[i].stencil_view_format)
10469 ID3D11DepthStencilView_Release(dsv);
10470 ID3D11ShaderResourceView_Release(depth_srv);
10471 ID3D11Texture2D_Release(texture);
10472 continue;
10475 srv_desc.Format = tests[i].stencil_view_format;
10476 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
10477 if (hr == E_OUTOFMEMORY)
10479 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
10480 ID3D11DepthStencilView_Release(dsv);
10481 ID3D11ShaderResourceView_Release(depth_srv);
10482 ID3D11Texture2D_Release(texture);
10483 continue;
10485 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
10486 srv_desc.Format, hr);
10488 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
10489 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
10491 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
10492 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10493 draw_quad(&test_context);
10494 check_texture_float(rt_texture, 0.0f, 0);
10496 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
10497 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10498 draw_quad(&test_context);
10499 check_texture_float(rt_texture, 100.0f, 0);
10501 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
10502 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10503 draw_quad(&test_context);
10504 check_texture_float(rt_texture, 255.0f, 0);
10506 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
10507 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
10508 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
10510 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
10511 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10512 draw_quad(&test_context);
10513 check_texture_float(rt_texture, 3.3f, 2);
10515 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
10516 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10517 draw_quad(&test_context);
10518 check_texture_float(rt_texture, 4.0f, 2);
10520 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
10521 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10522 draw_quad(&test_context);
10523 check_texture_float(rt_texture, 0.0f, 2);
10525 ID3D11DepthStencilView_Release(dsv);
10526 ID3D11ShaderResourceView_Release(depth_srv);
10527 ID3D11ShaderResourceView_Release(stencil_srv);
10528 ID3D11Texture2D_Release(texture);
10531 ID3D11Buffer_Release(cb);
10532 ID3D11PixelShader_Release(ps_cmp);
10533 ID3D11PixelShader_Release(ps_depth);
10534 ID3D11PixelShader_Release(ps_depth_stencil);
10535 ID3D11PixelShader_Release(ps_stencil);
10536 ID3D11RenderTargetView_Release(rtv);
10537 ID3D11SamplerState_Release(cmp_sampler);
10538 ID3D11SamplerState_Release(sampler);
10539 ID3D11Texture2D_Release(rt_texture);
10540 release_test_context(&test_context);
10543 static void test_sample_c_lz(void)
10545 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10546 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
10547 struct d3d11_test_context test_context;
10548 ID3D11Texture2D *texture, *rt_texture;
10549 D3D11_TEXTURE2D_DESC texture_desc;
10550 D3D11_SAMPLER_DESC sampler_desc;
10551 ID3D11ShaderResourceView *srv;
10552 ID3D11DeviceContext *context;
10553 ID3D11DepthStencilView *dsv;
10554 ID3D11RenderTargetView *rtv;
10555 ID3D11SamplerState *sampler;
10556 struct vec4 ps_constant;
10557 ID3D11PixelShader *ps;
10558 ID3D11Device *device;
10559 ID3D11Buffer *cb;
10560 unsigned int i;
10561 HRESULT hr;
10562 RECT rect;
10564 static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
10565 static const DWORD ps_array_code[] =
10567 #if 0
10568 Texture2DArray t;
10569 SamplerComparisonState s;
10571 float ref;
10572 float layer;
10574 float4 main(float4 position : SV_Position) : SV_Target
10576 return t.SampleCmpLevelZero(s, float3(position.x / 640.0f, position.y / 480.0f, layer), ref);
10578 #endif
10579 0x43425844, 0xfe28b3c3, 0xdd7ef404, 0x8d5874a1, 0x984ff182, 0x00000001, 0x00000180, 0x00000003,
10580 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10581 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10582 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10583 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000e4, 0x00000041,
10584 0x00000039, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
10585 0x00000000, 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
10586 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
10587 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
10588 0x06000036, 0x00100042, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0c000047, 0x00100012,
10589 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000, 0x0020800a,
10590 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
10592 static const DWORD ps_cube_code[] =
10594 #if 0
10595 TextureCube t;
10596 SamplerComparisonState s;
10598 float ref;
10599 float face;
10601 float4 main(float4 position : SV_Position) : SV_Target
10603 float2 p;
10604 p.x = position.x / 640.0f;
10605 p.y = position.y / 480.0f;
10607 float3 coord;
10608 switch ((uint)face)
10610 case 0:
10611 coord = float3(1.0f, p.x, p.y);
10612 break;
10613 case 1:
10614 coord = float3(-1.0f, p.x, p.y);
10615 break;
10616 case 2:
10617 coord = float3(p.x, 1.0f, p.y);
10618 break;
10619 case 3:
10620 coord = float3(p.x, -1.0f, p.y);
10621 break;
10622 case 4:
10623 coord = float3(p.x, p.y, 1.0f);
10624 break;
10625 case 5:
10626 default:
10627 coord = float3(p.x, p.y, -1.0f);
10628 break;
10631 return t.SampleCmpLevelZero(s, coord, ref);
10633 #endif
10634 0x43425844, 0xde5655e5, 0x1b116fa1, 0xfce9e757, 0x41c28aac, 0x00000001, 0x00000328, 0x00000003,
10635 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10636 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10637 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10638 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
10639 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
10640 0x00000000, 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
10641 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012,
10642 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006,
10643 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038,
10644 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889,
10645 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000,
10646 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
10647 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002,
10648 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000,
10649 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
10650 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
10651 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
10652 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032,
10653 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
10654 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038,
10655 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000,
10656 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017,
10657 0x0c000047, 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000,
10658 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006,
10659 0x00000000, 0x0100003e,
10661 static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
10662 static const struct
10664 unsigned int layer;
10665 float d_ref;
10666 float expected;
10668 tests[] =
10670 {0, 0.5f, 0.0f},
10671 {1, 0.5f, 1.0f},
10672 {2, 0.5f, 0.0f},
10673 {3, 0.5f, 0.0f},
10674 {4, 0.5f, 1.0f},
10675 {5, 0.5f, 1.0f},
10677 {0, 0.0f, 0.0f},
10678 {1, 0.0f, 0.0f},
10679 {2, 0.0f, 0.0f},
10680 {3, 0.0f, 0.0f},
10681 {4, 0.0f, 0.0f},
10682 {5, 0.0f, 0.0f},
10684 {0, 1.0f, 0.0f},
10685 {1, 1.0f, 1.0f},
10686 {2, 1.0f, 1.0f},
10687 {3, 1.0f, 1.0f},
10688 {4, 1.0f, 1.0f},
10689 {5, 1.0f, 1.0f},
10692 if (!init_test_context(&test_context, NULL))
10693 return;
10695 device = test_context.device;
10696 context = test_context.immediate_context;
10698 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
10699 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10700 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10701 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10702 sampler_desc.MipLODBias = 0.0f;
10703 sampler_desc.MaxAnisotropy = 0;
10704 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
10705 sampler_desc.BorderColor[0] = 0.0f;
10706 sampler_desc.BorderColor[1] = 0.0f;
10707 sampler_desc.BorderColor[2] = 0.0f;
10708 sampler_desc.BorderColor[3] = 0.0f;
10709 sampler_desc.MinLOD = 0.0f;
10710 sampler_desc.MaxLOD = 10.0f;
10711 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
10712 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10714 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10715 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
10716 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
10717 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10718 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
10719 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10720 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10722 memset(&ps_constant, 0, sizeof(ps_constant));
10723 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
10725 /* 2D array texture */
10726 texture_desc.Width = 32;
10727 texture_desc.Height = 32;
10728 texture_desc.MipLevels = 2;
10729 texture_desc.ArraySize = ARRAY_SIZE(depth_values);
10730 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
10731 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
10732 texture_desc.MiscFlags = 0;
10733 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10734 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10736 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
10738 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
10739 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
10740 dsv_desc.Flags = 0;
10741 U(dsv_desc).Texture2DArray.MipSlice = 0;
10742 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
10743 U(dsv_desc).Texture2DArray.ArraySize = 1;
10745 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10746 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10747 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
10748 ID3D11DepthStencilView_Release(dsv);
10750 U(dsv_desc).Texture2DArray.MipSlice = 1;
10751 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10752 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10753 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10754 ID3D11DepthStencilView_Release(dsv);
10757 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
10758 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
10759 U(srv_desc).Texture2DArray.MostDetailedMip = 0;
10760 U(srv_desc).Texture2DArray.MipLevels = ~0u;
10761 U(srv_desc).Texture2DArray.FirstArraySlice = 0;
10762 U(srv_desc).Texture2DArray.ArraySize = ~0u;
10763 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
10764 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10766 hr = ID3D11Device_CreatePixelShader(device, ps_array_code, sizeof(ps_array_code), NULL, &ps);
10767 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10769 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10770 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10771 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10772 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10774 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10776 ps_constant.x = tests[i].d_ref;
10777 ps_constant.y = tests[i].layer;
10778 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10779 NULL, &ps_constant, 0, 0);
10780 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
10781 draw_quad(&test_context);
10782 check_texture_float(rt_texture, tests[i].expected, 2);
10785 ID3D11Texture2D_Release(texture);
10786 ID3D11ShaderResourceView_Release(srv);
10787 ID3D11PixelShader_Release(ps);
10789 /* cube texture */
10790 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
10791 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10792 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10794 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
10796 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
10797 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
10798 dsv_desc.Flags = 0;
10799 U(dsv_desc).Texture2DArray.MipSlice = 0;
10800 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
10801 U(dsv_desc).Texture2DArray.ArraySize = 1;
10803 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10804 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10805 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
10806 ID3D11DepthStencilView_Release(dsv);
10808 U(dsv_desc).Texture2DArray.MipSlice = 1;
10809 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10810 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10811 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10812 ID3D11DepthStencilView_Release(dsv);
10815 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
10816 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
10817 U(srv_desc).TextureCube.MostDetailedMip = 0;
10818 U(srv_desc).TextureCube.MipLevels = ~0u;
10819 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
10820 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10822 hr = ID3D11Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), NULL, &ps);
10823 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10825 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10826 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10827 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10828 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10830 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10832 ps_constant.x = tests[i].d_ref;
10833 ps_constant.y = tests[i].layer;
10834 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10835 NULL, &ps_constant, 0, 0);
10836 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
10837 draw_quad(&test_context);
10838 /* Avoid testing values affected by seamless cube map filtering. */
10839 SetRect(&rect, 100, 100, 540, 380);
10840 check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
10843 ID3D11Texture2D_Release(texture);
10844 ID3D11ShaderResourceView_Release(srv);
10846 ID3D11Buffer_Release(cb);
10847 ID3D11PixelShader_Release(ps);
10848 ID3D11RenderTargetView_Release(rtv);
10849 ID3D11SamplerState_Release(sampler);
10850 ID3D11Texture2D_Release(rt_texture);
10851 release_test_context(&test_context);
10854 static void test_multiple_render_targets(void)
10856 ID3D11RenderTargetView *rtv[4], *tmp_rtv[4];
10857 D3D11_TEXTURE2D_DESC texture_desc;
10858 ID3D11InputLayout *input_layout;
10859 unsigned int stride, offset, i;
10860 ID3D11DeviceContext *context;
10861 ID3D11Texture2D *rt[4];
10862 ID3D11VertexShader *vs;
10863 ID3D11PixelShader *ps;
10864 ID3D11Device *device;
10865 ID3D11Buffer *vb;
10866 ULONG refcount;
10867 HRESULT hr;
10869 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
10871 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10873 static const DWORD vs_code[] =
10875 #if 0
10876 float4 main(float4 position : POSITION) : SV_POSITION
10878 return position;
10880 #endif
10881 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
10882 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10883 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10884 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
10885 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
10886 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10887 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10889 static const DWORD ps_code[] =
10891 #if 0
10892 struct output
10894 float4 t1 : SV_TARGET0;
10895 float4 t2 : SV_Target1;
10896 float4 t3 : SV_TARGET2;
10897 float4 t4 : SV_Target3;
10900 output main(float4 position : SV_POSITION)
10902 struct output o;
10903 o.t1 = (float4)1.0f;
10904 o.t2 = (float4)0.5f;
10905 o.t3 = (float4)0.2f;
10906 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
10907 return o;
10909 #endif
10910 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
10911 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10912 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
10913 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
10914 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10915 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
10916 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
10917 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
10918 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
10919 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
10920 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
10921 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
10922 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
10923 0x3f800000, 0x0100003e,
10925 static const struct vec2 quad[] =
10927 {-1.0f, -1.0f},
10928 {-1.0f, 1.0f},
10929 { 1.0f, -1.0f},
10930 { 1.0f, 1.0f},
10932 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
10934 if (!(device = create_device(NULL)))
10936 skip("Failed to create device.\n");
10937 return;
10940 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10941 vs_code, sizeof(vs_code), &input_layout);
10942 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10944 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10946 texture_desc.Width = 640;
10947 texture_desc.Height = 480;
10948 texture_desc.MipLevels = 1;
10949 texture_desc.ArraySize = 1;
10950 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10951 texture_desc.SampleDesc.Count = 1;
10952 texture_desc.SampleDesc.Quality = 0;
10953 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10954 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10955 texture_desc.CPUAccessFlags = 0;
10956 texture_desc.MiscFlags = 0;
10958 for (i = 0; i < ARRAY_SIZE(rt); ++i)
10960 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
10961 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
10963 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
10964 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
10967 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
10968 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10969 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10970 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10972 ID3D11Device_GetImmediateContext(device, &context);
10974 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
10975 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
10976 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10977 stride = sizeof(*quad);
10978 offset = 0;
10979 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
10980 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
10981 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10983 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
10985 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
10986 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
10987 ID3D11DeviceContext_Draw(context, 4, 0);
10988 check_texture_color(rt[0], 0xffffffff, 2);
10989 check_texture_color(rt[1], 0x7f7f7f7f, 2);
10990 check_texture_color(rt[2], 0x33333333, 2);
10991 check_texture_color(rt[3], 0xff7f3300, 2);
10993 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
10994 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
10995 for (i = 0; i < ARRAY_SIZE(tmp_rtv); ++i)
10997 memset(tmp_rtv, 0, sizeof(tmp_rtv));
10998 tmp_rtv[i] = rtv[i];
10999 ID3D11DeviceContext_OMSetRenderTargets(context, 4, tmp_rtv, NULL);
11000 ID3D11DeviceContext_Draw(context, 4, 0);
11002 check_texture_color(rt[0], 0xffffffff, 2);
11003 check_texture_color(rt[1], 0x7f7f7f7f, 2);
11004 check_texture_color(rt[2], 0x33333333, 2);
11005 check_texture_color(rt[3], 0xff7f3300, 2);
11007 ID3D11Buffer_Release(vb);
11008 ID3D11PixelShader_Release(ps);
11009 ID3D11VertexShader_Release(vs);
11010 ID3D11InputLayout_Release(input_layout);
11011 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
11013 ID3D11RenderTargetView_Release(rtv[i]);
11014 ID3D11Texture2D_Release(rt[i]);
11016 ID3D11DeviceContext_Release(context);
11017 refcount = ID3D11Device_Release(device);
11018 ok(!refcount, "Device has %u references left.\n", refcount);
11021 static void test_render_target_views(void)
11023 struct texture
11025 UINT miplevel_count;
11026 UINT array_size;
11029 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
11030 static struct test
11032 struct texture texture;
11033 struct rtv_desc rtv;
11034 DWORD expected_colors[4];
11036 tests[] =
11038 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
11039 {0xff0000ff, 0x00000000}},
11040 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
11041 {0x00000000, 0xff0000ff}},
11042 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
11043 {0xff0000ff, 0x00000000}},
11044 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
11045 {0x00000000, 0xff0000ff}},
11046 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
11047 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
11048 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
11049 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
11050 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
11051 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
11052 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
11053 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
11054 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
11055 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
11056 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
11057 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
11058 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
11059 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
11060 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
11061 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
11062 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
11063 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
11064 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
11065 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
11066 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
11067 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
11069 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
11070 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
11071 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
11072 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
11073 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
11074 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
11075 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
11076 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
11077 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
11078 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
11079 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
11080 static const struct
11082 struct
11084 D3D11_RTV_DIMENSION dimension;
11085 unsigned int miplevel_count;
11086 unsigned int depth_or_array_size;
11087 DXGI_FORMAT format;
11088 } texture;
11089 struct rtv_desc rtv_desc;
11091 invalid_desc_tests[] =
11093 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
11094 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
11095 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11096 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11097 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
11098 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
11099 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
11100 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
11101 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
11102 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
11103 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
11104 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
11105 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
11106 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
11107 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
11108 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
11109 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
11110 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11111 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11112 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
11113 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
11114 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11115 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11116 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
11117 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
11118 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
11119 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
11120 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
11121 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
11122 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
11123 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
11124 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
11125 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
11126 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
11127 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
11128 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
11129 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
11131 #undef FMT_UNKNOWN
11132 #undef RGBA8_UNORM
11133 #undef RGBA8_SRGB
11134 #undef RGBA8_UINT
11135 #undef RGBA8_TL
11136 #undef DIM_UNKNOWN
11137 #undef TEX_1D
11138 #undef TEX_1D_ARRAY
11139 #undef TEX_2D
11140 #undef TEX_2D_ARRAY
11141 #undef TEX_3D
11143 struct d3d11_test_context test_context;
11144 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
11145 D3D11_TEXTURE3D_DESC texture3d_desc;
11146 D3D11_TEXTURE2D_DESC texture_desc;
11147 ID3D11DeviceContext *context;
11148 ID3D11RenderTargetView *rtv;
11149 ID3D11Texture3D *texture3d;
11150 ID3D11Texture2D *texture;
11151 ID3D11Resource *resource;
11152 ID3D11Device *device;
11153 unsigned int i, j, k;
11154 void *data;
11155 HRESULT hr;
11157 if (!init_test_context(&test_context, NULL))
11158 return;
11160 device = test_context.device;
11161 context = test_context.immediate_context;
11163 texture_desc.Width = 32;
11164 texture_desc.Height = 32;
11165 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11166 texture_desc.SampleDesc.Count = 1;
11167 texture_desc.SampleDesc.Quality = 0;
11168 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11169 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11170 texture_desc.CPUAccessFlags = 0;
11171 texture_desc.MiscFlags = 0;
11173 data = heap_alloc_zero(texture_desc.Width * texture_desc.Height * 4);
11174 ok(!!data, "Failed to allocate memory.\n");
11176 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11178 const struct test *test = &tests[i];
11179 unsigned int sub_resource_count;
11181 texture_desc.MipLevels = test->texture.miplevel_count;
11182 texture_desc.ArraySize = test->texture.array_size;
11184 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11185 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
11187 get_rtv_desc(&rtv_desc, &test->rtv);
11188 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11189 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
11191 for (j = 0; j < texture_desc.ArraySize; ++j)
11193 for (k = 0; k < texture_desc.MipLevels; ++k)
11195 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
11196 ID3D11DeviceContext_UpdateSubresource(context,
11197 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
11200 check_texture_color(texture, 0, 0);
11202 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11203 draw_color_quad(&test_context, &red);
11205 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
11206 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
11207 for (j = 0; j < sub_resource_count; ++j)
11208 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
11210 ID3D11RenderTargetView_Release(rtv);
11211 ID3D11Texture2D_Release(texture);
11214 texture3d_desc.Width = 32;
11215 texture3d_desc.Height = 32;
11216 texture3d_desc.Depth = 32;
11217 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11218 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
11219 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11220 texture3d_desc.CPUAccessFlags = 0;
11221 texture3d_desc.MiscFlags = 0;
11223 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
11225 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
11226 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
11228 if (invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
11230 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
11231 texture_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
11232 texture_desc.Format = invalid_desc_tests[i].texture.format;
11233 texture_desc.MiscFlags = 0;
11235 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11236 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
11237 resource = (ID3D11Resource *)texture;
11239 else
11241 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
11242 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
11243 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
11245 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
11246 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
11247 resource = (ID3D11Resource *)texture3d;
11250 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
11251 hr = ID3D11Device_CreateRenderTargetView(device, resource, &rtv_desc, &rtv);
11252 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
11254 ID3D11Resource_Release(resource);
11257 heap_free(data);
11258 release_test_context(&test_context);
11261 static void test_layered_rendering(void)
11263 struct
11265 unsigned int layer_offset;
11266 unsigned int draw_id;
11267 unsigned int padding[2];
11268 } constant;
11269 struct d3d11_test_context test_context;
11270 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
11271 unsigned int i, sub_resource_count;
11272 D3D11_TEXTURE2D_DESC texture_desc;
11273 ID3D11DeviceContext *context;
11274 ID3D11RenderTargetView *rtv;
11275 ID3D11Texture2D *texture;
11276 ID3D11GeometryShader *gs;
11277 ID3D11VertexShader *vs;
11278 ID3D11PixelShader *ps;
11279 ID3D11Device *device;
11280 ID3D11Buffer *cb;
11281 HRESULT hr;
11282 BOOL warp;
11284 static const DWORD vs_code[] =
11286 #if 0
11287 uint layer_offset;
11289 void main(float4 position : POSITION,
11290 out float4 out_position : SV_POSITION,
11291 out uint layer : SV_RenderTargetArrayIndex)
11293 out_position = position;
11294 layer = layer_offset;
11296 #endif
11297 0x43425844, 0x71f7b9cd, 0x2ab8c713, 0x53e77663, 0x54a9ba68, 0x00000001, 0x00000158, 0x00000004,
11298 0x00000030, 0x00000064, 0x000000cc, 0x00000148, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11299 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954,
11300 0xababab00, 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
11301 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001,
11302 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567,
11303 0x79617272, 0x65646e49, 0xabab0078, 0x52444853, 0x00000074, 0x00010040, 0x0000001d, 0x04000059,
11304 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2,
11305 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x05000036, 0x001020f2,
11306 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020800a, 0x00000000,
11307 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00002000, 0x00000000,
11309 static const DWORD gs_5_code[] =
11311 #if 0
11312 uint layer_offset;
11314 struct gs_in
11316 float4 pos : SV_Position;
11319 struct gs_out
11321 float4 pos : SV_Position;
11322 uint layer : SV_RenderTargetArrayIndex;
11325 [instance(4)]
11326 [maxvertexcount(3)]
11327 void main(triangle gs_in vin[3], in uint instance_id : SV_GSInstanceID,
11328 inout TriangleStream<gs_out> vout)
11330 gs_out o;
11331 o.layer = layer_offset + instance_id;
11332 for (uint i = 0; i < 3; ++i)
11334 o.pos = vin[i].pos;
11335 vout.Append(o);
11338 #endif
11339 0x43425844, 0xb52da162, 0x9a13d8ee, 0xf7c30b50, 0xe80bc2e7, 0x00000001, 0x00000218, 0x00000003,
11340 0x0000002c, 0x00000060, 0x000000d0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11341 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
11342 0x3547534f, 0x00000068, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
11343 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000004, 0x00000001,
11344 0x00000001, 0x00000e01, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472,
11345 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x58454853, 0x00000140, 0x00020050, 0x00000050,
11346 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
11347 0x00000000, 0x00000001, 0x0200005f, 0x00025000, 0x02000068, 0x00000001, 0x020000ce, 0x00000004,
11348 0x0100185d, 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
11349 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x00000003, 0x0700001e,
11350 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0002500a, 0x05000036, 0x00100022,
11351 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a,
11352 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000, 0x07000036, 0x001020f2,
11353 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001,
11354 0x0010000a, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x0700001e, 0x00100022, 0x00000000,
11355 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
11357 static const DWORD gs_4_code[] =
11359 #if 0
11360 uint layer_offset;
11362 struct gs_in
11364 float4 pos : SV_Position;
11367 struct gs_out
11369 float4 pos : SV_Position;
11370 uint layer : SV_RenderTargetArrayIndex;
11373 [maxvertexcount(12)]
11374 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
11376 gs_out o;
11377 for (uint instance_id = 0; instance_id < 4; ++instance_id)
11379 o.layer = layer_offset + instance_id;
11380 for (uint i = 0; i < 3; ++i)
11382 o.pos = vin[i].pos;
11383 vout.Append(o);
11385 vout.RestartStrip();
11388 #endif
11389 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
11390 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11391 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
11392 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11393 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
11394 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
11395 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
11396 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
11397 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
11398 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
11399 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
11400 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
11401 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
11402 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
11403 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
11404 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
11405 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
11406 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
11407 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
11409 static const DWORD ps_code[] =
11411 #if 0
11412 uint layer_offset;
11413 uint draw_id;
11415 float4 main(in float4 pos : SV_Position,
11416 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
11418 return float4(layer, draw_id, 0, 0);
11420 #endif
11421 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
11422 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
11423 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
11424 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
11425 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
11426 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
11427 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
11428 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
11429 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
11430 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
11431 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
11433 static const struct vec4 expected_values[] =
11435 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
11436 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
11437 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
11438 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
11440 static const struct vec4 vs_expected_value = {1.0f, 42.0f};
11442 if (!init_test_context(&test_context, NULL))
11443 return;
11445 device = test_context.device;
11446 context = test_context.immediate_context;
11448 warp = is_warp_device(device);
11450 memset(&constant, 0, sizeof(constant));
11451 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
11452 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
11453 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
11454 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11456 /* Geometry shader instancing seems broken on WARP. */
11457 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0 || warp)
11459 hr = ID3D11Device_CreateGeometryShader(device, gs_4_code, sizeof(gs_4_code), NULL, &gs);
11460 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
11462 else
11464 hr = ID3D11Device_CreateGeometryShader(device, gs_5_code, sizeof(gs_5_code), NULL, &gs);
11465 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
11467 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
11469 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11470 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11471 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11473 texture_desc.Width = 32;
11474 texture_desc.Height = 32;
11475 texture_desc.MipLevels = 3;
11476 texture_desc.ArraySize = 8;
11477 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11478 texture_desc.SampleDesc.Count = 1;
11479 texture_desc.SampleDesc.Quality = 0;
11480 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11481 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11482 texture_desc.CPUAccessFlags = 0;
11483 texture_desc.MiscFlags = 0;
11484 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11485 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11487 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11488 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11489 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11490 constant.layer_offset = 0;
11491 constant.draw_id = 0;
11492 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11493 draw_quad(&test_context);
11494 constant.layer_offset = 4;
11495 constant.draw_id = 1;
11496 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11497 draw_quad(&test_context);
11498 ID3D11RenderTargetView_Release(rtv);
11500 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11501 rtv_desc.Format = texture_desc.Format;
11502 U(rtv_desc).Texture2DArray.MipSlice = 0;
11503 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
11504 U(rtv_desc).Texture2DArray.ArraySize = 1;
11505 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11506 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11507 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11508 constant.layer_offset = 1;
11509 constant.draw_id = 2;
11510 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11511 draw_quad(&test_context);
11512 ID3D11RenderTargetView_Release(rtv);
11514 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11515 U(rtv_desc).Texture2DArray.MipSlice = 1;
11516 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
11517 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
11518 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11519 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11520 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11521 constant.layer_offset = 0;
11522 constant.draw_id = 3;
11523 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11524 draw_quad(&test_context);
11525 constant.layer_offset = 4;
11526 constant.draw_id = 3;
11527 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11528 draw_quad(&test_context);
11529 ID3D11RenderTargetView_Release(rtv);
11531 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11532 U(rtv_desc).Texture2DArray.MipSlice = 2;
11533 U(rtv_desc).Texture2DArray.ArraySize = 1;
11534 for (i = 0; i < texture_desc.ArraySize; ++i)
11536 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
11537 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11538 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11539 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11540 constant.layer_offset = 0;
11541 constant.draw_id = 4 + i;
11542 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11543 draw_quad(&test_context);
11544 ID3D11RenderTargetView_Release(rtv);
11547 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
11548 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
11549 for (i = 0; i < sub_resource_count; ++i)
11551 if (warp && (i == 3 || i == 4)) /* Broken on WARP. */
11552 continue;
11553 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
11556 /* layered rendering without GS */
11557 if (!check_viewport_array_index_from_any_shader_support(device))
11559 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11560 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11561 if (SUCCEEDED(hr))
11562 ID3D11VertexShader_Release(vs);
11563 skip("Viewport array index not supported in vertex shaders.\n");
11564 goto done;
11567 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
11569 constant.layer_offset = 1;
11570 constant.draw_id = 42;
11571 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11572 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11573 U(rtv_desc).Texture2DArray.MipSlice = 0;
11574 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
11575 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
11576 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11577 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
11578 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11579 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
11580 check_texture_sub_resource_vec4(texture,
11581 constant.layer_offset * texture_desc.MipLevels, NULL, &vs_expected_value, 1);
11582 ID3D11RenderTargetView_Release(rtv);
11584 done:
11585 ID3D11Texture2D_Release(texture);
11587 ID3D11Buffer_Release(cb);
11588 ID3D11GeometryShader_Release(gs);
11589 ID3D11PixelShader_Release(ps);
11590 release_test_context(&test_context);
11593 static void test_scissor(void)
11595 struct d3d11_test_context test_context;
11596 ID3D11DeviceContext *immediate_context;
11597 D3D11_RASTERIZER_DESC rs_desc;
11598 ID3D11RasterizerState *rs;
11599 D3D11_RECT scissor_rect;
11600 ID3D11Device *device;
11601 DWORD color;
11602 HRESULT hr;
11604 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
11605 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11607 if (!init_test_context(&test_context, NULL))
11608 return;
11610 device = test_context.device;
11611 immediate_context = test_context.immediate_context;
11613 rs_desc.FillMode = D3D11_FILL_SOLID;
11614 rs_desc.CullMode = D3D11_CULL_BACK;
11615 rs_desc.FrontCounterClockwise = FALSE;
11616 rs_desc.DepthBias = 0;
11617 rs_desc.DepthBiasClamp = 0.0f;
11618 rs_desc.SlopeScaledDepthBias = 0.0f;
11619 rs_desc.DepthClipEnable = TRUE;
11620 rs_desc.ScissorEnable = TRUE;
11621 rs_desc.MultisampleEnable = FALSE;
11622 rs_desc.AntialiasedLineEnable = FALSE;
11623 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
11624 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11626 SetRect(&scissor_rect, 160, 120, 480, 360);
11627 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
11629 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
11630 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
11632 draw_color_quad(&test_context, &green);
11633 color = get_texture_color(test_context.backbuffer, 320, 60);
11634 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11635 color = get_texture_color(test_context.backbuffer, 80, 240);
11636 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11637 color = get_texture_color(test_context.backbuffer, 320, 240);
11638 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11639 color = get_texture_color(test_context.backbuffer, 560, 240);
11640 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11641 color = get_texture_color(test_context.backbuffer, 320, 420);
11642 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11644 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
11645 ID3D11DeviceContext_RSSetState(immediate_context, rs);
11646 draw_color_quad(&test_context, &green);
11647 color = get_texture_color(test_context.backbuffer, 320, 60);
11648 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11649 color = get_texture_color(test_context.backbuffer, 80, 240);
11650 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11651 color = get_texture_color(test_context.backbuffer, 320, 240);
11652 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11653 color = get_texture_color(test_context.backbuffer, 560, 240);
11654 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11655 color = get_texture_color(test_context.backbuffer, 320, 420);
11656 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11658 set_viewport(immediate_context, -1.0f, 0.0f, 641, 480, 0.0f, 1.0f);
11659 SetRect(&scissor_rect, -1, 0, 640, 480);
11660 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
11661 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
11662 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
11663 draw_color_quad(&test_context, &green);
11664 color = get_texture_color(test_context.backbuffer, 320, 60);
11665 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11666 color = get_texture_color(test_context.backbuffer, 80, 240);
11667 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11668 color = get_texture_color(test_context.backbuffer, 320, 240);
11669 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11670 color = get_texture_color(test_context.backbuffer, 560, 240);
11671 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11672 color = get_texture_color(test_context.backbuffer, 320, 420);
11673 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11675 ID3D11RasterizerState_Release(rs);
11676 release_test_context(&test_context);
11679 static void test_clear_state(void)
11681 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11682 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11684 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11686 #if 0
11687 float4 main(float4 pos : POSITION) : POSITION
11689 return pos;
11691 #endif
11692 static const DWORD simple_vs[] =
11694 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
11695 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11696 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11697 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11698 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
11699 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
11700 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11702 #if 0
11703 struct data
11705 float4 position : SV_Position;
11708 struct patch_constant_data
11710 float edges[3] : SV_TessFactor;
11711 float inside : SV_InsideTessFactor;
11714 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
11716 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
11717 output.inside = 1.0f;
11720 [domain("tri")]
11721 [outputcontrolpoints(3)]
11722 [partitioning("integer")]
11723 [outputtopology("triangle_ccw")]
11724 [patchconstantfunc("patch_constant")]
11725 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
11727 return input[i];
11730 [domain("tri")]
11731 void ds_main(patch_constant_data input,
11732 float3 tess_coord : SV_DomainLocation,
11733 const OutputPatch<data, 3> patch,
11734 out data output)
11736 output.position = tess_coord.x * patch[0].position
11737 + tess_coord.y * patch[1].position
11738 + tess_coord.z * patch[2].position;
11740 #endif
11741 static const DWORD simple_hs[] =
11743 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
11744 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11745 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
11746 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11747 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
11748 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
11749 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
11750 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
11751 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
11752 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
11753 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
11754 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
11755 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
11756 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
11757 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
11758 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
11759 0x00004001, 0x3f800000, 0x0100003e,
11761 static const DWORD simple_ds[] =
11763 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
11764 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11765 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
11766 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
11767 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
11768 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
11769 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
11770 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
11771 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
11772 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
11773 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
11774 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
11775 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
11776 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
11777 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
11779 #if 0
11780 struct gs_out
11782 float4 pos : SV_POSITION;
11785 [maxvertexcount(4)]
11786 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
11788 float offset = 0.1 * vin[0].w;
11789 gs_out v;
11791 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
11792 vout.Append(v);
11793 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
11794 vout.Append(v);
11795 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
11796 vout.Append(v);
11797 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
11798 vout.Append(v);
11800 #endif
11801 static const DWORD simple_gs[] =
11803 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
11804 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11805 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11806 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
11807 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
11808 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
11809 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
11810 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
11811 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
11812 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
11813 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
11814 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
11815 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
11816 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
11817 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
11818 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
11819 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
11820 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
11822 #if 0
11823 float4 main(float4 color : COLOR) : SV_TARGET
11825 return color;
11827 #endif
11828 static const DWORD simple_ps[] =
11830 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
11831 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
11832 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
11833 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11834 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11835 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
11836 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11838 #if 0
11839 [numthreads(1, 1, 1)]
11840 void main() { }
11841 #endif
11842 static const DWORD simple_cs[] =
11844 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
11845 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11846 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
11847 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
11850 D3D11_VIEWPORT tmp_viewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
11851 ID3D11ShaderResourceView *tmp_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
11852 ID3D11ShaderResourceView *srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
11853 ID3D11RenderTargetView *tmp_rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11854 RECT tmp_rect[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
11855 ID3D11SamplerState *tmp_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
11856 ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11857 ID3D11Texture2D *rt_texture[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11858 ID3D11Buffer *cb[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
11859 ID3D11Buffer *tmp_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11860 ID3D11SamplerState *sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
11861 ID3D11UnorderedAccessView *tmp_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
11862 ID3D11UnorderedAccessView *cs_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
11863 ID3D11Buffer *buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11864 ID3D11Buffer *cs_uav_buffer[D3D11_PS_CS_UAV_REGISTER_COUNT];
11865 UINT offset[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11866 UINT stride[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11867 ID3D11Buffer *so_buffer[D3D11_SO_BUFFER_SLOT_COUNT];
11868 ID3D11InputLayout *tmp_input_layout, *input_layout;
11869 ID3D11DepthStencilState *tmp_ds_state, *ds_state;
11870 ID3D11BlendState *tmp_blend_state, *blend_state;
11871 ID3D11RasterizerState *tmp_rs_state, *rs_state;
11872 ID3D11Predicate *tmp_predicate, *predicate;
11873 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
11874 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
11875 ID3D11DepthStencilView *tmp_dsv, *dsv;
11876 ID3D11UnorderedAccessView *ps_uav;
11877 D3D11_PRIMITIVE_TOPOLOGY topology;
11878 D3D11_TEXTURE2D_DESC texture_desc;
11879 ID3D11GeometryShader *tmp_gs, *gs;
11880 ID3D11ComputeShader *tmp_cs, *cs;
11881 D3D11_DEPTH_STENCIL_DESC ds_desc;
11882 ID3D11VertexShader *tmp_vs, *vs;
11883 ID3D11DomainShader *tmp_ds, *ds;
11884 D3D11_SAMPLER_DESC sampler_desc;
11885 D3D11_QUERY_DESC predicate_desc;
11886 struct device_desc device_desc;
11887 ID3D11PixelShader *tmp_ps, *ps;
11888 ID3D11HullShader *tmp_hs, *hs;
11889 D3D11_RASTERIZER_DESC rs_desc;
11890 ID3D11DeviceContext *context;
11891 D3D11_BLEND_DESC blend_desc;
11892 ID3D11Texture2D *ds_texture;
11893 ID3D11Buffer *ps_uav_buffer;
11894 float blend_factor[4];
11895 ID3D11Device *device;
11896 BOOL predicate_value;
11897 UINT instance_count;
11898 DXGI_FORMAT format;
11899 UINT sample_mask;
11900 UINT stencil_ref;
11901 ULONG refcount;
11902 UINT count, i;
11903 HRESULT hr;
11905 device_desc.feature_level = &feature_level;
11906 device_desc.flags = 0;
11907 if (!(device = create_device(&device_desc)))
11909 skip("Failed to create device.\n");
11910 return;
11913 ID3D11Device_GetImmediateContext(device, &context);
11915 /* Verify the initial state after device creation. */
11917 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11918 tmp_buffer);
11919 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11921 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11923 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11924 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11926 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11928 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11929 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11931 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11933 instance_count = 100;
11934 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, &instance_count);
11935 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
11936 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11938 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11939 tmp_buffer);
11940 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11942 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11944 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11945 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11947 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11949 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11950 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11952 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11954 instance_count = 100;
11955 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, &instance_count);
11956 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
11957 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11959 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11960 tmp_buffer);
11961 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11963 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11965 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11966 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11968 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11970 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11971 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11973 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11975 instance_count = 100;
11976 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, &instance_count);
11977 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
11978 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11980 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11981 tmp_buffer);
11982 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11984 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11986 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11987 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11989 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11991 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11992 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11994 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11996 instance_count = 100;
11997 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, &instance_count);
11998 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
11999 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
12001 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12002 tmp_buffer);
12003 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12005 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12007 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
12008 tmp_srv);
12009 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12011 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12013 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12014 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12016 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12018 instance_count = 100;
12019 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, &instance_count);
12020 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
12021 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
12023 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12024 tmp_buffer);
12025 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12027 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12029 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
12030 tmp_srv);
12031 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12033 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12035 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12036 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12038 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12040 instance_count = 100;
12041 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, &instance_count);
12042 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
12043 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
12044 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12045 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12047 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12050 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12051 tmp_buffer, stride, offset);
12052 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12054 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
12055 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
12056 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
12058 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
12059 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
12060 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
12061 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
12062 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
12063 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
12064 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
12065 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
12067 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
12068 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
12069 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
12070 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
12071 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12072 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12073 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
12074 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
12075 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
12076 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
12077 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
12078 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12080 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12082 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12083 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
12084 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
12085 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12086 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12088 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12090 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12091 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12093 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12096 if (!enable_debug_layer)
12098 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
12099 ok(!count, "Got unexpected scissor rect count %u.\n", count);
12101 memset(tmp_rect, 0x55, sizeof(tmp_rect));
12102 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12103 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
12104 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12106 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
12107 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
12109 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12110 ok(!count, "Got unexpected viewport count %u.\n", count);
12111 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12112 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12113 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12114 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12116 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
12117 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
12118 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12119 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12120 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12122 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12123 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
12125 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12126 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12128 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
12131 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12132 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
12133 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12135 /* Create resources. */
12137 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12138 cb[i] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 1024, NULL);
12140 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12142 buffer[i] = create_buffer(device,
12143 D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE,
12144 1024, NULL);
12146 stride[i] = (i + 1) * 4;
12147 offset[i] = (i + 1) * 16;
12150 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12151 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
12153 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12154 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
12155 U(srv_desc).Buffer.ElementOffset = 0;
12156 U(srv_desc).Buffer.ElementWidth = 64;
12158 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12160 hr = ID3D11Device_CreateShaderResourceView(device,
12161 (ID3D11Resource *)buffer[i % D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
12162 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12165 uav_desc.Format = DXGI_FORMAT_R32_UINT;
12166 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
12167 U(uav_desc).Buffer.FirstElement = 0;
12168 U(uav_desc).Buffer.NumElements = 8;
12169 U(uav_desc).Buffer.Flags = 0;
12171 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12173 cs_uav_buffer[i] = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
12174 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_uav_buffer[i],
12175 &uav_desc, &cs_uav[i]);
12176 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12179 ps_uav_buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
12180 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_uav_buffer,
12181 &uav_desc, &ps_uav);
12182 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12184 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
12185 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
12186 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
12187 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
12188 sampler_desc.MipLODBias = 0.0f;
12189 sampler_desc.MaxAnisotropy = 16;
12190 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
12191 sampler_desc.BorderColor[0] = 0.0f;
12192 sampler_desc.BorderColor[1] = 0.0f;
12193 sampler_desc.BorderColor[2] = 0.0f;
12194 sampler_desc.BorderColor[3] = 0.0f;
12195 sampler_desc.MinLOD = 0.0f;
12196 sampler_desc.MaxLOD = 16.0f;
12198 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12200 sampler_desc.MinLOD = (float)i;
12202 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
12203 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
12206 hr = ID3D11Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
12207 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12209 hr = ID3D11Device_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
12210 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
12212 hr = ID3D11Device_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
12213 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
12215 hr = ID3D11Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
12216 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
12218 hr = ID3D11Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
12219 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12221 hr = ID3D11Device_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
12222 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
12224 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12225 simple_vs, sizeof(simple_vs), &input_layout);
12226 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12228 memset(&blend_desc, 0, sizeof(blend_desc));
12229 blend_desc.AlphaToCoverageEnable = FALSE;
12230 blend_desc.IndependentBlendEnable = FALSE;
12231 blend_desc.RenderTarget[0].BlendEnable = TRUE;
12232 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
12233 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
12234 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
12235 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
12236 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
12237 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
12238 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
12240 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
12241 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
12243 ds_desc.DepthEnable = TRUE;
12244 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
12245 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
12246 ds_desc.StencilEnable = FALSE;
12247 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
12248 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
12249 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
12250 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
12251 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
12252 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
12253 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
12254 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
12255 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
12256 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
12258 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
12259 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
12261 texture_desc.Width = 512;
12262 texture_desc.Height = 512;
12263 texture_desc.MipLevels = 1;
12264 texture_desc.ArraySize = 1;
12265 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12266 texture_desc.SampleDesc.Count = 1;
12267 texture_desc.SampleDesc.Quality = 0;
12268 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12269 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12270 texture_desc.CPUAccessFlags = 0;
12271 texture_desc.MiscFlags = 0;
12273 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12275 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
12276 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12279 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
12280 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
12282 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
12283 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12285 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12287 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture[i], NULL, &rtv[i]);
12288 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12291 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)ds_texture, NULL, &dsv);
12292 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
12294 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12296 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
12298 tmp_viewport[i].TopLeftX = i * 3;
12299 tmp_viewport[i].TopLeftY = i * 4;
12300 tmp_viewport[i].Width = 3;
12301 tmp_viewport[i].Height = 4;
12302 tmp_viewport[i].MinDepth = i * 0.01f;
12303 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
12306 rs_desc.FillMode = D3D11_FILL_SOLID;
12307 rs_desc.CullMode = D3D11_CULL_BACK;
12308 rs_desc.FrontCounterClockwise = FALSE;
12309 rs_desc.DepthBias = 0;
12310 rs_desc.DepthBiasClamp = 0.0f;
12311 rs_desc.SlopeScaledDepthBias = 0.0f;
12312 rs_desc.DepthClipEnable = TRUE;
12313 rs_desc.ScissorEnable = FALSE;
12314 rs_desc.MultisampleEnable = FALSE;
12315 rs_desc.AntialiasedLineEnable = FALSE;
12317 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs_state);
12318 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12320 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
12321 predicate_desc.MiscFlags = 0;
12323 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
12324 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
12326 /* Setup state. */
12328 /* Some versions of Windows AMD drivers hang while the device is being
12329 * released, if the total number of used resource slots exceeds some limit.
12330 * Do not use all constant buffers slots in order to not trigger this
12331 * driver bug. */
12332 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb[0]);
12333 ID3D11DeviceContext_VSSetConstantBuffers(context, 7, 1, &cb[7]);
12334 ID3D11DeviceContext_VSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12335 ID3D11DeviceContext_VSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12336 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12338 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb[0]);
12339 ID3D11DeviceContext_HSSetConstantBuffers(context, 7, 1, &cb[7]);
12340 ID3D11DeviceContext_HSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12341 ID3D11DeviceContext_HSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12342 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
12344 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12345 ID3D11DeviceContext_DSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12346 ID3D11DeviceContext_DSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12347 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
12349 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12350 ID3D11DeviceContext_GSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12351 ID3D11DeviceContext_GSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12352 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
12354 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12355 ID3D11DeviceContext_PSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12356 ID3D11DeviceContext_PSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12357 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12359 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12360 ID3D11DeviceContext_CSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12361 ID3D11DeviceContext_CSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12362 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
12363 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, cs_uav, NULL);
12365 ID3D11DeviceContext_IASetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12366 buffer, stride, offset);
12367 ID3D11DeviceContext_IASetIndexBuffer(context, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
12368 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12369 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12371 blend_factor[0] = 0.1f;
12372 blend_factor[1] = 0.2f;
12373 blend_factor[2] = 0.3f;
12374 blend_factor[3] = 0.4f;
12375 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, 0xff00ff00);
12376 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 3);
12377 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
12378 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, rtv, dsv,
12379 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, 1, &ps_uav, NULL);
12381 ID3D11DeviceContext_RSSetScissorRects(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12382 tmp_rect);
12383 ID3D11DeviceContext_RSSetViewports(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12384 tmp_viewport);
12385 ID3D11DeviceContext_RSSetState(context, rs_state);
12387 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
12389 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
12391 /* Verify the set state. */
12393 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12394 tmp_buffer);
12395 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12397 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
12398 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12399 tmp_buffer[i], i, expected_cb);
12400 if (tmp_buffer[i])
12401 ID3D11Buffer_Release(tmp_buffer[i]);
12403 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12404 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12406 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12407 tmp_srv[i], i, srv[i]);
12408 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12410 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12411 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12413 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12414 tmp_sampler[i], i, sampler[i]);
12415 ID3D11SamplerState_Release(tmp_sampler[i]);
12417 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
12418 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
12419 ID3D11VertexShader_Release(tmp_vs);
12421 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12422 tmp_buffer);
12423 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12425 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
12426 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12427 tmp_buffer[i], i, expected_cb);
12428 if (tmp_buffer[i])
12429 ID3D11Buffer_Release(tmp_buffer[i]);
12431 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12432 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12434 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12435 tmp_srv[i], i, srv[i]);
12436 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12438 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12439 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12441 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12442 tmp_sampler[i], i, sampler[i]);
12443 ID3D11SamplerState_Release(tmp_sampler[i]);
12445 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
12446 ok(tmp_hs == hs, "Got unexpected hull shader %p, expected %p.\n", tmp_hs, hs);
12447 ID3D11HullShader_Release(tmp_hs);
12449 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12450 tmp_buffer);
12451 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12453 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12454 tmp_buffer[i], i, cb[i]);
12455 ID3D11Buffer_Release(tmp_buffer[i]);
12457 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12458 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12460 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12461 tmp_srv[i], i, srv[i]);
12462 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12464 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12465 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12467 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12468 tmp_sampler[i], i, sampler[i]);
12469 ID3D11SamplerState_Release(tmp_sampler[i]);
12471 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
12472 ok(tmp_ds == ds, "Got unexpected domain shader %p, expected %p.\n", tmp_ds, ds);
12473 ID3D11DomainShader_Release(tmp_ds);
12475 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12476 tmp_buffer);
12477 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12479 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12480 tmp_buffer[i], i, cb[i]);
12481 ID3D11Buffer_Release(tmp_buffer[i]);
12483 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12484 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12486 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12487 tmp_srv[i], i, srv[i]);
12488 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12490 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12491 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12493 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12494 tmp_sampler[i], i, sampler[i]);
12495 ID3D11SamplerState_Release(tmp_sampler[i]);
12497 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
12498 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
12499 ID3D11GeometryShader_Release(tmp_gs);
12501 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12502 tmp_buffer);
12503 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12505 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12506 tmp_buffer[i], i, cb[i]);
12507 ID3D11Buffer_Release(tmp_buffer[i]);
12509 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12510 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12512 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12513 tmp_srv[i], i, srv[i]);
12514 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12516 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12517 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12519 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12520 tmp_sampler[i], i, sampler[i]);
12521 ID3D11SamplerState_Release(tmp_sampler[i]);
12523 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
12524 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
12525 ID3D11PixelShader_Release(tmp_ps);
12527 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12528 tmp_buffer);
12529 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12531 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12532 tmp_buffer[i], i, cb[i]);
12533 ID3D11Buffer_Release(tmp_buffer[i]);
12535 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12536 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12538 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12539 tmp_srv[i], i, srv[i]);
12540 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12542 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12543 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12545 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12546 tmp_sampler[i], i, sampler[i]);
12547 ID3D11SamplerState_Release(tmp_sampler[i]);
12549 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
12550 ok(tmp_cs == cs, "Got unexpected compute shader %p, expected %p.\n", tmp_cs, cs);
12551 ID3D11ComputeShader_Release(tmp_cs);
12552 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12553 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12555 ok(tmp_uav[i] == cs_uav[i], "Got unexpected unordered access view %p in slot %u, expected %p.\n",
12556 tmp_uav[i], i, cs_uav[i]);
12557 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
12560 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12561 tmp_buffer, stride, offset);
12562 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12564 todo_wine_if(i >= D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
12566 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
12567 tmp_buffer[i], i, buffer[i]);
12568 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
12569 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
12571 if (tmp_buffer[i])
12572 ID3D11Buffer_Release(tmp_buffer[i]);
12574 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
12575 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
12576 ID3D11Buffer_Release(tmp_buffer[0]);
12577 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
12578 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
12579 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
12580 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
12581 tmp_input_layout, input_layout);
12582 ID3D11InputLayout_Release(tmp_input_layout);
12583 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
12584 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
12586 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
12587 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
12588 ID3D11BlendState_Release(tmp_blend_state);
12589 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
12590 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
12591 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12592 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12593 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
12594 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
12595 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
12596 ID3D11DepthStencilState_Release(tmp_ds_state);
12597 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
12598 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
12599 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
12601 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
12602 tmp_rtv[i], i, rtv[i]);
12603 ID3D11RenderTargetView_Release(tmp_rtv[i]);
12605 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12606 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
12607 ID3D11DepthStencilView_Release(tmp_dsv);
12608 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
12609 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
12610 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12611 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
12613 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
12614 tmp_rtv[i], i, rtv[i]);
12615 ID3D11RenderTargetView_Release(tmp_rtv[i]);
12617 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12618 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
12619 ID3D11DepthStencilView_Release(tmp_dsv);
12620 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT - 1; ++i)
12622 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12624 ok(tmp_uav[i] == ps_uav, "Got unexpected unordered access view %p in slot %u, expected %p.\n",
12625 tmp_uav[i], i, ps_uav);
12626 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
12628 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
12629 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12630 "Got unexpected scissor rect count %u.\n", count);
12631 memset(tmp_rect, 0x55, sizeof(tmp_rect));
12632 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
12633 for (i = 0; i < count; ++i)
12635 ok(tmp_rect[i].left == i
12636 && tmp_rect[i].top == i * 2
12637 && tmp_rect[i].right == i + 1
12638 && tmp_rect[i].bottom == (i + 1) * 2,
12639 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
12641 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12642 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12643 "Got unexpected viewport count %u.\n", count);
12644 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12645 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12646 for (i = 0; i < count; ++i)
12648 ok(tmp_viewport[i].TopLeftX == i * 3
12649 && tmp_viewport[i].TopLeftY == i * 4
12650 && tmp_viewport[i].Width == 3
12651 && tmp_viewport[i].Height == 4
12652 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
12653 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
12654 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12655 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12656 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12658 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12659 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
12660 ID3D11RasterizerState_Release(tmp_rs_state);
12662 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12663 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12665 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
12666 tmp_buffer[i], i, so_buffer[i]);
12667 ID3D11Buffer_Release(tmp_buffer[i]);
12670 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12671 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
12672 ID3D11Predicate_Release(tmp_predicate);
12673 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12675 /* Verify ClearState(). */
12677 ID3D11DeviceContext_ClearState(context);
12679 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12680 tmp_buffer);
12681 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12683 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12685 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12686 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12688 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12690 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12691 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12693 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12695 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
12696 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
12698 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12699 tmp_buffer);
12700 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12702 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12704 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12705 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12707 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12709 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12710 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12712 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12714 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
12715 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
12717 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12718 tmp_buffer);
12719 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12721 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12723 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12724 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12726 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12728 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12729 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12731 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12733 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
12734 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
12736 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12737 tmp_buffer);
12738 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12740 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12742 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12743 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12745 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12747 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12748 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12750 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12752 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
12753 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
12755 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12756 tmp_buffer);
12757 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12759 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12761 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12762 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12764 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12766 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12767 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12769 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12771 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
12772 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
12774 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12775 tmp_buffer);
12776 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12778 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12780 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
12781 tmp_srv);
12782 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12784 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12786 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12787 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12789 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12791 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
12792 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
12793 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12794 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12796 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12799 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12800 tmp_buffer, stride, offset);
12801 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12803 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
12804 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
12805 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
12807 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
12808 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
12809 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
12810 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
12811 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
12812 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
12813 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
12814 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
12816 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
12817 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
12818 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
12819 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
12820 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12821 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12822 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
12823 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
12824 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
12825 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
12826 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
12827 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12829 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12831 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12832 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
12833 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
12834 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12835 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12837 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12839 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12840 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12842 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12845 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
12846 ok(!count, "Got unexpected scissor rect count %u.\n", count);
12847 memset(tmp_rect, 0x55, sizeof(tmp_rect));
12848 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12849 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
12850 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12852 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
12853 "Got unexpected scissor rect %s in slot %u.\n",
12854 wine_dbgstr_rect(&tmp_rect[i]), i);
12856 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12857 ok(!count, "Got unexpected viewport count %u.\n", count);
12858 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12859 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12860 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12861 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12863 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
12864 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
12865 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12866 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12867 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12869 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12870 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
12872 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12873 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12875 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
12878 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12879 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
12880 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12882 /* Cleanup. */
12884 ID3D11Predicate_Release(predicate);
12885 ID3D11RasterizerState_Release(rs_state);
12886 ID3D11DepthStencilView_Release(dsv);
12887 ID3D11Texture2D_Release(ds_texture);
12889 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12891 ID3D11RenderTargetView_Release(rtv[i]);
12892 ID3D11Texture2D_Release(rt_texture[i]);
12895 ID3D11DepthStencilState_Release(ds_state);
12896 ID3D11BlendState_Release(blend_state);
12897 ID3D11InputLayout_Release(input_layout);
12898 ID3D11VertexShader_Release(vs);
12899 ID3D11HullShader_Release(hs);
12900 ID3D11DomainShader_Release(ds);
12901 ID3D11GeometryShader_Release(gs);
12902 ID3D11PixelShader_Release(ps);
12903 ID3D11ComputeShader_Release(cs);
12905 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12907 ID3D11SamplerState_Release(sampler[i]);
12910 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12912 ID3D11ShaderResourceView_Release(srv[i]);
12915 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12917 ID3D11UnorderedAccessView_Release(cs_uav[i]);
12918 ID3D11Buffer_Release(cs_uav_buffer[i]);
12920 ID3D11UnorderedAccessView_Release(ps_uav);
12921 ID3D11Buffer_Release(ps_uav_buffer);
12923 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12925 ID3D11Buffer_Release(so_buffer[i]);
12928 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12930 ID3D11Buffer_Release(buffer[i]);
12933 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12935 ID3D11Buffer_Release(cb[i]);
12938 ID3D11DeviceContext_Release(context);
12939 refcount = ID3D11Device_Release(device);
12940 ok(!refcount, "Device has %u references left.\n", refcount);
12943 static void test_il_append_aligned(void)
12945 struct d3d11_test_context test_context;
12946 ID3D11InputLayout *input_layout;
12947 ID3D11DeviceContext *context;
12948 unsigned int stride, offset;
12949 ID3D11VertexShader *vs;
12950 ID3D11PixelShader *ps;
12951 ID3D11Device *device;
12952 ID3D11Buffer *vb[3];
12953 DWORD color;
12954 HRESULT hr;
12956 /* Semantic names are case-insensitive. */
12957 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12959 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
12960 D3D11_INPUT_PER_INSTANCE_DATA, 2},
12961 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
12962 D3D11_INPUT_PER_INSTANCE_DATA, 1},
12963 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
12964 D3D11_INPUT_PER_VERTEX_DATA, 0},
12965 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
12966 D3D11_INPUT_PER_INSTANCE_DATA, 1},
12967 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
12968 D3D11_INPUT_PER_INSTANCE_DATA, 2},
12970 static const DWORD vs_code[] =
12972 #if 0
12973 struct vs_in
12975 float4 position : POSITION;
12976 float2 color_xy : COLOR0;
12977 float2 color_zw : COLOR1;
12978 unsigned int instance_id : SV_INSTANCEID;
12981 struct vs_out
12983 float4 position : SV_POSITION;
12984 float2 color_xy : COLOR0;
12985 float2 color_zw : COLOR1;
12988 struct vs_out main(struct vs_in i)
12990 struct vs_out o;
12992 o.position = i.position;
12993 o.position.x += i.instance_id * 0.5;
12994 o.color_xy = i.color_xy;
12995 o.color_zw = i.color_zw;
12997 return o;
12999 #endif
13000 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
13001 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
13002 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
13003 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
13004 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
13005 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
13006 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
13007 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
13008 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
13009 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
13010 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
13011 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
13012 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
13013 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
13014 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
13015 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
13016 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
13018 static const DWORD ps_code[] =
13020 #if 0
13021 struct vs_out
13023 float4 position : SV_POSITION;
13024 float2 color_xy : COLOR0;
13025 float2 color_zw : COLOR1;
13028 float4 main(struct vs_out i) : SV_TARGET
13030 return float4(i.color_xy.xy, i.color_zw.xy);
13032 #endif
13033 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
13034 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
13035 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
13036 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
13037 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
13038 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
13039 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
13040 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13041 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
13043 static const struct
13045 struct vec4 position;
13047 stream0[] =
13049 {{-1.0f, -1.0f, 0.0f, 1.0f}},
13050 {{-1.0f, 1.0f, 0.0f, 1.0f}},
13051 {{-0.5f, -1.0f, 0.0f, 1.0f}},
13052 {{-0.5f, 1.0f, 0.0f, 1.0f}},
13054 static const struct
13056 struct vec2 color2;
13057 struct vec2 color1;
13059 stream1[] =
13061 {{0.5f, 0.5f}, {0.0f, 1.0f}},
13062 {{0.5f, 0.5f}, {1.0f, 1.0f}},
13064 static const struct
13066 struct vec2 color3;
13067 struct vec2 color0;
13069 stream2[] =
13071 {{0.5f, 0.5f}, {1.0f, 0.0f}},
13072 {{0.5f, 0.5f}, {0.0f, 1.0f}},
13073 {{0.5f, 0.5f}, {0.0f, 0.0f}},
13074 {{0.5f, 0.5f}, {1.0f, 0.0f}},
13076 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13078 if (!init_test_context(&test_context, NULL))
13079 return;
13081 device = test_context.device;
13082 context = test_context.immediate_context;
13084 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13085 vs_code, sizeof(vs_code), &input_layout);
13086 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13088 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
13089 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
13090 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
13092 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13093 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13094 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13095 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13097 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13098 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13099 offset = 0;
13100 stride = sizeof(*stream0);
13101 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
13102 stride = sizeof(*stream1);
13103 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
13104 stride = sizeof(*stream2);
13105 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
13106 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13107 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13109 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13111 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
13113 color = get_texture_color(test_context.backbuffer, 80, 240);
13114 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
13115 color = get_texture_color(test_context.backbuffer, 240, 240);
13116 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13117 color = get_texture_color(test_context.backbuffer, 400, 240);
13118 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13119 color = get_texture_color(test_context.backbuffer, 560, 240);
13120 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
13122 ID3D11PixelShader_Release(ps);
13123 ID3D11VertexShader_Release(vs);
13124 ID3D11Buffer_Release(vb[2]);
13125 ID3D11Buffer_Release(vb[1]);
13126 ID3D11Buffer_Release(vb[0]);
13127 ID3D11InputLayout_Release(input_layout);
13128 release_test_context(&test_context);
13131 static void test_instanced_draw(void)
13133 struct d3d11_test_context test_context;
13134 D3D11_TEXTURE2D_DESC texture_desc;
13135 ID3D11InputLayout *input_layout;
13136 ID3D11RenderTargetView *rtvs[2];
13137 ID3D11Texture2D *render_target;
13138 ID3D11DeviceContext *context;
13139 struct resource_readback rb;
13140 unsigned int stride, offset;
13141 ID3D11Buffer *args_buffer;
13142 ID3D11VertexShader *vs;
13143 ID3D11PixelShader *ps;
13144 ID3D11Device *device;
13145 ID3D11Buffer *vb[4];
13146 unsigned int i;
13147 HRESULT hr;
13149 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13151 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
13152 D3D11_INPUT_PER_VERTEX_DATA, 0},
13153 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT,
13154 D3D11_INPUT_PER_INSTANCE_DATA, 1},
13155 {"color", 1, DXGI_FORMAT_R8_UNORM, 2, D3D11_APPEND_ALIGNED_ELEMENT,
13156 D3D10_INPUT_PER_INSTANCE_DATA, 0},
13157 {"color", 2, DXGI_FORMAT_R8_UNORM, 3, D3D11_APPEND_ALIGNED_ELEMENT,
13158 D3D10_INPUT_PER_INSTANCE_DATA, 2},
13159 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
13160 D3D11_INPUT_PER_INSTANCE_DATA, 1},
13162 static const DWORD vs_code[] =
13164 #if 0
13165 struct vs_in
13167 float4 position : Position;
13168 float r : color0;
13169 float g : color1;
13170 float b : color2;
13171 float v_offset : V_Offset;
13172 uint instance_id : SV_InstanceId;
13175 struct vs_out
13177 float4 position : SV_Position;
13178 float r : color0;
13179 float g : color1;
13180 float b : color2;
13181 uint instance_id : InstanceId;
13184 void main(vs_in i, out vs_out o)
13186 o.position = i.position;
13187 o.position.x += i.v_offset;
13188 o.r = i.r;
13189 o.g = i.g;
13190 o.b = i.b;
13191 o.instance_id = i.instance_id;
13193 #endif
13194 0x43425844, 0x036df42e, 0xff0da346, 0x7b23a14a, 0xc26ec9be, 0x00000001, 0x000002bc, 0x00000003,
13195 0x0000002c, 0x000000f4, 0x0000019c, 0x4e475349, 0x000000c0, 0x00000006, 0x00000008, 0x00000098,
13196 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a1, 0x00000000, 0x00000000,
13197 0x00000003, 0x00000001, 0x00000101, 0x000000a1, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
13198 0x00000101, 0x000000a1, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000a7,
13199 0x00000000, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000b0, 0x00000000, 0x00000008,
13200 0x00000001, 0x00000005, 0x00000101, 0x69736f50, 0x6e6f6974, 0x6c6f6300, 0x5600726f, 0x66664f5f,
13201 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e, 0xabab0064, 0x4e47534f, 0x000000a0, 0x00000005,
13202 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c,
13203 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000008c, 0x00000001, 0x00000000,
13204 0x00000003, 0x00000001, 0x00000d02, 0x0000008c, 0x00000002, 0x00000000, 0x00000003, 0x00000001,
13205 0x00000b04, 0x00000092, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
13206 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
13207 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
13208 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
13209 0x00101012, 0x00000004, 0x04000060, 0x00101012, 0x00000005, 0x00000008, 0x04000067, 0x001020f2,
13210 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065, 0x00102022, 0x00000001,
13211 0x03000065, 0x00102042, 0x00000001, 0x03000065, 0x00102012, 0x00000002, 0x07000000, 0x00102012,
13212 0x00000000, 0x0010100a, 0x00000000, 0x0010100a, 0x00000004, 0x05000036, 0x001020e2, 0x00000000,
13213 0x00101e56, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x05000036,
13214 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042, 0x00000001, 0x0010100a,
13215 0x00000003, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x0100003e,
13217 static const DWORD ps_code[] =
13219 #if 0
13220 struct vs_out
13222 float4 position : SV_Position;
13223 float r : color0;
13224 float g : color1;
13225 float b : color2;
13226 uint instance_id : InstanceId;
13229 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
13231 o0 = float4(i.r, i.g, i.b, 1.0f);
13232 o1 = i.instance_id;
13234 #endif
13235 0x43425844, 0xc9f9c86d, 0xa24d87aa, 0xff75d05b, 0xfbe0581a, 0x00000001, 0x000001b8, 0x00000003,
13236 0x0000002c, 0x000000d4, 0x00000120, 0x4e475349, 0x000000a0, 0x00000005, 0x00000008, 0x00000080,
13237 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
13238 0x00000003, 0x00000001, 0x00000101, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
13239 0x00000202, 0x0000008c, 0x00000002, 0x00000000, 0x00000003, 0x00000001, 0x00000404, 0x00000092,
13240 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
13241 0x6f6c6f63, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x4e47534f, 0x00000044, 0x00000002,
13242 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000038,
13243 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
13244 0x52444853, 0x00000090, 0x00000040, 0x00000024, 0x03001062, 0x00101012, 0x00000001, 0x03001062,
13245 0x00101022, 0x00000001, 0x03001062, 0x00101042, 0x00000001, 0x03000862, 0x00101012, 0x00000002,
13246 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072,
13247 0x00000000, 0x00101246, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
13248 0x05000036, 0x001020f2, 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
13250 static const struct vec4 stream0[] =
13252 {-1.00f, 0.0f, 0.0f, 1.0f},
13253 {-1.00f, 1.0f, 0.0f, 1.0f},
13254 {-0.75f, 0.0f, 0.0f, 1.0f},
13255 {-0.75f, 1.0f, 0.0f, 1.0f},
13256 /* indirect draws data */
13257 {-1.00f, -1.0f, 0.0f, 1.0f},
13258 {-1.00f, 0.0f, 0.0f, 1.0f},
13259 {-0.75f, -1.0f, 0.0f, 1.0f},
13260 {-0.75f, 0.0f, 0.0f, 1.0f},
13262 static const struct
13264 BYTE red;
13265 float v_offset;
13267 stream1[] =
13269 {0xf0, 0.00f},
13270 {0x80, 0.25f},
13271 {0x10, 0.50f},
13272 {0x40, 0.75f},
13274 {0xaa, 1.00f},
13275 {0xbb, 1.25f},
13276 {0xcc, 1.50f},
13277 {0x90, 1.75f},
13279 static const BYTE stream2[] = {0xf0, 0x80, 0x10, 0x40, 0xaa, 0xbb, 0xcc, 0x90};
13280 static const BYTE stream3[] = {0xf0, 0x80, 0x10, 0x40, 0xaa, 0xbb, 0xcc, 0x90};
13281 static const D3D11_DRAW_INSTANCED_INDIRECT_ARGS argument_data[] =
13283 {4, 4, 4, 0},
13284 {4, 4, 4, 4},
13286 static const struct
13288 RECT rect;
13289 unsigned int color;
13290 unsigned int instance_id;
13292 expected_results[] =
13294 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
13295 {{ 80, 0, 160, 240}, 0xfff0f080, 1},
13296 {{160, 0, 240, 240}, 0xff80f010, 2},
13297 {{240, 0, 320, 240}, 0xff80f040, 3},
13298 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
13299 {{400, 0, 480, 240}, 0xffaaaabb, 1},
13300 {{480, 0, 560, 240}, 0xffbbaacc, 2},
13301 {{560, 0, 640, 240}, 0xffbbaa90, 3},
13302 /* indirect draws results */
13303 {{ 0, 240, 80, 480}, 0xfff0f0f0, 0},
13304 {{ 80, 240, 160, 480}, 0xfff0f080, 1},
13305 {{160, 240, 240, 480}, 0xff80f010, 2},
13306 {{240, 240, 320, 480}, 0xff80f040, 3},
13307 {{320, 240, 400, 480}, 0xffaaaaaa, 0},
13308 {{400, 240, 480, 480}, 0xffaaaabb, 1},
13309 {{480, 240, 560, 480}, 0xffbbaacc, 2},
13310 {{560, 240, 640, 480}, 0xffbbaa90, 3},
13312 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13313 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13315 if (!init_test_context(&test_context, &feature_level))
13316 return;
13317 device = test_context.device;
13318 context = test_context.immediate_context;
13320 rtvs[0] = test_context.backbuffer_rtv;
13322 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13323 texture_desc.Format = DXGI_FORMAT_R32_UINT;
13324 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
13325 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13326 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtvs[1]);
13327 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13329 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13330 vs_code, sizeof(vs_code), &input_layout);
13331 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13333 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13334 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13335 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13336 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13338 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
13339 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
13340 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
13341 vb[3] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream3), stream3);
13343 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13344 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13345 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13346 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13347 offset = 0;
13348 stride = sizeof(*stream0);
13349 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
13350 stride = sizeof(*stream1);
13351 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
13352 stride = sizeof(*stream2);
13353 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
13354 stride = sizeof(*stream3);
13355 ID3D11DeviceContext_IASetVertexBuffers(context, 3, 1, &vb[3], &stride, &offset);
13357 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
13358 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[1], white);
13360 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
13361 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
13362 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 4);
13364 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
13365 sizeof(argument_data), argument_data);
13367 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, 0);
13368 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, sizeof(*argument_data));
13370 get_texture_readback(test_context.backbuffer, 0, &rb);
13371 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
13372 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
13373 release_resource_readback(&rb);
13375 get_texture_readback(render_target, 0, &rb);
13376 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
13377 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
13378 release_resource_readback(&rb);
13380 ID3D11Buffer_Release(vb[0]);
13381 ID3D11Buffer_Release(vb[1]);
13382 ID3D11Buffer_Release(vb[2]);
13383 ID3D11Buffer_Release(vb[3]);
13384 ID3D11Buffer_Release(args_buffer);
13385 ID3D11RenderTargetView_Release(rtvs[1]);
13386 ID3D11Texture2D_Release(render_target);
13387 ID3D11VertexShader_Release(vs);
13388 ID3D11PixelShader_Release(ps);
13389 ID3D11InputLayout_Release(input_layout);
13390 release_test_context(&test_context);
13393 static void test_vertex_id(void)
13395 static const DWORD vs_code[] =
13397 #if 0
13398 uint4 main(uint id : ID, uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID) : OUTPUT
13400 return uint4(id, instance_id, vertex_id, 0);
13402 #endif
13403 0x43425844, 0x5625197b, 0x588ccf8f, 0x48694905, 0x961d19ca, 0x00000001, 0x00000170, 0x00000003,
13404 0x0000002c, 0x000000a4, 0x000000d4, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
13405 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000101, 0x00000053, 0x00000000, 0x00000008,
13406 0x00000001, 0x00000001, 0x00000101, 0x00000061, 0x00000000, 0x00000006, 0x00000001, 0x00000002,
13407 0x00000101, 0x53004449, 0x6e495f56, 0x6e617473, 0x44496563, 0x5f565300, 0x74726556, 0x44497865,
13408 0xababab00, 0x4e47534f, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
13409 0x00000001, 0x00000000, 0x0000000f, 0x5054554f, 0xab005455, 0x52444853, 0x00000094, 0x00010040,
13410 0x00000025, 0x0300005f, 0x00101012, 0x00000000, 0x04000060, 0x00101012, 0x00000001, 0x00000008,
13411 0x04000060, 0x00101012, 0x00000002, 0x00000006, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
13412 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010100a,
13413 0x00000001, 0x05000036, 0x00102042, 0x00000000, 0x0010100a, 0x00000002, 0x05000036, 0x00102082,
13414 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
13416 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13418 {"ID", 0, DXGI_FORMAT_R32_UINT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
13420 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
13422 {0, "OUTPUT", 0, 0, 4, 0},
13424 static const unsigned int vertices[] =
13442 static const unsigned int indices[] =
13444 6, 7, 8,
13446 0, 1, 2,
13448 struct uvec4 expected_values[] =
13450 {0, 0, 0},
13451 {1, 0, 1},
13452 {2, 0, 2},
13453 {0, 1, 0},
13454 {1, 1, 1},
13455 {2, 1, 2},
13457 {3, 0, 0},
13458 {4, 0, 1},
13459 {5, 0, 2},
13461 {6, 0, 6},
13462 {7, 0, 7},
13463 {8, 0, 8},
13464 {6, 1, 6},
13465 {7, 1, 7},
13466 {8, 1, 8},
13468 {5, 0, 0},
13469 {6, 0, 1},
13470 {7, 0, 2},
13473 BOOL found_values[ARRAY_SIZE(expected_values)] = {0};
13474 BOOL used_values[ARRAY_SIZE(expected_values)] = {0};
13475 struct d3d11_test_context test_context;
13476 D3D11_QUERY_DATA_SO_STATISTICS data;
13477 ID3D11Buffer *vb, *ib, *so_buffer;
13478 ID3D11InputLayout *input_layout;
13479 ID3D11DeviceContext *context;
13480 D3D11_QUERY_DESC query_desc;
13481 struct resource_readback rb;
13482 unsigned int stride, offset;
13483 ID3D11Asynchronous *query;
13484 ID3D11GeometryShader *gs;
13485 ID3D11VertexShader *vs;
13486 ID3D11Device *device;
13487 unsigned int count;
13488 unsigned int i, j;
13489 HRESULT hr;
13491 if (!init_test_context(&test_context, NULL))
13492 return;
13493 device = test_context.device;
13494 context = test_context.immediate_context;
13496 query_desc.Query = D3D11_QUERY_SO_STATISTICS;
13497 query_desc.MiscFlags = 0;
13498 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
13499 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
13501 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13502 vs_code, sizeof(vs_code), &input_layout);
13503 ok(hr == S_OK, "Failed to create input layout, hr %#x.\n", hr);
13505 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13506 ok(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
13508 stride = 16;
13509 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
13510 so_declaration, ARRAY_SIZE(so_declaration), &stride, 1, 0, NULL, &gs);
13511 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
13513 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13514 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
13515 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
13517 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13518 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
13519 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13520 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
13521 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
13522 offset = 0;
13523 stride = sizeof(*vertices);
13524 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
13526 offset = 0;
13527 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
13529 ID3D11DeviceContext_Begin(context, query);
13531 ID3D11DeviceContext_DrawInstanced(context, 3, 2, 0, 0);
13532 ID3D11DeviceContext_DrawInstanced(context, 3, 1, 3, 16);
13534 ID3D11DeviceContext_DrawIndexedInstanced(context, 3, 2, 0, 0, 0);
13535 ID3D11DeviceContext_DrawIndexedInstanced(context, 3, 1, 3, 9, 7);
13537 ID3D11DeviceContext_End(context, query);
13539 get_query_data(context, query, &data, sizeof(data));
13540 count = data.NumPrimitivesWritten;
13541 ok(count == ARRAY_SIZE(expected_values), "Got unexpected value %u.\n", count);
13543 count = min(count, ARRAY_SIZE(used_values));
13544 get_buffer_readback(so_buffer, &rb);
13545 for (i = 0; i < ARRAY_SIZE(expected_values); ++i)
13547 for (j = 0; j < count; ++j)
13549 if (!used_values[j] && compare_uvec4(get_readback_uvec4(&rb, j, 0), &expected_values[i]))
13551 found_values[i] = TRUE;
13552 used_values[j] = TRUE;
13553 break;
13558 for (i = 0; i < count; ++i)
13560 const struct uvec4 *v = get_readback_uvec4(&rb, i, 0);
13561 ok(used_values[i], "Found unexpected value {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n", v->x, v->y, v->z, v->w);
13563 release_resource_readback(&rb);
13565 for (i = 0; i < ARRAY_SIZE(expected_values); ++i)
13567 ok(found_values[i], "Failed to find value {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n",
13568 expected_values[i].x, expected_values[i].y, expected_values[i].z, expected_values[i].w);
13571 ID3D11Asynchronous_Release(query);
13572 ID3D11Buffer_Release(so_buffer);
13573 ID3D11Buffer_Release(vb);
13574 ID3D11Buffer_Release(ib);
13575 ID3D11GeometryShader_Release(gs);
13576 ID3D11VertexShader_Release(vs);
13577 ID3D11InputLayout_Release(input_layout);
13578 release_test_context(&test_context);
13581 static void test_fragment_coords(void)
13583 struct d3d11_test_context test_context;
13584 ID3D11PixelShader *ps, *ps_frac;
13585 ID3D11DeviceContext *context;
13586 ID3D11Device *device;
13587 ID3D11Buffer *ps_cb;
13588 DWORD color;
13589 HRESULT hr;
13591 static const DWORD ps_code[] =
13593 #if 0
13594 float2 cutoff;
13596 float4 main(float4 position : SV_POSITION) : SV_TARGET
13598 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
13600 if (position.x > cutoff.x)
13601 ret.y = 1.0;
13602 if (position.y > cutoff.y)
13603 ret.z = 1.0;
13605 return ret;
13607 #endif
13608 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
13609 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13610 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13611 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13612 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
13613 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
13614 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
13615 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
13616 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
13617 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
13618 0x0100003e,
13620 static const DWORD ps_frac_code[] =
13622 #if 0
13623 float4 main(float4 position : SV_POSITION) : SV_TARGET
13625 return float4(frac(position.xy), 0.0, 1.0);
13627 #endif
13628 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
13629 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13630 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13631 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13632 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
13633 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13634 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
13635 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
13637 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13638 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
13640 if (!init_test_context(&test_context, NULL))
13641 return;
13643 device = test_context.device;
13644 context = test_context.immediate_context;
13646 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
13648 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13649 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13650 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
13651 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13653 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
13654 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13656 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13658 draw_quad(&test_context);
13660 color = get_texture_color(test_context.backbuffer, 319, 239);
13661 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
13662 color = get_texture_color(test_context.backbuffer, 320, 239);
13663 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13664 color = get_texture_color(test_context.backbuffer, 319, 240);
13665 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13666 color = get_texture_color(test_context.backbuffer, 320, 240);
13667 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
13669 ID3D11Buffer_Release(ps_cb);
13670 cutoff.x = 16.0f;
13671 cutoff.y = 16.0f;
13672 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
13673 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
13675 draw_quad(&test_context);
13677 color = get_texture_color(test_context.backbuffer, 14, 14);
13678 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
13679 color = get_texture_color(test_context.backbuffer, 18, 14);
13680 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13681 color = get_texture_color(test_context.backbuffer, 14, 18);
13682 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13683 color = get_texture_color(test_context.backbuffer, 18, 18);
13684 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
13686 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
13687 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13689 ID3D11DeviceContext_Draw(context, 4, 0);
13691 color = get_texture_color(test_context.backbuffer, 14, 14);
13692 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
13694 ID3D11Buffer_Release(ps_cb);
13695 ID3D11PixelShader_Release(ps_frac);
13696 ID3D11PixelShader_Release(ps);
13697 release_test_context(&test_context);
13700 static void test_initial_texture_data(void)
13702 ID3D11Texture2D *texture, *staging_texture;
13703 struct d3d11_test_context test_context;
13704 D3D11_SUBRESOURCE_DATA resource_data;
13705 D3D11_TEXTURE2D_DESC texture_desc;
13706 ID3D11SamplerState *sampler_state;
13707 ID3D11ShaderResourceView *ps_srv;
13708 D3D11_SAMPLER_DESC sampler_desc;
13709 ID3D11DeviceContext *context;
13710 struct resource_readback rb;
13711 ID3D11PixelShader *ps;
13712 ID3D11Device *device;
13713 unsigned int i, j;
13714 DWORD color;
13715 HRESULT hr;
13717 static const DWORD ps_code[] =
13719 #if 0
13720 Texture2D t;
13721 SamplerState s;
13723 float4 main(float4 position : SV_POSITION) : SV_Target
13725 float2 p;
13727 p.x = position.x / 640.0f;
13728 p.y = position.y / 480.0f;
13729 return t.Sample(s, p);
13731 #endif
13732 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13733 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13734 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13735 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13736 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13737 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13738 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13739 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13740 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13741 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13743 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13744 static const DWORD bitmap_data[] =
13746 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
13747 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
13748 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
13749 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
13752 if (!init_test_context(&test_context, NULL))
13753 return;
13755 device = test_context.device;
13756 context = test_context.immediate_context;
13758 texture_desc.Width = 4;
13759 texture_desc.Height = 4;
13760 texture_desc.MipLevels = 1;
13761 texture_desc.ArraySize = 1;
13762 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13763 texture_desc.SampleDesc.Count = 1;
13764 texture_desc.SampleDesc.Quality = 0;
13765 texture_desc.Usage = D3D11_USAGE_STAGING;
13766 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
13767 texture_desc.BindFlags = 0;
13768 texture_desc.MiscFlags = 0;
13770 resource_data.pSysMem = bitmap_data;
13771 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
13772 resource_data.SysMemSlicePitch = 0;
13774 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &staging_texture);
13775 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
13777 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13778 texture_desc.CPUAccessFlags = 0;
13779 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13780 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13781 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
13783 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)texture, (ID3D11Resource *)staging_texture);
13785 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
13786 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
13788 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
13789 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
13790 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
13791 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
13792 sampler_desc.MipLODBias = 0.0f;
13793 sampler_desc.MaxAnisotropy = 0;
13794 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
13795 sampler_desc.BorderColor[0] = 0.0f;
13796 sampler_desc.BorderColor[1] = 0.0f;
13797 sampler_desc.BorderColor[2] = 0.0f;
13798 sampler_desc.BorderColor[3] = 0.0f;
13799 sampler_desc.MinLOD = 0.0f;
13800 sampler_desc.MaxLOD = 0.0f;
13801 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
13802 ok(hr == S_OK, "Failed to create sampler state, hr %#x.\n", hr);
13804 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13805 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
13807 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
13808 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
13809 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13811 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13812 draw_quad(&test_context);
13813 get_texture_readback(test_context.backbuffer, 0, &rb);
13814 for (i = 0; i < 4; ++i)
13816 for (j = 0; j < 4; ++j)
13818 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13819 ok(compare_color(color, bitmap_data[j + i * 4], 1),
13820 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13821 color, j, i, bitmap_data[j + i * 4]);
13824 release_resource_readback(&rb);
13826 ID3D11PixelShader_Release(ps);
13827 ID3D11SamplerState_Release(sampler_state);
13828 ID3D11ShaderResourceView_Release(ps_srv);
13829 ID3D11Texture2D_Release(staging_texture);
13830 ID3D11Texture2D_Release(texture);
13831 release_test_context(&test_context);
13834 static void test_update_subresource(void)
13836 struct d3d11_test_context test_context;
13837 D3D11_SUBRESOURCE_DATA resource_data;
13838 D3D11_TEXTURE3D_DESC texture_desc_3d;
13839 D3D11_TEXTURE2D_DESC texture_desc;
13840 ID3D11SamplerState *sampler_state;
13841 ID3D11ShaderResourceView *ps_srv;
13842 D3D11_SAMPLER_DESC sampler_desc;
13843 ID3D11DeviceContext *context;
13844 struct resource_readback rb;
13845 ID3D11Texture3D *texture_3d;
13846 ID3D11Texture2D *texture;
13847 ID3D11PixelShader *ps;
13848 ID3D11Device *device;
13849 unsigned int i, j;
13850 D3D11_BOX box;
13851 DWORD color;
13852 HRESULT hr;
13854 static const DWORD ps_code[] =
13856 #if 0
13857 Texture2D t;
13858 SamplerState s;
13860 float4 main(float4 position : SV_POSITION) : SV_Target
13862 float2 p;
13864 p.x = position.x / 640.0f;
13865 p.y = position.y / 480.0f;
13866 return t.Sample(s, p);
13868 #endif
13869 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13870 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13871 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13872 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13873 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13874 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13875 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13876 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13877 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13878 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13880 static const DWORD ps_code_3d[] =
13882 #if 0
13883 Texture3D t;
13884 SamplerState s;
13886 float4 main(float4 position : SV_POSITION) : SV_Target
13888 float3 p1, p2;
13889 p2.x = p1.x = position.x / 640.0f;
13890 p2.y = p1.y = position.y / 480.0f;
13891 p1.z = 0.25;
13892 p2.z = 0.75;
13893 return 0.5 * (t.Sample(s, p1) + t.Sample(s, p2));
13895 #endif
13896 0x43425844, 0x4d466d63, 0xa3d10db1, 0xd6534470, 0x16d738ef, 0x00000001, 0x000001ec, 0x00000003,
13897 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13898 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13899 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13900 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000150, 0x00000040,
13901 0x00000054, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
13902 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13903 0x00000002, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13904 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3e800000,
13905 0x09000045, 0x001000f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
13906 0x00000000, 0x0a000038, 0x00100032, 0x00000001, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13907 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000001, 0x00004001, 0x3f400000,
13908 0x09000045, 0x001000f2, 0x00000001, 0x00100246, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
13909 0x00000000, 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
13910 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000,
13911 0x3f000000, 0x3f000000, 0x0100003e,
13913 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13914 static const DWORD initial_data[32] = {0};
13915 static const DWORD bitmap_data[] =
13917 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
13918 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
13919 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
13920 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
13922 static const DWORD expected_colors[] =
13924 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
13925 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
13926 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
13927 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
13929 static const DWORD bc7_data[] =
13931 0x3a7b944b, 0x982a5800, 0x9cab4983, 0xc6a09579,
13932 0x5f7f2bfe, 0xa95d98f2, 0x3bfb4c03, 0x8be16a41,
13933 0x8362e6c0, 0x358ed7a2, 0xec3e130b, 0x86cebc86,
13934 0xf045be66, 0x7a16507f, 0xfe9ccc9f, 0x3f103e16,
13935 0x84d466c5, 0xfaf5cb5a, 0x9b9e1859, 0x384589b0,
13936 0x9268b4b8, 0x212b3643, 0x813f853a, 0x4a2bd7c2,
13937 0x1809f3e0, 0xf646d5ef, 0x40e80679, 0x05791fe5,
13938 0x6604e7e5, 0x5c28b55d, 0x1ef211f5, 0x632d47f6,
13940 static const DWORD bc7_expected_colors[] =
13942 0xc1752752, 0xc39859a9, 0xff79c08e, 0xff63bf6c,
13943 0xbf7d2756, 0xb89f3d40, 0xffda3a77, 0xffd08099,
13944 0x415f1f37, 0x43671d3f, 0xffc64758, 0xff57a194,
13945 0x405a2032, 0x39422619, 0xff749b76, 0xffabb879,
13947 static const DWORD expected_colors_3d[] = { 0xffff8000, 0xffff8080, 0x80008000, 0xff8080ff };
13949 if (!init_test_context(&test_context, NULL))
13950 return;
13952 device = test_context.device;
13953 context = test_context.immediate_context;
13955 texture_desc.Width = 4;
13956 texture_desc.Height = 4;
13957 texture_desc.MipLevels = 1;
13958 texture_desc.ArraySize = 1;
13959 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13960 texture_desc.SampleDesc.Count = 1;
13961 texture_desc.SampleDesc.Quality = 0;
13962 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13963 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13964 texture_desc.CPUAccessFlags = 0;
13965 texture_desc.MiscFlags = 0;
13967 resource_data.pSysMem = initial_data;
13968 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
13969 resource_data.SysMemSlicePitch = 0;
13971 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
13972 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
13974 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
13975 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13977 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
13978 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
13979 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
13980 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
13981 sampler_desc.MipLODBias = 0.0f;
13982 sampler_desc.MaxAnisotropy = 0;
13983 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
13984 sampler_desc.BorderColor[0] = 0.0f;
13985 sampler_desc.BorderColor[1] = 0.0f;
13986 sampler_desc.BorderColor[2] = 0.0f;
13987 sampler_desc.BorderColor[3] = 0.0f;
13988 sampler_desc.MinLOD = 0.0f;
13989 sampler_desc.MaxLOD = 0.0f;
13991 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
13992 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
13994 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13995 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13997 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
13998 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
13999 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14001 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14002 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
14004 draw_quad(&test_context);
14005 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14007 set_box(&box, 1, 1, 0, 3, 3, 1);
14008 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
14009 bitmap_data, 4 * sizeof(*bitmap_data), 0);
14010 set_box(&box, 0, 3, 0, 3, 4, 1);
14011 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
14012 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
14013 set_box(&box, 0, 0, 0, 4, 1, 1);
14014 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
14015 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
14016 set_box(&box, 0, 1, 0, 1, 3, 1);
14017 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
14018 &bitmap_data[2], sizeof(*bitmap_data), 0);
14019 set_box(&box, 4, 4, 0, 3, 1, 1);
14020 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
14021 bitmap_data, sizeof(*bitmap_data), 0);
14022 set_box(&box, 0, 0, 0, 4, 4, 0);
14023 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
14024 bitmap_data, 4 * sizeof(*bitmap_data), 0);
14025 draw_quad(&test_context);
14026 get_texture_readback(test_context.backbuffer, 0, &rb);
14027 for (i = 0; i < 4; ++i)
14029 for (j = 0; j < 4; ++j)
14031 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14032 ok(compare_color(color, expected_colors[j + i * 4], 1),
14033 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14034 color, j, i, expected_colors[j + i * 4]);
14037 release_resource_readback(&rb);
14039 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
14040 bitmap_data, 4 * sizeof(*bitmap_data), 0);
14041 draw_quad(&test_context);
14042 get_texture_readback(test_context.backbuffer, 0, &rb);
14043 for (i = 0; i < 4; ++i)
14045 for (j = 0; j < 4; ++j)
14047 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14048 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14049 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14050 color, j, i, bitmap_data[j + i * 4]);
14053 release_resource_readback(&rb);
14055 ID3D11ShaderResourceView_Release(ps_srv);
14056 ID3D11Texture2D_Release(texture);
14057 ID3D11PixelShader_Release(ps);
14059 hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps);
14060 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14062 texture_desc_3d.Width = 2;
14063 texture_desc_3d.Height = 2;
14064 texture_desc_3d.Depth = 2;
14065 texture_desc_3d.MipLevels = 1;
14066 texture_desc_3d.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14067 texture_desc_3d.Usage = D3D11_USAGE_DEFAULT;
14068 texture_desc_3d.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14069 texture_desc_3d.CPUAccessFlags = 0;
14070 texture_desc_3d.MiscFlags = 0;
14072 resource_data.SysMemPitch = texture_desc_3d.Width * sizeof(*initial_data);
14073 resource_data.SysMemSlicePitch = texture_desc_3d.Width * texture_desc_3d.Height * sizeof(*initial_data);
14075 hr = ID3D11Device_CreateTexture3D(device, &texture_desc_3d, &resource_data, &texture_3d);
14076 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
14078 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture_3d, NULL, &ps_srv);
14079 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14081 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14082 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14084 set_box(&box, 0, 0, 0, 1, 2, 1);
14085 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data, 8, 16);
14086 set_box(&box, 0, 0, 0, 1, 1, 2);
14087 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 4, 16, 32);
14088 set_box(&box, 1, 0, 0, 2, 1, 2);
14089 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 8, 4, 0);
14090 set_box(&box, 0, 0, 1, 2, 1, 2);
14091 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 2, 4, 5);
14092 set_box(&box, 0, 0, 1, 2, 1, 2);
14093 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 3, 12, 0);
14094 set_box(&box, 1, 1, 0, 2, 2, 2);
14095 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data, 0, 32);
14097 draw_quad(&test_context);
14098 get_texture_readback(test_context.backbuffer, 0, &rb);
14099 for (i = 0; i < 2; ++i)
14101 for (j = 0; j < 2; ++j)
14103 color = get_readback_color(&rb, 160 + j * 320, 120 + i * 240, 0);
14104 ok(compare_color(color, expected_colors_3d[j + i * 2], 1),
14105 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14106 color, j, i, expected_colors_3d[j + i * 2]);
14109 release_resource_readback(&rb);
14110 ID3D11ShaderResourceView_Release(ps_srv);
14111 ID3D11Texture3D_Release(texture_3d);
14113 texture_desc_3d.Width = 8;
14114 texture_desc_3d.Height = 8;
14115 texture_desc_3d.Depth = 2;
14116 texture_desc_3d.Format = DXGI_FORMAT_BC7_UNORM;
14118 resource_data.SysMemPitch = 32;
14119 resource_data.SysMemSlicePitch = 64;
14121 hr = ID3D11Device_CreateTexture3D(device, &texture_desc_3d, &resource_data, &texture_3d);
14122 if (FAILED(hr))
14124 skip("Failed to create BC7 3d texture, hr %#x.\n", hr);
14126 else
14128 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture_3d, NULL, &ps_srv);
14129 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14131 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14132 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14134 set_box(&box, 0, 0, 0, 8, 8, 2);
14135 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data, 32, 64);
14136 set_box(&box, 0, 0, 1, 8, 8, 2);
14137 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data, 16, 0);
14138 set_box(&box, 0, 0, 0, 4, 4, 1);
14139 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 8, 0, 0);
14140 set_box(&box, 4, 4, 0, 8, 8, 2);
14141 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 16, 0, 16);
14142 set_box(&box, 0, 4, 1, 8, 8, 2);
14143 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 1, 4, 32);
14144 set_box(&box, 4, 0, 0, 8, 4, 2);
14145 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 2, 0, 1);
14147 draw_quad(&test_context);
14148 get_texture_readback(test_context.backbuffer, 0, &rb);
14149 for (i = 0; i < 4; ++i)
14151 for (j = 0; j < 4; ++j)
14153 color = get_readback_color(&rb, 70 + j * 160, 50 + i * 120, 0);
14154 ok(compare_color(color, bc7_expected_colors[j + i * 4], 1),
14155 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14156 color, j, i, bc7_expected_colors[j + i * 4]);
14159 release_resource_readback(&rb);
14160 ID3D11ShaderResourceView_Release(ps_srv);
14161 ID3D11Texture3D_Release(texture_3d);
14164 ID3D11PixelShader_Release(ps);
14165 ID3D11SamplerState_Release(sampler_state);
14166 release_test_context(&test_context);
14169 static void test_copy_subresource_region(void)
14171 ID3D11Texture2D *dst_texture, *src_texture;
14172 struct d3d11_test_context test_context;
14173 ID3D11Buffer *dst_buffer, *src_buffer;
14174 D3D11_SUBRESOURCE_DATA resource_data;
14175 D3D11_TEXTURE2D_DESC texture_desc;
14176 ID3D11SamplerState *sampler_state;
14177 ID3D11ShaderResourceView *ps_srv;
14178 D3D11_SAMPLER_DESC sampler_desc;
14179 ID3D11DeviceContext1 *context1;
14180 ID3D11DeviceContext *context;
14181 struct vec4 float_colors[16];
14182 struct resource_readback rb;
14183 ID3D11PixelShader *ps;
14184 ID3D11Device *device;
14185 unsigned int i, j;
14186 D3D11_BOX box;
14187 DWORD color;
14188 HRESULT hr;
14190 static const DWORD ps_code[] =
14192 #if 0
14193 Texture2D t;
14194 SamplerState s;
14196 float4 main(float4 position : SV_POSITION) : SV_Target
14198 float2 p;
14200 p.x = position.x / 640.0f;
14201 p.y = position.y / 480.0f;
14202 return t.Sample(s, p);
14204 #endif
14205 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
14206 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14207 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14208 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14209 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
14210 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
14211 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14212 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
14213 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
14214 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
14216 static const DWORD ps_buffer_code[] =
14218 #if 0
14219 float4 buffer[16];
14221 float4 main(float4 position : SV_POSITION) : SV_TARGET
14223 float2 p = (float2)4;
14224 p *= float2(position.x / 640.0f, position.y / 480.0f);
14225 return buffer[(int)p.y * 4 + (int)p.x];
14227 #endif
14228 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
14229 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14230 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14231 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14232 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
14233 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
14234 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
14235 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
14236 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
14237 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
14238 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
14239 0x0010000a, 0x00000000, 0x0100003e,
14241 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
14242 static const DWORD initial_data[16] = {0};
14243 static const DWORD bitmap_data[] =
14245 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14246 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14247 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14248 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14250 static const DWORD expected_colors[] =
14252 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14253 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
14254 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
14255 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
14258 if (!init_test_context(&test_context, NULL))
14259 return;
14261 device = test_context.device;
14262 context = test_context.immediate_context;
14264 texture_desc.Width = 4;
14265 texture_desc.Height = 4;
14266 texture_desc.MipLevels = 1;
14267 texture_desc.ArraySize = 1;
14268 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14269 texture_desc.SampleDesc.Count = 1;
14270 texture_desc.SampleDesc.Quality = 0;
14271 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14272 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14273 texture_desc.CPUAccessFlags = 0;
14274 texture_desc.MiscFlags = 0;
14276 resource_data.pSysMem = initial_data;
14277 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
14278 resource_data.SysMemSlicePitch = 0;
14280 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
14281 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14283 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
14285 resource_data.pSysMem = bitmap_data;
14286 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
14287 resource_data.SysMemSlicePitch = 0;
14289 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
14290 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14292 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
14293 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14295 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14296 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14297 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14298 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14299 sampler_desc.MipLODBias = 0.0f;
14300 sampler_desc.MaxAnisotropy = 0;
14301 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14302 sampler_desc.BorderColor[0] = 0.0f;
14303 sampler_desc.BorderColor[1] = 0.0f;
14304 sampler_desc.BorderColor[2] = 0.0f;
14305 sampler_desc.BorderColor[3] = 0.0f;
14306 sampler_desc.MinLOD = 0.0f;
14307 sampler_desc.MaxLOD = 0.0f;
14309 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
14310 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14312 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14313 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14315 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14316 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14317 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14319 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14321 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14322 1, 1, 0, NULL, 0, &box);
14323 ID3D11DeviceContext_CopySubresourceRegion(context, NULL, 0,
14324 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14326 set_box(&box, 0, 0, 0, 2, 2, 1);
14327 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14328 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14329 set_box(&box, 1, 2, 0, 4, 3, 1);
14330 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14331 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
14332 set_box(&box, 0, 3, 0, 4, 4, 1);
14333 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14334 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14335 set_box(&box, 3, 0, 0, 4, 2, 1);
14336 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14337 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14338 set_box(&box, 3, 1, 0, 4, 2, 1);
14339 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14340 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
14341 set_box(&box, 0, 0, 0, 4, 4, 0);
14342 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14343 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14344 draw_quad(&test_context);
14345 get_texture_readback(test_context.backbuffer, 0, &rb);
14346 for (i = 0; i < 4; ++i)
14348 for (j = 0; j < 4; ++j)
14350 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14351 ok(compare_color(color, expected_colors[j + i * 4], 1),
14352 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14353 color, j, i, expected_colors[j + i * 4]);
14356 release_resource_readback(&rb);
14358 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14359 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
14360 draw_quad(&test_context);
14361 get_texture_readback(test_context.backbuffer, 0, &rb);
14362 for (i = 0; i < 4; ++i)
14364 for (j = 0; j < 4; ++j)
14366 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14367 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14368 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14369 color, j, i, bitmap_data[j + i * 4]);
14372 release_resource_readback(&rb);
14374 hr = ID3D11DeviceContext_QueryInterface(context, &IID_ID3D11DeviceContext1, (void **)&context1);
14375 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
14376 "Failed to query ID3D11DeviceContext1, hr %#x.\n", hr);
14378 if (SUCCEEDED(hr))
14380 ID3D11DeviceContext1_ClearRenderTargetView(context1, test_context.backbuffer_rtv, red);
14381 check_texture_color(test_context.backbuffer, 0x800000ff, 2);
14383 memset(float_colors, 0, sizeof(float_colors));
14384 for (i = 0; i < texture_desc.Width; ++i)
14385 ((unsigned int *)float_colors)[i] = 0x45454545;
14387 ID3D11DeviceContext1_UpdateSubresource1(context1, (ID3D11Resource *)dst_texture, 0, NULL,
14388 float_colors, 0, 0, 0);
14389 draw_quad(&test_context);
14390 check_texture_color(test_context.backbuffer, 0x45454545, 1);
14392 ID3D11DeviceContext1_CopySubresourceRegion1(context1, (ID3D11Resource *)dst_texture, 0,
14393 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL, 0);
14394 draw_quad(&test_context);
14396 get_texture_readback(test_context.backbuffer, 0, &rb);
14397 for (i = 0; i < 4; ++i)
14399 for (j = 0; j < 4; ++j)
14401 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14402 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14403 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14404 color, j, i, bitmap_data[j + i * 4]);
14407 release_resource_readback(&rb);
14409 ID3D11DeviceContext1_Release(context1);
14413 ID3D11PixelShader_Release(ps);
14414 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
14415 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14417 ID3D11ShaderResourceView_Release(ps_srv);
14418 ps_srv = NULL;
14420 ID3D11SamplerState_Release(sampler_state);
14421 sampler_state = NULL;
14423 ID3D11Texture2D_Release(dst_texture);
14424 ID3D11Texture2D_Release(src_texture);
14426 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14427 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14428 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14430 memset(float_colors, 0, sizeof(float_colors));
14431 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
14432 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
14434 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
14436 for (i = 0; i < 4; ++i)
14438 for (j = 0; j < 4; ++j)
14440 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
14441 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
14442 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
14443 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
14446 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
14447 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
14449 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
14450 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14451 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14452 draw_quad(&test_context);
14453 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14455 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
14456 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14457 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14458 draw_quad(&test_context);
14459 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14461 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
14462 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14463 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14464 draw_quad(&test_context);
14465 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14467 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
14468 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14469 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14470 draw_quad(&test_context);
14471 get_texture_readback(test_context.backbuffer, 0, &rb);
14472 for (i = 0; i < 4; ++i)
14474 for (j = 0; j < 4; ++j)
14476 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14477 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14478 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14479 color, j, i, bitmap_data[j + i * 4]);
14482 release_resource_readback(&rb);
14484 ID3D11Buffer_Release(dst_buffer);
14485 ID3D11Buffer_Release(src_buffer);
14486 ID3D11PixelShader_Release(ps);
14487 release_test_context(&test_context);
14490 static void test_copy_subresource_region_1d(void)
14492 D3D11_SUBRESOURCE_DATA resource_data[4];
14493 struct d3d11_test_context test_context;
14494 D3D11_TEXTURE1D_DESC texture1d_desc;
14495 D3D11_TEXTURE2D_DESC texture2d_desc;
14496 ID3D11DeviceContext *context;
14497 struct resource_readback rb;
14498 ID3D11Texture1D *texture1d;
14499 ID3D11Texture2D *texture2d;
14500 ID3D11Device *device;
14501 unsigned int i, j;
14502 D3D11_BOX box;
14503 DWORD color;
14504 HRESULT hr;
14506 static const DWORD bitmap_data[] =
14508 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14509 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14510 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14511 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14514 if (!init_test_context(&test_context, NULL))
14515 return;
14516 device = test_context.device;
14517 context = test_context.immediate_context;
14519 texture1d_desc.Width = 4;
14520 texture1d_desc.MipLevels = 1;
14521 texture1d_desc.ArraySize = 4;
14522 texture1d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14523 texture1d_desc.Usage = D3D11_USAGE_DEFAULT;
14524 texture1d_desc.BindFlags = 0;
14525 texture1d_desc.CPUAccessFlags = 0;
14526 texture1d_desc.MiscFlags = 0;
14528 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14530 resource_data[i].pSysMem = &bitmap_data[4 * i];
14531 resource_data[i].SysMemPitch = texture1d_desc.Width * sizeof(bitmap_data);
14532 resource_data[i].SysMemSlicePitch = 0;
14535 hr = ID3D11Device_CreateTexture1D(device, &texture1d_desc, resource_data, &texture1d);
14536 ok(hr == S_OK, "Failed to create 1d texture, hr %#x.\n", hr);
14538 texture2d_desc.Width = 4;
14539 texture2d_desc.Height = 4;
14540 texture2d_desc.MipLevels = 1;
14541 texture2d_desc.ArraySize = 1;
14542 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14543 texture2d_desc.SampleDesc.Count = 1;
14544 texture2d_desc.SampleDesc.Quality = 0;
14545 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
14546 texture2d_desc.BindFlags = 0;
14547 texture2d_desc.CPUAccessFlags = 0;
14548 texture2d_desc.MiscFlags = 0;
14550 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14551 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
14553 set_box(&box, 0, 0, 0, 4, 1, 1);
14554 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14556 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2d, 0,
14557 0, i, 0, (ID3D11Resource *)texture1d, i, &box);
14560 get_texture_readback(texture2d, 0, &rb);
14561 for (i = 0; i < 4; ++i)
14563 for (j = 0; j < 4; ++j)
14565 color = get_readback_color(&rb, j, i, 0);
14566 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14567 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14568 color, j, i, bitmap_data[j + i * 4]);
14571 release_resource_readback(&rb);
14573 get_texture1d_readback(texture1d, 0, &rb);
14574 for (i = 0; i < texture1d_desc.Width; ++i)
14576 color = get_readback_color(&rb, i, 0, 0);
14577 ok(compare_color(color, bitmap_data[i], 1),
14578 "Got color 0x%08x at %u, expected 0x%08x.\n",
14579 color, i, bitmap_data[i]);
14581 release_resource_readback(&rb);
14583 ID3D11Texture1D_Release(texture1d);
14584 ID3D11Texture2D_Release(texture2d);
14585 release_test_context(&test_context);
14588 static void test_copy_subresource_region_3d(void)
14590 ID3D11ShaderResourceView *dst_srv, *src_srv;
14591 ID3D11Texture3D *dst_texture, *src_texture;
14592 D3D11_SUBRESOURCE_DATA resource_data[4];
14593 struct d3d11_test_context test_context;
14594 D3D11_TEXTURE2D_DESC texture2d_desc;
14595 D3D11_TEXTURE3D_DESC texture3d_desc;
14596 ID3D11SamplerState *sampler_state;
14597 D3D11_SAMPLER_DESC sampler_desc;
14598 ID3D11DeviceContext *context;
14599 struct resource_readback rb;
14600 ID3D11Texture2D *texture2d;
14601 ID3D11PixelShader *ps;
14602 ID3D11Device *device;
14603 unsigned int i, j;
14604 DWORD data[4][16];
14605 D3D11_BOX box;
14606 DWORD color;
14607 HRESULT hr;
14609 static const DWORD ps_code[] =
14611 #if 0
14612 Texture3D t;
14613 SamplerState s;
14615 float4 main(float4 position : SV_POSITION) : SV_Target
14617 return t.Sample(s, position.xyz / float3(640, 480, 1));
14619 #endif
14620 0x43425844, 0x27b15ae8, 0xbebf46f7, 0x6cd88d8d, 0x5118de51, 0x00000001, 0x00000134, 0x00000003,
14621 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14622 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000070f, 0x505f5653, 0x5449534f, 0x004e4f49,
14623 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14624 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
14625 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
14626 0x04002064, 0x00101072, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14627 0x00000001, 0x0a000038, 0x00100072, 0x00000000, 0x00101246, 0x00000000, 0x00004002, 0x3acccccd,
14628 0x3b088889, 0x3f800000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
14629 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
14631 static const DWORD bitmap_data[] =
14633 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14634 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14635 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14636 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14639 if (!init_test_context(&test_context, NULL))
14640 return;
14641 device = test_context.device;
14642 context = test_context.immediate_context;
14644 texture3d_desc.Width = 4;
14645 texture3d_desc.Height = 4;
14646 texture3d_desc.Depth = 4;
14647 texture3d_desc.MipLevels = 1;
14648 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14649 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
14650 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14651 texture3d_desc.CPUAccessFlags = 0;
14652 texture3d_desc.MiscFlags = 0;
14654 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &src_texture);
14655 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
14656 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &dst_texture);
14657 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
14659 texture2d_desc.Width = 4;
14660 texture2d_desc.Height = 4;
14661 texture2d_desc.MipLevels = 1;
14662 texture2d_desc.ArraySize = 4;
14663 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14664 texture2d_desc.SampleDesc.Count = 1;
14665 texture2d_desc.SampleDesc.Quality = 0;
14666 texture2d_desc.Usage = D3D11_USAGE_IMMUTABLE;
14667 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14668 texture2d_desc.CPUAccessFlags = 0;
14669 texture2d_desc.MiscFlags = 0;
14671 for (i = 0; i < ARRAY_SIZE(*data); ++i)
14673 data[0][i] = 0xff0000ff;
14674 data[1][i] = bitmap_data[i];
14675 data[2][i] = 0xff00ff00;
14676 data[3][i] = 0xffff00ff;
14679 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14681 resource_data[i].pSysMem = data[i];
14682 resource_data[i].SysMemPitch = texture2d_desc.Width * sizeof(data[0][0]);
14683 resource_data[i].SysMemSlicePitch = 0;
14686 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, resource_data, &texture2d);
14687 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
14689 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)src_texture, NULL, &src_srv);
14690 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
14691 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &dst_srv);
14692 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
14694 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14695 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14696 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14697 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14698 sampler_desc.MipLODBias = 0.0f;
14699 sampler_desc.MaxAnisotropy = 0;
14700 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14701 sampler_desc.BorderColor[0] = 0.0f;
14702 sampler_desc.BorderColor[1] = 0.0f;
14703 sampler_desc.BorderColor[2] = 0.0f;
14704 sampler_desc.BorderColor[3] = 0.0f;
14705 sampler_desc.MinLOD = 0.0f;
14706 sampler_desc.MaxLOD = 0.0f;
14708 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
14709 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14711 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14712 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
14714 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &src_srv);
14715 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14716 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14718 set_box(&box, 0, 0, 0, 4, 4, 1);
14719 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14721 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
14722 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
14724 draw_quad(&test_context);
14725 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14726 draw_quad_z(&test_context, 0.25f);
14727 get_texture_readback(test_context.backbuffer, 0, &rb);
14728 for (i = 0; i < 4; ++i)
14730 for (j = 0; j < 4; ++j)
14732 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14733 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14734 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14735 color, j, i, bitmap_data[j + i * 4]);
14738 release_resource_readback(&rb);
14739 draw_quad_z(&test_context, 0.5f);
14740 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14741 draw_quad_z(&test_context, 1.0f);
14742 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
14744 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &dst_srv);
14746 set_box(&box, 0, 0, 0, 4, 4, 2);
14747 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14748 0, 0, 2, (ID3D11Resource *)src_texture, 0, &box);
14749 set_box(&box, 0, 0, 2, 4, 4, 4);
14750 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14751 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14753 set_box(&box, 0, 0, 0, 4, 4, 1);
14754 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14756 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
14757 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
14759 draw_quad(&test_context);
14760 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14761 draw_quad_z(&test_context, 0.25f);
14762 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
14763 draw_quad_z(&test_context, 0.5f);
14764 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14765 draw_quad_z(&test_context, 1.0f);
14766 get_texture_readback(test_context.backbuffer, 0, &rb);
14767 for (i = 0; i < 4; ++i)
14769 for (j = 0; j < 4; ++j)
14771 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14772 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14773 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14774 color, j, i, bitmap_data[j + i * 4]);
14777 release_resource_readback(&rb);
14779 ID3D11PixelShader_Release(ps);
14780 ID3D11SamplerState_Release(sampler_state);
14781 ID3D11ShaderResourceView_Release(dst_srv);
14782 ID3D11ShaderResourceView_Release(src_srv);
14783 ID3D11Texture2D_Release(texture2d);
14784 ID3D11Texture3D_Release(dst_texture);
14785 ID3D11Texture3D_Release(src_texture);
14786 release_test_context(&test_context);
14789 static void test_resource_map(void)
14791 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
14792 D3D11_TEXTURE3D_DESC texture3d_desc;
14793 D3D11_TEXTURE2D_DESC texture2d_desc;
14794 D3D11_BUFFER_DESC buffer_desc;
14795 ID3D11DeviceContext *context;
14796 ID3D11Texture3D *texture3d;
14797 ID3D11Texture2D *texture2d;
14798 ID3D11Buffer *buffer;
14799 ID3D11Device *device;
14800 ULONG refcount;
14801 HRESULT hr;
14802 DWORD data;
14804 if (!(device = create_device(NULL)))
14806 skip("Failed to create device.\n");
14807 return;
14810 ID3D11Device_GetImmediateContext(device, &context);
14812 buffer_desc.ByteWidth = 1024;
14813 buffer_desc.Usage = D3D11_USAGE_STAGING;
14814 buffer_desc.BindFlags = 0;
14815 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14816 buffer_desc.MiscFlags = 0;
14817 buffer_desc.StructureByteStride = 0;
14819 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14820 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14822 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14823 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14825 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14826 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14827 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
14828 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14829 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
14830 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14831 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
14833 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14834 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14835 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
14836 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14837 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
14838 data = *((DWORD *)mapped_subresource.pData);
14839 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14840 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
14842 refcount = ID3D11Buffer_Release(buffer);
14843 ok(!refcount, "Buffer has %u references left.\n", refcount);
14845 texture2d_desc.Width = 512;
14846 texture2d_desc.Height = 512;
14847 texture2d_desc.MipLevels = 1;
14848 texture2d_desc.ArraySize = 1;
14849 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14850 texture2d_desc.SampleDesc.Count = 1;
14851 texture2d_desc.SampleDesc.Quality = 0;
14852 texture2d_desc.Usage = D3D11_USAGE_STAGING;
14853 texture2d_desc.BindFlags = 0;
14854 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14855 texture2d_desc.MiscFlags = 0;
14857 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14858 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14860 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14861 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14863 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14864 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14865 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14866 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14867 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
14868 mapped_subresource.DepthPitch);
14869 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14870 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
14872 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14873 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14874 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14875 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14876 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
14877 mapped_subresource.DepthPitch);
14878 data = *((DWORD *)mapped_subresource.pData);
14879 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14880 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
14882 refcount = ID3D11Texture2D_Release(texture2d);
14883 ok(!refcount, "2D texture has %u references left.\n", refcount);
14885 texture3d_desc.Width = 64;
14886 texture3d_desc.Height = 64;
14887 texture3d_desc.Depth = 64;
14888 texture3d_desc.MipLevels = 1;
14889 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14890 texture3d_desc.Usage = D3D11_USAGE_STAGING;
14891 texture3d_desc.BindFlags = 0;
14892 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14893 texture3d_desc.MiscFlags = 0;
14895 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14896 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
14898 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14899 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14901 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14902 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14903 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14904 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14905 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
14906 mapped_subresource.DepthPitch);
14907 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14908 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
14910 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14911 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14912 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14913 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14914 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
14915 mapped_subresource.DepthPitch);
14916 data = *((DWORD *)mapped_subresource.pData);
14917 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14918 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
14920 refcount = ID3D11Texture3D_Release(texture3d);
14921 ok(!refcount, "3D texture has %u references left.\n", refcount);
14923 ID3D11DeviceContext_Release(context);
14925 refcount = ID3D11Device_Release(device);
14926 ok(!refcount, "Device has %u references left.\n", refcount);
14929 #define check_resource_cpu_access(a, b, c, d, e) check_resource_cpu_access_(__LINE__, a, b, c, d, e)
14930 static void check_resource_cpu_access_(unsigned int line, ID3D11DeviceContext *context,
14931 ID3D11Resource *resource, D3D11_USAGE usage, UINT bind_flags, UINT cpu_access)
14933 BOOL cpu_write = cpu_access & D3D11_CPU_ACCESS_WRITE;
14934 BOOL cpu_read = cpu_access & D3D11_CPU_ACCESS_READ;
14935 BOOL dynamic = usage == D3D11_USAGE_DYNAMIC;
14936 D3D11_MAPPED_SUBRESOURCE map_desc;
14937 HRESULT hr, expected_hr;
14938 ID3D11Device *device;
14940 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
14941 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ, 0, &map_desc);
14942 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
14943 if (SUCCEEDED(hr))
14944 ID3D11DeviceContext_Unmap(context, resource, 0);
14946 /* WRITE_DISCARD and WRITE_NO_OVERWRITE are the only allowed options for dynamic resources. */
14947 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
14948 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE, 0, &map_desc);
14949 todo_wine_if(dynamic && cpu_write)
14950 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
14951 if (SUCCEEDED(hr))
14952 ID3D11DeviceContext_Unmap(context, resource, 0);
14954 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
14955 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
14956 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
14957 if (SUCCEEDED(hr))
14958 ID3D11DeviceContext_Unmap(context, resource, 0);
14960 expected_hr = dynamic ? S_OK : E_INVALIDARG;
14961 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
14962 todo_wine_if(!dynamic && cpu_write)
14963 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
14964 if (SUCCEEDED(hr))
14965 ID3D11DeviceContext_Unmap(context, resource, 0);
14967 if (!dynamic)
14968 return;
14970 ID3D11DeviceContext_GetDevice(context, &device);
14972 /* WRITE_NO_OVERWRITE is supported only for buffers. */
14973 expected_hr = is_buffer(resource) ? S_OK : E_INVALIDARG;
14974 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
14975 /* D3D11.1 is required for constant and shader buffers. */
14976 todo_wine_if(expected_hr != S_OK)
14977 ok_(__FILE__, line)(hr == expected_hr
14978 || broken(bind_flags & (D3D11_BIND_CONSTANT_BUFFER | D3D11_BIND_SHADER_RESOURCE)),
14979 "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
14980 if (SUCCEEDED(hr))
14981 ID3D11DeviceContext_Unmap(context, resource, 0);
14983 ID3D11Device_Release(device);
14986 static void test_resource_access(const D3D_FEATURE_LEVEL feature_level)
14988 D3D11_TEXTURE2D_DESC texture_desc;
14989 struct device_desc device_desc;
14990 D3D11_BUFFER_DESC buffer_desc;
14991 ID3D11DeviceContext *context;
14992 D3D11_SUBRESOURCE_DATA data;
14993 ID3D11Resource *resource;
14994 BOOL required_cpu_access;
14995 BOOL cpu_write, cpu_read;
14996 HRESULT hr, expected_hr;
14997 UINT allowed_cpu_access;
14998 BOOL broken_validation;
14999 ID3D11Device *device;
15000 unsigned int i;
15001 ULONG refcount;
15003 static const struct
15005 D3D11_USAGE usage;
15006 UINT bind_flags;
15007 BOOL is_valid;
15008 UINT allowed_cpu_access;
15010 tests[] =
15012 /* Default resources cannot be written by CPU. */
15013 {D3D11_USAGE_DEFAULT, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
15014 {D3D11_USAGE_DEFAULT, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
15015 {D3D11_USAGE_DEFAULT, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
15016 {D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
15017 {D3D11_USAGE_DEFAULT, D3D11_BIND_STREAM_OUTPUT, TRUE, 0},
15018 {D3D11_USAGE_DEFAULT, D3D11_BIND_RENDER_TARGET, TRUE, 0},
15019 {D3D11_USAGE_DEFAULT, D3D11_BIND_DEPTH_STENCIL, TRUE, 0},
15020 {D3D11_USAGE_DEFAULT, D3D11_BIND_UNORDERED_ACCESS, TRUE, 0},
15022 /* Immutable resources cannot be written by CPU and GPU. */
15023 {D3D11_USAGE_IMMUTABLE, 0, FALSE, 0},
15024 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
15025 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
15026 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
15027 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
15028 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
15029 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_RENDER_TARGET, FALSE, 0},
15030 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
15031 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
15033 /* Dynamic resources cannot be written by GPU. */
15034 {D3D11_USAGE_DYNAMIC, 0, FALSE, D3D11_CPU_ACCESS_WRITE},
15035 {D3D11_USAGE_DYNAMIC, D3D11_BIND_VERTEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
15036 {D3D11_USAGE_DYNAMIC, D3D11_BIND_INDEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
15037 {D3D11_USAGE_DYNAMIC, D3D11_BIND_CONSTANT_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
15038 {D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE, TRUE, D3D11_CPU_ACCESS_WRITE},
15039 {D3D11_USAGE_DYNAMIC, D3D11_BIND_STREAM_OUTPUT, FALSE, D3D11_CPU_ACCESS_WRITE},
15040 {D3D11_USAGE_DYNAMIC, D3D11_BIND_RENDER_TARGET, FALSE, D3D11_CPU_ACCESS_WRITE},
15041 {D3D11_USAGE_DYNAMIC, D3D11_BIND_DEPTH_STENCIL, FALSE, D3D11_CPU_ACCESS_WRITE},
15042 {D3D11_USAGE_DYNAMIC, D3D11_BIND_UNORDERED_ACCESS, FALSE, D3D11_CPU_ACCESS_WRITE},
15044 /* Staging resources support only data transfer. */
15045 {D3D11_USAGE_STAGING, 0, TRUE, D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ},
15046 {D3D11_USAGE_STAGING, D3D11_BIND_VERTEX_BUFFER, FALSE, 0},
15047 {D3D11_USAGE_STAGING, D3D11_BIND_INDEX_BUFFER, FALSE, 0},
15048 {D3D11_USAGE_STAGING, D3D11_BIND_CONSTANT_BUFFER, FALSE, 0},
15049 {D3D11_USAGE_STAGING, D3D11_BIND_SHADER_RESOURCE, FALSE, 0},
15050 {D3D11_USAGE_STAGING, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
15051 {D3D11_USAGE_STAGING, D3D11_BIND_RENDER_TARGET, FALSE, 0},
15052 {D3D11_USAGE_STAGING, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
15053 {D3D11_USAGE_STAGING, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
15056 device_desc.feature_level = &feature_level;
15057 device_desc.flags = 0;
15058 if (!(device = create_device(&device_desc)))
15060 skip("Failed to create device for feature level %#x.\n", feature_level);
15061 return;
15063 ID3D11Device_GetImmediateContext(device, &context);
15065 data.SysMemPitch = 0;
15066 data.SysMemSlicePitch = 0;
15067 data.pSysMem = heap_alloc(10240);
15068 ok(!!data.pSysMem, "Failed to allocate memory.\n");
15070 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15072 switch (tests[i].bind_flags)
15074 case D3D11_BIND_DEPTH_STENCIL:
15075 continue;
15077 case D3D11_BIND_SHADER_RESOURCE:
15078 case D3D11_BIND_STREAM_OUTPUT:
15079 case D3D11_BIND_RENDER_TARGET:
15080 if (feature_level < D3D_FEATURE_LEVEL_10_0)
15081 continue;
15082 break;
15084 case D3D11_BIND_UNORDERED_ACCESS:
15085 if (feature_level < D3D_FEATURE_LEVEL_11_0)
15086 continue;
15087 break;
15089 default:
15090 break;
15093 allowed_cpu_access = tests[i].allowed_cpu_access;
15094 if (feature_level >= D3D_FEATURE_LEVEL_11_0 && is_d3d11_2_runtime(device)
15095 && tests[i].usage == D3D11_USAGE_DEFAULT
15096 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
15097 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS))
15098 allowed_cpu_access |= D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
15100 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
15101 cpu_write = allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
15102 cpu_read = allowed_cpu_access & D3D11_CPU_ACCESS_READ;
15104 buffer_desc.ByteWidth = 1024;
15105 buffer_desc.Usage = tests[i].usage;
15106 buffer_desc.BindFlags = tests[i].bind_flags;
15107 buffer_desc.MiscFlags = 0;
15108 buffer_desc.StructureByteStride = 0;
15110 buffer_desc.CPUAccessFlags = 0;
15111 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
15112 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15113 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15114 if (SUCCEEDED(hr))
15116 check_resource_cpu_access(context, resource,
15117 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15118 ID3D11Resource_Release(resource);
15121 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
15122 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
15123 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15124 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15125 if (SUCCEEDED(hr))
15127 check_resource_cpu_access(context, resource,
15128 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15129 ID3D11Resource_Release(resource);
15132 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
15133 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
15134 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15135 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15136 if (SUCCEEDED(hr))
15138 check_resource_cpu_access(context, resource,
15139 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15140 ID3D11Resource_Release(resource);
15143 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
15144 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
15145 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15146 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15147 if (SUCCEEDED(hr))
15149 check_resource_cpu_access(context, resource,
15150 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15151 ID3D11Resource_Release(resource);
15155 data.SysMemPitch = 16;
15157 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15159 switch (tests[i].bind_flags)
15161 case D3D11_BIND_VERTEX_BUFFER:
15162 case D3D11_BIND_INDEX_BUFFER:
15163 case D3D11_BIND_CONSTANT_BUFFER:
15164 case D3D11_BIND_STREAM_OUTPUT:
15165 continue;
15167 case D3D11_BIND_UNORDERED_ACCESS:
15168 if (feature_level < D3D_FEATURE_LEVEL_11_0)
15169 continue;
15170 break;
15172 default:
15173 break;
15176 broken_validation = tests[i].usage == D3D11_USAGE_DEFAULT
15177 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
15178 || tests[i].bind_flags == D3D11_BIND_RENDER_TARGET
15179 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS);
15181 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
15182 cpu_write = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
15183 cpu_read = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_READ;
15185 texture_desc.Width = 4;
15186 texture_desc.Height = 4;
15187 texture_desc.MipLevels = 1;
15188 texture_desc.ArraySize = 1;
15189 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15190 texture_desc.SampleDesc.Count = 1;
15191 texture_desc.SampleDesc.Quality = 0;
15192 texture_desc.Usage = tests[i].usage;
15193 texture_desc.BindFlags = tests[i].bind_flags;
15194 texture_desc.MiscFlags = 0;
15195 if (tests[i].bind_flags == D3D11_BIND_DEPTH_STENCIL)
15196 texture_desc.Format = DXGI_FORMAT_D16_UNORM;
15198 texture_desc.CPUAccessFlags = 0;
15199 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
15200 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15201 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15202 if (SUCCEEDED(hr))
15204 check_resource_cpu_access(context, resource,
15205 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15206 ID3D11Resource_Release(resource);
15209 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
15210 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
15211 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15212 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15213 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15214 if (SUCCEEDED(hr))
15216 if (broken_validation)
15217 texture_desc.CPUAccessFlags = 0;
15218 check_resource_cpu_access(context, resource,
15219 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15220 ID3D11Resource_Release(resource);
15223 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
15224 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
15225 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15226 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15227 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15228 if (SUCCEEDED(hr))
15230 if (broken_validation)
15231 texture_desc.CPUAccessFlags = 0;
15232 check_resource_cpu_access(context, resource,
15233 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15234 ID3D11Resource_Release(resource);
15237 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
15238 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
15239 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15240 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15241 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15242 if (SUCCEEDED(hr))
15244 if (broken_validation)
15245 texture_desc.CPUAccessFlags = 0;
15246 check_resource_cpu_access(context, resource,
15247 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15248 ID3D11Resource_Release(resource);
15252 heap_free((void *)data.pSysMem);
15254 ID3D11DeviceContext_Release(context);
15255 refcount = ID3D11Device_Release(device);
15256 ok(!refcount, "Device has %u references left.\n", refcount);
15259 static void test_check_multisample_quality_levels(void)
15261 ID3D11Device *device;
15262 UINT quality_levels;
15263 ULONG refcount;
15264 HRESULT hr;
15266 if (!(device = create_device(NULL)))
15268 skip("Failed to create device.\n");
15269 return;
15272 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
15273 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
15274 if (!quality_levels)
15276 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
15277 goto done;
15280 quality_levels = 0xdeadbeef;
15281 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
15282 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15283 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15284 quality_levels = 0xdeadbeef;
15285 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
15286 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15287 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
15289 if (!enable_debug_layer)
15291 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
15292 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15293 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
15294 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15295 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
15296 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15299 quality_levels = 0xdeadbeef;
15300 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
15301 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15302 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15304 quality_levels = 0xdeadbeef;
15305 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
15306 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15307 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
15309 quality_levels = 0xdeadbeef;
15310 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
15311 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15312 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15314 /* We assume 15 samples multisampling is never supported in practice. */
15315 quality_levels = 0xdeadbeef;
15316 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
15317 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15318 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15319 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
15320 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15321 quality_levels = 0xdeadbeef;
15322 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
15323 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15324 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15325 quality_levels = 0xdeadbeef;
15326 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
15327 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15328 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15330 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
15331 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15332 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15334 done:
15335 refcount = ID3D11Device_Release(device);
15336 ok(!refcount, "Device has %u references left.\n", refcount);
15339 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
15341 DXGI_SWAP_CHAIN_DESC swapchain_desc;
15342 struct device_desc device_desc;
15343 IDXGISwapChain *swapchain;
15344 IDXGIDevice *dxgi_device;
15345 HRESULT hr, expected_hr;
15346 IDXGIAdapter *adapter;
15347 IDXGIFactory *factory;
15348 ID3D11Device *device;
15349 unsigned int i;
15350 ULONG refcount;
15352 swapchain_desc.BufferDesc.Width = 800;
15353 swapchain_desc.BufferDesc.Height = 600;
15354 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
15355 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
15356 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
15357 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
15358 swapchain_desc.SampleDesc.Count = 1;
15359 swapchain_desc.SampleDesc.Quality = 0;
15360 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
15361 swapchain_desc.BufferCount = 1;
15362 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
15363 swapchain_desc.Windowed = TRUE;
15364 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
15365 swapchain_desc.Flags = 0;
15367 device_desc.feature_level = &feature_level;
15368 device_desc.flags = 0;
15369 if (!(device = create_device(&device_desc)))
15371 skip("Failed to create device for feature level %#x.\n", feature_level);
15372 return;
15375 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
15376 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
15377 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
15378 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
15379 IDXGIDevice_Release(dxgi_device);
15380 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
15381 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
15382 IDXGIAdapter_Release(adapter);
15384 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15385 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
15386 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
15387 hr, feature_level);
15388 if (SUCCEEDED(hr))
15389 IDXGISwapChain_Release(swapchain);
15391 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
15393 DXGI_FORMAT format = display_format_support[i].format;
15394 BOOL todo = FALSE;
15396 if (display_format_support[i].fl_required <= feature_level)
15398 expected_hr = S_OK;
15399 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
15400 todo = TRUE;
15402 else if (!display_format_support[i].fl_optional
15403 || display_format_support[i].fl_optional > feature_level)
15405 expected_hr = E_INVALIDARG;
15406 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
15407 todo = TRUE;
15409 else
15411 continue;
15414 swapchain_desc.BufferDesc.Format = format;
15415 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
15416 todo_wine_if(todo)
15417 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
15418 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
15419 hr, expected_hr, feature_level, format);
15420 if (FAILED(hr))
15421 continue;
15422 refcount = IDXGISwapChain_Release(swapchain);
15423 ok(!refcount, "Swapchain has %u references left.\n", refcount);
15426 refcount = ID3D11Device_Release(device);
15427 ok(!refcount, "Device has %u references left.\n", refcount);
15428 refcount = IDXGIFactory_Release(factory);
15429 ok(!refcount, "Factory has %u references left.\n", refcount);
15430 DestroyWindow(swapchain_desc.OutputWindow);
15433 static void test_swapchain_views(void)
15435 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
15436 struct d3d11_test_context test_context;
15437 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15438 ID3D11ShaderResourceView *srv;
15439 ID3D11DeviceContext *context;
15440 ID3D11RenderTargetView *rtv;
15441 ID3D11Device *device;
15442 ULONG refcount;
15443 HRESULT hr;
15445 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
15447 if (!init_test_context(&test_context, NULL))
15448 return;
15450 device = test_context.device;
15451 context = test_context.immediate_context;
15453 refcount = get_refcount(test_context.backbuffer);
15454 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
15456 draw_color_quad(&test_context, &color);
15457 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
15459 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15460 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15461 U(rtv_desc).Texture2D.MipSlice = 0;
15462 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
15463 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15464 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15466 refcount = get_refcount(test_context.backbuffer);
15467 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
15469 draw_color_quad(&test_context, &color);
15470 check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
15472 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15473 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
15474 U(srv_desc).Texture2D.MostDetailedMip = 0;
15475 U(srv_desc).Texture2D.MipLevels = 1;
15476 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
15477 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15478 if (SUCCEEDED(hr))
15479 ID3D11ShaderResourceView_Release(srv);
15481 ID3D11RenderTargetView_Release(rtv);
15482 release_test_context(&test_context);
15485 static void test_swapchain_flip(void)
15487 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
15488 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
15489 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
15490 D3D11_TEXTURE2D_DESC texture_desc;
15491 ID3D11InputLayout *input_layout;
15492 ID3D11DeviceContext *context;
15493 unsigned int stride, offset;
15494 struct swapchain_desc desc;
15495 IDXGISwapChain *swapchain;
15496 ID3D11VertexShader *vs;
15497 ID3D11PixelShader *ps;
15498 ID3D11Device *device;
15499 ID3D11Buffer *vb;
15500 ULONG refcount;
15501 DWORD color;
15502 HWND window;
15503 HRESULT hr;
15504 RECT rect;
15506 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15508 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15510 static const DWORD vs_code[] =
15512 #if 0
15513 float4 main(float4 position : POSITION) : SV_POSITION
15515 return position;
15517 #endif
15518 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
15519 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15520 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
15521 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
15522 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
15523 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15524 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
15527 static const DWORD ps_code[] =
15529 #if 0
15530 Texture2D t0, t1;
15531 SamplerState s;
15533 float4 main(float4 position : SV_POSITION) : SV_Target
15535 float2 p;
15537 p.x = 0.5;
15538 p.y = 0.5;
15539 if (position.x < 320)
15540 return t0.Sample(s, p);
15541 return t1.Sample(s, p);
15543 #endif
15544 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
15545 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15546 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
15547 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15548 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
15549 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
15550 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
15551 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
15552 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
15553 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
15554 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
15555 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
15556 0x00000000, 0x0100003e,
15558 static const struct vec2 quad[] =
15560 {-1.0f, -1.0f},
15561 {-1.0f, 1.0f},
15562 { 1.0f, -1.0f},
15563 { 1.0f, 1.0f},
15565 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
15566 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15567 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
15569 if (!(device = create_device(NULL)))
15571 skip("Failed to create device, skipping tests.\n");
15572 return;
15574 SetRect(&rect, 0, 0, 640, 480);
15575 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
15576 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
15577 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
15578 desc.buffer_count = 3;
15579 desc.width = desc.height = 0;
15580 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
15581 desc.windowed = TRUE;
15582 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
15583 swapchain = create_swapchain(device, window, &desc);
15585 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
15586 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15587 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
15588 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15589 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
15590 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15592 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
15593 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15594 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
15595 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15596 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
15597 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15599 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
15600 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
15601 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
15602 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
15603 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
15605 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
15606 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
15607 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
15608 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
15609 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
15611 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
15612 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15613 if (SUCCEEDED(hr))
15614 ID3D11RenderTargetView_Release(offscreen_rtv);
15616 ID3D11Device_GetImmediateContext(device, &context);
15618 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
15619 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
15621 texture_desc.Width = 640;
15622 texture_desc.Height = 480;
15623 texture_desc.MipLevels = 1;
15624 texture_desc.ArraySize = 1;
15625 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15626 texture_desc.SampleDesc.Count = 1;
15627 texture_desc.SampleDesc.Quality = 0;
15628 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15629 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15630 texture_desc.CPUAccessFlags = 0;
15631 texture_desc.MiscFlags = 0;
15632 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
15633 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
15634 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
15635 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15636 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
15637 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
15639 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
15641 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15642 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15643 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15644 vs_code, sizeof(vs_code), &input_layout);
15645 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15646 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15647 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
15648 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15649 stride = sizeof(*quad);
15650 offset = 0;
15651 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15653 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15654 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15655 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15657 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
15659 ID3D11DeviceContext_Draw(context, 4, 0);
15660 color = get_texture_color(offscreen, 120, 240);
15661 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15663 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
15664 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
15665 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
15667 * What is this good for? I don't know. Ad-hoc tests suggest that
15668 * Present() always waits for the next V-sync interval, even if there are
15669 * still untouched buffers. Buffer 0 is the buffer that is shown on the
15670 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
15671 * rendering finishes before the V-sync interval is over. I haven't found
15672 * any productive use for more than one buffer. */
15673 IDXGISwapChain_Present(swapchain, 0, 0);
15675 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
15677 ID3D11DeviceContext_Draw(context, 4, 0);
15678 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
15679 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15680 /* Buffer 1 is still untouched. */
15682 color = get_texture_color(backbuffer_0, 320, 240); /* green */
15683 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15684 color = get_texture_color(backbuffer_2, 320, 240); /* red */
15685 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15687 IDXGISwapChain_Present(swapchain, 0, 0);
15689 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
15691 ID3D11DeviceContext_Draw(context, 4, 0);
15692 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
15693 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
15694 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
15695 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15697 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
15698 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
15699 color = get_texture_color(backbuffer_1, 320, 240); /* red */
15700 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15701 color = get_texture_color(backbuffer_2, 320, 240); /* green */
15702 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15704 ID3D11VertexShader_Release(vs);
15705 ID3D11PixelShader_Release(ps);
15706 ID3D11Buffer_Release(vb);
15707 ID3D11InputLayout_Release(input_layout);
15708 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
15709 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
15710 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
15711 ID3D11RenderTargetView_Release(offscreen_rtv);
15712 ID3D11Texture2D_Release(offscreen);
15713 ID3D11Texture2D_Release(backbuffer_0);
15714 ID3D11Texture2D_Release(backbuffer_1);
15715 ID3D11Texture2D_Release(backbuffer_2);
15716 IDXGISwapChain_Release(swapchain);
15718 ID3D11DeviceContext_Release(context);
15719 refcount = ID3D11Device_Release(device);
15720 ok(!refcount, "Device has %u references left.\n", refcount);
15721 DestroyWindow(window);
15724 static void test_clear_render_target_view_1d(void)
15726 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
15727 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15729 struct d3d11_test_context test_context;
15730 D3D11_TEXTURE1D_DESC texture_desc;
15731 ID3D11DeviceContext *context;
15732 ID3D11RenderTargetView *rtv;
15733 ID3D11Texture1D *texture;
15734 ID3D11Device *device;
15735 HRESULT hr;
15737 if (!init_test_context(&test_context, NULL))
15738 return;
15740 device = test_context.device;
15741 context = test_context.immediate_context;
15743 texture_desc.Width = 64;
15744 texture_desc.MipLevels = 1;
15745 texture_desc.ArraySize = 1;
15746 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15747 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15748 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15749 texture_desc.CPUAccessFlags = 0;
15750 texture_desc.MiscFlags = 0;
15751 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, NULL, &texture);
15752 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15754 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15755 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15757 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15758 check_texture1d_color(texture, 0xbf4c7f19, 1);
15760 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15761 check_texture1d_color(texture, 0x8000ff00, 1);
15763 ID3D11RenderTargetView_Release(rtv);
15764 ID3D11Texture1D_Release(texture);
15765 release_test_context(&test_context);
15768 static void test_clear_render_target_view_2d(void)
15770 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
15771 static const float clear_colour[] = {0.1f, 0.5f, 0.3f, 0.75f};
15772 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15773 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
15775 ID3D11RenderTargetView *rtv[3], *srgb_rtv;
15776 ID3D11Texture2D *texture, *srgb_texture;
15777 struct d3d11_test_context test_context;
15778 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15779 D3D11_TEXTURE2D_DESC texture_desc;
15780 ID3D11DeviceContext *context;
15781 struct resource_readback rb;
15782 ID3D11Device *device;
15783 unsigned int i, j;
15784 DWORD colour;
15785 HRESULT hr;
15787 if (!init_test_context(&test_context, NULL))
15788 return;
15790 device = test_context.device;
15791 context = test_context.immediate_context;
15793 texture_desc.Width = 640;
15794 texture_desc.Height = 480;
15795 texture_desc.MipLevels = 1;
15796 texture_desc.ArraySize = 1;
15797 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15798 texture_desc.SampleDesc.Count = 1;
15799 texture_desc.SampleDesc.Quality = 0;
15800 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15801 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15802 texture_desc.CPUAccessFlags = 0;
15803 texture_desc.MiscFlags = 0;
15804 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15805 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15807 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15808 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
15809 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15811 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv[0]);
15812 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15814 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
15815 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15817 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, clear_colour);
15818 check_texture_color(test_context.backbuffer, expected_color, 1);
15820 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], clear_colour);
15821 check_texture_color(texture, expected_color, 1);
15823 if (!enable_debug_layer)
15824 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
15825 check_texture_color(texture, expected_color, 1);
15827 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, clear_colour);
15828 check_texture_color(srgb_texture, expected_srgb_color, 1);
15830 ID3D11RenderTargetView_Release(srgb_rtv);
15831 ID3D11RenderTargetView_Release(rtv[0]);
15832 ID3D11Texture2D_Release(srgb_texture);
15833 ID3D11Texture2D_Release(texture);
15835 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15836 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15837 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15839 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15840 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15841 U(rtv_desc).Texture2D.MipSlice = 0;
15842 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
15843 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15845 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15846 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15847 U(rtv_desc).Texture2D.MipSlice = 0;
15848 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[0]);
15849 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15851 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], clear_colour);
15852 check_texture_color(texture, expected_color, 1);
15854 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, clear_colour);
15855 get_texture_readback(texture, 0, &rb);
15856 for (i = 0; i < 4; ++i)
15858 for (j = 0; j < 4; ++j)
15860 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
15861 colour = get_readback_color(&rb, 80 + i * 160, 60 + j * 120, 0);
15862 ok(compare_color(colour, expected_srgb_color, 1)
15863 || broken(compare_color(colour, expected_color, 1) && broken_device),
15864 "Got unexpected colour 0x%08x.\n", colour);
15867 release_resource_readback(&rb);
15869 ID3D11RenderTargetView_Release(srgb_rtv);
15870 ID3D11RenderTargetView_Release(rtv[0]);
15871 ID3D11Texture2D_Release(texture);
15873 texture_desc.Width = 16;
15874 texture_desc.Height = 16;
15875 texture_desc.ArraySize = 5;
15876 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15877 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15879 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
15880 U(rtv_desc).Texture2DArray.MipSlice = 0;
15881 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
15882 U(rtv_desc).Texture2DArray.ArraySize = 5;
15883 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[0]);
15884 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15886 U(rtv_desc).Texture2DArray.FirstArraySlice = 1;
15887 U(rtv_desc).Texture2DArray.ArraySize = 3;
15888 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[1]);
15889 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15891 U(rtv_desc).Texture2DArray.FirstArraySlice = 2;
15892 U(rtv_desc).Texture2DArray.ArraySize = 1;
15893 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[2]);
15894 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15896 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], blue);
15897 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[1], green);
15898 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[2], clear_colour);
15900 get_texture_readback(texture, 0, &rb);
15901 colour = get_readback_color(&rb, 8, 8, 0);
15902 ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
15903 release_resource_readback(&rb);
15905 get_texture_readback(texture, 1, &rb);
15906 colour = get_readback_color(&rb, 8, 8, 0);
15907 ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
15908 release_resource_readback(&rb);
15910 get_texture_readback(texture, 2, &rb);
15911 colour = get_readback_color(&rb, 8, 8, 0);
15912 ok(compare_color(colour, 0xbf4c7f19, 1), "Got unexpected colour 0x%08x.\n", colour);
15913 release_resource_readback(&rb);
15915 get_texture_readback(texture, 3, &rb);
15916 colour = get_readback_color(&rb, 8, 8, 0);
15917 ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
15918 release_resource_readback(&rb);
15920 get_texture_readback(texture, 4, &rb);
15921 colour = get_readback_color(&rb, 8, 8, 0);
15922 ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
15923 release_resource_readback(&rb);
15925 ID3D11RenderTargetView_Release(rtv[2]);
15926 ID3D11RenderTargetView_Release(rtv[1]);
15927 ID3D11RenderTargetView_Release(rtv[0]);
15928 ID3D11Texture2D_Release(texture);
15930 release_test_context(&test_context);
15933 static void test_clear_render_target_view_3d(void)
15935 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
15936 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15938 struct d3d11_test_context test_context;
15939 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15940 D3D11_TEXTURE3D_DESC texture_desc;
15941 ID3D11DeviceContext *context;
15942 ID3D11RenderTargetView *rtv;
15943 ID3D11Texture3D *texture;
15944 ID3D11Device *device;
15945 HRESULT hr;
15947 if (!init_test_context(&test_context, NULL))
15948 return;
15949 device = test_context.device;
15950 context = test_context.immediate_context;
15952 texture_desc.Width = 8;
15953 texture_desc.Height = 8;
15954 texture_desc.Depth = 4;
15955 texture_desc.MipLevels = 1;
15956 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15957 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15958 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15959 texture_desc.CPUAccessFlags = 0;
15960 texture_desc.MiscFlags = 0;
15961 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
15962 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15964 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15965 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15967 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15968 check_texture3d_color(texture, 0xbf4c7f19, 1);
15969 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15970 check_texture3d_color(texture, 0x8000ff00, 1);
15972 ID3D11RenderTargetView_Release(rtv);
15973 ID3D11Texture3D_Release(texture);
15975 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15976 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
15977 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15979 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15980 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
15981 U(rtv_desc).Texture3D.MipSlice = 0;
15982 U(rtv_desc).Texture3D.FirstWSlice = 0;
15983 U(rtv_desc).Texture3D.WSize = ~0u;
15984 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
15985 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15987 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15988 check_texture3d_color(texture, 0xbf95bc59, 1);
15989 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15990 check_texture3d_color(texture, 0x8000ff00, 1);
15992 ID3D11RenderTargetView_Release(rtv);
15993 ID3D11Texture3D_Release(texture);
15994 release_test_context(&test_context);
15997 static void test_clear_depth_stencil_view(void)
15999 D3D11_TEXTURE2D_DESC texture_desc;
16000 ID3D11Texture2D *depth_texture;
16001 ID3D11DeviceContext *context;
16002 ID3D11DepthStencilView *dsv;
16003 ID3D11Device *device;
16004 ULONG refcount;
16005 HRESULT hr;
16007 if (!(device = create_device(NULL)))
16009 skip("Failed to create device.\n");
16010 return;
16013 ID3D11Device_GetImmediateContext(device, &context);
16015 texture_desc.Width = 640;
16016 texture_desc.Height = 480;
16017 texture_desc.MipLevels = 1;
16018 texture_desc.ArraySize = 1;
16019 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
16020 texture_desc.SampleDesc.Count = 1;
16021 texture_desc.SampleDesc.Quality = 0;
16022 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16023 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16024 texture_desc.CPUAccessFlags = 0;
16025 texture_desc.MiscFlags = 0;
16026 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
16027 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
16029 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
16030 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16032 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16033 check_texture_float(depth_texture, 1.0f, 0);
16035 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
16036 check_texture_float(depth_texture, 0.25f, 0);
16038 if (!enable_debug_layer)
16039 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
16040 check_texture_float(depth_texture, 0.25f, 0);
16042 ID3D11Texture2D_Release(depth_texture);
16043 ID3D11DepthStencilView_Release(dsv);
16045 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
16046 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
16047 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
16049 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
16050 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16052 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
16053 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
16055 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
16056 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
16058 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
16059 check_texture_color(depth_texture, 0xffffffff, 0);
16061 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
16062 check_texture_color(depth_texture, 0x00000000, 0);
16064 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
16065 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
16067 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
16068 check_texture_color(depth_texture, 0xffffffff, 0);
16070 ID3D11Texture2D_Release(depth_texture);
16071 ID3D11DepthStencilView_Release(dsv);
16073 ID3D11DeviceContext_Release(context);
16075 refcount = ID3D11Device_Release(device);
16076 ok(!refcount, "Device has %u references left.\n", refcount);
16079 static unsigned int to_sint8(unsigned int x)
16081 union
16083 signed int s;
16084 unsigned int u;
16085 } bits;
16086 bits.u = x;
16087 return min(max(bits.s, -128), 127) & 0xff;
16090 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
16091 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
16093 unsigned int x = to_sint8(v->x);
16094 unsigned int y = to_sint8(v->y);
16095 unsigned int z = to_sint8(v->z);
16096 unsigned int w = to_sint8(v->w);
16097 DWORD expected[] =
16099 /* Windows 7 - Nvidia, WARP */
16100 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
16101 /* Windows 10 - AMD */
16102 x | y << 8 | z << 16 | w << 24,
16103 /* Windows 10 - Intel */
16104 x | x << 8 | x << 16 | x << 24,
16107 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
16108 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
16109 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
16112 static void test_clear_buffer_unordered_access_view(void)
16114 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16115 ID3D11UnorderedAccessView *uav, *uav2;
16116 struct device_desc device_desc;
16117 D3D11_BUFFER_DESC buffer_desc;
16118 ID3D11DeviceContext *context;
16119 struct resource_readback rb;
16120 ID3D11Buffer *buffer;
16121 ID3D11Device *device;
16122 struct uvec4 uvec4;
16123 unsigned int i, x;
16124 ULONG refcount;
16125 HRESULT hr;
16126 RECT rect;
16128 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16129 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
16130 static const struct uvec4 uvec4_data[] =
16132 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
16134 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
16135 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
16136 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
16137 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
16138 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
16140 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
16141 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
16142 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
16143 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
16144 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
16145 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
16146 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
16148 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
16149 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
16150 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
16151 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
16152 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
16153 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
16154 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
16155 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
16156 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
16157 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
16159 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
16160 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
16161 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
16162 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
16163 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
16164 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
16165 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
16166 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
16167 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
16168 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
16170 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
16171 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
16172 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
16173 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
16174 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
16175 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
16176 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
16177 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
16178 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
16179 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
16181 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
16182 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
16183 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
16184 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
16185 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
16186 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
16187 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
16188 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
16189 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
16190 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
16193 device_desc.feature_level = &feature_level;
16194 device_desc.flags = 0;
16195 if (!(device = create_device(&device_desc)))
16197 skip("Failed to create device for feature level %#x.\n", feature_level);
16198 return;
16201 ID3D11Device_GetImmediateContext(device, &context);
16203 /* Structured buffer views */
16204 buffer_desc.ByteWidth = 64;
16205 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
16206 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16207 buffer_desc.CPUAccessFlags = 0;
16208 buffer_desc.MiscFlags = 0;
16209 buffer_desc.StructureByteStride = 0;
16210 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
16211 buffer_desc.StructureByteStride = 4;
16212 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16213 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16215 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
16216 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16218 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
16219 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16220 U(uav_desc).Buffer.FirstElement = 0;
16221 U(uav_desc).Buffer.NumElements = 4;
16222 U(uav_desc).Buffer.Flags = 0;
16223 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16224 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16226 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16228 uvec4 = uvec4_data[i];
16229 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16230 get_buffer_readback(buffer, &rb);
16231 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16232 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16233 release_resource_readback(&rb);
16235 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16236 get_buffer_readback(buffer, &rb);
16237 SetRect(&rect, 0, 0, U(uav_desc).Buffer.NumElements, 1);
16238 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16239 SetRect(&rect, U(uav_desc).Buffer.NumElements, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16240 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16241 release_resource_readback(&rb);
16244 ID3D11Buffer_Release(buffer);
16245 ID3D11UnorderedAccessView_Release(uav);
16246 ID3D11UnorderedAccessView_Release(uav2);
16248 /* Raw buffer views */
16249 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
16250 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16251 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16253 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
16254 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16255 U(uav_desc).Buffer.FirstElement = 0;
16256 U(uav_desc).Buffer.NumElements = 16;
16257 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
16258 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16259 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16260 U(uav_desc).Buffer.FirstElement = 8;
16261 U(uav_desc).Buffer.NumElements = 8;
16262 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16263 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16265 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16267 uvec4 = uvec4_data[i];
16268 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16269 get_buffer_readback(buffer, &rb);
16270 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16271 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16272 release_resource_readback(&rb);
16274 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16275 get_buffer_readback(buffer, &rb);
16276 SetRect(&rect, 0, 0, U(uav_desc).Buffer.FirstElement, 1);
16277 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16278 SetRect(&rect, U(uav_desc).Buffer.FirstElement, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16279 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16280 release_resource_readback(&rb);
16283 ID3D11Buffer_Release(buffer);
16284 ID3D11UnorderedAccessView_Release(uav);
16285 ID3D11UnorderedAccessView_Release(uav2);
16287 /* Typed buffer views */
16288 buffer_desc.MiscFlags = 0;
16289 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16290 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16292 uav_desc.Format = DXGI_FORMAT_R32_SINT;
16293 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16294 U(uav_desc).Buffer.FirstElement = 0;
16295 U(uav_desc).Buffer.NumElements = 16;
16296 U(uav_desc).Buffer.Flags = 0;
16297 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16298 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16299 U(uav_desc).Buffer.FirstElement = 9;
16300 U(uav_desc).Buffer.NumElements = 7;
16301 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16302 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16304 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16306 uvec4 = uvec4_data[i];
16307 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16308 get_buffer_readback(buffer, &rb);
16309 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16310 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16311 release_resource_readback(&rb);
16313 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16314 get_buffer_readback(buffer, &rb);
16315 SetRect(&rect, 0, 0, U(uav_desc).Buffer.FirstElement, 1);
16316 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16317 SetRect(&rect, U(uav_desc).Buffer.FirstElement, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16318 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16319 release_resource_readback(&rb);
16322 ID3D11UnorderedAccessView_Release(uav);
16323 ID3D11UnorderedAccessView_Release(uav2);
16325 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
16326 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16327 U(uav_desc).Buffer.FirstElement = 0;
16328 U(uav_desc).Buffer.NumElements = 4;
16329 U(uav_desc).Buffer.Flags = 0;
16330 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16331 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16332 U(uav_desc).Buffer.FirstElement = 2;
16333 U(uav_desc).Buffer.NumElements = 2;
16334 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16335 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16337 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16339 const struct uvec4 *data = NULL;
16340 BOOL all_match;
16342 uvec4 = uvec4_data[i];
16343 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16344 get_buffer_readback(buffer, &rb);
16345 for (x = 0, all_match = TRUE; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
16347 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
16348 data = get_readback_uvec4(&rb, x, 0);
16349 if (!(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result))))
16351 all_match = FALSE;
16352 break;
16355 ok(all_match, "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
16356 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, x);
16357 release_resource_readback(&rb);
16359 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16360 get_buffer_readback(buffer, &rb);
16361 for (x = 0, all_match = TRUE; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
16363 struct uvec4 broken_result;
16364 data = get_readback_uvec4(&rb, x, 0);
16365 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
16366 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
16367 if (!(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result))))
16369 all_match = FALSE;
16370 break;
16373 ok(all_match, "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
16374 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, x);
16375 release_resource_readback(&rb);
16378 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
16379 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16380 ID3D11UnorderedAccessView_Release(uav);
16381 ID3D11UnorderedAccessView_Release(uav2);
16383 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
16384 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16385 U(uav_desc).Buffer.FirstElement = 0;
16386 U(uav_desc).Buffer.NumElements = 16;
16387 U(uav_desc).Buffer.Flags = 0;
16388 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16389 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16390 U(uav_desc).Buffer.FirstElement = 8;
16391 U(uav_desc).Buffer.NumElements = 8;
16392 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16393 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16395 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16397 uvec4 = uvec4_data[i];
16398 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16399 get_buffer_readback(buffer, &rb);
16400 todo_wine check_rgba_sint8(get_readback_color(&rb, 0, 0, 0), &uvec4);
16401 todo_wine check_rgba_sint8(get_readback_color(&rb, 7, 0, 0), &uvec4);
16402 todo_wine check_rgba_sint8(get_readback_color(&rb, 15, 0, 0), &uvec4);
16403 release_resource_readback(&rb);
16405 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16406 get_buffer_readback(buffer, &rb);
16407 todo_wine check_rgba_sint8(get_readback_color(&rb, 0, 0, 0), &uvec4);
16408 todo_wine check_rgba_sint8(get_readback_color(&rb, U(uav_desc).Buffer.FirstElement - 1, 0, 0), &uvec4);
16409 todo_wine check_rgba_sint8(get_readback_color(&rb, U(uav_desc).Buffer.FirstElement, 0, 0), &fe_uvec4);
16410 release_resource_readback(&rb);
16413 ID3D11UnorderedAccessView_Release(uav);
16414 ID3D11UnorderedAccessView_Release(uav2);
16416 ID3D11Buffer_Release(buffer);
16418 ID3D11DeviceContext_Release(context);
16419 refcount = ID3D11Device_Release(device);
16420 ok(!refcount, "Device has %u references left.\n", refcount);
16423 static void test_clear_image_unordered_access_view(void)
16425 unsigned int expected_colour, actual_colour;
16426 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16427 unsigned int i, j, d, p, x, y, z, layer;
16428 struct d3d11_test_context test_context;
16429 unsigned int image_size, image_depth;
16430 struct resource_desc resource_desc;
16431 ID3D11UnorderedAccessView *uav[2];
16432 ID3D11DeviceContext *context;
16433 struct resource_readback rb;
16434 BOOL is_small_float_format;
16435 ID3D11Resource *resource;
16436 BOOL is_inside, success;
16437 ID3D11Device *device;
16438 UINT clear_value[4];
16439 HRESULT hr;
16441 #define IMAGE_SIZE 16
16442 static const struct
16444 DXGI_FORMAT format;
16445 unsigned int image_mips;
16446 unsigned int image_layers;
16447 unsigned int mip_level;
16448 unsigned int first_layer;
16449 unsigned int layer_count;
16450 unsigned int values[4];
16451 unsigned int expected;
16452 BOOL is_float;
16453 unsigned int clamped;
16455 tests[] =
16457 /* Test clearing a specific mip level. */
16458 {DXGI_FORMAT_R32_FLOAT, 2, 1, 0, 0, 1, {1, 0, 0, 0}, 0x00000001},
16459 {DXGI_FORMAT_R32_FLOAT, 2, 1, 1, 0, 1, {1, 0, 0, 0}, 0x00000001},
16460 {DXGI_FORMAT_R32_FLOAT, 2, 1, 0, 0, 1, {0x3f000000, 0, 0, 0}, 0x3f000000, TRUE},
16461 {DXGI_FORMAT_R32_FLOAT, 2, 1, 1, 0, 1, {0x3f000000, 0, 0, 0}, 0x3f000000, TRUE},
16462 /* Test clearing specific array layers. */
16463 {DXGI_FORMAT_R32_FLOAT, 1, IMAGE_SIZE, 0, 0, IMAGE_SIZE, {1, 0, 0, 0}, 0x00000001},
16464 {DXGI_FORMAT_R32_FLOAT, 1, IMAGE_SIZE, 0, 3, 2, {1, 0, 0, 0}, 0x00000001},
16465 {DXGI_FORMAT_R32_FLOAT, 1, IMAGE_SIZE, 0, 0, IMAGE_SIZE, {0x3f000000, 0, 0, 0}, 0x3f000000, TRUE},
16466 {DXGI_FORMAT_R32_FLOAT, 1, IMAGE_SIZE, 0, 3, 2, {0x3f000000, 0, 0, 0}, 0x3f000000, TRUE},
16467 /* Test uint clears with formats. */
16468 {DXGI_FORMAT_R16G16_UINT, 1, 1, 0, 0, 1, {1, 2, 3, 4}, 0x00020001},
16469 {DXGI_FORMAT_R16G16_UINT, 1, 1, 0, 0, 1, {0x12345, 0, 0, 0}, 0x00002345, FALSE, 0x0000ffff},
16470 {DXGI_FORMAT_R16G16_UNORM, 1, 1, 0, 0, 1, {1, 2, 3, 4}, 0x00020001},
16471 {DXGI_FORMAT_R16G16_FLOAT, 1, 1, 0, 0, 1, {1, 2, 3, 4}, 0x00020001},
16472 {DXGI_FORMAT_R8G8B8A8_UINT, 1, 1, 0, 0, 1, {1, 2, 3, 4}, 0x04030201},
16473 {DXGI_FORMAT_R8G8B8A8_UINT, 1, 1, 0, 0, 1, {0x123, 0, 0, 0}, 0x00000023, FALSE, 0x000000ff},
16474 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1, 0, 0, 1, {1, 2, 3, 4}, 0x04030201},
16475 {DXGI_FORMAT_R11G11B10_FLOAT, 1, 1, 0, 0, 1, {1, 2, 3, 4}, 0x00c01001},
16476 /* Test float clears with formats. */
16477 {DXGI_FORMAT_R16G16_UNORM, 1, 1, 0, 0, 1,
16478 {0x3f000000 /* 0.5f */, 0x3f800000 /* 1.0f */, 0, 0}, 0xffff8000, TRUE},
16479 {DXGI_FORMAT_R16G16_FLOAT, 1, 1, 0, 0, 1,
16480 {0x3f000000 /* 0.5f */, 0x3f800000 /* 1.0f */, 0, 0}, 0x3c003800, TRUE},
16481 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1, 0, 0, 1,
16482 {0x3f000000 /* 0.5f */, 0x3f800000 /* 1.0f */, 0, 0}, 0x0000ff80, TRUE},
16483 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1, 0, 0, 1,
16484 {0, 0, 0x3f000000 /* 0.5f */, 0x3f800000 /* 1.0f */}, 0xff800000, TRUE},
16485 {DXGI_FORMAT_R11G11B10_FLOAT, 1, 1, 0, 0, 1,
16486 {0x3f000000 /* 1.0f */, 0 /* 0.0f */, 0xbf800000 /* -1.0f */, 0x3f000000 /* 1.0f */},
16487 0x00000380, TRUE},
16490 static const struct
16492 D3D11_RESOURCE_DIMENSION resource_dim;
16493 D3D11_UAV_DIMENSION view_dim;
16494 BOOL is_layered;
16496 uav_dimensions[] =
16498 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_UAV_DIMENSION_TEXTURE2D, FALSE},
16499 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_UAV_DIMENSION_TEXTURE2DARRAY, TRUE },
16500 /* Expected behaviour with partial layer coverage is unclear. */
16501 {D3D11_RESOURCE_DIMENSION_TEXTURE3D, D3D11_UAV_DIMENSION_TEXTURE3D, FALSE},
16504 if (!init_test_context(&test_context, NULL))
16505 return;
16506 device = test_context.device;
16507 context = test_context.immediate_context;
16509 memset(&resource_desc, 0, sizeof(resource_desc));
16510 resource_desc.width = IMAGE_SIZE;
16511 resource_desc.height = IMAGE_SIZE;
16512 resource_desc.sample_desc.Count = 1;
16513 resource_desc.usage = D3D11_USAGE_DEFAULT;
16514 resource_desc.bind_flags = D3D11_BIND_UNORDERED_ACCESS;
16516 for (d = 0; d < ARRAY_SIZE(uav_dimensions); ++d)
16518 for (i = 0; i < ARRAY_SIZE(tests); ++i)
16520 winetest_push_context("Dim %u, Test %u", d, i);
16522 if (tests[i].image_layers > 1 && !uav_dimensions[d].is_layered)
16524 winetest_pop_context();
16525 continue;
16528 resource_desc.dimension = uav_dimensions[d].resource_dim;
16529 resource_desc.depth_or_array_size = tests[i].image_layers;
16530 resource_desc.level_count = tests[i].image_mips;
16531 resource_desc.format = tests[i].format;
16532 if (FAILED(hr = create_resource(device, &resource_desc, NULL, &resource)))
16534 skip("Failed to create resource, hr %#x.\n", hr);
16535 winetest_pop_context();
16536 continue;
16539 uav_desc.Format = tests[i].format;
16540 uav_desc.ViewDimension = uav_dimensions[d].view_dim;
16542 for (j = 0; j < 2; ++j)
16544 unsigned int first_layer = j ? 0 : tests[i].first_layer;
16545 unsigned int layer_count = j ? tests[i].image_layers : tests[i].layer_count;
16547 switch (uav_desc.ViewDimension)
16549 case D3D11_UAV_DIMENSION_TEXTURE2D:
16550 uav_desc.Texture2D.MipSlice = tests[i].mip_level;
16551 break;
16553 case D3D11_UAV_DIMENSION_TEXTURE2DARRAY:
16554 uav_desc.Texture2DArray.MipSlice = tests[i].mip_level;
16555 uav_desc.Texture2DArray.FirstArraySlice = first_layer;
16556 uav_desc.Texture2DArray.ArraySize = layer_count;
16557 break;
16559 case D3D11_UAV_DIMENSION_TEXTURE3D:
16560 uav_desc.Texture3D.MipSlice = tests[i].mip_level;
16561 uav_desc.Texture3D.FirstWSlice = first_layer;
16562 uav_desc.Texture3D.WSize = layer_count;
16563 break;
16565 default:
16566 ok(0, "Unhandled uav dimension %#x.\n", uav_dimensions[d].view_dim);
16567 break;
16570 hr = ID3D11Device_CreateUnorderedAccessView(device, resource, &uav_desc, &uav[j]);
16571 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
16574 for (j = 0; j < 4; ++j)
16576 clear_value[j] = tests[i].expected ? 0u : ~0u;
16579 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav[1], clear_value);
16580 if (tests[i].is_float)
16581 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav[0], (const float *)tests[i].values);
16582 else
16583 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav[0], tests[i].values);
16585 image_depth = uav_dimensions[d].resource_dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D
16586 ? max(tests[i].image_layers >> tests[i].mip_level, 1u) : 1;
16587 image_size = max(IMAGE_SIZE >> tests[i].mip_level, 1u);
16589 is_small_float_format = tests[i].format == DXGI_FORMAT_R16G16_UNORM
16590 || tests[i].format == DXGI_FORMAT_R16G16_FLOAT
16591 || tests[i].format == DXGI_FORMAT_R11G11B10_FLOAT
16592 || tests[i].format == DXGI_FORMAT_R8G8B8A8_UNORM;
16593 for (layer = 0; layer < tests[i].image_layers / image_depth; ++layer)
16595 get_resource_readback(resource, tests[i].mip_level + (layer * tests[i].image_mips), &rb);
16597 success = TRUE;
16598 expected_colour = actual_colour = x = y = z = 0;
16599 for (p = 0; p < image_depth * image_size * image_size; ++p)
16601 x = p % image_size;
16602 y = (p / image_size) % image_size;
16603 z = p / (image_size * image_size);
16605 if (uav_dimensions[d].resource_dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D)
16606 is_inside = z >= tests[i].first_layer
16607 && z < tests[i].first_layer + tests[i].layer_count;
16608 else
16609 is_inside = layer >= tests[i].first_layer
16610 && layer < tests[i].first_layer + tests[i].layer_count;
16612 expected_colour = is_inside ? tests[i].expected : clear_value[0];
16613 actual_colour = get_readback_u32(&rb, x, y, z);
16614 if (!(success = compare_color(actual_colour, expected_colour, tests[i].is_float ? 1 : 0)
16615 /* Some drivers/GPUs clamp clear values that can't
16616 * be represented by the format. (Windows 7
16617 * testbot, AMD PALM) */
16618 || broken(is_inside && tests[i].clamped && actual_colour == tests[i].clamped)
16619 /* Some drivers/GPUs mishandle integer clears of
16620 * small float/normalised formats. (AMD PALM) */
16621 || broken(is_inside && !tests[i].is_float && is_small_float_format && !actual_colour)))
16622 break;
16624 ok(success, "At layer %u, (%u,%u,%u), expected 0x%08x, got 0x%08x.\n",
16625 layer, x, y, z, expected_colour, actual_colour);
16627 release_resource_readback(&rb);
16630 ID3D11UnorderedAccessView_Release(uav[1]);
16631 ID3D11UnorderedAccessView_Release(uav[0]);
16632 ID3D11Resource_Release(resource);
16633 winetest_pop_context();
16637 release_test_context(&test_context);
16638 #undef IMAGE_SIZE
16641 static void test_initial_depth_stencil_state(void)
16643 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16644 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
16645 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16646 struct d3d11_test_context test_context;
16647 D3D11_TEXTURE2D_DESC texture_desc;
16648 ID3D11DeviceContext *context;
16649 ID3D11DepthStencilView *dsv;
16650 ID3D11Texture2D *texture;
16651 ID3D11Device *device;
16652 unsigned int count;
16653 D3D11_VIEWPORT vp;
16654 HRESULT hr;
16656 if (!init_test_context(&test_context, NULL))
16657 return;
16659 device = test_context.device;
16660 context = test_context.immediate_context;
16662 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16663 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
16664 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16665 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16666 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16668 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
16669 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16671 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
16673 count = 1;
16674 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
16676 /* check if depth function is D3D11_COMPARISON_LESS */
16677 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16678 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
16679 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.4f);
16680 draw_color_quad(&test_context, &green);
16681 draw_color_quad(&test_context, &red);
16682 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.6f, 0.6f);
16683 draw_color_quad(&test_context, &red);
16684 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16685 check_texture_float(texture, 0.4f, 1);
16687 ID3D11DepthStencilView_Release(dsv);
16688 ID3D11Texture2D_Release(texture);
16689 release_test_context(&test_context);
16692 static void test_draw_depth_only(void)
16694 struct d3d11_test_context test_context;
16695 ID3D11PixelShader *ps_color, *ps_depth;
16696 D3D11_TEXTURE2D_DESC texture_desc;
16697 ID3D11DeviceContext *context;
16698 ID3D11DepthStencilView *dsv;
16699 struct resource_readback rb;
16700 ID3D11Texture2D *texture;
16701 ID3D11Device *device;
16702 unsigned int i, j;
16703 struct vec4 depth;
16704 ID3D11Buffer *cb;
16705 HRESULT hr;
16707 static const DWORD ps_color_code[] =
16709 #if 0
16710 float4 main(float4 position : SV_POSITION) : SV_Target
16712 return float4(0.0, 1.0, 0.0, 1.0);
16714 #endif
16715 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
16716 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16717 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
16718 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16719 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
16720 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
16721 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
16723 static const DWORD ps_depth_code[] =
16725 #if 0
16726 float depth;
16728 float main() : SV_Depth
16730 return depth;
16732 #endif
16733 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
16734 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16735 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
16736 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
16737 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
16738 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
16741 if (!init_test_context(&test_context, NULL))
16742 return;
16744 device = test_context.device;
16745 context = test_context.immediate_context;
16747 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
16749 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16750 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
16751 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16752 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16753 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16755 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
16756 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16758 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
16759 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16760 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
16761 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16763 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16764 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
16765 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
16767 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16768 check_texture_float(texture, 1.0f, 1);
16769 draw_quad(&test_context);
16770 check_texture_float(texture, 0.0f, 1);
16772 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
16774 depth.x = 0.7f;
16775 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16776 draw_quad(&test_context);
16777 check_texture_float(texture, 0.0f, 1);
16778 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16779 check_texture_float(texture, 1.0f, 1);
16780 draw_quad(&test_context);
16781 check_texture_float(texture, 0.7f, 1);
16782 depth.x = 0.8f;
16783 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16784 draw_quad(&test_context);
16785 check_texture_float(texture, 0.7f, 1);
16786 depth.x = 0.5f;
16787 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16788 draw_quad(&test_context);
16789 check_texture_float(texture, 0.5f, 1);
16791 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16792 for (i = 0; i < 4; ++i)
16794 for (j = 0; j < 4; ++j)
16796 depth.x = 1.0f / 16.0f * (j + 4 * i);
16797 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16799 set_viewport(context, 160.0f * j, 120.0f * i, 160.0f, 120.0f, 0.0f, 1.0f);
16801 draw_quad(&test_context);
16804 get_texture_readback(texture, 0, &rb);
16805 for (i = 0; i < 4; ++i)
16807 for (j = 0; j < 4; ++j)
16809 float obtained_depth, expected_depth;
16811 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
16812 expected_depth = 1.0f / 16.0f * (j + 4 * i);
16813 ok(compare_float(obtained_depth, expected_depth, 1),
16814 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
16815 obtained_depth, j, i, expected_depth);
16818 release_resource_readback(&rb);
16820 ID3D11Buffer_Release(cb);
16821 ID3D11PixelShader_Release(ps_color);
16822 ID3D11PixelShader_Release(ps_depth);
16823 ID3D11DepthStencilView_Release(dsv);
16824 ID3D11Texture2D_Release(texture);
16825 release_test_context(&test_context);
16828 static void test_draw_uav_only(void)
16830 struct d3d11_test_context test_context;
16831 D3D11_TEXTURE2D_DESC texture_desc;
16832 ID3D11UnorderedAccessView *uav;
16833 ID3D11DeviceContext *context;
16834 ID3D11Texture2D *texture;
16835 ID3D11PixelShader *ps;
16836 ID3D11Device *device;
16837 HRESULT hr;
16839 static const DWORD ps_code[] =
16841 #if 0
16842 RWTexture2D<int> u;
16844 void main()
16846 InterlockedAdd(u[uint2(0, 0)], 1);
16848 #endif
16849 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
16850 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16851 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
16852 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
16853 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
16855 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16856 static const UINT values[4] = {0};
16858 if (!init_test_context(&test_context, &feature_level))
16859 return;
16861 device = test_context.device;
16862 context = test_context.immediate_context;
16864 texture_desc.Width = 1;
16865 texture_desc.Height = 1;
16866 texture_desc.MipLevels = 1;
16867 texture_desc.ArraySize = 1;
16868 texture_desc.Format = DXGI_FORMAT_R32_SINT;
16869 texture_desc.SampleDesc.Count = 1;
16870 texture_desc.SampleDesc.Quality = 0;
16871 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16872 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16873 texture_desc.CPUAccessFlags = 0;
16874 texture_desc.MiscFlags = 0;
16876 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16877 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16879 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
16880 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16882 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16883 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16885 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16886 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
16887 0, 1, &uav, NULL);
16889 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
16890 set_viewport(context, 0.0f, 0.0f, 10.0f, 10.0f, 0.0f, 0.0f);
16891 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
16892 draw_quad(&test_context);
16893 check_texture_color(texture, 100, 1);
16895 draw_quad(&test_context);
16896 draw_quad(&test_context);
16897 draw_quad(&test_context);
16898 draw_quad(&test_context);
16899 check_texture_color(texture, 500, 1);
16901 ID3D11PixelShader_Release(ps);
16902 ID3D11Texture2D_Release(texture);
16903 ID3D11UnorderedAccessView_Release(uav);
16904 release_test_context(&test_context);
16907 static void test_cb_relative_addressing(void)
16909 struct d3d11_test_context test_context;
16910 ID3D11Buffer *colors_cb, *index_cb;
16911 unsigned int i, index[4] = {0};
16912 ID3D11DeviceContext *context;
16913 ID3D11PixelShader *ps;
16914 ID3D11Device *device;
16915 HRESULT hr;
16917 static const DWORD vs_code[] =
16919 #if 0
16920 int color_index;
16922 cbuffer colors
16924 float4 colors[8];
16927 struct vs_in
16929 float4 position : POSITION;
16932 struct vs_out
16934 float4 position : SV_POSITION;
16935 float4 color : COLOR;
16938 vs_out main(const vs_in v)
16940 vs_out o;
16942 o.position = v.position;
16943 o.color = colors[color_index];
16945 return o;
16947 #endif
16948 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
16949 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16950 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
16951 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
16952 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
16953 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
16954 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
16955 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
16956 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
16957 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
16958 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
16959 0x0100003e,
16961 static const DWORD ps_code[] =
16963 #if 0
16964 struct ps_in
16966 float4 position : SV_POSITION;
16967 float4 color : COLOR;
16970 float4 main(const ps_in v) : SV_TARGET
16972 return v.color;
16974 #endif
16975 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
16976 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16977 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
16978 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
16979 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16980 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
16981 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16982 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
16984 static const struct
16986 float color[4];
16988 colors[10] =
16990 {{0.0f, 0.0f, 0.0f, 1.0f}},
16991 {{0.0f, 0.0f, 1.0f, 0.0f}},
16992 {{0.0f, 0.0f, 1.0f, 1.0f}},
16993 {{0.0f, 1.0f, 0.0f, 0.0f}},
16994 {{0.0f, 1.0f, 0.0f, 1.0f}},
16995 {{0.0f, 1.0f, 1.0f, 0.0f}},
16996 {{0.0f, 1.0f, 1.0f, 1.0f}},
16997 {{1.0f, 0.0f, 0.0f, 0.0f}},
16998 {{1.0f, 0.0f, 0.0f, 1.0f}},
16999 {{1.0f, 0.0f, 1.0f, 0.0f}},
17001 static const struct
17003 unsigned int index;
17004 DWORD expected;
17006 test_data[] =
17008 {0, 0xff000000},
17009 {1, 0x00ff0000},
17010 {2, 0xffff0000},
17011 {3, 0x0000ff00},
17012 {4, 0xff00ff00},
17013 {5, 0x00ffff00},
17014 {6, 0xffffff00},
17015 {7, 0x000000ff},
17017 {8, 0xff0000ff},
17018 {9, 0x00ff00ff},
17020 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
17021 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17023 if (!init_test_context(&test_context, &feature_level))
17024 return;
17026 device = test_context.device;
17027 context = test_context.immediate_context;
17029 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
17030 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
17032 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17033 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17035 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
17036 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
17037 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17039 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
17041 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
17043 index[0] = test_data[i].index;
17044 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
17046 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
17047 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
17050 ID3D11Buffer_Release(index_cb);
17051 ID3D11Buffer_Release(colors_cb);
17052 ID3D11PixelShader_Release(ps);
17054 release_test_context(&test_context);
17057 static void test_vs_input_relative_addressing(void)
17059 struct d3d11_test_context test_context;
17060 ID3D11DeviceContext *context;
17061 unsigned int offset, stride;
17062 unsigned int index[4] = {0};
17063 ID3D11PixelShader *ps;
17064 ID3D11Buffer *vb, *cb;
17065 ID3D11Device *device;
17066 unsigned int i;
17067 HRESULT hr;
17069 static const DWORD vs_code[] =
17071 #if 0
17072 struct vertex
17074 float4 position : POSITION;
17075 float4 colors[4] : COLOR;
17078 uint index;
17080 void main(vertex vin, out float4 position : SV_Position,
17081 out float4 color : COLOR)
17083 position = vin.position;
17084 color = vin.colors[index];
17086 #endif
17087 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
17088 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
17089 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
17090 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
17091 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
17092 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
17093 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
17094 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
17095 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
17096 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
17097 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
17098 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
17099 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
17100 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
17101 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
17102 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
17104 static const DWORD ps_code[] =
17106 #if 0
17107 struct vs_out
17109 float4 position : SV_POSITION;
17110 float4 color : COLOR;
17113 float4 main(struct vs_out i) : SV_TARGET
17115 return i.color;
17117 #endif
17118 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
17119 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17120 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17121 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
17122 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17123 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
17124 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
17125 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
17127 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17129 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17130 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1},
17131 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D11_INPUT_PER_INSTANCE_DATA, 1},
17132 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D11_INPUT_PER_INSTANCE_DATA, 1},
17133 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D11_INPUT_PER_INSTANCE_DATA, 1},
17135 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
17136 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17138 if (!init_test_context(&test_context, NULL))
17139 return;
17140 device = test_context.device;
17141 context = test_context.immediate_context;
17143 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17144 vs_code, sizeof(vs_code), &test_context.input_layout);
17145 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17147 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
17148 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
17150 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(colors), colors);
17151 stride = sizeof(colors);
17152 offset = 0;
17153 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
17155 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17156 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17157 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17159 for (i = 0; i < ARRAY_SIZE(colors); ++i)
17161 *index = i;
17162 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
17163 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17164 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
17165 check_texture_color(test_context.backbuffer, colors[i], 1);
17168 ID3D11Buffer_Release(cb);
17169 ID3D11Buffer_Release(vb);
17170 ID3D11PixelShader_Release(ps);
17171 release_test_context(&test_context);
17174 static void test_getdc(void)
17176 static const struct
17178 const char *name;
17179 DXGI_FORMAT format;
17180 BOOL getdc_supported;
17182 testdata[] =
17184 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
17185 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
17186 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
17187 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
17188 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
17189 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
17191 struct device_desc device_desc;
17192 D3D11_TEXTURE2D_DESC desc;
17193 ID3D11Texture2D *texture;
17194 IDXGISurface1 *surface;
17195 ID3D11Device *device;
17196 unsigned int i;
17197 ULONG refcount;
17198 HRESULT hr;
17199 HDC dc;
17201 device_desc.feature_level = NULL;
17202 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
17203 if (!(device = create_device(&device_desc)))
17205 skip("Failed to create device.\n");
17206 return;
17209 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
17210 desc.Width = 512;
17211 desc.Height = 512;
17212 desc.MipLevels = 1;
17213 desc.ArraySize = 1;
17214 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
17215 desc.SampleDesc.Count = 1;
17216 desc.SampleDesc.Quality = 0;
17217 desc.Usage = D3D11_USAGE_DEFAULT;
17218 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17219 desc.CPUAccessFlags = 0;
17220 desc.MiscFlags = 0;
17221 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
17222 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17224 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
17225 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
17227 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
17228 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
17230 IDXGISurface1_Release(surface);
17231 ID3D11Texture2D_Release(texture);
17233 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
17234 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
17235 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17237 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
17238 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
17240 hr = IDXGISurface1_ReleaseDC(surface, NULL);
17241 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
17243 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
17244 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
17246 hr = IDXGISurface1_ReleaseDC(surface, NULL);
17247 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
17249 IDXGISurface1_Release(surface);
17250 ID3D11Texture2D_Release(texture);
17252 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
17254 static const unsigned int bit_count = 32;
17255 unsigned int width_bytes;
17256 DIBSECTION dib;
17257 HBITMAP bitmap;
17258 DWORD type;
17259 int size;
17261 desc.Width = 64;
17262 desc.Height = 64;
17263 desc.MipLevels = 1;
17264 desc.ArraySize = 1;
17265 desc.Format = testdata[i].format;
17266 desc.SampleDesc.Count = 1;
17267 desc.SampleDesc.Quality = 0;
17268 desc.Usage = D3D11_USAGE_STAGING;
17269 desc.BindFlags = 0;
17270 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
17271 desc.MiscFlags = 0;
17273 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
17274 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17275 ID3D11Texture2D_Release(texture);
17277 /* STAGING usage, requesting GDI compatibility mode. */
17278 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
17279 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
17280 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
17282 desc.Usage = D3D11_USAGE_DEFAULT;
17283 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
17284 desc.CPUAccessFlags = 0;
17285 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
17286 if (testdata[i].getdc_supported)
17287 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
17288 else
17289 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
17291 if (FAILED(hr))
17292 continue;
17294 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
17295 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
17297 dc = (void *)0x1234;
17298 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
17299 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
17301 if (FAILED(hr))
17303 IDXGISurface1_Release(surface);
17304 ID3D11Texture2D_Release(texture);
17305 continue;
17308 type = GetObjectType(dc);
17309 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
17310 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
17311 type = GetObjectType(bitmap);
17312 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
17314 size = GetObjectA(bitmap, sizeof(dib), &dib);
17315 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
17316 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
17318 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
17319 dib.dsBm.bmType, testdata[i].name);
17320 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
17321 dib.dsBm.bmWidth, testdata[i].name);
17322 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
17323 dib.dsBm.bmHeight, testdata[i].name);
17324 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
17325 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
17326 dib.dsBm.bmWidthBytes, testdata[i].name);
17327 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
17328 dib.dsBm.bmPlanes, testdata[i].name);
17329 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
17330 dib.dsBm.bmBitsPixel, testdata[i].name);
17332 if (size == sizeof(dib))
17333 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
17334 dib.dsBm.bmBits, testdata[i].name);
17335 else
17336 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
17337 dib.dsBm.bmBits, testdata[i].name);
17339 if (size == sizeof(dib))
17341 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
17342 dib.dsBmih.biSize, testdata[i].name);
17343 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
17344 dib.dsBmih.biHeight, testdata[i].name);
17345 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
17346 dib.dsBmih.biHeight, testdata[i].name);
17347 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
17348 dib.dsBmih.biPlanes, testdata[i].name);
17349 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
17350 dib.dsBmih.biBitCount, testdata[i].name);
17351 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
17352 dib.dsBmih.biCompression, testdata[i].name);
17353 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
17354 dib.dsBmih.biSizeImage, testdata[i].name);
17355 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
17356 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
17357 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
17358 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
17359 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
17360 dib.dsBmih.biClrUsed, testdata[i].name);
17361 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
17362 dib.dsBmih.biClrImportant, testdata[i].name);
17363 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
17364 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
17365 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
17366 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
17367 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
17370 hr = IDXGISurface1_ReleaseDC(surface, NULL);
17371 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
17373 IDXGISurface1_Release(surface);
17374 ID3D11Texture2D_Release(texture);
17377 refcount = ID3D11Device_Release(device);
17378 ok(!refcount, "Device has %u references left.\n", refcount);
17381 static void test_shader_stage_input_output_matching(void)
17383 struct d3d11_test_context test_context;
17384 D3D11_TEXTURE2D_DESC texture_desc;
17385 ID3D11Texture2D *render_target;
17386 ID3D11RenderTargetView *rtv[2];
17387 ID3D11DeviceContext *context;
17388 ID3D11VertexShader *vs;
17389 ID3D11PixelShader *ps;
17390 ID3D11Device *device;
17391 HRESULT hr;
17393 static const DWORD vs_code[] =
17395 #if 0
17396 struct output
17398 float4 position : SV_PoSiTion;
17399 float4 color0 : COLOR0;
17400 float4 color1 : COLOR1;
17403 void main(uint id : SV_VertexID, out output o)
17405 float2 coords = float2((id << 1) & 2, id & 2);
17406 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
17407 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
17408 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
17410 #endif
17411 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
17412 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17413 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
17414 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
17415 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17416 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
17417 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
17418 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
17419 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
17420 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
17421 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
17422 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
17423 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
17424 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
17425 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
17426 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
17427 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
17428 0x0100003e,
17430 static const DWORD ps_code[] =
17432 #if 0
17433 struct input
17435 float4 position : SV_PoSiTiOn;
17436 float4 color1 : COLOR1;
17437 float4 color0 : COLOR0;
17440 struct output
17442 float4 target0 : SV_Target0;
17443 float4 target1 : SV_Target1;
17446 void main(const in input i, out output o)
17448 o.target0 = i.color0;
17449 o.target1 = i.color1;
17451 #endif
17452 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
17453 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
17454 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
17455 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
17456 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
17457 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
17458 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
17459 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
17460 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
17461 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
17462 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
17465 if (!init_test_context(&test_context, NULL))
17466 return;
17468 device = test_context.device;
17469 context = test_context.immediate_context;
17471 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17472 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17473 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17474 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17476 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17477 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
17478 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17480 rtv[0] = test_context.backbuffer_rtv;
17481 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
17482 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17484 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17485 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17486 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
17487 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
17488 ID3D11DeviceContext_Draw(context, 3, 0);
17490 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17491 check_texture_color(render_target, 0xff0000ff, 0);
17493 ID3D11RenderTargetView_Release(rtv[1]);
17494 ID3D11Texture2D_Release(render_target);
17495 ID3D11PixelShader_Release(ps);
17496 ID3D11VertexShader_Release(vs);
17497 release_test_context(&test_context);
17500 static void test_unbound_streams(void)
17502 struct d3d11_test_context test_context;
17503 ID3D11DeviceContext *context;
17504 ID3D11PixelShader *ps;
17505 ID3D11Device *device;
17506 HRESULT hr;
17508 static const DWORD vs_code[] =
17510 #if 0
17511 struct vs_ps
17513 float4 position : SV_POSITION;
17514 float4 color : COLOR0;
17517 vs_ps vs_main(float4 position : POSITION, float4 color : COLOR0)
17519 vs_ps result;
17520 result.position = position;
17521 result.color = color;
17522 result.color.w = 1.0;
17523 return result;
17525 #endif
17526 0x43425844, 0x4a9efaec, 0xe2c6cdf5, 0x15dd28a7, 0xae68e320, 0x00000001, 0x00000154, 0x00000003,
17527 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
17528 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
17529 0x00000003, 0x00000001, 0x0000070f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
17530 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
17531 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
17532 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x0000007c, 0x00010040, 0x0000001f,
17533 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101072, 0x00000001, 0x04000067, 0x001020f2,
17534 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
17535 0x00101e46, 0x00000000, 0x05000036, 0x00102072, 0x00000001, 0x00101246, 0x00000001, 0x05000036,
17536 0x00102082, 0x00000001, 0x00004001, 0x3f800000, 0x0100003e,
17539 static const DWORD ps_code[] =
17541 #if 0
17542 float4 ps_main(vs_ps input) : SV_TARGET
17544 return input.color;
17546 #endif
17547 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
17548 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17549 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17550 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
17551 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17552 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
17553 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
17554 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
17557 static const float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
17559 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17561 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17562 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
17565 if (!init_test_context(&test_context, NULL))
17566 return;
17568 device = test_context.device;
17569 context = test_context.immediate_context;
17571 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17572 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17574 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17575 vs_code, sizeof(vs_code), &test_context.input_layout);
17576 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17578 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17579 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17580 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
17581 check_texture_color(test_context.backbuffer, 0xff000000, 1);
17583 ID3D11PixelShader_Release(ps);
17584 release_test_context(&test_context);
17587 static void test_shader_interstage_interface(void)
17589 struct d3d11_test_context test_context;
17590 D3D11_TEXTURE2D_DESC texture_desc;
17591 ID3D11InputLayout *input_layout;
17592 ID3D11Texture2D *render_target;
17593 ID3D11DeviceContext *context;
17594 ID3D11RenderTargetView *rtv;
17595 ID3D11VertexShader *vs;
17596 ID3D11PixelShader *ps;
17597 ID3D11Device *device;
17598 UINT stride, offset;
17599 ID3D11Buffer *vb;
17600 unsigned int i;
17601 HRESULT hr;
17603 static const DWORD vs_code[] =
17605 #if 0
17606 struct vertex
17608 float4 position : SV_Position;
17609 float2 t0 : TEXCOORD0;
17610 nointerpolation float t1 : TEXCOORD1;
17611 uint t2 : TEXCOORD2;
17612 uint t3 : TEXCOORD3;
17613 float t4 : TEXCOORD4;
17616 void main(in vertex vin, out vertex vout)
17618 vout = vin;
17620 #endif
17621 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
17622 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
17623 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
17624 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
17625 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
17626 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
17627 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17628 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
17629 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
17630 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
17631 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
17632 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
17633 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
17634 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
17635 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
17636 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
17637 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
17638 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
17639 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
17640 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
17641 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
17642 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
17644 static const DWORD ps_code[] =
17646 #if 0
17647 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
17648 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
17649 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
17651 o.x = t0.y + t1;
17652 o.y = t2 + t3;
17653 o.z = t4;
17654 o.w = t0.x;
17656 #endif
17657 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
17658 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
17659 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
17660 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
17661 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
17662 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
17663 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17664 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
17665 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
17666 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
17667 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
17668 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
17669 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
17670 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
17671 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
17673 static const DWORD ps_partial_input_code[] =
17675 #if 0
17676 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
17677 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
17678 uint t3 : TEXCOORD3, out float4 o : SV_Target)
17680 o.x = t0.y + t1;
17681 o.y = t2 + t3;
17682 o.z = 0.0f;
17683 o.w = t0.x;
17685 #endif
17686 0x43425844, 0x5b1db356, 0xaa5a5e9d, 0xb916a081, 0x61e6dcb1, 0x00000001, 0x000001cc, 0x00000003,
17687 0x0000002c, 0x000000cc, 0x00000100, 0x4e475349, 0x00000098, 0x00000005, 0x00000008, 0x00000080,
17688 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
17689 0x00000003, 0x00000001, 0x00000303, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
17690 0x00000101, 0x0000008c, 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x0000008c,
17691 0x00000003, 0x00000000, 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
17692 0x43584554, 0x44524f4f, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17693 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
17694 0x52444853, 0x000000c4, 0x00000040, 0x00000031, 0x03001062, 0x00101032, 0x00000001, 0x03000862,
17695 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042, 0x00000002,
17696 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012, 0x00000000,
17697 0x0010102a, 0x00000002, 0x0010101a, 0x00000002, 0x05000056, 0x00102022, 0x00000000, 0x0010000a,
17698 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a, 0x00000002,
17699 0x05000036, 0x00102042, 0x00000000, 0x00004001, 0x00000000, 0x05000036, 0x00102082, 0x00000000,
17700 0x0010100a, 0x00000001, 0x0100003e,
17702 static const DWORD ps_single_input_code[] =
17704 #if 0
17705 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0, out float4 o : SV_Target)
17707 o.x = t0.x;
17708 o.y = t0.y;
17709 o.z = 1.0f;
17710 o.w = 2.0f;
17712 #endif
17713 0x43425844, 0x7cc601b6, 0xc65b8bdb, 0x54d0f606, 0x9cc74d3d, 0x00000001, 0x00000118, 0x00000003,
17714 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
17715 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17716 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17717 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
17718 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058,
17719 0x00000040, 0x00000016, 0x03001062, 0x00101032, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17720 0x05000036, 0x00102032, 0x00000000, 0x00101046, 0x00000001, 0x08000036, 0x001020c2, 0x00000000,
17721 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x40000000, 0x0100003e,
17723 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17725 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17726 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
17727 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
17728 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
17729 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
17730 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
17732 static const struct
17734 struct vec2 position;
17735 struct vec2 t0;
17736 float t1;
17737 unsigned int t2;
17738 unsigned int t3;
17739 float t4;
17741 quad[] =
17743 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17744 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17745 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17746 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17748 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17749 static const struct
17751 const DWORD *ps_code;
17752 size_t ps_size;
17753 struct vec4 expected_result;
17755 tests[] =
17757 {ps_code, sizeof(ps_code), {10.0f, 8.0f, 7.0f, 3.0f}},
17758 {ps_partial_input_code, sizeof(ps_partial_input_code), {10.0f, 8.0f, 0.0f, 3.0f}},
17759 {ps_single_input_code, sizeof(ps_single_input_code), {3.0f, 5.0f, 1.0f, 2.0f}},
17762 if (!init_test_context(&test_context, NULL))
17763 return;
17765 device = test_context.device;
17766 context = test_context.immediate_context;
17768 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17769 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17771 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17772 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17773 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
17774 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17776 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
17777 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17779 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17780 vs_code, sizeof(vs_code), &input_layout);
17781 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17783 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
17785 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
17787 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17788 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17789 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
17790 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
17791 offset = 0;
17792 stride = sizeof(*quad);
17793 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
17795 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17797 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_size, NULL, &ps);
17798 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
17799 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17800 ID3D11DeviceContext_Draw(context, 4, 0);
17801 check_texture_vec4(render_target, &tests[i].expected_result, 0);
17802 ID3D11PixelShader_Release(ps);
17805 ID3D11InputLayout_Release(input_layout);
17806 ID3D11RenderTargetView_Release(rtv);
17807 ID3D11Texture2D_Release(render_target);
17808 ID3D11VertexShader_Release(vs);
17809 ID3D11Buffer_Release(vb);
17810 release_test_context(&test_context);
17813 static void test_sm4_if_instruction(void)
17815 struct d3d11_test_context test_context;
17816 ID3D11PixelShader *ps_if_nz, *ps_if_z;
17817 ID3D11DeviceContext *context;
17818 ID3D11Device *device;
17819 unsigned int bits[4];
17820 DWORD expected_color;
17821 ID3D11Buffer *cb;
17822 unsigned int i;
17823 HRESULT hr;
17825 static const DWORD ps_if_nz_code[] =
17827 #if 0
17828 uint bits;
17830 float4 main() : SV_TARGET
17832 if (bits)
17833 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17834 else
17835 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17837 #endif
17838 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
17839 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17840 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17841 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
17842 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
17843 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17844 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17845 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17847 static const DWORD ps_if_z_code[] =
17849 #if 0
17850 uint bits;
17852 float4 main() : SV_TARGET
17854 if (!bits)
17855 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17856 else
17857 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17859 #endif
17860 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
17861 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17862 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17863 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
17864 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
17865 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17866 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17867 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17869 static unsigned int bit_patterns[] =
17871 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
17874 if (!init_test_context(&test_context, NULL))
17875 return;
17877 device = test_context.device;
17878 context = test_context.immediate_context;
17880 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
17881 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
17882 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
17883 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
17885 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
17886 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17888 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
17890 *bits = bit_patterns[i];
17891 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
17893 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
17894 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
17895 draw_quad(&test_context);
17896 check_texture_color(test_context.backbuffer, expected_color, 0);
17898 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
17899 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
17900 draw_quad(&test_context);
17901 check_texture_color(test_context.backbuffer, expected_color, 0);
17904 ID3D11Buffer_Release(cb);
17905 ID3D11PixelShader_Release(ps_if_z);
17906 ID3D11PixelShader_Release(ps_if_nz);
17907 release_test_context(&test_context);
17910 static void test_sm4_breakc_instruction(void)
17912 struct d3d11_test_context test_context;
17913 ID3D11DeviceContext *context;
17914 ID3D11PixelShader *ps;
17915 ID3D11Device *device;
17916 HRESULT hr;
17918 static const DWORD ps_breakc_nz_code[] =
17920 #if 0
17921 float4 main() : SV_TARGET
17923 uint counter = 0;
17925 for (uint i = 0; i < 255; ++i)
17926 ++counter;
17928 if (counter == 255)
17929 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17930 else
17931 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17933 #endif
17934 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
17935 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17936 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17937 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
17938 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
17939 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
17940 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
17941 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
17942 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
17943 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
17944 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
17945 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
17946 0x01000015, 0x0100003e,
17948 static const DWORD ps_breakc_z_code[] =
17950 #if 0
17951 float4 main() : SV_TARGET
17953 uint counter = 0;
17955 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
17956 ++counter;
17958 if (counter == 255)
17959 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17960 else
17961 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17963 #endif
17964 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
17965 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17966 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17967 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
17968 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
17969 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
17970 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
17971 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
17972 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
17973 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
17974 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
17975 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17976 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17977 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17980 if (!init_test_context(&test_context, NULL))
17981 return;
17983 device = test_context.device;
17984 context = test_context.immediate_context;
17986 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
17987 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
17988 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17989 draw_quad(&test_context);
17990 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17991 ID3D11PixelShader_Release(ps);
17993 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
17994 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
17995 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17996 draw_quad(&test_context);
17997 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17998 ID3D11PixelShader_Release(ps);
18000 release_test_context(&test_context);
18003 static void test_sm4_continuec_instruction(void)
18005 struct d3d11_test_context test_context;
18006 ID3D11DeviceContext *context;
18007 ID3D11PixelShader *ps;
18008 ID3D11Device *device;
18009 HRESULT hr;
18011 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
18012 * with a normal continue inside, the shaders have been compiled with
18013 * the /Gfa flag. */
18014 static const DWORD ps_continuec_nz_code[] =
18016 #if 0
18017 float4 main() : SV_TARGET
18019 uint counter = 0;
18020 int i = -1;
18022 while (i < 255) {
18023 ++i;
18025 if (i != 0)
18026 continue;
18028 ++counter;
18031 if (counter == 1)
18032 return float4(0.0f, 1.0f, 0.0f, 1.0f);
18033 else
18034 return float4(1.0f, 0.0f, 0.0f, 1.0f);
18036 #endif
18037 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
18038 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18039 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18040 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
18041 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
18042 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
18043 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
18044 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
18045 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
18046 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
18047 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
18048 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
18049 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
18050 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
18051 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
18052 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
18053 0x3f800000, 0x0100003e,
18056 static const DWORD ps_continuec_z_code[] =
18058 #if 0
18059 float4 main() : SV_TARGET
18061 uint counter = 0;
18062 int i = -1;
18064 while (i < 255) {
18065 ++i;
18067 if (i == 0)
18068 continue;
18070 ++counter;
18073 if (counter == 255)
18074 return float4(0.0f, 1.0f, 0.0f, 1.0f);
18075 else
18076 return float4(1.0f, 0.0f, 0.0f, 1.0f);
18078 #endif
18079 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
18080 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18081 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18082 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
18083 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
18084 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
18085 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
18086 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
18087 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
18088 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
18089 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
18090 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
18091 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
18092 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
18093 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
18096 if (!init_test_context(&test_context, NULL))
18097 return;
18099 device = test_context.device;
18100 context = test_context.immediate_context;
18102 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
18103 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
18104 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18105 draw_quad(&test_context);
18106 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18107 ID3D11PixelShader_Release(ps);
18109 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
18110 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
18111 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18112 draw_quad(&test_context);
18113 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
18114 ID3D11PixelShader_Release(ps);
18116 release_test_context(&test_context);
18119 static void test_sm4_discard_instruction(void)
18121 ID3D11PixelShader *ps_discard_nz, *ps_discard_z;
18122 struct d3d11_test_context test_context;
18123 ID3D11DeviceContext *context;
18124 ID3D11Device *device;
18125 ID3D11Buffer *cb;
18126 unsigned int i;
18127 HRESULT hr;
18129 static const DWORD ps_discard_nz_code[] =
18131 #if 0
18132 uint data;
18134 float4 main() : SV_Target
18136 if (data)
18137 discard;
18138 return float4(0.0f, 0.5f, 0.0f, 1.0f);
18140 #endif
18141 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
18142 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18143 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18144 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
18145 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
18146 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
18147 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
18149 static const DWORD ps_discard_z_code[] =
18151 #if 0
18152 uint data;
18154 float4 main() : SV_Target
18156 if (!data)
18157 discard;
18158 return float4(0.0f, 1.0f, 0.0f, 1.0f);
18160 #endif
18161 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
18162 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18163 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18164 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
18165 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
18166 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
18167 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
18169 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
18170 static const struct uvec4 values[] =
18172 {0x0000000},
18173 {0x0000001},
18174 {0x8000000},
18175 {0xfffffff},
18178 if (!init_test_context(&test_context, NULL))
18179 return;
18181 device = test_context.device;
18182 context = test_context.immediate_context;
18184 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
18185 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18187 hr = ID3D11Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code),
18188 NULL, &ps_discard_nz);
18189 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
18190 hr = ID3D11Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code),
18191 NULL, &ps_discard_z);
18192 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
18194 for (i = 0; i < ARRAY_SIZE(values); ++i)
18196 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &values[i], 0, 0);
18198 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
18199 ID3D11DeviceContext_PSSetShader(context, ps_discard_nz, NULL, 0);
18200 draw_quad(&test_context);
18201 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
18203 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
18204 ID3D11DeviceContext_PSSetShader(context, ps_discard_z, NULL, 0);
18205 draw_quad(&test_context);
18206 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
18209 ID3D11Buffer_Release(cb);
18210 ID3D11PixelShader_Release(ps_discard_nz);
18211 ID3D11PixelShader_Release(ps_discard_z);
18212 release_test_context(&test_context);
18215 static void test_sm5_swapc_instruction(void)
18217 struct input
18219 struct uvec4 src0;
18220 struct uvec4 src1;
18221 struct uvec4 src2;
18224 struct d3d11_test_context test_context;
18225 D3D11_TEXTURE2D_DESC texture_desc;
18226 ID3D11DeviceContext *context;
18227 ID3D11RenderTargetView *rtv;
18228 ID3D11Texture2D *texture;
18229 ID3D11PixelShader *ps[6];
18230 ID3D11Device *device;
18231 ID3D11Buffer *cb;
18232 unsigned int i;
18233 HRESULT hr;
18235 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18236 static const DWORD ps_swapc0_code[] =
18238 #if 0
18239 ps_5_0
18240 dcl_globalFlags refactoringAllowed
18241 dcl_constantbuffer cb0[3], immediateIndexed
18242 dcl_output o0.xyzw
18243 dcl_temps 2
18244 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
18245 mov o0.xyzw, r0.xyzw
18247 #endif
18248 0x43425844, 0x9e089246, 0x9f8b5cbe, 0xbac66faf, 0xaef23488, 0x00000001, 0x000000f8, 0x00000003,
18249 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18250 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18251 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
18252 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18253 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
18254 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
18255 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
18257 static const DWORD ps_swapc1_code[] =
18259 #if 0
18260 ps_5_0
18261 dcl_globalFlags refactoringAllowed
18262 dcl_constantbuffer cb0[3], immediateIndexed
18263 dcl_output o0.xyzw
18264 dcl_temps 2
18265 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
18266 mov o0.xyzw, r1.xyzw
18268 #endif
18269 0x43425844, 0xf2daed61, 0xede211f7, 0x7300dbea, 0x573ed49f, 0x00000001, 0x000000f8, 0x00000003,
18270 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18271 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18272 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
18273 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18274 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
18275 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
18276 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
18278 static const DWORD ps_swapc2_code[] =
18280 #if 0
18281 ps_5_0
18282 dcl_globalFlags refactoringAllowed
18283 dcl_constantbuffer cb0[3], immediateIndexed
18284 dcl_output o0.xyzw
18285 dcl_temps 2
18286 mov r0.xyzw, cb0[1].xyzw
18287 mov r1.xyzw, cb0[2].xyzw
18288 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
18289 mov o0.xyzw, r0.xyzw
18291 #endif
18292 0x43425844, 0x230fcb22, 0x70d99148, 0x65814d89, 0x97473498, 0x00000001, 0x00000120, 0x00000003,
18293 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18294 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18295 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
18296 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18297 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
18298 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
18299 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
18300 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
18302 static const DWORD ps_swapc3_code[] =
18304 #if 0
18305 ps_5_0
18306 dcl_globalFlags refactoringAllowed
18307 dcl_constantbuffer cb0[3], immediateIndexed
18308 dcl_output o0.xyzw
18309 dcl_temps 2
18310 mov r0.xyzw, cb0[1].xyzw
18311 mov r1.xyzw, cb0[2].xyzw
18312 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
18313 mov o0.xyzw, r1.xyzw
18315 #endif
18316 0x43425844, 0xce595d62, 0x98305541, 0xb04e74c8, 0xfc010f3a, 0x00000001, 0x00000120, 0x00000003,
18317 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18318 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18319 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
18320 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18321 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
18322 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
18323 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
18324 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
18326 static const DWORD ps_swapc4_code[] =
18328 #if 0
18329 ps_5_0
18330 dcl_globalFlags refactoringAllowed
18331 dcl_constantbuffer cb0[3], immediateIndexed
18332 dcl_output o0.xyzw
18333 dcl_temps 2
18334 mov r0.xyzw, cb0[0].xyzw
18335 swapc r0.xyzw, r1.xyzw, r0.xyzw, cb0[1].xyzw, cb0[2].xyzw
18336 mov o0.xyzw, r0.xyzw
18338 #endif
18339 0x43425844, 0x72067c48, 0xb53572a0, 0x9dd9e0fd, 0x903e37e3, 0x00000001, 0x0000010c, 0x00000003,
18340 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18341 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18342 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
18343 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18344 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
18345 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000000, 0x00208e46,
18346 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
18347 0x00100e46, 0x00000000, 0x0100003e,
18349 static const DWORD ps_swapc5_code[] =
18351 #if 0
18352 ps_5_0
18353 dcl_globalFlags refactoringAllowed
18354 dcl_constantbuffer cb0[3], immediateIndexed
18355 dcl_output o0.xyzw
18356 dcl_temps 2
18357 mov r1.xyzw, cb0[0].xyzw
18358 swapc r0.xyzw, r1.xyzw, r1.xyzw, cb0[1].xyzw, cb0[2].xyzw
18359 mov o0.xyzw, r1.xyzw
18361 #endif
18362 0x43425844, 0x7078fb08, 0xdd24cd44, 0x469d3258, 0x9e33a0bc, 0x00000001, 0x0000010c, 0x00000003,
18363 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18364 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18365 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
18366 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18367 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000,
18368 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001, 0x00208e46,
18369 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
18370 0x00100e46, 0x00000001, 0x0100003e,
18372 static const struct
18374 struct input input;
18375 struct uvec4 dst0;
18376 struct uvec4 dst1;
18378 tests[] =
18381 {{0, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18382 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}
18385 {{1, 1, 1, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18386 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
18389 {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
18390 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18391 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
18394 {{1, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18395 {0xaaaa, 0xc0de, 0xcccc, 0xeeee}, {0xdead, 0xbbbb, 0xffff, 0xdddd},
18398 {{1, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18399 {0xaaaa, 0xc0de, 0xffff, 0xdddd}, {0xdead, 0xbbbb, 0xcccc, 0xeeee},
18402 {{1, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18403 {0xaaaa, 0xc0de, 0xffff, 0xeeee}, {0xdead, 0xbbbb, 0xcccc, 0xdddd}
18406 {{0, 1, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18407 {0xdead, 0xbbbb, 0xffff, 0xeeee}, {0xaaaa, 0xc0de, 0xcccc, 0xdddd}
18410 {{0, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18411 {0xdead, 0xc0de, 0xcccc, 0xeeee}, {0xaaaa, 0xbbbb, 0xffff, 0xdddd}
18414 {{0, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18415 {0xdead, 0xc0de, 0xffff, 0xdddd}, {0xaaaa, 0xbbbb, 0xcccc, 0xeeee},
18419 if (!init_test_context(&test_context, &feature_level))
18420 return;
18422 device = test_context.device;
18423 context = test_context.immediate_context;
18425 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18426 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
18427 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18428 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18430 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18431 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
18433 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18435 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct input), NULL);
18436 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18438 hr = ID3D11Device_CreatePixelShader(device, ps_swapc0_code, sizeof(ps_swapc0_code), NULL, &ps[0]);
18439 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18440 hr = ID3D11Device_CreatePixelShader(device, ps_swapc1_code, sizeof(ps_swapc1_code), NULL, &ps[1]);
18441 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18442 hr = ID3D11Device_CreatePixelShader(device, ps_swapc2_code, sizeof(ps_swapc2_code), NULL, &ps[2]);
18443 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18444 hr = ID3D11Device_CreatePixelShader(device, ps_swapc3_code, sizeof(ps_swapc3_code), NULL, &ps[3]);
18445 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18446 hr = ID3D11Device_CreatePixelShader(device, ps_swapc4_code, sizeof(ps_swapc4_code), NULL, &ps[4]);
18447 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18448 hr = ID3D11Device_CreatePixelShader(device, ps_swapc5_code, sizeof(ps_swapc5_code), NULL, &ps[5]);
18449 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18451 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18453 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &tests[i].input, 0, 0);
18455 ID3D11DeviceContext_PSSetShader(context, ps[0], NULL, 0);
18456 draw_quad(&test_context);
18457 check_texture_uvec4(texture, &tests[i].dst0);
18459 ID3D11DeviceContext_PSSetShader(context, ps[1], NULL, 0);
18460 draw_quad(&test_context);
18461 check_texture_uvec4(texture, &tests[i].dst1);
18463 ID3D11DeviceContext_PSSetShader(context, ps[2], NULL, 0);
18464 draw_quad(&test_context);
18465 check_texture_uvec4(texture, &tests[i].dst0);
18467 ID3D11DeviceContext_PSSetShader(context, ps[3], NULL, 0);
18468 draw_quad(&test_context);
18469 check_texture_uvec4(texture, &tests[i].dst1);
18471 ID3D11DeviceContext_PSSetShader(context, ps[4], NULL, 0);
18472 draw_quad(&test_context);
18473 check_texture_uvec4(texture, &tests[i].dst0);
18475 ID3D11DeviceContext_PSSetShader(context, ps[5], NULL, 0);
18476 draw_quad(&test_context);
18477 check_texture_uvec4(texture, &tests[i].dst1);
18480 for (i = 0; i < ARRAY_SIZE(ps); ++i)
18481 ID3D11PixelShader_Release(ps[i]);
18482 ID3D11RenderTargetView_Release(rtv);
18483 ID3D11Texture2D_Release(texture);
18484 ID3D11Buffer_Release(cb);
18485 release_test_context(&test_context);
18488 static void test_create_input_layout(void)
18490 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
18492 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18494 ULONG refcount, expected_refcount;
18495 ID3D11InputLayout *input_layout;
18496 ID3D11Device *device;
18497 unsigned int i;
18498 HRESULT hr;
18500 static const DWORD vs_code[] =
18502 #if 0
18503 float4 main(float4 position : POSITION) : SV_POSITION
18505 return position;
18507 #endif
18508 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
18509 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18510 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
18511 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
18512 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
18513 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18514 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
18516 static const DXGI_FORMAT vertex_formats[] =
18518 DXGI_FORMAT_R32G32_FLOAT,
18519 DXGI_FORMAT_R32G32_UINT,
18520 DXGI_FORMAT_R32G32_SINT,
18521 DXGI_FORMAT_R16G16_FLOAT,
18522 DXGI_FORMAT_R16G16_UINT,
18523 DXGI_FORMAT_R16G16_SINT,
18524 DXGI_FORMAT_R32_FLOAT,
18525 DXGI_FORMAT_R32_UINT,
18526 DXGI_FORMAT_R32_SINT,
18527 DXGI_FORMAT_R16_UINT,
18528 DXGI_FORMAT_R16_SINT,
18529 DXGI_FORMAT_R8G8_UNORM,
18530 DXGI_FORMAT_R8_UINT,
18531 DXGI_FORMAT_R8_SINT,
18534 if (!(device = create_device(NULL)))
18536 skip("Failed to create device.\n");
18537 return;
18540 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
18542 expected_refcount = get_refcount(device) + 1;
18543 layout_desc->Format = vertex_formats[i];
18544 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
18545 vs_code, sizeof(vs_code), &input_layout);
18546 ok(hr == S_OK, "Failed to create input layout for format %#x, hr %#x.\n",
18547 vertex_formats[i], hr);
18548 refcount = get_refcount(device);
18549 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
18550 refcount, expected_refcount);
18551 ID3D11InputLayout_Release(input_layout);
18554 refcount = ID3D11Device_Release(device);
18555 ok(!refcount, "Device has %u references left.\n", refcount);
18558 static void test_input_layout_alignment(void)
18560 ID3D11InputLayout *layout;
18561 ID3D11Device *device;
18562 unsigned int i;
18563 ULONG refcount;
18564 HRESULT hr;
18566 static const DWORD vs_code[] =
18568 #if 0
18569 float4 main(float4 position : POSITION) : SV_POSITION
18571 return position;
18573 #endif
18574 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
18575 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18576 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
18577 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
18578 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
18579 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18580 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
18583 static const struct
18585 D3D11_INPUT_ELEMENT_DESC elements[2];
18586 HRESULT hr;
18588 test_data[] =
18591 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18592 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18593 }, S_OK},
18595 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18596 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 1, D3D11_INPUT_PER_VERTEX_DATA, 0},
18597 }, E_INVALIDARG},
18599 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18600 {"COLOR", 0, DXGI_FORMAT_R8_UINT, 0, 1, D3D11_INPUT_PER_VERTEX_DATA, 0},
18601 }, S_OK},
18603 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18604 {"COLOR", 0, DXGI_FORMAT_R32_UINT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18605 }, E_INVALIDARG},
18607 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18608 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18609 }, E_INVALIDARG},
18611 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18612 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
18613 }, S_OK},
18615 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18616 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 17, D3D11_INPUT_PER_VERTEX_DATA, 0},
18617 }, E_INVALIDARG},
18619 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18620 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 18, D3D11_INPUT_PER_VERTEX_DATA, 0},
18621 }, E_INVALIDARG},
18623 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18624 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 19, D3D11_INPUT_PER_VERTEX_DATA, 0},
18625 }, E_INVALIDARG},
18627 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18628 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
18629 }, S_OK},
18632 if (!(device = create_device(NULL)))
18634 skip("Failed to create device.\n");
18635 return;
18638 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
18640 hr = ID3D11Device_CreateInputLayout(device, test_data[i].elements, 2, vs_code, sizeof(vs_code), &layout);
18641 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
18642 if (SUCCEEDED(hr))
18643 ID3D11InputLayout_Release(layout);
18646 refcount = ID3D11Device_Release(device);
18647 ok(!refcount, "Device has %u references left.\n", refcount);
18650 static void test_input_assembler(void)
18652 enum layout_id
18654 LAYOUT_FLOAT32,
18655 LAYOUT_UINT16,
18656 LAYOUT_SINT16,
18657 LAYOUT_UNORM16,
18658 LAYOUT_SNORM16,
18659 LAYOUT_UINT8,
18660 LAYOUT_SINT8,
18661 LAYOUT_UNORM8,
18662 LAYOUT_SNORM8,
18663 LAYOUT_UNORM10_2,
18664 LAYOUT_UINT10_2,
18666 LAYOUT_COUNT,
18669 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
18671 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18672 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18674 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
18675 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
18676 ID3D11Buffer *vb_position, *vb_attribute;
18677 struct d3d11_test_context test_context;
18678 D3D11_TEXTURE2D_DESC texture_desc;
18679 unsigned int i, j, stride, offset;
18680 ID3D11Texture2D *render_target;
18681 ID3D11DeviceContext *context;
18682 ID3D11RenderTargetView *rtv;
18683 ID3D11PixelShader *ps;
18684 ID3D11Device *device;
18685 HRESULT hr;
18687 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
18689 DXGI_FORMAT_R32G32B32A32_FLOAT,
18690 DXGI_FORMAT_R16G16B16A16_UINT,
18691 DXGI_FORMAT_R16G16B16A16_SINT,
18692 DXGI_FORMAT_R16G16B16A16_UNORM,
18693 DXGI_FORMAT_R16G16B16A16_SNORM,
18694 DXGI_FORMAT_R8G8B8A8_UINT,
18695 DXGI_FORMAT_R8G8B8A8_SINT,
18696 DXGI_FORMAT_R8G8B8A8_UNORM,
18697 DXGI_FORMAT_R8G8B8A8_SNORM,
18698 DXGI_FORMAT_R10G10B10A2_UNORM,
18699 DXGI_FORMAT_R10G10B10A2_UINT,
18701 static const struct vec2 quad[] =
18703 {-1.0f, -1.0f},
18704 {-1.0f, 1.0f},
18705 { 1.0f, -1.0f},
18706 { 1.0f, 1.0f},
18708 static const DWORD ps_code[] =
18710 #if 0
18711 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
18713 return color;
18715 #endif
18716 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
18717 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
18718 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
18719 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
18720 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18721 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
18722 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
18723 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
18725 static const DWORD vs_float_code[] =
18727 #if 0
18728 struct output
18730 float4 position : SV_Position;
18731 float4 color : COLOR;
18734 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
18736 o.position = position;
18737 o.color = color;
18739 #endif
18740 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
18741 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18742 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18743 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18744 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18745 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18746 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18747 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18748 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18749 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18750 0x0100003e,
18752 static const DWORD vs_uint_code[] =
18754 #if 0
18755 struct output
18757 float4 position : SV_Position;
18758 float4 color : COLOR;
18761 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
18763 o.position = position;
18764 o.color = color;
18766 #endif
18767 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
18768 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18769 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18770 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18771 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18772 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18773 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18774 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18775 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18776 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18777 0x0100003e,
18779 static const DWORD vs_sint_code[] =
18781 #if 0
18782 struct output
18784 float4 position : SV_Position;
18785 float4 color : COLOR;
18788 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
18790 o.position = position;
18791 o.color = color;
18793 #endif
18794 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
18795 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18796 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18797 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18798 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18799 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18800 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18801 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18802 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18803 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18804 0x0100003e,
18806 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
18807 static const unsigned short uint16_data[] = {6, 8, 55, 777};
18808 static const short sint16_data[] = {-1, 33, 8, -77};
18809 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
18810 static const short snorm16_data[] = {-32768, 0, 32767, 0};
18811 static const unsigned char uint8_data[] = {0, 64, 128, 255};
18812 static const signed char sint8_data[] = {-128, 0, 127, 64};
18813 static const unsigned int uint32_zero = 0;
18814 static const unsigned int uint32_max = 0xffffffff;
18815 static const unsigned int unorm10_2_data= 0xa00003ff;
18816 static const unsigned int g10_data = 0x000ffc00;
18817 static const unsigned int a2_data = 0xc0000000;
18818 static const struct
18820 enum layout_id layout_id;
18821 unsigned int stride;
18822 const void *data;
18823 struct vec4 expected_color;
18824 BOOL todo;
18826 tests[] =
18828 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
18829 {1.0f, 2.0f, 3.0f, 4.0f}},
18830 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
18831 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
18832 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
18833 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
18834 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
18835 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
18836 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
18837 {-1.0f, 0.0f, 1.0f, 0.0f}},
18838 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
18839 {0.0f, 0.0f, 0.0f, 0.0f}},
18840 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
18841 {255.0f, 255.0f, 255.0f, 255.0f}},
18842 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
18843 {0.0f, 64.0f, 128.0f, 255.0f}},
18844 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
18845 {0.0f, 0.0f, 0.0f, 0.0f}},
18846 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
18847 {-1.0f, -1.0f, -1.0f, -1.0f}},
18848 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
18849 {-128.0f, 0.0f, 127.0f, 64.0f}},
18850 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
18851 {0.0f, 0.0f, 0.0f, 0.0f}},
18852 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
18853 {1.0f, 1.0f, 1.0f, 1.0f}},
18854 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
18855 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
18856 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
18857 {0.0f, 0.0f, 0.0f, 0.0f}},
18858 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
18859 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
18860 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
18861 {0.0f, 0.0f, 0.0f, 0.0f}},
18862 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
18863 {1.0f, 1.0f, 1.0f, 1.0f}},
18864 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
18865 {0.0f, 1.0f, 0.0f, 0.0f}},
18866 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
18867 {0.0f, 0.0f, 0.0f, 1.0f}},
18868 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
18869 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
18870 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
18871 {0.0f, 0.0f, 0.0f, 0.0f}},
18872 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
18873 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
18874 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
18875 {0.0f, 1023.0f, 0.0f, 0.0f}},
18876 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
18877 {0.0f, 0.0f, 0.0f, 3.0f}},
18878 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
18879 {1023.0f, 0.0f, 512.0f, 2.0f}},
18882 if (!init_test_context(&test_context, NULL))
18883 return;
18885 device = test_context.device;
18886 context = test_context.immediate_context;
18888 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18889 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18891 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
18892 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
18893 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
18894 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
18895 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
18896 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
18898 for (i = 0; i < LAYOUT_COUNT; ++i)
18900 input_layout_desc[1].Format = layout_formats[i];
18901 input_layout[i] = NULL;
18902 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
18903 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
18904 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
18905 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
18908 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
18909 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
18911 texture_desc.Width = 640;
18912 texture_desc.Height = 480;
18913 texture_desc.MipLevels = 1;
18914 texture_desc.ArraySize = 1;
18915 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
18916 texture_desc.SampleDesc.Count = 1;
18917 texture_desc.SampleDesc.Quality = 0;
18918 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18919 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
18920 texture_desc.CPUAccessFlags = 0;
18921 texture_desc.MiscFlags = 0;
18923 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
18924 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
18926 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
18927 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18929 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
18930 offset = 0;
18931 stride = sizeof(*quad);
18932 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
18933 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18934 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18936 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18938 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
18940 if (tests[i].layout_id == LAYOUT_UINT10_2)
18941 continue;
18943 assert(tests[i].layout_id < LAYOUT_COUNT);
18944 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
18946 assert(4 * tests[i].stride <= 1024);
18947 box.right = tests[i].stride;
18948 for (j = 0; j < 4; ++j)
18950 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
18951 &box, tests[i].data, 0, 0);
18952 box.left += tests[i].stride;
18953 box.right += tests[i].stride;
18956 stride = tests[i].stride;
18957 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
18959 switch (layout_formats[tests[i].layout_id])
18961 case DXGI_FORMAT_R16G16B16A16_UINT:
18962 case DXGI_FORMAT_R10G10B10A2_UINT:
18963 case DXGI_FORMAT_R8G8B8A8_UINT:
18964 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
18965 break;
18966 case DXGI_FORMAT_R16G16B16A16_SINT:
18967 case DXGI_FORMAT_R8G8B8A8_SINT:
18968 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
18969 break;
18971 default:
18972 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
18973 /* Fall through. */
18974 case DXGI_FORMAT_R32G32B32A32_FLOAT:
18975 case DXGI_FORMAT_R16G16B16A16_UNORM:
18976 case DXGI_FORMAT_R16G16B16A16_SNORM:
18977 case DXGI_FORMAT_R10G10B10A2_UNORM:
18978 case DXGI_FORMAT_R8G8B8A8_UNORM:
18979 case DXGI_FORMAT_R8G8B8A8_SNORM:
18980 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
18981 break;
18984 ID3D11DeviceContext_Draw(context, 4, 0);
18985 check_texture_vec4(render_target, &tests[i].expected_color, 2);
18988 ID3D11Texture2D_Release(render_target);
18989 ID3D11RenderTargetView_Release(rtv);
18990 ID3D11Buffer_Release(vb_attribute);
18991 ID3D11Buffer_Release(vb_position);
18992 for (i = 0; i < LAYOUT_COUNT; ++i)
18994 if (input_layout[i])
18995 ID3D11InputLayout_Release(input_layout[i]);
18997 ID3D11PixelShader_Release(ps);
18998 ID3D11VertexShader_Release(vs_float);
18999 ID3D11VertexShader_Release(vs_uint);
19000 ID3D11VertexShader_Release(vs_sint);
19001 release_test_context(&test_context);
19004 static void test_null_sampler(void)
19006 struct d3d11_test_context test_context;
19007 D3D11_TEXTURE2D_DESC texture_desc;
19008 ID3D11ShaderResourceView *srv;
19009 ID3D11DeviceContext *context;
19010 ID3D11RenderTargetView *rtv;
19011 ID3D11SamplerState *sampler;
19012 ID3D11Texture2D *texture;
19013 ID3D11PixelShader *ps;
19014 ID3D11Device *device;
19015 HRESULT hr;
19017 static const DWORD ps_code[] =
19019 #if 0
19020 Texture2D t;
19021 SamplerState s;
19023 float4 main(float4 position : SV_POSITION) : SV_Target
19025 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
19027 #endif
19028 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
19029 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
19030 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
19031 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
19032 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
19033 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
19034 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
19035 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
19036 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
19037 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
19039 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
19041 if (!init_test_context(&test_context, NULL))
19042 return;
19044 device = test_context.device;
19045 context = test_context.immediate_context;
19047 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19048 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19050 texture_desc.Width = 64;
19051 texture_desc.Height = 64;
19052 texture_desc.MipLevels = 1;
19053 texture_desc.ArraySize = 1;
19054 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
19055 texture_desc.SampleDesc.Count = 1;
19056 texture_desc.SampleDesc.Quality = 0;
19057 texture_desc.Usage = D3D11_USAGE_DEFAULT;
19058 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
19059 texture_desc.CPUAccessFlags = 0;
19060 texture_desc.MiscFlags = 0;
19062 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19063 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19065 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19066 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19068 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
19069 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
19071 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
19073 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19074 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
19075 sampler = NULL;
19076 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
19077 draw_quad(&test_context);
19078 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
19080 ID3D11ShaderResourceView_Release(srv);
19081 ID3D11RenderTargetView_Release(rtv);
19082 ID3D11Texture2D_Release(texture);
19083 ID3D11PixelShader_Release(ps);
19084 release_test_context(&test_context);
19087 static void test_check_feature_support(void)
19089 D3D11_FEATURE_DATA_THREADING threading[2];
19090 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
19091 D3D11_FEATURE_DATA_ARCHITECTURE_INFO archinfo;
19092 ID3D11Device *device;
19093 ULONG refcount;
19094 HRESULT hr;
19096 if (!(device = create_device(NULL)))
19098 skip("Failed to create device.\n");
19099 return;
19102 memset(threading, 0xef, sizeof(threading));
19104 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
19105 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19106 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
19107 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19108 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
19109 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19110 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
19111 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19112 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
19113 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19114 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
19115 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19117 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
19118 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
19119 ok(threading[0].DriverCommandLists == 0xefefefef,
19120 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
19121 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
19122 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
19123 ok(threading[1].DriverCommandLists == 0xefefefef,
19124 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
19126 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
19127 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
19128 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
19129 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
19130 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
19131 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
19133 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
19134 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19135 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
19136 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19137 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
19138 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19139 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
19140 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19141 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
19142 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19143 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
19144 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19146 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
19147 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
19148 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
19150 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo));
19151 ok(hr == S_OK || broken(hr == E_INVALIDARG) /* Not available on all Windows versions. */,
19152 "Got unexpected hr %#x.\n", hr);
19153 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo)*2);
19154 ok(hr == E_INVALIDARG /* Not available on all Windows versions but they will return E_INVALIDARG anyways. */,
19155 "Got unexpected hr %#x.\n", hr);
19157 refcount = ID3D11Device_Release(device);
19158 ok(!refcount, "Device has %u references left.\n", refcount);
19161 static void test_create_unordered_access_view(void)
19163 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19164 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
19165 D3D11_TEXTURE3D_DESC texture3d_desc;
19166 D3D11_TEXTURE2D_DESC texture2d_desc;
19167 ULONG refcount, expected_refcount;
19168 D3D11_SUBRESOURCE_DATA data = {0};
19169 ID3D11UnorderedAccessView *uav;
19170 struct device_desc device_desc;
19171 D3D11_BUFFER_DESC buffer_desc;
19172 ID3D11Device *device, *tmp;
19173 ID3D11Texture3D *texture3d;
19174 ID3D11Texture2D *texture2d;
19175 ID3D11Resource *texture;
19176 ID3D11Buffer *buffer;
19177 unsigned int i;
19178 HRESULT hr;
19180 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
19181 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
19182 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
19183 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
19184 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
19185 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
19186 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
19187 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
19188 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
19189 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
19190 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
19191 static const struct
19193 struct
19195 unsigned int miplevel_count;
19196 unsigned int depth_or_array_size;
19197 DXGI_FORMAT format;
19198 } texture;
19199 struct uav_desc uav_desc;
19200 struct uav_desc expected_uav_desc;
19202 tests[] =
19204 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
19205 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
19206 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
19207 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
19208 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
19209 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
19210 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
19211 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
19212 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
19213 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
19214 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
19215 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
19216 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
19217 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
19218 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
19219 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
19220 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
19221 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
19222 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
19223 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
19224 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
19225 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
19226 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
19227 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
19228 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
19229 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
19230 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
19231 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
19232 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
19233 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
19234 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
19235 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
19236 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
19237 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
19238 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
19239 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
19241 static const struct
19243 struct
19245 D3D11_UAV_DIMENSION dimension;
19246 unsigned int miplevel_count;
19247 unsigned int depth_or_array_size;
19248 DXGI_FORMAT format;
19249 } texture;
19250 struct uav_desc uav_desc;
19252 invalid_desc_tests[] =
19254 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
19255 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
19256 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
19257 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
19258 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
19259 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
19260 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
19261 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
19262 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
19263 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
19264 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
19265 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
19266 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
19267 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
19268 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
19269 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
19270 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
19271 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
19272 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
19273 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
19274 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
19275 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
19276 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
19277 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
19278 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
19279 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
19280 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
19281 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
19282 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
19283 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
19284 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
19285 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
19286 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
19287 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
19288 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
19289 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
19290 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
19292 #undef FMT_UNKNOWN
19293 #undef RGBA8_UNORM
19294 #undef RGBA8_SRGB
19295 #undef RGBA8_UINT
19296 #undef RGBA8_TL
19297 #undef DIM_UNKNOWN
19298 #undef TEX_1D
19299 #undef TEX_1D_ARRAY
19300 #undef TEX_2D
19301 #undef TEX_2D_ARRAY
19302 #undef TEX_3D
19304 device_desc.feature_level = &feature_level;
19305 device_desc.flags = 0;
19306 if (!(device = create_device(&device_desc)))
19308 skip("Failed to create device.\n");
19309 return;
19312 buffer_desc.ByteWidth = 1024;
19313 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
19314 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19315 buffer_desc.CPUAccessFlags = 0;
19316 buffer_desc.MiscFlags = 0;
19317 buffer_desc.StructureByteStride = 0;
19319 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
19320 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19322 expected_refcount = get_refcount(device) + 1;
19323 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19324 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19325 refcount = get_refcount(device);
19326 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
19327 tmp = NULL;
19328 expected_refcount = refcount + 1;
19329 ID3D11Buffer_GetDevice(buffer, &tmp);
19330 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
19331 refcount = get_refcount(device);
19332 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
19333 ID3D11Device_Release(tmp);
19335 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19336 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19337 U(uav_desc).Buffer.FirstElement = 0;
19338 U(uav_desc).Buffer.NumElements = 64;
19339 U(uav_desc).Buffer.Flags = 0;
19341 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19342 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19344 expected_refcount = get_refcount(device) + 1;
19345 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19346 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19347 refcount = get_refcount(device);
19348 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
19349 tmp = NULL;
19350 expected_refcount = refcount + 1;
19351 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
19352 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
19353 refcount = get_refcount(device);
19354 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
19355 ID3D11Device_Release(tmp);
19357 ID3D11UnorderedAccessView_Release(uav);
19358 ID3D11Buffer_Release(buffer);
19360 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19361 buffer_desc.StructureByteStride = 4;
19363 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19364 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19366 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19367 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19369 memset(&uav_desc, 0, sizeof(uav_desc));
19370 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
19372 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
19373 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
19374 uav_desc.ViewDimension);
19375 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
19376 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
19377 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
19379 ID3D11UnorderedAccessView_Release(uav);
19380 ID3D11Buffer_Release(buffer);
19382 /* Without D3D11_BIND_UNORDERED_ACCESS. */
19383 buffer = create_buffer(device, 0, 1024, NULL);
19385 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19386 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19387 U(uav_desc).Buffer.FirstElement = 0;
19388 U(uav_desc).Buffer.NumElements = 64;
19389 U(uav_desc).Buffer.Flags = 0;
19391 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19392 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19394 ID3D11Buffer_Release(buffer);
19396 texture2d_desc.Width = 512;
19397 texture2d_desc.Height = 512;
19398 texture2d_desc.SampleDesc.Count = 1;
19399 texture2d_desc.SampleDesc.Quality = 0;
19400 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
19401 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19402 texture2d_desc.CPUAccessFlags = 0;
19403 texture2d_desc.MiscFlags = 0;
19405 texture3d_desc.Width = 64;
19406 texture3d_desc.Height = 64;
19407 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
19408 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19409 texture3d_desc.CPUAccessFlags = 0;
19410 texture3d_desc.MiscFlags = 0;
19412 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19414 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
19416 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
19418 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
19419 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
19420 texture2d_desc.Format = tests[i].texture.format;
19422 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
19423 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
19424 texture = (ID3D11Resource *)texture2d;
19426 else
19428 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
19429 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
19430 texture3d_desc.Format = tests[i].texture.format;
19432 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
19433 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
19434 texture = (ID3D11Resource *)texture3d;
19437 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
19439 current_desc = NULL;
19441 else
19443 current_desc = &uav_desc;
19444 get_uav_desc(current_desc, &tests[i].uav_desc);
19447 expected_refcount = get_refcount(texture);
19448 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
19449 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
19450 refcount = get_refcount(texture);
19451 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
19453 memset(&uav_desc, 0, sizeof(uav_desc));
19454 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
19455 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
19457 ID3D11UnorderedAccessView_Release(uav);
19458 ID3D11Resource_Release(texture);
19461 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
19463 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
19464 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
19466 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
19468 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
19469 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
19470 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
19472 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
19473 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
19474 texture = (ID3D11Resource *)texture2d;
19476 else
19478 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
19479 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
19480 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
19482 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
19483 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
19484 texture = (ID3D11Resource *)texture3d;
19487 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
19488 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
19489 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
19491 ID3D11Resource_Release(texture);
19494 refcount = ID3D11Device_Release(device);
19495 ok(!refcount, "Device has %u references left.\n", refcount);
19498 static void test_immediate_constant_buffer(void)
19500 struct d3d11_test_context test_context;
19501 D3D11_TEXTURE2D_DESC texture_desc;
19502 ID3D11DeviceContext *context;
19503 ID3D11RenderTargetView *rtv;
19504 unsigned int index[4] = {0};
19505 ID3D11Texture2D *texture;
19506 ID3D11PixelShader *ps;
19507 ID3D11Device *device;
19508 ID3D11Buffer *cb;
19509 unsigned int i;
19510 HRESULT hr;
19512 static const DWORD ps_code[] =
19514 #if 0
19515 uint index;
19517 static const int int_array[6] =
19519 310, 111, 212, -513, -318, 0,
19522 static const uint uint_array[6] =
19524 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
19527 static const float float_array[6] =
19529 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
19532 float4 main() : SV_Target
19534 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
19536 #endif
19537 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
19538 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19539 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19540 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
19541 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
19542 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
19543 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
19544 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
19545 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19546 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
19547 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
19548 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
19549 0x0100003e,
19551 static struct vec4 expected_result[] =
19553 { 310.0f, 2.0f, 76.00f, 1.0f},
19554 { 111.0f, 7.0f, 83.50f, 1.0f},
19555 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
19556 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
19557 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
19558 { 0.0f, 0.0f, 0.0f, 1.0f},
19561 if (!init_test_context(&test_context, NULL))
19562 return;
19564 device = test_context.device;
19565 context = test_context.immediate_context;
19567 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19568 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19569 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19571 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
19572 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19574 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19575 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19576 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19577 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19579 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19580 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19581 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19583 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
19585 *index = i;
19586 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
19588 draw_quad(&test_context);
19589 check_texture_vec4(texture, &expected_result[i], 0);
19592 ID3D11Buffer_Release(cb);
19593 ID3D11PixelShader_Release(ps);
19594 ID3D11Texture2D_Release(texture);
19595 ID3D11RenderTargetView_Release(rtv);
19596 release_test_context(&test_context);
19599 static void test_fp_specials(void)
19601 struct d3d11_test_context test_context;
19602 D3D11_TEXTURE2D_DESC texture_desc;
19603 ID3D11DeviceContext *context;
19604 ID3D11RenderTargetView *rtv;
19605 ID3D11Texture2D *texture;
19606 ID3D11PixelShader *ps;
19607 ID3D11Device *device;
19608 HRESULT hr;
19610 static const DWORD ps_code[] =
19612 #if 0
19613 float4 main() : SV_Target
19615 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
19617 #endif
19618 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
19619 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19620 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19621 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
19622 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
19623 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
19625 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
19627 if (!init_test_context(&test_context, NULL))
19628 return;
19630 device = test_context.device;
19631 context = test_context.immediate_context;
19633 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19634 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19635 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19637 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19638 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19639 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19640 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19642 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19643 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19645 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19647 draw_quad(&test_context);
19648 check_texture_uvec4(texture, &expected_result);
19650 ID3D11PixelShader_Release(ps);
19651 ID3D11Texture2D_Release(texture);
19652 ID3D11RenderTargetView_Release(rtv);
19653 release_test_context(&test_context);
19656 static void test_uint_shader_instructions(void)
19658 struct shader
19660 const DWORD *code;
19661 size_t size;
19662 D3D_FEATURE_LEVEL required_feature_level;
19665 struct d3d11_test_context test_context;
19666 D3D11_TEXTURE2D_DESC texture_desc;
19667 D3D_FEATURE_LEVEL feature_level;
19668 ID3D11DeviceContext *context;
19669 ID3D11RenderTargetView *rtv;
19670 ID3D11Texture2D *texture;
19671 ID3D11PixelShader *ps;
19672 ID3D11Device *device;
19673 ID3D11Buffer *cb;
19674 unsigned int i;
19675 HRESULT hr;
19677 static const DWORD ps_bfi_code[] =
19679 #if 0
19680 uint bits, offset, insert, base;
19682 uint4 main() : SV_Target
19684 uint mask = ((1 << bits) - 1) << offset;
19685 return ((insert << offset) & mask) | (base & ~mask);
19687 #endif
19688 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
19689 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19690 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19691 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
19692 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19693 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
19694 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
19696 static const DWORD ps_bfi2_code[] =
19698 #if 0
19699 ps_5_0
19700 dcl_globalFlags refactoringAllowed
19701 dcl_constantbuffer cb0[1], immediateIndexed
19702 dcl_output o0.xyzw
19703 dcl_temps 1
19704 mov r0.xyzw, cb0[0].xyzw
19705 bfi r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz, r0.wwww
19706 mov o0.xyzw, r0.xyzw
19708 #endif
19709 0x43425844, 0x900f86b6, 0x73f4dabf, 0xea1b1106, 0x591ac790, 0x00000001, 0x00000104, 0x00000003,
19710 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19711 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19712 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000008c, 0x00000050, 0x00000023,
19713 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19714 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19715 0x0b00008c, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19716 0x00000000, 0x00100ff6, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
19717 0x0100003e,
19719 static const DWORD ps_ibfe_code[] =
19721 #if 0
19722 ps_5_0
19723 dcl_globalFlags refactoringAllowed
19724 dcl_constantbuffer cb0[1], immediateIndexed
19725 dcl_output o0.xyzw
19726 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
19728 #endif
19729 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
19730 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19731 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19732 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
19733 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19734 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
19735 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
19737 static const DWORD ps_ibfe2_code[] =
19739 #if 0
19740 ps_5_0
19741 dcl_globalFlags refactoringAllowed
19742 dcl_constantbuffer cb0[1], immediateIndexed
19743 dcl_output o0.xyzw
19744 dcl_temps 1
19745 mov r0.xyzw, cb0[0].xyzw
19746 ibfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
19747 mov o0.xyzw, r0.xyzw
19749 #endif
19750 0x43425844, 0x347a9c0e, 0x3eff39a4, 0x3dd41cc5, 0xff87ec8d, 0x00000001, 0x000000fc, 0x00000003,
19751 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19752 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19753 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
19754 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19755 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19756 0x0900008b, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19757 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19759 static const DWORD ps_ubfe_code[] =
19761 #if 0
19762 uint u;
19764 uint4 main() : SV_Target
19766 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
19768 #endif
19769 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
19770 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19771 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19772 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
19773 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19774 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
19775 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
19776 0x0100003e,
19778 static const DWORD ps_ubfe2_code[] =
19780 #if 0
19781 ps_5_0
19782 dcl_globalFlags refactoringAllowed
19783 dcl_constantbuffer cb0[1], immediateIndexed
19784 dcl_output o0.xyzw
19785 dcl_temps 1
19786 mov r0.xyzw, cb0[0].xyzw
19787 ubfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
19788 mov o0.xyzw, r0.xyzw
19790 #endif
19791 0x43425844, 0xf377b7fc, 0x1e4cb9e7, 0xb9b1020d, 0xde484388, 0x00000001, 0x000000fc, 0x00000003,
19792 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19793 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19794 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
19795 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19796 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19797 0x0900008a, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19798 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19800 static const DWORD ps_bfrev_code[] =
19802 #if 0
19803 uint bits;
19805 uint4 main() : SV_Target
19807 return uint4(reversebits(bits), reversebits(reversebits(bits)),
19808 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
19810 #endif
19811 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
19812 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19813 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19814 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
19815 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19816 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
19817 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
19818 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
19819 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
19820 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
19821 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
19823 static const DWORD ps_bits_code[] =
19825 #if 0
19826 uint u;
19827 int i;
19829 uint4 main() : SV_Target
19831 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
19833 #endif
19834 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
19835 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19836 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19837 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
19838 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19839 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
19840 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
19841 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
19842 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
19843 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
19844 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
19845 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
19846 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
19847 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
19849 static const DWORD ps_ftou_code[] =
19851 #if 0
19852 float f;
19854 uint4 main() : SV_Target
19856 return uint4(f, -f, 0, 0);
19858 #endif
19859 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
19860 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19861 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19862 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
19863 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
19864 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
19865 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
19866 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
19868 static const DWORD ps_f16tof32_code[] =
19870 #if 0
19871 uint4 hf;
19873 uint4 main() : SV_Target
19875 return f16tof32(hf);
19877 #endif
19878 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
19879 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19880 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19881 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
19882 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19883 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19884 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19886 static const DWORD ps_f32tof16_code[] =
19888 #if 0
19889 float4 f;
19891 uint4 main() : SV_Target
19893 return f32tof16(f);
19895 #endif
19896 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
19897 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19898 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19899 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
19900 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19901 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
19903 static const DWORD ps_not_code[] =
19905 #if 0
19906 uint2 bits;
19908 uint4 main() : SV_Target
19910 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
19912 #endif
19913 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
19914 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19915 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19916 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
19917 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
19918 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
19919 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
19920 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
19922 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
19923 static const struct shader ps_bfi2 = {ps_bfi2_code, sizeof(ps_bfi2_code), D3D_FEATURE_LEVEL_11_0};
19924 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
19925 static const struct shader ps_ibfe2 = {ps_ibfe2_code, sizeof(ps_ibfe2_code), D3D_FEATURE_LEVEL_11_0};
19926 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
19927 static const struct shader ps_ubfe2 = {ps_ubfe2_code, sizeof(ps_ubfe2_code), D3D_FEATURE_LEVEL_11_0};
19928 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
19929 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
19930 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
19931 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
19932 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
19933 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
19934 static const struct
19936 const struct shader *ps;
19937 unsigned int bits[4];
19938 struct uvec4 expected_result;
19940 tests[] =
19942 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
19943 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
19944 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19945 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19946 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19947 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19948 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
19949 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
19950 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
19951 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
19952 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
19953 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
19954 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
19955 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
19956 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
19957 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
19958 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
19959 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
19960 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
19962 {&ps_bfi2, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19963 {&ps_bfi2, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19964 {&ps_bfi2, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19965 {&ps_bfi2, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19967 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19968 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19969 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19970 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19971 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
19972 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
19973 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19974 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19975 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
19976 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19977 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19978 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19979 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19980 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19981 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19982 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19983 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19984 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19985 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
19986 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
19987 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19988 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19989 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19990 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19991 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19992 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19994 {&ps_ibfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19996 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19997 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
19998 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
19999 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
20000 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
20001 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20002 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
20004 {&ps_ubfe2, { 4, 4, 0x7fffffff}, {0x0000000f, 0x0000000f, 0x0000000f, 0x0000000f}},
20005 {&ps_ubfe2, {23, 8, 0xffffffff}, {0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff}},
20006 {&ps_ubfe2, {30, 1, 0xffffffff}, {0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff}},
20007 {&ps_ubfe2, {15, 15, 0x7fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
20008 {&ps_ubfe2, {15, 15, 0xffff00ff}, {0x00007ffe, 0x00007ffe, 0x00007ffe, 0x00007ffe}},
20009 {&ps_ubfe2, {16, 15, 0xffffffff}, {0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff}},
20010 {&ps_ubfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
20011 {&ps_ubfe2, {20, 15, 0xffffffff}, {0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff}},
20012 {&ps_ubfe2, {31, 31, 0xffffffff}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
20013 {&ps_ubfe2, {31, 31, 0x80000000}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
20014 {&ps_ubfe2, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
20016 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
20017 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
20018 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
20020 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
20021 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
20022 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
20023 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
20024 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
20025 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
20026 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
20027 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
20028 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
20029 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
20030 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
20031 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
20033 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
20034 {&ps_ftou, {BITS_NAN}, { 0, 0}},
20035 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
20036 {&ps_ftou, {BITS_INF}, {~0u, 0}},
20037 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
20038 {&ps_ftou, {BITS_1_0}, { 1, 0}},
20040 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
20041 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
20042 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
20043 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
20045 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
20047 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
20048 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
20051 if (!init_test_context(&test_context, NULL))
20052 return;
20054 device = test_context.device;
20055 context = test_context.immediate_context;
20056 feature_level = ID3D11Device_GetFeatureLevel(device);
20058 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
20059 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
20061 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
20062 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
20063 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
20064 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20066 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
20067 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
20069 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20071 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20073 if (feature_level < tests[i].ps->required_feature_level)
20074 continue;
20076 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
20077 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20078 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20080 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
20082 draw_quad(&test_context);
20083 check_texture_uvec4(texture, &tests[i].expected_result);
20085 ID3D11PixelShader_Release(ps);
20088 ID3D11Buffer_Release(cb);
20089 ID3D11Texture2D_Release(texture);
20090 ID3D11RenderTargetView_Release(rtv);
20091 release_test_context(&test_context);
20094 static void test_index_buffer_offset(void)
20096 ID3D11Buffer *vb, *ib, *so_buffer, *args_buffer;
20097 struct d3d11_test_context test_context;
20098 ID3D11InputLayout *input_layout;
20099 ID3D11DeviceContext *context;
20100 struct resource_readback rb;
20101 ID3D11GeometryShader *gs;
20102 const struct vec4 *data;
20103 ID3D11VertexShader *vs;
20104 ID3D11Device *device;
20105 UINT stride, offset;
20106 unsigned int i;
20107 HRESULT hr;
20109 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
20110 static const DWORD vs_code[] =
20112 #if 0
20113 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
20114 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
20116 out_position = position;
20117 out_attrib = attrib;
20119 #endif
20120 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
20121 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20122 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
20123 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
20124 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
20125 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
20126 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
20127 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
20128 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
20129 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
20130 0x0100003e,
20132 static const DWORD gs_code[] =
20134 #if 0
20135 struct vertex
20137 float4 position : SV_POSITION;
20138 float4 attrib : ATTRIB;
20141 [maxvertexcount(1)]
20142 void main(point vertex input[1], inout PointStream<vertex> output)
20144 output.Append(input[0]);
20145 output.RestartStrip();
20147 #endif
20148 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
20149 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20150 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
20151 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
20152 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
20153 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
20154 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
20155 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
20156 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
20157 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
20158 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
20159 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
20161 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
20163 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
20164 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
20166 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
20168 {0, "SV_Position", 0, 0, 4, 0},
20169 {0, "ATTRIB", 0, 0, 4, 0},
20171 static const struct
20173 struct vec4 position;
20174 struct vec4 attrib;
20176 vertices[] =
20178 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
20179 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
20180 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
20181 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
20183 static const unsigned int indices[] =
20185 0, 1, 2, 3,
20186 3, 2, 1, 0,
20187 1, 3, 2, 0,
20189 static const struct vec4 expected_data[] =
20191 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
20192 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
20193 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
20194 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
20196 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
20197 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
20198 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
20199 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
20201 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
20202 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
20203 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
20204 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
20206 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
20207 static const D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS argument_data[] =
20209 {4, 1, 0, 0, 0},
20212 if (!init_test_context(&test_context, &feature_level))
20213 return;
20215 device = test_context.device;
20216 context = test_context.immediate_context;
20218 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
20219 vs_code, sizeof(vs_code), &input_layout);
20220 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
20222 stride = 32;
20223 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
20224 so_declaration, ARRAY_SIZE(so_declaration),
20225 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
20226 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
20228 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
20229 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
20231 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
20232 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
20233 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
20235 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
20236 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
20238 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
20239 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
20240 stride = sizeof(*vertices);
20241 offset = 0;
20242 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
20244 offset = 0;
20245 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20247 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
20248 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
20250 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
20251 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
20253 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
20254 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
20256 get_buffer_readback(so_buffer, &rb);
20257 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
20259 data = get_readback_vec4(&rb, i, 0);
20260 ok(compare_vec4(data, &expected_data[i], 0)
20261 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
20262 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
20263 data->x, data->y, data->z, data->w, i);
20265 release_resource_readback(&rb);
20267 /* indirect draws */
20268 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
20269 sizeof(argument_data), argument_data);
20271 offset = 0;
20272 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
20274 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
20275 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
20277 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
20278 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
20280 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
20281 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
20283 get_buffer_readback(so_buffer, &rb);
20284 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
20286 data = get_readback_vec4(&rb, i, 0);
20287 todo_wine_if(i >= 8 && i != 20 && i != 21)
20288 ok(compare_vec4(data, &expected_data[i], 0)
20289 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
20290 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
20291 data->x, data->y, data->z, data->w, i);
20293 release_resource_readback(&rb);
20295 ID3D11Buffer_Release(so_buffer);
20296 ID3D11Buffer_Release(args_buffer);
20297 ID3D11Buffer_Release(ib);
20298 ID3D11Buffer_Release(vb);
20299 ID3D11VertexShader_Release(vs);
20300 ID3D11GeometryShader_Release(gs);
20301 ID3D11InputLayout_Release(input_layout);
20302 release_test_context(&test_context);
20305 static void test_face_culling(void)
20307 struct d3d11_test_context test_context;
20308 D3D11_RASTERIZER_DESC rasterizer_desc;
20309 ID3D11RasterizerState *state;
20310 ID3D11DeviceContext *context;
20311 ID3D11Buffer *cw_vb, *ccw_vb;
20312 ID3D11Device *device;
20313 BOOL broken_warp;
20314 unsigned int i;
20315 HRESULT hr;
20317 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
20318 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
20319 static const DWORD ps_code[] =
20321 #if 0
20322 float4 main(uint front : SV_IsFrontFace) : SV_Target
20324 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
20326 #endif
20327 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
20328 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
20329 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
20330 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20331 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
20332 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
20333 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
20334 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
20335 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
20336 0x3f800000, 0x0100003e,
20338 static const struct vec3 ccw_quad[] =
20340 {-1.0f, 1.0f, 0.0f},
20341 {-1.0f, -1.0f, 0.0f},
20342 { 1.0f, 1.0f, 0.0f},
20343 { 1.0f, -1.0f, 0.0f},
20345 static const struct
20347 D3D11_CULL_MODE cull_mode;
20348 BOOL front_ccw;
20349 BOOL expected_cw;
20350 BOOL expected_ccw;
20352 tests[] =
20354 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
20355 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
20356 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
20357 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
20358 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
20359 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
20362 if (!init_test_context(&test_context, NULL))
20363 return;
20365 device = test_context.device;
20366 context = test_context.immediate_context;
20368 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20369 draw_color_quad(&test_context, &green);
20370 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20372 cw_vb = test_context.vb;
20373 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
20375 test_context.vb = ccw_vb;
20376 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20377 draw_color_quad(&test_context, &green);
20378 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
20380 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
20381 rasterizer_desc.CullMode = D3D11_CULL_BACK;
20382 rasterizer_desc.FrontCounterClockwise = FALSE;
20383 rasterizer_desc.DepthBias = 0;
20384 rasterizer_desc.DepthBiasClamp = 0.0f;
20385 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
20386 rasterizer_desc.DepthClipEnable = TRUE;
20387 rasterizer_desc.ScissorEnable = FALSE;
20388 rasterizer_desc.MultisampleEnable = FALSE;
20389 rasterizer_desc.AntialiasedLineEnable = FALSE;
20391 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20393 rasterizer_desc.CullMode = tests[i].cull_mode;
20394 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
20395 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20396 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
20398 ID3D11DeviceContext_RSSetState(context, state);
20400 test_context.vb = cw_vb;
20401 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20402 draw_color_quad(&test_context, &green);
20403 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
20405 test_context.vb = ccw_vb;
20406 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20407 draw_color_quad(&test_context, &green);
20408 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
20410 ID3D11RasterizerState_Release(state);
20413 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0;
20415 /* Test SV_IsFrontFace. */
20416 ID3D11PixelShader_Release(test_context.ps);
20417 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
20418 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20420 rasterizer_desc.CullMode = D3D11_CULL_NONE;
20421 rasterizer_desc.FrontCounterClockwise = FALSE;
20422 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20423 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20424 ID3D11DeviceContext_RSSetState(context, state);
20426 test_context.vb = cw_vb;
20427 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20428 draw_color_quad(&test_context, &green);
20429 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20430 test_context.vb = ccw_vb;
20431 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20432 draw_color_quad(&test_context, &green);
20433 if (!broken_warp)
20434 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
20435 else
20436 win_skip("Broken WARP.\n");
20438 ID3D11RasterizerState_Release(state);
20440 rasterizer_desc.CullMode = D3D11_CULL_NONE;
20441 rasterizer_desc.FrontCounterClockwise = TRUE;
20442 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20443 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20444 ID3D11DeviceContext_RSSetState(context, state);
20446 test_context.vb = cw_vb;
20447 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20448 draw_color_quad(&test_context, &green);
20449 if (!broken_warp)
20450 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
20451 else
20452 win_skip("Broken WARP.\n");
20453 test_context.vb = ccw_vb;
20454 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20455 draw_color_quad(&test_context, &green);
20456 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20458 ID3D11RasterizerState_Release(state);
20460 test_context.vb = cw_vb;
20461 ID3D11Buffer_Release(ccw_vb);
20462 release_test_context(&test_context);
20465 static void test_line_antialiasing_blending(void)
20467 ID3D11RasterizerState *rasterizer_state;
20468 struct d3d11_test_context test_context;
20469 D3D11_RASTERIZER_DESC rasterizer_desc;
20470 ID3D11BlendState *blend_state;
20471 ID3D11DeviceContext *context;
20472 D3D11_BLEND_DESC blend_desc;
20473 ID3D11Device *device;
20474 HRESULT hr;
20476 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
20477 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
20479 if (!init_test_context(&test_context, NULL))
20480 return;
20482 device = test_context.device;
20483 context = test_context.immediate_context;
20485 memset(&blend_desc, 0, sizeof(blend_desc));
20486 blend_desc.AlphaToCoverageEnable = FALSE;
20487 blend_desc.IndependentBlendEnable = FALSE;
20488 blend_desc.RenderTarget[0].BlendEnable = TRUE;
20489 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
20490 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
20491 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
20492 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
20493 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
20494 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
20495 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
20497 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
20498 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
20499 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
20501 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20502 draw_color_quad(&test_context, &green);
20503 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
20505 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20506 draw_color_quad(&test_context, &red);
20507 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
20509 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
20510 ID3D11BlendState_Release(blend_state);
20512 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20513 draw_color_quad(&test_context, &green);
20514 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
20516 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20517 draw_color_quad(&test_context, &red);
20518 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
20520 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
20521 rasterizer_desc.CullMode = D3D11_CULL_BACK;
20522 rasterizer_desc.FrontCounterClockwise = FALSE;
20523 rasterizer_desc.DepthBias = 0;
20524 rasterizer_desc.DepthBiasClamp = 0.0f;
20525 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
20526 rasterizer_desc.DepthClipEnable = TRUE;
20527 rasterizer_desc.ScissorEnable = FALSE;
20528 rasterizer_desc.MultisampleEnable = FALSE;
20529 rasterizer_desc.AntialiasedLineEnable = TRUE;
20531 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
20532 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20533 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
20535 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20536 draw_color_quad(&test_context, &green);
20537 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
20539 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20540 draw_color_quad(&test_context, &red);
20541 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
20543 ID3D11RasterizerState_Release(rasterizer_state);
20544 release_test_context(&test_context);
20547 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
20548 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
20549 const char *feature_name)
20551 unsigned int i;
20553 for (i = 0; i < format_count; ++i)
20555 DXGI_FORMAT format = formats[i].format;
20556 unsigned int supported = format_support[format] & feature_flag;
20558 if (formats[i].fl_required <= feature_level)
20560 todo_wine ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
20561 format, feature_name, feature_level, format_support[format]);
20562 continue;
20565 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
20567 if (supported)
20568 trace("Optional format %#x - %s supported, feature level %#x.\n",
20569 format, feature_name, feature_level);
20570 continue;
20573 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
20574 format, feature_name, feature_level, format_support[format]);
20578 static void test_format_support(const D3D_FEATURE_LEVEL feature_level)
20580 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
20581 struct device_desc device_desc;
20582 ID3D11Device *device;
20583 DXGI_FORMAT format;
20584 ULONG refcount;
20585 UINT support;
20586 HRESULT hr;
20588 static const struct format_support index_buffers[] =
20590 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
20591 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
20594 device_desc.feature_level = &feature_level;
20595 device_desc.flags = 0;
20596 if (!(device = create_device(&device_desc)))
20598 skip("Failed to create device for feature level %#x.\n", feature_level);
20599 return;
20602 support = 0xdeadbeef;
20603 hr = ID3D11Device_CheckFormatSupport(device, ~0u, &support);
20604 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
20605 ok(!support, "Got unexpected format support %#x.\n", support);
20607 memset(format_support, 0, sizeof(format_support));
20608 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
20610 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
20611 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
20612 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
20613 format, hr, format_support[format]);
20614 if (format_support[format] & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN)
20616 ok(format_support[format] & D3D11_FORMAT_SUPPORT_TEXTURE2D,
20617 "Got unexpected format support %#x for format %#x", format_support[format], format);
20621 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
20623 if (feature_level < D3D_FEATURE_LEVEL_10_0)
20625 /* SHADER_SAMPLE_COMPARISON is never advertised as supported on feature level 9. */
20626 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON),
20627 "Unexpected SHADER_SAMPLE_COMPARISON for format %#x, feature level %#x.\n",
20628 format, feature_level);
20629 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_BUFFER),
20630 "Unexpected BUFFER for format %#x, feature level %#x.\n",
20631 format, feature_level);
20633 if (feature_level < D3D_FEATURE_LEVEL_10_1)
20635 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER),
20636 "Unexpected SHADER_GATHER for format %#x, feature level %#x.\n",
20637 format, feature_level);
20638 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON),
20639 "Unexpected SHADER_GATHER_COMPARISON for format %#x, feature level %#x.\n",
20640 format, feature_level);
20644 ok(format_support[DXGI_FORMAT_R8G8B8A8_UNORM] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE,
20645 "SHADER_SAMPLE is not supported for R8G8B8A8_UNORM.\n");
20646 todo_wine
20647 ok(!(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE),
20648 "SHADER_SAMPLE is supported for R32G32B32A32_UINT.\n");
20649 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
20651 ok(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_LOAD,
20652 "SHADER_LOAD is not supported for R32G32B32A32_UINT.\n");
20655 check_format_support(format_support, feature_level,
20656 index_buffers, ARRAY_SIZE(index_buffers),
20657 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
20659 check_format_support(format_support, feature_level,
20660 display_format_support, ARRAY_SIZE(display_format_support),
20661 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
20663 refcount = ID3D11Device_Release(device);
20664 ok(!refcount, "Device has %u references left.\n", refcount);
20667 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
20669 struct d3d11_test_context test_context;
20670 D3D11_SUBRESOURCE_DATA resource_data;
20671 D3D11_TEXTURE2D_DESC texture_desc;
20672 ID3D11ShaderResourceView *srv;
20673 ID3D11DeviceContext *context;
20674 ID3D11Texture2D *texture;
20675 ID3D11PixelShader *ps;
20676 ID3D11Device *device;
20677 HRESULT hr;
20679 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
20680 static const DWORD ps_code[] =
20682 #if 0
20683 float4 main() : SV_TARGET
20685 return float4(1.0f, 0.0f, 0.0f, 0.5f);
20687 #endif
20688 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
20689 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
20690 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
20691 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
20692 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
20693 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
20694 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
20695 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
20696 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
20697 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
20698 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
20699 0x45475241, 0xabab0054,
20701 static const DWORD ps_texture_code[] =
20703 #if 0
20704 Texture2D t;
20705 SamplerState s;
20707 float4 main() : SV_TARGET
20709 return t.Sample(s, (float2)0);
20711 #endif
20712 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
20713 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
20714 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
20715 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
20716 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
20717 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
20718 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
20719 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
20720 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
20721 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
20722 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
20723 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
20724 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
20725 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20726 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
20728 static const DWORD texture_data[] = {0xffffff00};
20730 if (!init_test_context(&test_context, &feature_level))
20731 return;
20733 device = test_context.device;
20734 context = test_context.immediate_context;
20736 texture_desc.Width = 1;
20737 texture_desc.Height = 1;
20738 texture_desc.MipLevels = 0;
20739 texture_desc.ArraySize = 1;
20740 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20741 texture_desc.SampleDesc.Count = 1;
20742 texture_desc.SampleDesc.Quality = 0;
20743 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20744 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20745 texture_desc.CPUAccessFlags = 0;
20746 texture_desc.MiscFlags = 0;
20747 resource_data.pSysMem = texture_data;
20748 resource_data.SysMemPitch = sizeof(texture_data);
20749 resource_data.SysMemSlicePitch = 0;
20750 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20751 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
20752 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
20753 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20755 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20756 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
20757 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20758 draw_quad(&test_context);
20759 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
20760 ID3D11PixelShader_Release(ps);
20762 draw_color_quad(&test_context, &color);
20763 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
20765 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
20766 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
20767 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20768 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20769 draw_quad(&test_context);
20770 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
20771 ID3D11PixelShader_Release(ps);
20773 ID3D11ShaderResourceView_Release(srv);
20774 ID3D11Texture2D_Release(texture);
20775 release_test_context(&test_context);
20778 static void queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
20779 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
20781 static const D3D_FEATURE_LEVEL feature_levels[] =
20783 D3D_FEATURE_LEVEL_11_1,
20784 D3D_FEATURE_LEVEL_11_0,
20785 D3D_FEATURE_LEVEL_10_1,
20786 D3D_FEATURE_LEVEL_10_0,
20787 D3D_FEATURE_LEVEL_9_3,
20788 D3D_FEATURE_LEVEL_9_2,
20789 D3D_FEATURE_LEVEL_9_1
20791 unsigned int i;
20793 assert(begin <= end);
20794 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
20796 if (begin <= feature_levels[i] && feature_levels[i] <= end)
20797 queue_test_fl(test_func, feature_levels[i]);
20801 static void queue_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
20803 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
20804 D3D_FEATURE_LEVEL_11_1, test_func);
20807 static void queue_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
20809 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
20810 D3D_FEATURE_LEVEL_9_3, test_func);
20813 static void test_ddy(void)
20815 static const struct
20817 struct vec4 position;
20818 unsigned int color;
20820 quad[] =
20822 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
20823 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
20824 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
20825 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
20827 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
20829 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
20830 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
20832 #if 0
20833 struct vs_data
20835 float4 pos : SV_POSITION;
20836 float4 color : COLOR;
20839 void main(in struct vs_data vs_input, out struct vs_data vs_output)
20841 vs_output.pos = vs_input.pos;
20842 vs_output.color = vs_input.color;
20844 #endif
20845 static const DWORD vs_code[] =
20847 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
20848 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20849 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
20850 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20851 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
20852 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
20853 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
20854 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
20855 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
20856 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
20857 0x0100003e,
20859 #if 0
20860 struct ps_data
20862 float4 pos : SV_POSITION;
20863 float4 color : COLOR;
20866 float4 main(struct ps_data ps_input) : SV_Target
20868 return ddy(ps_input.color) * 240.0 + 0.5;
20870 #endif
20871 static const DWORD ps_code_ddy[] =
20873 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
20874 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20875 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20876 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20877 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20878 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
20879 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
20880 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
20881 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
20882 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20884 #if 0
20885 struct ps_data
20887 float4 pos : SV_POSITION;
20888 float4 color : COLOR;
20891 float4 main(struct ps_data ps_input) : SV_Target
20893 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
20895 #endif
20896 static const DWORD ps_code_ddy_coarse[] =
20898 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
20899 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20900 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20901 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20902 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20903 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
20904 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
20905 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
20906 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
20907 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20909 #if 0
20910 struct ps_data
20912 float4 pos : SV_POSITION;
20913 float4 color : COLOR;
20916 float4 main(struct ps_data ps_input) : SV_Target
20918 return ddy_fine(ps_input.color) * 240.0 + 0.5;
20920 #endif
20921 static const DWORD ps_code_ddy_fine[] =
20923 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
20924 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20925 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20926 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20927 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20928 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
20929 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
20930 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
20931 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
20932 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20934 static const struct
20936 D3D_FEATURE_LEVEL min_feature_level;
20937 const DWORD *ps_code;
20938 unsigned int ps_code_size;
20940 tests[] =
20942 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
20943 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
20944 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
20946 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
20947 struct d3d11_test_context test_context;
20948 D3D11_TEXTURE2D_DESC texture_desc;
20949 D3D_FEATURE_LEVEL feature_level;
20950 ID3D11InputLayout *input_layout;
20951 ID3D11DeviceContext *context;
20952 unsigned int stride, offset;
20953 struct resource_readback rb;
20954 ID3D11RenderTargetView *rtv;
20955 ID3D11Texture2D *texture;
20956 ID3D11VertexShader *vs;
20957 ID3D11PixelShader *ps;
20958 ID3D11Device *device;
20959 ID3D11Buffer *vb;
20960 unsigned int i;
20961 DWORD color;
20962 HRESULT hr;
20964 if (!init_test_context(&test_context, NULL))
20965 return;
20967 device = test_context.device;
20968 context = test_context.immediate_context;
20969 feature_level = ID3D11Device_GetFeatureLevel(device);
20971 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
20972 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
20973 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20975 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
20976 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
20978 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
20979 vs_code, sizeof(vs_code), &input_layout);
20980 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
20982 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
20984 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
20985 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
20987 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
20988 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
20989 stride = sizeof(*quad);
20990 offset = 0;
20991 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
20992 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
20994 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20996 if (feature_level < tests[i].min_feature_level)
20998 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
20999 feature_level, tests[i].min_feature_level);
21000 continue;
21003 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
21004 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21006 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21008 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
21009 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
21010 ID3D11DeviceContext_Draw(context, 4, 0);
21012 get_texture_readback(texture, 0, &rb);
21013 color = get_readback_color(&rb, 320, 190, 0);
21014 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21015 color = get_readback_color(&rb, 255, 240, 0);
21016 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21017 color = get_readback_color(&rb, 320, 240, 0);
21018 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21019 color = get_readback_color(&rb, 385, 240, 0);
21020 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21021 color = get_readback_color(&rb, 320, 290, 0);
21022 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21023 release_resource_readback(&rb);
21025 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
21026 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
21027 ID3D11DeviceContext_Draw(context, 4, 0);
21029 get_texture_readback(test_context.backbuffer, 0, &rb);
21030 color = get_readback_color(&rb, 320, 190, 0);
21031 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21032 color = get_readback_color(&rb, 255, 240, 0);
21033 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21034 color = get_readback_color(&rb, 320, 240, 0);
21035 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21036 color = get_readback_color(&rb, 385, 240, 0);
21037 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21038 color = get_readback_color(&rb, 320, 290, 0);
21039 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
21040 release_resource_readback(&rb);
21042 ID3D11PixelShader_Release(ps);
21045 ID3D11VertexShader_Release(vs);
21046 ID3D11Buffer_Release(vb);
21047 ID3D11InputLayout_Release(input_layout);
21048 ID3D11Texture2D_Release(texture);
21049 ID3D11RenderTargetView_Release(rtv);
21050 release_test_context(&test_context);
21053 static void test_shader_input_registers_limits(void)
21055 struct d3d11_test_context test_context;
21056 D3D11_SUBRESOURCE_DATA resource_data;
21057 D3D11_TEXTURE2D_DESC texture_desc;
21058 D3D11_SAMPLER_DESC sampler_desc;
21059 ID3D11ShaderResourceView *srv;
21060 ID3D11DeviceContext *context;
21061 ID3D11SamplerState *sampler;
21062 ID3D11Texture2D *texture;
21063 ID3D11PixelShader *ps;
21064 ID3D11Device *device;
21065 HRESULT hr;
21067 static const DWORD ps_last_register_code[] =
21069 #if 0
21070 Texture2D t : register(t127);
21071 SamplerState s : register(s15);
21073 void main(out float4 target : SV_Target)
21075 target = t.Sample(s, float2(0, 0));
21077 #endif
21078 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
21079 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21080 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
21081 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
21082 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
21083 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
21084 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
21086 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
21087 static const DWORD texture_data[] = {0xff00ff00};
21089 if (!init_test_context(&test_context, NULL))
21090 return;
21092 device = test_context.device;
21093 context = test_context.immediate_context;
21095 texture_desc.Width = 1;
21096 texture_desc.Height = 1;
21097 texture_desc.MipLevels = 0;
21098 texture_desc.ArraySize = 1;
21099 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
21100 texture_desc.SampleDesc.Count = 1;
21101 texture_desc.SampleDesc.Quality = 0;
21102 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21103 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
21104 texture_desc.CPUAccessFlags = 0;
21105 texture_desc.MiscFlags = 0;
21107 resource_data.pSysMem = texture_data;
21108 resource_data.SysMemPitch = sizeof(texture_data);
21109 resource_data.SysMemSlicePitch = 0;
21111 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
21112 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
21114 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
21115 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
21117 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
21118 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
21119 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
21120 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
21121 sampler_desc.MipLODBias = 0.0f;
21122 sampler_desc.MaxAnisotropy = 0;
21123 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
21124 sampler_desc.BorderColor[0] = 0.0f;
21125 sampler_desc.BorderColor[1] = 0.0f;
21126 sampler_desc.BorderColor[2] = 0.0f;
21127 sampler_desc.BorderColor[3] = 0.0f;
21128 sampler_desc.MinLOD = 0.0f;
21129 sampler_desc.MaxLOD = 0.0f;
21131 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
21132 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
21134 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
21135 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21136 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21138 ID3D11DeviceContext_PSSetShaderResources(context,
21139 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
21140 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
21141 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
21142 draw_quad(&test_context);
21143 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
21145 ID3D11PixelShader_Release(ps);
21146 ID3D11SamplerState_Release(sampler);
21147 ID3D11ShaderResourceView_Release(srv);
21148 ID3D11Texture2D_Release(texture);
21149 release_test_context(&test_context);
21152 static void test_unbind_shader_resource_view(void)
21154 struct d3d11_test_context test_context;
21155 D3D11_SUBRESOURCE_DATA resource_data;
21156 ID3D11ShaderResourceView *srv, *srv2;
21157 D3D11_TEXTURE2D_DESC texture_desc;
21158 ID3D11DeviceContext *context;
21159 ID3D11Texture2D *texture;
21160 ID3D11PixelShader *ps;
21161 ID3D11Device *device;
21162 HRESULT hr;
21164 static const DWORD ps_code[] =
21166 #if 0
21167 Texture2D t0;
21168 Texture2D t1;
21169 SamplerState s;
21171 float4 main() : SV_Target
21173 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
21175 #endif
21176 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
21177 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21178 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
21179 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
21180 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
21181 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
21182 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21183 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
21184 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
21185 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
21186 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
21187 0x3f800000, 0x0100003e,
21189 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
21190 static const DWORD texture_data[] = {0xff00ff00};
21192 if (!init_test_context(&test_context, NULL))
21193 return;
21195 device = test_context.device;
21196 context = test_context.immediate_context;
21198 texture_desc.Width = 1;
21199 texture_desc.Height = 1;
21200 texture_desc.MipLevels = 0;
21201 texture_desc.ArraySize = 1;
21202 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
21203 texture_desc.SampleDesc.Count = 1;
21204 texture_desc.SampleDesc.Quality = 0;
21205 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21206 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
21207 texture_desc.CPUAccessFlags = 0;
21208 texture_desc.MiscFlags = 0;
21210 resource_data.pSysMem = texture_data;
21211 resource_data.SysMemPitch = sizeof(texture_data);
21212 resource_data.SysMemSlicePitch = 0;
21214 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
21215 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
21216 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
21217 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
21218 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
21219 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
21220 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21222 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
21223 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
21224 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
21225 draw_quad(&test_context);
21226 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
21228 srv2 = NULL;
21229 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
21230 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
21231 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
21232 draw_quad(&test_context);
21233 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
21235 ID3D11PixelShader_Release(ps);
21236 ID3D11ShaderResourceView_Release(srv);
21237 ID3D11Texture2D_Release(texture);
21238 release_test_context(&test_context);
21241 static void test_stencil_separate(void)
21243 struct d3d11_test_context test_context;
21244 D3D11_TEXTURE2D_DESC texture_desc;
21245 D3D11_DEPTH_STENCIL_DESC ds_desc;
21246 ID3D11DepthStencilState *ds_state;
21247 ID3D11DepthStencilView *ds_view;
21248 D3D11_RASTERIZER_DESC rs_desc;
21249 ID3D11DeviceContext *context;
21250 ID3D11RasterizerState *rs;
21251 ID3D11Texture2D *texture;
21252 ID3D11Device *device;
21253 HRESULT hr;
21255 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
21256 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
21257 static const struct vec3 ccw_quad[] =
21259 {-1.0f, -1.0f, 0.0f},
21260 { 1.0f, -1.0f, 0.0f},
21261 {-1.0f, 1.0f, 0.0f},
21262 { 1.0f, 1.0f, 0.0f},
21265 if (!init_test_context(&test_context, NULL))
21266 return;
21268 device = test_context.device;
21269 context = test_context.immediate_context;
21271 texture_desc.Width = 640;
21272 texture_desc.Height = 480;
21273 texture_desc.MipLevels = 1;
21274 texture_desc.ArraySize = 1;
21275 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
21276 texture_desc.SampleDesc.Count = 1;
21277 texture_desc.SampleDesc.Quality = 0;
21278 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21279 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
21280 texture_desc.CPUAccessFlags = 0;
21281 texture_desc.MiscFlags = 0;
21282 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21283 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21284 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
21285 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
21287 ds_desc.DepthEnable = TRUE;
21288 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
21289 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
21290 ds_desc.StencilEnable = TRUE;
21291 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
21292 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
21293 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
21294 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
21295 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
21296 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
21297 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
21298 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
21299 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
21300 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
21301 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
21302 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
21304 rs_desc.FillMode = D3D11_FILL_SOLID;
21305 rs_desc.CullMode = D3D11_CULL_NONE;
21306 rs_desc.FrontCounterClockwise = FALSE;
21307 rs_desc.DepthBias = 0;
21308 rs_desc.DepthBiasClamp = 0.0f;
21309 rs_desc.SlopeScaledDepthBias = 0.0f;
21310 rs_desc.DepthClipEnable = TRUE;
21311 rs_desc.ScissorEnable = FALSE;
21312 rs_desc.MultisampleEnable = FALSE;
21313 rs_desc.AntialiasedLineEnable = FALSE;
21314 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
21315 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
21317 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
21318 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
21319 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
21320 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
21321 ID3D11DeviceContext_RSSetState(context, rs);
21323 draw_color_quad(&test_context, &green);
21324 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
21326 ID3D11Buffer_Release(test_context.vb);
21327 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
21329 draw_color_quad(&test_context, &green);
21330 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
21332 ID3D11RasterizerState_Release(rs);
21333 rs_desc.FrontCounterClockwise = TRUE;
21334 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
21335 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
21336 ID3D11DeviceContext_RSSetState(context, rs);
21338 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
21339 draw_color_quad(&test_context, &green);
21340 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
21342 ID3D11DepthStencilState_Release(ds_state);
21343 ID3D11DepthStencilView_Release(ds_view);
21344 ID3D11RasterizerState_Release(rs);
21345 ID3D11Texture2D_Release(texture);
21346 release_test_context(&test_context);
21349 static void test_uav_load(void)
21351 struct shader
21353 const DWORD *code;
21354 size_t size;
21356 struct texture
21358 UINT width;
21359 UINT height;
21360 UINT miplevel_count;
21361 UINT array_size;
21362 DXGI_FORMAT format;
21363 D3D11_SUBRESOURCE_DATA data[3];
21366 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
21367 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21368 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
21369 struct d3d11_test_context test_context;
21370 const struct texture *current_texture;
21371 ID3D11Texture2D *texture, *rt_texture;
21372 D3D11_TEXTURE2D_DESC texture_desc;
21373 const struct shader *current_ps;
21374 ID3D11UnorderedAccessView *uav;
21375 ID3D11DeviceContext *context;
21376 struct resource_readback rb;
21377 ID3D11PixelShader *ps;
21378 ID3D11Device *device;
21379 unsigned int i, x, y;
21380 ID3D11Buffer *cb;
21381 HRESULT hr;
21383 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
21384 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21385 static const DWORD ps_ld_2d_float_code[] =
21387 #if 0
21388 RWTexture2D<float> u;
21390 float main(float4 position : SV_Position) : SV_Target
21392 float2 s;
21393 u.GetDimensions(s.x, s.y);
21394 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21396 #endif
21397 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
21398 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21399 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21400 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21401 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21402 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
21403 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21404 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21405 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21406 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21407 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21408 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21409 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21411 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
21412 static const DWORD ps_ld_2d_uint_code[] =
21414 #if 0
21415 RWTexture2D<uint> u;
21417 uint main(float4 position : SV_Position) : SV_Target
21419 float2 s;
21420 u.GetDimensions(s.x, s.y);
21421 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21423 #endif
21424 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
21425 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21426 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21427 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
21428 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21429 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
21430 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21431 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21432 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21433 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21434 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21435 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21436 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21438 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
21439 static const DWORD ps_ld_2d_int_code[] =
21441 #if 0
21442 RWTexture2D<int> u;
21444 int main(float4 position : SV_Position) : SV_Target
21446 float2 s;
21447 u.GetDimensions(s.x, s.y);
21448 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21450 #endif
21451 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
21452 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21453 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21454 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
21455 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21456 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
21457 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21458 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21459 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21460 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21461 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21462 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21463 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21465 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
21466 static const DWORD ps_ld_2d_uint_arr_code[] =
21468 #if 0
21469 RWTexture2DArray<uint> u;
21471 uint layer;
21473 uint main(float4 position : SV_Position) : SV_Target
21475 float3 s;
21476 u.GetDimensions(s.x, s.y, s.z);
21477 s.z = layer;
21478 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
21480 #endif
21481 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
21482 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21483 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21484 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
21485 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
21486 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
21487 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
21488 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
21489 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
21490 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
21491 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
21492 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
21493 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
21494 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21496 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
21497 static const float float_data[] =
21499 0.50f, 0.25f, 1.00f, 0.00f,
21500 -1.00f, -2.00f, -3.00f, -4.00f,
21501 -0.50f, -0.25f, -1.00f, -0.00f,
21502 1.00f, 2.00f, 3.00f, 4.00f,
21504 static const unsigned int uint_data[] =
21506 0x00, 0x10, 0x20, 0x30,
21507 0x40, 0x50, 0x60, 0x70,
21508 0x80, 0x90, 0xa0, 0xb0,
21509 0xc0, 0xd0, 0xe0, 0xf0,
21511 static const unsigned int uint_data2[] =
21513 0xffff, 0xffff, 0xffff, 0xffff,
21514 0xffff, 0xc000, 0xc000, 0xffff,
21515 0xffff, 0xc000, 0xc000, 0xffff,
21516 0xffff, 0xffff, 0xffff, 0xffff,
21518 static const unsigned int uint_data3[] =
21520 0xaa, 0xaa, 0xcc, 0xcc,
21521 0xaa, 0xaa, 0xdd, 0xdd,
21522 0xbb, 0xbb, 0xee, 0xee,
21523 0xbb, 0xbb, 0xff, 0xff,
21525 static const int int_data[] =
21527 -1, 0x10, 0x20, 0x30,
21528 0x40, 0x50, 0x60, -777,
21529 -666, 0x90, -555, 0xb0,
21530 0xc0, 0xd0, 0xe0, -101,
21532 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
21533 {{float_data, 4 * sizeof(*float_data), 0}}};
21534 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
21535 {{uint_data, 4 * sizeof(*uint_data), 0}}};
21536 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
21537 {{uint_data, 4 * sizeof(*uint_data), 0},
21538 {uint_data2, 4 * sizeof(*uint_data2), 0},
21539 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
21540 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
21541 {{int_data, 4 * sizeof(*int_data), 0}}};
21543 static const struct test
21545 const struct shader *ps;
21546 const struct texture *texture;
21547 struct uav_desc uav_desc;
21548 struct uvec4 constant;
21549 const DWORD *expected_colors;
21551 tests[] =
21553 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
21554 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
21555 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
21556 #define R32_UINT DXGI_FORMAT_R32_UINT
21557 #define R32_SINT DXGI_FORMAT_R32_SINT
21558 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {0}, (const DWORD *)float_data},
21559 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {0}, (const DWORD *)uint_data},
21560 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {0}, (const DWORD *)int_data},
21561 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
21562 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
21563 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
21564 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
21565 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
21566 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
21567 #undef TEX_2D
21568 #undef TEX_2D_ARRAY
21569 #undef R32_FLOAT
21570 #undef R32_UINT
21571 #undef R32_SINT
21574 if (!init_test_context(&test_context, &feature_level))
21575 return;
21577 device = test_context.device;
21578 context = test_context.immediate_context;
21580 texture_desc.Width = 640;
21581 texture_desc.Height = 480;
21582 texture_desc.MipLevels = 1;
21583 texture_desc.ArraySize = 1;
21584 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
21585 texture_desc.SampleDesc.Count = 1;
21586 texture_desc.SampleDesc.Quality = 0;
21587 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21588 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21589 texture_desc.CPUAccessFlags = 0;
21590 texture_desc.MiscFlags = 0;
21591 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
21592 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21594 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
21595 U(rtv_desc).Texture2D.MipSlice = 0;
21597 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
21598 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
21599 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21601 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
21602 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
21603 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21605 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
21606 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
21607 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21609 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21611 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
21612 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21614 ps = NULL;
21615 uav = NULL;
21616 texture = NULL;
21617 current_ps = NULL;
21618 current_texture = NULL;
21619 for (i = 0; i < ARRAY_SIZE(tests); ++i)
21621 const struct test *test = &tests[i];
21622 ID3D11RenderTargetView *current_rtv;
21624 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21625 NULL, &test->constant, 0, 0);
21627 if (current_ps != test->ps)
21629 if (ps)
21630 ID3D11PixelShader_Release(ps);
21632 current_ps = test->ps;
21634 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
21635 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
21637 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21640 if (current_texture != test->texture)
21642 if (texture)
21643 ID3D11Texture2D_Release(texture);
21645 current_texture = test->texture;
21647 texture_desc.Width = current_texture->width;
21648 texture_desc.Height = current_texture->height;
21649 texture_desc.MipLevels = current_texture->miplevel_count;
21650 texture_desc.ArraySize = current_texture->array_size;
21651 texture_desc.Format = current_texture->format;
21653 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
21654 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
21657 if (uav)
21658 ID3D11UnorderedAccessView_Release(uav);
21660 get_uav_desc(&uav_desc, &test->uav_desc);
21661 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
21662 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
21664 switch (uav_desc.Format)
21666 case DXGI_FORMAT_R32_FLOAT:
21667 current_rtv = rtv_float;
21668 break;
21669 case DXGI_FORMAT_R32_UINT:
21670 current_rtv = rtv_uint;
21671 break;
21672 case DXGI_FORMAT_R32_SINT:
21673 current_rtv = rtv_sint;
21674 break;
21675 default:
21676 trace("Unhandled format %#x.\n", uav_desc.Format);
21677 current_rtv = NULL;
21678 break;
21681 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
21683 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
21684 1, 1, &uav, NULL);
21686 draw_quad(&test_context);
21688 get_texture_readback(rt_texture, 0, &rb);
21689 for (y = 0; y < 4; ++y)
21691 for (x = 0; x < 4; ++x)
21693 DWORD expected = test->expected_colors[y * 4 + x];
21694 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
21695 ok(compare_color(color, expected, 0),
21696 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
21697 i, color, expected, x, y);
21700 release_resource_readback(&rb);
21702 ID3D11PixelShader_Release(ps);
21703 ID3D11Texture2D_Release(texture);
21704 ID3D11UnorderedAccessView_Release(uav);
21706 ID3D11Buffer_Release(cb);
21707 ID3D11RenderTargetView_Release(rtv_float);
21708 ID3D11RenderTargetView_Release(rtv_sint);
21709 ID3D11RenderTargetView_Release(rtv_uint);
21710 ID3D11Texture2D_Release(rt_texture);
21711 release_test_context(&test_context);
21714 static void test_cs_uav_store(void)
21716 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21717 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21718 static const float zero[4] = {0.0f};
21719 D3D11_TEXTURE2D_DESC texture_desc;
21720 ID3D11UnorderedAccessView *uav;
21721 struct device_desc device_desc;
21722 ID3D11DeviceContext *context;
21723 struct vec4 input = {1.0f};
21724 ID3D11Texture2D *texture;
21725 ID3D11ComputeShader *cs;
21726 ID3D11Device *device;
21727 ID3D11Buffer *cb;
21728 ULONG refcount;
21729 HRESULT hr;
21730 RECT rect;
21732 static const DWORD cs_1_thread_code[] =
21734 #if 0
21735 RWTexture2D<float> u;
21737 float value;
21739 [numthreads(1, 1, 1)]
21740 void main()
21742 uint x, y, width, height;
21743 u.GetDimensions(width, height);
21744 for (y = 0; y < height; ++y)
21746 for (x = 0; x < width; ++x)
21747 u[uint2(x, y)] = value;
21750 #endif
21751 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
21752 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21753 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
21754 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21755 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
21756 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
21757 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
21758 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
21759 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
21760 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
21761 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
21762 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
21763 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
21764 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
21765 0x01000016, 0x0100003e,
21767 static const DWORD cs_1_group_code[] =
21769 #if 0
21770 RWTexture2D<float> u;
21772 float value;
21774 [numthreads(16, 16, 1)]
21775 void main(uint3 threadID : SV_GroupThreadID)
21777 uint2 count, size ;
21778 u.GetDimensions(size.x, size.y);
21779 count = size / (uint2)16;
21780 for (uint y = 0; y < count.y; ++y)
21781 for (uint x = 0; x < count.x; ++x)
21782 u[count * threadID.xy + uint2(x, y)] = value;
21784 #endif
21785 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
21786 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21787 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
21788 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21789 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
21790 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
21791 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
21792 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
21793 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
21794 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
21795 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
21796 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
21797 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
21798 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
21799 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
21800 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
21801 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
21803 static const DWORD cs_1_store_code[] =
21805 #if 0
21806 RWTexture2D<float> u;
21808 float value;
21810 [numthreads(1, 1, 1)]
21811 void main(uint3 groupID : SV_GroupID)
21813 u[groupID.xy] = value;
21815 #endif
21816 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
21817 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21818 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21819 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21820 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
21821 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
21823 static const DWORD cs_dispatch_id_code[] =
21825 #if 0
21826 RWTexture2D<float> u;
21828 float value;
21830 [numthreads(4, 4, 1)]
21831 void main(uint3 id : SV_DispatchThreadID)
21833 u[id.xy] = value;
21835 #endif
21836 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
21837 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21838 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21839 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21840 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
21841 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
21843 static const DWORD cs_group_index_code[] =
21845 #if 0
21846 RWTexture2D<float> u;
21848 float value;
21850 [numthreads(32, 1, 1)]
21851 void main(uint index : SV_GroupIndex)
21853 uint2 size;
21854 u.GetDimensions(size.x, size.y);
21855 uint count = size.x * size.y / 32;
21856 index *= count;
21857 for (uint i = 0; i < count; ++i, ++index)
21858 u[uint2(index % size.x, index / size.x)] = value;
21860 #endif
21861 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
21862 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21863 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
21864 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21865 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
21866 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
21867 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
21868 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
21869 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
21870 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
21871 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
21872 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
21873 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
21874 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
21875 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
21876 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
21879 device_desc.feature_level = &feature_level;
21880 device_desc.flags = 0;
21881 if (!(device = create_device(&device_desc)))
21883 skip("Failed to create device for feature level %#x.\n", feature_level);
21884 return;
21887 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
21889 texture_desc.Width = 64;
21890 texture_desc.Height = 64;
21891 texture_desc.MipLevels = 1;
21892 texture_desc.ArraySize = 1;
21893 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
21894 texture_desc.SampleDesc.Count = 1;
21895 texture_desc.SampleDesc.Quality = 0;
21896 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21897 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21898 texture_desc.CPUAccessFlags = 0;
21899 texture_desc.MiscFlags = 0;
21901 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21902 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21904 uav_desc.Format = texture_desc.Format;
21905 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
21906 U(uav_desc).Texture2D.MipSlice = 0;
21908 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
21909 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21911 ID3D11Device_GetImmediateContext(device, &context);
21913 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
21914 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21916 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
21917 check_texture_float(texture, 0.0f, 2);
21919 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
21920 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21921 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21923 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21924 check_texture_float(texture, 1.0f, 2);
21926 input.x = 0.5f;
21927 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21928 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21929 check_texture_float(texture, 0.5f, 2);
21931 ID3D11ComputeShader_Release(cs);
21933 input.x = 2.0f;
21934 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21935 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
21936 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21937 check_texture_float(texture, 0.5f, 2);
21939 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
21940 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21941 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21943 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21944 check_texture_float(texture, 2.0f, 2);
21946 input.x = 4.0f;
21947 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21948 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21949 check_texture_float(texture, 4.0f, 2);
21951 ID3D11ComputeShader_Release(cs);
21953 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
21954 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21955 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21957 input.x = 1.0f;
21958 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21959 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
21960 check_texture_float(texture, 1.0f, 2);
21962 input.x = 0.5f;
21963 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21964 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
21965 SetRect(&rect, 0, 0, 16, 32);
21966 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
21967 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
21968 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21969 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
21970 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21972 ID3D11ComputeShader_Release(cs);
21974 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
21975 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21976 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21978 input.x = 0.6f;
21979 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21980 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
21981 SetRect(&rect, 0, 0, 60, 60);
21982 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
21983 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
21984 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21985 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
21986 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21988 input.x = 0.7f;
21989 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21990 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
21991 check_texture_float(texture, 0.7f, 2);
21993 ID3D11ComputeShader_Release(cs);
21995 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
21996 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21997 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21999 input.x = 0.3f;
22000 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
22001 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22002 check_texture_float(texture, 0.3f, 2);
22004 input.x = 0.1f;
22005 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
22006 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
22007 check_texture_float(texture, 0.1f, 2);
22009 ID3D11ComputeShader_Release(cs);
22011 ID3D11Buffer_Release(cb);
22012 ID3D11Texture2D_Release(texture);
22013 ID3D11UnorderedAccessView_Release(uav);
22014 ID3D11DeviceContext_Release(context);
22015 refcount = ID3D11Device_Release(device);
22016 ok(!refcount, "Device has %u references left.\n", refcount);
22019 static void test_uav_store_immediate_constant(void)
22021 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22022 struct d3d11_test_context test_context;
22023 D3D11_TEXTURE2D_DESC texture_desc;
22024 ID3D11UnorderedAccessView *uav;
22025 ID3D11DeviceContext *context;
22026 struct resource_readback rb;
22027 ID3D11Texture2D *texture;
22028 ID3D11ComputeShader *cs;
22029 unsigned int uint_data;
22030 ID3D11Device *device;
22031 ID3D11Buffer *buffer;
22032 float float_data;
22033 int int_data;
22034 HRESULT hr;
22036 static const DWORD cs_store_int_code[] =
22038 #if 0
22039 RWBuffer<int> u;
22041 [numthreads(1, 1, 1)]
22042 void main()
22044 u[0] = 42;
22046 #endif
22047 0x43425844, 0x7246d785, 0x3f4ccbd6, 0x6a7cdbc0, 0xe2b58c72, 0x00000001, 0x000000b8, 0x00000003,
22048 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22049 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
22050 0x0400089c, 0x0011e000, 0x00000000, 0x00003333, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22051 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
22052 0x00004002, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, 0x0100003e,
22054 static const DWORD cs_store_float_code[] =
22056 #if 0
22057 RWBuffer<float> u;
22059 [numthreads(1, 1, 1)]
22060 void main()
22062 u[0] = 1.0;
22064 #endif
22065 0x43425844, 0x525eea68, 0xc4cd5716, 0xc588f9c4, 0x0da27c5a, 0x00000001, 0x000000b8, 0x00000003,
22066 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22067 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
22068 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22069 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
22070 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
22072 static const DWORD cs_store_unorm_code[] =
22074 #if 0
22075 RWTexture2D<unorm float> u;
22077 [numthreads(1, 1, 1)]
22078 void main()
22080 u[uint2(0, 0)] = 0.5f;
22082 #endif
22083 0x43425844, 0x3623f1de, 0xe847109e, 0x8e3da13f, 0xb6787b06, 0x00000001, 0x000000b8, 0x00000003,
22084 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22085 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
22086 0x0400189c, 0x0011e000, 0x00000000, 0x00001111, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22087 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
22088 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
22090 static const DWORD cs_store_snorm_code[] =
22092 #if 0
22093 RWTexture2D<snorm float> u;
22095 [numthreads(1, 1, 1)]
22096 void main()
22098 u[uint2(0, 0)] = -0.5f;
22100 #endif
22101 0x43425844, 0xce5397fc, 0x7464bc06, 0xc79aa56c, 0x881bd7ef, 0x00000001, 0x000000b8, 0x00000003,
22102 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22103 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
22104 0x0400189c, 0x0011e000, 0x00000000, 0x00002222, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22105 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
22106 0x00004002, 0xbf000000, 0xbf000000, 0xbf000000, 0xbf000000, 0x0100003e,
22108 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22109 static const unsigned int zero[4] = {0};
22111 if (!init_test_context(&test_context, &feature_level))
22112 return;
22114 device = test_context.device;
22115 context = test_context.immediate_context;
22117 buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
22119 uav_desc.Format = DXGI_FORMAT_R32_SINT;
22120 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
22121 U(uav_desc).Buffer.FirstElement = 0;
22122 U(uav_desc).Buffer.NumElements = 1;
22123 U(uav_desc).Buffer.Flags = 0;
22124 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
22125 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22126 hr = ID3D11Device_CreateComputeShader(device, cs_store_int_code, sizeof(cs_store_int_code), NULL, &cs);
22127 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22129 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
22130 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22131 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22132 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22133 get_buffer_readback(buffer, &rb);
22134 int_data = get_readback_color(&rb, 0, 0, 0);
22135 ok(int_data == 42, "Got unexpected value %u.\n", int_data);
22136 release_resource_readback(&rb);
22138 ID3D11ComputeShader_Release(cs);
22139 ID3D11UnorderedAccessView_Release(uav);
22140 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
22141 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
22142 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22143 hr = ID3D11Device_CreateComputeShader(device, cs_store_float_code, sizeof(cs_store_float_code), NULL, &cs);
22144 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22146 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
22147 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22148 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22149 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22150 get_buffer_readback(buffer, &rb);
22151 float_data = get_readback_float(&rb, 0, 0);
22152 ok(float_data == 1.0f, "Got unexpected value %.8e.\n", float_data);
22153 release_resource_readback(&rb);
22155 texture_desc.Width = 64;
22156 texture_desc.Height = 64;
22157 texture_desc.MipLevels = 1;
22158 texture_desc.ArraySize = 1;
22159 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
22160 texture_desc.SampleDesc.Count = 1;
22161 texture_desc.SampleDesc.Quality = 0;
22162 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22163 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22164 texture_desc.CPUAccessFlags = 0;
22165 texture_desc.MiscFlags = 0;
22166 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22167 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
22168 ID3D11UnorderedAccessView_Release(uav);
22169 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
22170 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
22172 ID3D11ComputeShader_Release(cs);
22173 hr = ID3D11Device_CreateComputeShader(device, cs_store_unorm_code, sizeof(cs_store_unorm_code), NULL, &cs);
22174 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
22175 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
22176 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22177 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22178 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22179 get_texture_readback(texture, 0, &rb);
22180 uint_data = get_readback_color(&rb, 0, 0, 0);
22181 ok(compare_color(uint_data, 0x80808080, 1), "Got unexpected color 0x%08x.\n", uint_data);
22182 release_resource_readback(&rb);
22184 ID3D11Texture2D_Release(texture);
22185 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_SNORM;
22186 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
22187 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
22188 ID3D11UnorderedAccessView_Release(uav);
22189 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
22190 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
22192 ID3D11ComputeShader_Release(cs);
22193 hr = ID3D11Device_CreateComputeShader(device, cs_store_snorm_code, sizeof(cs_store_snorm_code), NULL, &cs);
22194 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
22195 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
22196 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22197 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
22198 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22199 get_texture_readback(texture, 0, &rb);
22200 uint_data = get_readback_color(&rb, 0, 0, 0);
22201 ok(compare_color(uint_data, 0xc0c0c0c0, 1), "Got unexpected color 0x%08x.\n", uint_data);
22202 release_resource_readback(&rb);
22204 ID3D11Buffer_Release(buffer);
22205 ID3D11Texture2D_Release(texture);
22206 ID3D11ComputeShader_Release(cs);
22207 ID3D11UnorderedAccessView_Release(uav);
22208 release_test_context(&test_context);
22211 static void test_ps_cs_uav_binding(void)
22213 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22214 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
22215 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22216 ID3D11Texture2D *cs_texture, *ps_texture;
22217 struct d3d11_test_context test_context;
22218 static const float zero[4] = {0.0f};
22219 D3D11_TEXTURE2D_DESC texture_desc;
22220 ID3D11DeviceContext *context;
22221 ID3D11Buffer *cs_cb, *ps_cb;
22222 struct vec4 input = {1.0f};
22223 ID3D11ComputeShader *cs;
22224 ID3D11PixelShader *ps;
22225 ID3D11Device *device;
22226 HRESULT hr;
22228 static const DWORD cs_code[] =
22230 #if 0
22231 RWTexture2D<float> u;
22233 float value;
22235 [numthreads(1, 1, 1)]
22236 void main()
22238 uint x, y, width, height;
22239 u.GetDimensions(width, height);
22240 for (y = 0; y < height; ++y)
22242 for (x = 0; x < width; ++x)
22243 u[uint2(x, y)] = value;
22246 #endif
22247 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
22248 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22249 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
22250 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
22251 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
22252 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
22253 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
22254 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
22255 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
22256 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
22257 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
22258 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
22259 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
22260 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
22261 0x01000016, 0x0100003e,
22263 static const DWORD ps_code[] =
22265 #if 0
22266 RWTexture2D<float> u : register(u1);
22268 float value;
22270 void main()
22272 uint x, y, width, height;
22273 u.GetDimensions(width, height);
22274 for (y = 0; y < height; ++y)
22276 for (x = 0; x < width; ++x)
22277 u[uint2(x, y)] = value;
22280 #endif
22281 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
22282 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22283 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
22284 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
22285 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
22286 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
22287 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
22288 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
22289 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
22290 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
22291 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
22292 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
22293 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
22294 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
22297 if (!init_test_context(&test_context, &feature_level))
22298 return;
22300 device = test_context.device;
22301 context = test_context.immediate_context;
22303 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
22304 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
22306 texture_desc.Width = 64;
22307 texture_desc.Height = 64;
22308 texture_desc.MipLevels = 1;
22309 texture_desc.ArraySize = 1;
22310 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
22311 texture_desc.SampleDesc.Count = 1;
22312 texture_desc.SampleDesc.Quality = 0;
22313 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22314 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22315 texture_desc.CPUAccessFlags = 0;
22316 texture_desc.MiscFlags = 0;
22317 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
22318 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22319 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
22320 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22322 uav_desc.Format = texture_desc.Format;
22323 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
22324 U(uav_desc).Texture2D.MipSlice = 0;
22325 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
22326 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22327 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
22328 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22330 ID3D11Device_GetImmediateContext(device, &context);
22332 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
22333 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
22334 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
22335 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
22336 0, NULL, NULL, 1, 1, &ps_uav, NULL);
22338 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
22339 check_texture_float(cs_texture, 0.0f, 2);
22340 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
22341 check_texture_float(ps_texture, 0.0f, 2);
22343 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
22344 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22345 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22346 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22347 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22348 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22350 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22351 check_texture_float(cs_texture, 1.0f, 2);
22352 check_texture_float(ps_texture, 0.0f, 2);
22353 draw_quad(&test_context);
22354 check_texture_float(cs_texture, 1.0f, 2);
22355 check_texture_float(ps_texture, 1.0f, 2);
22357 input.x = 0.5f;
22358 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
22359 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22360 check_texture_float(cs_texture, 0.5f, 2);
22361 check_texture_float(ps_texture, 1.0f, 2);
22362 input.x = 2.0f;
22363 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
22364 draw_quad(&test_context);
22365 check_texture_float(cs_texture, 0.5f, 2);
22366 check_texture_float(ps_texture, 2.0f, 2);
22368 input.x = 8.0f;
22369 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
22370 input.x = 4.0f;
22371 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
22372 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22373 check_texture_float(cs_texture, 8.0f, 2);
22374 check_texture_float(ps_texture, 2.0f, 2);
22375 draw_quad(&test_context);
22376 check_texture_float(cs_texture, 8.0f, 2);
22377 check_texture_float(ps_texture, 4.0f, 2);
22379 ID3D11ComputeShader_Release(cs);
22380 ID3D11PixelShader_Release(ps);
22381 ID3D11Buffer_Release(cs_cb);
22382 ID3D11Buffer_Release(ps_cb);
22383 ID3D11Texture2D_Release(cs_texture);
22384 ID3D11Texture2D_Release(ps_texture);
22385 ID3D11UnorderedAccessView_Release(cs_uav);
22386 ID3D11UnorderedAccessView_Release(ps_uav);
22387 ID3D11DeviceContext_Release(context);
22388 release_test_context(&test_context);
22391 static void test_atomic_instructions(void)
22393 ID3D11UnorderedAccessView *in_uav, *out_uav;
22394 ID3D11Buffer *cb, *in_buffer, *out_buffer;
22395 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22396 struct d3d11_test_context test_context;
22397 struct resource_readback rb, out_rb;
22398 D3D11_BUFFER_DESC buffer_desc;
22399 ID3D11DeviceContext *context;
22400 ID3D11ComputeShader *cs;
22401 ID3D11PixelShader *ps;
22402 ID3D11Device *device;
22403 unsigned int i, j;
22404 HRESULT hr;
22406 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22407 static const unsigned int zero[4] = {0, 0, 0, 0};
22408 static const DWORD ps_atomics_code[] =
22410 #if 0
22411 RWByteAddressBuffer u;
22413 uint4 v;
22414 int4 i;
22416 void main()
22418 u.InterlockedAnd(0 * 4, v.x);
22419 u.InterlockedCompareStore(1 * 4, v.y, v.x);
22420 u.InterlockedAdd(2 * 4, v.x);
22421 u.InterlockedOr(3 * 4, v.x);
22422 u.InterlockedMax(4 * 4, i.x);
22423 u.InterlockedMin(5 * 4, i.x);
22424 u.InterlockedMax(6 * 4, v.x);
22425 u.InterlockedMin(7 * 4, v.x);
22426 u.InterlockedXor(8 * 4, v.x);
22428 #endif
22429 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
22430 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22431 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
22432 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
22433 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
22434 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
22435 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
22436 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
22437 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
22438 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
22439 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
22440 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
22441 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
22442 0x00000000, 0x00000000, 0x0100003e,
22444 static const DWORD cs_atomics_code[] =
22446 #if 0
22447 RWByteAddressBuffer u;
22448 RWByteAddressBuffer u2;
22450 uint4 v;
22451 int4 i;
22453 [numthreads(1, 1, 1)]
22454 void main()
22456 uint r;
22457 u.InterlockedAnd(0 * 4, v.x, r);
22458 u2.Store(0 * 4, r);
22459 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
22460 u2.Store(1 * 4, r);
22461 u.InterlockedAdd(2 * 4, v.x, r);
22462 u2.Store(2 * 4, r);
22463 u.InterlockedOr(3 * 4, v.x, r);
22464 u2.Store(3 * 4, r);
22465 u.InterlockedMax(4 * 4, i.x, r);
22466 u2.Store(4 * 4, r);
22467 u.InterlockedMin(5 * 4, i.x, r);
22468 u2.Store(5 * 4, r);
22469 u.InterlockedMax(6 * 4, v.x, r);
22470 u2.Store(6 * 4, r);
22471 u.InterlockedMin(7 * 4, v.x, r);
22472 u2.Store(7 * 4, r);
22473 u.InterlockedXor(8 * 4, v.x, r);
22474 u2.Store(8 * 4, r);
22476 #endif
22477 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
22478 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22479 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
22480 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
22481 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22482 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
22483 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
22484 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
22485 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
22486 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
22487 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
22488 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
22489 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
22490 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
22491 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
22492 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
22493 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
22494 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
22495 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
22496 0x0010000a, 0x00000000, 0x0100003e,
22499 static const char * const instructions[] =
22501 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
22502 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
22504 static const char * const imm_instructions[] =
22506 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
22507 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
22509 static const struct test
22511 struct uvec4 v;
22512 struct ivec4 i;
22513 unsigned int input[ARRAY_SIZE(instructions)];
22514 unsigned int expected_result[ARRAY_SIZE(instructions)];
22516 tests[] =
22518 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
22519 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
22522 if (!init_test_context(&test_context, &feature_level))
22523 return;
22525 device = test_context.device;
22526 context = test_context.immediate_context;
22528 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
22529 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22530 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
22532 buffer_desc.ByteWidth = sizeof(tests->input);
22533 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
22534 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22535 buffer_desc.CPUAccessFlags = 0;
22536 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
22537 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
22538 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22539 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
22540 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22542 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
22543 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
22544 U(uav_desc).Buffer.FirstElement = 0;
22545 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
22546 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
22547 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
22548 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22549 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
22550 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22552 set_viewport(context, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f);
22554 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
22555 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22556 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22558 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
22559 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22560 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22562 for (i = 0; i < ARRAY_SIZE(tests); ++i)
22564 const struct test *test = &tests[i];
22566 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22567 NULL, &test->v, 0, 0);
22569 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
22570 NULL, test->input, 0, 0);
22572 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
22573 0, 1, &in_uav, NULL);
22575 draw_quad(&test_context);
22576 get_buffer_readback(in_buffer, &rb);
22577 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
22579 unsigned int value = get_readback_color(&rb, j, 0, 0);
22580 unsigned int expected = test->expected_result[j];
22582 todo_wine_if(expected != test->input[j]
22583 && (!strcmp(instructions[j], "atomic_imax")
22584 || !strcmp(instructions[j], "atomic_imin")))
22585 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
22586 "with inputs (%u, %u), (%d), %#x (%d).\n",
22587 i, value, value, expected, expected, instructions[j],
22588 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
22590 release_resource_readback(&rb);
22592 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
22593 NULL, test->input, 0, 0);
22594 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
22596 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
22597 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
22599 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22600 get_buffer_readback(in_buffer, &rb);
22601 get_buffer_readback(out_buffer, &out_rb);
22602 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
22604 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
22605 || !strcmp(imm_instructions[j], "imm_atomic_imin");
22606 unsigned int out_value = get_readback_color(&out_rb, j, 0, 0);
22607 unsigned int value = get_readback_color(&rb, j, 0, 0);
22608 unsigned int expected = test->expected_result[j];
22610 todo_wine_if(expected != test->input[j] && todo_instruction)
22611 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
22612 "with inputs (%u, %u), (%d), %#x (%d).\n",
22613 i, value, value, expected, expected, imm_instructions[j],
22614 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
22616 todo_wine_if(todo_instruction && out_value != test->input[j])
22617 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
22618 out_value, test->input[j], imm_instructions[j]);
22620 release_resource_readback(&out_rb);
22621 release_resource_readback(&rb);
22624 ID3D11Buffer_Release(cb);
22625 ID3D11Buffer_Release(in_buffer);
22626 ID3D11Buffer_Release(out_buffer);
22627 ID3D11ComputeShader_Release(cs);
22628 ID3D11PixelShader_Release(ps);
22629 ID3D11UnorderedAccessView_Release(in_uav);
22630 ID3D11UnorderedAccessView_Release(out_uav);
22631 release_test_context(&test_context);
22634 static void test_sm4_ret_instruction(void)
22636 struct d3d11_test_context test_context;
22637 ID3D11DeviceContext *context;
22638 ID3D11PixelShader *ps;
22639 struct uvec4 constant;
22640 ID3D11Device *device;
22641 ID3D11Buffer *cb;
22642 HRESULT hr;
22644 static const DWORD ps_code[] =
22646 #if 0
22647 uint c;
22649 float4 main() : SV_TARGET
22651 if (c == 1)
22652 return float4(1, 0, 0, 1);
22653 if (c == 2)
22654 return float4(0, 1, 0, 1);
22655 if (c == 3)
22656 return float4(0, 0, 1, 1);
22657 return float4(1, 1, 1, 1);
22659 #endif
22660 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
22661 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22662 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22663 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
22664 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
22665 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
22666 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
22667 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
22668 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
22669 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
22670 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
22671 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
22672 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
22673 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
22674 0x0100003e,
22677 if (!init_test_context(&test_context, NULL))
22678 return;
22680 device = test_context.device;
22681 context = test_context.immediate_context;
22683 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22684 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
22685 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22686 memset(&constant, 0, sizeof(constant));
22687 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
22688 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22690 draw_quad(&test_context);
22691 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22693 constant.x = 1;
22694 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22695 draw_quad(&test_context);
22696 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
22698 constant.x = 2;
22699 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22700 draw_quad(&test_context);
22701 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
22703 constant.x = 3;
22704 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22705 draw_quad(&test_context);
22706 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
22708 constant.x = 4;
22709 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22710 draw_quad(&test_context);
22711 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22713 ID3D11Buffer_Release(cb);
22714 ID3D11PixelShader_Release(ps);
22715 release_test_context(&test_context);
22718 static void test_primitive_restart(void)
22720 struct d3d11_test_context test_context;
22721 ID3D11Buffer *ib32, *ib16, *vb;
22722 ID3D11DeviceContext *context;
22723 unsigned int stride, offset;
22724 ID3D11InputLayout *layout;
22725 ID3D11VertexShader *vs;
22726 ID3D11PixelShader *ps;
22727 ID3D11Device *device;
22728 unsigned int i;
22729 HRESULT hr;
22730 RECT rect;
22732 static const DWORD ps_code[] =
22734 #if 0
22735 struct vs_out
22737 float4 position : SV_Position;
22738 float4 color : color;
22741 float4 main(vs_out input) : SV_TARGET
22743 return input.color;
22745 #endif
22746 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
22747 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22748 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
22749 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
22750 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
22751 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
22752 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
22753 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
22755 static const DWORD vs_code[] =
22757 #if 0
22758 struct vs_out
22760 float4 position : SV_Position;
22761 float4 color : color;
22764 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
22766 output.position = position;
22767 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
22769 #endif
22770 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
22771 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
22772 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
22773 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
22774 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
22775 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
22776 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
22777 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
22778 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
22779 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
22780 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
22781 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
22782 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
22784 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
22786 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
22788 static const struct vec2 vertices[] =
22790 {-1.00f, -1.0f},
22791 {-1.00f, 1.0f},
22792 {-0.25f, -1.0f},
22793 {-0.25f, 1.0f},
22794 { 0.25f, -1.0f},
22795 { 0.25f, 1.0f},
22796 { 1.00f, -1.0f},
22797 { 1.00f, 1.0f},
22799 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
22800 static const unsigned short indices16[] =
22802 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
22804 static const unsigned int indices32[] =
22806 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
22809 if (!init_test_context(&test_context, NULL))
22810 return;
22812 device = test_context.device;
22813 context = test_context.immediate_context;
22815 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
22816 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
22817 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22818 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
22820 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
22821 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
22823 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
22824 vs_code, sizeof(vs_code), &layout);
22825 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
22827 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
22829 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
22830 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22832 ID3D11DeviceContext_IASetInputLayout(context, layout);
22833 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
22834 stride = sizeof(*vertices);
22835 offset = 0;
22836 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
22838 for (i = 0; i < 2; ++i)
22840 if (!i)
22841 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
22842 else
22843 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
22845 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
22846 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
22847 SetRect(&rect, 0, 0, 240, 480);
22848 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
22849 SetRect(&rect, 240, 0, 400, 480);
22850 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
22851 SetRect(&rect, 400, 0, 640, 480);
22852 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
22855 ID3D11Buffer_Release(ib16);
22856 ID3D11Buffer_Release(ib32);
22857 ID3D11Buffer_Release(vb);
22858 ID3D11InputLayout_Release(layout);
22859 ID3D11PixelShader_Release(ps);
22860 ID3D11VertexShader_Release(vs);
22861 release_test_context(&test_context);
22864 static void test_resinfo_instruction(void)
22866 struct shader
22868 const DWORD *code;
22869 size_t size;
22872 struct d3d11_test_context test_context;
22873 D3D11_TEXTURE3D_DESC texture3d_desc;
22874 D3D11_TEXTURE2D_DESC texture_desc;
22875 const struct shader *current_ps;
22876 D3D_FEATURE_LEVEL feature_level;
22877 ID3D11ShaderResourceView *srv;
22878 ID3D11DeviceContext *context;
22879 ID3D11Texture2D *rtv_texture;
22880 ID3D11RenderTargetView *rtv;
22881 ID3D11Resource *texture;
22882 struct uvec4 constant;
22883 ID3D11PixelShader *ps;
22884 ID3D11Device *device;
22885 unsigned int i, type;
22886 ID3D11Buffer *cb;
22887 HRESULT hr;
22889 static const DWORD ps_2d_code[] =
22891 #if 0
22892 Texture2D t;
22894 uint type;
22895 uint level;
22897 float4 main() : SV_TARGET
22899 if (!type)
22901 float width, height, miplevels;
22902 t.GetDimensions(level, width, height, miplevels);
22903 return float4(width, height, miplevels, 0);
22905 else
22907 uint width, height, miplevels;
22908 t.GetDimensions(level, width, height, miplevels);
22909 return float4(width, height, miplevels, 0);
22912 #endif
22913 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
22914 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22915 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22916 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
22917 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
22918 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22919 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22920 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
22921 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
22922 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
22923 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
22924 0x01000015, 0x0100003e,
22926 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
22927 static const DWORD ps_2d_array_code[] =
22929 #if 0
22930 Texture2DArray t;
22932 uint type;
22933 uint level;
22935 float4 main() : SV_TARGET
22937 if (!type)
22939 float width, height, elements, miplevels;
22940 t.GetDimensions(level, width, height, elements, miplevels);
22941 return float4(width, height, elements, miplevels);
22943 else
22945 uint width, height, elements, miplevels;
22946 t.GetDimensions(level, width, height, elements, miplevels);
22947 return float4(width, height, elements, miplevels);
22950 #endif
22951 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
22952 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22953 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22954 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
22955 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
22956 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22957 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22958 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
22959 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
22960 0x0100003e, 0x01000015, 0x0100003e,
22962 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
22963 static const DWORD ps_3d_code[] =
22965 #if 0
22966 Texture3D t;
22968 uint type;
22969 uint level;
22971 float4 main() : SV_TARGET
22973 if (!type)
22975 float width, height, depth, miplevels;
22976 t.GetDimensions(level, width, height, depth, miplevels);
22977 return float4(width, height, depth, miplevels);
22979 else
22981 uint width, height, depth, miplevels;
22982 t.GetDimensions(level, width, height, depth, miplevels);
22983 return float4(width, height, depth, miplevels);
22986 #endif
22987 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
22988 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22989 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22990 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
22991 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
22992 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22993 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22994 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
22995 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
22996 0x0100003e, 0x01000015, 0x0100003e,
22998 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
22999 static const DWORD ps_cube_code[] =
23001 #if 0
23002 TextureCube t;
23004 uint type;
23005 uint level;
23007 float4 main() : SV_TARGET
23009 if (!type)
23011 float width, height, miplevels;
23012 t.GetDimensions(level, width, height, miplevels);
23013 return float4(width, height, miplevels, 0);
23015 else
23017 uint width, height, miplevels;
23018 t.GetDimensions(level, width, height, miplevels);
23019 return float4(width, height, miplevels, 0);
23022 #endif
23023 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
23024 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23025 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23026 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
23027 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
23028 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
23029 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
23030 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
23031 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
23032 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
23033 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
23034 0x01000015, 0x0100003e,
23036 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
23037 static const DWORD ps_cube_array_code[] =
23039 #if 0
23040 TextureCubeArray t;
23042 uint type;
23043 uint level;
23045 float4 main() : SV_TARGET
23047 if (!type)
23049 float width, height, elements, miplevels;
23050 t.GetDimensions(level, width, height, elements, miplevels);
23051 return float4(width, height, miplevels, 0);
23053 else
23055 uint width, height, elements, miplevels;
23056 t.GetDimensions(level, width, height, elements, miplevels);
23057 return float4(width, height, miplevels, 0);
23060 #endif
23061 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
23062 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23063 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23064 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
23065 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
23066 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
23067 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
23068 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
23069 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
23070 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
23071 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
23072 0x0100003e, 0x01000015, 0x0100003e,
23074 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
23075 static const struct ps_test
23077 const struct shader *ps;
23078 struct
23080 unsigned int width;
23081 unsigned int height;
23082 unsigned int depth;
23083 unsigned int miplevel_count;
23084 unsigned int array_size;
23085 unsigned int cube_count;
23086 } texture_desc;
23087 unsigned int miplevel;
23088 struct vec4 expected_result;
23090 ps_tests[] =
23092 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
23093 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
23094 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
23095 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
23097 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
23098 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
23099 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
23100 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
23102 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
23103 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
23104 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
23105 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
23106 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
23107 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
23108 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
23109 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
23110 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
23112 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
23113 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
23114 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
23115 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
23116 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
23118 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
23119 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
23120 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
23123 if (!init_test_context(&test_context, NULL))
23124 return;
23126 device = test_context.device;
23127 context = test_context.immediate_context;
23128 feature_level = ID3D11Device_GetFeatureLevel(device);
23130 texture_desc.Width = 64;
23131 texture_desc.Height = 64;
23132 texture_desc.MipLevels = 1;
23133 texture_desc.ArraySize = 1;
23134 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
23135 texture_desc.SampleDesc.Count = 1;
23136 texture_desc.SampleDesc.Quality = 0;
23137 texture_desc.Usage = D3D11_USAGE_DEFAULT;
23138 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23139 texture_desc.CPUAccessFlags = 0;
23140 texture_desc.MiscFlags = 0;
23141 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
23142 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
23143 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
23144 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
23146 memset(&constant, 0, sizeof(constant));
23147 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
23149 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23150 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
23152 ps = NULL;
23153 current_ps = NULL;
23154 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
23156 const struct ps_test *test = &ps_tests[i];
23158 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
23160 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
23161 continue;
23164 if (current_ps != test->ps)
23166 if (ps)
23167 ID3D11PixelShader_Release(ps);
23169 current_ps = test->ps;
23171 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
23172 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
23173 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23176 if (test->texture_desc.depth != 1)
23178 texture3d_desc.Width = test->texture_desc.width;
23179 texture3d_desc.Height = test->texture_desc.height;
23180 texture3d_desc.Depth = test->texture_desc.depth;
23181 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
23182 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
23183 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
23184 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23185 texture3d_desc.CPUAccessFlags = 0;
23186 texture3d_desc.MiscFlags = 0;
23187 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
23188 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
23190 else
23192 texture_desc.Width = test->texture_desc.width;
23193 texture_desc.Height = test->texture_desc.height;
23194 texture_desc.MipLevels = test->texture_desc.miplevel_count;
23195 texture_desc.ArraySize = test->texture_desc.array_size;
23196 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
23197 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23198 texture_desc.MiscFlags = 0;
23199 if (test->texture_desc.cube_count)
23200 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
23201 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
23202 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
23205 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
23206 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
23207 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23209 for (type = 0; type < 2; ++type)
23211 constant.x = type;
23212 constant.y = test->miplevel;
23213 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
23215 draw_quad(&test_context);
23216 check_texture_vec4(rtv_texture, &test->expected_result, 0);
23219 ID3D11Resource_Release(texture);
23220 ID3D11ShaderResourceView_Release(srv);
23222 ID3D11PixelShader_Release(ps);
23224 ID3D11Buffer_Release(cb);
23225 ID3D11RenderTargetView_Release(rtv);
23226 ID3D11Texture2D_Release(rtv_texture);
23227 release_test_context(&test_context);
23230 static void test_sm5_bufinfo_instruction(void)
23232 struct shader
23234 const DWORD *code;
23235 size_t size;
23238 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
23239 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
23240 struct d3d11_test_context test_context;
23241 D3D11_TEXTURE2D_DESC texture_desc;
23242 const struct shader *current_ps;
23243 ID3D11UnorderedAccessView *uav;
23244 ID3D11ShaderResourceView *srv;
23245 D3D11_BUFFER_DESC buffer_desc;
23246 ID3D11DeviceContext *context;
23247 ID3D11RenderTargetView *rtv;
23248 ID3D11Texture2D *texture;
23249 ID3D11PixelShader *ps;
23250 ID3D11Buffer *buffer;
23251 ID3D11Device *device;
23252 unsigned int i;
23253 HRESULT hr;
23255 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23256 static const DWORD ps_uav_structured_code[] =
23258 #if 0
23259 struct s
23261 uint4 u;
23262 bool b;
23265 RWStructuredBuffer<s> b;
23267 uint4 main(void) : SV_Target
23269 uint count, stride;
23270 b.GetDimensions(count, stride);
23271 return uint4(count, stride, 0, 1);
23273 #endif
23274 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
23275 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23276 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23277 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
23278 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
23279 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
23280 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
23281 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
23283 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
23284 static const DWORD ps_uav_structured32_code[] =
23286 #if 0
23287 struct s
23289 uint4 u;
23290 bool4 b;
23293 RWStructuredBuffer<s> b;
23295 uint4 main(void) : SV_Target
23297 uint count, stride;
23298 b.GetDimensions(count, stride);
23299 return uint4(count, stride, 0, 1);
23301 #endif
23302 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
23303 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23304 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23305 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
23306 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
23307 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
23308 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
23309 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
23311 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
23312 static const DWORD ps_srv_structured_code[] =
23314 #if 0
23315 StructuredBuffer<bool> b;
23317 uint4 main(void) : SV_Target
23319 uint count, stride;
23320 b.GetDimensions(count, stride);
23321 return uint4(count, stride, 0, 1);
23323 #endif
23324 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
23325 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23326 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23327 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
23328 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
23329 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
23330 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
23331 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
23333 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
23334 static const DWORD ps_uav_raw_code[] =
23336 #if 0
23337 RWByteAddressBuffer b;
23339 uint4 main(void) : SV_Target
23341 uint width;
23342 b.GetDimensions(width);
23343 return width;
23345 #endif
23346 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
23347 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23348 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23349 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
23350 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
23351 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
23352 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23354 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
23355 static const DWORD ps_srv_raw_code[] =
23357 #if 0
23358 ByteAddressBuffer b;
23360 uint4 main(void) : SV_Target
23362 uint width;
23363 b.GetDimensions(width);
23364 return width;
23366 #endif
23367 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
23368 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23369 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23370 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
23371 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
23372 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
23373 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23375 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
23376 static const DWORD ps_uav_typed_code[] =
23378 #if 0
23379 RWBuffer<float> b;
23381 uint4 main(void) : SV_Target
23383 uint width;
23384 b.GetDimensions(width);
23385 return width;
23387 #endif
23388 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
23389 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23390 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23391 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
23392 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23393 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
23394 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23396 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
23397 static const DWORD ps_srv_typed_code[] =
23399 #if 0
23400 Buffer<float> b;
23402 uint4 main(void) : SV_Target
23404 uint width;
23405 b.GetDimensions(width);
23406 return width;
23408 #endif
23409 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
23410 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23411 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23412 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
23413 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23414 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
23415 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23417 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
23418 static const struct test
23420 const struct shader *ps;
23421 BOOL uav;
23422 unsigned int buffer_size;
23423 unsigned int buffer_misc_flags;
23424 unsigned int buffer_structure_byte_stride;
23425 DXGI_FORMAT view_format;
23426 unsigned int view_element_idx;
23427 unsigned int view_element_count;
23428 struct uvec4 expected_result;
23430 tests[] =
23432 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
23433 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
23434 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
23435 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
23436 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
23437 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
23438 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
23439 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
23440 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
23441 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
23442 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
23443 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
23444 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
23445 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
23446 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
23447 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
23448 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
23449 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
23450 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
23451 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
23452 #undef RAW
23453 #undef STRUCTURED
23456 if (!init_test_context(&test_context, &feature_level))
23457 return;
23459 device = test_context.device;
23460 context = test_context.immediate_context;
23462 texture_desc.Width = 64;
23463 texture_desc.Height = 64;
23464 texture_desc.MipLevels = 1;
23465 texture_desc.ArraySize = 1;
23466 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
23467 texture_desc.SampleDesc.Count = 1;
23468 texture_desc.SampleDesc.Quality = 0;
23469 texture_desc.Usage = D3D11_USAGE_DEFAULT;
23470 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23471 texture_desc.CPUAccessFlags = 0;
23472 texture_desc.MiscFlags = 0;
23473 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23474 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
23475 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23476 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
23478 ps = NULL;
23479 current_ps = NULL;
23480 for (i = 0; i < ARRAY_SIZE(tests); ++i)
23482 const struct test *test = &tests[i];
23484 if (current_ps != test->ps)
23486 if (ps)
23487 ID3D11PixelShader_Release(ps);
23489 current_ps = test->ps;
23491 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
23492 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
23493 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23496 buffer_desc.ByteWidth = test->buffer_size;
23497 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23498 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
23499 buffer_desc.CPUAccessFlags = 0;
23500 buffer_desc.MiscFlags = test->buffer_misc_flags;
23501 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
23502 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
23503 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
23505 if (test->uav)
23507 uav_desc.Format = test->view_format;
23508 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
23509 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
23510 U(uav_desc).Buffer.NumElements = test->view_element_count;
23511 U(uav_desc).Buffer.Flags = 0;
23512 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
23513 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
23514 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
23515 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
23516 srv = NULL;
23518 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
23519 1, 1, &uav, NULL);
23521 else
23523 srv_desc.Format = test->view_format;
23524 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
23525 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
23526 U(srv_desc).BufferEx.NumElements = test->view_element_count;
23527 U(srv_desc).BufferEx.Flags = 0;
23528 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
23529 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
23530 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
23531 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
23532 uav = NULL;
23534 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23535 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23538 draw_quad(&test_context);
23539 check_texture_uvec4(texture, &test->expected_result);
23541 if (srv)
23542 ID3D11ShaderResourceView_Release(srv);
23543 if (uav)
23544 ID3D11UnorderedAccessView_Release(uav);
23545 ID3D11Buffer_Release(buffer);
23547 ID3D11PixelShader_Release(ps);
23549 ID3D11RenderTargetView_Release(rtv);
23550 ID3D11Texture2D_Release(texture);
23551 release_test_context(&test_context);
23554 static void test_sampleinfo_instruction(void)
23556 ID3D11Texture2D *float_rt_texture, *uint_rt_texture;
23557 ID3D11RenderTargetView *float_rtv, *uint_rtv, *rtv;
23558 ID3D11PixelShader *ps_float, *ps_uint, *ps_rt;
23559 ID3D11Texture2D *texture, *readback_texture;
23560 struct d3d11_test_context test_context;
23561 unsigned int sample_count, quality;
23562 D3D11_TEXTURE2D_DESC texture_desc;
23563 ID3D11RenderTargetView *rtvs[2];
23564 ID3D11ShaderResourceView *srv;
23565 ID3D11DeviceContext *context;
23566 struct uvec4 expected_uint;
23567 struct vec4 expected_float;
23568 ID3D11Device *device;
23569 HRESULT hr;
23571 static const DWORD ps_uint_code[] =
23573 #if 0
23574 Texture2DMS<float> t;
23576 uint4 main() : SV_Target1
23578 uint width, height, sample_count;
23579 t.GetDimensions(width, height, sample_count);
23580 return sample_count;
23582 #endif
23583 0x43425844, 0x4342ad12, 0x19addd8c, 0x5cb87c48, 0xe604a242, 0x00000001, 0x000000d4, 0x00000003,
23584 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23585 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
23586 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
23587 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000001,
23588 0x02000068, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a, 0x00000000, 0x05000036,
23589 0x001020f2, 0x00000001, 0x00100006, 0x00000000, 0x0100003e,
23591 static const DWORD ps_float_code[] =
23593 #if 0
23594 Texture2DMS<float> t;
23596 float4 main() : SV_Target
23598 uint width, height, sample_count;
23599 t.GetDimensions(width, height, sample_count);
23600 return sample_count;
23602 #endif
23603 0x43425844, 0x2b8aea46, 0x34ceda6f, 0xf98d222b, 0x235ebc0b, 0x00000001, 0x000000b8, 0x00000003,
23604 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23605 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23606 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000040, 0x00000050, 0x00000010,
23607 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23608 0x0500006f, 0x001020f2, 0x00000000, 0x0010700a, 0x00000000, 0x0100003e,
23610 static const DWORD ps_rt_code[] =
23612 #if 0
23613 float4 main() : SV_Target
23615 return GetRenderTargetSampleCount();
23617 #endif
23618 0x43425844, 0x74404d37, 0xad6f88e4, 0xb006ea57, 0xf07d9e2a, 0x00000001, 0x000000a4, 0x00000003,
23619 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23620 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23621 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000002c, 0x00000050, 0x0000000b,
23622 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x0400006f, 0x001020f2, 0x00000000, 0x0000e00a,
23623 0x0100003e,
23625 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23627 if (!init_test_context(&test_context, &feature_level))
23628 return;
23630 device = test_context.device;
23631 context = test_context.immediate_context;
23633 texture_desc.Width = 64;
23634 texture_desc.Height = 64;
23635 texture_desc.MipLevels = 1;
23636 texture_desc.ArraySize = 1;
23637 texture_desc.SampleDesc.Count = 1;
23638 texture_desc.SampleDesc.Quality = 0;
23639 texture_desc.Usage = D3D11_USAGE_DEFAULT;
23640 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23641 texture_desc.CPUAccessFlags = 0;
23642 texture_desc.MiscFlags = 0;
23644 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
23645 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &float_rt_texture);
23646 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23647 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)float_rt_texture, NULL, &float_rtv);
23648 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
23649 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
23650 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &uint_rt_texture);
23651 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23652 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)uint_rt_texture, NULL, &uint_rtv);
23653 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
23655 rtvs[0] = float_rtv;
23656 rtvs[1] = uint_rtv;
23657 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
23659 hr = ID3D11Device_CreatePixelShader(device, ps_float_code, sizeof(ps_float_code), NULL, &ps_float);
23660 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23661 hr = ID3D11Device_CreatePixelShader(device, ps_uint_code, sizeof(ps_uint_code), NULL, &ps_uint);
23662 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23664 for (sample_count = 2; sample_count <= 8; sample_count *= 2)
23666 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
23667 texture_desc.SampleDesc.Count = sample_count;
23668 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
23670 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
23671 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
23672 if (!quality)
23674 skip("Sample count %u not supported.\n", sample_count);
23675 continue;
23678 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23679 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
23680 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
23681 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
23682 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23684 ID3D11DeviceContext_PSSetShader(context, ps_float, NULL, 0);
23685 draw_quad(&test_context);
23686 ID3D11DeviceContext_PSSetShader(context, ps_uint, NULL, 0);
23687 draw_quad(&test_context);
23689 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
23690 check_texture_vec4(float_rt_texture, &expected_float, 0);
23691 expected_uint.x = expected_uint.y = expected_uint.z = expected_uint.w = sample_count;
23692 check_texture_uvec4(uint_rt_texture, &expected_uint);
23694 ID3D11Texture2D_Release(texture);
23695 ID3D11ShaderResourceView_Release(srv);
23698 hr = ID3D11Device_CreatePixelShader(device, ps_rt_code, sizeof(ps_rt_code), NULL, &ps_rt);
23699 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23700 for (sample_count = 1; sample_count <= 8; sample_count *= 2)
23702 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
23703 texture_desc.SampleDesc.Count = sample_count;
23704 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23706 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
23707 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
23708 if (!quality)
23710 skip("Sample count %u not supported.\n", sample_count);
23711 continue;
23714 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23715 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
23716 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23717 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
23718 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23720 /* Some drivers (AMD Radeon HD 6310) return stale sample counts if we
23721 * don't rebind the pixel shader between runs with different sample
23722 * counts. */
23723 ID3D11DeviceContext_PSSetShader(context, NULL, NULL, 0);
23724 ID3D11DeviceContext_PSSetShader(context, ps_rt, NULL, 0);
23725 draw_quad(&test_context);
23727 if (sample_count != 1)
23729 texture_desc.SampleDesc.Count = 1;
23730 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
23731 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23732 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
23733 (ID3D11Resource *)texture, 0, texture_desc.Format);
23735 else
23737 readback_texture = texture;
23738 ID3D11Texture2D_AddRef(readback_texture);
23741 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
23742 check_texture_vec4(readback_texture, &expected_float, 0);
23744 ID3D11Texture2D_Release(readback_texture);
23745 ID3D11Texture2D_Release(texture);
23746 ID3D11RenderTargetView_Release(rtv);
23749 ID3D11RenderTargetView_Release(float_rtv);
23750 ID3D11RenderTargetView_Release(uint_rtv);
23751 ID3D11Texture2D_Release(float_rt_texture);
23752 ID3D11Texture2D_Release(uint_rt_texture);
23753 ID3D11PixelShader_Release(ps_float);
23754 ID3D11PixelShader_Release(ps_uint);
23755 ID3D11PixelShader_Release(ps_rt);
23756 release_test_context(&test_context);
23759 static void test_render_target_device_mismatch(void)
23761 struct d3d11_test_context test_context;
23762 struct device_desc device_desc = {0};
23763 ID3D11DeviceContext *context;
23764 ID3D11RenderTargetView *rtv;
23765 ID3D11Device *device;
23766 ULONG refcount;
23768 if (!init_test_context(&test_context, NULL))
23769 return;
23771 device = create_device(&device_desc);
23772 ok(!!device, "Failed to create device.\n");
23774 ID3D11Device_GetImmediateContext(device, &context);
23776 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
23777 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
23778 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
23779 if (!enable_debug_layer)
23781 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
23782 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
23783 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
23784 ID3D11RenderTargetView_Release(rtv);
23787 rtv = NULL;
23788 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23790 ID3D11DeviceContext_Release(context);
23791 refcount = ID3D11Device_Release(device);
23792 ok(!refcount, "Device has %u references left.\n", refcount);
23793 release_test_context(&test_context);
23796 static void test_buffer_srv(void)
23798 struct shader
23800 const DWORD *code;
23801 size_t size;
23802 BOOL requires_raw_and_structured_buffers;
23804 struct buffer
23806 unsigned int byte_count;
23807 unsigned int data_offset;
23808 const void *data;
23809 unsigned int structure_byte_stride;
23812 BOOL raw_and_structured_buffers_supported;
23813 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
23814 struct d3d11_test_context test_context;
23815 D3D11_SUBRESOURCE_DATA resource_data;
23816 const struct buffer *current_buffer;
23817 const struct shader *current_shader;
23818 ID3D11ShaderResourceView *srv;
23819 D3D11_BUFFER_DESC buffer_desc;
23820 ID3D11DeviceContext *context;
23821 DWORD color, expected_color;
23822 struct resource_readback rb;
23823 ID3D11Buffer *cb, *buffer;
23824 ID3D11PixelShader *ps;
23825 ID3D11Device *device;
23826 unsigned int i, x, y;
23827 struct vec4 cb_size;
23828 HRESULT hr;
23830 static const DWORD ps_float4_code[] =
23832 #if 0
23833 Buffer<float4> b;
23835 float2 size;
23837 float4 main(float4 position : SV_POSITION) : SV_Target
23839 float2 p;
23840 int2 coords;
23841 p.x = position.x / 640.0f;
23842 p.y = position.y / 480.0f;
23843 coords = int2(p.x * size.x, p.y * size.y);
23844 return b.Load(coords.y * size.x + coords.x);
23846 #endif
23847 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
23848 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
23849 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
23850 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
23851 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
23852 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
23853 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
23854 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
23855 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
23856 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
23857 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
23858 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
23859 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
23861 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
23862 static const DWORD ps_structured_code[] =
23864 #if 0
23865 StructuredBuffer<float4> b;
23867 float2 size;
23869 float4 main(float4 position : SV_POSITION) : SV_Target
23871 float2 p;
23872 int2 coords;
23873 p.x = position.x / 640.0f;
23874 p.y = position.y / 480.0f;
23875 coords = int2(p.x * size.x, p.y * size.y);
23876 return b[coords.y * size.x + coords.x];
23878 #endif
23879 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
23880 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
23881 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
23882 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
23883 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
23884 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
23885 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
23886 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
23887 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
23888 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
23889 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
23890 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
23891 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
23892 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
23894 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
23895 static const DWORD rgba16[] =
23897 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
23898 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
23899 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
23900 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
23902 static const DWORD rgba4[] =
23904 0xffffffff, 0xff0000ff,
23905 0xff000000, 0xff00ff00,
23907 static const BYTE r4[] =
23909 0xde, 0xad,
23910 0xba, 0xbe,
23912 static const struct vec4 rgba_float[] =
23914 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
23915 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
23917 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
23918 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
23919 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
23920 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
23921 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
23922 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
23923 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
23924 &rgba_float, sizeof(*rgba_float)};
23925 static const DWORD rgba16_colors2x2[] =
23927 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
23928 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
23929 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
23930 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
23932 static const DWORD rgba16_colors1x1[] =
23934 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23935 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23936 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23937 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23939 static const DWORD rgba4_colors[] =
23941 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
23942 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
23943 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
23944 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
23946 static const DWORD r4_colors[] =
23948 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
23949 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
23950 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
23951 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
23953 static const DWORD zero_colors[16] = {0};
23954 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
23956 static const struct test
23958 const struct shader *shader;
23959 const struct buffer *buffer;
23960 DXGI_FORMAT srv_format;
23961 unsigned int srv_first_element;
23962 unsigned int srv_element_count;
23963 struct vec2 size;
23964 const DWORD *expected_colors;
23966 tests[] =
23968 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
23969 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
23970 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
23971 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
23972 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
23973 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
23974 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
23975 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
23976 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
23977 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
23978 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
23981 if (!init_test_context(&test_context, NULL))
23982 return;
23984 device = test_context.device;
23985 context = test_context.immediate_context;
23986 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
23987 || check_compute_shaders_via_sm4_support(device);
23989 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
23990 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
23992 buffer_desc.ByteWidth = 256;
23993 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23994 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23995 buffer_desc.CPUAccessFlags = 0;
23996 buffer_desc.MiscFlags = 0;
23997 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
23998 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23999 srv_desc.Format = DXGI_FORMAT_R8_UNORM;
24000 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
24001 U(srv_desc).Buffer.FirstElement = 0;
24002 U(srv_desc).Buffer.NumElements = 0;
24003 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
24004 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
24005 ID3D11Buffer_Release(buffer);
24007 ps = NULL;
24008 srv = NULL;
24009 buffer = NULL;
24010 current_shader = NULL;
24011 current_buffer = NULL;
24012 for (i = 0; i < ARRAY_SIZE(tests); ++i)
24014 const struct test *test = &tests[i];
24016 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
24018 skip("Test %u: Raw and structured buffers are not supported.\n", i);
24019 continue;
24021 /* Structured buffer views with an offset don't seem to work on WARP. */
24022 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
24023 && is_warp_device(device))
24025 skip("Test %u: Broken WARP.\n", i);
24026 continue;
24029 if (current_shader != test->shader)
24031 if (ps)
24032 ID3D11PixelShader_Release(ps);
24034 current_shader = test->shader;
24036 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
24037 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
24038 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
24041 if (current_buffer != test->buffer)
24043 if (buffer)
24044 ID3D11Buffer_Release(buffer);
24046 current_buffer = test->buffer;
24047 if (current_buffer)
24049 BYTE *data = NULL;
24051 buffer_desc.ByteWidth = current_buffer->byte_count;
24052 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24053 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
24054 buffer_desc.CPUAccessFlags = 0;
24055 buffer_desc.MiscFlags = 0;
24056 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
24057 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24058 resource_data.SysMemPitch = 0;
24059 resource_data.SysMemSlicePitch = 0;
24060 if (current_buffer->data_offset)
24062 data = heap_alloc_zero(current_buffer->byte_count);
24063 ok(!!data, "Failed to allocate memory.\n");
24064 memcpy(data + current_buffer->data_offset, current_buffer->data,
24065 current_buffer->byte_count - current_buffer->data_offset);
24066 resource_data.pSysMem = data;
24068 else
24070 resource_data.pSysMem = current_buffer->data;
24072 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
24073 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
24074 heap_free(data);
24076 else
24078 buffer = NULL;
24082 if (srv)
24083 ID3D11ShaderResourceView_Release(srv);
24084 if (current_buffer)
24086 srv_desc.Format = test->srv_format;
24087 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
24088 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
24089 U(srv_desc).Buffer.NumElements = test->srv_element_count;
24090 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
24091 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
24093 else
24095 srv = NULL;
24097 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
24099 cb_size.x = test->size.x;
24100 cb_size.y = test->size.y;
24101 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
24103 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
24104 draw_quad(&test_context);
24106 get_texture_readback(test_context.backbuffer, 0, &rb);
24107 for (y = 0; y < 4; ++y)
24109 for (x = 0; x < 4; ++x)
24111 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
24112 expected_color = test->expected_colors[y * 4 + x];
24113 ok(compare_color(color, expected_color, 1),
24114 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
24115 i, color, expected_color, x, y);
24118 release_resource_readback(&rb);
24120 if (srv)
24121 ID3D11ShaderResourceView_Release(srv);
24122 if (buffer)
24123 ID3D11Buffer_Release(buffer);
24125 ID3D11Buffer_Release(cb);
24126 ID3D11PixelShader_Release(ps);
24127 release_test_context(&test_context);
24130 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
24132 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24133 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
24134 struct d3d11_test_context test_context;
24135 D3D11_SUBRESOURCE_DATA resource_data;
24136 D3D11_TEXTURE2D_DESC texture_desc;
24137 ID3D11UnorderedAccessView *uav;
24138 ID3D11ShaderResourceView *srv;
24139 D3D11_BUFFER_DESC buffer_desc;
24140 ID3D11Buffer *cb, *raw_buffer;
24141 ID3D11DeviceContext *context;
24142 struct resource_readback rb;
24143 ID3D11RenderTargetView *rtv;
24144 ID3D11Texture2D *texture;
24145 ID3D11ComputeShader *cs;
24146 ID3D11PixelShader *ps;
24147 ID3D11Device *device;
24148 unsigned int i, data;
24149 struct uvec4 offset;
24150 HRESULT hr;
24152 static const unsigned int buffer_data[] =
24154 0xffffffff, 0x00000000,
24156 static const DWORD ps_code[] =
24158 #if 0
24159 ByteAddressBuffer buffer;
24161 uint offset;
24163 uint main() : SV_Target0
24165 return buffer.Load(offset);
24167 #endif
24168 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
24169 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
24170 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
24171 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
24172 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
24173 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
24174 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
24175 0x00000000,
24177 static const DWORD cs_code[] =
24179 #if 0
24180 RWByteAddressBuffer buffer;
24182 uint2 input;
24184 [numthreads(1, 1, 1)]
24185 void main()
24187 buffer.Store(input.x, input.y);
24189 #endif
24190 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
24191 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24192 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
24193 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
24194 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
24195 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
24197 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
24199 if (!init_test_context(&test_context, &feature_level))
24200 return;
24202 device = test_context.device;
24203 context = test_context.immediate_context;
24205 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
24207 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
24208 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
24209 if (SUCCEEDED(hr))
24210 ID3D11PixelShader_Release(ps);
24211 skip("Raw buffers are not supported.\n");
24212 release_test_context(&test_context);
24213 return;
24216 if (is_intel_device(device))
24218 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
24219 * This test checks what happens when offsets are not properly aligned.
24220 * The behavior seems to be undefined on Intel hardware. */
24221 win_skip("Skipping the test on Intel hardware.\n");
24222 release_test_context(&test_context);
24223 return;
24226 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
24227 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
24229 memset(&offset, 0, sizeof(offset));
24230 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
24232 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
24233 texture_desc.Format = DXGI_FORMAT_R32_UINT;
24234 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
24235 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
24236 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
24237 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
24239 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
24241 buffer_desc.ByteWidth = sizeof(buffer_data);
24242 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24243 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
24244 buffer_desc.CPUAccessFlags = 0;
24245 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
24246 resource_data.pSysMem = buffer_data;
24247 resource_data.SysMemPitch = 0;
24248 resource_data.SysMemSlicePitch = 0;
24249 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
24250 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24252 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
24253 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
24254 U(srv_desc).BufferEx.FirstElement = 0;
24255 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
24256 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
24257 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
24258 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
24260 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
24261 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
24262 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
24264 offset.x = 0;
24265 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24266 NULL, &offset, 0, 0);
24267 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
24268 draw_quad(&test_context);
24269 check_texture_color(texture, buffer_data[0], 0);
24270 offset.x = 1;
24271 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24272 NULL, &offset, 0, 0);
24273 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
24274 draw_quad(&test_context);
24275 check_texture_color(texture, buffer_data[0], 0);
24276 offset.x = 2;
24277 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24278 NULL, &offset, 0, 0);
24279 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
24280 draw_quad(&test_context);
24281 check_texture_color(texture, buffer_data[0], 0);
24282 offset.x = 3;
24283 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24284 NULL, &offset, 0, 0);
24285 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
24286 draw_quad(&test_context);
24287 check_texture_color(texture, buffer_data[0], 0);
24289 offset.x = 4;
24290 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24291 NULL, &offset, 0, 0);
24292 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
24293 draw_quad(&test_context);
24294 check_texture_color(texture, buffer_data[1], 0);
24295 offset.x = 7;
24296 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24297 NULL, &offset, 0, 0);
24298 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
24299 draw_quad(&test_context);
24300 check_texture_color(texture, buffer_data[1], 0);
24302 if (feature_level < D3D_FEATURE_LEVEL_11_0)
24304 skip("Feature level 11_0 required for unaligned UAV test.\n");
24305 goto done;
24308 ID3D11Buffer_Release(raw_buffer);
24309 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24310 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
24311 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24313 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
24314 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24315 U(uav_desc).Buffer.FirstElement = 0;
24316 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
24317 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
24318 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
24319 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24321 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
24322 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24324 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24325 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
24326 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24328 offset.x = 0;
24329 offset.y = 0xffffffff;
24330 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24331 NULL, &offset, 0, 0);
24332 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24333 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24334 get_buffer_readback(raw_buffer, &rb);
24335 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24337 data = get_readback_color(&rb, i, 0, 0);
24338 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24340 release_resource_readback(&rb);
24342 offset.x = 1;
24343 offset.y = 0xffffffff;
24344 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24345 NULL, &offset, 0, 0);
24346 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24347 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24348 get_buffer_readback(raw_buffer, &rb);
24349 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24351 data = get_readback_color(&rb, i, 0, 0);
24352 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24354 release_resource_readback(&rb);
24356 offset.x = 2;
24357 offset.y = 0xffffffff;
24358 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24359 NULL, &offset, 0, 0);
24360 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24361 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24362 get_buffer_readback(raw_buffer, &rb);
24363 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24365 data = get_readback_color(&rb, i, 0, 0);
24366 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24368 release_resource_readback(&rb);
24370 offset.x = 3;
24371 offset.y = 0xffffffff;
24372 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24373 NULL, &offset, 0, 0);
24374 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24375 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24376 get_buffer_readback(raw_buffer, &rb);
24377 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24379 data = get_readback_color(&rb, i, 0, 0);
24380 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24382 release_resource_readback(&rb);
24384 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24385 offset.x = 3;
24386 offset.y = 0xffff;
24387 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24388 NULL, &offset, 0, 0);
24389 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24390 offset.x = 4;
24391 offset.y = 0xa;
24392 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24393 NULL, &offset, 0, 0);
24394 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24395 get_buffer_readback(raw_buffer, &rb);
24396 data = get_readback_color(&rb, 0, 0, 0);
24397 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
24398 data = get_readback_color(&rb, 1, 0, 0);
24399 ok(data == 0xa, "Got unexpected result %#x.\n", data);
24400 release_resource_readback(&rb);
24402 ID3D11ComputeShader_Release(cs);
24403 ID3D11UnorderedAccessView_Release(uav);
24405 done:
24406 ID3D11Buffer_Release(cb);
24407 ID3D11Buffer_Release(raw_buffer);
24408 ID3D11PixelShader_Release(ps);
24409 ID3D11RenderTargetView_Release(rtv);
24410 ID3D11ShaderResourceView_Release(srv);
24411 ID3D11Texture2D_Release(texture);
24412 release_test_context(&test_context);
24415 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
24416 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
24418 D3D11_MAPPED_SUBRESOURCE map_desc;
24419 unsigned int counter;
24421 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
24423 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
24424 D3D11_MAP_READ, 0, &map_desc)))
24425 return 0xdeadbeef;
24426 counter = *(unsigned int *)map_desc.pData;
24427 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
24428 return counter;
24431 static int compare_id(const void *a, const void *b)
24433 return *(int *)a - *(int *)b;
24436 static void test_uav_counters(void)
24438 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
24439 ID3D11ComputeShader *cs_producer, *cs_consumer;
24440 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24441 struct d3d11_test_context test_context;
24442 ID3D11UnorderedAccessView *uav, *uav2;
24443 unsigned int data, id[128], i;
24444 D3D11_BUFFER_DESC buffer_desc;
24445 ID3D11DeviceContext *context;
24446 struct resource_readback rb;
24447 ID3D11Device *device;
24448 D3D11_BOX box;
24449 HRESULT hr;
24451 static const DWORD cs_producer_code[] =
24453 #if 0
24454 RWStructuredBuffer<uint> u;
24456 [numthreads(4, 1, 1)]
24457 void main(uint3 dispatch_id : SV_DispatchThreadID)
24459 uint counter = u.IncrementCounter();
24460 u[counter] = dispatch_id.x;
24462 #endif
24463 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
24464 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24465 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
24466 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
24467 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
24468 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
24469 0x0002000a, 0x0100003e,
24471 static const DWORD cs_consumer_code[] =
24473 #if 0
24474 RWStructuredBuffer<uint> u;
24475 RWStructuredBuffer<uint> u2;
24477 [numthreads(4, 1, 1)]
24478 void main()
24480 uint counter = u.DecrementCounter();
24481 u2[counter] = u[counter];
24483 #endif
24484 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
24485 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24486 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
24487 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
24488 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
24489 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
24490 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
24491 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
24493 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24495 if (!init_test_context(&test_context, &feature_level))
24496 return;
24498 device = test_context.device;
24499 context = test_context.immediate_context;
24501 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
24502 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24503 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
24504 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24506 memset(&buffer_desc, 0, sizeof(buffer_desc));
24507 buffer_desc.ByteWidth = sizeof(unsigned int);
24508 buffer_desc.Usage = D3D11_USAGE_STAGING;
24509 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
24510 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
24511 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24513 buffer_desc.ByteWidth = 1024;
24514 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24515 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24516 buffer_desc.CPUAccessFlags = 0;
24517 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24518 buffer_desc.StructureByteStride = sizeof(unsigned int);
24519 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24520 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24521 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
24522 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24523 U(uav_desc).Buffer.FirstElement = 0;
24524 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
24525 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
24526 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24527 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24528 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
24529 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24530 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
24531 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24533 data = read_uav_counter(context, staging_buffer, uav);
24534 ok(!data, "Got unexpected initial value %u.\n", data);
24535 data = 8;
24536 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24537 data = read_uav_counter(context, staging_buffer, uav);
24538 ok(data == 8, "Got unexpected value %u.\n", data);
24539 data = ~0u;
24540 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24541 data = read_uav_counter(context, staging_buffer, uav);
24542 ok(data == 8, "Got unexpected value %u.\n", data);
24543 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24544 data = read_uav_counter(context, staging_buffer, uav);
24545 ok(data == 8, "Got unexpected value %u.\n", data);
24547 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
24548 data = 0;
24549 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24550 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
24551 data = read_uav_counter(context, staging_buffer, uav);
24552 ok(!data, "Got unexpected value %u.\n", data);
24554 /* produce */
24555 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
24556 data = read_uav_counter(context, staging_buffer, uav);
24557 ok(data == 64, "Got unexpected value %u.\n", data);
24558 get_buffer_readback(buffer, &rb);
24559 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
24560 release_resource_readback(&rb);
24561 qsort(id, 64, sizeof(*id), compare_id);
24562 for (i = 0; i < 64; ++i)
24564 if (id[i] != i)
24565 break;
24567 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
24569 /* consume */
24570 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
24571 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
24572 data = read_uav_counter(context, staging_buffer, uav);
24573 ok(!data, "Got unexpected value %u.\n", data);
24574 get_buffer_readback(buffer2, &rb);
24575 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
24576 release_resource_readback(&rb);
24577 qsort(id, 64, sizeof(*id), compare_id);
24578 for (i = 0; i < 64; ++i)
24580 if (id[i] != i)
24581 break;
24583 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
24585 /* produce on CPU */
24586 for (i = 0; i < 8; ++i)
24587 id[i] = 0xdeadbeef;
24588 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
24589 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
24590 data = 8;
24591 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24592 data = read_uav_counter(context, staging_buffer, uav);
24593 ok(data == 8, "Got unexpected value %u.\n", data);
24595 /* consume */
24596 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24597 data = read_uav_counter(context, staging_buffer, uav);
24598 ok(data == 4, "Got unexpected value %u.\n", data);
24599 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24600 data = read_uav_counter(context, staging_buffer, uav);
24601 ok(!data, "Got unexpected value %u.\n", data);
24602 get_buffer_readback(buffer2, &rb);
24603 for (i = 0; i < 8; ++i)
24605 data = get_readback_color(&rb, i, 0, 0);
24606 ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
24608 release_resource_readback(&rb);
24610 ID3D11Buffer_Release(buffer);
24611 ID3D11Buffer_Release(buffer2);
24612 ID3D11Buffer_Release(staging_buffer);
24613 ID3D11ComputeShader_Release(cs_producer);
24614 ID3D11ComputeShader_Release(cs_consumer);
24615 ID3D11UnorderedAccessView_Release(uav);
24616 ID3D11UnorderedAccessView_Release(uav2);
24617 release_test_context(&test_context);
24620 static void test_dispatch_indirect(void)
24622 struct stats
24624 unsigned int dispatch_count;
24625 unsigned int thread_count;
24626 unsigned int max_x;
24627 unsigned int max_y;
24628 unsigned int max_z;
24631 ID3D11Buffer *append_buffer, *stats_buffer, *args_buffer, *staging_buffer;
24632 ID3D11UnorderedAccessView *uav, *stats_uav;
24633 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24634 ID3D11ComputeShader *cs_append, *cs_stats;
24635 struct d3d11_test_context test_context;
24636 D3D11_BUFFER_DESC buffer_desc;
24637 ID3D11DeviceContext *context;
24638 struct resource_readback rb;
24639 ID3D11Device *device;
24640 unsigned int data, i;
24641 struct stats *stats;
24642 HRESULT hr;
24644 static const DWORD cs_append_code[] =
24646 #if 0
24647 struct dispatch_args
24649 uint x, y, z;
24652 AppendStructuredBuffer<dispatch_args> u;
24654 [numthreads(1, 1, 1)]
24655 void main()
24657 dispatch_args args = {4, 2, 1};
24658 u.Append(args);
24659 args.y = 1;
24660 u.Append(args);
24661 args.x = 3;
24662 u.Append(args);
24664 #endif
24665 0x43425844, 0x954de75a, 0x8bb1b78b, 0x84ded464, 0x9d9532b7, 0x00000001, 0x00000158, 0x00000003,
24666 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24667 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000104, 0x00050050, 0x00000041, 0x0100086a,
24668 0x0400009e, 0x0011e000, 0x00000000, 0x0000000c, 0x02000068, 0x00000001, 0x0400009b, 0x00000001,
24669 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x0c0000a8,
24670 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002, 0x00000004,
24671 0x00000002, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000,
24672 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002,
24673 0x00000004, 0x00000001, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
24674 0x00000000, 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
24675 0x00004002, 0x00000003, 0x00000001, 0x00000001, 0x00000000, 0x0100003e,
24677 static const DWORD cs_stats_code[] =
24679 #if 0
24680 struct stats
24682 uint dispatch_count;
24683 uint thread_count;
24684 uint max_x;
24685 uint max_y;
24686 uint max_z;
24689 RWStructuredBuffer<stats> u;
24691 [numthreads(1, 1, 1)]
24692 void main(uint3 id : SV_DispatchThreadID)
24694 if (all(!id))
24695 InterlockedAdd(u[0].dispatch_count, 1);
24696 InterlockedAdd(u[0].thread_count, 1);
24697 InterlockedMax(u[0].max_x, id.x);
24698 InterlockedMax(u[0].max_y, id.y);
24699 InterlockedMax(u[0].max_z, id.z);
24701 #endif
24702 0x43425844, 0xbd3f2e4e, 0xb0f61ff7, 0xa8e10584, 0x2f61aec9, 0x00000001, 0x000001bc, 0x00000003,
24703 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24704 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000168, 0x00050050, 0x0000005a, 0x0100086a,
24705 0x0400009e, 0x0011e000, 0x00000000, 0x00000014, 0x0200005f, 0x00020072, 0x02000068, 0x00000001,
24706 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x09000020, 0x00100072, 0x00000000, 0x00020246,
24707 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000001, 0x00100012, 0x00000000,
24708 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00100012, 0x00000000, 0x0010002a,
24709 0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x0a0000ad, 0x0011e000,
24710 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001,
24711 0x01000015, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000,
24712 0x00000000, 0x00004001, 0x00000001, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002, 0x00000000,
24713 0x00000008, 0x00000000, 0x00000000, 0x0002000a, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002,
24714 0x00000000, 0x0000000c, 0x00000000, 0x00000000, 0x0002001a, 0x090000b0, 0x0011e000, 0x00000000,
24715 0x00004002, 0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x0002002a, 0x0100003e,
24717 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24718 static const unsigned int zero[4] = {0, 0, 0, 0};
24720 if (!init_test_context(&test_context, &feature_level))
24721 return;
24723 device = test_context.device;
24724 context = test_context.immediate_context;
24726 hr = ID3D11Device_CreateComputeShader(device, cs_append_code, sizeof(cs_append_code), NULL, &cs_append);
24727 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24728 hr = ID3D11Device_CreateComputeShader(device, cs_stats_code, sizeof(cs_stats_code), NULL, &cs_stats);
24729 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24731 memset(&buffer_desc, 0, sizeof(buffer_desc));
24732 buffer_desc.ByteWidth = sizeof(unsigned int);
24733 buffer_desc.Usage = D3D11_USAGE_STAGING;
24734 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
24735 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
24736 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24738 buffer_desc.ByteWidth = 60;
24739 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24740 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24741 buffer_desc.CPUAccessFlags = 0;
24742 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24743 buffer_desc.StructureByteStride = 3 * sizeof(unsigned int);
24744 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &append_buffer);
24745 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24746 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
24747 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24748 U(uav_desc).Buffer.FirstElement = 0;
24749 U(uav_desc).Buffer.NumElements = 5;
24750 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
24751 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)append_buffer, &uav_desc, &uav);
24752 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24754 /* We use a separate buffer because D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
24755 * and D3D11_RESOURCE_MISC_BUFFER_STRUCTURED are mutually exclusive flags.
24757 buffer_desc.BindFlags = 0;
24758 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
24759 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &args_buffer);
24760 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24762 buffer_desc.ByteWidth = sizeof(*stats);
24763 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24764 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24765 buffer_desc.StructureByteStride = sizeof(*stats);
24766 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &stats_buffer);
24767 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24768 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)stats_buffer, NULL, &stats_uav);
24769 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24771 data = read_uav_counter(context, staging_buffer, uav);
24772 ok(!data, "Got unexpected initial value %u.\n", data);
24773 data = 8;
24774 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24775 data = read_uav_counter(context, staging_buffer, uav);
24776 ok(data == 8, "Got unexpected value %u.\n", data);
24778 ID3D11DeviceContext_CSSetShader(context, cs_append, NULL, 0);
24779 data = 0;
24780 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24781 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24782 data = read_uav_counter(context, staging_buffer, uav);
24783 ok(data == 3, "Got unexpected value %u.\n", data);
24784 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)args_buffer, (ID3D11Resource *)append_buffer);
24786 ID3D11DeviceContext_CSSetShader(context, cs_stats, NULL, 0);
24787 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, stats_uav, zero);
24788 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &stats_uav, NULL);
24789 data = read_uav_counter(context, staging_buffer, uav);
24790 for (i = 0; i < data; ++i)
24791 ID3D11DeviceContext_DispatchIndirect(context, args_buffer, i * 3 * sizeof(unsigned int));
24792 get_buffer_readback(stats_buffer, &rb);
24793 stats = rb.map_desc.pData;
24794 ok(stats->dispatch_count == 3, "Got unexpected dispatch count %u.\n", stats->dispatch_count);
24795 ok(stats->thread_count == 15, "Got unexpected thread count %u.\n", stats->thread_count);
24796 ok(stats->max_x == 3, "Got unexpected max x %u.\n", stats->max_x);
24797 ok(stats->max_y == 1, "Got unexpected max y %u.\n", stats->max_y);
24798 ok(stats->max_z == 0, "Got unexpected max z %u.\n", stats->max_z);
24799 release_resource_readback(&rb);
24801 ID3D11Buffer_Release(append_buffer);
24802 ID3D11Buffer_Release(args_buffer);
24803 ID3D11Buffer_Release(staging_buffer);
24804 ID3D11Buffer_Release(stats_buffer);
24805 ID3D11ComputeShader_Release(cs_append);
24806 ID3D11ComputeShader_Release(cs_stats);
24807 ID3D11UnorderedAccessView_Release(uav);
24808 ID3D11UnorderedAccessView_Release(stats_uav);
24809 release_test_context(&test_context);
24812 static void test_compute_shader_registers(void)
24814 struct data
24816 unsigned int group_id[3];
24817 unsigned int group_index;
24818 unsigned int dispatch_id[3];
24819 unsigned int thread_id[3];
24822 struct d3d11_test_context test_context;
24823 unsigned int i, x, y, group_x, group_y;
24824 ID3D11UnorderedAccessView *uav;
24825 D3D11_BUFFER_DESC buffer_desc;
24826 ID3D11DeviceContext *context;
24827 struct resource_readback rb;
24828 ID3D11Buffer *cb, *buffer;
24829 struct uvec4 dimensions;
24830 ID3D11ComputeShader *cs;
24831 const struct data *data;
24832 ID3D11Device *device;
24833 HRESULT hr;
24835 static const DWORD cs_code[] =
24837 #if 0
24838 struct data
24840 uint3 group_id;
24841 uint group_index;
24842 uint3 dispatch_id;
24843 uint3 group_thread_id;
24846 RWStructuredBuffer<data> u;
24848 uint2 dim;
24850 [numthreads(3, 2, 1)]
24851 void main(uint3 group_id : SV_GroupID,
24852 uint group_index : SV_GroupIndex,
24853 uint3 dispatch_id : SV_DispatchThreadID,
24854 uint3 group_thread_id : SV_GroupThreadID)
24856 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
24857 u[i].group_id = group_id;
24858 u[i].group_index = group_index;
24859 u[i].dispatch_id = dispatch_id;
24860 u[i].group_thread_id = group_thread_id;
24862 #endif
24863 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
24864 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24865 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
24866 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
24867 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
24868 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
24869 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
24870 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
24871 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
24872 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
24873 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
24874 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
24875 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
24876 0x0100003e,
24878 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24880 if (!init_test_context(&test_context, &feature_level))
24881 return;
24883 device = test_context.device;
24884 context = test_context.immediate_context;
24886 buffer_desc.ByteWidth = 10240;
24887 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24888 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24889 buffer_desc.CPUAccessFlags = 0;
24890 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24891 buffer_desc.StructureByteStride = 40;
24892 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
24893 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24894 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24895 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
24896 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24898 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
24900 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
24901 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24903 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24904 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
24905 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24907 dimensions.x = 2;
24908 dimensions.y = 3;
24909 dimensions.z = 1;
24910 dimensions.w = 0;
24911 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24912 NULL, &dimensions, 0, 0);
24913 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
24915 get_buffer_readback(buffer, &rb);
24916 i = 0;
24917 data = rb.map_desc.pData;
24918 for (y = 0; y < dimensions.y; ++y)
24920 for (group_y = 0; group_y < 2; ++group_y)
24922 for (x = 0; x < dimensions.x; ++x)
24924 for (group_x = 0; group_x < 3; ++group_x)
24926 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
24927 const unsigned int group_index = group_y * 3 + group_x;
24928 const struct data *d = &data[i];
24930 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
24931 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
24932 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
24933 i, x, y, group_x, group_y);
24934 ok(d->group_index == group_index,
24935 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
24936 d->group_index, group_index, i, x, y, group_x, group_y);
24937 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
24938 && !d->dispatch_id[2],
24939 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
24940 "at %u (%u, %u, %u, %u).\n",
24941 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
24942 dispatch_id[0], dispatch_id[1], 0,
24943 i, x, y, group_x, group_y);
24944 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
24945 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
24946 "at %u (%u, %u, %u, %u).\n",
24947 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
24948 i, x, y, group_x, group_y);
24949 ++i;
24954 release_resource_readback(&rb);
24956 ID3D11Buffer_Release(cb);
24957 ID3D11Buffer_Release(buffer);
24958 ID3D11ComputeShader_Release(cs);
24959 ID3D11UnorderedAccessView_Release(uav);
24960 release_test_context(&test_context);
24963 static void test_tgsm(void)
24965 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24966 struct d3d11_test_context test_context;
24967 ID3D11UnorderedAccessView *uav, *uav2;
24968 struct resource_readback rb, rb2;
24969 unsigned int i, data, expected;
24970 ID3D11Buffer *buffer, *buffer2;
24971 D3D11_BUFFER_DESC buffer_desc;
24972 ID3D11DeviceContext *context;
24973 ID3D11ComputeShader *cs;
24974 ID3D11Device *device;
24975 float float_data;
24976 HRESULT hr;
24978 static const DWORD raw_tgsm_code[] =
24980 #if 0
24981 RWByteAddressBuffer u;
24982 groupshared uint m;
24984 [numthreads(32, 1, 1)]
24985 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
24987 if (!local_idx)
24988 m = group_id.x;
24989 GroupMemoryBarrierWithGroupSync();
24990 InterlockedAdd(m, group_id.x);
24991 GroupMemoryBarrierWithGroupSync();
24992 if (!local_idx)
24993 u.Store(4 * group_id.x, m);
24995 #endif
24996 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
24997 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24998 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
24999 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
25000 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
25001 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
25002 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
25003 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
25004 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
25005 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
25006 0x01000015, 0x0100003e,
25008 static const DWORD structured_tgsm_code[] =
25010 #if 0
25011 #define GROUP_SIZE 32
25013 RWByteAddressBuffer u;
25014 RWByteAddressBuffer u2;
25015 groupshared uint m[GROUP_SIZE];
25017 [numthreads(GROUP_SIZE, 1, 1)]
25018 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
25020 uint sum, original, i;
25022 if (!local_idx)
25024 for (i = 0; i < GROUP_SIZE; ++i)
25025 m[i] = 2 * group_id.x;
25027 GroupMemoryBarrierWithGroupSync();
25028 InterlockedAdd(m[local_idx], 1);
25029 GroupMemoryBarrierWithGroupSync();
25030 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
25031 u.InterlockedExchange(4 * group_id.x, sum, original);
25032 u2.Store(4 * group_id.x, original);
25034 #endif
25035 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
25036 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
25037 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
25038 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
25039 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
25040 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
25041 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
25042 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
25043 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
25044 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
25045 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
25046 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
25047 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
25048 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
25049 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
25050 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
25051 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
25052 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
25053 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
25054 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
25055 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
25056 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
25058 static const DWORD structured_tgsm_float_code[] =
25060 #if 0
25061 #define GROUP_SIZE 32
25063 struct data
25065 float f;
25066 uint u;
25069 RWBuffer<float> u;
25070 RWBuffer<uint> u2;
25071 groupshared data m[GROUP_SIZE];
25073 [numthreads(GROUP_SIZE, 1, 1)]
25074 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
25075 uint thread_id : SV_DispatchThreadID)
25077 uint i;
25078 if (!local_idx)
25080 for (i = 0; i < GROUP_SIZE; ++i)
25082 m[i].f = group_id.x;
25083 m[i].u = group_id.x;
25086 GroupMemoryBarrierWithGroupSync();
25087 for (i = 0; i < local_idx; ++i)
25089 m[local_idx].f += group_id.x;
25090 m[local_idx].u += group_id.x;
25092 u[thread_id.x] = m[local_idx].f;
25093 u2[thread_id.x] = m[local_idx].u;
25095 #endif
25096 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
25097 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
25098 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
25099 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
25100 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
25101 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
25102 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
25103 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
25104 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
25105 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
25106 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
25107 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
25108 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
25109 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
25110 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
25111 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
25112 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
25113 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
25114 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
25115 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
25116 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
25117 0x00100556, 0x00000000, 0x0100003e,
25119 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25120 static const unsigned int zero[4] = {0};
25122 if (!init_test_context(&test_context, &feature_level))
25123 return;
25125 device = test_context.device;
25126 context = test_context.immediate_context;
25128 buffer_desc.ByteWidth = 1024;
25129 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
25130 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
25131 buffer_desc.CPUAccessFlags = 0;
25132 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
25133 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
25134 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
25136 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
25137 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
25138 U(uav_desc).Buffer.FirstElement = 0;
25139 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
25140 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
25141 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
25142 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
25144 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
25145 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
25147 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
25148 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
25150 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
25151 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
25152 get_buffer_readback(buffer, &rb);
25153 for (i = 0; i < 64; ++i)
25155 data = get_readback_color(&rb, i, 0, 0);
25156 expected = 33 * i;
25157 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
25159 release_resource_readback(&rb);
25161 ID3D11Buffer_Release(buffer);
25162 ID3D11ComputeShader_Release(cs);
25163 ID3D11UnorderedAccessView_Release(uav);
25165 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
25166 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
25167 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
25168 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
25169 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
25170 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
25171 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
25172 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
25173 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
25174 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
25176 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
25177 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
25178 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
25180 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
25181 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
25182 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
25183 get_buffer_readback(buffer, &rb);
25184 get_buffer_readback(buffer2, &rb2);
25185 for (i = 0; i < 32; ++i)
25187 expected = 64 * i + 32;
25188 data = get_readback_color(&rb, i, 0, 0);
25189 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
25190 data = get_readback_color(&rb2, i, 0, 0);
25191 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
25193 release_resource_readback(&rb);
25194 release_resource_readback(&rb2);
25196 ID3D11Buffer_Release(buffer);
25197 ID3D11Buffer_Release(buffer2);
25198 ID3D11ComputeShader_Release(cs);
25199 ID3D11UnorderedAccessView_Release(uav);
25200 ID3D11UnorderedAccessView_Release(uav2);
25202 buffer_desc.MiscFlags = 0;
25203 U(uav_desc).Buffer.Flags = 0;
25204 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
25205 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
25206 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
25207 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
25208 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
25209 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
25210 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
25211 uav_desc.Format = DXGI_FORMAT_R32_UINT;
25212 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
25213 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
25214 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
25215 sizeof(structured_tgsm_float_code), NULL, &cs);
25216 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
25218 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
25219 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
25220 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
25222 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
25223 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
25224 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
25225 get_buffer_readback(buffer, &rb);
25226 get_buffer_readback(buffer2, &rb2);
25227 for (i = 0; i < 96; ++i)
25229 expected = (i % 32 + 1) * (i / 32);
25230 float_data = get_readback_float(&rb, i, 0);
25231 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
25232 data = get_readback_color(&rb2, i, 0, 0);
25233 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
25235 release_resource_readback(&rb);
25236 release_resource_readback(&rb2);
25238 ID3D11Buffer_Release(buffer);
25239 ID3D11Buffer_Release(buffer2);
25240 ID3D11ComputeShader_Release(cs);
25241 ID3D11UnorderedAccessView_Release(uav);
25242 ID3D11UnorderedAccessView_Release(uav2);
25243 release_test_context(&test_context);
25246 static void test_geometry_shader(void)
25248 static const struct
25250 struct vec4 position;
25251 unsigned int color;
25253 vertex[] =
25255 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
25257 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
25259 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
25260 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
25262 #if 0
25263 struct vs_data
25265 float4 pos : SV_POSITION;
25266 float4 color : COLOR;
25269 void main(in struct vs_data vs_input, out struct vs_data vs_output)
25271 vs_output.pos = vs_input.pos;
25272 vs_output.color = vs_input.color;
25274 #endif
25275 static const DWORD vs_code[] =
25277 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
25278 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25279 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
25280 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25281 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
25282 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
25283 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
25284 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
25285 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
25286 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
25287 0x0100003e,
25289 #if 0
25290 struct gs_data
25292 float4 pos : SV_POSITION;
25293 float4 color : COLOR;
25296 [maxvertexcount(4)]
25297 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
25299 float offset = 0.2 * vin[0].pos.w;
25300 gs_data v;
25302 v.color = vin[0].color;
25304 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
25305 vout.Append(v);
25306 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
25307 vout.Append(v);
25308 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
25309 vout.Append(v);
25310 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
25311 vout.Append(v);
25313 #endif
25314 static const DWORD gs_code[] =
25316 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
25317 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25318 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
25319 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25320 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
25321 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
25322 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
25323 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
25324 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
25325 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
25326 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
25327 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
25328 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
25329 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
25330 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
25331 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
25332 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
25333 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
25334 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
25335 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
25336 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
25337 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
25338 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25339 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
25340 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
25341 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
25342 0x00000001, 0x01000013, 0x0100003e,
25344 static const DWORD gs_5_0_code[] =
25346 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
25347 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25348 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
25349 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25350 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
25351 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
25352 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
25353 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
25354 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
25355 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25356 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
25357 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
25358 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
25359 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
25360 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25361 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
25362 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
25363 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
25364 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
25365 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
25366 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
25367 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
25368 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
25369 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
25370 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
25371 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
25372 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
25373 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
25374 0x0100003e,
25376 #if 0
25377 struct ps_data
25379 float4 pos : SV_POSITION;
25380 float4 color : COLOR;
25383 float4 main(struct ps_data ps_input) : SV_Target
25385 return ps_input.color;
25387 #endif
25388 static const DWORD ps_code[] =
25390 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
25391 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25392 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
25393 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25394 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
25395 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
25396 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
25397 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
25399 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
25400 struct d3d11_test_context test_context;
25401 ID3D11InputLayout *input_layout;
25402 ID3D11DeviceContext *context;
25403 unsigned int stride, offset;
25404 struct resource_readback rb;
25405 ID3D11GeometryShader *gs;
25406 ID3D11VertexShader *vs;
25407 ID3D11PixelShader *ps;
25408 ID3D11Device *device;
25409 ID3D11Buffer *vb;
25410 DWORD color;
25411 HRESULT hr;
25413 if (!init_test_context(&test_context, NULL))
25414 return;
25416 device = test_context.device;
25417 context = test_context.immediate_context;
25419 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
25420 vs_code, sizeof(vs_code), &input_layout);
25421 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
25423 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
25425 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
25426 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
25427 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
25428 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
25429 else
25430 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
25431 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
25432 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
25433 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25435 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
25436 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
25437 stride = sizeof(*vertex);
25438 offset = 0;
25439 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
25440 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
25441 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
25442 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25444 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
25445 ID3D11DeviceContext_Draw(context, 1, 0);
25447 get_texture_readback(test_context.backbuffer, 0, &rb);
25448 color = get_readback_color(&rb, 320, 190, 0);
25449 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25450 color = get_readback_color(&rb, 255, 240, 0);
25451 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25452 color = get_readback_color(&rb, 320, 240, 0);
25453 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
25454 color = get_readback_color(&rb, 385, 240, 0);
25455 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25456 color = get_readback_color(&rb, 320, 290, 0);
25457 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25458 release_resource_readback(&rb);
25460 ID3D11PixelShader_Release(ps);
25461 ID3D11GeometryShader_Release(gs);
25462 ID3D11VertexShader_Release(vs);
25463 ID3D11Buffer_Release(vb);
25464 ID3D11InputLayout_Release(input_layout);
25465 release_test_context(&test_context);
25468 struct triangle
25470 struct vec4 v[3];
25473 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
25474 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
25475 const struct triangle *triangles, unsigned int triangle_count)
25477 const struct triangle *current, *expected;
25478 struct resource_readback rb;
25479 unsigned int i, j, offset;
25480 BOOL all_match = TRUE;
25482 get_buffer_readback(buffer, &rb);
25484 for (i = 0; i < triangle_count; ++i)
25486 current = get_readback_data(&rb, i, 0, 0, sizeof(*current));
25487 expected = &triangles[i];
25489 offset = ~0u;
25490 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
25492 if (compare_vec4(&current->v[0], &expected->v[j], 0))
25494 offset = j;
25495 break;
25499 if (offset == ~0u)
25501 all_match = FALSE;
25502 break;
25505 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
25507 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
25509 all_match = FALSE;
25510 break;
25513 if (!all_match)
25514 break;
25517 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
25518 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
25519 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
25520 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
25521 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
25522 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
25523 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
25524 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
25525 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
25526 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
25528 release_resource_readback(&rb);
25531 static void test_quad_tessellation(void)
25533 #if 0
25534 struct point_data
25536 float4 position : SV_POSITION;
25539 struct patch_constant_data
25541 float edges[4] : SV_TessFactor;
25542 float inside[2] : SV_InsideTessFactor;
25545 float4 tess_factors;
25546 float2 inside_tess_factors;
25548 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
25550 patch_constant_data output;
25552 output.edges[0] = tess_factors.x;
25553 output.edges[1] = tess_factors.y;
25554 output.edges[2] = tess_factors.z;
25555 output.edges[3] = tess_factors.w;
25556 output.inside[0] = inside_tess_factors.x;
25557 output.inside[1] = inside_tess_factors.y;
25559 return output;
25562 [domain("quad")]
25563 [outputcontrolpoints(4)]
25564 [outputtopology("triangle_ccw")]
25565 [partitioning("integer")]
25566 [patchconstantfunc("patch_constant")]
25567 point_data hs_main(InputPatch<point_data, 4> input,
25568 uint i : SV_OutputControlPointID)
25570 return input[i];
25573 [domain("quad")]
25574 point_data ds_main(patch_constant_data input,
25575 float2 tess_coord : SV_DomainLocation,
25576 const OutputPatch<point_data, 4> patch)
25578 point_data output;
25580 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
25581 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
25582 output.position = lerp(a, b, tess_coord.y);
25584 return output;
25586 #endif
25587 static const DWORD hs_quad_ccw_code[] =
25589 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
25590 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25591 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25592 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
25593 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
25594 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
25595 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
25596 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
25597 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
25598 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
25599 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
25600 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
25601 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
25602 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
25603 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
25604 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25605 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
25606 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
25607 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25608 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
25609 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
25610 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
25612 static const DWORD ds_quad_code[] =
25614 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
25615 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25616 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25617 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
25618 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
25619 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
25620 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
25621 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
25622 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
25623 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
25624 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
25625 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
25626 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25627 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
25628 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
25629 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
25630 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
25631 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
25632 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
25633 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
25634 0x0100003e,
25636 #if 0
25638 [outputtopology("triangle_cw")]
25640 #endif
25641 static const DWORD hs_quad_cw_code[] =
25643 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
25644 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25645 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25646 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
25647 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
25648 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
25649 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
25650 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
25651 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
25652 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
25653 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
25654 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
25655 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
25656 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
25657 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
25658 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25659 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
25660 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
25661 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25662 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
25663 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
25664 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
25666 #if 0
25667 struct point_data
25669 float4 pos : SV_POSITION;
25672 [maxvertexcount(3)]
25673 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
25675 for (uint i = 0; i < 3; ++i)
25676 vout.Append(vin[i]);
25678 #endif
25679 static const DWORD gs_code[] =
25681 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
25682 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
25683 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
25684 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
25685 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
25686 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
25687 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
25688 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
25689 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
25690 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
25691 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
25692 0x0100003e,
25694 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
25696 {0, "SV_POSITION", 0, 0, 4, 0},
25698 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25699 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
25700 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
25701 static const BYTE zero_data[1024];
25702 static const struct triangle expected_quad_ccw[] =
25704 {{{-1.0f, -1.0f, 0.0f, 1.0f},
25705 { 1.0f, -1.0f, 0.0f, 1.0f},
25706 {-1.0f, 1.0f, 0.0f, 1.0f}}},
25707 {{{-1.0f, 1.0f, 0.0f, 1.0f},
25708 { 1.0f, -1.0f, 0.0f, 1.0f},
25709 { 1.0f, 1.0f, 0.0f, 1.0f}}},
25710 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
25711 { 0.0f, 0.0f, 0.0f, 0.0f},
25712 { 0.0f, 0.0f, 0.0f, 0.0f}}},
25714 static const struct triangle expected_quad_cw[] =
25716 {{{-1.0f, -1.0f, 0.0f, 1.0f},
25717 {-1.0f, 1.0f, 0.0f, 1.0f},
25718 { 1.0f, -1.0f, 0.0f, 1.0f}}},
25719 {{{-1.0f, 1.0f, 0.0f, 1.0f},
25720 { 1.0f, 1.0f, 0.0f, 1.0f},
25721 { 1.0f, -1.0f, 0.0f, 1.0f}}},
25722 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
25723 { 0.0f, 0.0f, 0.0f, 0.0f},
25724 { 0.0f, 0.0f, 0.0f, 0.0f}}},
25726 struct
25728 float tess_factors[4];
25729 float inside_tess_factors[2];
25730 DWORD padding[2];
25731 } constant;
25733 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
25734 struct d3d11_test_context test_context;
25735 ID3D11DeviceContext *context;
25736 ID3D11Buffer *cb, *so_buffer;
25737 D3D11_QUERY_DESC query_desc;
25738 ID3D11Asynchronous *query;
25739 ID3D11GeometryShader *gs;
25740 ID3D11DomainShader *ds;
25741 const UINT offset = 0;
25742 ID3D11HullShader *hs;
25743 ID3D11Device *device;
25744 unsigned int i;
25745 HRESULT hr;
25747 if (!init_test_context(&test_context, &feature_level))
25748 return;
25750 device = test_context.device;
25751 context = test_context.immediate_context;
25753 draw_color_quad(&test_context, &white);
25754 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25756 set_quad_color(&test_context, &green);
25757 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
25759 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
25760 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
25761 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
25762 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
25763 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
25765 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
25766 constant.tess_factors[i] = 1.0f;
25767 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
25768 constant.inside_tess_factors[i] = 1.0f;
25769 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
25770 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
25771 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
25772 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
25773 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
25774 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
25775 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
25776 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
25778 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25779 ID3D11DeviceContext_Draw(context, 4, 0);
25780 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25781 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
25782 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
25784 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
25786 ID3D11HullShader_Release(hs);
25787 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
25788 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
25789 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
25791 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25792 ID3D11DeviceContext_Draw(context, 4, 0);
25793 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
25794 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
25795 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
25797 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
25799 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25800 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
25801 query_desc.MiscFlags = 0;
25802 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
25803 ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
25804 ID3D11DeviceContext_Begin(context, query);
25806 set_quad_color(&test_context, &white);
25807 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
25808 constant.tess_factors[i] = 2.0f;
25809 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25810 ID3D11DeviceContext_Draw(context, 4, 0);
25811 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25813 set_quad_color(&test_context, &green);
25814 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
25815 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25816 ID3D11DeviceContext_Draw(context, 4, 0);
25817 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25819 ID3D11DeviceContext_End(context, query);
25820 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
25821 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
25822 (unsigned int)so_statistics.NumPrimitivesWritten);
25823 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
25824 (unsigned int)so_statistics.PrimitivesStorageNeeded);
25825 ID3D11DeviceContext_Begin(context, query);
25827 constant.tess_factors[0] = 5.0f;
25828 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25829 ID3D11DeviceContext_Draw(context, 4, 0);
25830 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
25832 ID3D11DeviceContext_End(context, query);
25833 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
25834 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
25835 (unsigned int)so_statistics.NumPrimitivesWritten);
25836 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
25837 (unsigned int)so_statistics.PrimitivesStorageNeeded);
25838 ID3D11Asynchronous_Release(query);
25840 ID3D11Buffer_Release(so_buffer);
25841 ID3D11GeometryShader_Release(gs);
25842 ID3D11DomainShader_Release(ds);
25843 ID3D11HullShader_Release(hs);
25844 ID3D11Buffer_Release(cb);
25845 release_test_context(&test_context);
25848 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
25849 static void check_so_desc_(unsigned int line, ID3D11Device *device,
25850 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
25851 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
25852 unsigned int rasterizer_stream)
25854 ID3D11GeometryShader *gs;
25855 HRESULT hr;
25857 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
25858 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
25859 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
25860 if (SUCCEEDED(hr))
25861 ID3D11GeometryShader_Release(gs);
25864 #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)
25865 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
25866 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
25867 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
25868 unsigned int rasterizer_stream)
25870 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
25871 HRESULT hr;
25873 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
25874 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
25875 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
25876 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
25877 if (SUCCEEDED(hr))
25878 ID3D11GeometryShader_Release(gs);
25881 static void test_stream_output(void)
25883 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
25884 struct d3d11_test_context test_context;
25885 unsigned int i, count;
25886 ID3D11Device *device;
25888 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25889 static const DWORD vs_code[] =
25891 #if 0
25892 struct data
25894 float4 position : SV_Position;
25895 float4 attrib1 : ATTRIB1;
25896 float3 attrib2 : attrib2;
25897 float2 attrib3 : ATTriB3;
25898 float attrib4 : ATTRIB4;
25901 void main(in data i, out data o)
25903 o = i;
25905 #endif
25906 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
25907 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
25908 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
25909 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
25910 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
25911 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
25912 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
25913 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
25914 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
25915 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
25916 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
25917 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
25918 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
25919 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
25920 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25921 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
25922 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
25923 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
25924 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
25925 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
25927 static const DWORD gs_code[] =
25929 #if 0
25930 struct data
25932 float4 position : SV_Position;
25933 float4 attrib1 : ATTRIB1;
25934 float3 attrib2 : attrib2;
25935 float2 attrib3 : ATTriB3;
25936 float attrib4 : ATTRIB4;
25939 [maxvertexcount(1)]
25940 void main(point data i[1], inout PointStream<data> o)
25942 o.Append(i[0]);
25944 #endif
25945 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
25946 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
25947 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
25948 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
25949 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
25950 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
25951 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
25952 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
25953 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
25954 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
25955 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
25956 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
25957 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
25958 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
25959 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
25960 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25961 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
25962 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
25963 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25964 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
25965 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
25967 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
25969 {0, "SV_Position", 0, 0, 4, 0},
25971 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
25973 {0, "SV_Position", 0, 0, 4, 0},
25974 {0, NULL, 0, 0, 0, 0},
25976 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
25978 /* SemanticName and SemanticIndex */
25980 {0, "sv_position", 0, 0, 4, 0},
25981 {0, "attrib", 1, 0, 4, 0},
25984 {0, "sv_position", 0, 0, 4, 0},
25985 {0, "ATTRIB", 1, 0, 4, 0},
25987 /* Gaps */
25989 {0, "SV_POSITION", 0, 0, 4, 0},
25990 {0, NULL, 0, 0, 8, 0},
25991 {0, "ATTRIB", 1, 0, 4, 0},
25994 {0, "SV_POSITION", 0, 0, 4, 0},
25995 {0, NULL, 0, 0, 4, 0},
25996 {0, NULL, 0, 0, 4, 0},
25997 {0, "ATTRIB", 1, 0, 4, 0},
25999 /* ComponentCount */
26001 {0, "ATTRIB", 1, 0, 4, 0},
26004 {0, "ATTRIB", 2, 0, 3, 0},
26007 {0, "ATTRIB", 3, 0, 2, 0},
26010 {0, "ATTRIB", 4, 0, 1, 0},
26012 /* ComponentIndex */
26014 {0, "ATTRIB", 1, 1, 3, 0},
26017 {0, "ATTRIB", 1, 2, 2, 0},
26020 {0, "ATTRIB", 1, 3, 1, 0},
26023 {0, "ATTRIB", 3, 1, 1, 0},
26025 /* OutputSlot */
26027 {0, "attrib", 1, 0, 4, 0},
26030 {0, "attrib", 1, 0, 4, 1},
26033 {0, "attrib", 1, 0, 4, 2},
26036 {0, "attrib", 1, 0, 4, 3},
26039 {0, "attrib", 1, 0, 4, 0},
26040 {0, "attrib", 2, 0, 3, 1},
26041 {0, NULL, 0, 0, 1, 1},
26042 {0, "attrib", 3, 0, 2, 2},
26043 {0, NULL, 0, 0, 2, 2},
26044 {0, "attrib", 4, 0, 1, 3},
26045 {0, NULL, 0, 0, 7, 3},
26048 {0, "attrib", 1, 0, 4, 0},
26049 {0, "attrib", 2, 0, 3, 1},
26050 {0, NULL, 0, 0, 1, 1},
26051 {0, "attrib", 3, 0, 2, 2},
26052 {0, NULL, 0, 0, 1, 2},
26053 {0, NULL, 0, 0, 1, 2},
26054 {0, "attrib", 4, 0, 1, 3},
26055 {0, NULL, 0, 0, 3, 3},
26056 {0, NULL, 0, 0, 1, 3},
26057 {0, NULL, 0, 0, 1, 3},
26058 {0, NULL, 0, 0, 1, 3},
26059 {0, NULL, 0, 0, 1, 3},
26062 {0, "attrib", 1, 0, 4, 0},
26063 {0, "attrib", 2, 0, 3, 0},
26064 {0, "attrib", 3, 0, 2, 0},
26065 {0, NULL, 0, 0, 1, 0},
26066 {0, "attrib", 4, 0, 1, 0},
26069 {0, "attrib", 1, 0, 4, 0},
26070 {0, "attrib", 2, 0, 3, 0},
26071 {0, "attrib", 3, 0, 2, 3},
26072 {0, NULL, 0, 0, 1, 3},
26073 {0, "attrib", 4, 0, 1, 3},
26075 /* Multiple occurrences of the same output */
26077 {0, "ATTRIB", 1, 0, 2, 0},
26078 {0, "ATTRIB", 1, 2, 2, 1},
26081 {0, "ATTRIB", 1, 0, 1, 0},
26082 {0, "ATTRIB", 1, 1, 3, 0},
26085 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
26087 /* SemanticName and SemanticIndex */
26089 {0, "SV_Position", 0, 0, 4, 0},
26090 {0, "ATTRIB", 0, 0, 4, 0},
26093 {0, "sv_position", 0, 0, 4, 0},
26094 {0, "ATTRIB_", 1, 0, 4, 0},
26096 /* Gaps */
26098 {0, "SV_POSITION", 0, 0, 4, 0},
26099 {0, NULL, 0, 1, 8, 0},
26100 {0, "ATTRIB", 1, 0, 4, 0},
26103 {0, "SV_POSITION", 0, 0, 4, 0},
26104 {0, NULL, 1, 0, 8, 0},
26105 {0, "ATTRIB", 1, 0, 4, 0},
26107 /* Buffer stride */
26109 {0, "SV_POSITION", 0, 0, 4, 0},
26110 {0, NULL, 0, 0, 8, 0},
26111 {0, NULL, 0, 0, 8, 0},
26112 {0, "ATTRIB", 1, 0, 4, 0},
26114 /* ComponentCount */
26116 {0, "ATTRIB", 2, 0, 5, 0},
26119 {0, "ATTRIB", 2, 0, 4, 0},
26122 {0, "ATTRIB", 3, 0, 3, 0},
26125 {0, "ATTRIB", 4, 0, 2, 0},
26127 /* ComponentIndex */
26129 {0, "ATTRIB", 1, 1, 4, 0},
26132 {0, "ATTRIB", 1, 2, 3, 0},
26135 {0, "ATTRIB", 1, 3, 2, 0},
26138 {0, "ATTRIB", 1, 4, 0, 0},
26141 {0, "ATTRIB", 1, 4, 1, 0},
26144 {0, "ATTRIB", 3, 2, 1, 0},
26147 {0, "ATTRIB", 3, 2, 0, 0},
26149 /* OutputSlot */
26151 {0, "attrib", 1, 0, 4, 4},
26154 {0, "attrib", 1, 0, 4, 4},
26157 {0, "attrib", 1, 0, 4, 4},
26160 {0, "attrib", 1, 0, 4, 4},
26163 {0, "attrib", 1, 0, 4, 0},
26164 {0, "attrib", 2, 0, 3, 1},
26165 {0, NULL, 0, 0, 1, 1},
26166 {0, "attrib", 3, 0, 2, 2},
26167 {0, NULL, 0, 0, 2, 2},
26168 {0, "attrib", 4, 0, 1, 3},
26169 {0, NULL, 0, 0, 3, 4},
26172 {0, "attrib", 1, 0, 4, 0},
26173 {0, "attrib", 2, 0, 3, 0},
26174 {0, "attrib", 3, 0, 2, 0},
26175 {0, NULL, 0, 0, 1, 0},
26176 {0, "attrib", 4, 0, 1, 0},
26177 {0, NULL, 0, 0, 3, 3},
26178 {0, NULL, 0, 0, 1, 3},
26179 {0, NULL, 0, 0, 1, 3},
26180 {0, NULL, 0, 0, 1, 3},
26181 {0, NULL, 0, 0, 1, 3},
26184 {0, "attrib", 1, 0, 4, 0},
26185 {0, NULL, 0, 0, 3, 1},
26186 {0, NULL, 0, 0, 1, 1},
26187 {0, NULL, 0, 0, 1, 2},
26188 {0, "attrib", 2, 0, 3, 3},
26189 {0, NULL, 0, 0, 1, 3},
26192 {0, "attrib", 2, 0, 3, 3},
26193 {0, NULL, 0, 0, 3, 1},
26194 {0, NULL, 0, 0, 1, 3},
26195 {0, "attrib", 1, 0, 4, 0},
26196 {0, NULL, 0, 0, 1, 2},
26197 {0, NULL, 0, 0, 1, 1},
26199 /* Stream */
26201 {1, "attrib", 1, 0, 4, 0},
26204 {4, "attrib", 1, 0, 4, 0},
26206 /* Multiple occurrences of the same output */
26208 {0, "ATTRIB", 1, 0, 4, 0},
26209 {0, "ATTRIB", 1, 0, 4, 1},
26212 {0, "ATTRIB", 1, 0, 4, 0},
26213 {0, "ATTRIB", 1, 0, 3, 0},
26217 if (!init_test_context(&test_context, &feature_level))
26218 return;
26220 device = test_context.device;
26222 for (i = 0; i < ARRAY_SIZE(stride); ++i)
26223 stride[i] = 64;
26225 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26226 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26227 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26228 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26229 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26230 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26232 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
26233 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26234 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
26235 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26237 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
26238 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26239 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
26240 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
26241 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26243 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
26244 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26245 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
26246 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26248 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
26250 unsigned int max_output_slot = 0;
26251 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
26253 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
26254 max_output_slot = max(max_output_slot, e->OutputSlot);
26255 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26256 break;
26259 /* Buffer strides are required for all buffers. */
26260 if (!max_output_slot)
26262 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26263 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26264 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26265 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26266 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26267 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
26268 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26269 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
26270 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26271 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
26273 else
26275 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26276 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26277 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
26278 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
26282 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
26284 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
26286 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
26287 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26288 break;
26291 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26292 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26293 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26294 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
26295 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26296 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
26297 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26298 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
26301 /* Buffer strides */
26302 stride[1] = 63;
26303 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26304 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
26305 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26306 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
26307 stride[1] = 1;
26308 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26309 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
26310 stride[0] = 0;
26311 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26312 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
26314 /* Rasterizer stream */
26315 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
26316 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
26317 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26318 NULL, 0, D3D11_SO_STREAM_COUNT);
26320 release_test_context(&test_context);
26323 static void test_fl10_stream_output_desc(void)
26325 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
26326 struct d3d11_test_context test_context;
26327 unsigned int i, count;
26328 ID3D11Device *device;
26330 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
26331 static const DWORD vs_code[] =
26333 #if 0
26334 struct data
26336 float4 position : SV_Position;
26337 float4 attrib1 : ATTRIB1;
26338 float3 attrib2 : attrib2;
26339 float2 attrib3 : ATTriB3;
26340 float attrib4 : ATTRIB4;
26343 void main(in data i, out data o)
26345 o = i;
26347 #endif
26348 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
26349 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
26350 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
26351 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26352 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
26353 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
26354 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
26355 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26356 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
26357 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
26358 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
26359 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
26360 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
26361 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
26362 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
26363 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
26364 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
26365 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
26366 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
26367 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
26369 static const DWORD gs_code[] =
26371 #if 0
26372 struct data
26374 float4 position : SV_Position;
26375 float4 attrib1 : ATTRIB1;
26376 float3 attrib2 : attrib2;
26377 float2 attrib3 : ATTriB3;
26378 float attrib4 : ATTRIB4;
26381 [maxvertexcount(1)]
26382 void main(point data i[1], inout PointStream<data> o)
26384 o.Append(i[0]);
26386 #endif
26387 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
26388 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
26389 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
26390 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26391 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
26392 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
26393 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
26394 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26395 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
26396 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
26397 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
26398 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
26399 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
26400 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
26401 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
26402 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
26403 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
26404 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
26405 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
26406 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
26407 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
26409 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26411 {0, "SV_Position", 0, 0, 4, 0},
26413 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
26415 {0, "SV_Position", 0, 0, 4, 0},
26416 {0, NULL, 0, 0, 0, 0},
26418 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
26420 /* Gaps */
26422 {0, "SV_POSITION", 0, 0, 4, 0},
26423 {0, NULL, 0, 0, 8, 0},
26424 {0, "ATTRIB", 1, 0, 4, 0},
26427 {0, "SV_POSITION", 0, 0, 4, 0},
26428 {0, NULL, 0, 0, 4, 0},
26429 {0, NULL, 0, 0, 4, 0},
26430 {0, "ATTRIB", 1, 0, 4, 0},
26432 /* OutputSlot */
26434 {0, "attrib", 1, 0, 4, 0},
26435 {0, "attrib", 2, 0, 3, 0},
26436 {0, "attrib", 3, 0, 2, 0},
26437 {0, "attrib", 4, 0, 1, 0},
26440 {0, "attrib", 1, 0, 4, 0},
26441 {0, "attrib", 2, 0, 3, 1},
26442 {0, "attrib", 3, 0, 2, 2},
26443 {0, "attrib", 4, 0, 1, 3},
26446 {0, "attrib", 1, 0, 4, 0},
26447 {0, "attrib", 2, 0, 3, 3},
26450 {0, "attrib", 1, 0, 4, 0},
26451 {0, "attrib", 2, 0, 3, 0},
26452 {0, "attrib", 3, 0, 2, 0},
26453 {0, NULL, 0, 0, 1, 0},
26454 {0, "attrib", 4, 0, 1, 0},
26456 /* Multiple occurrences of the same output */
26458 {0, "ATTRIB", 1, 0, 2, 0},
26459 {0, "ATTRIB", 1, 2, 2, 1},
26462 {0, "ATTRIB", 1, 0, 1, 0},
26463 {0, "ATTRIB", 1, 1, 3, 0},
26466 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
26468 /* OutputSlot */
26470 {0, "attrib", 1, 0, 4, 0},
26471 {0, NULL, 0, 0, 4, 0},
26472 {0, "attrib", 4, 0, 1, 3},
26475 {0, "attrib", 1, 0, 4, 0},
26476 {0, NULL, 0, 0, 4, 0},
26477 {0, NULL, 0, 0, 4, 0},
26478 {0, "attrib", 4, 0, 1, 3},
26481 {0, "attrib", 1, 0, 4, 0},
26482 {0, "attrib", 2, 0, 3, 0},
26483 {0, "attrib", 3, 0, 2, 0},
26484 {0, "attrib", 4, 0, 1, 1},
26487 {0, "attrib", 1, 0, 4, 0},
26488 {0, "attrib", 2, 0, 3, 0},
26489 {0, "attrib", 3, 0, 2, 3},
26490 {0, NULL, 0, 0, 1, 3},
26491 {0, "attrib", 4, 0, 1, 3},
26494 {0, "attrib", 1, 0, 4, 0},
26495 {0, "attrib", 1, 0, 3, 1},
26496 {0, "attrib", 1, 0, 2, 2},
26497 {0, "attrib", 1, 0, 1, 3},
26498 {0, NULL, 0, 0, 3, 3},
26502 if (!init_test_context(&test_context, &feature_level))
26503 return;
26505 device = test_context.device;
26507 for (i = 0; i < ARRAY_SIZE(stride); ++i)
26508 stride[i] = 64;
26510 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
26511 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
26512 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26513 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
26515 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26516 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
26518 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
26519 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
26520 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
26521 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
26522 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
26524 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
26525 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
26527 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
26529 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
26531 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
26532 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26533 break;
26536 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
26539 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
26541 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
26543 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
26544 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26545 break;
26548 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26549 stride, 1, 0);
26550 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26551 stride, 2, 0);
26552 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26553 stride, 3, 0);
26554 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26555 stride, 4, 0);
26558 /* Buffer strides */
26559 stride[1] = 63;
26560 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26561 &stride[1], 1, 0);
26562 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26563 stride, 2, 0);
26564 stride[0] = 0;
26565 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26566 stride, 1, 0);
26568 /* Rasterizer stream */
26569 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26570 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26571 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
26572 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26573 NULL, 0, i);
26574 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26576 release_test_context(&test_context);
26579 static void test_stream_output_resume(void)
26581 struct d3d11_test_context test_context;
26582 ID3D11Buffer *cb, *so_buffer, *buffer;
26583 unsigned int i, j, idx, offset;
26584 ID3D11DeviceContext *context;
26585 struct resource_readback rb;
26586 ID3D11GeometryShader *gs;
26587 const struct vec4 *data;
26588 ID3D11Device *device;
26589 HRESULT hr;
26591 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26592 static const DWORD gs_code[] =
26594 #if 0
26595 float4 constant;
26597 struct vertex
26599 float4 position : SV_POSITION;
26602 struct element
26604 float4 position : SV_POSITION;
26605 float4 so_output : so_output;
26608 [maxvertexcount(3)]
26609 void main(triangle vertex input[3], inout PointStream<element> output)
26611 element o;
26612 o.so_output = constant;
26613 o.position = input[0].position;
26614 output.Append(o);
26615 o.position = input[1].position;
26616 output.Append(o);
26617 o.position = input[2].position;
26618 output.Append(o);
26620 #endif
26621 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
26622 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26623 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
26624 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
26625 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
26626 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
26627 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
26628 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
26629 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
26630 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
26631 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
26632 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
26633 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
26634 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
26636 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26638 {0, "so_output", 0, 0, 4, 0},
26640 static const struct vec4 constants[] =
26642 {0.5f, 0.250f, 0.0f, 0.0f},
26643 {0.0f, 0.125f, 0.0f, 1.0f},
26644 {1.0f, 1.000f, 1.0f, 0.0f}
26646 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
26647 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
26648 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
26650 if (!init_test_context(&test_context, &feature_level))
26651 return;
26653 device = test_context.device;
26654 context = test_context.immediate_context;
26656 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
26657 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
26658 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
26660 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
26661 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26663 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26664 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
26666 offset = 0;
26667 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
26669 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
26670 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26672 draw_color_quad(&test_context, &red);
26673 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26675 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26676 draw_color_quad(&test_context, &green);
26677 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26679 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
26680 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26681 draw_color_quad(&test_context, &red);
26682 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26684 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26685 draw_color_quad(&test_context, &red);
26686 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
26688 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
26689 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26690 draw_color_quad(&test_context, &white);
26691 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
26693 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26694 draw_color_quad(&test_context, &green);
26695 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26697 buffer = NULL;
26698 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
26699 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26700 draw_color_quad(&test_context, &white);
26701 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26703 idx = 0;
26704 get_buffer_readback(so_buffer, &rb);
26705 for (i = 0; i < ARRAY_SIZE(constants); ++i)
26707 for (j = 0; j < 6; ++j) /* 2 triangles */
26709 data = get_readback_vec4(&rb, idx++, 0);
26710 ok(compare_vec4(data, &constants[i], 0),
26711 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
26712 data->x, data->y, data->z, data->w, idx, i, j);
26715 release_resource_readback(&rb);
26717 ID3D11Buffer_Release(cb);
26718 ID3D11Buffer_Release(so_buffer);
26719 ID3D11GeometryShader_Release(gs);
26720 release_test_context(&test_context);
26723 static void test_stream_output_components(void)
26725 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
26726 struct d3d11_test_context test_context;
26727 ID3D11InputLayout *input_layout[2];
26728 ID3D11Buffer *vb[2], *so_buffer;
26729 ID3D11DeviceContext *context;
26730 struct resource_readback rb;
26731 unsigned int stride, offset;
26732 ID3D11GeometryShader *gs;
26733 ID3D11VertexShader *vs;
26734 ID3D11PixelShader *ps;
26735 ID3D11Device *device;
26736 const float *result;
26737 unsigned int i, j;
26738 HRESULT hr;
26740 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26741 static const DWORD vs_code[] =
26743 #if 0
26744 struct vertex
26746 float4 position : POSITION;
26747 float4 color : COLOR;
26748 float4 color2 : COLOR2;
26751 void main(in vertex i, out vertex o)
26753 o = i;
26755 #endif
26756 0x43425844, 0x95991b76, 0x4898640b, 0xe36ad9d6, 0xfbfe78b4, 0x00000001, 0x00000194, 0x00000003,
26757 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26758 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26759 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26760 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26761 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26762 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
26763 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26764 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
26765 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
26766 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
26767 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
26768 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
26770 static const DWORD gs_code[] =
26772 #if 0
26773 struct vertex
26775 float4 position : POSITION;
26776 float4 color : COLOR;
26777 float4 color2 : COLOR2;
26780 [maxvertexcount(1)]
26781 void main(point vertex input[1], inout PointStream<vertex> output)
26783 output.Append(input[0]);
26785 #endif
26786 0x43425844, 0x218f7d27, 0x555fa7f1, 0x282c545f, 0x3989c843, 0x00000001, 0x000001c0, 0x00000003,
26787 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26788 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26789 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26790 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26791 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26792 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
26793 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26794 0x000000bc, 0x00020040, 0x0000002f, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x0400005f,
26795 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000002, 0x0100085d,
26796 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x03000065,
26797 0x001020f2, 0x00000002, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
26798 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001,
26799 0x06000036, 0x001020f2, 0x00000002, 0x00201e46, 0x00000000, 0x00000002, 0x01000013, 0x0100003e,
26801 static const DWORD ps_code[] =
26803 #if 0
26804 float4 main(float4 position : SV_Position,
26805 float2 texcoord : TEXCOORD) : SV_Target
26807 return float4(position.xy, texcoord);
26809 #endif
26810 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
26811 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
26812 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
26813 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
26814 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
26815 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
26816 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
26817 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
26818 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
26820 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
26822 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26823 {"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26824 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
26826 static const D3D11_INPUT_ELEMENT_DESC layout_desc2[] =
26828 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26829 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26830 {"COLOR", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
26832 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26834 {0, "POSITION", 0, 0, 4, 0},
26835 {0, "COLOR", 0, 0, 3, 0},
26836 {0, "COLOR", 2, 0, 2, 0},
26838 static const D3D11_SO_DECLARATION_ENTRY so_declaration2[] =
26840 {0, "POSITION", 0, 0, 1, 0},
26841 {0, "POSITION", 0, 1, 1, 0},
26842 {0, "POSITION", 0, 2, 1, 0},
26843 {0, "POSITION", 0, 3, 1, 0},
26844 {0, "COLOR", 0, 0, 1, 0},
26845 {0, "COLOR", 0, 1, 1, 0},
26846 {0, "COLOR", 0, 2, 1, 0},
26847 {0, "COLOR", 2, 0, 1, 0},
26848 {0, "COLOR", 2, 1, 1, 0},
26850 static const D3D11_SO_DECLARATION_ENTRY so_declaration3[] =
26852 {0, "COLOR", 0, 2, 2, 0},
26853 {0, "COLOR", 2, 3, 1, 0},
26855 static const struct
26857 struct vec4 position;
26858 struct vec3 color;
26859 struct vec2 color2;
26861 vb_data[] =
26863 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},
26864 {{-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
26865 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.5f, 0.4f}},
26866 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.1f, 0.6f}},
26868 static const struct
26870 struct vec4 position;
26871 struct vec4 color;
26872 struct vec4 color2;
26874 vb_data2[] =
26876 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
26877 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
26878 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
26879 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
26881 static const unsigned int vb_stride[] = {sizeof(*vb_data), sizeof(*vb_data2)};
26882 static const float expected_data[] =
26884 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f,
26885 -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
26886 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.4f,
26887 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.1f, 0.6f,
26889 static const float expected_data2[] =
26891 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
26892 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
26893 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
26894 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
26896 static const float expected_data3[] =
26898 3.0f, 4.0f, 8.0f, 1.2f, 1.3f, 1.7f, 2.0f, 2.1f, 2.5f, 2.7f, 2.8f, 3.2f,
26900 static const struct
26902 BOOL with_ps;
26903 unsigned int vb_idx;
26904 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
26905 unsigned int so_entry_count;
26906 const float *expected_data;
26907 unsigned int expected_data_size;
26909 tests[] =
26911 {TRUE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
26912 {TRUE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
26913 {TRUE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
26914 {TRUE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
26915 {TRUE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
26917 {FALSE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
26918 {FALSE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
26919 {FALSE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
26920 {FALSE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
26921 {FALSE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
26924 if (!init_test_context(&test_context, &feature_level))
26925 return;
26927 device = test_context.device;
26928 context = test_context.immediate_context;
26930 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
26931 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data2), vb_data2);
26933 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
26934 vs_code, sizeof(vs_code), &input_layout[0]);
26935 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26936 hr = ID3D11Device_CreateInputLayout(device, layout_desc2, ARRAY_SIZE(layout_desc2),
26937 vs_code, sizeof(vs_code), &input_layout[1]);
26938 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26940 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
26941 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
26942 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
26943 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
26945 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
26946 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
26948 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26950 gs = NULL;
26951 current_so_declaration = NULL;
26952 for (i = 0; i < ARRAY_SIZE(tests); ++i)
26954 ID3D11DeviceContext_PSSetShader(context, tests[i].with_ps ? ps : NULL, NULL, 0);
26956 if (current_so_declaration != tests[i].so_declaration)
26958 if (gs)
26959 ID3D11GeometryShader_Release(gs);
26961 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
26962 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
26963 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
26964 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
26965 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26966 current_so_declaration = tests[i].so_declaration;
26969 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].vb_idx]);
26970 stride = vb_stride[tests[i].vb_idx];
26971 offset = 0;
26972 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[tests[i].vb_idx], &stride, &offset);
26974 offset = 0;
26975 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
26977 ID3D11DeviceContext_Draw(context, 4, 0);
26979 get_buffer_readback(so_buffer, &rb);
26980 result = rb.map_desc.pData;
26981 for (j = 0; j < tests[i].expected_data_size; ++j)
26983 float expected_value = tests[i].expected_data[j];
26984 ok(compare_float(result[j], expected_value, 2),
26985 "Test %u: Got %.8e, expected %.8e at %u.\n",
26986 i, result[j], expected_value, j);
26988 release_resource_readback(&rb);
26991 for (i = 0; i < ARRAY_SIZE(vb); ++i)
26992 ID3D11Buffer_Release(vb[i]);
26993 ID3D11Buffer_Release(so_buffer);
26994 ID3D11VertexShader_Release(vs);
26995 ID3D11GeometryShader_Release(gs);
26996 ID3D11PixelShader_Release(ps);
26997 for (i = 0; i < ARRAY_SIZE(input_layout); ++i)
26998 ID3D11InputLayout_Release(input_layout[i]);
26999 release_test_context(&test_context);
27002 static void test_stream_output_vs(void)
27004 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
27005 struct d3d11_test_context test_context;
27006 ID3D11InputLayout *input_layout;
27007 ID3D11Buffer *vb, *so_buffer;
27008 ID3D11DeviceContext *context;
27009 struct resource_readback rb;
27010 ID3D11GeometryShader *gs;
27011 ID3D11VertexShader *vs;
27012 ID3D11Device *device;
27013 const float *result;
27014 unsigned int offset;
27015 unsigned int i, j;
27016 HRESULT hr;
27018 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27019 static const DWORD vs_code[] =
27021 #if 0
27022 struct vertex
27024 float4 position : POSITION;
27025 float4 color0 : COLOR0;
27026 float4 color1 : COLOR1;
27029 vertex main(in vertex i)
27031 return i;
27033 #endif
27034 0x43425844, 0xa67e993e, 0x1632c139, 0x02a7725f, 0xfb0221cd, 0x00000001, 0x00000194, 0x00000003,
27035 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
27036 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
27037 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
27038 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
27039 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
27040 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000001, 0x00000000,
27041 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
27042 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
27043 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
27044 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
27045 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
27046 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
27048 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
27050 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
27051 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
27052 {"COLOR", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
27054 static const D3D11_SO_DECLARATION_ENTRY all_so_decl[] =
27056 {0, "POSITION", 0, 0, 4, 0},
27057 {0, "COLOR", 0, 0, 3, 0},
27058 {0, "COLOR", 1, 0, 2, 0},
27060 static const D3D11_SO_DECLARATION_ENTRY position_so_decl[] =
27062 {0, "POSITION", 0, 0, 4, 0},
27064 static const D3D11_SO_DECLARATION_ENTRY position2_so_decl[] =
27066 {0, "POSITION", 0, 0, 2, 0},
27068 static const struct
27070 struct vec4 position;
27071 struct vec4 color0;
27072 struct vec4 color1;
27074 vb_data[] =
27076 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
27077 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
27078 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
27079 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
27081 static const unsigned int vb_stride[] = {sizeof(*vb_data)};
27082 static const float expected_data[] =
27084 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
27085 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
27086 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
27087 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
27089 static const float expected_data2[] =
27091 -1.0f, -1.0f, 0.0f, 1.0f,
27092 -1.0f, 1.0f, 0.0f, 1.0f,
27093 1.0f, -1.0f, 0.0f, 1.0f,
27094 1.0f, 1.0f, 0.0f, 1.0f,
27096 static const float expected_data3[] =
27098 -1.0f, -1.0f,
27099 -1.0f, 1.0f,
27100 1.0f, -1.0f,
27101 1.0f, 1.0f,
27103 static const struct
27105 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
27106 unsigned int so_entry_count;
27107 const float *expected_data;
27108 unsigned int expected_data_size;
27110 tests[] =
27112 {all_so_decl, ARRAY_SIZE(all_so_decl), expected_data, ARRAY_SIZE(expected_data)},
27113 {position_so_decl, ARRAY_SIZE(position_so_decl), expected_data2, ARRAY_SIZE(expected_data2)},
27114 {position2_so_decl, ARRAY_SIZE(position2_so_decl), expected_data3, ARRAY_SIZE(expected_data3)},
27117 if (!init_test_context(&test_context, &feature_level))
27118 return;
27120 device = test_context.device;
27121 context = test_context.immediate_context;
27123 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
27125 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
27126 vs_code, sizeof(vs_code), &input_layout);
27127 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
27129 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
27130 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
27132 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
27134 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
27135 offset = 0;
27136 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, vb_stride, &offset);
27137 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
27139 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
27141 gs = NULL;
27142 current_so_declaration = NULL;
27143 for (i = 0; i < ARRAY_SIZE(tests); ++i)
27145 if (current_so_declaration != tests[i].so_declaration)
27147 if (gs)
27148 ID3D11GeometryShader_Release(gs);
27150 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
27151 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
27152 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
27153 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
27154 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
27155 current_so_declaration = tests[i].so_declaration;
27158 offset = 0;
27159 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
27161 ID3D11DeviceContext_Draw(context, 4, 0);
27163 get_buffer_readback(so_buffer, &rb);
27164 result = rb.map_desc.pData;
27165 for (j = 0; j < tests[i].expected_data_size; ++j)
27167 float expected_value = tests[i].expected_data[j];
27168 ok(compare_float(result[j], expected_value, 2),
27169 "Test %u: Got %.8e, expected %.8e at %u.\n",
27170 i, result[j], expected_value, j);
27172 release_resource_readback(&rb);
27175 ID3D11Buffer_Release(vb);
27176 ID3D11Buffer_Release(so_buffer);
27177 ID3D11VertexShader_Release(vs);
27178 ID3D11GeometryShader_Release(gs);
27179 ID3D11InputLayout_Release(input_layout);
27180 release_test_context(&test_context);
27183 static void test_gather(void)
27185 struct
27187 int width, height;
27188 int offset_x, offset_y;
27189 } constant;
27190 struct d3d11_test_context test_context;
27191 D3D11_TEXTURE2D_DESC texture_desc;
27192 ID3D11ShaderResourceView *srv;
27193 ID3D11Texture2D *texture, *rt;
27194 ID3D11DeviceContext *context;
27195 ID3D11RenderTargetView *rtv;
27196 struct resource_readback rb;
27197 ID3D11PixelShader *ps;
27198 ID3D11Device *device;
27199 unsigned int x, y;
27200 ID3D11Buffer *cb;
27201 HRESULT hr;
27203 static const DWORD gather4_code[] =
27205 #if 0
27206 SamplerState s;
27207 Texture2D<float4> t;
27209 int2 size;
27211 float4 main(float4 position : SV_Position) : SV_Target
27213 return t.Gather(s, position.xy / size);
27215 #endif
27216 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
27217 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27218 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27219 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27220 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
27221 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
27222 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27223 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27224 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27225 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
27226 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
27228 static const DWORD gather4_offset_code[] =
27230 #if 0
27231 SamplerState s;
27232 Texture2D<float4> t;
27234 int2 size;
27236 float4 main(float4 position : SV_Position) : SV_Target
27238 return t.Gather(s, position.xy / size, int2(1, 1));
27240 #endif
27241 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
27242 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27243 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27244 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27245 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
27246 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
27247 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27248 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27249 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27250 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
27251 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
27253 static const DWORD gather4_green_code[] =
27255 #if 0
27256 SamplerState s;
27257 Texture2D<float4> t;
27259 int2 size;
27261 float4 main(float4 position : SV_Position) : SV_Target
27263 return t.GatherGreen(s, position.xy / size);
27265 #endif
27266 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
27267 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27268 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27269 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27270 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
27271 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
27272 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27273 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27274 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27275 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27276 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
27278 static const DWORD gather4_po_code[] =
27280 #if 0
27281 SamplerState s;
27282 Texture2D<float4> t;
27284 int2 size;
27285 int2 offset;
27287 float4 main(float4 position : SV_Position) : SV_Target
27289 return t.Gather(s, position.xy / size, offset);
27291 #endif
27292 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
27293 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27294 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27295 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27296 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
27297 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
27298 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27299 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27300 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27301 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27302 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
27303 0x00000000, 0x0100003e,
27305 static const struct vec4 texture_data[] =
27307 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
27308 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
27309 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
27310 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
27312 static const struct vec4 expected_gather4[] =
27314 {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},
27315 {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},
27316 {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},
27317 {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},
27319 static const struct vec4 expected_gather4_offset[] =
27321 {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},
27322 {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},
27323 {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},
27324 {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},
27326 static const struct vec4 expected_gather4_green[] =
27328 {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},
27329 {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},
27330 {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},
27331 {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},
27333 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
27334 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
27336 if (!init_test_context(&test_context, NULL))
27337 return;
27339 device = test_context.device;
27340 context = test_context.immediate_context;
27342 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
27344 skip("Shader model 4.1 required for gather4 instruction.\n");
27345 release_test_context(&test_context);
27346 return;
27349 texture_desc.Width = 4;
27350 texture_desc.Height = 4;
27351 texture_desc.MipLevels = 1;
27352 texture_desc.ArraySize = 1;
27353 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27354 texture_desc.SampleDesc.Count = 1;
27355 texture_desc.SampleDesc.Quality = 0;
27356 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27357 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27358 texture_desc.CPUAccessFlags = 0;
27359 texture_desc.MiscFlags = 0;
27360 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27361 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27362 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27363 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27364 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27366 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
27367 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
27368 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27369 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
27370 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
27371 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
27373 constant.width = texture_desc.Width;
27374 constant.height = texture_desc.Height;
27375 constant.offset_x = 1;
27376 constant.offset_y = 1;
27377 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
27378 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
27380 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
27381 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27382 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27384 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27385 draw_quad(&test_context);
27386 get_texture_readback(rt, 0, &rb);
27387 for (y = 0; y < texture_desc.Height; ++y)
27389 for (x = 0; x < texture_desc.Width; ++x)
27391 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
27392 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27393 ok(compare_vec4(got, expected, 0),
27394 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27395 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27398 release_resource_readback(&rb);
27400 ID3D11PixelShader_Release(ps);
27401 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
27402 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27403 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27405 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27406 draw_quad(&test_context);
27407 get_texture_readback(rt, 0, &rb);
27408 for (y = 0; y < texture_desc.Height; ++y)
27410 for (x = 0; x < texture_desc.Width; ++x)
27412 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
27413 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27414 ok(compare_vec4(got, expected, 0),
27415 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27416 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27419 release_resource_readback(&rb);
27421 ID3D11PixelShader_Release(ps);
27423 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
27425 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
27426 goto done;
27429 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
27430 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27431 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27433 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27434 draw_quad(&test_context);
27435 get_texture_readback(rt, 0, &rb);
27436 for (y = 0; y < texture_desc.Height; ++y)
27438 for (x = 0; x < texture_desc.Width; ++x)
27440 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
27441 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27442 ok(compare_vec4(got, expected, 0),
27443 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27444 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27447 release_resource_readback(&rb);
27449 ID3D11PixelShader_Release(ps);
27450 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
27451 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27452 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27454 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27455 draw_quad(&test_context);
27456 get_texture_readback(rt, 0, &rb);
27457 for (y = 0; y < texture_desc.Height; ++y)
27459 for (x = 0; x < texture_desc.Width; ++x)
27461 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
27462 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27463 ok(compare_vec4(got, expected, 0),
27464 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27465 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27468 release_resource_readback(&rb);
27470 constant.offset_x = 0;
27471 constant.offset_y = 0;
27472 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
27473 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27474 draw_quad(&test_context);
27475 get_texture_readback(rt, 0, &rb);
27476 for (y = 0; y < texture_desc.Height; ++y)
27478 for (x = 0; x < texture_desc.Width; ++x)
27480 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
27481 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27482 ok(compare_vec4(got, expected, 0),
27483 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27484 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27487 release_resource_readback(&rb);
27489 ID3D11PixelShader_Release(ps);
27491 done:
27492 ID3D11Buffer_Release(cb);
27493 ID3D11Texture2D_Release(rt);
27494 ID3D11Texture2D_Release(texture);
27495 ID3D11RenderTargetView_Release(rtv);
27496 ID3D11ShaderResourceView_Release(srv);
27497 release_test_context(&test_context);
27500 static void test_gather_c(void)
27502 struct
27504 int width, height;
27505 int offset_x, offset_y;
27506 float compare_value;
27507 int padding[3];
27508 } constant;
27509 struct d3d11_test_context test_context;
27510 D3D11_TEXTURE2D_DESC texture_desc;
27511 D3D11_SAMPLER_DESC sampler_desc;
27512 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
27513 ID3D11ShaderResourceView *srv;
27514 ID3D11Texture2D *texture, *rt;
27515 ID3D11DeviceContext *context;
27516 ID3D11SamplerState *sampler;
27517 ID3D11RenderTargetView *rtv;
27518 struct resource_readback rb;
27519 ID3D11PixelShader *ps;
27520 ID3D11Device *device;
27521 unsigned int x, y;
27522 ID3D11Buffer *cb;
27523 HRESULT hr;
27525 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27526 static const DWORD gather4_c_code[] =
27528 #if 0
27529 SamplerComparisonState s;
27530 Texture2D<float4> t;
27532 int2 size;
27533 int2 offset;
27534 float compare;
27536 float4 main(float4 position : SV_Position) : SV_Target
27538 return t.GatherCmp(s, position.xy / size, compare);
27540 #endif
27541 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
27542 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27543 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27544 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27545 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
27546 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
27547 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27548 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27549 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27550 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27551 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
27552 0x00000001, 0x0100003e,
27554 static const DWORD gather4_po_c_code[] =
27556 #if 0
27557 SamplerComparisonState s;
27558 Texture2D<float4> t;
27560 int2 size;
27561 int2 offset;
27562 float compare;
27564 float4 main(float4 position : SV_Position) : SV_Target
27566 return t.GatherCmp(s, position.xy / size, compare, offset);
27568 #endif
27569 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
27570 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27571 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27572 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27573 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
27574 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
27575 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27576 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27577 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27578 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27579 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
27580 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
27582 static const float texture_data[] =
27584 0.00f, 0.10f, 0.20f, 0.30f,
27585 0.40f, 0.50f, 0.60f, 0.70f,
27586 0.80f, 0.90f, 0.05f, 0.15f,
27587 0.25f, 0.35f, 0.45f, 0.55f,
27589 static const struct vec4 expected_gather4_c[] =
27591 {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},
27592 {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},
27593 {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},
27594 {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},
27596 static const struct vec4 expected_gather4_po_c[] =
27598 {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},
27599 {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},
27600 {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},
27601 {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},
27603 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
27604 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
27606 if (!init_test_context(&test_context, &feature_level))
27607 return;
27609 device = test_context.device;
27610 context = test_context.immediate_context;
27612 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
27613 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
27614 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
27615 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
27616 sampler_desc.MipLODBias = 0.0f;
27617 sampler_desc.MaxAnisotropy = 0;
27618 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
27619 sampler_desc.BorderColor[0] = 0.0f;
27620 sampler_desc.BorderColor[1] = 0.0f;
27621 sampler_desc.BorderColor[2] = 0.0f;
27622 sampler_desc.BorderColor[3] = 0.0f;
27623 sampler_desc.MinLOD = 0.0f;
27624 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
27626 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
27627 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
27628 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
27630 texture_desc.Width = 4;
27631 texture_desc.Height = 4;
27632 texture_desc.MipLevels = 1;
27633 texture_desc.ArraySize = 1;
27634 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27635 texture_desc.SampleDesc.Count = 1;
27636 texture_desc.SampleDesc.Quality = 0;
27637 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27638 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27639 texture_desc.CPUAccessFlags = 0;
27640 texture_desc.MiscFlags = 0;
27641 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27642 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27643 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27644 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27645 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27647 constant.width = texture_desc.Width;
27648 constant.height = texture_desc.Height;
27649 constant.offset_x = 1;
27650 constant.offset_y = 1;
27651 constant.compare_value = 0.5f;
27652 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
27653 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
27655 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
27656 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
27657 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
27658 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27660 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
27661 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
27662 U(srv_desc).Texture2D.MostDetailedMip = 0;
27663 U(srv_desc).Texture2D.MipLevels = 1;
27664 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
27665 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
27666 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
27668 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
27669 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27670 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27672 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27673 draw_quad(&test_context);
27674 get_texture_readback(rt, 0, &rb);
27675 for (y = 0; y < texture_desc.Height; ++y)
27677 for (x = 0; x < texture_desc.Width; ++x)
27679 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
27680 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27681 ok(compare_vec4(got, expected, 0),
27682 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27683 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27686 release_resource_readback(&rb);
27687 ID3D11PixelShader_Release(ps);
27689 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
27690 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27691 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27693 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27694 draw_quad(&test_context);
27695 get_texture_readback(rt, 0, &rb);
27696 for (y = 0; y < texture_desc.Height; ++y)
27698 for (x = 0; x < texture_desc.Width; ++x)
27700 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
27701 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27702 ok(compare_vec4(got, expected, 0),
27703 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27704 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27707 release_resource_readback(&rb);
27708 ID3D11PixelShader_Release(ps);
27710 ID3D11ShaderResourceView_Release(srv);
27711 ID3D11Texture2D_Release(texture);
27713 ID3D11Buffer_Release(cb);
27714 ID3D11Texture2D_Release(rt);
27715 ID3D11RenderTargetView_Release(rtv);
27716 ID3D11SamplerState_Release(sampler);
27717 release_test_context(&test_context);
27720 static float clamp_depth_bias(float bias, float clamp)
27722 if (clamp > 0.0f)
27723 return min(bias, clamp);
27724 if (clamp < 0.0f)
27725 return max(bias, clamp);
27726 return bias;
27729 static void test_depth_bias(void)
27731 struct vec3 vertices[] =
27733 {-1.0f, -1.0f, 0.5f},
27734 {-1.0f, 1.0f, 0.5f},
27735 { 1.0f, -1.0f, 0.5f},
27736 { 1.0f, 1.0f, 0.5f},
27738 struct d3d11_test_context test_context;
27739 D3D11_RASTERIZER_DESC rasterizer_desc;
27740 struct swapchain_desc swapchain_desc;
27741 D3D11_TEXTURE2D_DESC texture_desc;
27742 ID3D11DeviceContext *context;
27743 double m, bias, depth, data;
27744 struct resource_readback rb;
27745 ID3D11DepthStencilView *dsv;
27746 unsigned int expected_value;
27747 ID3D11RasterizerState *rs;
27748 ID3D11Texture2D *texture;
27749 unsigned int format_idx;
27750 unsigned int y, i, j, k;
27751 unsigned int shift = 0;
27752 ID3D11Device *device;
27753 float *depth_values;
27754 DXGI_FORMAT format;
27755 const UINT32 *u32;
27756 const UINT16 *u16;
27757 UINT32 u32_value;
27758 HRESULT hr;
27760 static const struct
27762 float z;
27763 float exponent;
27765 quads[] =
27767 {0.125f, -3.0f},
27768 {0.250f, -2.0f},
27769 {0.500f, -1.0f},
27770 {1.000f, 0.0f},
27772 static const int bias_tests[] =
27774 -10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
27775 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000,
27777 static const float bias_clamp_tests[] =
27779 0.0f, -1e-5f, 1e-5f,
27781 static const float quad_slopes[] =
27783 0.0f, 0.5f, 1.0f
27785 static const float slope_scaled_bias_tests[] =
27787 0.0f, 0.5f, 1.0f, 2.0f, 128.0f, 1000.0f, 10000.0f,
27789 static const DXGI_FORMAT formats[] =
27791 DXGI_FORMAT_D32_FLOAT,
27792 DXGI_FORMAT_D24_UNORM_S8_UINT,
27793 DXGI_FORMAT_D16_UNORM,
27796 swapchain_desc.windowed = TRUE;
27797 swapchain_desc.buffer_count = 1;
27798 swapchain_desc.width = 200;
27799 swapchain_desc.height = 200;
27800 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
27801 swapchain_desc.flags = 0;
27802 if (!init_test_context_ext(&test_context, NULL, &swapchain_desc))
27803 return;
27805 device = test_context.device;
27806 context = test_context.immediate_context;
27808 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
27809 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
27810 rasterizer_desc.CullMode = D3D11_CULL_NONE;
27811 rasterizer_desc.FrontCounterClockwise = FALSE;
27812 rasterizer_desc.DepthBias = 0;
27813 rasterizer_desc.DepthBiasClamp = 0.0f;
27814 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
27815 rasterizer_desc.DepthClipEnable = TRUE;
27817 depth_values = heap_calloc(swapchain_desc.height, sizeof(*depth_values));
27818 ok(!!depth_values, "Failed to allocate memory.\n");
27820 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
27822 format = formats[format_idx];
27824 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
27825 texture_desc.Format = format;
27826 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
27827 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
27828 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27829 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
27830 ok(SUCCEEDED(hr), "Failed to create render depth stencil view, hr %#x.\n", hr);
27831 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
27832 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
27833 draw_quad_z(&test_context, 1.0f);
27834 switch (format)
27836 case DXGI_FORMAT_D32_FLOAT:
27837 check_texture_float(texture, 1.0f, 0);
27838 break;
27839 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27840 /* FIXME: Depth/stencil byte order is reversed in wined3d. */
27841 shift = get_texture_color(texture, 0, 0) == 0xffffff ? 0 : 8;
27842 todo_wine
27843 check_texture_color(texture, 0xffffff, 1);
27844 break;
27845 case DXGI_FORMAT_D16_UNORM:
27846 get_texture_readback(texture, 0, &rb);
27847 check_readback_data_u16(&rb, NULL, 0xffffu, 0);
27848 release_resource_readback(&rb);
27849 break;
27850 default:
27851 trace("Unhandled format %#x.\n", format);
27852 break;
27854 draw_quad(&test_context);
27856 /* DepthBias */
27857 for (i = 0; i < ARRAY_SIZE(quads); ++i)
27859 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
27860 vertices[j].z = quads[i].z;
27861 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
27862 0, NULL, vertices, 0, 0);
27864 for (j = 0; j < ARRAY_SIZE(bias_tests); ++j)
27866 rasterizer_desc.DepthBias = bias_tests[j];
27868 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
27870 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
27871 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
27872 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
27873 ID3D11DeviceContext_RSSetState(context, rs);
27874 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27875 draw_quad(&test_context);
27876 switch (format)
27878 case DXGI_FORMAT_D32_FLOAT:
27879 bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f);
27880 bias = clamp_depth_bias(bias, rasterizer_desc.DepthBiasClamp);
27881 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27883 check_texture_float(texture, depth, 2);
27884 break;
27885 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27886 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 16777215.0f,
27887 rasterizer_desc.DepthBiasClamp);
27888 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27890 get_texture_readback(texture, 0, &rb);
27891 check_readback_data_u24(&rb, NULL, shift, depth * 16777215.0f + 0.5f, 1);
27892 release_resource_readback(&rb);
27893 break;
27894 case DXGI_FORMAT_D16_UNORM:
27895 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 65535.0f,
27896 rasterizer_desc.DepthBiasClamp);
27897 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27899 get_texture_readback(texture, 0, &rb);
27900 check_readback_data_u16(&rb, NULL, depth * 65535.0f + 0.5f, 1);
27901 release_resource_readback(&rb);
27902 break;
27903 default:
27904 break;
27906 ID3D11RasterizerState_Release(rs);
27911 /* SlopeScaledDepthBias */
27912 rasterizer_desc.DepthBias = 0;
27913 for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i)
27915 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
27916 vertices[j].z = j == 1 || j == 3 ? 0.0f : quad_slopes[i];
27917 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
27918 0, NULL, vertices, 0, 0);
27920 ID3D11DeviceContext_RSSetState(context, NULL);
27921 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27922 draw_quad(&test_context);
27923 get_texture_readback(texture, 0, &rb);
27924 for (y = 0; y < texture_desc.Height; ++y)
27926 switch (format)
27928 case DXGI_FORMAT_D32_FLOAT:
27929 depth_values[y] = get_readback_float(&rb, 0, y);
27930 break;
27931 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27932 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
27933 u32_value = *u32 >> shift;
27934 depth_values[y] = u32_value / 16777215.0f;
27935 break;
27936 case DXGI_FORMAT_D16_UNORM:
27937 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
27938 depth_values[y] = *u16 / 65535.0f;
27939 break;
27940 default:
27941 break;
27944 release_resource_readback(&rb);
27946 for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j)
27948 rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j];
27950 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
27952 BOOL all_match = TRUE;
27953 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
27954 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
27955 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
27956 ID3D11DeviceContext_RSSetState(context, rs);
27957 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27958 draw_quad(&test_context);
27960 m = quad_slopes[i] / texture_desc.Height;
27961 bias = clamp_depth_bias(rasterizer_desc.SlopeScaledDepthBias * m, rasterizer_desc.DepthBiasClamp);
27962 get_texture_readback(texture, 0, &rb);
27963 for (y = 0; y < texture_desc.Height && all_match; ++y)
27965 depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
27966 switch (format)
27968 case DXGI_FORMAT_D32_FLOAT:
27969 data = get_readback_float(&rb, 0, y);
27970 all_match = compare_float(data, depth, 64);
27971 ok(all_match,
27972 "Got depth %.8e, expected %.8e.\n", data, depth);
27973 break;
27974 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27975 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
27976 u32_value = *u32 >> shift;
27977 expected_value = depth * 16777215.0f + 0.5f;
27978 all_match = compare_uint(u32_value, expected_value, 3);
27979 ok(all_match,
27980 "Got value %#x (%.8e), expected %#x (%.8e).\n",
27981 u32_value, u32_value / 16777215.0f,
27982 expected_value, expected_value / 16777215.0f);
27983 break;
27984 case DXGI_FORMAT_D16_UNORM:
27985 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
27986 expected_value = depth * 65535.0f + 0.5f;
27987 all_match = compare_uint(*u16, expected_value, 1);
27988 ok(all_match,
27989 "Got value %#x (%.8e), expected %#x (%.8e).\n",
27990 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
27991 break;
27992 default:
27993 break;
27996 release_resource_readback(&rb);
27997 ID3D11RasterizerState_Release(rs);
28002 ID3D11Texture2D_Release(texture);
28003 ID3D11DepthStencilView_Release(dsv);
28006 heap_free(depth_values);
28007 release_test_context(&test_context);
28010 static void test_fractional_viewports(void)
28012 struct d3d11_test_context test_context;
28013 D3D11_TEXTURE2D_DESC texture_desc;
28014 ID3D11InputLayout *input_layout;
28015 ID3D11DeviceContext *context;
28016 struct resource_readback rb;
28017 ID3D11RenderTargetView *rtv;
28018 ID3D11VertexShader *vs;
28019 ID3D11PixelShader *ps;
28020 unsigned int i, x, y;
28021 ID3D11Device *device;
28022 ID3D11Texture2D *rt;
28023 UINT offset, stride;
28024 ID3D11Buffer *vb;
28025 HRESULT hr;
28027 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
28028 static const DWORD vs_code[] =
28030 #if 0
28031 void main(in float4 in_position : POSITION,
28032 in float2 in_texcoord : TEXCOORD,
28033 out float4 position : SV_Position,
28034 out float2 texcoord : TEXCOORD)
28036 position = in_position;
28037 texcoord = in_texcoord;
28039 #endif
28040 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
28041 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
28042 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
28043 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
28044 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
28045 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
28046 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
28047 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
28048 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
28049 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
28050 0x00000001, 0x0100003e,
28052 static const DWORD ps_code[] =
28054 #if 0
28055 float4 main(float4 position : SV_Position,
28056 float2 texcoord : TEXCOORD) : SV_Target
28058 return float4(position.xy, texcoord);
28060 #endif
28061 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
28062 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
28063 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
28064 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
28065 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
28066 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
28067 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
28068 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
28069 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
28071 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
28073 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
28074 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
28076 static const struct
28078 struct vec2 position;
28079 struct vec2 texcoord;
28081 quad[] =
28083 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
28084 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
28085 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
28086 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
28088 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28089 static const float viewport_offsets[] =
28091 0.0f, 1.0f / 2.0f, 1.0f / 4.0f, 1.0f / 8.0f, 1.0f / 16.0f, 1.0f / 32.0f,
28092 1.0f / 64.0f, 1.0f / 128.0f, 1.0f / 256.0f, 63.0f / 128.0f,
28095 if (!init_test_context(&test_context, &feature_level))
28096 return;
28097 device = test_context.device;
28098 context = test_context.immediate_context;
28100 texture_desc.Width = 4;
28101 texture_desc.Height = 4;
28102 texture_desc.MipLevels = 1;
28103 texture_desc.ArraySize = 1;
28104 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
28105 texture_desc.SampleDesc.Count = 1;
28106 texture_desc.SampleDesc.Quality = 0;
28107 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28108 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
28109 texture_desc.CPUAccessFlags = 0;
28110 texture_desc.MiscFlags = 0;
28111 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
28112 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28113 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
28114 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
28115 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
28117 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
28118 vs_code, sizeof(vs_code), &input_layout);
28119 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
28120 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
28122 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
28123 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
28124 stride = sizeof(*quad);
28125 offset = 0;
28126 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
28128 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
28129 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
28130 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
28132 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
28133 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
28134 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
28136 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
28138 set_viewport(context, viewport_offsets[i], viewport_offsets[i],
28139 texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
28140 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
28141 ID3D11DeviceContext_Draw(context, 4, 0);
28142 get_texture_readback(rt, 0, &rb);
28143 for (y = 0; y < texture_desc.Height; ++y)
28145 for (x = 0; x < texture_desc.Width; ++x)
28147 const struct vec4 *v = get_readback_vec4(&rb, x, y);
28148 struct vec4 expected = {x + 0.5f, y + 0.5f,
28149 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
28150 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
28151 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
28152 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
28153 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
28154 todo_wine
28155 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
28156 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
28157 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
28160 release_resource_readback(&rb);
28163 ID3D11InputLayout_Release(input_layout);
28164 ID3D11Buffer_Release(vb);
28165 ID3D11VertexShader_Release(vs);
28166 ID3D11PixelShader_Release(ps);
28167 ID3D11RenderTargetView_Release(rtv);
28168 ID3D11Texture2D_Release(rt);
28169 release_test_context(&test_context);
28172 static void test_negative_viewports(const D3D_FEATURE_LEVEL feature_level)
28174 struct d3d11_test_context test_context;
28175 ID3D11DeviceContext *context;
28176 BOOL quirk;
28177 RECT rect;
28179 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28180 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
28182 if (!init_test_context(&test_context, &feature_level))
28183 return;
28184 context = test_context.immediate_context;
28186 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
28187 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28188 draw_color_quad(&test_context, &green);
28189 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
28191 set_viewport(context, -0.0f, -0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
28192 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28193 draw_color_quad(&test_context, &green);
28194 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
28196 /* For feature levels greater than or equal to 11_0, a negative top left
28197 * corner shifts the bottom right corner by a whole integer. It seems that
28198 * floor() is used to round viewport corners to integers.
28200 quirk = feature_level >= D3D_FEATURE_LEVEL_11_0;
28202 set_viewport(context, -0.4f, -0.4f, 640.0f, 480.0f, 0.0f, 1.0f);
28203 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28204 draw_color_quad(&test_context, &green);
28205 SetRect(&rect, 0, 0, 639, 479);
28206 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
28207 SetRect(&rect, 639, 479, 640, 480);
28208 todo_wine_if(quirk)
28209 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
28211 set_viewport(context, -1.0f / 128.0f, -1.0 / 128.0f, 640.0f, 480.0f, 0.0f, 1.0f);
28212 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28213 draw_color_quad(&test_context, &green);
28214 SetRect(&rect, 0, 0, 639, 479);
28215 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
28216 SetRect(&rect, 639, 479, 640, 480);
28217 todo_wine_if(quirk)
28218 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
28220 release_test_context(&test_context);
28223 static void test_early_depth_stencil(void)
28225 ID3D11DepthStencilState *depth_stencil_state;
28226 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
28227 ID3D11Texture2D *texture, *depth_texture;
28228 struct d3d11_test_context test_context;
28229 D3D11_TEXTURE2D_DESC texture_desc;
28230 ID3D11UnorderedAccessView *uav;
28231 ID3D11DeviceContext *context;
28232 ID3D11DepthStencilView *dsv;
28233 ID3D11PixelShader *ps;
28234 ID3D11Device *device;
28235 HRESULT hr;
28237 static const DWORD ps_code[] =
28239 #if 0
28240 RWTexture2D<int> u;
28242 [earlydepthstencil]
28243 float4 main() : SV_Target
28245 InterlockedAdd(u[uint2(0, 0)], 1);
28246 return float4(1.0f, 1.0f, 1.0f, 1.0f);
28248 #endif
28249 0x43425844, 0xda4325ad, 0xc01d3815, 0xfd610cc9, 0x8ed1e351, 0x00000001, 0x000000ec, 0x00000003,
28250 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28251 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28252 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000074, 0x00000050, 0x0000001d,
28253 0x0100286a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x03000065, 0x001020f2, 0x00000000,
28254 0x0a0000ad, 0x0011e000, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
28255 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
28256 0x3f800000, 0x3f800000, 0x0100003e,
28258 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
28259 static const UINT values[4] = {0};
28261 if (!init_test_context(&test_context, &feature_level))
28262 return;
28264 device = test_context.device;
28265 context = test_context.immediate_context;
28267 depth_stencil_desc.DepthEnable = TRUE;
28268 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
28269 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
28270 depth_stencil_desc.StencilEnable = FALSE;
28271 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
28272 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
28274 texture_desc.Width = 1;
28275 texture_desc.Height = 1;
28276 texture_desc.MipLevels = 1;
28277 texture_desc.ArraySize = 1;
28278 texture_desc.Format = DXGI_FORMAT_R32_SINT;
28279 texture_desc.SampleDesc.Count = 1;
28280 texture_desc.SampleDesc.Quality = 0;
28281 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28282 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
28283 texture_desc.CPUAccessFlags = 0;
28284 texture_desc.MiscFlags = 0;
28285 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
28286 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28287 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
28288 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
28290 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28291 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
28292 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28293 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
28294 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
28295 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28296 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
28297 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
28299 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
28300 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
28301 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
28303 set_viewport(context, 0.0f, 0.0f, 1.0f, 100.0f, 0.5f, 0.5f);
28304 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
28305 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
28306 1, &test_context.backbuffer_rtv, dsv, 1, 1, &uav, NULL);
28308 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
28310 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
28311 draw_quad(&test_context);
28312 check_texture_color(texture, 100, 1);
28313 draw_quad(&test_context);
28314 check_texture_color(texture, 200, 1);
28315 check_texture_float(depth_texture, 0.6f, 1);
28317 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.3f, 0);
28318 draw_quad(&test_context);
28319 draw_quad(&test_context);
28320 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.55f, 0);
28321 draw_quad(&test_context);
28322 check_texture_color(texture, 300, 1);
28324 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
28325 draw_quad(&test_context);
28326 check_texture_color(texture, 400, 1);
28327 check_texture_float(depth_texture, 0.5f, 1);
28329 ID3D11Texture2D_Release(depth_texture);
28330 ID3D11DepthStencilView_Release(dsv);
28331 ID3D11DepthStencilState_Release(depth_stencil_state);
28332 ID3D11PixelShader_Release(ps);
28333 ID3D11Texture2D_Release(texture);
28334 ID3D11UnorderedAccessView_Release(uav);
28335 release_test_context(&test_context);
28338 static void test_conservative_depth_output(void)
28340 struct shader
28342 const DWORD *code;
28343 size_t size;
28346 ID3D11DepthStencilState *depth_stencil_state;
28347 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
28348 struct d3d11_test_context test_context;
28349 const struct shader *current_shader;
28350 D3D11_TEXTURE2D_DESC texture_desc;
28351 ID3D11DeviceContext *context;
28352 ID3D11DepthStencilView *dsv;
28353 ID3D11Texture2D *texture;
28354 ID3D11PixelShader *ps;
28355 DWORD expected_color;
28356 float expected_depth;
28357 ID3D11Device *device;
28358 struct vec4 ps_depth;
28359 ID3D11Buffer *cb;
28360 unsigned int i;
28361 HRESULT hr;
28363 static const DWORD ps_depth_le_code[] =
28365 #if 0
28366 float depth;
28368 float4 main(out float out_depth : SV_DepthLessEqual) : SV_Target0
28370 out_depth = depth;
28371 return float4(0.0f, 1.0f, 0.f, 1.0f);
28373 #endif
28374 0x43425844, 0x045c8d00, 0xc49e2ebe, 0x76f6022a, 0xf6996ecc, 0x00000001, 0x00000108, 0x00000003,
28375 0x0000002c, 0x0000003c, 0x00000098, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28376 0x00000054, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28377 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
28378 0x65677261, 0x56530074, 0x7065445f, 0x654c6874, 0x71457373, 0x006c6175, 0x58454853, 0x00000068,
28379 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065,
28380 0x001020f2, 0x00000000, 0x02000065, 0x00027001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
28381 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00027001, 0x0020800a, 0x00000000,
28382 0x00000000, 0x0100003e,
28384 static const struct shader ps_depth_le = {ps_depth_le_code, sizeof(ps_depth_le_code)};
28385 static const DWORD ps_depth_ge_code[] =
28387 #if 0
28388 float depth;
28390 float4 main(out float out_depth : SV_DepthGreaterEqual) : SV_Target0
28392 out_depth = depth;
28393 return float4(0.0f, 1.0f, 0.f, 1.0f);
28395 #endif
28396 0x43425844, 0xd17af83e, 0xa32c01cc, 0x0d8e9665, 0xe6dc17c2, 0x00000001, 0x0000010c, 0x00000003,
28397 0x0000002c, 0x0000003c, 0x0000009c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28398 0x00000058, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28399 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
28400 0x65677261, 0x56530074, 0x7065445f, 0x72476874, 0x65746165, 0x75714572, 0xab006c61, 0x58454853,
28401 0x00000068, 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
28402 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x00026001, 0x08000036, 0x001020f2, 0x00000000,
28403 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00026001, 0x0020800a,
28404 0x00000000, 0x00000000, 0x0100003e,
28406 static const struct shader ps_depth_ge = {ps_depth_ge_code, sizeof(ps_depth_ge_code)};
28407 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
28408 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28409 static const struct
28411 const struct shader *ps;
28412 float vs_depth;
28413 float ps_depth;
28414 BOOL passes_depth_test;
28416 tests[] =
28418 {&ps_depth_le, 0.7f, 0.7f, TRUE},
28419 {&ps_depth_le, 0.7f, 0.4f, FALSE},
28420 {&ps_depth_le, 0.4f, 0.4f, FALSE},
28421 /* {&ps_depth_le, 0.4f, 0.6f, FALSE}, undefined result */
28422 {&ps_depth_ge, 0.7f, 0.7f, TRUE},
28423 /* {&ps_depth_ge, 0.7f, 0.4f, TRUE}, undefined result */
28424 {&ps_depth_ge, 0.4f, 0.4f, FALSE},
28425 {&ps_depth_ge, 0.4f, 0.6f, TRUE},
28428 if (!init_test_context(&test_context, &feature_level))
28429 return;
28431 device = test_context.device;
28432 context = test_context.immediate_context;
28434 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_depth), NULL);
28436 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28437 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
28438 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28439 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
28440 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
28441 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28442 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
28443 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
28445 depth_stencil_desc.DepthEnable = TRUE;
28446 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
28447 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_GREATER_EQUAL;
28448 depth_stencil_desc.StencilEnable = FALSE;
28449 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
28450 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
28452 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
28453 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
28454 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
28456 ps = NULL;
28457 current_shader = NULL;
28458 for (i = 0; i < ARRAY_SIZE(tests); ++i)
28460 if (current_shader != tests[i].ps)
28462 if (ps)
28463 ID3D11PixelShader_Release(ps);
28465 current_shader = tests[i].ps;
28466 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
28467 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
28468 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
28471 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28472 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
28473 ps_depth.x = tests[i].ps_depth;
28474 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_depth, 0, 0);
28475 draw_quad_z(&test_context, tests[i].vs_depth);
28477 expected_color = tests[i].passes_depth_test ? 0xff00ff00 : 0xffffffff;
28478 expected_depth = tests[i].passes_depth_test ? max(tests[i].vs_depth, tests[i].ps_depth) : 0.5f;
28479 check_texture_color(test_context.backbuffer, expected_color, 0);
28480 check_texture_float(texture, expected_depth, 1);
28483 ID3D11Buffer_Release(cb);
28484 ID3D11PixelShader_Release(ps);
28485 ID3D11DepthStencilView_Release(dsv);
28486 ID3D11DepthStencilState_Release(depth_stencil_state);
28487 ID3D11Texture2D_Release(texture);
28488 release_test_context(&test_context);
28491 static void test_format_compatibility(void)
28493 ID3D11Texture2D *dst_texture, *src_texture;
28494 D3D11_SUBRESOURCE_DATA resource_data;
28495 D3D11_TEXTURE2D_DESC texture_desc;
28496 ID3D11DeviceContext *context;
28497 struct resource_readback rb;
28498 DWORD colour, expected;
28499 ID3D11Device *device;
28500 unsigned int i, j;
28501 ULONG refcount;
28502 HRESULT hr;
28504 static const struct
28506 DXGI_FORMAT src_format;
28507 DXGI_FORMAT dst_format;
28508 size_t texel_size;
28509 BOOL success;
28510 BOOL src_ds;
28511 BOOL dst_ds;
28513 test_data[] =
28515 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
28516 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
28517 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
28518 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
28519 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
28520 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
28521 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
28522 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
28523 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
28524 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
28525 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
28526 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
28527 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
28528 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
28529 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
28530 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_TYPELESS, 4, TRUE},
28531 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_FLOAT, 4, TRUE},
28532 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_UINT, 4, TRUE},
28533 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_SINT, 4, TRUE},
28534 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, FALSE},
28535 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_B8G8R8A8_TYPELESS, 4, FALSE},
28536 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R16G16_TYPELESS, 4, FALSE},
28537 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
28538 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
28539 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
28540 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
28541 {DXGI_FORMAT_D16_UNORM, DXGI_FORMAT_R16_UNORM, 2, TRUE, TRUE},
28542 {DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_D16_UNORM, 2, TRUE, FALSE, TRUE},
28543 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_TYPELESS, 2, TRUE, TRUE},
28544 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_TYPELESS, 2, TRUE, FALSE, TRUE},
28546 static const DWORD initial_data[16] = {0};
28547 static const DWORD bitmap_data[] =
28549 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28550 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28551 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28552 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28555 if (!(device = create_device(NULL)))
28557 skip("Failed to create device.\n");
28558 return;
28560 ID3D11Device_GetImmediateContext(device, &context);
28562 texture_desc.Height = 4;
28563 texture_desc.MipLevels = 1;
28564 texture_desc.ArraySize = 1;
28565 texture_desc.SampleDesc.Count = 1;
28566 texture_desc.SampleDesc.Quality = 0;
28567 texture_desc.CPUAccessFlags = 0;
28568 texture_desc.MiscFlags = 0;
28570 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
28572 unsigned int x, y, texel_dwords;
28573 BOOL broken = FALSE;
28574 D3D11_BOX box;
28576 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
28577 texture_desc.Format = test_data[i].src_format;
28578 texture_desc.Usage = test_data[i].src_ds ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE;
28579 texture_desc.BindFlags = test_data[i].src_ds ? D3D11_BIND_DEPTH_STENCIL : D3D11_BIND_SHADER_RESOURCE;
28581 resource_data.pSysMem = bitmap_data;
28582 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
28583 resource_data.SysMemSlicePitch = 0;
28585 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
28586 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
28588 texture_desc.Format = test_data[i].dst_format;
28589 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28590 texture_desc.BindFlags = test_data[i].dst_ds ? D3D11_BIND_DEPTH_STENCIL : D3D11_BIND_SHADER_RESOURCE;
28592 resource_data.pSysMem = initial_data;
28594 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
28595 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
28597 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
28598 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0, 1, 1, 0,
28599 (ID3D11Resource *)src_texture, 0, &box);
28601 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
28602 get_texture_readback(dst_texture, 0, &rb);
28603 colour = get_readback_color(&rb, 0, 0, 0);
28604 if (test_data[i].src_format == DXGI_FORMAT_R9G9B9E5_SHAREDEXP && colour == bitmap_data[0])
28606 win_skip("Broken destination offset for %#x -> %#x copy.\n",
28607 test_data[i].src_format, test_data[i].dst_format);
28608 broken = TRUE;
28610 for (j = 0; j < ARRAY_SIZE(bitmap_data) && !broken; ++j)
28612 x = j % 4;
28613 y = j / 4;
28614 colour = get_readback_color(&rb, x, y, 0);
28615 expected = test_data[i].success && !test_data[i].src_ds && !test_data[i].dst_ds
28616 && x >= texel_dwords && y ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
28617 todo_wine_if((test_data[i].src_ds || test_data[i].dst_ds) && colour)
28618 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
28619 i, colour, x, y, expected);
28621 release_resource_readback(&rb);
28623 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
28625 get_texture_readback(dst_texture, 0, &rb);
28626 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
28628 x = j % 4;
28629 y = j / 4;
28630 colour = get_readback_color(&rb, x, y, 0);
28631 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
28632 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
28633 i, colour, x, y, expected);
28635 release_resource_readback(&rb);
28637 ID3D11Texture2D_Release(dst_texture);
28638 ID3D11Texture2D_Release(src_texture);
28641 ID3D11DeviceContext_Release(context);
28642 refcount = ID3D11Device_Release(device);
28643 ok(!refcount, "Device has %u references left.\n", refcount);
28646 static void test_compressed_format_compatibility(const D3D_FEATURE_LEVEL feature_level)
28648 const struct format_info *src_format, *dst_format;
28649 unsigned int row_block_count, row_count, i, j, k;
28650 ID3D11Texture2D *src_texture, *dst_texture;
28651 BOOL supported, broken_dst_offset = FALSE;
28652 D3D11_SUBRESOURCE_DATA resource_data;
28653 D3D11_TEXTURE2D_DESC texture_desc;
28654 ID3D11DeviceContext *context;
28655 unsigned int block_idx, x, y;
28656 struct resource_readback rb;
28657 DWORD colour, expected;
28658 ID3D11Device *device;
28659 UINT format_support;
28660 const BYTE *row;
28661 ULONG refcount;
28662 D3D11_BOX box;
28663 HRESULT hr;
28664 const struct device_desc device_desc =
28666 .feature_level = &feature_level,
28669 static const struct format_info
28671 DXGI_FORMAT id;
28672 size_t block_size;
28673 size_t block_edge;
28674 BOOL supported;
28675 BOOL skip_if_broken;
28677 formats[] =
28679 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 16, 1, TRUE},
28680 {DXGI_FORMAT_R32G32B32A32_FLOAT, 16, 1, TRUE},
28681 {DXGI_FORMAT_R32G32B32A32_UINT, 16, 1, TRUE},
28682 {DXGI_FORMAT_R32G32B32A32_SINT, 16, 1, TRUE},
28684 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 8, 1, TRUE},
28685 {DXGI_FORMAT_R16G16B16A16_FLOAT, 8, 1, TRUE},
28686 {DXGI_FORMAT_R16G16B16A16_UNORM, 8, 1, TRUE},
28687 {DXGI_FORMAT_R16G16B16A16_UINT, 8, 1, TRUE},
28688 {DXGI_FORMAT_R16G16B16A16_SNORM, 8, 1, TRUE},
28689 {DXGI_FORMAT_R16G16B16A16_SINT, 8, 1, TRUE},
28691 {DXGI_FORMAT_R32G32_TYPELESS, 8, 1, TRUE},
28692 {DXGI_FORMAT_R32G32_FLOAT, 8, 1, TRUE},
28693 {DXGI_FORMAT_R32G32_UINT, 8, 1, TRUE},
28694 {DXGI_FORMAT_R32G32_SINT, 8, 1, TRUE},
28696 {DXGI_FORMAT_R32_TYPELESS, 4, 1, TRUE},
28697 {DXGI_FORMAT_R32_FLOAT, 4, 1, TRUE},
28698 {DXGI_FORMAT_R32_UINT, 4, 1, TRUE},
28699 {DXGI_FORMAT_R32_SINT, 4, 1, TRUE},
28701 {DXGI_FORMAT_R32G8X24_TYPELESS, 8, 1},
28702 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 4, 1},
28703 {DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, 1},
28704 {DXGI_FORMAT_R16G16_TYPELESS, 4, 1},
28705 {DXGI_FORMAT_R24G8_TYPELESS, 4, 1},
28706 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 4, 1},
28707 {DXGI_FORMAT_B8G8R8A8_TYPELESS, 4, 1},
28708 {DXGI_FORMAT_R8G8_TYPELESS, 2, 1},
28709 {DXGI_FORMAT_R16_TYPELESS, 2, 1},
28710 {DXGI_FORMAT_R8_TYPELESS, 1, 1},
28712 {DXGI_FORMAT_BC1_TYPELESS, 8, 4},
28713 {DXGI_FORMAT_BC1_UNORM, 8, 4},
28714 {DXGI_FORMAT_BC1_UNORM_SRGB, 8, 4},
28716 {DXGI_FORMAT_BC2_TYPELESS, 16, 4},
28717 {DXGI_FORMAT_BC2_UNORM, 16, 4},
28718 {DXGI_FORMAT_BC2_UNORM_SRGB, 16, 4},
28720 {DXGI_FORMAT_BC3_TYPELESS, 16, 4},
28721 {DXGI_FORMAT_BC3_UNORM, 16, 4},
28722 {DXGI_FORMAT_BC3_UNORM_SRGB, 16, 4},
28724 {DXGI_FORMAT_BC4_TYPELESS, 8, 4},
28725 {DXGI_FORMAT_BC4_UNORM, 8, 4},
28726 {DXGI_FORMAT_BC4_SNORM, 8, 4},
28728 {DXGI_FORMAT_BC5_TYPELESS, 16, 4},
28729 {DXGI_FORMAT_BC5_UNORM, 16, 4},
28730 {DXGI_FORMAT_BC5_SNORM, 16, 4},
28732 {DXGI_FORMAT_BC6H_TYPELESS, 16, 4, FALSE, TRUE},
28733 {DXGI_FORMAT_BC6H_UF16, 16, 4, FALSE, TRUE},
28734 {DXGI_FORMAT_BC6H_SF16, 16, 4, FALSE, TRUE},
28736 {DXGI_FORMAT_BC7_TYPELESS, 16, 4, FALSE, TRUE},
28737 {DXGI_FORMAT_BC7_UNORM, 16, 4, FALSE, TRUE},
28738 {DXGI_FORMAT_BC7_UNORM_SRGB, 16, 4, FALSE, TRUE},
28741 static const DWORD initial_data[64] = {0};
28742 static const DWORD texture_data[] =
28744 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28745 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28746 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28747 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28749 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28750 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28751 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28752 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28754 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
28755 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
28756 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
28757 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
28759 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
28760 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
28761 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
28762 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
28765 if (!(device = create_device(&device_desc)))
28767 skip("Failed to create device for feature level %#x.\n", feature_level);
28768 return;
28770 ID3D11Device_GetImmediateContext(device, &context);
28772 row_block_count = 4;
28774 texture_desc.MipLevels = 1;
28775 texture_desc.ArraySize = 1;
28776 texture_desc.SampleDesc.Count = 1;
28777 texture_desc.SampleDesc.Quality = 0;
28778 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
28779 texture_desc.CPUAccessFlags = 0;
28780 texture_desc.MiscFlags = 0;
28782 resource_data.SysMemSlicePitch = 0;
28784 for (i = 0; i < ARRAY_SIZE(formats); ++i)
28786 src_format = &formats[i];
28787 row_count = sizeof(texture_data) / (row_block_count * src_format->block_size);
28788 texture_desc.Width = row_block_count * src_format->block_edge;
28789 texture_desc.Height = row_count * src_format->block_edge;
28790 texture_desc.Format = src_format->id;
28791 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
28793 resource_data.pSysMem = texture_data;
28794 resource_data.SysMemPitch = row_block_count * src_format->block_size;
28796 hr = ID3D11Device_CheckFormatSupport(device, src_format->id, &format_support);
28797 if (hr == E_FAIL || !(format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
28798 continue;
28800 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
28801 ok(hr == S_OK, "Source format %#x: Got unexpected hr %#x.\n", src_format->id, hr);
28803 for (j = 0; j < ARRAY_SIZE(formats); ++j)
28805 dst_format = &formats[j];
28807 if ((src_format->block_edge == 1 && dst_format->block_edge == 1)
28808 || (src_format->block_edge != 1 && dst_format->block_edge != 1))
28809 continue;
28811 hr = ID3D11Device_CheckFormatSupport(device, dst_format->id, &format_support);
28812 if (hr == E_FAIL || !(format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
28813 continue;
28815 supported = ((src_format->block_edge != 1 && dst_format->supported)
28816 || (src_format->supported && dst_format->block_edge != 1))
28817 && src_format->block_size == dst_format->block_size
28818 && feature_level >= D3D_FEATURE_LEVEL_10_1;
28820 /* These cause the device to be removed on some versions of Windows. */
28821 if (supported && broken_dst_offset && (src_format->skip_if_broken || dst_format->skip_if_broken))
28823 win_skip("Skipping %#x -> %#x tests because of broken destination offset.\n",
28824 src_format->id, dst_format->id);
28825 continue;
28828 row_count = sizeof(initial_data) / (row_block_count * dst_format->block_size);
28829 texture_desc.Width = row_block_count * dst_format->block_edge;
28830 texture_desc.Height = row_count * dst_format->block_edge;
28831 texture_desc.Format = dst_format->id;
28832 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28834 resource_data.pSysMem = initial_data;
28835 resource_data.SysMemPitch = row_block_count * dst_format->block_size;
28837 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
28838 ok(hr == S_OK, "%#x -> %#x: Got unexpected hr %#x.\n", src_format->id, dst_format->id, hr);
28840 if (supported && broken_dst_offset)
28842 win_skip("Skipping %#x -> %#x CopySubresourceRegion() test because of broken destination offset.\n",
28843 src_format->id, dst_format->id);
28845 else
28847 set_box(&box, 0, 0, 0, src_format->block_edge, src_format->block_edge, 1);
28848 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
28849 dst_format->block_edge, dst_format->block_edge, 0, (ID3D11Resource *)src_texture, 0, &box);
28850 get_texture_readback(dst_texture, 0, &rb);
28851 colour = get_readback_color(&rb, 0, 0, 0);
28852 if (supported && colour == texture_data[0])
28854 win_skip("Detected broken destination offset for %#x -> %#x copy.\n",
28855 src_format->id, dst_format->id);
28856 broken_dst_offset = TRUE;
28858 for (k = 0; k < ARRAY_SIZE(texture_data) && (!supported || !broken_dst_offset); ++k)
28860 block_idx = (k * sizeof(colour)) / dst_format->block_size;
28861 x = block_idx % row_block_count;
28862 y = block_idx / row_block_count;
28864 row = rb.map_desc.pData;
28865 row += y * rb.map_desc.RowPitch;
28866 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
28868 if (supported && x == 1 && y == 1)
28869 expected = texture_data[k - ((row_block_count + 1) * dst_format->block_size) / sizeof(colour)];
28870 else
28871 expected = initial_data[k];
28872 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
28873 src_format->id, dst_format->id, colour, k, expected);
28874 if (colour != expected)
28875 break;
28877 release_resource_readback(&rb);
28880 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
28881 get_texture_readback(dst_texture, 0, &rb);
28882 for (k = 0; k < ARRAY_SIZE(texture_data); ++k)
28884 block_idx = (k * sizeof(colour)) / dst_format->block_size;
28885 y = block_idx / row_block_count;
28887 row = rb.map_desc.pData;
28888 row += y * rb.map_desc.RowPitch;
28889 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
28891 if (supported)
28892 expected = texture_data[k];
28893 else
28894 expected = initial_data[k];
28895 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
28896 src_format->id, dst_format->id, colour, k, expected);
28897 if (colour != expected)
28898 break;
28900 release_resource_readback(&rb);
28902 ID3D11Texture2D_Release(dst_texture);
28905 ID3D11Texture2D_Release(src_texture);
28908 ID3D11DeviceContext_Release(context);
28909 refcount = ID3D11Device_Release(device);
28910 ok(!refcount, "Device has %u references left.\n", refcount);
28913 static void check_clip_distance(struct d3d11_test_context *test_context, ID3D11Buffer *vb)
28915 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28916 struct vertex
28918 float clip_distance0;
28919 float clip_distance1;
28922 ID3D11DeviceContext *context = test_context->immediate_context;
28923 struct resource_readback rb;
28924 struct vertex vertices[4];
28925 unsigned int i;
28926 RECT rect;
28928 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28929 vertices[i].clip_distance0 = 1.0f;
28930 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28931 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28932 ID3D11DeviceContext_Draw(context, 4, 0);
28933 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
28935 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28936 vertices[i].clip_distance0 = 0.0f;
28937 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28938 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28939 ID3D11DeviceContext_Draw(context, 4, 0);
28940 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
28942 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28943 vertices[i].clip_distance0 = -1.0f;
28944 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28945 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28946 ID3D11DeviceContext_Draw(context, 4, 0);
28947 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
28949 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28950 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
28951 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28952 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28953 ID3D11DeviceContext_Draw(context, 4, 0);
28954 get_texture_readback(test_context->backbuffer, 0, &rb);
28955 SetRect(&rect, 0, 0, 320, 480);
28956 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
28957 SetRect(&rect, 320, 0, 320, 480);
28958 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28959 release_resource_readback(&rb);
28961 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28962 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
28963 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28964 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28965 ID3D11DeviceContext_Draw(context, 4, 0);
28966 get_texture_readback(test_context->backbuffer, 0, &rb);
28967 SetRect(&rect, 0, 0, 640, 240);
28968 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
28969 SetRect(&rect, 0, 240, 640, 240);
28970 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28971 release_resource_readback(&rb);
28974 static void test_clip_distance(void)
28976 struct d3d11_test_context test_context;
28977 ID3D11Buffer *vs_cb, *tess_cb, *gs_cb;
28978 D3D_FEATURE_LEVEL feature_level;
28979 ID3D11DomainShader *ds = NULL;
28980 ID3D11DeviceContext *context;
28981 struct resource_readback rb;
28982 unsigned int offset, stride;
28983 ID3D11HullShader *hs = NULL;
28984 ID3D11GeometryShader *gs;
28985 ID3D11Device *device;
28986 ID3D11Buffer *vb;
28987 unsigned int i;
28988 HRESULT hr;
28989 RECT rect;
28991 static const DWORD vs_code[] =
28993 #if 0
28994 bool use_constant;
28995 float clip_distance;
28997 struct input
28999 float4 position : POSITION;
29000 float distance0 : CLIP_DISTANCE0;
29001 float distance1 : CLIP_DISTANCE1;
29004 struct vertex
29006 float4 position : SV_POSITION;
29007 float user_clip : CLIP_DISTANCE;
29008 float clip : SV_ClipDistance;
29011 void main(input vin, out vertex vertex)
29013 vertex.position = vin.position;
29014 vertex.user_clip = vin.distance0;
29015 vertex.clip = vin.distance0;
29016 if (use_constant)
29017 vertex.clip = clip_distance;
29019 #endif
29020 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
29021 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
29022 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
29023 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
29024 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
29025 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
29026 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
29027 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
29028 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
29029 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
29030 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
29031 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
29032 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
29033 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
29034 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
29036 static const DWORD vs_multiple_code[] =
29038 #if 0
29039 bool use_constant;
29040 float clip_distance0;
29041 float clip_distance1;
29043 struct input
29045 float4 position : POSITION;
29046 float distance0 : CLIP_DISTANCE0;
29047 float distance1 : CLIP_DISTANCE1;
29050 struct vertex
29052 float4 position : SV_POSITION;
29053 float user_clip : CLIP_DISTANCE;
29054 float2 clip : SV_ClipDistance;
29057 void main(input vin, out vertex vertex)
29059 vertex.position = vin.position;
29060 vertex.user_clip = vin.distance0;
29061 vertex.clip.x = vin.distance0;
29062 if (use_constant)
29063 vertex.clip.x = clip_distance0;
29064 vertex.clip.y = vin.distance1;
29065 if (use_constant)
29066 vertex.clip.y = clip_distance1;
29068 #endif
29069 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
29070 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
29071 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
29072 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
29073 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
29074 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
29075 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
29076 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
29077 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
29078 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
29079 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
29080 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
29081 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
29082 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
29083 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
29084 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
29085 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
29087 #if 0
29088 bool use_constant;
29089 float clip_distance0;
29090 float clip_distance1;
29091 float tessellation_factor;
29093 struct vertex
29095 float4 position : SV_POSITION;
29096 float user_clip : CLIP_DISTANCE;
29097 float clip : SV_ClipDistance;
29100 struct patch_constant_data
29102 float edges[4] : SV_TessFactor;
29103 float inside[2] : SV_InsideTessFactor;
29106 patch_constant_data patch_constant()
29108 patch_constant_data output;
29110 output.edges[0] = tessellation_factor;
29111 output.edges[1] = tessellation_factor;
29112 output.edges[2] = tessellation_factor;
29113 output.edges[3] = tessellation_factor;
29114 output.inside[0] = tessellation_factor;
29115 output.inside[1] = tessellation_factor;
29117 return output;
29120 [domain("quad")]
29121 [outputcontrolpoints(4)]
29122 [outputtopology("triangle_cw")]
29123 [partitioning("pow2")]
29124 [patchconstantfunc("patch_constant")]
29125 vertex hs_main(InputPatch<vertex, 4> input,
29126 uint i : SV_OutputControlPointID)
29128 vertex o;
29129 o.position = input[i].position;
29130 o.user_clip = input[i].user_clip;
29131 o.clip = input[i].user_clip;
29132 return o;
29135 float4 interpolate_vec(float4 a, float4 b, float4 c, float4 d, float2 tess_coord)
29137 float4 e = lerp(a, b, tess_coord.x);
29138 float4 f = lerp(c, d, tess_coord.x);
29139 return lerp(e, f, tess_coord.y);
29142 float interpolate(float a, float b, float c, float d, float2 tess_coord)
29144 float e = lerp(a, b, tess_coord.x);
29145 float f = lerp(c, d, tess_coord.x);
29146 return lerp(e, f, tess_coord.y);
29149 [domain("quad")]
29150 vertex ds_main(patch_constant_data input,
29151 float2 tess_coord : SV_DomainLocation,
29152 const OutputPatch<vertex, 4> patch)
29154 vertex output;
29156 output.position = interpolate_vec(patch[0].position, patch[1].position,
29157 patch[2].position, patch[3].position, tess_coord);
29158 output.user_clip = interpolate(patch[0].user_clip, patch[1].user_clip,
29159 patch[2].user_clip, patch[3].user_clip, tess_coord);
29160 output.clip = interpolate(patch[0].clip, patch[1].clip,
29161 patch[2].clip, patch[3].clip, tess_coord);
29162 if (use_constant)
29163 output.clip = clip_distance0;
29165 return output;
29167 #endif
29168 static const DWORD hs_code[] =
29170 0x43425844, 0x5a6d7564, 0x5f30a6c9, 0x2cf3b848, 0x5b4c6dca, 0x00000001, 0x00000414, 0x00000004,
29171 0x00000030, 0x000000b4, 0x00000138, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
29172 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
29173 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
29174 0x00000002, 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
29175 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003,
29176 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c,
29177 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002,
29178 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f,
29179 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc,
29180 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
29181 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
29182 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
29183 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
29184 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
29185 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
29186 0x00000210, 0x00030050, 0x00000084, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01001096,
29187 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x01000072, 0x0200005f,
29188 0x00016000, 0x0400005f, 0x002010f2, 0x00000004, 0x00000000, 0x0400005f, 0x00201012, 0x00000004,
29189 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
29190 0x00102012, 0x00000002, 0x02000068, 0x00000001, 0x04000036, 0x00100012, 0x00000000, 0x00016001,
29191 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x07000036,
29192 0x00102012, 0x00000001, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x07000036, 0x00102012,
29193 0x00000002, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x0100003e, 0x01000073, 0x02000099,
29194 0x00000004, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x0000000b, 0x04000067,
29195 0x00102012, 0x00000001, 0x0000000c, 0x04000067, 0x00102012, 0x00000002, 0x0000000d, 0x04000067,
29196 0x00102012, 0x00000003, 0x0000000e, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000000,
29197 0x00000004, 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, 0x00902012, 0x0010000a,
29198 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002,
29199 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000004, 0x0000000f, 0x04000067, 0x00102012,
29200 0x00000005, 0x00000010, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000004, 0x00000002,
29201 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x08000036, 0x00d02012, 0x00000004, 0x0010000a,
29202 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e,
29204 static const DWORD ds_code[] =
29206 0x43425844, 0xc54dc020, 0x063a9622, 0x6f649eb9, 0xceb1dd36, 0x00000001, 0x0000054c, 0x00000004,
29207 0x00000030, 0x000000b4, 0x00000178, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
29208 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
29209 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
29210 0x00000002, 0x00000101, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
29211 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc, 0x00000006,
29212 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000001, 0x00000098,
29213 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000001, 0x00000098, 0x00000002, 0x0000000b,
29214 0x00000003, 0x00000002, 0x00000001, 0x00000098, 0x00000003, 0x0000000b, 0x00000003, 0x00000003,
29215 0x00000001, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000001, 0x000000a6,
29216 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
29217 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000007c,
29218 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
29219 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000,
29220 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43,
29221 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x58454853,
29222 0x00000348, 0x00040050, 0x000000d2, 0x01002093, 0x01001895, 0x0100086a, 0x04000059, 0x00208e46,
29223 0x00000000, 0x00000001, 0x0200005f, 0x0001c032, 0x0400005f, 0x002190f2, 0x00000004, 0x00000000,
29224 0x0400005f, 0x00219012, 0x00000004, 0x00000001, 0x0400005f, 0x00219012, 0x00000004, 0x00000002,
29225 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067,
29226 0x00102012, 0x00000002, 0x00000002, 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000,
29227 0x80219e46, 0x00000041, 0x00000002, 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032,
29228 0x001000f2, 0x00000000, 0x0001c006, 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000,
29229 0x0a000000, 0x001000f2, 0x00000001, 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46,
29230 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001,
29231 0x00219e46, 0x00000000, 0x00000000, 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
29232 0x80100e46, 0x00000041, 0x00000001, 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46,
29233 0x00000000, 0x00100e46, 0x00000001, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041,
29234 0x00000002, 0x00000001, 0x0021900a, 0x00000003, 0x00000001, 0x09000032, 0x00100012, 0x00000000,
29235 0x0001c00a, 0x0010000a, 0x00000000, 0x0021900a, 0x00000002, 0x00000001, 0x0a000000, 0x00100022,
29236 0x00000000, 0x8021900a, 0x00000041, 0x00000000, 0x00000001, 0x0021900a, 0x00000001, 0x00000001,
29237 0x09000032, 0x00100022, 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000,
29238 0x00000001, 0x08000000, 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a,
29239 0x00000000, 0x08000032, 0x00102012, 0x00000001, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a,
29240 0x00000000, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041, 0x00000002, 0x00000002,
29241 0x0021900a, 0x00000003, 0x00000002, 0x09000032, 0x00100012, 0x00000000, 0x0001c00a, 0x0010000a,
29242 0x00000000, 0x0021900a, 0x00000002, 0x00000002, 0x0a000000, 0x00100022, 0x00000000, 0x8021900a,
29243 0x00000041, 0x00000000, 0x00000002, 0x0021900a, 0x00000001, 0x00000002, 0x09000032, 0x00100022,
29244 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000, 0x00000002, 0x08000000,
29245 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a, 0x00000000, 0x08000032,
29246 0x00100012, 0x00000000, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000, 0x0b000037,
29247 0x00102012, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
29248 0x0010000a, 0x00000000, 0x0100003e,
29250 static const DWORD gs_code[] =
29252 #if 0
29253 bool use_constant;
29254 float clip_distance;
29256 struct vertex
29258 float4 position : SV_POSITION;
29259 float user_clip : CLIP_DISTANCE;
29260 float clip : SV_ClipDistance;
29263 [maxvertexcount(3)]
29264 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
29266 vertex o;
29267 o = input[0];
29268 o.clip = input[0].user_clip;
29269 if (use_constant)
29270 o.clip = clip_distance;
29271 output.Append(o);
29272 o = input[1];
29273 o.clip = input[1].user_clip;
29274 if (use_constant)
29275 o.clip = clip_distance;
29276 output.Append(o);
29277 o = input[2];
29278 o.clip = input[2].user_clip;
29279 if (use_constant)
29280 o.clip = clip_distance;
29281 output.Append(o);
29283 #endif
29284 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
29285 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
29286 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
29287 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
29288 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
29289 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
29290 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
29291 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
29292 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
29293 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
29294 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
29295 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
29296 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
29297 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
29298 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
29299 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
29300 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
29301 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
29302 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
29303 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
29304 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
29305 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
29306 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
29307 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
29308 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
29309 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
29311 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
29313 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29314 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29315 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
29317 struct
29319 float clip_distance0;
29320 float clip_distance1;
29322 vertices[] =
29324 {1.0f, 1.0f},
29325 {1.0f, 1.0f},
29326 {1.0f, 1.0f},
29327 {1.0f, 1.0f},
29329 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29330 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
29331 struct
29333 BOOL use_constant;
29334 float clip_distance0;
29335 float clip_distance1;
29336 float tessellation_factor;
29337 } cb_data;
29339 if (!init_test_context(&test_context, NULL))
29340 return;
29341 device = test_context.device;
29342 context = test_context.immediate_context;
29343 feature_level = ID3D11Device_GetFeatureLevel(device);
29345 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
29346 vs_code, sizeof(vs_code), &test_context.input_layout);
29347 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
29349 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
29350 stride = sizeof(*vertices);
29351 offset = 0;
29352 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
29354 memset(&cb_data, 0, sizeof(cb_data));
29355 cb_data.tessellation_factor = 1.0f;
29356 vs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29357 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &vs_cb);
29358 tess_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29359 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &tess_cb);
29360 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, 1, &tess_cb);
29361 gs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29362 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &gs_cb);
29364 /* vertex shader */
29365 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29366 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29367 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29369 check_clip_distance(&test_context, vb);
29371 cb_data.use_constant = TRUE;
29372 cb_data.clip_distance0 = -1.0f;
29373 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29375 /* tessellation shaders */
29376 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
29378 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
29380 hr = ID3D11Device_CreateHullShader(device, hs_code, sizeof(hs_code), NULL, &hs);
29381 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
29382 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
29383 hr = ID3D11Device_CreateDomainShader(device, ds_code, sizeof(ds_code), NULL, &ds);
29384 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
29385 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
29387 check_clip_distance(&test_context, vb);
29389 cb_data.use_constant = FALSE;
29390 cb_data.tessellation_factor = 2.0f;
29391 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
29393 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29394 vertices[i].clip_distance0 = 1.0f;
29395 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29396 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29397 ID3D11DeviceContext_Draw(context, 4, 0);
29398 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29400 cb_data.use_constant = TRUE;
29401 cb_data.clip_distance0 = -1.0f;
29402 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
29404 else
29406 skip("Tessellation shaders are not supported.\n");
29409 /* geometry shader */
29410 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
29411 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
29412 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
29414 check_clip_distance(&test_context, vb);
29416 cb_data.use_constant = TRUE;
29417 cb_data.clip_distance0 = 1.0f;
29418 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
29419 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29420 ID3D11DeviceContext_Draw(context, 4, 0);
29421 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29423 /* multiple clip distances */
29424 ID3D11DeviceContext_HSSetShader(context, NULL, NULL, 0);
29425 ID3D11DeviceContext_DSSetShader(context, NULL, NULL, 0);
29426 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
29428 cb_data.use_constant = FALSE;
29429 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29431 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29432 vertices[i].clip_distance0 = 1.0f;
29433 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29434 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29435 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29436 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29438 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29440 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
29441 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
29443 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29444 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29445 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29446 get_texture_readback(test_context.backbuffer, 0, &rb);
29447 SetRect(&rect, 0, 0, 320, 240);
29448 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
29449 SetRect(&rect, 0, 240, 320, 480);
29450 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29451 SetRect(&rect, 320, 0, 640, 480);
29452 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29453 release_resource_readback(&rb);
29455 cb_data.use_constant = TRUE;
29456 cb_data.clip_distance0 = 0.0f;
29457 cb_data.clip_distance1 = 0.0f;
29458 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29459 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29460 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29461 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29463 if (hs)
29464 ID3D11HullShader_Release(hs);
29465 if (ds)
29466 ID3D11DomainShader_Release(ds);
29467 ID3D11GeometryShader_Release(gs);
29468 ID3D11Buffer_Release(vb);
29469 ID3D11Buffer_Release(vs_cb);
29470 ID3D11Buffer_Release(tess_cb);
29471 ID3D11Buffer_Release(gs_cb);
29472 release_test_context(&test_context);
29475 static void test_combined_clip_and_cull_distances(void)
29477 struct d3d11_test_context test_context;
29478 ID3D11DeviceContext *context;
29479 struct resource_readback rb;
29480 unsigned int offset, stride;
29481 ID3D11Device *device;
29482 unsigned int i, j, k;
29483 ID3D11Buffer *vb;
29484 HRESULT hr;
29486 static const DWORD vs_code[] =
29488 #if 0
29489 struct input
29491 float4 position : POSITION;
29492 float clip0 : CLIP_DISTANCE0;
29493 float clip1 : CLIP_DISTANCE1;
29494 float clip2 : CLIP_DISTANCE2;
29495 float clip3 : CLIP_DISTANCE3;
29496 float cull0 : CULL_DISTANCE0;
29497 float cull1 : CULL_DISTANCE1;
29498 float cull2 : CULL_DISTANCE2;
29499 float cull3 : CULL_DISTANCE3;
29502 struct vertex
29504 float4 position : SV_Position;
29505 float3 clip0 : SV_ClipDistance1;
29506 float3 cull0 : SV_CullDistance1;
29507 float clip1 : SV_ClipDistance2;
29508 float cull1 : SV_CullDistance2;
29511 void main(input vin, out vertex vertex)
29513 vertex.position = vin.position;
29514 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
29515 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
29516 vertex.clip1 = vin.clip3;
29517 vertex.cull1 = vin.cull3;
29519 #endif
29520 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
29521 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
29522 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
29523 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
29524 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
29525 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
29526 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
29527 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
29528 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
29529 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
29530 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
29531 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
29532 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
29533 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
29534 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
29535 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
29536 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
29537 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
29538 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
29539 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
29540 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
29541 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
29542 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
29543 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
29544 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
29545 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
29546 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
29547 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
29549 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
29551 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29552 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29553 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
29554 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
29555 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
29556 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
29557 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
29558 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
29559 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
29561 struct
29563 float clip_distance[4];
29564 float cull_distance[4];
29566 vertices[4] =
29568 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29569 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29570 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29571 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29573 static const struct test
29575 float vertices[4];
29576 BOOL triangle_visible[2];
29578 cull_distance_tests[] =
29580 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29581 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29582 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29583 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29584 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
29585 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29586 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
29587 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29588 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
29590 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
29591 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29592 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29593 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
29594 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
29596 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
29598 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29599 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
29601 if (!init_test_context(&test_context, NULL))
29602 return;
29603 device = test_context.device;
29604 context = test_context.immediate_context;
29606 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
29607 vs_code, sizeof(vs_code), &test_context.input_layout);
29608 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
29610 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
29611 stride = sizeof(*vertices);
29612 offset = 0;
29613 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
29615 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29616 draw_color_quad(&test_context, &green);
29617 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29619 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
29621 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
29623 const struct test *test = &cull_distance_tests[j];
29624 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
29625 unsigned int color;
29627 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
29628 vertices[k].cull_distance[i] = test->vertices[k];
29629 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29631 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29632 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29634 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
29635 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
29637 if (expected_color[0] == expected_color[1])
29639 check_texture_color(test_context.backbuffer, *expected_color, 1);
29641 else
29643 get_texture_readback(test_context.backbuffer, 0, &rb);
29644 color = get_readback_color(&rb, 160, 240, 0);
29645 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
29646 color = get_readback_color(&rb, 480, 240, 0);
29647 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
29648 release_resource_readback(&rb);
29652 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29653 vertices[j].cull_distance[i] = 1.0f;
29656 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
29658 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29659 vertices[j].clip_distance[i] = -1.0f;
29660 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29662 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29663 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29664 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
29666 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29667 vertices[j].clip_distance[i] = 1.0f;
29670 memset(vertices, 0, sizeof(vertices));
29671 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29672 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29673 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29674 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29676 ID3D11Buffer_Release(vb);
29677 release_test_context(&test_context);
29680 static void test_generate_mips(void)
29682 static const DWORD ps_code[] =
29684 #if 0
29685 Texture2D t;
29686 SamplerState s;
29688 float4 main(float4 position : SV_POSITION) : SV_Target
29690 float2 p;
29692 p.x = position.x / 640.0f;
29693 p.y = position.y / 480.0f;
29694 return t.Sample(s, p);
29696 #endif
29697 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
29698 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29699 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
29700 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
29701 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
29702 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
29703 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
29704 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
29705 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
29706 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
29708 static const DWORD ps_code_3d[] =
29710 #if 0
29711 Texture3D t;
29712 SamplerState s;
29714 float4 main(float4 position : SV_POSITION) : SV_Target
29716 float3 p;
29718 p.x = position.x / 640.0f;
29719 p.y = position.y / 480.0f;
29720 p.z = 0.5f;
29721 return t.Sample(s, p);
29723 #endif
29724 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003,
29725 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29726 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
29727 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
29728 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040,
29729 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
29730 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
29731 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
29732 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000,
29733 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
29734 0x00000000, 0x0100003e,
29736 static const struct
29738 D3D11_RESOURCE_DIMENSION dim;
29739 D3D11_SRV_DIMENSION srv_dim;
29740 unsigned int array_size;
29742 resource_types[] =
29744 {D3D11_RESOURCE_DIMENSION_BUFFER, D3D11_SRV_DIMENSION_BUFFER, 1},
29745 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2D, 1},
29746 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2DARRAY, 4},
29747 {D3D11_RESOURCE_DIMENSION_TEXTURE3D, D3D11_SRV_DIMENSION_TEXTURE3D, 1},
29749 static const struct
29751 DXGI_FORMAT texture_format;
29752 UINT bind_flags;
29753 UINT misc_flags;
29754 BOOL null_srv;
29755 UINT base_level;
29756 BOOL expected_creation;
29757 BOOL expected_mips;
29759 tests[] =
29761 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
29762 0, TRUE, FALSE},
29763 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
29764 0, TRUE, FALSE},
29765 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
29766 0, TRUE, FALSE},
29767 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
29768 0, TRUE, FALSE},
29769 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29770 0, FALSE, FALSE},
29771 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29772 0, FALSE, FALSE},
29773 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29774 0, TRUE, TRUE},
29775 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29776 1, TRUE, TRUE},
29777 {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29778 1, TRUE, TRUE},
29779 {DXGI_FORMAT_R8G8B8A8_UINT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, TRUE,
29780 1, TRUE, FALSE},
29782 static const struct
29784 POINT pos;
29785 DWORD color;
29787 expected[] =
29789 {{200, 200}, 0xffff0000},
29790 {{280, 200}, 0xffff0000},
29791 {{360, 200}, 0xff00ff00},
29792 {{440, 200}, 0xff00ff00},
29793 {{200, 270}, 0xff0000ff},
29794 {{280, 270}, 0xff0000ff},
29795 {{360, 270}, 0xff000000},
29796 {{440, 270}, 0xff000000},
29798 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
29799 static const RECT r1 = {8, 8, 16, 16};
29800 static const RECT r2 = {16, 8, 24, 16};
29801 static const RECT r3 = {8, 16, 16, 24};
29802 static const RECT r4 = {16, 16, 24, 24};
29803 DWORD *data, *zero_data, color, expected_color;
29804 ID3D11ShaderResourceView *srv, *srv_sampling;
29805 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
29806 struct d3d11_test_context test_context;
29807 D3D11_TEXTURE2D_DESC texture2d_desc;
29808 D3D11_TEXTURE3D_DESC texture3d_desc;
29809 ID3D11SamplerState *sampler_state;
29810 D3D11_SAMPLER_DESC sampler_desc;
29811 D3D11_BUFFER_DESC buffer_desc;
29812 unsigned int i, j, k, x, y, z;
29813 ID3D11PixelShader *ps, *ps_3d;
29814 ID3D11DeviceContext *context;
29815 struct resource_readback rb;
29816 ID3D11Resource *resource;
29817 ID3D11Device *device;
29818 HRESULT hr;
29820 if (!init_test_context(&test_context, NULL))
29821 return;
29823 device = test_context.device;
29824 context = test_context.immediate_context;
29826 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
29827 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29829 hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps_3d);
29830 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29832 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
29833 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
29834 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
29835 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
29836 sampler_desc.MipLODBias = 0.0f;
29837 sampler_desc.MaxAnisotropy = 0;
29838 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
29839 sampler_desc.BorderColor[0] = 0.0f;
29840 sampler_desc.BorderColor[1] = 0.0f;
29841 sampler_desc.BorderColor[2] = 0.0f;
29842 sampler_desc.BorderColor[3] = 0.0f;
29843 sampler_desc.MinLOD = 0.0f;
29844 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
29846 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
29847 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
29848 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
29850 data = heap_alloc(sizeof(*data) * 32 * 32 * 32);
29852 for (z = 0; z < 32; ++z)
29854 for (y = 0; y < 32; ++y)
29856 for (x = 0; x < 32; ++x)
29858 DWORD *dst = &data[z * 32 * 32 + y * 32 + x];
29859 POINT pt;
29861 pt.x = x;
29862 pt.y = y;
29863 if (PtInRect(&r1, pt))
29864 *dst = 0xffff0000;
29865 else if (PtInRect(&r2, pt))
29866 *dst = 0xff00ff00;
29867 else if (PtInRect(&r3, pt))
29868 *dst = 0xff0000ff;
29869 else if (PtInRect(&r4, pt))
29870 *dst = 0xff000000;
29871 else
29872 *dst = 0xffffffff;
29877 zero_data = heap_alloc_zero(sizeof(*zero_data) * 16 * 16 * 16);
29879 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
29881 for (j = 0; j < ARRAY_SIZE(tests); ++j)
29883 unsigned int base_multiplier = 1u << tests[j].base_level;
29885 if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT)
29887 /* Testing this format seems to break the WARP device. */
29888 skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n");
29889 continue;
29892 switch (resource_types[i].dim)
29894 case D3D11_RESOURCE_DIMENSION_BUFFER:
29895 buffer_desc.ByteWidth = 32 * base_multiplier;
29896 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
29897 buffer_desc.BindFlags = tests[j].bind_flags;
29898 buffer_desc.CPUAccessFlags = 0;
29899 buffer_desc.MiscFlags = tests[j].misc_flags;
29900 buffer_desc.StructureByteStride = 0;
29902 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL,
29903 (ID3D11Buffer **)&resource);
29904 break;
29905 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
29906 texture2d_desc.Width = 32 * base_multiplier;
29907 texture2d_desc.Height = 32 * base_multiplier;
29908 texture2d_desc.MipLevels = 0;
29909 texture2d_desc.ArraySize = resource_types[i].array_size;
29910 texture2d_desc.Format = tests[j].texture_format;
29911 texture2d_desc.SampleDesc.Count = 1;
29912 texture2d_desc.SampleDesc.Quality = 0;
29913 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
29914 texture2d_desc.BindFlags = tests[j].bind_flags;
29915 texture2d_desc.CPUAccessFlags = 0;
29916 texture2d_desc.MiscFlags = tests[j].misc_flags;
29918 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL,
29919 (ID3D11Texture2D **)&resource);
29920 break;
29921 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
29922 texture3d_desc.Width = 32 * base_multiplier;
29923 texture3d_desc.Height = 32 * base_multiplier;
29924 texture3d_desc.Depth = 32 * base_multiplier;
29925 texture3d_desc.MipLevels = 0;
29926 texture3d_desc.Format = tests[j].texture_format;
29927 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
29928 texture3d_desc.BindFlags = tests[j].bind_flags;
29929 texture3d_desc.CPUAccessFlags = 0;
29930 texture3d_desc.MiscFlags = tests[j].misc_flags;
29932 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL,
29933 (ID3D11Texture3D **)&resource);
29934 break;
29935 default:
29936 break;
29938 if (tests[j].expected_creation && (resource_types[i].dim != D3D11_RESOURCE_DIMENSION_BUFFER
29939 || !(tests[j].misc_flags & D3D11_RESOURCE_MISC_GENERATE_MIPS)))
29941 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr);
29943 else
29945 ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded "
29946 "to create resource, hr %#x.\n", i, j, hr);
29947 continue;
29950 if (tests[j].null_srv)
29952 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
29954 else
29956 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29957 srv_desc.ViewDimension = resource_types[i].srv_dim;
29958 switch (resource_types[i].srv_dim)
29960 case D3D11_SRV_DIMENSION_BUFFER:
29961 srv_desc.Buffer.ElementOffset = 0;
29962 srv_desc.Buffer.ElementWidth = 0;
29963 break;
29964 case D3D11_SRV_DIMENSION_TEXTURE2D:
29965 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level;
29966 srv_desc.Texture2D.MipLevels = ~0u;
29967 break;
29968 case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
29969 srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level;
29970 srv_desc.Texture2DArray.MipLevels = ~0u;
29971 srv_desc.Texture2DArray.FirstArraySlice = 0;
29972 srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size;
29973 break;
29974 case D3D11_SRV_DIMENSION_TEXTURE3D:
29975 srv_desc.Texture3D.MostDetailedMip = tests[j].base_level;
29976 srv_desc.Texture3D.MipLevels = ~0u;
29977 break;
29978 default:
29979 break;
29981 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
29983 if (resource_types[i].dim == D3D11_RESOURCE_DIMENSION_BUFFER)
29985 ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, "
29986 "hr %#x.\n", j, hr);
29987 ID3D11Resource_Release(resource);
29988 continue;
29990 else
29992 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create "
29993 "shader resource view, hr %#x.\n", i, j, hr);
29996 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level,
29997 NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
29998 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level + 1,
29999 NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16);
30001 ID3D11DeviceContext_GenerateMips(context, srv);
30003 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
30005 srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT
30006 ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
30007 srv_desc.ViewDimension = resource_types[i].dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D
30008 ? D3D11_SRV_DIMENSION_TEXTURE3D : D3D11_SRV_DIMENSION_TEXTURE2D;
30009 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1;
30010 srv_desc.Texture2D.MipLevels = ~0u;
30011 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
30012 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, "
30013 "hr %#x.\n", i, j, hr);
30014 ID3D11DeviceContext_PSSetShader(context, resource_types[i].dim
30015 == D3D11_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps, NULL, 0);
30016 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
30018 draw_quad(&test_context);
30020 get_texture_readback(test_context.backbuffer, 0, &rb);
30021 for (k = 0; k < ARRAY_SIZE(expected); ++k)
30023 color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y, 0);
30024 expected_color = tests[j].expected_mips ? expected[k].color : 0;
30025 ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) "
30026 "has color %08x, expected %08x.\n",
30027 i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color);
30029 release_resource_readback(&rb);
30031 ID3D11ShaderResourceView_Release(srv_sampling);
30032 ID3D11ShaderResourceView_Release(srv);
30033 ID3D11Resource_Release(resource);
30037 /* Test the effect of sRGB views. */
30038 for (y = 0; y < 32; ++y)
30040 for (x = 0; x < 32; ++x)
30042 DWORD *dst = &data[y * 32 + x];
30044 *dst = (x + y) % 2 * 0xffffffff;
30047 texture2d_desc.Width = 32;
30048 texture2d_desc.Height = 32;
30049 texture2d_desc.MipLevels = 0;
30050 texture2d_desc.ArraySize = 1;
30051 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
30052 texture2d_desc.SampleDesc.Count = 1;
30053 texture2d_desc.SampleDesc.Quality = 0;
30054 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
30055 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
30056 texture2d_desc.CPUAccessFlags = 0;
30057 texture2d_desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
30059 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D11Texture2D **)&resource);
30060 ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr);
30061 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
30062 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
30063 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
30064 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
30065 srv_desc.Texture2D.MostDetailedMip = 0;
30066 srv_desc.Texture2D.MipLevels = ~0u;
30067 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
30068 ID3D11DeviceContext_UpdateSubresource(context, resource,
30069 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
30071 ID3D11DeviceContext_GenerateMips(context, srv);
30073 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
30075 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
30076 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
30077 srv_desc.Texture2D.MostDetailedMip = 1;
30078 srv_desc.Texture2D.MipLevels = ~0u;
30079 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
30080 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
30081 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30082 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
30084 draw_quad(&test_context);
30086 get_texture_readback(test_context.backbuffer, 0, &rb);
30087 color = get_readback_color(&rb, 320, 240, 0);
30088 ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */
30089 "Unexpected color %08x.\n", color);
30090 release_resource_readback(&rb);
30092 ID3D11ShaderResourceView_Release(srv_sampling);
30093 ID3D11ShaderResourceView_Release(srv);
30095 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
30096 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
30097 srv_desc.Texture2D.MostDetailedMip = 0;
30098 srv_desc.Texture2D.MipLevels = ~0u;
30099 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
30100 ID3D11DeviceContext_UpdateSubresource(context, resource,
30101 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
30103 ID3D11DeviceContext_GenerateMips(context, srv);
30105 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
30107 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
30108 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
30109 srv_desc.Texture2D.MostDetailedMip = 1;
30110 srv_desc.Texture2D.MipLevels = ~0u;
30111 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
30112 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
30113 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30114 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
30116 draw_quad(&test_context);
30118 get_texture_readback(test_context.backbuffer, 0, &rb);
30119 check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1);
30120 release_resource_readback(&rb);
30122 ID3D11ShaderResourceView_Release(srv_sampling);
30123 ID3D11ShaderResourceView_Release(srv);
30125 ID3D11Resource_Release(resource);
30127 heap_free(zero_data);
30128 heap_free(data);
30130 ID3D11SamplerState_Release(sampler_state);
30131 ID3D11PixelShader_Release(ps_3d);
30132 ID3D11PixelShader_Release(ps);
30133 release_test_context(&test_context);
30136 static void test_alpha_to_coverage(void)
30138 struct ps_cb
30140 struct vec2 top;
30141 struct vec2 bottom;
30142 float alpha[2];
30143 float padding[2];
30146 struct d3d11_test_context test_context;
30147 ID3D11Texture2D *render_targets[3];
30148 D3D11_TEXTURE2D_DESC texture_desc;
30149 ID3D11Texture2D *readback_texture;
30150 ID3D11RenderTargetView *rtvs[3];
30151 ID3D11BlendState *blend_state;
30152 ID3D11DeviceContext *context;
30153 D3D11_BLEND_DESC blend_desc;
30154 struct resource_readback rb;
30155 UINT quality_level_count;
30156 ID3D11PixelShader *ps;
30157 struct ps_cb cb_data;
30158 ID3D11Device *device;
30159 ID3D11Buffer *cb;
30160 unsigned int i;
30161 HRESULT hr;
30162 RECT rect;
30164 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30165 static const DWORD ps_code[] =
30167 #if 0
30168 float2 top;
30169 float2 bottom;
30170 float alpha1;
30171 float alpha2;
30173 void main(float4 position : SV_Position,
30174 out float4 target0 : SV_Target0,
30175 out float4 target1 : SV_Target1,
30176 out float4 target2 : SV_Target2)
30178 float alpha = all(top <= position.xy) && all(position.xy <= bottom) ? 1.0f : 0.0f;
30179 target0 = float4(0.0f, 1.0f, 0.0f, alpha);
30180 target1 = float4(0.0f, 0.0f, 1.0f, alpha1);
30181 target2 = float4(0.0f, 1.0f, 0.0f, alpha2);
30183 #endif
30184 0x43425844, 0x771ff802, 0xca927279, 0x5bdd75ae, 0xf53cb31b, 0x00000001, 0x00000264, 0x00000003,
30185 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30186 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
30187 0x4e47534f, 0x0000005c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003,
30188 0x00000000, 0x0000000f, 0x00000050, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
30189 0x00000050, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x545f5653, 0x65677261,
30190 0xabab0074, 0x52444853, 0x00000198, 0x00000040, 0x00000066, 0x04000059, 0x00208e46, 0x00000000,
30191 0x00000002, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
30192 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001,
30193 0x0800001d, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00208046, 0x00000000, 0x00000000,
30194 0x07000001, 0x00100012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0800001d,
30195 0x00100062, 0x00000000, 0x00208ba6, 0x00000000, 0x00000000, 0x00101106, 0x00000000, 0x07000001,
30196 0x00100022, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x07000001, 0x00100012,
30197 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00102082, 0x00000000,
30198 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x08000036, 0x00102072, 0x00000000, 0x00004002,
30199 0x00000000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x00102072, 0x00000001, 0x00004002,
30200 0x00000000, 0x00000000, 0x3f800000, 0x00000000, 0x06000036, 0x00102082, 0x00000001, 0x0020800a,
30201 0x00000000, 0x00000001, 0x08000036, 0x00102072, 0x00000002, 0x00004002, 0x00000000, 0x3f800000,
30202 0x00000000, 0x00000000, 0x06000036, 0x00102082, 0x00000002, 0x0020801a, 0x00000000, 0x00000001,
30203 0x0100003e,
30205 static const DWORD colors[] = {0xff00ff00, 0xbfff0000, 0x8000ff00};
30207 if (!init_test_context(&test_context, NULL))
30208 return;
30209 device = test_context.device;
30210 context = test_context.immediate_context;
30212 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30213 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
30214 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30216 memset(&blend_desc, 0, sizeof(blend_desc));
30217 blend_desc.AlphaToCoverageEnable = TRUE;
30218 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
30219 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
30220 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
30221 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
30223 render_targets[0] = test_context.backbuffer;
30224 rtvs[0] = test_context.backbuffer_rtv;
30225 for (i = 1; i < ARRAY_SIZE(render_targets); ++i)
30227 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30228 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
30229 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30230 hr = ID3D11Device_CreateRenderTargetView(device,
30231 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
30232 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
30234 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
30236 cb_data.top.x = cb_data.top.y = 0.0f;
30237 cb_data.bottom.x = cb_data.bottom.y = 200.0f;
30238 cb_data.alpha[0] = 0.75;
30239 cb_data.alpha[1] = 0.5f;
30240 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
30241 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30243 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
30244 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
30245 draw_quad(&test_context);
30246 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
30248 DWORD expected_color;
30250 assert(i < ARRAY_SIZE(colors));
30251 expected_color = colors[i];
30252 get_texture_readback(render_targets[i], 0, &rb);
30253 SetRect(&rect, 0, 0, 200, 200);
30254 check_readback_data_color(&rb, &rect, expected_color, 1);
30255 SetRect(&rect, 200, 0, 640, 200);
30256 todo_wine
30257 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30258 SetRect(&rect, 0, 200, 640, 480);
30259 todo_wine
30260 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30261 release_resource_readback(&rb);
30263 if (i > 0)
30264 ID3D11Texture2D_Release(render_targets[i]);
30265 render_targets[i] = NULL;
30268 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30269 texture_desc.Format = DXGI_FORMAT_R16G16_UNORM;
30270 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[0]);
30271 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30272 hr = ID3D11Device_CreateRenderTargetView(device,
30273 (ID3D11Resource *)render_targets[0], NULL, &rtvs[0]);
30274 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
30275 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
30277 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
30278 draw_quad(&test_context);
30279 get_texture_readback(render_targets[0], 0, &rb);
30280 SetRect(&rect, 0, 0, 200, 200);
30281 check_readback_data_color(&rb, &rect, 0xffff0000, 1);
30282 SetRect(&rect, 200, 0, 640, 200);
30283 todo_wine
30284 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30285 SetRect(&rect, 0, 200, 640, 480);
30286 todo_wine
30287 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30288 release_resource_readback(&rb);
30290 ID3D11Texture2D_Release(render_targets[0]);
30291 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
30292 ID3D11RenderTargetView_Release(rtvs[i]);
30294 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30295 hr = ID3D11Device_CheckMultisampleQualityLevels(device,
30296 texture_desc.Format, 4, &quality_level_count);
30297 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
30298 if (!quality_level_count)
30300 skip("4xMSAA not supported.\n");
30301 goto done;
30303 texture_desc.SampleDesc.Count = 4;
30304 texture_desc.SampleDesc.Quality = 0;
30306 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
30308 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
30309 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30310 hr = ID3D11Device_CreateRenderTargetView(device,
30311 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
30312 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
30314 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
30316 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
30317 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
30318 draw_quad(&test_context);
30319 texture_desc.SampleDesc.Count = 1;
30320 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
30321 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30322 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
30324 DWORD expected_color;
30326 assert(i < ARRAY_SIZE(colors));
30327 expected_color = colors[i];
30329 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
30330 (ID3D11Resource *)render_targets[i], 0, texture_desc.Format);
30332 get_texture_readback(readback_texture, 0, &rb);
30333 SetRect(&rect, 0, 0, 200, 200);
30334 check_readback_data_color(&rb, &rect, expected_color, 1);
30335 SetRect(&rect, 200, 0, 640, 200);
30336 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30337 SetRect(&rect, 0, 200, 640, 480);
30338 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30339 release_resource_readback(&rb);
30341 ID3D11Texture2D_Release(readback_texture);
30343 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
30345 ID3D11Texture2D_Release(render_targets[i]);
30346 ID3D11RenderTargetView_Release(rtvs[i]);
30349 done:
30350 ID3D11Buffer_Release(cb);
30351 ID3D11PixelShader_Release(ps);
30352 ID3D11BlendState_Release(blend_state);
30353 release_test_context(&test_context);
30356 static void test_unbound_multisample_texture(void)
30358 struct d3d11_test_context test_context;
30359 ID3D11DeviceContext *context;
30360 ID3D11PixelShader *ps;
30361 struct uvec4 cb_data;
30362 ID3D11Device *device;
30363 ID3D11Buffer *cb;
30364 unsigned int i;
30365 HRESULT hr;
30367 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30368 static const DWORD ps_code[] =
30370 #if 0
30371 Texture2DMS<float4, 4> t;
30373 uint sample_index;
30375 float4 main(float4 position : SV_Position) : SV_Target
30377 float3 p;
30378 t.GetDimensions(p.x, p.y, p.z);
30379 p *= float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
30380 /* sample index must be a literal */
30381 switch (sample_index)
30383 case 1: return t.Load(int2(p.xy), 1);
30384 case 2: return t.Load(int2(p.xy), 2);
30385 case 3: return t.Load(int2(p.xy), 3);
30386 default: return t.Load(int2(p.xy), 0);
30389 #endif
30390 0x43425844, 0x03d62416, 0x1914ee8b, 0xccd08d68, 0x27f42136, 0x00000001, 0x000002f8, 0x00000003,
30391 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30392 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
30393 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
30394 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000025c, 0x00000040,
30395 0x00000097, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04042058, 0x00107000, 0x00000000,
30396 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
30397 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46,
30398 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000,
30399 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
30400 0x00000000, 0x00000000, 0x0400004c, 0x0020800a, 0x00000000, 0x00000000, 0x03000006, 0x00004001,
30401 0x00000001, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000, 0x08000036, 0x001000c2,
30402 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0900002e, 0x001020f2,
30403 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
30404 0x03000006, 0x00004001, 0x00000002, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000,
30405 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
30406 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001,
30407 0x00000002, 0x0100003e, 0x03000006, 0x00004001, 0x00000003, 0x0500001b, 0x00100032, 0x00000001,
30408 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000,
30409 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46,
30410 0x00000000, 0x00004001, 0x00000003, 0x0100003e, 0x0100000a, 0x0500001b, 0x00100032, 0x00000000,
30411 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
30412 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46,
30413 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000017, 0x0100003e,
30416 if (!init_test_context(&test_context, NULL))
30417 return;
30418 device = test_context.device;
30419 context = test_context.immediate_context;
30421 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30422 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30423 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30425 memset(&cb_data, 0, sizeof(cb_data));
30426 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
30427 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30429 for (i = 0; i < 4; ++i)
30431 cb_data.x = i;
30432 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_data, 0, 0);
30433 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
30434 draw_quad(&test_context);
30435 check_texture_color(test_context.backbuffer, 0x00000000, 1);
30438 ID3D11Buffer_Release(cb);
30439 ID3D11PixelShader_Release(ps);
30440 release_test_context(&test_context);
30443 static void test_multiple_viewports(void)
30445 struct
30447 unsigned int draw_id;
30448 unsigned int padding[3];
30449 } constant;
30450 D3D11_VIEWPORT vp[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE + 1];
30451 struct d3d11_test_context test_context;
30452 D3D11_TEXTURE2D_DESC texture_desc;
30453 ID3D11DeviceContext *context;
30454 ID3D11RenderTargetView *rtv;
30455 ID3D11Texture2D *texture;
30456 ID3D11GeometryShader *gs;
30457 ID3D11PixelShader *ps;
30458 ID3D11Device *device;
30459 ID3D11Buffer *cb;
30460 HRESULT hr;
30462 static const DWORD gs_code[] =
30464 #if 0
30465 struct gs_in
30467 float4 pos : SV_Position;
30470 struct gs_out
30472 float4 pos : SV_Position;
30473 uint viewport : SV_ViewportArrayIndex;
30476 [maxvertexcount(6)]
30477 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
30479 gs_out o;
30480 for (uint instance_id = 0; instance_id < 2; ++instance_id)
30482 o.viewport = instance_id;
30483 for (uint i = 0; i < 3; ++i)
30485 o.pos = vin[i].pos;
30486 vout.Append(o);
30488 vout.RestartStrip();
30491 #endif
30492 0x43425844, 0xabbb660f, 0x0729bf23, 0x14a9a104, 0x1b454917, 0x00000001, 0x0000021c, 0x00000003,
30493 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30494 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
30495 0x4e47534f, 0x0000005c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
30496 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005, 0x00000001, 0x00000001, 0x00000e01,
30497 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569, 0x4174726f, 0x79617272, 0x65646e49,
30498 0xabab0078, 0x52444853, 0x00000150, 0x00020040, 0x00000054, 0x05000061, 0x002010f2, 0x00000003,
30499 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
30500 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000005, 0x0200005e, 0x00000006,
30501 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
30502 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x03040003, 0x0010001a, 0x00000000,
30503 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
30504 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000,
30505 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036,
30506 0x00102012, 0x00000001, 0x0010000a, 0x00000000, 0x01000013, 0x0700001e, 0x00100022, 0x00000000,
30507 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012,
30508 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
30510 static const DWORD ps_code[] =
30512 #if 0
30513 uint draw_id;
30515 float4 main(in float4 pos : SV_Position,
30516 in uint viewport : SV_ViewportArrayIndex) : SV_Target
30518 return float4(viewport, draw_id, 0, 0);
30520 #endif
30521 0x43425844, 0x77334c0f, 0x5df3ca7a, 0xc53c00db, 0x3e6e5750, 0x00000001, 0x00000150, 0x00000003,
30522 0x0000002c, 0x00000090, 0x000000c4, 0x4e475349, 0x0000005c, 0x00000002, 0x00000008, 0x00000038,
30523 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005,
30524 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569,
30525 0x4174726f, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
30526 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261,
30527 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46, 0x00000000,
30528 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000005, 0x03000065, 0x001020f2, 0x00000000,
30529 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022, 0x00000000,
30530 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000,
30531 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
30533 static const struct vec4 expected_values[] =
30535 {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},
30536 {0.0f, 5.0f}, {0.5f, 0.5f}, {1.0f, 5.0f}, {0.5f, 0.5f},
30538 static const float clear_color[] = {0.5f, 0.5f, 0.0f, 0.0f};
30539 ID3D11RasterizerState *rasterizer_state;
30540 D3D11_RASTERIZER_DESC rasterizer_desc;
30541 unsigned int count, i;
30542 D3D11_RECT rects[2];
30543 RECT rect;
30544 int width;
30546 if (!init_test_context(&test_context, NULL))
30547 return;
30549 device = test_context.device;
30550 context = test_context.immediate_context;
30552 memset(&constant, 0, sizeof(constant));
30553 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
30554 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30556 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
30557 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
30558 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
30560 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30561 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
30562 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30564 texture_desc.Width = 32;
30565 texture_desc.Height = 32;
30566 texture_desc.MipLevels = 1;
30567 texture_desc.ArraySize = 1;
30568 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
30569 texture_desc.SampleDesc.Count = 1;
30570 texture_desc.SampleDesc.Quality = 0;
30571 texture_desc.Usage = D3D11_USAGE_DEFAULT;
30572 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
30573 texture_desc.CPUAccessFlags = 0;
30574 texture_desc.MiscFlags = 0;
30575 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30576 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30578 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
30579 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
30580 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30582 width = texture_desc.Width / 2;
30584 vp[0].TopLeftX = 0.0f;
30585 vp[0].TopLeftY = 0.0f;
30586 vp[0].Width = width;
30587 vp[0].Height = texture_desc.Height;
30588 vp[0].MinDepth = 0.0f;
30589 vp[0].MaxDepth = 1.0f;
30591 vp[1] = vp[0];
30592 vp[1].TopLeftX = width;
30593 vp[1].Width = width;
30594 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
30596 count = enable_debug_layer ? ARRAY_SIZE(vp) - 1 : ARRAY_SIZE(vp);
30597 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
30598 ok(count == 2, "Unexpected viewport count %d.\n", count);
30600 constant.draw_id = 0;
30601 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30602 draw_quad(&test_context);
30603 constant.draw_id = 1;
30604 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30605 draw_quad(&test_context);
30607 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
30608 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[0], 1);
30609 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30610 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[1], 1);
30612 /* One viewport. */
30613 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30614 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
30615 constant.draw_id = 2;
30616 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30617 draw_quad(&test_context);
30618 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
30619 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[2], 1);
30620 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30621 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[3], 1);
30623 /* Reset viewports. */
30624 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30625 ID3D11DeviceContext_RSSetViewports(context, 0, NULL);
30626 constant.draw_id = 3;
30627 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30628 draw_quad(&test_context);
30629 check_texture_sub_resource_vec4(texture, 0, NULL, &expected_values[4], 1);
30631 /* Two viewports, only first scissor rectangle set. */
30632 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
30633 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
30634 rasterizer_desc.CullMode = D3D11_CULL_BACK;
30635 rasterizer_desc.DepthClipEnable = TRUE;
30636 rasterizer_desc.ScissorEnable = TRUE;
30637 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
30638 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
30640 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
30641 ID3D11RasterizerState_Release(rasterizer_state);
30643 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30644 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
30646 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
30647 memset(&rects[1], 0, sizeof(*rects));
30648 ID3D11DeviceContext_RSSetScissorRects(context, 1, rects);
30649 constant.draw_id = 4;
30650 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30651 draw_quad(&test_context);
30653 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
30654 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[5], 1);
30655 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
30656 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[6], 1);
30657 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30658 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[7], 1);
30660 /* Set both rectangles. */
30661 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
30662 SetRect(&rects[1], width, 0, 2 * width, texture_desc.Height / 2);
30663 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30664 ID3D11DeviceContext_RSSetScissorRects(context, 2, rects);
30665 constant.draw_id = 5;
30666 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30667 draw_quad(&test_context);
30669 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
30670 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[8], 1);
30671 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
30672 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[9], 1);
30674 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height / 2 - 1);
30675 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[10], 1);
30676 SetRect(&rect, width, texture_desc.Height / 2, 2 * width - 1, texture_desc.Height - 1);
30677 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[11], 1);
30679 if (enable_debug_layer)
30680 goto done;
30682 /* Viewport count exceeding maximum value. */
30683 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
30685 vp[0].TopLeftX = 1.0f;
30686 vp[0].TopLeftY = 0.0f;
30687 vp[0].Width = width;
30688 vp[0].Height = texture_desc.Height;
30689 vp[0].MinDepth = 0.0f;
30690 vp[0].MaxDepth = 1.0f;
30691 for (i = 1; i < ARRAY_SIZE(vp); ++i)
30693 vp[i] = vp[0];
30695 ID3D11DeviceContext_RSSetViewports(context, ARRAY_SIZE(vp), vp);
30697 count = ARRAY_SIZE(vp);
30698 memset(vp, 0, sizeof(vp));
30699 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
30700 ok(count == 1, "Unexpected viewport count %d.\n", count);
30701 ok(vp[0].TopLeftX == 0.0f && vp[0].Width == width, "Unexpected viewport.\n");
30703 done:
30704 ID3D11RenderTargetView_Release(rtv);
30705 ID3D11Texture2D_Release(texture);
30707 ID3D11Buffer_Release(cb);
30708 ID3D11GeometryShader_Release(gs);
30709 ID3D11PixelShader_Release(ps);
30710 release_test_context(&test_context);
30713 static void test_multisample_resolve(void)
30715 struct d3d11_test_context test_context;
30716 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
30717 ID3D11Texture2D *texture, *ms_texture;
30718 D3D11_TEXTURE2D_DESC texture_desc;
30719 ID3D11DeviceContext *context;
30720 ID3D11RenderTargetView *rtv;
30721 ID3D11Device *device;
30722 unsigned int i;
30723 HRESULT hr;
30725 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30726 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
30727 static const struct vec4 color = {0.25f, 0.5f, 0.75f, 1.0f};
30728 static const struct
30730 DXGI_FORMAT src_format;
30731 DXGI_FORMAT dst_format;
30732 DXGI_FORMAT format;
30734 DXGI_FORMAT rtv_format;
30736 const struct vec4 *color;
30737 DWORD expected_color;
30739 BOOL todo;
30741 tests[] =
30743 {DXGI_FORMAT_R8G8B8A8_UNORM,
30744 DXGI_FORMAT_R8G8B8A8_UNORM,
30745 DXGI_FORMAT_R8G8B8A8_UNORM,
30746 DXGI_FORMAT_R8G8B8A8_UNORM,
30747 &green, 0xff80ff80},
30748 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30749 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30750 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30751 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30752 &green, 0xffbcffbc},
30753 {DXGI_FORMAT_R8G8B8A8_UNORM,
30754 DXGI_FORMAT_R8G8B8A8_UNORM,
30755 DXGI_FORMAT_R8G8B8A8_UNORM,
30756 DXGI_FORMAT_R8G8B8A8_UNORM,
30757 &color, 0xffdfc0a0},
30758 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30759 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30760 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30761 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30762 &color, 0xfff1e1cf},
30764 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30765 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30766 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30767 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30768 &green, 0xffbcffbc},
30769 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30770 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30771 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30772 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30773 &green, 0xffbcffbc},
30774 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30775 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30776 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30777 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30778 &color, 0xfff1e1cf},
30779 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30780 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30781 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30782 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30783 &color, 0xfff1e1cf},
30785 {DXGI_FORMAT_R8G8B8A8_UNORM,
30786 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30787 DXGI_FORMAT_R8G8B8A8_UNORM,
30788 DXGI_FORMAT_R8G8B8A8_UNORM,
30789 &green, 0xff80ff80},
30790 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30791 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30792 DXGI_FORMAT_R8G8B8A8_UNORM,
30793 DXGI_FORMAT_R8G8B8A8_UNORM,
30794 &green, 0xff80ff80},
30795 {DXGI_FORMAT_R8G8B8A8_UNORM,
30796 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30797 DXGI_FORMAT_R8G8B8A8_UNORM,
30798 DXGI_FORMAT_R8G8B8A8_UNORM,
30799 &color, 0xffdfc0a0},
30800 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30801 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30802 DXGI_FORMAT_R8G8B8A8_UNORM,
30803 DXGI_FORMAT_R8G8B8A8_UNORM,
30804 &color, 0xffdfc0a0},
30806 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30807 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30808 DXGI_FORMAT_R8G8B8A8_UNORM,
30809 DXGI_FORMAT_R8G8B8A8_UNORM,
30810 &green, 0xff80ff80},
30811 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30812 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30813 DXGI_FORMAT_R8G8B8A8_UNORM,
30814 DXGI_FORMAT_R8G8B8A8_UNORM,
30815 &color, 0xffdfc0a0},
30816 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30817 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30818 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30819 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30820 &green, 0xffbcffbc},
30821 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30822 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30823 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30824 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30825 &color, 0xfff1e1cf},
30826 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30827 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30828 DXGI_FORMAT_R8G8B8A8_UNORM,
30829 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30830 &green, 0xff80ff80},
30831 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30832 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30833 DXGI_FORMAT_R8G8B8A8_UNORM,
30834 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30835 &color, 0xfff0dec4},
30836 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30837 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30838 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30839 DXGI_FORMAT_R8G8B8A8_UNORM,
30840 &green, 0xffbcffbc, TRUE},
30841 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30842 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30843 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30844 DXGI_FORMAT_R8G8B8A8_UNORM,
30845 &color, 0xffe2cdc0, TRUE},
30848 if (!init_test_context(&test_context, NULL))
30849 return;
30850 device = test_context.device;
30851 context = test_context.immediate_context;
30853 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &i);
30854 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
30855 if (!i)
30857 skip("4xMSAA not supported.\n");
30858 release_test_context(&test_context);
30859 return;
30862 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, 3);
30864 for (i = 0; i < ARRAY_SIZE(tests); ++i)
30866 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30867 texture_desc.Format = tests[i].dst_format;
30868 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30869 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30871 texture_desc.Format = tests[i].src_format;
30872 texture_desc.SampleDesc.Count = 4;
30873 texture_desc.SampleDesc.Quality = 0;
30874 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ms_texture);
30875 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30876 rtv_desc.Format = tests[i].rtv_format;
30877 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
30878 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)ms_texture, &rtv_desc, &rtv);
30879 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
30881 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30882 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
30883 draw_color_quad(&test_context, tests[i].color);
30884 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)texture, 0,
30885 (ID3D11Resource *)ms_texture, 0, tests[i].format);
30887 /* Found broken on AMD Radeon HD 6310 */
30888 if (!broken(is_amd_device(device) && tests[i].format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB))
30889 todo_wine_if(tests[i].todo) check_texture_color(texture, tests[i].expected_color, 2);
30891 ID3D11RenderTargetView_Release(rtv);
30892 ID3D11Texture2D_Release(ms_texture);
30893 ID3D11Texture2D_Release(texture);
30896 release_test_context(&test_context);
30899 static void test_sample_shading(void)
30901 struct shader
30903 const DWORD *code;
30904 size_t size;
30907 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
30908 struct d3d11_test_context test_context;
30909 struct swapchain_desc swapchain_desc;
30910 D3D11_TEXTURE2D_DESC texture_desc;
30911 ID3D11UnorderedAccessView *uav;
30912 D3D11_BUFFER_DESC buffer_desc;
30913 ID3D11ShaderResourceView *srv;
30914 ID3D11DeviceContext *context;
30915 ID3D11RenderTargetView *rtv;
30916 struct resource_readback rb;
30917 ID3D11Buffer *buffer, *cb;
30918 ID3D11Texture2D *texture;
30919 struct uvec4 ps_constant;
30920 ID3D11PixelShader *ps;
30921 ID3D11Device *device;
30922 unsigned int data;
30923 unsigned int i;
30924 HRESULT hr;
30926 static const DWORD ps_unused_sample_index_code[] =
30928 #if 0
30929 RWByteAddressBuffer u;
30931 float4 main(uint id : SV_SampleIndex) : SV_Target
30933 u.InterlockedAdd(0, 1);
30934 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30936 #endif
30937 0x43425844, 0x41e4574b, 0x1e6441d6, 0x5e756375, 0xacd5dc27, 0x00000001, 0x00000104, 0x00000003,
30938 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30939 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000001, 0x535f5653, 0x6c706d61, 0x646e4965,
30940 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30941 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064,
30942 0x00000050, 0x00000019, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2,
30943 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
30944 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
30945 0x0100003e,
30947 static const struct shader ps_unused_sample_index
30948 = {ps_unused_sample_index_code, sizeof(ps_unused_sample_index_code)};
30949 static const DWORD ps_sample_index_code[] =
30951 #if 0
30952 RWByteAddressBuffer u;
30954 float4 main(uint id : SV_SampleIndex) : SV_Target
30956 u.InterlockedAdd(0, 1);
30957 u.InterlockedAdd(4, id);
30958 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30960 #endif
30961 0x43425844, 0x943ab9ed, 0x91520b4a, 0xb75df9d0, 0x692cd3e6, 0x00000001, 0x00000130, 0x00000003,
30962 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30963 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
30964 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30965 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000090,
30966 0x00000050, 0x00000024, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
30967 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001,
30968 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
30969 0x00000004, 0x0010100a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
30970 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30972 static const struct shader ps_sample_index = {ps_sample_index_code, sizeof(ps_sample_index_code)};
30973 static const DWORD ps_samplepos_code[] =
30975 #if 0
30976 Texture2DMS<float> t;
30977 RWByteAddressBuffer u;
30979 float4 main() : SV_Target
30981 float2 sample_position = t.GetSamplePosition(0);
30982 u.InterlockedAdd(0, 1);
30983 u.InterlockedAdd(4, sample_position.x + sample_position.y);
30984 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30986 #endif
30987 0x43425844, 0x9ec7f344, 0x588f5863, 0x436c0531, 0x69dc54bb, 0x00000001, 0x00000160, 0x00000003,
30988 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
30989 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
30990 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e8, 0x00000050, 0x0000003a,
30991 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
30992 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
30993 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
30994 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
30995 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
30996 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
30997 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30999 static const struct shader ps_samplepos = {ps_samplepos_code, sizeof(ps_samplepos_code)};
31000 static const DWORD ps_samplepos_rasterizer_code[] =
31002 #if 0
31003 RWByteAddressBuffer u;
31005 float4 main() : SV_Target
31007 float2 sample_position = GetRenderTargetSamplePosition(0);
31008 u.InterlockedAdd(0, 1);
31009 u.InterlockedAdd(4, sample_position.x + sample_position.y);
31010 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31012 #endif
31013 0x43425844, 0xe31795d9, 0x4e9951da, 0xc1713913, 0xfb12da31, 0x00000001, 0x00000148, 0x00000003,
31014 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31015 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31016 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d0, 0x00000050, 0x00000034,
31017 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
31018 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
31019 0x0600006e, 0x00100032, 0x00000000, 0x0000e046, 0x00004001, 0x00000000, 0x07000000, 0x00100012,
31020 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
31021 0x0010000a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
31022 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
31023 0x3f800000, 0x0100003e,
31025 static const struct shader ps_samplepos_rasterizer
31026 = {ps_samplepos_rasterizer_code, sizeof(ps_samplepos_rasterizer_code)};
31027 static const DWORD ps_samplepos_indexed_code[] =
31029 #if 0
31030 RWByteAddressBuffer u;
31032 float4 main(uint id : SV_SampleIndex) : SV_Target
31034 float2 sample_position = GetRenderTargetSamplePosition(id);
31035 u.InterlockedAdd(0, 1);
31036 u.InterlockedAdd(4, sample_position.x + sample_position.y);
31037 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31039 #endif
31040 0x43425844, 0x4b501464, 0x0cd4f636, 0x36428677, 0x6db6b4fb, 0x00000001, 0x00000180, 0x00000003,
31041 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
31042 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
31043 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
31044 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e0,
31045 0x00000050, 0x00000038, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
31046 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad,
31047 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0600006e, 0x00100032,
31048 0x00000000, 0x0000e046, 0x0010100a, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
31049 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
31050 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
31051 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
31053 static const struct shader ps_samplepos_indexed
31054 = {ps_samplepos_indexed_code, sizeof(ps_samplepos_indexed_code)};
31055 static const DWORD ps_sampleinfo_code[] =
31057 #if 0
31058 Texture2DMS<float> t;
31059 RWByteAddressBuffer u;
31061 float4 main() : SV_Target
31063 uint width, height, sample_count;
31064 t.GetDimensions(width, height, sample_count);
31065 u.InterlockedAdd(0, 1);
31066 u.InterlockedAdd(4, sample_count);
31067 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31069 #endif
31070 0x43425844, 0x4e4f4065, 0x20d88902, 0xd4750e8c, 0x652b8c04, 0x00000001, 0x00000124, 0x00000003,
31071 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31072 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31073 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050, 0x0000002b,
31074 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
31075 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
31076 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a,
31077 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000,
31078 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
31079 0x0100003e,
31081 static const struct shader ps_sampleinfo = {ps_sampleinfo_code, sizeof(ps_sampleinfo_code)};
31082 static const DWORD ps_sampleinfo_rasterizer_code[] =
31084 #if 0
31085 RWByteAddressBuffer u;
31087 float4 main() : SV_Target
31089 uint sample_count = GetRenderTargetSampleCount();
31090 u.InterlockedAdd(0, 1);
31091 u.InterlockedAdd(4, sample_count);
31092 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31094 #endif
31095 0x43425844, 0xfbbd8619, 0x9c2654c8, 0xb385363a, 0x4aacd10f, 0x00000001, 0x00000110, 0x00000003,
31096 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31097 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31098 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000098, 0x00000050, 0x00000026,
31099 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
31100 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
31101 0x0400086f, 0x00100012, 0x00000000, 0x0000e00a, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
31102 0x00000004, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31103 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
31105 static const struct shader ps_sampleinfo_rasterizer
31106 = {ps_sampleinfo_rasterizer_code, sizeof(ps_sampleinfo_rasterizer_code)};
31107 static const DWORD ps_sample_code[] =
31109 #if 0
31110 RWByteAddressBuffer u;
31112 float4 main(sample float4 position : SV_Position) : SV_Target
31114 u.InterlockedAdd(0, 1);
31115 u.InterlockedAdd(4, position.x);
31116 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31118 #endif
31119 0x43425844, 0x46ecbadb, 0xedccbea6, 0x236d7923, 0x0c356c8c, 0x00000001, 0x00000148, 0x00000003,
31120 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31121 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x7469736f, 0x006e6f69,
31122 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
31123 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050,
31124 0x0000002b, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04003864, 0x00101012, 0x00000000,
31125 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000,
31126 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500001c, 0x00100012, 0x00000000,
31127 0x0010100a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
31128 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
31129 0x3f800000, 0x0100003e,
31131 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
31132 static const DWORD ps_color_code[] =
31134 #if 0
31135 float4 main(uint id : SV_SampleIndex) : SV_Target
31137 switch (id)
31139 case 0: return float4(1.0f, 0.0f, 0.0f, 1.0f);
31140 case 1: return float4(0.0f, 1.0f, 0.0f, 1.0f);
31141 case 2: return float4(0.0f, 0.0f, 1.0f, 1.0f);
31142 default: return float4(0.0f, 0.0f, 0.0f, 1.0f);
31145 #endif
31146 0x43425844, 0x94c35f48, 0x04c6b0f7, 0x407d8214, 0xc24f01e5, 0x00000001, 0x00000194, 0x00000003,
31147 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
31148 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
31149 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
31150 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f4,
31151 0x00000050, 0x0000003d, 0x0100086a, 0x04000863, 0x00101012, 0x00000000, 0x0000000a, 0x03000065,
31152 0x001020f2, 0x00000000, 0x0300004c, 0x0010100a, 0x00000000, 0x03000006, 0x00004001, 0x00000000,
31153 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
31154 0x0100003e, 0x03000006, 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
31155 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x03000006, 0x00004001, 0x00000002,
31156 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000,
31157 0x0100003e, 0x0100000a, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
31158 0x00000000, 0x3f800000, 0x0100003e, 0x01000017, 0x0100003e,
31160 static const DWORD ps_resolve_code[] =
31162 #if 0
31163 Texture2DMS<float4> t;
31165 uint sample;
31166 uint rt_size;
31168 float4 main(float4 position : SV_Position) : SV_Target
31170 float3 p;
31171 t.GetDimensions(p.x, p.y, p.z);
31172 p *= float3(position.x / rt_size, position.y / rt_size, 0);
31173 return t.Load((int2)p.xy, sample);
31175 #endif
31176 0x43425844, 0x68a4590b, 0xc1ec3070, 0x1b957c43, 0x0c080741, 0x00000001, 0x000001c8, 0x00000003,
31177 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31178 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
31179 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
31180 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000012c, 0x00000050,
31181 0x0000004b, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002058, 0x00107000,
31182 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
31183 0x00000000, 0x02000068, 0x00000001, 0x06000056, 0x00100012, 0x00000000, 0x0020801a, 0x00000000,
31184 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00100006, 0x00000000,
31185 0x8900003d, 0x80000102, 0x00155543, 0x001000c2, 0x00000000, 0x00004001, 0x00000000, 0x001074e6,
31186 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000,
31187 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000,
31188 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8c00002e, 0x80000102, 0x00155543,
31189 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0020800a, 0x00000000,
31190 0x00000000, 0x0100003e,
31192 static const struct
31194 const struct shader *ps;
31195 BOOL sample_shading;
31196 BOOL todo;
31197 BOOL broken;
31199 tests[] =
31201 {&ps_unused_sample_index, FALSE, FALSE, TRUE /* broken on Nvidia */},
31202 {&ps_sample_index, TRUE},
31203 {&ps_samplepos, FALSE},
31204 {&ps_samplepos_rasterizer, FALSE},
31205 {&ps_samplepos_indexed, TRUE, TRUE},
31206 {&ps_sampleinfo, FALSE},
31207 {&ps_sampleinfo_rasterizer, FALSE},
31208 {&ps_sample, TRUE, TRUE, TRUE /* broken on Intel */},
31210 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
31211 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
31212 static const unsigned int zero[4] = {0};
31214 swapchain_desc.windowed = TRUE;
31215 swapchain_desc.buffer_count = 1;
31216 swapchain_desc.width = 32;
31217 swapchain_desc.height = 32;
31218 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
31219 swapchain_desc.flags = 0;
31220 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
31221 return;
31222 device = test_context.device;
31223 context = test_context.immediate_context;
31225 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31226 texture_desc.SampleDesc.Count = 4;
31227 texture_desc.SampleDesc.Quality = 0;
31228 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
31229 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31230 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31231 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
31232 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
31233 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
31234 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
31236 buffer_desc.ByteWidth = 1024;
31237 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
31238 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
31239 buffer_desc.CPUAccessFlags = 0;
31240 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
31241 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
31242 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31243 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
31244 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
31245 U(uav_desc).Buffer.FirstElement = 0;
31246 U(uav_desc).Buffer.NumElements = 256;
31247 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
31248 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
31249 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
31251 for (i = 0; i < ARRAY_SIZE(tests); ++i)
31253 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
31254 ok(hr == S_OK, "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
31255 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31257 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
31258 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
31259 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
31260 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
31261 draw_quad(&test_context);
31262 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
31263 get_buffer_readback(buffer, &rb);
31264 data = get_readback_color(&rb, 0, 0, 0);
31265 ok(1024 <= data && data <= 1056, "Test %u: Got unexpected value %u.\n", i, data);
31266 release_resource_readback(&rb);
31268 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
31269 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
31270 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
31271 1, &rtv, NULL, 1, 1, &uav, NULL);
31272 draw_quad(&test_context);
31273 get_buffer_readback(buffer, &rb);
31274 data = get_readback_color(&rb, 0, 0, 0);
31275 todo_wine_if(tests[i].todo)
31277 if (tests[i].sample_shading)
31279 ok(4096 <= data || broken(tests[i].broken && data >= 1024),
31280 "Test %u: Got unexpected value %u.\n", i, data);
31282 else
31284 ok((1024 <= data && data <= 1056) || broken(tests[i].broken && data >= 4096),
31285 "Test %u: Got unexpected value %u.\n", i, data);
31288 release_resource_readback(&rb);
31290 ID3D11PixelShader_Release(ps);
31293 if (is_warp_device(device))
31295 skip("Sample shading tests fail on WARP.\n");
31296 goto done;
31299 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps);
31300 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31301 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31302 ID3D11PixelShader_Release(ps);
31304 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
31305 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
31306 draw_quad(&test_context);
31307 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
31308 (ID3D11Resource *)texture, 0, texture_desc.Format);
31309 check_texture_color(test_context.backbuffer, 0xff404040, 2);
31311 hr = ID3D11Device_CreatePixelShader(device, ps_resolve_code, sizeof(ps_resolve_code), NULL, &ps);
31312 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31313 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31314 ID3D11PixelShader_Release(ps);
31315 ps_constant.x = 0;
31316 ps_constant.y = texture_desc.Width;
31317 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
31318 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
31320 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
31321 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
31322 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31323 draw_quad(&test_context);
31324 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
31325 ps_constant.x = 1;
31326 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
31327 draw_quad(&test_context);
31328 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
31329 ps_constant.x = 2;
31330 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
31331 draw_quad(&test_context);
31332 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
31333 ps_constant.x = 3;
31334 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
31335 draw_quad(&test_context);
31336 check_texture_color(test_context.backbuffer, 0xff000000, 0);
31338 ID3D11Buffer_Release(cb);
31339 done:
31340 ID3D11Buffer_Release(buffer);
31341 ID3D11UnorderedAccessView_Release(uav);
31342 ID3D11RenderTargetView_Release(rtv);
31343 ID3D11ShaderResourceView_Release(srv);
31344 ID3D11Texture2D_Release(texture);
31345 release_test_context(&test_context);
31348 static void test_sample_mask(void)
31350 static const DWORD ps_code[] =
31352 #if 0
31353 float4 main(in float4 pos : SV_Position, out uint sample_mask : SV_Coverage) : SV_Target
31355 sample_mask = 0x5;
31356 return float4(1.0, 1.0, 1.0, 1.0);
31358 #endif
31359 0x43425844, 0x196779a9, 0xda85988a, 0xb7f0a0b6, 0xb30dd6ba, 0x00000001, 0x00000114, 0x00000003,
31360 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31361 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
31362 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
31363 0x00000000, 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000001, 0xffffffff, 0x00000e01,
31364 0x545f5653, 0x65677261, 0x56530074, 0x766f435f, 0x67617265, 0xabab0065, 0x58454853, 0x00000054,
31365 0x00000050, 0x00000015, 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x0000f000,
31366 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
31367 0x04000036, 0x0000f001, 0x00004001, 0x00000005, 0x0100003e,
31369 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
31370 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
31371 struct d3d11_test_context test_context;
31372 D3D11_TEXTURE2D_DESC texture_desc;
31373 ID3D11DeviceContext *context;
31374 ID3D11RenderTargetView *rtv;
31375 ID3D11Texture2D *texture;
31376 ID3D11PixelShader *ps;
31377 ID3D11Device *device;
31378 UINT quality_levels;
31379 HRESULT hr;
31381 if (!init_test_context(&test_context, &feature_level))
31382 return;
31383 device = test_context.device;
31384 context = test_context.immediate_context;
31386 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &quality_levels);
31387 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
31388 if (!quality_levels)
31390 skip("4xMSAA not supported.\n");
31391 release_test_context(&test_context);
31392 return;
31395 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31396 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31397 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31399 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31400 texture_desc.SampleDesc.Count = 4;
31401 texture_desc.SampleDesc.Quality = 0;
31402 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31403 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31404 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
31405 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
31407 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
31408 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31409 draw_quad(&test_context);
31410 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
31411 (ID3D11Resource *)texture, 0, texture_desc.Format);
31412 check_texture_color(test_context.backbuffer, 0x7f7f7f7f, 1);
31414 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, 0xb);
31415 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31416 draw_quad(&test_context);
31417 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
31418 (ID3D11Resource *)texture, 0, texture_desc.Format);
31419 check_texture_color(test_context.backbuffer, 0x3f3f3f3f, 1);
31421 ID3D11RenderTargetView_Release(rtv);
31422 ID3D11Texture2D_Release(texture);
31423 ID3D11PixelShader_Release(ps);
31424 release_test_context(&test_context);
31427 static void test_depth_clip(void)
31429 struct d3d11_test_context test_context;
31430 D3D11_TEXTURE2D_DESC texture_desc;
31431 D3D11_RASTERIZER_DESC rs_desc;
31432 ID3D11DeviceContext *context;
31433 ID3D11DepthStencilView *dsv;
31434 ID3D11RasterizerState *rs;
31435 ID3D11Texture2D *texture;
31436 ID3D11Device *device;
31437 unsigned int count;
31438 D3D11_VIEWPORT vp;
31439 HRESULT hr;
31441 if (!init_test_context(&test_context, NULL))
31442 return;
31443 device = test_context.device;
31444 context = test_context.immediate_context;
31446 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31447 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
31448 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
31450 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31451 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
31452 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
31453 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
31454 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
31456 count = 1;
31457 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
31459 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
31460 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
31461 draw_quad_z(&test_context, 2.0f);
31462 check_texture_float(texture, 1.0f, 1);
31463 draw_quad_z(&test_context, 0.5f);
31464 check_texture_float(texture, 0.5f, 1);
31465 draw_quad_z(&test_context, -1.0f);
31466 check_texture_float(texture, 0.5f, 1);
31468 rs_desc.FillMode = D3D11_FILL_SOLID;
31469 rs_desc.CullMode = D3D11_CULL_BACK;
31470 rs_desc.FrontCounterClockwise = FALSE;
31471 rs_desc.DepthBias = 0;
31472 rs_desc.DepthBiasClamp = 0.0f;
31473 rs_desc.SlopeScaledDepthBias = 0.0f;
31474 rs_desc.DepthClipEnable = FALSE;
31475 rs_desc.ScissorEnable = FALSE;
31476 rs_desc.MultisampleEnable = FALSE;
31477 rs_desc.AntialiasedLineEnable = FALSE;
31478 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
31479 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
31481 ID3D11DeviceContext_RSSetState(context, rs);
31483 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
31484 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
31485 draw_quad_z(&test_context, 2.0f);
31486 check_texture_float(texture, 0.6f, 1);
31487 draw_quad_z(&test_context, 0.5f);
31488 check_texture_float(texture, 0.5f, 1);
31489 draw_quad_z(&test_context, -1.0f);
31490 check_texture_float(texture, 0.4f, 1);
31492 ID3D11DepthStencilView_Release(dsv);
31493 ID3D11Texture2D_Release(texture);
31494 ID3D11RasterizerState_Release(rs);
31495 release_test_context(&test_context);
31498 static void test_staging_buffers(void)
31500 struct d3d11_test_context test_context;
31501 ID3D11Buffer *dst_buffer, *src_buffer;
31502 D3D11_SUBRESOURCE_DATA resource_data;
31503 D3D11_BUFFER_DESC buffer_desc;
31504 ID3D11DeviceContext *context;
31505 struct resource_readback rb;
31506 float data[16], value;
31507 ID3D11Device *device;
31508 unsigned int i;
31509 HRESULT hr;
31511 if (!init_test_context(&test_context, NULL))
31512 return;
31513 device = test_context.device;
31514 context = test_context.immediate_context;
31516 buffer_desc.ByteWidth = sizeof(data);
31517 buffer_desc.Usage = D3D11_USAGE_STAGING;
31518 buffer_desc.BindFlags = 0;
31519 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
31520 buffer_desc.MiscFlags = 0;
31521 buffer_desc.StructureByteStride = 0;
31523 for (i = 0; i < ARRAY_SIZE(data); ++i)
31524 data[i] = i;
31525 resource_data.pSysMem = data;
31526 resource_data.SysMemPitch = 0;
31527 resource_data.SysMemSlicePitch = 0;
31529 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &src_buffer);
31530 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31532 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
31533 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
31534 buffer_desc.CPUAccessFlags = 0;
31535 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &dst_buffer);
31536 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31538 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
31539 get_buffer_readback(dst_buffer, &rb);
31540 for (i = 0; i < ARRAY_SIZE(data); ++i)
31542 value = get_readback_float(&rb, i, 0);
31543 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
31545 release_resource_readback(&rb);
31547 for (i = 0; i < ARRAY_SIZE(data); ++i)
31548 data[i] = 2 * i;
31549 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, NULL, data, 0, 0);
31550 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
31551 get_buffer_readback(dst_buffer, &rb);
31552 for (i = 0; i < ARRAY_SIZE(data); ++i)
31554 value = get_readback_float(&rb, i, 0);
31555 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
31557 release_resource_readback(&rb);
31559 ID3D11Buffer_Release(dst_buffer);
31560 ID3D11Buffer_Release(src_buffer);
31561 release_test_context(&test_context);
31564 static void test_render_a8(void)
31566 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
31567 struct d3d11_test_context test_context;
31568 D3D11_TEXTURE2D_DESC texture_desc;
31569 ID3D11DeviceContext *context;
31570 ID3D11RenderTargetView *rtv;
31571 struct resource_readback rb;
31572 ID3D11Texture2D *texture;
31573 ID3D11PixelShader *ps;
31574 ID3D11Device *device;
31575 unsigned int i;
31576 HRESULT hr;
31578 static const DWORD ps_code[] =
31580 #if 0
31581 void main(out float4 target : SV_Target)
31583 target = float4(0.0f, 0.25f, 0.5f, 1.0f);
31585 #endif
31586 0x43425844, 0x8a06129f, 0x3041bde2, 0x09389749, 0xb339ba8b, 0x00000001, 0x000000b0, 0x00000003,
31587 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31588 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31589 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
31590 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31591 0x3e800000, 0x3f000000, 0x3f800000, 0x0100003e,
31594 if (!init_test_context(&test_context, NULL))
31595 return;
31596 device = test_context.device;
31597 context = test_context.immediate_context;
31599 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31600 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31601 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31603 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31604 texture_desc.Format = DXGI_FORMAT_A8_UNORM;
31605 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31606 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31607 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
31608 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
31610 for (i = 0; i < 2; ++i)
31612 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31613 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
31614 draw_quad(&test_context);
31615 get_texture_readback(texture, 0, &rb);
31616 check_readback_data_u8(&rb, NULL, 0xff, 0);
31617 release_resource_readback(&rb);
31619 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
31620 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
31621 draw_quad(&test_context);
31622 check_texture_sub_resource_color(test_context.backbuffer, 0, NULL, 0xff7f4000, 1);
31625 ID3D11PixelShader_Release(ps);
31626 ID3D11Texture2D_Release(texture);
31627 ID3D11RenderTargetView_Release(rtv);
31628 release_test_context(&test_context);
31631 static void test_standard_pattern(void)
31633 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
31634 struct d3d11_test_context test_context;
31635 struct swapchain_desc swapchain_desc;
31636 D3D11_TEXTURE2D_DESC texture_desc;
31637 ID3D11UnorderedAccessView *uav;
31638 D3D11_BUFFER_DESC buffer_desc;
31639 ID3D11ShaderResourceView *srv;
31640 ID3D11DeviceContext *context;
31641 struct resource_readback rb;
31642 ID3D11Texture2D *texture;
31643 ID3D11PixelShader *ps;
31644 ID3D11Buffer *buffer;
31645 ID3D11Device *device;
31646 unsigned int i;
31647 HRESULT hr;
31649 static const DWORD ps_samplepos[] =
31651 #if 0
31652 Texture2DMS<float> t;
31653 RWByteAddressBuffer u;
31655 float4 main() : SV_Target
31657 u.Store2(0, asuint(t.GetSamplePosition(0)));
31658 u.Store2(8, asuint(t.GetSamplePosition(1)));
31659 u.Store2(16, asuint(t.GetSamplePosition(2)));
31660 u.Store2(24, asuint(t.GetSamplePosition(3)));
31661 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31663 #endif
31664 0x43425844, 0xa1db77e8, 0x804d8862, 0x0e3c213d, 0x2703dec6, 0x00000001, 0x00000190, 0x00000003,
31665 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31666 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31667 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000118, 0x00000050, 0x00000046,
31668 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
31669 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0800006e, 0x00100032, 0x00000000,
31670 0x00107046, 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x0800006e, 0x001000c2, 0x00000000,
31671 0x00107406, 0x00000000, 0x00004001, 0x00000001, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001,
31672 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
31673 0x00000000, 0x00004001, 0x00000002, 0x00000000, 0x0800006e, 0x001000c2, 0x00000000, 0x00107406,
31674 0x00000000, 0x00004001, 0x00000003, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001,
31675 0x00000010, 0x00100e46, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31676 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e
31678 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
31679 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
31680 static const unsigned int zero[4] = {0};
31681 static const float standard_pos4[] =
31683 -2 / 16.0f, -6 / 16.0f,
31684 6 / 16.0f, -2 / 16.0f,
31685 -6 / 16.0f, 2 / 16.0f,
31686 2 / 16.0f, 6 / 16.0f,
31689 swapchain_desc.windowed = TRUE;
31690 swapchain_desc.buffer_count = 1;
31691 swapchain_desc.width = 32;
31692 swapchain_desc.height = 32;
31693 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
31694 swapchain_desc.flags = 0;
31695 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
31696 return;
31697 device = test_context.device;
31698 context = test_context.immediate_context;
31700 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31701 texture_desc.SampleDesc.Count = 4;
31702 texture_desc.SampleDesc.Quality = D3D11_STANDARD_MULTISAMPLE_PATTERN;
31703 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
31704 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31705 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31706 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
31707 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
31709 buffer_desc.ByteWidth = 1024;
31710 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
31711 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
31712 buffer_desc.CPUAccessFlags = 0;
31713 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
31714 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
31715 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31716 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
31717 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
31718 U(uav_desc).Buffer.FirstElement = 0;
31719 U(uav_desc).Buffer.NumElements = 256;
31720 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
31721 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
31722 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
31724 hr = ID3D11Device_CreatePixelShader(device, ps_samplepos, sizeof(ps_samplepos), NULL, &ps);
31725 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31726 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31728 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
31729 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
31730 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
31731 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
31732 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31733 draw_quad(&test_context);
31734 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
31735 get_buffer_readback(buffer, &rb);
31736 for (i = 0; i < ARRAY_SIZE(standard_pos4); ++i)
31738 float data = get_readback_float(&rb, i, 0);
31739 /* Wine does not support GetSamplePosition. */
31740 todo_wine ok(data == standard_pos4[i], "Got sample position %.8e, expected %.8e.\n", data, standard_pos4[i]);
31742 release_resource_readback(&rb);
31744 ID3D11PixelShader_Release(ps);
31745 ID3D11Buffer_Release(buffer);
31746 ID3D11UnorderedAccessView_Release(uav);
31747 ID3D11ShaderResourceView_Release(srv);
31748 ID3D11Texture2D_Release(texture);
31749 release_test_context(&test_context);
31752 static void test_desktop_window(void)
31754 ID3D11RenderTargetView *backbuffer_rtv;
31755 DXGI_SWAP_CHAIN_DESC swapchain_desc;
31756 ID3D11DeviceContext *context;
31757 ID3D11Texture2D *backbuffer;
31758 IDXGISwapChain *swapchain;
31759 IDXGIDevice *dxgi_device;
31760 IDXGIAdapter *adapter;
31761 IDXGIFactory *factory;
31762 ID3D11Device *device;
31763 ULONG refcount;
31764 HRESULT hr;
31766 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
31768 if (!(device = create_device(NULL)))
31770 skip("Failed to create device.\n");
31771 return;
31774 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
31775 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
31776 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
31777 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
31778 IDXGIDevice_Release(dxgi_device);
31779 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
31780 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
31781 IDXGIAdapter_Release(adapter);
31783 swapchain_desc.BufferDesc.Width = 640;
31784 swapchain_desc.BufferDesc.Height = 480;
31785 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
31786 swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
31787 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31788 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
31789 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
31790 swapchain_desc.SampleDesc.Count = 1;
31791 swapchain_desc.SampleDesc.Quality = 0;
31792 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
31793 swapchain_desc.BufferCount = 1;
31794 swapchain_desc.OutputWindow = GetDesktopWindow();
31795 swapchain_desc.Windowed = TRUE;
31796 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
31797 swapchain_desc.Flags = 0;
31799 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
31800 ok(hr == S_OK || broken(hr == DXGI_ERROR_INVALID_CALL) /* Not available on all Windows versions. */,
31801 "Failed to create swapchain, hr %#x.\n", hr);
31802 IDXGIFactory_Release(factory);
31803 if (FAILED(hr))
31805 ID3D11Device_Release(device);
31806 return;
31809 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
31810 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
31812 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &backbuffer_rtv);
31813 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
31815 ID3D11Device_GetImmediateContext(device, &context);
31817 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
31818 check_texture_color(backbuffer, 0xff0000ff, 1);
31820 hr = IDXGISwapChain_Present(swapchain, 0, 0);
31821 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31823 ID3D11RenderTargetView_Release(backbuffer_rtv);
31824 ID3D11Texture2D_Release(backbuffer);
31825 IDXGISwapChain_Release(swapchain);
31826 ID3D11DeviceContext_Release(context);
31827 refcount = ID3D11Device_Release(device);
31828 ok(!refcount, "Device has %u references left.\n", refcount);
31831 static void test_sample_attached_rtv(void)
31833 ID3D11ShaderResourceView *srv, *srv2, *srv_test, *srv_ds;
31834 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc, srvds_desc;
31835 ID3D11Texture2D *texture, *texture2, *dstexture;
31836 ID3D11RenderTargetView *rtv, *rtv2, *rtvs[2];
31837 D3D11_DEPTH_STENCIL_VIEW_DESC dsview_desc;
31838 struct d3d11_test_context test_context;
31839 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
31840 D3D11_TEXTURE2D_DESC texture_desc;
31841 D3D_FEATURE_LEVEL feature_level;
31842 D3D11_SAMPLER_DESC sampler_desc;
31843 ID3D11DepthStencilView *dsview;
31844 ID3D11BlendState *blend_state;
31845 ID3D11DeviceContext *context;
31846 D3D11_BLEND_DESC blend_desc;
31847 ID3D11SamplerState *sampler;
31848 struct resource_readback rb;
31849 ID3D11PixelShader *ps;
31850 ID3D11Device *device;
31851 unsigned int x, y;
31852 unsigned int i;
31853 D3D11_BOX box;
31854 DWORD color;
31855 HRESULT hr;
31857 static const DWORD ps_ld_code[] =
31859 #if 0
31860 Texture2D t;
31862 struct PS_OUTPUT
31864 float4 color0: SV_Target0;
31865 float4 color1: SV_Target1;
31868 PS_OUTPUT main(float4 position : SV_POSITION)
31870 PS_OUTPUT output;
31871 float3 p;
31873 t.GetDimensions(0, p.x, p.y, p.z);
31874 p.z = 0;
31875 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
31876 output.color0 = output.color1 = t.Load(int3(p)) + float4(0.25, 0.25, 0.25, 0.25);
31877 return output;
31879 #endif
31880 0x43425844, 0x08dd0517, 0x07d7e538, 0x4cad261f, 0xa2ae5942, 0x00000001, 0x00000200, 0x00000003,
31881 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31882 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
31883 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
31884 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
31885 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000014c, 0x00000040, 0x00000053, 0x04001858,
31886 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
31887 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0700003d,
31888 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032,
31889 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000,
31890 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
31891 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0500001b,
31892 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46,
31893 0x00000000, 0x00107e46, 0x00000000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
31894 0x00004002, 0x3e800000, 0x3e800000, 0x3e800000, 0x3e800000, 0x05000036, 0x001020f2, 0x00000000,
31895 0x00100e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00100e46, 0x00000000, 0x0100003e,
31897 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
31898 static const struct
31900 DXGI_FORMAT texture_format, dsv_format, srv_format;
31901 UINT dsv_flags;
31902 BOOL srv_bind_allowed;
31904 ds_tests[] =
31906 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
31907 0, FALSE},
31908 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
31909 D3D11_DSV_READ_ONLY_DEPTH, TRUE},
31910 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_X24_TYPELESS_G8_UINT,
31911 D3D11_DSV_READ_ONLY_DEPTH, FALSE},
31912 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_X24_TYPELESS_G8_UINT,
31913 D3D11_DSV_READ_ONLY_STENCIL, TRUE},
31914 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT,
31915 0, FALSE},
31916 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT,
31917 D3D11_DSV_READ_ONLY_DEPTH, TRUE},
31920 if (!init_test_context(&test_context, NULL))
31921 return;
31923 device = test_context.device;
31924 context = test_context.immediate_context;
31926 feature_level = ID3D11Device_GetFeatureLevel(device);
31928 texture_desc.SampleDesc.Count = 1;
31929 texture_desc.SampleDesc.Quality = 0;
31930 texture_desc.Usage = D3D11_USAGE_DEFAULT;
31931 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
31932 texture_desc.CPUAccessFlags = 0;
31933 texture_desc.MiscFlags = 0;
31935 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
31936 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
31937 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
31938 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
31939 sampler_desc.MipLODBias = 0.0f;
31940 sampler_desc.MaxAnisotropy = 0;
31941 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
31942 sampler_desc.BorderColor[0] = 0.0f;
31943 sampler_desc.BorderColor[1] = 0.0f;
31944 sampler_desc.BorderColor[2] = 0.0f;
31945 sampler_desc.BorderColor[3] = 0.0f;
31946 sampler_desc.MinLOD = 0.0f;
31947 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
31949 hr = ID3D11Device_CreatePixelShader(device, ps_ld_code, sizeof(ps_ld_code), NULL, &ps);
31950 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31952 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31954 texture_desc.Width = 64;
31955 texture_desc.Height = 64;
31956 texture_desc.MipLevels = 2;
31957 texture_desc.ArraySize = 1;
31958 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31960 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31961 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31963 texture_desc.Width = 640;
31964 texture_desc.Height = 480;
31965 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture2);
31966 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31968 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
31969 sampler_desc.MipLODBias = 0.0f;
31970 sampler_desc.MinLOD = 0.0f;
31971 sampler_desc.MaxLOD = 0.0f;
31973 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
31974 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31976 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
31978 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
31980 memset(&rtv_desc, 0, sizeof(rtv_desc));
31981 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31982 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
31983 U(rtv_desc).Texture2D.MipSlice = 0;
31985 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv);
31986 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31987 U(rtv_desc).Texture2D.MipSlice = 1;
31988 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv2);
31989 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31991 rtvs[0] = test_context.backbuffer_rtv;
31992 rtvs[1] = rtv;
31994 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31996 memset(&srv_desc, 0, sizeof(srv_desc));
31997 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31998 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
31999 U(srv_desc).Texture2D.MipLevels = 1;
32001 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
32002 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32003 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
32005 draw_quad(&test_context);
32007 set_box(&box, 0, 0, 0, 320, 240, 1);
32008 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2, 1, 0, 0, 0, (ID3D11Resource *)texture2, 0, &box);
32010 get_texture_readback(texture2, 0, &rb);
32011 for (y = 0; y < 4; ++y)
32013 for (x = 0; x < 4; ++x)
32015 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
32016 ok(compare_color(color, 0x40404040, 2),
32017 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
32020 release_resource_readback(&rb);
32021 get_texture_readback(texture2, 1, &rb);
32022 for (y = 0; y < 4; ++y)
32024 for (x = 0; x < 4; ++x)
32026 color = get_readback_color(&rb, 40 + x * 80, 30 + y * 60, 0);
32027 ok(compare_color(color, 0x40404040, 2),
32028 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
32031 release_resource_readback(&rb);
32033 ID3D11ShaderResourceView_Release(srv);
32034 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
32036 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
32038 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv);
32039 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32041 U(srv_desc).Texture2D.MostDetailedMip = 1;
32042 U(srv_desc).Texture2D.MipLevels = 1;
32043 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv2);
32044 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32046 memset(&blend_desc, 0, sizeof(blend_desc));
32047 blend_desc.IndependentBlendEnable = TRUE;
32048 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
32049 blend_desc.RenderTarget[1].RenderTargetWriteMask = 0;
32050 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32051 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32052 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32053 ID3D11BlendState_Release(blend_state);
32055 /* SRV does not get bound if resource is attached as render target, even if write mask is 0. */
32056 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
32057 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32058 ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
32060 blend_desc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
32061 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32062 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32063 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32064 ID3D11BlendState_Release(blend_state);
32066 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
32068 draw_quad(&test_context);
32069 draw_quad(&test_context);
32071 get_texture_readback(test_context.backbuffer, 0, &rb);
32072 for (y = 0; y < 4; ++y)
32074 for (x = 0; x < 4; ++x)
32076 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
32077 ok(compare_color(color, 0x40404040, 2),
32078 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
32081 release_resource_readback(&rb);
32083 get_texture_readback(texture2, 0, &rb);
32084 for (y = 0; y < 4; ++y)
32086 for (x = 0; x < 4; ++x)
32088 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
32089 ok(compare_color(color, 0x40404040, 2),
32090 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
32093 release_resource_readback(&rb);
32095 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
32096 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
32097 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32098 ok(!!srv_test, "Unexpected SRV %p.\n", srv_test);
32099 ID3D11ShaderResourceView_Release(srv_test);
32101 draw_quad(&test_context);
32102 get_texture_readback(test_context.backbuffer, 0, &rb);
32103 for (y = 0; y < 4; ++y)
32105 for (x = 0; x < 4; ++x)
32107 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
32108 ok(compare_color(color, 0x80808080, 2),
32109 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
32112 release_resource_readback(&rb);
32114 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
32116 /* SRV is reset when the same resource is set as render target. */
32117 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32118 ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
32120 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
32121 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
32122 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32123 ok(!!srv_test, "Unexpected SRV %p.\n", srv_test);
32124 ID3D11ShaderResourceView_Release(srv_test);
32126 draw_quad(&test_context);
32127 get_texture_readback(test_context.backbuffer, 0, &rb);
32128 for (y = 0; y < 4; ++y)
32130 for (x = 0; x < 4; ++x)
32132 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
32133 ok(compare_color(color, 0x80808080, 2),
32134 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
32137 release_resource_readback(&rb);
32139 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
32140 memset(&dsview_desc, 0, sizeof(dsview_desc));
32141 dsview_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
32143 memset(&srvds_desc, 0, sizeof(srvds_desc));
32144 srvds_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
32145 U(srvds_desc).Texture2D.MipLevels = 1;
32147 for (i = 0; i < ARRAY_SIZE(ds_tests); ++i)
32149 if (ds_tests[i].dsv_flags && feature_level < D3D_FEATURE_LEVEL_11_0)
32151 static unsigned int skip_once;
32153 if (!skip_once++)
32154 skip("Read only depths or stencils are not supported.\n");
32156 continue;
32159 texture_desc.Format = ds_tests[i].texture_format;
32160 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &dstexture);
32161 ok(hr == S_OK, "Test %u, got unexpected hr %#x.\n", i, hr);
32162 dsview_desc.Format = ds_tests[i].dsv_format;
32163 dsview_desc.Flags = ds_tests[i].dsv_flags;
32164 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)dstexture, &dsview_desc, &dsview);
32165 ok(hr == S_OK, "Test %u, got unexpected hr %#x.\n", i, hr);
32167 srvds_desc.Format = ds_tests[i].srv_format;
32168 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dstexture, &srvds_desc, &srv_ds);
32169 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32171 ID3D11DeviceContext_OMSetRenderTargets(context, 1, rtvs, NULL);
32172 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_ds);
32173 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32174 ok(!!srv_test, "Test %u, unexpected SRV %p.\n", i, srv_test);
32175 ID3D11ShaderResourceView_Release(srv_test);
32177 ID3D11DeviceContext_OMSetRenderTargets(context, 1, rtvs, dsview);
32178 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32179 ok(!!srv_test == ds_tests[i].srv_bind_allowed, "Test %u, unexpected SRV %p.\n", i, srv_test);
32180 if (srv_test)
32181 ID3D11ShaderResourceView_Release(srv_test);
32183 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_ds);
32184 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
32185 ok(!!srv_test == ds_tests[i].srv_bind_allowed, "Test %u, unexpected SRV %p.\n", i, srv_test);
32186 if (srv_test)
32187 ID3D11ShaderResourceView_Release(srv_test);
32189 ID3D11Texture2D_Release(dstexture);
32190 ID3D11DepthStencilView_Release(dsview);
32191 ID3D11ShaderResourceView_Release(srv_ds);
32194 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
32196 ID3D11RenderTargetView_Release(rtv2);
32197 ID3D11RenderTargetView_Release(rtv);
32198 ID3D11ShaderResourceView_Release(srv2);
32199 ID3D11ShaderResourceView_Release(srv);
32200 ID3D11SamplerState_Release(sampler);
32201 ID3D11PixelShader_Release(ps);
32202 ID3D11Texture2D_Release(texture2);
32203 ID3D11Texture2D_Release(texture);
32204 ID3D11SamplerState_Release(sampler);
32206 release_test_context(&test_context);
32209 static void test_color_mask(void)
32211 struct d3d11_test_context test_context;
32212 D3D11_TEXTURE2D_DESC texture_desc;
32213 ID3D11RenderTargetView *rtvs[8];
32214 ID3D11BlendState *blend_state;
32215 ID3D11DeviceContext *context;
32216 struct resource_readback rb;
32217 D3D11_BLEND_DESC blend_desc;
32218 ID3D11Texture2D *rts[8];
32219 ID3D11PixelShader *ps;
32220 ID3D11Device *device;
32221 unsigned int i;
32222 DWORD color;
32223 HRESULT hr;
32225 static const DWORD expected_colors[] =
32226 {0xff000080, 0xff0080ff, 0xff8000ff, 0x80808080, 0x800000ff, 0xff008080, 0x800080ff, 0xff0000ff};
32228 static const DWORD ps_code[] =
32230 #if 0
32231 void main(float4 position : SV_Position,
32232 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
32233 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
32234 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
32235 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
32237 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.5f, 0.5f, 0.5f, 0.5f);
32239 #endif
32240 0x43425844, 0x7b1ab233, 0xdbe32d3b, 0x77084cc5, 0xe874d2b5, 0x00000001, 0x000002b0, 0x00000003,
32241 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
32242 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
32243 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
32244 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
32245 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
32246 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
32247 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
32248 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
32249 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
32250 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
32251 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
32252 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
32253 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000,
32254 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000,
32255 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3f000000,
32256 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3f000000,
32257 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3f000000,
32258 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3f000000,
32259 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3f000000,
32260 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3f000000,
32261 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
32264 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
32266 if (!init_test_context(&test_context, NULL))
32267 return;
32269 device = test_context.device;
32270 context = test_context.immediate_context;
32272 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
32273 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
32274 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32276 memset(&blend_desc, 0, sizeof(blend_desc));
32277 blend_desc.IndependentBlendEnable = TRUE;
32278 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED;
32279 blend_desc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN;
32280 blend_desc.RenderTarget[2].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_BLUE;
32281 blend_desc.RenderTarget[3].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
32282 blend_desc.RenderTarget[4].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALPHA;
32283 blend_desc.RenderTarget[5].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED | D3D11_COLOR_WRITE_ENABLE_GREEN;
32284 blend_desc.RenderTarget[6].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN | D3D11_COLOR_WRITE_ENABLE_ALPHA;
32285 blend_desc.RenderTarget[7].RenderTargetWriteMask = 0;
32287 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32288 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32289 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32290 ID3D11BlendState_Release(blend_state);
32292 for (i = 0; i < 8; ++i)
32294 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32295 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
32296 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
32298 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
32299 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
32302 ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
32304 for (i = 0; i < 8; ++i)
32305 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], red);
32306 draw_quad(&test_context);
32308 for (i = 0; i < 8; ++i)
32310 get_texture_readback(rts[i], 0, &rb);
32311 color = get_readback_color(&rb, 320, 240, 0);
32312 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32313 release_resource_readback(&rb);
32316 blend_desc.IndependentBlendEnable = FALSE;
32317 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32318 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32319 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32320 ID3D11BlendState_Release(blend_state);
32322 for (i = 0; i < 8; ++i)
32323 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], red);
32324 draw_quad(&test_context);
32326 for (i = 0; i < 8; ++i)
32328 get_texture_readback(rts[i], 0, &rb);
32329 color = get_readback_color(&rb, 320, 240, 0);
32330 ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32331 release_resource_readback(&rb);
32333 ID3D11Texture2D_Release(rts[i]);
32334 ID3D11RenderTargetView_Release(rtvs[i]);
32337 ID3D11PixelShader_Release(ps);
32338 release_test_context(&test_context);
32341 static void test_independent_blend(void)
32343 struct d3d11_test_context test_context;
32344 D3D11_TEXTURE2D_DESC texture_desc;
32345 ID3D11RenderTargetView *rtvs[8];
32346 ID3D11BlendState *blend_state;
32347 ID3D11DeviceContext *context;
32348 struct resource_readback rb;
32349 ID3D11Texture2D *rts[8];
32350 ID3D11PixelShader *ps;
32351 ID3D11Device *device;
32352 unsigned int i;
32353 DWORD color;
32354 HRESULT hr;
32356 static const DWORD ps_code[] =
32358 #if 0
32359 void main(float4 position : SV_Position,
32360 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
32361 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
32362 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
32363 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
32365 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.1f, 0.2f, 0.3f, 0.4f);
32367 #endif
32368 0x43425844, 0xb3dca7dc, 0x4a31f0f1, 0x747569cb, 0xae7af5ce, 0x00000001, 0x000002b0, 0x00000003,
32369 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
32370 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
32371 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
32372 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
32373 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
32374 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
32375 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
32376 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
32377 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
32378 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
32379 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
32380 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
32381 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3dcccccd,
32382 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3dcccccd,
32383 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3dcccccd,
32384 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3dcccccd,
32385 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3dcccccd,
32386 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3dcccccd,
32387 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3dcccccd,
32388 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3dcccccd,
32389 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x0100003e,
32392 D3D11_BLEND_DESC blend_desc =
32394 .IndependentBlendEnable = TRUE,
32395 .RenderTarget =
32397 {TRUE, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD,
32398 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32399 {TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
32400 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32401 {TRUE, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_OP_ADD,
32402 D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32403 {TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
32404 D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN, D3D11_COLOR_WRITE_ENABLE_ALL},
32405 {TRUE, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_OP_ADD,
32406 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32407 {TRUE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_BLEND_FACTOR, D3D11_BLEND_OP_SUBTRACT,
32408 D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_REV_SUBTRACT, D3D11_COLOR_WRITE_ENABLE_ALL},
32409 {FALSE, 0, 0, 0, 0, 0, 0, D3D11_COLOR_WRITE_ENABLE_ALL},
32410 {TRUE, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_OP_ADD,
32411 D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_DEST_ALPHA, D3D11_BLEND_OP_SUBTRACT,
32412 D3D11_COLOR_WRITE_ENABLE_ALL},
32416 static const DWORD expected_colors[] =
32417 {0x66426e1c, 0xb34c3319, 0xa6214a05, 0x66333319, 0xb34c4829, 0x4d19000a, 0x664c3319, 0x081f3305};
32419 static const float clear_color[] = {0.1f, 0.5f, 0.2f, 0.7f};
32420 static const float blend_factor[] = {0.8f, 0.4f, 0.6f, 0.2f};
32422 if (!init_test_context(&test_context, NULL))
32423 return;
32425 device = test_context.device;
32426 context = test_context.immediate_context;
32428 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
32429 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
32430 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32432 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32433 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32434 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
32435 ID3D11BlendState_Release(blend_state);
32437 for (i = 0; i < 8; ++i)
32439 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32440 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
32441 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
32443 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
32444 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
32447 ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
32449 for (i = 0; i < 8; ++i)
32450 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
32451 draw_quad(&test_context);
32453 for (i = 0; i < 8; ++i)
32455 get_texture_readback(rts[i], 0, &rb);
32456 color = get_readback_color(&rb, 320, 240, 0);
32457 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32458 release_resource_readback(&rb);
32461 blend_desc.IndependentBlendEnable = FALSE;
32462 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32463 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32464 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
32465 ID3D11BlendState_Release(blend_state);
32467 for (i = 0; i < 8; ++i)
32468 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
32469 draw_quad(&test_context);
32471 for (i = 0; i < 8; ++i)
32473 get_texture_readback(rts[i], 0, &rb);
32474 color = get_readback_color(&rb, 320, 240, 0);
32475 ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32476 release_resource_readback(&rb);
32478 ID3D11Texture2D_Release(rts[i]);
32479 ID3D11RenderTargetView_Release(rtvs[i]);
32482 ID3D11PixelShader_Release(ps);
32483 release_test_context(&test_context);
32486 static void test_dual_source_blend(void)
32488 struct d3d11_test_context test_context;
32489 ID3D11BlendState *blend_state;
32490 ID3D11DeviceContext *context;
32491 ID3D11PixelShader *ps;
32492 ID3D11Device *device;
32493 DWORD color;
32494 HRESULT hr;
32496 static const DWORD ps_code[] =
32498 #if 0
32499 void main(float4 position : SV_Position,
32500 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1)
32502 t0 = float4(0.5, 0.5, 0.0, 1.0);
32503 t1 = float4(0.0, 0.5, 0.5, 0.0);
32505 #endif
32506 0x43425844, 0x87120d01, 0xa0014738, 0x3a32d86c, 0x9d757441, 0x00000001, 0x00000118, 0x00000003,
32507 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
32508 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
32509 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
32510 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
32511 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03000065,
32512 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x08000036, 0x001020f2, 0x00000000,
32513 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001,
32514 0x00004002, 0x00000000, 0x3f000000, 0x3f000000, 0x00000000, 0x0100003e
32517 static const D3D11_BLEND_DESC blend_desc =
32519 .RenderTarget[0].BlendEnable = TRUE,
32520 .RenderTarget[0].SrcBlend = D3D11_BLEND_SRC1_COLOR,
32521 .RenderTarget[0].DestBlend = D3D11_BLEND_SRC1_COLOR,
32522 .RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD,
32523 .RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE,
32524 .RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO,
32525 .RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD,
32526 .RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL,
32529 static const float clear_color[] = {0.7f, 0.0f, 1.0f, 1.0f};
32531 if (!init_test_context(&test_context, NULL))
32532 return;
32534 device = test_context.device;
32535 context = test_context.immediate_context;
32537 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
32538 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
32539 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32541 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32542 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32543 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32544 ID3D11BlendState_Release(blend_state);
32546 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, clear_color);
32547 draw_quad(&test_context);
32549 color = get_texture_color(test_context.backbuffer, 320, 240);
32550 ok(compare_color(color, 0x80804000, 1), "Got unexpected color 0x%08x.\n", color);
32552 ID3D11PixelShader_Release(ps);
32553 release_test_context(&test_context);
32556 static void test_deferred_context_state(void)
32558 ID3D11Buffer *green_buffer, *blue_buffer, *ret_buffer;
32559 ID3D11DeviceContext *immediate, *deferred, *deferred2;
32560 ID3D11ShaderResourceView *srv, *ret_srv;
32561 struct d3d11_test_context test_context;
32562 ID3D11RenderTargetView *rtv, *ret_rtv;
32563 D3D11_TEXTURE2D_DESC texture_desc;
32564 ID3D11CommandList *list1, *list2;
32565 ID3D11Texture2D *texture;
32566 ID3D11Device *device;
32567 HRESULT hr;
32569 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32570 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
32572 if (!init_test_context(&test_context, NULL))
32573 return;
32575 device = test_context.device;
32576 immediate = test_context.immediate_context;
32578 green_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(green), &green);
32579 blue_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(blue), &blue);
32580 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32582 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32583 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32585 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32586 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32588 ID3D11DeviceContext_PSSetConstantBuffers(deferred, 0, 1, &blue_buffer);
32590 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32591 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32592 ID3D11Buffer_Release(ret_buffer);
32594 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32595 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32597 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32598 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32599 ID3D11Buffer_Release(ret_buffer);
32601 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list2);
32602 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32604 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32605 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32607 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32608 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32609 ID3D11DeviceContext_PSGetConstantBuffers(immediate, 0, 1, &ret_buffer);
32610 ok(ret_buffer == green_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32611 ID3D11Buffer_Release(ret_buffer);
32613 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32614 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
32615 ID3D11DeviceContext_PSGetConstantBuffers(immediate, 0, 1, &ret_buffer);
32616 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32618 ID3D11CommandList_Release(list2);
32619 ID3D11CommandList_Release(list1);
32621 /* Test recording a command list into another deferred context. */
32623 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred2);
32624 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32626 ID3D11DeviceContext_PSSetConstantBuffers(deferred2, 0, 1, &green_buffer);
32628 hr = ID3D11DeviceContext_FinishCommandList(deferred2, FALSE, &list1);
32629 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32631 ID3D11DeviceContext_PSSetConstantBuffers(deferred, 0, 1, &blue_buffer);
32632 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, TRUE);
32633 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32634 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32635 ID3D11Buffer_Release(ret_buffer);
32637 ID3D11DeviceContext_PSSetConstantBuffers(deferred, 0, 1, &blue_buffer);
32638 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, FALSE);
32639 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32640 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32642 ID3D11CommandList_Release(list1);
32643 ID3D11DeviceContext_Release(deferred2);
32645 /* Test unbinding an SRV when using the same resource as RTV. */
32647 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32648 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
32649 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
32650 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
32651 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
32652 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32653 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
32654 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32656 ID3D11DeviceContext_PSSetShaderResources(deferred, 0, 1, &srv);
32657 ID3D11DeviceContext_PSGetShaderResources(deferred, 0, 1, &ret_srv);
32658 ok(ret_srv == srv, "Got unexpected SRV %p.\n", ret_srv);
32659 ID3D11ShaderResourceView_Release(ret_srv);
32661 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &rtv, NULL);
32662 ID3D11DeviceContext_OMGetRenderTargets(deferred, 1, &ret_rtv, NULL);
32663 ok(ret_rtv == rtv, "Got unexpected RTV %p.\n", ret_rtv);
32664 ID3D11RenderTargetView_Release(ret_rtv);
32665 ID3D11DeviceContext_PSGetShaderResources(deferred, 0, 1, &ret_srv);
32666 ok(!ret_srv, "Got unexpected SRV %p.\n", ret_srv);
32668 ID3D11DeviceContext_PSSetShaderResources(deferred, 0, 1, &srv);
32669 ID3D11DeviceContext_PSGetShaderResources(deferred, 0, 1, &ret_srv);
32670 ok(!ret_srv, "Got unexpected SRV %p.\n", ret_srv);
32672 ID3D11DeviceContext_PSSetShaderResources(immediate, 0, 1, &srv);
32673 ID3D11DeviceContext_PSGetShaderResources(immediate, 0, 1, &ret_srv);
32674 ok(ret_srv == srv, "Got unexpected SRV %p.\n", ret_srv);
32675 ID3D11ShaderResourceView_Release(ret_srv);
32677 ID3D11ShaderResourceView_Release(srv);
32678 ID3D11RenderTargetView_Release(rtv);
32679 ID3D11Texture2D_Release(texture);
32680 ID3D11DeviceContext_Release(deferred);
32681 ID3D11Buffer_Release(blue_buffer);
32682 ID3D11Buffer_Release(green_buffer);
32683 release_test_context(&test_context);
32686 static void test_deferred_context_swap_state(void)
32688 ID3D11DeviceContext1 *immediate, *deferred;
32689 ID3DDeviceContextState *state, *prev_state;
32690 ID3D11Buffer *green_buffer, *ret_buffer;
32691 struct d3d11_test_context test_context;
32692 D3D_FEATURE_LEVEL feature_level;
32693 ID3D11Device1 *device;
32694 HRESULT hr;
32696 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32698 if (!init_test_context(&test_context, NULL))
32699 return;
32701 if (FAILED(ID3D11Device_QueryInterface(test_context.device, &IID_ID3D11Device1, (void **)&device)))
32703 skip("ID3D11Device1 is not available.\n");
32704 release_test_context(&test_context);
32705 return;
32708 ID3D11Device1_GetImmediateContext1(device, &immediate);
32710 green_buffer = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(green), &green);
32711 ID3D11DeviceContext1_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32713 hr = ID3D11Device1_CreateDeferredContext1(device, 0, &deferred);
32714 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32716 feature_level = ID3D11Device1_GetFeatureLevel(device);
32717 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
32718 &IID_ID3D11Device1, NULL, &state);
32719 ok(hr == S_OK, "Failed to create device context state, hr %#x.\n", hr);
32721 prev_state = (void *)0xdeadbeef;
32722 ID3D11DeviceContext1_SwapDeviceContextState(deferred, NULL, &prev_state);
32723 ok(!prev_state, "Got state %p.\n", prev_state);
32725 prev_state = (void *)0xdeadbeef;
32726 ID3D11DeviceContext1_SwapDeviceContextState(deferred, state, &prev_state);
32727 ok(!prev_state, "Got state %p.\n", prev_state);
32729 ID3D11DeviceContext1_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32730 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32732 ID3DDeviceContextState_Release(state);
32733 ID3D11DeviceContext1_Release(deferred);
32735 ID3D11Buffer_Release(green_buffer);
32736 ID3D11DeviceContext1_Release(immediate);
32737 ID3D11Device1_Release(device);
32738 release_test_context(&test_context);
32741 static void test_deferred_context_rendering(void)
32743 ID3D11BlendState *red_blend, *green_blend, *blue_blend, *ret_blend;
32744 ID3D11DeviceContext *immediate, *deferred, *deferred2;
32745 struct d3d11_test_context test_context;
32746 D3D11_TEXTURE2D_DESC texture_desc;
32747 ID3D11CommandList *list1, *list2;
32748 ID3D11RenderTargetView *rtv;
32749 D3D11_BLEND_DESC blend_desc;
32750 ID3D11Texture2D *texture;
32751 float blend_factor[4];
32752 ID3D11Device *device;
32753 UINT sample_mask;
32754 DWORD color;
32755 HRESULT hr;
32757 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
32758 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32759 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
32760 static const float black[] = {0.0f, 0.0f, 0.0f, 1.0f};
32762 if (!init_test_context(&test_context, NULL))
32763 return;
32765 device = test_context.device;
32766 immediate = test_context.immediate_context;
32768 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32769 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32771 memset(&blend_desc, 0, sizeof(blend_desc));
32773 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED;
32774 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &red_blend);
32775 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32776 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN;
32777 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &green_blend);
32778 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32779 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_BLUE;
32780 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blue_blend);
32781 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32783 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32785 ID3D11DeviceContext_ClearRenderTargetView(deferred, test_context.backbuffer_rtv, green);
32787 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32788 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32790 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32791 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32793 color = get_texture_color(test_context.backbuffer, 320, 240);
32794 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32796 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32797 color = get_texture_color(test_context.backbuffer, 320, 240);
32798 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32800 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32801 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32802 color = get_texture_color(test_context.backbuffer, 320, 240);
32803 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32805 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32806 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, TRUE);
32807 color = get_texture_color(test_context.backbuffer, 320, 240);
32808 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32810 ID3D11CommandList_Release(list2);
32812 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, TRUE);
32813 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32814 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32816 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32817 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, TRUE);
32818 color = get_texture_color(test_context.backbuffer, 320, 240);
32819 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32821 ID3D11CommandList_Release(list2);
32822 ID3D11CommandList_Release(list1);
32823 ID3D11DeviceContext_Release(deferred);
32825 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32826 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
32827 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
32828 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
32829 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32831 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32832 ID3D11DeviceContext_ClearRenderTargetView(immediate, rtv, green);
32834 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32835 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32837 ID3D11DeviceContext_CopyResource(deferred, (ID3D11Resource *)test_context.backbuffer, (ID3D11Resource *)texture);
32839 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32840 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32842 ID3D11DeviceContext_ClearRenderTargetView(immediate, rtv, blue);
32843 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32844 color = get_texture_color(test_context.backbuffer, 320, 240);
32845 ok(color == 0xffff0000, "Got unexpected color %#08x.\n", color);
32847 ID3D11CommandList_Release(list1);
32848 ID3D11DeviceContext_Release(deferred);
32850 /* As Get* calls imply, state changes recorded into a command list do not
32851 * affect subsequent draws after the state is restored or cleared. */
32853 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32854 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32856 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32858 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32859 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32861 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32862 ID3D11DeviceContext_OMSetBlendState(immediate, blue_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32863 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32864 draw_color_quad(&test_context, &white);
32865 color = get_texture_color(test_context.backbuffer, 320, 240);
32866 ok(color == 0xffff0000, "Got unexpected color %#08x.\n", color);
32868 ID3D11DeviceContext_OMGetBlendState(immediate, &ret_blend, blend_factor, &sample_mask);
32869 ok(ret_blend == blue_blend, "Got unexpected blend state %p.\n", ret_blend);
32870 ID3D11BlendState_Release(ret_blend);
32872 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32873 ID3D11DeviceContext_OMSetBlendState(immediate, blue_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32874 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
32875 ID3D11DeviceContext_OMSetRenderTargets(immediate, 1, &test_context.backbuffer_rtv, NULL);
32876 set_viewport(immediate, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
32877 draw_color_quad(&test_context, &white);
32878 color = get_texture_color(test_context.backbuffer, 320, 240);
32879 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32881 ID3D11DeviceContext_OMGetBlendState(immediate, &ret_blend, blend_factor, &sample_mask);
32882 ok(!ret_blend, "Got unexpected blend state %p.\n", ret_blend);
32884 ID3D11CommandList_Release(list1);
32885 ID3D11DeviceContext_Release(deferred);
32887 /* The clearing of state done by FinishCommandList is captured by a
32888 * subsequent call to FinishCommandList... */
32890 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32891 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32893 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32894 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list1);
32895 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32896 ID3D11CommandList_Release(list1);
32898 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
32899 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
32900 test_context.immediate_context = deferred;
32901 draw_color_quad(&test_context, &white);
32902 test_context.immediate_context = immediate;
32903 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32904 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32906 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32907 ID3D11DeviceContext_OMSetBlendState(immediate, red_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32908 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
32909 color = get_texture_color(test_context.backbuffer, 320, 240);
32910 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32912 ID3D11CommandList_Release(list1);
32914 /* ...and so is the save/restore. */
32916 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32917 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32918 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32919 ID3D11CommandList_Release(list1);
32921 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
32922 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
32923 test_context.immediate_context = deferred;
32924 draw_color_quad(&test_context, &white);
32925 test_context.immediate_context = immediate;
32926 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32927 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32929 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32930 ID3D11DeviceContext_OMSetBlendState(immediate, red_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32931 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
32932 color = get_texture_color(test_context.backbuffer, 320, 240);
32933 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32935 ID3D11CommandList_Release(list1);
32937 ID3D11DeviceContext_Release(deferred);
32939 /* Similarly, clearing of state done by ExecuteCommandList is captured by a
32940 * subsequent call to FinishCommandList. */
32942 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32943 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32944 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred2);
32945 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32947 ID3D11DeviceContext_OMSetBlendState(deferred2, blue_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32949 hr = ID3D11DeviceContext_FinishCommandList(deferred2, FALSE, &list1);
32950 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32952 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32953 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, FALSE);
32954 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
32955 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
32956 test_context.immediate_context = deferred;
32957 draw_color_quad(&test_context, &white);
32958 test_context.immediate_context = immediate;
32959 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32960 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32962 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32963 ID3D11DeviceContext_OMSetBlendState(immediate, red_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32964 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, FALSE);
32965 color = get_texture_color(test_context.backbuffer, 320, 240);
32966 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32968 ID3D11CommandList_Release(list2);
32970 /* Make sure that save/restore is handled correctly as well. */
32972 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32973 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, TRUE);
32974 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
32975 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
32976 test_context.immediate_context = deferred;
32977 draw_color_quad(&test_context, &white);
32978 test_context.immediate_context = immediate;
32979 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32980 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32982 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32983 ID3D11DeviceContext_OMSetBlendState(immediate, red_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32984 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, FALSE);
32985 color = get_texture_color(test_context.backbuffer, 320, 240);
32986 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32988 ID3D11CommandList_Release(list2);
32990 ID3D11CommandList_Release(list1);
32991 ID3D11DeviceContext_Release(deferred2);
32992 ID3D11DeviceContext_Release(deferred);
32994 ID3D11BlendState_Release(red_blend);
32995 ID3D11BlendState_Release(green_blend);
32996 ID3D11BlendState_Release(blue_blend);
32997 ID3D11RenderTargetView_Release(rtv);
32998 ID3D11Texture2D_Release(texture);
32999 release_test_context(&test_context);
33002 static void test_deferred_context_map(void)
33004 ID3D11DeviceContext *immediate, *deferred;
33005 struct d3d11_test_context test_context;
33006 D3D11_SUBRESOURCE_DATA resource_data;
33007 D3D11_BUFFER_DESC buffer_desc = {0};
33008 D3D11_MAPPED_SUBRESOURCE map_desc;
33009 ID3D11Buffer *buffer, *buffer2;
33010 struct resource_readback rb;
33011 ID3D11CommandList *list;
33012 float data[16], value;
33013 ID3D11Device *device;
33014 float *map_data;
33015 unsigned int i;
33016 HRESULT hr;
33018 if (!init_test_context(&test_context, NULL))
33019 return;
33021 device = test_context.device;
33022 immediate = test_context.immediate_context;
33024 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
33025 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
33027 for (i = 0; i < ARRAY_SIZE(data); ++i)
33028 data[i] = i;
33029 resource_data.pSysMem = data;
33030 resource_data.SysMemPitch = 0;
33031 resource_data.SysMemSlicePitch = 0;
33033 buffer_desc.ByteWidth = sizeof(data);
33034 buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
33035 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
33036 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
33037 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
33038 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
33039 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer2);
33040 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
33042 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &map_desc);
33043 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
33045 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
33046 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
33048 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &map_desc);
33049 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
33051 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
33052 todo_wine ok(hr == D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, "Got unexpected hr %#x.\n", hr);
33054 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33055 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33056 if (hr != S_OK)
33058 ID3D11Buffer_Release(buffer2);
33059 ID3D11Buffer_Release(buffer);
33060 ID3D11DeviceContext_Release(deferred);
33061 release_test_context(&test_context);
33062 return;
33064 map_data = map_desc.pData;
33065 /* The previous contents of map_data are undefined and may in practice be
33066 * uninitialized garbage. */
33067 for (i = 0; i < ARRAY_SIZE(data); ++i)
33068 map_data[i] = 2 * i;
33070 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33072 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33073 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33074 map_data = map_desc.pData;
33075 for (i = 0; i < ARRAY_SIZE(data); ++i)
33076 map_data[i] = 3 * i;
33077 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33079 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
33080 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33082 get_buffer_readback(buffer, &rb);
33083 for (i = 0; i < ARRAY_SIZE(data); ++i)
33085 value = get_readback_float(&rb, i, 0);
33086 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
33088 release_resource_readback(&rb);
33090 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
33092 get_buffer_readback(buffer, &rb);
33093 for (i = 0; i < ARRAY_SIZE(data); ++i)
33095 value = get_readback_float(&rb, i, 0);
33096 ok(value == 3 * i, "Got unexpected value %.8e at %u.\n", value, i);
33098 release_resource_readback(&rb);
33100 ID3D11CommandList_Release(list);
33102 /* Test WRITE_NO_OVERWRITE. */
33104 hr = ID3D11DeviceContext_Map(immediate, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33105 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33106 map_data = map_desc.pData;
33107 for (i = 0; i < ARRAY_SIZE(data); ++i)
33108 map_data[i] = i;
33109 ID3D11DeviceContext_Unmap(immediate, (ID3D11Resource *)buffer, 0);
33111 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
33112 ok(hr == D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, "Got unexpected hr %#x.\n", hr);
33114 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33115 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33116 map_data = map_desc.pData;
33117 for (i = 0; i < ARRAY_SIZE(data); ++i)
33118 map_data[i] = 2 * i;
33119 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33121 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &map_desc);
33122 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
33124 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
33125 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
33127 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &map_desc);
33128 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
33130 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
33131 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33133 map_data = map_desc.pData;
33134 for (i = 0; i < ARRAY_SIZE(data); ++i)
33136 ok(map_data[i] == 2 * i, "Got unexpected value %.8e at %u.\n", map_data[i], i);
33137 if (i % 2)
33138 map_data[i] = 3 * i;
33140 memcpy(data, map_data, sizeof(data));
33142 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33144 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
33145 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33147 map_data = map_desc.pData;
33148 for (i = 0; i < ARRAY_SIZE(data); ++i)
33150 ok(map_data[i] == data[i], "Got unexpected value %.8e at %u.\n", map_data[i], i);
33151 if (i % 3)
33152 map_data[i] = 4 * i;
33154 memcpy(data, map_data, sizeof(data));
33156 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33158 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
33159 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33161 get_buffer_readback(buffer, &rb);
33162 for (i = 0; i < ARRAY_SIZE(data); ++i)
33164 value = get_readback_float(&rb, i, 0);
33165 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
33167 release_resource_readback(&rb);
33169 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
33171 get_buffer_readback(buffer, &rb);
33172 for (i = 0; i < ARRAY_SIZE(data); ++i)
33174 value = get_readback_float(&rb, i, 0);
33175 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
33177 release_resource_readback(&rb);
33179 ID3D11CommandList_Release(list);
33181 /* Do something with the mapped data from within the deferred context. */
33183 hr = ID3D11DeviceContext_Map(immediate, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33184 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33185 map_data = map_desc.pData;
33186 for (i = 0; i < ARRAY_SIZE(data); ++i)
33187 map_data[i] = i;
33188 ID3D11DeviceContext_Unmap(immediate, (ID3D11Resource *)buffer, 0);
33190 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33191 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33192 map_data = map_desc.pData;
33193 for (i = 0; i < ARRAY_SIZE(data); ++i)
33194 map_data[i] = 2 * i;
33195 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33197 ID3D11DeviceContext_CopyResource(deferred, (ID3D11Resource *)buffer2, (ID3D11Resource *)buffer);
33199 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
33200 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33201 map_data = map_desc.pData;
33202 for (i = 0; i < ARRAY_SIZE(data); ++i)
33203 map_data[i] = 3 * i;
33204 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
33206 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
33207 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33209 get_buffer_readback(buffer, &rb);
33210 for (i = 0; i < ARRAY_SIZE(data); ++i)
33212 value = get_readback_float(&rb, i, 0);
33213 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
33215 release_resource_readback(&rb);
33217 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
33219 get_buffer_readback(buffer2, &rb);
33220 for (i = 0; i < ARRAY_SIZE(data); ++i)
33222 value = get_readback_float(&rb, i, 0);
33223 ok(value == 2 * i, "Got unexpected value %.8e at %u.\n", value, i);
33225 release_resource_readback(&rb);
33227 get_buffer_readback(buffer, &rb);
33228 for (i = 0; i < ARRAY_SIZE(data); ++i)
33230 value = get_readback_float(&rb, i, 0);
33231 ok(value == 3 * i, "Got unexpected value %.8e at %u.\n", value, i);
33233 release_resource_readback(&rb);
33235 ID3D11CommandList_Release(list);
33237 ID3D11Buffer_Release(buffer2);
33238 ID3D11Buffer_Release(buffer);
33240 /* Test UpdateSubresource. */
33242 for (i = 0; i < ARRAY_SIZE(data); ++i)
33243 data[i] = i;
33245 buffer_desc.ByteWidth = sizeof(data);
33246 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
33247 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
33248 buffer_desc.CPUAccessFlags = 0;
33249 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
33250 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
33251 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer2);
33252 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
33254 for (i = 0; i < ARRAY_SIZE(data); ++i)
33255 data[i] = 2 * i;
33256 ID3D11DeviceContext_UpdateSubresource(deferred, (ID3D11Resource *)buffer, 0, NULL, data, 0, 0);
33258 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
33259 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
33261 get_buffer_readback(buffer, &rb);
33262 for (i = 0; i < ARRAY_SIZE(data); ++i)
33264 value = get_readback_float(&rb, i, 0);
33265 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
33267 release_resource_readback(&rb);
33269 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
33271 get_buffer_readback(buffer, &rb);
33272 for (i = 0; i < ARRAY_SIZE(data); ++i)
33274 value = get_readback_float(&rb, i, 0);
33275 ok(value == 2 * i, "Got unexpected value %.8e at %u.\n", value, i);
33277 release_resource_readback(&rb);
33279 ID3D11CommandList_Release(list);
33281 ID3D11Buffer_Release(buffer2);
33282 ID3D11Buffer_Release(buffer);
33284 ID3D11DeviceContext_Release(deferred);
33285 release_test_context(&test_context);
33288 static void test_texture_compressed_3d(void)
33290 struct d3d11_test_context test_context;
33291 D3D11_SUBRESOURCE_DATA resource_data;
33292 D3D11_TEXTURE3D_DESC texture_desc;
33293 ID3D11SamplerState *sampler_state;
33294 unsigned int idx, r0, r1, x, y, z;
33295 D3D11_SAMPLER_DESC sampler_desc;
33296 ID3D11ShaderResourceView *srv;
33297 ID3D11DeviceContext *context;
33298 struct resource_readback rb;
33299 ID3D11Texture3D *texture;
33300 DWORD colour, expected;
33301 ID3D11PixelShader *ps;
33302 ID3D11Device *device;
33303 DWORD *texture_data;
33304 BOOL equal = TRUE;
33305 HRESULT hr;
33307 static const DWORD ps_code[] =
33309 #if 0
33310 Texture3D t;
33311 SamplerState s;
33313 float4 main(float4 position : SV_POSITION) : SV_Target
33315 return t.Sample(s, position.xyz / float3(640, 480, 1));
33317 #endif
33318 0x43425844, 0x27b15ae8, 0xbebf46f7, 0x6cd88d8d, 0x5118de51, 0x00000001, 0x00000134, 0x00000003,
33319 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
33320 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000070f, 0x505f5653, 0x5449534f, 0x004e4f49,
33321 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
33322 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
33323 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
33324 0x04002064, 0x00101072, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
33325 0x00000001, 0x0a000038, 0x00100072, 0x00000000, 0x00101246, 0x00000000, 0x00004002, 0x3acccccd,
33326 0x3b088889, 0x3f800000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
33327 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
33330 static const unsigned int block_indices[] =
33332 0, 1, 3, 2,
33333 6, 7, 5, 4,
33334 0, 1, 3, 2,
33335 6, 7, 5, 4,
33338 if (!init_test_context(&test_context, NULL))
33339 return;
33340 device = test_context.device;
33341 context = test_context.immediate_context;
33343 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
33344 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33346 /* Simply test all combinations of r0 and r1. */
33347 texture_data = heap_alloc(256 * 256 * sizeof(UINT64));
33348 for (r1 = 0; r1 < 256; ++r1)
33350 for (r0 = 0; r0 < 256; ++r0)
33352 /* bits = block_indices[] */
33353 texture_data[(r1 * 256 + r0) * 2 + 0] = 0xe4c80000 | (r1 << 8) | r0;
33354 texture_data[(r1 * 256 + r0) * 2 + 1] = 0x97e4c897;
33357 resource_data.pSysMem = texture_data;
33358 resource_data.SysMemPitch = 64 * sizeof(UINT64);
33359 resource_data.SysMemSlicePitch = 64 * resource_data.SysMemPitch;
33361 texture_desc.Width = 256;
33362 texture_desc.Height = 256;
33363 texture_desc.Depth = 16;
33364 texture_desc.MipLevels = 1;
33365 texture_desc.Format = DXGI_FORMAT_BC4_UNORM;
33366 texture_desc.Usage = D3D11_USAGE_DEFAULT;
33367 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
33368 texture_desc.CPUAccessFlags = 0;
33369 texture_desc.MiscFlags = 0;
33370 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, &resource_data, &texture);
33371 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33372 heap_free(texture_data);
33374 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
33375 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33377 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
33378 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
33379 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
33380 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
33381 sampler_desc.MipLODBias = 0.0f;
33382 sampler_desc.MaxAnisotropy = 0;
33383 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
33384 sampler_desc.BorderColor[0] = 0.0f;
33385 sampler_desc.BorderColor[1] = 0.0f;
33386 sampler_desc.BorderColor[2] = 0.0f;
33387 sampler_desc.BorderColor[3] = 0.0f;
33388 sampler_desc.MinLOD = 0.0f;
33389 sampler_desc.MaxLOD = 0.0f;
33390 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
33391 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
33393 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
33394 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
33395 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
33397 for (z = 0; z < 16; ++z)
33399 draw_quad_z(&test_context, (z * 2.0f + 1.0f) / 32.0f);
33400 get_texture_readback(test_context.backbuffer, 0, &rb);
33401 for (y = 0; y < 256; ++y)
33403 for (x = 0; x < 256; ++x)
33405 idx = z * 64 * 64 + (y / 4) * 64 + (x / 4);
33406 r0 = idx % 256;
33407 r1 = idx / 256;
33409 switch (block_indices[(y % 4) * 4 + (x % 4)])
33411 case 0: expected = r0; break;
33412 case 1: expected = r1; break;
33413 case 2: expected = r0 > r1 ? (12 * r0 + 2 * r1 + 7) / 14 : (8 * r0 + 2 * r1 + 5) / 10; break;
33414 case 3: expected = r0 > r1 ? (10 * r0 + 4 * r1 + 7) / 14 : (6 * r0 + 4 * r1 + 5) / 10; break;
33415 case 4: expected = r0 > r1 ? ( 8 * r0 + 6 * r1 + 7) / 14 : (4 * r0 + 6 * r1 + 5) / 10; break;
33416 case 5: expected = r0 > r1 ? ( 6 * r0 + 8 * r1 + 7) / 14 : (2 * r0 + 8 * r1 + 5) / 10; break;
33417 case 6: expected = r0 > r1 ? ( 4 * r0 + 10 * r1 + 7) / 14 : 0x00; break;
33418 case 7: expected = r0 > r1 ? ( 2 * r0 + 12 * r1 + 7) / 14 : 0xff; break;
33419 default: expected = ~0u; break;
33421 expected |= 0xff000000;
33422 colour = get_readback_color(&rb, (x * 640 + 128) / 256, (y * 480 + 128) / 256, 0);
33423 if (!(equal = compare_color(colour, expected, 8)))
33424 break;
33426 if (!equal)
33427 break;
33429 release_resource_readback(&rb);
33430 if (!equal)
33431 break;
33433 ok(equal, "Got unexpected colour 0x%08x at (%u, %u, %u), expected 0x%08x.\n", colour, x, y, z, expected);
33435 ID3D11PixelShader_Release(ps);
33436 ID3D11SamplerState_Release(sampler_state);
33437 ID3D11ShaderResourceView_Release(srv);
33438 ID3D11Texture3D_Release(texture);
33439 release_test_context(&test_context);
33442 START_TEST(d3d11)
33444 unsigned int argc, i;
33445 char **argv;
33447 use_mt = !getenv("WINETEST_NO_MT_D3D");
33449 argc = winetest_get_mainargs(&argv);
33450 for (i = 2; i < argc; ++i)
33452 if (!strcmp(argv[i], "--validate"))
33453 enable_debug_layer = TRUE;
33454 else if (!strcmp(argv[i], "--warp"))
33455 use_warp_adapter = TRUE;
33456 else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
33457 use_adapter_idx = atoi(argv[++i]);
33458 else if (!strcmp(argv[i], "--single"))
33459 use_mt = FALSE;
33462 print_adapter_info();
33464 queue_test(test_create_device);
33465 queue_for_each_feature_level(test_device_interfaces);
33466 queue_test(test_immediate_context);
33467 queue_test(test_create_deferred_context);
33468 queue_test(test_create_texture1d);
33469 queue_test(test_texture1d_interfaces);
33470 queue_test(test_create_texture2d);
33471 queue_test(test_texture2d_interfaces);
33472 queue_test(test_create_texture3d);
33473 queue_test(test_texture3d_interfaces);
33474 queue_test(test_create_buffer);
33475 queue_test(test_create_depthstencil_view);
33476 queue_test(test_depthstencil_view_interfaces);
33477 queue_test(test_create_rendertarget_view);
33478 queue_test(test_create_shader_resource_view);
33479 queue_for_each_feature_level(test_create_shader);
33480 queue_test(test_create_sampler_state);
33481 queue_test(test_create_blend_state);
33482 queue_test(test_create_depthstencil_state);
33483 queue_test(test_create_rasterizer_state);
33484 queue_test(test_create_query);
33485 queue_test(test_occlusion_query);
33486 queue_test(test_pipeline_statistics_query);
33487 queue_test(test_timestamp_query);
33488 queue_test(test_so_statistics_query);
33489 queue_test(test_device_removed_reason);
33490 queue_test(test_private_data);
33491 queue_for_each_feature_level(test_state_refcounting);
33492 queue_test(test_device_context_state);
33493 queue_test(test_blend);
33494 queue_test(test_texture1d);
33495 queue_test(test_texture);
33496 queue_test(test_cube_maps);
33497 queue_test(test_depth_stencil_sampling);
33498 queue_test(test_sample_c_lz);
33499 queue_test(test_multiple_render_targets);
33500 queue_test(test_render_target_views);
33501 queue_test(test_layered_rendering);
33502 queue_test(test_scissor);
33503 queue_test(test_clear_state);
33504 queue_test(test_il_append_aligned);
33505 queue_test(test_instanced_draw);
33506 queue_test(test_vertex_id);
33507 queue_test(test_fragment_coords);
33508 queue_test(test_initial_texture_data);
33509 queue_test(test_update_subresource);
33510 queue_test(test_copy_subresource_region);
33511 queue_test(test_copy_subresource_region_1d);
33512 queue_test(test_copy_subresource_region_3d);
33513 queue_test(test_resource_map);
33514 queue_for_each_feature_level(test_resource_access);
33515 queue_test(test_check_multisample_quality_levels);
33516 queue_for_each_feature_level(test_swapchain_formats);
33517 queue_test(test_swapchain_views);
33518 queue_test(test_swapchain_flip);
33519 queue_test(test_clear_render_target_view_1d);
33520 queue_test(test_clear_render_target_view_2d);
33521 queue_test(test_clear_render_target_view_3d);
33522 queue_test(test_clear_depth_stencil_view);
33523 queue_test(test_clear_buffer_unordered_access_view);
33524 queue_test(test_clear_image_unordered_access_view);
33525 queue_test(test_initial_depth_stencil_state);
33526 queue_test(test_draw_depth_only);
33527 queue_test(test_draw_uav_only);
33528 queue_test(test_cb_relative_addressing);
33529 queue_test(test_vs_input_relative_addressing);
33530 queue_test(test_getdc);
33531 queue_test(test_shader_stage_input_output_matching);
33532 queue_test(test_shader_interstage_interface);
33533 queue_test(test_sm4_if_instruction);
33534 queue_test(test_sm4_breakc_instruction);
33535 queue_test(test_sm4_continuec_instruction);
33536 queue_test(test_sm4_discard_instruction);
33537 queue_test(test_sm5_swapc_instruction);
33538 queue_test(test_create_input_layout);
33539 queue_test(test_input_layout_alignment);
33540 queue_test(test_input_assembler);
33541 queue_test(test_null_sampler);
33542 queue_test(test_check_feature_support);
33543 queue_test(test_create_unordered_access_view);
33544 queue_test(test_immediate_constant_buffer);
33545 queue_test(test_fp_specials);
33546 queue_test(test_uint_shader_instructions);
33547 queue_test(test_index_buffer_offset);
33548 queue_test(test_face_culling);
33549 queue_test(test_line_antialiasing_blending);
33550 queue_for_each_feature_level(test_format_support);
33551 queue_for_each_9_x_feature_level(test_fl9_draw);
33552 queue_test(test_ddy);
33553 queue_test(test_shader_input_registers_limits);
33554 queue_test(test_unbind_shader_resource_view);
33555 queue_test(test_stencil_separate);
33556 queue_test(test_uav_load);
33557 queue_test(test_cs_uav_store);
33558 queue_test(test_uav_store_immediate_constant);
33559 queue_test(test_ps_cs_uav_binding);
33560 queue_test(test_atomic_instructions);
33561 queue_test(test_sm4_ret_instruction);
33562 queue_test(test_primitive_restart);
33563 queue_test(test_resinfo_instruction);
33564 queue_test(test_sm5_bufinfo_instruction);
33565 queue_test(test_sampleinfo_instruction);
33566 queue_test(test_render_target_device_mismatch);
33567 queue_test(test_buffer_srv);
33568 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
33569 test_unaligned_raw_buffer_access);
33570 queue_test(test_uav_counters);
33571 queue_test(test_dispatch_indirect);
33572 queue_test(test_compute_shader_registers);
33573 queue_test(test_tgsm);
33574 queue_test(test_geometry_shader);
33575 queue_test(test_quad_tessellation);
33576 queue_test(test_stream_output);
33577 queue_test(test_fl10_stream_output_desc);
33578 queue_test(test_stream_output_resume);
33579 queue_test(test_stream_output_components);
33580 queue_test(test_stream_output_vs);
33581 queue_test(test_gather);
33582 queue_test(test_gather_c);
33583 queue_test(test_depth_bias);
33584 queue_test(test_fractional_viewports);
33585 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0, test_negative_viewports);
33586 queue_test(test_early_depth_stencil);
33587 queue_test(test_conservative_depth_output);
33588 queue_test(test_format_compatibility);
33589 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
33590 test_compressed_format_compatibility);
33591 queue_test(test_clip_distance);
33592 queue_test(test_combined_clip_and_cull_distances);
33593 queue_test(test_generate_mips);
33594 queue_test(test_alpha_to_coverage);
33595 queue_test(test_unbound_multisample_texture);
33596 queue_test(test_multiple_viewports);
33597 queue_test(test_multisample_resolve);
33598 queue_test(test_sample_shading);
33599 queue_test(test_sample_mask);
33600 queue_test(test_depth_clip);
33601 queue_test(test_staging_buffers);
33602 queue_test(test_render_a8);
33603 queue_test(test_standard_pattern);
33604 queue_test(test_desktop_window);
33605 queue_test(test_sample_attached_rtv);
33606 queue_test(test_color_mask);
33607 queue_test(test_independent_blend);
33608 queue_test(test_dual_source_blend);
33609 queue_test(test_deferred_context_state);
33610 queue_test(test_deferred_context_swap_state);
33611 queue_test(test_deferred_context_rendering);
33612 queue_test(test_deferred_context_map);
33613 queue_test(test_unbound_streams);
33614 queue_test(test_texture_compressed_3d);
33616 run_queued_tests();