d3d11: Implement ID3D11DeviceContext::ExecuteCommandList().
[wine.git] / dlls / d3d11 / tests / d3d11.c
blobfc0da4391733aa9fd9fa2cad3b167c795ee737a9
1 /*
2 * Copyright 2008 Henri Verbeet for CodeWeavers
3 * Copyright 2015 Józef Kucia for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <assert.h>
21 #include <float.h>
22 #include <limits.h>
23 #include <math.h>
24 #include <stdlib.h>
25 #define COBJMACROS
26 #include "initguid.h"
27 #include "d3d11_4.h"
28 #include "wine/heap.h"
29 #include "wine/test.h"
31 #define BITS_NNAN 0xffc00000
32 #define BITS_NAN 0x7fc00000
33 #define BITS_NINF 0xff800000
34 #define BITS_INF 0x7f800000
35 #define BITS_N1_0 0xbf800000
36 #define BITS_1_0 0x3f800000
38 #define SWAPCHAIN_FLAG_SHADER_INPUT 0x1
40 static unsigned int use_adapter_idx;
41 static BOOL enable_debug_layer;
42 static BOOL use_warp_adapter;
43 static BOOL use_mt = TRUE;
45 static struct test_entry
47 union
49 void (*test)(void);
50 void (*test_fl)(D3D_FEATURE_LEVEL fl);
51 } u;
52 D3D_FEATURE_LEVEL fl;
53 } *mt_tests;
54 size_t mt_tests_size, mt_test_count;
56 struct format_support
58 DXGI_FORMAT format;
59 D3D_FEATURE_LEVEL fl_required;
60 D3D_FEATURE_LEVEL fl_optional;
63 static const struct format_support display_format_support[] =
65 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
66 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
67 {DXGI_FORMAT_B8G8R8A8_UNORM, D3D_FEATURE_LEVEL_9_1},
68 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D3D_FEATURE_LEVEL_9_1},
69 {DXGI_FORMAT_R16G16B16A16_FLOAT, D3D_FEATURE_LEVEL_10_0},
70 {DXGI_FORMAT_R10G10B10A2_UNORM, D3D_FEATURE_LEVEL_10_0},
71 {DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_0},
74 struct vec2
76 float x, y;
79 struct vec3
81 float x, y, z;
84 struct vec4
86 float x, y, z, w;
89 struct ivec4
91 int x, y, z, w;
94 struct uvec4
96 unsigned int x, y, z, w;
99 struct device_desc
101 const D3D_FEATURE_LEVEL *feature_level;
102 UINT flags;
105 struct swapchain_desc
107 BOOL windowed;
108 unsigned buffer_count;
109 unsigned int width, height;
110 DXGI_SWAP_EFFECT swap_effect;
111 DWORD flags;
114 static void queue_test_entry(const struct test_entry *t)
116 if (mt_test_count >= mt_tests_size)
118 mt_tests_size = max(16, mt_tests_size * 2);
119 mt_tests = heap_realloc(mt_tests, mt_tests_size * sizeof(*t));
121 mt_tests[mt_test_count++] = *t;
124 static void queue_test_fl(void (*test)(const D3D_FEATURE_LEVEL fl), D3D_FEATURE_LEVEL fl)
126 struct test_entry t;
128 t.u.test_fl = test;
129 t.fl = fl;
130 queue_test_entry(&t);
133 static void queue_test(void (*test)(void))
135 struct test_entry t;
137 t.u.test = test;
138 t.fl = 0;
139 queue_test_entry(&t);
142 static void run_mt_test(const struct test_entry *t)
144 if (t->fl)
145 t->u.test_fl(t->fl);
146 else
147 t->u.test();
150 static DWORD WINAPI thread_func(void *ctx)
152 LONG *i = ctx, j;
154 while (*i < mt_test_count)
156 j = *i;
157 if (InterlockedCompareExchange(i, j + 1, j) == j)
158 run_mt_test(&mt_tests[j]);
161 return 0;
164 static void run_queued_tests(void)
166 unsigned int thread_count, i;
167 HANDLE *threads;
168 SYSTEM_INFO si;
169 LONG test_idx;
171 if (!use_mt)
173 for (i = 0; i < mt_test_count; ++i)
175 run_mt_test(&mt_tests[i]);
178 return;
181 GetSystemInfo(&si);
182 thread_count = si.dwNumberOfProcessors;
183 threads = heap_calloc(thread_count, sizeof(*threads));
184 for (i = 0, test_idx = 0; i < thread_count; ++i)
186 threads[i] = CreateThread(NULL, 0, thread_func, &test_idx, 0, NULL);
187 ok(!!threads[i], "Failed to create thread %u.\n", i);
189 WaitForMultipleObjects(thread_count, threads, TRUE, INFINITE);
190 for (i = 0; i < thread_count; ++i)
192 CloseHandle(threads[i]);
194 heap_free(threads);
197 static void set_box(D3D11_BOX *box, UINT left, UINT top, UINT front, UINT right, UINT bottom, UINT back)
199 box->left = left;
200 box->top = top;
201 box->front = front;
202 box->right = right;
203 box->bottom = bottom;
204 box->back = back;
207 static ULONG get_refcount(void *iface)
209 IUnknown *unknown = iface;
210 IUnknown_AddRef(unknown);
211 return IUnknown_Release(unknown);
214 #define check_interface(a, b, c, d) check_interface_(__LINE__, a, b, c, d)
215 static HRESULT check_interface_(unsigned int line, void *iface, REFIID riid, BOOL supported, BOOL is_broken)
217 HRESULT hr, expected_hr, broken_hr;
218 IUnknown *unknown = iface, *out;
220 if (supported)
222 expected_hr = S_OK;
223 broken_hr = E_NOINTERFACE;
225 else
227 expected_hr = E_NOINTERFACE;
228 broken_hr = S_OK;
231 hr = IUnknown_QueryInterface(unknown, riid, (void **)&out);
232 ok_(__FILE__, line)(hr == expected_hr || broken(is_broken && hr == broken_hr),
233 "Got hr %#x, expected %#x.\n", hr, expected_hr);
234 if (SUCCEEDED(hr))
235 IUnknown_Release(out);
236 return hr;
239 static BOOL compare_float(float f, float g, unsigned int ulps)
241 int x = *(int *)&f;
242 int y = *(int *)&g;
244 if (x < 0)
245 x = INT_MIN - x;
246 if (y < 0)
247 y = INT_MIN - y;
249 if (abs(x - y) > ulps)
250 return FALSE;
252 return TRUE;
255 static BOOL compare_vec4(const struct vec4 *v1, const struct vec4 *v2, unsigned int ulps)
257 return compare_float(v1->x, v2->x, ulps)
258 && compare_float(v1->y, v2->y, ulps)
259 && compare_float(v1->z, v2->z, ulps)
260 && compare_float(v1->w, v2->w, ulps);
263 static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
265 unsigned int diff = x > y ? x - y : y - x;
267 return diff <= max_diff;
270 static BOOL compare_uvec4(const struct uvec4* v1, const struct uvec4 *v2)
272 return v1->x == v2->x && v1->y == v2->y && v1->z == v2->z && v1->w == v2->w;
275 static BOOL compare_color(DWORD c1, DWORD c2, BYTE max_diff)
277 return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
278 && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
279 && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
280 && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
283 static char const *debugstr_viewport(D3D11_VIEWPORT *vp)
285 if (!vp) return "(null)";
286 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}",
287 vp->TopLeftX, vp->TopLeftY, vp->Width, vp->Height, vp->MinDepth, vp->MaxDepth);
290 struct srv_desc
292 DXGI_FORMAT format;
293 D3D11_SRV_DIMENSION dimension;
294 unsigned int miplevel_idx;
295 unsigned int miplevel_count;
296 unsigned int layer_idx;
297 unsigned int layer_count;
300 static void get_srv_desc(D3D11_SHADER_RESOURCE_VIEW_DESC *d3d11_desc, const struct srv_desc *desc)
302 d3d11_desc->Format = desc->format;
303 d3d11_desc->ViewDimension = desc->dimension;
304 if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1D)
306 U(*d3d11_desc).Texture1D.MostDetailedMip = desc->miplevel_idx;
307 U(*d3d11_desc).Texture1D.MipLevels = desc->miplevel_count;
309 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE1DARRAY)
311 U(*d3d11_desc).Texture1DArray.MostDetailedMip = desc->miplevel_idx;
312 U(*d3d11_desc).Texture1DArray.MipLevels = desc->miplevel_count;
313 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
314 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
316 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
318 U(*d3d11_desc).Texture2D.MostDetailedMip = desc->miplevel_idx;
319 U(*d3d11_desc).Texture2D.MipLevels = desc->miplevel_count;
321 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
323 U(*d3d11_desc).Texture2DArray.MostDetailedMip = desc->miplevel_idx;
324 U(*d3d11_desc).Texture2DArray.MipLevels = desc->miplevel_count;
325 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
326 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
328 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
330 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
331 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
333 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURE3D)
335 U(*d3d11_desc).Texture3D.MostDetailedMip = desc->miplevel_idx;
336 U(*d3d11_desc).Texture3D.MipLevels = desc->miplevel_count;
338 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
340 U(*d3d11_desc).TextureCube.MostDetailedMip = desc->miplevel_idx;
341 U(*d3d11_desc).TextureCube.MipLevels = desc->miplevel_count;
343 else if (desc->dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
345 U(*d3d11_desc).TextureCubeArray.MostDetailedMip = desc->miplevel_idx;
346 U(*d3d11_desc).TextureCubeArray.MipLevels = desc->miplevel_count;
347 U(*d3d11_desc).TextureCubeArray.First2DArrayFace = desc->layer_idx;
348 U(*d3d11_desc).TextureCubeArray.NumCubes = desc->layer_count;
350 else if (desc->dimension != D3D11_SRV_DIMENSION_UNKNOWN
351 && desc->dimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
353 trace("Unhandled view dimension %#x.\n", desc->dimension);
357 #define check_srv_desc(a, b) check_srv_desc_(__LINE__, a, b)
358 static void check_srv_desc_(unsigned int line, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc,
359 const struct srv_desc *expected_desc)
361 ok_(__FILE__, line)(desc->Format == expected_desc->format,
362 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
363 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
364 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
366 if (desc->ViewDimension != expected_desc->dimension)
367 return;
369 if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2D)
371 ok_(__FILE__, line)(U(*desc).Texture2D.MostDetailedMip == expected_desc->miplevel_idx,
372 "Got MostDetailedMip %u, expected %u.\n",
373 U(*desc).Texture2D.MostDetailedMip, expected_desc->miplevel_idx);
374 ok_(__FILE__, line)(U(*desc).Texture2D.MipLevels == expected_desc->miplevel_count,
375 "Got MipLevels %u, expected %u.\n",
376 U(*desc).Texture2D.MipLevels, expected_desc->miplevel_count);
378 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DARRAY)
380 ok_(__FILE__, line)(U(*desc).Texture2DArray.MostDetailedMip == expected_desc->miplevel_idx,
381 "Got MostDetailedMip %u, expected %u.\n",
382 U(*desc).Texture2DArray.MostDetailedMip, expected_desc->miplevel_idx);
383 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipLevels == expected_desc->miplevel_count,
384 "Got MipLevels %u, expected %u.\n",
385 U(*desc).Texture2DArray.MipLevels, expected_desc->miplevel_count);
386 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
387 "Got FirstArraySlice %u, expected %u.\n",
388 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
389 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
390 "Got ArraySize %u, expected %u.\n",
391 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
393 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY)
395 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
396 "Got FirstArraySlice %u, expected %u.\n",
397 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
398 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
399 "Got ArraySize %u, expected %u.\n",
400 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
402 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURE3D)
404 ok_(__FILE__, line)(U(*desc).Texture3D.MostDetailedMip == expected_desc->miplevel_idx,
405 "Got MostDetailedMip %u, expected %u.\n",
406 U(*desc).Texture3D.MostDetailedMip, expected_desc->miplevel_idx);
407 ok_(__FILE__, line)(U(*desc).Texture3D.MipLevels == expected_desc->miplevel_count,
408 "Got MipLevels %u, expected %u.\n",
409 U(*desc).Texture3D.MipLevels, expected_desc->miplevel_count);
411 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBE)
413 ok_(__FILE__, line)(U(*desc).TextureCube.MostDetailedMip == expected_desc->miplevel_idx,
414 "Got MostDetailedMip %u, expected %u.\n",
415 U(*desc).TextureCube.MostDetailedMip, expected_desc->miplevel_idx);
416 ok_(__FILE__, line)(U(*desc).TextureCube.MipLevels == expected_desc->miplevel_count,
417 "Got MipLevels %u, expected %u.\n",
418 U(*desc).TextureCube.MipLevels, expected_desc->miplevel_count);
420 else if (desc->ViewDimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
422 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MostDetailedMip == expected_desc->miplevel_idx,
423 "Got MostDetailedMip %u, expected %u.\n",
424 U(*desc).TextureCubeArray.MostDetailedMip, expected_desc->miplevel_idx);
425 ok_(__FILE__, line)(U(*desc).TextureCubeArray.MipLevels == expected_desc->miplevel_count,
426 "Got MipLevels %u, expected %u.\n",
427 U(*desc).TextureCubeArray.MipLevels, expected_desc->miplevel_count);
428 ok_(__FILE__, line)(U(*desc).TextureCubeArray.First2DArrayFace == expected_desc->layer_idx,
429 "Got First2DArrayFace %u, expected %u.\n",
430 U(*desc).TextureCubeArray.First2DArrayFace, expected_desc->layer_idx);
431 ok_(__FILE__, line)(U(*desc).TextureCubeArray.NumCubes == expected_desc->layer_count,
432 "Got NumCubes %u, expected %u.\n",
433 U(*desc).TextureCubeArray.NumCubes, expected_desc->layer_count);
435 else if (desc->ViewDimension != D3D11_SRV_DIMENSION_TEXTURE2DMS)
437 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
441 struct rtv_desc
443 DXGI_FORMAT format;
444 D3D11_RTV_DIMENSION dimension;
445 unsigned int miplevel_idx;
446 unsigned int layer_idx;
447 unsigned int layer_count;
450 static void get_rtv_desc(D3D11_RENDER_TARGET_VIEW_DESC *d3d11_desc, const struct rtv_desc *desc)
452 d3d11_desc->Format = desc->format;
453 d3d11_desc->ViewDimension = desc->dimension;
454 if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1D)
456 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
458 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE1DARRAY)
460 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
461 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
462 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
464 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
466 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
468 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
470 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
471 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
472 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
474 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
476 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
477 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
479 else if (desc->dimension == D3D11_RTV_DIMENSION_TEXTURE3D)
481 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
482 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
483 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
485 else if (desc->dimension != D3D11_RTV_DIMENSION_UNKNOWN
486 && desc->dimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
488 trace("Unhandled view dimension %#x.\n", desc->dimension);
492 #define check_rtv_desc(a, b) check_rtv_desc_(__LINE__, a, b)
493 static void check_rtv_desc_(unsigned int line, const D3D11_RENDER_TARGET_VIEW_DESC *desc,
494 const struct rtv_desc *expected_desc)
496 ok_(__FILE__, line)(desc->Format == expected_desc->format,
497 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
498 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
499 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
501 if (desc->ViewDimension != expected_desc->dimension)
502 return;
504 if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2D)
506 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
507 "Got MipSlice %u, expected %u.\n",
508 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
510 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DARRAY)
512 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
513 "Got MipSlice %u, expected %u.\n",
514 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
515 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
516 "Got FirstArraySlice %u, expected %u.\n",
517 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
518 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
519 "Got ArraySize %u, expected %u.\n",
520 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
522 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY)
524 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
525 "Got FirstArraySlice %u, expected %u.\n",
526 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
527 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
528 "Got ArraySize %u, expected %u.\n",
529 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
531 else if (desc->ViewDimension == D3D11_RTV_DIMENSION_TEXTURE3D)
533 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
534 "Got MipSlice %u, expected %u.\n",
535 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
536 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
537 "Got FirstWSlice %u, expected %u.\n",
538 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
539 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
540 "Got WSize %u, expected %u.\n",
541 U(*desc).Texture3D.WSize, expected_desc->layer_count);
543 else if (desc->ViewDimension != D3D11_RTV_DIMENSION_TEXTURE2DMS)
545 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
549 struct dsv_desc
551 DXGI_FORMAT format;
552 D3D11_DSV_DIMENSION dimension;
553 unsigned int miplevel_idx;
554 unsigned int layer_idx;
555 unsigned int layer_count;
558 static void get_dsv_desc(D3D11_DEPTH_STENCIL_VIEW_DESC *d3d11_desc, const struct dsv_desc *desc)
560 d3d11_desc->Format = desc->format;
561 d3d11_desc->ViewDimension = desc->dimension;
562 d3d11_desc->Flags = 0;
563 if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1D)
565 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
567 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE1DARRAY)
569 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
570 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
571 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
573 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2D)
575 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
577 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
579 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
580 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
581 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
583 else if (desc->dimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
585 U(*d3d11_desc).Texture2DMSArray.FirstArraySlice = desc->layer_idx;
586 U(*d3d11_desc).Texture2DMSArray.ArraySize = desc->layer_count;
588 else if (desc->dimension != D3D11_DSV_DIMENSION_UNKNOWN
589 && desc->dimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
591 trace("Unhandled view dimension %#x.\n", desc->dimension);
595 #define check_dsv_desc(a, b) check_dsv_desc_(__LINE__, a, b)
596 static void check_dsv_desc_(unsigned int line, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc,
597 const struct dsv_desc *expected_desc)
599 ok_(__FILE__, line)(desc->Format == expected_desc->format,
600 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
601 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
602 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
604 if (desc->ViewDimension != expected_desc->dimension)
605 return;
607 if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D)
609 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
610 "Got MipSlice %u, expected %u.\n",
611 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
613 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DARRAY)
615 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
616 "Got MipSlice %u, expected %u.\n",
617 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
618 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
619 "Got FirstArraySlice %u, expected %u.\n",
620 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
621 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
622 "Got ArraySize %u, expected %u.\n",
623 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
625 else if (desc->ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY)
627 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.FirstArraySlice == expected_desc->layer_idx,
628 "Got FirstArraySlice %u, expected %u.\n",
629 U(*desc).Texture2DMSArray.FirstArraySlice, expected_desc->layer_idx);
630 ok_(__FILE__, line)(U(*desc).Texture2DMSArray.ArraySize == expected_desc->layer_count,
631 "Got ArraySize %u, expected %u.\n",
632 U(*desc).Texture2DMSArray.ArraySize, expected_desc->layer_count);
634 else if (desc->ViewDimension != D3D11_DSV_DIMENSION_TEXTURE2DMS)
636 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
640 struct uav_desc
642 DXGI_FORMAT format;
643 D3D11_UAV_DIMENSION dimension;
644 unsigned int miplevel_idx;
645 unsigned int layer_idx;
646 unsigned int layer_count;
649 static void get_uav_desc(D3D11_UNORDERED_ACCESS_VIEW_DESC *d3d11_desc, const struct uav_desc *desc)
651 d3d11_desc->Format = desc->format;
652 d3d11_desc->ViewDimension = desc->dimension;
653 if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1D)
655 U(*d3d11_desc).Texture1D.MipSlice = desc->miplevel_idx;
657 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE1DARRAY)
659 U(*d3d11_desc).Texture1DArray.MipSlice = desc->miplevel_idx;
660 U(*d3d11_desc).Texture1DArray.FirstArraySlice = desc->layer_idx;
661 U(*d3d11_desc).Texture1DArray.ArraySize = desc->layer_count;
663 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2D)
665 U(*d3d11_desc).Texture2D.MipSlice = desc->miplevel_idx;
667 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
669 U(*d3d11_desc).Texture2DArray.MipSlice = desc->miplevel_idx;
670 U(*d3d11_desc).Texture2DArray.FirstArraySlice = desc->layer_idx;
671 U(*d3d11_desc).Texture2DArray.ArraySize = desc->layer_count;
673 else if (desc->dimension == D3D11_UAV_DIMENSION_TEXTURE3D)
675 U(*d3d11_desc).Texture3D.MipSlice = desc->miplevel_idx;
676 U(*d3d11_desc).Texture3D.FirstWSlice = desc->layer_idx;
677 U(*d3d11_desc).Texture3D.WSize = desc->layer_count;
679 else if (desc->dimension != D3D11_UAV_DIMENSION_UNKNOWN)
681 trace("Unhandled view dimension %#x.\n", desc->dimension);
685 #define check_uav_desc(a, b) check_uav_desc_(__LINE__, a, b)
686 static void check_uav_desc_(unsigned int line, const D3D11_UNORDERED_ACCESS_VIEW_DESC *desc,
687 const struct uav_desc *expected_desc)
689 ok_(__FILE__, line)(desc->Format == expected_desc->format,
690 "Got format %#x, expected %#x.\n", desc->Format, expected_desc->format);
691 ok_(__FILE__, line)(desc->ViewDimension == expected_desc->dimension,
692 "Got view dimension %#x, expected %#x.\n", desc->ViewDimension, expected_desc->dimension);
694 if (desc->ViewDimension != expected_desc->dimension)
695 return;
697 if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2D)
699 ok_(__FILE__, line)(U(*desc).Texture2D.MipSlice == expected_desc->miplevel_idx,
700 "Got MipSlice %u, expected %u.\n",
701 U(*desc).Texture2D.MipSlice, expected_desc->miplevel_idx);
703 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE2DARRAY)
705 ok_(__FILE__, line)(U(*desc).Texture2DArray.MipSlice == expected_desc->miplevel_idx,
706 "Got MipSlice %u, expected %u.\n",
707 U(*desc).Texture2DArray.MipSlice, expected_desc->miplevel_idx);
708 ok_(__FILE__, line)(U(*desc).Texture2DArray.FirstArraySlice == expected_desc->layer_idx,
709 "Got FirstArraySlice %u, expected %u.\n",
710 U(*desc).Texture2DArray.FirstArraySlice, expected_desc->layer_idx);
711 ok_(__FILE__, line)(U(*desc).Texture2DArray.ArraySize == expected_desc->layer_count,
712 "Got ArraySize %u, expected %u.\n",
713 U(*desc).Texture2DArray.ArraySize, expected_desc->layer_count);
715 else if (desc->ViewDimension == D3D11_UAV_DIMENSION_TEXTURE3D)
717 ok_(__FILE__, line)(U(*desc).Texture3D.MipSlice == expected_desc->miplevel_idx,
718 "Got MipSlice %u, expected %u.\n",
719 U(*desc).Texture3D.MipSlice, expected_desc->miplevel_idx);
720 ok_(__FILE__, line)(U(*desc).Texture3D.FirstWSlice == expected_desc->layer_idx,
721 "Got FirstWSlice %u, expected %u.\n",
722 U(*desc).Texture3D.FirstWSlice, expected_desc->layer_idx);
723 ok_(__FILE__, line)(U(*desc).Texture3D.WSize == expected_desc->layer_count,
724 "Got WSize %u, expected %u.\n",
725 U(*desc).Texture3D.WSize, expected_desc->layer_count);
727 else
729 trace("Unhandled view dimension %#x.\n", desc->ViewDimension);
733 static void set_viewport(ID3D11DeviceContext *context, float x, float y,
734 float width, float height, float min_depth, float max_depth)
736 D3D11_VIEWPORT vp;
738 vp.TopLeftX = x;
739 vp.TopLeftY = y;
740 vp.Width = width;
741 vp.Height = height;
742 vp.MinDepth = min_depth;
743 vp.MaxDepth = max_depth;
745 ID3D11DeviceContext_RSSetViewports(context, 1, &vp);
748 #define create_buffer(a, b, c, d) create_buffer_(__LINE__, a, b, 0, c, d)
749 #define create_buffer_misc(a, b, c, d, e) create_buffer_(__LINE__, a, b, c, d, e)
750 static ID3D11Buffer *create_buffer_(unsigned int line, ID3D11Device *device,
751 unsigned int bind_flags, unsigned int misc_flags, unsigned int size, const void *data)
753 D3D11_SUBRESOURCE_DATA resource_data;
754 D3D11_BUFFER_DESC buffer_desc;
755 ID3D11Buffer *buffer;
756 HRESULT hr;
758 buffer_desc.ByteWidth = size;
759 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
760 buffer_desc.BindFlags = bind_flags;
761 buffer_desc.CPUAccessFlags = 0;
762 buffer_desc.MiscFlags = misc_flags;
763 buffer_desc.StructureByteStride = 0;
765 resource_data.pSysMem = data;
766 resource_data.SysMemPitch = 0;
767 resource_data.SysMemSlicePitch = 0;
769 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, data ? &resource_data : NULL, &buffer);
770 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
771 return buffer;
774 struct resource_readback
776 ID3D11Resource *resource;
777 D3D11_MAPPED_SUBRESOURCE map_desc;
778 ID3D11DeviceContext *immediate_context;
779 unsigned int width, height, depth, sub_resource_idx;
782 static void init_resource_readback(ID3D11Resource *resource, ID3D11Resource *readback_resource,
783 unsigned int width, unsigned int height, unsigned int depth, unsigned int sub_resource_idx,
784 ID3D11Device *device, struct resource_readback *rb)
786 HRESULT hr;
788 rb->resource = readback_resource;
789 rb->width = width;
790 rb->height = height;
791 rb->depth = depth;
792 rb->sub_resource_idx = sub_resource_idx;
794 ID3D11Device_GetImmediateContext(device, &rb->immediate_context);
796 ID3D11DeviceContext_CopyResource(rb->immediate_context, rb->resource, resource);
797 if (FAILED(hr = ID3D11DeviceContext_Map(rb->immediate_context,
798 rb->resource, sub_resource_idx, D3D11_MAP_READ, 0, &rb->map_desc)))
800 trace("Failed to map resource, hr %#x.\n", hr);
801 ID3D11Resource_Release(rb->resource);
802 rb->resource = NULL;
803 ID3D11DeviceContext_Release(rb->immediate_context);
804 rb->immediate_context = NULL;
808 static void get_buffer_readback(ID3D11Buffer *buffer, struct resource_readback *rb)
810 D3D11_BUFFER_DESC buffer_desc;
811 ID3D11Resource *rb_buffer;
812 ID3D11Device *device;
813 HRESULT hr;
815 memset(rb, 0, sizeof(*rb));
817 ID3D11Buffer_GetDevice(buffer, &device);
819 ID3D11Buffer_GetDesc(buffer, &buffer_desc);
820 buffer_desc.Usage = D3D11_USAGE_STAGING;
821 buffer_desc.BindFlags = 0;
822 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
823 buffer_desc.MiscFlags = 0;
824 buffer_desc.StructureByteStride = 0;
825 if (FAILED(hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, (ID3D11Buffer **)&rb_buffer)))
827 trace("Failed to create staging buffer, hr %#x.\n", hr);
828 ID3D11Device_Release(device);
829 return;
832 init_resource_readback((ID3D11Resource *)buffer, rb_buffer,
833 buffer_desc.ByteWidth, 1, 1, 0, device, rb);
835 ID3D11Device_Release(device);
838 static void get_texture1d_readback(ID3D11Texture1D *texture, unsigned int sub_resource_idx,
839 struct resource_readback *rb)
841 D3D11_TEXTURE1D_DESC texture_desc;
842 ID3D11Resource *rb_texture;
843 unsigned int miplevel;
844 ID3D11Device *device;
845 HRESULT hr;
847 memset(rb, 0, sizeof(*rb));
849 ID3D11Texture1D_GetDevice(texture, &device);
851 ID3D11Texture1D_GetDesc(texture, &texture_desc);
852 texture_desc.Usage = D3D11_USAGE_STAGING;
853 texture_desc.BindFlags = 0;
854 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
855 texture_desc.MiscFlags = 0;
856 if (FAILED(hr = ID3D11Device_CreateTexture1D(device, &texture_desc, NULL, (ID3D11Texture1D **)&rb_texture)))
858 trace("Failed to create texture, hr %#x.\n", hr);
859 ID3D11Device_Release(device);
860 return;
863 miplevel = sub_resource_idx % texture_desc.MipLevels;
864 init_resource_readback((ID3D11Resource *)texture, rb_texture,
865 max(1, texture_desc.Width >> miplevel), 1, 1, sub_resource_idx, device, rb);
867 ID3D11Device_Release(device);
870 static void get_texture_readback(ID3D11Texture2D *texture, unsigned int sub_resource_idx,
871 struct resource_readback *rb)
873 D3D11_TEXTURE2D_DESC texture_desc;
874 ID3D11Resource *rb_texture;
875 unsigned int miplevel;
876 ID3D11Device *device;
877 HRESULT hr;
879 memset(rb, 0, sizeof(*rb));
881 ID3D11Texture2D_GetDevice(texture, &device);
883 ID3D11Texture2D_GetDesc(texture, &texture_desc);
884 texture_desc.Usage = D3D11_USAGE_STAGING;
885 texture_desc.BindFlags = 0;
886 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
887 texture_desc.MiscFlags = 0;
888 if (FAILED(hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&rb_texture)))
890 trace("Failed to create texture, hr %#x.\n", hr);
891 ID3D11Device_Release(device);
892 return;
895 miplevel = sub_resource_idx % texture_desc.MipLevels;
896 init_resource_readback((ID3D11Resource *)texture, rb_texture,
897 max(1, texture_desc.Width >> miplevel),
898 max(1, texture_desc.Height >> miplevel),
899 1, sub_resource_idx, device, rb);
901 ID3D11Device_Release(device);
904 static void get_texture3d_readback(ID3D11Texture3D *texture, unsigned int sub_resource_idx,
905 struct resource_readback *rb)
907 D3D11_TEXTURE3D_DESC texture_desc;
908 ID3D11Resource *rb_texture;
909 unsigned int miplevel;
910 ID3D11Device *device;
911 HRESULT hr;
913 memset(rb, 0, sizeof(*rb));
915 ID3D11Texture3D_GetDevice(texture, &device);
917 ID3D11Texture3D_GetDesc(texture, &texture_desc);
918 texture_desc.Usage = D3D11_USAGE_STAGING;
919 texture_desc.BindFlags = 0;
920 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
921 texture_desc.MiscFlags = 0;
922 if (FAILED(hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, (ID3D11Texture3D **)&rb_texture)))
924 trace("Failed to create texture, hr %#x.\n", hr);
925 ID3D11Device_Release(device);
926 return;
929 miplevel = sub_resource_idx % texture_desc.MipLevels;
930 init_resource_readback((ID3D11Resource *)texture, rb_texture,
931 max(1, texture_desc.Width >> miplevel),
932 max(1, texture_desc.Height >> miplevel),
933 max(1, texture_desc.Depth >> miplevel),
934 sub_resource_idx, device, rb);
936 ID3D11Device_Release(device);
939 static void *get_readback_data(struct resource_readback *rb,
940 unsigned int x, unsigned int y, unsigned int z, unsigned byte_width)
942 return (BYTE *)rb->map_desc.pData + z * rb->map_desc.DepthPitch + y * rb->map_desc.RowPitch + x * byte_width;
945 static BYTE get_readback_u8(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
947 return *(BYTE *)get_readback_data(rb, x, y, z, sizeof(BYTE));
950 static WORD get_readback_u16(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
952 return *(WORD *)get_readback_data(rb, x, y, z, sizeof(WORD));
955 static DWORD get_readback_u32(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
957 return *(DWORD *)get_readback_data(rb, x, y, z, sizeof(DWORD));
960 static DWORD get_readback_color(struct resource_readback *rb, unsigned int x, unsigned int y, unsigned int z)
962 return get_readback_u32(rb, x, y, z);
965 static float get_readback_float(struct resource_readback *rb, unsigned int x, unsigned int y)
967 return *(float *)get_readback_data(rb, x, y, 0, sizeof(float));
970 static const struct vec4 *get_readback_vec4(struct resource_readback *rb, unsigned int x, unsigned int y)
972 return get_readback_data(rb, x, y, 0, sizeof(struct vec4));
975 static const struct uvec4 *get_readback_uvec4(struct resource_readback *rb, unsigned int x, unsigned int y)
977 return get_readback_data(rb, x, y, 0, sizeof(struct uvec4));
980 static void release_resource_readback(struct resource_readback *rb)
982 ID3D11DeviceContext_Unmap(rb->immediate_context, rb->resource, rb->sub_resource_idx);
983 ID3D11Resource_Release(rb->resource);
984 ID3D11DeviceContext_Release(rb->immediate_context);
987 static DWORD get_texture_color(ID3D11Texture2D *texture, unsigned int x, unsigned int y)
989 struct resource_readback rb;
990 DWORD color;
992 get_texture_readback(texture, 0, &rb);
993 color = get_readback_color(&rb, x, y, 0);
994 release_resource_readback(&rb);
996 return color;
999 #define check_readback_data_u8(a, b, c, d) check_readback_data_u8_(__LINE__, a, b, c, d)
1000 static void check_readback_data_u8_(unsigned int line, struct resource_readback *rb,
1001 const RECT *rect, BYTE expected_value, BYTE max_diff)
1003 unsigned int x = 0, y = 0, z = 0;
1004 BOOL all_match = FALSE;
1005 RECT default_rect;
1006 BYTE value = 0;
1008 if (!rect)
1010 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1011 rect = &default_rect;
1014 for (z = 0; z < rb->depth; ++z)
1016 for (y = rect->top; y < rect->bottom; ++y)
1018 for (x = rect->left; x < rect->right; ++x)
1020 value = get_readback_u8(rb, x, y, z);
1021 if (!compare_uint(value, expected_value, max_diff))
1022 goto done;
1026 all_match = TRUE;
1028 done:
1029 ok_(__FILE__, line)(all_match,
1030 "Got 0x%02x, expected 0x%02x at (%u, %u, %u), sub-resource %u.\n",
1031 value, expected_value, x, y, z, rb->sub_resource_idx);
1034 #define check_readback_data_u16(a, b, c, d) check_readback_data_u16_(__LINE__, a, b, c, d)
1035 static void check_readback_data_u16_(unsigned int line, struct resource_readback *rb,
1036 const RECT *rect, WORD expected_value, BYTE max_diff)
1038 unsigned int x = 0, y = 0, z = 0;
1039 BOOL all_match = FALSE;
1040 RECT default_rect;
1041 WORD value = 0;
1043 if (!rect)
1045 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1046 rect = &default_rect;
1049 for (z = 0; z < rb->depth; ++z)
1051 for (y = rect->top; y < rect->bottom; ++y)
1053 for (x = rect->left; x < rect->right; ++x)
1055 value = get_readback_u16(rb, x, y, z);
1056 if (!compare_uint(value, expected_value, max_diff))
1057 goto done;
1061 all_match = TRUE;
1063 done:
1064 ok_(__FILE__, line)(all_match,
1065 "Got 0x%04x, expected 0x%04x at (%u, %u, %u), sub-resource %u.\n",
1066 value, expected_value, x, y, z, rb->sub_resource_idx);
1069 #define check_readback_data_u24(a, b, c, d, e) check_readback_data_u24_(__LINE__, a, b, c, d, e)
1070 static void check_readback_data_u24_(unsigned int line, struct resource_readback *rb,
1071 const RECT *rect, unsigned int shift, DWORD expected_value, BYTE max_diff)
1073 unsigned int x = 0, y = 0, z = 0;
1074 BOOL all_match = FALSE;
1075 RECT default_rect;
1076 DWORD value = 0;
1078 if (!rect)
1080 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1081 rect = &default_rect;
1084 for (z = 0; z < rb->depth; ++z)
1086 for (y = rect->top; y < rect->bottom; ++y)
1088 for (x = rect->left; x < rect->right; ++x)
1090 value = get_readback_u32(rb, x, y, z) >> shift;
1091 if (!compare_uint(value, expected_value, max_diff))
1092 goto done;
1096 all_match = TRUE;
1098 done:
1099 ok_(__FILE__, line)(all_match,
1100 "Got 0x%06x, expected 0x%06x at (%u, %u, %u), sub-resource %u.\n",
1101 value, expected_value, x, y, z, rb->sub_resource_idx);
1104 #define check_readback_data_color(a, b, c, d) check_readback_data_color_(__LINE__, a, b, c, d)
1105 static void check_readback_data_color_(unsigned int line, struct resource_readback *rb,
1106 const RECT *rect, DWORD expected_color, BYTE max_diff)
1108 unsigned int x = 0, y = 0, z = 0;
1109 BOOL all_match = FALSE;
1110 RECT default_rect;
1111 DWORD color = 0;
1113 if (!rect)
1115 SetRect(&default_rect, 0, 0, rb->width, rb->height);
1116 rect = &default_rect;
1119 for (z = 0; z < rb->depth; ++z)
1121 for (y = rect->top; y < rect->bottom; ++y)
1123 for (x = rect->left; x < rect->right; ++x)
1125 color = get_readback_color(rb, x, y, z);
1126 if (!compare_color(color, expected_color, max_diff))
1127 goto done;
1131 all_match = TRUE;
1133 done:
1134 ok_(__FILE__, line)(all_match,
1135 "Got 0x%08x, expected 0x%08x at (%u, %u, %u), sub-resource %u.\n",
1136 color, expected_color, x, y, z, rb->sub_resource_idx);
1139 #define check_texture_sub_resource_color(a, b, c, d, e) check_texture_sub_resource_color_(__LINE__, a, b, c, d, e)
1140 static void check_texture_sub_resource_color_(unsigned int line, ID3D11Texture2D *texture,
1141 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1143 struct resource_readback rb;
1145 get_texture_readback(texture, sub_resource_idx, &rb);
1146 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1147 release_resource_readback(&rb);
1150 #define check_texture_color(t, c, d) check_texture_color_(__LINE__, t, c, d)
1151 static void check_texture_color_(unsigned int line, ID3D11Texture2D *texture,
1152 DWORD expected_color, BYTE max_diff)
1154 unsigned int sub_resource_idx, sub_resource_count;
1155 D3D11_TEXTURE2D_DESC texture_desc;
1157 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1158 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1159 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1160 check_texture_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1163 #define check_texture1d_sub_resource_color(a, b, c, d, e) check_texture1d_sub_resource_color_(__LINE__, a, b, c, d, e)
1164 static void check_texture1d_sub_resource_color_(unsigned int line, ID3D11Texture1D *texture,
1165 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1167 struct resource_readback rb;
1169 get_texture1d_readback(texture, sub_resource_idx, &rb);
1170 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1171 release_resource_readback(&rb);
1174 #define check_texture1d_color(t, c, d) check_texture1d_color_(__LINE__, t, c, d)
1175 static void check_texture1d_color_(unsigned int line, ID3D11Texture1D *texture,
1176 DWORD expected_color, BYTE max_diff)
1178 unsigned int sub_resource_idx, sub_resource_count;
1179 D3D11_TEXTURE1D_DESC texture_desc;
1181 ID3D11Texture1D_GetDesc(texture, &texture_desc);
1182 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1183 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1184 check_texture1d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1187 #define check_texture3d_sub_resource_color(a, b, c, d, e) check_texture3d_sub_resource_color_(__LINE__, a, b, c, d, e)
1188 static void check_texture3d_sub_resource_color_(unsigned int line, ID3D11Texture3D *texture,
1189 unsigned int sub_resource_idx, const RECT *rect, DWORD expected_color, BYTE max_diff)
1191 struct resource_readback rb;
1193 get_texture3d_readback(texture, sub_resource_idx, &rb);
1194 check_readback_data_color_(line, &rb, rect, expected_color, max_diff);
1195 release_resource_readback(&rb);
1198 #define check_texture3d_color(t, c, d) check_texture3d_color_(__LINE__, t, c, d)
1199 static void check_texture3d_color_(unsigned int line, ID3D11Texture3D *texture,
1200 DWORD expected_color, BYTE max_diff)
1202 unsigned int sub_resource_idx, sub_resource_count;
1203 D3D11_TEXTURE3D_DESC texture_desc;
1205 ID3D11Texture3D_GetDesc(texture, &texture_desc);
1206 sub_resource_count = texture_desc.MipLevels;
1207 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1208 check_texture3d_sub_resource_color_(line, texture, sub_resource_idx, NULL, expected_color, max_diff);
1211 #define check_texture_sub_resource_float(a, b, c, d, e) check_texture_sub_resource_float_(__LINE__, a, b, c, d, e)
1212 static void check_texture_sub_resource_float_(unsigned int line, ID3D11Texture2D *texture,
1213 unsigned int sub_resource_idx, const RECT *rect, float expected_value, BYTE max_diff)
1215 struct resource_readback rb;
1216 unsigned int x = 0, y = 0;
1217 BOOL all_match = TRUE;
1218 float value = 0.0f;
1219 RECT default_rect;
1221 get_texture_readback(texture, sub_resource_idx, &rb);
1222 if (!rect)
1224 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1225 rect = &default_rect;
1227 for (y = rect->top; y < rect->bottom; ++y)
1229 for (x = rect->left; x < rect->right; ++x)
1231 value = get_readback_float(&rb, x, y);
1232 if (!compare_float(value, expected_value, max_diff))
1234 all_match = FALSE;
1235 break;
1238 if (!all_match)
1239 break;
1241 release_resource_readback(&rb);
1242 ok_(__FILE__, line)(all_match,
1243 "Got %.8e, expected %.8e at (%u, %u), sub-resource %u.\n",
1244 value, expected_value, x, y, sub_resource_idx);
1247 #define check_texture_float(r, f, d) check_texture_float_(__LINE__, r, f, d)
1248 static void check_texture_float_(unsigned int line, ID3D11Texture2D *texture,
1249 float expected_value, BYTE max_diff)
1251 unsigned int sub_resource_idx, sub_resource_count;
1252 D3D11_TEXTURE2D_DESC texture_desc;
1254 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1255 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1256 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1257 check_texture_sub_resource_float_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1260 #define check_texture_sub_resource_vec4(a, b, c, d, e) check_texture_sub_resource_vec4_(__LINE__, a, b, c, d, e)
1261 static void check_texture_sub_resource_vec4_(unsigned int line, ID3D11Texture2D *texture,
1262 unsigned int sub_resource_idx, const RECT *rect, const struct vec4 *expected_value, BYTE max_diff)
1264 struct resource_readback rb;
1265 unsigned int x = 0, y = 0;
1266 struct vec4 value = {0};
1267 BOOL all_match = TRUE;
1268 RECT default_rect;
1270 get_texture_readback(texture, sub_resource_idx, &rb);
1271 if (!rect)
1273 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1274 rect = &default_rect;
1276 for (y = rect->top; y < rect->bottom; ++y)
1278 for (x = rect->left; x < rect->right; ++x)
1280 value = *get_readback_vec4(&rb, x, y);
1281 if (!compare_vec4(&value, expected_value, max_diff))
1283 all_match = FALSE;
1284 break;
1287 if (!all_match)
1288 break;
1290 release_resource_readback(&rb);
1291 ok_(__FILE__, line)(all_match,
1292 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e} at (%u, %u), sub-resource %u.\n",
1293 value.x, value.y, value.z, value.w,
1294 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1295 x, y, sub_resource_idx);
1298 #define check_texture_vec4(a, b, c) check_texture_vec4_(__LINE__, a, b, c)
1299 static void check_texture_vec4_(unsigned int line, ID3D11Texture2D *texture,
1300 const struct vec4 *expected_value, BYTE max_diff)
1302 unsigned int sub_resource_idx, sub_resource_count;
1303 D3D11_TEXTURE2D_DESC texture_desc;
1305 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1306 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1307 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1308 check_texture_sub_resource_vec4_(line, texture, sub_resource_idx, NULL, expected_value, max_diff);
1311 #define check_texture_sub_resource_uvec4(a, b, c, d) check_texture_sub_resource_uvec4_(__LINE__, a, b, c, d)
1312 static void check_texture_sub_resource_uvec4_(unsigned int line, ID3D11Texture2D *texture,
1313 unsigned int sub_resource_idx, const RECT *rect, const struct uvec4 *expected_value)
1315 struct resource_readback rb;
1316 unsigned int x = 0, y = 0;
1317 struct uvec4 value = {0};
1318 BOOL all_match = TRUE;
1319 RECT default_rect;
1321 get_texture_readback(texture, sub_resource_idx, &rb);
1322 if (!rect)
1324 SetRect(&default_rect, 0, 0, rb.width, rb.height);
1325 rect = &default_rect;
1327 for (y = rect->top; y < rect->bottom; ++y)
1329 for (x = rect->left; x < rect->right; ++x)
1331 value = *get_readback_uvec4(&rb, x, y);
1332 if (!compare_uvec4(&value, expected_value))
1334 all_match = FALSE;
1335 break;
1338 if (!all_match)
1339 break;
1341 release_resource_readback(&rb);
1342 ok_(__FILE__, line)(all_match,
1343 "Got {0x%08x, 0x%08x, 0x%08x, 0x%08x}, expected {0x%08x, 0x%08x, 0x%08x, 0x%08x} "
1344 "at (%u, %u), sub-resource %u.\n",
1345 value.x, value.y, value.z, value.w,
1346 expected_value->x, expected_value->y, expected_value->z, expected_value->w,
1347 x, y, sub_resource_idx);
1350 #define check_texture_uvec4(a, b) check_texture_uvec4_(__LINE__, a, b)
1351 static void check_texture_uvec4_(unsigned int line, ID3D11Texture2D *texture,
1352 const struct uvec4 *expected_value)
1354 unsigned int sub_resource_idx, sub_resource_count;
1355 D3D11_TEXTURE2D_DESC texture_desc;
1357 ID3D11Texture2D_GetDesc(texture, &texture_desc);
1358 sub_resource_count = texture_desc.ArraySize * texture_desc.MipLevels;
1359 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
1360 check_texture_sub_resource_uvec4_(line, texture, sub_resource_idx, NULL, expected_value);
1363 static IDXGIAdapter *create_adapter(void)
1365 IDXGIFactory4 *factory4;
1366 IDXGIFactory *factory;
1367 IDXGIAdapter *adapter;
1368 HRESULT hr;
1370 if (!use_warp_adapter && !use_adapter_idx)
1371 return NULL;
1373 if (FAILED(hr = CreateDXGIFactory1(&IID_IDXGIFactory, (void **)&factory)))
1375 trace("Failed to create IDXGIFactory, hr %#x.\n", hr);
1376 return NULL;
1379 adapter = NULL;
1380 if (use_warp_adapter)
1382 if (SUCCEEDED(hr = IDXGIFactory_QueryInterface(factory, &IID_IDXGIFactory4, (void **)&factory4)))
1384 hr = IDXGIFactory4_EnumWarpAdapter(factory4, &IID_IDXGIAdapter, (void **)&adapter);
1385 IDXGIFactory4_Release(factory4);
1387 else
1389 trace("Failed to get IDXGIFactory4, hr %#x.\n", hr);
1392 else
1394 hr = IDXGIFactory_EnumAdapters(factory, use_adapter_idx, &adapter);
1396 IDXGIFactory_Release(factory);
1397 if (FAILED(hr))
1398 trace("Failed to get adapter, hr %#x.\n", hr);
1399 return adapter;
1402 static ID3D11Device *create_device(const struct device_desc *desc)
1404 static const D3D_FEATURE_LEVEL default_feature_level[] =
1406 D3D_FEATURE_LEVEL_11_0,
1407 D3D_FEATURE_LEVEL_10_1,
1408 D3D_FEATURE_LEVEL_10_0,
1410 const D3D_FEATURE_LEVEL *feature_level;
1411 UINT flags = desc ? desc->flags : 0;
1412 unsigned int feature_level_count;
1413 IDXGIAdapter *adapter;
1414 ID3D11Device *device;
1415 HRESULT hr;
1417 if (desc && desc->feature_level)
1419 feature_level = desc->feature_level;
1420 feature_level_count = 1;
1422 else
1424 feature_level = default_feature_level;
1425 feature_level_count = ARRAY_SIZE(default_feature_level);
1428 if (enable_debug_layer)
1429 flags |= D3D11_CREATE_DEVICE_DEBUG;
1431 if ((adapter = create_adapter()))
1433 hr = D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags,
1434 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL);
1435 IDXGIAdapter_Release(adapter);
1436 return SUCCEEDED(hr) ? device : NULL;
1439 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, flags,
1440 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1441 return device;
1442 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, flags,
1443 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1444 return device;
1445 if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, flags,
1446 feature_level, feature_level_count, D3D11_SDK_VERSION, &device, NULL, NULL)))
1447 return device;
1449 return NULL;
1452 static void get_device_adapter_desc(ID3D11Device *device, DXGI_ADAPTER_DESC *adapter_desc)
1454 IDXGIDevice *dxgi_device;
1455 IDXGIAdapter *adapter;
1456 HRESULT hr;
1458 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1459 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice interface, hr %#x.\n", hr);
1460 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1461 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1462 IDXGIDevice_Release(dxgi_device);
1463 hr = IDXGIAdapter_GetDesc(adapter, adapter_desc);
1464 ok(SUCCEEDED(hr), "Failed to get adapter desc, hr %#x.\n", hr);
1465 IDXGIAdapter_Release(adapter);
1468 static void print_adapter_info(void)
1470 DXGI_ADAPTER_DESC adapter_desc;
1471 ID3D11Device *device;
1473 if (!(device = create_device(NULL)))
1474 return;
1476 get_device_adapter_desc(device, &adapter_desc);
1477 trace("Adapter: %s, %04x:%04x.\n", wine_dbgstr_w(adapter_desc.Description),
1478 adapter_desc.VendorId, adapter_desc.DeviceId);
1479 ID3D11Device_Release(device);
1482 static BOOL is_warp_device(ID3D11Device *device)
1484 DXGI_ADAPTER_DESC adapter_desc;
1485 get_device_adapter_desc(device, &adapter_desc);
1486 return !adapter_desc.SubSysId && !adapter_desc.Revision
1487 && ((!adapter_desc.VendorId && !adapter_desc.DeviceId)
1488 || (adapter_desc.VendorId == 0x1414 && adapter_desc.DeviceId == 0x008c));
1491 static BOOL is_vendor_device(ID3D11Device *device, unsigned int vendor_id)
1493 DXGI_ADAPTER_DESC adapter_desc;
1495 if (!strcmp(winetest_platform, "wine"))
1496 return FALSE;
1498 get_device_adapter_desc(device, &adapter_desc);
1499 return adapter_desc.VendorId == vendor_id;
1502 static BOOL is_amd_device(ID3D11Device *device)
1504 return is_vendor_device(device, 0x1002);
1507 static BOOL is_intel_device(ID3D11Device *device)
1509 return is_vendor_device(device, 0x8086);
1512 static BOOL is_nvidia_device(ID3D11Device *device)
1514 return is_vendor_device(device, 0x10de);
1517 static BOOL is_d3d11_2_runtime(ID3D11Device *device)
1519 ID3D11Device2 *device2;
1520 HRESULT hr;
1522 hr = ID3D11Device_QueryInterface(device, &IID_ID3D11Device2, (void **)&device2);
1523 if (SUCCEEDED(hr))
1524 ID3D11Device2_Release(device2);
1525 return hr == S_OK;
1528 static BOOL check_compute_shaders_via_sm4_support(ID3D11Device *device)
1530 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS options;
1532 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1533 D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &options, sizeof(options))))
1534 return FALSE;
1535 return options.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x;
1538 static BOOL check_viewport_array_index_from_any_shader_support(ID3D11Device *device)
1540 D3D11_FEATURE_DATA_D3D11_OPTIONS3 options;
1542 if (FAILED(ID3D11Device_CheckFeatureSupport(device,
1543 D3D11_FEATURE_D3D11_OPTIONS3, &options, sizeof(options))))
1544 return FALSE;
1545 return options.VPAndRTArrayIndexFromAnyShaderFeedingRasterizer;
1548 static BOOL is_buffer(ID3D11Resource *resource)
1550 D3D11_RESOURCE_DIMENSION dimension;
1551 ID3D11Resource_GetType(resource, &dimension);
1552 return dimension == D3D11_RESOURCE_DIMENSION_BUFFER;
1555 static IDXGISwapChain *create_swapchain(ID3D11Device *device, HWND window,
1556 const struct swapchain_desc *swapchain_desc)
1558 DXGI_SWAP_CHAIN_DESC dxgi_desc;
1559 IDXGISwapChain *swapchain;
1560 IDXGIDevice *dxgi_device;
1561 IDXGIAdapter *adapter;
1562 IDXGIFactory *factory;
1563 HRESULT hr;
1565 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
1566 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
1567 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
1568 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
1569 IDXGIDevice_Release(dxgi_device);
1570 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
1571 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
1572 IDXGIAdapter_Release(adapter);
1574 dxgi_desc.BufferDesc.Width = 640;
1575 dxgi_desc.BufferDesc.Height = 480;
1576 dxgi_desc.BufferDesc.RefreshRate.Numerator = 60;
1577 dxgi_desc.BufferDesc.RefreshRate.Denominator = 1;
1578 dxgi_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1579 dxgi_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1580 dxgi_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1581 dxgi_desc.SampleDesc.Count = 1;
1582 dxgi_desc.SampleDesc.Quality = 0;
1583 dxgi_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1584 dxgi_desc.BufferCount = 1;
1585 dxgi_desc.OutputWindow = window;
1586 dxgi_desc.Windowed = TRUE;
1587 dxgi_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1588 dxgi_desc.Flags = 0;
1590 if (swapchain_desc)
1592 dxgi_desc.Windowed = swapchain_desc->windowed;
1593 dxgi_desc.SwapEffect = swapchain_desc->swap_effect;
1594 dxgi_desc.BufferCount = swapchain_desc->buffer_count;
1595 if (swapchain_desc->width)
1596 dxgi_desc.BufferDesc.Width = swapchain_desc->width;
1597 if (swapchain_desc->height)
1598 dxgi_desc.BufferDesc.Height = swapchain_desc->height;
1600 if (swapchain_desc->flags & SWAPCHAIN_FLAG_SHADER_INPUT)
1601 dxgi_desc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
1604 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &dxgi_desc, &swapchain);
1605 ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr);
1606 IDXGIFactory_Release(factory);
1608 return swapchain;
1611 struct d3d11_test_context
1613 ID3D11Device *device;
1614 HWND window;
1615 IDXGISwapChain *swapchain;
1616 ID3D11Texture2D *backbuffer;
1617 ID3D11RenderTargetView *backbuffer_rtv;
1618 ID3D11DeviceContext *immediate_context;
1620 ID3D11InputLayout *input_layout;
1621 ID3D11VertexShader *vs;
1622 const DWORD *vs_code;
1623 ID3D11Buffer *vs_cb;
1624 ID3D11Buffer *vb;
1626 ID3D11PixelShader *ps;
1627 ID3D11Buffer *ps_cb;
1630 #define init_test_context(a, b) init_test_context_(__LINE__, a, b, NULL)
1631 #define init_test_context_ext(a, b, c) init_test_context_(__LINE__, a, b, c)
1632 static BOOL init_test_context_(unsigned int line, struct d3d11_test_context *context,
1633 const D3D_FEATURE_LEVEL *feature_level, const struct swapchain_desc *swapchain_desc)
1635 unsigned int rt_width, rt_height;
1636 struct device_desc device_desc;
1637 HRESULT hr;
1638 RECT rect;
1640 memset(context, 0, sizeof(*context));
1642 device_desc.feature_level = feature_level;
1643 device_desc.flags = 0;
1644 if (!(context->device = create_device(&device_desc)))
1646 skip_(__FILE__, line)("Failed to create device.\n");
1647 return FALSE;
1650 rt_width = swapchain_desc && swapchain_desc->width ? swapchain_desc->width : 640;
1651 rt_height = swapchain_desc && swapchain_desc->height ? swapchain_desc->height : 480;
1652 SetRect(&rect, 0, 0, rt_width, rt_height);
1653 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
1654 context->window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
1655 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
1656 context->swapchain = create_swapchain(context->device, context->window, swapchain_desc);
1657 hr = IDXGISwapChain_GetBuffer(context->swapchain, 0, &IID_ID3D11Texture2D, (void **)&context->backbuffer);
1658 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
1660 hr = ID3D11Device_CreateRenderTargetView(context->device, (ID3D11Resource *)context->backbuffer,
1661 NULL, &context->backbuffer_rtv);
1662 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
1664 ID3D11Device_GetImmediateContext(context->device, &context->immediate_context);
1666 ID3D11DeviceContext_OMSetRenderTargets(context->immediate_context, 1, &context->backbuffer_rtv, NULL);
1668 set_viewport(context->immediate_context, 0.0f, 0.0f, rt_width, rt_height, 0.0f, 1.0f);
1670 return TRUE;
1673 #define release_test_context(context) release_test_context_(__LINE__, context)
1674 static void release_test_context_(unsigned int line, struct d3d11_test_context *context)
1676 ULONG ref;
1678 if (context->input_layout)
1679 ID3D11InputLayout_Release(context->input_layout);
1680 if (context->vs)
1681 ID3D11VertexShader_Release(context->vs);
1682 if (context->vs_cb)
1683 ID3D11Buffer_Release(context->vs_cb);
1684 if (context->vb)
1685 ID3D11Buffer_Release(context->vb);
1686 if (context->ps)
1687 ID3D11PixelShader_Release(context->ps);
1688 if (context->ps_cb)
1689 ID3D11Buffer_Release(context->ps_cb);
1691 ID3D11DeviceContext_Release(context->immediate_context);
1692 ID3D11RenderTargetView_Release(context->backbuffer_rtv);
1693 ID3D11Texture2D_Release(context->backbuffer);
1694 IDXGISwapChain_Release(context->swapchain);
1695 DestroyWindow(context->window);
1697 ref = ID3D11Device_Release(context->device);
1698 ok_(__FILE__, line)(!ref, "Device has %u references left.\n", ref);
1701 #define draw_quad(context) draw_quad_vs_(__LINE__, context, NULL, 0)
1702 #define draw_quad_vs(a, b, c) draw_quad_vs_(__LINE__, a, b, c)
1703 static void draw_quad_vs_(unsigned int line, struct d3d11_test_context *context,
1704 const DWORD *vs_code, size_t vs_code_size)
1706 static const D3D11_INPUT_ELEMENT_DESC default_layout_desc[] =
1708 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
1710 static const DWORD default_vs_code[] =
1712 #if 0
1713 float4 main(float4 position : POSITION) : SV_POSITION
1715 return position;
1717 #endif
1718 0x43425844, 0x4fb19b86, 0x955fa240, 0x1a630688, 0x24eb9db4, 0x00000001, 0x000001e0, 0x00000006,
1719 0x00000038, 0x00000084, 0x000000d0, 0x00000134, 0x00000178, 0x000001ac, 0x53414e58, 0x00000044,
1720 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
1721 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x02000001, 0xc00f0000, 0x80e40000,
1722 0x0000ffff, 0x50414e58, 0x00000044, 0x00000044, 0xfffe0200, 0x00000020, 0x00000024, 0x00240000,
1723 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000,
1724 0x02000001, 0xc00f0000, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x0000005c, 0x0000005c, 0xfffe0200,
1725 0x00000034, 0x00000028, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240001, 0x00000000,
1726 0xfffe0200, 0x0200001f, 0x80000005, 0x900f0000, 0x04000004, 0xc0030000, 0x90ff0000, 0xa0e40000,
1727 0x90e40000, 0x02000001, 0xc00c0000, 0x90e40000, 0x0000ffff, 0x52444853, 0x0000003c, 0x00010040,
1728 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
1729 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x0000002c,
1730 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
1731 0x49534f50, 0x4e4f4954, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1732 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
1734 static const struct vec3 quad[] =
1736 {-1.0f, -1.0f, 0.0f},
1737 {-1.0f, 1.0f, 0.0f},
1738 { 1.0f, -1.0f, 0.0f},
1739 { 1.0f, 1.0f, 0.0f},
1742 ID3D11Device *device = context->device;
1743 unsigned int stride, offset;
1744 HRESULT hr;
1746 if (!vs_code)
1748 vs_code = default_vs_code;
1749 vs_code_size = sizeof(default_vs_code);
1752 if (!context->input_layout)
1754 hr = ID3D11Device_CreateInputLayout(device, default_layout_desc, ARRAY_SIZE(default_layout_desc),
1755 vs_code, vs_code_size, &context->input_layout);
1756 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
1759 if (context->vs_code != vs_code)
1761 if (context->vs)
1762 ID3D11VertexShader_Release(context->vs);
1764 hr = ID3D11Device_CreateVertexShader(device, vs_code, vs_code_size, NULL, &context->vs);
1765 ok_(__FILE__, line)(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
1767 context->vs_code = vs_code;
1770 if (!context->vb)
1771 context->vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
1773 ID3D11DeviceContext_IASetInputLayout(context->immediate_context, context->input_layout);
1774 ID3D11DeviceContext_IASetPrimitiveTopology(context->immediate_context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
1775 stride = sizeof(*quad);
1776 offset = 0;
1777 ID3D11DeviceContext_IASetVertexBuffers(context->immediate_context, 0, 1, &context->vb, &stride, &offset);
1778 ID3D11DeviceContext_VSSetShader(context->immediate_context, context->vs, NULL, 0);
1780 ID3D11DeviceContext_Draw(context->immediate_context, 4, 0);
1783 #define draw_quad_z(context, z) draw_quad_z_(__LINE__, context, z)
1784 static void draw_quad_z_(unsigned int line, struct d3d11_test_context *context, float z)
1786 static const DWORD vs_code[] =
1788 #if 0
1789 float depth;
1791 void main(float4 in_position : POSITION, out float4 out_position : SV_Position)
1793 out_position = in_position;
1794 out_position.z = depth;
1796 #endif
1797 0x43425844, 0x22d7ff76, 0xd53b167c, 0x1b49ccf1, 0xbebfec39, 0x00000001, 0x00000100, 0x00000003,
1798 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
1799 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000b0f, 0x49534f50, 0x4e4f4954, 0xababab00,
1800 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
1801 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x52444853, 0x00000064, 0x00010040,
1802 0x00000019, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010b2, 0x00000000,
1803 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x05000036, 0x001020b2, 0x00000000, 0x00101c46,
1804 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
1807 struct vec4 data = {z};
1809 if (!context->vs_cb)
1810 context->vs_cb = create_buffer(context->device, D3D11_BIND_CONSTANT_BUFFER, sizeof(data), NULL);
1812 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1813 (ID3D11Resource *)context->vs_cb, 0, NULL, &data, 0, 0);
1815 ID3D11DeviceContext_VSSetConstantBuffers(context->immediate_context, 0, 1, &context->vs_cb);
1816 draw_quad_vs_(__LINE__, context, vs_code, sizeof(vs_code));
1819 static void set_quad_color(struct d3d11_test_context *context, const struct vec4 *color)
1821 ID3D11DeviceContext_UpdateSubresource(context->immediate_context,
1822 (ID3D11Resource *)context->ps_cb, 0, NULL, color, 0, 0);
1825 #define draw_color_quad(a, b) draw_color_quad_(__LINE__, a, b, NULL, 0)
1826 #define draw_color_quad_vs(a, b, c, d) draw_color_quad_(__LINE__, a, b, c, d)
1827 static void draw_color_quad_(unsigned int line, struct d3d11_test_context *context,
1828 const struct vec4 *color, const DWORD *vs_code, size_t vs_code_size)
1830 static const DWORD ps_color_code[] =
1832 #if 0
1833 float4 color;
1835 float4 main() : SV_TARGET
1837 return color;
1839 #endif
1840 0x43425844, 0xe7ffb369, 0x72bb84ee, 0x6f684dcd, 0xd367d788, 0x00000001, 0x00000158, 0x00000005,
1841 0x00000034, 0x00000080, 0x000000cc, 0x00000114, 0x00000124, 0x53414e58, 0x00000044, 0x00000044,
1842 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000, 0x00300000, 0x00240000, 0x00300000,
1843 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001, 0x800f0800, 0xa0e40000, 0x0000ffff,
1844 0x396e6f41, 0x00000044, 0x00000044, 0xffff0200, 0x00000014, 0x00000030, 0x00240001, 0x00300000,
1845 0x00300000, 0x00240000, 0x00300000, 0x00000000, 0x00000001, 0x00000000, 0xffff0200, 0x02000001,
1846 0x800f0800, 0xa0e40000, 0x0000ffff, 0x52444853, 0x00000040, 0x00000040, 0x00000010, 0x04000059,
1847 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x06000036, 0x001020f2,
1848 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000,
1849 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
1850 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
1853 ID3D11Device *device = context->device;
1854 HRESULT hr;
1856 if (!context->ps)
1858 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &context->ps);
1859 ok_(__FILE__, line)(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
1862 if (!context->ps_cb)
1863 context->ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*color), NULL);
1865 ID3D11DeviceContext_PSSetShader(context->immediate_context, context->ps, NULL, 0);
1866 ID3D11DeviceContext_PSSetConstantBuffers(context->immediate_context, 0, 1, &context->ps_cb);
1868 set_quad_color(context, color);
1870 draw_quad_vs_(line, context, vs_code, vs_code_size);
1873 static void test_create_device(void)
1875 static const D3D_FEATURE_LEVEL default_feature_levels[] =
1877 D3D_FEATURE_LEVEL_11_0,
1878 D3D_FEATURE_LEVEL_10_1,
1879 D3D_FEATURE_LEVEL_10_0,
1880 D3D_FEATURE_LEVEL_9_3,
1881 D3D_FEATURE_LEVEL_9_2,
1882 D3D_FEATURE_LEVEL_9_1,
1884 D3D_FEATURE_LEVEL feature_level, supported_feature_level;
1885 DXGI_SWAP_CHAIN_DESC swapchain_desc, obtained_desc;
1886 ID3D11DeviceContext *immediate_context;
1887 IDXGISwapChain *swapchain;
1888 ID3D11Device *device;
1889 ULONG refcount;
1890 HWND window;
1891 HRESULT hr;
1893 if (FAILED(hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1894 &device, NULL, NULL)))
1896 skip("Failed to create HAL device.\n");
1897 if ((device = create_device(NULL)))
1899 trace("Feature level %#x.\n", ID3D11Device_GetFeatureLevel(device));
1900 ID3D11Device_Release(device);
1902 return;
1905 supported_feature_level = ID3D11Device_GetFeatureLevel(device);
1906 trace("Feature level %#x.\n", supported_feature_level);
1907 ID3D11Device_Release(device);
1909 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL, NULL);
1910 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1912 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL,
1913 &feature_level, NULL);
1914 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1915 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1916 feature_level, supported_feature_level);
1918 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, default_feature_levels,
1919 ARRAY_SIZE(default_feature_levels), D3D11_SDK_VERSION, NULL, &feature_level, NULL);
1920 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1921 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1922 feature_level, supported_feature_level);
1924 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION, NULL, NULL,
1925 &immediate_context);
1926 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1928 ok(!!immediate_context, "Expected immediate device context pointer, got NULL.\n");
1929 refcount = get_refcount(immediate_context);
1930 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1932 ID3D11DeviceContext_GetDevice(immediate_context, &device);
1933 refcount = ID3D11Device_Release(device);
1934 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
1936 refcount = ID3D11DeviceContext_Release(immediate_context);
1937 ok(!refcount, "ID3D11DeviceContext has %u references left.\n", refcount);
1939 device = (ID3D11Device *)0xdeadbeef;
1940 feature_level = 0xdeadbeef;
1941 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
1942 hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_UNKNOWN, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1943 &device, &feature_level, &immediate_context);
1944 todo_wine ok(hr == E_INVALIDARG, "D3D11CreateDevice returned %#x.\n", hr);
1945 ok(!device, "Got unexpected device pointer %p.\n", device);
1946 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
1947 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
1949 window = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
1951 swapchain_desc.BufferDesc.Width = 800;
1952 swapchain_desc.BufferDesc.Height = 600;
1953 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
1954 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
1955 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
1956 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
1957 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
1958 swapchain_desc.SampleDesc.Count = 1;
1959 swapchain_desc.SampleDesc.Quality = 0;
1960 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
1961 swapchain_desc.BufferCount = 1;
1962 swapchain_desc.OutputWindow = window;
1963 swapchain_desc.Windowed = TRUE;
1964 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
1965 swapchain_desc.Flags = 0;
1967 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1968 &swapchain_desc, NULL, NULL, NULL, NULL);
1969 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1971 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1972 &swapchain_desc, NULL, NULL, &feature_level, NULL);
1973 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
1974 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
1975 feature_level, supported_feature_level);
1977 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
1978 &swapchain_desc, &swapchain, &device, NULL, NULL);
1979 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
1981 check_interface(swapchain, &IID_IDXGISwapChain1, TRUE, FALSE);
1983 memset(&obtained_desc, 0, sizeof(obtained_desc));
1984 hr = IDXGISwapChain_GetDesc(swapchain, &obtained_desc);
1985 ok(SUCCEEDED(hr), "GetDesc failed %#x.\n", hr);
1986 ok(obtained_desc.BufferDesc.Width == swapchain_desc.BufferDesc.Width,
1987 "Got unexpected BufferDesc.Width %u.\n", obtained_desc.BufferDesc.Width);
1988 ok(obtained_desc.BufferDesc.Height == swapchain_desc.BufferDesc.Height,
1989 "Got unexpected BufferDesc.Height %u.\n", obtained_desc.BufferDesc.Height);
1990 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Numerator == swapchain_desc.BufferDesc.RefreshRate.Numerator,
1991 "Got unexpected BufferDesc.RefreshRate.Numerator %u.\n",
1992 obtained_desc.BufferDesc.RefreshRate.Numerator);
1993 todo_wine ok(obtained_desc.BufferDesc.RefreshRate.Denominator == swapchain_desc.BufferDesc.RefreshRate.Denominator,
1994 "Got unexpected BufferDesc.RefreshRate.Denominator %u.\n",
1995 obtained_desc.BufferDesc.RefreshRate.Denominator);
1996 ok(obtained_desc.BufferDesc.Format == swapchain_desc.BufferDesc.Format,
1997 "Got unexpected BufferDesc.Format %#x.\n", obtained_desc.BufferDesc.Format);
1998 ok(obtained_desc.BufferDesc.ScanlineOrdering == swapchain_desc.BufferDesc.ScanlineOrdering,
1999 "Got unexpected BufferDesc.ScanlineOrdering %#x.\n", obtained_desc.BufferDesc.ScanlineOrdering);
2000 ok(obtained_desc.BufferDesc.Scaling == swapchain_desc.BufferDesc.Scaling,
2001 "Got unexpected BufferDesc.Scaling %#x.\n", obtained_desc.BufferDesc.Scaling);
2002 ok(obtained_desc.SampleDesc.Count == swapchain_desc.SampleDesc.Count,
2003 "Got unexpected SampleDesc.Count %u.\n", obtained_desc.SampleDesc.Count);
2004 ok(obtained_desc.SampleDesc.Quality == swapchain_desc.SampleDesc.Quality,
2005 "Got unexpected SampleDesc.Quality %u.\n", obtained_desc.SampleDesc.Quality);
2006 ok(obtained_desc.BufferUsage == swapchain_desc.BufferUsage,
2007 "Got unexpected BufferUsage %#x.\n", obtained_desc.BufferUsage);
2008 ok(obtained_desc.BufferCount == swapchain_desc.BufferCount,
2009 "Got unexpected BufferCount %u.\n", obtained_desc.BufferCount);
2010 ok(obtained_desc.OutputWindow == swapchain_desc.OutputWindow,
2011 "Got unexpected OutputWindow %p.\n", obtained_desc.OutputWindow);
2012 ok(obtained_desc.Windowed == swapchain_desc.Windowed,
2013 "Got unexpected Windowed %#x.\n", obtained_desc.Windowed);
2014 ok(obtained_desc.SwapEffect == swapchain_desc.SwapEffect,
2015 "Got unexpected SwapEffect %#x.\n", obtained_desc.SwapEffect);
2016 ok(obtained_desc.Flags == swapchain_desc.Flags,
2017 "Got unexpected Flags %#x.\n", obtained_desc.Flags);
2019 refcount = IDXGISwapChain_Release(swapchain);
2020 ok(!refcount, "Swapchain has %u references left.\n", refcount);
2022 feature_level = ID3D11Device_GetFeatureLevel(device);
2023 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2024 feature_level, supported_feature_level);
2026 refcount = ID3D11Device_Release(device);
2027 ok(!refcount, "Device has %u references left.\n", refcount);
2029 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2030 NULL, NULL, &device, NULL, NULL);
2031 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2032 ID3D11Device_Release(device);
2034 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2035 NULL, NULL, NULL, NULL, NULL);
2036 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2038 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2039 NULL, NULL, NULL, &feature_level, NULL);
2040 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2041 ok(feature_level == supported_feature_level, "Got feature level %#x, expected %#x.\n",
2042 feature_level, supported_feature_level);
2044 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2045 NULL, NULL, NULL, NULL, &immediate_context);
2046 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2047 ID3D11DeviceContext_Release(immediate_context);
2049 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2050 &swapchain_desc, NULL, NULL, NULL, NULL);
2051 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
2053 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2054 &swapchain_desc, &swapchain, NULL, NULL, NULL);
2055 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2056 IDXGISwapChain_Release(swapchain);
2058 swapchain_desc.OutputWindow = NULL;
2059 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2060 &swapchain_desc, NULL, NULL, NULL, NULL);
2061 ok(hr == S_FALSE, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2062 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2063 &swapchain_desc, NULL, &device, NULL, NULL);
2064 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2065 ID3D11Device_Release(device);
2067 swapchain = (IDXGISwapChain *)0xdeadbeef;
2068 device = (ID3D11Device *)0xdeadbeef;
2069 feature_level = 0xdeadbeef;
2070 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
2071 swapchain_desc.OutputWindow = NULL;
2072 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2073 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
2074 ok(hr == DXGI_ERROR_INVALID_CALL, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2075 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
2076 ok(!device, "Got unexpected device pointer %p.\n", device);
2077 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
2078 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
2080 swapchain = (IDXGISwapChain *)0xdeadbeef;
2081 device = (ID3D11Device *)0xdeadbeef;
2082 feature_level = 0xdeadbeef;
2083 immediate_context = (ID3D11DeviceContext *)0xdeadbeef;
2084 swapchain_desc.OutputWindow = window;
2085 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_BC5_UNORM;
2086 hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, 0, NULL, 0, D3D11_SDK_VERSION,
2087 &swapchain_desc, &swapchain, &device, &feature_level, &immediate_context);
2088 ok(hr == E_INVALIDARG, "D3D11CreateDeviceAndSwapChain returned %#x.\n", hr);
2089 ok(!swapchain, "Got unexpected swapchain pointer %p.\n", swapchain);
2090 ok(!device, "Got unexpected device pointer %p.\n", device);
2091 ok(!feature_level, "Got unexpected feature level %#x.\n", feature_level);
2092 ok(!immediate_context, "Got unexpected immediate context pointer %p.\n", immediate_context);
2094 DestroyWindow(window);
2097 static void test_device_interfaces(const D3D_FEATURE_LEVEL feature_level)
2099 struct device_desc device_desc;
2100 IDXGIAdapter *dxgi_adapter;
2101 IDXGIDevice *dxgi_device;
2102 ID3D11Device *device;
2103 IUnknown *iface;
2104 ULONG refcount;
2105 HRESULT hr;
2107 device_desc.feature_level = &feature_level;
2108 device_desc.flags = 0;
2109 if (!(device = create_device(&device_desc)))
2111 skip("Failed to create device for feature level %#x.\n", feature_level);
2112 return;
2115 check_interface(device, &IID_IUnknown, TRUE, FALSE);
2116 check_interface(device, &IID_IDXGIObject, TRUE, FALSE);
2117 check_interface(device, &IID_IDXGIDevice, TRUE, FALSE);
2118 check_interface(device, &IID_IDXGIDevice1, TRUE, FALSE);
2119 check_interface(device, &IID_ID3D10Multithread, TRUE, TRUE); /* Not available on all Windows versions. */
2120 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
2121 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
2122 check_interface(device, &IID_ID3D11InfoQueue, enable_debug_layer, FALSE);
2124 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
2125 ok(SUCCEEDED(hr), "Device should implement IDXGIDevice.\n");
2126 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter, (void **)&dxgi_adapter);
2127 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter.\n");
2128 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&iface);
2129 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory.\n");
2130 IUnknown_Release(iface);
2131 IDXGIAdapter_Release(dxgi_adapter);
2132 hr = IDXGIDevice_GetParent(dxgi_device, &IID_IDXGIAdapter1, (void **)&dxgi_adapter);
2133 ok(SUCCEEDED(hr), "Device parent should implement IDXGIAdapter1.\n");
2134 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory1, (void **)&iface);
2135 ok(SUCCEEDED(hr), "Adapter parent should implement IDXGIFactory1.\n");
2136 IUnknown_Release(iface);
2137 IDXGIAdapter_Release(dxgi_adapter);
2138 IDXGIDevice_Release(dxgi_device);
2140 refcount = ID3D11Device_Release(device);
2141 ok(!refcount, "Device has %u references left.\n", refcount);
2143 device_desc.feature_level = &feature_level;
2144 device_desc.flags = D3D11_CREATE_DEVICE_DEBUG;
2145 if (!(device = create_device(&device_desc)))
2147 skip("Failed to create debug device for feature level %#x.\n", feature_level);
2148 return;
2151 todo_wine check_interface(device, &IID_ID3D11InfoQueue, TRUE, FALSE);
2153 refcount = ID3D11Device_Release(device);
2154 ok(!refcount, "Device has %u references left.\n", refcount);
2157 static void test_immediate_context(void)
2159 ID3D11DeviceContext *immediate_context, *previous_immediate_context;
2160 ULONG expected_refcount, refcount;
2161 ID3D11CommandList *command_list;
2162 ID3D11Multithread *multithread;
2163 ID3D11Buffer *buffer[2];
2164 ID3D11Device *device;
2165 unsigned int flags;
2166 BOOL enabled;
2167 HRESULT hr;
2169 static const unsigned int buffer_contents[] =
2171 0x11111111, 0x22222222, 0x33333333, 0x44444444,
2172 0x55555555, 0x66666666, 0x77777777, 0x88888888,
2175 if (!(device = create_device(NULL)))
2177 skip("Failed to create device.\n");
2178 return;
2181 expected_refcount = get_refcount(device) + 1;
2182 ID3D11Device_GetImmediateContext(device, &immediate_context);
2183 refcount = get_refcount(device);
2184 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
2185 previous_immediate_context = immediate_context;
2187 ID3D11Device_GetImmediateContext(device, &immediate_context);
2188 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
2189 refcount = get_refcount(device);
2190 ok(refcount == expected_refcount, "Got unexpected refcount %u.\n", refcount);
2192 refcount = ID3D11DeviceContext_Release(previous_immediate_context);
2193 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2194 refcount = ID3D11DeviceContext_Release(immediate_context);
2195 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2197 ID3D11Device_GetImmediateContext(device, &immediate_context);
2198 ok(immediate_context == previous_immediate_context, "Got different immediate device context objects.\n");
2199 refcount = ID3D11DeviceContext_Release(immediate_context);
2200 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2202 ID3D11Device_GetImmediateContext(device, &immediate_context);
2203 expected_refcount = get_refcount(immediate_context) + 1;
2204 hr = ID3D11DeviceContext_QueryInterface(immediate_context, &IID_ID3D11Multithread, (void **)&multithread);
2205 if (hr == E_NOINTERFACE)
2207 win_skip("ID3D11Multithread is not supported.\n");
2208 goto done;
2210 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
2212 refcount = get_refcount(immediate_context);
2213 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2215 expected_refcount = refcount;
2216 refcount = get_refcount(multithread);
2217 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2219 enabled = ID3D11Multithread_GetMultithreadProtected(multithread);
2220 todo_wine ok(!enabled, "Multithread protection is %#x.\n", enabled);
2222 ID3D11Multithread_Release(multithread);
2224 ID3D11Device_GetImmediateContext(device, &immediate_context);
2226 flags = ID3D11DeviceContext_GetContextFlags(immediate_context);
2227 ok(!flags, "Got unexpected flags %#x.\n", flags);
2229 hr = ID3D11DeviceContext_FinishCommandList(immediate_context, FALSE, &command_list);
2230 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
2232 buffer[0] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 16, &buffer_contents[0]);
2233 buffer[1] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 16, &buffer_contents[4]);
2235 ID3D11DeviceContext_CopyResource(immediate_context, (ID3D11Resource *)buffer[1], (ID3D11Resource *)buffer[0]);
2237 hr = ID3D11DeviceContext_FinishCommandList(immediate_context, FALSE, &command_list);
2238 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
2240 ID3D11Buffer_Release(buffer[1]);
2241 ID3D11Buffer_Release(buffer[0]);
2242 ID3D11DeviceContext_Release(immediate_context);
2244 done:
2245 refcount = ID3D11DeviceContext_Release(immediate_context);
2246 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2247 refcount = ID3D11Device_Release(device);
2248 ok(!refcount, "Device has %u references left.\n", refcount);
2251 static void test_create_deferred_context(void)
2253 ULONG refcount, expected_refcount;
2254 struct device_desc device_desc;
2255 ID3D11DeviceContext *context;
2256 ID3D11Device *device;
2257 HRESULT hr;
2259 device_desc.feature_level = NULL;
2260 device_desc.flags = D3D11_CREATE_DEVICE_SINGLETHREADED;
2261 if (!(device = create_device(&device_desc)))
2263 skip("Failed to create single-threaded device.\n");
2264 return;
2267 hr = ID3D11Device_CreateDeferredContext(device, 0, &context);
2268 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Failed to create deferred context, hr %#x.\n", hr);
2269 if (hr == S_OK)
2270 ID3D11DeviceContext_Release(context);
2272 refcount = ID3D11Device_Release(device);
2273 ok(!refcount, "Device has %u references left.\n", refcount);
2275 if (!(device = create_device(NULL)))
2277 skip("Failed to create device.\n");
2278 return;
2281 expected_refcount = get_refcount(device) + 1;
2282 hr = ID3D11Device_CreateDeferredContext(device, 0, &context);
2283 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
2284 refcount = get_refcount(device);
2285 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
2286 refcount = get_refcount(context);
2287 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
2289 check_interface(context, &IID_IUnknown, TRUE, FALSE);
2290 check_interface(context, &IID_ID3D11DeviceChild, TRUE, FALSE);
2291 check_interface(context, &IID_ID3D11DeviceContext, TRUE, FALSE);
2292 check_interface(context, &IID_ID3D11Multithread, FALSE, FALSE);
2294 refcount = ID3D11DeviceContext_Release(context);
2295 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
2297 refcount = ID3D11Device_Release(device);
2298 ok(!refcount, "Device has %u references left.\n", refcount);
2301 static void test_create_texture1d(void)
2303 ULONG refcount, expected_refcount;
2304 D3D11_SUBRESOURCE_DATA data = {0};
2305 ID3D11Device *device, *tmp;
2306 D3D11_TEXTURE1D_DESC desc;
2307 ID3D11Texture1D *texture;
2308 unsigned int i;
2309 HRESULT hr;
2311 if (!(device = create_device(NULL)))
2313 skip("Failed to create device.\n");
2314 return;
2317 desc.Width = 512;
2318 desc.MipLevels = 1;
2319 desc.ArraySize = 1;
2320 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2321 desc.Usage = D3D11_USAGE_DEFAULT;
2322 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2323 desc.CPUAccessFlags = 0;
2324 desc.MiscFlags = 0;
2326 hr = ID3D11Device_CreateTexture1D(device, &desc, &data, &texture);
2327 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2329 expected_refcount = get_refcount(device) + 1;
2330 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2331 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2332 refcount = get_refcount(device);
2333 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2334 tmp = NULL;
2335 expected_refcount = refcount + 1;
2336 ID3D11Texture1D_GetDevice(texture, &tmp);
2337 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2338 refcount = get_refcount(device);
2339 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2340 ID3D11Device_Release(tmp);
2342 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2343 ID3D11Texture1D_Release(texture);
2345 desc.MipLevels = 0;
2346 expected_refcount = get_refcount(device) + 1;
2347 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2348 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2349 refcount = get_refcount(device);
2350 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2351 tmp = NULL;
2352 expected_refcount = refcount + 1;
2353 ID3D11Texture1D_GetDevice(texture, &tmp);
2354 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2355 refcount = get_refcount(device);
2356 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2357 ID3D11Device_Release(tmp);
2359 ID3D11Texture1D_GetDesc(texture, &desc);
2360 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2361 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2362 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2363 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2364 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2365 ok(desc.BindFlags == D3D11_BIND_SHADER_RESOURCE, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
2366 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
2367 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
2369 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2370 ID3D11Texture1D_Release(texture);
2372 desc.MipLevels = 1;
2373 desc.ArraySize = 2;
2374 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2375 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2377 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2378 ID3D11Texture1D_Release(texture);
2380 for (i = 0; i < 4; ++i)
2382 desc.ArraySize = i;
2383 desc.Format = DXGI_FORMAT_R32G32B32A32_TYPELESS;
2384 desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
2385 desc.MiscFlags = 0;
2386 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2387 ok(hr == (i ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
2388 if (SUCCEEDED(hr))
2389 ID3D11Texture1D_Release(texture);
2392 refcount = ID3D11Device_Release(device);
2393 ok(!refcount, "Device has %u references left.\n", refcount);
2396 static void test_texture1d_interfaces(void)
2398 ID3D10Texture1D *d3d10_texture;
2399 D3D11_TEXTURE1D_DESC desc;
2400 ID3D11Texture1D *texture;
2401 ID3D11Device *device;
2402 unsigned int i;
2403 ULONG refcount;
2404 HRESULT hr;
2406 static const struct test
2408 BOOL implements_d3d10_interfaces;
2409 UINT bind_flags;
2410 UINT misc_flags;
2411 UINT expected_bind_flags;
2412 UINT expected_misc_flags;
2414 desc_conversion_tests[] =
2417 TRUE,
2418 D3D11_BIND_SHADER_RESOURCE, 0,
2419 D3D10_BIND_SHADER_RESOURCE, 0
2422 TRUE,
2423 D3D11_BIND_UNORDERED_ACCESS, 0,
2424 D3D11_BIND_UNORDERED_ACCESS, 0
2427 FALSE,
2428 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2429 0, 0
2432 TRUE,
2433 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2434 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2438 if (!(device = create_device(NULL)))
2440 skip("Failed to create ID3D11Device, skipping tests.\n");
2441 return;
2444 desc.Width = 512;
2445 desc.MipLevels = 0;
2446 desc.ArraySize = 1;
2447 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2448 desc.Usage = D3D11_USAGE_DEFAULT;
2449 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2450 desc.CPUAccessFlags = 0;
2451 desc.MiscFlags = 0;
2453 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2454 ok(SUCCEEDED(hr), "Failed to create a 1d texture, hr %#x.\n", hr);
2455 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2456 hr = check_interface(texture, &IID_ID3D10Texture1D, TRUE, TRUE); /* Not available on all Windows versions. */
2457 ID3D11Texture1D_Release(texture);
2458 if (FAILED(hr))
2460 win_skip("1D textures do not implement ID3D10Texture1D, skipping tests.\n");
2461 ID3D11Device_Release(device);
2462 return;
2465 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2467 const struct test *current = &desc_conversion_tests[i];
2468 D3D10_TEXTURE1D_DESC d3d10_desc;
2469 ID3D10Device *d3d10_device;
2471 desc.Width = 512;
2472 desc.MipLevels = 1;
2473 desc.ArraySize = 1;
2474 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2475 desc.Usage = D3D11_USAGE_DEFAULT;
2476 desc.BindFlags = current->bind_flags;
2477 desc.CPUAccessFlags = 0;
2478 desc.MiscFlags = current->misc_flags;
2480 hr = ID3D11Device_CreateTexture1D(device, &desc, NULL, &texture);
2481 /* Shared resources are not supported by REF and WARP devices. */
2482 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2483 "Test %u: Failed to create a 1d texture, hr %#x.\n", i, hr);
2484 if (FAILED(hr))
2486 win_skip("Failed to create ID3D11Texture1D, skipping test %u.\n", i);
2487 continue;
2490 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2492 hr = ID3D11Texture1D_QueryInterface(texture, &IID_ID3D10Texture1D, (void **)&d3d10_texture);
2493 ID3D11Texture1D_Release(texture);
2495 if (current->implements_d3d10_interfaces)
2497 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture1D.\n", i);
2499 else
2501 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture1D.\n", i);
2502 if (SUCCEEDED(hr)) ID3D10Texture1D_Release(d3d10_texture);
2503 continue;
2506 ID3D10Texture1D_GetDesc(d3d10_texture, &d3d10_desc);
2508 ok(d3d10_desc.Width == desc.Width,
2509 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2510 ok(d3d10_desc.MipLevels == desc.MipLevels,
2511 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2512 ok(d3d10_desc.ArraySize == desc.ArraySize,
2513 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2514 ok(d3d10_desc.Format == desc.Format,
2515 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2516 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2517 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2518 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2519 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2520 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2521 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2523 d3d10_device = (ID3D10Device *)0xdeadbeef;
2524 ID3D10Texture1D_GetDevice(d3d10_texture, &d3d10_device);
2525 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2526 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2528 ID3D10Texture1D_Release(d3d10_texture);
2531 refcount = ID3D11Device_Release(device);
2532 ok(!refcount, "Device has %u references left.\n", refcount);
2535 static void test_create_texture2d(void)
2537 ULONG refcount, expected_refcount;
2538 D3D11_SUBRESOURCE_DATA data = {0};
2539 D3D_FEATURE_LEVEL feature_level;
2540 ID3D11Device *device, *tmp;
2541 D3D11_TEXTURE2D_DESC desc;
2542 ID3D11Texture2D *texture;
2543 UINT quality_level_count;
2544 unsigned int i;
2545 HRESULT hr;
2547 static const struct
2549 DXGI_FORMAT format;
2550 UINT array_size;
2551 D3D11_BIND_FLAG bind_flags;
2552 UINT misc_flags;
2553 BOOL succeeds;
2554 BOOL todo;
2556 tests[] =
2558 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
2559 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
2560 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
2561 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
2562 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2563 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2564 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2565 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 3, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2566 FALSE, FALSE},
2567 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2568 FALSE, FALSE},
2569 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 5, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2570 FALSE, FALSE},
2571 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 6, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2572 TRUE, FALSE},
2573 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 7, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2574 TRUE, FALSE},
2575 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 10, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2576 TRUE, FALSE},
2577 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 12, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2578 TRUE, FALSE},
2579 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 0, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2580 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2581 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 2, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2582 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 9, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2583 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2584 {DXGI_FORMAT_R32G32B32A32_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2585 {DXGI_FORMAT_R32G32B32A32_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2586 {DXGI_FORMAT_R32G32B32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2587 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2588 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2589 {DXGI_FORMAT_R32G32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2590 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2591 {DXGI_FORMAT_R32G8X24_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2592 {DXGI_FORMAT_X32_TYPELESS_G8X24_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2593 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2594 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2595 {DXGI_FORMAT_R16G16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2596 {DXGI_FORMAT_R16G16_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2597 {DXGI_FORMAT_R16G16_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2598 {DXGI_FORMAT_R32_TYPELESS, 0, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, FALSE},
2599 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2600 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2601 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
2602 TRUE, FALSE},
2603 {DXGI_FORMAT_R32_TYPELESS, 9, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_TEXTURECUBE,
2604 TRUE, FALSE},
2605 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2606 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_RENDER_TARGET | D3D11_BIND_DEPTH_STENCIL, 0,
2607 FALSE, TRUE},
2608 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2609 {DXGI_FORMAT_R32_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_UNORDERED_ACCESS, 0,
2610 FALSE, TRUE},
2611 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_VERTEX_BUFFER, 0, FALSE, TRUE},
2612 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_INDEX_BUFFER, 0, FALSE, TRUE},
2613 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_CONSTANT_BUFFER, 0, FALSE, TRUE},
2614 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2615 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2616 {DXGI_FORMAT_R24G8_TYPELESS, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2617 {DXGI_FORMAT_X24_TYPELESS_G8_UINT, 1, D3D11_BIND_UNORDERED_ACCESS, 0, FALSE, TRUE},
2618 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2619 {DXGI_FORMAT_R8G8_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2620 {DXGI_FORMAT_R8G8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2621 {DXGI_FORMAT_R8G8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2622 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2623 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2624 {DXGI_FORMAT_R16_TYPELESS, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2625 {DXGI_FORMAT_R16_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2626 {DXGI_FORMAT_R16_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2627 {DXGI_FORMAT_R8_TYPELESS, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2628 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2629 {DXGI_FORMAT_R8G8B8A8_UNORM, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2630 {DXGI_FORMAT_R8G8B8A8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2631 {DXGI_FORMAT_R8G8B8A8_SNORM, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2632 {DXGI_FORMAT_R8G8B8A8_SINT, 1, D3D11_BIND_RENDER_TARGET, 0, TRUE, FALSE},
2633 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
2634 {DXGI_FORMAT_D24_UNORM_S8_UINT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2635 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE, 0, FALSE, TRUE},
2636 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL, 0,
2637 FALSE, TRUE},
2638 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2639 {DXGI_FORMAT_D32_FLOAT, 1, D3D11_BIND_DEPTH_STENCIL, 0, TRUE, FALSE},
2640 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_SHADER_RESOURCE, 0, TRUE, FALSE},
2641 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_RENDER_TARGET, 0, FALSE, FALSE},
2642 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 1, D3D11_BIND_DEPTH_STENCIL, 0, FALSE, FALSE},
2645 if (!(device = create_device(NULL)))
2647 skip("Failed to create device.\n");
2648 return;
2651 feature_level = ID3D11Device_GetFeatureLevel(device);
2653 desc.Width = 512;
2654 desc.Height = 512;
2655 desc.MipLevels = 1;
2656 desc.ArraySize = 1;
2657 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2658 desc.SampleDesc.Count = 1;
2659 desc.SampleDesc.Quality = 0;
2660 desc.Usage = D3D11_USAGE_DEFAULT;
2661 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2662 desc.CPUAccessFlags = 0;
2663 desc.MiscFlags = 0;
2665 hr = ID3D11Device_CreateTexture2D(device, &desc, &data, &texture);
2666 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2668 expected_refcount = get_refcount(device) + 1;
2669 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2670 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2671 refcount = get_refcount(device);
2672 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2673 tmp = NULL;
2674 expected_refcount = refcount + 1;
2675 ID3D11Texture2D_GetDevice(texture, &tmp);
2676 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2677 refcount = get_refcount(device);
2678 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2679 ID3D11Device_Release(tmp);
2681 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2682 ID3D11Texture2D_Release(texture);
2684 desc.MipLevels = 0;
2685 expected_refcount = get_refcount(device) + 1;
2686 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2687 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2688 refcount = get_refcount(device);
2689 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2690 tmp = NULL;
2691 expected_refcount = refcount + 1;
2692 ID3D11Texture2D_GetDevice(texture, &tmp);
2693 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2694 refcount = get_refcount(device);
2695 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2696 ID3D11Device_Release(tmp);
2698 ID3D11Texture2D_GetDesc(texture, &desc);
2699 ok(desc.Width == 512, "Got unexpected Width %u.\n", desc.Width);
2700 ok(desc.Height == 512, "Got unexpected Height %u.\n", desc.Height);
2701 ok(desc.MipLevels == 10, "Got unexpected MipLevels %u.\n", desc.MipLevels);
2702 ok(desc.ArraySize == 1, "Got unexpected ArraySize %u.\n", desc.ArraySize);
2703 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
2704 ok(desc.SampleDesc.Count == 1, "Got unexpected SampleDesc.Count %u.\n", desc.SampleDesc.Count);
2705 ok(desc.SampleDesc.Quality == 0, "Got unexpected SampleDesc.Quality %u.\n", desc.SampleDesc.Quality);
2706 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
2707 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %#x.\n", desc.BindFlags);
2708 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %#x.\n", desc.CPUAccessFlags);
2709 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %#x.\n", desc.MiscFlags);
2711 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2712 ID3D11Texture2D_Release(texture);
2714 desc.MipLevels = 1;
2715 desc.ArraySize = 2;
2716 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2717 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2719 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2720 ID3D11Texture2D_Release(texture);
2722 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_level_count);
2723 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
2724 desc.ArraySize = 1;
2725 desc.SampleDesc.Count = 2;
2726 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2727 if (quality_level_count)
2729 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
2730 ID3D11Texture2D_Release(texture);
2731 desc.SampleDesc.Quality = quality_level_count;
2732 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2734 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2736 /* We assume 15 samples multisampling is never supported in practice. */
2737 desc.SampleDesc.Count = 15;
2738 desc.SampleDesc.Quality = 0;
2739 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2740 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2742 desc.SampleDesc.Count = 1;
2743 for (i = 0; i < ARRAY_SIZE(tests); ++i)
2745 HRESULT expected_hr = tests[i].succeeds ? S_OK : E_INVALIDARG;
2746 BOOL todo = tests[i].todo;
2748 if (feature_level < D3D_FEATURE_LEVEL_10_1
2749 && (tests[i].misc_flags & D3D11_RESOURCE_MISC_TEXTURECUBE)
2750 && tests[i].array_size > 6)
2752 expected_hr = E_INVALIDARG;
2753 todo = TRUE;
2756 desc.ArraySize = tests[i].array_size;
2757 desc.Format = tests[i].format;
2758 desc.BindFlags = tests[i].bind_flags;
2759 desc.MiscFlags = tests[i].misc_flags;
2760 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2762 todo_wine_if(todo)
2763 ok(hr == expected_hr, "Test %u: Got unexpected hr %#x (format %#x).\n",
2764 i, hr, desc.Format);
2766 if (SUCCEEDED(hr))
2767 ID3D11Texture2D_Release(texture);
2770 refcount = ID3D11Device_Release(device);
2771 ok(!refcount, "Device has %u references left.\n", refcount);
2774 static void test_texture2d_interfaces(void)
2776 ID3D10Texture2D *d3d10_texture;
2777 D3D11_TEXTURE2D_DESC desc;
2778 ID3D11Texture2D *texture;
2779 ID3D11Device *device;
2780 unsigned int i;
2781 ULONG refcount;
2782 HRESULT hr;
2784 static const struct test
2786 BOOL implements_d3d10_interfaces;
2787 UINT bind_flags;
2788 UINT misc_flags;
2789 UINT expected_bind_flags;
2790 UINT expected_misc_flags;
2792 desc_conversion_tests[] =
2795 TRUE,
2796 D3D11_BIND_SHADER_RESOURCE, 0,
2797 D3D10_BIND_SHADER_RESOURCE, 0
2800 TRUE,
2801 D3D11_BIND_UNORDERED_ACCESS, 0,
2802 D3D11_BIND_UNORDERED_ACCESS, 0
2805 FALSE,
2806 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
2807 0, 0
2810 TRUE,
2811 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
2812 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2815 TRUE,
2816 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE,
2817 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
2821 if (!(device = create_device(NULL)))
2823 skip("Failed to create ID3D11Device, skipping tests.\n");
2824 return;
2827 desc.Width = 512;
2828 desc.Height = 512;
2829 desc.MipLevels = 0;
2830 desc.ArraySize = 1;
2831 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2832 desc.SampleDesc.Count = 1;
2833 desc.SampleDesc.Quality = 0;
2834 desc.Usage = D3D11_USAGE_DEFAULT;
2835 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2836 desc.CPUAccessFlags = 0;
2837 desc.MiscFlags = 0;
2839 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2840 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
2841 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2842 hr = check_interface(texture, &IID_ID3D10Texture2D, TRUE, TRUE); /* Not available on all Windows versions. */
2843 ID3D11Texture2D_Release(texture);
2844 if (FAILED(hr))
2846 win_skip("2D textures do not implement ID3D10Texture2D, skipping tests.\n");
2847 ID3D11Device_Release(device);
2848 return;
2851 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
2853 const struct test *current = &desc_conversion_tests[i];
2854 D3D10_TEXTURE2D_DESC d3d10_desc;
2855 ID3D10Device *d3d10_device;
2857 desc.Width = 512;
2858 desc.Height = 512;
2859 desc.MipLevels = 1;
2860 desc.ArraySize = 1;
2861 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2862 desc.SampleDesc.Count = 1;
2863 desc.SampleDesc.Quality = 0;
2864 desc.Usage = D3D11_USAGE_DEFAULT;
2865 desc.BindFlags = current->bind_flags;
2866 desc.CPUAccessFlags = 0;
2867 desc.MiscFlags = current->misc_flags;
2869 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
2870 /* Shared resources are not supported by REF and WARP devices. */
2871 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
2872 "Test %u: Failed to create a 2d texture, hr %#x.\n", i, hr);
2873 if (FAILED(hr))
2875 win_skip("Failed to create ID3D11Texture2D, skipping test %u.\n", i);
2876 continue;
2879 check_interface(texture, &IID_IDXGISurface, TRUE, FALSE);
2881 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
2882 ID3D11Texture2D_Release(texture);
2884 if (current->implements_d3d10_interfaces)
2886 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture2D.\n", i);
2888 else
2890 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture2D.\n", i);
2891 if (SUCCEEDED(hr)) ID3D10Texture2D_Release(d3d10_texture);
2892 continue;
2895 ID3D10Texture2D_GetDesc(d3d10_texture, &d3d10_desc);
2897 ok(d3d10_desc.Width == desc.Width,
2898 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
2899 ok(d3d10_desc.Height == desc.Height,
2900 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
2901 ok(d3d10_desc.MipLevels == desc.MipLevels,
2902 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
2903 ok(d3d10_desc.ArraySize == desc.ArraySize,
2904 "Test %u: Got unexpected ArraySize %u.\n", i, d3d10_desc.ArraySize);
2905 ok(d3d10_desc.Format == desc.Format,
2906 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
2907 ok(d3d10_desc.SampleDesc.Count == desc.SampleDesc.Count,
2908 "Test %u: Got unexpected SampleDesc.Count %u.\n", i, d3d10_desc.SampleDesc.Count);
2909 ok(d3d10_desc.SampleDesc.Quality == desc.SampleDesc.Quality,
2910 "Test %u: Got unexpected SampleDesc.Quality %u.\n", i, d3d10_desc.SampleDesc.Quality);
2911 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
2912 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
2913 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
2914 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
2915 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
2916 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
2917 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
2918 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
2920 d3d10_device = (ID3D10Device *)0xdeadbeef;
2921 ID3D10Texture2D_GetDevice(d3d10_texture, &d3d10_device);
2922 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
2923 if (d3d10_device) ID3D10Device_Release(d3d10_device);
2925 ID3D10Texture2D_Release(d3d10_texture);
2928 refcount = ID3D11Device_Release(device);
2929 ok(!refcount, "Device has %u references left.\n", refcount);
2932 static void test_create_texture3d(void)
2934 ULONG refcount, expected_refcount;
2935 D3D11_SUBRESOURCE_DATA data = {0};
2936 ID3D11Device *device, *tmp;
2937 D3D11_TEXTURE3D_DESC desc;
2938 ID3D11Texture3D *texture;
2939 unsigned int i;
2940 HRESULT hr;
2942 static const struct
2944 DXGI_FORMAT format;
2945 D3D11_BIND_FLAG bind_flags;
2946 BOOL succeeds;
2947 BOOL todo;
2949 tests[] =
2951 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_VERTEX_BUFFER, FALSE, TRUE},
2952 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_INDEX_BUFFER, FALSE, TRUE},
2953 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_CONSTANT_BUFFER, FALSE, TRUE},
2954 {DXGI_FORMAT_R32G32B32A32_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2955 {DXGI_FORMAT_R16G16B16A16_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2956 {DXGI_FORMAT_R10G10B10A2_TYPELESS, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2957 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2958 {DXGI_FORMAT_D24_UNORM_S8_UINT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2959 {DXGI_FORMAT_D32_FLOAT, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2960 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_SHADER_RESOURCE, TRUE, FALSE},
2961 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_RENDER_TARGET, FALSE, FALSE},
2962 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, D3D11_BIND_DEPTH_STENCIL, FALSE, FALSE},
2965 if (!(device = create_device(NULL)))
2967 skip("Failed to create ID3D11Device, skipping tests.\n");
2968 return;
2971 desc.Width = 64;
2972 desc.Height = 64;
2973 desc.Depth = 64;
2974 desc.MipLevels = 1;
2975 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
2976 desc.Usage = D3D11_USAGE_DEFAULT;
2977 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
2978 desc.CPUAccessFlags = 0;
2979 desc.MiscFlags = 0;
2981 hr = ID3D11Device_CreateTexture3D(device, &desc, &data, &texture);
2982 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
2984 expected_refcount = get_refcount(device) + 1;
2985 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
2986 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
2987 refcount = get_refcount(device);
2988 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
2989 tmp = NULL;
2990 expected_refcount = refcount + 1;
2991 ID3D11Texture3D_GetDevice(texture, &tmp);
2992 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
2993 refcount = get_refcount(device);
2994 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
2995 ID3D11Device_Release(tmp);
2997 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
2998 ID3D11Texture3D_Release(texture);
3000 desc.MipLevels = 0;
3001 expected_refcount = get_refcount(device) + 1;
3002 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3003 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
3004 refcount = get_refcount(device);
3005 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3006 tmp = NULL;
3007 expected_refcount = refcount + 1;
3008 ID3D11Texture3D_GetDevice(texture, &tmp);
3009 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3010 refcount = get_refcount(device);
3011 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3012 ID3D11Device_Release(tmp);
3014 ID3D11Texture3D_GetDesc(texture, &desc);
3015 ok(desc.Width == 64, "Got unexpected Width %u.\n", desc.Width);
3016 ok(desc.Height == 64, "Got unexpected Height %u.\n", desc.Height);
3017 ok(desc.Depth == 64, "Got unexpected Depth %u.\n", desc.Depth);
3018 ok(desc.MipLevels == 7, "Got unexpected MipLevels %u.\n", desc.MipLevels);
3019 ok(desc.Format == DXGI_FORMAT_R8G8B8A8_UNORM, "Got unexpected Format %#x.\n", desc.Format);
3020 ok(desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected Usage %u.\n", desc.Usage);
3021 ok(desc.BindFlags == D3D11_BIND_RENDER_TARGET, "Got unexpected BindFlags %u.\n", desc.BindFlags);
3022 ok(desc.CPUAccessFlags == 0, "Got unexpected CPUAccessFlags %u.\n", desc.CPUAccessFlags);
3023 ok(desc.MiscFlags == 0, "Got unexpected MiscFlags %u.\n", desc.MiscFlags);
3025 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3026 ID3D11Texture3D_Release(texture);
3028 desc.MipLevels = 1;
3029 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3031 desc.Format = tests[i].format;
3032 desc.BindFlags = tests[i].bind_flags;
3033 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3035 todo_wine_if(tests[i].todo)
3036 ok(hr == (tests[i].succeeds ? S_OK : E_INVALIDARG), "Test %u: Got unexpected hr %#x.\n", i, hr);
3038 if (SUCCEEDED(hr))
3039 ID3D11Texture3D_Release(texture);
3042 refcount = ID3D11Device_Release(device);
3043 ok(!refcount, "Device has %u references left.\n", refcount);
3046 static void test_texture3d_interfaces(void)
3048 ID3D10Texture3D *d3d10_texture;
3049 D3D11_TEXTURE3D_DESC desc;
3050 ID3D11Texture3D *texture;
3051 ID3D11Device *device;
3052 unsigned int i;
3053 ULONG refcount;
3054 HRESULT hr;
3056 static const struct test
3058 BOOL implements_d3d10_interfaces;
3059 UINT bind_flags;
3060 UINT misc_flags;
3061 UINT expected_bind_flags;
3062 UINT expected_misc_flags;
3064 desc_conversion_tests[] =
3067 TRUE,
3068 D3D11_BIND_SHADER_RESOURCE, 0,
3069 D3D10_BIND_SHADER_RESOURCE, 0
3072 TRUE,
3073 D3D11_BIND_UNORDERED_ACCESS, 0,
3074 D3D11_BIND_UNORDERED_ACCESS, 0
3077 FALSE,
3078 0, D3D11_RESOURCE_MISC_RESOURCE_CLAMP,
3079 0, 0
3082 TRUE,
3083 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX,
3084 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
3088 if (!(device = create_device(NULL)))
3090 skip("Failed to create ID3D11Device.\n");
3091 return;
3094 desc.Width = 64;
3095 desc.Height = 64;
3096 desc.Depth = 64;
3097 desc.MipLevels = 0;
3098 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3099 desc.Usage = D3D11_USAGE_DEFAULT;
3100 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3101 desc.CPUAccessFlags = 0;
3102 desc.MiscFlags = 0;
3104 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3105 ok(SUCCEEDED(hr), "Failed to create a 3d texture, hr %#x.\n", hr);
3106 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3107 hr = check_interface(texture, &IID_ID3D10Texture3D, TRUE, TRUE); /* Not available on all Windows versions. */
3108 ID3D11Texture3D_Release(texture);
3109 if (FAILED(hr))
3111 win_skip("3D textures do not implement ID3D10Texture3D.\n");
3112 ID3D11Device_Release(device);
3113 return;
3116 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
3118 const struct test *current = &desc_conversion_tests[i];
3119 D3D10_TEXTURE3D_DESC d3d10_desc;
3120 ID3D10Device *d3d10_device;
3122 desc.Width = 64;
3123 desc.Height = 64;
3124 desc.Depth = 64;
3125 desc.MipLevels = 1;
3126 desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
3127 desc.Usage = D3D11_USAGE_DEFAULT;
3128 desc.BindFlags = current->bind_flags;
3129 desc.CPUAccessFlags = 0;
3130 desc.MiscFlags = current->misc_flags;
3132 hr = ID3D11Device_CreateTexture3D(device, &desc, NULL, &texture);
3133 /* Shared resources are not supported by REF and WARP devices. */
3134 ok(SUCCEEDED(hr) || broken(hr == E_OUTOFMEMORY),
3135 "Test %u: Failed to create a 3d texture, hr %#x.\n", i, hr);
3136 if (FAILED(hr))
3138 win_skip("Failed to create ID3D11Texture3D, skipping test %u.\n", i);
3139 continue;
3142 check_interface(texture, &IID_IDXGISurface, FALSE, FALSE);
3144 hr = ID3D11Texture3D_QueryInterface(texture, &IID_ID3D10Texture3D, (void **)&d3d10_texture);
3145 ID3D11Texture3D_Release(texture);
3147 if (current->implements_d3d10_interfaces)
3149 ok(SUCCEEDED(hr), "Test %u: Texture should implement ID3D10Texture3D.\n", i);
3151 else
3153 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Texture should not implement ID3D10Texture3D.\n", i);
3154 if (SUCCEEDED(hr)) ID3D10Texture3D_Release(d3d10_texture);
3155 continue;
3158 ID3D10Texture3D_GetDesc(d3d10_texture, &d3d10_desc);
3160 ok(d3d10_desc.Width == desc.Width,
3161 "Test %u: Got unexpected Width %u.\n", i, d3d10_desc.Width);
3162 ok(d3d10_desc.Height == desc.Height,
3163 "Test %u: Got unexpected Height %u.\n", i, d3d10_desc.Height);
3164 ok(d3d10_desc.Depth == desc.Depth,
3165 "Test %u: Got unexpected Depth %u.\n", i, d3d10_desc.Depth);
3166 ok(d3d10_desc.MipLevels == desc.MipLevels,
3167 "Test %u: Got unexpected MipLevels %u.\n", i, d3d10_desc.MipLevels);
3168 ok(d3d10_desc.Format == desc.Format,
3169 "Test %u: Got unexpected Format %u.\n", i, d3d10_desc.Format);
3170 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3171 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3172 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3173 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3174 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3175 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3176 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3177 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3179 d3d10_device = (ID3D10Device *)0xdeadbeef;
3180 ID3D10Texture3D_GetDevice(d3d10_texture, &d3d10_device);
3181 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3182 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3184 ID3D10Texture3D_Release(d3d10_texture);
3187 refcount = ID3D11Device_Release(device);
3188 ok(!refcount, "Device has %u references left.\n", refcount);
3191 static void test_create_buffer(void)
3193 ID3D10Buffer *d3d10_buffer;
3194 HRESULT expected_hr, hr;
3195 D3D11_BUFFER_DESC desc;
3196 ID3D11Buffer *buffer;
3197 ID3D11Device *device;
3198 unsigned int i;
3199 ULONG refcount;
3201 static const struct test
3203 BOOL succeeds;
3204 BOOL implements_d3d10_interfaces;
3205 UINT bind_flags;
3206 UINT misc_flags;
3207 UINT structure_stride;
3208 UINT expected_bind_flags;
3209 UINT expected_misc_flags;
3211 tests[] =
3214 TRUE, TRUE,
3215 D3D11_BIND_VERTEX_BUFFER, 0, 0,
3216 D3D10_BIND_VERTEX_BUFFER, 0
3219 TRUE, TRUE,
3220 D3D11_BIND_INDEX_BUFFER, 0, 0,
3221 D3D10_BIND_INDEX_BUFFER, 0
3224 TRUE, TRUE,
3225 D3D11_BIND_CONSTANT_BUFFER, 0, 0,
3226 D3D10_BIND_CONSTANT_BUFFER, 0
3229 TRUE, TRUE,
3230 D3D11_BIND_SHADER_RESOURCE, 0, 0,
3231 D3D10_BIND_SHADER_RESOURCE, 0
3234 TRUE, TRUE,
3235 D3D11_BIND_STREAM_OUTPUT, 0, 0,
3236 D3D10_BIND_STREAM_OUTPUT, 0
3239 TRUE, TRUE,
3240 D3D11_BIND_RENDER_TARGET, 0, 0,
3241 D3D10_BIND_RENDER_TARGET, 0
3244 TRUE, TRUE,
3245 D3D11_BIND_UNORDERED_ACCESS, 0, 0,
3246 D3D11_BIND_UNORDERED_ACCESS, 0
3249 TRUE, TRUE,
3250 0, D3D11_RESOURCE_MISC_SHARED, 0,
3251 0, D3D10_RESOURCE_MISC_SHARED
3254 TRUE, TRUE,
3255 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS, 0,
3256 0, 0
3259 FALSE, FALSE,
3260 D3D11_BIND_VERTEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3263 FALSE, FALSE,
3264 D3D11_BIND_INDEX_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3267 FALSE, FALSE,
3268 D3D11_BIND_CONSTANT_BUFFER, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3271 TRUE, TRUE,
3272 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3273 D3D10_BIND_SHADER_RESOURCE, 0
3276 FALSE, FALSE,
3277 D3D11_BIND_STREAM_OUTPUT, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3280 FALSE, FALSE,
3281 D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3284 TRUE, TRUE,
3285 D3D11_BIND_UNORDERED_ACCESS, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3286 D3D11_BIND_UNORDERED_ACCESS, 0
3289 FALSE, FALSE,
3290 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS, 0,
3292 /* Structured buffers do not implement ID3D10Buffer. */
3294 TRUE, FALSE,
3295 0, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3298 TRUE, FALSE,
3299 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3302 FALSE, FALSE,
3303 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, ~0u,
3306 FALSE, FALSE,
3307 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 0,
3310 FALSE, FALSE,
3311 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1,
3314 FALSE, FALSE,
3315 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 2,
3318 FALSE, FALSE,
3319 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 3,
3322 TRUE, FALSE,
3323 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 4,
3326 FALSE, FALSE,
3327 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 5,
3330 TRUE, FALSE,
3331 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 8,
3334 TRUE, FALSE,
3335 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 512,
3338 FALSE, FALSE,
3339 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 513,
3342 TRUE, FALSE,
3343 D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 1024,
3346 TRUE, TRUE,
3347 0, 0, 513,
3348 0, 0
3351 TRUE, TRUE,
3352 D3D11_BIND_CONSTANT_BUFFER, 0, 513,
3353 D3D10_BIND_CONSTANT_BUFFER, 0
3356 TRUE, TRUE,
3357 D3D11_BIND_SHADER_RESOURCE, 0, 513,
3358 D3D10_BIND_SHADER_RESOURCE, 0
3361 TRUE, TRUE,
3362 D3D11_BIND_UNORDERED_ACCESS, 0, 513,
3363 D3D11_BIND_UNORDERED_ACCESS, 0
3366 FALSE, FALSE,
3367 0, D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3370 FALSE, FALSE,
3371 D3D11_BIND_SHADER_RESOURCE,
3372 D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS | D3D11_RESOURCE_MISC_BUFFER_STRUCTURED, 16,
3375 TRUE, TRUE,
3376 0, D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX, 0,
3377 0, D3D10_RESOURCE_MISC_SHARED_KEYEDMUTEX
3381 if (!(device = create_device(NULL)))
3383 skip("Failed to create ID3D11Device.\n");
3384 return;
3387 buffer = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
3388 hr = check_interface(buffer, &IID_ID3D10Buffer, TRUE, TRUE); /* Not available on all Windows versions. */
3389 ID3D11Buffer_Release(buffer);
3390 if (FAILED(hr))
3392 win_skip("Buffers do not implement ID3D10Buffer.\n");
3393 ID3D11Device_Release(device);
3394 return;
3397 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3399 const struct test *current = &tests[i];
3400 D3D11_BUFFER_DESC obtained_desc;
3401 D3D10_BUFFER_DESC d3d10_desc;
3402 ID3D10Device *d3d10_device;
3404 desc.ByteWidth = 1024;
3405 desc.Usage = D3D11_USAGE_DEFAULT;
3406 desc.BindFlags = current->bind_flags;
3407 desc.CPUAccessFlags = 0;
3408 desc.MiscFlags = current->misc_flags;
3409 desc.StructureByteStride = current->structure_stride;
3411 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
3412 expected_hr = current->succeeds ? S_OK : E_INVALIDARG;
3413 /* Shared resources are not supported by REF and WARP devices. */
3414 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY), "Test %u: Got hr %#x, expected %#x.\n",
3415 i, hr, expected_hr);
3416 if (FAILED(hr))
3418 if (hr == E_OUTOFMEMORY)
3419 win_skip("Failed to create a buffer, skipping test %u.\n", i);
3420 continue;
3423 if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_STRUCTURED))
3424 desc.StructureByteStride = 0;
3426 ID3D11Buffer_GetDesc(buffer, &obtained_desc);
3428 ok(obtained_desc.ByteWidth == desc.ByteWidth,
3429 "Test %u: Got unexpected ByteWidth %u.\n", i, obtained_desc.ByteWidth);
3430 ok(obtained_desc.Usage == desc.Usage,
3431 "Test %u: Got unexpected Usage %u.\n", i, obtained_desc.Usage);
3432 ok(obtained_desc.BindFlags == desc.BindFlags,
3433 "Test %u: Got unexpected BindFlags %#x.\n", i, obtained_desc.BindFlags);
3434 ok(obtained_desc.CPUAccessFlags == desc.CPUAccessFlags,
3435 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, obtained_desc.CPUAccessFlags);
3436 ok(obtained_desc.MiscFlags == desc.MiscFlags,
3437 "Test %u: Got unexpected MiscFlags %#x.\n", i, obtained_desc.MiscFlags);
3438 ok(obtained_desc.StructureByteStride == desc.StructureByteStride,
3439 "Test %u: Got unexpected StructureByteStride %u.\n", i, obtained_desc.StructureByteStride);
3441 hr = ID3D11Buffer_QueryInterface(buffer, &IID_ID3D10Buffer, (void **)&d3d10_buffer);
3442 ID3D11Buffer_Release(buffer);
3444 if (current->implements_d3d10_interfaces)
3446 ok(SUCCEEDED(hr), "Test %u: Buffer should implement ID3D10Buffer.\n", i);
3448 else
3450 todo_wine ok(hr == E_NOINTERFACE, "Test %u: Buffer should not implement ID3D10Buffer.\n", i);
3451 if (SUCCEEDED(hr)) ID3D10Buffer_Release(d3d10_buffer);
3452 continue;
3455 ID3D10Buffer_GetDesc(d3d10_buffer, &d3d10_desc);
3457 ok(d3d10_desc.ByteWidth == desc.ByteWidth,
3458 "Test %u: Got unexpected ByteWidth %u.\n", i, d3d10_desc.ByteWidth);
3459 ok(d3d10_desc.Usage == (D3D10_USAGE)desc.Usage,
3460 "Test %u: Got unexpected Usage %u.\n", i, d3d10_desc.Usage);
3461 ok(d3d10_desc.BindFlags == current->expected_bind_flags,
3462 "Test %u: Got unexpected BindFlags %#x.\n", i, d3d10_desc.BindFlags);
3463 ok(d3d10_desc.CPUAccessFlags == desc.CPUAccessFlags,
3464 "Test %u: Got unexpected CPUAccessFlags %#x.\n", i, d3d10_desc.CPUAccessFlags);
3465 ok(d3d10_desc.MiscFlags == current->expected_misc_flags,
3466 "Test %u: Got unexpected MiscFlags %#x.\n", i, d3d10_desc.MiscFlags);
3468 d3d10_device = (ID3D10Device *)0xdeadbeef;
3469 ID3D10Buffer_GetDevice(d3d10_buffer, &d3d10_device);
3470 ok(!d3d10_device, "Test %u: Got unexpected device pointer %p, expected NULL.\n", i, d3d10_device);
3471 if (d3d10_device) ID3D10Device_Release(d3d10_device);
3473 ID3D10Buffer_Release(d3d10_buffer);
3476 memset(&desc, 0, sizeof(desc));
3477 desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
3478 for (i = 0; i <= 32; ++i)
3480 desc.ByteWidth = i;
3481 expected_hr = !i || i % 16 ? E_INVALIDARG : S_OK;
3482 hr = ID3D11Device_CreateBuffer(device, &desc, NULL, &buffer);
3483 ok(hr == expected_hr, "Got unexpected hr %#x for constant buffer size %u.\n", hr, i);
3484 if (SUCCEEDED(hr))
3485 ID3D11Buffer_Release(buffer);
3488 refcount = ID3D11Device_Release(device);
3489 ok(!refcount, "Device has %u references left.\n", refcount);
3492 static void test_create_depthstencil_view(void)
3494 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
3495 D3D11_TEXTURE2D_DESC texture_desc;
3496 ULONG refcount, expected_refcount;
3497 ID3D11DepthStencilView *dsview;
3498 ID3D11Device *device, *tmp;
3499 ID3D11Texture2D *texture;
3500 unsigned int i;
3501 HRESULT hr;
3503 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3504 #define D24S8 DXGI_FORMAT_D24_UNORM_S8_UINT
3505 #define R24G8_TL DXGI_FORMAT_R24G8_TYPELESS
3506 #define DIM_UNKNOWN D3D11_DSV_DIMENSION_UNKNOWN
3507 #define TEX_1D D3D11_DSV_DIMENSION_TEXTURE1D
3508 #define TEX_1D_ARRAY D3D11_DSV_DIMENSION_TEXTURE1DARRAY
3509 #define TEX_2D D3D11_DSV_DIMENSION_TEXTURE2D
3510 #define TEX_2D_ARRAY D3D11_DSV_DIMENSION_TEXTURE2DARRAY
3511 #define TEX_2DMS D3D11_DSV_DIMENSION_TEXTURE2DMS
3512 #define TEX_2DMS_ARR D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY
3513 static const struct
3515 struct
3517 unsigned int miplevel_count;
3518 unsigned int array_size;
3519 DXGI_FORMAT format;
3520 } texture;
3521 struct dsv_desc dsv_desc;
3522 struct dsv_desc expected_dsv_desc;
3524 tests[] =
3526 {{ 1, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
3527 {{10, 1, D24S8}, {0}, {D24S8, TEX_2D, 0}},
3528 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3529 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 1}, {D24S8, TEX_2D, 1}},
3530 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2D, 9}, {D24S8, TEX_2D, 9}},
3531 {{ 1, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3532 {{10, 1, R24G8_TL}, {D24S8, TEX_2D, 0}, {D24S8, TEX_2D, 0}},
3533 {{ 1, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3534 {{10, 4, D24S8}, {0}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3535 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 0, 4}},
3536 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 1, 0, 4}},
3537 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 3, 0, 4}},
3538 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 5, 0, 4}},
3539 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {D24S8, TEX_2D_ARRAY, 9, 0, 4}},
3540 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 1, 3}},
3541 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 2, 2}},
3542 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {D24S8, TEX_2D_ARRAY, 0, 3, 1}},
3543 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3544 {{ 1, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3545 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS}, {D24S8, TEX_2DMS}},
3546 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3547 {{ 1, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3548 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3549 {{10, 1, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3550 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {D24S8, TEX_2DMS_ARR, 0, 0, 1}},
3551 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
3552 {{10, 4, D24S8}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {D24S8, TEX_2DMS_ARR, 0, 0, 4}},
3554 static const struct
3556 struct
3558 unsigned int miplevel_count;
3559 unsigned int array_size;
3560 DXGI_FORMAT format;
3561 } texture;
3562 struct dsv_desc dsv_desc;
3564 invalid_desc_tests[] =
3566 {{1, 1, D24S8}, {D24S8, DIM_UNKNOWN}},
3567 {{6, 4, D24S8}, {D24S8, DIM_UNKNOWN}},
3568 {{1, 1, D24S8}, {D24S8, TEX_1D, 0}},
3569 {{1, 1, D24S8}, {D24S8, TEX_1D_ARRAY, 0, 0, 1}},
3570 {{1, 1, D24S8}, {R24G8_TL, TEX_2D, 0}},
3571 {{1, 1, R24G8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3572 {{1, 1, D24S8}, {D24S8, TEX_2D, 1}},
3573 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 0}},
3574 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 1, 0, 1}},
3575 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 0, 2}},
3576 {{1, 1, D24S8}, {D24S8, TEX_2D_ARRAY, 0, 1, 1}},
3577 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 0, 2}},
3578 {{1, 1, D24S8}, {D24S8, TEX_2DMS_ARR, 0, 1, 1}},
3580 #undef FMT_UNKNOWN
3581 #undef D24S8
3582 #undef R24G8_TL
3583 #undef DIM_UNKNOWN
3584 #undef TEX_1D
3585 #undef TEX_1D_ARRAY
3586 #undef TEX_2D
3587 #undef TEX_2D_ARRAY
3588 #undef TEX_2DMS
3589 #undef TEX_2DMS_ARR
3591 if (!(device = create_device(NULL)))
3593 skip("Failed to create device.\n");
3594 return;
3597 texture_desc.Width = 512;
3598 texture_desc.Height = 512;
3599 texture_desc.MipLevels = 1;
3600 texture_desc.ArraySize = 1;
3601 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
3602 texture_desc.SampleDesc.Count = 1;
3603 texture_desc.SampleDesc.Quality = 0;
3604 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3605 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3606 texture_desc.CPUAccessFlags = 0;
3607 texture_desc.MiscFlags = 0;
3609 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3610 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
3612 expected_refcount = get_refcount(device) + 1;
3613 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsview);
3614 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
3615 refcount = get_refcount(device);
3616 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3617 tmp = NULL;
3618 expected_refcount = refcount + 1;
3619 ID3D11DepthStencilView_GetDevice(dsview, &tmp);
3620 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3621 refcount = get_refcount(device);
3622 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3623 ID3D11Device_Release(tmp);
3625 memset(&dsv_desc, 0, sizeof(dsv_desc));
3626 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
3627 ok(dsv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", dsv_desc.Format);
3628 ok(dsv_desc.ViewDimension == D3D11_DSV_DIMENSION_TEXTURE2D,
3629 "Got unexpected view dimension %#x.\n", dsv_desc.ViewDimension);
3630 ok(!dsv_desc.Flags, "Got unexpected flags %#x.\n", dsv_desc.Flags);
3631 ok(!U(dsv_desc).Texture2D.MipSlice, "Got unexpected mip slice %u.\n", U(dsv_desc).Texture2D.MipSlice);
3633 ID3D11DepthStencilView_Release(dsview);
3634 ID3D11Texture2D_Release(texture);
3636 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3638 D3D11_DEPTH_STENCIL_VIEW_DESC *current_desc;
3640 texture_desc.MipLevels = tests[i].texture.miplevel_count;
3641 texture_desc.ArraySize = tests[i].texture.array_size;
3642 texture_desc.Format = tests[i].texture.format;
3644 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3645 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3647 if (tests[i].dsv_desc.dimension == D3D11_DSV_DIMENSION_UNKNOWN)
3649 current_desc = NULL;
3651 else
3653 current_desc = &dsv_desc;
3654 get_dsv_desc(current_desc, &tests[i].dsv_desc);
3657 expected_refcount = get_refcount(texture);
3658 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, current_desc, &dsview);
3659 ok(SUCCEEDED(hr), "Test %u: Failed to create depth stencil view, hr %#x.\n", i, hr);
3660 refcount = get_refcount(texture);
3661 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
3663 /* Not available on all Windows versions. */
3664 check_interface(dsview, &IID_ID3D10DepthStencilView, TRUE, TRUE);
3666 memset(&dsv_desc, 0, sizeof(dsv_desc));
3667 ID3D11DepthStencilView_GetDesc(dsview, &dsv_desc);
3668 check_dsv_desc(&dsv_desc, &tests[i].expected_dsv_desc);
3670 ID3D11DepthStencilView_Release(dsview);
3671 ID3D11Texture2D_Release(texture);
3674 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
3676 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
3677 texture_desc.ArraySize = invalid_desc_tests[i].texture.array_size;
3678 texture_desc.Format = invalid_desc_tests[i].texture.format;
3680 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3681 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3683 get_dsv_desc(&dsv_desc, &invalid_desc_tests[i].dsv_desc);
3684 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
3685 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
3687 ID3D11Texture2D_Release(texture);
3690 refcount = ID3D11Device_Release(device);
3691 ok(!refcount, "Device has %u references left.\n", refcount);
3694 static void test_depthstencil_view_interfaces(void)
3696 D3D10_DEPTH_STENCIL_VIEW_DESC d3d10_dsv_desc;
3697 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
3698 ID3D10DepthStencilView *d3d10_dsview;
3699 D3D11_TEXTURE2D_DESC texture_desc;
3700 ID3D11DepthStencilView *dsview;
3701 ID3D11Texture2D *texture;
3702 ID3D11Device *device;
3703 ULONG refcount;
3704 HRESULT hr;
3706 if (!(device = create_device(NULL)))
3708 skip("Failed to create device.\n");
3709 return;
3712 texture_desc.Width = 512;
3713 texture_desc.Height = 512;
3714 texture_desc.MipLevels = 1;
3715 texture_desc.ArraySize = 1;
3716 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
3717 texture_desc.SampleDesc.Count = 1;
3718 texture_desc.SampleDesc.Quality = 0;
3719 texture_desc.Usage = D3D11_USAGE_DEFAULT;
3720 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
3721 texture_desc.CPUAccessFlags = 0;
3722 texture_desc.MiscFlags = 0;
3724 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
3725 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
3727 dsv_desc.Format = texture_desc.Format;
3728 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
3729 dsv_desc.Flags = 0;
3730 U(dsv_desc).Texture2D.MipSlice = 0;
3732 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsview);
3733 ok(SUCCEEDED(hr), "Failed to create a depthstencil view, hr %#x.\n", hr);
3735 hr = ID3D11DepthStencilView_QueryInterface(dsview, &IID_ID3D10DepthStencilView, (void **)&d3d10_dsview);
3736 ID3D11DepthStencilView_Release(dsview);
3737 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
3738 "Depth stencil view should implement ID3D10DepthStencilView.\n");
3740 if (FAILED(hr))
3742 win_skip("Depth stencil view does not implement ID3D10DepthStencilView.\n");
3743 goto done;
3746 ID3D10DepthStencilView_GetDesc(d3d10_dsview, &d3d10_dsv_desc);
3747 ok(d3d10_dsv_desc.Format == dsv_desc.Format, "Got unexpected format %#x.\n", d3d10_dsv_desc.Format);
3748 ok(d3d10_dsv_desc.ViewDimension == (D3D10_DSV_DIMENSION)dsv_desc.ViewDimension,
3749 "Got unexpected view dimension %u.\n", d3d10_dsv_desc.ViewDimension);
3750 ok(U(d3d10_dsv_desc).Texture2D.MipSlice == U(dsv_desc).Texture2D.MipSlice,
3751 "Got unexpected mip slice %u.\n", U(d3d10_dsv_desc).Texture2D.MipSlice);
3753 ID3D10DepthStencilView_Release(d3d10_dsview);
3755 done:
3756 ID3D11Texture2D_Release(texture);
3758 refcount = ID3D11Device_Release(device);
3759 ok(!refcount, "Device has %u references left.\n", refcount);
3762 static void test_create_rendertarget_view(void)
3764 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
3765 D3D11_TEXTURE3D_DESC texture3d_desc;
3766 D3D11_TEXTURE2D_DESC texture2d_desc;
3767 D3D11_SUBRESOURCE_DATA data = {0};
3768 ULONG refcount, expected_refcount;
3769 D3D11_BUFFER_DESC buffer_desc;
3770 ID3D11RenderTargetView *rtview;
3771 ID3D11Device *device, *tmp;
3772 ID3D11Texture3D *texture3d;
3773 ID3D11Texture2D *texture2d;
3774 ID3D11Resource *texture;
3775 ID3D11Buffer *buffer;
3776 unsigned int i;
3777 HRESULT hr;
3779 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
3780 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
3781 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
3782 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
3783 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
3784 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
3785 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
3786 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
3787 #define TEX_2DMS D3D11_RTV_DIMENSION_TEXTURE2DMS
3788 #define TEX_2DMS_ARR D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY
3789 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
3790 static const struct
3792 struct
3794 unsigned int miplevel_count;
3795 unsigned int depth_or_array_size;
3796 DXGI_FORMAT format;
3797 } texture;
3798 struct rtv_desc rtv_desc;
3799 struct rtv_desc expected_rtv_desc;
3801 tests[] =
3803 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
3804 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
3805 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3806 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
3807 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
3808 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3809 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
3810 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3811 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3812 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
3813 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
3814 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
3815 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
3816 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
3817 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
3818 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
3819 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
3820 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3821 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3822 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
3823 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3824 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3825 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3826 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3827 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 1}},
3828 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3829 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 4}},
3830 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3831 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3832 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
3833 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3834 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
3835 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
3836 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
3837 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
3838 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
3839 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3840 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
3841 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
3842 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
3843 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
3844 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
3845 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
3846 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
3848 static const struct
3850 struct
3852 D3D11_RTV_DIMENSION dimension;
3853 unsigned int miplevel_count;
3854 unsigned int depth_or_array_size;
3855 DXGI_FORMAT format;
3856 } texture;
3857 struct rtv_desc rtv_desc;
3859 invalid_desc_tests[] =
3861 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3862 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
3863 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3864 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3865 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
3866 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
3867 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
3868 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
3869 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
3870 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
3871 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
3872 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
3873 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
3874 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 0, 2}},
3875 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1}},
3876 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3877 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3878 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3879 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3880 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
3881 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
3882 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
3883 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
3884 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
3885 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
3886 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3887 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
3888 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
3889 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
3890 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
3891 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
3892 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
3893 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
3894 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
3895 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
3897 #undef FMT_UNKNOWN
3898 #undef RGBA8_UNORM
3899 #undef RGBA8_TL
3900 #undef DIM_UNKNOWN
3901 #undef TEX_1D
3902 #undef TEX_1D_ARRAY
3903 #undef TEX_2D
3904 #undef TEX_2D_ARRAY
3905 #undef TEX_2DMS
3906 #undef TEX_2DMS_ARR
3907 #undef TEX_3D
3909 if (!(device = create_device(NULL)))
3911 skip("Failed to create device.\n");
3912 return;
3915 buffer_desc.ByteWidth = 1024;
3916 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
3917 buffer_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3918 buffer_desc.CPUAccessFlags = 0;
3919 buffer_desc.MiscFlags = 0;
3920 buffer_desc.StructureByteStride = 0;
3922 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
3923 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3925 expected_refcount = get_refcount(device) + 1;
3926 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
3927 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
3928 refcount = get_refcount(device);
3929 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3930 tmp = NULL;
3931 expected_refcount = refcount + 1;
3932 ID3D11Buffer_GetDevice(buffer, &tmp);
3933 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3934 refcount = get_refcount(device);
3935 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3936 ID3D11Device_Release(tmp);
3938 rtv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
3939 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_BUFFER;
3940 U1(U(rtv_desc).Buffer).ElementOffset = 0;
3941 U2(U(rtv_desc).Buffer).ElementWidth = 64;
3943 if (!enable_debug_layer)
3945 hr = ID3D11Device_CreateRenderTargetView(device, NULL, &rtv_desc, &rtview);
3946 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
3949 expected_refcount = get_refcount(device) + 1;
3950 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)buffer, &rtv_desc, &rtview);
3951 ok(SUCCEEDED(hr), "Failed to create a rendertarget view, hr %#x.\n", hr);
3952 refcount = get_refcount(device);
3953 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
3954 tmp = NULL;
3955 expected_refcount = refcount + 1;
3956 ID3D11RenderTargetView_GetDevice(rtview, &tmp);
3957 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
3958 refcount = get_refcount(device);
3959 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
3960 ID3D11Device_Release(tmp);
3962 /* Not available on all Windows versions. */
3963 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
3965 ID3D11RenderTargetView_Release(rtview);
3966 ID3D11Buffer_Release(buffer);
3968 texture2d_desc.Width = 512;
3969 texture2d_desc.Height = 512;
3970 texture2d_desc.SampleDesc.Count = 1;
3971 texture2d_desc.SampleDesc.Quality = 0;
3972 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
3973 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3974 texture2d_desc.CPUAccessFlags = 0;
3975 texture2d_desc.MiscFlags = 0;
3977 texture3d_desc.Width = 64;
3978 texture3d_desc.Height = 64;
3979 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
3980 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
3981 texture3d_desc.CPUAccessFlags = 0;
3982 texture3d_desc.MiscFlags = 0;
3984 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3986 D3D11_RENDER_TARGET_VIEW_DESC *current_desc;
3988 if (tests[i].expected_rtv_desc.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
3990 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
3991 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
3992 texture2d_desc.Format = tests[i].texture.format;
3994 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
3995 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
3996 texture = (ID3D11Resource *)texture2d;
3998 else
4000 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
4001 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
4002 texture3d_desc.Format = tests[i].texture.format;
4004 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4005 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4006 texture = (ID3D11Resource *)texture3d;
4009 if (tests[i].rtv_desc.dimension == D3D11_RTV_DIMENSION_UNKNOWN)
4011 current_desc = NULL;
4013 else
4015 current_desc = &rtv_desc;
4016 get_rtv_desc(current_desc, &tests[i].rtv_desc);
4019 expected_refcount = get_refcount(texture);
4020 hr = ID3D11Device_CreateRenderTargetView(device, texture, current_desc, &rtview);
4021 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
4022 refcount = get_refcount(texture);
4023 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
4025 /* Not available on all Windows versions. */
4026 check_interface(rtview, &IID_ID3D10RenderTargetView, TRUE, TRUE);
4028 memset(&rtv_desc, 0, sizeof(rtv_desc));
4029 ID3D11RenderTargetView_GetDesc(rtview, &rtv_desc);
4030 check_rtv_desc(&rtv_desc, &tests[i].expected_rtv_desc);
4032 ID3D11RenderTargetView_Release(rtview);
4033 ID3D11Resource_Release(texture);
4036 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
4038 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
4039 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
4041 if (invalid_desc_tests[i].texture.dimension != D3D11_RTV_DIMENSION_TEXTURE3D)
4043 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4044 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
4045 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
4047 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4048 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4049 texture = (ID3D11Resource *)texture2d;
4051 else
4053 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4054 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
4055 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
4057 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4058 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4059 texture = (ID3D11Resource *)texture3d;
4062 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
4063 hr = ID3D11Device_CreateRenderTargetView(device, texture, &rtv_desc, &rtview);
4064 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
4066 ID3D11Resource_Release(texture);
4069 refcount = ID3D11Device_Release(device);
4070 ok(!refcount, "Device has %u references left.\n", refcount);
4073 static void test_create_shader_resource_view(void)
4075 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
4076 D3D11_TEXTURE3D_DESC texture3d_desc;
4077 D3D11_TEXTURE2D_DESC texture2d_desc;
4078 ULONG refcount, expected_refcount;
4079 ID3D11ShaderResourceView *srview;
4080 D3D_FEATURE_LEVEL feature_level;
4081 D3D11_BUFFER_DESC buffer_desc;
4082 ID3D11Device *device, *tmp;
4083 ID3D11Texture3D *texture3d;
4084 ID3D11Texture2D *texture2d;
4085 ID3D11Resource *texture;
4086 ID3D11Buffer *buffer;
4087 unsigned int i;
4088 HRESULT hr;
4090 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
4091 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
4092 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
4093 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
4094 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
4095 #define DIM_UNKNOWN D3D11_SRV_DIMENSION_UNKNOWN
4096 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
4097 #define TEX_1D_ARRAY D3D11_SRV_DIMENSION_TEXTURE1DARRAY
4098 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
4099 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
4100 #define TEX_2DMS D3D11_SRV_DIMENSION_TEXTURE2DMS
4101 #define TEX_2DMS_ARR D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY
4102 #define TEX_3D D3D11_SRV_DIMENSION_TEXTURE3D
4103 #define TEX_CUBE D3D11_SRV_DIMENSION_TEXTURECUBE
4104 #define CUBE_ARRAY D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
4105 static const struct
4107 struct
4109 unsigned int miplevel_count;
4110 unsigned int depth_or_array_size;
4111 DXGI_FORMAT format;
4112 } texture;
4113 struct srv_desc srv_desc;
4114 struct srv_desc expected_srv_desc;
4116 tests[] =
4118 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4119 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4120 {{10, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4121 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0, 10}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4122 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4123 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0, ~0u}, {RGBA8_UNORM, TEX_2D, 0, 10}},
4124 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
4125 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 0, 4}},
4126 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 9, 0, 4}},
4127 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 7, 0, 4}},
4128 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 5, 0, 4}},
4129 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, ~0u, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 1, 0, 4}},
4130 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 1, 3}},
4131 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 2, 2}},
4132 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, ~0u, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 10, 3, 1}},
4133 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4134 {{ 1, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4135 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS}, {RGBA8_UNORM, TEX_2DMS}},
4136 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4137 {{ 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4138 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4139 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4140 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 1}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 1}},
4141 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, 4}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
4142 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2DMS_ARR, 0, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 4}},
4143 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4144 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4145 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4146 {{ 4, 12, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 4}},
4147 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4148 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4149 {{ 2, 9, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4150 {{ 2, 11, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4151 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, ~0u}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4152 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 0, 1}, {RGBA8_UNORM, TEX_CUBE , 0, 1}},
4153 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_CUBE, 1, 1}, {RGBA8_UNORM, TEX_CUBE , 1, 1}},
4154 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, 1, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4155 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
4156 {{ 1, 8, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4157 {{ 1, 12, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4158 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, ~0u}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4159 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 1}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 1}},
4160 {{ 1, 12, RGBA8_UNORM}, {FMT_UNKNOWN, CUBE_ARRAY, 0, ~0u, 0, 2}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4161 {{ 1, 13, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4162 {{ 1, 14, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4163 {{ 1, 18, RGBA8_UNORM}, {0}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 3}},
4164 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
4165 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 1, 0, 1}},
4167 static const struct
4169 struct
4171 D3D11_SRV_DIMENSION dimension;
4172 unsigned int miplevel_count;
4173 unsigned int depth_or_array_size;
4174 DXGI_FORMAT format;
4175 } texture;
4176 struct srv_desc srv_desc;
4178 invalid_desc_tests[] =
4180 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
4181 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
4182 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4183 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4184 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 1}},
4185 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, ~0u}},
4186 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0, 1}},
4187 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, ~0u}},
4188 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0, 1}},
4189 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 0}},
4190 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 2}},
4191 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1, 1}},
4192 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 0}},
4193 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0, 1}},
4194 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 0}},
4195 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 0, 1}},
4196 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 1, 0, 1}},
4197 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 2}},
4198 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1, 1}},
4199 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 0, 2}},
4200 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2DMS_ARR, 0, 1, 1, 1}},
4201 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 0}},
4202 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 2}},
4203 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 1, 1}},
4204 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 0}},
4205 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 0, 0, 1}},
4206 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
4207 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 0}},
4208 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 2, 0, 1}},
4209 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 1, 1, 0, 1}},
4210 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, 1}},
4211 {{TEX_2D, 1, 6, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 1, ~0u}},
4212 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, 1}},
4213 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 2, ~0u}},
4214 {{TEX_2D, 1, 7, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4215 {{TEX_2D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, CUBE_ARRAY, 0, 1, 0, 2}},
4216 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 1}},
4217 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4218 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 1}},
4219 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4220 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4221 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4222 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4223 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4224 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
4225 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0, 1}},
4226 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 1, 0, 1}},
4227 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0, 1}},
4228 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_CUBE, 0, 1}},
4229 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 0, 1}},
4230 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0}},
4231 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 1}},
4232 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2}},
4233 {{TEX_3D, 1, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1}},
4234 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 2}},
4235 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 1}},
4237 #undef FMT_UNKNOWN
4238 #undef RGBA8_UNORM
4239 #undef RGBA8_SRGB
4240 #undef RGBA8_UINT
4241 #undef RGBA8_TL
4242 #undef DIM_UNKNOWN
4243 #undef TEX_1D
4244 #undef TEX_1D_ARRAY
4245 #undef TEX_2D
4246 #undef TEX_2D_ARRAY
4247 #undef TEX_2DMS
4248 #undef TEX_2DMS_ARR
4249 #undef TEX_3D
4250 #undef TEX_CUBE
4251 #undef CUBE_ARRAY
4253 if (!(device = create_device(NULL)))
4255 skip("Failed to create device.\n");
4256 return;
4258 feature_level = ID3D11Device_GetFeatureLevel(device);
4260 buffer = create_buffer(device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
4262 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
4263 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4265 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
4266 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
4267 U1(U(srv_desc).Buffer).ElementOffset = 0;
4268 U2(U(srv_desc).Buffer).ElementWidth = 64;
4270 hr = ID3D11Device_CreateShaderResourceView(device, NULL, &srv_desc, &srview);
4271 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4273 expected_refcount = get_refcount(device) + 1;
4274 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
4275 ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x.\n", hr);
4276 refcount = get_refcount(device);
4277 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4278 tmp = NULL;
4279 expected_refcount = refcount + 1;
4280 ID3D11ShaderResourceView_GetDevice(srview, &tmp);
4281 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4282 refcount = get_refcount(device);
4283 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4284 ID3D11Device_Release(tmp);
4286 /* Not available on all Windows versions. */
4287 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
4288 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
4290 ID3D11ShaderResourceView_Release(srview);
4291 ID3D11Buffer_Release(buffer);
4293 /* Without D3D11_BIND_SHADER_RESOURCE. */
4294 buffer = create_buffer(device, 0, 1024, NULL);
4296 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srview);
4297 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4299 ID3D11Buffer_Release(buffer);
4301 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
4303 buffer_desc.ByteWidth = 1024;
4304 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
4305 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4306 buffer_desc.CPUAccessFlags = 0;
4307 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
4308 buffer_desc.StructureByteStride = 4;
4310 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
4311 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
4313 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, NULL, &srview);
4314 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
4316 memset(&srv_desc, 0, sizeof(srv_desc));
4317 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
4319 ok(srv_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", srv_desc.Format);
4320 ok(srv_desc.ViewDimension == D3D11_SRV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
4321 srv_desc.ViewDimension);
4322 ok(!U1(U(srv_desc).Buffer).FirstElement, "Got unexpected first element %u.\n",
4323 U1(U(srv_desc).Buffer).FirstElement);
4324 ok(U2(U(srv_desc).Buffer).NumElements == 256, "Got unexpected num elements %u.\n",
4325 U2(U(srv_desc).Buffer).NumElements);
4327 ID3D11ShaderResourceView_Release(srview);
4328 ID3D11Buffer_Release(buffer);
4330 else
4332 skip("Structured buffers require feature level 11_0.\n");
4335 texture2d_desc.Width = 512;
4336 texture2d_desc.Height = 512;
4337 texture2d_desc.SampleDesc.Count = 1;
4338 texture2d_desc.SampleDesc.Quality = 0;
4339 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
4340 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4341 texture2d_desc.CPUAccessFlags = 0;
4343 texture3d_desc.Width = 64;
4344 texture3d_desc.Height = 64;
4345 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
4346 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
4347 texture3d_desc.CPUAccessFlags = 0;
4348 texture3d_desc.MiscFlags = 0;
4350 for (i = 0; i < ARRAY_SIZE(tests); ++i)
4352 D3D11_SHADER_RESOURCE_VIEW_DESC *current_desc;
4354 if (tests[i].expected_srv_desc.dimension != D3D11_SRV_DIMENSION_TEXTURE3D)
4356 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
4357 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
4358 texture2d_desc.Format = tests[i].texture.format;
4359 texture2d_desc.MiscFlags = 0;
4361 if (tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
4362 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4363 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
4365 if (texture2d_desc.MiscFlags & D3D11_RESOURCE_MISC_TEXTURECUBE
4366 && (texture2d_desc.ArraySize != 6
4367 || tests[i].expected_srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4368 && feature_level < D3D_FEATURE_LEVEL_10_1)
4370 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
4371 continue;
4374 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4375 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4376 texture = (ID3D11Resource *)texture2d;
4378 else
4380 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
4381 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
4382 texture3d_desc.Format = tests[i].texture.format;
4384 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4385 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4386 texture = (ID3D11Resource *)texture3d;
4389 if (tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_UNKNOWN)
4391 current_desc = NULL;
4393 else
4395 current_desc = &srv_desc;
4396 get_srv_desc(current_desc, &tests[i].srv_desc);
4399 expected_refcount = get_refcount(texture);
4400 hr = ID3D11Device_CreateShaderResourceView(device, texture, current_desc, &srview);
4401 ok(SUCCEEDED(hr), "Test %u: Failed to create a shader resource view, hr %#x.\n", i, hr);
4402 refcount = get_refcount(texture);
4403 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
4405 /* Not available on all Windows versions. */
4406 check_interface(srview, &IID_ID3D10ShaderResourceView, TRUE, TRUE);
4407 check_interface(srview, &IID_ID3D10ShaderResourceView1, TRUE, TRUE);
4409 memset(&srv_desc, 0, sizeof(srv_desc));
4410 ID3D11ShaderResourceView_GetDesc(srview, &srv_desc);
4411 check_srv_desc(&srv_desc, &tests[i].expected_srv_desc);
4413 ID3D11ShaderResourceView_Release(srview);
4414 ID3D11Resource_Release(texture);
4417 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
4419 assert(invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D
4420 || invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE3D);
4422 if (invalid_desc_tests[i].texture.dimension == D3D11_SRV_DIMENSION_TEXTURE2D)
4424 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4425 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
4426 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
4427 texture2d_desc.MiscFlags = 0;
4429 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBE
4430 || invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY)
4431 texture2d_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
4433 if (invalid_desc_tests[i].srv_desc.dimension == D3D11_SRV_DIMENSION_TEXTURECUBEARRAY
4434 && feature_level < D3D_FEATURE_LEVEL_10_1)
4436 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
4437 continue;
4440 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
4441 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
4442 texture = (ID3D11Resource *)texture2d;
4444 else
4446 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
4447 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
4448 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
4450 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
4451 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
4452 texture = (ID3D11Resource *)texture3d;
4455 get_srv_desc(&srv_desc, &invalid_desc_tests[i].srv_desc);
4456 hr = ID3D11Device_CreateShaderResourceView(device, texture, &srv_desc, &srview);
4457 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
4459 ID3D11Resource_Release(texture);
4462 refcount = ID3D11Device_Release(device);
4463 ok(!refcount, "Device has %u references left.\n", refcount);
4466 static void test_create_shader(const D3D_FEATURE_LEVEL feature_level)
4468 #if 0
4469 float4 light;
4470 float4x4 mat;
4472 struct input
4474 float4 position : POSITION;
4475 float3 normal : NORMAL;
4478 struct output
4480 float4 position : POSITION;
4481 float4 diffuse : COLOR;
4484 output main(const input v)
4486 output o;
4488 o.position = mul(v.position, mat);
4489 o.diffuse = dot((float3)light, v.normal);
4491 return o;
4493 #endif
4494 static const DWORD vs_4_1[] =
4496 0x43425844, 0xfce5b27c, 0x965db93d, 0x8c3d0459, 0x9890ebac, 0x00000001, 0x000001c4, 0x00000003,
4497 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
4498 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
4499 0x00000003, 0x00000001, 0x00000707, 0x49534f50, 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f,
4500 0x00000048, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4501 0x0000000f, 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50,
4502 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000f0, 0x00010041, 0x0000003c, 0x0100086a,
4503 0x04000059, 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
4504 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001,
4505 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
4506 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000002,
4507 0x08000011, 0x00102042, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000003,
4508 0x08000011, 0x00102082, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004,
4509 0x08000010, 0x001020f2, 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001,
4510 0x0100003e,
4512 static const DWORD vs_4_0[] =
4514 0x43425844, 0x3ae813ca, 0x0f034b91, 0x790f3226, 0x6b4a718a, 0x00000001, 0x000001c0,
4515 0x00000003, 0x0000002c, 0x0000007c, 0x000000cc, 0x4e475349, 0x00000048, 0x00000002,
4516 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
4517 0x00000041, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000707, 0x49534f50,
4518 0x4e4f4954, 0x524f4e00, 0x004c414d, 0x4e47534f, 0x00000048, 0x00000002, 0x00000008,
4519 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041,
4520 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x49534f50, 0x4e4f4954,
4521 0x4c4f4300, 0xab00524f, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059,
4522 0x00208e46, 0x00000000, 0x00000005, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f,
4523 0x00101072, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
4524 0x00000001, 0x08000011, 0x00102012, 0x00000000, 0x00101e46, 0x00000000, 0x00208e46,
4525 0x00000000, 0x00000001, 0x08000011, 0x00102022, 0x00000000, 0x00101e46, 0x00000000,
4526 0x00208e46, 0x00000000, 0x00000002, 0x08000011, 0x00102042, 0x00000000, 0x00101e46,
4527 0x00000000, 0x00208e46, 0x00000000, 0x00000003, 0x08000011, 0x00102082, 0x00000000,
4528 0x00101e46, 0x00000000, 0x00208e46, 0x00000000, 0x00000004, 0x08000010, 0x001020f2,
4529 0x00000001, 0x00208246, 0x00000000, 0x00000000, 0x00101246, 0x00000001, 0x0100003e,
4531 static const DWORD vs_3_0[] =
4533 0xfffe0300, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0300, 0x00000002,
4534 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
4535 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
4536 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
4537 0x00040004, 0x00000001, 0x00000000, 0x335f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
4538 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
4539 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
4540 0x80000003, 0x900f0001, 0x0200001f, 0x80000000, 0xe00f0000, 0x0200001f, 0x8000000a,
4541 0xe00f0001, 0x03000009, 0xe0010000, 0x90e40000, 0xa0e40000, 0x03000009, 0xe0020000,
4542 0x90e40000, 0xa0e40001, 0x03000009, 0xe0040000, 0x90e40000, 0xa0e40002, 0x03000009,
4543 0xe0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xe00f0001, 0xa0e40004, 0x90e40001,
4544 0x0000ffff,
4546 static const DWORD vs_2_0[] =
4548 0xfffe0200, 0x002bfffe, 0x42415443, 0x0000001c, 0x00000077, 0xfffe0200, 0x00000002,
4549 0x0000001c, 0x00000100, 0x00000070, 0x00000044, 0x00040002, 0x00000001, 0x0000004c,
4550 0x00000000, 0x0000005c, 0x00000002, 0x00000004, 0x00000060, 0x00000000, 0x6867696c,
4551 0xabab0074, 0x00030001, 0x00040001, 0x00000001, 0x00000000, 0x0074616d, 0x00030003,
4552 0x00040004, 0x00000001, 0x00000000, 0x325f7376, 0x4d00305f, 0x6f726369, 0x74666f73,
4553 0x29522820, 0x534c4820, 0x6853204c, 0x72656461, 0x6d6f4320, 0x656c6970, 0x2e392072,
4554 0x392e3932, 0x332e3235, 0x00313131, 0x0200001f, 0x80000000, 0x900f0000, 0x0200001f,
4555 0x80000003, 0x900f0001, 0x03000009, 0xc0010000, 0x90e40000, 0xa0e40000, 0x03000009,
4556 0xc0020000, 0x90e40000, 0xa0e40001, 0x03000009, 0xc0040000, 0x90e40000, 0xa0e40002,
4557 0x03000009, 0xc0080000, 0x90e40000, 0xa0e40003, 0x03000008, 0xd00f0000, 0xa0e40004,
4558 0x90e40001, 0x0000ffff,
4561 #if 0
4562 float4 main(const float4 color : COLOR) : SV_TARGET
4564 float4 o;
4566 o = color;
4568 return o;
4570 #endif
4571 static const DWORD ps_4_1[] =
4573 0x43425844, 0xa1a44423, 0xa4cfcec2, 0x64610832, 0xb7a852bd, 0x00000001, 0x000000d4, 0x00000003,
4574 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4575 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4576 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4577 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000003c, 0x00000041, 0x0000000f,
4578 0x0100086a, 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4579 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4581 static const DWORD ps_4_0[] =
4583 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
4584 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
4585 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
4586 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4587 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4588 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4589 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
4591 static const DWORD ps_4_0_level_9_0[] =
4593 0x43425844, 0xbc6626e7, 0x7778dc9d, 0xc8a43be2, 0xe4b53f7a, 0x00000001, 0x00000170,
4594 0x00000005, 0x00000034, 0x00000080, 0x000000cc, 0x0000010c, 0x0000013c, 0x53414e58,
4595 0x00000044, 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000,
4596 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000,
4597 0x02000001, 0x800f0800, 0x80e40000, 0x0000ffff, 0x396e6f41, 0x00000044, 0x00000044,
4598 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
4599 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001, 0x800f0800,
4600 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03001062,
4601 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
4602 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028, 0x00000001,
4603 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f,
4604 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4605 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x45475241,
4606 0xabab0054,
4608 static const DWORD ps_4_0_level_9_1[] =
4610 0x43425844, 0x275ecf38, 0x4349ff01, 0xa6b0e324, 0x6e54a4fc, 0x00000001, 0x00000120,
4611 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
4612 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
4613 0x00240000, 0x00240000, 0xffff0200, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
4614 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4615 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4616 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
4617 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4618 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
4619 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
4620 0x45475241, 0xabab0054,
4622 static const DWORD ps_4_0_level_9_3[] =
4624 0x43425844, 0xc7d541c4, 0x961d4e0e, 0x9ce7ec57, 0x70f47dcb, 0x00000001, 0x00000120,
4625 0x00000004, 0x00000030, 0x0000007c, 0x000000bc, 0x000000ec, 0x396e6f41, 0x00000044,
4626 0x00000044, 0xffff0200, 0x00000020, 0x00000024, 0x00240000, 0x00240000, 0x00240000,
4627 0x00240000, 0x00240000, 0xffff0201, 0x0200001f, 0x80000000, 0xb00f0000, 0x02000001,
4628 0x800f0800, 0xb0e40000, 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
4629 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
4630 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e, 0x4e475349, 0x00000028,
4631 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
4632 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
4633 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
4634 0x45475241, 0xabab0054,
4637 #if 0
4638 struct gs_out
4640 float4 pos : SV_POSITION;
4643 [maxvertexcount(4)]
4644 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
4646 float offset = 0.1 * vin[0].w;
4647 gs_out v;
4649 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
4650 vout.Append(v);
4651 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
4652 vout.Append(v);
4653 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
4654 vout.Append(v);
4655 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
4656 vout.Append(v);
4658 #endif
4659 static const DWORD gs_4_1[] =
4661 0x43425844, 0x779daaf5, 0x7e154197, 0xcf5e99da, 0xb502b4d2, 0x00000001, 0x00000240, 0x00000003,
4662 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4663 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4664 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4665 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a4, 0x00020041,
4666 0x00000069, 0x0100086a, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001,
4667 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004,
4668 0x0f000032, 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002,
4669 0x3dcccccd, 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036,
4670 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
4671 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000,
4672 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4673 0x00000000, 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022,
4674 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4675 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
4676 0x00102022, 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6,
4677 0x00000000, 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
4678 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4680 static const DWORD gs_4_0[] =
4682 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
4683 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
4684 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
4685 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
4686 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
4687 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
4688 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
4689 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
4690 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
4691 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4692 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
4693 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
4694 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
4695 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
4696 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
4697 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
4698 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
4699 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
4702 ULONG refcount, expected_refcount;
4703 struct device_desc device_desc;
4704 ID3D11Device *device, *tmp;
4705 ID3D11GeometryShader *gs;
4706 ID3D11VertexShader *vs;
4707 ID3D11PixelShader *ps;
4708 HRESULT hr;
4710 device_desc.feature_level = &feature_level;
4711 device_desc.flags = 0;
4712 if (!(device = create_device(&device_desc)))
4714 skip("Failed to create device for feature level %#x.\n", feature_level);
4715 return;
4718 /* level_9 shaders */
4719 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_0, sizeof(ps_4_0_level_9_0), NULL, &ps);
4720 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_0 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4721 ID3D11PixelShader_Release(ps);
4723 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_1, sizeof(ps_4_0_level_9_1), NULL, &ps);
4724 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_1 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4725 ID3D11PixelShader_Release(ps);
4727 hr = ID3D11Device_CreatePixelShader(device, ps_4_0_level_9_3, sizeof(ps_4_0_level_9_3), NULL, &ps);
4728 ok(SUCCEEDED(hr), "Failed to create ps_4_0_level_9_3 shader, hr %#x, feature level %#x.\n", hr, feature_level);
4729 ID3D11PixelShader_Release(ps);
4731 /* vertex shader */
4732 hr = ID3D11Device_CreateVertexShader(device, vs_2_0, sizeof(vs_2_0), NULL, &vs);
4733 ok(hr == E_INVALIDARG, "Created a SM2 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4735 hr = ID3D11Device_CreateVertexShader(device, vs_3_0, sizeof(vs_3_0), NULL, &vs);
4736 ok(hr == E_INVALIDARG, "Created a SM3 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4738 hr = ID3D11Device_CreateVertexShader(device, ps_4_0, sizeof(ps_4_0), NULL, &vs);
4739 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader from a pixel shader source, hr %#x, feature level %#x.\n",
4740 hr, feature_level);
4742 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4743 hr = ID3D11Device_CreateVertexShader(device, vs_4_0, sizeof(vs_4_0), NULL, &vs);
4744 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4745 ok(SUCCEEDED(hr), "Failed to create SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4746 else
4747 ok(hr == E_INVALIDARG, "Created a SM4 vertex shader, hr %#x, feature level %#x.\n", hr, feature_level);
4749 refcount = get_refcount(device);
4750 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4751 refcount, expected_refcount);
4752 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4754 tmp = NULL;
4755 expected_refcount = refcount + 1;
4756 ID3D11VertexShader_GetDevice(vs, &tmp);
4757 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4758 refcount = get_refcount(device);
4759 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4760 refcount, expected_refcount);
4761 ID3D11Device_Release(tmp);
4763 /* Not available on all Windows versions. */
4764 check_interface(vs, &IID_ID3D10VertexShader, TRUE, TRUE);
4766 refcount = ID3D11VertexShader_Release(vs);
4767 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
4770 hr = ID3D11Device_CreateVertexShader(device, vs_4_1, sizeof(vs_4_1), NULL, &vs);
4771 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4773 ok(SUCCEEDED(hr), "Failed to create SM4.1 vertex shader, hr %#x, feature level %#x.\n",
4774 hr, feature_level);
4775 refcount = ID3D11VertexShader_Release(vs);
4776 ok(!refcount, "Vertex shader has %u references left.\n", refcount);
4778 else
4780 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4781 ok(hr == E_INVALIDARG, "Created a SM4.1 vertex shader, hr %#x, feature level %#x.\n",
4782 hr, feature_level);
4783 if (SUCCEEDED(hr))
4784 ID3D11VertexShader_Release(vs);
4787 /* pixel shader */
4788 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4789 hr = ID3D11Device_CreatePixelShader(device, ps_4_0, sizeof(ps_4_0), NULL, &ps);
4790 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4791 ok(SUCCEEDED(hr), "Failed to create SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4792 else
4793 ok(hr == E_INVALIDARG, "Created a SM4 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4795 refcount = get_refcount(device);
4796 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4797 refcount, expected_refcount);
4798 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4800 tmp = NULL;
4801 expected_refcount = refcount + 1;
4802 ID3D11PixelShader_GetDevice(ps, &tmp);
4803 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4804 refcount = get_refcount(device);
4805 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4806 refcount, expected_refcount);
4807 ID3D11Device_Release(tmp);
4809 /* Not available on all Windows versions. */
4810 check_interface(ps, &IID_ID3D10PixelShader, TRUE, TRUE);
4812 refcount = ID3D11PixelShader_Release(ps);
4813 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
4816 hr = ID3D11Device_CreatePixelShader(device, ps_4_1, sizeof(ps_4_1), NULL, &ps);
4817 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4819 ok(SUCCEEDED(hr), "Failed to create SM4.1 pixel shader, hr %#x, feature level %#x.\n",
4820 hr, feature_level);
4821 refcount = ID3D11PixelShader_Release(ps);
4822 ok(!refcount, "Pixel shader has %u references left.\n", refcount);
4824 else
4826 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4827 ok(hr == E_INVALIDARG, "Created a SM4.1 pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
4828 if (SUCCEEDED(hr))
4829 ID3D11PixelShader_Release(ps);
4832 /* geometry shader */
4833 expected_refcount = get_refcount(device) + (feature_level >= D3D_FEATURE_LEVEL_10_0);
4834 hr = ID3D11Device_CreateGeometryShader(device, gs_4_0, sizeof(gs_4_0), NULL, &gs);
4835 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4836 ok(SUCCEEDED(hr), "Failed to create SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4837 else
4838 ok(hr == E_INVALIDARG, "Created a SM4 geometry shader, hr %#x, feature level %#x.\n", hr, feature_level);
4840 refcount = get_refcount(device);
4841 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n",
4842 refcount, expected_refcount);
4843 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
4845 tmp = NULL;
4846 expected_refcount = refcount + 1;
4847 ID3D11GeometryShader_GetDevice(gs, &tmp);
4848 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4849 refcount = get_refcount(device);
4850 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n",
4851 refcount, expected_refcount);
4852 ID3D11Device_Release(tmp);
4854 /* Not available on all Windows versions. */
4855 check_interface(gs, &IID_ID3D10GeometryShader, TRUE, TRUE);
4857 refcount = ID3D11GeometryShader_Release(gs);
4858 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4861 hr = ID3D11Device_CreateGeometryShader(device, gs_4_1, sizeof(gs_4_1), NULL, &gs);
4862 if (feature_level >= D3D_FEATURE_LEVEL_10_1)
4864 ok(SUCCEEDED(hr), "Failed to create SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4865 hr, feature_level);
4866 refcount = ID3D11GeometryShader_Release(gs);
4867 ok(!refcount, "Geometry shader has %u references left.\n", refcount);
4869 else
4871 todo_wine_if(feature_level >= D3D_FEATURE_LEVEL_10_0)
4872 ok(hr == E_INVALIDARG, "Created a SM4.1 geometry shader, hr %#x, feature level %#x.\n",
4873 hr, feature_level);
4874 if (SUCCEEDED(hr))
4875 ID3D11GeometryShader_Release(gs);
4878 refcount = ID3D11Device_Release(device);
4879 ok(!refcount, "Device has %u references left.\n", refcount);
4882 static void test_create_sampler_state(void)
4884 static const struct test
4886 D3D11_FILTER filter;
4887 D3D10_FILTER expected_filter;
4889 desc_conversion_tests[] =
4891 {D3D11_FILTER_MIN_MAG_MIP_POINT, D3D10_FILTER_MIN_MAG_MIP_POINT},
4892 {D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_MAG_POINT_MIP_LINEAR},
4893 {D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT},
4894 {D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_MIN_POINT_MAG_MIP_LINEAR},
4895 {D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_MIN_LINEAR_MAG_MIP_POINT},
4896 {D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR, D3D10_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR},
4897 {D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_MIN_MAG_LINEAR_MIP_POINT},
4898 {D3D11_FILTER_MIN_MAG_MIP_LINEAR, D3D10_FILTER_MIN_MAG_MIP_LINEAR},
4899 {D3D11_FILTER_ANISOTROPIC, D3D10_FILTER_ANISOTROPIC},
4900 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_POINT},
4901 {D3D11_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_POINT_MIP_LINEAR},
4903 D3D11_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT,
4904 D3D10_FILTER_COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT
4906 {D3D11_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_POINT_MAG_MIP_LINEAR},
4907 {D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_MIP_POINT},
4909 D3D11_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR,
4910 D3D10_FILTER_COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR
4912 {D3D11_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT, D3D10_FILTER_COMPARISON_MIN_MAG_LINEAR_MIP_POINT},
4913 {D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR, D3D10_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR},
4914 {D3D11_FILTER_COMPARISON_ANISOTROPIC, D3D10_FILTER_COMPARISON_ANISOTROPIC},
4917 ID3D11SamplerState *sampler_state1, *sampler_state2;
4918 ID3D10SamplerState *d3d10_sampler_state;
4919 ULONG refcount, expected_refcount;
4920 ID3D11Device *device, *tmp;
4921 D3D11_SAMPLER_DESC desc;
4922 unsigned int i;
4923 HRESULT hr;
4925 if (!(device = create_device(NULL)))
4927 skip("Failed to create device.\n");
4928 return;
4931 hr = ID3D11Device_CreateSamplerState(device, NULL, &sampler_state1);
4932 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
4934 desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
4935 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4936 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4937 desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
4938 desc.MipLODBias = 0.0f;
4939 desc.MaxAnisotropy = 16;
4940 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4941 desc.BorderColor[0] = 0.0f;
4942 desc.BorderColor[1] = 1.0f;
4943 desc.BorderColor[2] = 0.0f;
4944 desc.BorderColor[3] = 1.0f;
4945 desc.MinLOD = 0.0f;
4946 desc.MaxLOD = 16.0f;
4948 expected_refcount = get_refcount(device) + 1;
4949 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
4950 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4951 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state2);
4952 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
4953 ok(sampler_state1 == sampler_state2, "Got different sampler state objects.\n");
4954 refcount = get_refcount(device);
4955 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
4956 tmp = NULL;
4957 expected_refcount = refcount + 1;
4958 ID3D11SamplerState_GetDevice(sampler_state1, &tmp);
4959 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
4960 refcount = get_refcount(device);
4961 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
4962 ID3D11Device_Release(tmp);
4964 ID3D11SamplerState_GetDesc(sampler_state1, &desc);
4965 ok(desc.Filter == D3D11_FILTER_MIN_MAG_MIP_LINEAR, "Got unexpected filter %#x.\n", desc.Filter);
4966 ok(desc.AddressU == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address u %u.\n", desc.AddressU);
4967 ok(desc.AddressV == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address v %u.\n", desc.AddressV);
4968 ok(desc.AddressW == D3D11_TEXTURE_ADDRESS_WRAP, "Got unexpected address w %u.\n", desc.AddressW);
4969 ok(!desc.MipLODBias, "Got unexpected mip LOD bias %f.\n", desc.MipLODBias);
4970 ok(!desc.MaxAnisotropy, "Got unexpected max anisotropy %u.\n", desc.MaxAnisotropy);
4971 ok(desc.ComparisonFunc == D3D11_COMPARISON_NEVER, "Got unexpected comparison func %u.\n", desc.ComparisonFunc);
4972 ok(!desc.BorderColor[0] && !desc.BorderColor[1] && !desc.BorderColor[2] && !desc.BorderColor[3],
4973 "Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n",
4974 desc.BorderColor[0], desc.BorderColor[1], desc.BorderColor[2], desc.BorderColor[3]);
4975 ok(!desc.MinLOD, "Got unexpected min LOD %f.\n", desc.MinLOD);
4976 ok(desc.MaxLOD == 16.0f, "Got unexpected max LOD %f.\n", desc.MaxLOD);
4978 refcount = ID3D11SamplerState_Release(sampler_state2);
4979 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
4980 refcount = ID3D11SamplerState_Release(sampler_state1);
4981 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
4983 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
4985 const struct test *current = &desc_conversion_tests[i];
4986 D3D10_SAMPLER_DESC d3d10_desc, expected_desc;
4988 desc.Filter = current->filter;
4989 desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
4990 desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
4991 desc.AddressW = D3D11_TEXTURE_ADDRESS_BORDER;
4992 desc.MipLODBias = 0.0f;
4993 desc.MaxAnisotropy = 16;
4994 desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
4995 desc.BorderColor[0] = 0.0f;
4996 desc.BorderColor[1] = 1.0f;
4997 desc.BorderColor[2] = 0.0f;
4998 desc.BorderColor[3] = 1.0f;
4999 desc.MinLOD = 0.0f;
5000 desc.MaxLOD = 16.0f;
5002 hr = ID3D11Device_CreateSamplerState(device, &desc, &sampler_state1);
5003 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
5005 hr = ID3D11SamplerState_QueryInterface(sampler_state1, &IID_ID3D10SamplerState,
5006 (void **)&d3d10_sampler_state);
5007 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5008 "Test %u: Sampler state should implement ID3D10SamplerState.\n", i);
5009 if (FAILED(hr))
5011 win_skip("Sampler state does not implement ID3D10SamplerState.\n");
5012 ID3D11SamplerState_Release(sampler_state1);
5013 break;
5016 memcpy(&expected_desc, &desc, sizeof(expected_desc));
5017 expected_desc.Filter = current->expected_filter;
5018 if (!D3D11_DECODE_IS_ANISOTROPIC_FILTER(current->filter))
5019 expected_desc.MaxAnisotropy = 0;
5020 if (!D3D11_DECODE_IS_COMPARISON_FILTER(current->filter))
5021 expected_desc.ComparisonFunc = D3D10_COMPARISON_NEVER;
5023 ID3D10SamplerState_GetDesc(d3d10_sampler_state, &d3d10_desc);
5024 ok(d3d10_desc.Filter == expected_desc.Filter,
5025 "Test %u: Got unexpected filter %#x.\n", i, d3d10_desc.Filter);
5026 ok(d3d10_desc.AddressU == expected_desc.AddressU,
5027 "Test %u: Got unexpected address u %u.\n", i, d3d10_desc.AddressU);
5028 ok(d3d10_desc.AddressV == expected_desc.AddressV,
5029 "Test %u: Got unexpected address v %u.\n", i, d3d10_desc.AddressV);
5030 ok(d3d10_desc.AddressW == expected_desc.AddressW,
5031 "Test %u: Got unexpected address w %u.\n", i, d3d10_desc.AddressW);
5032 ok(d3d10_desc.MipLODBias == expected_desc.MipLODBias,
5033 "Test %u: Got unexpected mip LOD bias %f.\n", i, d3d10_desc.MipLODBias);
5034 ok(d3d10_desc.MaxAnisotropy == expected_desc.MaxAnisotropy,
5035 "Test %u: Got unexpected max anisotropy %u.\n", i, d3d10_desc.MaxAnisotropy);
5036 ok(d3d10_desc.ComparisonFunc == expected_desc.ComparisonFunc,
5037 "Test %u: Got unexpected comparison func %u.\n", i, d3d10_desc.ComparisonFunc);
5038 ok(d3d10_desc.BorderColor[0] == expected_desc.BorderColor[0]
5039 && d3d10_desc.BorderColor[1] == expected_desc.BorderColor[1]
5040 && d3d10_desc.BorderColor[2] == expected_desc.BorderColor[2]
5041 && d3d10_desc.BorderColor[3] == expected_desc.BorderColor[3],
5042 "Test %u: Got unexpected border color {%.8e, %.8e, %.8e, %.8e}.\n", i,
5043 d3d10_desc.BorderColor[0], d3d10_desc.BorderColor[1],
5044 d3d10_desc.BorderColor[2], d3d10_desc.BorderColor[3]);
5045 ok(d3d10_desc.MinLOD == expected_desc.MinLOD,
5046 "Test %u: Got unexpected min LOD %f.\n", i, d3d10_desc.MinLOD);
5047 ok(d3d10_desc.MaxLOD == expected_desc.MaxLOD,
5048 "Test %u: Got unexpected max LOD %f.\n", i, d3d10_desc.MaxLOD);
5050 refcount = ID3D10SamplerState_Release(d3d10_sampler_state);
5051 ok(refcount == 1, "Test %u: Got unexpected refcount %u.\n", i, refcount);
5052 refcount = ID3D11SamplerState_Release(sampler_state1);
5053 ok(!refcount, "Test %u: Got unexpected refcount %u.\n", i, refcount);
5056 refcount = ID3D11Device_Release(device);
5057 ok(!refcount, "Device has %u references left.\n", refcount);
5060 static void test_create_blend_state(void)
5062 static const D3D11_BLEND_DESC desc_conversion_tests[] =
5065 FALSE, FALSE,
5068 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5069 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD
5074 FALSE, TRUE,
5077 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5078 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5081 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5082 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_RED
5085 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5086 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5089 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5090 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_GREEN
5093 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5094 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5097 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5098 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5101 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5102 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5105 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5106 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5111 FALSE, TRUE,
5114 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5115 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5118 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_SUBTRACT,
5119 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5122 TRUE, D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD,
5123 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5126 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5127 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5130 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MAX,
5131 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5134 TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
5135 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5138 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5139 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5142 FALSE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
5143 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL
5149 ID3D11BlendState *blend_state1, *blend_state2;
5150 D3D11_BLEND_DESC desc, obtained_desc;
5151 ID3D10BlendState *d3d10_blend_state;
5152 D3D10_BLEND_DESC d3d10_blend_desc;
5153 ULONG refcount, expected_refcount;
5154 ID3D11Device *device, *tmp;
5155 unsigned int i, j;
5156 HRESULT hr;
5158 if (!(device = create_device(NULL)))
5160 skip("Failed to create device.\n");
5161 return;
5164 hr = ID3D11Device_CreateBlendState(device, NULL, &blend_state1);
5165 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5167 memset(&desc, 0, sizeof(desc));
5168 desc.AlphaToCoverageEnable = FALSE;
5169 desc.IndependentBlendEnable = FALSE;
5170 desc.RenderTarget[0].BlendEnable = FALSE;
5171 desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
5173 expected_refcount = get_refcount(device) + 1;
5174 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state1);
5175 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5176 hr = ID3D11Device_CreateBlendState(device, &desc, &blend_state2);
5177 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5178 ok(blend_state1 == blend_state2, "Got different blend state objects.\n");
5179 refcount = get_refcount(device);
5180 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5181 tmp = NULL;
5182 expected_refcount = refcount + 1;
5183 ID3D11BlendState_GetDevice(blend_state1, &tmp);
5184 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5185 refcount = get_refcount(device);
5186 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5187 ID3D11Device_Release(tmp);
5189 ID3D11BlendState_GetDesc(blend_state1, &obtained_desc);
5190 ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n",
5191 obtained_desc.AlphaToCoverageEnable);
5192 ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n",
5193 obtained_desc.IndependentBlendEnable);
5194 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
5196 ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE,
5197 "Got unexpected blend enable %#x for render target %u.\n",
5198 obtained_desc.RenderTarget[i].BlendEnable, i);
5199 ok(obtained_desc.RenderTarget[i].SrcBlend == D3D11_BLEND_ONE,
5200 "Got unexpected src blend %u for render target %u.\n",
5201 obtained_desc.RenderTarget[i].SrcBlend, i);
5202 ok(obtained_desc.RenderTarget[i].DestBlend == D3D11_BLEND_ZERO,
5203 "Got unexpected dest blend %u for render target %u.\n",
5204 obtained_desc.RenderTarget[i].DestBlend, i);
5205 ok(obtained_desc.RenderTarget[i].BlendOp == D3D11_BLEND_OP_ADD,
5206 "Got unexpected blend op %u for render target %u.\n",
5207 obtained_desc.RenderTarget[i].BlendOp, i);
5208 ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D11_BLEND_ONE,
5209 "Got unexpected src blend alpha %u for render target %u.\n",
5210 obtained_desc.RenderTarget[i].SrcBlendAlpha, i);
5211 ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D11_BLEND_ZERO,
5212 "Got unexpected dest blend alpha %u for render target %u.\n",
5213 obtained_desc.RenderTarget[i].DestBlendAlpha, i);
5214 ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D11_BLEND_OP_ADD,
5215 "Got unexpected blend op alpha %u for render target %u.\n",
5216 obtained_desc.RenderTarget[i].BlendOpAlpha, i);
5217 ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D11_COLOR_WRITE_ENABLE_ALL,
5218 "Got unexpected render target write mask %#x for render target %u.\n",
5219 obtained_desc.RenderTarget[0].RenderTargetWriteMask, i);
5222 /* Not available on all Windows versions. */
5223 check_interface(blend_state1, &IID_ID3D10BlendState, TRUE, TRUE);
5224 check_interface(blend_state1, &IID_ID3D10BlendState1, TRUE, TRUE);
5226 refcount = ID3D11BlendState_Release(blend_state1);
5227 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5228 refcount = ID3D11BlendState_Release(blend_state2);
5229 ok(!refcount, "Blend state has %u references left.\n", refcount);
5231 for (i = 0; i < ARRAY_SIZE(desc_conversion_tests); ++i)
5233 const D3D11_BLEND_DESC *current_desc = &desc_conversion_tests[i];
5235 hr = ID3D11Device_CreateBlendState(device, current_desc, &blend_state1);
5236 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
5238 hr = ID3D11BlendState_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state);
5239 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5240 "Blend state should implement ID3D10BlendState.\n");
5241 if (FAILED(hr))
5243 win_skip("Blend state does not implement ID3D10BlendState.\n");
5244 ID3D11BlendState_Release(blend_state1);
5245 break;
5248 ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc);
5249 ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable,
5250 "Got unexpected alpha to coverage enable %#x for test %u.\n",
5251 d3d10_blend_desc.AlphaToCoverageEnable, i);
5252 ok(d3d10_blend_desc.SrcBlend == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlend,
5253 "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i);
5254 ok(d3d10_blend_desc.DestBlend == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlend,
5255 "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i);
5256 ok(d3d10_blend_desc.BlendOp == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOp,
5257 "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i);
5258 ok(d3d10_blend_desc.SrcBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].SrcBlendAlpha,
5259 "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i);
5260 ok(d3d10_blend_desc.DestBlendAlpha == (D3D10_BLEND)current_desc->RenderTarget[0].DestBlendAlpha,
5261 "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i);
5262 ok(d3d10_blend_desc.BlendOpAlpha == (D3D10_BLEND_OP)current_desc->RenderTarget[0].BlendOpAlpha,
5263 "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i);
5264 for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
5266 unsigned int k = current_desc->IndependentBlendEnable ? j : 0;
5267 ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable,
5268 "Got unexpected blend enable %#x for test %u, render target %u.\n",
5269 d3d10_blend_desc.BlendEnable[j], i, j);
5270 ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask,
5271 "Got unexpected render target write mask %#x for test %u, render target %u.\n",
5272 d3d10_blend_desc.RenderTargetWriteMask[j], i, j);
5275 ID3D10BlendState_Release(d3d10_blend_state);
5277 refcount = ID3D11BlendState_Release(blend_state1);
5278 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5281 refcount = ID3D11Device_Release(device);
5282 ok(!refcount, "Device has %u references left.\n", refcount);
5285 static void test_create_depthstencil_state(void)
5287 ID3D11DepthStencilState *ds_state1, *ds_state2;
5288 ULONG refcount, expected_refcount;
5289 D3D11_DEPTH_STENCIL_DESC ds_desc;
5290 ID3D11Device *device, *tmp;
5291 HRESULT hr;
5293 if (!(device = create_device(NULL)))
5295 skip("Failed to create device.\n");
5296 return;
5299 hr = ID3D11Device_CreateDepthStencilState(device, NULL, &ds_state1);
5300 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5302 ds_desc.DepthEnable = TRUE;
5303 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
5304 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
5305 ds_desc.StencilEnable = FALSE;
5306 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
5307 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
5308 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
5309 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
5310 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
5311 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
5312 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
5313 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
5314 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
5315 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
5317 expected_refcount = get_refcount(device) + 1;
5318 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
5319 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5320 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state2);
5321 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5322 ok(ds_state1 == ds_state2, "Got different depthstencil state objects.\n");
5323 refcount = get_refcount(device);
5324 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5325 tmp = NULL;
5326 expected_refcount = refcount + 1;
5327 ID3D11DepthStencilState_GetDevice(ds_state1, &tmp);
5328 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5329 refcount = get_refcount(device);
5330 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5331 ID3D11Device_Release(tmp);
5333 /* Not available on all Windows versions. */
5334 check_interface(ds_state1, &IID_ID3D10DepthStencilState, TRUE, TRUE);
5336 refcount = ID3D11DepthStencilState_Release(ds_state2);
5337 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5338 refcount = ID3D11DepthStencilState_Release(ds_state1);
5339 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5341 ds_desc.DepthEnable = FALSE;
5342 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
5343 ds_desc.DepthFunc = D3D11_COMPARISON_NEVER;
5344 ds_desc.StencilEnable = FALSE;
5345 ds_desc.StencilReadMask = 0;
5346 ds_desc.StencilWriteMask = 0;
5347 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
5348 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
5349 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
5350 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
5351 ds_desc.BackFace = ds_desc.FrontFace;
5353 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state1);
5354 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
5356 memset(&ds_desc, 0, sizeof(ds_desc));
5357 ID3D11DepthStencilState_GetDesc(ds_state1, &ds_desc);
5358 ok(!ds_desc.DepthEnable, "Got unexpected depth enable %#x.\n", ds_desc.DepthEnable);
5359 ok(ds_desc.DepthWriteMask == D3D11_DEPTH_WRITE_MASK_ALL,
5360 "Got unexpected depth write mask %#x.\n", ds_desc.DepthWriteMask);
5361 ok(ds_desc.DepthFunc == D3D11_COMPARISON_LESS, "Got unexpected depth func %#x.\n", ds_desc.DepthFunc);
5362 ok(!ds_desc.StencilEnable, "Got unexpected stencil enable %#x.\n", ds_desc.StencilEnable);
5363 ok(ds_desc.StencilReadMask == D3D11_DEFAULT_STENCIL_READ_MASK,
5364 "Got unexpected stencil read mask %#x.\n", ds_desc.StencilReadMask);
5365 ok(ds_desc.StencilWriteMask == D3D11_DEFAULT_STENCIL_WRITE_MASK,
5366 "Got unexpected stencil write mask %#x.\n", ds_desc.StencilWriteMask);
5367 ok(ds_desc.FrontFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
5368 "Got unexpected front face stencil depth fail op %#x.\n", ds_desc.FrontFace.StencilDepthFailOp);
5369 ok(ds_desc.FrontFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
5370 "Got unexpected front face stencil pass op %#x.\n", ds_desc.FrontFace.StencilPassOp);
5371 ok(ds_desc.FrontFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
5372 "Got unexpected front face stencil fail op %#x.\n", ds_desc.FrontFace.StencilFailOp);
5373 ok(ds_desc.FrontFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
5374 "Got unexpected front face stencil func %#x.\n", ds_desc.FrontFace.StencilFunc);
5375 ok(ds_desc.BackFace.StencilDepthFailOp == D3D11_STENCIL_OP_KEEP,
5376 "Got unexpected back face stencil depth fail op %#x.\n", ds_desc.BackFace.StencilDepthFailOp);
5377 ok(ds_desc.BackFace.StencilPassOp == D3D11_STENCIL_OP_KEEP,
5378 "Got unexpected back face stencil pass op %#x.\n", ds_desc.BackFace.StencilPassOp);
5379 ok(ds_desc.BackFace.StencilFailOp == D3D11_STENCIL_OP_KEEP,
5380 "Got unexpected back face stencil fail op %#x.\n", ds_desc.BackFace.StencilFailOp);
5381 ok(ds_desc.BackFace.StencilFunc == D3D11_COMPARISON_ALWAYS,
5382 "Got unexpected back face stencil func %#x.\n", ds_desc.BackFace.StencilFunc);
5384 ID3D11DepthStencilState_Release(ds_state1);
5386 refcount = ID3D11Device_Release(device);
5387 ok(!refcount, "Device has %u references left.\n", refcount);
5390 static void test_create_rasterizer_state(void)
5392 ID3D11RasterizerState *rast_state1, *rast_state2;
5393 ID3D10RasterizerState *d3d10_rast_state;
5394 ULONG refcount, expected_refcount;
5395 D3D10_RASTERIZER_DESC d3d10_desc;
5396 D3D11_RASTERIZER_DESC desc;
5397 ID3D11Device *device, *tmp;
5398 HRESULT hr;
5400 if (!(device = create_device(NULL)))
5402 skip("Failed to create device.\n");
5403 return;
5406 hr = ID3D11Device_CreateRasterizerState(device, NULL, &rast_state1);
5407 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5409 desc.FillMode = D3D11_FILL_SOLID;
5410 desc.CullMode = D3D11_CULL_BACK;
5411 desc.FrontCounterClockwise = FALSE;
5412 desc.DepthBias = 0;
5413 desc.DepthBiasClamp = 0.0f;
5414 desc.SlopeScaledDepthBias = 0.0f;
5415 desc.DepthClipEnable = TRUE;
5416 desc.ScissorEnable = FALSE;
5417 desc.MultisampleEnable = FALSE;
5418 desc.AntialiasedLineEnable = FALSE;
5420 expected_refcount = get_refcount(device) + 1;
5421 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state1);
5422 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5423 hr = ID3D11Device_CreateRasterizerState(device, &desc, &rast_state2);
5424 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
5425 ok(rast_state1 == rast_state2, "Got different rasterizer state objects.\n");
5426 refcount = get_refcount(device);
5427 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5428 tmp = NULL;
5429 expected_refcount = refcount + 1;
5430 ID3D11RasterizerState_GetDevice(rast_state1, &tmp);
5431 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5432 refcount = get_refcount(device);
5433 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5434 ID3D11Device_Release(tmp);
5436 hr = ID3D11RasterizerState_QueryInterface(rast_state1, &IID_ID3D10RasterizerState, (void **)&d3d10_rast_state);
5437 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
5438 "Rasterizer state should implement ID3D10RasterizerState.\n");
5439 if (SUCCEEDED(hr))
5441 ID3D10RasterizerState_GetDesc(d3d10_rast_state, &d3d10_desc);
5442 ok(d3d10_desc.FillMode == D3D10_FILL_SOLID, "Got unexpected fill mode %u.\n", d3d10_desc.FillMode);
5443 ok(d3d10_desc.CullMode == D3D10_CULL_BACK, "Got unexpected cull mode %u.\n", d3d10_desc.CullMode);
5444 ok(!d3d10_desc.FrontCounterClockwise, "Got unexpected front counter clockwise %#x.\n",
5445 d3d10_desc.FrontCounterClockwise);
5446 ok(!d3d10_desc.DepthBias, "Got unexpected depth bias %d.\n", d3d10_desc.DepthBias);
5447 ok(!d3d10_desc.DepthBiasClamp, "Got unexpected depth bias clamp %f.\n", d3d10_desc.DepthBiasClamp);
5448 ok(!d3d10_desc.SlopeScaledDepthBias, "Got unexpected slope scaled depth bias %f.\n",
5449 d3d10_desc.SlopeScaledDepthBias);
5450 ok(!!d3d10_desc.DepthClipEnable, "Got unexpected depth clip enable %#x.\n", d3d10_desc.DepthClipEnable);
5451 ok(!d3d10_desc.ScissorEnable, "Got unexpected scissor enable %#x.\n", d3d10_desc.ScissorEnable);
5452 ok(!d3d10_desc.MultisampleEnable, "Got unexpected multisample enable %#x.\n",
5453 d3d10_desc.MultisampleEnable);
5454 ok(!d3d10_desc.AntialiasedLineEnable, "Got unexpected antialiased line enable %#x.\n",
5455 d3d10_desc.AntialiasedLineEnable);
5457 refcount = ID3D10RasterizerState_Release(d3d10_rast_state);
5458 ok(refcount == 2, "Got unexpected refcount %u.\n", refcount);
5461 refcount = ID3D11RasterizerState_Release(rast_state2);
5462 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
5463 refcount = ID3D11RasterizerState_Release(rast_state1);
5464 ok(!refcount, "Got unexpected refcount %u.\n", refcount);
5466 refcount = ID3D11Device_Release(device);
5467 ok(!refcount, "Device has %u references left.\n", refcount);
5470 static void test_create_query(void)
5472 static const struct
5474 D3D11_QUERY query;
5475 D3D_FEATURE_LEVEL required_feature_level;
5476 BOOL is_predicate;
5477 BOOL can_use_create_predicate;
5478 BOOL todo;
5480 tests[] =
5482 {D3D11_QUERY_EVENT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5483 {D3D11_QUERY_OCCLUSION, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5484 {D3D11_QUERY_TIMESTAMP, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5485 {D3D11_QUERY_TIMESTAMP_DISJOINT, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5486 {D3D11_QUERY_PIPELINE_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5487 {D3D11_QUERY_OCCLUSION_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, FALSE},
5488 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0, FALSE, FALSE, FALSE},
5489 {D3D11_QUERY_SO_OVERFLOW_PREDICATE, D3D_FEATURE_LEVEL_10_0, TRUE, TRUE, TRUE},
5490 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5491 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5492 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5493 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5494 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5495 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5496 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0, FALSE, FALSE, FALSE},
5497 {D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3, D3D_FEATURE_LEVEL_11_0, TRUE, FALSE, TRUE},
5500 ULONG refcount, expected_refcount;
5501 D3D_FEATURE_LEVEL feature_level;
5502 D3D11_QUERY_DESC query_desc;
5503 ID3D11Predicate *predicate;
5504 ID3D11Device *device, *tmp;
5505 HRESULT hr, expected_hr;
5506 ID3D11Query *query;
5507 unsigned int i;
5509 if (!(device = create_device(NULL)))
5511 skip("Failed to create device.\n");
5512 return;
5514 feature_level = ID3D11Device_GetFeatureLevel(device);
5516 hr = ID3D11Device_CreateQuery(device, NULL, &query);
5517 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5518 hr = ID3D11Device_CreatePredicate(device, NULL, &predicate);
5519 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5521 for (i = 0; i < ARRAY_SIZE(tests); ++i)
5523 if (tests[i].required_feature_level > feature_level)
5525 skip("Query type %u requires feature level %#x.\n", tests[i].query, tests[i].required_feature_level);
5526 continue;
5529 query_desc.Query = tests[i].query;
5530 query_desc.MiscFlags = 0;
5532 hr = ID3D11Device_CreateQuery(device, &query_desc, NULL);
5533 todo_wine_if(tests[i].todo)
5534 ok(hr == S_FALSE, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5536 query_desc.Query = tests[i].query;
5537 hr = ID3D11Device_CreateQuery(device, &query_desc, &query);
5538 todo_wine_if(tests[i].todo)
5539 ok(hr == S_OK, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5540 if (FAILED(hr))
5541 continue;
5543 check_interface(query, &IID_ID3D11Predicate, tests[i].is_predicate, FALSE);
5544 ID3D11Query_Release(query);
5546 expected_hr = tests[i].can_use_create_predicate ? S_FALSE : E_INVALIDARG;
5547 hr = ID3D11Device_CreatePredicate(device, &query_desc, NULL);
5548 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5550 expected_hr = tests[i].can_use_create_predicate ? S_OK : E_INVALIDARG;
5551 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
5552 ok(hr == expected_hr, "Got unexpected hr %#x for query type %u.\n", hr, query_desc.Query);
5553 if (SUCCEEDED(hr))
5554 ID3D11Predicate_Release(predicate);
5557 query_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
5558 expected_refcount = get_refcount(device) + 1;
5559 hr = ID3D11Device_CreatePredicate(device, &query_desc, &predicate);
5560 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
5561 refcount = get_refcount(device);
5562 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
5563 tmp = NULL;
5564 expected_refcount = refcount + 1;
5565 ID3D11Predicate_GetDevice(predicate, &tmp);
5566 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
5567 refcount = get_refcount(device);
5568 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
5569 ID3D11Device_Release(tmp);
5570 /* Not available on all Windows versions. */
5571 check_interface(predicate, &IID_ID3D10Predicate, TRUE, TRUE);
5572 ID3D11Predicate_Release(predicate);
5574 refcount = ID3D11Device_Release(device);
5575 ok(!refcount, "Device has %u references left.\n", refcount);
5578 #define get_query_data(a, b, c, d) get_query_data_(__LINE__, a, b, c, d)
5579 static void get_query_data_(unsigned int line, ID3D11DeviceContext *context,
5580 ID3D11Asynchronous *query, void *data, unsigned int data_size)
5582 unsigned int i;
5583 HRESULT hr;
5585 for (i = 0; i < 500; ++i)
5587 if ((hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0)) != S_FALSE)
5588 break;
5589 Sleep(10);
5591 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5592 memset(data, 0xff, data_size);
5593 hr = ID3D11DeviceContext_GetData(context, query, data, data_size, 0);
5594 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5597 static void test_occlusion_query(void)
5599 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5600 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5602 struct d3d11_test_context test_context;
5603 D3D11_TEXTURE2D_DESC texture_desc;
5604 ID3D11DeviceContext *context;
5605 ID3D11RenderTargetView *rtv;
5606 D3D11_QUERY_DESC query_desc;
5607 ID3D11Asynchronous *query;
5608 unsigned int data_size, i;
5609 ID3D11Texture2D *texture;
5610 ID3D11Device *device;
5611 union
5613 UINT64 uint;
5614 DWORD dword[2];
5615 } data;
5616 HRESULT hr;
5618 if (!init_test_context(&test_context, NULL))
5619 return;
5621 device = test_context.device;
5622 context = test_context.immediate_context;
5624 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5626 query_desc.Query = D3D11_QUERY_OCCLUSION;
5627 query_desc.MiscFlags = 0;
5628 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5629 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5630 data_size = ID3D11Asynchronous_GetDataSize(query);
5631 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
5633 memset(&data, 0xff, sizeof(data));
5634 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5635 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5636 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5637 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5638 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5639 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5641 ID3D11DeviceContext_End(context, query);
5642 ID3D11DeviceContext_Begin(context, query);
5643 ID3D11DeviceContext_Begin(context, query);
5645 memset(&data, 0xff, sizeof(data));
5646 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5647 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5648 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5649 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5650 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5651 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5653 draw_color_quad(&test_context, &red);
5655 ID3D11DeviceContext_End(context, query);
5656 get_query_data(context, query, &data, sizeof(data));
5657 ok(data.uint == 640 * 480, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5659 memset(&data, 0xff, sizeof(data));
5660 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(DWORD), 0);
5661 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5662 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(WORD), 0);
5663 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5664 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) - 1, 0);
5665 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5666 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data) + 1, 0);
5667 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5668 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5669 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5671 memset(&data, 0xff, sizeof(data));
5672 hr = ID3D11DeviceContext_GetData(context, query, &data, 0, 0);
5673 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5674 ok(data.dword[0] == 0xffffffff && data.dword[1] == 0xffffffff,
5675 "Data was modified 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5677 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(DWORD), 0);
5678 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5679 hr = ID3D11DeviceContext_GetData(context, query, NULL, sizeof(data), 0);
5680 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5682 ID3D11DeviceContext_Begin(context, query);
5683 ID3D11DeviceContext_End(context, query);
5684 ID3D11DeviceContext_End(context, query);
5686 get_query_data(context, query, &data, sizeof(data));
5687 ok(!data.uint, "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5688 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5689 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5691 texture_desc.Width = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
5692 texture_desc.Height = D3D10_REQ_TEXTURE2D_U_OR_V_DIMENSION;
5693 texture_desc.MipLevels = 1;
5694 texture_desc.ArraySize = 1;
5695 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
5696 texture_desc.SampleDesc.Count = 1;
5697 texture_desc.SampleDesc.Quality = 0;
5698 texture_desc.Usage = D3D11_USAGE_DEFAULT;
5699 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
5700 texture_desc.CPUAccessFlags = 0;
5701 texture_desc.MiscFlags = 0;
5702 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
5703 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
5704 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
5705 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
5707 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
5708 set_viewport(context, 0.0f, 0.0f, texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
5710 ID3D11DeviceContext_Begin(context, query);
5711 for (i = 0; i < 100; i++)
5712 draw_color_quad(&test_context, &red);
5713 ID3D11DeviceContext_End(context, query);
5715 get_query_data(context, query, &data, sizeof(data));
5716 ok((data.dword[0] == 0x90000000 && data.dword[1] == 0x1)
5717 || (data.dword[0] == 0xffffffff && !data.dword[1])
5718 || broken(!data.uint),
5719 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5720 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5721 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5723 ID3D11Asynchronous_Release(query);
5725 /* The following test exercises a code path in wined3d. A wined3d context
5726 * associated with the query is destroyed when the swapchain is released. */
5727 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5728 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5730 set_viewport(context, 0.0f, 0.0f, 64.0f, 64.0f, 0.0f, 1.0f);
5731 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5732 ID3D11DeviceContext_Begin(context, query);
5733 draw_color_quad(&test_context, &red);
5734 ID3D11DeviceContext_End(context, query);
5736 ID3D11RenderTargetView_Release(test_context.backbuffer_rtv);
5737 ID3D11Texture2D_Release(test_context.backbuffer);
5738 IDXGISwapChain_Release(test_context.swapchain);
5739 test_context.swapchain = create_swapchain(device, test_context.window, NULL);
5740 hr = IDXGISwapChain_GetBuffer(test_context.swapchain, 0, &IID_ID3D11Texture2D,
5741 (void **)&test_context.backbuffer);
5742 ok(SUCCEEDED(hr), "Failed to get backbuffer, hr %#x.\n", hr);
5743 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer,
5744 NULL, &test_context.backbuffer_rtv);
5745 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
5746 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
5747 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5749 get_query_data(context, query, &data, sizeof(data));
5750 /* This test occasionally succeeds with CSMT enabled because of a race condition. */
5751 if (0)
5752 todo_wine ok(data.dword[0] == 0x1000 && !data.dword[1],
5753 "Got unexpected query result 0x%08x%08x.\n", data.dword[1], data.dword[0]);
5755 ID3D11Asynchronous_Release(query);
5756 ID3D11RenderTargetView_Release(rtv);
5757 ID3D11Texture2D_Release(texture);
5758 release_test_context(&test_context);
5761 static void test_pipeline_statistics_query(void)
5763 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5764 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
5766 D3D11_QUERY_DATA_PIPELINE_STATISTICS data;
5767 struct d3d11_test_context test_context;
5768 ID3D11DeviceContext *context;
5769 D3D11_QUERY_DESC query_desc;
5770 ID3D11Asynchronous *query;
5771 unsigned int data_size;
5772 ID3D11Device *device;
5773 HRESULT hr;
5775 if (!init_test_context(&test_context, NULL))
5776 return;
5778 device = test_context.device;
5779 context = test_context.immediate_context;
5781 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
5783 query_desc.Query = D3D11_QUERY_PIPELINE_STATISTICS;
5784 query_desc.MiscFlags = 0;
5785 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
5786 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5787 data_size = ID3D11Asynchronous_GetDataSize(query);
5788 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
5790 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5791 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5792 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5793 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5795 ID3D11DeviceContext_End(context, query);
5796 ID3D11DeviceContext_Begin(context, query);
5797 ID3D11DeviceContext_Begin(context, query);
5799 memset(&data, 0xff, sizeof(data));
5800 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
5801 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5802 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
5803 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5804 ok(data.IAVertices == ~(UINT64)0, "Data was modified.\n");
5806 draw_quad(&test_context);
5808 ID3D11DeviceContext_End(context, query);
5809 get_query_data(context, query, &data, sizeof(data));
5810 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5811 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5812 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5813 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5814 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5815 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5816 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5817 todo_wine
5818 ok(!data.PSInvocations, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5819 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5820 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5821 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5823 ID3D11DeviceContext_Begin(context, query);
5824 draw_color_quad(&test_context, &red);
5825 ID3D11DeviceContext_End(context, query);
5826 get_query_data(context, query, &data, sizeof(data));
5827 ok(data.IAVertices == 4, "Got unexpected IAVertices count: %u.\n", (unsigned int)data.IAVertices);
5828 ok(data.IAPrimitives == 2, "Got unexpected IAPrimitives count: %u.\n", (unsigned int)data.IAPrimitives);
5829 ok(data.VSInvocations == 4, "Got unexpected VSInvocations count: %u.\n", (unsigned int)data.VSInvocations);
5830 ok(!data.GSInvocations, "Got unexpected GSInvocations count: %u.\n", (unsigned int)data.GSInvocations);
5831 ok(!data.GSPrimitives, "Got unexpected GSPrimitives count: %u.\n", (unsigned int)data.GSPrimitives);
5832 ok(data.CInvocations == 2, "Got unexpected CInvocations count: %u.\n", (unsigned int)data.CInvocations);
5833 ok(data.CPrimitives == 2, "Got unexpected CPrimitives count: %u.\n", (unsigned int)data.CPrimitives);
5834 ok(data.PSInvocations >= 640 * 480, "Got unexpected PSInvocations count: %u.\n", (unsigned int)data.PSInvocations);
5835 ok(!data.HSInvocations, "Got unexpected HSInvocations count: %u.\n", (unsigned int)data.HSInvocations);
5836 ok(!data.DSInvocations, "Got unexpected DSInvocations count: %u.\n", (unsigned int)data.DSInvocations);
5837 ok(!data.CSInvocations, "Got unexpected CSInvocations count: %u.\n", (unsigned int)data.CSInvocations);
5839 ID3D11Asynchronous_Release(query);
5840 release_test_context(&test_context);
5843 static void test_timestamp_query(void)
5845 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
5847 ID3D11Asynchronous *timestamp_query, *timestamp_disjoint_query;
5848 D3D11_QUERY_DATA_TIMESTAMP_DISJOINT disjoint, prev_disjoint;
5849 struct d3d11_test_context test_context;
5850 ID3D11DeviceContext *context;
5851 D3D11_QUERY_DESC query_desc;
5852 unsigned int data_size;
5853 ID3D11Device *device;
5854 UINT64 timestamp;
5855 HRESULT hr;
5857 if (!init_test_context(&test_context, NULL))
5858 return;
5860 device = test_context.device;
5861 context = test_context.immediate_context;
5863 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5864 query_desc.MiscFlags = 0;
5865 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5866 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5867 data_size = ID3D11Asynchronous_GetDataSize(timestamp_query);
5868 ok(data_size == sizeof(UINT64), "Got unexpected data size %u.\n", data_size);
5870 query_desc.Query = D3D11_QUERY_TIMESTAMP_DISJOINT;
5871 query_desc.MiscFlags = 0;
5872 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_disjoint_query);
5873 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5874 data_size = ID3D11Asynchronous_GetDataSize(timestamp_disjoint_query);
5875 ok(data_size == sizeof(disjoint), "Got unexpected data size %u.\n", data_size);
5877 disjoint.Frequency = 0xdeadbeef;
5878 disjoint.Disjoint = 0xdeadbeef;
5879 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5880 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5881 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5882 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5883 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5884 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5886 /* Test a TIMESTAMP_DISJOINT query. */
5887 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5889 disjoint.Frequency = 0xdeadbeef;
5890 disjoint.Disjoint = 0xdeadbeef;
5891 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5892 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5893 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5894 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5895 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5896 ok(disjoint.Disjoint == 0xdeadbeef, "Disjoint data was modified.\n");
5898 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5899 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5900 ok(disjoint.Frequency != ~(UINT64)0, "Frequency data was not modified.\n");
5901 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5903 prev_disjoint = disjoint;
5905 disjoint.Frequency = 0xdeadbeef;
5906 disjoint.Disjoint = 0xff;
5907 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) - 1, 0);
5908 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5909 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) + 1, 0);
5910 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5911 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) / 2, 0);
5912 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5913 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint) * 2, 0);
5914 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5915 ok(disjoint.Frequency == 0xdeadbeef, "Frequency data was modified.\n");
5916 ok(disjoint.Disjoint == 0xff, "Disjoint data was modified.\n");
5918 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, NULL, 0, 0);
5919 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5920 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint),
5921 D3D11_ASYNC_GETDATA_DONOTFLUSH);
5922 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5923 ok(disjoint.Frequency == prev_disjoint.Frequency, "Frequency data mismatch.\n");
5924 ok(disjoint.Disjoint == prev_disjoint.Disjoint, "Disjoint data mismatch.\n");
5926 memset(&timestamp, 0xff, sizeof(timestamp));
5927 hr = ID3D11DeviceContext_GetData(context, timestamp_query, NULL, 0, 0);
5928 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5929 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5930 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5931 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5933 /* Test a TIMESTAMP query inside a TIMESTAMP_DISJOINT query. */
5934 ID3D11DeviceContext_Begin(context, timestamp_disjoint_query);
5936 memset(&timestamp, 0xff, sizeof(timestamp));
5937 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5938 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
5939 ok(timestamp == ~(UINT64)0, "Timestamp data was modified.\n");
5941 draw_color_quad(&test_context, &red);
5943 ID3D11DeviceContext_End(context, timestamp_query);
5944 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5946 timestamp = 0xdeadbeef;
5947 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5948 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5949 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5951 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp), 0);
5952 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5953 ok(timestamp != 0xdeadbeef, "Timestamp was not modified.\n");
5955 timestamp = 0xdeadbeef;
5956 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) - 1, 0);
5957 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5958 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) + 1, 0);
5959 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5960 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) / 2, 0);
5961 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5962 hr = ID3D11DeviceContext_GetData(context, timestamp_query, &timestamp, sizeof(timestamp) * 2, 0);
5963 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
5964 ok(timestamp == 0xdeadbeef, "Timestamp was modified.\n");
5966 ID3D11DeviceContext_End(context, timestamp_disjoint_query);
5967 get_query_data(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint));
5968 disjoint.Frequency = 0xdeadbeef;
5969 disjoint.Disjoint = 0xff;
5970 hr = ID3D11DeviceContext_GetData(context, timestamp_disjoint_query, &disjoint, sizeof(disjoint), 0);
5971 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5972 ok(disjoint.Frequency != 0xdeadbeef, "Frequency data was not modified.\n");
5973 ok(disjoint.Disjoint == TRUE || disjoint.Disjoint == FALSE, "Got unexpected disjoint %#x.\n", disjoint.Disjoint);
5975 /* It's not strictly necessary for the TIMESTAMP query to be inside a TIMESTAMP_DISJOINT query. */
5976 ID3D11Asynchronous_Release(timestamp_query);
5977 query_desc.Query = D3D11_QUERY_TIMESTAMP;
5978 query_desc.MiscFlags = 0;
5979 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&timestamp_query);
5980 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
5982 draw_color_quad(&test_context, &red);
5984 ID3D11DeviceContext_End(context, timestamp_query);
5985 get_query_data(context, timestamp_query, &timestamp, sizeof(timestamp));
5987 ID3D11Asynchronous_Release(timestamp_query);
5988 ID3D11Asynchronous_Release(timestamp_disjoint_query);
5989 release_test_context(&test_context);
5992 static void test_so_statistics_query(void)
5994 struct d3d11_test_context test_context;
5995 D3D11_QUERY_DATA_SO_STATISTICS data;
5996 ID3D11DeviceContext *context;
5997 unsigned int vertex_count[4];
5998 D3D11_QUERY_DESC query_desc;
5999 ID3D11Buffer *so_buffer[4];
6000 ID3D11Asynchronous *query;
6001 ID3D11GeometryShader *gs;
6002 ID3D11VertexShader *vs;
6003 unsigned int data_size;
6004 ID3D11Device *device;
6005 ID3D11Buffer *cb;
6006 unsigned int i;
6007 HRESULT hr;
6009 static const DWORD vs_code[] =
6011 #if 0
6012 float4 main(uint id : SV_VertexID) : custom
6014 return (float4)id;
6016 #endif
6017 0x43425844, 0x8b0e47b9, 0x6efc9512, 0xd55ca6ff, 0x487c5ef2, 0x00000001, 0x000000d4, 0x00000003,
6018 0x0000002c, 0x00000060, 0x00000090, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6019 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
6020 0x4e47534f, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6021 0x00000000, 0x0000000f, 0x74737563, 0xab006d6f, 0x52444853, 0x0000003c, 0x00010040, 0x0000000f,
6022 0x04000060, 0x00101012, 0x00000000, 0x00000006, 0x03000065, 0x001020f2, 0x00000000, 0x05000056,
6023 0x001020f2, 0x00000000, 0x00101006, 0x00000000, 0x0100003e,
6025 static const DWORD gs_code[] =
6027 #if 0
6028 struct vertex
6030 float4 data : custom;
6033 uint4 vertex_count;
6035 [maxvertexcount(32)]
6036 void main(point vertex input[1], uint id : SV_PrimitiveID,
6037 inout PointStream<vertex> output0,
6038 inout PointStream<vertex> output1,
6039 inout PointStream<vertex> output2,
6040 inout PointStream<vertex> output3)
6042 if (id < vertex_count.x)
6043 output0.Append(input[0]);
6044 if (id < vertex_count.y)
6045 output1.Append(input[0]);
6046 if (id < vertex_count.z)
6047 output2.Append(input[0]);
6048 if (id < vertex_count.w)
6049 output3.Append(input[0]);
6051 #endif
6052 0x43425844, 0xd616829d, 0x4355ce2a, 0xd71909e5, 0xdc916d4c, 0x00000001, 0x000002bc, 0x00000003,
6053 0x0000002c, 0x00000084, 0x0000010c, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
6054 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000003f, 0x00000000, 0x00000007,
6055 0x00000001, 0xffffffff, 0x00000101, 0x74737563, 0x53006d6f, 0x72505f56, 0x74696d69, 0x49657669,
6056 0xabab0044, 0x3547534f, 0x00000080, 0x00000004, 0x00000008, 0x00000000, 0x00000078, 0x00000000,
6057 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000001, 0x00000078, 0x00000000, 0x00000000,
6058 0x00000003, 0x00000000, 0x0000000f, 0x00000002, 0x00000078, 0x00000000, 0x00000000, 0x00000003,
6059 0x00000000, 0x0000000f, 0x00000003, 0x00000078, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
6060 0x0000000f, 0x74737563, 0xab006d6f, 0x58454853, 0x000001a8, 0x00020050, 0x0000006a, 0x0100086a,
6061 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000,
6062 0x0200005f, 0x0000b000, 0x02000068, 0x00000001, 0x0100085d, 0x0300008f, 0x00110000, 0x00000000,
6063 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000001, 0x0100085c,
6064 0x03000065, 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000002, 0x0100085c, 0x03000065,
6065 0x001020f2, 0x00000000, 0x0300008f, 0x00110000, 0x00000003, 0x0100085c, 0x03000065, 0x001020f2,
6066 0x00000000, 0x0200005e, 0x00000020, 0x0700004f, 0x001000f2, 0x00000000, 0x0000b001, 0x00208e46,
6067 0x00000000, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000,
6068 0x00201e46, 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x01000015, 0x0304001f,
6069 0x0010001a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000, 0x00000000,
6070 0x03000075, 0x00110000, 0x00000001, 0x01000015, 0x0304001f, 0x0010002a, 0x00000000, 0x06000036,
6071 0x001020f2, 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000002,
6072 0x01000015, 0x0304001f, 0x0010003a, 0x00000000, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
6073 0x00000000, 0x00000000, 0x03000075, 0x00110000, 0x00000003, 0x01000015, 0x0100003e,
6075 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
6077 {0, "custom", 0, 0, 4, 0},
6078 {1, "custom", 0, 0, 4, 1},
6079 {2, "custom", 0, 0, 4, 2},
6080 {3, "custom", 0, 0, 4, 3},
6082 static const unsigned int offset[4] = {0};
6084 static const struct
6086 D3D11_QUERY query;
6087 D3D_FEATURE_LEVEL feature_level;
6089 tests[] =
6091 {D3D11_QUERY_SO_STATISTICS, D3D_FEATURE_LEVEL_10_0},
6092 {D3D11_QUERY_SO_STATISTICS_STREAM0, D3D_FEATURE_LEVEL_11_0},
6093 {D3D11_QUERY_SO_STATISTICS_STREAM1, D3D_FEATURE_LEVEL_11_0},
6094 {D3D11_QUERY_SO_STATISTICS_STREAM2, D3D_FEATURE_LEVEL_11_0},
6095 {D3D11_QUERY_SO_STATISTICS_STREAM3, D3D_FEATURE_LEVEL_11_0},
6098 if (!init_test_context(&test_context, NULL))
6099 return;
6101 device = test_context.device;
6102 context = test_context.immediate_context;
6104 for (i = 0; i < ARRAY_SIZE(tests); ++i)
6106 if (ID3D11Device_GetFeatureLevel(device) < tests[i].feature_level)
6108 skip("Feature level %#x is required.\n", tests[i].feature_level);
6109 continue;
6112 query_desc.Query = tests[i].query;
6113 query_desc.MiscFlags = 0;
6114 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
6115 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6116 data_size = ID3D11Asynchronous_GetDataSize(query);
6117 ok(data_size == sizeof(data), "Got unexpected data size %u.\n", data_size);
6119 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
6120 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6121 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
6122 ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6124 ID3D11DeviceContext_End(context, query);
6125 ID3D11DeviceContext_Begin(context, query);
6126 ID3D11DeviceContext_Begin(context, query);
6128 memset(&data, 0xff, sizeof(data));
6129 hr = ID3D11DeviceContext_GetData(context, query, NULL, 0, 0);
6130 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6131 hr = ID3D11DeviceContext_GetData(context, query, &data, sizeof(data), 0);
6132 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
6133 ok(data.NumPrimitivesWritten == ~(UINT64)0, "Data was modified.\n");
6134 ok(data.PrimitivesStorageNeeded == ~(UINT64)0, "Data was modified.\n");
6136 draw_quad(&test_context);
6138 ID3D11DeviceContext_End(context, query);
6139 get_query_data(context, query, &data, sizeof(data));
6140 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
6141 (unsigned int)data.NumPrimitivesWritten);
6142 todo_wine_if(query_desc.Query == D3D11_QUERY_SO_STATISTICS || query_desc.Query == D3D11_QUERY_SO_STATISTICS_STREAM0)
6143 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
6144 (unsigned int)data.PrimitivesStorageNeeded);
6146 ID3D11DeviceContext_Begin(context, query);
6147 draw_quad(&test_context);
6148 ID3D11DeviceContext_End(context, query);
6149 get_query_data(context, query, &data, sizeof(data));
6150 ok(!data.NumPrimitivesWritten, "Got unexpected NumPrimitivesWritten: %u.\n",
6151 (unsigned int)data.NumPrimitivesWritten);
6152 todo_wine_if(query_desc.Query == D3D11_QUERY_SO_STATISTICS || query_desc.Query == D3D11_QUERY_SO_STATISTICS_STREAM0)
6153 ok(!data.PrimitivesStorageNeeded, "Got unexpected PrimitivesStorageNeeded: %u.\n",
6154 (unsigned int)data.PrimitivesStorageNeeded);
6156 ID3D11Asynchronous_Release(query);
6159 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
6161 skip("Vertex streams are not supported.\n");
6162 goto done;
6165 /* multiple vertex streams */
6166 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
6167 ok(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
6168 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
6170 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
6171 so_declaration, ARRAY_SIZE(so_declaration),
6172 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
6173 todo_wine
6174 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
6175 if (FAILED(hr))
6177 ID3D11VertexShader_Release(vs);
6178 goto done;
6180 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
6182 for (i = 0; i < ARRAY_SIZE(vertex_count); ++i)
6183 vertex_count[i] = 5;
6184 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(vertex_count), vertex_count);
6185 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
6187 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
6189 query_desc.Query = D3D11_QUERY_SO_STATISTICS;
6190 query_desc.MiscFlags = 0;
6191 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
6192 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6194 ID3D11DeviceContext_Begin(context, query);
6195 ID3D11DeviceContext_Draw(context, 5, 0);
6196 ID3D11DeviceContext_End(context, query);
6198 memset(&data, 0xff, sizeof(data));
6199 get_query_data(context, query, &data, sizeof(data));
6200 ok(!data.NumPrimitivesWritten, "Got unexpected primitives written %u.\n",
6201 (unsigned int)data.NumPrimitivesWritten);
6202 ok(data.PrimitivesStorageNeeded == 5, "Got unexpected primitives storage needed %u.\n",
6203 (unsigned int)data.PrimitivesStorageNeeded);
6205 for (i = 0; i < ARRAY_SIZE(so_buffer); ++i)
6206 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(struct vec4) * 10, NULL);
6208 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6209 ID3D11DeviceContext_Begin(context, query);
6210 ID3D11DeviceContext_Draw(context, 16, 0);
6211 ID3D11DeviceContext_End(context, query);
6212 memset(&data, 0xff, sizeof(data));
6213 get_query_data(context, query, &data, sizeof(data));
6214 ok(data.NumPrimitivesWritten == 5, "Got unexpected primitives written %u.\n",
6215 (unsigned int)data.NumPrimitivesWritten);
6216 ok(data.PrimitivesStorageNeeded == 5, "Got unexpected primitives storage needed %u.\n",
6217 (unsigned int)data.PrimitivesStorageNeeded);
6219 vertex_count[0] = 3;
6220 vertex_count[1] = 6;
6221 vertex_count[2] = 4;
6222 vertex_count[3] = 12;
6223 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, vertex_count, 0, 0);
6225 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6226 ID3D11DeviceContext_Begin(context, query);
6227 ID3D11DeviceContext_Draw(context, 32, 0);
6228 ID3D11DeviceContext_End(context, query);
6229 memset(&data, 0xff, sizeof(data));
6230 get_query_data(context, query, &data, sizeof(data));
6231 ok(data.NumPrimitivesWritten == 3, "Got unexpected primitives written %u.\n",
6232 (unsigned int)data.NumPrimitivesWritten);
6233 ok(data.PrimitivesStorageNeeded == 3, "Got unexpected primitives storage needed %u.\n",
6234 (unsigned int)data.PrimitivesStorageNeeded);
6236 vertex_count[0] = 16;
6237 vertex_count[1] = 6;
6238 vertex_count[2] = 4;
6239 vertex_count[3] = 12;
6240 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, vertex_count, 0, 0);
6242 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
6243 ID3D11DeviceContext_Begin(context, query);
6244 ID3D11DeviceContext_Draw(context, 32, 0);
6245 ID3D11DeviceContext_End(context, query);
6246 memset(&data, 0xff, sizeof(data));
6247 get_query_data(context, query, &data, sizeof(data));
6248 ok(data.NumPrimitivesWritten == 10, "Got unexpected primitives written %u.\n",
6249 (unsigned int)data.NumPrimitivesWritten);
6250 ok(data.PrimitivesStorageNeeded == 16, "Got unexpected primitives storage needed %u.\n",
6251 (unsigned int)data.PrimitivesStorageNeeded);
6253 ID3D11Asynchronous_Release(query);
6255 for (i = 0; i < ARRAY_SIZE(so_buffer); ++i)
6256 ID3D11Buffer_Release(so_buffer[i]);
6257 ID3D11Buffer_Release(cb);
6258 ID3D11GeometryShader_Release(gs);
6259 ID3D11VertexShader_Release(vs);
6261 done:
6262 release_test_context(&test_context);
6265 static void test_device_removed_reason(void)
6267 ID3D11Device *device;
6268 ULONG refcount;
6269 HRESULT hr;
6271 if (!(device = create_device(NULL)))
6273 skip("Failed to create device.\n");
6274 return;
6277 hr = ID3D11Device_GetDeviceRemovedReason(device);
6278 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6279 hr = ID3D11Device_GetDeviceRemovedReason(device);
6280 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6282 refcount = ID3D11Device_Release(device);
6283 ok(!refcount, "Device has %u references left.\n", refcount);
6286 static void test_private_data(void)
6288 ULONG refcount, expected_refcount;
6289 D3D11_TEXTURE2D_DESC texture_desc;
6290 ID3D10Texture2D *d3d10_texture;
6291 ID3D11Device *test_object;
6292 ID3D11Texture2D *texture;
6293 IDXGIDevice *dxgi_device;
6294 IDXGISurface *surface;
6295 ID3D11Device *device;
6296 IUnknown *ptr;
6297 HRESULT hr;
6298 UINT size;
6300 static const GUID test_guid =
6301 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
6302 static const GUID test_guid2 =
6303 {0x2e5afac2, 0x87b5, 0x4c10, {0x9b, 0x4b, 0x89, 0xd7, 0xd1, 0x12, 0xe7, 0x2b}};
6304 static const DWORD data[] = {1, 2, 3, 4};
6306 if (!(device = create_device(NULL)))
6308 skip("Failed to create device.\n");
6309 return;
6312 test_object = create_device(NULL);
6314 texture_desc.Width = 512;
6315 texture_desc.Height = 512;
6316 texture_desc.MipLevels = 1;
6317 texture_desc.ArraySize = 1;
6318 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6319 texture_desc.SampleDesc.Count = 1;
6320 texture_desc.SampleDesc.Quality = 0;
6321 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6322 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6323 texture_desc.CPUAccessFlags = 0;
6324 texture_desc.MiscFlags = 0;
6326 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6327 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6328 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&surface);
6329 ok(SUCCEEDED(hr), "Failed to get IDXGISurface, hr %#x.\n", hr);
6331 hr = ID3D11Device_SetPrivateData(device, &test_guid, 0, NULL);
6332 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6333 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6334 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6335 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6336 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6337 hr = ID3D11Device_SetPrivateData(device, &test_guid, ~0u, NULL);
6338 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6340 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6341 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6342 size = sizeof(ptr) * 2;
6343 ptr = (IUnknown *)0xdeadbeef;
6344 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6345 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6346 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6347 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6349 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
6350 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
6351 size = sizeof(ptr) * 2;
6352 ptr = (IUnknown *)0xdeadbeef;
6353 hr = IDXGIDevice_GetPrivateData(dxgi_device, &test_guid, &size, &ptr);
6354 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6355 ok(!ptr, "Got unexpected pointer %p.\n", ptr);
6356 ok(size == sizeof(IUnknown *), "Got unexpected size %u.\n", size);
6357 IDXGIDevice_Release(dxgi_device);
6359 refcount = get_refcount(test_object);
6360 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6361 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6362 expected_refcount = refcount + 1;
6363 refcount = get_refcount(test_object);
6364 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6365 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6366 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6367 refcount = get_refcount(test_object);
6368 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6370 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, NULL);
6371 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6372 --expected_refcount;
6373 refcount = get_refcount(test_object);
6374 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6376 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6377 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6378 size = sizeof(data);
6379 hr = ID3D11Device_SetPrivateData(device, &test_guid, size, data);
6380 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6381 refcount = get_refcount(test_object);
6382 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6383 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
6384 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6385 hr = ID3D11Device_SetPrivateData(device, &test_guid, 42, NULL);
6386 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6388 hr = ID3D11Device_SetPrivateDataInterface(device, &test_guid, (IUnknown *)test_object);
6389 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6390 ++expected_refcount;
6391 size = 2 * sizeof(ptr);
6392 ptr = NULL;
6393 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6394 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6395 ok(size == sizeof(test_object), "Got unexpected size %u.\n", size);
6396 ++expected_refcount;
6397 refcount = get_refcount(test_object);
6398 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6399 IUnknown_Release(ptr);
6400 --expected_refcount;
6402 ptr = (IUnknown *)0xdeadbeef;
6403 size = 1;
6404 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
6405 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6406 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6407 size = 2 * sizeof(ptr);
6408 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, NULL);
6409 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6410 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6411 refcount = get_refcount(test_object);
6412 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
6414 size = 1;
6415 hr = ID3D11Device_GetPrivateData(device, &test_guid, &size, &ptr);
6416 ok(hr == DXGI_ERROR_MORE_DATA, "Got unexpected hr %#x.\n", hr);
6417 ok(size == sizeof(device), "Got unexpected size %u.\n", size);
6418 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6419 if (!enable_debug_layer)
6421 hr = ID3D11Device_GetPrivateData(device, &test_guid2, NULL, NULL);
6422 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6423 size = 0xdeadbabe;
6424 hr = ID3D11Device_GetPrivateData(device, &test_guid2, &size, &ptr);
6425 ok(hr == DXGI_ERROR_NOT_FOUND, "Got unexpected hr %#x.\n", hr);
6426 ok(size == 0, "Got unexpected size %u.\n", size);
6427 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6428 hr = ID3D11Device_GetPrivateData(device, &test_guid, NULL, &ptr);
6429 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6430 ok(ptr == (IUnknown *)0xdeadbeef, "Got unexpected pointer %p.\n", ptr);
6433 hr = ID3D11Texture2D_SetPrivateDataInterface(texture, &test_guid, (IUnknown *)test_object);
6434 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6435 ptr = NULL;
6436 size = sizeof(ptr);
6437 hr = IDXGISurface_GetPrivateData(surface, &test_guid, &size, &ptr);
6438 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6439 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6440 IUnknown_Release(ptr);
6442 hr = ID3D11Texture2D_QueryInterface(texture, &IID_ID3D10Texture2D, (void **)&d3d10_texture);
6443 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
6444 "Texture should implement ID3D10Texture2D.\n");
6445 if (SUCCEEDED(hr))
6447 ptr = NULL;
6448 size = sizeof(ptr);
6449 hr = ID3D10Texture2D_GetPrivateData(d3d10_texture, &test_guid, &size, &ptr);
6450 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6451 ok(ptr == (IUnknown *)test_object, "Got unexpected ptr %p, expected %p.\n", ptr, test_object);
6452 IUnknown_Release(ptr);
6453 ID3D10Texture2D_Release(d3d10_texture);
6456 IDXGISurface_Release(surface);
6457 ID3D11Texture2D_Release(texture);
6458 refcount = ID3D11Device_Release(device);
6459 ok(!refcount, "Device has %u references left.\n", refcount);
6460 refcount = ID3D11Device_Release(test_object);
6461 ok(!refcount, "Test object has %u references left.\n", refcount);
6464 static void test_state_refcounting(const D3D_FEATURE_LEVEL feature_level)
6466 ID3D11RasterizerState *rasterizer_state, *tmp_rasterizer_state;
6467 ID3D11Predicate *predicate, *tmp_predicate;
6468 ID3D11SamplerState *sampler, *tmp_sampler;
6469 ID3D11ShaderResourceView *srv, *tmp_srv;
6470 ID3D11RenderTargetView *rtv, *tmp_rtv;
6471 D3D11_RASTERIZER_DESC rasterizer_desc;
6472 D3D11_TEXTURE2D_DESC texture_desc;
6473 D3D11_QUERY_DESC predicate_desc;
6474 D3D11_SAMPLER_DESC sampler_desc;
6475 struct device_desc device_desc;
6476 ID3D11DeviceContext *context;
6477 ID3D11Texture2D *texture;
6478 ID3D11Device *device;
6479 ULONG refcount;
6480 HRESULT hr;
6482 device_desc.feature_level = &feature_level;
6483 device_desc.flags = 0;
6484 if (!(device = create_device(&device_desc)))
6486 skip("Failed to create device for feature level %#x.\n", feature_level);
6487 return;
6490 ID3D11Device_GetImmediateContext(device, &context);
6492 /* ID3D11SamplerState */
6493 memset(&sampler_desc, 0, sizeof(sampler_desc));
6494 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
6495 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
6496 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
6497 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
6498 sampler_desc.MaxLOD = FLT_MAX;
6499 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
6500 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6502 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
6503 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6504 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6505 ID3D11SamplerState_Release(tmp_sampler);
6507 tmp_sampler = sampler;
6508 refcount = get_refcount(sampler);
6509 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
6510 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
6511 refcount = ID3D11SamplerState_Release(sampler);
6512 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6513 sampler = NULL;
6514 ID3D11DeviceContext_PSGetSamplers(context, 0, 1, &sampler);
6515 ok(sampler == tmp_sampler, "Got sampler %p, expected %p.\n", sampler, tmp_sampler);
6516 refcount = ID3D11SamplerState_Release(sampler);
6517 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6519 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &tmp_sampler);
6520 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6521 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
6522 refcount = ID3D11SamplerState_Release(tmp_sampler);
6523 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6525 /* ID3D11RasterizerState */
6526 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
6527 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
6528 rasterizer_desc.CullMode = D3D11_CULL_BACK;
6529 rasterizer_desc.DepthClipEnable = TRUE;
6530 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
6531 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
6533 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
6534 refcount = ID3D11RasterizerState_Release(rasterizer_state);
6535 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6536 ID3D11DeviceContext_RSGetState(context, &tmp_rasterizer_state);
6537 ok(tmp_rasterizer_state == rasterizer_state, "Got rasterizer state %p, expected %p.\n",
6538 tmp_rasterizer_state, rasterizer_state);
6539 refcount = ID3D11RasterizerState_Release(tmp_rasterizer_state);
6540 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6542 /* ID3D11ShaderResourceView */
6543 memset(&texture_desc, 0, sizeof(texture_desc));
6544 texture_desc.Width = 32;
6545 texture_desc.Height = 32;
6546 texture_desc.MipLevels = 1;
6547 texture_desc.ArraySize = 1;
6548 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6549 texture_desc.SampleDesc.Count = 1;
6550 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6551 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
6552 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6553 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6554 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
6555 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
6556 ID3D11Texture2D_Release(texture);
6558 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
6559 refcount = ID3D11ShaderResourceView_Release(srv);
6560 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6561 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &tmp_srv);
6562 ok(tmp_srv == srv, "Got SRV %p, expected %p.\n", tmp_srv, srv);
6563 refcount = ID3D11ShaderResourceView_Release(tmp_srv);
6564 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6566 /* ID3D11RenderTargetView */
6567 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6568 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
6569 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6570 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
6571 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
6572 ID3D11Texture2D_Release(texture);
6574 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
6575 refcount = ID3D11RenderTargetView_Release(rtv);
6576 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6577 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &tmp_rtv, NULL);
6578 ok(tmp_rtv == rtv, "Got RTV %p, expected %p.\n", tmp_rtv, rtv);
6579 refcount = ID3D11RenderTargetView_Release(tmp_rtv);
6580 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6582 /* ID3D11Predicate */
6583 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
6585 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
6586 predicate_desc.MiscFlags = 0;
6587 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
6588 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
6590 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
6591 refcount = ID3D11Predicate_Release(predicate);
6592 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6593 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, NULL);
6594 ok(tmp_predicate == predicate, "Got predicate %p, expected %p.\n", tmp_predicate, predicate);
6595 refcount = ID3D11Predicate_Release(tmp_predicate);
6596 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
6599 ID3D11DeviceContext_Release(context);
6600 refcount = ID3D11Device_Release(device);
6601 ok(!refcount, "Device has %u references left.\n", refcount);
6604 static void test_device_context_state(void)
6606 static const GUID test_guid =
6607 {0xfdb37466, 0x428f, 0x4edf, {0xa3, 0x7f, 0x9b, 0x1d, 0xf4, 0x88, 0xc5, 0xfc}};
6608 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
6610 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
6612 static const float custom_blend_factor[] = {0.1f, 0.2f, 0.3f, 0.4f};
6613 static const float default_blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
6614 #if 0
6615 float4 main(float4 pos : POSITION) : POSITION
6617 return pos;
6619 #endif
6620 static const DWORD simple_vs[] =
6622 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
6623 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6624 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6625 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
6626 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
6627 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
6628 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6630 #if 0
6631 struct data
6633 float4 position : SV_Position;
6636 struct patch_constant_data
6638 float edges[3] : SV_TessFactor;
6639 float inside : SV_InsideTessFactor;
6642 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
6644 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
6645 output.inside = 1.0f;
6648 [domain("tri")]
6649 [outputcontrolpoints(3)]
6650 [partitioning("integer")]
6651 [outputtopology("triangle_ccw")]
6652 [patchconstantfunc("patch_constant")]
6653 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
6655 return input[i];
6658 [domain("tri")]
6659 void ds_main(patch_constant_data input,
6660 float3 tess_coord : SV_DomainLocation,
6661 const OutputPatch<data, 3> patch,
6662 out data output)
6664 output.position = tess_coord.x * patch[0].position
6665 + tess_coord.y * patch[1].position
6666 + tess_coord.z * patch[2].position;
6668 #endif
6669 static const DWORD simple_hs[] =
6671 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
6672 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
6673 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
6674 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
6675 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
6676 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
6677 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
6678 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
6679 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
6680 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
6681 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
6682 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
6683 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
6684 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
6685 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
6686 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
6687 0x00004001, 0x3f800000, 0x0100003e,
6689 static const DWORD simple_ds[] =
6691 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
6692 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
6693 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
6694 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
6695 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
6696 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
6697 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
6698 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
6699 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
6700 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
6701 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
6702 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
6703 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
6704 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
6705 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
6707 #if 0
6708 struct gs_out
6710 float4 pos : SV_POSITION;
6713 [maxvertexcount(4)]
6714 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
6716 float offset = 0.1 * vin[0].w;
6717 gs_out v;
6719 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
6720 vout.Append(v);
6721 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
6722 vout.Append(v);
6723 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
6724 vout.Append(v);
6725 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
6726 vout.Append(v);
6728 #endif
6729 static const DWORD simple_gs[] =
6731 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
6732 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
6733 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
6734 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
6735 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
6736 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
6737 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
6738 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
6739 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
6740 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
6741 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
6742 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
6743 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
6744 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
6745 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
6746 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
6747 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
6748 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
6750 #if 0
6751 float4 main(float4 color : COLOR) : SV_TARGET
6753 return color;
6755 #endif
6756 static const DWORD simple_ps[] =
6758 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
6759 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
6760 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
6761 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
6762 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
6763 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
6764 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
6766 #if 0
6767 [numthreads(1, 1, 1)]
6768 void main() { }
6769 #endif
6770 static const DWORD simple_cs[] =
6772 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
6773 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
6774 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
6775 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
6777 static const struct vec4 constant = {1.257f, 1.885f, 2.513f, 3.770f};
6779 ID3DDeviceContextState *context_state, *previous_context_state, *tmp_context_state, *context_state2;
6780 UINT ib_offset, vb_offset, vb_stride, so_offset, offset, stride, sample_mask, stencil_ref, count;
6781 ID3D11Buffer *cb, *srvb, *uavb, *ib, *vb, *sob, *tmp_cb, *tmp_ib, *tmp_vb, *tmp_sob;
6782 D3D_FEATURE_LEVEL feature_level, selected_feature_level;
6783 ID3D11UnorderedAccessView *tmp_uav, *uav, *ps_uav;
6784 ID3D11Device *d3d11_device, *d3d11_device2;
6785 ID3D11SamplerState *sampler, *tmp_sampler;
6786 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
6787 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
6788 ID3D11DeviceContext1 *context, *context2;
6789 ID3D11ShaderResourceView *tmp_srv, *srv;
6790 D3D11_DEVICE_CONTEXT_TYPE context_type;
6791 ID3D11DepthStencilState *tmp_dss, *dss;
6792 ID3D11RenderTargetView *tmp_rtv, *rtv;
6793 ID3D11DepthStencilView *tmp_dsv, *dsv;
6794 ID3D11VertexShader *tmp_vs, *vs, *vs2;
6795 ID3D11RasterizerState *tmp_rs, *rs;
6796 D3D11_TEXTURE2D_DESC texture_desc;
6797 ID3D11GeometryShader *tmp_gs, *gs;
6798 enum D3D_PRIMITIVE_TOPOLOGY topo;
6799 ID3D11ComputeShader *tmp_cs, *cs;
6800 D3D11_DEPTH_STENCIL_DESC ds_desc;
6801 ID3D11Predicate *tmp_pred, *pred;
6802 ID3D11DomainShader *tmp_ds, *ds;
6803 D3D11_SAMPLER_DESC sampler_desc;
6804 D3D11_QUERY_DESC predicate_desc;
6805 ID3D11Device1 *device, *device2;
6806 ID3D11InputLayout *il, *tmp_il;
6807 ID3D11PixelShader *tmp_ps, *ps;
6808 D3D11_RASTERIZER_DESC rs_desc;
6809 ID3D11BlendState *tmp_bs, *bs;
6810 ID3D11HullShader *tmp_hs, *hs;
6811 D3D11_VIEWPORT tmp_vp[2], vp;
6812 D3D11_RECT tmp_rect[2], rect;
6813 D3D11_BLEND_DESC blend_desc;
6814 ID3D11Texture2D *texture;
6815 enum DXGI_FORMAT format;
6816 float blend_factor[4];
6817 DWORD data_size;
6818 BOOL pred_value;
6819 ULONG refcount;
6820 char data[64];
6821 HRESULT hr;
6823 if (!(d3d11_device = create_device(NULL)))
6825 skip("Failed to create device.\n");
6826 return;
6829 hr = ID3D11Device_QueryInterface(d3d11_device, &IID_ID3D11Device1, (void **)&device);
6830 ID3D11Device_Release(d3d11_device);
6831 if (FAILED(hr))
6833 skip("ID3D11Device1 is not available.\n");
6834 return;
6837 check_interface(device, &IID_ID3D10Device, FALSE, FALSE);
6838 check_interface(device, &IID_ID3D10Device1, FALSE, FALSE);
6840 feature_level = ID3D11Device1_GetFeatureLevel(device);
6841 context = NULL;
6842 ID3D11Device1_GetImmediateContext1(device, &context);
6843 ok(!!context, "Failed to get immediate context.\n");
6845 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
6846 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
6847 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
6848 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
6849 sampler_desc.MipLODBias = 0.0f;
6850 sampler_desc.MaxAnisotropy = 0;
6851 sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
6852 sampler_desc.BorderColor[0] = 0.0f;
6853 sampler_desc.BorderColor[1] = 1.0f;
6854 sampler_desc.BorderColor[2] = 0.0f;
6855 sampler_desc.BorderColor[3] = 1.0f;
6856 sampler_desc.MinLOD = 0.0f;
6857 sampler_desc.MaxLOD = 16.0f;
6858 hr = ID3D11Device1_CreateSamplerState(device, &sampler_desc, &sampler);
6859 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
6861 feature_level = min(feature_level, D3D_FEATURE_LEVEL_11_1);
6863 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level,
6864 1, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, NULL);
6865 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6867 selected_feature_level = 0xc0de0000;
6868 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1,
6869 D3D11_SDK_VERSION, &IID_ID3D11Device1, &selected_feature_level, NULL);
6870 ok(hr == S_FALSE, "Got unexpected hr %#x.\n", hr);
6871 ok(selected_feature_level == feature_level, "Got unexpected feature level %#x, expected %#x.\n",
6872 selected_feature_level, feature_level);
6874 selected_feature_level = 0xc0de0000;
6875 context_state = (void *)0xc0de0001;
6876 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 0,
6877 D3D11_SDK_VERSION, &IID_ID3D11Device1, &selected_feature_level, &context_state);
6878 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6879 ok(!selected_feature_level, "Got unexpected feature level %#x.\n", selected_feature_level);
6880 ok(!context_state, "Got unexpected context state %p.\n", context_state);
6882 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level,
6883 0, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, NULL);
6884 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6886 hr = ID3D11Device1_CreateDeviceContextState(device, 0, NULL,
6887 0, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, NULL);
6888 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
6890 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level,
6891 1, D3D11_SDK_VERSION, &IID_ID3D11Device1, NULL, &context_state);
6892 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
6893 refcount = get_refcount(context_state);
6894 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
6896 context_type = ID3D11DeviceContext1_GetType(context);
6897 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
6899 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
6900 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
6901 check_interface(device, &IID_ID3D11Device, TRUE, FALSE);
6902 check_interface(device, &IID_ID3D11Device1, TRUE, FALSE);
6904 cb = create_buffer((ID3D11Device *)device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), NULL);
6905 srvb = create_buffer((ID3D11Device *)device, D3D11_BIND_SHADER_RESOURCE, 1024, NULL);
6906 uavb = create_buffer((ID3D11Device *)device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
6907 ib = create_buffer((ID3D11Device *)device, D3D11_BIND_INDEX_BUFFER, 1024, NULL);
6908 vb = create_buffer((ID3D11Device *)device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
6909 sob = create_buffer((ID3D11Device *)device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
6911 hr = ID3D11Device1_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
6912 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
6914 hr = ID3D11Device1_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
6915 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
6917 hr = ID3D11Device1_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
6918 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
6920 if (feature_level < D3D_FEATURE_LEVEL_11_0) hs = NULL;
6921 else
6923 hr = ID3D11Device1_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
6924 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
6927 if (feature_level < D3D_FEATURE_LEVEL_11_0) ds = NULL;
6928 else
6930 hr = ID3D11Device1_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
6931 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
6934 if (feature_level < D3D_FEATURE_LEVEL_11_0) cs = NULL;
6935 else
6937 hr = ID3D11Device1_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
6938 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
6941 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
6942 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
6943 U(srv_desc).Buffer.ElementOffset = 0;
6944 U(srv_desc).Buffer.ElementWidth = 64;
6945 hr = ID3D11Device1_CreateShaderResourceView(device, (ID3D11Resource *)srvb, &srv_desc, &srv);
6946 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
6947 ID3D11Buffer_Release(srvb);
6949 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
6950 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
6951 U(uav_desc).Buffer.FirstElement = 0;
6952 U(uav_desc).Buffer.NumElements = 4;
6953 U(uav_desc).Buffer.Flags = 0;
6954 hr = ID3D11Device1_CreateUnorderedAccessView(device, (ID3D11Resource *)uavb, &uav_desc, &uav);
6955 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
6956 ID3D11Buffer_Release(uavb);
6958 uavb = create_buffer((ID3D11Device *)device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
6959 hr = ID3D11Device1_CreateUnorderedAccessView(device, (ID3D11Resource *)uavb, &uav_desc, &ps_uav);
6960 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
6961 ID3D11Buffer_Release(uavb);
6963 hr = ID3D11Device1_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
6964 simple_vs, sizeof(simple_vs), &il);
6965 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
6967 ib_offset = 16;
6968 vb_offset = 16;
6969 vb_stride = 16;
6970 so_offset = 16;
6972 texture_desc.Width = 512;
6973 texture_desc.Height = 512;
6974 texture_desc.MipLevels = 1;
6975 texture_desc.ArraySize = 1;
6976 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
6977 texture_desc.SampleDesc.Count = 1;
6978 texture_desc.SampleDesc.Quality = 0;
6979 texture_desc.Usage = D3D11_USAGE_DEFAULT;
6980 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
6981 texture_desc.CPUAccessFlags = 0;
6982 texture_desc.MiscFlags = 0;
6983 hr = ID3D11Device1_CreateTexture2D(device, &texture_desc, NULL, &texture);
6984 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6985 hr = ID3D11Device1_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
6986 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
6987 ID3D11Texture2D_Release(texture);
6989 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
6990 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
6991 hr = ID3D11Device1_CreateTexture2D(device, &texture_desc, NULL, &texture);
6992 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
6993 hr = ID3D11Device1_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
6994 ok(SUCCEEDED(hr), "Failed to create depth/stencil view, hr %#x.\n", hr);
6995 ID3D11Texture2D_Release(texture);
6997 memset(&blend_desc, 0, sizeof(blend_desc));
6998 blend_desc.RenderTarget[0].BlendEnable = TRUE;
6999 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
7000 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
7001 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
7002 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
7003 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
7004 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
7005 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
7006 hr = ID3D11Device1_CreateBlendState(device, &blend_desc, &bs);
7007 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
7009 ds_desc.DepthEnable = TRUE;
7010 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
7011 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
7012 ds_desc.StencilEnable = FALSE;
7013 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
7014 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
7015 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
7016 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
7017 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
7018 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
7019 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
7020 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
7021 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
7022 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
7023 hr = ID3D11Device1_CreateDepthStencilState(device, &ds_desc, &dss);
7024 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
7026 rs_desc.FillMode = D3D11_FILL_SOLID;
7027 rs_desc.CullMode = D3D11_CULL_BACK;
7028 rs_desc.FrontCounterClockwise = FALSE;
7029 rs_desc.DepthBias = 0;
7030 rs_desc.DepthBiasClamp = 0.0f;
7031 rs_desc.SlopeScaledDepthBias = 0.0f;
7032 rs_desc.DepthClipEnable = TRUE;
7033 rs_desc.ScissorEnable = TRUE;
7034 rs_desc.MultisampleEnable = FALSE;
7035 rs_desc.AntialiasedLineEnable = FALSE;
7036 hr = ID3D11Device1_CreateRasterizerState(device, &rs_desc, &rs);
7037 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
7039 SetRect(&rect, 0, 0, 1, 2);
7040 vp.TopLeftX = 0;
7041 vp.TopLeftY = 0;
7042 vp.Width = 3;
7043 vp.Height = 4;
7044 vp.MinDepth = 0.f;
7045 vp.MaxDepth = 0.01f;
7047 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
7048 predicate_desc.MiscFlags = 0;
7049 ID3D11Device1_CreatePredicate(device, &predicate_desc, &pred);
7051 ID3D11DeviceContext1_VSSetConstantBuffers(context, 0, 1, &cb);
7052 ID3D11DeviceContext1_VSSetSamplers(context, 0, 1, &sampler);
7053 ID3D11DeviceContext1_VSSetShader(context, vs, NULL, 0);
7054 ID3D11DeviceContext1_VSSetShaderResources(context, 0, 1, &srv);
7055 refcount = get_refcount(vs);
7056 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7058 ID3D11DeviceContext1_GSSetConstantBuffers(context, 0, 1, &cb);
7059 ID3D11DeviceContext1_GSSetSamplers(context, 0, 1, &sampler);
7060 ID3D11DeviceContext1_GSSetShader(context, gs, NULL, 0);
7061 ID3D11DeviceContext1_GSSetShaderResources(context, 0, 1, &srv);
7063 ID3D11DeviceContext1_PSSetConstantBuffers(context, 0, 1, &cb);
7064 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
7065 ID3D11DeviceContext1_PSSetShader(context, ps, NULL, 0);
7066 ID3D11DeviceContext1_PSSetShaderResources(context, 0, 1, &srv);
7068 ID3D11DeviceContext1_HSSetConstantBuffers(context, 0, 1, &cb);
7069 ID3D11DeviceContext1_HSSetSamplers(context, 0, 1, &sampler);
7070 ID3D11DeviceContext1_HSSetShader(context, hs, NULL, 0);
7071 ID3D11DeviceContext1_HSSetShaderResources(context, 0, 1, &srv);
7073 ID3D11DeviceContext1_DSSetConstantBuffers(context, 0, 1, &cb);
7074 ID3D11DeviceContext1_DSSetSamplers(context, 0, 1, &sampler);
7075 ID3D11DeviceContext1_DSSetShader(context, ds, NULL, 0);
7076 ID3D11DeviceContext1_DSSetShaderResources(context, 0, 1, &srv);
7078 ID3D11DeviceContext1_CSSetConstantBuffers(context, 0, 1, &cb);
7079 ID3D11DeviceContext1_CSSetSamplers(context, 0, 1, &sampler);
7080 ID3D11DeviceContext1_CSSetShader(context, cs, NULL, 0);
7081 ID3D11DeviceContext1_CSSetShaderResources(context, 0, 1, &srv);
7082 ID3D11DeviceContext1_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
7084 ID3D11DeviceContext1_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7085 ID3D11DeviceContext1_IASetInputLayout(context, il);
7086 ID3D11DeviceContext1_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, ib_offset);
7087 ID3D11DeviceContext1_IASetVertexBuffers(context, 0, 1, &vb, &vb_stride, &vb_offset);
7089 ID3D11DeviceContext1_OMSetBlendState(context, bs, custom_blend_factor, 0xff00ff00);
7090 ID3D11DeviceContext1_OMSetDepthStencilState(context, dss, 3);
7091 ID3D11DeviceContext1_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, dsv, 1, 1, &ps_uav, NULL);
7093 ID3D11DeviceContext1_RSSetScissorRects(context, 1, &rect);
7094 ID3D11DeviceContext1_RSSetViewports(context, 1, &vp);
7095 ID3D11DeviceContext1_RSSetState(context, rs);
7097 ID3D11DeviceContext1_SOSetTargets(context, 1, &sob, &so_offset);
7098 ID3D11DeviceContext1_SetPredication(context, pred, TRUE);
7100 previous_context_state = (ID3DDeviceContextState *)0xdeadbeef;
7101 ID3D11DeviceContext1_SwapDeviceContextState(context, NULL, &previous_context_state);
7102 ok(previous_context_state == NULL, "Got unexpected state pointer.\n");
7103 previous_context_state = NULL;
7104 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
7105 ok(previous_context_state != NULL, "Failed to get previous context state\n");
7106 refcount = get_refcount(vs);
7107 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7109 hr = ID3DDeviceContextState_SetPrivateData(context_state, &test_guid, sizeof(constant), &constant);
7110 ok(hr == S_OK, "Failed to set private data, hr %#x.\n", hr);
7111 refcount = ID3DDeviceContextState_Release(context_state);
7112 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7113 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
7114 data_size = sizeof(data);
7115 memset(data, 0xa5, sizeof(data));
7116 hr = ID3DDeviceContextState_GetPrivateData(context_state, &test_guid, &data_size, data);
7117 ok(hr == S_OK, "Failed to get private data, hr %#x.\n", hr);
7118 ok(data_size == sizeof(constant), "Got private data size %x, expected %x.\n", data_size, sizeof(constant));
7119 ok(!memcmp(data, &constant, sizeof(constant)), "Got unexpected private data.\n");
7120 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, NULL);
7122 context_type = ID3D11DeviceContext1_GetType(context);
7123 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7125 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7126 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7127 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7128 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7129 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7130 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7131 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7132 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7133 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7134 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7135 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7136 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7138 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7139 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7140 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7141 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7142 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7143 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7144 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7145 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7146 ok(!tmp_gs, "Got unexpected shader %p.\n", tmp_gs);
7147 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7148 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7149 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7151 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7152 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7153 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7154 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7155 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7156 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7157 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7158 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7159 ok(!tmp_ps, "Got unexpected shader %p.\n", tmp_ps);
7160 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7161 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7162 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7164 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7165 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7166 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7167 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7168 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7169 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7170 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7171 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7172 if (hs) ok(!tmp_hs, "Got unexpected shader %p.\n", tmp_hs);
7173 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7174 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7175 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7177 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7178 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7179 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7180 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7181 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7182 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7183 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7184 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7185 if (ds) ok(!tmp_ds, "Got unexpected shader %p.\n", tmp_ds);
7186 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7187 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7188 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7190 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7191 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7192 ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7193 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7194 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7195 ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7196 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7197 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7198 if (cs) ok(!tmp_cs, "Got unexpected shader %p.\n", tmp_cs);
7199 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7200 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7201 ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7202 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7203 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7204 ok(!tmp_uav, "Got unexpected uav %p.\n", tmp_uav);
7206 topo = 0xdeadbeef;
7207 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7208 ok(topo == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected topology %#x.\n", topo);
7209 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7210 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7211 ok(!tmp_il, "Got unexpected input layout %p.\n", tmp_il);
7212 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7213 format = 0xdeadbeef;
7214 offset = 0xdeadbeef;
7215 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7216 ok(!tmp_ib, "Got unexpected input buffer %p.\n", tmp_ib);
7217 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected input buffer format %#x.\n", format);
7218 ok(offset == 0, "Got unexpected input buffer offset %#x.\n", offset);
7219 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7220 stride = 0xdeadbeef;
7221 offset = 0xdeadbeef;
7222 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7223 ok(!tmp_vb, "Got unexpected vertex buffer %p.\n", tmp_vb);
7224 ok(stride == 0, "Got unexpected vertex buffer stride %#x.\n", stride);
7225 ok(offset == 0, "Got unexpected vertex buffer offset %#x.\n", offset);
7227 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7228 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7229 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7230 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7231 ok(!tmp_rtv, "Got unexpected rendertarget view %p.\n", tmp_rtv);
7232 ok(!tmp_dsv, "Got unexpected depth/stencil view %p.\n", tmp_dsv);
7233 ok(!tmp_uav, "Got unexpected unordered access view %p.\n", tmp_uav);
7234 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7235 memset(blend_factor, 0xcd, sizeof(blend_factor));
7236 sample_mask = 0xdeadbeef;
7237 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7238 ok(!tmp_bs, "Got unexpected blend state %p.\n", tmp_bs);
7239 ok(!memcmp(blend_factor, default_blend_factor, sizeof(blend_factor)),
7240 "Got unexpected blend factor %f,%f,%f,%f.\n",
7241 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
7242 ok(sample_mask == ~0, "Got unexpected sample mask %#x.\n", sample_mask);
7243 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7244 stencil_ref = 0xdeadbeef;
7245 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7246 ok(!tmp_dss, "Got unexpected depth/stencil state %p.\n", tmp_dss);
7247 ok(stencil_ref == 0, "Got unexpected stencil ref %#x.\n", stencil_ref);
7249 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7250 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7251 ok(!tmp_rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7252 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7253 count = 2;
7254 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7255 ok(count == 0, "Got unexpected viewport count %u.\n", count);
7256 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7257 count = 2;
7258 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7259 ok(count == 0, "Got unexpected scissor rect count %u.\n", count);
7261 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7262 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7263 ok(!tmp_sob, "Got unexpected stream output buffer %p.\n", tmp_sob);
7265 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7266 pred_value = 0xdeadbeef;
7267 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7268 ok(!tmp_pred, "Got unexpected predicate %p.\n", tmp_pred);
7269 ok(!pred_value, "Got unexpected predicate value %d.\n", pred_value);
7271 /* updating the device context should also update the device context state */
7272 hr = ID3D11Device1_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs2);
7273 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
7274 ID3D11DeviceContext1_VSSetShader(context, vs2, NULL, 0);
7275 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &tmp_context_state);
7276 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7277 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7278 ok(tmp_context_state == context_state, "Got unexpected state pointer.\n");
7279 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7280 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7281 ok(tmp_vs == vs2, "Got shader %p, expected %p.\n", tmp_vs, vs2);
7282 refcount = ID3D11VertexShader_Release(tmp_vs);
7283 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7285 /* context states may be used with other devices instances too */
7286 d3d11_device2 = create_device(NULL);
7287 ok(!!d3d11_device2, "Failed to create device.\n");
7288 hr = ID3D11Device_QueryInterface(d3d11_device2, &IID_ID3D11Device1, (void **)&device2);
7289 ok(SUCCEEDED(hr), "Failed to query device interface, hr %#x.\n", hr);
7290 ID3D11Device_Release(d3d11_device2);
7291 ID3D11Device1_GetImmediateContext1(device2, &context2);
7292 ok(!!context2, "Failed to get immediate context.\n");
7294 /* but they track a distinct state on each context */
7295 ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, &tmp_context_state);
7296 ok(!!tmp_context_state, "Failed to get context state.\n");
7297 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7298 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7299 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7301 /* updating context2 vertex shader doesn't update other contexts using the same state */
7302 ID3D11DeviceContext1_VSSetShader(context2, vs, NULL, 0);
7303 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7304 ok(tmp_vs == vs2, "Got shader %p, expected %p.\n", tmp_vs, vs2);
7305 refcount = ID3D11VertexShader_Release(tmp_vs);
7306 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7308 ID3D11DeviceContext1_SwapDeviceContextState(context2, tmp_context_state, &context_state2);
7309 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7310 ok(refcount == 0, "Got refcount %u, expected 1.\n", refcount);
7311 refcount = ID3DDeviceContextState_Release(context_state2);
7312 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7313 ok(context_state2 == context_state, "Got unexpected state pointer.\n");
7315 /* swapping the default state on context2 effectively clears the vertex shader */
7316 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7317 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7318 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7320 ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, &tmp_context_state);
7321 ok(!!tmp_context_state, "Failed to get context state.\n");
7322 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7323 ok(refcount == 0, "Got refcount %u, expected 1.\n", refcount);
7325 /* clearing the vertex shader on context doesn't have side effect on context2 */
7326 ID3D11DeviceContext1_VSSetShader(context, NULL, NULL, 0);
7327 refcount = ID3D11VertexShader_Release(vs2);
7328 ok(refcount == 0, "Got refcount %u, expected 0.\n", refcount);
7329 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7330 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7331 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7332 refcount = ID3D11VertexShader_Release(tmp_vs);
7333 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7335 /* even after swapping it again */
7336 ID3D11DeviceContext1_SwapDeviceContextState(context2, context_state, NULL);
7337 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7338 ID3D11DeviceContext1_VSGetShader(context2, &tmp_vs, NULL, NULL);
7339 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7340 refcount = ID3D11VertexShader_Release(tmp_vs);
7341 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7343 /* swapping the initial state on context2 doesn't have side effect on context either */
7344 ID3D11DeviceContext1_SwapDeviceContextState(context2, previous_context_state, NULL);
7345 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7346 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7347 ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7349 refcount = ID3D11DeviceContext1_Release(context2);
7350 ok(refcount == 0, "Got refcount %u, expected 0.\n", refcount);
7351 refcount = ID3D11Device1_Release(device2);
7352 ok(refcount == 0, "Got refcount %u, expected 0.\n", refcount);
7354 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &tmp_context_state);
7355 refcount = ID3DDeviceContextState_Release(previous_context_state);
7356 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7357 refcount = ID3DDeviceContextState_Release(tmp_context_state);
7358 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7359 refcount = ID3DDeviceContextState_Release(context_state);
7360 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7361 ok(tmp_context_state == context_state, "Got unexpected state pointer.\n");
7362 refcount = get_refcount(vs);
7363 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7365 /* ID3DDeviceContextState retains the previous state. */
7367 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7368 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7369 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7370 ID3D11SamplerState_Release(tmp_sampler);
7371 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7372 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7373 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7374 ID3D11Buffer_Release(tmp_cb);
7375 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7376 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7377 ok(tmp_ps == ps, "Got shader %p, expected %p.\n", tmp_ps, ps);
7378 ID3D11PixelShader_Release(tmp_ps);
7379 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7380 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7381 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7382 ID3D11ShaderResourceView_Release(tmp_srv);
7384 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7385 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7386 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7387 ID3D11SamplerState_Release(tmp_sampler);
7388 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7389 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7390 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7391 ID3D11Buffer_Release(tmp_cb);
7392 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7393 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7394 ok(tmp_cs == cs, "Got shader %p, expected %p.\n", tmp_cs, cs);
7395 if (cs) ID3D11ComputeShader_Release(tmp_cs);
7396 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7397 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7398 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7399 ID3D11ShaderResourceView_Release(tmp_srv);
7400 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7401 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7402 ok(tmp_uav == uav, "Got uav %p, expected %p.\n", tmp_uav, uav);
7403 ID3D11UnorderedAccessView_Release(tmp_uav);
7405 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7406 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7407 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7408 ID3D11SamplerState_Release(tmp_sampler);
7409 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7410 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7411 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7412 ID3D11Buffer_Release(tmp_cb);
7413 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7414 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7415 ok(tmp_ds == ds, "Got shader %p, expected %p.\n", tmp_ds, ds);
7416 if (ds) ID3D11DomainShader_Release(tmp_ds);
7417 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7418 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7419 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7420 ID3D11ShaderResourceView_Release(tmp_srv);
7422 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7423 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7424 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7425 ID3D11SamplerState_Release(tmp_sampler);
7426 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7427 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7428 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7429 ID3D11Buffer_Release(tmp_cb);
7430 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7431 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7432 ok(tmp_gs == gs, "Got shader %p, expected %p.\n", tmp_gs, gs);
7433 ID3D11GeometryShader_Release(tmp_gs);
7434 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7435 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7436 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7437 ID3D11ShaderResourceView_Release(tmp_srv);
7439 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7440 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7441 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7442 ID3D11SamplerState_Release(tmp_sampler);
7443 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7444 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7445 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7446 ID3D11Buffer_Release(tmp_cb);
7447 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7448 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7449 ok(tmp_hs == hs, "Got shader %p, expected %p.\n", tmp_hs, hs);
7450 if (hs) ID3D11HullShader_Release(tmp_hs);
7451 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7452 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7453 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7454 ID3D11ShaderResourceView_Release(tmp_srv);
7456 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7457 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7458 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7459 ID3D11SamplerState_Release(tmp_sampler);
7460 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7461 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7462 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7463 ID3D11Buffer_Release(tmp_cb);
7464 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7465 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7466 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7467 ID3D11VertexShader_Release(tmp_vs);
7468 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7469 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7470 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7471 ID3D11ShaderResourceView_Release(tmp_srv);
7473 topo = 0xdeadbeef;
7474 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7475 ok(topo == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got topology %#x, expected %#x.\n", topo, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7476 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7477 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7478 ok(tmp_il == il, "Got input layout %p, expected %p.\n", tmp_il, il);
7479 ID3D11InputLayout_Release(tmp_il);
7480 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7481 format = 0xdeadbeef;
7482 offset = 0xdeadbeef;
7483 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7484 ok(tmp_ib == ib, "Got input buffer %p, expected %p.\n", tmp_ib, ib);
7485 ID3D11Buffer_Release(tmp_ib);
7486 ok(format == DXGI_FORMAT_R32_UINT, "Got input buffer format %#x, expected %#x.\n", format, DXGI_FORMAT_R32_UINT);
7487 ok(offset == 16, "Got input buffer offset %#x, expected 16.\n", offset);
7488 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7489 stride = 0xdeadbeef;
7490 offset = 0xdeadbeef;
7491 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7492 ok(tmp_vb == vb, "Got vertex buffer %p, expected %p.\n", tmp_vb, vb);
7493 ID3D11Buffer_Release(tmp_vb);
7494 ok(stride == 16, "Got vertex buffer stride %#x, expected 16.\n", stride);
7495 ok(offset == 16, "Got vertex buffer offset %#x, expected 16.\n", offset);
7497 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7498 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7499 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7500 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7501 ok(tmp_rtv == rtv, "Got rendertarget view %p, expected %p.\n", tmp_rtv, rtv);
7502 ID3D11RenderTargetView_Release(tmp_rtv);
7503 ok(tmp_dsv == dsv, "Got depth/stencil view %p, expected %p.\n", tmp_dsv, dsv);
7504 ID3D11DepthStencilView_Release(tmp_dsv);
7505 ok(tmp_uav == ps_uav, "Got unordered access view %p, expected %p.\n", tmp_uav, ps_uav);
7506 ID3D11UnorderedAccessView_Release(tmp_uav);
7507 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7508 memset(blend_factor, 0xcd, sizeof(blend_factor));
7509 sample_mask = 0xdeadbeef;
7510 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7511 ok(tmp_bs == bs, "Got blend state %p, expected %p.\n", tmp_bs, bs);
7512 ID3D11BlendState_Release(tmp_bs);
7513 ok(!memcmp(blend_factor, custom_blend_factor, sizeof(blend_factor)),
7514 "Got blend factor %f,%f,%f,%f, expected %f,%f,%f,%f.\n",
7515 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3],
7516 custom_blend_factor[0], custom_blend_factor[1], custom_blend_factor[2], custom_blend_factor[3]);
7517 ok(sample_mask == 0xff00ff00, "Got sample mask %#x, expected %#x.\n", sample_mask, 0xff00ff00);
7518 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7519 stencil_ref = 0xdeadbeef;
7520 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7521 ok(tmp_dss == dss, "Got depth/stencil state %p, expected %p.\n", tmp_dss, dss);
7522 ID3D11DepthStencilState_Release(tmp_dss);
7523 ok(stencil_ref == 3, "Got stencil ref %#x, expected 3.\n", stencil_ref);
7525 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7526 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7527 ok(tmp_rs == rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7528 ID3D11RasterizerState_Release(tmp_rs);
7529 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7530 count = 2;
7531 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7532 ok(count == 1, "Got viewport count %u, expected 1.\n", count);
7533 ok(!memcmp(tmp_vp, &vp, sizeof(vp)), "Got viewport %s, expected %s.\n",
7534 debugstr_viewport(tmp_vp), debugstr_viewport(&vp));
7535 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7536 count = 2;
7537 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7538 ok(count == 1, "Got scissor rect count %u, expected 1.\n", count);
7539 ok(!memcmp(tmp_rect, &rect, sizeof(rect)), "Got scissor rect %s, expected %s.\n",
7540 wine_dbgstr_rect(tmp_rect), wine_dbgstr_rect(&rect));
7542 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7543 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7544 ok(tmp_sob == sob, "Got stream output buffer %p, expected %p.\n", tmp_sob, sob);
7545 ID3D11Buffer_Release(tmp_sob);
7547 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7548 pred_value = 0xdeadbeef;
7549 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7550 ok(tmp_pred == pred, "Got predicate %p, expected %p.\n", tmp_pred, pred);
7551 ID3D11Predicate_Release(tmp_pred);
7552 ok(pred_value == TRUE, "Got predicate value %#x, expected TRUE.\n", pred_value);
7554 feature_level = min(feature_level, D3D_FEATURE_LEVEL_10_1);
7555 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
7556 &IID_ID3D10Device, NULL, &context_state);
7557 ok(SUCCEEDED(hr), "Failed to create device context state, hr %#x.\n", hr);
7558 refcount = get_refcount(context_state);
7559 ok(refcount == 1, "Got refcount %u, expected 1.\n", refcount);
7561 context_type = ID3D11DeviceContext1_GetType(context);
7562 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7564 /* Enable ID3D10Device behavior. */
7565 previous_context_state = NULL;
7566 ID3D11DeviceContext1_SwapDeviceContextState(context, context_state, &previous_context_state);
7567 refcount = ID3DDeviceContextState_Release(context_state);
7568 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7569 ok(previous_context_state != NULL, "Failed to get previous context state\n");
7571 context_type = ID3D11DeviceContext1_GetType(context);
7572 ok(context_type == D3D11_DEVICE_CONTEXT_IMMEDIATE, "Unexpected context type %u.\n", context_type);
7574 ID3D11DeviceContext1_VSSetConstantBuffers(context, 0, 1, &cb);
7575 ID3D11DeviceContext1_VSSetSamplers(context, 0, 1, &sampler);
7576 ID3D11DeviceContext1_VSSetShader(context, vs, NULL, 0);
7577 ID3D11DeviceContext1_VSSetShaderResources(context, 0, 1, &srv);
7579 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7580 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7581 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7582 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7583 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7584 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7585 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7586 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7587 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7588 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7589 todo_wine ok(!tmp_vs, "Got unexpected shader %p.\n", tmp_vs);
7590 if (tmp_vs && tmp_vs != (ID3D11VertexShader *)0xdeadbeef) ID3D11VertexShader_Release(tmp_vs);
7591 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7592 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7593 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7594 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7596 ID3D11DeviceContext1_GSSetConstantBuffers(context, 0, 1, &cb);
7597 ID3D11DeviceContext1_GSSetSamplers(context, 0, 1, &sampler);
7598 ID3D11DeviceContext1_GSSetShader(context, gs, NULL, 0);
7599 ID3D11DeviceContext1_GSSetShaderResources(context, 0, 1, &srv);
7601 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7602 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7603 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7604 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7605 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7606 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7607 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7608 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7609 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7610 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7611 todo_wine ok(!tmp_gs, "Got unexpected shader %p.\n", tmp_gs);
7612 if (tmp_gs && tmp_gs != (ID3D11GeometryShader *)0xdeadbeef) ID3D11GeometryShader_Release(tmp_gs);
7613 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7614 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7615 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7616 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7618 ID3D11DeviceContext1_PSSetConstantBuffers(context, 0, 1, &cb);
7619 ID3D11DeviceContext1_PSSetSamplers(context, 0, 1, &sampler);
7620 ID3D11DeviceContext1_PSSetShader(context, ps, NULL, 0);
7621 ID3D11DeviceContext1_PSSetShaderResources(context, 0, 1, &srv);
7623 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7624 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7625 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7626 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7627 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7628 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7629 todo_wine ok(tmp_sampler == (ID3D11SamplerState *)0xdeadbeef, "Got unexpected sampler %p.\n", tmp_sampler);
7630 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7631 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7632 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7633 todo_wine ok(!tmp_ps, "Got unexpected shader %p.\n", tmp_ps);
7634 if (tmp_ps && tmp_ps != (ID3D11PixelShader *)0xdeadbeef) ID3D11PixelShader_Release(tmp_ps);
7635 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7636 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7637 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7638 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7640 ID3D11DeviceContext1_HSSetConstantBuffers(context, 0, 1, &cb);
7641 ID3D11DeviceContext1_HSSetSamplers(context, 0, 1, &sampler);
7642 ID3D11DeviceContext1_HSSetShader(context, hs, NULL, 0);
7643 ID3D11DeviceContext1_HSSetShaderResources(context, 0, 1, &srv);
7645 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7646 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7647 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7648 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7649 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7650 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7651 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7652 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7653 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7654 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7655 if (hs) todo_wine ok(!tmp_hs, "Got unexpected shader %p.\n", tmp_hs);
7656 if (tmp_hs && tmp_hs != (ID3D11HullShader *)0xdeadbeef) ID3D11HullShader_Release(tmp_hs);
7657 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7658 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7659 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7660 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7662 ID3D11DeviceContext1_DSSetConstantBuffers(context, 0, 1, &cb);
7663 ID3D11DeviceContext1_DSSetSamplers(context, 0, 1, &sampler);
7664 ID3D11DeviceContext1_DSSetShader(context, ds, NULL, 0);
7665 ID3D11DeviceContext1_DSSetShaderResources(context, 0, 1, &srv);
7667 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7668 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7669 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7670 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7671 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7672 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7673 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7674 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7675 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7676 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7677 if (ds) todo_wine ok(!tmp_ds, "Got unexpected shader %p.\n", tmp_ds);
7678 if (tmp_ds && tmp_ds != (ID3D11DomainShader *)0xdeadbeef) ID3D11DomainShader_Release(tmp_ds);
7679 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7680 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7681 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7682 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7684 ID3D11DeviceContext1_CSSetConstantBuffers(context, 0, 1, &cb);
7685 ID3D11DeviceContext1_CSSetSamplers(context, 0, 1, &sampler);
7686 ID3D11DeviceContext1_CSSetShader(context, cs, NULL, 0);
7687 ID3D11DeviceContext1_CSSetShaderResources(context, 0, 1, &srv);
7688 ID3D11DeviceContext1_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
7690 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7691 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7692 todo_wine ok(!tmp_cb, "Got unexpected buffer %p.\n", tmp_cb);
7693 if (tmp_cb && tmp_cb != (ID3D11Buffer *)0xdeadbeef) ID3D11Buffer_Release(tmp_cb);
7694 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7695 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7696 todo_wine ok(!tmp_sampler, "Got unexpected sampler %p.\n", tmp_sampler);
7697 if (tmp_sampler && tmp_sampler != (ID3D11SamplerState *)0xdeadbeef) ID3D11SamplerState_Release(tmp_sampler);
7698 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7699 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7700 if (cs) todo_wine ok(!tmp_cs, "Got unexpected shader %p.\n", tmp_cs);
7701 if (tmp_cs && tmp_cs != (ID3D11ComputeShader *)0xdeadbeef) ID3D11ComputeShader_Release(tmp_cs);
7702 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7703 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7704 todo_wine ok(!tmp_srv, "Got unexpected srv %p.\n", tmp_srv);
7705 if (tmp_srv && tmp_srv != (ID3D11ShaderResourceView *)0xdeadbeef) ID3D11ShaderResourceView_Release(tmp_srv);
7706 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7707 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7708 todo_wine ok(!tmp_uav, "Got unexpected uav %p.\n", tmp_uav);
7709 if (tmp_uav && tmp_uav != (ID3D11UnorderedAccessView *)0xdeadbeef) ID3D11UnorderedAccessView_Release(tmp_uav);
7711 ID3D11DeviceContext1_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7712 ID3D11DeviceContext1_IASetInputLayout(context, il);
7713 ID3D11DeviceContext1_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, ib_offset);
7714 ID3D11DeviceContext1_IASetVertexBuffers(context, 0, 1, &vb, &vb_stride, &vb_offset);
7716 topo = 0xdeadbeef;
7717 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7718 todo_wine ok(topo == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected topology %#x.\n", topo);
7719 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7720 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7721 todo_wine ok(!tmp_il, "Got unexpected input layout %p.\n", tmp_il);
7722 if (tmp_il) ID3D11InputLayout_Release(tmp_il);
7723 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7724 format = 0xdeadbeef;
7725 offset = 0xdeadbeef;
7726 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7727 todo_wine ok(!tmp_ib, "Got unexpected input buffer %p.\n", tmp_ib);
7728 if (tmp_ib) ID3D11Buffer_Release(tmp_ib);
7729 todo_wine ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected input buffer format %#x.\n", format);
7730 todo_wine ok(offset == 0, "Got unexpected input buffer offset %#x.\n", offset);
7731 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7732 stride = 0xdeadbeef;
7733 offset = 0xdeadbeef;
7734 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7735 todo_wine ok(!tmp_vb, "Got unexpected vertex buffer %p.\n", tmp_vb);
7736 if (tmp_vb) ID3D11Buffer_Release(tmp_vb);
7737 todo_wine ok(stride == 0, "Got unexpected vertex buffer stride %#x.\n", stride);
7738 todo_wine ok(offset == 0, "Got unexpected vertex buffer offset %#x.\n", offset);
7740 ID3D11DeviceContext1_OMSetBlendState(context, bs, custom_blend_factor, 0xff00ff00);
7741 ID3D11DeviceContext1_OMSetDepthStencilState(context, dss, 3);
7742 ID3D11DeviceContext1_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, dsv, 1, 1, &ps_uav, NULL);
7744 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7745 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7746 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7747 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7748 todo_wine ok(!tmp_rtv, "Got unexpected rendertarget view %p.\n", tmp_rtv);
7749 if (tmp_rtv) ID3D11RenderTargetView_Release(tmp_rtv);
7750 todo_wine ok(!tmp_dsv, "Got unexpected depth/stencil view %p.\n", tmp_dsv);
7751 if (tmp_dsv) ID3D11DepthStencilView_Release(tmp_dsv);
7752 todo_wine ok(!tmp_uav, "Got unexpected unordered access view %p.\n", tmp_uav);
7753 if (tmp_uav) ID3D11UnorderedAccessView_Release(tmp_uav);
7754 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7755 memset(blend_factor, 0xcd, sizeof(blend_factor));
7756 sample_mask = 0xdeadbeef;
7757 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7758 todo_wine ok(!tmp_bs, "Got unexpected blend state %p.\n", tmp_bs);
7759 if (tmp_bs) ID3D11BlendState_Release(tmp_bs);
7760 todo_wine ok(!memcmp(blend_factor, default_blend_factor, sizeof(blend_factor)),
7761 "Got unexpected blend factor %f,%f,%f,%f.\n",
7762 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
7763 todo_wine ok(sample_mask == ~0, "Got unexpected sample mask %#x.\n", sample_mask);
7764 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7765 stencil_ref = 0xdeadbeef;
7766 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7767 todo_wine ok(!tmp_dss, "Got unexpected depth/stencil state %p.\n", tmp_dss);
7768 if (tmp_dss) ID3D11DepthStencilState_Release(tmp_dss);
7769 todo_wine ok(stencil_ref == 0, "Got unexpected stencil ref %#x.\n", stencil_ref);
7771 ID3D11DeviceContext1_RSSetScissorRects(context, 1, &rect);
7772 ID3D11DeviceContext1_RSSetViewports(context, 1, &vp);
7773 ID3D11DeviceContext1_RSSetState(context, rs);
7775 ID3D11DeviceContext1_SOSetTargets(context, 1, &sob, &so_offset);
7776 ID3D11DeviceContext1_SetPredication(context, pred, TRUE);
7778 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7779 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7780 todo_wine ok(!tmp_rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7781 if (tmp_rs) ID3D11RasterizerState_Release(tmp_rs);
7782 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7783 count = 2;
7784 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7785 todo_wine ok(count == 0, "Got unexpected viewport count %u.\n", count);
7786 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7787 count = 2;
7788 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7789 todo_wine ok(count == 0, "Got unexpected scissor rect count %u.\n", count);
7791 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7792 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7793 todo_wine ok(!tmp_sob, "Got unexpected stream output buffer %p.\n", tmp_sob);
7794 if (tmp_sob) ID3D11Buffer_Release(tmp_sob);
7796 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7797 pred_value = 0xdeadbeef;
7798 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7799 todo_wine ok(!tmp_pred, "Got unexpected predicate %p.\n", tmp_pred);
7800 if (tmp_pred) ID3D11Predicate_Release(tmp_pred);
7801 todo_wine ok(!pred_value, "Got unexpected predicate value %d.\n", pred_value);
7803 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
7804 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
7806 context_state = NULL;
7807 ID3D11DeviceContext1_SwapDeviceContextState(context, previous_context_state, &context_state);
7808 refcount = ID3DDeviceContextState_Release(context_state);
7809 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7810 refcount = ID3DDeviceContextState_Release(previous_context_state);
7811 ok(!refcount, "Got refcount %u, expected 0.\n", refcount);
7813 /* ID3DDeviceContextState retains the previous state. */
7815 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7816 ID3D11DeviceContext1_VSGetSamplers(context, 0, 1, &tmp_sampler);
7817 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7818 ID3D11SamplerState_Release(tmp_sampler);
7819 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7820 ID3D11DeviceContext1_VSGetConstantBuffers(context, 0, 1, &tmp_cb);
7821 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7822 ID3D11Buffer_Release(tmp_cb);
7823 tmp_vs = (ID3D11VertexShader *)0xdeadbeef;
7824 ID3D11DeviceContext1_VSGetShader(context, &tmp_vs, NULL, NULL);
7825 ok(tmp_vs == vs, "Got shader %p, expected %p.\n", tmp_vs, vs);
7826 ID3D11VertexShader_Release(tmp_vs);
7827 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7828 ID3D11DeviceContext1_VSGetShaderResources(context, 0, 1, &tmp_srv);
7829 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7830 ID3D11ShaderResourceView_Release(tmp_srv);
7832 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7833 ID3D11DeviceContext1_GSGetSamplers(context, 0, 1, &tmp_sampler);
7834 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7835 ID3D11SamplerState_Release(tmp_sampler);
7836 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7837 ID3D11DeviceContext1_GSGetConstantBuffers(context, 0, 1, &tmp_cb);
7838 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7839 ID3D11Buffer_Release(tmp_cb);
7840 tmp_gs = (ID3D11GeometryShader *)0xdeadbeef;
7841 ID3D11DeviceContext1_GSGetShader(context, &tmp_gs, NULL, NULL);
7842 ok(tmp_gs == gs, "Got shader %p, expected %p.\n", tmp_gs, gs);
7843 ID3D11GeometryShader_Release(tmp_gs);
7844 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7845 ID3D11DeviceContext1_GSGetShaderResources(context, 0, 1, &tmp_srv);
7846 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7847 ID3D11ShaderResourceView_Release(tmp_srv);
7849 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7850 ID3D11DeviceContext1_PSGetSamplers(context, 0, 1, &tmp_sampler);
7851 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7852 ID3D11SamplerState_Release(tmp_sampler);
7853 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7854 ID3D11DeviceContext1_PSGetConstantBuffers(context, 0, 1, &tmp_cb);
7855 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7856 ID3D11Buffer_Release(tmp_cb);
7857 tmp_ps = (ID3D11PixelShader *)0xdeadbeef;
7858 ID3D11DeviceContext1_PSGetShader(context, &tmp_ps, NULL, NULL);
7859 ok(tmp_ps == ps, "Got shader %p, expected %p.\n", tmp_ps, ps);
7860 ID3D11PixelShader_Release(tmp_ps);
7861 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7862 ID3D11DeviceContext1_PSGetShaderResources(context, 0, 1, &tmp_srv);
7863 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7864 ID3D11ShaderResourceView_Release(tmp_srv);
7866 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7867 ID3D11DeviceContext1_HSGetSamplers(context, 0, 1, &tmp_sampler);
7868 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7869 ID3D11SamplerState_Release(tmp_sampler);
7870 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7871 ID3D11DeviceContext1_HSGetConstantBuffers(context, 0, 1, &tmp_cb);
7872 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7873 ID3D11Buffer_Release(tmp_cb);
7874 tmp_hs = (ID3D11HullShader *)0xdeadbeef;
7875 ID3D11DeviceContext1_HSGetShader(context, &tmp_hs, NULL, NULL);
7876 ok(tmp_hs == hs, "Got shader %p, expected %p.\n", tmp_hs, hs);
7877 if (hs) ID3D11HullShader_Release(tmp_hs);
7878 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7879 ID3D11DeviceContext1_HSGetShaderResources(context, 0, 1, &tmp_srv);
7880 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7881 ID3D11ShaderResourceView_Release(tmp_srv);
7883 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7884 ID3D11DeviceContext1_DSGetSamplers(context, 0, 1, &tmp_sampler);
7885 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7886 ID3D11SamplerState_Release(tmp_sampler);
7887 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7888 ID3D11DeviceContext1_DSGetConstantBuffers(context, 0, 1, &tmp_cb);
7889 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7890 ID3D11Buffer_Release(tmp_cb);
7891 tmp_ds = (ID3D11DomainShader *)0xdeadbeef;
7892 ID3D11DeviceContext1_DSGetShader(context, &tmp_ds, NULL, NULL);
7893 ok(tmp_ds == ds, "Got shader %p, expected %p.\n", tmp_ds, ds);
7894 if (ds) ID3D11DomainShader_Release(tmp_ds);
7895 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7896 ID3D11DeviceContext1_DSGetShaderResources(context, 0, 1, &tmp_srv);
7897 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7898 ID3D11ShaderResourceView_Release(tmp_srv);
7900 tmp_sampler = (ID3D11SamplerState *)0xdeadbeef;
7901 ID3D11DeviceContext1_CSGetSamplers(context, 0, 1, &tmp_sampler);
7902 ok(tmp_sampler == sampler, "Got sampler %p, expected %p.\n", tmp_sampler, sampler);
7903 ID3D11SamplerState_Release(tmp_sampler);
7904 tmp_cb = (ID3D11Buffer *)0xdeadbeef;
7905 ID3D11DeviceContext1_CSGetConstantBuffers(context, 0, 1, &tmp_cb);
7906 ok(tmp_cb == cb, "Got buffer %p, expected %p.\n", tmp_cb, cb);
7907 ID3D11Buffer_Release(tmp_cb);
7908 tmp_cs = (ID3D11ComputeShader *)0xdeadbeef;
7909 ID3D11DeviceContext1_CSGetShader(context, &tmp_cs, NULL, NULL);
7910 ok(tmp_cs == cs, "Got shader %p, expected %p.\n", tmp_cs, cs);
7911 if (cs) ID3D11ComputeShader_Release(tmp_cs);
7912 tmp_srv = (ID3D11ShaderResourceView *)0xdeadbeef;
7913 ID3D11DeviceContext1_CSGetShaderResources(context, 0, 1, &tmp_srv);
7914 ok(tmp_srv == srv, "Got srv %p, expected %p.\n", tmp_srv, srv);
7915 ID3D11ShaderResourceView_Release(tmp_srv);
7916 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7917 ID3D11DeviceContext1_CSGetUnorderedAccessViews(context, 0, 1, &tmp_uav);
7918 ok(tmp_uav == uav, "Got uav %p, expected %p.\n", tmp_uav, uav);
7919 ID3D11UnorderedAccessView_Release(tmp_uav);
7921 topo = 0xdeadbeef;
7922 ID3D11DeviceContext1_IAGetPrimitiveTopology(context, &topo);
7923 ok(topo == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got topology %#x, expected %#x.\n", topo, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
7924 tmp_il = (ID3D11InputLayout *)0xdeadbeef;
7925 ID3D11DeviceContext1_IAGetInputLayout(context, &tmp_il);
7926 ok(tmp_il == il, "Got input layout %p, expected %p.\n", tmp_il, il);
7927 ID3D11InputLayout_Release(tmp_il);
7928 tmp_ib = (ID3D11Buffer *)0xdeadbeef;
7929 format = 0xdeadbeef;
7930 offset = 0xdeadbeef;
7931 ID3D11DeviceContext1_IAGetIndexBuffer(context, &tmp_ib, &format, &offset);
7932 ok(tmp_ib == ib, "Got input buffer %p, expected %p.\n", tmp_ib, ib);
7933 ID3D11Buffer_Release(tmp_ib);
7934 ok(format == DXGI_FORMAT_R32_UINT, "Got input buffer format %#x, expected %#x.\n", format, DXGI_FORMAT_R32_UINT);
7935 ok(offset == 16, "Got input buffer offset %#x, expected 16.\n", offset);
7936 tmp_vb = (ID3D11Buffer *)0xdeadbeef;
7937 stride = 0xdeadbeef;
7938 offset = 0xdeadbeef;
7939 ID3D11DeviceContext1_IAGetVertexBuffers(context, 0, 1, &tmp_vb, &stride, &offset);
7940 ok(tmp_vb == vb, "Got vertex buffer %p, expected %p.\n", tmp_vb, vb);
7941 ID3D11Buffer_Release(tmp_vb);
7942 ok(stride == 16, "Got vertex buffer stride %#x, expected 16.\n", stride);
7943 ok(offset == 16, "Got vertex buffer offset %#x, expected 16.\n", offset);
7945 tmp_rtv = (ID3D11RenderTargetView *)0xdeadbeef;
7946 tmp_dsv = (ID3D11DepthStencilView *)0xdeadbeef;
7947 tmp_uav = (ID3D11UnorderedAccessView *)0xdeadbeef;
7948 ID3D11DeviceContext1_OMGetRenderTargetsAndUnorderedAccessViews(context, 1, &tmp_rtv, &tmp_dsv, 1, 1, &tmp_uav);
7949 ok(tmp_rtv == rtv, "Got rendertarget view %p, expected %p.\n", tmp_rtv, rtv);
7950 ID3D11RenderTargetView_Release(tmp_rtv);
7951 ok(tmp_dsv == dsv, "Got depth/stencil view %p, expected %p.\n", tmp_dsv, dsv);
7952 ID3D11DepthStencilView_Release(tmp_dsv);
7953 ok(tmp_uav == ps_uav, "Got unordered access view %p, expected %p.\n", tmp_uav, ps_uav);
7954 ID3D11UnorderedAccessView_Release(tmp_uav);
7955 tmp_bs = (ID3D11BlendState *)0xdeadbeef;
7956 memset(blend_factor, 0xcd, sizeof(blend_factor));
7957 sample_mask = 0xdeadbeef;
7958 ID3D11DeviceContext1_OMGetBlendState(context, &tmp_bs, blend_factor, &sample_mask);
7959 ok(tmp_bs == bs, "Got blend state %p, expected %p.\n", tmp_bs, bs);
7960 ID3D11BlendState_Release(tmp_bs);
7961 ok(!memcmp(blend_factor, custom_blend_factor, sizeof(blend_factor)),
7962 "Got blend factor %f,%f,%f,%f, expected %f,%f,%f,%f.\n",
7963 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3],
7964 custom_blend_factor[0], custom_blend_factor[1], custom_blend_factor[2], custom_blend_factor[3]);
7965 ok(sample_mask == 0xff00ff00, "Got sample mask %#x, expected %#x.\n", sample_mask, 0xff00ff00);
7966 tmp_dss = (ID3D11DepthStencilState *)0xdeadbeef;
7967 stencil_ref = 0xdeadbeef;
7968 ID3D11DeviceContext1_OMGetDepthStencilState(context, &tmp_dss, &stencil_ref);
7969 ok(tmp_dss == dss, "Got depth/stencil state %p, expected %p.\n", tmp_dss, dss);
7970 ID3D11DepthStencilState_Release(tmp_dss);
7971 ok(stencil_ref == 3, "Got stencil ref %#x, expected 3.\n", stencil_ref);
7973 tmp_rs = (ID3D11RasterizerState *)0xdeadbeef;
7974 ID3D11DeviceContext1_RSGetState(context, &tmp_rs);
7975 ok(tmp_rs == rs, "Got unexpected rasterizer state %p.\n", tmp_rs);
7976 ID3D11RasterizerState_Release(tmp_rs);
7977 memset(tmp_vp, 0xa5, sizeof(tmp_vp));
7978 count = 2;
7979 ID3D11DeviceContext1_RSGetViewports(context, &count, tmp_vp);
7980 ok(count == 1, "Got viewport count %u, expected 1.\n", count);
7981 ok(!memcmp(tmp_vp, &vp, sizeof(vp)), "Got viewport %s, expected %s.\n",
7982 debugstr_viewport(tmp_vp), debugstr_viewport(&vp));
7983 memset(tmp_rect, 0xa5, sizeof(tmp_rect));
7984 count = 2;
7985 ID3D11DeviceContext1_RSGetScissorRects(context, &count, tmp_rect);
7986 ok(count == 1, "Got scissor rect count %u, expected 1.\n", count);
7987 ok(!memcmp(tmp_rect, &rect, sizeof(rect)), "Got scissor rect %s, expected %s.\n",
7988 wine_dbgstr_rect(tmp_rect), wine_dbgstr_rect(&rect));
7990 tmp_sob = (ID3D11Buffer *)0xdeadbeef;
7991 ID3D11DeviceContext1_SOGetTargets(context, 1, &tmp_sob);
7992 ok(tmp_sob == sob, "Got stream output buffer %p, expected %p.\n", tmp_sob, sob);
7993 ID3D11Buffer_Release(tmp_sob);
7995 tmp_pred = (ID3D11Predicate *)0xdeadbeef;
7996 pred_value = 0xdeadbeef;
7997 ID3D11DeviceContext1_GetPredication(context, &tmp_pred, &pred_value);
7998 ok(tmp_pred == pred, "Got predicate %p, expected %p.\n", tmp_pred, pred);
7999 ID3D11Predicate_Release(tmp_pred);
8000 ok(pred_value == TRUE, "Got predicate value %#x, expected TRUE.\n", pred_value);
8002 check_interface(device, &IID_ID3D10Device, TRUE, FALSE);
8003 check_interface(device, &IID_ID3D10Device1, TRUE, FALSE);
8005 ID3D11Predicate_Release(pred);
8006 ID3D11Buffer_Release(sob);
8007 ID3D11RasterizerState_Release(rs);
8008 ID3D11BlendState_Release(bs);
8009 ID3D11DepthStencilState_Release(dss);
8010 ID3D11DepthStencilView_Release(dsv);
8011 ID3D11RenderTargetView_Release(rtv);
8012 ID3D11UnorderedAccessView_Release(ps_uav);
8013 ID3D11InputLayout_Release(il);
8014 ID3D11Buffer_Release(ib);
8015 ID3D11Buffer_Release(vb);
8016 if (cs) ID3D11ComputeShader_Release(cs);
8017 if (ds) ID3D11DomainShader_Release(ds);
8018 if (hs) ID3D11HullShader_Release(hs);
8019 ID3D11PixelShader_Release(ps);
8020 ID3D11GeometryShader_Release(gs);
8021 ID3D11VertexShader_Release(vs);
8022 ID3D11Buffer_Release(cb);
8023 ID3D11ShaderResourceView_Release(srv);
8024 ID3D11UnorderedAccessView_Release(uav);
8025 ID3D11SamplerState_Release(sampler);
8026 ID3D11DeviceContext1_Release(context);
8027 refcount = ID3D11Device1_Release(device);
8028 ok(!refcount, "Device has %u references left.\n", refcount);
8031 static void test_blend(void)
8033 ID3D11BlendState *src_blend, *dst_blend, *dst_blend_factor;
8034 struct d3d11_test_context test_context;
8035 ID3D11RenderTargetView *offscreen_rtv;
8036 D3D11_TEXTURE2D_DESC texture_desc;
8037 ID3D11InputLayout *input_layout;
8038 ID3D11DeviceContext *context;
8039 D3D11_BLEND_DESC blend_desc;
8040 unsigned int stride, offset;
8041 ID3D11Texture2D *offscreen;
8042 ID3D11VertexShader *vs;
8043 ID3D11PixelShader *ps;
8044 ID3D11Device *device;
8045 ID3D11Buffer *vb;
8046 DWORD color;
8047 HRESULT hr;
8049 static const DWORD vs_code[] =
8051 #if 0
8052 struct vs_out
8054 float4 position : SV_POSITION;
8055 float4 color : COLOR;
8058 struct vs_out main(float4 position : POSITION, float4 color : COLOR)
8060 struct vs_out o;
8062 o.position = position;
8063 o.color = color;
8065 return o;
8067 #endif
8068 0x43425844, 0x5c73b061, 0x5c71125f, 0x3f8b345f, 0xce04b9ab, 0x00000001, 0x00000140, 0x00000003,
8069 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
8070 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
8071 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
8072 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
8073 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
8074 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040, 0x0000001a,
8075 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067, 0x001020f2,
8076 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
8077 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
8079 static const DWORD ps_code[] =
8081 #if 0
8082 struct vs_out
8084 float4 position : SV_POSITION;
8085 float4 color : COLOR;
8088 float4 main(struct vs_out i) : SV_TARGET
8090 return i.color;
8092 #endif
8093 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
8094 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
8095 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
8096 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
8097 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8098 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
8099 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
8100 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
8102 static const struct
8104 struct vec3 position;
8105 DWORD diffuse;
8107 quads[] =
8109 /* quad1 */
8110 {{-1.0f, -1.0f, 0.1f}, 0x4000ff00},
8111 {{-1.0f, 0.0f, 0.1f}, 0x4000ff00},
8112 {{ 1.0f, -1.0f, 0.1f}, 0x4000ff00},
8113 {{ 1.0f, 0.0f, 0.1f}, 0x4000ff00},
8114 /* quad2 */
8115 {{-1.0f, 0.0f, 0.1f}, 0xc0ff0000},
8116 {{-1.0f, 1.0f, 0.1f}, 0xc0ff0000},
8117 {{ 1.0f, 0.0f, 0.1f}, 0xc0ff0000},
8118 {{ 1.0f, 1.0f, 0.1f}, 0xc0ff0000},
8120 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
8122 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
8123 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
8125 static const float blend_factor[] = {0.3f, 0.4f, 0.8f, 0.9f};
8126 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8128 if (!init_test_context(&test_context, NULL))
8129 return;
8131 device = test_context.device;
8132 context = test_context.immediate_context;
8134 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
8135 vs_code, sizeof(vs_code), &input_layout);
8136 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
8138 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quads), quads);
8140 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
8141 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
8142 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
8143 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
8145 memset(&blend_desc, 0, sizeof(blend_desc));
8146 blend_desc.RenderTarget[0].BlendEnable = TRUE;
8147 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
8148 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
8149 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
8150 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
8151 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
8152 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
8153 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
8155 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &src_blend);
8156 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8158 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_DEST_ALPHA;
8159 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_DEST_ALPHA;
8160 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
8161 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
8163 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend);
8164 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8166 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_BLEND_FACTOR;
8167 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_BLEND_FACTOR;
8168 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
8169 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
8171 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &dst_blend_factor);
8172 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
8174 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
8175 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
8176 stride = sizeof(*quads);
8177 offset = 0;
8178 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
8179 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
8180 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8182 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8184 ID3D11DeviceContext_OMSetBlendState(context, src_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8185 ID3D11DeviceContext_Draw(context, 4, 0);
8186 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8187 ID3D11DeviceContext_Draw(context, 4, 4);
8189 color = get_texture_color(test_context.backbuffer, 320, 360);
8190 ok(compare_color(color, 0x700040bf, 1), "Got unexpected color 0x%08x.\n", color);
8191 color = get_texture_color(test_context.backbuffer, 320, 120);
8192 ok(compare_color(color, 0xa080007f, 1), "Got unexpected color 0x%08x.\n", color);
8194 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8196 ID3D11DeviceContext_OMSetBlendState(context, dst_blend_factor, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
8197 ID3D11DeviceContext_Draw(context, 4, 0);
8198 ID3D11DeviceContext_Draw(context, 4, 4);
8200 color = get_texture_color(test_context.backbuffer, 320, 360);
8201 ok(compare_color(color, 0x600066b3, 1), "Got unexpected color 0x%08x.\n", color);
8202 color = get_texture_color(test_context.backbuffer, 320, 120);
8203 ok(compare_color(color, 0xa0cc00b3, 1), "Got unexpected color 0x%08x.\n", color);
8205 texture_desc.Width = 128;
8206 texture_desc.Height = 128;
8207 texture_desc.MipLevels = 1;
8208 texture_desc.ArraySize = 1;
8209 texture_desc.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
8210 texture_desc.SampleDesc.Count = 1;
8211 texture_desc.SampleDesc.Quality = 0;
8212 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8213 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
8214 texture_desc.CPUAccessFlags = 0;
8215 texture_desc.MiscFlags = 0;
8217 /* DXGI_FORMAT_B8G8R8X8_UNORM is not supported on all implementations. */
8218 if (FAILED(ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen)))
8220 skip("DXGI_FORMAT_B8G8R8X8_UNORM not supported.\n");
8221 goto done;
8224 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
8225 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
8227 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
8229 set_viewport(context, 0.0f, 0.0f, 128.0f, 128.0f, 0.0f, 1.0f);
8231 ID3D11DeviceContext_ClearRenderTargetView(context, offscreen_rtv, red);
8233 ID3D11DeviceContext_OMSetBlendState(context, src_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8234 ID3D11DeviceContext_Draw(context, 4, 0);
8235 ID3D11DeviceContext_OMSetBlendState(context, dst_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
8236 ID3D11DeviceContext_Draw(context, 4, 4);
8238 color = get_texture_color(offscreen, 64, 96) & 0x00ffffff;
8239 ok(compare_color(color, 0x00bf4000, 1), "Got unexpected color 0x%08x.\n", color);
8240 color = get_texture_color(offscreen, 64, 32) & 0x00ffffff;
8241 ok(compare_color(color, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color);
8243 ID3D11RenderTargetView_Release(offscreen_rtv);
8244 ID3D11Texture2D_Release(offscreen);
8245 done:
8246 ID3D11BlendState_Release(dst_blend_factor);
8247 ID3D11BlendState_Release(dst_blend);
8248 ID3D11BlendState_Release(src_blend);
8249 ID3D11PixelShader_Release(ps);
8250 ID3D11VertexShader_Release(vs);
8251 ID3D11Buffer_Release(vb);
8252 ID3D11InputLayout_Release(input_layout);
8253 release_test_context(&test_context);
8256 static void test_texture1d(void)
8258 struct shader
8260 const DWORD *code;
8261 size_t size;
8263 struct texture
8265 UINT width;
8266 UINT miplevel_count;
8267 UINT array_size;
8268 DXGI_FORMAT format;
8269 D3D11_SUBRESOURCE_DATA data[3];
8272 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8273 struct d3d11_test_context test_context;
8274 const struct texture *current_texture;
8275 D3D11_TEXTURE1D_DESC texture_desc;
8276 D3D11_SAMPLER_DESC sampler_desc;
8277 const struct shader *current_ps;
8278 D3D_FEATURE_LEVEL feature_level;
8279 ID3D11ShaderResourceView *srv;
8280 ID3D11DeviceContext *context;
8281 ID3D11SamplerState *sampler;
8282 struct resource_readback rb;
8283 ID3D11Texture1D *texture;
8284 struct vec4 ps_constant;
8285 ID3D11PixelShader *ps;
8286 ID3D11Device *device;
8287 unsigned int i, x;
8288 ID3D11Buffer *cb;
8289 DWORD color;
8290 HRESULT hr;
8292 static const DWORD ps_ld_code[] =
8294 #if 0
8295 Texture1D t;
8297 float miplevel;
8299 float4 main(float4 position : SV_POSITION) : SV_TARGET
8301 float2 p;
8302 t.GetDimensions(miplevel, p.x, p.y);
8303 p.y = miplevel;
8304 p *= float2(position.x / 640.0f, 1.0f);
8305 return t.Load(int2(p));
8307 #endif
8308 0x43425844, 0x7b0c6359, 0x598178f6, 0xef2ddbdb, 0x88fc794c, 0x00000001, 0x000001ac, 0x00000003,
8309 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8310 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8311 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8312 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
8313 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001058, 0x00107000, 0x00000000,
8314 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8315 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
8316 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
8317 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000e2,
8318 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
8319 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
8320 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
8321 0x00107e46, 0x00000000, 0x0100003e,
8323 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
8324 static const DWORD ps_ld_sint8_code[] =
8326 #if 0
8327 Texture1D<int4> t;
8329 float4 main(float4 position : SV_POSITION) : SV_TARGET
8331 float2 p, s;
8332 int4 c;
8334 p = float2(position.x / 640.0f, 0.0f);
8335 t.GetDimensions(0, s.x, s.y);
8336 p *= s;
8338 c = t.Load(int2(p));
8339 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
8341 #endif
8342 0x43425844, 0x65a13d1e, 0x8a0bfc92, 0xa2f2708a, 0x0bafafb6, 0x00000001, 0x00000234, 0x00000003,
8343 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8344 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8345 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8346 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000198, 0x00000040,
8347 0x00000066, 0x04001058, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101012, 0x00000000,
8348 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8349 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
8350 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
8351 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
8352 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8353 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0500002b,
8354 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
8355 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204, 0x3c010204, 0x0a000034, 0x001000f2,
8356 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000, 0xbf800000, 0xbf800000, 0xbf800000,
8357 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
8358 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002,
8359 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
8361 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
8362 static const DWORD ps_ld_uint8_code[] =
8364 #if 0
8365 Texture1D<uint4> t;
8367 float4 main(float4 position : SV_POSITION) : SV_TARGET
8369 float2 p, s;
8371 p = float2(position.x / 640.0f, 0.0f);
8372 t.GetDimensions(0, s.x, s.y);
8373 p *= s;
8375 return t.Load(int2(p)) / (float4)255;
8377 #endif
8378 0x43425844, 0x35186c1f, 0x55bad4fd, 0xb7c97a57, 0x99c060e7, 0x00000001, 0x000001bc, 0x00000003,
8379 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8380 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8381 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8382 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000120, 0x00000040,
8383 0x00000048, 0x04001058, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101012, 0x00000000,
8384 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8385 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100012, 0x00000001,
8386 0x0010100a, 0x00000000, 0x00004001, 0x3acccccd, 0x08000036, 0x001000e2, 0x00000001, 0x00004002,
8387 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038, 0x001000f2, 0x00000000, 0x00100fc6,
8388 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8389 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x05000056,
8390 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46,
8391 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081, 0x3b808081, 0x0100003e,
8393 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
8394 static DWORD ps_ld_array_code[] =
8396 #if 0
8397 Texture1DArray t;
8399 float miplevel;
8401 float4 main(float4 position : SV_POSITION) : SV_TARGET
8403 float3 p;
8404 t.GetDimensions(miplevel, p.x, p.y, p.z);
8405 p.y = 1;
8406 p.z = miplevel;
8407 p *= float3(position.x / 640.0f, 1.0f, 1.0f);
8408 return t.Load(int3(p));
8410 #endif
8411 0x43425844, 0xbfccadc4, 0xc00ff13d, 0x2ba75365, 0xf747cbee, 0x00000001, 0x000001c0, 0x00000003,
8412 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8413 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
8414 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8415 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000124, 0x00000040,
8416 0x00000049, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003858, 0x00107000, 0x00000000,
8417 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8418 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
8419 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
8420 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0010100a, 0x00000000, 0x06000036, 0x001000c2,
8421 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x00100072, 0x00000000, 0x00100386,
8422 0x00000000, 0x00004002, 0x3acccccd, 0x3f800000, 0x3f800000, 0x00000000, 0x0500001b, 0x001000d2,
8423 0x00000000, 0x00100906, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000001,
8424 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
8426 static const struct shader ps_ld_array = {ps_ld_array_code, sizeof(ps_ld_array_code)};
8428 static const DWORD rgba_level_0[] =
8430 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8432 static const DWORD rgba_level_1[] =
8434 0xffffffff, 0xff0000ff,
8436 static const DWORD rgba_level_2[] =
8438 0xffff0000,
8440 static const DWORD srgb_data[] =
8442 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
8444 static const DWORD r32_uint[] =
8446 0, 1, 2, 3,
8448 static const DWORD r9g9b9e5_data[] =
8450 0x80000100, 0x80020000, 0x84000000, 0x84000100,
8452 static const DWORD array_data0[] =
8454 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
8456 static const DWORD array_data1[] =
8458 0x00ffff00, 0xff000000, 0x00ff0000, 0x000000ff,
8460 static const DWORD array_data2[] =
8462 0x000000ff, 0xffff00ff, 0x0000ff00, 0xff000000,
8464 static const struct texture rgba_texture =
8466 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
8468 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
8469 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
8470 {rgba_level_2, sizeof(*rgba_level_2), 0},
8473 static const struct texture srgb_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
8474 {{srgb_data, 4 * sizeof(*srgb_data)}}};
8475 static const struct texture sint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
8476 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
8477 static const struct texture uint8_texture = {4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
8478 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
8479 static const struct texture r32u_typeless = {4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
8480 {{r32_uint, 4 * sizeof(*r32_uint)}}};
8481 static const struct texture r9g9b9e5_texture = {4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
8482 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
8483 static const struct texture array_texture = {4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
8485 {array_data0, 4 * sizeof(*array_data0)},
8486 {array_data1, 4 * sizeof(*array_data1)},
8487 {array_data2, 4 * sizeof(*array_data2)},
8491 static const DWORD level_1_colors[] =
8493 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
8495 static const DWORD level_2_colors[] =
8497 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
8499 static const DWORD srgb_colors[] =
8501 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
8503 static const DWORD sint8_colors[] =
8505 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
8507 static const DWORD r32u_colors[4] =
8509 0x01000000, 0x01000001, 0x01000002, 0x01000003,
8511 static const DWORD r9g9b9e5_colors[4] =
8513 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
8515 static const DWORD zero_colors[4] = {0};
8516 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
8517 static const struct texture_test
8519 const struct shader *ps;
8520 const struct texture *texture;
8521 D3D11_FILTER filter;
8522 float lod_bias;
8523 float min_lod;
8524 float max_lod;
8525 float ps_constant;
8526 const DWORD *expected_colors;
8528 texture_tests[] =
8530 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
8531 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
8532 #define MIP_MAX D3D11_FLOAT32_MAX
8533 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
8534 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
8535 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
8536 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
8537 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
8538 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
8539 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
8540 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
8541 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
8542 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
8543 {&ps_ld_array, &array_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, array_data1},
8545 #undef POINT
8546 #undef POINT_LINEAR
8547 #undef MIP_MAX
8548 static const struct srv_test
8550 const struct shader *ps;
8551 const struct texture *texture;
8552 struct srv_desc srv_desc;
8553 float ps_constant;
8554 const DWORD *expected_colors;
8556 srv_tests[] =
8558 #define TEX_1D D3D11_SRV_DIMENSION_TEXTURE1D
8559 #define R32_UINT DXGI_FORMAT_R32_UINT
8560 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_1D, 0, 1}, 0.0f, r32u_colors},
8561 #undef TEX_1D
8562 #undef R32_UINT
8563 #undef FMT_UNKNOWN
8566 if (!init_test_context(&test_context, NULL))
8567 return;
8569 device = test_context.device;
8570 context = test_context.immediate_context;
8571 feature_level = ID3D11Device_GetFeatureLevel(device);
8573 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
8575 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
8577 texture_desc.Usage = D3D11_USAGE_DEFAULT;
8578 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
8579 texture_desc.CPUAccessFlags = 0;
8580 texture_desc.MiscFlags = 0;
8582 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8583 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
8584 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
8585 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
8586 sampler_desc.MipLODBias = 0.0f;
8587 sampler_desc.MaxAnisotropy = 0;
8588 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
8589 sampler_desc.BorderColor[0] = 0.0f;
8590 sampler_desc.BorderColor[1] = 0.0f;
8591 sampler_desc.BorderColor[2] = 0.0f;
8592 sampler_desc.BorderColor[3] = 0.0f;
8593 sampler_desc.MinLOD = 0.0f;
8594 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
8596 ps = NULL;
8597 srv = NULL;
8598 sampler = NULL;
8599 texture = NULL;
8600 current_ps = NULL;
8601 current_texture = NULL;
8602 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
8604 const struct texture_test *test = &texture_tests[i];
8606 if (current_ps != test->ps)
8608 if (ps)
8609 ID3D11PixelShader_Release(ps);
8611 current_ps = test->ps;
8613 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
8614 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
8616 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8619 if (current_texture != test->texture)
8621 if (texture)
8622 ID3D11Texture1D_Release(texture);
8623 if (srv)
8624 ID3D11ShaderResourceView_Release(srv);
8626 current_texture = test->texture;
8628 if (current_texture)
8630 texture_desc.Width = current_texture->width;
8631 texture_desc.MipLevels = current_texture->miplevel_count;
8632 texture_desc.ArraySize = current_texture->array_size;
8633 texture_desc.Format = current_texture->format;
8635 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
8636 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
8638 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
8639 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
8641 else
8643 texture = NULL;
8644 srv = NULL;
8647 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8650 if (!sampler || (sampler_desc.Filter != test->filter
8651 || sampler_desc.MipLODBias != test->lod_bias
8652 || sampler_desc.MinLOD != test->min_lod
8653 || sampler_desc.MaxLOD != test->max_lod))
8655 if (sampler)
8656 ID3D11SamplerState_Release(sampler);
8658 sampler_desc.Filter = test->filter;
8659 sampler_desc.MipLODBias = test->lod_bias;
8660 sampler_desc.MinLOD = test->min_lod;
8661 sampler_desc.MaxLOD = test->max_lod;
8663 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
8664 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
8666 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8669 ps_constant.x = test->ps_constant;
8670 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
8672 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8674 draw_quad(&test_context);
8676 get_texture_readback(test_context.backbuffer, 0, &rb);
8677 for (x = 0; x < 4; ++x)
8679 color = get_readback_color(&rb, 80 + x * 160, 0, 0);
8680 ok(compare_color(color, test->expected_colors[x], 2),
8681 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
8683 release_resource_readback(&rb);
8685 if (srv)
8686 ID3D11ShaderResourceView_Release(srv);
8687 ID3D11SamplerState_Release(sampler);
8688 if (texture)
8689 ID3D11Texture1D_Release(texture);
8690 ID3D11PixelShader_Release(ps);
8692 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
8694 win_skip("SRV tests are broken on WARP.\n");
8695 ID3D11Buffer_Release(cb);
8696 release_test_context(&test_context);
8697 return;
8700 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
8701 sampler_desc.MipLODBias = 0.0f;
8702 sampler_desc.MinLOD = 0.0f;
8703 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
8705 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
8706 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
8708 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
8710 ps = NULL;
8711 srv = NULL;
8712 texture = NULL;
8713 current_ps = NULL;
8714 current_texture = NULL;
8715 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
8717 const struct srv_test *test = &srv_tests[i];
8719 if (current_ps != test->ps)
8721 if (ps)
8722 ID3D11PixelShader_Release(ps);
8724 current_ps = test->ps;
8726 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
8727 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
8729 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
8732 if (current_texture != test->texture)
8734 if (texture)
8735 ID3D11Texture1D_Release(texture);
8737 current_texture = test->texture;
8739 texture_desc.Width = current_texture->width;
8740 texture_desc.MipLevels = current_texture->miplevel_count;
8741 texture_desc.ArraySize = current_texture->array_size;
8742 texture_desc.Format = current_texture->format;
8744 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, current_texture->data, &texture);
8745 ok(SUCCEEDED(hr), "Test %u: Failed to create 1d texture, hr %#x.\n", i, hr);
8748 if (srv)
8749 ID3D11ShaderResourceView_Release(srv);
8751 get_srv_desc(&srv_desc, &test->srv_desc);
8752 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
8753 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
8755 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
8757 ps_constant.x = test->ps_constant;
8758 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
8760 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
8762 draw_quad(&test_context);
8764 get_texture_readback(test_context.backbuffer, 0, &rb);
8765 for (x = 0; x < 4; ++x)
8767 color = get_readback_color(&rb, 80 + x * 160, 0, 0);
8768 ok(compare_color(color, test->expected_colors[x], 1),
8769 "Test %u: Got unexpected color 0x%08x at (%u).\n", i, color, x);
8771 release_resource_readback(&rb);
8773 ID3D11PixelShader_Release(ps);
8774 ID3D11Texture1D_Release(texture);
8775 ID3D11ShaderResourceView_Release(srv);
8776 ID3D11SamplerState_Release(sampler);
8778 ID3D11Buffer_Release(cb);
8779 release_test_context(&test_context);
8782 static void test_texture(void)
8784 struct shader
8786 const DWORD *code;
8787 size_t size;
8789 struct texture
8791 UINT width;
8792 UINT height;
8793 UINT miplevel_count;
8794 UINT array_size;
8795 DXGI_FORMAT format;
8796 D3D11_SUBRESOURCE_DATA data[3];
8799 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
8800 struct d3d11_test_context test_context;
8801 const struct texture *current_texture;
8802 D3D11_TEXTURE2D_DESC texture_desc;
8803 D3D11_SAMPLER_DESC sampler_desc;
8804 const struct shader *current_ps;
8805 D3D_FEATURE_LEVEL feature_level;
8806 ID3D11ShaderResourceView *srv;
8807 ID3D11DeviceContext *context;
8808 ID3D11SamplerState *sampler;
8809 struct resource_readback rb;
8810 ID3D11Texture2D *texture;
8811 struct vec4 ps_constant;
8812 ID3D11PixelShader *ps;
8813 ID3D11Device *device;
8814 unsigned int i, x, y;
8815 ID3D11Buffer *cb;
8816 DWORD color;
8817 HRESULT hr;
8819 static const DWORD ps_ld_code[] =
8821 #if 0
8822 Texture2D t;
8824 float miplevel;
8826 float4 main(float4 position : SV_POSITION) : SV_TARGET
8828 float3 p;
8829 t.GetDimensions(miplevel, p.x, p.y, p.z);
8830 p.z = miplevel;
8831 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
8832 return t.Load(int3(p));
8834 #endif
8835 0x43425844, 0xbdda6bdf, 0xc6ffcdf1, 0xa58596b3, 0x822383f0, 0x00000001, 0x000001ac, 0x00000003,
8836 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8837 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8838 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8839 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040,
8840 0x00000044, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000,
8841 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
8842 0x02000068, 0x00000001, 0x0600001c, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
8843 0x0700003d, 0x001000f2, 0x00000000, 0x0010000a, 0x00000000, 0x00107e46, 0x00000000, 0x07000038,
8844 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x06000036, 0x001000c2,
8845 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46,
8846 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001b, 0x001000f2,
8847 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
8848 0x00107e46, 0x00000000, 0x0100003e,
8850 static const struct shader ps_ld = {ps_ld_code, sizeof(ps_ld_code)};
8851 static const DWORD ps_ld_sint8_code[] =
8853 #if 0
8854 Texture2D<int4> t;
8856 float4 main(float4 position : SV_POSITION) : SV_TARGET
8858 float3 p, s;
8859 int4 c;
8861 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
8862 t.GetDimensions(0, s.x, s.y, s.z);
8863 p *= s;
8865 c = t.Load(int3(p));
8866 return (max(c / (float4)127, (float4)-1) + (float4)1) / 2.0f;
8868 #endif
8869 0x43425844, 0xb3d0b0fc, 0x0e486f4a, 0xf67eec12, 0xfb9dd52f, 0x00000001, 0x00000240, 0x00000003,
8870 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8871 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8872 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8873 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000001a4, 0x00000040,
8874 0x00000069, 0x04001858, 0x00107000, 0x00000000, 0x00003333, 0x04002064, 0x00101032, 0x00000000,
8875 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8876 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
8877 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
8878 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
8879 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
8880 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8881 0x00107e46, 0x00000000, 0x0500002b, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
8882 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3c010204, 0x3c010204, 0x3c010204,
8883 0x3c010204, 0x0a000034, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0xbf800000,
8884 0xbf800000, 0xbf800000, 0xbf800000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8885 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0a000038, 0x001020f2, 0x00000000,
8886 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
8888 static const struct shader ps_ld_sint8 = {ps_ld_sint8_code, sizeof(ps_ld_sint8_code)};
8889 static const DWORD ps_ld_uint8_code[] =
8891 #if 0
8892 Texture2D<uint4> t;
8894 float4 main(float4 position : SV_POSITION) : SV_TARGET
8896 float3 p, s;
8898 p = float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
8899 t.GetDimensions(0, s.x, s.y, s.z);
8900 p *= s;
8902 return t.Load(int3(p)) / (float4)255;
8904 #endif
8905 0x43425844, 0xd09917eb, 0x4508a07e, 0xb0b7250a, 0x228c1f0e, 0x00000001, 0x000001c8, 0x00000003,
8906 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8907 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8908 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8909 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000012c, 0x00000040,
8910 0x0000004b, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
8911 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2,
8912 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x00100032, 0x00000001,
8913 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
8914 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000038,
8915 0x001000f2, 0x00000000, 0x00100f46, 0x00000000, 0x00100e46, 0x00000001, 0x0500001b, 0x001000f2,
8916 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
8917 0x00107e46, 0x00000000, 0x05000056, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0a000038,
8918 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3b808081, 0x3b808081, 0x3b808081,
8919 0x3b808081, 0x0100003e,
8921 static const struct shader ps_ld_uint8 = {ps_ld_uint8_code, sizeof(ps_ld_uint8_code)};
8922 static const DWORD ps_sample_code[] =
8924 #if 0
8925 Texture2D t;
8926 SamplerState s;
8928 float4 main(float4 position : SV_POSITION) : SV_Target
8930 float2 p;
8932 p.x = position.x / 640.0f;
8933 p.y = position.y / 480.0f;
8934 return t.Sample(s, p);
8936 #endif
8937 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
8938 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8939 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8940 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8941 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
8942 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
8943 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
8944 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
8945 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
8946 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
8948 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
8949 static const DWORD ps_sample_b_code[] =
8951 #if 0
8952 Texture2D t;
8953 SamplerState s;
8955 float bias;
8957 float4 main(float4 position : SV_POSITION) : SV_Target
8959 float2 p;
8961 p.x = position.x / 640.0f;
8962 p.y = position.y / 480.0f;
8963 return t.SampleBias(s, p, bias);
8965 #endif
8966 0x43425844, 0xc39b0686, 0x8244a7fc, 0x14c0b97a, 0x2900b3b7, 0x00000001, 0x00000150, 0x00000003,
8967 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8968 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8969 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
8970 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
8971 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
8972 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
8973 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
8974 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c00004a,
8975 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
8976 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
8978 static const struct shader ps_sample_b = {ps_sample_b_code, sizeof(ps_sample_b_code)};
8979 static const DWORD ps_sample_l_code[] =
8981 #if 0
8982 Texture2D t;
8983 SamplerState s;
8985 float level;
8987 float4 main(float4 position : SV_POSITION) : SV_Target
8989 float2 p;
8991 p.x = position.x / 640.0f;
8992 p.y = position.y / 480.0f;
8993 return t.SampleLevel(s, p, level);
8995 #endif
8996 0x43425844, 0x61e05d85, 0x2a7300fb, 0x0a83706b, 0x889d1683, 0x00000001, 0x00000150, 0x00000003,
8997 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
8998 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
8999 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9000 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b4, 0x00000040,
9001 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9002 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9003 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
9004 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000048,
9005 0x001020f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000,
9006 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
9008 static const struct shader ps_sample_l = {ps_sample_l_code, sizeof(ps_sample_l_code)};
9009 static const DWORD ps_sample_2d_array_code[] =
9011 #if 0
9012 Texture2DArray t;
9013 SamplerState s;
9015 float layer;
9017 float4 main(float4 position : SV_POSITION) : SV_TARGET
9019 float3 d;
9020 float3 p = float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
9021 t.GetDimensions(d.x, d.y, d.z);
9022 d.z = layer;
9023 return t.Sample(s, p * d);
9025 #endif
9026 0x43425844, 0xa9457e44, 0xc0b3ef8e, 0x3d751ae8, 0x23fa4807, 0x00000001, 0x00000194, 0x00000003,
9027 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9028 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9029 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9030 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f8, 0x00000040,
9031 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9032 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9033 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2, 0x00000000,
9034 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x0a000038, 0x001000c2, 0x00000000, 0x00101406,
9035 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3acccccd, 0x3b088889, 0x07000038, 0x00100032,
9036 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000, 0x06000036, 0x00100042, 0x00000000,
9037 0x0020800a, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
9038 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
9040 static const struct shader ps_sample_2d_array = {ps_sample_2d_array_code, sizeof(ps_sample_2d_array_code)};
9041 static const DWORD red_data[] =
9043 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9044 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9045 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9046 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff, 0x00000000, 0x00000000,
9048 static const DWORD green_data[] =
9050 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9051 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9052 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9053 0xff00ff00, 0xff00ff00, 0xff00ff00, 0xff00ff00,
9055 static const DWORD blue_data[] =
9057 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9058 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9059 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9060 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000, 0x00000000,
9062 static const DWORD rgba_level_0[] =
9064 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
9065 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
9066 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
9067 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
9069 static const DWORD rgba_level_1[] =
9071 0xffffffff, 0xff0000ff,
9072 0xff000000, 0xff00ff00,
9074 static const DWORD rgba_level_2[] =
9076 0xffff0000,
9078 static const DWORD srgb_data[] =
9080 0x00000000, 0xffffffff, 0xff000000, 0x7f7f7f7f,
9081 0xff010203, 0xff102030, 0xff0a0b0c, 0xff8090a0,
9082 0xffb1c4de, 0xfff0f1f2, 0xfffafdfe, 0xff5a560f,
9083 0xffd5ff00, 0xffc8f99f, 0xffaa00aa, 0xffdd55bb,
9085 static const WORD r8g8_data[] =
9087 0x0000, 0xffff, 0x0000, 0x7fff,
9088 0x0203, 0xff10, 0x0b0c, 0x8000,
9089 0xc4de, 0xfff0, 0xfdfe, 0x5a6f,
9090 0xff00, 0xffc8, 0x00aa, 0xdd5b,
9092 static const BYTE a8_data[] =
9094 0x00, 0x10, 0x20, 0x30,
9095 0x40, 0x50, 0x60, 0x70,
9096 0x80, 0x90, 0xa0, 0xb0,
9097 0xc0, 0xd0, 0xe0, 0xf0,
9099 static const BYTE bc1_data[] =
9101 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
9102 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
9103 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
9104 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
9106 static const BYTE bc2_data[] =
9108 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
9109 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
9110 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
9111 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
9113 static const BYTE bc3_data[] =
9115 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00,
9116 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0xe0, 0x07, 0x00, 0x00, 0x00, 0x00,
9117 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00,
9118 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
9120 static const BYTE bc4_data[] =
9122 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
9123 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
9124 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
9125 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
9127 static const BYTE bc5_data[] =
9129 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00, 0x10, 0x7f, 0x77, 0x39, 0x05, 0x00, 0x00, 0x00,
9130 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, 0x10, 0x7f, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24,
9131 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x10, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
9132 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb, 0x10, 0x7f, 0xb6, 0x6d, 0xdb, 0xb6, 0x6d, 0xdb,
9134 static const BYTE bc6h_u_data[] =
9136 0xe3, 0x5e, 0x00, 0x00, 0x78, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9137 0x03, 0x80, 0x7b, 0x01, 0x00, 0xe0, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9138 0x03, 0x00, 0x00, 0xee, 0x05, 0x00, 0x80, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9139 0xe3, 0xde, 0x7b, 0xef, 0x7d, 0xef, 0xbd, 0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9141 static const BYTE bc6h_s_data[] =
9143 0x63, 0x2f, 0x00, 0x00, 0xb8, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9144 0x03, 0x80, 0xbd, 0x00, 0x00, 0xe0, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9145 0x03, 0x00, 0x00, 0xf6, 0x02, 0x00, 0x80, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9146 0x63, 0xaf, 0xbd, 0xf6, 0xba, 0xe7, 0x9e, 0x7b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9148 static const BYTE bc7_data[] =
9150 0x02, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9151 0x02, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9152 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9153 0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
9155 static const float r32_float[] =
9157 0.0f, 1.0f, 0.5f, 0.50f,
9158 1.0f, 0.0f, 0.0f, 0.75f,
9159 0.0f, 1.0f, 0.5f, 0.25f,
9160 1.0f, 0.0f, 0.0f, 0.75f,
9162 static const DWORD r32_uint[] =
9164 0, 1, 2, 3,
9165 100, 200, 255, 128,
9166 40, 30, 20, 10,
9167 250, 210, 155, 190,
9169 static const DWORD r9g9b9e5_data[] =
9171 0x80000100, 0x80020000, 0x84000000, 0x84000100,
9172 0x78000100, 0x78020000, 0x7c000000, 0x78020100,
9173 0x70000133, 0x70026600, 0x74cc0000, 0x74cc0133,
9174 0x6800019a, 0x68033400, 0x6e680000, 0x6e6b359a,
9176 static const struct texture rgba_texture =
9178 4, 4, 3, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
9180 {rgba_level_0, 4 * sizeof(*rgba_level_0), 0},
9181 {rgba_level_1, 2 * sizeof(*rgba_level_1), 0},
9182 {rgba_level_2, sizeof(*rgba_level_2), 0},
9185 static const struct texture srgb_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
9186 {{srgb_data, 4 * sizeof(*srgb_data)}}};
9187 static const struct texture srgb_typeless = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_TYPELESS,
9188 {{srgb_data, 4 * sizeof(*srgb_data)}}};
9189 static const struct texture a8_texture = {4, 4, 1, 1, DXGI_FORMAT_A8_UNORM,
9190 {{a8_data, 4 * sizeof(*a8_data)}}};
9191 static const struct texture bc1_texture = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM, {{bc1_data, 2 * 8}}};
9192 static const struct texture bc2_texture = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM, {{bc2_data, 2 * 16}}};
9193 static const struct texture bc3_texture = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM, {{bc3_data, 2 * 16}}};
9194 static const struct texture bc4_texture = {8, 8, 1, 1, DXGI_FORMAT_BC4_UNORM, {{bc4_data, 2 * 8}}};
9195 static const struct texture bc5_texture = {8, 8, 1, 1, DXGI_FORMAT_BC5_UNORM, {{bc5_data, 2 * 16}}};
9196 static const struct texture bc6h_u_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_UF16, {{bc6h_u_data, 2 * 16}}};
9197 static const struct texture bc6h_s_texture = {8, 8, 1, 1, DXGI_FORMAT_BC6H_SF16, {{bc6h_s_data, 2 * 16}}};
9198 static const struct texture bc7_texture = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM, {{bc7_data, 2 * 16}}};
9199 static const struct texture bc1_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC1_UNORM_SRGB, {{bc1_data, 2 * 8}}};
9200 static const struct texture bc2_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC2_UNORM_SRGB, {{bc2_data, 2 * 16}}};
9201 static const struct texture bc3_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC3_UNORM_SRGB, {{bc3_data, 2 * 16}}};
9202 static const struct texture bc7_texture_srgb = {8, 8, 1, 1, DXGI_FORMAT_BC7_UNORM_SRGB, {{bc7_data, 2 * 16}}};
9203 static const struct texture bc1_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC1_TYPELESS, {{bc1_data, 2 * 8}}};
9204 static const struct texture bc2_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC2_TYPELESS, {{bc2_data, 2 * 16}}};
9205 static const struct texture bc3_typeless = {8, 8, 1, 1, DXGI_FORMAT_BC3_TYPELESS, {{bc3_data, 2 * 16}}};
9206 static const struct texture sint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_SINT,
9207 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
9208 static const struct texture uint8_texture = {4, 4, 1, 1, DXGI_FORMAT_R8G8B8A8_UINT,
9209 {{rgba_level_0, 4 * sizeof(*rgba_level_0)}}};
9210 static const struct texture array_2d_texture =
9212 4, 4, 1, 3, DXGI_FORMAT_R8G8B8A8_UNORM,
9214 {red_data, 6 * sizeof(*red_data)},
9215 {green_data, 4 * sizeof(*green_data)},
9216 {blue_data, 5 * sizeof(*blue_data)},
9219 static const struct texture r32f_float = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
9220 {{r32_float, 4 * sizeof(*r32_float)}}};
9221 static const struct texture r32f_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
9222 {{r32_float, 4 * sizeof(*r32_float)}}};
9223 static const struct texture r32u_typeless = {4, 4, 1, 1, DXGI_FORMAT_R32_TYPELESS,
9224 {{r32_uint, 4 * sizeof(*r32_uint)}}};
9225 static const struct texture r8g8_snorm = {4, 4, 1, 1, DXGI_FORMAT_R8G8_SNORM,
9226 {{r8g8_data, 4 * sizeof(*r8g8_data)}}};
9227 static const struct texture r9g9b9e5_texture = {4, 4, 1, 1, DXGI_FORMAT_R9G9B9E5_SHAREDEXP,
9228 {{r9g9b9e5_data, 4 * sizeof(*r9g9b9e5_data)}}};
9229 static const DWORD red_colors[] =
9231 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9232 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9233 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9234 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
9236 static const DWORD blue_colors[] =
9238 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9239 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9240 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9241 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9243 static const DWORD level_1_colors[] =
9245 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
9246 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
9247 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
9248 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
9250 static const DWORD lerp_1_2_colors[] =
9252 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
9253 0xffff7f7f, 0xffff7f7f, 0xff7f007f, 0xff7f007f,
9254 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
9255 0xff7f0000, 0xff7f0000, 0xff7f7f00, 0xff7f7f00,
9257 static const DWORD level_2_colors[] =
9259 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9260 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9261 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9262 0xffff0000, 0xffff0000, 0xffff0000, 0xffff0000,
9264 static const DWORD srgb_colors[] =
9266 0x00000001, 0xffffffff, 0xff000000, 0x7f363636,
9267 0xff000000, 0xff010408, 0xff010101, 0xff37475a,
9268 0xff708cba, 0xffdee0e2, 0xfff3fbfd, 0xff1a1801,
9269 0xffa9ff00, 0xff93f159, 0xff670067, 0xffb8177f,
9271 static const DWORD a8_colors[] =
9273 0x00000000, 0x10000000, 0x20000000, 0x30000000,
9274 0x40000000, 0x50000000, 0x60000000, 0x70000000,
9275 0x80000000, 0x90000000, 0xa0000000, 0xb0000000,
9276 0xc0000000, 0xd0000000, 0xe0000000, 0xf0000000,
9278 static const DWORD bc_colors[] =
9280 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
9281 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xff00ff00,
9282 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
9283 0xffff0000, 0xffff0000, 0xffffffff, 0xffffffff,
9285 static const DWORD bc4_colors[] =
9287 0xff000026, 0xff000010, 0xff00007f, 0xff00007f,
9288 0xff000010, 0xff000010, 0xff00007f, 0xff00007f,
9289 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
9290 0xff0000ff, 0xff0000ff, 0xff000000, 0xff000000,
9292 static const DWORD bc5_colors[] =
9294 0xff002626, 0xff001010, 0xff007f7f, 0xff007f7f,
9295 0xff001010, 0xff001010, 0xff007f7f, 0xff007f7f,
9296 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
9297 0xff00ffff, 0xff00ffff, 0xff000000, 0xff000000,
9299 static const DWORD bc7_colors[] =
9301 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
9302 0xff0000fc, 0xff0000fc, 0xff00fc00, 0xff00fc00,
9303 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
9304 0xfffc0000, 0xfffc0000, 0xffffffff, 0xffffffff,
9306 static const DWORD sint8_colors[] =
9308 0x7e80807e, 0x7e807e7e, 0x7e807e80, 0x7e7e7e80,
9309 0x7e7e8080, 0x7e7e7f7f, 0x7e808080, 0x7effffff,
9310 0x7e7e7e7e, 0x7e7e7e7e, 0x7e7e7e7e, 0x7e808080,
9311 0x7e7e7e7e, 0x7e7f7f7f, 0x7e7f7f7f, 0x7e7f7f7f,
9313 static const DWORD snorm_colors[] =
9315 0xff000000, 0xff000000, 0xff000000, 0xff00ff00,
9316 0xff000406, 0xff000020, 0xff001618, 0xff000000,
9317 0xff000000, 0xff000000, 0xff000000, 0xff00b5df,
9318 0xff000000, 0xff000000, 0xff000000, 0xff0000b7,
9320 static const DWORD r32f_colors[] =
9322 0xff000000, 0xff0000ff, 0xff00007f, 0xff00007f,
9323 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
9324 0xff000000, 0xff0000ff, 0xff00007f, 0xff000040,
9325 0xff0000ff, 0xff000000, 0xff000000, 0xff0000bf,
9327 static const DWORD r32u_colors[16] =
9329 0x01000000, 0x01000001, 0x01000002, 0x01000003,
9330 0x01000064, 0x010000c8, 0x010000ff, 0x01000080,
9331 0x01000028, 0x0100001e, 0x01000014, 0x0100000a,
9332 0x010000fa, 0x010000d2, 0x0100009b, 0x010000be,
9334 static const DWORD r9g9b9e5_colors[16] =
9336 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffff00ff,
9337 0xff00007f, 0xff007f00, 0xff7f0000, 0xff007f7f,
9338 0xff00004c, 0xff004c00, 0xff4c0000, 0xff4c004c,
9339 0xff000033, 0xff003300, 0xff330000, 0xff333333,
9341 static const DWORD zero_colors[4 * 4] = {0};
9342 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
9344 static const struct texture_test
9346 const struct shader *ps;
9347 const struct texture *texture;
9348 D3D11_FILTER filter;
9349 float lod_bias;
9350 float min_lod;
9351 float max_lod;
9352 float ps_constant;
9353 const DWORD *expected_colors;
9355 texture_tests[] =
9357 #define POINT D3D11_FILTER_MIN_MAG_MIP_POINT
9358 #define POINT_LINEAR D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR
9359 #define MIP_MAX D3D11_FLOAT32_MAX
9360 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
9361 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, level_1_colors},
9362 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 2.0f, level_2_colors},
9363 {&ps_ld, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 3.0f, zero_colors},
9364 {&ps_ld, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
9365 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9366 {&ps_ld, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9367 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9368 {&ps_ld, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9369 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9370 {&ps_ld, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9371 {&ps_ld, &bc1_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9372 {&ps_ld, &bc2_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9373 {&ps_ld, &bc3_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9374 {&ps_ld, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
9375 {&ps_ld, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
9376 {&ps_ld, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9377 {&ps_ld, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9378 {&ps_ld, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9379 {&ps_ld, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9380 {&ps_ld, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
9381 {&ps_ld, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9382 {&ps_ld, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9383 {&ps_ld_sint8, &sint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, sint8_colors},
9384 {&ps_ld_uint8, &uint8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
9385 {&ps_sample, &bc1_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9386 {&ps_sample, &bc2_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9387 {&ps_sample, &bc3_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9388 {&ps_sample, &bc4_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc4_colors},
9389 {&ps_sample, &bc5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc5_colors},
9390 {&ps_sample, &bc6h_u_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9391 {&ps_sample, &bc6h_s_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc_colors},
9392 {&ps_sample, &bc7_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9393 {&ps_sample, &bc7_texture_srgb, POINT, 0.0f, 0.0f, 0.0f, 0.0f, bc7_colors},
9394 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, rgba_level_0},
9395 {&ps_sample, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9396 {&ps_sample, &rgba_texture, POINT, 2.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9397 {&ps_sample, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
9398 {&ps_sample, &srgb_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, srgb_colors},
9399 {&ps_sample, &a8_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, a8_colors},
9400 {&ps_sample, &r9g9b9e5_texture, POINT, 0.0f, 0.0f, 0.0f, 0.0f, r9g9b9e5_colors},
9401 {&ps_sample, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9402 {&ps_sample, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9403 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9404 {&ps_sample_b, &rgba_texture, POINT, 8.0f, 0.0f, MIP_MAX, 0.0f, level_1_colors},
9405 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.0f, level_1_colors},
9406 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.4f, level_1_colors},
9407 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 8.5f, level_2_colors},
9408 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, level_2_colors},
9409 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 1.0f, rgba_level_0},
9410 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 2.0f, 9.0f, level_2_colors},
9411 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 1.0f, 9.0f, level_1_colors},
9412 {&ps_sample_b, &rgba_texture, POINT, 0.0f, 0.0f, 0.0f, 9.0f, rgba_level_0},
9413 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9414 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9415 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9416 {&ps_sample_b, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
9417 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, rgba_level_0},
9418 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, rgba_level_0},
9419 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, rgba_level_0},
9420 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, level_1_colors},
9421 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, level_1_colors},
9422 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, level_1_colors},
9423 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
9424 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, level_2_colors},
9425 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, level_2_colors},
9426 {&ps_sample_l, &rgba_texture, POINT, 0.0f, 0.0f, MIP_MAX, 4.0f, level_2_colors},
9427 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 0.0f, 0.0f, MIP_MAX, 1.5f, lerp_1_2_colors},
9428 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -2.0f, rgba_level_0},
9429 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, -1.0f, level_1_colors},
9430 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 0.0f, level_2_colors},
9431 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.0f, level_2_colors},
9432 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 0.0f, MIP_MAX, 1.5f, level_2_colors},
9433 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
9434 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
9435 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
9436 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
9437 {&ps_sample_l, &rgba_texture, POINT_LINEAR, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
9438 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -9.0f, level_2_colors},
9439 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, -1.0f, level_2_colors},
9440 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 0.0f, level_2_colors},
9441 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 1.0f, level_2_colors},
9442 {&ps_sample_l, &rgba_texture, POINT, 2.0f, 2.0f, 2.0f, 9.0f, level_2_colors},
9443 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 0.0f, zero_colors},
9444 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, 0.0f, 1.0f, zero_colors},
9445 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 0.0f, zero_colors},
9446 {&ps_sample_l, NULL, POINT, 2.0f, 2.0f, MIP_MAX, 1.0f, zero_colors},
9447 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -9.0f, red_colors},
9448 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, -1.0f, red_colors},
9449 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, red_colors},
9450 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.4f, red_colors},
9451 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 0.5f, red_colors},
9452 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, green_data},
9453 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 1.4f, green_data},
9454 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, blue_colors},
9455 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 2.1f, blue_colors},
9456 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.0f, blue_colors},
9457 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 3.1f, blue_colors},
9458 {&ps_sample_2d_array, &array_2d_texture, POINT, 0.0f, 0.0f, MIP_MAX, 9.0f, blue_colors},
9459 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 0.0f, zero_colors},
9460 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 1.0f, zero_colors},
9461 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, 0.0f, 2.0f, zero_colors},
9462 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 0.0f, zero_colors},
9463 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 1.0f, zero_colors},
9464 {&ps_sample_2d_array, NULL, POINT, 0.0f, 0.0f, MIP_MAX, 2.0f, zero_colors},
9465 #undef POINT
9466 #undef POINT_LINEAR
9467 #undef MIP_MAX
9469 static const struct srv_test
9471 const struct shader *ps;
9472 const struct texture *texture;
9473 struct srv_desc srv_desc;
9474 float ps_constant;
9475 const DWORD *expected_colors;
9477 srv_tests[] =
9479 #define TEX_2D D3D11_SRV_DIMENSION_TEXTURE2D
9480 #define TEX_2D_ARRAY D3D11_SRV_DIMENSION_TEXTURE2DARRAY
9481 #define BC1_UNORM DXGI_FORMAT_BC1_UNORM
9482 #define BC1_UNORM_SRGB DXGI_FORMAT_BC1_UNORM_SRGB
9483 #define BC2_UNORM DXGI_FORMAT_BC2_UNORM
9484 #define BC2_UNORM_SRGB DXGI_FORMAT_BC2_UNORM_SRGB
9485 #define BC3_UNORM DXGI_FORMAT_BC3_UNORM
9486 #define BC3_UNORM_SRGB DXGI_FORMAT_BC3_UNORM_SRGB
9487 #define R8G8B8A8_UNORM_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
9488 #define R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
9489 #define R8G8_SNORM DXGI_FORMAT_R8G8_SNORM
9490 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
9491 #define R32_UINT DXGI_FORMAT_R32_UINT
9492 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
9493 {&ps_sample, &bc1_typeless, {BC1_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
9494 {&ps_sample, &bc1_typeless, {BC1_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
9495 {&ps_sample, &bc2_typeless, {BC2_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
9496 {&ps_sample, &bc2_typeless, {BC2_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
9497 {&ps_sample, &bc3_typeless, {BC3_UNORM, TEX_2D, 0, 1}, 0.0f, bc_colors},
9498 {&ps_sample, &bc3_typeless, {BC3_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, bc_colors},
9499 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM_SRGB, TEX_2D, 0, 1}, 0.0f, srgb_colors},
9500 {&ps_sample, &srgb_typeless, {R8G8B8A8_UNORM, TEX_2D, 0, 1}, 0.0f, srgb_data},
9501 {&ps_sample, &r32f_typeless, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
9502 {&ps_sample, &r32f_float, {R32_FLOAT, TEX_2D, 0, 1}, 0.0f, r32f_colors},
9503 {&ps_sample, &r8g8_snorm, {R8G8_SNORM, TEX_2D, 0, 1}, 0.0f, snorm_colors},
9504 {&ps_sample, &array_2d_texture, {FMT_UNKNOWN, TEX_2D, 0, 1}, 0.0f, red_colors},
9505 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 0, 1}, 0.0f, red_colors},
9506 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 1, 1}, 0.0f, green_data},
9507 {&ps_sample_2d_array, &array_2d_texture, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, 2, 1}, 0.0f, blue_colors},
9508 {&ps_ld_uint8, &r32u_typeless, {R32_UINT, TEX_2D, 0, 1}, 0.0f, r32u_colors},
9509 #undef TEX_2D
9510 #undef TEX_2D_ARRAY
9511 #undef BC1_UNORM
9512 #undef BC1_UNORM_SRGB
9513 #undef BC2_UNORM
9514 #undef BC2_UNORM_SRGB
9515 #undef BC3_UNORM
9516 #undef BC3_UNORM_SRGB
9517 #undef R8G8B8A8_UNORM_SRGB
9518 #undef R8G8B8A8_UNORM
9519 #undef R8G8_SNORM
9520 #undef R32_FLOAT
9521 #undef R32_UINT
9522 #undef FMT_UNKNOWN
9525 if (!init_test_context(&test_context, NULL))
9526 return;
9528 device = test_context.device;
9529 context = test_context.immediate_context;
9530 feature_level = ID3D11Device_GetFeatureLevel(device);
9532 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), NULL);
9534 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9536 texture_desc.SampleDesc.Count = 1;
9537 texture_desc.SampleDesc.Quality = 0;
9538 texture_desc.Usage = D3D11_USAGE_DEFAULT;
9539 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
9540 texture_desc.CPUAccessFlags = 0;
9541 texture_desc.MiscFlags = 0;
9543 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9544 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
9545 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
9546 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
9547 sampler_desc.MipLODBias = 0.0f;
9548 sampler_desc.MaxAnisotropy = 0;
9549 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
9550 sampler_desc.BorderColor[0] = 0.0f;
9551 sampler_desc.BorderColor[1] = 0.0f;
9552 sampler_desc.BorderColor[2] = 0.0f;
9553 sampler_desc.BorderColor[3] = 0.0f;
9554 sampler_desc.MinLOD = 0.0f;
9555 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
9557 ps = NULL;
9558 srv = NULL;
9559 sampler = NULL;
9560 texture = NULL;
9561 current_ps = NULL;
9562 current_texture = NULL;
9563 for (i = 0; i < ARRAY_SIZE(texture_tests); ++i)
9565 const struct texture_test *test = &texture_tests[i];
9567 if (test->texture && (test->texture->format == DXGI_FORMAT_BC7_UNORM
9568 || test->texture->format == DXGI_FORMAT_BC7_UNORM_SRGB)
9569 && feature_level < D3D_FEATURE_LEVEL_11_0)
9571 skip("Feature level >= 11.0 is required for BC7 tests.\n");
9572 continue;
9575 if (test->texture && (test->texture->format == DXGI_FORMAT_BC6H_UF16
9576 || test->texture->format == DXGI_FORMAT_BC6H_SF16)
9577 && feature_level < D3D_FEATURE_LEVEL_11_0)
9579 skip("Feature level >= 11.0 is required for BC6H tests.\n");
9580 continue;
9583 if (current_ps != test->ps)
9585 if (ps)
9586 ID3D11PixelShader_Release(ps);
9588 current_ps = test->ps;
9590 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
9591 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
9593 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9596 if (current_texture != test->texture)
9598 if (texture)
9599 ID3D11Texture2D_Release(texture);
9600 if (srv)
9601 ID3D11ShaderResourceView_Release(srv);
9603 current_texture = test->texture;
9605 if (current_texture)
9607 texture_desc.Width = current_texture->width;
9608 texture_desc.Height = current_texture->height;
9609 texture_desc.MipLevels = current_texture->miplevel_count;
9610 texture_desc.ArraySize = current_texture->array_size;
9611 texture_desc.Format = current_texture->format;
9613 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
9614 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9616 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
9617 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
9619 else
9621 texture = NULL;
9622 srv = NULL;
9625 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
9628 if (!sampler || (sampler_desc.Filter != test->filter
9629 || sampler_desc.MipLODBias != test->lod_bias
9630 || sampler_desc.MinLOD != test->min_lod
9631 || sampler_desc.MaxLOD != test->max_lod))
9633 if (sampler)
9634 ID3D11SamplerState_Release(sampler);
9636 sampler_desc.Filter = test->filter;
9637 sampler_desc.MipLODBias = test->lod_bias;
9638 sampler_desc.MinLOD = test->min_lod;
9639 sampler_desc.MaxLOD = test->max_lod;
9641 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
9642 ok(SUCCEEDED(hr), "Test %u: Failed to create sampler state, hr %#x.\n", i, hr);
9644 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9647 ps_constant.x = test->ps_constant;
9648 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
9650 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9652 draw_quad(&test_context);
9654 get_texture_readback(test_context.backbuffer, 0, &rb);
9655 for (y = 0; y < 4; ++y)
9657 for (x = 0; x < 4; ++x)
9659 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
9660 ok(compare_color(color, test->expected_colors[y * 4 + x], 2),
9661 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
9664 release_resource_readback(&rb);
9666 if (srv)
9667 ID3D11ShaderResourceView_Release(srv);
9668 ID3D11SamplerState_Release(sampler);
9669 if (texture)
9670 ID3D11Texture2D_Release(texture);
9671 ID3D11PixelShader_Release(ps);
9673 if (is_warp_device(device) && feature_level < D3D_FEATURE_LEVEL_11_0)
9675 win_skip("SRV tests are broken on WARP.\n");
9676 ID3D11Buffer_Release(cb);
9677 release_test_context(&test_context);
9678 return;
9681 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
9682 sampler_desc.MipLODBias = 0.0f;
9683 sampler_desc.MinLOD = 0.0f;
9684 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
9686 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
9687 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
9689 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
9691 ps = NULL;
9692 srv = NULL;
9693 texture = NULL;
9694 current_ps = NULL;
9695 current_texture = NULL;
9696 for (i = 0; i < ARRAY_SIZE(srv_tests); ++i)
9698 const struct srv_test *test = &srv_tests[i];
9700 if (current_ps != test->ps)
9702 if (ps)
9703 ID3D11PixelShader_Release(ps);
9705 current_ps = test->ps;
9707 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
9708 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
9710 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
9713 if (current_texture != test->texture)
9715 if (texture)
9716 ID3D11Texture2D_Release(texture);
9718 current_texture = test->texture;
9720 texture_desc.Width = current_texture->width;
9721 texture_desc.Height = current_texture->height;
9722 texture_desc.MipLevels = current_texture->miplevel_count;
9723 texture_desc.ArraySize = current_texture->array_size;
9724 texture_desc.Format = current_texture->format;
9726 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
9727 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
9730 if (srv)
9731 ID3D11ShaderResourceView_Release(srv);
9733 get_srv_desc(&srv_desc, &test->srv_desc);
9734 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
9735 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
9737 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
9739 ps_constant.x = test->ps_constant;
9740 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
9742 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
9744 draw_quad(&test_context);
9746 get_texture_readback(test_context.backbuffer, 0, &rb);
9747 for (y = 0; y < 4; ++y)
9749 for (x = 0; x < 4; ++x)
9751 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
9752 ok(compare_color(color, test->expected_colors[y * 4 + x], 1),
9753 "Test %u: Got unexpected color 0x%08x at (%u, %u).\n", i, color, x, y);
9756 release_resource_readback(&rb);
9758 ID3D11PixelShader_Release(ps);
9759 ID3D11Texture2D_Release(texture);
9760 ID3D11ShaderResourceView_Release(srv);
9761 ID3D11SamplerState_Release(sampler);
9763 ID3D11Buffer_Release(cb);
9764 release_test_context(&test_context);
9767 static void test_cube_maps(void)
9769 struct shader
9771 const DWORD *code;
9772 size_t size;
9775 unsigned int i, j, sub_resource_idx, sub_resource_count;
9776 struct d3d11_test_context test_context;
9777 D3D11_TEXTURE2D_DESC texture_desc;
9778 const struct shader *current_ps;
9779 D3D_FEATURE_LEVEL feature_level;
9780 ID3D11ShaderResourceView *srv;
9781 ID3D11DeviceContext *context;
9782 ID3D11Texture2D *rtv_texture;
9783 ID3D11RenderTargetView *rtv;
9784 struct vec4 expected_result;
9785 ID3D11Resource *texture;
9786 ID3D11PixelShader *ps;
9787 ID3D11Device *device;
9788 float data[64 * 64];
9789 ID3D11Buffer *cb;
9790 HRESULT hr;
9791 RECT rect;
9792 struct
9794 unsigned int face;
9795 unsigned int level;
9796 unsigned int cube;
9797 unsigned int padding;
9798 } constant;
9800 static const DWORD ps_cube_code[] =
9802 #if 0
9803 TextureCube t;
9804 SamplerState s;
9806 uint face;
9807 uint level;
9809 float4 main(float4 position : SV_POSITION) : SV_Target
9811 float2 p;
9812 p.x = position.x / 640.0f;
9813 p.y = position.y / 480.0f;
9815 float3 coord;
9816 switch (face)
9818 case 0:
9819 coord = float3(1.0f, p.x, p.y);
9820 break;
9821 case 1:
9822 coord = float3(-1.0f, p.x, p.y);
9823 break;
9824 case 2:
9825 coord = float3(p.x, 1.0f, p.y);
9826 break;
9827 case 3:
9828 coord = float3(p.x, -1.0f, p.y);
9829 break;
9830 case 4:
9831 coord = float3(p.x, p.y, 1.0f);
9832 break;
9833 case 5:
9834 default:
9835 coord = float3(p.x, p.y, -1.0f);
9836 break;
9838 return t.SampleLevel(s, coord, level);
9840 #endif
9841 0x43425844, 0x039aee18, 0xfd630453, 0xb884cf0f, 0x10100744, 0x00000001, 0x00000310, 0x00000003,
9842 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9843 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9844 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9845 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000274, 0x00000040,
9846 0x0000009d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000, 0x00000000,
9847 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
9848 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400004c, 0x0020800a, 0x00000000,
9849 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001,
9850 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000,
9851 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036,
9852 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106,
9853 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006,
9854 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
9855 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
9856 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000,
9857 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036,
9858 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004,
9859 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
9860 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
9861 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9862 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000,
9863 0x01000002, 0x01000017, 0x06000056, 0x00100082, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
9864 0x0b000048, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
9865 0x00000000, 0x0010003a, 0x00000000, 0x0100003e,
9867 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
9868 static const DWORD ps_cube_array_code[] =
9870 #if 0
9871 TextureCubeArray t;
9872 SamplerState s;
9874 uint face;
9875 uint level;
9876 uint cube;
9878 float4 main(float4 position : SV_POSITION) : SV_Target
9880 float2 p;
9881 p.x = position.x / 640.0f;
9882 p.y = position.y / 480.0f;
9884 float3 coord;
9885 switch (face)
9887 case 0:
9888 coord = float3(1.0f, p.x, p.y);
9889 break;
9890 case 1:
9891 coord = float3(-1.0f, p.x, p.y);
9892 break;
9893 case 2:
9894 coord = float3(p.x, 1.0f, p.y);
9895 break;
9896 case 3:
9897 coord = float3(p.x, -1.0f, p.y);
9898 break;
9899 case 4:
9900 coord = float3(p.x, p.y, 1.0f);
9901 break;
9902 case 5:
9903 default:
9904 coord = float3(p.x, p.y, -1.0f);
9905 break;
9907 return t.SampleLevel(s, float4(coord, cube), level);
9909 #endif
9910 0x43425844, 0xb8d5b94a, 0xdb4be034, 0x183aed19, 0xad4af415, 0x00000001, 0x00000328, 0x00000003,
9911 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
9912 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
9913 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
9914 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
9915 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
9916 0x00000000, 0x04005058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
9917 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x0400004c, 0x0020800a,
9918 0x00000000, 0x00000000, 0x03000006, 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000,
9919 0x00004001, 0x3f800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
9920 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001,
9921 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000,
9922 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002,
9923 0x03000006, 0x00004001, 0x00000002, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
9924 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
9925 0x00004001, 0x3f800000, 0x01000002, 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052,
9926 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000,
9927 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001,
9928 0x00000004, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
9929 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000,
9930 0x01000002, 0x0100000a, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002,
9931 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001,
9932 0xbf800000, 0x01000002, 0x01000017, 0x06000056, 0x00100032, 0x00000001, 0x00208a66, 0x00000000,
9933 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x0010000a, 0x00000001, 0x0b000048, 0x001020f2,
9934 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0010001a,
9935 0x00000001, 0x0100003e,
9937 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
9938 static const struct ps_test
9940 const struct shader *ps;
9941 unsigned int miplevel_count;
9942 unsigned int array_size;
9944 ps_tests[] =
9946 {&ps_cube, 1, 6},
9947 {&ps_cube, 2, 6},
9948 {&ps_cube, 3, 6},
9949 {&ps_cube, 0, 6},
9951 {&ps_cube_array, 1, 12},
9952 {&ps_cube_array, 2, 12},
9953 {&ps_cube_array, 3, 12},
9954 {&ps_cube_array, 0, 12},
9957 if (!init_test_context(&test_context, NULL))
9958 return;
9960 device = test_context.device;
9961 context = test_context.immediate_context;
9962 feature_level = ID3D11Device_GetFeatureLevel(device);
9964 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
9965 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
9966 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
9967 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
9968 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
9969 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
9971 memset(&constant, 0, sizeof(constant));
9972 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
9974 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
9975 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
9977 ps = NULL;
9978 current_ps = NULL;
9979 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
9981 const struct ps_test *test = &ps_tests[i];
9983 if (test->array_size / 6 > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
9985 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
9986 continue;
9989 if (current_ps != test->ps)
9991 if (ps)
9992 ID3D11PixelShader_Release(ps);
9994 current_ps = test->ps;
9996 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
9997 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
9998 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10001 if (!test->miplevel_count)
10003 srv = NULL;
10004 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10006 memset(&expected_result, 0, sizeof(expected_result));
10008 memset(&constant, 0, sizeof(constant));
10009 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10010 draw_quad(&test_context);
10011 check_texture_vec4(rtv_texture, &expected_result, 0);
10012 constant.level = 1;
10013 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10014 draw_quad(&test_context);
10015 check_texture_vec4(rtv_texture, &expected_result, 0);
10016 continue;
10019 texture_desc.Width = 64;
10020 texture_desc.Height = 64;
10021 texture_desc.MipLevels = test->miplevel_count;
10022 texture_desc.ArraySize = test->array_size;
10023 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
10024 texture_desc.SampleDesc.Count = 1;
10025 texture_desc.SampleDesc.Quality = 0;
10026 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10027 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
10028 texture_desc.CPUAccessFlags = 0;
10029 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
10030 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
10031 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
10033 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
10034 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
10035 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10037 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
10038 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
10040 for (j = 0; j < ARRAY_SIZE(data); ++j)
10041 data[j] = sub_resource_idx;
10042 ID3D11DeviceContext_UpdateSubresource(context, texture, sub_resource_idx, NULL, data,
10043 texture_desc.Width * sizeof(*data), 0);
10046 expected_result.y = expected_result.z = 0.0f;
10047 expected_result.w = 1.0f;
10048 for (sub_resource_idx = 0; sub_resource_idx < sub_resource_count; ++sub_resource_idx)
10050 constant.face = (sub_resource_idx / texture_desc.MipLevels) % 6;
10051 constant.level = sub_resource_idx % texture_desc.MipLevels;
10052 constant.cube = (sub_resource_idx / texture_desc.MipLevels) / 6;
10053 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
10055 draw_quad(&test_context);
10056 expected_result.x = sub_resource_idx;
10057 /* Avoid testing values affected by seamless cube map filtering. */
10058 SetRect(&rect, 100, 100, 540, 380);
10059 check_texture_sub_resource_vec4(rtv_texture, 0, &rect, &expected_result, 0);
10062 ID3D11Resource_Release(texture);
10063 ID3D11ShaderResourceView_Release(srv);
10065 ID3D11PixelShader_Release(ps);
10067 ID3D11Buffer_Release(cb);
10068 ID3D11RenderTargetView_Release(rtv);
10069 ID3D11Texture2D_Release(rtv_texture);
10070 release_test_context(&test_context);
10073 static void test_depth_stencil_sampling(void)
10075 ID3D11PixelShader *ps_cmp, *ps_depth, *ps_stencil, *ps_depth_stencil;
10076 ID3D11ShaderResourceView *depth_srv, *stencil_srv;
10077 ID3D11SamplerState *cmp_sampler, *sampler;
10078 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10079 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
10080 struct d3d11_test_context test_context;
10081 ID3D11Texture2D *texture, *rt_texture;
10082 D3D11_TEXTURE2D_DESC texture_desc;
10083 D3D11_SAMPLER_DESC sampler_desc;
10084 ID3D11DeviceContext *context;
10085 ID3D11DepthStencilView *dsv;
10086 ID3D11RenderTargetView *rtv;
10087 struct vec4 ps_constant;
10088 ID3D11Device *device;
10089 ID3D11Buffer *cb;
10090 unsigned int i;
10091 HRESULT hr;
10093 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
10094 static const DWORD ps_compare_code[] =
10096 #if 0
10097 Texture2D t;
10098 SamplerComparisonState s;
10100 float ref;
10102 float4 main(float4 position : SV_Position) : SV_Target
10104 return t.SampleCmp(s, float2(position.x / 640.0f, position.y / 480.0f), ref);
10106 #endif
10107 0x43425844, 0xc2e0d84e, 0x0522c395, 0x9ff41580, 0xd3ca29cc, 0x00000001, 0x00000164, 0x00000003,
10108 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10109 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10110 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10111 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000c8, 0x00000040,
10112 0x00000032, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000, 0x00000000,
10113 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
10114 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032, 0x00000000,
10115 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0c000046,
10116 0x00100012, 0x00000000, 0x00100046, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000,
10117 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000,
10118 0x0100003e,
10120 static const DWORD ps_sample_code[] =
10122 #if 0
10123 Texture2D t;
10124 SamplerState s;
10126 float4 main(float4 position : SV_Position) : SV_Target
10128 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
10130 #endif
10131 0x43425844, 0x7472c092, 0x5548f00e, 0xf4e007f1, 0x5970429c, 0x00000001, 0x00000134, 0x00000003,
10132 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10133 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10134 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10135 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
10136 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10137 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
10138 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
10139 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
10140 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
10142 static const DWORD ps_stencil_code[] =
10144 #if 0
10145 Texture2D<uint4> t;
10147 float4 main(float4 position : SV_Position) : SV_Target
10149 float2 s;
10150 t.GetDimensions(s.x, s.y);
10151 return t.Load(int3(float3(s.x * position.x / 640.0f, s.y * position.y / 480.0f, 0))).y;
10153 #endif
10154 0x43425844, 0x929fced8, 0x2cd93320, 0x0591ece3, 0xee50d04a, 0x00000001, 0x000001a0, 0x00000003,
10155 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10156 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10157 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10158 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
10159 0x00000041, 0x04001858, 0x00107000, 0x00000000, 0x00004444, 0x04002064, 0x00101032, 0x00000000,
10160 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700003d, 0x001000f2,
10161 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000,
10162 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
10163 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032,
10164 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000,
10165 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
10166 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100556, 0x00000000, 0x0100003e,
10168 static const DWORD ps_depth_stencil_code[] =
10170 #if 0
10171 SamplerState samp;
10172 Texture2D depth_tex;
10173 Texture2D<uint4> stencil_tex;
10175 float main(float4 position: SV_Position) : SV_Target
10177 float2 s, p;
10178 float depth, stencil;
10179 depth_tex.GetDimensions(s.x, s.y);
10180 p = float2(s.x * position.x / 640.0f, s.y * position.y / 480.0f);
10181 depth = depth_tex.Sample(samp, p).r;
10182 stencil = stencil_tex.Load(int3(float3(p.x, p.y, 0))).y;
10183 return depth + stencil;
10185 #endif
10186 0x43425844, 0x348f8377, 0x977d1ee0, 0x8cca4f35, 0xff5c5afc, 0x00000001, 0x000001fc, 0x00000003,
10187 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10188 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10189 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10190 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000160, 0x00000040,
10191 0x00000058, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
10192 0x04001858, 0x00107000, 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001,
10193 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000,
10194 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
10195 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000,
10196 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x0500001b, 0x00100032, 0x00000001,
10197 0x00100046, 0x00000000, 0x09000045, 0x001000f2, 0x00000000, 0x00100046, 0x00000000, 0x00107e46,
10198 0x00000000, 0x00106000, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000,
10199 0x00000000, 0x00000000, 0x00000000, 0x0700002d, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001,
10200 0x00107e46, 0x00000001, 0x05000056, 0x00100022, 0x00000000, 0x0010001a, 0x00000001, 0x07000000,
10201 0x00102012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
10203 static const struct test
10205 DXGI_FORMAT typeless_format;
10206 DXGI_FORMAT dsv_format;
10207 DXGI_FORMAT depth_view_format;
10208 DXGI_FORMAT stencil_view_format;
10210 tests[] =
10212 {DXGI_FORMAT_R32G8X24_TYPELESS, DXGI_FORMAT_D32_FLOAT_S8X24_UINT,
10213 DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS, DXGI_FORMAT_X32_TYPELESS_G8X24_UINT},
10214 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT,
10215 DXGI_FORMAT_R32_FLOAT},
10216 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT,
10217 DXGI_FORMAT_R24_UNORM_X8_TYPELESS, DXGI_FORMAT_X24_TYPELESS_G8_UINT},
10218 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_D16_UNORM,
10219 DXGI_FORMAT_R16_UNORM},
10222 if (!init_test_context(&test_context, NULL))
10223 return;
10225 device = test_context.device;
10226 context = test_context.immediate_context;
10228 if (is_amd_device(device))
10230 /* Reads from depth/stencil shader resource views return stale values on some AMD drivers. */
10231 win_skip("Some AMD drivers have a bug affecting the test.\n");
10232 release_test_context(&test_context);
10233 return;
10236 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
10237 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10238 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10239 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10240 sampler_desc.MipLODBias = 0.0f;
10241 sampler_desc.MaxAnisotropy = 0;
10242 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
10243 sampler_desc.BorderColor[0] = 0.0f;
10244 sampler_desc.BorderColor[1] = 0.0f;
10245 sampler_desc.BorderColor[2] = 0.0f;
10246 sampler_desc.BorderColor[3] = 0.0f;
10247 sampler_desc.MinLOD = 0.0f;
10248 sampler_desc.MaxLOD = 0.0f;
10249 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &cmp_sampler);
10250 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10252 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
10253 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
10254 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
10255 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10257 texture_desc.Width = 640;
10258 texture_desc.Height = 480;
10259 texture_desc.MipLevels = 1;
10260 texture_desc.ArraySize = 1;
10261 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
10262 texture_desc.SampleDesc.Count = 1;
10263 texture_desc.SampleDesc.Quality = 0;
10264 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10265 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10266 texture_desc.CPUAccessFlags = 0;
10267 texture_desc.MiscFlags = 0;
10268 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
10269 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10270 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
10271 ok(SUCCEEDED(hr), "Failed to create render target, hr %#x.\n", hr);
10272 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10274 memset(&ps_constant, 0, sizeof(ps_constant));
10275 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
10276 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10278 hr = ID3D11Device_CreatePixelShader(device, ps_compare_code, sizeof(ps_compare_code), NULL, &ps_cmp);
10279 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10280 hr = ID3D11Device_CreatePixelShader(device, ps_sample_code, sizeof(ps_sample_code), NULL, &ps_depth);
10281 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10282 hr = ID3D11Device_CreatePixelShader(device, ps_stencil_code, sizeof(ps_stencil_code), NULL, &ps_stencil);
10283 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10284 hr = ID3D11Device_CreatePixelShader(device, ps_depth_stencil_code, sizeof(ps_depth_stencil_code), NULL,
10285 &ps_depth_stencil);
10286 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10288 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10290 texture_desc.Format = tests[i].typeless_format;
10291 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
10292 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10293 ok(SUCCEEDED(hr), "Failed to create texture for format %#x, hr %#x.\n",
10294 texture_desc.Format, hr);
10296 dsv_desc.Format = tests[i].dsv_format;
10297 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
10298 dsv_desc.Flags = 0;
10299 U(dsv_desc).Texture2D.MipSlice = 0;
10300 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10301 ok(SUCCEEDED(hr), "Failed to create depth stencil view for format %#x, hr %#x.\n",
10302 dsv_desc.Format, hr);
10304 srv_desc.Format = tests[i].depth_view_format;
10305 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
10306 U(srv_desc).Texture2D.MostDetailedMip = 0;
10307 U(srv_desc).Texture2D.MipLevels = 1;
10308 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &depth_srv);
10309 ok(SUCCEEDED(hr), "Failed to create depth shader resource view for format %#x, hr %#x.\n",
10310 srv_desc.Format, hr);
10312 ID3D11DeviceContext_PSSetShader(context, ps_cmp, NULL, 0);
10313 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
10314 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &cmp_sampler);
10316 ps_constant.x = 0.5f;
10317 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10318 NULL, &ps_constant, 0, 0);
10320 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10321 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10322 draw_quad(&test_context);
10323 check_texture_float(rt_texture, 0.0f, 2);
10325 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.0f, 0);
10326 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10327 draw_quad(&test_context);
10328 check_texture_float(rt_texture, 1.0f, 2);
10330 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
10331 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10332 draw_quad(&test_context);
10333 check_texture_float(rt_texture, 0.0f, 2);
10335 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
10336 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10337 draw_quad(&test_context);
10338 check_texture_float(rt_texture, 0.0f, 2);
10340 ps_constant.x = 0.7f;
10341 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10342 NULL, &ps_constant, 0, 0);
10344 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10345 draw_quad(&test_context);
10346 check_texture_float(rt_texture, 1.0f, 2);
10348 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
10349 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10351 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10352 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10353 draw_quad(&test_context);
10354 check_texture_float(rt_texture, 1.0f, 2);
10356 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.2f, 0);
10357 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10358 draw_quad(&test_context);
10359 check_texture_float(rt_texture, 0.2f, 2);
10361 if (!tests[i].stencil_view_format)
10363 ID3D11DepthStencilView_Release(dsv);
10364 ID3D11ShaderResourceView_Release(depth_srv);
10365 ID3D11Texture2D_Release(texture);
10366 continue;
10369 srv_desc.Format = tests[i].stencil_view_format;
10370 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &stencil_srv);
10371 if (hr == E_OUTOFMEMORY)
10373 skip("Could not create SRV for format %#x.\n", srv_desc.Format);
10374 ID3D11DepthStencilView_Release(dsv);
10375 ID3D11ShaderResourceView_Release(depth_srv);
10376 ID3D11Texture2D_Release(texture);
10377 continue;
10379 ok(SUCCEEDED(hr), "Failed to create stencil shader resource view for format %#x, hr %#x.\n",
10380 srv_desc.Format, hr);
10382 ID3D11DeviceContext_PSSetShader(context, ps_stencil, NULL, 0);
10383 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &stencil_srv);
10385 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0);
10386 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10387 draw_quad(&test_context);
10388 check_texture_float(rt_texture, 0.0f, 0);
10390 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 100);
10391 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10392 draw_quad(&test_context);
10393 check_texture_float(rt_texture, 100.0f, 0);
10395 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 255);
10396 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10397 draw_quad(&test_context);
10398 check_texture_float(rt_texture, 255.0f, 0);
10400 ID3D11DeviceContext_PSSetShader(context, ps_depth_stencil, NULL, 0);
10401 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &depth_srv);
10402 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &stencil_srv);
10404 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.3f, 3);
10405 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10406 draw_quad(&test_context);
10407 check_texture_float(rt_texture, 3.3f, 2);
10409 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 3);
10410 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10411 draw_quad(&test_context);
10412 check_texture_float(rt_texture, 4.0f, 2);
10414 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
10415 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
10416 draw_quad(&test_context);
10417 check_texture_float(rt_texture, 0.0f, 2);
10419 ID3D11DepthStencilView_Release(dsv);
10420 ID3D11ShaderResourceView_Release(depth_srv);
10421 ID3D11ShaderResourceView_Release(stencil_srv);
10422 ID3D11Texture2D_Release(texture);
10425 ID3D11Buffer_Release(cb);
10426 ID3D11PixelShader_Release(ps_cmp);
10427 ID3D11PixelShader_Release(ps_depth);
10428 ID3D11PixelShader_Release(ps_depth_stencil);
10429 ID3D11PixelShader_Release(ps_stencil);
10430 ID3D11RenderTargetView_Release(rtv);
10431 ID3D11SamplerState_Release(cmp_sampler);
10432 ID3D11SamplerState_Release(sampler);
10433 ID3D11Texture2D_Release(rt_texture);
10434 release_test_context(&test_context);
10437 static void test_sample_c_lz(void)
10439 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
10440 D3D11_DEPTH_STENCIL_VIEW_DESC dsv_desc;
10441 struct d3d11_test_context test_context;
10442 ID3D11Texture2D *texture, *rt_texture;
10443 D3D11_TEXTURE2D_DESC texture_desc;
10444 D3D11_SAMPLER_DESC sampler_desc;
10445 ID3D11ShaderResourceView *srv;
10446 ID3D11DeviceContext *context;
10447 ID3D11DepthStencilView *dsv;
10448 ID3D11RenderTargetView *rtv;
10449 ID3D11SamplerState *sampler;
10450 struct vec4 ps_constant;
10451 ID3D11PixelShader *ps;
10452 ID3D11Device *device;
10453 ID3D11Buffer *cb;
10454 unsigned int i;
10455 HRESULT hr;
10456 RECT rect;
10458 static const float clear_color[] = {0.5f, 0.5f, 0.5f, 0.5f};
10459 static const DWORD ps_array_code[] =
10461 #if 0
10462 Texture2DArray t;
10463 SamplerComparisonState s;
10465 float ref;
10466 float layer;
10468 float4 main(float4 position : SV_Position) : SV_Target
10470 return t.SampleCmpLevelZero(s, float3(position.x / 640.0f, position.y / 480.0f, layer), ref);
10472 #endif
10473 0x43425844, 0xfe28b3c3, 0xdd7ef404, 0x8d5874a1, 0x984ff182, 0x00000001, 0x00000180, 0x00000003,
10474 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10475 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10476 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10477 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000e4, 0x00000041,
10478 0x00000039, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
10479 0x00000000, 0x04004058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
10480 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
10481 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
10482 0x06000036, 0x00100042, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0c000047, 0x00100012,
10483 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000, 0x00000000, 0x0020800a,
10484 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
10486 static const DWORD ps_cube_code[] =
10488 #if 0
10489 TextureCube t;
10490 SamplerComparisonState s;
10492 float ref;
10493 float face;
10495 float4 main(float4 position : SV_Position) : SV_Target
10497 float2 p;
10498 p.x = position.x / 640.0f;
10499 p.y = position.y / 480.0f;
10501 float3 coord;
10502 switch ((uint)face)
10504 case 0:
10505 coord = float3(1.0f, p.x, p.y);
10506 break;
10507 case 1:
10508 coord = float3(-1.0f, p.x, p.y);
10509 break;
10510 case 2:
10511 coord = float3(p.x, 1.0f, p.y);
10512 break;
10513 case 3:
10514 coord = float3(p.x, -1.0f, p.y);
10515 break;
10516 case 4:
10517 coord = float3(p.x, p.y, 1.0f);
10518 break;
10519 case 5:
10520 default:
10521 coord = float3(p.x, p.y, -1.0f);
10522 break;
10525 return t.SampleCmpLevelZero(s, coord, ref);
10527 #endif
10528 0x43425844, 0xde5655e5, 0x1b116fa1, 0xfce9e757, 0x41c28aac, 0x00000001, 0x00000328, 0x00000003,
10529 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10530 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
10531 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
10532 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000028c, 0x00000041,
10533 0x000000a3, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300085a, 0x00106000,
10534 0x00000000, 0x04003058, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
10535 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600001c, 0x00100012,
10536 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0300004c, 0x0010000a, 0x00000000, 0x03000006,
10537 0x00004001, 0x00000000, 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x3f800000, 0x0a000038,
10538 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x00000000, 0x3acccccd, 0x3b088889,
10539 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000001, 0x05000036, 0x00100012, 0x00000000,
10540 0x00004001, 0xbf800000, 0x0a000038, 0x00100062, 0x00000000, 0x00101106, 0x00000000, 0x00004002,
10541 0x00000000, 0x3acccccd, 0x3b088889, 0x00000000, 0x01000002, 0x03000006, 0x00004001, 0x00000002,
10542 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000, 0x00004002, 0x3acccccd, 0x00000000,
10543 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x3f800000, 0x01000002,
10544 0x03000006, 0x00004001, 0x00000003, 0x0a000038, 0x00100052, 0x00000000, 0x00101106, 0x00000000,
10545 0x00004002, 0x3acccccd, 0x00000000, 0x3b088889, 0x00000000, 0x05000036, 0x00100022, 0x00000000,
10546 0x00004001, 0xbf800000, 0x01000002, 0x03000006, 0x00004001, 0x00000004, 0x0a000038, 0x00100032,
10547 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000,
10548 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f800000, 0x01000002, 0x0100000a, 0x0a000038,
10549 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000,
10550 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0xbf800000, 0x01000002, 0x01000017,
10551 0x0c000047, 0x00100012, 0x00000000, 0x00100246, 0x00000000, 0x00107006, 0x00000000, 0x00106000,
10552 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006,
10553 0x00000000, 0x0100003e,
10555 static const float depth_values[] = {1.0f, 0.0f, 0.5f, 0.6f, 0.4f, 0.1f};
10556 static const struct
10558 unsigned int layer;
10559 float d_ref;
10560 float expected;
10562 tests[] =
10564 {0, 0.5f, 0.0f},
10565 {1, 0.5f, 1.0f},
10566 {2, 0.5f, 0.0f},
10567 {3, 0.5f, 0.0f},
10568 {4, 0.5f, 1.0f},
10569 {5, 0.5f, 1.0f},
10571 {0, 0.0f, 0.0f},
10572 {1, 0.0f, 0.0f},
10573 {2, 0.0f, 0.0f},
10574 {3, 0.0f, 0.0f},
10575 {4, 0.0f, 0.0f},
10576 {5, 0.0f, 0.0f},
10578 {0, 1.0f, 0.0f},
10579 {1, 1.0f, 1.0f},
10580 {2, 1.0f, 1.0f},
10581 {3, 1.0f, 1.0f},
10582 {4, 1.0f, 1.0f},
10583 {5, 1.0f, 1.0f},
10586 if (!init_test_context(&test_context, NULL))
10587 return;
10589 device = test_context.device;
10590 context = test_context.immediate_context;
10592 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_LINEAR;
10593 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
10594 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
10595 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
10596 sampler_desc.MipLODBias = 0.0f;
10597 sampler_desc.MaxAnisotropy = 0;
10598 sampler_desc.ComparisonFunc = D3D11_COMPARISON_GREATER;
10599 sampler_desc.BorderColor[0] = 0.0f;
10600 sampler_desc.BorderColor[1] = 0.0f;
10601 sampler_desc.BorderColor[2] = 0.0f;
10602 sampler_desc.BorderColor[3] = 0.0f;
10603 sampler_desc.MinLOD = 0.0f;
10604 sampler_desc.MaxLOD = 10.0f;
10605 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
10606 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
10608 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
10609 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
10610 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
10611 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10612 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, NULL, &rtv);
10613 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
10614 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
10616 memset(&ps_constant, 0, sizeof(ps_constant));
10617 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
10619 /* 2D array texture */
10620 texture_desc.Width = 32;
10621 texture_desc.Height = 32;
10622 texture_desc.MipLevels = 2;
10623 texture_desc.ArraySize = ARRAY_SIZE(depth_values);
10624 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
10625 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
10626 texture_desc.MiscFlags = 0;
10627 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10628 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10630 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
10632 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
10633 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
10634 dsv_desc.Flags = 0;
10635 U(dsv_desc).Texture2DArray.MipSlice = 0;
10636 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
10637 U(dsv_desc).Texture2DArray.ArraySize = 1;
10639 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10640 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10641 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
10642 ID3D11DepthStencilView_Release(dsv);
10644 U(dsv_desc).Texture2DArray.MipSlice = 1;
10645 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10646 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10647 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10648 ID3D11DepthStencilView_Release(dsv);
10651 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
10652 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
10653 U(srv_desc).Texture2DArray.MostDetailedMip = 0;
10654 U(srv_desc).Texture2DArray.MipLevels = ~0u;
10655 U(srv_desc).Texture2DArray.FirstArraySlice = 0;
10656 U(srv_desc).Texture2DArray.ArraySize = ~0u;
10657 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
10658 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10660 hr = ID3D11Device_CreatePixelShader(device, ps_array_code, sizeof(ps_array_code), NULL, &ps);
10661 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10663 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10664 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10665 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10666 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10668 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10670 ps_constant.x = tests[i].d_ref;
10671 ps_constant.y = tests[i].layer;
10672 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10673 NULL, &ps_constant, 0, 0);
10674 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
10675 draw_quad(&test_context);
10676 check_texture_float(rt_texture, tests[i].expected, 2);
10679 ID3D11Texture2D_Release(texture);
10680 ID3D11ShaderResourceView_Release(srv);
10681 ID3D11PixelShader_Release(ps);
10683 /* cube texture */
10684 texture_desc.MiscFlags = D3D11_RESOURCE_MISC_TEXTURECUBE;
10685 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
10686 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
10688 for (i = 0; i < ARRAY_SIZE(depth_values); ++i)
10690 dsv_desc.Format = DXGI_FORMAT_D32_FLOAT;
10691 dsv_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
10692 dsv_desc.Flags = 0;
10693 U(dsv_desc).Texture2DArray.MipSlice = 0;
10694 U(dsv_desc).Texture2DArray.FirstArraySlice = i;
10695 U(dsv_desc).Texture2DArray.ArraySize = 1;
10697 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10698 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10699 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, depth_values[i], 0);
10700 ID3D11DepthStencilView_Release(dsv);
10702 U(dsv_desc).Texture2DArray.MipSlice = 1;
10703 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, &dsv_desc, &dsv);
10704 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
10705 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
10706 ID3D11DepthStencilView_Release(dsv);
10709 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
10710 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;
10711 U(srv_desc).TextureCube.MostDetailedMip = 0;
10712 U(srv_desc).TextureCube.MipLevels = ~0u;
10713 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
10714 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
10716 hr = ID3D11Device_CreatePixelShader(device, ps_cube_code, sizeof(ps_cube_code), NULL, &ps);
10717 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10719 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10720 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
10721 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
10722 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
10724 for (i = 0; i < ARRAY_SIZE(tests); ++i)
10726 ps_constant.x = tests[i].d_ref;
10727 ps_constant.y = tests[i].layer;
10728 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
10729 NULL, &ps_constant, 0, 0);
10730 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
10731 draw_quad(&test_context);
10732 /* Avoid testing values affected by seamless cube map filtering. */
10733 SetRect(&rect, 100, 100, 540, 380);
10734 check_texture_sub_resource_float(rt_texture, 0, &rect, tests[i].expected, 2);
10737 ID3D11Texture2D_Release(texture);
10738 ID3D11ShaderResourceView_Release(srv);
10740 ID3D11Buffer_Release(cb);
10741 ID3D11PixelShader_Release(ps);
10742 ID3D11RenderTargetView_Release(rtv);
10743 ID3D11SamplerState_Release(sampler);
10744 ID3D11Texture2D_Release(rt_texture);
10745 release_test_context(&test_context);
10748 static void test_multiple_render_targets(void)
10750 ID3D11RenderTargetView *rtv[4], *tmp_rtv[4];
10751 D3D11_TEXTURE2D_DESC texture_desc;
10752 ID3D11InputLayout *input_layout;
10753 unsigned int stride, offset, i;
10754 ID3D11DeviceContext *context;
10755 ID3D11Texture2D *rt[4];
10756 ID3D11VertexShader *vs;
10757 ID3D11PixelShader *ps;
10758 ID3D11Device *device;
10759 ID3D11Buffer *vb;
10760 ULONG refcount;
10761 HRESULT hr;
10763 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
10765 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
10767 static const DWORD vs_code[] =
10769 #if 0
10770 float4 main(float4 position : POSITION) : SV_POSITION
10772 return position;
10774 #endif
10775 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
10776 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10777 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
10778 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
10779 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
10780 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
10781 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
10783 static const DWORD ps_code[] =
10785 #if 0
10786 struct output
10788 float4 t1 : SV_TARGET0;
10789 float4 t2 : SV_Target1;
10790 float4 t3 : SV_TARGET2;
10791 float4 t4 : SV_Target3;
10794 output main(float4 position : SV_POSITION)
10796 struct output o;
10797 o.t1 = (float4)1.0f;
10798 o.t2 = (float4)0.5f;
10799 o.t3 = (float4)0.2f;
10800 o.t4 = float4(0.0f, 0.2f, 0.5f, 1.0f);
10801 return o;
10803 #endif
10804 0x43425844, 0x8701ad18, 0xe3d5291d, 0x7b4288a6, 0x01917515, 0x00000001, 0x000001a8, 0x00000003,
10805 0x0000002c, 0x00000060, 0x000000e4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
10806 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
10807 0x4e47534f, 0x0000007c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x00000000, 0x00000003,
10808 0x00000000, 0x0000000f, 0x00000072, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
10809 0x00000068, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x00000072, 0x00000003,
10810 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x545f5653, 0x45475241, 0x56530054, 0x7261545f,
10811 0x00746567, 0x52444853, 0x000000bc, 0x00000040, 0x0000002f, 0x03000065, 0x001020f2, 0x00000000,
10812 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2,
10813 0x00000003, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
10814 0x3f800000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000,
10815 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x3e4ccccd,
10816 0x3e4ccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x00000000, 0x3e4ccccd, 0x3f000000,
10817 0x3f800000, 0x0100003e,
10819 static const struct vec2 quad[] =
10821 {-1.0f, -1.0f},
10822 {-1.0f, 1.0f},
10823 { 1.0f, -1.0f},
10824 { 1.0f, 1.0f},
10826 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
10828 if (!(device = create_device(NULL)))
10830 skip("Failed to create device.\n");
10831 return;
10834 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
10835 vs_code, sizeof(vs_code), &input_layout);
10836 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
10838 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
10840 texture_desc.Width = 640;
10841 texture_desc.Height = 480;
10842 texture_desc.MipLevels = 1;
10843 texture_desc.ArraySize = 1;
10844 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
10845 texture_desc.SampleDesc.Count = 1;
10846 texture_desc.SampleDesc.Quality = 0;
10847 texture_desc.Usage = D3D11_USAGE_DEFAULT;
10848 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
10849 texture_desc.CPUAccessFlags = 0;
10850 texture_desc.MiscFlags = 0;
10852 for (i = 0; i < ARRAY_SIZE(rt); ++i)
10854 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt[i]);
10855 ok(SUCCEEDED(hr), "Failed to create texture %u, hr %#x.\n", i, hr);
10857 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt[i], NULL, &rtv[i]);
10858 ok(SUCCEEDED(hr), "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
10861 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
10862 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
10863 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
10864 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
10866 ID3D11Device_GetImmediateContext(device, &context);
10868 ID3D11DeviceContext_OMSetRenderTargets(context, 4, rtv, NULL);
10869 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
10870 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
10871 stride = sizeof(*quad);
10872 offset = 0;
10873 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
10874 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
10875 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
10877 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
10879 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
10880 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
10881 ID3D11DeviceContext_Draw(context, 4, 0);
10882 check_texture_color(rt[0], 0xffffffff, 2);
10883 check_texture_color(rt[1], 0x7f7f7f7f, 2);
10884 check_texture_color(rt[2], 0x33333333, 2);
10885 check_texture_color(rt[3], 0xff7f3300, 2);
10887 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
10888 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[i], red);
10889 for (i = 0; i < ARRAY_SIZE(tmp_rtv); ++i)
10891 memset(tmp_rtv, 0, sizeof(tmp_rtv));
10892 tmp_rtv[i] = rtv[i];
10893 ID3D11DeviceContext_OMSetRenderTargets(context, 4, tmp_rtv, NULL);
10894 ID3D11DeviceContext_Draw(context, 4, 0);
10896 check_texture_color(rt[0], 0xffffffff, 2);
10897 check_texture_color(rt[1], 0x7f7f7f7f, 2);
10898 check_texture_color(rt[2], 0x33333333, 2);
10899 check_texture_color(rt[3], 0xff7f3300, 2);
10901 ID3D11Buffer_Release(vb);
10902 ID3D11PixelShader_Release(ps);
10903 ID3D11VertexShader_Release(vs);
10904 ID3D11InputLayout_Release(input_layout);
10905 for (i = 0; i < ARRAY_SIZE(rtv); ++i)
10907 ID3D11RenderTargetView_Release(rtv[i]);
10908 ID3D11Texture2D_Release(rt[i]);
10910 ID3D11DeviceContext_Release(context);
10911 refcount = ID3D11Device_Release(device);
10912 ok(!refcount, "Device has %u references left.\n", refcount);
10915 static void test_render_target_views(void)
10917 struct texture
10919 UINT miplevel_count;
10920 UINT array_size;
10923 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
10924 static struct test
10926 struct texture texture;
10927 struct rtv_desc rtv;
10928 DWORD expected_colors[4];
10930 tests[] =
10932 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
10933 {0xff0000ff, 0x00000000}},
10934 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 1},
10935 {0x00000000, 0xff0000ff}},
10936 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
10937 {0xff0000ff, 0x00000000}},
10938 {{2, 1}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
10939 {0x00000000, 0xff0000ff}},
10940 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
10941 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
10942 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
10943 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
10944 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
10945 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
10946 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 2, 1},
10947 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
10948 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 3, 1},
10949 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
10950 {{1, 4}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 4},
10951 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
10952 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2D, 0},
10953 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
10954 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 0, 1},
10955 {0xff0000ff, 0x00000000, 0x00000000, 0x00000000}},
10956 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 0, 1, 1},
10957 {0x00000000, 0x00000000, 0xff0000ff, 0x00000000}},
10958 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 0, 1},
10959 {0x00000000, 0xff0000ff, 0x00000000, 0x00000000}},
10960 {{2, 2}, {DXGI_FORMAT_UNKNOWN, D3D11_RTV_DIMENSION_TEXTURE2DARRAY, 1, 1, 1},
10961 {0x00000000, 0x00000000, 0x00000000, 0xff0000ff}},
10963 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
10964 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
10965 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
10966 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
10967 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
10968 #define DIM_UNKNOWN D3D11_RTV_DIMENSION_UNKNOWN
10969 #define TEX_1D D3D11_RTV_DIMENSION_TEXTURE1D
10970 #define TEX_1D_ARRAY D3D11_RTV_DIMENSION_TEXTURE1DARRAY
10971 #define TEX_2D D3D11_RTV_DIMENSION_TEXTURE2D
10972 #define TEX_2D_ARRAY D3D11_RTV_DIMENSION_TEXTURE2DARRAY
10973 #define TEX_3D D3D11_RTV_DIMENSION_TEXTURE3D
10974 static const struct
10976 struct
10978 D3D11_RTV_DIMENSION dimension;
10979 unsigned int miplevel_count;
10980 unsigned int depth_or_array_size;
10981 DXGI_FORMAT format;
10982 } texture;
10983 struct rtv_desc rtv_desc;
10985 invalid_desc_tests[] =
10987 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
10988 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
10989 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
10990 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
10991 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
10992 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
10993 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
10994 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
10995 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
10996 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
10997 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
10998 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
10999 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
11000 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
11001 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
11002 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
11003 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
11004 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11005 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11006 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
11007 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
11008 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
11009 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
11010 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
11011 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
11012 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
11013 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
11014 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
11015 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
11016 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
11017 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
11018 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
11019 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
11020 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
11021 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
11022 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
11023 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
11025 #undef FMT_UNKNOWN
11026 #undef RGBA8_UNORM
11027 #undef RGBA8_SRGB
11028 #undef RGBA8_UINT
11029 #undef RGBA8_TL
11030 #undef DIM_UNKNOWN
11031 #undef TEX_1D
11032 #undef TEX_1D_ARRAY
11033 #undef TEX_2D
11034 #undef TEX_2D_ARRAY
11035 #undef TEX_3D
11037 struct d3d11_test_context test_context;
11038 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
11039 D3D11_TEXTURE3D_DESC texture3d_desc;
11040 D3D11_TEXTURE2D_DESC texture_desc;
11041 ID3D11DeviceContext *context;
11042 ID3D11RenderTargetView *rtv;
11043 ID3D11Texture3D *texture3d;
11044 ID3D11Texture2D *texture;
11045 ID3D11Resource *resource;
11046 ID3D11Device *device;
11047 unsigned int i, j, k;
11048 void *data;
11049 HRESULT hr;
11051 if (!init_test_context(&test_context, NULL))
11052 return;
11054 device = test_context.device;
11055 context = test_context.immediate_context;
11057 texture_desc.Width = 32;
11058 texture_desc.Height = 32;
11059 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11060 texture_desc.SampleDesc.Count = 1;
11061 texture_desc.SampleDesc.Quality = 0;
11062 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11063 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11064 texture_desc.CPUAccessFlags = 0;
11065 texture_desc.MiscFlags = 0;
11067 data = heap_alloc_zero(texture_desc.Width * texture_desc.Height * 4);
11068 ok(!!data, "Failed to allocate memory.\n");
11070 for (i = 0; i < ARRAY_SIZE(tests); ++i)
11072 const struct test *test = &tests[i];
11073 unsigned int sub_resource_count;
11075 texture_desc.MipLevels = test->texture.miplevel_count;
11076 texture_desc.ArraySize = test->texture.array_size;
11078 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11079 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
11081 get_rtv_desc(&rtv_desc, &test->rtv);
11082 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11083 ok(SUCCEEDED(hr), "Test %u: Failed to create render target view, hr %#x.\n", i, hr);
11085 for (j = 0; j < texture_desc.ArraySize; ++j)
11087 for (k = 0; k < texture_desc.MipLevels; ++k)
11089 unsigned int sub_resource_idx = j * texture_desc.MipLevels + k;
11090 ID3D11DeviceContext_UpdateSubresource(context,
11091 (ID3D11Resource *)texture, sub_resource_idx, NULL, data, texture_desc.Width * 4, 0);
11094 check_texture_color(texture, 0, 0);
11096 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11097 draw_color_quad(&test_context, &red);
11099 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
11100 assert(sub_resource_count <= ARRAY_SIZE(test->expected_colors));
11101 for (j = 0; j < sub_resource_count; ++j)
11102 check_texture_sub_resource_color(texture, j, NULL, test->expected_colors[j], 1);
11104 ID3D11RenderTargetView_Release(rtv);
11105 ID3D11Texture2D_Release(texture);
11108 texture3d_desc.Width = 32;
11109 texture3d_desc.Height = 32;
11110 texture3d_desc.Depth = 32;
11111 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
11112 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
11113 texture3d_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11114 texture3d_desc.CPUAccessFlags = 0;
11115 texture3d_desc.MiscFlags = 0;
11117 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
11119 assert(invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D
11120 || invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE3D);
11122 if (invalid_desc_tests[i].texture.dimension == D3D11_RTV_DIMENSION_TEXTURE2D)
11124 texture_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
11125 texture_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
11126 texture_desc.Format = invalid_desc_tests[i].texture.format;
11127 texture_desc.MiscFlags = 0;
11129 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11130 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
11131 resource = (ID3D11Resource *)texture;
11133 else
11135 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
11136 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
11137 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
11139 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
11140 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
11141 resource = (ID3D11Resource *)texture3d;
11144 get_rtv_desc(&rtv_desc, &invalid_desc_tests[i].rtv_desc);
11145 hr = ID3D11Device_CreateRenderTargetView(device, resource, &rtv_desc, &rtv);
11146 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
11148 ID3D11Resource_Release(resource);
11151 heap_free(data);
11152 release_test_context(&test_context);
11155 static void test_layered_rendering(void)
11157 struct
11159 unsigned int layer_offset;
11160 unsigned int draw_id;
11161 unsigned int padding[2];
11162 } constant;
11163 struct d3d11_test_context test_context;
11164 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
11165 unsigned int i, sub_resource_count;
11166 D3D11_TEXTURE2D_DESC texture_desc;
11167 ID3D11DeviceContext *context;
11168 ID3D11RenderTargetView *rtv;
11169 ID3D11Texture2D *texture;
11170 ID3D11GeometryShader *gs;
11171 ID3D11VertexShader *vs;
11172 ID3D11PixelShader *ps;
11173 ID3D11Device *device;
11174 ID3D11Buffer *cb;
11175 HRESULT hr;
11176 BOOL warp;
11178 static const DWORD vs_code[] =
11180 #if 0
11181 uint layer_offset;
11183 void main(float4 position : POSITION,
11184 out float4 out_position : SV_POSITION,
11185 out uint layer : SV_RenderTargetArrayIndex)
11187 out_position = position;
11188 layer = layer_offset;
11190 #endif
11191 0x43425844, 0x71f7b9cd, 0x2ab8c713, 0x53e77663, 0x54a9ba68, 0x00000001, 0x00000158, 0x00000004,
11192 0x00000030, 0x00000064, 0x000000cc, 0x00000148, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11193 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954,
11194 0xababab00, 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
11195 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001,
11196 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567,
11197 0x79617272, 0x65646e49, 0xabab0078, 0x52444853, 0x00000074, 0x00010040, 0x0000001d, 0x04000059,
11198 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2,
11199 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x05000036, 0x001020f2,
11200 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020800a, 0x00000000,
11201 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00002000, 0x00000000,
11203 static const DWORD gs_5_code[] =
11205 #if 0
11206 uint layer_offset;
11208 struct gs_in
11210 float4 pos : SV_Position;
11213 struct gs_out
11215 float4 pos : SV_Position;
11216 uint layer : SV_RenderTargetArrayIndex;
11219 [instance(4)]
11220 [maxvertexcount(3)]
11221 void main(triangle gs_in vin[3], in uint instance_id : SV_GSInstanceID,
11222 inout TriangleStream<gs_out> vout)
11224 gs_out o;
11225 o.layer = layer_offset + instance_id;
11226 for (uint i = 0; i < 3; ++i)
11228 o.pos = vin[i].pos;
11229 vout.Append(o);
11232 #endif
11233 0x43425844, 0xb52da162, 0x9a13d8ee, 0xf7c30b50, 0xe80bc2e7, 0x00000001, 0x00000218, 0x00000003,
11234 0x0000002c, 0x00000060, 0x000000d0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11235 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
11236 0x3547534f, 0x00000068, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
11237 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000004, 0x00000001,
11238 0x00000001, 0x00000e01, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472,
11239 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x58454853, 0x00000140, 0x00020050, 0x00000050,
11240 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
11241 0x00000000, 0x00000001, 0x0200005f, 0x00025000, 0x02000068, 0x00000001, 0x020000ce, 0x00000004,
11242 0x0100185d, 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000,
11243 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x00000003, 0x0700001e,
11244 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0002500a, 0x05000036, 0x00100022,
11245 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a,
11246 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000, 0x07000036, 0x001020f2,
11247 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001,
11248 0x0010000a, 0x00000000, 0x03000075, 0x00110000, 0x00000000, 0x0700001e, 0x00100022, 0x00000000,
11249 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
11251 static const DWORD gs_4_code[] =
11253 #if 0
11254 uint layer_offset;
11256 struct gs_in
11258 float4 pos : SV_Position;
11261 struct gs_out
11263 float4 pos : SV_Position;
11264 uint layer : SV_RenderTargetArrayIndex;
11267 [maxvertexcount(12)]
11268 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
11270 gs_out o;
11271 for (uint instance_id = 0; instance_id < 4; ++instance_id)
11273 o.layer = layer_offset + instance_id;
11274 for (uint i = 0; i < 3; ++i)
11276 o.pos = vin[i].pos;
11277 vout.Append(o);
11279 vout.RestartStrip();
11282 #endif
11283 0x43425844, 0x7eabd7c5, 0x8af1468e, 0xd585cade, 0xfe0d761d, 0x00000001, 0x00000250, 0x00000003,
11284 0x0000002c, 0x00000060, 0x000000c8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11285 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
11286 0x4e47534f, 0x00000060, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
11287 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004, 0x00000001, 0x00000001, 0x00000e01,
11288 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65, 0x72615472, 0x41746567, 0x79617272,
11289 0x65646e49, 0xabab0078, 0x52444853, 0x00000180, 0x00020040, 0x00000060, 0x04000059, 0x00208e46,
11290 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068,
11291 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
11292 0x00102012, 0x00000001, 0x00000004, 0x0200005e, 0x0000000c, 0x05000036, 0x00100012, 0x00000000,
11293 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022, 0x00000000, 0x0010000a, 0x00000000,
11294 0x00004001, 0x00000004, 0x03040003, 0x0010001a, 0x00000000, 0x0800001e, 0x00100022, 0x00000000,
11295 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00100042, 0x00000000,
11296 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000,
11297 0x00004001, 0x00000003, 0x03040003, 0x0010003a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000,
11298 0x00a01e46, 0x0010002a, 0x00000000, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010001a,
11299 0x00000000, 0x01000013, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001,
11300 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
11301 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
11303 static const DWORD ps_code[] =
11305 #if 0
11306 uint layer_offset;
11307 uint draw_id;
11309 float4 main(in float4 pos : SV_Position,
11310 in uint layer : SV_RenderTargetArrayIndex) : SV_Target
11312 return float4(layer, draw_id, 0, 0);
11314 #endif
11315 0x43425844, 0x5fa6ae84, 0x3f893c81, 0xf15892d6, 0x142e2e6b, 0x00000001, 0x00000154, 0x00000003,
11316 0x0000002c, 0x00000094, 0x000000c8, 0x4e475349, 0x00000060, 0x00000002, 0x00000008, 0x00000038,
11317 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000004,
11318 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x525f5653, 0x65646e65,
11319 0x72615472, 0x41746567, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001,
11320 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
11321 0x65677261, 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46,
11322 0x00000000, 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000004, 0x03000065, 0x001020f2,
11323 0x00000000, 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022,
11324 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
11325 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
11327 static const struct vec4 expected_values[] =
11329 {0.0f, 0.0f}, {0.0f, 3.0f}, {3.0f, 11.0f}, {1.0f, 0.0f}, {1.0f, 3.0f}, {3.0f, 10.0f},
11330 {2.0f, 0.0f}, {2.0f, 3.0f}, {3.0f, 9.0f}, {4.0f, 2.0f}, {3.0f, 3.0f}, {3.0f, 8.0f},
11331 {4.0f, 1.0f}, {4.0f, 3.0f}, {3.0f, 7.0f}, {5.0f, 1.0f}, {5.0f, 3.0f}, {3.0f, 6.0f},
11332 {6.0f, 1.0f}, {6.0f, 3.0f}, {3.0f, 5.0f}, {7.0f, 1.0f}, {7.0f, 3.0f}, {3.0f, 4.0f},
11334 static const struct vec4 vs_expected_value = {1.0f, 42.0f};
11336 if (!init_test_context(&test_context, NULL))
11337 return;
11339 device = test_context.device;
11340 context = test_context.immediate_context;
11342 warp = is_warp_device(device);
11344 memset(&constant, 0, sizeof(constant));
11345 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
11346 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
11347 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
11348 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
11350 /* Geometry shader instancing seems broken on WARP. */
11351 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0 || warp)
11353 hr = ID3D11Device_CreateGeometryShader(device, gs_4_code, sizeof(gs_4_code), NULL, &gs);
11354 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
11356 else
11358 hr = ID3D11Device_CreateGeometryShader(device, gs_5_code, sizeof(gs_5_code), NULL, &gs);
11359 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
11361 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
11363 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
11364 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
11365 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
11367 texture_desc.Width = 32;
11368 texture_desc.Height = 32;
11369 texture_desc.MipLevels = 3;
11370 texture_desc.ArraySize = 8;
11371 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
11372 texture_desc.SampleDesc.Count = 1;
11373 texture_desc.SampleDesc.Quality = 0;
11374 texture_desc.Usage = D3D11_USAGE_DEFAULT;
11375 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
11376 texture_desc.CPUAccessFlags = 0;
11377 texture_desc.MiscFlags = 0;
11378 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
11379 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
11381 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
11382 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11383 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11384 constant.layer_offset = 0;
11385 constant.draw_id = 0;
11386 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11387 draw_quad(&test_context);
11388 constant.layer_offset = 4;
11389 constant.draw_id = 1;
11390 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11391 draw_quad(&test_context);
11392 ID3D11RenderTargetView_Release(rtv);
11394 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11395 rtv_desc.Format = texture_desc.Format;
11396 U(rtv_desc).Texture2DArray.MipSlice = 0;
11397 U(rtv_desc).Texture2DArray.FirstArraySlice = 3;
11398 U(rtv_desc).Texture2DArray.ArraySize = 1;
11399 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11400 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11401 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11402 constant.layer_offset = 1;
11403 constant.draw_id = 2;
11404 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11405 draw_quad(&test_context);
11406 ID3D11RenderTargetView_Release(rtv);
11408 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11409 U(rtv_desc).Texture2DArray.MipSlice = 1;
11410 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
11411 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
11412 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11413 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11414 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11415 constant.layer_offset = 0;
11416 constant.draw_id = 3;
11417 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11418 draw_quad(&test_context);
11419 constant.layer_offset = 4;
11420 constant.draw_id = 3;
11421 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11422 draw_quad(&test_context);
11423 ID3D11RenderTargetView_Release(rtv);
11425 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11426 U(rtv_desc).Texture2DArray.MipSlice = 2;
11427 U(rtv_desc).Texture2DArray.ArraySize = 1;
11428 for (i = 0; i < texture_desc.ArraySize; ++i)
11430 U(rtv_desc).Texture2DArray.FirstArraySlice = texture_desc.ArraySize - 1 - i;
11431 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11432 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
11433 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11434 constant.layer_offset = 0;
11435 constant.draw_id = 4 + i;
11436 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11437 draw_quad(&test_context);
11438 ID3D11RenderTargetView_Release(rtv);
11441 sub_resource_count = texture_desc.MipLevels * texture_desc.ArraySize;
11442 assert(ARRAY_SIZE(expected_values) == sub_resource_count);
11443 for (i = 0; i < sub_resource_count; ++i)
11445 if (warp && (i == 3 || i == 4)) /* Broken on WARP. */
11446 continue;
11447 check_texture_sub_resource_vec4(texture, i, NULL, &expected_values[i], 1);
11450 /* layered rendering without GS */
11451 if (!check_viewport_array_index_from_any_shader_support(device))
11453 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
11454 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
11455 if (SUCCEEDED(hr))
11456 ID3D11VertexShader_Release(vs);
11457 skip("Viewport array index not supported in vertex shaders.\n");
11458 goto done;
11461 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
11463 constant.layer_offset = 1;
11464 constant.draw_id = 42;
11465 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
11466 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
11467 U(rtv_desc).Texture2DArray.MipSlice = 0;
11468 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
11469 U(rtv_desc).Texture2DArray.ArraySize = ~0u;
11470 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
11471 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
11472 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
11473 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
11474 check_texture_sub_resource_vec4(texture,
11475 constant.layer_offset * texture_desc.MipLevels, NULL, &vs_expected_value, 1);
11476 ID3D11RenderTargetView_Release(rtv);
11478 done:
11479 ID3D11Texture2D_Release(texture);
11481 ID3D11Buffer_Release(cb);
11482 ID3D11GeometryShader_Release(gs);
11483 ID3D11PixelShader_Release(ps);
11484 release_test_context(&test_context);
11487 static void test_scissor(void)
11489 struct d3d11_test_context test_context;
11490 ID3D11DeviceContext *immediate_context;
11491 D3D11_RASTERIZER_DESC rs_desc;
11492 ID3D11RasterizerState *rs;
11493 D3D11_RECT scissor_rect;
11494 ID3D11Device *device;
11495 DWORD color;
11496 HRESULT hr;
11498 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
11499 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
11501 if (!init_test_context(&test_context, NULL))
11502 return;
11504 device = test_context.device;
11505 immediate_context = test_context.immediate_context;
11507 rs_desc.FillMode = D3D11_FILL_SOLID;
11508 rs_desc.CullMode = D3D11_CULL_BACK;
11509 rs_desc.FrontCounterClockwise = FALSE;
11510 rs_desc.DepthBias = 0;
11511 rs_desc.DepthBiasClamp = 0.0f;
11512 rs_desc.SlopeScaledDepthBias = 0.0f;
11513 rs_desc.DepthClipEnable = TRUE;
11514 rs_desc.ScissorEnable = TRUE;
11515 rs_desc.MultisampleEnable = FALSE;
11516 rs_desc.AntialiasedLineEnable = FALSE;
11517 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
11518 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
11520 SetRect(&scissor_rect, 160, 120, 480, 360);
11521 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
11523 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
11524 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
11526 draw_color_quad(&test_context, &green);
11527 color = get_texture_color(test_context.backbuffer, 320, 60);
11528 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11529 color = get_texture_color(test_context.backbuffer, 80, 240);
11530 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11531 color = get_texture_color(test_context.backbuffer, 320, 240);
11532 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11533 color = get_texture_color(test_context.backbuffer, 560, 240);
11534 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11535 color = get_texture_color(test_context.backbuffer, 320, 420);
11536 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11538 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
11539 ID3D11DeviceContext_RSSetState(immediate_context, rs);
11540 draw_color_quad(&test_context, &green);
11541 color = get_texture_color(test_context.backbuffer, 320, 60);
11542 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11543 color = get_texture_color(test_context.backbuffer, 80, 240);
11544 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11545 color = get_texture_color(test_context.backbuffer, 320, 240);
11546 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11547 color = get_texture_color(test_context.backbuffer, 560, 240);
11548 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11549 color = get_texture_color(test_context.backbuffer, 320, 420);
11550 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
11552 set_viewport(immediate_context, -1.0f, 0.0f, 641, 480, 0.0f, 1.0f);
11553 SetRect(&scissor_rect, -1, 0, 640, 480);
11554 ID3D11DeviceContext_RSSetScissorRects(immediate_context, 1, &scissor_rect);
11555 ID3D11DeviceContext_ClearRenderTargetView(immediate_context, test_context.backbuffer_rtv, red);
11556 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
11557 draw_color_quad(&test_context, &green);
11558 color = get_texture_color(test_context.backbuffer, 320, 60);
11559 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11560 color = get_texture_color(test_context.backbuffer, 80, 240);
11561 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11562 color = get_texture_color(test_context.backbuffer, 320, 240);
11563 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11564 color = get_texture_color(test_context.backbuffer, 560, 240);
11565 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11566 color = get_texture_color(test_context.backbuffer, 320, 420);
11567 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
11569 ID3D11RasterizerState_Release(rs);
11570 release_test_context(&test_context);
11573 static void test_clear_state(void)
11575 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
11576 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
11578 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
11580 #if 0
11581 float4 main(float4 pos : POSITION) : POSITION
11583 return pos;
11585 #endif
11586 static const DWORD simple_vs[] =
11588 0x43425844, 0x66689e7c, 0x643f0971, 0xb7f67ff4, 0xabc48688, 0x00000001, 0x000000d4, 0x00000003,
11589 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11590 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11591 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
11592 0x00000000, 0x0000000f, 0x49534f50, 0x4e4f4954, 0xababab00, 0x52444853, 0x00000038, 0x00010040,
11593 0x0000000e, 0x0300005f, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
11594 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11596 #if 0
11597 struct data
11599 float4 position : SV_Position;
11602 struct patch_constant_data
11604 float edges[3] : SV_TessFactor;
11605 float inside : SV_InsideTessFactor;
11608 void patch_constant(InputPatch<data, 3> input, out patch_constant_data output)
11610 output.edges[0] = output.edges[1] = output.edges[2] = 1.0f;
11611 output.inside = 1.0f;
11614 [domain("tri")]
11615 [outputcontrolpoints(3)]
11616 [partitioning("integer")]
11617 [outputtopology("triangle_ccw")]
11618 [patchconstantfunc("patch_constant")]
11619 data hs_main(InputPatch<data, 3> input, uint i : SV_OutputControlPointID)
11621 return input[i];
11624 [domain("tri")]
11625 void ds_main(patch_constant_data input,
11626 float3 tess_coord : SV_DomainLocation,
11627 const OutputPatch<data, 3> patch,
11628 out data output)
11630 output.position = tess_coord.x * patch[0].position
11631 + tess_coord.y * patch[1].position
11632 + tess_coord.z * patch[2].position;
11634 #endif
11635 static const DWORD simple_hs[] =
11637 0x43425844, 0x42b5df25, 0xfd8aa2b1, 0xbe5490cb, 0xb595f8b1, 0x00000001, 0x0000020c, 0x00000004,
11638 0x00000030, 0x00000064, 0x00000098, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11639 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
11640 0x006e6f69, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
11641 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x47534350, 0x0000008c,
11642 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d, 0x00000003, 0x00000000, 0x00000e01,
11643 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001, 0x00000e01, 0x00000068, 0x00000002,
11644 0x0000000d, 0x00000003, 0x00000002, 0x00000e01, 0x00000076, 0x00000000, 0x0000000e, 0x00000003,
11645 0x00000003, 0x00000e01, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469,
11646 0x46737365, 0x6f746361, 0xabab0072, 0x58454853, 0x000000d8, 0x00030050, 0x00000036, 0x01000071,
11647 0x01001893, 0x01001894, 0x01001095, 0x01000896, 0x01002097, 0x0100086a, 0x01000073, 0x02000099,
11648 0x00000003, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x00000011, 0x04000067,
11649 0x00102012, 0x00000001, 0x00000012, 0x04000067, 0x00102012, 0x00000002, 0x00000013, 0x02000068,
11650 0x00000001, 0x0400005b, 0x00102012, 0x00000000, 0x00000003, 0x04000036, 0x00100012, 0x00000000,
11651 0x0001700a, 0x06000036, 0x00902012, 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x0100003e,
11652 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x00000014, 0x05000036, 0x00102012, 0x00000003,
11653 0x00004001, 0x3f800000, 0x0100003e,
11655 static const DWORD simple_ds[] =
11657 0x43425844, 0xb7e35b82, 0x1b930ff2, 0x48d3a0f2, 0x375219ed, 0x00000001, 0x000001e0, 0x00000004,
11658 0x00000030, 0x00000064, 0x000000f8, 0x0000012c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
11659 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f,
11660 0x006e6f69, 0x47534350, 0x0000008c, 0x00000004, 0x00000008, 0x00000068, 0x00000000, 0x0000000d,
11661 0x00000003, 0x00000000, 0x00000001, 0x00000068, 0x00000001, 0x0000000d, 0x00000003, 0x00000001,
11662 0x00000001, 0x00000068, 0x00000002, 0x0000000d, 0x00000003, 0x00000002, 0x00000001, 0x00000076,
11663 0x00000000, 0x0000000e, 0x00000003, 0x00000003, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
11664 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c,
11665 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
11666 0x505f5653, 0x7469736f, 0x006e6f69, 0x58454853, 0x000000ac, 0x00040050, 0x0000002b, 0x01001893,
11667 0x01001095, 0x0100086a, 0x0200005f, 0x0001c072, 0x0400005f, 0x002190f2, 0x00000003, 0x00000000,
11668 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x07000038, 0x001000f2,
11669 0x00000000, 0x0001c556, 0x00219e46, 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000000,
11670 0x0001c006, 0x00219e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000, 0x09000032, 0x001020f2,
11671 0x00000000, 0x0001caa6, 0x00219e46, 0x00000002, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
11673 #if 0
11674 struct gs_out
11676 float4 pos : SV_POSITION;
11679 [maxvertexcount(4)]
11680 void main(point float4 vin[1] : POSITION, inout TriangleStream<gs_out> vout)
11682 float offset = 0.1 * vin[0].w;
11683 gs_out v;
11685 v.pos = float4(vin[0].x - offset, vin[0].y - offset, vin[0].z, vin[0].w);
11686 vout.Append(v);
11687 v.pos = float4(vin[0].x - offset, vin[0].y + offset, vin[0].z, vin[0].w);
11688 vout.Append(v);
11689 v.pos = float4(vin[0].x + offset, vin[0].y - offset, vin[0].z, vin[0].w);
11690 vout.Append(v);
11691 v.pos = float4(vin[0].x + offset, vin[0].y + offset, vin[0].z, vin[0].w);
11692 vout.Append(v);
11694 #endif
11695 static const DWORD simple_gs[] =
11697 0x43425844, 0x000ee786, 0xc624c269, 0x885a5cbe, 0x444b3b1f, 0x00000001, 0x0000023c, 0x00000003,
11698 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
11699 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
11700 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
11701 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000001a0, 0x00020040,
11702 0x00000068, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x02000068, 0x00000001, 0x0100085d,
11703 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
11704 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd,
11705 0x3dcccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
11706 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
11707 0x00000000, 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0e000032,
11708 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000, 0x00004002, 0x3dcccccd, 0x00000000,
11709 0x3dcccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000, 0x05000036, 0x00102022, 0x00000000,
11710 0x0010002a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000,
11711 0x01000013, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
11712 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000,
11713 0x00000000, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036,
11714 0x001020c2, 0x00000000, 0x00201ea6, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
11716 #if 0
11717 float4 main(float4 color : COLOR) : SV_TARGET
11719 return color;
11721 #endif
11722 static const DWORD simple_ps[] =
11724 0x43425844, 0x08c2b568, 0x17d33120, 0xb7d82948, 0x13a570fb, 0x00000001, 0x000000d0, 0x00000003,
11725 0x0000002c, 0x0000005c, 0x00000090, 0x4e475349, 0x00000028, 0x00000001, 0x00000008, 0x00000020,
11726 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x4f4c4f43, 0xabab0052, 0x4e47534f,
11727 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
11728 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
11729 0x03001062, 0x001010f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
11730 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
11732 #if 0
11733 [numthreads(1, 1, 1)]
11734 void main() { }
11735 #endif
11736 static const DWORD simple_cs[] =
11738 0x43425844, 0x1acc3ad0, 0x71c7b057, 0xc72c4306, 0xf432cb57, 0x00000001, 0x00000074, 0x00000003,
11739 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
11740 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000020, 0x00050050, 0x00000008, 0x0100086a,
11741 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x0100003e,
11744 D3D11_VIEWPORT tmp_viewport[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
11745 ID3D11ShaderResourceView *tmp_srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
11746 ID3D11ShaderResourceView *srv[D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT];
11747 ID3D11RenderTargetView *tmp_rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11748 RECT tmp_rect[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE];
11749 ID3D11SamplerState *tmp_sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
11750 ID3D11RenderTargetView *rtv[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11751 ID3D11Texture2D *rt_texture[D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT];
11752 ID3D11Buffer *cb[D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT];
11753 ID3D11Buffer *tmp_buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11754 ID3D11SamplerState *sampler[D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT];
11755 ID3D11UnorderedAccessView *tmp_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
11756 ID3D11UnorderedAccessView *cs_uav[D3D11_PS_CS_UAV_REGISTER_COUNT];
11757 ID3D11Buffer *buffer[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11758 ID3D11Buffer *cs_uav_buffer[D3D11_PS_CS_UAV_REGISTER_COUNT];
11759 UINT offset[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11760 UINT stride[D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT];
11761 ID3D11Buffer *so_buffer[D3D11_SO_BUFFER_SLOT_COUNT];
11762 ID3D11InputLayout *tmp_input_layout, *input_layout;
11763 ID3D11DepthStencilState *tmp_ds_state, *ds_state;
11764 ID3D11BlendState *tmp_blend_state, *blend_state;
11765 ID3D11RasterizerState *tmp_rs_state, *rs_state;
11766 ID3D11Predicate *tmp_predicate, *predicate;
11767 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
11768 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
11769 ID3D11DepthStencilView *tmp_dsv, *dsv;
11770 ID3D11UnorderedAccessView *ps_uav;
11771 D3D11_PRIMITIVE_TOPOLOGY topology;
11772 D3D11_TEXTURE2D_DESC texture_desc;
11773 ID3D11GeometryShader *tmp_gs, *gs;
11774 ID3D11ComputeShader *tmp_cs, *cs;
11775 D3D11_DEPTH_STENCIL_DESC ds_desc;
11776 ID3D11VertexShader *tmp_vs, *vs;
11777 ID3D11DomainShader *tmp_ds, *ds;
11778 D3D11_SAMPLER_DESC sampler_desc;
11779 D3D11_QUERY_DESC predicate_desc;
11780 struct device_desc device_desc;
11781 ID3D11PixelShader *tmp_ps, *ps;
11782 ID3D11HullShader *tmp_hs, *hs;
11783 D3D11_RASTERIZER_DESC rs_desc;
11784 ID3D11DeviceContext *context;
11785 D3D11_BLEND_DESC blend_desc;
11786 ID3D11Texture2D *ds_texture;
11787 ID3D11Buffer *ps_uav_buffer;
11788 float blend_factor[4];
11789 ID3D11Device *device;
11790 BOOL predicate_value;
11791 UINT instance_count;
11792 DXGI_FORMAT format;
11793 UINT sample_mask;
11794 UINT stencil_ref;
11795 ULONG refcount;
11796 UINT count, i;
11797 HRESULT hr;
11799 device_desc.feature_level = &feature_level;
11800 device_desc.flags = 0;
11801 if (!(device = create_device(&device_desc)))
11803 skip("Failed to create device.\n");
11804 return;
11807 ID3D11Device_GetImmediateContext(device, &context);
11809 /* Verify the initial state after device creation. */
11811 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11812 tmp_buffer);
11813 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11815 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11817 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11818 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11820 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11822 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11823 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11825 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11827 instance_count = 100;
11828 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, &instance_count);
11829 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
11830 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11832 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11833 tmp_buffer);
11834 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11836 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11838 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11839 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11841 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11843 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11844 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11846 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11848 instance_count = 100;
11849 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, &instance_count);
11850 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
11851 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11853 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11854 tmp_buffer);
11855 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11857 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11859 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11860 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11862 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11864 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11865 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11867 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11869 instance_count = 100;
11870 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, &instance_count);
11871 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
11872 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11874 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11875 tmp_buffer);
11876 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11878 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11880 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
11881 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11883 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11885 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11886 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11888 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11890 instance_count = 100;
11891 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, &instance_count);
11892 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
11893 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11895 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
11896 tmp_buffer);
11897 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
11899 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
11901 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
11902 tmp_srv);
11903 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11905 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11907 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11908 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11910 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11912 instance_count = 100;
11913 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, &instance_count);
11914 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
11915 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11917 ID3D11DeviceContext_CSGetConstantBuffers(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_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
11924 tmp_srv);
11925 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
11927 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
11929 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
11930 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
11932 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
11934 instance_count = 100;
11935 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, &instance_count);
11936 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
11937 ok(!instance_count, "Got unexpected instance count %u.\n", instance_count);
11938 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
11939 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
11941 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
11944 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
11945 tmp_buffer, stride, offset);
11946 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
11948 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
11949 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
11950 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
11952 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
11953 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
11954 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
11955 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
11956 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
11957 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
11958 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
11959 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
11961 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
11962 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
11963 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
11964 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
11965 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
11966 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
11967 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
11968 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
11969 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
11970 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
11971 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
11972 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
11974 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
11976 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
11977 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
11978 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
11979 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
11980 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
11982 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
11984 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
11985 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
11987 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
11990 if (!enable_debug_layer)
11992 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
11993 ok(!count, "Got unexpected scissor rect count %u.\n", count);
11995 memset(tmp_rect, 0x55, sizeof(tmp_rect));
11996 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
11997 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
11998 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12000 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
12001 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
12003 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12004 ok(!count, "Got unexpected viewport count %u.\n", count);
12005 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12006 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12007 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12008 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12010 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
12011 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
12012 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12013 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12014 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12016 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12017 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
12019 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12020 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12022 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
12025 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12026 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
12027 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12029 /* Create resources. */
12031 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12032 cb[i] = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 1024, NULL);
12034 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12036 buffer[i] = create_buffer(device,
12037 D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_INDEX_BUFFER | D3D11_BIND_SHADER_RESOURCE,
12038 1024, NULL);
12040 stride[i] = (i + 1) * 4;
12041 offset[i] = (i + 1) * 16;
12044 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12045 so_buffer[i] = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
12047 srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
12048 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
12049 U(srv_desc).Buffer.ElementOffset = 0;
12050 U(srv_desc).Buffer.ElementWidth = 64;
12052 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12054 hr = ID3D11Device_CreateShaderResourceView(device,
12055 (ID3D11Resource *)buffer[i % D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT], &srv_desc, &srv[i]);
12056 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
12059 uav_desc.Format = DXGI_FORMAT_R32_UINT;
12060 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
12061 U(uav_desc).Buffer.FirstElement = 0;
12062 U(uav_desc).Buffer.NumElements = 8;
12063 U(uav_desc).Buffer.Flags = 0;
12065 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12067 cs_uav_buffer[i] = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
12068 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_uav_buffer[i],
12069 &uav_desc, &cs_uav[i]);
12070 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12073 ps_uav_buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 32, NULL);
12074 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_uav_buffer,
12075 &uav_desc, &ps_uav);
12076 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
12078 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
12079 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
12080 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
12081 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
12082 sampler_desc.MipLODBias = 0.0f;
12083 sampler_desc.MaxAnisotropy = 16;
12084 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
12085 sampler_desc.BorderColor[0] = 0.0f;
12086 sampler_desc.BorderColor[1] = 0.0f;
12087 sampler_desc.BorderColor[2] = 0.0f;
12088 sampler_desc.BorderColor[3] = 0.0f;
12089 sampler_desc.MinLOD = 0.0f;
12090 sampler_desc.MaxLOD = 16.0f;
12092 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12094 sampler_desc.MinLOD = (float)i;
12096 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler[i]);
12097 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
12100 hr = ID3D11Device_CreateVertexShader(device, simple_vs, sizeof(simple_vs), NULL, &vs);
12101 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12103 hr = ID3D11Device_CreateHullShader(device, simple_hs, sizeof(simple_hs), NULL, &hs);
12104 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
12106 hr = ID3D11Device_CreateDomainShader(device, simple_ds, sizeof(simple_ds), NULL, &ds);
12107 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
12109 hr = ID3D11Device_CreateGeometryShader(device, simple_gs, sizeof(simple_gs), NULL, &gs);
12110 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
12112 hr = ID3D11Device_CreatePixelShader(device, simple_ps, sizeof(simple_ps), NULL, &ps);
12113 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12115 hr = ID3D11Device_CreateComputeShader(device, simple_cs, sizeof(simple_cs), NULL, &cs);
12116 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
12118 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12119 simple_vs, sizeof(simple_vs), &input_layout);
12120 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12122 memset(&blend_desc, 0, sizeof(blend_desc));
12123 blend_desc.AlphaToCoverageEnable = FALSE;
12124 blend_desc.IndependentBlendEnable = FALSE;
12125 blend_desc.RenderTarget[0].BlendEnable = TRUE;
12126 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
12127 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
12128 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
12129 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
12130 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
12131 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
12132 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
12134 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
12135 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
12137 ds_desc.DepthEnable = TRUE;
12138 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
12139 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
12140 ds_desc.StencilEnable = FALSE;
12141 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
12142 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
12143 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
12144 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
12145 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
12146 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
12147 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_KEEP;
12148 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_KEEP;
12149 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
12150 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
12152 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
12153 ok(SUCCEEDED(hr), "Failed to create depthstencil state, hr %#x.\n", hr);
12155 texture_desc.Width = 512;
12156 texture_desc.Height = 512;
12157 texture_desc.MipLevels = 1;
12158 texture_desc.ArraySize = 1;
12159 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
12160 texture_desc.SampleDesc.Count = 1;
12161 texture_desc.SampleDesc.Quality = 0;
12162 texture_desc.Usage = D3D11_USAGE_DEFAULT;
12163 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
12164 texture_desc.CPUAccessFlags = 0;
12165 texture_desc.MiscFlags = 0;
12167 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12169 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture[i]);
12170 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12173 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
12174 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
12176 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ds_texture);
12177 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
12179 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12181 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture[i], NULL, &rtv[i]);
12182 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
12185 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)ds_texture, NULL, &dsv);
12186 ok(SUCCEEDED(hr), "Failed to create depthstencil view, hr %#x.\n", hr);
12188 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12190 SetRect(&tmp_rect[i], i, i * 2, i + 1, (i + 1) * 2);
12192 tmp_viewport[i].TopLeftX = i * 3;
12193 tmp_viewport[i].TopLeftY = i * 4;
12194 tmp_viewport[i].Width = 3;
12195 tmp_viewport[i].Height = 4;
12196 tmp_viewport[i].MinDepth = i * 0.01f;
12197 tmp_viewport[i].MaxDepth = (i + 1) * 0.01f;
12200 rs_desc.FillMode = D3D11_FILL_SOLID;
12201 rs_desc.CullMode = D3D11_CULL_BACK;
12202 rs_desc.FrontCounterClockwise = FALSE;
12203 rs_desc.DepthBias = 0;
12204 rs_desc.DepthBiasClamp = 0.0f;
12205 rs_desc.SlopeScaledDepthBias = 0.0f;
12206 rs_desc.DepthClipEnable = TRUE;
12207 rs_desc.ScissorEnable = FALSE;
12208 rs_desc.MultisampleEnable = FALSE;
12209 rs_desc.AntialiasedLineEnable = FALSE;
12211 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs_state);
12212 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
12214 predicate_desc.Query = D3D11_QUERY_OCCLUSION_PREDICATE;
12215 predicate_desc.MiscFlags = 0;
12217 hr = ID3D11Device_CreatePredicate(device, &predicate_desc, &predicate);
12218 ok(SUCCEEDED(hr), "Failed to create predicate, hr %#x.\n", hr);
12220 /* Setup state. */
12222 /* Some versions of Windows AMD drivers hang while the device is being
12223 * released, if the total number of used resource slots exceeds some limit.
12224 * Do not use all constant buffers slots in order to not trigger this
12225 * driver bug. */
12226 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb[0]);
12227 ID3D11DeviceContext_VSSetConstantBuffers(context, 7, 1, &cb[7]);
12228 ID3D11DeviceContext_VSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12229 ID3D11DeviceContext_VSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12230 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
12232 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb[0]);
12233 ID3D11DeviceContext_HSSetConstantBuffers(context, 7, 1, &cb[7]);
12234 ID3D11DeviceContext_HSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12235 ID3D11DeviceContext_HSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12236 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
12238 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12239 ID3D11DeviceContext_DSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12240 ID3D11DeviceContext_DSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12241 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
12243 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12244 ID3D11DeviceContext_GSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12245 ID3D11DeviceContext_GSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12246 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
12248 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12249 ID3D11DeviceContext_PSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12250 ID3D11DeviceContext_PSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12251 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
12253 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT, cb);
12254 ID3D11DeviceContext_CSSetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, srv);
12255 ID3D11DeviceContext_CSSetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, sampler);
12256 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
12257 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, cs_uav, NULL);
12259 ID3D11DeviceContext_IASetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12260 buffer, stride, offset);
12261 ID3D11DeviceContext_IASetIndexBuffer(context, buffer[0], DXGI_FORMAT_R32_UINT, offset[0]);
12262 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12263 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12265 blend_factor[0] = 0.1f;
12266 blend_factor[1] = 0.2f;
12267 blend_factor[2] = 0.3f;
12268 blend_factor[3] = 0.4f;
12269 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, 0xff00ff00);
12270 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 3);
12271 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
12272 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, rtv, dsv,
12273 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1, 1, &ps_uav, NULL);
12275 ID3D11DeviceContext_RSSetScissorRects(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12276 tmp_rect);
12277 ID3D11DeviceContext_RSSetViewports(context, D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12278 tmp_viewport);
12279 ID3D11DeviceContext_RSSetState(context, rs_state);
12281 ID3D11DeviceContext_SOSetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, so_buffer, offset);
12283 ID3D11DeviceContext_SetPredication(context, predicate, TRUE);
12285 /* Verify the set state. */
12287 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12288 tmp_buffer);
12289 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12291 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
12292 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12293 tmp_buffer[i], i, expected_cb);
12294 if (tmp_buffer[i])
12295 ID3D11Buffer_Release(tmp_buffer[i]);
12297 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12298 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12300 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12301 tmp_srv[i], i, srv[i]);
12302 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12304 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12305 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12307 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12308 tmp_sampler[i], i, sampler[i]);
12309 ID3D11SamplerState_Release(tmp_sampler[i]);
12311 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
12312 ok(tmp_vs == vs, "Got unexpected vertex shader %p, expected %p.\n", tmp_vs, vs);
12313 ID3D11VertexShader_Release(tmp_vs);
12315 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12316 tmp_buffer);
12317 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12319 ID3D11Buffer *expected_cb = i % 7 ? NULL : cb[i];
12320 ok(tmp_buffer[i] == expected_cb, "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12321 tmp_buffer[i], i, expected_cb);
12322 if (tmp_buffer[i])
12323 ID3D11Buffer_Release(tmp_buffer[i]);
12325 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12326 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12328 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12329 tmp_srv[i], i, srv[i]);
12330 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12332 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12333 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12335 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12336 tmp_sampler[i], i, sampler[i]);
12337 ID3D11SamplerState_Release(tmp_sampler[i]);
12339 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
12340 ok(tmp_hs == hs, "Got unexpected hull shader %p, expected %p.\n", tmp_hs, hs);
12341 ID3D11HullShader_Release(tmp_hs);
12343 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12344 tmp_buffer);
12345 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12347 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12348 tmp_buffer[i], i, cb[i]);
12349 ID3D11Buffer_Release(tmp_buffer[i]);
12351 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12352 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12354 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12355 tmp_srv[i], i, srv[i]);
12356 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12358 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12359 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12361 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12362 tmp_sampler[i], i, sampler[i]);
12363 ID3D11SamplerState_Release(tmp_sampler[i]);
12365 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
12366 ok(tmp_ds == ds, "Got unexpected domain shader %p, expected %p.\n", tmp_ds, ds);
12367 ID3D11DomainShader_Release(tmp_ds);
12369 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12370 tmp_buffer);
12371 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12373 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12374 tmp_buffer[i], i, cb[i]);
12375 ID3D11Buffer_Release(tmp_buffer[i]);
12377 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12378 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12380 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12381 tmp_srv[i], i, srv[i]);
12382 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12384 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12385 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12387 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12388 tmp_sampler[i], i, sampler[i]);
12389 ID3D11SamplerState_Release(tmp_sampler[i]);
12391 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
12392 ok(tmp_gs == gs, "Got unexpected geometry shader %p, expected %p.\n", tmp_gs, gs);
12393 ID3D11GeometryShader_Release(tmp_gs);
12395 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12396 tmp_buffer);
12397 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12399 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12400 tmp_buffer[i], i, cb[i]);
12401 ID3D11Buffer_Release(tmp_buffer[i]);
12403 ID3D11DeviceContext_PSGetShaderResources(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_PSGetSamplers(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_PSGetShader(context, &tmp_ps, NULL, 0);
12418 ok(tmp_ps == ps, "Got unexpected pixel shader %p, expected %p.\n", tmp_ps, ps);
12419 ID3D11PixelShader_Release(tmp_ps);
12421 ID3D11DeviceContext_CSGetConstantBuffers(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 ok(tmp_buffer[i] == cb[i], "Got unexpected constant buffer %p in slot %u, expected %p.\n",
12426 tmp_buffer[i], i, cb[i]);
12427 ID3D11Buffer_Release(tmp_buffer[i]);
12429 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12430 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12432 ok(tmp_srv[i] == srv[i], "Got unexpected shader resource view %p in slot %u, expected %p.\n",
12433 tmp_srv[i], i, srv[i]);
12434 ID3D11ShaderResourceView_Release(tmp_srv[i]);
12436 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12437 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12439 ok(tmp_sampler[i] == sampler[i], "Got unexpected sampler %p in slot %u, expected %p.\n",
12440 tmp_sampler[i], i, sampler[i]);
12441 ID3D11SamplerState_Release(tmp_sampler[i]);
12443 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
12444 ok(tmp_cs == cs, "Got unexpected compute shader %p, expected %p.\n", tmp_cs, cs);
12445 ID3D11ComputeShader_Release(tmp_cs);
12446 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12447 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12449 ok(tmp_uav[i] == cs_uav[i], "Got unexpected unordered access view %p in slot %u, expected %p.\n",
12450 tmp_uav[i], i, cs_uav[i]);
12451 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
12454 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12455 tmp_buffer, stride, offset);
12456 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12458 todo_wine_if(i >= D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT)
12460 ok(tmp_buffer[i] == buffer[i], "Got unexpected vertex buffer %p in slot %u, expected %p.\n",
12461 tmp_buffer[i], i, buffer[i]);
12462 ok(stride[i] == (i + 1) * 4, "Got unexpected stride %u in slot %u.\n", stride[i], i);
12463 ok(offset[i] == (i + 1) * 16, "Got unexpected offset %u in slot %u.\n", offset[i], i);
12465 if (tmp_buffer[i])
12466 ID3D11Buffer_Release(tmp_buffer[i]);
12468 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
12469 ok(tmp_buffer[0] == buffer[0], "Got unexpected index buffer %p, expected %p.\n", tmp_buffer[0], buffer[0]);
12470 ID3D11Buffer_Release(tmp_buffer[0]);
12471 ok(format == DXGI_FORMAT_R32_UINT, "Got unexpected index buffer format %#x.\n", format);
12472 ok(offset[0] == 16, "Got unexpected index buffer offset %u.\n", offset[0]);
12473 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
12474 ok(tmp_input_layout == input_layout, "Got unexpected input layout %p, expected %p.\n",
12475 tmp_input_layout, input_layout);
12476 ID3D11InputLayout_Release(tmp_input_layout);
12477 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
12478 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, "Got unexpected primitive topology %#x.\n", topology);
12480 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
12481 ok(tmp_blend_state == blend_state, "Got unexpected blend state %p, expected %p.\n", tmp_blend_state, blend_state);
12482 ID3D11BlendState_Release(tmp_blend_state);
12483 ok(blend_factor[0] == 0.1f && blend_factor[1] == 0.2f
12484 && blend_factor[2] == 0.3f && blend_factor[3] == 0.4f,
12485 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12486 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12487 ok(sample_mask == 0xff00ff00, "Got unexpected sample mask %#x.\n", sample_mask);
12488 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
12489 ok(tmp_ds_state == ds_state, "Got unexpected depth stencil state %p, expected %p.\n", tmp_ds_state, ds_state);
12490 ID3D11DepthStencilState_Release(tmp_ds_state);
12491 ok(stencil_ref == 3, "Got unexpected stencil ref %u.\n", stencil_ref);
12492 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
12493 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
12495 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
12496 tmp_rtv[i], i, rtv[i]);
12497 ID3D11RenderTargetView_Release(tmp_rtv[i]);
12499 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12500 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
12501 ID3D11DepthStencilView_Release(tmp_dsv);
12502 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
12503 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
12504 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12505 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT - 1; ++i)
12507 ok(tmp_rtv[i] == rtv[i], "Got unexpected render target view %p in slot %u, expected %p.\n",
12508 tmp_rtv[i], i, rtv[i]);
12509 ID3D11RenderTargetView_Release(tmp_rtv[i]);
12511 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12512 ok(tmp_dsv == dsv, "Got unexpected depth stencil view %p, expected %p.\n", tmp_dsv, dsv);
12513 ID3D11DepthStencilView_Release(tmp_dsv);
12514 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT - 1; ++i)
12516 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12518 ok(tmp_uav[i] == ps_uav, "Got unexpected unordered access view %p in slot %u, expected %p.\n",
12519 tmp_uav[i], i, ps_uav);
12520 ID3D11UnorderedAccessView_Release(tmp_uav[i]);
12522 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
12523 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12524 "Got unexpected scissor rect count %u.\n", count);
12525 memset(tmp_rect, 0x55, sizeof(tmp_rect));
12526 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
12527 for (i = 0; i < count; ++i)
12529 ok(tmp_rect[i].left == i
12530 && tmp_rect[i].top == i * 2
12531 && tmp_rect[i].right == i + 1
12532 && tmp_rect[i].bottom == (i + 1) * 2,
12533 "Got unexpected scissor rect %s in slot %u.\n", wine_dbgstr_rect(&tmp_rect[i]), i);
12535 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12536 ok(count == D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE,
12537 "Got unexpected viewport count %u.\n", count);
12538 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12539 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12540 for (i = 0; i < count; ++i)
12542 ok(tmp_viewport[i].TopLeftX == i * 3
12543 && tmp_viewport[i].TopLeftY == i * 4
12544 && tmp_viewport[i].Width == 3
12545 && tmp_viewport[i].Height == 4
12546 && compare_float(tmp_viewport[i].MinDepth, i * 0.01f, 16)
12547 && compare_float(tmp_viewport[i].MaxDepth, (i + 1) * 0.01f, 16),
12548 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12549 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12550 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12552 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12553 ok(tmp_rs_state == rs_state, "Got unexpected rasterizer state %p, expected %p.\n", tmp_rs_state, rs_state);
12554 ID3D11RasterizerState_Release(tmp_rs_state);
12556 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12557 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12559 ok(tmp_buffer[i] == so_buffer[i], "Got unexpected stream output %p in slot %u, expected %p.\n",
12560 tmp_buffer[i], i, so_buffer[i]);
12561 ID3D11Buffer_Release(tmp_buffer[i]);
12564 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12565 ok(tmp_predicate == predicate, "Got unexpected predicate %p, expected %p.\n", tmp_predicate, predicate);
12566 ID3D11Predicate_Release(tmp_predicate);
12567 ok(predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12569 /* Verify ClearState(). */
12571 ID3D11DeviceContext_ClearState(context);
12573 ID3D11DeviceContext_VSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12574 tmp_buffer);
12575 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12577 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12579 ID3D11DeviceContext_VSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12580 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12582 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12584 ID3D11DeviceContext_VSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12585 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12587 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12589 ID3D11DeviceContext_VSGetShader(context, &tmp_vs, NULL, 0);
12590 ok(!tmp_vs, "Got unexpected vertex shader %p.\n", tmp_vs);
12592 ID3D11DeviceContext_HSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12593 tmp_buffer);
12594 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12596 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12598 ID3D11DeviceContext_HSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12599 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12601 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12603 ID3D11DeviceContext_HSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12604 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12606 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12608 ID3D11DeviceContext_HSGetShader(context, &tmp_hs, NULL, 0);
12609 ok(!tmp_hs, "Got unexpected hull shader %p.\n", tmp_hs);
12611 ID3D11DeviceContext_DSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12612 tmp_buffer);
12613 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12615 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12617 ID3D11DeviceContext_DSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12618 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12620 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12622 ID3D11DeviceContext_DSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12623 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12625 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12627 ID3D11DeviceContext_DSGetShader(context, &tmp_ds, NULL, 0);
12628 ok(!tmp_ds, "Got unexpected domain shader %p.\n", tmp_ds);
12630 ID3D11DeviceContext_GSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12631 tmp_buffer);
12632 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12634 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12636 ID3D11DeviceContext_GSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12637 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12639 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12641 ID3D11DeviceContext_GSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12642 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12644 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12646 ID3D11DeviceContext_GSGetShader(context, &tmp_gs, NULL, 0);
12647 ok(!tmp_gs, "Got unexpected geometry shader %p.\n", tmp_gs);
12649 ID3D11DeviceContext_PSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12650 tmp_buffer);
12651 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12653 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12655 ID3D11DeviceContext_PSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT, tmp_srv);
12656 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12658 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12660 ID3D11DeviceContext_PSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12661 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12663 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12665 ID3D11DeviceContext_PSGetShader(context, &tmp_ps, NULL, 0);
12666 ok(!tmp_ps, "Got unexpected pixel shader %p.\n", tmp_ps);
12668 ID3D11DeviceContext_CSGetConstantBuffers(context, 0, D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT,
12669 tmp_buffer);
12670 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12672 ok(!tmp_buffer[i], "Got unexpected constant buffer %p in slot %u.\n", tmp_buffer[i], i);
12674 ID3D11DeviceContext_CSGetShaderResources(context, 0, D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT,
12675 tmp_srv);
12676 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12678 ok(!tmp_srv[i], "Got unexpected shader resource view %p in slot %u.\n", tmp_srv[i], i);
12680 ID3D11DeviceContext_CSGetSamplers(context, 0, D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT, tmp_sampler);
12681 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12683 ok(!tmp_sampler[i], "Got unexpected sampler %p in slot %u.\n", tmp_sampler[i], i);
12685 ID3D11DeviceContext_CSGetShader(context, &tmp_cs, NULL, 0);
12686 ok(!tmp_cs, "Got unexpected compute shader %p.\n", tmp_cs);
12687 ID3D11DeviceContext_CSGetUnorderedAccessViews(context, 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12688 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12690 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12693 ID3D11DeviceContext_IAGetVertexBuffers(context, 0, D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT,
12694 tmp_buffer, stride, offset);
12695 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12697 ok(!tmp_buffer[i], "Got unexpected vertex buffer %p in slot %u.\n", tmp_buffer[i], i);
12698 ok(!stride[i], "Got unexpected stride %u in slot %u.\n", stride[i], i);
12699 ok(!offset[i], "Got unexpected offset %u in slot %u.\n", offset[i], i);
12701 ID3D11DeviceContext_IAGetIndexBuffer(context, tmp_buffer, &format, offset);
12702 ok(!tmp_buffer[0], "Got unexpected index buffer %p.\n", tmp_buffer[0]);
12703 ok(format == DXGI_FORMAT_UNKNOWN, "Got unexpected index buffer format %#x.\n", format);
12704 ok(!offset[0], "Got unexpected index buffer offset %u.\n", offset[0]);
12705 ID3D11DeviceContext_IAGetInputLayout(context, &tmp_input_layout);
12706 ok(!tmp_input_layout, "Got unexpected input layout %p.\n", tmp_input_layout);
12707 ID3D11DeviceContext_IAGetPrimitiveTopology(context, &topology);
12708 ok(topology == D3D11_PRIMITIVE_TOPOLOGY_UNDEFINED, "Got unexpected primitive topology %#x.\n", topology);
12710 ID3D11DeviceContext_OMGetBlendState(context, &tmp_blend_state, blend_factor, &sample_mask);
12711 ok(!tmp_blend_state, "Got unexpected blend state %p.\n", tmp_blend_state);
12712 ok(blend_factor[0] == 1.0f && blend_factor[1] == 1.0f
12713 && blend_factor[2] == 1.0f && blend_factor[3] == 1.0f,
12714 "Got unexpected blend factor {%.8e, %.8e, %.8e, %.8e}.\n",
12715 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
12716 ok(sample_mask == D3D11_DEFAULT_SAMPLE_MASK, "Got unexpected sample mask %#x.\n", sample_mask);
12717 ID3D11DeviceContext_OMGetDepthStencilState(context, &tmp_ds_state, &stencil_ref);
12718 ok(!tmp_ds_state, "Got unexpected depth stencil state %p.\n", tmp_ds_state);
12719 ok(!stencil_ref, "Got unexpected stencil ref %u.\n", stencil_ref);
12720 ID3D11DeviceContext_OMGetRenderTargets(context, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv);
12721 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12723 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12725 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12726 ID3D11DeviceContext_OMGetRenderTargetsAndUnorderedAccessViews(context,
12727 D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT, tmp_rtv, &tmp_dsv,
12728 0, D3D11_PS_CS_UAV_REGISTER_COUNT, tmp_uav);
12729 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12731 ok(!tmp_rtv[i], "Got unexpected render target view %p in slot %u.\n", tmp_rtv[i], i);
12733 ok(!tmp_dsv, "Got unexpected depth stencil view %p.\n", tmp_dsv);
12734 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12736 ok(!tmp_uav[i], "Got unexpected unordered access view %p in slot %u.\n", tmp_uav[i], i);
12739 ID3D11DeviceContext_RSGetScissorRects(context, &count, NULL);
12740 ok(!count, "Got unexpected scissor rect count %u.\n", count);
12741 memset(tmp_rect, 0x55, sizeof(tmp_rect));
12742 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12743 ID3D11DeviceContext_RSGetScissorRects(context, &count, tmp_rect);
12744 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12746 ok(!tmp_rect[i].left && !tmp_rect[i].top && !tmp_rect[i].right && !tmp_rect[i].bottom,
12747 "Got unexpected scissor rect %s in slot %u.\n",
12748 wine_dbgstr_rect(&tmp_rect[i]), i);
12750 ID3D11DeviceContext_RSGetViewports(context, &count, NULL);
12751 ok(!count, "Got unexpected viewport count %u.\n", count);
12752 memset(tmp_viewport, 0x55, sizeof(tmp_viewport));
12753 count = D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE;
12754 ID3D11DeviceContext_RSGetViewports(context, &count, tmp_viewport);
12755 for (i = 0; i < D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE; ++i)
12757 ok(!tmp_viewport[i].TopLeftX && !tmp_viewport[i].TopLeftY && !tmp_viewport[i].Width
12758 && !tmp_viewport[i].Height && !tmp_viewport[i].MinDepth && !tmp_viewport[i].MaxDepth,
12759 "Got unexpected viewport {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e} in slot %u.\n",
12760 tmp_viewport[i].TopLeftX, tmp_viewport[i].TopLeftY, tmp_viewport[i].Width,
12761 tmp_viewport[i].Height, tmp_viewport[i].MinDepth, tmp_viewport[i].MaxDepth, i);
12763 ID3D11DeviceContext_RSGetState(context, &tmp_rs_state);
12764 ok(!tmp_rs_state, "Got unexpected rasterizer state %p.\n", tmp_rs_state);
12766 ID3D11DeviceContext_SOGetTargets(context, D3D11_SO_BUFFER_SLOT_COUNT, tmp_buffer);
12767 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12769 ok(!tmp_buffer[i], "Got unexpected stream output %p in slot %u.\n", tmp_buffer[i], i);
12772 ID3D11DeviceContext_GetPredication(context, &tmp_predicate, &predicate_value);
12773 ok(!tmp_predicate, "Got unexpected predicate %p.\n", tmp_predicate);
12774 ok(!predicate_value, "Got unexpected predicate value %#x.\n", predicate_value);
12776 /* Cleanup. */
12778 ID3D11Predicate_Release(predicate);
12779 ID3D11RasterizerState_Release(rs_state);
12780 ID3D11DepthStencilView_Release(dsv);
12781 ID3D11Texture2D_Release(ds_texture);
12783 for (i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
12785 ID3D11RenderTargetView_Release(rtv[i]);
12786 ID3D11Texture2D_Release(rt_texture[i]);
12789 ID3D11DepthStencilState_Release(ds_state);
12790 ID3D11BlendState_Release(blend_state);
12791 ID3D11InputLayout_Release(input_layout);
12792 ID3D11VertexShader_Release(vs);
12793 ID3D11HullShader_Release(hs);
12794 ID3D11DomainShader_Release(ds);
12795 ID3D11GeometryShader_Release(gs);
12796 ID3D11PixelShader_Release(ps);
12797 ID3D11ComputeShader_Release(cs);
12799 for (i = 0; i < D3D11_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
12801 ID3D11SamplerState_Release(sampler[i]);
12804 for (i = 0; i < D3D11_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
12806 ID3D11ShaderResourceView_Release(srv[i]);
12809 for (i = 0; i < D3D11_PS_CS_UAV_REGISTER_COUNT; ++i)
12811 ID3D11UnorderedAccessView_Release(cs_uav[i]);
12812 ID3D11Buffer_Release(cs_uav_buffer[i]);
12814 ID3D11UnorderedAccessView_Release(ps_uav);
12815 ID3D11Buffer_Release(ps_uav_buffer);
12817 for (i = 0; i < D3D11_SO_BUFFER_SLOT_COUNT; ++i)
12819 ID3D11Buffer_Release(so_buffer[i]);
12822 for (i = 0; i < D3D11_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
12824 ID3D11Buffer_Release(buffer[i]);
12827 for (i = 0; i < D3D11_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
12829 ID3D11Buffer_Release(cb[i]);
12832 ID3D11DeviceContext_Release(context);
12833 refcount = ID3D11Device_Release(device);
12834 ok(!refcount, "Device has %u references left.\n", refcount);
12837 static void test_il_append_aligned(void)
12839 struct d3d11_test_context test_context;
12840 ID3D11InputLayout *input_layout;
12841 ID3D11DeviceContext *context;
12842 unsigned int stride, offset;
12843 ID3D11VertexShader *vs;
12844 ID3D11PixelShader *ps;
12845 ID3D11Device *device;
12846 ID3D11Buffer *vb[3];
12847 DWORD color;
12848 HRESULT hr;
12850 /* Semantic names are case-insensitive. */
12851 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
12853 {"CoLoR", 2, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
12854 D3D11_INPUT_PER_INSTANCE_DATA, 2},
12855 {"ColoR", 3, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
12856 D3D11_INPUT_PER_INSTANCE_DATA, 1},
12857 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
12858 D3D11_INPUT_PER_VERTEX_DATA, 0},
12859 {"ColoR", 0, DXGI_FORMAT_R32G32_FLOAT, 2, D3D11_APPEND_ALIGNED_ELEMENT,
12860 D3D11_INPUT_PER_INSTANCE_DATA, 1},
12861 {"cOLOr", 1, DXGI_FORMAT_R32G32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
12862 D3D11_INPUT_PER_INSTANCE_DATA, 2},
12864 static const DWORD vs_code[] =
12866 #if 0
12867 struct vs_in
12869 float4 position : POSITION;
12870 float2 color_xy : COLOR0;
12871 float2 color_zw : COLOR1;
12872 unsigned int instance_id : SV_INSTANCEID;
12875 struct vs_out
12877 float4 position : SV_POSITION;
12878 float2 color_xy : COLOR0;
12879 float2 color_zw : COLOR1;
12882 struct vs_out main(struct vs_in i)
12884 struct vs_out o;
12886 o.position = i.position;
12887 o.position.x += i.instance_id * 0.5;
12888 o.color_xy = i.color_xy;
12889 o.color_zw = i.color_zw;
12891 return o;
12893 #endif
12894 0x43425844, 0x52e3bf46, 0x6300403d, 0x624cffe4, 0xa4fc0013, 0x00000001, 0x00000214, 0x00000003,
12895 0x0000002c, 0x000000bc, 0x00000128, 0x4e475349, 0x00000088, 0x00000004, 0x00000008, 0x00000068,
12896 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000071, 0x00000000, 0x00000000,
12897 0x00000003, 0x00000001, 0x00000303, 0x00000071, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
12898 0x00000303, 0x00000077, 0x00000000, 0x00000008, 0x00000001, 0x00000003, 0x00000101, 0x49534f50,
12899 0x4e4f4954, 0x4c4f4300, 0x5300524f, 0x4e495f56, 0x4e415453, 0x44494543, 0xababab00, 0x4e47534f,
12900 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
12901 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03, 0x0000005c,
12902 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000030c, 0x505f5653, 0x5449534f, 0x004e4f49,
12903 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000e4, 0x00010040, 0x00000039, 0x0300005f, 0x001010f2,
12904 0x00000000, 0x0300005f, 0x00101032, 0x00000001, 0x0300005f, 0x00101032, 0x00000002, 0x04000060,
12905 0x00101012, 0x00000003, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
12906 0x00102032, 0x00000001, 0x03000065, 0x001020c2, 0x00000001, 0x02000068, 0x00000001, 0x05000056,
12907 0x00100012, 0x00000000, 0x0010100a, 0x00000003, 0x09000032, 0x00102012, 0x00000000, 0x0010000a,
12908 0x00000000, 0x00004001, 0x3f000000, 0x0010100a, 0x00000000, 0x05000036, 0x001020e2, 0x00000000,
12909 0x00101e56, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046, 0x00000001, 0x05000036,
12910 0x001020c2, 0x00000001, 0x00101406, 0x00000002, 0x0100003e,
12912 static const DWORD ps_code[] =
12914 #if 0
12915 struct vs_out
12917 float4 position : SV_POSITION;
12918 float2 color_xy : COLOR0;
12919 float2 color_zw : COLOR1;
12922 float4 main(struct vs_out i) : SV_TARGET
12924 return float4(i.color_xy.xy, i.color_zw.xy);
12926 #endif
12927 0x43425844, 0x64e48a09, 0xaa484d46, 0xe40a6e78, 0x9885edf3, 0x00000001, 0x00000118, 0x00000003,
12928 0x0000002c, 0x00000098, 0x000000cc, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
12929 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000,
12930 0x00000003, 0x00000001, 0x00000303, 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
12931 0x00000c0c, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x0000002c,
12932 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
12933 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000044, 0x00000040, 0x00000011, 0x03001062,
12934 0x00101032, 0x00000001, 0x03001062, 0x001010c2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
12935 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
12937 static const struct
12939 struct vec4 position;
12941 stream0[] =
12943 {{-1.0f, -1.0f, 0.0f, 1.0f}},
12944 {{-1.0f, 1.0f, 0.0f, 1.0f}},
12945 {{-0.5f, -1.0f, 0.0f, 1.0f}},
12946 {{-0.5f, 1.0f, 0.0f, 1.0f}},
12948 static const struct
12950 struct vec2 color2;
12951 struct vec2 color1;
12953 stream1[] =
12955 {{0.5f, 0.5f}, {0.0f, 1.0f}},
12956 {{0.5f, 0.5f}, {1.0f, 1.0f}},
12958 static const struct
12960 struct vec2 color3;
12961 struct vec2 color0;
12963 stream2[] =
12965 {{0.5f, 0.5f}, {1.0f, 0.0f}},
12966 {{0.5f, 0.5f}, {0.0f, 1.0f}},
12967 {{0.5f, 0.5f}, {0.0f, 0.0f}},
12968 {{0.5f, 0.5f}, {1.0f, 0.0f}},
12970 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
12972 if (!init_test_context(&test_context, NULL))
12973 return;
12975 device = test_context.device;
12976 context = test_context.immediate_context;
12978 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
12979 vs_code, sizeof(vs_code), &input_layout);
12980 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
12982 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
12983 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
12984 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
12986 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
12987 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
12988 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
12989 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
12991 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
12992 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
12993 offset = 0;
12994 stride = sizeof(*stream0);
12995 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
12996 stride = sizeof(*stream1);
12997 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
12998 stride = sizeof(*stream2);
12999 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
13000 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13001 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13003 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13005 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
13007 color = get_texture_color(test_context.backbuffer, 80, 240);
13008 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
13009 color = get_texture_color(test_context.backbuffer, 240, 240);
13010 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13011 color = get_texture_color(test_context.backbuffer, 400, 240);
13012 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13013 color = get_texture_color(test_context.backbuffer, 560, 240);
13014 ok(compare_color(color, 0xffff00ff, 1), "Got unexpected color 0x%08x.\n", color);
13016 ID3D11PixelShader_Release(ps);
13017 ID3D11VertexShader_Release(vs);
13018 ID3D11Buffer_Release(vb[2]);
13019 ID3D11Buffer_Release(vb[1]);
13020 ID3D11Buffer_Release(vb[0]);
13021 ID3D11InputLayout_Release(input_layout);
13022 release_test_context(&test_context);
13025 static void test_instanced_draw(void)
13027 struct d3d11_test_context test_context;
13028 D3D11_TEXTURE2D_DESC texture_desc;
13029 ID3D11InputLayout *input_layout;
13030 ID3D11RenderTargetView *rtvs[2];
13031 ID3D11Texture2D *render_target;
13032 ID3D11DeviceContext *context;
13033 struct resource_readback rb;
13034 unsigned int stride, offset;
13035 ID3D11Buffer *args_buffer;
13036 ID3D11VertexShader *vs;
13037 ID3D11PixelShader *ps;
13038 ID3D11Device *device;
13039 ID3D11Buffer *vb[4];
13040 unsigned int i;
13041 HRESULT hr;
13043 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13045 {"position", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT,
13046 D3D11_INPUT_PER_VERTEX_DATA, 0},
13047 {"color", 0, DXGI_FORMAT_R8_UNORM, 1, D3D11_APPEND_ALIGNED_ELEMENT,
13048 D3D11_INPUT_PER_INSTANCE_DATA, 1},
13049 {"color", 1, DXGI_FORMAT_R8_UNORM, 2, D3D11_APPEND_ALIGNED_ELEMENT,
13050 D3D10_INPUT_PER_INSTANCE_DATA, 0},
13051 {"color", 2, DXGI_FORMAT_R8_UNORM, 3, D3D11_APPEND_ALIGNED_ELEMENT,
13052 D3D10_INPUT_PER_INSTANCE_DATA, 2},
13053 {"v_offset", 0, DXGI_FORMAT_R32_FLOAT, 1, D3D11_APPEND_ALIGNED_ELEMENT,
13054 D3D11_INPUT_PER_INSTANCE_DATA, 1},
13056 static const DWORD vs_code[] =
13058 #if 0
13059 struct vs_in
13061 float4 position : Position;
13062 float r : color0;
13063 float g : color1;
13064 float b : color2;
13065 float v_offset : V_Offset;
13066 uint instance_id : SV_InstanceId;
13069 struct vs_out
13071 float4 position : SV_Position;
13072 float r : color0;
13073 float g : color1;
13074 float b : color2;
13075 uint instance_id : InstanceId;
13078 void main(vs_in i, out vs_out o)
13080 o.position = i.position;
13081 o.position.x += i.v_offset;
13082 o.r = i.r;
13083 o.g = i.g;
13084 o.b = i.b;
13085 o.instance_id = i.instance_id;
13087 #endif
13088 0x43425844, 0x036df42e, 0xff0da346, 0x7b23a14a, 0xc26ec9be, 0x00000001, 0x000002bc, 0x00000003,
13089 0x0000002c, 0x000000f4, 0x0000019c, 0x4e475349, 0x000000c0, 0x00000006, 0x00000008, 0x00000098,
13090 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a1, 0x00000000, 0x00000000,
13091 0x00000003, 0x00000001, 0x00000101, 0x000000a1, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
13092 0x00000101, 0x000000a1, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000a7,
13093 0x00000000, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000b0, 0x00000000, 0x00000008,
13094 0x00000001, 0x00000005, 0x00000101, 0x69736f50, 0x6e6f6974, 0x6c6f6300, 0x5600726f, 0x66664f5f,
13095 0x00746573, 0x495f5653, 0x6174736e, 0x4965636e, 0xabab0064, 0x4e47534f, 0x000000a0, 0x00000005,
13096 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c,
13097 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000008c, 0x00000001, 0x00000000,
13098 0x00000003, 0x00000001, 0x00000d02, 0x0000008c, 0x00000002, 0x00000000, 0x00000003, 0x00000001,
13099 0x00000b04, 0x00000092, 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000e01, 0x505f5653,
13100 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x52444853,
13101 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012,
13102 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
13103 0x00101012, 0x00000004, 0x04000060, 0x00101012, 0x00000005, 0x00000008, 0x04000067, 0x001020f2,
13104 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x03000065, 0x00102022, 0x00000001,
13105 0x03000065, 0x00102042, 0x00000001, 0x03000065, 0x00102012, 0x00000002, 0x07000000, 0x00102012,
13106 0x00000000, 0x0010100a, 0x00000000, 0x0010100a, 0x00000004, 0x05000036, 0x001020e2, 0x00000000,
13107 0x00101e56, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x05000036,
13108 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042, 0x00000001, 0x0010100a,
13109 0x00000003, 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x0100003e,
13111 static const DWORD ps_code[] =
13113 #if 0
13114 struct vs_out
13116 float4 position : SV_Position;
13117 float r : color0;
13118 float g : color1;
13119 float b : color2;
13120 uint instance_id : InstanceId;
13123 void main(vs_out i, out float4 o0 : SV_Target0, out uint4 o1 : SV_Target1)
13125 o0 = float4(i.r, i.g, i.b, 1.0f);
13126 o1 = i.instance_id;
13128 #endif
13129 0x43425844, 0xc9f9c86d, 0xa24d87aa, 0xff75d05b, 0xfbe0581a, 0x00000001, 0x000001b8, 0x00000003,
13130 0x0000002c, 0x000000d4, 0x00000120, 0x4e475349, 0x000000a0, 0x00000005, 0x00000008, 0x00000080,
13131 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
13132 0x00000003, 0x00000001, 0x00000101, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001,
13133 0x00000202, 0x0000008c, 0x00000002, 0x00000000, 0x00000003, 0x00000001, 0x00000404, 0x00000092,
13134 0x00000000, 0x00000000, 0x00000001, 0x00000002, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
13135 0x6f6c6f63, 0x6e490072, 0x6e617473, 0x64496563, 0xababab00, 0x4e47534f, 0x00000044, 0x00000002,
13136 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000038,
13137 0x00000001, 0x00000000, 0x00000001, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
13138 0x52444853, 0x00000090, 0x00000040, 0x00000024, 0x03001062, 0x00101012, 0x00000001, 0x03001062,
13139 0x00101022, 0x00000001, 0x03001062, 0x00101042, 0x00000001, 0x03000862, 0x00101012, 0x00000002,
13140 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x00102072,
13141 0x00000000, 0x00101246, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
13142 0x05000036, 0x001020f2, 0x00000001, 0x00101006, 0x00000002, 0x0100003e,
13144 static const struct vec4 stream0[] =
13146 {-1.00f, 0.0f, 0.0f, 1.0f},
13147 {-1.00f, 1.0f, 0.0f, 1.0f},
13148 {-0.75f, 0.0f, 0.0f, 1.0f},
13149 {-0.75f, 1.0f, 0.0f, 1.0f},
13150 /* indirect draws data */
13151 {-1.00f, -1.0f, 0.0f, 1.0f},
13152 {-1.00f, 0.0f, 0.0f, 1.0f},
13153 {-0.75f, -1.0f, 0.0f, 1.0f},
13154 {-0.75f, 0.0f, 0.0f, 1.0f},
13156 static const struct
13158 BYTE red;
13159 float v_offset;
13161 stream1[] =
13163 {0xf0, 0.00f},
13164 {0x80, 0.25f},
13165 {0x10, 0.50f},
13166 {0x40, 0.75f},
13168 {0xaa, 1.00f},
13169 {0xbb, 1.25f},
13170 {0xcc, 1.50f},
13171 {0x90, 1.75f},
13173 static const BYTE stream2[] = {0xf0, 0x80, 0x10, 0x40, 0xaa, 0xbb, 0xcc, 0x90};
13174 static const BYTE stream3[] = {0xf0, 0x80, 0x10, 0x40, 0xaa, 0xbb, 0xcc, 0x90};
13175 static const D3D11_DRAW_INSTANCED_INDIRECT_ARGS argument_data[] =
13177 {4, 4, 4, 0},
13178 {4, 4, 4, 4},
13180 static const struct
13182 RECT rect;
13183 unsigned int color;
13184 unsigned int instance_id;
13186 expected_results[] =
13188 {{ 0, 0, 80, 240}, 0xfff0f0f0, 0},
13189 {{ 80, 0, 160, 240}, 0xfff0f080, 1},
13190 {{160, 0, 240, 240}, 0xff80f010, 2},
13191 {{240, 0, 320, 240}, 0xff80f040, 3},
13192 {{320, 0, 400, 240}, 0xffaaaaaa, 0},
13193 {{400, 0, 480, 240}, 0xffaaaabb, 1},
13194 {{480, 0, 560, 240}, 0xffbbaacc, 2},
13195 {{560, 0, 640, 240}, 0xffbbaa90, 3},
13196 /* indirect draws results */
13197 {{ 0, 240, 80, 480}, 0xfff0f0f0, 0},
13198 {{ 80, 240, 160, 480}, 0xfff0f080, 1},
13199 {{160, 240, 240, 480}, 0xff80f010, 2},
13200 {{240, 240, 320, 480}, 0xff80f040, 3},
13201 {{320, 240, 400, 480}, 0xffaaaaaa, 0},
13202 {{400, 240, 480, 480}, 0xffaaaabb, 1},
13203 {{480, 240, 560, 480}, 0xffbbaacc, 2},
13204 {{560, 240, 640, 480}, 0xffbbaa90, 3},
13206 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
13207 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
13209 if (!init_test_context(&test_context, &feature_level))
13210 return;
13211 device = test_context.device;
13212 context = test_context.immediate_context;
13214 rtvs[0] = test_context.backbuffer_rtv;
13216 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
13217 texture_desc.Format = DXGI_FORMAT_R32_UINT;
13218 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
13219 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
13220 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtvs[1]);
13221 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
13223 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13224 vs_code, sizeof(vs_code), &input_layout);
13225 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
13227 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13228 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
13229 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13230 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13232 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream0), stream0);
13233 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream1), stream1);
13234 vb[2] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream2), stream2);
13235 vb[3] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(stream3), stream3);
13237 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13238 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13239 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13240 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
13241 offset = 0;
13242 stride = sizeof(*stream0);
13243 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[0], &stride, &offset);
13244 stride = sizeof(*stream1);
13245 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb[1], &stride, &offset);
13246 stride = sizeof(*stream2);
13247 ID3D11DeviceContext_IASetVertexBuffers(context, 2, 1, &vb[2], &stride, &offset);
13248 stride = sizeof(*stream3);
13249 ID3D11DeviceContext_IASetVertexBuffers(context, 3, 1, &vb[3], &stride, &offset);
13251 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
13252 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[1], white);
13254 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
13255 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 0);
13256 ID3D11DeviceContext_DrawInstanced(context, 4, 4, 0, 4);
13258 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
13259 sizeof(argument_data), argument_data);
13261 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, 0);
13262 ID3D11DeviceContext_DrawInstancedIndirect(context, args_buffer, sizeof(*argument_data));
13264 get_texture_readback(test_context.backbuffer, 0, &rb);
13265 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
13266 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].color, 1);
13267 release_resource_readback(&rb);
13269 get_texture_readback(render_target, 0, &rb);
13270 for (i = 0; i < ARRAY_SIZE(expected_results); ++i)
13271 check_readback_data_color(&rb, &expected_results[i].rect, expected_results[i].instance_id, 0);
13272 release_resource_readback(&rb);
13274 ID3D11Buffer_Release(vb[0]);
13275 ID3D11Buffer_Release(vb[1]);
13276 ID3D11Buffer_Release(vb[2]);
13277 ID3D11Buffer_Release(vb[3]);
13278 ID3D11Buffer_Release(args_buffer);
13279 ID3D11RenderTargetView_Release(rtvs[1]);
13280 ID3D11Texture2D_Release(render_target);
13281 ID3D11VertexShader_Release(vs);
13282 ID3D11PixelShader_Release(ps);
13283 ID3D11InputLayout_Release(input_layout);
13284 release_test_context(&test_context);
13287 static void test_vertex_id(void)
13289 static const DWORD vs_code[] =
13291 #if 0
13292 uint4 main(uint id : ID, uint instance_id : SV_InstanceID, uint vertex_id : SV_VertexID) : OUTPUT
13294 return uint4(id, instance_id, vertex_id, 0);
13296 #endif
13297 0x43425844, 0x5625197b, 0x588ccf8f, 0x48694905, 0x961d19ca, 0x00000001, 0x00000170, 0x00000003,
13298 0x0000002c, 0x000000a4, 0x000000d4, 0x4e475349, 0x00000070, 0x00000003, 0x00000008, 0x00000050,
13299 0x00000000, 0x00000000, 0x00000001, 0x00000000, 0x00000101, 0x00000053, 0x00000000, 0x00000008,
13300 0x00000001, 0x00000001, 0x00000101, 0x00000061, 0x00000000, 0x00000006, 0x00000001, 0x00000002,
13301 0x00000101, 0x53004449, 0x6e495f56, 0x6e617473, 0x44496563, 0x5f565300, 0x74726556, 0x44497865,
13302 0xababab00, 0x4e47534f, 0x00000028, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
13303 0x00000001, 0x00000000, 0x0000000f, 0x5054554f, 0xab005455, 0x52444853, 0x00000094, 0x00010040,
13304 0x00000025, 0x0300005f, 0x00101012, 0x00000000, 0x04000060, 0x00101012, 0x00000001, 0x00000008,
13305 0x04000060, 0x00101012, 0x00000002, 0x00000006, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
13306 0x00102012, 0x00000000, 0x0010100a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010100a,
13307 0x00000001, 0x05000036, 0x00102042, 0x00000000, 0x0010100a, 0x00000002, 0x05000036, 0x00102082,
13308 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
13310 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
13312 {"ID", 0, DXGI_FORMAT_R32_UINT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0},
13314 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
13316 {0, "OUTPUT", 0, 0, 4, 0},
13318 static const unsigned int vertices[] =
13336 static const unsigned int indices[] =
13338 6, 7, 8,
13340 0, 1, 2,
13342 struct uvec4 expected_values[] =
13344 {0, 0, 0},
13345 {1, 0, 1},
13346 {2, 0, 2},
13347 {0, 1, 0},
13348 {1, 1, 1},
13349 {2, 1, 2},
13351 {3, 0, 0},
13352 {4, 0, 1},
13353 {5, 0, 2},
13355 {6, 0, 6},
13356 {7, 0, 7},
13357 {8, 0, 8},
13358 {6, 1, 6},
13359 {7, 1, 7},
13360 {8, 1, 8},
13362 {5, 0, 0},
13363 {6, 0, 1},
13364 {7, 0, 2},
13367 BOOL found_values[ARRAY_SIZE(expected_values)] = {0};
13368 BOOL used_values[ARRAY_SIZE(expected_values)] = {0};
13369 struct d3d11_test_context test_context;
13370 D3D11_QUERY_DATA_SO_STATISTICS data;
13371 ID3D11Buffer *vb, *ib, *so_buffer;
13372 ID3D11InputLayout *input_layout;
13373 ID3D11DeviceContext *context;
13374 D3D11_QUERY_DESC query_desc;
13375 struct resource_readback rb;
13376 unsigned int stride, offset;
13377 ID3D11Asynchronous *query;
13378 ID3D11GeometryShader *gs;
13379 ID3D11VertexShader *vs;
13380 ID3D11Device *device;
13381 unsigned int count;
13382 unsigned int i, j;
13383 HRESULT hr;
13385 if (!init_test_context(&test_context, NULL))
13386 return;
13387 device = test_context.device;
13388 context = test_context.immediate_context;
13390 query_desc.Query = D3D11_QUERY_SO_STATISTICS;
13391 query_desc.MiscFlags = 0;
13392 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
13393 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
13395 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
13396 vs_code, sizeof(vs_code), &input_layout);
13397 ok(hr == S_OK, "Failed to create input layout, hr %#x.\n", hr);
13399 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
13400 ok(hr == S_OK, "Failed to create vertex shader, hr %#x.\n", hr);
13402 stride = 16;
13403 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
13404 so_declaration, ARRAY_SIZE(so_declaration), &stride, 1, 0, NULL, &gs);
13405 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
13407 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
13408 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
13409 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
13411 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
13412 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
13413 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
13414 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
13415 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
13416 offset = 0;
13417 stride = sizeof(*vertices);
13418 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
13420 offset = 0;
13421 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
13423 ID3D11DeviceContext_Begin(context, query);
13425 ID3D11DeviceContext_DrawInstanced(context, 3, 2, 0, 0);
13426 ID3D11DeviceContext_DrawInstanced(context, 3, 1, 3, 16);
13428 ID3D11DeviceContext_DrawIndexedInstanced(context, 3, 2, 0, 0, 0);
13429 ID3D11DeviceContext_DrawIndexedInstanced(context, 3, 1, 3, 9, 7);
13431 ID3D11DeviceContext_End(context, query);
13433 get_query_data(context, query, &data, sizeof(data));
13434 count = data.NumPrimitivesWritten;
13435 ok(count == ARRAY_SIZE(expected_values), "Got unexpected value %u.\n", count);
13437 count = min(count, ARRAY_SIZE(used_values));
13438 get_buffer_readback(so_buffer, &rb);
13439 for (i = 0; i < ARRAY_SIZE(expected_values); ++i)
13441 for (j = 0; j < count; ++j)
13443 if (!used_values[j] && compare_uvec4(get_readback_uvec4(&rb, j, 0), &expected_values[i]))
13445 found_values[i] = TRUE;
13446 used_values[j] = TRUE;
13447 break;
13452 for (i = 0; i < count; ++i)
13454 const struct uvec4 *v = get_readback_uvec4(&rb, i, 0);
13455 ok(used_values[i], "Found unexpected value {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n", v->x, v->y, v->z, v->w);
13457 release_resource_readback(&rb);
13459 for (i = 0; i < ARRAY_SIZE(expected_values); ++i)
13461 ok(found_values[i], "Failed to find value {0x%08x, 0x%08x, 0x%08x, 0x%08x}.\n",
13462 expected_values[i].x, expected_values[i].y, expected_values[i].z, expected_values[i].w);
13465 ID3D11Asynchronous_Release(query);
13466 ID3D11Buffer_Release(so_buffer);
13467 ID3D11Buffer_Release(vb);
13468 ID3D11Buffer_Release(ib);
13469 ID3D11GeometryShader_Release(gs);
13470 ID3D11VertexShader_Release(vs);
13471 ID3D11InputLayout_Release(input_layout);
13472 release_test_context(&test_context);
13475 static void test_fragment_coords(void)
13477 struct d3d11_test_context test_context;
13478 ID3D11PixelShader *ps, *ps_frac;
13479 ID3D11DeviceContext *context;
13480 ID3D11Device *device;
13481 ID3D11Buffer *ps_cb;
13482 DWORD color;
13483 HRESULT hr;
13485 static const DWORD ps_code[] =
13487 #if 0
13488 float2 cutoff;
13490 float4 main(float4 position : SV_POSITION) : SV_TARGET
13492 float4 ret = float4(0.0, 0.0, 0.0, 1.0);
13494 if (position.x > cutoff.x)
13495 ret.y = 1.0;
13496 if (position.y > cutoff.y)
13497 ret.z = 1.0;
13499 return ret;
13501 #endif
13502 0x43425844, 0x49fc9e51, 0x8068867d, 0xf20cfa39, 0xb8099e6b, 0x00000001, 0x00000144, 0x00000003,
13503 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13504 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13505 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13506 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000a8, 0x00000040,
13507 0x0000002a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002064, 0x00101032, 0x00000000,
13508 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000031, 0x00100032,
13509 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00101046, 0x00000000, 0x0a000001, 0x00102062,
13510 0x00000000, 0x00100106, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x00000000,
13511 0x08000036, 0x00102092, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
13512 0x0100003e,
13514 static const DWORD ps_frac_code[] =
13516 #if 0
13517 float4 main(float4 position : SV_POSITION) : SV_TARGET
13519 return float4(frac(position.xy), 0.0, 1.0);
13521 #endif
13522 0x43425844, 0x86d9d78a, 0x190b72c2, 0x50841fd6, 0xdc24022e, 0x00000001, 0x000000f8, 0x00000003,
13523 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13524 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13525 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13526 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000005c, 0x00000040,
13527 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
13528 0x0500001a, 0x00102032, 0x00000000, 0x00101046, 0x00000000, 0x08000036, 0x001020c2, 0x00000000,
13529 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
13531 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13532 struct vec4 cutoff = {320.0f, 240.0f, 0.0f, 0.0f};
13534 if (!init_test_context(&test_context, NULL))
13535 return;
13537 device = test_context.device;
13538 context = test_context.immediate_context;
13540 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
13542 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13543 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13544 hr = ID3D11Device_CreatePixelShader(device, ps_frac_code, sizeof(ps_frac_code), NULL, &ps_frac);
13545 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13547 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
13548 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13550 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13552 draw_quad(&test_context);
13554 color = get_texture_color(test_context.backbuffer, 319, 239);
13555 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
13556 color = get_texture_color(test_context.backbuffer, 320, 239);
13557 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13558 color = get_texture_color(test_context.backbuffer, 319, 240);
13559 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13560 color = get_texture_color(test_context.backbuffer, 320, 240);
13561 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
13563 ID3D11Buffer_Release(ps_cb);
13564 cutoff.x = 16.0f;
13565 cutoff.y = 16.0f;
13566 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cutoff), &cutoff);
13567 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
13569 draw_quad(&test_context);
13571 color = get_texture_color(test_context.backbuffer, 14, 14);
13572 ok(compare_color(color, 0xff000000, 1), "Got unexpected color 0x%08x.\n", color);
13573 color = get_texture_color(test_context.backbuffer, 18, 14);
13574 ok(compare_color(color, 0xff00ff00, 1), "Got unexpected color 0x%08x.\n", color);
13575 color = get_texture_color(test_context.backbuffer, 14, 18);
13576 ok(compare_color(color, 0xffff0000, 1), "Got unexpected color 0x%08x.\n", color);
13577 color = get_texture_color(test_context.backbuffer, 18, 18);
13578 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
13580 ID3D11DeviceContext_PSSetShader(context, ps_frac, NULL, 0);
13581 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13583 ID3D11DeviceContext_Draw(context, 4, 0);
13585 color = get_texture_color(test_context.backbuffer, 14, 14);
13586 ok(compare_color(color, 0xff008080, 1), "Got unexpected color 0x%08x.\n", color);
13588 ID3D11Buffer_Release(ps_cb);
13589 ID3D11PixelShader_Release(ps_frac);
13590 ID3D11PixelShader_Release(ps);
13591 release_test_context(&test_context);
13594 static void test_initial_texture_data(void)
13596 ID3D11Texture2D *texture, *staging_texture;
13597 struct d3d11_test_context test_context;
13598 D3D11_SUBRESOURCE_DATA resource_data;
13599 D3D11_TEXTURE2D_DESC texture_desc;
13600 ID3D11SamplerState *sampler_state;
13601 ID3D11ShaderResourceView *ps_srv;
13602 D3D11_SAMPLER_DESC sampler_desc;
13603 ID3D11DeviceContext *context;
13604 struct resource_readback rb;
13605 ID3D11PixelShader *ps;
13606 ID3D11Device *device;
13607 unsigned int i, j;
13608 DWORD color;
13609 HRESULT hr;
13611 static const DWORD ps_code[] =
13613 #if 0
13614 Texture2D t;
13615 SamplerState s;
13617 float4 main(float4 position : SV_POSITION) : SV_Target
13619 float2 p;
13621 p.x = position.x / 640.0f;
13622 p.y = position.y / 480.0f;
13623 return t.Sample(s, p);
13625 #endif
13626 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13627 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13628 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13629 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13630 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13631 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13632 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13633 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13634 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13635 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13637 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13638 static const DWORD bitmap_data[] =
13640 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
13641 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
13642 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
13643 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
13646 if (!init_test_context(&test_context, NULL))
13647 return;
13649 device = test_context.device;
13650 context = test_context.immediate_context;
13652 texture_desc.Width = 4;
13653 texture_desc.Height = 4;
13654 texture_desc.MipLevels = 1;
13655 texture_desc.ArraySize = 1;
13656 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13657 texture_desc.SampleDesc.Count = 1;
13658 texture_desc.SampleDesc.Quality = 0;
13659 texture_desc.Usage = D3D11_USAGE_STAGING;
13660 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
13661 texture_desc.BindFlags = 0;
13662 texture_desc.MiscFlags = 0;
13664 resource_data.pSysMem = bitmap_data;
13665 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
13666 resource_data.SysMemSlicePitch = 0;
13668 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &staging_texture);
13669 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
13671 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13672 texture_desc.CPUAccessFlags = 0;
13673 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13674 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
13675 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
13677 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)texture, (ID3D11Resource *)staging_texture);
13679 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
13680 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
13682 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
13683 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
13684 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
13685 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
13686 sampler_desc.MipLODBias = 0.0f;
13687 sampler_desc.MaxAnisotropy = 0;
13688 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
13689 sampler_desc.BorderColor[0] = 0.0f;
13690 sampler_desc.BorderColor[1] = 0.0f;
13691 sampler_desc.BorderColor[2] = 0.0f;
13692 sampler_desc.BorderColor[3] = 0.0f;
13693 sampler_desc.MinLOD = 0.0f;
13694 sampler_desc.MaxLOD = 0.0f;
13695 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
13696 ok(hr == S_OK, "Failed to create sampler state, hr %#x.\n", hr);
13698 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13699 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
13701 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
13702 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
13703 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13705 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13706 draw_quad(&test_context);
13707 get_texture_readback(test_context.backbuffer, 0, &rb);
13708 for (i = 0; i < 4; ++i)
13710 for (j = 0; j < 4; ++j)
13712 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13713 ok(compare_color(color, bitmap_data[j + i * 4], 1),
13714 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13715 color, j, i, bitmap_data[j + i * 4]);
13718 release_resource_readback(&rb);
13720 ID3D11PixelShader_Release(ps);
13721 ID3D11SamplerState_Release(sampler_state);
13722 ID3D11ShaderResourceView_Release(ps_srv);
13723 ID3D11Texture2D_Release(staging_texture);
13724 ID3D11Texture2D_Release(texture);
13725 release_test_context(&test_context);
13728 static void test_update_subresource(void)
13730 struct d3d11_test_context test_context;
13731 D3D11_SUBRESOURCE_DATA resource_data;
13732 D3D11_TEXTURE3D_DESC texture_desc_3d;
13733 D3D11_TEXTURE2D_DESC texture_desc;
13734 ID3D11SamplerState *sampler_state;
13735 ID3D11ShaderResourceView *ps_srv;
13736 D3D11_SAMPLER_DESC sampler_desc;
13737 ID3D11DeviceContext *context;
13738 struct resource_readback rb;
13739 ID3D11Texture3D *texture_3d;
13740 ID3D11Texture2D *texture;
13741 ID3D11PixelShader *ps;
13742 ID3D11Device *device;
13743 unsigned int i, j;
13744 D3D11_BOX box;
13745 DWORD color;
13746 HRESULT hr;
13748 static const DWORD ps_code[] =
13750 #if 0
13751 Texture2D t;
13752 SamplerState s;
13754 float4 main(float4 position : SV_POSITION) : SV_Target
13756 float2 p;
13758 p.x = position.x / 640.0f;
13759 p.y = position.y / 480.0f;
13760 return t.Sample(s, p);
13762 #endif
13763 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
13764 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13765 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13766 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13767 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
13768 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
13769 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13770 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13771 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
13772 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
13774 static const DWORD ps_code_3d[] =
13776 #if 0
13777 Texture3D t;
13778 SamplerState s;
13780 float4 main(float4 position : SV_POSITION) : SV_Target
13782 float3 p1, p2;
13783 p2.x = p1.x = position.x / 640.0f;
13784 p2.y = p1.y = position.y / 480.0f;
13785 p1.z = 0.25;
13786 p2.z = 0.75;
13787 return 0.5 * (t.Sample(s, p1) + t.Sample(s, p2));
13789 #endif
13790 0x43425844, 0x4d466d63, 0xa3d10db1, 0xd6534470, 0x16d738ef, 0x00000001, 0x000001ec, 0x00000003,
13791 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
13792 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
13793 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
13794 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000150, 0x00000040,
13795 0x00000054, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
13796 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
13797 0x00000002, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13798 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3e800000,
13799 0x09000045, 0x001000f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
13800 0x00000000, 0x0a000038, 0x00100032, 0x00000001, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
13801 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000001, 0x00004001, 0x3f400000,
13802 0x09000045, 0x001000f2, 0x00000001, 0x00100246, 0x00000001, 0x00107e46, 0x00000000, 0x00106000,
13803 0x00000000, 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
13804 0x0a000038, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000,
13805 0x3f000000, 0x3f000000, 0x0100003e,
13807 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
13808 static const DWORD initial_data[32] = {0};
13809 static const DWORD bitmap_data[] =
13811 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
13812 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
13813 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
13814 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
13816 static const DWORD expected_colors[] =
13818 0xffffffff, 0xff000000, 0xffffffff, 0xff000000,
13819 0xff00ff00, 0xff0000ff, 0xff00ffff, 0x00000000,
13820 0xffffff00, 0xffff0000, 0xffff00ff, 0x00000000,
13821 0xff000000, 0xff7f7f7f, 0xffffffff, 0x00000000,
13823 static const DWORD bc7_data[] =
13825 0x3a7b944b, 0x982a5800, 0x9cab4983, 0xc6a09579,
13826 0x5f7f2bfe, 0xa95d98f2, 0x3bfb4c03, 0x8be16a41,
13827 0x8362e6c0, 0x358ed7a2, 0xec3e130b, 0x86cebc86,
13828 0xf045be66, 0x7a16507f, 0xfe9ccc9f, 0x3f103e16,
13829 0x84d466c5, 0xfaf5cb5a, 0x9b9e1859, 0x384589b0,
13830 0x9268b4b8, 0x212b3643, 0x813f853a, 0x4a2bd7c2,
13831 0x1809f3e0, 0xf646d5ef, 0x40e80679, 0x05791fe5,
13832 0x6604e7e5, 0x5c28b55d, 0x1ef211f5, 0x632d47f6,
13834 static const DWORD bc7_expected_colors[] =
13836 0xc1752752, 0xc39859a9, 0xff79c08e, 0xff63bf6c,
13837 0xbf7d2756, 0xb89f3d40, 0xffda3a77, 0xffd08099,
13838 0x415f1f37, 0x43671d3f, 0xffc64758, 0xff57a194,
13839 0x405a2032, 0x39422619, 0xff749b76, 0xffabb879,
13841 static const DWORD expected_colors_3d[] = { 0xffff8000, 0xffff8080, 0x80008000, 0xff8080ff };
13843 if (!init_test_context(&test_context, NULL))
13844 return;
13846 device = test_context.device;
13847 context = test_context.immediate_context;
13849 texture_desc.Width = 4;
13850 texture_desc.Height = 4;
13851 texture_desc.MipLevels = 1;
13852 texture_desc.ArraySize = 1;
13853 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13854 texture_desc.SampleDesc.Count = 1;
13855 texture_desc.SampleDesc.Quality = 0;
13856 texture_desc.Usage = D3D11_USAGE_DEFAULT;
13857 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13858 texture_desc.CPUAccessFlags = 0;
13859 texture_desc.MiscFlags = 0;
13861 resource_data.pSysMem = initial_data;
13862 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
13863 resource_data.SysMemSlicePitch = 0;
13865 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
13866 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
13868 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &ps_srv);
13869 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13871 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
13872 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
13873 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
13874 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
13875 sampler_desc.MipLODBias = 0.0f;
13876 sampler_desc.MaxAnisotropy = 0;
13877 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
13878 sampler_desc.BorderColor[0] = 0.0f;
13879 sampler_desc.BorderColor[1] = 0.0f;
13880 sampler_desc.BorderColor[2] = 0.0f;
13881 sampler_desc.BorderColor[3] = 0.0f;
13882 sampler_desc.MinLOD = 0.0f;
13883 sampler_desc.MaxLOD = 0.0f;
13885 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
13886 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
13888 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
13889 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13891 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
13892 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
13893 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13895 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
13896 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
13898 draw_quad(&test_context);
13899 check_texture_color(test_context.backbuffer, 0x00000000, 0);
13901 set_box(&box, 1, 1, 0, 3, 3, 1);
13902 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13903 bitmap_data, 4 * sizeof(*bitmap_data), 0);
13904 set_box(&box, 0, 3, 0, 3, 4, 1);
13905 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13906 &bitmap_data[6], 4 * sizeof(*bitmap_data), 0);
13907 set_box(&box, 0, 0, 0, 4, 1, 1);
13908 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13909 &bitmap_data[10], 4 * sizeof(*bitmap_data), 0);
13910 set_box(&box, 0, 1, 0, 1, 3, 1);
13911 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13912 &bitmap_data[2], sizeof(*bitmap_data), 0);
13913 set_box(&box, 4, 4, 0, 3, 1, 1);
13914 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13915 bitmap_data, sizeof(*bitmap_data), 0);
13916 set_box(&box, 0, 0, 0, 4, 4, 0);
13917 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, &box,
13918 bitmap_data, 4 * sizeof(*bitmap_data), 0);
13919 draw_quad(&test_context);
13920 get_texture_readback(test_context.backbuffer, 0, &rb);
13921 for (i = 0; i < 4; ++i)
13923 for (j = 0; j < 4; ++j)
13925 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13926 ok(compare_color(color, expected_colors[j + i * 4], 1),
13927 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13928 color, j, i, expected_colors[j + i * 4]);
13931 release_resource_readback(&rb);
13933 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture, 0, NULL,
13934 bitmap_data, 4 * sizeof(*bitmap_data), 0);
13935 draw_quad(&test_context);
13936 get_texture_readback(test_context.backbuffer, 0, &rb);
13937 for (i = 0; i < 4; ++i)
13939 for (j = 0; j < 4; ++j)
13941 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
13942 ok(compare_color(color, bitmap_data[j + i * 4], 1),
13943 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
13944 color, j, i, bitmap_data[j + i * 4]);
13947 release_resource_readback(&rb);
13949 ID3D11ShaderResourceView_Release(ps_srv);
13950 ID3D11Texture2D_Release(texture);
13951 ID3D11PixelShader_Release(ps);
13953 hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps);
13954 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
13956 texture_desc_3d.Width = 2;
13957 texture_desc_3d.Height = 2;
13958 texture_desc_3d.Depth = 2;
13959 texture_desc_3d.MipLevels = 1;
13960 texture_desc_3d.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
13961 texture_desc_3d.Usage = D3D11_USAGE_DEFAULT;
13962 texture_desc_3d.BindFlags = D3D11_BIND_SHADER_RESOURCE;
13963 texture_desc_3d.CPUAccessFlags = 0;
13964 texture_desc_3d.MiscFlags = 0;
13966 resource_data.SysMemPitch = texture_desc_3d.Width * sizeof(*initial_data);
13967 resource_data.SysMemSlicePitch = texture_desc_3d.Width * texture_desc_3d.Height * sizeof(*initial_data);
13969 hr = ID3D11Device_CreateTexture3D(device, &texture_desc_3d, &resource_data, &texture_3d);
13970 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
13972 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture_3d, NULL, &ps_srv);
13973 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
13975 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
13976 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
13978 set_box(&box, 0, 0, 0, 1, 2, 1);
13979 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data, 8, 16);
13980 set_box(&box, 0, 0, 0, 1, 1, 2);
13981 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 4, 16, 32);
13982 set_box(&box, 1, 0, 0, 2, 1, 2);
13983 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 8, 4, 0);
13984 set_box(&box, 0, 0, 1, 2, 1, 2);
13985 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 2, 4, 5);
13986 set_box(&box, 0, 0, 1, 2, 1, 2);
13987 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data + 3, 12, 0);
13988 set_box(&box, 1, 1, 0, 2, 2, 2);
13989 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bitmap_data, 0, 32);
13991 draw_quad(&test_context);
13992 get_texture_readback(test_context.backbuffer, 0, &rb);
13993 for (i = 0; i < 2; ++i)
13995 for (j = 0; j < 2; ++j)
13997 color = get_readback_color(&rb, 160 + j * 320, 120 + i * 240, 0);
13998 ok(compare_color(color, expected_colors_3d[j + i * 2], 1),
13999 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14000 color, j, i, expected_colors_3d[j + i * 2]);
14003 release_resource_readback(&rb);
14004 ID3D11ShaderResourceView_Release(ps_srv);
14005 ID3D11Texture3D_Release(texture_3d);
14007 texture_desc_3d.Width = 8;
14008 texture_desc_3d.Height = 8;
14009 texture_desc_3d.Depth = 2;
14010 texture_desc_3d.Format = DXGI_FORMAT_BC7_UNORM;
14012 resource_data.SysMemPitch = 32;
14013 resource_data.SysMemSlicePitch = 64;
14015 hr = ID3D11Device_CreateTexture3D(device, &texture_desc_3d, &resource_data, &texture_3d);
14016 if (FAILED(hr))
14018 skip("Failed to create BC7 3d texture, hr %#x.\n", hr);
14020 else
14022 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture_3d, NULL, &ps_srv);
14023 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14025 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14026 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14028 set_box(&box, 0, 0, 0, 8, 8, 2);
14029 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data, 32, 64);
14030 set_box(&box, 0, 0, 1, 8, 8, 2);
14031 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data, 16, 0);
14032 set_box(&box, 0, 0, 0, 4, 4, 1);
14033 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 8, 0, 0);
14034 set_box(&box, 4, 4, 0, 8, 8, 2);
14035 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 16, 0, 16);
14036 set_box(&box, 0, 4, 1, 8, 8, 2);
14037 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 1, 4, 32);
14038 set_box(&box, 4, 0, 0, 8, 4, 2);
14039 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)texture_3d, 0, &box, bc7_data + 2, 0, 1);
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, 70 + j * 160, 50 + i * 120, 0);
14048 ok(compare_color(color, bc7_expected_colors[j + i * 4], 1),
14049 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14050 color, j, i, bc7_expected_colors[j + i * 4]);
14053 release_resource_readback(&rb);
14054 ID3D11ShaderResourceView_Release(ps_srv);
14055 ID3D11Texture3D_Release(texture_3d);
14058 ID3D11PixelShader_Release(ps);
14059 ID3D11SamplerState_Release(sampler_state);
14060 release_test_context(&test_context);
14063 static void test_copy_subresource_region(void)
14065 ID3D11Texture2D *dst_texture, *src_texture;
14066 struct d3d11_test_context test_context;
14067 ID3D11Buffer *dst_buffer, *src_buffer;
14068 D3D11_SUBRESOURCE_DATA resource_data;
14069 D3D11_TEXTURE2D_DESC texture_desc;
14070 ID3D11SamplerState *sampler_state;
14071 ID3D11ShaderResourceView *ps_srv;
14072 D3D11_SAMPLER_DESC sampler_desc;
14073 ID3D11DeviceContext1 *context1;
14074 ID3D11DeviceContext *context;
14075 struct vec4 float_colors[16];
14076 struct resource_readback rb;
14077 ID3D11PixelShader *ps;
14078 ID3D11Device *device;
14079 unsigned int i, j;
14080 D3D11_BOX box;
14081 DWORD color;
14082 HRESULT hr;
14084 static const DWORD ps_code[] =
14086 #if 0
14087 Texture2D t;
14088 SamplerState s;
14090 float4 main(float4 position : SV_POSITION) : SV_Target
14092 float2 p;
14094 p.x = position.x / 640.0f;
14095 p.y = position.y / 480.0f;
14096 return t.Sample(s, p);
14098 #endif
14099 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
14100 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14101 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14102 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14103 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
14104 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
14105 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14106 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
14107 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
14108 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
14110 static const DWORD ps_buffer_code[] =
14112 #if 0
14113 float4 buffer[16];
14115 float4 main(float4 position : SV_POSITION) : SV_TARGET
14117 float2 p = (float2)4;
14118 p *= float2(position.x / 640.0f, position.y / 480.0f);
14119 return buffer[(int)p.y * 4 + (int)p.x];
14121 #endif
14122 0x43425844, 0x57e7139f, 0x4f0c9e52, 0x598b77e3, 0x5a239132, 0x00000001, 0x0000016c, 0x00000003,
14123 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14124 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
14125 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14126 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000d0, 0x00000040,
14127 0x00000034, 0x04000859, 0x00208e46, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000,
14128 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0a000038, 0x00100032,
14129 0x00000000, 0x00101516, 0x00000000, 0x00004002, 0x3c088889, 0x3bcccccd, 0x00000000, 0x00000000,
14130 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x07000029, 0x00100012, 0x00000000,
14131 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x0700001e, 0x00100012, 0x00000000, 0x0010000a,
14132 0x00000000, 0x0010001a, 0x00000000, 0x07000036, 0x001020f2, 0x00000000, 0x04208e46, 0x00000000,
14133 0x0010000a, 0x00000000, 0x0100003e,
14135 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
14136 static const DWORD initial_data[16] = {0};
14137 static const DWORD bitmap_data[] =
14139 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14140 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14141 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14142 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14144 static const DWORD expected_colors[] =
14146 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14147 0xffffff00, 0xff0000ff, 0xff00ffff, 0x00000000,
14148 0xff7f7f7f, 0xffff0000, 0xffff00ff, 0xff7f7f7f,
14149 0xffffffff, 0xffffffff, 0xff000000, 0x00000000,
14152 if (!init_test_context(&test_context, NULL))
14153 return;
14155 device = test_context.device;
14156 context = test_context.immediate_context;
14158 texture_desc.Width = 4;
14159 texture_desc.Height = 4;
14160 texture_desc.MipLevels = 1;
14161 texture_desc.ArraySize = 1;
14162 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14163 texture_desc.SampleDesc.Count = 1;
14164 texture_desc.SampleDesc.Quality = 0;
14165 texture_desc.Usage = D3D11_USAGE_DEFAULT;
14166 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14167 texture_desc.CPUAccessFlags = 0;
14168 texture_desc.MiscFlags = 0;
14170 resource_data.pSysMem = initial_data;
14171 resource_data.SysMemPitch = texture_desc.Width * sizeof(*initial_data);
14172 resource_data.SysMemSlicePitch = 0;
14174 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
14175 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14177 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
14179 resource_data.pSysMem = bitmap_data;
14180 resource_data.SysMemPitch = texture_desc.Width * sizeof(*bitmap_data);
14181 resource_data.SysMemSlicePitch = 0;
14183 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
14184 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14186 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &ps_srv);
14187 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
14189 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14190 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14191 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14192 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14193 sampler_desc.MipLODBias = 0.0f;
14194 sampler_desc.MaxAnisotropy = 0;
14195 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14196 sampler_desc.BorderColor[0] = 0.0f;
14197 sampler_desc.BorderColor[1] = 0.0f;
14198 sampler_desc.BorderColor[2] = 0.0f;
14199 sampler_desc.BorderColor[3] = 0.0f;
14200 sampler_desc.MinLOD = 0.0f;
14201 sampler_desc.MaxLOD = 0.0f;
14203 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
14204 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14206 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14207 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14209 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14210 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14211 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14213 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
14215 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14216 1, 1, 0, NULL, 0, &box);
14217 ID3D11DeviceContext_CopySubresourceRegion(context, NULL, 0,
14218 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14220 set_box(&box, 0, 0, 0, 2, 2, 1);
14221 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14222 1, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14223 set_box(&box, 1, 2, 0, 4, 3, 1);
14224 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14225 0, 3, 0, (ID3D11Resource *)src_texture, 0, &box);
14226 set_box(&box, 0, 3, 0, 4, 4, 1);
14227 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14228 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14229 set_box(&box, 3, 0, 0, 4, 2, 1);
14230 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14231 0, 1, 0, (ID3D11Resource *)src_texture, 0, &box);
14232 set_box(&box, 3, 1, 0, 4, 2, 1);
14233 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14234 3, 2, 0, (ID3D11Resource *)src_texture, 0, &box);
14235 set_box(&box, 0, 0, 0, 4, 4, 0);
14236 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14237 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14238 draw_quad(&test_context);
14239 get_texture_readback(test_context.backbuffer, 0, &rb);
14240 for (i = 0; i < 4; ++i)
14242 for (j = 0; j < 4; ++j)
14244 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14245 ok(compare_color(color, expected_colors[j + i * 4], 1),
14246 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14247 color, j, i, expected_colors[j + i * 4]);
14250 release_resource_readback(&rb);
14252 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14253 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL);
14254 draw_quad(&test_context);
14255 get_texture_readback(test_context.backbuffer, 0, &rb);
14256 for (i = 0; i < 4; ++i)
14258 for (j = 0; j < 4; ++j)
14260 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14261 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14262 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14263 color, j, i, bitmap_data[j + i * 4]);
14266 release_resource_readback(&rb);
14268 hr = ID3D11DeviceContext_QueryInterface(context, &IID_ID3D11DeviceContext1, (void **)&context1);
14269 ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */,
14270 "Failed to query ID3D11DeviceContext1, hr %#x.\n", hr);
14272 if (SUCCEEDED(hr))
14274 ID3D11DeviceContext1_ClearRenderTargetView(context1, test_context.backbuffer_rtv, red);
14275 check_texture_color(test_context.backbuffer, 0x800000ff, 2);
14277 memset(float_colors, 0, sizeof(float_colors));
14278 for (i = 0; i < texture_desc.Width; ++i)
14279 ((unsigned int *)float_colors)[i] = 0x45454545;
14281 ID3D11DeviceContext1_UpdateSubresource1(context1, (ID3D11Resource *)dst_texture, 0, NULL,
14282 float_colors, 0, 0, 0);
14283 draw_quad(&test_context);
14284 check_texture_color(test_context.backbuffer, 0x45454545, 1);
14286 ID3D11DeviceContext1_CopySubresourceRegion1(context1, (ID3D11Resource *)dst_texture, 0,
14287 0, 0, 0, (ID3D11Resource *)src_texture, 0, NULL, 0);
14288 draw_quad(&test_context);
14290 get_texture_readback(test_context.backbuffer, 0, &rb);
14291 for (i = 0; i < 4; ++i)
14293 for (j = 0; j < 4; ++j)
14295 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14296 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14297 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14298 color, j, i, bitmap_data[j + i * 4]);
14301 release_resource_readback(&rb);
14303 ID3D11DeviceContext1_Release(context1);
14307 ID3D11PixelShader_Release(ps);
14308 hr = ID3D11Device_CreatePixelShader(device, ps_buffer_code, sizeof(ps_buffer_code), NULL, &ps);
14309 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
14311 ID3D11ShaderResourceView_Release(ps_srv);
14312 ps_srv = NULL;
14314 ID3D11SamplerState_Release(sampler_state);
14315 sampler_state = NULL;
14317 ID3D11Texture2D_Release(dst_texture);
14318 ID3D11Texture2D_Release(src_texture);
14320 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &ps_srv);
14321 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14322 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14324 memset(float_colors, 0, sizeof(float_colors));
14325 dst_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(float_colors), float_colors);
14326 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &dst_buffer);
14328 src_buffer = create_buffer(device, 0, 256 * sizeof(*float_colors), NULL);
14330 for (i = 0; i < 4; ++i)
14332 for (j = 0; j < 4; ++j)
14334 float_colors[j + i * 4].x = ((bitmap_data[j + i * 4] >> 0) & 0xff) / 255.0f;
14335 float_colors[j + i * 4].y = ((bitmap_data[j + i * 4] >> 8) & 0xff) / 255.0f;
14336 float_colors[j + i * 4].z = ((bitmap_data[j + i * 4] >> 16) & 0xff) / 255.0f;
14337 float_colors[j + i * 4].w = ((bitmap_data[j + i * 4] >> 24) & 0xff) / 255.0f;
14340 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
14341 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, &box, float_colors, 0, 0);
14343 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 1);
14344 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14345 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14346 draw_quad(&test_context);
14347 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14349 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 0);
14350 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14351 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14352 draw_quad(&test_context);
14353 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14355 set_box(&box, 0, 0, 0, sizeof(float_colors), 0, 0);
14356 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14357 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14358 draw_quad(&test_context);
14359 check_texture_color(test_context.backbuffer, 0x00000000, 0);
14361 set_box(&box, 0, 0, 0, sizeof(float_colors), 1, 1);
14362 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_buffer, 0,
14363 0, 0, 0, (ID3D11Resource *)src_buffer, 0, &box);
14364 draw_quad(&test_context);
14365 get_texture_readback(test_context.backbuffer, 0, &rb);
14366 for (i = 0; i < 4; ++i)
14368 for (j = 0; j < 4; ++j)
14370 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14371 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14372 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14373 color, j, i, bitmap_data[j + i * 4]);
14376 release_resource_readback(&rb);
14378 ID3D11Buffer_Release(dst_buffer);
14379 ID3D11Buffer_Release(src_buffer);
14380 ID3D11PixelShader_Release(ps);
14381 release_test_context(&test_context);
14384 static void test_copy_subresource_region_1d(void)
14386 D3D11_SUBRESOURCE_DATA resource_data[4];
14387 struct d3d11_test_context test_context;
14388 D3D11_TEXTURE1D_DESC texture1d_desc;
14389 D3D11_TEXTURE2D_DESC texture2d_desc;
14390 ID3D11DeviceContext *context;
14391 struct resource_readback rb;
14392 ID3D11Texture1D *texture1d;
14393 ID3D11Texture2D *texture2d;
14394 ID3D11Device *device;
14395 unsigned int i, j;
14396 D3D11_BOX box;
14397 DWORD color;
14398 HRESULT hr;
14400 static const DWORD bitmap_data[] =
14402 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14403 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14404 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14405 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14408 if (!init_test_context(&test_context, NULL))
14409 return;
14410 device = test_context.device;
14411 context = test_context.immediate_context;
14413 texture1d_desc.Width = 4;
14414 texture1d_desc.MipLevels = 1;
14415 texture1d_desc.ArraySize = 4;
14416 texture1d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14417 texture1d_desc.Usage = D3D11_USAGE_DEFAULT;
14418 texture1d_desc.BindFlags = 0;
14419 texture1d_desc.CPUAccessFlags = 0;
14420 texture1d_desc.MiscFlags = 0;
14422 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14424 resource_data[i].pSysMem = &bitmap_data[4 * i];
14425 resource_data[i].SysMemPitch = texture1d_desc.Width * sizeof(bitmap_data);
14426 resource_data[i].SysMemSlicePitch = 0;
14429 hr = ID3D11Device_CreateTexture1D(device, &texture1d_desc, resource_data, &texture1d);
14430 ok(hr == S_OK, "Failed to create 1d texture, hr %#x.\n", hr);
14432 texture2d_desc.Width = 4;
14433 texture2d_desc.Height = 4;
14434 texture2d_desc.MipLevels = 1;
14435 texture2d_desc.ArraySize = 1;
14436 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14437 texture2d_desc.SampleDesc.Count = 1;
14438 texture2d_desc.SampleDesc.Quality = 0;
14439 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
14440 texture2d_desc.BindFlags = 0;
14441 texture2d_desc.CPUAccessFlags = 0;
14442 texture2d_desc.MiscFlags = 0;
14444 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14445 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
14447 set_box(&box, 0, 0, 0, 4, 1, 1);
14448 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14450 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2d, 0,
14451 0, i, 0, (ID3D11Resource *)texture1d, i, &box);
14454 get_texture_readback(texture2d, 0, &rb);
14455 for (i = 0; i < 4; ++i)
14457 for (j = 0; j < 4; ++j)
14459 color = get_readback_color(&rb, j, i, 0);
14460 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14461 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14462 color, j, i, bitmap_data[j + i * 4]);
14465 release_resource_readback(&rb);
14467 get_texture1d_readback(texture1d, 0, &rb);
14468 for (i = 0; i < texture1d_desc.Width; ++i)
14470 color = get_readback_color(&rb, i, 0, 0);
14471 ok(compare_color(color, bitmap_data[i], 1),
14472 "Got color 0x%08x at %u, expected 0x%08x.\n",
14473 color, i, bitmap_data[i]);
14475 release_resource_readback(&rb);
14477 ID3D11Texture1D_Release(texture1d);
14478 ID3D11Texture2D_Release(texture2d);
14479 release_test_context(&test_context);
14482 static void test_copy_subresource_region_3d(void)
14484 ID3D11ShaderResourceView *dst_srv, *src_srv;
14485 ID3D11Texture3D *dst_texture, *src_texture;
14486 D3D11_SUBRESOURCE_DATA resource_data[4];
14487 struct d3d11_test_context test_context;
14488 D3D11_TEXTURE2D_DESC texture2d_desc;
14489 D3D11_TEXTURE3D_DESC texture3d_desc;
14490 ID3D11SamplerState *sampler_state;
14491 D3D11_SAMPLER_DESC sampler_desc;
14492 ID3D11DeviceContext *context;
14493 struct resource_readback rb;
14494 ID3D11Texture2D *texture2d;
14495 ID3D11PixelShader *ps;
14496 ID3D11Device *device;
14497 unsigned int i, j;
14498 DWORD data[4][16];
14499 D3D11_BOX box;
14500 DWORD color;
14501 HRESULT hr;
14503 static const DWORD ps_code[] =
14505 #if 0
14506 Texture3D t;
14507 SamplerState s;
14509 float4 main(float4 position : SV_POSITION) : SV_Target
14511 return t.Sample(s, position.xyz / float3(640, 480, 1));
14513 #endif
14514 0x43425844, 0x27b15ae8, 0xbebf46f7, 0x6cd88d8d, 0x5118de51, 0x00000001, 0x00000134, 0x00000003,
14515 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
14516 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000070f, 0x505f5653, 0x5449534f, 0x004e4f49,
14517 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
14518 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
14519 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
14520 0x04002064, 0x00101072, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
14521 0x00000001, 0x0a000038, 0x00100072, 0x00000000, 0x00101246, 0x00000000, 0x00004002, 0x3acccccd,
14522 0x3b088889, 0x3f800000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000,
14523 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
14525 static const DWORD bitmap_data[] =
14527 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
14528 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
14529 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
14530 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
14533 if (!init_test_context(&test_context, NULL))
14534 return;
14535 device = test_context.device;
14536 context = test_context.immediate_context;
14538 texture3d_desc.Width = 4;
14539 texture3d_desc.Height = 4;
14540 texture3d_desc.Depth = 4;
14541 texture3d_desc.MipLevels = 1;
14542 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14543 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
14544 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14545 texture3d_desc.CPUAccessFlags = 0;
14546 texture3d_desc.MiscFlags = 0;
14548 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &src_texture);
14549 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
14550 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &dst_texture);
14551 ok(hr == S_OK, "Failed to create 3d texture, hr %#x.\n", hr);
14553 texture2d_desc.Width = 4;
14554 texture2d_desc.Height = 4;
14555 texture2d_desc.MipLevels = 1;
14556 texture2d_desc.ArraySize = 4;
14557 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14558 texture2d_desc.SampleDesc.Count = 1;
14559 texture2d_desc.SampleDesc.Quality = 0;
14560 texture2d_desc.Usage = D3D11_USAGE_IMMUTABLE;
14561 texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
14562 texture2d_desc.CPUAccessFlags = 0;
14563 texture2d_desc.MiscFlags = 0;
14565 for (i = 0; i < ARRAY_SIZE(*data); ++i)
14567 data[0][i] = 0xff0000ff;
14568 data[1][i] = bitmap_data[i];
14569 data[2][i] = 0xff00ff00;
14570 data[3][i] = 0xffff00ff;
14573 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14575 resource_data[i].pSysMem = data[i];
14576 resource_data[i].SysMemPitch = texture2d_desc.Width * sizeof(data[0][0]);
14577 resource_data[i].SysMemSlicePitch = 0;
14580 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, resource_data, &texture2d);
14581 ok(hr == S_OK, "Failed to create 2d texture, hr %#x.\n", hr);
14583 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)src_texture, NULL, &src_srv);
14584 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
14585 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dst_texture, NULL, &dst_srv);
14586 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
14588 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
14589 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
14590 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
14591 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
14592 sampler_desc.MipLODBias = 0.0f;
14593 sampler_desc.MaxAnisotropy = 0;
14594 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
14595 sampler_desc.BorderColor[0] = 0.0f;
14596 sampler_desc.BorderColor[1] = 0.0f;
14597 sampler_desc.BorderColor[2] = 0.0f;
14598 sampler_desc.BorderColor[3] = 0.0f;
14599 sampler_desc.MinLOD = 0.0f;
14600 sampler_desc.MaxLOD = 0.0f;
14602 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
14603 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
14605 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
14606 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
14608 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &src_srv);
14609 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
14610 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
14612 set_box(&box, 0, 0, 0, 4, 4, 1);
14613 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14615 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
14616 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
14618 draw_quad(&test_context);
14619 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14620 draw_quad_z(&test_context, 0.25f);
14621 get_texture_readback(test_context.backbuffer, 0, &rb);
14622 for (i = 0; i < 4; ++i)
14624 for (j = 0; j < 4; ++j)
14626 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14627 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14628 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14629 color, j, i, bitmap_data[j + i * 4]);
14632 release_resource_readback(&rb);
14633 draw_quad_z(&test_context, 0.5f);
14634 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14635 draw_quad_z(&test_context, 1.0f);
14636 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
14638 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &dst_srv);
14640 set_box(&box, 0, 0, 0, 4, 4, 2);
14641 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14642 0, 0, 2, (ID3D11Resource *)src_texture, 0, &box);
14643 set_box(&box, 0, 0, 2, 4, 4, 4);
14644 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
14645 0, 0, 0, (ID3D11Resource *)src_texture, 0, &box);
14647 set_box(&box, 0, 0, 0, 4, 4, 1);
14648 for (i = 0; i < ARRAY_SIZE(resource_data); ++i)
14650 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)src_texture, 0,
14651 0, 0, i, (ID3D11Resource *)texture2d, i, &box);
14653 draw_quad(&test_context);
14654 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
14655 draw_quad_z(&test_context, 0.25f);
14656 check_texture_color(test_context.backbuffer, 0xffff00ff, 1);
14657 draw_quad_z(&test_context, 0.5f);
14658 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
14659 draw_quad_z(&test_context, 1.0f);
14660 get_texture_readback(test_context.backbuffer, 0, &rb);
14661 for (i = 0; i < 4; ++i)
14663 for (j = 0; j < 4; ++j)
14665 color = get_readback_color(&rb, 80 + j * 160, 60 + i * 120, 0);
14666 ok(compare_color(color, bitmap_data[j + i * 4], 1),
14667 "Got color 0x%08x at (%u, %u), expected 0x%08x.\n",
14668 color, j, i, bitmap_data[j + i * 4]);
14671 release_resource_readback(&rb);
14673 ID3D11PixelShader_Release(ps);
14674 ID3D11SamplerState_Release(sampler_state);
14675 ID3D11ShaderResourceView_Release(dst_srv);
14676 ID3D11ShaderResourceView_Release(src_srv);
14677 ID3D11Texture2D_Release(texture2d);
14678 ID3D11Texture3D_Release(dst_texture);
14679 ID3D11Texture3D_Release(src_texture);
14680 release_test_context(&test_context);
14683 static void test_resource_map(void)
14685 D3D11_MAPPED_SUBRESOURCE mapped_subresource;
14686 D3D11_TEXTURE3D_DESC texture3d_desc;
14687 D3D11_TEXTURE2D_DESC texture2d_desc;
14688 D3D11_BUFFER_DESC buffer_desc;
14689 ID3D11DeviceContext *context;
14690 ID3D11Texture3D *texture3d;
14691 ID3D11Texture2D *texture2d;
14692 ID3D11Buffer *buffer;
14693 ID3D11Device *device;
14694 ULONG refcount;
14695 HRESULT hr;
14696 DWORD data;
14698 if (!(device = create_device(NULL)))
14700 skip("Failed to create device.\n");
14701 return;
14704 ID3D11Device_GetImmediateContext(device, &context);
14706 buffer_desc.ByteWidth = 1024;
14707 buffer_desc.Usage = D3D11_USAGE_STAGING;
14708 buffer_desc.BindFlags = 0;
14709 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14710 buffer_desc.MiscFlags = 0;
14711 buffer_desc.StructureByteStride = 0;
14713 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
14714 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
14716 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14717 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14719 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14720 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14721 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
14722 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14723 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
14724 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14725 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
14727 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14728 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14729 ok(SUCCEEDED(hr), "Failed to map buffer, hr %#x.\n", hr);
14730 ok(mapped_subresource.RowPitch == 1024, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14731 ok(mapped_subresource.DepthPitch == 1024, "Got unexpected depth pitch %u.\n", mapped_subresource.DepthPitch);
14732 data = *((DWORD *)mapped_subresource.pData);
14733 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14734 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)buffer, 0);
14736 refcount = ID3D11Buffer_Release(buffer);
14737 ok(!refcount, "Buffer has %u references left.\n", refcount);
14739 texture2d_desc.Width = 512;
14740 texture2d_desc.Height = 512;
14741 texture2d_desc.MipLevels = 1;
14742 texture2d_desc.ArraySize = 1;
14743 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14744 texture2d_desc.SampleDesc.Count = 1;
14745 texture2d_desc.SampleDesc.Quality = 0;
14746 texture2d_desc.Usage = D3D11_USAGE_STAGING;
14747 texture2d_desc.BindFlags = 0;
14748 texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14749 texture2d_desc.MiscFlags = 0;
14751 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
14752 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
14754 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14755 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14757 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14758 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14759 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14760 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14761 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
14762 mapped_subresource.DepthPitch);
14763 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14764 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
14766 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14767 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture2d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14768 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14769 ok(mapped_subresource.RowPitch == 4 * 512, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14770 ok(mapped_subresource.DepthPitch == 4 * 512 * 512, "Got unexpected depth pitch %u.\n",
14771 mapped_subresource.DepthPitch);
14772 data = *((DWORD *)mapped_subresource.pData);
14773 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14774 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture2d, 0);
14776 refcount = ID3D11Texture2D_Release(texture2d);
14777 ok(!refcount, "2D texture has %u references left.\n", refcount);
14779 texture3d_desc.Width = 64;
14780 texture3d_desc.Height = 64;
14781 texture3d_desc.Depth = 64;
14782 texture3d_desc.MipLevels = 1;
14783 texture3d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
14784 texture3d_desc.Usage = D3D11_USAGE_STAGING;
14785 texture3d_desc.BindFlags = 0;
14786 texture3d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
14787 texture3d_desc.MiscFlags = 0;
14789 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
14790 ok(SUCCEEDED(hr), "Failed to create 3d texture, hr %#x.\n", hr);
14792 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 1, D3D11_MAP_READ, 0, &mapped_subresource);
14793 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
14795 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14796 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_WRITE, 0, &mapped_subresource);
14797 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14798 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14799 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
14800 mapped_subresource.DepthPitch);
14801 *((DWORD *)mapped_subresource.pData) = 0xdeadbeef;
14802 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
14804 memset(&mapped_subresource, 0, sizeof(mapped_subresource));
14805 hr = ID3D11DeviceContext_Map(context, (ID3D11Resource *)texture3d, 0, D3D11_MAP_READ, 0, &mapped_subresource);
14806 ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr);
14807 ok(mapped_subresource.RowPitch == 4 * 64, "Got unexpected row pitch %u.\n", mapped_subresource.RowPitch);
14808 ok(mapped_subresource.DepthPitch == 4 * 64 * 64, "Got unexpected depth pitch %u.\n",
14809 mapped_subresource.DepthPitch);
14810 data = *((DWORD *)mapped_subresource.pData);
14811 ok(data == 0xdeadbeef, "Got unexpected data %#x.\n", data);
14812 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)texture3d, 0);
14814 refcount = ID3D11Texture3D_Release(texture3d);
14815 ok(!refcount, "3D texture has %u references left.\n", refcount);
14817 ID3D11DeviceContext_Release(context);
14819 refcount = ID3D11Device_Release(device);
14820 ok(!refcount, "Device has %u references left.\n", refcount);
14823 #define check_resource_cpu_access(a, b, c, d, e) check_resource_cpu_access_(__LINE__, a, b, c, d, e)
14824 static void check_resource_cpu_access_(unsigned int line, ID3D11DeviceContext *context,
14825 ID3D11Resource *resource, D3D11_USAGE usage, UINT bind_flags, UINT cpu_access)
14827 BOOL cpu_write = cpu_access & D3D11_CPU_ACCESS_WRITE;
14828 BOOL cpu_read = cpu_access & D3D11_CPU_ACCESS_READ;
14829 BOOL dynamic = usage == D3D11_USAGE_DYNAMIC;
14830 D3D11_MAPPED_SUBRESOURCE map_desc;
14831 HRESULT hr, expected_hr;
14832 ID3D11Device *device;
14834 expected_hr = cpu_read ? S_OK : E_INVALIDARG;
14835 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ, 0, &map_desc);
14836 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ.\n", hr);
14837 if (SUCCEEDED(hr))
14838 ID3D11DeviceContext_Unmap(context, resource, 0);
14840 /* WRITE_DISCARD and WRITE_NO_OVERWRITE are the only allowed options for dynamic resources. */
14841 expected_hr = !dynamic && cpu_write ? S_OK : E_INVALIDARG;
14842 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE, 0, &map_desc);
14843 todo_wine_if(dynamic && cpu_write)
14844 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE.\n", hr);
14845 if (SUCCEEDED(hr))
14846 ID3D11DeviceContext_Unmap(context, resource, 0);
14848 expected_hr = cpu_read && cpu_write ? S_OK : E_INVALIDARG;
14849 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
14850 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for READ_WRITE.\n", hr);
14851 if (SUCCEEDED(hr))
14852 ID3D11DeviceContext_Unmap(context, resource, 0);
14854 expected_hr = dynamic ? S_OK : E_INVALIDARG;
14855 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
14856 todo_wine_if(!dynamic && cpu_write)
14857 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x for WRITE_DISCARD.\n", hr);
14858 if (SUCCEEDED(hr))
14859 ID3D11DeviceContext_Unmap(context, resource, 0);
14861 if (!dynamic)
14862 return;
14864 ID3D11DeviceContext_GetDevice(context, &device);
14866 /* WRITE_NO_OVERWRITE is supported only for buffers. */
14867 expected_hr = is_buffer(resource) ? S_OK : E_INVALIDARG;
14868 hr = ID3D11DeviceContext_Map(context, resource, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
14869 /* D3D11.1 is required for constant and shader buffers. */
14870 todo_wine_if(expected_hr != S_OK)
14871 ok_(__FILE__, line)(hr == expected_hr
14872 || broken(bind_flags & (D3D11_BIND_CONSTANT_BUFFER | D3D11_BIND_SHADER_RESOURCE)),
14873 "Got hr %#x for WRITE_NO_OVERWRITE.\n", hr);
14874 if (SUCCEEDED(hr))
14875 ID3D11DeviceContext_Unmap(context, resource, 0);
14877 ID3D11Device_Release(device);
14880 static void test_resource_access(const D3D_FEATURE_LEVEL feature_level)
14882 D3D11_TEXTURE2D_DESC texture_desc;
14883 struct device_desc device_desc;
14884 D3D11_BUFFER_DESC buffer_desc;
14885 ID3D11DeviceContext *context;
14886 D3D11_SUBRESOURCE_DATA data;
14887 ID3D11Resource *resource;
14888 BOOL required_cpu_access;
14889 BOOL cpu_write, cpu_read;
14890 HRESULT hr, expected_hr;
14891 UINT allowed_cpu_access;
14892 BOOL broken_validation;
14893 ID3D11Device *device;
14894 unsigned int i;
14895 ULONG refcount;
14897 static const struct
14899 D3D11_USAGE usage;
14900 UINT bind_flags;
14901 BOOL is_valid;
14902 UINT allowed_cpu_access;
14904 tests[] =
14906 /* Default resources cannot be written by CPU. */
14907 {D3D11_USAGE_DEFAULT, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
14908 {D3D11_USAGE_DEFAULT, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
14909 {D3D11_USAGE_DEFAULT, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
14910 {D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
14911 {D3D11_USAGE_DEFAULT, D3D11_BIND_STREAM_OUTPUT, TRUE, 0},
14912 {D3D11_USAGE_DEFAULT, D3D11_BIND_RENDER_TARGET, TRUE, 0},
14913 {D3D11_USAGE_DEFAULT, D3D11_BIND_DEPTH_STENCIL, TRUE, 0},
14914 {D3D11_USAGE_DEFAULT, D3D11_BIND_UNORDERED_ACCESS, TRUE, 0},
14916 /* Immutable resources cannot be written by CPU and GPU. */
14917 {D3D11_USAGE_IMMUTABLE, 0, FALSE, 0},
14918 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_VERTEX_BUFFER, TRUE, 0},
14919 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_INDEX_BUFFER, TRUE, 0},
14920 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_CONSTANT_BUFFER, TRUE, 0},
14921 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_SHADER_RESOURCE, TRUE, 0},
14922 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
14923 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_RENDER_TARGET, FALSE, 0},
14924 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
14925 {D3D11_USAGE_IMMUTABLE, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
14927 /* Dynamic resources cannot be written by GPU. */
14928 {D3D11_USAGE_DYNAMIC, 0, FALSE, D3D11_CPU_ACCESS_WRITE},
14929 {D3D11_USAGE_DYNAMIC, D3D11_BIND_VERTEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
14930 {D3D11_USAGE_DYNAMIC, D3D11_BIND_INDEX_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
14931 {D3D11_USAGE_DYNAMIC, D3D11_BIND_CONSTANT_BUFFER, TRUE, D3D11_CPU_ACCESS_WRITE},
14932 {D3D11_USAGE_DYNAMIC, D3D11_BIND_SHADER_RESOURCE, TRUE, D3D11_CPU_ACCESS_WRITE},
14933 {D3D11_USAGE_DYNAMIC, D3D11_BIND_STREAM_OUTPUT, FALSE, D3D11_CPU_ACCESS_WRITE},
14934 {D3D11_USAGE_DYNAMIC, D3D11_BIND_RENDER_TARGET, FALSE, D3D11_CPU_ACCESS_WRITE},
14935 {D3D11_USAGE_DYNAMIC, D3D11_BIND_DEPTH_STENCIL, FALSE, D3D11_CPU_ACCESS_WRITE},
14936 {D3D11_USAGE_DYNAMIC, D3D11_BIND_UNORDERED_ACCESS, FALSE, D3D11_CPU_ACCESS_WRITE},
14938 /* Staging resources support only data transfer. */
14939 {D3D11_USAGE_STAGING, 0, TRUE, D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ},
14940 {D3D11_USAGE_STAGING, D3D11_BIND_VERTEX_BUFFER, FALSE, 0},
14941 {D3D11_USAGE_STAGING, D3D11_BIND_INDEX_BUFFER, FALSE, 0},
14942 {D3D11_USAGE_STAGING, D3D11_BIND_CONSTANT_BUFFER, FALSE, 0},
14943 {D3D11_USAGE_STAGING, D3D11_BIND_SHADER_RESOURCE, FALSE, 0},
14944 {D3D11_USAGE_STAGING, D3D11_BIND_STREAM_OUTPUT, FALSE, 0},
14945 {D3D11_USAGE_STAGING, D3D11_BIND_RENDER_TARGET, FALSE, 0},
14946 {D3D11_USAGE_STAGING, D3D11_BIND_DEPTH_STENCIL, FALSE, 0},
14947 {D3D11_USAGE_STAGING, D3D11_BIND_UNORDERED_ACCESS, FALSE, 0},
14950 device_desc.feature_level = &feature_level;
14951 device_desc.flags = 0;
14952 if (!(device = create_device(&device_desc)))
14954 skip("Failed to create device for feature level %#x.\n", feature_level);
14955 return;
14957 ID3D11Device_GetImmediateContext(device, &context);
14959 data.SysMemPitch = 0;
14960 data.SysMemSlicePitch = 0;
14961 data.pSysMem = heap_alloc(10240);
14962 ok(!!data.pSysMem, "Failed to allocate memory.\n");
14964 for (i = 0; i < ARRAY_SIZE(tests); ++i)
14966 switch (tests[i].bind_flags)
14968 case D3D11_BIND_DEPTH_STENCIL:
14969 continue;
14971 case D3D11_BIND_SHADER_RESOURCE:
14972 case D3D11_BIND_STREAM_OUTPUT:
14973 case D3D11_BIND_RENDER_TARGET:
14974 if (feature_level < D3D_FEATURE_LEVEL_10_0)
14975 continue;
14976 break;
14978 case D3D11_BIND_UNORDERED_ACCESS:
14979 if (feature_level < D3D_FEATURE_LEVEL_11_0)
14980 continue;
14981 break;
14983 default:
14984 break;
14987 allowed_cpu_access = tests[i].allowed_cpu_access;
14988 if (feature_level >= D3D_FEATURE_LEVEL_11_0 && is_d3d11_2_runtime(device)
14989 && tests[i].usage == D3D11_USAGE_DEFAULT
14990 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
14991 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS))
14992 allowed_cpu_access |= D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
14994 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
14995 cpu_write = allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
14996 cpu_read = allowed_cpu_access & D3D11_CPU_ACCESS_READ;
14998 buffer_desc.ByteWidth = 1024;
14999 buffer_desc.Usage = tests[i].usage;
15000 buffer_desc.BindFlags = tests[i].bind_flags;
15001 buffer_desc.MiscFlags = 0;
15002 buffer_desc.StructureByteStride = 0;
15004 buffer_desc.CPUAccessFlags = 0;
15005 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
15006 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15007 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15008 if (SUCCEEDED(hr))
15010 check_resource_cpu_access(context, resource,
15011 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15012 ID3D11Resource_Release(resource);
15015 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
15016 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
15017 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15018 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15019 if (SUCCEEDED(hr))
15021 check_resource_cpu_access(context, resource,
15022 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15023 ID3D11Resource_Release(resource);
15026 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
15027 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
15028 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15029 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15030 if (SUCCEEDED(hr))
15032 check_resource_cpu_access(context, resource,
15033 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15034 ID3D11Resource_Release(resource);
15037 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
15038 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
15039 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, (ID3D11Buffer **)&resource);
15040 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15041 if (SUCCEEDED(hr))
15043 check_resource_cpu_access(context, resource,
15044 buffer_desc.Usage, buffer_desc.BindFlags, buffer_desc.CPUAccessFlags);
15045 ID3D11Resource_Release(resource);
15049 data.SysMemPitch = 16;
15051 for (i = 0; i < ARRAY_SIZE(tests); ++i)
15053 switch (tests[i].bind_flags)
15055 case D3D11_BIND_VERTEX_BUFFER:
15056 case D3D11_BIND_INDEX_BUFFER:
15057 case D3D11_BIND_CONSTANT_BUFFER:
15058 case D3D11_BIND_STREAM_OUTPUT:
15059 continue;
15061 case D3D11_BIND_UNORDERED_ACCESS:
15062 if (feature_level < D3D_FEATURE_LEVEL_11_0)
15063 continue;
15064 break;
15066 default:
15067 break;
15070 broken_validation = tests[i].usage == D3D11_USAGE_DEFAULT
15071 && (tests[i].bind_flags == D3D11_BIND_SHADER_RESOURCE
15072 || tests[i].bind_flags == D3D11_BIND_RENDER_TARGET
15073 || tests[i].bind_flags == D3D11_BIND_UNORDERED_ACCESS);
15075 required_cpu_access = tests[i].usage == D3D11_USAGE_DYNAMIC || tests[i].usage == D3D11_USAGE_STAGING;
15076 cpu_write = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_WRITE;
15077 cpu_read = tests[i].allowed_cpu_access & D3D11_CPU_ACCESS_READ;
15079 texture_desc.Width = 4;
15080 texture_desc.Height = 4;
15081 texture_desc.MipLevels = 1;
15082 texture_desc.ArraySize = 1;
15083 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15084 texture_desc.SampleDesc.Count = 1;
15085 texture_desc.SampleDesc.Quality = 0;
15086 texture_desc.Usage = tests[i].usage;
15087 texture_desc.BindFlags = tests[i].bind_flags;
15088 texture_desc.MiscFlags = 0;
15089 if (tests[i].bind_flags == D3D11_BIND_DEPTH_STENCIL)
15090 texture_desc.Format = DXGI_FORMAT_D16_UNORM;
15092 texture_desc.CPUAccessFlags = 0;
15093 expected_hr = tests[i].is_valid && !required_cpu_access ? S_OK : E_INVALIDARG;
15094 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15095 ok(hr == expected_hr, "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15096 if (SUCCEEDED(hr))
15098 check_resource_cpu_access(context, resource,
15099 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15100 ID3D11Resource_Release(resource);
15103 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
15104 expected_hr = tests[i].is_valid && cpu_write ? S_OK : E_INVALIDARG;
15105 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15106 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15107 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15108 if (SUCCEEDED(hr))
15110 if (broken_validation)
15111 texture_desc.CPUAccessFlags = 0;
15112 check_resource_cpu_access(context, resource,
15113 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15114 ID3D11Resource_Release(resource);
15117 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
15118 expected_hr = tests[i].is_valid && cpu_read ? S_OK : E_INVALIDARG;
15119 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15120 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15121 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15122 if (SUCCEEDED(hr))
15124 if (broken_validation)
15125 texture_desc.CPUAccessFlags = 0;
15126 check_resource_cpu_access(context, resource,
15127 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15128 ID3D11Resource_Release(resource);
15131 texture_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE | D3D11_CPU_ACCESS_READ;
15132 expected_hr = tests[i].is_valid && cpu_write && cpu_read ? S_OK : E_INVALIDARG;
15133 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &data, (ID3D11Texture2D **)&resource);
15134 ok(hr == expected_hr || (hr == S_OK && broken_validation),
15135 "Got hr %#x, expected %#x, test %u.\n", hr, expected_hr, i);
15136 if (SUCCEEDED(hr))
15138 if (broken_validation)
15139 texture_desc.CPUAccessFlags = 0;
15140 check_resource_cpu_access(context, resource,
15141 texture_desc.Usage, texture_desc.BindFlags, texture_desc.CPUAccessFlags);
15142 ID3D11Resource_Release(resource);
15146 heap_free((void *)data.pSysMem);
15148 ID3D11DeviceContext_Release(context);
15149 refcount = ID3D11Device_Release(device);
15150 ok(!refcount, "Device has %u references left.\n", refcount);
15153 static void test_check_multisample_quality_levels(void)
15155 ID3D11Device *device;
15156 UINT quality_levels;
15157 ULONG refcount;
15158 HRESULT hr;
15160 if (!(device = create_device(NULL)))
15162 skip("Failed to create device.\n");
15163 return;
15166 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
15167 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
15168 if (!quality_levels)
15170 skip("Multisampling not supported for DXGI_FORMAT_R8G8B8A8_UNORM, skipping test.\n");
15171 goto done;
15174 quality_levels = 0xdeadbeef;
15175 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_UNKNOWN, 2, &quality_levels);
15176 todo_wine ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15177 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15178 quality_levels = 0xdeadbeef;
15179 hr = ID3D11Device_CheckMultisampleQualityLevels(device, 65536, 2, &quality_levels);
15180 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15181 todo_wine ok(quality_levels == 0xdeadbeef, "Got unexpected quality_levels %u.\n", quality_levels);
15183 if (!enable_debug_layer)
15185 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, NULL);
15186 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15187 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, NULL);
15188 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15189 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, NULL);
15190 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15193 quality_levels = 0xdeadbeef;
15194 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 0, &quality_levels);
15195 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15196 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15198 quality_levels = 0xdeadbeef;
15199 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 1, &quality_levels);
15200 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15201 ok(quality_levels == 1, "Got unexpected quality_levels %u.\n", quality_levels);
15203 quality_levels = 0xdeadbeef;
15204 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 2, &quality_levels);
15205 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15206 ok(quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15208 /* We assume 15 samples multisampling is never supported in practice. */
15209 quality_levels = 0xdeadbeef;
15210 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 15, &quality_levels);
15211 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15212 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15213 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 32, &quality_levels);
15214 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15215 quality_levels = 0xdeadbeef;
15216 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 33, &quality_levels);
15217 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15218 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15219 quality_levels = 0xdeadbeef;
15220 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_UNORM, 64, &quality_levels);
15221 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
15222 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15224 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_BC3_UNORM, 2, &quality_levels);
15225 ok(SUCCEEDED(hr), "Got unexpected hr %#x.\n", hr);
15226 ok(!quality_levels, "Got unexpected quality_levels %u.\n", quality_levels);
15228 done:
15229 refcount = ID3D11Device_Release(device);
15230 ok(!refcount, "Device has %u references left.\n", refcount);
15233 static void test_swapchain_formats(const D3D_FEATURE_LEVEL feature_level)
15235 DXGI_SWAP_CHAIN_DESC swapchain_desc;
15236 struct device_desc device_desc;
15237 IDXGISwapChain *swapchain;
15238 IDXGIDevice *dxgi_device;
15239 HRESULT hr, expected_hr;
15240 IDXGIAdapter *adapter;
15241 IDXGIFactory *factory;
15242 ID3D11Device *device;
15243 unsigned int i;
15244 ULONG refcount;
15246 swapchain_desc.BufferDesc.Width = 800;
15247 swapchain_desc.BufferDesc.Height = 600;
15248 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
15249 swapchain_desc.BufferDesc.RefreshRate.Denominator = 60;
15250 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
15251 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
15252 swapchain_desc.SampleDesc.Count = 1;
15253 swapchain_desc.SampleDesc.Quality = 0;
15254 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
15255 swapchain_desc.BufferCount = 1;
15256 swapchain_desc.OutputWindow = CreateWindowA("static", "d3d11_test", 0, 0, 0, 0, 0, 0, 0, 0, 0);
15257 swapchain_desc.Windowed = TRUE;
15258 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
15259 swapchain_desc.Flags = 0;
15261 device_desc.feature_level = &feature_level;
15262 device_desc.flags = 0;
15263 if (!(device = create_device(&device_desc)))
15265 skip("Failed to create device for feature level %#x.\n", feature_level);
15266 return;
15269 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
15270 ok(SUCCEEDED(hr), "Failed to query IDXGIDevice, hr %#x.\n", hr);
15271 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
15272 ok(SUCCEEDED(hr), "GetAdapter failed, hr %#x.\n", hr);
15273 IDXGIDevice_Release(dxgi_device);
15274 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
15275 ok(SUCCEEDED(hr), "GetParent failed, hr %#x.\n", hr);
15276 IDXGIAdapter_Release(adapter);
15278 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15279 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
15280 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x for typeless format (feature level %#x).\n",
15281 hr, feature_level);
15282 if (SUCCEEDED(hr))
15283 IDXGISwapChain_Release(swapchain);
15285 for (i = 0; i < ARRAY_SIZE(display_format_support); ++i)
15287 DXGI_FORMAT format = display_format_support[i].format;
15288 BOOL todo = FALSE;
15290 if (display_format_support[i].fl_required <= feature_level)
15292 expected_hr = S_OK;
15293 if (format == DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
15294 todo = TRUE;
15296 else if (!display_format_support[i].fl_optional
15297 || display_format_support[i].fl_optional > feature_level)
15299 expected_hr = E_INVALIDARG;
15300 if (format != DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM)
15301 todo = TRUE;
15303 else
15305 continue;
15308 swapchain_desc.BufferDesc.Format = format;
15309 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
15310 todo_wine_if(todo)
15311 ok(hr == expected_hr || broken(hr == E_OUTOFMEMORY),
15312 "Got hr %#x, expected %#x (feature level %#x, format %#x).\n",
15313 hr, expected_hr, feature_level, format);
15314 if (FAILED(hr))
15315 continue;
15316 refcount = IDXGISwapChain_Release(swapchain);
15317 ok(!refcount, "Swapchain has %u references left.\n", refcount);
15320 refcount = ID3D11Device_Release(device);
15321 ok(!refcount, "Device has %u references left.\n", refcount);
15322 refcount = IDXGIFactory_Release(factory);
15323 ok(!refcount, "Factory has %u references left.\n", refcount);
15324 DestroyWindow(swapchain_desc.OutputWindow);
15327 static void test_swapchain_views(void)
15329 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
15330 struct d3d11_test_context test_context;
15331 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15332 ID3D11ShaderResourceView *srv;
15333 ID3D11DeviceContext *context;
15334 ID3D11RenderTargetView *rtv;
15335 ID3D11Device *device;
15336 ULONG refcount;
15337 HRESULT hr;
15339 static const struct vec4 color = {0.2f, 0.3f, 0.5f, 1.0f};
15341 if (!init_test_context(&test_context, NULL))
15342 return;
15344 device = test_context.device;
15345 context = test_context.immediate_context;
15347 refcount = get_refcount(test_context.backbuffer);
15348 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
15350 draw_color_quad(&test_context, &color);
15351 check_texture_color(test_context.backbuffer, 0xff7f4c33, 1);
15353 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15354 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15355 U(rtv_desc).Texture2D.MipSlice = 0;
15356 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)test_context.backbuffer, &rtv_desc, &rtv);
15357 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15358 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
15360 refcount = get_refcount(test_context.backbuffer);
15361 ok(refcount == 1, "Got unexpected refcount %u.\n", refcount);
15363 draw_color_quad(&test_context, &color);
15364 check_texture_color(test_context.backbuffer, 0xffbc957c, 1);
15366 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15367 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
15368 U(srv_desc).Texture2D.MostDetailedMip = 0;
15369 U(srv_desc).Texture2D.MipLevels = 1;
15370 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)test_context.backbuffer, &srv_desc, &srv);
15371 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15372 if (SUCCEEDED(hr))
15373 ID3D11ShaderResourceView_Release(srv);
15375 ID3D11RenderTargetView_Release(rtv);
15376 release_test_context(&test_context);
15379 static void test_swapchain_flip(void)
15381 ID3D11Texture2D *backbuffer_0, *backbuffer_1, *backbuffer_2, *offscreen;
15382 ID3D11ShaderResourceView *backbuffer_0_srv, *backbuffer_1_srv;
15383 ID3D11RenderTargetView *backbuffer_0_rtv, *offscreen_rtv;
15384 D3D11_TEXTURE2D_DESC texture_desc;
15385 ID3D11InputLayout *input_layout;
15386 ID3D11DeviceContext *context;
15387 unsigned int stride, offset;
15388 struct swapchain_desc desc;
15389 IDXGISwapChain *swapchain;
15390 ID3D11VertexShader *vs;
15391 ID3D11PixelShader *ps;
15392 ID3D11Device *device;
15393 ID3D11Buffer *vb;
15394 ULONG refcount;
15395 DWORD color;
15396 HWND window;
15397 HRESULT hr;
15398 RECT rect;
15400 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
15402 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
15404 static const DWORD vs_code[] =
15406 #if 0
15407 float4 main(float4 position : POSITION) : SV_POSITION
15409 return position;
15411 #endif
15412 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
15413 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15414 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
15415 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
15416 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
15417 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
15418 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
15421 static const DWORD ps_code[] =
15423 #if 0
15424 Texture2D t0, t1;
15425 SamplerState s;
15427 float4 main(float4 position : SV_POSITION) : SV_Target
15429 float2 p;
15431 p.x = 0.5;
15432 p.y = 0.5;
15433 if (position.x < 320)
15434 return t0.Sample(s, p);
15435 return t1.Sample(s, p);
15437 #endif
15438 0x43425844, 0xc00961ea, 0x48558efd, 0x5eec7aed, 0xb597e6d1, 0x00000001, 0x00000188, 0x00000003,
15439 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
15440 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x5449534f, 0x004e4f49,
15441 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
15442 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ec, 0x00000040,
15443 0x0000003b, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
15444 0x04001858, 0x00107000, 0x00000001, 0x00005555, 0x04002064, 0x00101012, 0x00000000, 0x00000001,
15445 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x07000031, 0x00100012, 0x00000000,
15446 0x0010100a, 0x00000000, 0x00004001, 0x43a00000, 0x0304001f, 0x0010000a, 0x00000000, 0x0c000045,
15447 0x001020f2, 0x00000000, 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46,
15448 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x01000015, 0x0c000045, 0x001020f2, 0x00000000,
15449 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000,
15450 0x00000000, 0x0100003e,
15452 static const struct vec2 quad[] =
15454 {-1.0f, -1.0f},
15455 {-1.0f, 1.0f},
15456 { 1.0f, -1.0f},
15457 { 1.0f, 1.0f},
15459 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
15460 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15461 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
15463 if (!(device = create_device(NULL)))
15465 skip("Failed to create device, skipping tests.\n");
15466 return;
15468 SetRect(&rect, 0, 0, 640, 480);
15469 AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_VISIBLE, FALSE);
15470 window = CreateWindowA("static", "d3d11_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
15471 0, 0, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, NULL, NULL);
15472 desc.buffer_count = 3;
15473 desc.width = desc.height = 0;
15474 desc.swap_effect = DXGI_SWAP_EFFECT_SEQUENTIAL;
15475 desc.windowed = TRUE;
15476 desc.flags = SWAPCHAIN_FLAG_SHADER_INPUT;
15477 swapchain = create_swapchain(device, window, &desc);
15479 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer_0);
15480 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15481 hr = IDXGISwapChain_GetBuffer(swapchain, 1, &IID_ID3D11Texture2D, (void **)&backbuffer_1);
15482 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15483 hr = IDXGISwapChain_GetBuffer(swapchain, 2, &IID_ID3D11Texture2D, (void **)&backbuffer_2);
15484 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
15486 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_rtv);
15487 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15488 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_0, NULL, &backbuffer_0_srv);
15489 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15490 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)backbuffer_1, NULL, &backbuffer_1_srv);
15491 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
15493 ID3D11Texture2D_GetDesc(backbuffer_0, &texture_desc);
15494 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
15495 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
15496 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
15497 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
15499 ID3D11Texture2D_GetDesc(backbuffer_1, &texture_desc);
15500 ok((texture_desc.BindFlags & (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE))
15501 == (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE),
15502 "Got unexpected bind flags %x.\n", texture_desc.BindFlags);
15503 ok(texture_desc.Usage == D3D11_USAGE_DEFAULT, "Got unexpected usage %u.\n", texture_desc.Usage);
15505 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer_1, NULL, &offscreen_rtv);
15506 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
15507 if (SUCCEEDED(hr))
15508 ID3D11RenderTargetView_Release(offscreen_rtv);
15510 ID3D11Device_GetImmediateContext(device, &context);
15512 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &backbuffer_0_srv);
15513 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &backbuffer_1_srv);
15515 texture_desc.Width = 640;
15516 texture_desc.Height = 480;
15517 texture_desc.MipLevels = 1;
15518 texture_desc.ArraySize = 1;
15519 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15520 texture_desc.SampleDesc.Count = 1;
15521 texture_desc.SampleDesc.Quality = 0;
15522 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15523 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15524 texture_desc.CPUAccessFlags = 0;
15525 texture_desc.MiscFlags = 0;
15526 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &offscreen);
15527 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
15528 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)offscreen, NULL, &offscreen_rtv);
15529 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
15530 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &offscreen_rtv, NULL);
15531 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
15533 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
15535 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
15536 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
15537 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
15538 vs_code, sizeof(vs_code), &input_layout);
15539 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
15540 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
15541 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
15542 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
15543 stride = sizeof(*quad);
15544 offset = 0;
15545 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
15547 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
15548 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
15549 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
15551 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, red);
15553 ID3D11DeviceContext_Draw(context, 4, 0);
15554 color = get_texture_color(offscreen, 120, 240);
15555 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15557 /* DXGI moves buffers in the same direction as earlier versions. Buffer 2
15558 * becomes buffer 1, buffer 1 becomes the new buffer 0, and buffer 0
15559 * becomes buffer n - 1. However, only buffer 0 can be rendered to.
15561 * What is this good for? I don't know. Ad-hoc tests suggest that
15562 * Present() always waits for the next V-sync interval, even if there are
15563 * still untouched buffers. Buffer 0 is the buffer that is shown on the
15564 * screen, just like in <= d3d9. Present() also doesn't discard buffers if
15565 * rendering finishes before the V-sync interval is over. I haven't found
15566 * any productive use for more than one buffer. */
15567 IDXGISwapChain_Present(swapchain, 0, 0);
15569 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, green);
15571 ID3D11DeviceContext_Draw(context, 4, 0);
15572 color = get_texture_color(offscreen, 120, 240); /* green, buf 0 */
15573 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15574 /* Buffer 1 is still untouched. */
15576 color = get_texture_color(backbuffer_0, 320, 240); /* green */
15577 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15578 color = get_texture_color(backbuffer_2, 320, 240); /* red */
15579 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15581 IDXGISwapChain_Present(swapchain, 0, 0);
15583 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_0_rtv, blue);
15585 ID3D11DeviceContext_Draw(context, 4, 0);
15586 color = get_texture_color(offscreen, 120, 240); /* blue, buf 0 */
15587 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
15588 color = get_texture_color(offscreen, 360, 240); /* red, buf 1 */
15589 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15591 color = get_texture_color(backbuffer_0, 320, 240); /* blue */
15592 ok(compare_color(color, 0x7fff0000, 1), "Got unexpected color 0x%08x.\n", color);
15593 color = get_texture_color(backbuffer_1, 320, 240); /* red */
15594 ok(compare_color(color, 0x7f0000ff, 1), "Got unexpected color 0x%08x.\n", color);
15595 color = get_texture_color(backbuffer_2, 320, 240); /* green */
15596 ok(compare_color(color, 0x7f00ff00, 1), "Got unexpected color 0x%08x.\n", color);
15598 ID3D11VertexShader_Release(vs);
15599 ID3D11PixelShader_Release(ps);
15600 ID3D11Buffer_Release(vb);
15601 ID3D11InputLayout_Release(input_layout);
15602 ID3D11ShaderResourceView_Release(backbuffer_0_srv);
15603 ID3D11ShaderResourceView_Release(backbuffer_1_srv);
15604 ID3D11RenderTargetView_Release(backbuffer_0_rtv);
15605 ID3D11RenderTargetView_Release(offscreen_rtv);
15606 ID3D11Texture2D_Release(offscreen);
15607 ID3D11Texture2D_Release(backbuffer_0);
15608 ID3D11Texture2D_Release(backbuffer_1);
15609 ID3D11Texture2D_Release(backbuffer_2);
15610 IDXGISwapChain_Release(swapchain);
15612 ID3D11DeviceContext_Release(context);
15613 refcount = ID3D11Device_Release(device);
15614 ok(!refcount, "Device has %u references left.\n", refcount);
15615 DestroyWindow(window);
15618 static void test_clear_render_target_view_1d(void)
15620 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
15621 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15623 struct d3d11_test_context test_context;
15624 D3D11_TEXTURE1D_DESC texture_desc;
15625 ID3D11DeviceContext *context;
15626 ID3D11RenderTargetView *rtv;
15627 ID3D11Texture1D *texture;
15628 ID3D11Device *device;
15629 HRESULT hr;
15631 if (!init_test_context(&test_context, NULL))
15632 return;
15634 device = test_context.device;
15635 context = test_context.immediate_context;
15637 texture_desc.Width = 64;
15638 texture_desc.MipLevels = 1;
15639 texture_desc.ArraySize = 1;
15640 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15641 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15642 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15643 texture_desc.CPUAccessFlags = 0;
15644 texture_desc.MiscFlags = 0;
15645 hr = ID3D11Device_CreateTexture1D(device, &texture_desc, NULL, &texture);
15646 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15648 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15649 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15651 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15652 check_texture1d_color(texture, 0xbf4c7f19, 1);
15654 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15655 check_texture1d_color(texture, 0x8000ff00, 1);
15657 ID3D11RenderTargetView_Release(rtv);
15658 ID3D11Texture1D_Release(texture);
15659 release_test_context(&test_context);
15662 static void test_clear_render_target_view_2d(void)
15664 static const DWORD expected_color = 0xbf4c7f19, expected_srgb_color = 0xbf95bc59;
15665 static const float clear_colour[] = {0.1f, 0.5f, 0.3f, 0.75f};
15666 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15667 static const float blue[] = {0.0f, 0.0f, 1.0f, 0.5f};
15669 ID3D11RenderTargetView *rtv[3], *srgb_rtv;
15670 ID3D11Texture2D *texture, *srgb_texture;
15671 struct d3d11_test_context test_context;
15672 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15673 D3D11_TEXTURE2D_DESC texture_desc;
15674 ID3D11DeviceContext *context;
15675 struct resource_readback rb;
15676 ID3D11Device *device;
15677 unsigned int i, j;
15678 DWORD colour;
15679 HRESULT hr;
15681 if (!init_test_context(&test_context, NULL))
15682 return;
15684 device = test_context.device;
15685 context = test_context.immediate_context;
15687 texture_desc.Width = 640;
15688 texture_desc.Height = 480;
15689 texture_desc.MipLevels = 1;
15690 texture_desc.ArraySize = 1;
15691 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15692 texture_desc.SampleDesc.Count = 1;
15693 texture_desc.SampleDesc.Quality = 0;
15694 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15695 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15696 texture_desc.CPUAccessFlags = 0;
15697 texture_desc.MiscFlags = 0;
15698 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15699 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15701 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15702 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &srgb_texture);
15703 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15705 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv[0]);
15706 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15708 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)srgb_texture, NULL, &srgb_rtv);
15709 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15711 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, clear_colour);
15712 check_texture_color(test_context.backbuffer, expected_color, 1);
15714 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], clear_colour);
15715 check_texture_color(texture, expected_color, 1);
15717 if (!enable_debug_layer)
15718 ID3D11DeviceContext_ClearRenderTargetView(context, NULL, green);
15719 check_texture_color(texture, expected_color, 1);
15721 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, clear_colour);
15722 check_texture_color(srgb_texture, expected_srgb_color, 1);
15724 ID3D11RenderTargetView_Release(srgb_rtv);
15725 ID3D11RenderTargetView_Release(rtv[0]);
15726 ID3D11Texture2D_Release(srgb_texture);
15727 ID3D11Texture2D_Release(texture);
15729 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15730 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15731 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15733 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15734 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15735 U(rtv_desc).Texture2D.MipSlice = 0;
15736 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &srgb_rtv);
15737 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15739 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15740 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
15741 U(rtv_desc).Texture2D.MipSlice = 0;
15742 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[0]);
15743 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15745 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], clear_colour);
15746 check_texture_color(texture, expected_color, 1);
15748 ID3D11DeviceContext_ClearRenderTargetView(context, srgb_rtv, clear_colour);
15749 get_texture_readback(texture, 0, &rb);
15750 for (i = 0; i < 4; ++i)
15752 for (j = 0; j < 4; ++j)
15754 BOOL broken_device = is_warp_device(device) || is_nvidia_device(device);
15755 colour = get_readback_color(&rb, 80 + i * 160, 60 + j * 120, 0);
15756 ok(compare_color(colour, expected_srgb_color, 1)
15757 || broken(compare_color(colour, expected_color, 1) && broken_device),
15758 "Got unexpected colour 0x%08x.\n", colour);
15761 release_resource_readback(&rb);
15763 ID3D11RenderTargetView_Release(srgb_rtv);
15764 ID3D11RenderTargetView_Release(rtv[0]);
15765 ID3D11Texture2D_Release(texture);
15767 texture_desc.Width = 16;
15768 texture_desc.Height = 16;
15769 texture_desc.ArraySize = 5;
15770 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
15771 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15773 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
15774 U(rtv_desc).Texture2DArray.MipSlice = 0;
15775 U(rtv_desc).Texture2DArray.FirstArraySlice = 0;
15776 U(rtv_desc).Texture2DArray.ArraySize = 5;
15777 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[0]);
15778 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15780 U(rtv_desc).Texture2DArray.FirstArraySlice = 1;
15781 U(rtv_desc).Texture2DArray.ArraySize = 3;
15782 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[1]);
15783 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15785 U(rtv_desc).Texture2DArray.FirstArraySlice = 2;
15786 U(rtv_desc).Texture2DArray.ArraySize = 1;
15787 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv[2]);
15788 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
15790 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[0], blue);
15791 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[1], green);
15792 ID3D11DeviceContext_ClearRenderTargetView(context, rtv[2], clear_colour);
15794 get_texture_readback(texture, 0, &rb);
15795 colour = get_readback_color(&rb, 8, 8, 0);
15796 ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
15797 release_resource_readback(&rb);
15799 get_texture_readback(texture, 1, &rb);
15800 colour = get_readback_color(&rb, 8, 8, 0);
15801 ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
15802 release_resource_readback(&rb);
15804 get_texture_readback(texture, 2, &rb);
15805 colour = get_readback_color(&rb, 8, 8, 0);
15806 ok(compare_color(colour, 0xbf4c7f19, 1), "Got unexpected colour 0x%08x.\n", colour);
15807 release_resource_readback(&rb);
15809 get_texture_readback(texture, 3, &rb);
15810 colour = get_readback_color(&rb, 8, 8, 0);
15811 ok(compare_color(colour, 0x8000ff00, 1), "Got unexpected colour 0x%08x.\n", colour);
15812 release_resource_readback(&rb);
15814 get_texture_readback(texture, 4, &rb);
15815 colour = get_readback_color(&rb, 8, 8, 0);
15816 ok(compare_color(colour, 0x80ff0000, 1), "Got unexpected colour 0x%08x.\n", colour);
15817 release_resource_readback(&rb);
15819 ID3D11RenderTargetView_Release(rtv[2]);
15820 ID3D11RenderTargetView_Release(rtv[1]);
15821 ID3D11RenderTargetView_Release(rtv[0]);
15822 ID3D11Texture2D_Release(texture);
15824 release_test_context(&test_context);
15827 static void test_clear_render_target_view_3d(void)
15829 static const float color[] = {0.1f, 0.5f, 0.3f, 0.75f};
15830 static const float green[] = {0.0f, 1.0f, 0.0f, 0.5f};
15832 struct d3d11_test_context test_context;
15833 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
15834 D3D11_TEXTURE3D_DESC texture_desc;
15835 ID3D11DeviceContext *context;
15836 ID3D11RenderTargetView *rtv;
15837 ID3D11Texture3D *texture;
15838 ID3D11Device *device;
15839 HRESULT hr;
15841 if (!init_test_context(&test_context, NULL))
15842 return;
15843 device = test_context.device;
15844 context = test_context.immediate_context;
15846 texture_desc.Width = 8;
15847 texture_desc.Height = 8;
15848 texture_desc.Depth = 4;
15849 texture_desc.MipLevels = 1;
15850 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
15851 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15852 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
15853 texture_desc.CPUAccessFlags = 0;
15854 texture_desc.MiscFlags = 0;
15855 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
15856 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15858 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
15859 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15861 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15862 check_texture3d_color(texture, 0xbf4c7f19, 1);
15863 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15864 check_texture3d_color(texture, 0x8000ff00, 1);
15866 ID3D11RenderTargetView_Release(rtv);
15867 ID3D11Texture3D_Release(texture);
15869 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
15870 hr = ID3D11Device_CreateTexture3D(device, &texture_desc, NULL, &texture);
15871 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
15873 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
15874 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
15875 U(rtv_desc).Texture3D.MipSlice = 0;
15876 U(rtv_desc).Texture3D.FirstWSlice = 0;
15877 U(rtv_desc).Texture3D.WSize = ~0u;
15878 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, &rtv_desc, &rtv);
15879 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
15881 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, color);
15882 check_texture3d_color(texture, 0xbf95bc59, 1);
15883 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, green);
15884 check_texture3d_color(texture, 0x8000ff00, 1);
15886 ID3D11RenderTargetView_Release(rtv);
15887 ID3D11Texture3D_Release(texture);
15888 release_test_context(&test_context);
15891 static void test_clear_depth_stencil_view(void)
15893 D3D11_TEXTURE2D_DESC texture_desc;
15894 ID3D11Texture2D *depth_texture;
15895 ID3D11DeviceContext *context;
15896 ID3D11DepthStencilView *dsv;
15897 ID3D11Device *device;
15898 ULONG refcount;
15899 HRESULT hr;
15901 if (!(device = create_device(NULL)))
15903 skip("Failed to create device.\n");
15904 return;
15907 ID3D11Device_GetImmediateContext(device, &context);
15909 texture_desc.Width = 640;
15910 texture_desc.Height = 480;
15911 texture_desc.MipLevels = 1;
15912 texture_desc.ArraySize = 1;
15913 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
15914 texture_desc.SampleDesc.Count = 1;
15915 texture_desc.SampleDesc.Quality = 0;
15916 texture_desc.Usage = D3D11_USAGE_DEFAULT;
15917 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
15918 texture_desc.CPUAccessFlags = 0;
15919 texture_desc.MiscFlags = 0;
15920 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
15921 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
15923 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
15924 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
15926 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
15927 check_texture_float(depth_texture, 1.0f, 0);
15929 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.25f, 0);
15930 check_texture_float(depth_texture, 0.25f, 0);
15932 if (!enable_debug_layer)
15933 ID3D11DeviceContext_ClearDepthStencilView(context, NULL, D3D11_CLEAR_DEPTH, 1.0f, 0);
15934 check_texture_float(depth_texture, 0.25f, 0);
15936 ID3D11Texture2D_Release(depth_texture);
15937 ID3D11DepthStencilView_Release(dsv);
15939 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
15940 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
15941 ok(SUCCEEDED(hr), "Failed to create depth texture, hr %#x.\n", hr);
15943 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
15944 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
15946 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
15947 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
15949 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0xff);
15950 todo_wine check_texture_color(depth_texture, 0xff000000, 0);
15952 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0xff);
15953 check_texture_color(depth_texture, 0xffffffff, 0);
15955 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 0.0f, 0);
15956 check_texture_color(depth_texture, 0x00000000, 0);
15958 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0xff);
15959 todo_wine check_texture_color(depth_texture, 0x00ffffff, 0);
15961 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_STENCIL, 0.0f, 0xff);
15962 check_texture_color(depth_texture, 0xffffffff, 0);
15964 ID3D11Texture2D_Release(depth_texture);
15965 ID3D11DepthStencilView_Release(dsv);
15967 ID3D11DeviceContext_Release(context);
15969 refcount = ID3D11Device_Release(device);
15970 ok(!refcount, "Device has %u references left.\n", refcount);
15973 static unsigned int to_sint8(unsigned int x)
15975 union
15977 signed int s;
15978 unsigned int u;
15979 } bits;
15980 bits.u = x;
15981 return min(max(bits.s, -128), 127) & 0xff;
15984 #define check_rgba_sint8(data, uvec) check_rgba_sint8_(__LINE__, data, uvec)
15985 static void check_rgba_sint8_(unsigned int line, DWORD data, const struct uvec4 *v)
15987 unsigned int x = to_sint8(v->x);
15988 unsigned int y = to_sint8(v->y);
15989 unsigned int z = to_sint8(v->z);
15990 unsigned int w = to_sint8(v->w);
15991 DWORD expected[] =
15993 /* Windows 7 - Nvidia, WARP */
15994 (v->x & 0xff) | (v->y & 0xff) << 8 | (v->z & 0xff) << 16 | (v->w & 0xff) << 24,
15995 /* Windows 10 - AMD */
15996 x | y << 8 | z << 16 | w << 24,
15997 /* Windows 10 - Intel */
15998 x | x << 8 | x << 16 | x << 24,
16001 ok_(__FILE__, line)(data == expected[0] || data == expected[1] || broken(data == expected[2]),
16002 "Got %#x, expected %#x or %#x at %u, uvec4 %#x, %#x, %#x, %#x.\n",
16003 data, expected[0], expected[1], x, v->x, v->y, v->z, v->w);
16006 static void test_clear_buffer_unordered_access_view(void)
16008 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
16009 ID3D11UnorderedAccessView *uav, *uav2;
16010 struct device_desc device_desc;
16011 D3D11_BUFFER_DESC buffer_desc;
16012 ID3D11DeviceContext *context;
16013 struct resource_readback rb;
16014 ID3D11Buffer *buffer;
16015 ID3D11Device *device;
16016 struct uvec4 uvec4;
16017 unsigned int i, x;
16018 ULONG refcount;
16019 HRESULT hr;
16020 RECT rect;
16022 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16023 static const struct uvec4 fe_uvec4 = {0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe};
16024 static const struct uvec4 uvec4_data[] =
16026 {0x00000000, 0x00000000, 0x00000000, 0x00000000},
16028 {0x00000000, 0xffffffff, 0xffffffff, 0xffffffff},
16029 {0xffffffff, 0x00000000, 0x00000000, 0x00000000},
16030 {0x00000000, 0xffffffff, 0x00000000, 0x00000000},
16031 {0x00000000, 0x00000000, 0xffffffff, 0x00000000},
16032 {0x00000000, 0x00000000, 0x00000000, 0xffffffff},
16034 {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff},
16035 {0x80000000, 0x80000000, 0x80000000, 0x80000000},
16036 {0x000000ff, 0x00000080, 0x80000080, 0x00000080},
16037 {0x000000ff, 0x0000007f, 0x000000ef, 0x000000fe},
16038 {0x800000ff, 0x8000007f, 0x800000ef, 0x800000fe},
16039 {0xfefefefe, 0xf0f0f0f0, 0xefefefef, 0x0f0f0f0f},
16040 {0xaaaaaaaa, 0xdeadbeef, 0xdeadbabe, 0xdeadf00d},
16042 {0x00000001, 0x00000002, 0x00000003, 0x00000004},
16043 {0x000000ff, 0x000000fe, 0x000000fd, 0x000000fc},
16044 {0x000000f2, 0x000000f1, 0x000000f0, 0x000000ef},
16045 {0x0000000a, 0x0000000d, 0x0000000e, 0x0000000f},
16046 {0x0000001a, 0x0000002d, 0x0000003e, 0x0000004f},
16047 {0x00000050, 0x00000060, 0x00000070, 0x00000080},
16048 {0x00000090, 0x000000a0, 0x000000b0, 0x000000c0},
16049 {0x000000d0, 0x000000e0, 0x000000f0, 0x000000ff},
16050 {0x00000073, 0x00000077, 0x0000007a, 0x0000007b},
16051 {0x0000007c, 0x0000007d, 0x0000007e, 0x0000007f},
16053 {0x80000001, 0x80000002, 0x80000003, 0x80000004},
16054 {0x800000ff, 0x800000fe, 0x800000fd, 0x800000fc},
16055 {0x800000f2, 0x800000f1, 0x800000f0, 0x800000ef},
16056 {0x8000000a, 0x0000000d, 0x8000000e, 0x8000000f},
16057 {0x8000001a, 0x8000002d, 0x8000003e, 0x8000004f},
16058 {0x80000050, 0x80000060, 0x80000070, 0x00000080},
16059 {0x80000090, 0x800000a0, 0x800000b0, 0x800000c0},
16060 {0x800000d0, 0x800000e0, 0x800000f0, 0x800000ff},
16061 {0x80000073, 0x80000077, 0x8000007a, 0x8000007b},
16062 {0x8000007c, 0x8000007d, 0x8000007e, 0x8000007f},
16064 {0x7fffff01, 0x7fffff02, 0x7fffff03, 0x7fffff04},
16065 {0x7fffffff, 0x7ffffffe, 0x7ffffffd, 0x7ffffffc},
16066 {0x7ffffff2, 0x7ffffff1, 0x7ffffff0, 0x7fffffef},
16067 {0x7fffff0a, 0x7fffff0d, 0x7fffff0e, 0x7fffff0f},
16068 {0x7fffff1a, 0x7fffff2d, 0x7fffff3e, 0x7fffff4f},
16069 {0x7fffff50, 0x7fffff60, 0x7fffff70, 0x7fffff80},
16070 {0x8fffff90, 0x7fffffa0, 0x7fffffb0, 0x7fffffc0},
16071 {0x7fffffd0, 0x7fffffe0, 0x7ffffff0, 0x7fffffff},
16072 {0x7fffff73, 0x7fffff77, 0x7fffff7a, 0x7fffff7b},
16073 {0x7fffff7c, 0x7fffff7d, 0x7fffff7e, 0x7fffff7f},
16075 {0xffffff01, 0xffffff02, 0xffffff03, 0xffffff04},
16076 {0xffffffff, 0xfffffffe, 0xfffffffd, 0xfffffffc},
16077 {0xfffffff2, 0xfffffff1, 0xfffffff0, 0xffffffef},
16078 {0xffffff0a, 0xffffff0d, 0xffffff0e, 0xffffff0f},
16079 {0xffffff1a, 0xffffff2d, 0xffffff3e, 0xffffff4f},
16080 {0xffffff50, 0xffffff60, 0xffffff70, 0xffffff80},
16081 {0xffffff90, 0xffffffa0, 0xffffffb0, 0xffffffc0},
16082 {0xffffffd0, 0xffffffe0, 0xfffffff0, 0xffffffff},
16083 {0xffffff73, 0xffffff77, 0xffffff7a, 0xffffff7b},
16084 {0xffffff7c, 0xffffff7d, 0xffffff7e, 0xffffff7f},
16087 device_desc.feature_level = &feature_level;
16088 device_desc.flags = 0;
16089 if (!(device = create_device(&device_desc)))
16091 skip("Failed to create device for feature level %#x.\n", feature_level);
16092 return;
16095 ID3D11Device_GetImmediateContext(device, &context);
16097 /* Structured buffer views */
16098 buffer_desc.ByteWidth = 64;
16099 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
16100 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16101 buffer_desc.CPUAccessFlags = 0;
16102 buffer_desc.MiscFlags = 0;
16103 buffer_desc.StructureByteStride = 0;
16104 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
16105 buffer_desc.StructureByteStride = 4;
16106 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16107 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16109 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
16110 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16112 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
16113 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16114 U(uav_desc).Buffer.FirstElement = 0;
16115 U(uav_desc).Buffer.NumElements = 4;
16116 U(uav_desc).Buffer.Flags = 0;
16117 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16118 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16120 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16122 uvec4 = uvec4_data[i];
16123 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16124 get_buffer_readback(buffer, &rb);
16125 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16126 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16127 release_resource_readback(&rb);
16129 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16130 get_buffer_readback(buffer, &rb);
16131 SetRect(&rect, 0, 0, U(uav_desc).Buffer.NumElements, 1);
16132 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16133 SetRect(&rect, U(uav_desc).Buffer.NumElements, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16134 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16135 release_resource_readback(&rb);
16138 ID3D11Buffer_Release(buffer);
16139 ID3D11UnorderedAccessView_Release(uav);
16140 ID3D11UnorderedAccessView_Release(uav2);
16142 /* Raw buffer views */
16143 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
16144 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16145 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16147 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
16148 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16149 U(uav_desc).Buffer.FirstElement = 0;
16150 U(uav_desc).Buffer.NumElements = 16;
16151 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
16152 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16153 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16154 U(uav_desc).Buffer.FirstElement = 8;
16155 U(uav_desc).Buffer.NumElements = 8;
16156 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16157 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16159 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16161 uvec4 = uvec4_data[i];
16162 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16163 get_buffer_readback(buffer, &rb);
16164 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16165 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16166 release_resource_readback(&rb);
16168 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16169 get_buffer_readback(buffer, &rb);
16170 SetRect(&rect, 0, 0, U(uav_desc).Buffer.FirstElement, 1);
16171 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16172 SetRect(&rect, U(uav_desc).Buffer.FirstElement, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16173 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16174 release_resource_readback(&rb);
16177 ID3D11Buffer_Release(buffer);
16178 ID3D11UnorderedAccessView_Release(uav);
16179 ID3D11UnorderedAccessView_Release(uav2);
16181 /* Typed buffer views */
16182 buffer_desc.MiscFlags = 0;
16183 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
16184 ok(hr == S_OK, "Failed to create a buffer, hr %#x.\n", hr);
16186 uav_desc.Format = DXGI_FORMAT_R32_SINT;
16187 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16188 U(uav_desc).Buffer.FirstElement = 0;
16189 U(uav_desc).Buffer.NumElements = 16;
16190 U(uav_desc).Buffer.Flags = 0;
16191 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16192 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16193 U(uav_desc).Buffer.FirstElement = 9;
16194 U(uav_desc).Buffer.NumElements = 7;
16195 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16196 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16198 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16200 uvec4 = uvec4_data[i];
16201 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16202 get_buffer_readback(buffer, &rb);
16203 SetRect(&rect, 0, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16204 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16205 release_resource_readback(&rb);
16207 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16208 get_buffer_readback(buffer, &rb);
16209 SetRect(&rect, 0, 0, U(uav_desc).Buffer.FirstElement, 1);
16210 check_readback_data_color(&rb, &rect, uvec4.x, 0);
16211 SetRect(&rect, U(uav_desc).Buffer.FirstElement, 0, buffer_desc.ByteWidth / sizeof(uvec4.x), 1);
16212 check_readback_data_color(&rb, &rect, fe_uvec4.x, 0);
16213 release_resource_readback(&rb);
16216 ID3D11UnorderedAccessView_Release(uav);
16217 ID3D11UnorderedAccessView_Release(uav2);
16219 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_SINT;
16220 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16221 U(uav_desc).Buffer.FirstElement = 0;
16222 U(uav_desc).Buffer.NumElements = 4;
16223 U(uav_desc).Buffer.Flags = 0;
16224 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16225 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16226 U(uav_desc).Buffer.FirstElement = 2;
16227 U(uav_desc).Buffer.NumElements = 2;
16228 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16229 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16231 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16233 const struct uvec4 *data = NULL;
16234 BOOL all_match;
16236 uvec4 = uvec4_data[i];
16237 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16238 get_buffer_readback(buffer, &rb);
16239 for (x = 0, all_match = TRUE; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
16241 const struct uvec4 broken_result = {uvec4.x, uvec4.x, uvec4.x, uvec4.x}; /* Intel */
16242 data = get_readback_uvec4(&rb, x, 0);
16243 if (!(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result))))
16245 all_match = FALSE;
16246 break;
16249 ok(all_match, "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
16250 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, x);
16251 release_resource_readback(&rb);
16253 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16254 get_buffer_readback(buffer, &rb);
16255 for (x = 0, all_match = TRUE; x < buffer_desc.ByteWidth / sizeof(uvec4); ++x)
16257 struct uvec4 broken_result;
16258 data = get_readback_uvec4(&rb, x, 0);
16259 uvec4 = U(uav_desc).Buffer.FirstElement <= x ? fe_uvec4 : uvec4_data[i];
16260 broken_result.x = broken_result.y = broken_result.z = broken_result.w = uvec4.x;
16261 if (!(compare_uvec4(data, &uvec4) || broken(compare_uvec4(data, &broken_result))))
16263 all_match = FALSE;
16264 break;
16267 ok(all_match, "Got {%#x, %#x, %#x, %#x}, expected {%#x, %#x, %#x, %#x} at %u.\n",
16268 data->x, data->y, data->z, data->w, uvec4.x, uvec4.y, uvec4.z, uvec4.w, x);
16269 release_resource_readback(&rb);
16272 uvec4.x = uvec4.y = uvec4.z = uvec4.w = 0xdeadbeef;
16273 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16274 ID3D11UnorderedAccessView_Release(uav);
16275 ID3D11UnorderedAccessView_Release(uav2);
16277 uav_desc.Format = DXGI_FORMAT_R8G8B8A8_SINT;
16278 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
16279 U(uav_desc).Buffer.FirstElement = 0;
16280 U(uav_desc).Buffer.NumElements = 16;
16281 U(uav_desc).Buffer.Flags = 0;
16282 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
16283 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16284 U(uav_desc).Buffer.FirstElement = 8;
16285 U(uav_desc).Buffer.NumElements = 8;
16286 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav2);
16287 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
16289 for (i = 0; i < ARRAY_SIZE(uvec4_data); ++i)
16291 uvec4 = uvec4_data[i];
16292 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, &uvec4.x);
16293 get_buffer_readback(buffer, &rb);
16294 todo_wine check_rgba_sint8(get_readback_color(&rb, 0, 0, 0), &uvec4);
16295 todo_wine check_rgba_sint8(get_readback_color(&rb, 7, 0, 0), &uvec4);
16296 todo_wine check_rgba_sint8(get_readback_color(&rb, 15, 0, 0), &uvec4);
16297 release_resource_readback(&rb);
16299 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, &fe_uvec4.x);
16300 get_buffer_readback(buffer, &rb);
16301 todo_wine check_rgba_sint8(get_readback_color(&rb, 0, 0, 0), &uvec4);
16302 todo_wine check_rgba_sint8(get_readback_color(&rb, U(uav_desc).Buffer.FirstElement - 1, 0, 0), &uvec4);
16303 todo_wine check_rgba_sint8(get_readback_color(&rb, U(uav_desc).Buffer.FirstElement, 0, 0), &fe_uvec4);
16304 release_resource_readback(&rb);
16307 ID3D11UnorderedAccessView_Release(uav);
16308 ID3D11UnorderedAccessView_Release(uav2);
16310 ID3D11Buffer_Release(buffer);
16312 ID3D11DeviceContext_Release(context);
16313 refcount = ID3D11Device_Release(device);
16314 ok(!refcount, "Device has %u references left.\n", refcount);
16317 static void test_initial_depth_stencil_state(void)
16319 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
16320 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
16321 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16322 struct d3d11_test_context test_context;
16323 D3D11_TEXTURE2D_DESC texture_desc;
16324 ID3D11DeviceContext *context;
16325 ID3D11DepthStencilView *dsv;
16326 ID3D11Texture2D *texture;
16327 ID3D11Device *device;
16328 unsigned int count;
16329 D3D11_VIEWPORT vp;
16330 HRESULT hr;
16332 if (!init_test_context(&test_context, NULL))
16333 return;
16335 device = test_context.device;
16336 context = test_context.immediate_context;
16338 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16339 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
16340 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16341 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16342 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16344 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
16345 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16347 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
16349 count = 1;
16350 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
16352 /* check if depth function is D3D11_COMPARISON_LESS */
16353 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16354 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
16355 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.4f);
16356 draw_color_quad(&test_context, &green);
16357 draw_color_quad(&test_context, &red);
16358 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.6f, 0.6f);
16359 draw_color_quad(&test_context, &red);
16360 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
16361 check_texture_float(texture, 0.4f, 1);
16363 ID3D11DepthStencilView_Release(dsv);
16364 ID3D11Texture2D_Release(texture);
16365 release_test_context(&test_context);
16368 static void test_draw_depth_only(void)
16370 struct d3d11_test_context test_context;
16371 ID3D11PixelShader *ps_color, *ps_depth;
16372 D3D11_TEXTURE2D_DESC texture_desc;
16373 ID3D11DeviceContext *context;
16374 ID3D11DepthStencilView *dsv;
16375 struct resource_readback rb;
16376 ID3D11Texture2D *texture;
16377 ID3D11Device *device;
16378 unsigned int i, j;
16379 struct vec4 depth;
16380 ID3D11Buffer *cb;
16381 HRESULT hr;
16383 static const DWORD ps_color_code[] =
16385 #if 0
16386 float4 main(float4 position : SV_POSITION) : SV_Target
16388 return float4(0.0, 1.0, 0.0, 1.0);
16390 #endif
16391 0x43425844, 0x30240e72, 0x012f250c, 0x8673c6ea, 0x392e4cec, 0x00000001, 0x000000d4, 0x00000003,
16392 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16393 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49,
16394 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16395 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
16396 0x0000000e, 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
16397 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
16399 static const DWORD ps_depth_code[] =
16401 #if 0
16402 float depth;
16404 float main() : SV_Depth
16406 return depth;
16408 #endif
16409 0x43425844, 0x91af6cd0, 0x7e884502, 0xcede4f54, 0x6f2c9326, 0x00000001, 0x000000b0, 0x00000003,
16410 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16411 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0xffffffff,
16412 0x00000e01, 0x445f5653, 0x68747065, 0xababab00, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
16413 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x02000065, 0x0000c001, 0x05000036, 0x0000c001,
16414 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
16417 if (!init_test_context(&test_context, NULL))
16418 return;
16420 device = test_context.device;
16421 context = test_context.immediate_context;
16423 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(depth), NULL);
16425 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
16426 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
16427 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
16428 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16429 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16431 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
16432 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
16434 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps_color);
16435 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16436 hr = ID3D11Device_CreatePixelShader(device, ps_depth_code, sizeof(ps_depth_code), NULL, &ps_depth);
16437 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16439 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
16440 ID3D11DeviceContext_PSSetShader(context, ps_color, NULL, 0);
16441 ID3D11DeviceContext_OMSetRenderTargets(context, 0, NULL, dsv);
16443 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16444 check_texture_float(texture, 1.0f, 1);
16445 draw_quad(&test_context);
16446 check_texture_float(texture, 0.0f, 1);
16448 ID3D11DeviceContext_PSSetShader(context, ps_depth, NULL, 0);
16450 depth.x = 0.7f;
16451 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16452 draw_quad(&test_context);
16453 check_texture_float(texture, 0.0f, 1);
16454 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16455 check_texture_float(texture, 1.0f, 1);
16456 draw_quad(&test_context);
16457 check_texture_float(texture, 0.7f, 1);
16458 depth.x = 0.8f;
16459 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16460 draw_quad(&test_context);
16461 check_texture_float(texture, 0.7f, 1);
16462 depth.x = 0.5f;
16463 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16464 draw_quad(&test_context);
16465 check_texture_float(texture, 0.5f, 1);
16467 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
16468 for (i = 0; i < 4; ++i)
16470 for (j = 0; j < 4; ++j)
16472 depth.x = 1.0f / 16.0f * (j + 4 * i);
16473 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &depth, 0, 0);
16475 set_viewport(context, 160.0f * j, 120.0f * i, 160.0f, 120.0f, 0.0f, 1.0f);
16477 draw_quad(&test_context);
16480 get_texture_readback(texture, 0, &rb);
16481 for (i = 0; i < 4; ++i)
16483 for (j = 0; j < 4; ++j)
16485 float obtained_depth, expected_depth;
16487 obtained_depth = get_readback_float(&rb, 80 + j * 160, 60 + i * 120);
16488 expected_depth = 1.0f / 16.0f * (j + 4 * i);
16489 ok(compare_float(obtained_depth, expected_depth, 1),
16490 "Got unexpected depth %.8e at (%u, %u), expected %.8e.\n",
16491 obtained_depth, j, i, expected_depth);
16494 release_resource_readback(&rb);
16496 ID3D11Buffer_Release(cb);
16497 ID3D11PixelShader_Release(ps_color);
16498 ID3D11PixelShader_Release(ps_depth);
16499 ID3D11DepthStencilView_Release(dsv);
16500 ID3D11Texture2D_Release(texture);
16501 release_test_context(&test_context);
16504 static void test_draw_uav_only(void)
16506 struct d3d11_test_context test_context;
16507 D3D11_TEXTURE2D_DESC texture_desc;
16508 ID3D11UnorderedAccessView *uav;
16509 ID3D11DeviceContext *context;
16510 ID3D11Texture2D *texture;
16511 ID3D11PixelShader *ps;
16512 ID3D11Device *device;
16513 HRESULT hr;
16515 static const DWORD ps_code[] =
16517 #if 0
16518 RWTexture2D<int> u;
16520 void main()
16522 InterlockedAdd(u[uint2(0, 0)], 1);
16524 #endif
16525 0x43425844, 0x237a8398, 0xe7b34c17, 0xa28c91a4, 0xb3614d73, 0x00000001, 0x0000009c, 0x00000003,
16526 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
16527 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000048, 0x00000050, 0x00000012, 0x0100086a,
16528 0x0400189c, 0x0011e000, 0x00000000, 0x00003333, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002,
16529 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
16531 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16532 static const UINT values[4] = {0};
16534 if (!init_test_context(&test_context, &feature_level))
16535 return;
16537 device = test_context.device;
16538 context = test_context.immediate_context;
16540 texture_desc.Width = 1;
16541 texture_desc.Height = 1;
16542 texture_desc.MipLevels = 1;
16543 texture_desc.ArraySize = 1;
16544 texture_desc.Format = DXGI_FORMAT_R32_SINT;
16545 texture_desc.SampleDesc.Count = 1;
16546 texture_desc.SampleDesc.Quality = 0;
16547 texture_desc.Usage = D3D11_USAGE_DEFAULT;
16548 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
16549 texture_desc.CPUAccessFlags = 0;
16550 texture_desc.MiscFlags = 0;
16552 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
16553 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16555 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
16556 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
16558 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16559 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16561 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16562 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
16563 0, 1, &uav, NULL);
16565 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
16566 set_viewport(context, 0.0f, 0.0f, 10.0f, 10.0f, 0.0f, 0.0f);
16567 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
16568 draw_quad(&test_context);
16569 check_texture_color(texture, 100, 1);
16571 draw_quad(&test_context);
16572 draw_quad(&test_context);
16573 draw_quad(&test_context);
16574 draw_quad(&test_context);
16575 check_texture_color(texture, 500, 1);
16577 ID3D11PixelShader_Release(ps);
16578 ID3D11Texture2D_Release(texture);
16579 ID3D11UnorderedAccessView_Release(uav);
16580 release_test_context(&test_context);
16583 static void test_cb_relative_addressing(void)
16585 struct d3d11_test_context test_context;
16586 ID3D11Buffer *colors_cb, *index_cb;
16587 unsigned int i, index[4] = {0};
16588 ID3D11DeviceContext *context;
16589 ID3D11PixelShader *ps;
16590 ID3D11Device *device;
16591 HRESULT hr;
16593 static const DWORD vs_code[] =
16595 #if 0
16596 int color_index;
16598 cbuffer colors
16600 float4 colors[8];
16603 struct vs_in
16605 float4 position : POSITION;
16608 struct vs_out
16610 float4 position : SV_POSITION;
16611 float4 color : COLOR;
16614 vs_out main(const vs_in v)
16616 vs_out o;
16618 o.position = v.position;
16619 o.color = colors[color_index];
16621 return o;
16623 #endif
16624 0x43425844, 0xc2eb30bf, 0x2868c855, 0xaa34b609, 0x1f4957d4, 0x00000001, 0x00000164, 0x00000003,
16625 0x0000002c, 0x00000060, 0x000000b4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
16626 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
16627 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
16628 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
16629 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853, 0x000000a8, 0x00010050,
16630 0x0000002a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000859, 0x00208e46,
16631 0x00000001, 0x00000008, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000,
16632 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x05000036, 0x001020f2,
16633 0x00000000, 0x00101e46, 0x00000000, 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
16634 0x00000000, 0x07000036, 0x001020f2, 0x00000001, 0x04208e46, 0x00000001, 0x0010000a, 0x00000000,
16635 0x0100003e,
16637 static const DWORD ps_code[] =
16639 #if 0
16640 struct ps_in
16642 float4 position : SV_POSITION;
16643 float4 color : COLOR;
16646 float4 main(const ps_in v) : SV_TARGET
16648 return v.color;
16650 #endif
16651 0x43425844, 0x1a6def50, 0x9c069300, 0x7cce68f0, 0x621239b9, 0x00000001, 0x000000f8, 0x00000003,
16652 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16653 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
16654 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
16655 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16656 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x58454853, 0x0000003c, 0x00000050,
16657 0x0000000f, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
16658 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
16660 static const struct
16662 float color[4];
16664 colors[10] =
16666 {{0.0f, 0.0f, 0.0f, 1.0f}},
16667 {{0.0f, 0.0f, 1.0f, 0.0f}},
16668 {{0.0f, 0.0f, 1.0f, 1.0f}},
16669 {{0.0f, 1.0f, 0.0f, 0.0f}},
16670 {{0.0f, 1.0f, 0.0f, 1.0f}},
16671 {{0.0f, 1.0f, 1.0f, 0.0f}},
16672 {{0.0f, 1.0f, 1.0f, 1.0f}},
16673 {{1.0f, 0.0f, 0.0f, 0.0f}},
16674 {{1.0f, 0.0f, 0.0f, 1.0f}},
16675 {{1.0f, 0.0f, 1.0f, 0.0f}},
16677 static const struct
16679 unsigned int index;
16680 DWORD expected;
16682 test_data[] =
16684 {0, 0xff000000},
16685 {1, 0x00ff0000},
16686 {2, 0xffff0000},
16687 {3, 0x0000ff00},
16688 {4, 0xff00ff00},
16689 {5, 0x00ffff00},
16690 {6, 0xffffff00},
16691 {7, 0x000000ff},
16693 {8, 0xff0000ff},
16694 {9, 0x00ff00ff},
16696 static const float white_color[] = {1.0f, 1.0f, 1.0f, 1.0f};
16697 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
16699 if (!init_test_context(&test_context, &feature_level))
16700 return;
16702 device = test_context.device;
16703 context = test_context.immediate_context;
16705 colors_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(colors), &colors);
16706 index_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
16708 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16709 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16711 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &index_cb);
16712 ID3D11DeviceContext_VSSetConstantBuffers(context, 1, 1, &colors_cb);
16713 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16715 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
16717 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white_color);
16719 index[0] = test_data[i].index;
16720 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)index_cb, 0, NULL, &index, 0, 0);
16722 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
16723 check_texture_color(test_context.backbuffer, test_data[i].expected, 1);
16726 ID3D11Buffer_Release(index_cb);
16727 ID3D11Buffer_Release(colors_cb);
16728 ID3D11PixelShader_Release(ps);
16730 release_test_context(&test_context);
16733 static void test_vs_input_relative_addressing(void)
16735 struct d3d11_test_context test_context;
16736 ID3D11DeviceContext *context;
16737 unsigned int offset, stride;
16738 unsigned int index[4] = {0};
16739 ID3D11PixelShader *ps;
16740 ID3D11Buffer *vb, *cb;
16741 ID3D11Device *device;
16742 unsigned int i;
16743 HRESULT hr;
16745 static const DWORD vs_code[] =
16747 #if 0
16748 struct vertex
16750 float4 position : POSITION;
16751 float4 colors[4] : COLOR;
16754 uint index;
16756 void main(vertex vin, out float4 position : SV_Position,
16757 out float4 color : COLOR)
16759 position = vin.position;
16760 color = vin.colors[index];
16762 #endif
16763 0x43425844, 0x8623dd89, 0xe37fecf5, 0xea3fdfe1, 0xdf36e4e4, 0x00000001, 0x000001f4, 0x00000003,
16764 0x0000002c, 0x000000c4, 0x00000118, 0x4e475349, 0x00000090, 0x00000005, 0x00000008, 0x00000080,
16765 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000089, 0x00000000, 0x00000000,
16766 0x00000003, 0x00000001, 0x00000f0f, 0x00000089, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
16767 0x00000f0f, 0x00000089, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000f0f, 0x00000089,
16768 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300,
16769 0xab00524f, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
16770 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
16771 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x000000d4,
16772 0x00010040, 0x00000035, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005f, 0x001010f2,
16773 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x0300005f,
16774 0x001010f2, 0x00000003, 0x0300005f, 0x001010f2, 0x00000004, 0x04000067, 0x001020f2, 0x00000000,
16775 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0400005b, 0x001010f2,
16776 0x00000001, 0x00000004, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x06000036,
16777 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x07000036, 0x001020f2, 0x00000001,
16778 0x00d01e46, 0x00000001, 0x0010000a, 0x00000000, 0x0100003e,
16780 static const DWORD ps_code[] =
16782 #if 0
16783 struct vs_out
16785 float4 position : SV_POSITION;
16786 float4 color : COLOR;
16789 float4 main(struct vs_out i) : SV_TARGET
16791 return i.color;
16793 #endif
16794 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
16795 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
16796 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
16797 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
16798 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
16799 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
16800 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
16801 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
16803 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
16805 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
16806 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1},
16807 {"COLOR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 4, D3D11_INPUT_PER_INSTANCE_DATA, 1},
16808 {"COLOR", 2, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 8, D3D11_INPUT_PER_INSTANCE_DATA, 1},
16809 {"COLOR", 3, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 12, D3D11_INPUT_PER_INSTANCE_DATA, 1},
16811 static const unsigned int colors[] = {0xff0000ff, 0xff00ff00, 0xffff0000, 0xff0f0f0f};
16812 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
16814 if (!init_test_context(&test_context, NULL))
16815 return;
16816 device = test_context.device;
16817 context = test_context.immediate_context;
16819 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
16820 vs_code, sizeof(vs_code), &test_context.input_layout);
16821 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
16823 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
16824 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &cb);
16826 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(colors), colors);
16827 stride = sizeof(colors);
16828 offset = 0;
16829 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
16831 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
16832 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
16833 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
16835 for (i = 0; i < ARRAY_SIZE(colors); ++i)
16837 *index = i;
16838 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
16839 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
16840 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
16841 check_texture_color(test_context.backbuffer, colors[i], 1);
16844 ID3D11Buffer_Release(cb);
16845 ID3D11Buffer_Release(vb);
16846 ID3D11PixelShader_Release(ps);
16847 release_test_context(&test_context);
16850 static void test_getdc(void)
16852 static const struct
16854 const char *name;
16855 DXGI_FORMAT format;
16856 BOOL getdc_supported;
16858 testdata[] =
16860 {"B8G8R8A8_UNORM", DXGI_FORMAT_B8G8R8A8_UNORM, TRUE },
16861 {"B8G8R8A8_TYPELESS", DXGI_FORMAT_B8G8R8A8_TYPELESS, TRUE },
16862 {"B8G8R8A8_UNORM_SRGB", DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, TRUE },
16863 {"B8G8R8X8_UNORM", DXGI_FORMAT_B8G8R8X8_UNORM, FALSE },
16864 {"B8G8R8X8_TYPELESS", DXGI_FORMAT_B8G8R8X8_TYPELESS, FALSE },
16865 {"B8G8R8X8_UNORM_SRGB", DXGI_FORMAT_B8G8R8X8_UNORM_SRGB, FALSE },
16867 struct device_desc device_desc;
16868 D3D11_TEXTURE2D_DESC desc;
16869 ID3D11Texture2D *texture;
16870 IDXGISurface1 *surface;
16871 ID3D11Device *device;
16872 unsigned int i;
16873 ULONG refcount;
16874 HRESULT hr;
16875 HDC dc;
16877 device_desc.feature_level = NULL;
16878 device_desc.flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
16879 if (!(device = create_device(&device_desc)))
16881 skip("Failed to create device.\n");
16882 return;
16885 /* Without D3D11_RESOURCE_MISC_GDI_COMPATIBLE. */
16886 desc.Width = 512;
16887 desc.Height = 512;
16888 desc.MipLevels = 1;
16889 desc.ArraySize = 1;
16890 desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
16891 desc.SampleDesc.Count = 1;
16892 desc.SampleDesc.Quality = 0;
16893 desc.Usage = D3D11_USAGE_DEFAULT;
16894 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16895 desc.CPUAccessFlags = 0;
16896 desc.MiscFlags = 0;
16897 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16898 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16900 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
16901 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
16903 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
16904 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
16906 IDXGISurface1_Release(surface);
16907 ID3D11Texture2D_Release(texture);
16909 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
16910 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16911 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16913 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
16914 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
16916 hr = IDXGISurface1_ReleaseDC(surface, NULL);
16917 todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr);
16919 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
16920 ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr);
16922 hr = IDXGISurface1_ReleaseDC(surface, NULL);
16923 ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr);
16925 IDXGISurface1_Release(surface);
16926 ID3D11Texture2D_Release(texture);
16928 for (i = 0; i < ARRAY_SIZE(testdata); ++i)
16930 static const unsigned int bit_count = 32;
16931 unsigned int width_bytes;
16932 DIBSECTION dib;
16933 HBITMAP bitmap;
16934 DWORD type;
16935 int size;
16937 desc.Width = 64;
16938 desc.Height = 64;
16939 desc.MipLevels = 1;
16940 desc.ArraySize = 1;
16941 desc.Format = testdata[i].format;
16942 desc.SampleDesc.Count = 1;
16943 desc.SampleDesc.Quality = 0;
16944 desc.Usage = D3D11_USAGE_STAGING;
16945 desc.BindFlags = 0;
16946 desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
16947 desc.MiscFlags = 0;
16949 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16950 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
16951 ID3D11Texture2D_Release(texture);
16953 /* STAGING usage, requesting GDI compatibility mode. */
16954 desc.MiscFlags = D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
16955 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16956 ok(FAILED(hr), "Expected CreateTexture2D to fail, hr %#x.\n", hr);
16958 desc.Usage = D3D11_USAGE_DEFAULT;
16959 desc.BindFlags = D3D11_BIND_RENDER_TARGET;
16960 desc.CPUAccessFlags = 0;
16961 hr = ID3D11Device_CreateTexture2D(device, &desc, NULL, &texture);
16962 if (testdata[i].getdc_supported)
16963 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
16964 else
16965 ok(FAILED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
16967 if (FAILED(hr))
16968 continue;
16970 hr = ID3D11Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface);
16971 ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr);
16973 dc = (void *)0x1234;
16974 hr = IDXGISurface1_GetDC(surface, FALSE, &dc);
16975 ok(SUCCEEDED(hr), "Got unexpected hr %#x for format %s.\n", hr, testdata[i].name);
16977 if (FAILED(hr))
16979 IDXGISurface1_Release(surface);
16980 ID3D11Texture2D_Release(texture);
16981 continue;
16984 type = GetObjectType(dc);
16985 ok(type == OBJ_MEMDC, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
16986 bitmap = GetCurrentObject(dc, OBJ_BITMAP);
16987 type = GetObjectType(bitmap);
16988 ok(type == OBJ_BITMAP, "Got unexpected object type %#x for format %s.\n", type, testdata[i].name);
16990 size = GetObjectA(bitmap, sizeof(dib), &dib);
16991 ok(size == sizeof(dib) || broken(size == sizeof(dib.dsBm)),
16992 "Got unexpected size %d for format %s.\n", size, testdata[i].name);
16994 ok(!dib.dsBm.bmType, "Got unexpected type %#x for format %s.\n",
16995 dib.dsBm.bmType, testdata[i].name);
16996 ok(dib.dsBm.bmWidth == 64, "Got unexpected width %d for format %s.\n",
16997 dib.dsBm.bmWidth, testdata[i].name);
16998 ok(dib.dsBm.bmHeight == 64, "Got unexpected height %d for format %s.\n",
16999 dib.dsBm.bmHeight, testdata[i].name);
17000 width_bytes = ((dib.dsBm.bmWidth * bit_count + 31) >> 3) & ~3;
17001 ok(dib.dsBm.bmWidthBytes == width_bytes, "Got unexpected width bytes %d for format %s.\n",
17002 dib.dsBm.bmWidthBytes, testdata[i].name);
17003 ok(dib.dsBm.bmPlanes == 1, "Got unexpected plane count %d for format %s.\n",
17004 dib.dsBm.bmPlanes, testdata[i].name);
17005 ok(dib.dsBm.bmBitsPixel == bit_count, "Got unexpected bit count %d for format %s.\n",
17006 dib.dsBm.bmBitsPixel, testdata[i].name);
17008 if (size == sizeof(dib))
17009 ok(!!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
17010 dib.dsBm.bmBits, testdata[i].name);
17011 else
17012 ok(!dib.dsBm.bmBits, "Got unexpected bits %p for format %s.\n",
17013 dib.dsBm.bmBits, testdata[i].name);
17015 if (size == sizeof(dib))
17017 ok(dib.dsBmih.biSize == sizeof(dib.dsBmih), "Got unexpected size %u for format %s.\n",
17018 dib.dsBmih.biSize, testdata[i].name);
17019 ok(dib.dsBmih.biWidth == 64, "Got unexpected width %d for format %s.\n",
17020 dib.dsBmih.biHeight, testdata[i].name);
17021 ok(dib.dsBmih.biHeight == 64, "Got unexpected height %d for format %s.\n",
17022 dib.dsBmih.biHeight, testdata[i].name);
17023 ok(dib.dsBmih.biPlanes == 1, "Got unexpected plane count %u for format %s.\n",
17024 dib.dsBmih.biPlanes, testdata[i].name);
17025 ok(dib.dsBmih.biBitCount == bit_count, "Got unexpected bit count %u for format %s.\n",
17026 dib.dsBmih.biBitCount, testdata[i].name);
17027 ok(dib.dsBmih.biCompression == BI_RGB, "Got unexpected compression %#x for format %s.\n",
17028 dib.dsBmih.biCompression, testdata[i].name);
17029 ok(!dib.dsBmih.biSizeImage, "Got unexpected image size %u for format %s.\n",
17030 dib.dsBmih.biSizeImage, testdata[i].name);
17031 ok(!dib.dsBmih.biXPelsPerMeter, "Got unexpected horizontal resolution %d for format %s.\n",
17032 dib.dsBmih.biXPelsPerMeter, testdata[i].name);
17033 ok(!dib.dsBmih.biYPelsPerMeter, "Got unexpected vertical resolution %d for format %s.\n",
17034 dib.dsBmih.biYPelsPerMeter, testdata[i].name);
17035 ok(!dib.dsBmih.biClrUsed, "Got unexpected used colour count %u for format %s.\n",
17036 dib.dsBmih.biClrUsed, testdata[i].name);
17037 ok(!dib.dsBmih.biClrImportant, "Got unexpected important colour count %u for format %s.\n",
17038 dib.dsBmih.biClrImportant, testdata[i].name);
17039 ok(!dib.dsBitfields[0] && !dib.dsBitfields[1] && !dib.dsBitfields[2],
17040 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
17041 dib.dsBitfields[0], dib.dsBitfields[1], dib.dsBitfields[2], testdata[i].name);
17042 ok(!dib.dshSection, "Got unexpected section %p for format %s.\n", dib.dshSection, testdata[i].name);
17043 ok(!dib.dsOffset, "Got unexpected offset %u for format %s.\n", dib.dsOffset, testdata[i].name);
17046 hr = IDXGISurface1_ReleaseDC(surface, NULL);
17047 ok(hr == S_OK, "Failed to release DC, hr %#x.\n", hr);
17049 IDXGISurface1_Release(surface);
17050 ID3D11Texture2D_Release(texture);
17053 refcount = ID3D11Device_Release(device);
17054 ok(!refcount, "Device has %u references left.\n", refcount);
17057 static void test_shader_stage_input_output_matching(void)
17059 struct d3d11_test_context test_context;
17060 D3D11_TEXTURE2D_DESC texture_desc;
17061 ID3D11Texture2D *render_target;
17062 ID3D11RenderTargetView *rtv[2];
17063 ID3D11DeviceContext *context;
17064 ID3D11VertexShader *vs;
17065 ID3D11PixelShader *ps;
17066 ID3D11Device *device;
17067 HRESULT hr;
17069 static const DWORD vs_code[] =
17071 #if 0
17072 struct output
17074 float4 position : SV_PoSiTion;
17075 float4 color0 : COLOR0;
17076 float4 color1 : COLOR1;
17079 void main(uint id : SV_VertexID, out output o)
17081 float2 coords = float2((id << 1) & 2, id & 2);
17082 o.position = float4(coords * float2(2, -2) + float2(-1, 1), 0, 1);
17083 o.color0 = float4(1.0f, 0.0f, 0.0f, 1.0f);
17084 o.color1 = float4(0.0f, 1.0f, 0.0f, 1.0f);
17086 #endif
17087 0x43425844, 0x93c216a1, 0xbaa7e8d4, 0xd5368c6a, 0x4e889e07, 0x00000001, 0x00000224, 0x00000003,
17088 0x0000002c, 0x00000060, 0x000000cc, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17089 0x00000000, 0x00000006, 0x00000001, 0x00000000, 0x00000101, 0x565f5653, 0x65747265, 0x00444978,
17090 0x4e47534f, 0x00000064, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003,
17091 0x00000000, 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
17092 0x0000005c, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x505f5653, 0x5469536f,
17093 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000150, 0x00010040, 0x00000054, 0x04000060,
17094 0x00101012, 0x00000000, 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065,
17095 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001, 0x07000029,
17096 0x00100012, 0x00000000, 0x0010100a, 0x00000000, 0x00004001, 0x00000001, 0x07000001, 0x00100012,
17097 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x07000001, 0x00100042, 0x00000000,
17098 0x0010100a, 0x00000000, 0x00004001, 0x00000002, 0x05000056, 0x00100032, 0x00000000, 0x00100086,
17099 0x00000000, 0x0f000032, 0x00102032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x40000000,
17100 0xc0000000, 0x00000000, 0x00000000, 0x00004002, 0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
17101 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x3f800000,
17102 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
17103 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
17104 0x0100003e,
17106 static const DWORD ps_code[] =
17108 #if 0
17109 struct input
17111 float4 position : SV_PoSiTiOn;
17112 float4 color1 : COLOR1;
17113 float4 color0 : COLOR0;
17116 struct output
17118 float4 target0 : SV_Target0;
17119 float4 target1 : SV_Target1;
17122 void main(const in input i, out output o)
17124 o.target0 = i.color0;
17125 o.target1 = i.color1;
17127 #endif
17128 0x43425844, 0x620ef963, 0xed8f19fe, 0x7b3a0a53, 0x126ce021, 0x00000001, 0x00000150, 0x00000003,
17129 0x0000002c, 0x00000098, 0x000000e4, 0x4e475349, 0x00000064, 0x00000003, 0x00000008, 0x00000050,
17130 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000001, 0x00000000,
17131 0x00000003, 0x00000001, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000002,
17132 0x00000f0f, 0x505f5653, 0x5469536f, 0x006e4f69, 0x4f4c4f43, 0xabab0052, 0x4e47534f, 0x00000044,
17133 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f,
17134 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x545f5653, 0x65677261,
17135 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03001062, 0x001010f2, 0x00000001,
17136 0x03001062, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
17137 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000002, 0x05000036, 0x001020f2,
17138 0x00000001, 0x00101e46, 0x00000001, 0x0100003e,
17141 if (!init_test_context(&test_context, NULL))
17142 return;
17144 device = test_context.device;
17145 context = test_context.immediate_context;
17147 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17148 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17149 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17150 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17152 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17153 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
17154 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17156 rtv[0] = test_context.backbuffer_rtv;
17157 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv[1]);
17158 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17160 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17161 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17162 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
17163 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtv, NULL);
17164 ID3D11DeviceContext_Draw(context, 3, 0);
17166 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17167 check_texture_color(render_target, 0xff0000ff, 0);
17169 ID3D11RenderTargetView_Release(rtv[1]);
17170 ID3D11Texture2D_Release(render_target);
17171 ID3D11PixelShader_Release(ps);
17172 ID3D11VertexShader_Release(vs);
17173 release_test_context(&test_context);
17176 static void test_unbound_streams(void)
17178 struct d3d11_test_context test_context;
17179 ID3D11DeviceContext *context;
17180 ID3D11PixelShader *ps;
17181 ID3D11Device *device;
17182 HRESULT hr;
17184 static const DWORD vs_code[] =
17186 #if 0
17187 struct vs_ps
17189 float4 position : SV_POSITION;
17190 float4 color : COLOR0;
17193 vs_ps vs_main(float4 position : POSITION, float4 color : COLOR0)
17195 vs_ps result;
17196 result.position = position;
17197 result.color = color;
17198 result.color.w = 1.0;
17199 return result;
17201 #endif
17202 0x43425844, 0x4a9efaec, 0xe2c6cdf5, 0x15dd28a7, 0xae68e320, 0x00000001, 0x00000154, 0x00000003,
17203 0x0000002c, 0x0000007c, 0x000000d0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
17204 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
17205 0x00000003, 0x00000001, 0x0000070f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
17206 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
17207 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x505f5653,
17208 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x0000007c, 0x00010040, 0x0000001f,
17209 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101072, 0x00000001, 0x04000067, 0x001020f2,
17210 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2, 0x00000000,
17211 0x00101e46, 0x00000000, 0x05000036, 0x00102072, 0x00000001, 0x00101246, 0x00000001, 0x05000036,
17212 0x00102082, 0x00000001, 0x00004001, 0x3f800000, 0x0100003e,
17215 static const DWORD ps_code[] =
17217 #if 0
17218 float4 ps_main(vs_ps input) : SV_TARGET
17220 return input.color;
17222 #endif
17223 0x43425844, 0xe2087fa6, 0xa35fbd95, 0x8e585b3f, 0x67890f54, 0x00000001, 0x000000f4, 0x00000003,
17224 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
17225 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17226 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
17227 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
17228 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
17229 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
17230 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
17233 static const float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
17235 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17237 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17238 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
17241 if (!init_test_context(&test_context, NULL))
17242 return;
17244 device = test_context.device;
17245 context = test_context.immediate_context;
17247 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
17248 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
17250 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17251 vs_code, sizeof(vs_code), &test_context.input_layout);
17252 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17254 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17255 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17256 draw_quad_vs(&test_context, vs_code, sizeof(vs_code));
17257 check_texture_color(test_context.backbuffer, 0xff000000, 1);
17259 ID3D11PixelShader_Release(ps);
17260 release_test_context(&test_context);
17263 static void test_shader_interstage_interface(void)
17265 struct d3d11_test_context test_context;
17266 D3D11_TEXTURE2D_DESC texture_desc;
17267 ID3D11InputLayout *input_layout;
17268 ID3D11Texture2D *render_target;
17269 ID3D11DeviceContext *context;
17270 ID3D11RenderTargetView *rtv;
17271 ID3D11VertexShader *vs;
17272 ID3D11PixelShader *ps;
17273 ID3D11Device *device;
17274 UINT stride, offset;
17275 ID3D11Buffer *vb;
17276 unsigned int i;
17277 HRESULT hr;
17279 static const DWORD vs_code[] =
17281 #if 0
17282 struct vertex
17284 float4 position : SV_Position;
17285 float2 t0 : TEXCOORD0;
17286 nointerpolation float t1 : TEXCOORD1;
17287 uint t2 : TEXCOORD2;
17288 uint t3 : TEXCOORD3;
17289 float t4 : TEXCOORD4;
17292 void main(in vertex vin, out vertex vout)
17294 vout = vin;
17296 #endif
17297 0x43425844, 0xd55780bf, 0x76866b06, 0x45d697a2, 0xafac2ecd, 0x00000001, 0x000002bc, 0x00000003,
17298 0x0000002c, 0x000000e4, 0x0000019c, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
17299 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000a4, 0x00000000, 0x00000000,
17300 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
17301 0x00000101, 0x000000a4, 0x00000002, 0x00000000, 0x00000001, 0x00000003, 0x00000101, 0x000000a4,
17302 0x00000003, 0x00000000, 0x00000001, 0x00000004, 0x00000101, 0x000000a4, 0x00000004, 0x00000000,
17303 0x00000003, 0x00000005, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17304 0xababab00, 0x4e47534f, 0x000000b0, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x00000001,
17305 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
17306 0x00000c03, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001, 0x00000b04, 0x000000a4,
17307 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000e01, 0x000000a4, 0x00000002, 0x00000000,
17308 0x00000001, 0x00000002, 0x00000d02, 0x000000a4, 0x00000003, 0x00000000, 0x00000001, 0x00000002,
17309 0x00000b04, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853,
17310 0x00000118, 0x00010040, 0x00000046, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032,
17311 0x00000001, 0x0300005f, 0x00101012, 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f,
17312 0x00101012, 0x00000004, 0x0300005f, 0x00101012, 0x00000005, 0x04000067, 0x001020f2, 0x00000000,
17313 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x03000065, 0x00102042, 0x00000001, 0x03000065,
17314 0x00102012, 0x00000002, 0x03000065, 0x00102022, 0x00000002, 0x03000065, 0x00102042, 0x00000002,
17315 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001,
17316 0x00101046, 0x00000001, 0x05000036, 0x00102042, 0x00000001, 0x0010100a, 0x00000005, 0x05000036,
17317 0x00102012, 0x00000002, 0x0010100a, 0x00000002, 0x05000036, 0x00102022, 0x00000002, 0x0010100a,
17318 0x00000003, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000004, 0x0100003e,
17320 static const DWORD ps_code[] =
17322 #if 0
17323 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
17324 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
17325 uint t3 : TEXCOORD3, float t4 : TEXCOORD4, out float4 o : SV_Target)
17327 o.x = t0.y + t1;
17328 o.y = t2 + t3;
17329 o.z = t4;
17330 o.w = t0.x;
17332 #endif
17333 0x43425844, 0x8a7ef706, 0xc8f2cbf1, 0x83a05df1, 0xfab8e613, 0x00000001, 0x000001dc, 0x00000003,
17334 0x0000002c, 0x000000e4, 0x00000118, 0x4e475349, 0x000000b0, 0x00000006, 0x00000008, 0x00000098,
17335 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x000000a4, 0x00000000, 0x00000000,
17336 0x00000003, 0x00000001, 0x00000303, 0x000000a4, 0x00000004, 0x00000000, 0x00000003, 0x00000001,
17337 0x00000404, 0x000000a4, 0x00000001, 0x00000000, 0x00000003, 0x00000002, 0x00000101, 0x000000a4,
17338 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x000000a4, 0x00000003, 0x00000000,
17339 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17340 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
17341 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc,
17342 0x00000040, 0x0000002f, 0x03001062, 0x00101032, 0x00000001, 0x03001062, 0x00101042, 0x00000001,
17343 0x03000862, 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042,
17344 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012,
17345 0x00000000, 0x0010101a, 0x00000002, 0x0010102a, 0x00000002, 0x05000056, 0x00102022, 0x00000000,
17346 0x0010000a, 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a,
17347 0x00000002, 0x05000036, 0x001020c2, 0x00000000, 0x001012a6, 0x00000001, 0x0100003e,
17349 static const DWORD ps_partial_input_code[] =
17351 #if 0
17352 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0,
17353 nointerpolation float t1 : TEXCOORD1, uint t2 : TEXCOORD2,
17354 uint t3 : TEXCOORD3, out float4 o : SV_Target)
17356 o.x = t0.y + t1;
17357 o.y = t2 + t3;
17358 o.z = 0.0f;
17359 o.w = t0.x;
17361 #endif
17362 0x43425844, 0x5b1db356, 0xaa5a5e9d, 0xb916a081, 0x61e6dcb1, 0x00000001, 0x000001cc, 0x00000003,
17363 0x0000002c, 0x000000cc, 0x00000100, 0x4e475349, 0x00000098, 0x00000005, 0x00000008, 0x00000080,
17364 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000008c, 0x00000000, 0x00000000,
17365 0x00000003, 0x00000001, 0x00000303, 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
17366 0x00000101, 0x0000008c, 0x00000002, 0x00000000, 0x00000001, 0x00000002, 0x00000202, 0x0000008c,
17367 0x00000003, 0x00000000, 0x00000001, 0x00000002, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
17368 0x43584554, 0x44524f4f, 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
17369 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074,
17370 0x52444853, 0x000000c4, 0x00000040, 0x00000031, 0x03001062, 0x00101032, 0x00000001, 0x03000862,
17371 0x00101012, 0x00000002, 0x03000862, 0x00101022, 0x00000002, 0x03000862, 0x00101042, 0x00000002,
17372 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0700001e, 0x00100012, 0x00000000,
17373 0x0010102a, 0x00000002, 0x0010101a, 0x00000002, 0x05000056, 0x00102022, 0x00000000, 0x0010000a,
17374 0x00000000, 0x07000000, 0x00102012, 0x00000000, 0x0010101a, 0x00000001, 0x0010100a, 0x00000002,
17375 0x05000036, 0x00102042, 0x00000000, 0x00004001, 0x00000000, 0x05000036, 0x00102082, 0x00000000,
17376 0x0010100a, 0x00000001, 0x0100003e,
17378 static const DWORD ps_single_input_code[] =
17380 #if 0
17381 void main(float4 position : SV_Position, float2 t0 : TEXCOORD0, out float4 o : SV_Target)
17383 o.x = t0.x;
17384 o.y = t0.y;
17385 o.z = 1.0f;
17386 o.w = 2.0f;
17388 #endif
17389 0x43425844, 0x7cc601b6, 0xc65b8bdb, 0x54d0f606, 0x9cc74d3d, 0x00000001, 0x00000118, 0x00000003,
17390 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
17391 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
17392 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
17393 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
17394 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058,
17395 0x00000040, 0x00000016, 0x03001062, 0x00101032, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
17396 0x05000036, 0x00102032, 0x00000000, 0x00101046, 0x00000001, 0x08000036, 0x001020c2, 0x00000000,
17397 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x40000000, 0x0100003e,
17399 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
17401 {"SV_POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
17402 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
17403 {"TEXCOORD", 1, DXGI_FORMAT_R32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
17404 {"TEXCOORD", 2, DXGI_FORMAT_R32_UINT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
17405 {"TEXCOORD", 3, DXGI_FORMAT_R32_UINT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
17406 {"TEXCOORD", 4, DXGI_FORMAT_R32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
17408 static const struct
17410 struct vec2 position;
17411 struct vec2 t0;
17412 float t1;
17413 unsigned int t2;
17414 unsigned int t3;
17415 float t4;
17417 quad[] =
17419 {{-1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17420 {{-1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17421 {{ 1.0f, -1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17422 {{ 1.0f, 1.0f}, {3.0f, 5.0f}, 5.0f, 2, 6, 7.0f},
17424 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17425 static const struct
17427 const DWORD *ps_code;
17428 size_t ps_size;
17429 struct vec4 expected_result;
17431 tests[] =
17433 {ps_code, sizeof(ps_code), {10.0f, 8.0f, 7.0f, 3.0f}},
17434 {ps_partial_input_code, sizeof(ps_partial_input_code), {10.0f, 8.0f, 0.0f, 3.0f}},
17435 {ps_single_input_code, sizeof(ps_single_input_code), {3.0f, 5.0f, 1.0f, 2.0f}},
17438 if (!init_test_context(&test_context, NULL))
17439 return;
17441 device = test_context.device;
17442 context = test_context.immediate_context;
17444 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
17445 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
17447 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
17448 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
17449 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
17450 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
17452 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
17453 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
17455 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
17456 vs_code, sizeof(vs_code), &input_layout);
17457 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
17459 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
17461 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
17463 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
17464 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
17465 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
17466 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
17467 offset = 0;
17468 stride = sizeof(*quad);
17469 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
17471 for (i = 0; i < ARRAY_SIZE(tests); ++i)
17473 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_size, NULL, &ps);
17474 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
17475 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17476 ID3D11DeviceContext_Draw(context, 4, 0);
17477 check_texture_vec4(render_target, &tests[i].expected_result, 0);
17478 ID3D11PixelShader_Release(ps);
17481 ID3D11InputLayout_Release(input_layout);
17482 ID3D11RenderTargetView_Release(rtv);
17483 ID3D11Texture2D_Release(render_target);
17484 ID3D11VertexShader_Release(vs);
17485 ID3D11Buffer_Release(vb);
17486 release_test_context(&test_context);
17489 static void test_sm4_if_instruction(void)
17491 struct d3d11_test_context test_context;
17492 ID3D11PixelShader *ps_if_nz, *ps_if_z;
17493 ID3D11DeviceContext *context;
17494 ID3D11Device *device;
17495 unsigned int bits[4];
17496 DWORD expected_color;
17497 ID3D11Buffer *cb;
17498 unsigned int i;
17499 HRESULT hr;
17501 static const DWORD ps_if_nz_code[] =
17503 #if 0
17504 uint bits;
17506 float4 main() : SV_TARGET
17508 if (bits)
17509 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17510 else
17511 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17513 #endif
17514 0x43425844, 0x2a94f6f1, 0xdbe88943, 0x3426a708, 0x09cec990, 0x00000001, 0x00000100, 0x00000003,
17515 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17516 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17517 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
17518 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404001f,
17519 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17520 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17521 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17523 static const DWORD ps_if_z_code[] =
17525 #if 0
17526 uint bits;
17528 float4 main() : SV_TARGET
17530 if (!bits)
17531 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17532 else
17533 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17535 #endif
17536 0x43425844, 0x2e3030ca, 0x94c8610c, 0xdf0c1b1f, 0x80f2ca2c, 0x00000001, 0x00000100, 0x00000003,
17537 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17538 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17539 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
17540 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400001f,
17541 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17542 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17543 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17545 static unsigned int bit_patterns[] =
17547 0x00000000, 0x00000001, 0x10010001, 0x10000000, 0x80000000, 0xffff0000, 0x0000ffff, 0xffffffff,
17550 if (!init_test_context(&test_context, NULL))
17551 return;
17553 device = test_context.device;
17554 context = test_context.immediate_context;
17556 hr = ID3D11Device_CreatePixelShader(device, ps_if_nz_code, sizeof(ps_if_nz_code), NULL, &ps_if_nz);
17557 ok(SUCCEEDED(hr), "Failed to create if_nz pixel shader, hr %#x.\n", hr);
17558 hr = ID3D11Device_CreatePixelShader(device, ps_if_z_code, sizeof(ps_if_z_code), NULL, &ps_if_z);
17559 ok(SUCCEEDED(hr), "Failed to create if_z pixel shader, hr %#x.\n", hr);
17561 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(bits), NULL);
17562 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17564 for (i = 0; i < ARRAY_SIZE(bit_patterns); ++i)
17566 *bits = bit_patterns[i];
17567 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, bits, 0, 0);
17569 ID3D11DeviceContext_PSSetShader(context, ps_if_nz, NULL, 0);
17570 expected_color = *bits ? 0xff00ff00 : 0xff0000ff;
17571 draw_quad(&test_context);
17572 check_texture_color(test_context.backbuffer, expected_color, 0);
17574 ID3D11DeviceContext_PSSetShader(context, ps_if_z, NULL, 0);
17575 expected_color = *bits ? 0xff0000ff : 0xff00ff00;
17576 draw_quad(&test_context);
17577 check_texture_color(test_context.backbuffer, expected_color, 0);
17580 ID3D11Buffer_Release(cb);
17581 ID3D11PixelShader_Release(ps_if_z);
17582 ID3D11PixelShader_Release(ps_if_nz);
17583 release_test_context(&test_context);
17586 static void test_sm4_breakc_instruction(void)
17588 struct d3d11_test_context test_context;
17589 ID3D11DeviceContext *context;
17590 ID3D11PixelShader *ps;
17591 ID3D11Device *device;
17592 HRESULT hr;
17594 static const DWORD ps_breakc_nz_code[] =
17596 #if 0
17597 float4 main() : SV_TARGET
17599 uint counter = 0;
17601 for (uint i = 0; i < 255; ++i)
17602 ++counter;
17604 if (counter == 255)
17605 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17606 else
17607 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17609 #endif
17610 0x43425844, 0x065ac80a, 0x24369e7e, 0x218d5dc1, 0x3532868c, 0x00000001, 0x00000188, 0x00000003,
17611 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17612 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17613 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000110, 0x00000040, 0x00000044,
17614 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000036, 0x00100032, 0x00000000,
17615 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
17616 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
17617 0x0a00001e, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x00000001, 0x00000001,
17618 0x00000000, 0x00000000, 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
17619 0x00004001, 0x000000ff, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000,
17620 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036,
17621 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
17622 0x01000015, 0x0100003e,
17624 static const DWORD ps_breakc_z_code[] =
17626 #if 0
17627 float4 main() : SV_TARGET
17629 uint counter = 0;
17631 for (int i = 0, j = 254; i < 255 && j >= 0; ++i, --j)
17632 ++counter;
17634 if (counter == 255)
17635 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17636 else
17637 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17639 #endif
17640 0x43425844, 0x687406ef, 0x7bdeb7d1, 0xb3282292, 0x934a9101, 0x00000001, 0x000001c0, 0x00000003,
17641 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17642 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17643 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000148, 0x00000040, 0x00000052,
17644 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100072, 0x00000000,
17645 0x00004002, 0x00000000, 0x00000000, 0x000000fe, 0x00000000, 0x01000030, 0x07000022, 0x00100082,
17646 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x07000021, 0x00100012, 0x00000001,
17647 0x0010002a, 0x00000000, 0x00004001, 0x00000000, 0x07000001, 0x00100082, 0x00000000, 0x0010003a,
17648 0x00000000, 0x0010000a, 0x00000001, 0x03000003, 0x0010003a, 0x00000000, 0x0a00001e, 0x00100072,
17649 0x00000000, 0x00100246, 0x00000000, 0x00004002, 0x00000001, 0x00000001, 0xffffffff, 0x00000000,
17650 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
17651 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17652 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000012, 0x08000036, 0x001020f2, 0x00000000,
17653 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x0100003e,
17656 if (!init_test_context(&test_context, NULL))
17657 return;
17659 device = test_context.device;
17660 context = test_context.immediate_context;
17662 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_nz_code, sizeof(ps_breakc_nz_code), NULL, &ps);
17663 ok(SUCCEEDED(hr), "Failed to create breakc_nz pixel shader, hr %#x.\n", hr);
17664 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17665 draw_quad(&test_context);
17666 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17667 ID3D11PixelShader_Release(ps);
17669 hr = ID3D11Device_CreatePixelShader(device, ps_breakc_z_code, sizeof(ps_breakc_z_code), NULL, &ps);
17670 ok(SUCCEEDED(hr), "Failed to create breakc_z pixel shader, hr %#x.\n", hr);
17671 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17672 draw_quad(&test_context);
17673 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17674 ID3D11PixelShader_Release(ps);
17676 release_test_context(&test_context);
17679 static void test_sm4_continuec_instruction(void)
17681 struct d3d11_test_context test_context;
17682 ID3D11DeviceContext *context;
17683 ID3D11PixelShader *ps;
17684 ID3D11Device *device;
17685 HRESULT hr;
17687 /* To get fxc to output continuec_z/continuec_nz instead of an if-block
17688 * with a normal continue inside, the shaders have been compiled with
17689 * the /Gfa flag. */
17690 static const DWORD ps_continuec_nz_code[] =
17692 #if 0
17693 float4 main() : SV_TARGET
17695 uint counter = 0;
17696 int i = -1;
17698 while (i < 255) {
17699 ++i;
17701 if (i != 0)
17702 continue;
17704 ++counter;
17707 if (counter == 1)
17708 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17709 else
17710 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17712 #endif
17713 0x43425844, 0xaadaac96, 0xbe00fdfb, 0x29356be0, 0x47e79bd6, 0x00000001, 0x00000208, 0x00000003,
17714 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17715 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17716 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000190, 0x00000040, 0x00000064,
17717 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000003, 0x08000036, 0x00100032, 0x00000000,
17718 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
17719 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
17720 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x09000037,
17721 0x00100022, 0x00000002, 0x0010001a, 0x00000001, 0x0010001a, 0x00000001, 0x00004001, 0x00000000,
17722 0x05000036, 0x00100012, 0x00000002, 0x0010000a, 0x00000000, 0x05000036, 0x00100032, 0x00000000,
17723 0x00100046, 0x00000002, 0x05000036, 0x00100042, 0x00000000, 0x0010001a, 0x00000001, 0x03040008,
17724 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x00004001,
17725 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001, 0x01000016, 0x07000020,
17726 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x08000036, 0x001020f2,
17727 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0304003f, 0x0010000a,
17728 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000,
17729 0x3f800000, 0x0100003e,
17732 static const DWORD ps_continuec_z_code[] =
17734 #if 0
17735 float4 main() : SV_TARGET
17737 uint counter = 0;
17738 int i = -1;
17740 while (i < 255) {
17741 ++i;
17743 if (i == 0)
17744 continue;
17746 ++counter;
17749 if (counter == 255)
17750 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17751 else
17752 return float4(1.0f, 0.0f, 0.0f, 1.0f);
17754 #endif
17755 0x43425844, 0x0322b23d, 0x52b25dc8, 0xa625f5f1, 0x271e3f46, 0x00000001, 0x000001d0, 0x00000003,
17756 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17757 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17758 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000158, 0x00000040, 0x00000056,
17759 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002, 0x08000036, 0x00100032, 0x00000000,
17760 0x00004002, 0x00000000, 0xffffffff, 0x00000000, 0x00000000, 0x01000030, 0x07000021, 0x00100042,
17761 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x000000ff, 0x03040003, 0x0010002a, 0x00000000,
17762 0x0700001e, 0x00100022, 0x00000001, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x05000036,
17763 0x00100042, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x00100072, 0x00000000, 0x00100966,
17764 0x00000001, 0x03000008, 0x0010002a, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
17765 0x00000000, 0x00004001, 0x00000001, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
17766 0x01000016, 0x07000020, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x000000ff,
17767 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
17768 0x0304003f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000,
17769 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
17772 if (!init_test_context(&test_context, NULL))
17773 return;
17775 device = test_context.device;
17776 context = test_context.immediate_context;
17778 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_nz_code, sizeof(ps_continuec_nz_code), NULL, &ps);
17779 ok(SUCCEEDED(hr), "Failed to create continuec_nz pixel shader, hr %#x.\n", hr);
17780 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17781 draw_quad(&test_context);
17782 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17783 ID3D11PixelShader_Release(ps);
17785 hr = ID3D11Device_CreatePixelShader(device, ps_continuec_z_code, sizeof(ps_continuec_z_code), NULL, &ps);
17786 ok(SUCCEEDED(hr), "Failed to create continuec_z pixel shader, hr %#x.\n", hr);
17787 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
17788 draw_quad(&test_context);
17789 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
17790 ID3D11PixelShader_Release(ps);
17792 release_test_context(&test_context);
17795 static void test_sm4_discard_instruction(void)
17797 ID3D11PixelShader *ps_discard_nz, *ps_discard_z;
17798 struct d3d11_test_context test_context;
17799 ID3D11DeviceContext *context;
17800 ID3D11Device *device;
17801 ID3D11Buffer *cb;
17802 unsigned int i;
17803 HRESULT hr;
17805 static const DWORD ps_discard_nz_code[] =
17807 #if 0
17808 uint data;
17810 float4 main() : SV_Target
17812 if (data)
17813 discard;
17814 return float4(0.0f, 0.5f, 0.0f, 1.0f);
17816 #endif
17817 0x43425844, 0xfa7e5758, 0xd8716ffc, 0x5ad6a940, 0x2b99bba2, 0x00000001, 0x000000d0, 0x00000003,
17818 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17819 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17820 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
17821 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0404000d,
17822 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17823 0x3f000000, 0x00000000, 0x3f800000, 0x0100003e,
17825 static const DWORD ps_discard_z_code[] =
17827 #if 0
17828 uint data;
17830 float4 main() : SV_Target
17832 if (!data)
17833 discard;
17834 return float4(0.0f, 1.0f, 0.0f, 1.0f);
17836 #endif
17837 0x43425844, 0x5c4dd108, 0x1eb43558, 0x7c02c98c, 0xd81eb34c, 0x00000001, 0x000000d0, 0x00000003,
17838 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17839 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
17840 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000058, 0x00000040, 0x00000016,
17841 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0400000d,
17842 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
17843 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
17845 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
17846 static const struct uvec4 values[] =
17848 {0x0000000},
17849 {0x0000001},
17850 {0x8000000},
17851 {0xfffffff},
17854 if (!init_test_context(&test_context, NULL))
17855 return;
17857 device = test_context.device;
17858 context = test_context.immediate_context;
17860 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(*values), NULL);
17861 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
17863 hr = ID3D11Device_CreatePixelShader(device, ps_discard_nz_code, sizeof(ps_discard_nz_code),
17864 NULL, &ps_discard_nz);
17865 ok(SUCCEEDED(hr), "Failed to create discard_nz pixel shader, hr %#x.\n", hr);
17866 hr = ID3D11Device_CreatePixelShader(device, ps_discard_z_code, sizeof(ps_discard_z_code),
17867 NULL, &ps_discard_z);
17868 ok(SUCCEEDED(hr), "Failed to create discard_z pixel shader, hr %#x.\n", hr);
17870 for (i = 0; i < ARRAY_SIZE(values); ++i)
17872 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &values[i], 0, 0);
17874 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17875 ID3D11DeviceContext_PSSetShader(context, ps_discard_nz, NULL, 0);
17876 draw_quad(&test_context);
17877 check_texture_color(test_context.backbuffer, values[i].x ? 0xffffffff : 0xff007f00, 1);
17879 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
17880 ID3D11DeviceContext_PSSetShader(context, ps_discard_z, NULL, 0);
17881 draw_quad(&test_context);
17882 check_texture_color(test_context.backbuffer, values[i].x ? 0xff00ff00 : 0xffffffff, 1);
17885 ID3D11Buffer_Release(cb);
17886 ID3D11PixelShader_Release(ps_discard_nz);
17887 ID3D11PixelShader_Release(ps_discard_z);
17888 release_test_context(&test_context);
17891 static void test_sm5_swapc_instruction(void)
17893 struct input
17895 struct uvec4 src0;
17896 struct uvec4 src1;
17897 struct uvec4 src2;
17900 struct d3d11_test_context test_context;
17901 D3D11_TEXTURE2D_DESC texture_desc;
17902 ID3D11DeviceContext *context;
17903 ID3D11RenderTargetView *rtv;
17904 ID3D11Texture2D *texture;
17905 ID3D11PixelShader *ps[6];
17906 ID3D11Device *device;
17907 ID3D11Buffer *cb;
17908 unsigned int i;
17909 HRESULT hr;
17911 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
17912 static const DWORD ps_swapc0_code[] =
17914 #if 0
17915 ps_5_0
17916 dcl_globalFlags refactoringAllowed
17917 dcl_constantbuffer cb0[3], immediateIndexed
17918 dcl_output o0.xyzw
17919 dcl_temps 2
17920 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
17921 mov o0.xyzw, r0.xyzw
17923 #endif
17924 0x43425844, 0x9e089246, 0x9f8b5cbe, 0xbac66faf, 0xaef23488, 0x00000001, 0x000000f8, 0x00000003,
17925 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17926 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17927 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
17928 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
17929 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
17930 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
17931 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
17933 static const DWORD ps_swapc1_code[] =
17935 #if 0
17936 ps_5_0
17937 dcl_globalFlags refactoringAllowed
17938 dcl_constantbuffer cb0[3], immediateIndexed
17939 dcl_output o0.xyzw
17940 dcl_temps 2
17941 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, cb0[1].xyzw, cb0[2].xyzw
17942 mov o0.xyzw, r1.xyzw
17944 #endif
17945 0x43425844, 0xf2daed61, 0xede211f7, 0x7300dbea, 0x573ed49f, 0x00000001, 0x000000f8, 0x00000003,
17946 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17947 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17948 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050, 0x00000020,
17949 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
17950 0x02000068, 0x00000002, 0x0e00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00208e46,
17951 0x00000000, 0x00000000, 0x00208e46, 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002,
17952 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
17954 static const DWORD ps_swapc2_code[] =
17956 #if 0
17957 ps_5_0
17958 dcl_globalFlags refactoringAllowed
17959 dcl_constantbuffer cb0[3], immediateIndexed
17960 dcl_output o0.xyzw
17961 dcl_temps 2
17962 mov r0.xyzw, cb0[1].xyzw
17963 mov r1.xyzw, cb0[2].xyzw
17964 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
17965 mov o0.xyzw, r0.xyzw
17967 #endif
17968 0x43425844, 0x230fcb22, 0x70d99148, 0x65814d89, 0x97473498, 0x00000001, 0x00000120, 0x00000003,
17969 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17970 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17971 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
17972 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
17973 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
17974 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
17975 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
17976 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
17978 static const DWORD ps_swapc3_code[] =
17980 #if 0
17981 ps_5_0
17982 dcl_globalFlags refactoringAllowed
17983 dcl_constantbuffer cb0[3], immediateIndexed
17984 dcl_output o0.xyzw
17985 dcl_temps 2
17986 mov r0.xyzw, cb0[1].xyzw
17987 mov r1.xyzw, cb0[2].xyzw
17988 swapc r0.xyzw, r1.xyzw, cb0[0].xyzw, r0.xyzw, r1.xyzw
17989 mov o0.xyzw, r1.xyzw
17991 #endif
17992 0x43425844, 0xce595d62, 0x98305541, 0xb04e74c8, 0xfc010f3a, 0x00000001, 0x00000120, 0x00000003,
17993 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
17994 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
17995 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000a8, 0x00000050, 0x0000002a,
17996 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
17997 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000001,
17998 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x0c00008e, 0x001000f2,
17999 0x00000000, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x00100e46, 0x00000000,
18000 0x00100e46, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x0100003e,
18002 static const DWORD ps_swapc4_code[] =
18004 #if 0
18005 ps_5_0
18006 dcl_globalFlags refactoringAllowed
18007 dcl_constantbuffer cb0[3], immediateIndexed
18008 dcl_output o0.xyzw
18009 dcl_temps 2
18010 mov r0.xyzw, cb0[0].xyzw
18011 swapc r0.xyzw, r1.xyzw, r0.xyzw, cb0[1].xyzw, cb0[2].xyzw
18012 mov o0.xyzw, r0.xyzw
18014 #endif
18015 0x43425844, 0x72067c48, 0xb53572a0, 0x9dd9e0fd, 0x903e37e3, 0x00000001, 0x0000010c, 0x00000003,
18016 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18017 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18018 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
18019 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18020 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
18021 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000000, 0x00208e46,
18022 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
18023 0x00100e46, 0x00000000, 0x0100003e,
18025 static const DWORD ps_swapc5_code[] =
18027 #if 0
18028 ps_5_0
18029 dcl_globalFlags refactoringAllowed
18030 dcl_constantbuffer cb0[3], immediateIndexed
18031 dcl_output o0.xyzw
18032 dcl_temps 2
18033 mov r1.xyzw, cb0[0].xyzw
18034 swapc r0.xyzw, r1.xyzw, r1.xyzw, cb0[1].xyzw, cb0[2].xyzw
18035 mov o0.xyzw, r1.xyzw
18037 #endif
18038 0x43425844, 0x7078fb08, 0xdd24cd44, 0x469d3258, 0x9e33a0bc, 0x00000001, 0x0000010c, 0x00000003,
18039 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
18040 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
18041 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000094, 0x00000050, 0x00000025,
18042 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000003, 0x03000065, 0x001020f2, 0x00000000,
18043 0x02000068, 0x00000002, 0x06000036, 0x001000f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000,
18044 0x0d00008e, 0x001000f2, 0x00000000, 0x001000f2, 0x00000001, 0x00100e46, 0x00000001, 0x00208e46,
18045 0x00000000, 0x00000001, 0x00208e46, 0x00000000, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
18046 0x00100e46, 0x00000001, 0x0100003e,
18048 static const struct
18050 struct input input;
18051 struct uvec4 dst0;
18052 struct uvec4 dst1;
18054 tests[] =
18057 {{0, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18058 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}
18061 {{1, 1, 1, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18062 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
18065 {{0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff},
18066 {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18067 {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}, {0xdead, 0xc0de, 0xffff, 0xeeee},
18070 {{1, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18071 {0xaaaa, 0xc0de, 0xcccc, 0xeeee}, {0xdead, 0xbbbb, 0xffff, 0xdddd},
18074 {{1, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18075 {0xaaaa, 0xc0de, 0xffff, 0xdddd}, {0xdead, 0xbbbb, 0xcccc, 0xeeee},
18078 {{1, 0, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18079 {0xaaaa, 0xc0de, 0xffff, 0xeeee}, {0xdead, 0xbbbb, 0xcccc, 0xdddd}
18082 {{0, 1, 0, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18083 {0xdead, 0xbbbb, 0xffff, 0xeeee}, {0xaaaa, 0xc0de, 0xcccc, 0xdddd}
18086 {{0, 0, 1, 0}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18087 {0xdead, 0xc0de, 0xcccc, 0xeeee}, {0xaaaa, 0xbbbb, 0xffff, 0xdddd}
18090 {{0, 0, 0, 1}, {0xdead, 0xc0de, 0xffff, 0xeeee}, {0xaaaa, 0xbbbb, 0xcccc, 0xdddd}},
18091 {0xdead, 0xc0de, 0xffff, 0xdddd}, {0xaaaa, 0xbbbb, 0xcccc, 0xeeee},
18095 if (!init_test_context(&test_context, &feature_level))
18096 return;
18098 device = test_context.device;
18099 context = test_context.immediate_context;
18101 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
18102 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
18103 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18104 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18106 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18107 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
18109 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18111 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct input), NULL);
18112 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
18114 hr = ID3D11Device_CreatePixelShader(device, ps_swapc0_code, sizeof(ps_swapc0_code), NULL, &ps[0]);
18115 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18116 hr = ID3D11Device_CreatePixelShader(device, ps_swapc1_code, sizeof(ps_swapc1_code), NULL, &ps[1]);
18117 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18118 hr = ID3D11Device_CreatePixelShader(device, ps_swapc2_code, sizeof(ps_swapc2_code), NULL, &ps[2]);
18119 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18120 hr = ID3D11Device_CreatePixelShader(device, ps_swapc3_code, sizeof(ps_swapc3_code), NULL, &ps[3]);
18121 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18122 hr = ID3D11Device_CreatePixelShader(device, ps_swapc4_code, sizeof(ps_swapc4_code), NULL, &ps[4]);
18123 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18124 hr = ID3D11Device_CreatePixelShader(device, ps_swapc5_code, sizeof(ps_swapc5_code), NULL, &ps[5]);
18125 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18127 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18129 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &tests[i].input, 0, 0);
18131 ID3D11DeviceContext_PSSetShader(context, ps[0], NULL, 0);
18132 draw_quad(&test_context);
18133 check_texture_uvec4(texture, &tests[i].dst0);
18135 ID3D11DeviceContext_PSSetShader(context, ps[1], NULL, 0);
18136 draw_quad(&test_context);
18137 check_texture_uvec4(texture, &tests[i].dst1);
18139 ID3D11DeviceContext_PSSetShader(context, ps[2], NULL, 0);
18140 draw_quad(&test_context);
18141 check_texture_uvec4(texture, &tests[i].dst0);
18143 ID3D11DeviceContext_PSSetShader(context, ps[3], NULL, 0);
18144 draw_quad(&test_context);
18145 check_texture_uvec4(texture, &tests[i].dst1);
18147 ID3D11DeviceContext_PSSetShader(context, ps[4], NULL, 0);
18148 draw_quad(&test_context);
18149 check_texture_uvec4(texture, &tests[i].dst0);
18151 ID3D11DeviceContext_PSSetShader(context, ps[5], NULL, 0);
18152 draw_quad(&test_context);
18153 check_texture_uvec4(texture, &tests[i].dst1);
18156 for (i = 0; i < ARRAY_SIZE(ps); ++i)
18157 ID3D11PixelShader_Release(ps[i]);
18158 ID3D11RenderTargetView_Release(rtv);
18159 ID3D11Texture2D_Release(texture);
18160 ID3D11Buffer_Release(cb);
18161 release_test_context(&test_context);
18164 static void test_create_input_layout(void)
18166 D3D11_INPUT_ELEMENT_DESC layout_desc[] =
18168 {"POSITION", 0, DXGI_FORMAT_UNKNOWN, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18170 ULONG refcount, expected_refcount;
18171 ID3D11InputLayout *input_layout;
18172 ID3D11Device *device;
18173 unsigned int i;
18174 HRESULT hr;
18176 static const DWORD vs_code[] =
18178 #if 0
18179 float4 main(float4 position : POSITION) : SV_POSITION
18181 return position;
18183 #endif
18184 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
18185 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18186 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
18187 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
18188 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
18189 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18190 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
18192 static const DXGI_FORMAT vertex_formats[] =
18194 DXGI_FORMAT_R32G32_FLOAT,
18195 DXGI_FORMAT_R32G32_UINT,
18196 DXGI_FORMAT_R32G32_SINT,
18197 DXGI_FORMAT_R16G16_FLOAT,
18198 DXGI_FORMAT_R16G16_UINT,
18199 DXGI_FORMAT_R16G16_SINT,
18200 DXGI_FORMAT_R32_FLOAT,
18201 DXGI_FORMAT_R32_UINT,
18202 DXGI_FORMAT_R32_SINT,
18203 DXGI_FORMAT_R16_UINT,
18204 DXGI_FORMAT_R16_SINT,
18205 DXGI_FORMAT_R8G8_UNORM,
18206 DXGI_FORMAT_R8_UINT,
18207 DXGI_FORMAT_R8_SINT,
18210 if (!(device = create_device(NULL)))
18212 skip("Failed to create device.\n");
18213 return;
18216 for (i = 0; i < ARRAY_SIZE(vertex_formats); ++i)
18218 expected_refcount = get_refcount(device) + 1;
18219 layout_desc->Format = vertex_formats[i];
18220 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
18221 vs_code, sizeof(vs_code), &input_layout);
18222 ok(hr == S_OK, "Failed to create input layout for format %#x, hr %#x.\n",
18223 vertex_formats[i], hr);
18224 refcount = get_refcount(device);
18225 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n",
18226 refcount, expected_refcount);
18227 ID3D11InputLayout_Release(input_layout);
18230 refcount = ID3D11Device_Release(device);
18231 ok(!refcount, "Device has %u references left.\n", refcount);
18234 static void test_input_layout_alignment(void)
18236 ID3D11InputLayout *layout;
18237 ID3D11Device *device;
18238 unsigned int i;
18239 ULONG refcount;
18240 HRESULT hr;
18242 static const DWORD vs_code[] =
18244 #if 0
18245 float4 main(float4 position : POSITION) : SV_POSITION
18247 return position;
18249 #endif
18250 0x43425844, 0xa7a2f22d, 0x83ff2560, 0xe61638bd, 0x87e3ce90, 0x00000001, 0x000000d8, 0x00000003,
18251 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18252 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0xababab00,
18253 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
18254 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x0000003c, 0x00010040,
18255 0x0000000f, 0x0300005f, 0x001010f2, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
18256 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0100003e,
18259 static const struct
18261 D3D11_INPUT_ELEMENT_DESC elements[2];
18262 HRESULT hr;
18264 test_data[] =
18267 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18268 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18269 }, S_OK},
18271 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18272 {"COLOR", 0, DXGI_FORMAT_R16_UINT, 0, 1, D3D11_INPUT_PER_VERTEX_DATA, 0},
18273 }, E_INVALIDARG},
18275 {"POSITION", 0, DXGI_FORMAT_R8_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18276 {"COLOR", 0, DXGI_FORMAT_R8_UINT, 0, 1, D3D11_INPUT_PER_VERTEX_DATA, 0},
18277 }, S_OK},
18279 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18280 {"COLOR", 0, DXGI_FORMAT_R32_UINT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18281 }, E_INVALIDARG},
18283 {"POSITION", 0, DXGI_FORMAT_R16_UINT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18284 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 2, D3D11_INPUT_PER_VERTEX_DATA, 0},
18285 }, E_INVALIDARG},
18287 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18288 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
18289 }, S_OK},
18291 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18292 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 17, D3D11_INPUT_PER_VERTEX_DATA, 0},
18293 }, E_INVALIDARG},
18295 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18296 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 18, D3D11_INPUT_PER_VERTEX_DATA, 0},
18297 }, E_INVALIDARG},
18299 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18300 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 19, D3D11_INPUT_PER_VERTEX_DATA, 0},
18301 }, E_INVALIDARG},
18303 {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18304 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
18305 }, S_OK},
18308 if (!(device = create_device(NULL)))
18310 skip("Failed to create device.\n");
18311 return;
18314 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
18316 hr = ID3D11Device_CreateInputLayout(device, test_data[i].elements, 2, vs_code, sizeof(vs_code), &layout);
18317 ok(hr == test_data[i].hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
18318 if (SUCCEEDED(hr))
18319 ID3D11InputLayout_Release(layout);
18322 refcount = ID3D11Device_Release(device);
18323 ok(!refcount, "Device has %u references left.\n", refcount);
18326 static void test_input_assembler(void)
18328 enum layout_id
18330 LAYOUT_FLOAT32,
18331 LAYOUT_UINT16,
18332 LAYOUT_SINT16,
18333 LAYOUT_UNORM16,
18334 LAYOUT_SNORM16,
18335 LAYOUT_UINT8,
18336 LAYOUT_SINT8,
18337 LAYOUT_UNORM8,
18338 LAYOUT_SNORM8,
18339 LAYOUT_UNORM10_2,
18340 LAYOUT_UINT10_2,
18342 LAYOUT_COUNT,
18345 D3D11_INPUT_ELEMENT_DESC input_layout_desc[] =
18347 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18348 {"ATTRIBUTE", 0, DXGI_FORMAT_UNKNOWN, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
18350 ID3D11VertexShader *vs_float, *vs_uint, *vs_sint;
18351 ID3D11InputLayout *input_layout[LAYOUT_COUNT];
18352 ID3D11Buffer *vb_position, *vb_attribute;
18353 struct d3d11_test_context test_context;
18354 D3D11_TEXTURE2D_DESC texture_desc;
18355 unsigned int i, j, stride, offset;
18356 ID3D11Texture2D *render_target;
18357 ID3D11DeviceContext *context;
18358 ID3D11RenderTargetView *rtv;
18359 ID3D11PixelShader *ps;
18360 ID3D11Device *device;
18361 HRESULT hr;
18363 static const DXGI_FORMAT layout_formats[LAYOUT_COUNT] =
18365 DXGI_FORMAT_R32G32B32A32_FLOAT,
18366 DXGI_FORMAT_R16G16B16A16_UINT,
18367 DXGI_FORMAT_R16G16B16A16_SINT,
18368 DXGI_FORMAT_R16G16B16A16_UNORM,
18369 DXGI_FORMAT_R16G16B16A16_SNORM,
18370 DXGI_FORMAT_R8G8B8A8_UINT,
18371 DXGI_FORMAT_R8G8B8A8_SINT,
18372 DXGI_FORMAT_R8G8B8A8_UNORM,
18373 DXGI_FORMAT_R8G8B8A8_SNORM,
18374 DXGI_FORMAT_R10G10B10A2_UNORM,
18375 DXGI_FORMAT_R10G10B10A2_UINT,
18377 static const struct vec2 quad[] =
18379 {-1.0f, -1.0f},
18380 {-1.0f, 1.0f},
18381 { 1.0f, -1.0f},
18382 { 1.0f, 1.0f},
18384 static const DWORD ps_code[] =
18386 #if 0
18387 float4 main(float4 position : POSITION, float4 color: COLOR) : SV_Target
18389 return color;
18391 #endif
18392 0x43425844, 0xa9150342, 0x70e18d2e, 0xf7769835, 0x4c3a7f02, 0x00000001, 0x000000f0, 0x00000003,
18393 0x0000002c, 0x0000007c, 0x000000b0, 0x4e475349, 0x00000048, 0x00000002, 0x00000008, 0x00000038,
18394 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000041, 0x00000000, 0x00000000,
18395 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f,
18396 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
18397 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
18398 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x001020f2,
18399 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
18401 static const DWORD vs_float_code[] =
18403 #if 0
18404 struct output
18406 float4 position : SV_Position;
18407 float4 color : COLOR;
18410 void main(float4 position : POSITION, float4 color : ATTRIBUTE, out output o)
18412 o.position = position;
18413 o.color = color;
18415 #endif
18416 0x43425844, 0xf6051ffd, 0xd9e49503, 0x171ad197, 0x3764fe47, 0x00000001, 0x00000144, 0x00000003,
18417 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18418 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18419 0x00000003, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18420 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18421 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18422 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18423 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18424 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18425 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18426 0x0100003e,
18428 static const DWORD vs_uint_code[] =
18430 #if 0
18431 struct output
18433 float4 position : SV_Position;
18434 float4 color : COLOR;
18437 void main(float4 position : POSITION, uint4 color : ATTRIBUTE, out output o)
18439 o.position = position;
18440 o.color = color;
18442 #endif
18443 0x43425844, 0x0bae0bc0, 0xf6473aa5, 0x4ecf4a25, 0x414fac23, 0x00000001, 0x00000144, 0x00000003,
18444 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18445 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18446 0x00000001, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18447 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18448 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18449 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18450 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18451 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18452 0x00000000, 0x00101e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18453 0x0100003e,
18455 static const DWORD vs_sint_code[] =
18457 #if 0
18458 struct output
18460 float4 position : SV_Position;
18461 float4 color : COLOR;
18464 void main(float4 position : POSITION, int4 color : ATTRIBUTE, out output o)
18466 o.position = position;
18467 o.color = color;
18469 #endif
18470 0x43425844, 0xaf60aad9, 0xba91f3a4, 0x2015d384, 0xf746fdf5, 0x00000001, 0x00000144, 0x00000003,
18471 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
18472 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
18473 0x00000002, 0x00000001, 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x54544100, 0x55424952, 0xab004554,
18474 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
18475 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
18476 0x505f5653, 0x7469736f, 0x006e6f69, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
18477 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
18478 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
18479 0x00000000, 0x00101e46, 0x00000000, 0x0500002b, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
18480 0x0100003e,
18482 static const float float32_data[] = {1.0f, 2.0f, 3.0f, 4.0f};
18483 static const unsigned short uint16_data[] = {6, 8, 55, 777};
18484 static const short sint16_data[] = {-1, 33, 8, -77};
18485 static const unsigned short unorm16_data[] = {0, 16383, 32767, 65535};
18486 static const short snorm16_data[] = {-32768, 0, 32767, 0};
18487 static const unsigned char uint8_data[] = {0, 64, 128, 255};
18488 static const signed char sint8_data[] = {-128, 0, 127, 64};
18489 static const unsigned int uint32_zero = 0;
18490 static const unsigned int uint32_max = 0xffffffff;
18491 static const unsigned int unorm10_2_data= 0xa00003ff;
18492 static const unsigned int g10_data = 0x000ffc00;
18493 static const unsigned int a2_data = 0xc0000000;
18494 static const struct
18496 enum layout_id layout_id;
18497 unsigned int stride;
18498 const void *data;
18499 struct vec4 expected_color;
18500 BOOL todo;
18502 tests[] =
18504 {LAYOUT_FLOAT32, sizeof(float32_data), float32_data,
18505 {1.0f, 2.0f, 3.0f, 4.0f}},
18506 {LAYOUT_UINT16, sizeof(uint16_data), uint16_data,
18507 {6.0f, 8.0f, 55.0f, 777.0f}, TRUE},
18508 {LAYOUT_SINT16, sizeof(sint16_data), sint16_data,
18509 {-1.0f, 33.0f, 8.0f, -77.0f}, TRUE},
18510 {LAYOUT_UNORM16, sizeof(unorm16_data), unorm16_data,
18511 {0.0f, 16383.0f / 65535.0f, 32767.0f / 65535.0f, 1.0f}},
18512 {LAYOUT_SNORM16, sizeof(snorm16_data), snorm16_data,
18513 {-1.0f, 0.0f, 1.0f, 0.0f}},
18514 {LAYOUT_UINT8, sizeof(uint32_zero), &uint32_zero,
18515 {0.0f, 0.0f, 0.0f, 0.0f}},
18516 {LAYOUT_UINT8, sizeof(uint32_max), &uint32_max,
18517 {255.0f, 255.0f, 255.0f, 255.0f}},
18518 {LAYOUT_UINT8, sizeof(uint8_data), uint8_data,
18519 {0.0f, 64.0f, 128.0f, 255.0f}},
18520 {LAYOUT_SINT8, sizeof(uint32_zero), &uint32_zero,
18521 {0.0f, 0.0f, 0.0f, 0.0f}},
18522 {LAYOUT_SINT8, sizeof(uint32_max), &uint32_max,
18523 {-1.0f, -1.0f, -1.0f, -1.0f}},
18524 {LAYOUT_SINT8, sizeof(sint8_data), sint8_data,
18525 {-128.0f, 0.0f, 127.0f, 64.0f}},
18526 {LAYOUT_UNORM8, sizeof(uint32_zero), &uint32_zero,
18527 {0.0f, 0.0f, 0.0f, 0.0f}},
18528 {LAYOUT_UNORM8, sizeof(uint32_max), &uint32_max,
18529 {1.0f, 1.0f, 1.0f, 1.0f}},
18530 {LAYOUT_UNORM8, sizeof(uint8_data), uint8_data,
18531 {0.0f, 64.0f / 255.0f, 128.0f / 255.0f, 1.0f}},
18532 {LAYOUT_SNORM8, sizeof(uint32_zero), &uint32_zero,
18533 {0.0f, 0.0f, 0.0f, 0.0f}},
18534 {LAYOUT_SNORM8, sizeof(sint8_data), sint8_data,
18535 {-1.0f, 0.0f, 1.0f, 64.0f / 127.0f}},
18536 {LAYOUT_UNORM10_2, sizeof(uint32_zero), &uint32_zero,
18537 {0.0f, 0.0f, 0.0f, 0.0f}},
18538 {LAYOUT_UNORM10_2, sizeof(uint32_max), &uint32_max,
18539 {1.0f, 1.0f, 1.0f, 1.0f}},
18540 {LAYOUT_UNORM10_2, sizeof(g10_data), &g10_data,
18541 {0.0f, 1.0f, 0.0f, 0.0f}},
18542 {LAYOUT_UNORM10_2, sizeof(a2_data), &a2_data,
18543 {0.0f, 0.0f, 0.0f, 1.0f}},
18544 {LAYOUT_UNORM10_2, sizeof(unorm10_2_data), &unorm10_2_data,
18545 {1.0f, 0.0f, 512.0f / 1023.0f, 2.0f / 3.0f}},
18546 {LAYOUT_UINT10_2, sizeof(uint32_zero), &uint32_zero,
18547 {0.0f, 0.0f, 0.0f, 0.0f}},
18548 {LAYOUT_UINT10_2, sizeof(uint32_max), &uint32_max,
18549 {1023.0f, 1023.0f, 1023.0f, 3.0f}},
18550 {LAYOUT_UINT10_2, sizeof(g10_data), &g10_data,
18551 {0.0f, 1023.0f, 0.0f, 0.0f}},
18552 {LAYOUT_UINT10_2, sizeof(a2_data), &a2_data,
18553 {0.0f, 0.0f, 0.0f, 3.0f}},
18554 {LAYOUT_UINT10_2, sizeof(unorm10_2_data), &unorm10_2_data,
18555 {1023.0f, 0.0f, 512.0f, 2.0f}},
18558 if (!init_test_context(&test_context, NULL))
18559 return;
18561 device = test_context.device;
18562 context = test_context.immediate_context;
18564 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18565 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18567 hr = ID3D11Device_CreateVertexShader(device, vs_float_code, sizeof(vs_float_code), NULL, &vs_float);
18568 ok(SUCCEEDED(hr), "Failed to create float vertex shader, hr %#x.\n", hr);
18569 hr = ID3D11Device_CreateVertexShader(device, vs_uint_code, sizeof(vs_uint_code), NULL, &vs_uint);
18570 ok(SUCCEEDED(hr), "Failed to create uint vertex shader, hr %#x.\n", hr);
18571 hr = ID3D11Device_CreateVertexShader(device, vs_sint_code, sizeof(vs_sint_code), NULL, &vs_sint);
18572 ok(SUCCEEDED(hr), "Failed to create sint vertex shader, hr %#x.\n", hr);
18574 for (i = 0; i < LAYOUT_COUNT; ++i)
18576 input_layout_desc[1].Format = layout_formats[i];
18577 input_layout[i] = NULL;
18578 hr = ID3D11Device_CreateInputLayout(device, input_layout_desc, ARRAY_SIZE(input_layout_desc),
18579 vs_float_code, sizeof(vs_float_code), &input_layout[i]);
18580 todo_wine_if(input_layout_desc[1].Format == DXGI_FORMAT_R10G10B10A2_UINT)
18581 ok(SUCCEEDED(hr), "Failed to create input layout for format %#x, hr %#x.\n", layout_formats[i], hr);
18584 vb_position = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
18585 vb_attribute = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, 1024, NULL);
18587 texture_desc.Width = 640;
18588 texture_desc.Height = 480;
18589 texture_desc.MipLevels = 1;
18590 texture_desc.ArraySize = 1;
18591 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
18592 texture_desc.SampleDesc.Count = 1;
18593 texture_desc.SampleDesc.Quality = 0;
18594 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18595 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
18596 texture_desc.CPUAccessFlags = 0;
18597 texture_desc.MiscFlags = 0;
18599 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_target);
18600 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
18602 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)render_target, NULL, &rtv);
18603 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
18605 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
18606 offset = 0;
18607 stride = sizeof(*quad);
18608 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb_position, &stride, &offset);
18609 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18610 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
18612 for (i = 0; i < ARRAY_SIZE(tests); ++i)
18614 D3D11_BOX box = {0, 0, 0, 1, 1, 1};
18616 if (tests[i].layout_id == LAYOUT_UINT10_2)
18617 continue;
18619 assert(tests[i].layout_id < LAYOUT_COUNT);
18620 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].layout_id]);
18622 assert(4 * tests[i].stride <= 1024);
18623 box.right = tests[i].stride;
18624 for (j = 0; j < 4; ++j)
18626 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb_attribute, 0,
18627 &box, tests[i].data, 0, 0);
18628 box.left += tests[i].stride;
18629 box.right += tests[i].stride;
18632 stride = tests[i].stride;
18633 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb_attribute, &stride, &offset);
18635 switch (layout_formats[tests[i].layout_id])
18637 case DXGI_FORMAT_R16G16B16A16_UINT:
18638 case DXGI_FORMAT_R10G10B10A2_UINT:
18639 case DXGI_FORMAT_R8G8B8A8_UINT:
18640 ID3D11DeviceContext_VSSetShader(context, vs_uint, NULL, 0);
18641 break;
18642 case DXGI_FORMAT_R16G16B16A16_SINT:
18643 case DXGI_FORMAT_R8G8B8A8_SINT:
18644 ID3D11DeviceContext_VSSetShader(context, vs_sint, NULL, 0);
18645 break;
18647 default:
18648 trace("Unhandled format %#x.\n", layout_formats[tests[i].layout_id]);
18649 /* Fall through. */
18650 case DXGI_FORMAT_R32G32B32A32_FLOAT:
18651 case DXGI_FORMAT_R16G16B16A16_UNORM:
18652 case DXGI_FORMAT_R16G16B16A16_SNORM:
18653 case DXGI_FORMAT_R10G10B10A2_UNORM:
18654 case DXGI_FORMAT_R8G8B8A8_UNORM:
18655 case DXGI_FORMAT_R8G8B8A8_SNORM:
18656 ID3D11DeviceContext_VSSetShader(context, vs_float, NULL, 0);
18657 break;
18660 ID3D11DeviceContext_Draw(context, 4, 0);
18661 check_texture_vec4(render_target, &tests[i].expected_color, 2);
18664 ID3D11Texture2D_Release(render_target);
18665 ID3D11RenderTargetView_Release(rtv);
18666 ID3D11Buffer_Release(vb_attribute);
18667 ID3D11Buffer_Release(vb_position);
18668 for (i = 0; i < LAYOUT_COUNT; ++i)
18670 if (input_layout[i])
18671 ID3D11InputLayout_Release(input_layout[i]);
18673 ID3D11PixelShader_Release(ps);
18674 ID3D11VertexShader_Release(vs_float);
18675 ID3D11VertexShader_Release(vs_uint);
18676 ID3D11VertexShader_Release(vs_sint);
18677 release_test_context(&test_context);
18680 static void test_null_sampler(void)
18682 struct d3d11_test_context test_context;
18683 D3D11_TEXTURE2D_DESC texture_desc;
18684 ID3D11ShaderResourceView *srv;
18685 ID3D11DeviceContext *context;
18686 ID3D11RenderTargetView *rtv;
18687 ID3D11SamplerState *sampler;
18688 ID3D11Texture2D *texture;
18689 ID3D11PixelShader *ps;
18690 ID3D11Device *device;
18691 HRESULT hr;
18693 static const DWORD ps_code[] =
18695 #if 0
18696 Texture2D t;
18697 SamplerState s;
18699 float4 main(float4 position : SV_POSITION) : SV_Target
18701 return t.Sample(s, float2(position.x / 640.0f, position.y / 480.0f));
18703 #endif
18704 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
18705 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
18706 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
18707 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
18708 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
18709 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
18710 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
18711 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
18712 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
18713 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
18715 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
18717 if (!init_test_context(&test_context, NULL))
18718 return;
18720 device = test_context.device;
18721 context = test_context.immediate_context;
18723 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
18724 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
18726 texture_desc.Width = 64;
18727 texture_desc.Height = 64;
18728 texture_desc.MipLevels = 1;
18729 texture_desc.ArraySize = 1;
18730 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
18731 texture_desc.SampleDesc.Count = 1;
18732 texture_desc.SampleDesc.Quality = 0;
18733 texture_desc.Usage = D3D11_USAGE_DEFAULT;
18734 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
18735 texture_desc.CPUAccessFlags = 0;
18736 texture_desc.MiscFlags = 0;
18738 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
18739 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
18741 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
18742 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
18744 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
18745 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
18747 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, blue);
18749 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
18750 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
18751 sampler = NULL;
18752 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
18753 draw_quad(&test_context);
18754 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
18756 ID3D11ShaderResourceView_Release(srv);
18757 ID3D11RenderTargetView_Release(rtv);
18758 ID3D11Texture2D_Release(texture);
18759 ID3D11PixelShader_Release(ps);
18760 release_test_context(&test_context);
18763 static void test_check_feature_support(void)
18765 D3D11_FEATURE_DATA_THREADING threading[2];
18766 D3D11_FEATURE_DATA_D3D10_X_HARDWARE_OPTIONS hwopts;
18767 D3D11_FEATURE_DATA_ARCHITECTURE_INFO archinfo;
18768 ID3D11Device *device;
18769 ULONG refcount;
18770 HRESULT hr;
18772 if (!(device = create_device(NULL)))
18774 skip("Failed to create device.\n");
18775 return;
18778 memset(threading, 0xef, sizeof(threading));
18780 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, NULL, 0);
18781 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18782 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, 0);
18783 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18784 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) - 1);
18785 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18786 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) / 2);
18787 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18788 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) + 1);
18789 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18790 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading) * 2);
18791 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18793 ok(threading[0].DriverConcurrentCreates == 0xefefefef,
18794 "Got unexpected concurrent creates %#x.\n", threading[0].DriverConcurrentCreates);
18795 ok(threading[0].DriverCommandLists == 0xefefefef,
18796 "Got unexpected command lists %#x.\n", threading[0].DriverCommandLists);
18797 ok(threading[1].DriverConcurrentCreates == 0xefefefef,
18798 "Got unexpected concurrent creates %#x.\n", threading[1].DriverConcurrentCreates);
18799 ok(threading[1].DriverCommandLists == 0xefefefef,
18800 "Got unexpected command lists %#x.\n", threading[1].DriverCommandLists);
18802 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_THREADING, threading, sizeof(*threading));
18803 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18804 ok(threading->DriverConcurrentCreates == TRUE || threading->DriverConcurrentCreates == FALSE,
18805 "Got unexpected concurrent creates %#x.\n", threading->DriverConcurrentCreates);
18806 ok(threading->DriverCommandLists == TRUE || threading->DriverCommandLists == FALSE,
18807 "Got unexpected command lists %#x.\n", threading->DriverCommandLists);
18809 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, NULL, 0);
18810 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18811 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, 0);
18812 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18813 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) - 1);
18814 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18815 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) / 2);
18816 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18817 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) + 1);
18818 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18819 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts) * 2);
18820 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18822 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_D3D10_X_HARDWARE_OPTIONS, &hwopts, sizeof(hwopts));
18823 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
18824 trace("Compute shader support via SM4 %#x.\n", hwopts.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x);
18826 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo));
18827 ok(hr == S_OK || broken(hr == E_INVALIDARG) /* Not available on all Windows versions. */,
18828 "Got unexpected hr %#x.\n", hr);
18829 hr = ID3D11Device_CheckFeatureSupport(device, D3D11_FEATURE_ARCHITECTURE_INFO, &archinfo, sizeof(archinfo)*2);
18830 ok(hr == E_INVALIDARG /* Not available on all Windows versions but they will return E_INVALIDARG anyways. */,
18831 "Got unexpected hr %#x.\n", hr);
18833 refcount = ID3D11Device_Release(device);
18834 ok(!refcount, "Device has %u references left.\n", refcount);
18837 static void test_create_unordered_access_view(void)
18839 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
18840 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
18841 D3D11_TEXTURE3D_DESC texture3d_desc;
18842 D3D11_TEXTURE2D_DESC texture2d_desc;
18843 ULONG refcount, expected_refcount;
18844 D3D11_SUBRESOURCE_DATA data = {0};
18845 ID3D11UnorderedAccessView *uav;
18846 struct device_desc device_desc;
18847 D3D11_BUFFER_DESC buffer_desc;
18848 ID3D11Device *device, *tmp;
18849 ID3D11Texture3D *texture3d;
18850 ID3D11Texture2D *texture2d;
18851 ID3D11Resource *texture;
18852 ID3D11Buffer *buffer;
18853 unsigned int i;
18854 HRESULT hr;
18856 #define FMT_UNKNOWN DXGI_FORMAT_UNKNOWN
18857 #define RGBA8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM
18858 #define RGBA8_SRGB DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
18859 #define RGBA8_UINT DXGI_FORMAT_R8G8B8A8_UINT
18860 #define RGBA8_TL DXGI_FORMAT_R8G8B8A8_TYPELESS
18861 #define DIM_UNKNOWN D3D11_UAV_DIMENSION_UNKNOWN
18862 #define TEX_1D D3D11_UAV_DIMENSION_TEXTURE1D
18863 #define TEX_1D_ARRAY D3D11_UAV_DIMENSION_TEXTURE1DARRAY
18864 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
18865 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
18866 #define TEX_3D D3D11_UAV_DIMENSION_TEXTURE3D
18867 static const struct
18869 struct
18871 unsigned int miplevel_count;
18872 unsigned int depth_or_array_size;
18873 DXGI_FORMAT format;
18874 } texture;
18875 struct uav_desc uav_desc;
18876 struct uav_desc expected_uav_desc;
18878 tests[] =
18880 {{ 1, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
18881 {{10, 1, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D, 0}},
18882 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
18883 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 1}, {RGBA8_UNORM, TEX_2D, 1}},
18884 {{10, 1, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D, 9}, {RGBA8_UNORM, TEX_2D, 9}},
18885 {{ 1, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
18886 {{10, 1, RGBA8_TL}, {RGBA8_UNORM, TEX_2D, 0}, {RGBA8_UNORM, TEX_2D, 0}},
18887 {{ 1, 1, RGBA8_UINT}, {0}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
18888 {{ 1, 1, RGBA8_TL}, {RGBA8_UINT, TEX_2D, 0, 0, ~0u}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
18889 {{ 1, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
18890 {{10, 4, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
18891 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 4}},
18892 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 1, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 4}},
18893 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 3, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 3, 0, 4}},
18894 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 5, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 5, 0, 4}},
18895 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 9, 0, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 9, 0, 4}},
18896 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 1, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 3}},
18897 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 2, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 2, 2}},
18898 {{10, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_2D_ARRAY, 0, 3, ~0u}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 3, 1}},
18899 {{ 1, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
18900 {{ 2, 6, RGBA8_UNORM}, {0}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
18901 {{ 2, 6, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 6}},
18902 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
18903 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 2}},
18904 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 1, 3}},
18905 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 2, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 2, 2}},
18906 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 3, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 3, 1}},
18907 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 1, 1}, {RGBA8_UNORM, TEX_3D, 0, 1, 1}},
18908 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, 1}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
18909 {{ 2, 4, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 1, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 1, 1}},
18910 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 0, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 0, 0, 8}},
18911 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 1, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 1, 0, 4}},
18912 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 2, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 2, 0, 2}},
18913 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 3, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 3, 0, 1}},
18914 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 4, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 4, 0, 1}},
18915 {{ 6, 8, RGBA8_UNORM}, {FMT_UNKNOWN, TEX_3D, 5, 0, ~0u}, {RGBA8_UNORM, TEX_3D, 5, 0, 1}},
18917 static const struct
18919 struct
18921 D3D11_UAV_DIMENSION dimension;
18922 unsigned int miplevel_count;
18923 unsigned int depth_or_array_size;
18924 DXGI_FORMAT format;
18925 } texture;
18926 struct uav_desc uav_desc;
18928 invalid_desc_tests[] =
18930 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
18931 {{TEX_2D, 6, 4, RGBA8_UNORM}, {RGBA8_UNORM, DIM_UNKNOWN}},
18932 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
18933 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
18934 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 1}},
18935 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, ~0u}},
18936 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_2D, 0}},
18937 {{TEX_2D, 1, 1, RGBA8_TL}, {FMT_UNKNOWN, TEX_2D, 0}},
18938 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 1}},
18939 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 0}},
18940 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 1, 0, 1}},
18941 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 2}},
18942 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 1, 1}},
18943 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_UINT, TEX_2D, 0, 0, 1}},
18944 {{TEX_2D, 1, 1, RGBA8_UINT}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
18945 {{TEX_2D, 1, 1, RGBA8_UNORM}, {RGBA8_SRGB, TEX_2D, 0, 0, 1}},
18946 {{TEX_2D, 1, 1, RGBA8_SRGB}, {RGBA8_UNORM, TEX_2D, 0, 0, 1}},
18947 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
18948 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
18949 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
18950 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
18951 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D, 0}},
18952 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_1D_ARRAY, 0, 0, 1}},
18953 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D, 0}},
18954 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_UNORM, TEX_2D_ARRAY, 0, 0, 1}},
18955 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 0}},
18956 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 1}},
18957 {{TEX_3D, 1, 1, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
18958 {{TEX_3D, 1, 9, RGBA8_UNORM}, {RGBA8_TL, TEX_3D, 0, 0, 1}},
18959 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 0, 9}},
18960 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 0, 2}},
18961 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 0, 4}},
18962 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 0, 8}},
18963 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 0, 8, ~0u}},
18964 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 1, 4, ~0u}},
18965 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 2, 2, ~0u}},
18966 {{TEX_3D, 4, 8, RGBA8_UNORM}, {RGBA8_UNORM, TEX_3D, 3, 1, ~0u}},
18968 #undef FMT_UNKNOWN
18969 #undef RGBA8_UNORM
18970 #undef RGBA8_SRGB
18971 #undef RGBA8_UINT
18972 #undef RGBA8_TL
18973 #undef DIM_UNKNOWN
18974 #undef TEX_1D
18975 #undef TEX_1D_ARRAY
18976 #undef TEX_2D
18977 #undef TEX_2D_ARRAY
18978 #undef TEX_3D
18980 device_desc.feature_level = &feature_level;
18981 device_desc.flags = 0;
18982 if (!(device = create_device(&device_desc)))
18984 skip("Failed to create device.\n");
18985 return;
18988 buffer_desc.ByteWidth = 1024;
18989 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
18990 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
18991 buffer_desc.CPUAccessFlags = 0;
18992 buffer_desc.MiscFlags = 0;
18993 buffer_desc.StructureByteStride = 0;
18995 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &data, &buffer);
18996 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
18998 expected_refcount = get_refcount(device) + 1;
18999 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19000 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19001 refcount = get_refcount(device);
19002 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
19003 tmp = NULL;
19004 expected_refcount = refcount + 1;
19005 ID3D11Buffer_GetDevice(buffer, &tmp);
19006 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
19007 refcount = get_refcount(device);
19008 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
19009 ID3D11Device_Release(tmp);
19011 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19012 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19013 U(uav_desc).Buffer.FirstElement = 0;
19014 U(uav_desc).Buffer.NumElements = 64;
19015 U(uav_desc).Buffer.Flags = 0;
19017 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19018 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19020 expected_refcount = get_refcount(device) + 1;
19021 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19022 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19023 refcount = get_refcount(device);
19024 ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount);
19025 tmp = NULL;
19026 expected_refcount = refcount + 1;
19027 ID3D11UnorderedAccessView_GetDevice(uav, &tmp);
19028 ok(tmp == device, "Got unexpected device %p, expected %p.\n", tmp, device);
19029 refcount = get_refcount(device);
19030 ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount);
19031 ID3D11Device_Release(tmp);
19033 ID3D11UnorderedAccessView_Release(uav);
19034 ID3D11Buffer_Release(buffer);
19036 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
19037 buffer_desc.StructureByteStride = 4;
19039 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
19040 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
19042 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
19043 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
19045 memset(&uav_desc, 0, sizeof(uav_desc));
19046 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
19048 ok(uav_desc.Format == DXGI_FORMAT_UNKNOWN, "Got unexpected format %#x.\n", uav_desc.Format);
19049 ok(uav_desc.ViewDimension == D3D11_UAV_DIMENSION_BUFFER, "Got unexpected view dimension %#x.\n",
19050 uav_desc.ViewDimension);
19051 ok(!U(uav_desc).Buffer.FirstElement, "Got unexpected first element %u.\n", U(uav_desc).Buffer.FirstElement);
19052 ok(U(uav_desc).Buffer.NumElements == 256, "Got unexpected num elements %u.\n", U(uav_desc).Buffer.NumElements);
19053 ok(!U(uav_desc).Buffer.Flags, "Got unexpected flags %u.\n", U(uav_desc).Buffer.Flags);
19055 ID3D11UnorderedAccessView_Release(uav);
19056 ID3D11Buffer_Release(buffer);
19058 /* Without D3D11_BIND_UNORDERED_ACCESS. */
19059 buffer = create_buffer(device, 0, 1024, NULL);
19061 uav_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19062 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
19063 U(uav_desc).Buffer.FirstElement = 0;
19064 U(uav_desc).Buffer.NumElements = 64;
19065 U(uav_desc).Buffer.Flags = 0;
19067 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
19068 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
19070 ID3D11Buffer_Release(buffer);
19072 texture2d_desc.Width = 512;
19073 texture2d_desc.Height = 512;
19074 texture2d_desc.SampleDesc.Count = 1;
19075 texture2d_desc.SampleDesc.Quality = 0;
19076 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
19077 texture2d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19078 texture2d_desc.CPUAccessFlags = 0;
19079 texture2d_desc.MiscFlags = 0;
19081 texture3d_desc.Width = 64;
19082 texture3d_desc.Height = 64;
19083 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
19084 texture3d_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
19085 texture3d_desc.CPUAccessFlags = 0;
19086 texture3d_desc.MiscFlags = 0;
19088 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19090 D3D11_UNORDERED_ACCESS_VIEW_DESC *current_desc;
19092 if (tests[i].expected_uav_desc.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
19094 texture2d_desc.MipLevels = tests[i].texture.miplevel_count;
19095 texture2d_desc.ArraySize = tests[i].texture.depth_or_array_size;
19096 texture2d_desc.Format = tests[i].texture.format;
19098 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
19099 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
19100 texture = (ID3D11Resource *)texture2d;
19102 else
19104 texture3d_desc.MipLevels = tests[i].texture.miplevel_count;
19105 texture3d_desc.Depth = tests[i].texture.depth_or_array_size;
19106 texture3d_desc.Format = tests[i].texture.format;
19108 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
19109 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
19110 texture = (ID3D11Resource *)texture3d;
19113 if (tests[i].uav_desc.dimension == D3D11_UAV_DIMENSION_UNKNOWN)
19115 current_desc = NULL;
19117 else
19119 current_desc = &uav_desc;
19120 get_uav_desc(current_desc, &tests[i].uav_desc);
19123 expected_refcount = get_refcount(texture);
19124 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, current_desc, &uav);
19125 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
19126 refcount = get_refcount(texture);
19127 ok(refcount == expected_refcount, "Got refcount %u, expected %u.\n", refcount, expected_refcount);
19129 memset(&uav_desc, 0, sizeof(uav_desc));
19130 ID3D11UnorderedAccessView_GetDesc(uav, &uav_desc);
19131 check_uav_desc(&uav_desc, &tests[i].expected_uav_desc);
19133 ID3D11UnorderedAccessView_Release(uav);
19134 ID3D11Resource_Release(texture);
19137 for (i = 0; i < ARRAY_SIZE(invalid_desc_tests); ++i)
19139 assert(invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE2D
19140 || invalid_desc_tests[i].texture.dimension == D3D11_UAV_DIMENSION_TEXTURE3D);
19142 if (invalid_desc_tests[i].texture.dimension != D3D11_UAV_DIMENSION_TEXTURE3D)
19144 texture2d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
19145 texture2d_desc.ArraySize = invalid_desc_tests[i].texture.depth_or_array_size;
19146 texture2d_desc.Format = invalid_desc_tests[i].texture.format;
19148 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, &texture2d);
19149 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
19150 texture = (ID3D11Resource *)texture2d;
19152 else
19154 texture3d_desc.MipLevels = invalid_desc_tests[i].texture.miplevel_count;
19155 texture3d_desc.Depth = invalid_desc_tests[i].texture.depth_or_array_size;
19156 texture3d_desc.Format = invalid_desc_tests[i].texture.format;
19158 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, &texture3d);
19159 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
19160 texture = (ID3D11Resource *)texture3d;
19163 get_uav_desc(&uav_desc, &invalid_desc_tests[i].uav_desc);
19164 hr = ID3D11Device_CreateUnorderedAccessView(device, texture, &uav_desc, &uav);
19165 ok(hr == E_INVALIDARG, "Test %u: Got unexpected hr %#x.\n", i, hr);
19167 ID3D11Resource_Release(texture);
19170 refcount = ID3D11Device_Release(device);
19171 ok(!refcount, "Device has %u references left.\n", refcount);
19174 static void test_immediate_constant_buffer(void)
19176 struct d3d11_test_context test_context;
19177 D3D11_TEXTURE2D_DESC texture_desc;
19178 ID3D11DeviceContext *context;
19179 ID3D11RenderTargetView *rtv;
19180 unsigned int index[4] = {0};
19181 ID3D11Texture2D *texture;
19182 ID3D11PixelShader *ps;
19183 ID3D11Device *device;
19184 ID3D11Buffer *cb;
19185 unsigned int i;
19186 HRESULT hr;
19188 static const DWORD ps_code[] =
19190 #if 0
19191 uint index;
19193 static const int int_array[6] =
19195 310, 111, 212, -513, -318, 0,
19198 static const uint uint_array[6] =
19200 2, 7, 0x7f800000, 0xff800000, 0x7fc00000, 0
19203 static const float float_array[6] =
19205 76, 83.5f, 0.5f, 0.75f, -0.5f, 0.0f,
19208 float4 main() : SV_Target
19210 return float4(int_array[index], uint_array[index], float_array[index], 1.0f);
19212 #endif
19213 0x43425844, 0xbad068da, 0xd631ea3c, 0x41648374, 0x3ccd0120, 0x00000001, 0x00000184, 0x00000003,
19214 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19215 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19216 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000010c, 0x00000040, 0x00000043,
19217 0x00001835, 0x0000001a, 0x00000136, 0x00000002, 0x42980000, 0x00000000, 0x0000006f, 0x00000007,
19218 0x42a70000, 0x00000000, 0x000000d4, 0x7f800000, 0x3f000000, 0x00000000, 0xfffffdff, 0xff800000,
19219 0x3f400000, 0x00000000, 0xfffffec2, 0x7fc00000, 0xbf000000, 0x00000000, 0x00000000, 0x00000000,
19220 0x00000000, 0x00000000, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
19221 0x00000000, 0x02000068, 0x00000001, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
19222 0x06000036, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000056, 0x00102022,
19223 0x00000000, 0x0090901a, 0x0010000a, 0x00000000, 0x0600002b, 0x00102012, 0x00000000, 0x0090900a,
19224 0x0010000a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0090902a, 0x0010000a, 0x00000000,
19225 0x0100003e,
19227 static struct vec4 expected_result[] =
19229 { 310.0f, 2.0f, 76.00f, 1.0f},
19230 { 111.0f, 7.0f, 83.50f, 1.0f},
19231 { 212.0f, 2139095040.0f, 0.50f, 1.0f},
19232 {-513.0f, 4286578688.0f, 0.75f, 1.0f},
19233 {-318.0f, 2143289344.0f, -0.50f, 1.0f},
19234 { 0.0f, 0.0f, 0.0f, 1.0f},
19237 if (!init_test_context(&test_context, NULL))
19238 return;
19240 device = test_context.device;
19241 context = test_context.immediate_context;
19243 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19244 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19245 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19247 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(index), NULL);
19248 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19250 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19251 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19252 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19253 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19255 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19256 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19257 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19259 for (i = 0; i < ARRAY_SIZE(expected_result); ++i)
19261 *index = i;
19262 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, index, 0, 0);
19264 draw_quad(&test_context);
19265 check_texture_vec4(texture, &expected_result[i], 0);
19268 ID3D11Buffer_Release(cb);
19269 ID3D11PixelShader_Release(ps);
19270 ID3D11Texture2D_Release(texture);
19271 ID3D11RenderTargetView_Release(rtv);
19272 release_test_context(&test_context);
19275 static void test_fp_specials(void)
19277 struct d3d11_test_context test_context;
19278 D3D11_TEXTURE2D_DESC texture_desc;
19279 ID3D11DeviceContext *context;
19280 ID3D11RenderTargetView *rtv;
19281 ID3D11Texture2D *texture;
19282 ID3D11PixelShader *ps;
19283 ID3D11Device *device;
19284 HRESULT hr;
19286 static const DWORD ps_code[] =
19288 #if 0
19289 float4 main() : SV_Target
19291 return float4(0.0f / 0.0f, 1.0f / 0.0f, -1.0f / 0.0f, 1.0f);
19293 #endif
19294 0x43425844, 0x86d7f319, 0x14cde598, 0xe7ce83a8, 0x0e06f3f0, 0x00000001, 0x000000b0, 0x00000003,
19295 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19296 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
19297 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
19298 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0xffc00000,
19299 0x7f800000, 0xff800000, 0x3f800000, 0x0100003e,
19301 static const struct uvec4 expected_result = {BITS_NNAN, BITS_INF, BITS_NINF, BITS_1_0};
19303 if (!init_test_context(&test_context, NULL))
19304 return;
19306 device = test_context.device;
19307 context = test_context.immediate_context;
19309 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
19310 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19311 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19313 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19314 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
19315 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19316 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19318 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19319 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19321 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19323 draw_quad(&test_context);
19324 check_texture_uvec4(texture, &expected_result);
19326 ID3D11PixelShader_Release(ps);
19327 ID3D11Texture2D_Release(texture);
19328 ID3D11RenderTargetView_Release(rtv);
19329 release_test_context(&test_context);
19332 static void test_uint_shader_instructions(void)
19334 struct shader
19336 const DWORD *code;
19337 size_t size;
19338 D3D_FEATURE_LEVEL required_feature_level;
19341 struct d3d11_test_context test_context;
19342 D3D11_TEXTURE2D_DESC texture_desc;
19343 D3D_FEATURE_LEVEL feature_level;
19344 ID3D11DeviceContext *context;
19345 ID3D11RenderTargetView *rtv;
19346 ID3D11Texture2D *texture;
19347 ID3D11PixelShader *ps;
19348 ID3D11Device *device;
19349 ID3D11Buffer *cb;
19350 unsigned int i;
19351 HRESULT hr;
19353 static const DWORD ps_bfi_code[] =
19355 #if 0
19356 uint bits, offset, insert, base;
19358 uint4 main() : SV_Target
19360 uint mask = ((1 << bits) - 1) << offset;
19361 return ((insert << offset) & mask) | (base & ~mask);
19363 #endif
19364 0x43425844, 0xbe9af688, 0xf5caec6f, 0x63ed2522, 0x5f91f209, 0x00000001, 0x000000e0, 0x00000003,
19365 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19366 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19367 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000068, 0x00000050, 0x0000001a,
19368 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19369 0x0f00008c, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
19370 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x00208ff6, 0x00000000, 0x00000000, 0x0100003e,
19372 static const DWORD ps_bfi2_code[] =
19374 #if 0
19375 ps_5_0
19376 dcl_globalFlags refactoringAllowed
19377 dcl_constantbuffer cb0[1], immediateIndexed
19378 dcl_output o0.xyzw
19379 dcl_temps 1
19380 mov r0.xyzw, cb0[0].xyzw
19381 bfi r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz, r0.wwww
19382 mov o0.xyzw, r0.xyzw
19384 #endif
19385 0x43425844, 0x900f86b6, 0x73f4dabf, 0xea1b1106, 0x591ac790, 0x00000001, 0x00000104, 0x00000003,
19386 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19387 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19388 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000008c, 0x00000050, 0x00000023,
19389 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19390 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19391 0x0b00008c, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19392 0x00000000, 0x00100ff6, 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
19393 0x0100003e,
19395 static const DWORD ps_ibfe_code[] =
19397 #if 0
19398 ps_5_0
19399 dcl_globalFlags refactoringAllowed
19400 dcl_constantbuffer cb0[1], immediateIndexed
19401 dcl_output o0.xyzw
19402 ibfe o0.xyzw, cb0[0].xxxx, cb0[0].yyyy, cb0[0].zzzz
19404 #endif
19405 0x43425844, 0x4b2225f7, 0xd0860f66, 0xe38775bb, 0x6d23d1d2, 0x00000001, 0x000000d4, 0x00000003,
19406 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19407 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19408 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
19409 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19410 0x0c00008b, 0x001020f2, 0x00000000, 0x00208006, 0x00000000, 0x00000000, 0x00208556, 0x00000000,
19411 0x00000000, 0x00208aa6, 0x00000000, 0x00000000, 0x0100003e,
19413 static const DWORD ps_ibfe2_code[] =
19415 #if 0
19416 ps_5_0
19417 dcl_globalFlags refactoringAllowed
19418 dcl_constantbuffer cb0[1], immediateIndexed
19419 dcl_output o0.xyzw
19420 dcl_temps 1
19421 mov r0.xyzw, cb0[0].xyzw
19422 ibfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
19423 mov o0.xyzw, r0.xyzw
19425 #endif
19426 0x43425844, 0x347a9c0e, 0x3eff39a4, 0x3dd41cc5, 0xff87ec8d, 0x00000001, 0x000000fc, 0x00000003,
19427 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19428 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19429 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
19430 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19431 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19432 0x0900008b, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19433 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19435 static const DWORD ps_ubfe_code[] =
19437 #if 0
19438 uint u;
19440 uint4 main() : SV_Target
19442 return uint4((u & 0xf0) >> 4, (u & 0x7fffff00) >> 8, (u & 0xfe) >> 1, (u & 0x7fffffff) >> 1);
19444 #endif
19445 0x43425844, 0xc4ac0509, 0xaea83154, 0xf1fb3b80, 0x4c22e3cc, 0x00000001, 0x000000e4, 0x00000003,
19446 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19447 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19448 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000006c, 0x00000050, 0x0000001b,
19449 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19450 0x1000008a, 0x001020f2, 0x00000000, 0x00004002, 0x00000004, 0x00000017, 0x00000007, 0x0000001e,
19451 0x00004002, 0x00000004, 0x00000008, 0x00000001, 0x00000001, 0x00208006, 0x00000000, 0x00000000,
19452 0x0100003e,
19454 static const DWORD ps_ubfe2_code[] =
19456 #if 0
19457 ps_5_0
19458 dcl_globalFlags refactoringAllowed
19459 dcl_constantbuffer cb0[1], immediateIndexed
19460 dcl_output o0.xyzw
19461 dcl_temps 1
19462 mov r0.xyzw, cb0[0].xyzw
19463 ubfe r0.xyzw, r0.xxxx, r0.yyyy, r0.zzzz
19464 mov o0.xyzw, r0.xyzw
19466 #endif
19467 0x43425844, 0xf377b7fc, 0x1e4cb9e7, 0xb9b1020d, 0xde484388, 0x00000001, 0x000000fc, 0x00000003,
19468 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19469 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19470 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
19471 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19472 0x02000068, 0x00000001, 0x06000036, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19473 0x0900008a, 0x001000f2, 0x00000000, 0x00100006, 0x00000000, 0x00100556, 0x00000000, 0x00100aa6,
19474 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19476 static const DWORD ps_bfrev_code[] =
19478 #if 0
19479 uint bits;
19481 uint4 main() : SV_Target
19483 return uint4(reversebits(bits), reversebits(reversebits(bits)),
19484 reversebits(bits & 0xFFFF), reversebits(bits >> 16));
19486 #endif
19487 0x43425844, 0x73daef82, 0xe52befa3, 0x8504d5f0, 0xebdb321d, 0x00000001, 0x00000154, 0x00000003,
19488 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19489 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19490 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000dc, 0x00000050, 0x00000037,
19491 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19492 0x02000068, 0x00000001, 0x08000001, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000,
19493 0x00004001, 0x0000ffff, 0x0500008d, 0x00102042, 0x00000000, 0x0010000a, 0x00000000, 0x08000055,
19494 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000010, 0x0500008d,
19495 0x00102082, 0x00000000, 0x0010000a, 0x00000000, 0x0600008d, 0x00100012, 0x00000000, 0x0020800a,
19496 0x00000000, 0x00000000, 0x0500008d, 0x00102022, 0x00000000, 0x0010000a, 0x00000000, 0x05000036,
19497 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
19499 static const DWORD ps_bits_code[] =
19501 #if 0
19502 uint u;
19503 int i;
19505 uint4 main() : SV_Target
19507 return uint4(countbits(u), firstbitlow(u), firstbithigh(u), firstbithigh(i));
19509 #endif
19510 0x43425844, 0x23fee911, 0x145287d1, 0xea904419, 0x8aa59a6a, 0x00000001, 0x000001b4, 0x00000003,
19511 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19512 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19513 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000013c, 0x00000050, 0x0000004f,
19514 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19515 0x02000068, 0x00000001, 0x06000089, 0x00100012, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
19516 0x07000020, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff, 0x0800001e,
19517 0x00100012, 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x09000037,
19518 0x00102082, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0xffffffff, 0x0010000a, 0x00000000,
19519 0x06000087, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0800001e, 0x00100012,
19520 0x00000000, 0x00004001, 0x0000001f, 0x8010000a, 0x00000041, 0x00000000, 0x0a000037, 0x00102042,
19521 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0xffffffff,
19522 0x06000086, 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x06000088, 0x00102022,
19523 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0100003e,
19525 static const DWORD ps_ftou_code[] =
19527 #if 0
19528 float f;
19530 uint4 main() : SV_Target
19532 return uint4(f, -f, 0, 0);
19534 #endif
19535 0x43425844, 0xfde0ee2d, 0x812b339a, 0xb9fc36d2, 0x5820bec6, 0x00000001, 0x000000f4, 0x00000003,
19536 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19537 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19538 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040, 0x0000001f,
19539 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x0600001c,
19540 0x00102012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0700001c, 0x00102022, 0x00000000,
19541 0x8020800a, 0x00000041, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002,
19542 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
19544 static const DWORD ps_f16tof32_code[] =
19546 #if 0
19547 uint4 hf;
19549 uint4 main() : SV_Target
19551 return f16tof32(hf);
19553 #endif
19554 0x43425844, 0xc1816e6e, 0x27562d96, 0x56980fa2, 0x421e6640, 0x00000001, 0x000000d8, 0x00000003,
19555 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19556 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19557 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
19558 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19559 0x02000068, 0x00000001, 0x06000083, 0x001000f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000,
19560 0x0500001c, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x0100003e,
19562 static const DWORD ps_f32tof16_code[] =
19564 #if 0
19565 float4 f;
19567 uint4 main() : SV_Target
19569 return f32tof16(f);
19571 #endif
19572 0x43425844, 0x523a765c, 0x1a5be3a9, 0xaed69c80, 0xd26fe296, 0x00000001, 0x000000bc, 0x00000003,
19573 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19574 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19575 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000044, 0x00000050, 0x00000011,
19576 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
19577 0x06000082, 0x001020f2, 0x00000000, 0x00208e46, 0x00000000, 0x00000000, 0x0100003e,
19579 static const DWORD ps_not_code[] =
19581 #if 0
19582 uint2 bits;
19584 uint4 main() : SV_Target
19586 return uint4(~bits.x, ~(bits.x ^ ~0u), ~bits.y, ~(bits.y ^ ~0u));
19588 #endif
19589 0x43425844, 0xaed0fd26, 0xf719a878, 0xc832efd6, 0xba03c264, 0x00000001, 0x00000100, 0x00000003,
19590 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
19591 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
19592 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088, 0x00000040, 0x00000022,
19593 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
19594 0x00000001, 0x0b000057, 0x00100032, 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x00004002,
19595 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x0500003b, 0x001020a2, 0x00000000, 0x00100406,
19596 0x00000000, 0x0600003b, 0x00102052, 0x00000000, 0x00208106, 0x00000000, 0x00000000, 0x0100003e,
19598 static const struct shader ps_bfi = {ps_bfi_code, sizeof(ps_bfi_code), D3D_FEATURE_LEVEL_11_0};
19599 static const struct shader ps_bfi2 = {ps_bfi2_code, sizeof(ps_bfi2_code), D3D_FEATURE_LEVEL_11_0};
19600 static const struct shader ps_ibfe = {ps_ibfe_code, sizeof(ps_ibfe_code), D3D_FEATURE_LEVEL_11_0};
19601 static const struct shader ps_ibfe2 = {ps_ibfe2_code, sizeof(ps_ibfe2_code), D3D_FEATURE_LEVEL_11_0};
19602 static const struct shader ps_ubfe = {ps_ubfe_code, sizeof(ps_ubfe_code), D3D_FEATURE_LEVEL_11_0};
19603 static const struct shader ps_ubfe2 = {ps_ubfe2_code, sizeof(ps_ubfe2_code), D3D_FEATURE_LEVEL_11_0};
19604 static const struct shader ps_bfrev = {ps_bfrev_code, sizeof(ps_bfrev_code), D3D_FEATURE_LEVEL_11_0};
19605 static const struct shader ps_bits = {ps_bits_code, sizeof(ps_bits_code), D3D_FEATURE_LEVEL_11_0};
19606 static const struct shader ps_ftou = {ps_ftou_code, sizeof(ps_ftou_code), D3D_FEATURE_LEVEL_10_0};
19607 static const struct shader ps_f16tof32 = {ps_f16tof32_code, sizeof(ps_f16tof32_code), D3D_FEATURE_LEVEL_11_0};
19608 static const struct shader ps_f32tof16 = {ps_f32tof16_code, sizeof(ps_f32tof16_code), D3D_FEATURE_LEVEL_11_0};
19609 static const struct shader ps_not = {ps_not_code, sizeof(ps_not_code), D3D_FEATURE_LEVEL_10_0};
19610 static const struct
19612 const struct shader *ps;
19613 unsigned int bits[4];
19614 struct uvec4 expected_result;
19616 tests[] =
19618 {&ps_bfi, { 0, 0, 0, 0}, { 0, 0, 0, 0}},
19619 {&ps_bfi, { 0, 0, 0, 1}, { 1, 1, 1, 1}},
19620 {&ps_bfi, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19621 {&ps_bfi, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19622 {&ps_bfi, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19623 {&ps_bfi, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19624 {&ps_bfi, { 0, 0, 0xff, 1}, { 1, 1, 1, 1}},
19625 {&ps_bfi, { 0, 0, 0xff, 2}, { 2, 2, 2, 2}},
19626 {&ps_bfi, { 16, 16, 0xff, 0xff}, {0x00ff00ff, 0x00ff00ff, 0x00ff00ff, 0x00ff00ff}},
19627 {&ps_bfi, { 0, 0, ~0u, ~0u}, { ~0u, ~0u, ~0u, ~0u}},
19628 {&ps_bfi, {~0x1fu, 0, ~0u, 0}, { 0, 0, 0, 0}},
19629 {&ps_bfi, {~0x1fu, 0, ~0u, 1}, { 1, 1, 1, 1}},
19630 {&ps_bfi, {~0x1fu, 0, ~0u, 2}, { 2, 2, 2, 2}},
19631 {&ps_bfi, { 0, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
19632 {&ps_bfi, { 0, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
19633 {&ps_bfi, { 0, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
19634 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 0}, { 0, 0, 0, 0}},
19635 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 1}, { 1, 1, 1, 1}},
19636 {&ps_bfi, {~0x1fu, ~0x1fu, ~0u, 2}, { 2, 2, 2, 2}},
19638 {&ps_bfi2, { ~0u, 0, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19639 {&ps_bfi2, { ~0u, ~0u, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19640 {&ps_bfi2, { ~0u, 0x1fu, ~0u, 0}, {0x80000000, 0x80000000, 0x80000000, 0x80000000}},
19641 {&ps_bfi2, { ~0u, ~0x1fu, ~0u, 0}, {0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff}},
19643 {&ps_ibfe, { 0, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19644 {&ps_ibfe, { 0, 4, 0xffffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19645 {&ps_ibfe, { 0, 4, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19646 {&ps_ibfe, { 4, 0, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19647 {&ps_ibfe, { 4, 0, 0xfffffffa}, {0xfffffffa, 0xfffffffa, 0xfffffffa, 0xfffffffa}},
19648 {&ps_ibfe, { 4, 0, 0x7ffffffc}, {0xfffffffc, 0xfffffffc, 0xfffffffc, 0xfffffffc}},
19649 {&ps_ibfe, { 4, 4, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19650 {&ps_ibfe, { 4, 4, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19651 {&ps_ibfe, { 4, 4, 0xffffff1f}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
19652 {&ps_ibfe, { 4, 4, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19653 {&ps_ibfe, {23, 8, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19654 {&ps_ibfe, {23, 8, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19655 {&ps_ibfe, {23, 8, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19656 {&ps_ibfe, {30, 1, 0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19657 {&ps_ibfe, {30, 1, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19658 {&ps_ibfe, {30, 1, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19659 {&ps_ibfe, {15, 15, 0x7fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19660 {&ps_ibfe, {15, 15, 0x3fffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19661 {&ps_ibfe, {15, 15, 0x1fffffff}, {0x00003fff, 0x00003fff, 0x00003fff, 0x00003fff}},
19662 {&ps_ibfe, {15, 15, 0xffff00ff}, {0xfffffffe, 0xfffffffe, 0xfffffffe, 0xfffffffe}},
19663 {&ps_ibfe, {16, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19664 {&ps_ibfe, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19665 {&ps_ibfe, {20, 15, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19666 {&ps_ibfe, {31, 31, 0xffffffff}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19667 {&ps_ibfe, {31, 31, 0x80000000}, {0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}},
19668 {&ps_ibfe, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19670 {&ps_ibfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19672 {&ps_ubfe, {0x00000000}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19673 {&ps_ubfe, {0xffffffff}, {0x0000000f, 0x007fffff, 0x0000007f, 0x3fffffff}},
19674 {&ps_ubfe, {0xff000000}, {0x00000000, 0x007f0000, 0x00000000, 0x3f800000}},
19675 {&ps_ubfe, {0x00ff0000}, {0x00000000, 0x0000ff00, 0x00000000, 0x007f8000}},
19676 {&ps_ubfe, {0x000000ff}, {0x0000000f, 0x00000000, 0x0000007f, 0x0000007f}},
19677 {&ps_ubfe, {0x80000001}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19678 {&ps_ubfe, {0xc0000003}, {0x00000000, 0x00400000, 0x00000001, 0x20000001}},
19680 {&ps_ubfe2, { 4, 4, 0x7fffffff}, {0x0000000f, 0x0000000f, 0x0000000f, 0x0000000f}},
19681 {&ps_ubfe2, {23, 8, 0xffffffff}, {0x007fffff, 0x007fffff, 0x007fffff, 0x007fffff}},
19682 {&ps_ubfe2, {30, 1, 0xffffffff}, {0x3fffffff, 0x3fffffff, 0x3fffffff, 0x3fffffff}},
19683 {&ps_ubfe2, {15, 15, 0x7fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19684 {&ps_ubfe2, {15, 15, 0xffff00ff}, {0x00007ffe, 0x00007ffe, 0x00007ffe, 0x00007ffe}},
19685 {&ps_ubfe2, {16, 15, 0xffffffff}, {0x0000ffff, 0x0000ffff, 0x0000ffff, 0x0000ffff}},
19686 {&ps_ubfe2, {16, 15, 0x3fffffff}, {0x00007fff, 0x00007fff, 0x00007fff, 0x00007fff}},
19687 {&ps_ubfe2, {20, 15, 0xffffffff}, {0x0001ffff, 0x0001ffff, 0x0001ffff, 0x0001ffff}},
19688 {&ps_ubfe2, {31, 31, 0xffffffff}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
19689 {&ps_ubfe2, {31, 31, 0x80000000}, {0x00000001, 0x00000001, 0x00000001, 0x00000001}},
19690 {&ps_ubfe2, {31, 31, 0x7fffffff}, {0x00000000, 0x00000000, 0x00000000, 0x00000000}},
19692 {&ps_bfrev, {0x12345678}, {0x1e6a2c48, 0x12345678, 0x1e6a0000, 0x2c480000}},
19693 {&ps_bfrev, {0xffff0000}, {0x0000ffff, 0xffff0000, 0x00000000, 0xffff0000}},
19694 {&ps_bfrev, {0xffffffff}, {0xffffffff, 0xffffffff, 0xffff0000, 0xffff0000}},
19696 {&ps_bits, { 0, 0}, { 0, ~0u, ~0u, ~0u}},
19697 {&ps_bits, { ~0u, ~0u}, {32, 0, 31, ~0u}},
19698 {&ps_bits, {0x7fffffff, 0x7fffffff}, {31, 0, 30, 30}},
19699 {&ps_bits, {0x80000000, 0x80000000}, { 1, 31, 31, 30}},
19700 {&ps_bits, {0x00000001, 0x00000001}, { 1, 0, 0, 0}},
19701 {&ps_bits, {0x80000001, 0x80000001}, { 2, 0, 31, 30}},
19702 {&ps_bits, {0x88888888, 0x88888888}, { 8, 3, 31, 30}},
19703 {&ps_bits, {0xcccccccc, 0xcccccccc}, {16, 2, 31, 29}},
19704 {&ps_bits, {0x11111111, 0x11111c11}, { 8, 0, 28, 28}},
19705 {&ps_bits, {0x0000000f, 0x0000000f}, { 4, 0, 3, 3}},
19706 {&ps_bits, {0x8000000f, 0x8000000f}, { 5, 0, 31, 30}},
19707 {&ps_bits, {0x00080000, 0x00080000}, { 1, 19, 19, 19}},
19709 {&ps_ftou, {BITS_NNAN}, { 0, 0}},
19710 {&ps_ftou, {BITS_NAN}, { 0, 0}},
19711 {&ps_ftou, {BITS_NINF}, { 0, ~0u}},
19712 {&ps_ftou, {BITS_INF}, {~0u, 0}},
19713 {&ps_ftou, {BITS_N1_0}, { 0, 1}},
19714 {&ps_ftou, {BITS_1_0}, { 1, 0}},
19716 {&ps_f16tof32, {0x00000000, 0x00003c00, 0x00005640, 0x00005bd0}, {0, 1, 100, 250}},
19717 {&ps_f16tof32, {0x00010000, 0x00013c00, 0x00015640, 0x00015bd0}, {0, 1, 100, 250}},
19718 {&ps_f16tof32, {0x000f0000, 0x000f3c00, 0x000f5640, 0x000f5bd0}, {0, 1, 100, 250}},
19719 {&ps_f16tof32, {0xffff0000, 0xffff3c00, 0xffff5640, 0xffff5bd0}, {0, 1, 100, 250}},
19721 {&ps_f32tof16, {0, BITS_1_0, BITS_N1_0, 0x44268000}, {0, 0x3c00, 0xbc00, 0x6134}},
19723 {&ps_not, {0x00000000, 0xffffffff}, {0xffffffff, 0x00000000, 0x00000000, 0xffffffff}},
19724 {&ps_not, {0xf0f0f0f0, 0x0f0f0f0f}, {0x0f0f0f0f, 0xf0f0f0f0, 0xf0f0f0f0, 0x0f0f0f0f}},
19727 if (!init_test_context(&test_context, NULL))
19728 return;
19730 device = test_context.device;
19731 context = test_context.immediate_context;
19732 feature_level = ID3D11Device_GetFeatureLevel(device);
19734 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(tests[0].bits), NULL);
19735 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
19737 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
19738 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
19739 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
19740 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
19742 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
19743 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
19745 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
19747 for (i = 0; i < ARRAY_SIZE(tests); ++i)
19749 if (feature_level < tests[i].ps->required_feature_level)
19750 continue;
19752 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
19753 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
19754 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
19756 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, tests[i].bits, 0, 0);
19758 draw_quad(&test_context);
19759 check_texture_uvec4(texture, &tests[i].expected_result);
19761 ID3D11PixelShader_Release(ps);
19764 ID3D11Buffer_Release(cb);
19765 ID3D11Texture2D_Release(texture);
19766 ID3D11RenderTargetView_Release(rtv);
19767 release_test_context(&test_context);
19770 static void test_index_buffer_offset(void)
19772 ID3D11Buffer *vb, *ib, *so_buffer, *args_buffer;
19773 struct d3d11_test_context test_context;
19774 ID3D11InputLayout *input_layout;
19775 ID3D11DeviceContext *context;
19776 struct resource_readback rb;
19777 ID3D11GeometryShader *gs;
19778 const struct vec4 *data;
19779 ID3D11VertexShader *vs;
19780 ID3D11Device *device;
19781 UINT stride, offset;
19782 unsigned int i;
19783 HRESULT hr;
19785 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
19786 static const DWORD vs_code[] =
19788 #if 0
19789 void main(float4 position : SV_POSITION, float4 attrib : ATTRIB,
19790 out float4 out_position : SV_Position, out float4 out_attrib : ATTRIB)
19792 out_position = position;
19793 out_attrib = attrib;
19795 #endif
19796 0x43425844, 0xd7716716, 0xe23207f3, 0xc8af57c0, 0x585e2919, 0x00000001, 0x00000144, 0x00000003,
19797 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19798 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19799 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
19800 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19801 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19802 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0xab004249, 0x52444853, 0x00000068, 0x00010040,
19803 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
19804 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
19805 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
19806 0x0100003e,
19808 static const DWORD gs_code[] =
19810 #if 0
19811 struct vertex
19813 float4 position : SV_POSITION;
19814 float4 attrib : ATTRIB;
19817 [maxvertexcount(1)]
19818 void main(point vertex input[1], inout PointStream<vertex> output)
19820 output.Append(input[0]);
19821 output.RestartStrip();
19823 #endif
19824 0x43425844, 0x3d1dc497, 0xdf450406, 0x284ab03b, 0xa4ec0fd6, 0x00000001, 0x00000170, 0x00000003,
19825 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
19826 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
19827 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249,
19828 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
19829 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
19830 0x505f5653, 0x5449534f, 0x004e4f49, 0x52545441, 0xab004249, 0x52444853, 0x00000094, 0x00020040,
19831 0x00000025, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
19832 0x00000001, 0x00000001, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
19833 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000,
19834 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
19835 0x00000001, 0x01000013, 0x01000009, 0x0100003e,
19837 static const D3D11_INPUT_ELEMENT_DESC input_desc[] =
19839 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
19840 {"ATTRIB", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
19842 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
19844 {0, "SV_Position", 0, 0, 4, 0},
19845 {0, "ATTRIB", 0, 0, 4, 0},
19847 static const struct
19849 struct vec4 position;
19850 struct vec4 attrib;
19852 vertices[] =
19854 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f}},
19855 {{-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f}},
19856 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f}},
19857 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f}},
19859 static const unsigned int indices[] =
19861 0, 1, 2, 3,
19862 3, 2, 1, 0,
19863 1, 3, 2, 0,
19865 static const struct vec4 expected_data[] =
19867 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
19868 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
19869 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
19870 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
19872 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
19873 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
19874 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
19875 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
19877 {-1.0f, 1.0f, 0.0f, 1.0f}, {2.0f},
19878 { 1.0f, 1.0f, 0.0f, 1.0f}, {4.0f},
19879 { 1.0f, -1.0f, 0.0f, 1.0f}, {3.0f},
19880 {-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f},
19882 static const struct vec4 broken_result = {0.0f, 0.0f, 0.0f, 1.0f};
19883 static const D3D11_DRAW_INDEXED_INSTANCED_INDIRECT_ARGS argument_data[] =
19885 {4, 1, 0, 0, 0},
19888 if (!init_test_context(&test_context, &feature_level))
19889 return;
19891 device = test_context.device;
19892 context = test_context.immediate_context;
19894 hr = ID3D11Device_CreateInputLayout(device, input_desc, ARRAY_SIZE(input_desc),
19895 vs_code, sizeof(vs_code), &input_layout);
19896 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
19898 stride = 32;
19899 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
19900 so_declaration, ARRAY_SIZE(so_declaration),
19901 &stride, 1, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
19902 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
19904 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
19905 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
19907 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
19908 ib = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices), indices);
19909 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
19911 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
19912 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
19914 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
19915 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
19916 stride = sizeof(*vertices);
19917 offset = 0;
19918 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
19920 offset = 0;
19921 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
19923 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
19924 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
19926 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
19927 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
19929 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
19930 ID3D11DeviceContext_DrawIndexed(context, 4, 0, 0);
19932 get_buffer_readback(so_buffer, &rb);
19933 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
19935 data = get_readback_vec4(&rb, i, 0);
19936 ok(compare_vec4(data, &expected_data[i], 0)
19937 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
19938 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
19939 data->x, data->y, data->z, data->w, i);
19941 release_resource_readback(&rb);
19943 /* indirect draws */
19944 args_buffer = create_buffer_misc(device, 0, D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS,
19945 sizeof(argument_data), argument_data);
19947 offset = 0;
19948 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
19950 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 0);
19951 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
19953 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 4 * sizeof(*indices));
19954 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
19956 ID3D11DeviceContext_IASetIndexBuffer(context, ib, DXGI_FORMAT_R32_UINT, 8 * sizeof(*indices));
19957 ID3D11DeviceContext_DrawIndexedInstancedIndirect(context, args_buffer, 0);
19959 get_buffer_readback(so_buffer, &rb);
19960 for (i = 0; i < ARRAY_SIZE(expected_data); ++i)
19962 data = get_readback_vec4(&rb, i, 0);
19963 todo_wine_if(i >= 8 && i != 20 && i != 21)
19964 ok(compare_vec4(data, &expected_data[i], 0)
19965 || broken(is_nvidia_device(device) && !(i % 2) && compare_vec4(data, &broken_result, 0)),
19966 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u.\n",
19967 data->x, data->y, data->z, data->w, i);
19969 release_resource_readback(&rb);
19971 ID3D11Buffer_Release(so_buffer);
19972 ID3D11Buffer_Release(args_buffer);
19973 ID3D11Buffer_Release(ib);
19974 ID3D11Buffer_Release(vb);
19975 ID3D11VertexShader_Release(vs);
19976 ID3D11GeometryShader_Release(gs);
19977 ID3D11InputLayout_Release(input_layout);
19978 release_test_context(&test_context);
19981 static void test_face_culling(void)
19983 struct d3d11_test_context test_context;
19984 D3D11_RASTERIZER_DESC rasterizer_desc;
19985 ID3D11RasterizerState *state;
19986 ID3D11DeviceContext *context;
19987 ID3D11Buffer *cw_vb, *ccw_vb;
19988 ID3D11Device *device;
19989 BOOL broken_warp;
19990 unsigned int i;
19991 HRESULT hr;
19993 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
19994 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
19995 static const DWORD ps_code[] =
19997 #if 0
19998 float4 main(uint front : SV_IsFrontFace) : SV_Target
20000 return (front == ~0u) ? float4(0.0f, 1.0f, 0.0f, 1.0f) : float4(0.0f, 0.0f, 1.0f, 1.0f);
20002 #endif
20003 0x43425844, 0x92002fad, 0xc5c620b9, 0xe7a154fb, 0x78b54e63, 0x00000001, 0x00000128, 0x00000003,
20004 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
20005 0x00000000, 0x00000009, 0x00000001, 0x00000000, 0x00000101, 0x495f5653, 0x6f724673, 0x6146746e,
20006 0xab006563, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
20007 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000088,
20008 0x00000040, 0x00000022, 0x04000863, 0x00101012, 0x00000000, 0x00000009, 0x03000065, 0x001020f2,
20009 0x00000000, 0x02000068, 0x00000001, 0x07000020, 0x00100012, 0x00000000, 0x0010100a, 0x00000000,
20010 0x00004001, 0xffffffff, 0x0f000037, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00004002,
20011 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000,
20012 0x3f800000, 0x0100003e,
20014 static const struct vec3 ccw_quad[] =
20016 {-1.0f, 1.0f, 0.0f},
20017 {-1.0f, -1.0f, 0.0f},
20018 { 1.0f, 1.0f, 0.0f},
20019 { 1.0f, -1.0f, 0.0f},
20021 static const struct
20023 D3D11_CULL_MODE cull_mode;
20024 BOOL front_ccw;
20025 BOOL expected_cw;
20026 BOOL expected_ccw;
20028 tests[] =
20030 {D3D11_CULL_NONE, FALSE, TRUE, TRUE},
20031 {D3D11_CULL_NONE, TRUE, TRUE, TRUE},
20032 {D3D11_CULL_FRONT, FALSE, FALSE, TRUE},
20033 {D3D11_CULL_FRONT, TRUE, TRUE, FALSE},
20034 {D3D11_CULL_BACK, FALSE, TRUE, FALSE},
20035 {D3D11_CULL_BACK, TRUE, FALSE, TRUE},
20038 if (!init_test_context(&test_context, NULL))
20039 return;
20041 device = test_context.device;
20042 context = test_context.immediate_context;
20044 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20045 draw_color_quad(&test_context, &green);
20046 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20048 cw_vb = test_context.vb;
20049 ccw_vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
20051 test_context.vb = ccw_vb;
20052 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20053 draw_color_quad(&test_context, &green);
20054 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
20056 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
20057 rasterizer_desc.CullMode = D3D11_CULL_BACK;
20058 rasterizer_desc.FrontCounterClockwise = FALSE;
20059 rasterizer_desc.DepthBias = 0;
20060 rasterizer_desc.DepthBiasClamp = 0.0f;
20061 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
20062 rasterizer_desc.DepthClipEnable = TRUE;
20063 rasterizer_desc.ScissorEnable = FALSE;
20064 rasterizer_desc.MultisampleEnable = FALSE;
20065 rasterizer_desc.AntialiasedLineEnable = FALSE;
20067 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20069 rasterizer_desc.CullMode = tests[i].cull_mode;
20070 rasterizer_desc.FrontCounterClockwise = tests[i].front_ccw;
20071 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20072 ok(SUCCEEDED(hr), "Test %u: Failed to create rasterizer state, hr %#x.\n", i, hr);
20074 ID3D11DeviceContext_RSSetState(context, state);
20076 test_context.vb = cw_vb;
20077 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20078 draw_color_quad(&test_context, &green);
20079 check_texture_color(test_context.backbuffer, tests[i].expected_cw ? 0xff00ff00 : 0xff0000ff, 0);
20081 test_context.vb = ccw_vb;
20082 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20083 draw_color_quad(&test_context, &green);
20084 check_texture_color(test_context.backbuffer, tests[i].expected_ccw ? 0xff00ff00 : 0xff0000ff, 0);
20086 ID3D11RasterizerState_Release(state);
20089 broken_warp = is_warp_device(device) && ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0;
20091 /* Test SV_IsFrontFace. */
20092 ID3D11PixelShader_Release(test_context.ps);
20093 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &test_context.ps);
20094 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20096 rasterizer_desc.CullMode = D3D11_CULL_NONE;
20097 rasterizer_desc.FrontCounterClockwise = FALSE;
20098 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20099 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20100 ID3D11DeviceContext_RSSetState(context, state);
20102 test_context.vb = cw_vb;
20103 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20104 draw_color_quad(&test_context, &green);
20105 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20106 test_context.vb = ccw_vb;
20107 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20108 draw_color_quad(&test_context, &green);
20109 if (!broken_warp)
20110 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
20111 else
20112 win_skip("Broken WARP.\n");
20114 ID3D11RasterizerState_Release(state);
20116 rasterizer_desc.CullMode = D3D11_CULL_NONE;
20117 rasterizer_desc.FrontCounterClockwise = TRUE;
20118 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &state);
20119 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20120 ID3D11DeviceContext_RSSetState(context, state);
20122 test_context.vb = cw_vb;
20123 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20124 draw_color_quad(&test_context, &green);
20125 if (!broken_warp)
20126 check_texture_color(test_context.backbuffer, 0xffff0000 , 0);
20127 else
20128 win_skip("Broken WARP.\n");
20129 test_context.vb = ccw_vb;
20130 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20131 draw_color_quad(&test_context, &green);
20132 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
20134 ID3D11RasterizerState_Release(state);
20136 test_context.vb = cw_vb;
20137 ID3D11Buffer_Release(ccw_vb);
20138 release_test_context(&test_context);
20141 static void test_line_antialiasing_blending(void)
20143 ID3D11RasterizerState *rasterizer_state;
20144 struct d3d11_test_context test_context;
20145 D3D11_RASTERIZER_DESC rasterizer_desc;
20146 ID3D11BlendState *blend_state;
20147 ID3D11DeviceContext *context;
20148 D3D11_BLEND_DESC blend_desc;
20149 ID3D11Device *device;
20150 HRESULT hr;
20152 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 0.8f};
20153 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 0.5f};
20155 if (!init_test_context(&test_context, NULL))
20156 return;
20158 device = test_context.device;
20159 context = test_context.immediate_context;
20161 memset(&blend_desc, 0, sizeof(blend_desc));
20162 blend_desc.AlphaToCoverageEnable = FALSE;
20163 blend_desc.IndependentBlendEnable = FALSE;
20164 blend_desc.RenderTarget[0].BlendEnable = TRUE;
20165 blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
20166 blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_DEST_ALPHA;
20167 blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
20168 blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
20169 blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
20170 blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
20171 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
20173 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
20174 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
20175 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
20177 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20178 draw_color_quad(&test_context, &green);
20179 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
20181 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20182 draw_color_quad(&test_context, &red);
20183 check_texture_color(test_context.backbuffer, 0xe2007fcc, 1);
20185 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, D3D11_DEFAULT_SAMPLE_MASK);
20186 ID3D11BlendState_Release(blend_state);
20188 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20189 draw_color_quad(&test_context, &green);
20190 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
20192 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20193 draw_color_quad(&test_context, &red);
20194 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
20196 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
20197 rasterizer_desc.CullMode = D3D11_CULL_BACK;
20198 rasterizer_desc.FrontCounterClockwise = FALSE;
20199 rasterizer_desc.DepthBias = 0;
20200 rasterizer_desc.DepthBiasClamp = 0.0f;
20201 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
20202 rasterizer_desc.DepthClipEnable = TRUE;
20203 rasterizer_desc.ScissorEnable = FALSE;
20204 rasterizer_desc.MultisampleEnable = FALSE;
20205 rasterizer_desc.AntialiasedLineEnable = TRUE;
20207 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
20208 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20209 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
20211 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &red.x);
20212 draw_color_quad(&test_context, &green);
20213 check_texture_color(test_context.backbuffer, 0x7f00ff00, 1);
20215 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &green.x);
20216 draw_color_quad(&test_context, &red);
20217 check_texture_color(test_context.backbuffer, 0xcc0000ff, 1);
20219 ID3D11RasterizerState_Release(rasterizer_state);
20220 release_test_context(&test_context);
20223 static void check_format_support(const unsigned int *format_support, D3D_FEATURE_LEVEL feature_level,
20224 const struct format_support *formats, unsigned int format_count, unsigned int feature_flag,
20225 const char *feature_name)
20227 unsigned int i;
20229 for (i = 0; i < format_count; ++i)
20231 DXGI_FORMAT format = formats[i].format;
20232 unsigned int supported = format_support[format] & feature_flag;
20234 if (formats[i].fl_required <= feature_level)
20236 todo_wine ok(supported, "Format %#x - %s not supported, feature_level %#x, format support %#x.\n",
20237 format, feature_name, feature_level, format_support[format]);
20238 continue;
20241 if (formats[i].fl_optional && formats[i].fl_optional <= feature_level)
20243 if (supported)
20244 trace("Optional format %#x - %s supported, feature level %#x.\n",
20245 format, feature_name, feature_level);
20246 continue;
20249 ok(!supported, "Format %#x - %s supported, feature level %#x, format support %#x.\n",
20250 format, feature_name, feature_level, format_support[format]);
20254 static void test_format_support(const D3D_FEATURE_LEVEL feature_level)
20256 unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
20257 struct device_desc device_desc;
20258 ID3D11Device *device;
20259 DXGI_FORMAT format;
20260 ULONG refcount;
20261 UINT support;
20262 HRESULT hr;
20264 static const struct format_support index_buffers[] =
20266 {DXGI_FORMAT_R32_UINT, D3D_FEATURE_LEVEL_9_2},
20267 {DXGI_FORMAT_R16_UINT, D3D_FEATURE_LEVEL_9_1},
20270 device_desc.feature_level = &feature_level;
20271 device_desc.flags = 0;
20272 if (!(device = create_device(&device_desc)))
20274 skip("Failed to create device for feature level %#x.\n", feature_level);
20275 return;
20278 support = 0xdeadbeef;
20279 hr = ID3D11Device_CheckFormatSupport(device, ~0u, &support);
20280 ok(hr == E_FAIL, "Got unexpected hr %#x.\n", hr);
20281 ok(!support, "Got unexpected format support %#x.\n", support);
20283 memset(format_support, 0, sizeof(format_support));
20284 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
20286 hr = ID3D11Device_CheckFormatSupport(device, format, &format_support[format]);
20287 ok(hr == S_OK || (hr == E_FAIL && !format_support[format]),
20288 "Got unexpected result for format %#x: hr %#x, format_support %#x.\n",
20289 format, hr, format_support[format]);
20290 if (format_support[format] & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN)
20292 ok(format_support[format] & D3D11_FORMAT_SUPPORT_TEXTURE2D,
20293 "Got unexpected format support %#x for format %#x", format_support[format], format);
20297 for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
20299 if (feature_level < D3D_FEATURE_LEVEL_10_0)
20301 /* SHADER_SAMPLE_COMPARISON is never advertised as supported on feature level 9. */
20302 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON),
20303 "Unexpected SHADER_SAMPLE_COMPARISON for format %#x, feature level %#x.\n",
20304 format, feature_level);
20305 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_BUFFER),
20306 "Unexpected BUFFER for format %#x, feature level %#x.\n",
20307 format, feature_level);
20309 if (feature_level < D3D_FEATURE_LEVEL_10_1)
20311 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER),
20312 "Unexpected SHADER_GATHER for format %#x, feature level %#x.\n",
20313 format, feature_level);
20314 ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON),
20315 "Unexpected SHADER_GATHER_COMPARISON for format %#x, feature level %#x.\n",
20316 format, feature_level);
20320 ok(format_support[DXGI_FORMAT_R8G8B8A8_UNORM] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE,
20321 "SHADER_SAMPLE is not supported for R8G8B8A8_UNORM.\n");
20322 todo_wine
20323 ok(!(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE),
20324 "SHADER_SAMPLE is supported for R32G32B32A32_UINT.\n");
20325 if (feature_level >= D3D_FEATURE_LEVEL_10_0)
20327 ok(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_LOAD,
20328 "SHADER_LOAD is not supported for R32G32B32A32_UINT.\n");
20331 check_format_support(format_support, feature_level,
20332 index_buffers, ARRAY_SIZE(index_buffers),
20333 D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
20335 check_format_support(format_support, feature_level,
20336 display_format_support, ARRAY_SIZE(display_format_support),
20337 D3D11_FORMAT_SUPPORT_DISPLAY, "display");
20339 refcount = ID3D11Device_Release(device);
20340 ok(!refcount, "Device has %u references left.\n", refcount);
20343 static void test_fl9_draw(const D3D_FEATURE_LEVEL feature_level)
20345 struct d3d11_test_context test_context;
20346 D3D11_SUBRESOURCE_DATA resource_data;
20347 D3D11_TEXTURE2D_DESC texture_desc;
20348 ID3D11ShaderResourceView *srv;
20349 ID3D11DeviceContext *context;
20350 ID3D11Texture2D *texture;
20351 ID3D11PixelShader *ps;
20352 ID3D11Device *device;
20353 HRESULT hr;
20355 static const struct vec4 color = {0.2f, 0.3f, 0.0f, 1.0f};
20356 static const DWORD ps_code[] =
20358 #if 0
20359 float4 main() : SV_TARGET
20361 return float4(1.0f, 0.0f, 0.0f, 0.5f);
20363 #endif
20364 0x43425844, 0xb70eda74, 0xc9a7f982, 0xebc31bbf, 0x952a1360, 0x00000001, 0x00000168, 0x00000005,
20365 0x00000034, 0x0000008c, 0x000000e4, 0x00000124, 0x00000134, 0x53414e58, 0x00000050, 0x00000050,
20366 0xffff0200, 0x0000002c, 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000,
20367 0xffff0200, 0x05000051, 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001,
20368 0x800f0800, 0xa0e40000, 0x0000ffff, 0x396e6f41, 0x00000050, 0x00000050, 0xffff0200, 0x0000002c,
20369 0x00000024, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0x00240000, 0xffff0200, 0x05000051,
20370 0xa00f0000, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000, 0x02000001, 0x800f0800, 0xa0e40000,
20371 0x0000ffff, 0x52444853, 0x00000038, 0x00000040, 0x0000000e, 0x03000065, 0x001020f2, 0x00000000,
20372 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f000000,
20373 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f, 0x0000002c, 0x00000001,
20374 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653,
20375 0x45475241, 0xabab0054,
20377 static const DWORD ps_texture_code[] =
20379 #if 0
20380 Texture2D t;
20381 SamplerState s;
20383 float4 main() : SV_TARGET
20385 return t.Sample(s, (float2)0);
20387 #endif
20388 0x43425844, 0xf876c2db, 0x13725f1f, 0xcb6d3d65, 0x9994473f, 0x00000001, 0x000001d4, 0x00000005,
20389 0x00000034, 0x000000a0, 0x00000124, 0x00000190, 0x000001a0, 0x53414e58, 0x00000064, 0x00000064,
20390 0xffff0200, 0x0000003c, 0x00000028, 0x00280000, 0x00280000, 0x00280000, 0x00240001, 0x00280000,
20391 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
20392 0x0200001f, 0x90000000, 0xa00f0800, 0x03000042, 0x800f0800, 0xa0000000, 0xa0e40800, 0x0000ffff,
20393 0x396e6f41, 0x0000007c, 0x0000007c, 0xffff0200, 0x00000054, 0x00000028, 0x00280000, 0x00280000,
20394 0x00280000, 0x00240001, 0x00280000, 0x00000000, 0xffff0200, 0x05000051, 0xa00f0000, 0x00000000,
20395 0x00000000, 0x00000000, 0x00000000, 0x0200001f, 0x90000000, 0xa00f0800, 0x02000001, 0x80030000,
20396 0xa0000000, 0x03000042, 0x800f0000, 0x80e40000, 0xa0e40800, 0x02000001, 0x800f0800, 0x80e40000,
20397 0x0000ffff, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x0300005a, 0x00106000, 0x00000000,
20398 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x0c000045,
20399 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46,
20400 0x00000000, 0x00106000, 0x00000000, 0x0100003e, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
20401 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20402 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054,
20404 static const DWORD texture_data[] = {0xffffff00};
20406 if (!init_test_context(&test_context, &feature_level))
20407 return;
20409 device = test_context.device;
20410 context = test_context.immediate_context;
20412 texture_desc.Width = 1;
20413 texture_desc.Height = 1;
20414 texture_desc.MipLevels = 0;
20415 texture_desc.ArraySize = 1;
20416 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20417 texture_desc.SampleDesc.Count = 1;
20418 texture_desc.SampleDesc.Quality = 0;
20419 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20420 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20421 texture_desc.CPUAccessFlags = 0;
20422 texture_desc.MiscFlags = 0;
20423 resource_data.pSysMem = texture_data;
20424 resource_data.SysMemPitch = sizeof(texture_data);
20425 resource_data.SysMemSlicePitch = 0;
20426 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20427 ok(SUCCEEDED(hr), "Failed to create 2d texture, hr %#x.\n", hr);
20428 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
20429 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20431 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20432 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
20433 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20434 draw_quad(&test_context);
20435 check_texture_color(test_context.backbuffer, 0x7f0000ff, 1);
20436 ID3D11PixelShader_Release(ps);
20438 draw_color_quad(&test_context, &color);
20439 todo_wine check_texture_color(test_context.backbuffer, 0xff004c33, 1);
20441 hr = ID3D11Device_CreatePixelShader(device, ps_texture_code, sizeof(ps_texture_code), NULL, &ps);
20442 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x, feature level %#x.\n", hr, feature_level);
20443 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20444 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20445 draw_quad(&test_context);
20446 check_texture_color(test_context.backbuffer, 0xffffff00, 1);
20447 ID3D11PixelShader_Release(ps);
20449 ID3D11ShaderResourceView_Release(srv);
20450 ID3D11Texture2D_Release(texture);
20451 release_test_context(&test_context);
20454 static void queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL begin,
20455 D3D_FEATURE_LEVEL end, void (*test_func)(const D3D_FEATURE_LEVEL fl))
20457 static const D3D_FEATURE_LEVEL feature_levels[] =
20459 D3D_FEATURE_LEVEL_11_1,
20460 D3D_FEATURE_LEVEL_11_0,
20461 D3D_FEATURE_LEVEL_10_1,
20462 D3D_FEATURE_LEVEL_10_0,
20463 D3D_FEATURE_LEVEL_9_3,
20464 D3D_FEATURE_LEVEL_9_2,
20465 D3D_FEATURE_LEVEL_9_1
20467 unsigned int i;
20469 assert(begin <= end);
20470 for (i = 0; i < ARRAY_SIZE(feature_levels); ++i)
20472 if (begin <= feature_levels[i] && feature_levels[i] <= end)
20473 queue_test_fl(test_func, feature_levels[i]);
20477 static void queue_for_each_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
20479 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
20480 D3D_FEATURE_LEVEL_11_1, test_func);
20483 static void queue_for_each_9_x_feature_level(void (*test_func)(const D3D_FEATURE_LEVEL fl))
20485 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_9_1,
20486 D3D_FEATURE_LEVEL_9_3, test_func);
20489 static void test_ddy(void)
20491 static const struct
20493 struct vec4 position;
20494 unsigned int color;
20496 quad[] =
20498 {{-1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
20499 {{-1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
20500 {{ 1.0f, -1.0f, 0.0f, 1.0f}, 0x00ff0000},
20501 {{ 1.0f, 1.0f, 0.0f, 1.0f}, 0x0000ff00},
20503 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
20505 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
20506 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
20508 #if 0
20509 struct vs_data
20511 float4 pos : SV_POSITION;
20512 float4 color : COLOR;
20515 void main(in struct vs_data vs_input, out struct vs_data vs_output)
20517 vs_output.pos = vs_input.pos;
20518 vs_output.color = vs_input.color;
20520 #endif
20521 static const DWORD vs_code[] =
20523 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
20524 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20525 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
20526 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20527 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
20528 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
20529 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
20530 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
20531 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
20532 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
20533 0x0100003e,
20535 #if 0
20536 struct ps_data
20538 float4 pos : SV_POSITION;
20539 float4 color : COLOR;
20542 float4 main(struct ps_data ps_input) : SV_Target
20544 return ddy(ps_input.color) * 240.0 + 0.5;
20546 #endif
20547 static const DWORD ps_code_ddy[] =
20549 0x43425844, 0x423712f6, 0x786c59c2, 0xa6023c60, 0xb79faad2, 0x00000001, 0x00000138, 0x00000003,
20550 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20551 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20552 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20553 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20554 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000007c, 0x00000040,
20555 0x0000001f, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
20556 0x00000001, 0x0500000c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032, 0x001020f2,
20557 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000, 0x43700000,
20558 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20560 #if 0
20561 struct ps_data
20563 float4 pos : SV_POSITION;
20564 float4 color : COLOR;
20567 float4 main(struct ps_data ps_input) : SV_Target
20569 return ddy_coarse(ps_input.color) * 240.0 + 0.5;
20571 #endif
20572 static const DWORD ps_code_ddy_coarse[] =
20574 0x43425844, 0xbf9a31cb, 0xb42695b6, 0x629119b8, 0x6962d5dd, 0x00000001, 0x0000013c, 0x00000003,
20575 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20576 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20577 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20578 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20579 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
20580 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
20581 0x02000068, 0x00000001, 0x0500007c, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
20582 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
20583 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20585 #if 0
20586 struct ps_data
20588 float4 pos : SV_POSITION;
20589 float4 color : COLOR;
20592 float4 main(struct ps_data ps_input) : SV_Target
20594 return ddy_fine(ps_input.color) * 240.0 + 0.5;
20596 #endif
20597 static const DWORD ps_code_ddy_fine[] =
20599 0x43425844, 0xea6563ae, 0x3ee0da50, 0x4c2b3ef3, 0xa69a4077, 0x00000001, 0x0000013c, 0x00000003,
20600 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
20601 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
20602 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
20603 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
20604 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000080, 0x00000050,
20605 0x00000020, 0x0100086a, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
20606 0x02000068, 0x00000001, 0x0500007d, 0x001000f2, 0x00000000, 0x00101e46, 0x00000001, 0x0f000032,
20607 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x43700000, 0x43700000, 0x43700000,
20608 0x43700000, 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
20610 static const struct
20612 D3D_FEATURE_LEVEL min_feature_level;
20613 const DWORD *ps_code;
20614 unsigned int ps_code_size;
20616 tests[] =
20618 {D3D_FEATURE_LEVEL_10_0, ps_code_ddy, sizeof(ps_code_ddy)},
20619 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_coarse, sizeof(ps_code_ddy_coarse)},
20620 {D3D_FEATURE_LEVEL_11_0, ps_code_ddy_fine, sizeof(ps_code_ddy_fine)},
20622 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
20623 struct d3d11_test_context test_context;
20624 D3D11_TEXTURE2D_DESC texture_desc;
20625 D3D_FEATURE_LEVEL feature_level;
20626 ID3D11InputLayout *input_layout;
20627 ID3D11DeviceContext *context;
20628 unsigned int stride, offset;
20629 struct resource_readback rb;
20630 ID3D11RenderTargetView *rtv;
20631 ID3D11Texture2D *texture;
20632 ID3D11VertexShader *vs;
20633 ID3D11PixelShader *ps;
20634 ID3D11Device *device;
20635 ID3D11Buffer *vb;
20636 unsigned int i;
20637 DWORD color;
20638 HRESULT hr;
20640 if (!init_test_context(&test_context, NULL))
20641 return;
20643 device = test_context.device;
20644 context = test_context.immediate_context;
20645 feature_level = ID3D11Device_GetFeatureLevel(device);
20647 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
20648 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
20649 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20651 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
20652 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
20654 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
20655 vs_code, sizeof(vs_code), &input_layout);
20656 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
20658 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
20660 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
20661 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
20663 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
20664 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
20665 stride = sizeof(*quad);
20666 offset = 0;
20667 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
20668 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
20670 for (i = 0; i < ARRAY_SIZE(tests); ++i)
20672 if (feature_level < tests[i].min_feature_level)
20674 skip("Skipping test %u, feature_level %#x lower than minimum required %#x.\n", i,
20675 feature_level, tests[i].min_feature_level);
20676 continue;
20679 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps_code, tests[i].ps_code_size, NULL, &ps);
20680 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20682 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20684 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
20685 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
20686 ID3D11DeviceContext_Draw(context, 4, 0);
20688 get_texture_readback(texture, 0, &rb);
20689 color = get_readback_color(&rb, 320, 190, 0);
20690 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20691 color = get_readback_color(&rb, 255, 240, 0);
20692 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20693 color = get_readback_color(&rb, 320, 240, 0);
20694 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20695 color = get_readback_color(&rb, 385, 240, 0);
20696 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20697 color = get_readback_color(&rb, 320, 290, 0);
20698 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20699 release_resource_readback(&rb);
20701 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
20702 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
20703 ID3D11DeviceContext_Draw(context, 4, 0);
20705 get_texture_readback(test_context.backbuffer, 0, &rb);
20706 color = get_readback_color(&rb, 320, 190, 0);
20707 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20708 color = get_readback_color(&rb, 255, 240, 0);
20709 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20710 color = get_readback_color(&rb, 320, 240, 0);
20711 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20712 color = get_readback_color(&rb, 385, 240, 0);
20713 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20714 color = get_readback_color(&rb, 320, 290, 0);
20715 ok(compare_color(color, 0x7fff007f, 1), "Got unexpected color 0x%08x.\n", color);
20716 release_resource_readback(&rb);
20718 ID3D11PixelShader_Release(ps);
20721 ID3D11VertexShader_Release(vs);
20722 ID3D11Buffer_Release(vb);
20723 ID3D11InputLayout_Release(input_layout);
20724 ID3D11Texture2D_Release(texture);
20725 ID3D11RenderTargetView_Release(rtv);
20726 release_test_context(&test_context);
20729 static void test_shader_input_registers_limits(void)
20731 struct d3d11_test_context test_context;
20732 D3D11_SUBRESOURCE_DATA resource_data;
20733 D3D11_TEXTURE2D_DESC texture_desc;
20734 D3D11_SAMPLER_DESC sampler_desc;
20735 ID3D11ShaderResourceView *srv;
20736 ID3D11DeviceContext *context;
20737 ID3D11SamplerState *sampler;
20738 ID3D11Texture2D *texture;
20739 ID3D11PixelShader *ps;
20740 ID3D11Device *device;
20741 HRESULT hr;
20743 static const DWORD ps_last_register_code[] =
20745 #if 0
20746 Texture2D t : register(t127);
20747 SamplerState s : register(s15);
20749 void main(out float4 target : SV_Target)
20751 target = t.Sample(s, float2(0, 0));
20753 #endif
20754 0x43425844, 0xd81ff2f8, 0x8c704b9c, 0x8c6f4857, 0xd02949ac, 0x00000001, 0x000000dc, 0x00000003,
20755 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20756 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
20757 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019,
20758 0x0300005a, 0x00106000, 0x0000000f, 0x04001858, 0x00107000, 0x0000007f, 0x00005555, 0x03000065,
20759 0x001020f2, 0x00000000, 0x0c000045, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
20760 0x00000000, 0x00000000, 0x00107e46, 0x0000007f, 0x00106000, 0x0000000f, 0x0100003e,
20762 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
20763 static const DWORD texture_data[] = {0xff00ff00};
20765 if (!init_test_context(&test_context, NULL))
20766 return;
20768 device = test_context.device;
20769 context = test_context.immediate_context;
20771 texture_desc.Width = 1;
20772 texture_desc.Height = 1;
20773 texture_desc.MipLevels = 0;
20774 texture_desc.ArraySize = 1;
20775 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20776 texture_desc.SampleDesc.Count = 1;
20777 texture_desc.SampleDesc.Quality = 0;
20778 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20779 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20780 texture_desc.CPUAccessFlags = 0;
20781 texture_desc.MiscFlags = 0;
20783 resource_data.pSysMem = texture_data;
20784 resource_data.SysMemPitch = sizeof(texture_data);
20785 resource_data.SysMemSlicePitch = 0;
20787 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20788 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
20790 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
20791 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20793 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
20794 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
20795 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
20796 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
20797 sampler_desc.MipLODBias = 0.0f;
20798 sampler_desc.MaxAnisotropy = 0;
20799 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
20800 sampler_desc.BorderColor[0] = 0.0f;
20801 sampler_desc.BorderColor[1] = 0.0f;
20802 sampler_desc.BorderColor[2] = 0.0f;
20803 sampler_desc.BorderColor[3] = 0.0f;
20804 sampler_desc.MinLOD = 0.0f;
20805 sampler_desc.MaxLOD = 0.0f;
20807 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
20808 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
20810 hr = ID3D11Device_CreatePixelShader(device, ps_last_register_code, sizeof(ps_last_register_code), NULL, &ps);
20811 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20812 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20814 ID3D11DeviceContext_PSSetShaderResources(context,
20815 D3D11_COMMONSHADER_INPUT_RESOURCE_REGISTER_COUNT - 1, 1, &srv);
20816 ID3D11DeviceContext_PSSetSamplers(context, D3D11_COMMONSHADER_SAMPLER_REGISTER_COUNT - 1, 1, &sampler);
20817 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
20818 draw_quad(&test_context);
20819 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
20821 ID3D11PixelShader_Release(ps);
20822 ID3D11SamplerState_Release(sampler);
20823 ID3D11ShaderResourceView_Release(srv);
20824 ID3D11Texture2D_Release(texture);
20825 release_test_context(&test_context);
20828 static void test_unbind_shader_resource_view(void)
20830 struct d3d11_test_context test_context;
20831 D3D11_SUBRESOURCE_DATA resource_data;
20832 ID3D11ShaderResourceView *srv, *srv2;
20833 D3D11_TEXTURE2D_DESC texture_desc;
20834 ID3D11DeviceContext *context;
20835 ID3D11Texture2D *texture;
20836 ID3D11PixelShader *ps;
20837 ID3D11Device *device;
20838 HRESULT hr;
20840 static const DWORD ps_code[] =
20842 #if 0
20843 Texture2D t0;
20844 Texture2D t1;
20845 SamplerState s;
20847 float4 main() : SV_Target
20849 return min(t0.Sample(s, float2(0, 0)) + t1.Sample(s, float2(0, 0)), 1.0f);
20851 #endif
20852 0x43425844, 0x698dc0cb, 0x0bf322b8, 0xee127418, 0xfe9214ce, 0x00000001, 0x00000168, 0x00000003,
20853 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
20854 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
20855 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
20856 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04001858,
20857 0x00107000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000002,
20858 0x0c000045, 0x001000f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
20859 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0c000045, 0x001000f2, 0x00000001, 0x00004002,
20860 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00107e46, 0x00000001, 0x00106000, 0x00000000,
20861 0x07000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001, 0x0a000033,
20862 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000,
20863 0x3f800000, 0x0100003e,
20865 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
20866 static const DWORD texture_data[] = {0xff00ff00};
20868 if (!init_test_context(&test_context, NULL))
20869 return;
20871 device = test_context.device;
20872 context = test_context.immediate_context;
20874 texture_desc.Width = 1;
20875 texture_desc.Height = 1;
20876 texture_desc.MipLevels = 0;
20877 texture_desc.ArraySize = 1;
20878 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
20879 texture_desc.SampleDesc.Count = 1;
20880 texture_desc.SampleDesc.Quality = 0;
20881 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20882 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
20883 texture_desc.CPUAccessFlags = 0;
20884 texture_desc.MiscFlags = 0;
20886 resource_data.pSysMem = texture_data;
20887 resource_data.SysMemPitch = sizeof(texture_data);
20888 resource_data.SysMemSlicePitch = 0;
20890 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
20891 ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x.\n", hr);
20892 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
20893 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
20894 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
20895 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
20896 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
20898 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
20899 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv);
20900 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
20901 draw_quad(&test_context);
20902 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
20904 srv2 = NULL;
20905 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
20906 ID3D11DeviceContext_PSSetShaderResources(context, 1, 1, &srv2);
20907 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
20908 draw_quad(&test_context);
20909 todo_wine check_texture_color(test_context.backbuffer, 0x00000000, 1);
20911 ID3D11PixelShader_Release(ps);
20912 ID3D11ShaderResourceView_Release(srv);
20913 ID3D11Texture2D_Release(texture);
20914 release_test_context(&test_context);
20917 static void test_stencil_separate(void)
20919 struct d3d11_test_context test_context;
20920 D3D11_TEXTURE2D_DESC texture_desc;
20921 D3D11_DEPTH_STENCIL_DESC ds_desc;
20922 ID3D11DepthStencilState *ds_state;
20923 ID3D11DepthStencilView *ds_view;
20924 D3D11_RASTERIZER_DESC rs_desc;
20925 ID3D11DeviceContext *context;
20926 ID3D11RasterizerState *rs;
20927 ID3D11Texture2D *texture;
20928 ID3D11Device *device;
20929 HRESULT hr;
20931 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
20932 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
20933 static const struct vec3 ccw_quad[] =
20935 {-1.0f, -1.0f, 0.0f},
20936 { 1.0f, -1.0f, 0.0f},
20937 {-1.0f, 1.0f, 0.0f},
20938 { 1.0f, 1.0f, 0.0f},
20941 if (!init_test_context(&test_context, NULL))
20942 return;
20944 device = test_context.device;
20945 context = test_context.immediate_context;
20947 texture_desc.Width = 640;
20948 texture_desc.Height = 480;
20949 texture_desc.MipLevels = 1;
20950 texture_desc.ArraySize = 1;
20951 texture_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
20952 texture_desc.SampleDesc.Count = 1;
20953 texture_desc.SampleDesc.Quality = 0;
20954 texture_desc.Usage = D3D11_USAGE_DEFAULT;
20955 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
20956 texture_desc.CPUAccessFlags = 0;
20957 texture_desc.MiscFlags = 0;
20958 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
20959 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
20960 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &ds_view);
20961 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
20963 ds_desc.DepthEnable = TRUE;
20964 ds_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
20965 ds_desc.DepthFunc = D3D11_COMPARISON_LESS;
20966 ds_desc.StencilEnable = TRUE;
20967 ds_desc.StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK;
20968 ds_desc.StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK;
20969 ds_desc.FrontFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
20970 ds_desc.FrontFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
20971 ds_desc.FrontFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
20972 ds_desc.FrontFace.StencilFunc = D3D11_COMPARISON_NEVER;
20973 ds_desc.BackFace.StencilFailOp = D3D11_STENCIL_OP_ZERO;
20974 ds_desc.BackFace.StencilDepthFailOp = D3D11_STENCIL_OP_ZERO;
20975 ds_desc.BackFace.StencilPassOp = D3D11_STENCIL_OP_ZERO;
20976 ds_desc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
20977 hr = ID3D11Device_CreateDepthStencilState(device, &ds_desc, &ds_state);
20978 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
20980 rs_desc.FillMode = D3D11_FILL_SOLID;
20981 rs_desc.CullMode = D3D11_CULL_NONE;
20982 rs_desc.FrontCounterClockwise = FALSE;
20983 rs_desc.DepthBias = 0;
20984 rs_desc.DepthBiasClamp = 0.0f;
20985 rs_desc.SlopeScaledDepthBias = 0.0f;
20986 rs_desc.DepthClipEnable = TRUE;
20987 rs_desc.ScissorEnable = FALSE;
20988 rs_desc.MultisampleEnable = FALSE;
20989 rs_desc.AntialiasedLineEnable = FALSE;
20990 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
20991 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
20993 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
20994 ID3D11DeviceContext_ClearDepthStencilView(context, ds_view, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
20995 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, ds_view);
20996 ID3D11DeviceContext_OMSetDepthStencilState(context, ds_state, 0);
20997 ID3D11DeviceContext_RSSetState(context, rs);
20999 draw_color_quad(&test_context, &green);
21000 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
21002 ID3D11Buffer_Release(test_context.vb);
21003 test_context.vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(ccw_quad), ccw_quad);
21005 draw_color_quad(&test_context, &green);
21006 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
21008 ID3D11RasterizerState_Release(rs);
21009 rs_desc.FrontCounterClockwise = TRUE;
21010 ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
21011 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
21012 ID3D11DeviceContext_RSSetState(context, rs);
21014 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
21015 draw_color_quad(&test_context, &green);
21016 check_texture_color(test_context.backbuffer, 0xff0000ff, 1);
21018 ID3D11DepthStencilState_Release(ds_state);
21019 ID3D11DepthStencilView_Release(ds_view);
21020 ID3D11RasterizerState_Release(rs);
21021 ID3D11Texture2D_Release(texture);
21022 release_test_context(&test_context);
21025 static void test_uav_load(void)
21027 struct shader
21029 const DWORD *code;
21030 size_t size;
21032 struct texture
21034 UINT width;
21035 UINT height;
21036 UINT miplevel_count;
21037 UINT array_size;
21038 DXGI_FORMAT format;
21039 D3D11_SUBRESOURCE_DATA data[3];
21042 ID3D11RenderTargetView *rtv_float, *rtv_uint, *rtv_sint;
21043 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21044 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
21045 struct d3d11_test_context test_context;
21046 const struct texture *current_texture;
21047 ID3D11Texture2D *texture, *rt_texture;
21048 D3D11_TEXTURE2D_DESC texture_desc;
21049 const struct shader *current_ps;
21050 ID3D11UnorderedAccessView *uav;
21051 ID3D11DeviceContext *context;
21052 struct resource_readback rb;
21053 ID3D11PixelShader *ps;
21054 ID3D11Device *device;
21055 unsigned int i, x, y;
21056 ID3D11Buffer *cb;
21057 HRESULT hr;
21059 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
21060 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21061 static const DWORD ps_ld_2d_float_code[] =
21063 #if 0
21064 RWTexture2D<float> u;
21066 float main(float4 position : SV_Position) : SV_Target
21068 float2 s;
21069 u.GetDimensions(s.x, s.y);
21070 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21072 #endif
21073 0x43425844, 0xd5996e04, 0x6bede909, 0x0a7ad18e, 0x5eb277fb, 0x00000001, 0x00000194, 0x00000003,
21074 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21075 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21076 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
21077 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21078 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555, 0x04002064, 0x00101032,
21079 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21080 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21081 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21082 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21083 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21084 0x00155543, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21085 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21087 static const struct shader ps_ld_2d_float = {ps_ld_2d_float_code, sizeof(ps_ld_2d_float_code)};
21088 static const DWORD ps_ld_2d_uint_code[] =
21090 #if 0
21091 RWTexture2D<uint> u;
21093 uint main(float4 position : SV_Position) : SV_Target
21095 float2 s;
21096 u.GetDimensions(s.x, s.y);
21097 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21099 #endif
21100 0x43425844, 0x2cc0af18, 0xb28eca73, 0x9651215b, 0xebe3f361, 0x00000001, 0x00000194, 0x00000003,
21101 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21102 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21103 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
21104 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21105 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00004444, 0x04002064, 0x00101032,
21106 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21107 0x800000c2, 0x00111103, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21108 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21109 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21110 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21111 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21112 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21114 static const struct shader ps_ld_2d_uint = {ps_ld_2d_uint_code, sizeof(ps_ld_2d_uint_code)};
21115 static const DWORD ps_ld_2d_int_code[] =
21117 #if 0
21118 RWTexture2D<int> u;
21120 int main(float4 position : SV_Position) : SV_Target
21122 float2 s;
21123 u.GetDimensions(s.x, s.y);
21124 return u[s * float2(position.x / 640.0f, position.y / 480.0f)];
21126 #endif
21127 0x43425844, 0x7deee248, 0xe7c48698, 0x9454db00, 0x921810e7, 0x00000001, 0x00000194, 0x00000003,
21128 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21129 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21130 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000002,
21131 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f8, 0x00000050,
21132 0x0000003e, 0x0100086a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x04002064, 0x00101032,
21133 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000000, 0x02000068, 0x00000001, 0x8900003d,
21134 0x800000c2, 0x000cccc3, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000001,
21135 0x07000038, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00101546, 0x00000000, 0x0a000038,
21136 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x3b088889,
21137 0x3b088889, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x890000a3, 0x800000c2,
21138 0x000cccc3, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46, 0x00000001, 0x05000036,
21139 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21141 static const struct shader ps_ld_2d_int = {ps_ld_2d_int_code, sizeof(ps_ld_2d_int_code)};
21142 static const DWORD ps_ld_2d_uint_arr_code[] =
21144 #if 0
21145 RWTexture2DArray<uint> u;
21147 uint layer;
21149 uint main(float4 position : SV_Position) : SV_Target
21151 float3 s;
21152 u.GetDimensions(s.x, s.y, s.z);
21153 s.z = layer;
21154 return u[s * float3(position.x / 640.0f, position.y / 480.0f, 1.0f)];
21156 #endif
21157 0x43425844, 0xa7630358, 0xd7e7228f, 0xa9f1be03, 0x838554f1, 0x00000001, 0x000001bc, 0x00000003,
21158 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
21159 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
21160 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
21161 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000120, 0x00000050,
21162 0x00000048, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400409c, 0x0011e000,
21163 0x00000001, 0x00004444, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x00102012,
21164 0x00000000, 0x02000068, 0x00000001, 0x8900003d, 0x80000202, 0x00111103, 0x00100032, 0x00000000,
21165 0x00004001, 0x00000000, 0x0011ee46, 0x00000001, 0x07000038, 0x00100032, 0x00000000, 0x00100046,
21166 0x00000000, 0x00101046, 0x00000000, 0x06000056, 0x001000c2, 0x00000000, 0x00208006, 0x00000000,
21167 0x00000000, 0x0a000038, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x00004002, 0x3acccccd,
21168 0x3b088889, 0x3f800000, 0x3f800000, 0x0500001c, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
21169 0x890000a3, 0x80000202, 0x00111103, 0x00100012, 0x00000000, 0x00100e46, 0x00000000, 0x0011ee46,
21170 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x0100003e,
21172 static const struct shader ps_ld_2d_uint_arr = {ps_ld_2d_uint_arr_code, sizeof(ps_ld_2d_uint_arr_code)};
21173 static const float float_data[] =
21175 0.50f, 0.25f, 1.00f, 0.00f,
21176 -1.00f, -2.00f, -3.00f, -4.00f,
21177 -0.50f, -0.25f, -1.00f, -0.00f,
21178 1.00f, 2.00f, 3.00f, 4.00f,
21180 static const unsigned int uint_data[] =
21182 0x00, 0x10, 0x20, 0x30,
21183 0x40, 0x50, 0x60, 0x70,
21184 0x80, 0x90, 0xa0, 0xb0,
21185 0xc0, 0xd0, 0xe0, 0xf0,
21187 static const unsigned int uint_data2[] =
21189 0xffff, 0xffff, 0xffff, 0xffff,
21190 0xffff, 0xc000, 0xc000, 0xffff,
21191 0xffff, 0xc000, 0xc000, 0xffff,
21192 0xffff, 0xffff, 0xffff, 0xffff,
21194 static const unsigned int uint_data3[] =
21196 0xaa, 0xaa, 0xcc, 0xcc,
21197 0xaa, 0xaa, 0xdd, 0xdd,
21198 0xbb, 0xbb, 0xee, 0xee,
21199 0xbb, 0xbb, 0xff, 0xff,
21201 static const int int_data[] =
21203 -1, 0x10, 0x20, 0x30,
21204 0x40, 0x50, 0x60, -777,
21205 -666, 0x90, -555, 0xb0,
21206 0xc0, 0xd0, 0xe0, -101,
21208 static const struct texture float_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_FLOAT,
21209 {{float_data, 4 * sizeof(*float_data), 0}}};
21210 static const struct texture uint_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_UINT,
21211 {{uint_data, 4 * sizeof(*uint_data), 0}}};
21212 static const struct texture uint2d_arr = {4, 4, 1, 3, DXGI_FORMAT_R32_UINT,
21213 {{uint_data, 4 * sizeof(*uint_data), 0},
21214 {uint_data2, 4 * sizeof(*uint_data2), 0},
21215 {uint_data3, 4 * sizeof(*uint_data3), 0}}};
21216 static const struct texture int_2d = {4, 4, 1, 1, DXGI_FORMAT_R32_SINT,
21217 {{int_data, 4 * sizeof(*int_data), 0}}};
21219 static const struct test
21221 const struct shader *ps;
21222 const struct texture *texture;
21223 struct uav_desc uav_desc;
21224 struct uvec4 constant;
21225 const DWORD *expected_colors;
21227 tests[] =
21229 #define TEX_2D D3D11_UAV_DIMENSION_TEXTURE2D
21230 #define TEX_2D_ARRAY D3D11_UAV_DIMENSION_TEXTURE2DARRAY
21231 #define R32_FLOAT DXGI_FORMAT_R32_FLOAT
21232 #define R32_UINT DXGI_FORMAT_R32_UINT
21233 #define R32_SINT DXGI_FORMAT_R32_SINT
21234 {&ps_ld_2d_float, &float_2d, {R32_FLOAT, TEX_2D, 0}, {0}, (const DWORD *)float_data},
21235 {&ps_ld_2d_uint, &uint_2d, {R32_UINT, TEX_2D, 0}, {0}, (const DWORD *)uint_data},
21236 {&ps_ld_2d_int, &int_2d, {R32_SINT, TEX_2D, 0}, {0}, (const DWORD *)int_data},
21237 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {0}, (const DWORD *)uint_data},
21238 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {1}, (const DWORD *)uint_data2},
21239 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 0, ~0u}, {2}, (const DWORD *)uint_data3},
21240 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {0}, (const DWORD *)uint_data2},
21241 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 1, ~0u}, {1}, (const DWORD *)uint_data3},
21242 {&ps_ld_2d_uint_arr, &uint2d_arr, {R32_UINT, TEX_2D_ARRAY, 0, 2, ~0u}, {0}, (const DWORD *)uint_data3},
21243 #undef TEX_2D
21244 #undef TEX_2D_ARRAY
21245 #undef R32_FLOAT
21246 #undef R32_UINT
21247 #undef R32_SINT
21250 if (!init_test_context(&test_context, &feature_level))
21251 return;
21253 device = test_context.device;
21254 context = test_context.immediate_context;
21256 texture_desc.Width = 640;
21257 texture_desc.Height = 480;
21258 texture_desc.MipLevels = 1;
21259 texture_desc.ArraySize = 1;
21260 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
21261 texture_desc.SampleDesc.Count = 1;
21262 texture_desc.SampleDesc.Quality = 0;
21263 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21264 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
21265 texture_desc.CPUAccessFlags = 0;
21266 texture_desc.MiscFlags = 0;
21267 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt_texture);
21268 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21270 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
21271 U(rtv_desc).Texture2D.MipSlice = 0;
21273 rtv_desc.Format = DXGI_FORMAT_R32_FLOAT;
21274 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_float);
21275 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21277 rtv_desc.Format = DXGI_FORMAT_R32_UINT;
21278 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_uint);
21279 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21281 rtv_desc.Format = DXGI_FORMAT_R32_SINT;
21282 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt_texture, &rtv_desc, &rtv_sint);
21283 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
21285 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21287 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(struct uvec4), NULL);
21288 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
21290 ps = NULL;
21291 uav = NULL;
21292 texture = NULL;
21293 current_ps = NULL;
21294 current_texture = NULL;
21295 for (i = 0; i < ARRAY_SIZE(tests); ++i)
21297 const struct test *test = &tests[i];
21298 ID3D11RenderTargetView *current_rtv;
21300 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
21301 NULL, &test->constant, 0, 0);
21303 if (current_ps != test->ps)
21305 if (ps)
21306 ID3D11PixelShader_Release(ps);
21308 current_ps = test->ps;
21310 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
21311 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
21313 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
21316 if (current_texture != test->texture)
21318 if (texture)
21319 ID3D11Texture2D_Release(texture);
21321 current_texture = test->texture;
21323 texture_desc.Width = current_texture->width;
21324 texture_desc.Height = current_texture->height;
21325 texture_desc.MipLevels = current_texture->miplevel_count;
21326 texture_desc.ArraySize = current_texture->array_size;
21327 texture_desc.Format = current_texture->format;
21329 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, current_texture->data, &texture);
21330 ok(SUCCEEDED(hr), "Test %u: Failed to create texture, hr %#x.\n", i, hr);
21333 if (uav)
21334 ID3D11UnorderedAccessView_Release(uav);
21336 get_uav_desc(&uav_desc, &test->uav_desc);
21337 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
21338 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
21340 switch (uav_desc.Format)
21342 case DXGI_FORMAT_R32_FLOAT:
21343 current_rtv = rtv_float;
21344 break;
21345 case DXGI_FORMAT_R32_UINT:
21346 current_rtv = rtv_uint;
21347 break;
21348 case DXGI_FORMAT_R32_SINT:
21349 current_rtv = rtv_sint;
21350 break;
21351 default:
21352 trace("Unhandled format %#x.\n", uav_desc.Format);
21353 current_rtv = NULL;
21354 break;
21357 ID3D11DeviceContext_ClearRenderTargetView(context, current_rtv, white);
21359 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &current_rtv, NULL,
21360 1, 1, &uav, NULL);
21362 draw_quad(&test_context);
21364 get_texture_readback(rt_texture, 0, &rb);
21365 for (y = 0; y < 4; ++y)
21367 for (x = 0; x < 4; ++x)
21369 DWORD expected = test->expected_colors[y * 4 + x];
21370 DWORD color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
21371 ok(compare_color(color, expected, 0),
21372 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
21373 i, color, expected, x, y);
21376 release_resource_readback(&rb);
21378 ID3D11PixelShader_Release(ps);
21379 ID3D11Texture2D_Release(texture);
21380 ID3D11UnorderedAccessView_Release(uav);
21382 ID3D11Buffer_Release(cb);
21383 ID3D11RenderTargetView_Release(rtv_float);
21384 ID3D11RenderTargetView_Release(rtv_sint);
21385 ID3D11RenderTargetView_Release(rtv_uint);
21386 ID3D11Texture2D_Release(rt_texture);
21387 release_test_context(&test_context);
21390 static void test_cs_uav_store(void)
21392 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21393 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21394 static const float zero[4] = {0.0f};
21395 D3D11_TEXTURE2D_DESC texture_desc;
21396 ID3D11UnorderedAccessView *uav;
21397 struct device_desc device_desc;
21398 ID3D11DeviceContext *context;
21399 struct vec4 input = {1.0f};
21400 ID3D11Texture2D *texture;
21401 ID3D11ComputeShader *cs;
21402 ID3D11Device *device;
21403 ID3D11Buffer *cb;
21404 ULONG refcount;
21405 HRESULT hr;
21406 RECT rect;
21408 static const DWORD cs_1_thread_code[] =
21410 #if 0
21411 RWTexture2D<float> u;
21413 float value;
21415 [numthreads(1, 1, 1)]
21416 void main()
21418 uint x, y, width, height;
21419 u.GetDimensions(width, height);
21420 for (y = 0; y < height; ++y)
21422 for (x = 0; x < width; ++x)
21423 u[uint2(x, y)] = value;
21426 #endif
21427 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
21428 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21429 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
21430 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21431 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
21432 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
21433 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
21434 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
21435 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
21436 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
21437 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
21438 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
21439 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
21440 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
21441 0x01000016, 0x0100003e,
21443 static const DWORD cs_1_group_code[] =
21445 #if 0
21446 RWTexture2D<float> u;
21448 float value;
21450 [numthreads(16, 16, 1)]
21451 void main(uint3 threadID : SV_GroupThreadID)
21453 uint2 count, size ;
21454 u.GetDimensions(size.x, size.y);
21455 count = size / (uint2)16;
21456 for (uint y = 0; y < count.y; ++y)
21457 for (uint x = 0; x < count.x; ++x)
21458 u[count * threadID.xy + uint2(x, y)] = value;
21460 #endif
21461 0x43425844, 0x9fb86044, 0x352c196d, 0x92e14094, 0x46bb95a7, 0x00000001, 0x00000218, 0x00000003,
21462 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21463 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001c4, 0x00050050, 0x00000071, 0x0100086a,
21464 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21465 0x0200005f, 0x00022032, 0x02000068, 0x00000004, 0x0400009b, 0x00000010, 0x00000010, 0x00000001,
21466 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
21467 0x00000000, 0x0a000055, 0x001000f2, 0x00000000, 0x00100546, 0x00000000, 0x00004002, 0x00000004,
21468 0x00000004, 0x00000004, 0x00000004, 0x05000036, 0x00100012, 0x00000001, 0x00004001, 0x00000000,
21469 0x01000030, 0x07000050, 0x00100022, 0x00000001, 0x0010000a, 0x00000001, 0x0010003a, 0x00000000,
21470 0x03040003, 0x0010001a, 0x00000001, 0x05000036, 0x001000e2, 0x00000002, 0x00100006, 0x00000001,
21471 0x05000036, 0x00100022, 0x00000001, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
21472 0x00000001, 0x0010001a, 0x00000001, 0x0010000a, 0x00000000, 0x03040003, 0x0010002a, 0x00000001,
21473 0x05000036, 0x00100012, 0x00000002, 0x0010001a, 0x00000001, 0x08000023, 0x001000f2, 0x00000003,
21474 0x00100e46, 0x00000000, 0x00022546, 0x00100e46, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000,
21475 0x00100e46, 0x00000003, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100022, 0x00000001,
21476 0x0010001a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100012, 0x00000001,
21477 0x0010000a, 0x00000001, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
21479 static const DWORD cs_1_store_code[] =
21481 #if 0
21482 RWTexture2D<float> u;
21484 float value;
21486 [numthreads(1, 1, 1)]
21487 void main(uint3 groupID : SV_GroupID)
21489 u[groupID.xy] = value;
21491 #endif
21492 0x43425844, 0xc3add41b, 0x67df51b1, 0x2b887930, 0xcb1ee991, 0x00000001, 0x000000b8, 0x00000003,
21493 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21494 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21495 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21496 0x0200005f, 0x00021032, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x070000a4, 0x0011e0f2,
21497 0x00000000, 0x00021546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
21499 static const DWORD cs_dispatch_id_code[] =
21501 #if 0
21502 RWTexture2D<float> u;
21504 float value;
21506 [numthreads(4, 4, 1)]
21507 void main(uint3 id : SV_DispatchThreadID)
21509 u[id.xy] = value;
21511 #endif
21512 0x43425844, 0x60166991, 0x4b595266, 0x7fb67d79, 0x485c4f0d, 0x00000001, 0x000000b8, 0x00000003,
21513 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21514 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21515 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21516 0x0200005f, 0x00020032, 0x0400009b, 0x00000004, 0x00000004, 0x00000001, 0x070000a4, 0x0011e0f2,
21517 0x00000000, 0x00020546, 0x00208006, 0x00000000, 0x00000000, 0x0100003e,
21519 static const DWORD cs_group_index_code[] =
21521 #if 0
21522 RWTexture2D<float> u;
21524 float value;
21526 [numthreads(32, 1, 1)]
21527 void main(uint index : SV_GroupIndex)
21529 uint2 size;
21530 u.GetDimensions(size.x, size.y);
21531 uint count = size.x * size.y / 32;
21532 index *= count;
21533 for (uint i = 0; i < count; ++i, ++index)
21534 u[uint2(index % size.x, index / size.x)] = value;
21536 #endif
21537 0x43425844, 0xb685a70f, 0x94c2f263, 0x4f1d8eaa, 0xeab65731, 0x00000001, 0x000001f8, 0x00000003,
21538 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21539 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000001a4, 0x00050050, 0x00000069, 0x0100086a,
21540 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21541 0x0200005f, 0x00024000, 0x02000068, 0x00000004, 0x0400009b, 0x00000020, 0x00000001, 0x00000001,
21542 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46,
21543 0x00000000, 0x08000026, 0x0000d000, 0x00100022, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a,
21544 0x00000000, 0x07000055, 0x00100022, 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000005,
21545 0x07000026, 0x0000d000, 0x00100042, 0x00000000, 0x0002400a, 0x0010001a, 0x00000000, 0x05000036,
21546 0x00100012, 0x00000001, 0x0010002a, 0x00000000, 0x05000036, 0x00100022, 0x00000001, 0x00004001,
21547 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010001a, 0x00000001, 0x0010001a,
21548 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x0900004e, 0x00100012, 0x00000002, 0x00100012,
21549 0x00000003, 0x0010000a, 0x00000001, 0x0010000a, 0x00000000, 0x05000036, 0x001000e2, 0x00000003,
21550 0x00100006, 0x00000002, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000003, 0x00208006,
21551 0x00000000, 0x00000000, 0x0a00001e, 0x00100032, 0x00000001, 0x00100046, 0x00000001, 0x00004002,
21552 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x01000016, 0x0100003e,
21555 device_desc.feature_level = &feature_level;
21556 device_desc.flags = 0;
21557 if (!(device = create_device(&device_desc)))
21559 skip("Failed to create device for feature level %#x.\n", feature_level);
21560 return;
21563 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
21565 texture_desc.Width = 64;
21566 texture_desc.Height = 64;
21567 texture_desc.MipLevels = 1;
21568 texture_desc.ArraySize = 1;
21569 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
21570 texture_desc.SampleDesc.Count = 1;
21571 texture_desc.SampleDesc.Quality = 0;
21572 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21573 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21574 texture_desc.CPUAccessFlags = 0;
21575 texture_desc.MiscFlags = 0;
21577 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21578 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21580 uav_desc.Format = texture_desc.Format;
21581 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
21582 U(uav_desc).Texture2D.MipSlice = 0;
21584 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, &uav_desc, &uav);
21585 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21587 ID3D11Device_GetImmediateContext(device, &context);
21589 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
21590 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21592 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, zero);
21593 check_texture_float(texture, 0.0f, 2);
21595 hr = ID3D11Device_CreateComputeShader(device, cs_1_thread_code, sizeof(cs_1_thread_code), NULL, &cs);
21596 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21597 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21599 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21600 check_texture_float(texture, 1.0f, 2);
21602 input.x = 0.5f;
21603 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21604 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21605 check_texture_float(texture, 0.5f, 2);
21607 ID3D11ComputeShader_Release(cs);
21609 input.x = 2.0f;
21610 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21611 ID3D11DeviceContext_CSSetShader(context, NULL, NULL, 0);
21612 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21613 check_texture_float(texture, 0.5f, 2);
21615 hr = ID3D11Device_CreateComputeShader(device, cs_1_group_code, sizeof(cs_1_group_code), NULL, &cs);
21616 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21617 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21619 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21620 check_texture_float(texture, 2.0f, 2);
21622 input.x = 4.0f;
21623 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21624 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21625 check_texture_float(texture, 4.0f, 2);
21627 ID3D11ComputeShader_Release(cs);
21629 hr = ID3D11Device_CreateComputeShader(device, cs_1_store_code, sizeof(cs_1_store_code), NULL, &cs);
21630 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21631 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21633 input.x = 1.0f;
21634 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21635 ID3D11DeviceContext_Dispatch(context, texture_desc.Width, texture_desc.Height, 1);
21636 check_texture_float(texture, 1.0f, 2);
21638 input.x = 0.5f;
21639 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21640 ID3D11DeviceContext_Dispatch(context, 16, 32, 1);
21641 SetRect(&rect, 0, 0, 16, 32);
21642 check_texture_sub_resource_float(texture, 0, &rect, 0.5f, 2);
21643 SetRect(&rect, 0, 32, texture_desc.Width, texture_desc.Height);
21644 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21645 SetRect(&rect, 16, 0, texture_desc.Width, texture_desc.Height);
21646 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21648 ID3D11ComputeShader_Release(cs);
21650 hr = ID3D11Device_CreateComputeShader(device, cs_dispatch_id_code, sizeof(cs_dispatch_id_code), NULL, &cs);
21651 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21652 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21654 input.x = 0.6f;
21655 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21656 ID3D11DeviceContext_Dispatch(context, 15, 15, 1);
21657 SetRect(&rect, 0, 0, 60, 60);
21658 check_texture_sub_resource_float(texture, 0, &rect, 0.6f, 2);
21659 SetRect(&rect, 0, 60, texture_desc.Width, texture_desc.Height);
21660 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21661 SetRect(&rect, 60, 0, texture_desc.Width, texture_desc.Height);
21662 check_texture_sub_resource_float(texture, 0, &rect, 1.0f, 2);
21664 input.x = 0.7f;
21665 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21666 ID3D11DeviceContext_Dispatch(context, 16, 16, 1);
21667 check_texture_float(texture, 0.7f, 2);
21669 ID3D11ComputeShader_Release(cs);
21671 hr = ID3D11Device_CreateComputeShader(device, cs_group_index_code, sizeof(cs_group_index_code), NULL, &cs);
21672 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21673 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21675 input.x = 0.3f;
21676 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21677 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21678 check_texture_float(texture, 0.3f, 2);
21680 input.x = 0.1f;
21681 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &input, 0, 0);
21682 ID3D11DeviceContext_Dispatch(context, 2, 2, 2);
21683 check_texture_float(texture, 0.1f, 2);
21685 ID3D11ComputeShader_Release(cs);
21687 ID3D11Buffer_Release(cb);
21688 ID3D11Texture2D_Release(texture);
21689 ID3D11UnorderedAccessView_Release(uav);
21690 ID3D11DeviceContext_Release(context);
21691 refcount = ID3D11Device_Release(device);
21692 ok(!refcount, "Device has %u references left.\n", refcount);
21695 static void test_uav_store_immediate_constant(void)
21697 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21698 struct d3d11_test_context test_context;
21699 D3D11_TEXTURE2D_DESC texture_desc;
21700 ID3D11UnorderedAccessView *uav;
21701 ID3D11DeviceContext *context;
21702 struct resource_readback rb;
21703 ID3D11Texture2D *texture;
21704 ID3D11ComputeShader *cs;
21705 unsigned int uint_data;
21706 ID3D11Device *device;
21707 ID3D11Buffer *buffer;
21708 float float_data;
21709 int int_data;
21710 HRESULT hr;
21712 static const DWORD cs_store_int_code[] =
21714 #if 0
21715 RWBuffer<int> u;
21717 [numthreads(1, 1, 1)]
21718 void main()
21720 u[0] = 42;
21722 #endif
21723 0x43425844, 0x7246d785, 0x3f4ccbd6, 0x6a7cdbc0, 0xe2b58c72, 0x00000001, 0x000000b8, 0x00000003,
21724 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21725 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21726 0x0400089c, 0x0011e000, 0x00000000, 0x00003333, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
21727 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21728 0x00004002, 0x0000002a, 0x0000002a, 0x0000002a, 0x0000002a, 0x0100003e,
21730 static const DWORD cs_store_float_code[] =
21732 #if 0
21733 RWBuffer<float> u;
21735 [numthreads(1, 1, 1)]
21736 void main()
21738 u[0] = 1.0;
21740 #endif
21741 0x43425844, 0x525eea68, 0xc4cd5716, 0xc588f9c4, 0x0da27c5a, 0x00000001, 0x000000b8, 0x00000003,
21742 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21743 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21744 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
21745 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21746 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000, 0x0100003e,
21748 static const DWORD cs_store_unorm_code[] =
21750 #if 0
21751 RWTexture2D<unorm float> u;
21753 [numthreads(1, 1, 1)]
21754 void main()
21756 u[uint2(0, 0)] = 0.5f;
21758 #endif
21759 0x43425844, 0x3623f1de, 0xe847109e, 0x8e3da13f, 0xb6787b06, 0x00000001, 0x000000b8, 0x00000003,
21760 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21761 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21762 0x0400189c, 0x0011e000, 0x00000000, 0x00001111, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
21763 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21764 0x00004002, 0x3f000000, 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
21766 static const DWORD cs_store_snorm_code[] =
21768 #if 0
21769 RWTexture2D<snorm float> u;
21771 [numthreads(1, 1, 1)]
21772 void main()
21774 u[uint2(0, 0)] = -0.5f;
21776 #endif
21777 0x43425844, 0xce5397fc, 0x7464bc06, 0xc79aa56c, 0x881bd7ef, 0x00000001, 0x000000b8, 0x00000003,
21778 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21779 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000064, 0x00050050, 0x00000019, 0x0100086a,
21780 0x0400189c, 0x0011e000, 0x00000000, 0x00002222, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
21781 0x0d0000a4, 0x0011e0f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
21782 0x00004002, 0xbf000000, 0xbf000000, 0xbf000000, 0xbf000000, 0x0100003e,
21784 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21785 static const unsigned int zero[4] = {0};
21787 if (!init_test_context(&test_context, &feature_level))
21788 return;
21790 device = test_context.device;
21791 context = test_context.immediate_context;
21793 buffer = create_buffer(device, D3D11_BIND_UNORDERED_ACCESS, 1024, NULL);
21795 uav_desc.Format = DXGI_FORMAT_R32_SINT;
21796 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
21797 U(uav_desc).Buffer.FirstElement = 0;
21798 U(uav_desc).Buffer.NumElements = 1;
21799 U(uav_desc).Buffer.Flags = 0;
21800 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
21801 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21802 hr = ID3D11Device_CreateComputeShader(device, cs_store_int_code, sizeof(cs_store_int_code), NULL, &cs);
21803 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21805 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
21806 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21807 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21808 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21809 get_buffer_readback(buffer, &rb);
21810 int_data = get_readback_color(&rb, 0, 0, 0);
21811 ok(int_data == 42, "Got unexpected value %u.\n", int_data);
21812 release_resource_readback(&rb);
21814 ID3D11ComputeShader_Release(cs);
21815 ID3D11UnorderedAccessView_Release(uav);
21816 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
21817 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
21818 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
21819 hr = ID3D11Device_CreateComputeShader(device, cs_store_float_code, sizeof(cs_store_float_code), NULL, &cs);
21820 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
21822 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
21823 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21824 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21825 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21826 get_buffer_readback(buffer, &rb);
21827 float_data = get_readback_float(&rb, 0, 0);
21828 ok(float_data == 1.0f, "Got unexpected value %.8e.\n", float_data);
21829 release_resource_readback(&rb);
21831 texture_desc.Width = 64;
21832 texture_desc.Height = 64;
21833 texture_desc.MipLevels = 1;
21834 texture_desc.ArraySize = 1;
21835 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
21836 texture_desc.SampleDesc.Count = 1;
21837 texture_desc.SampleDesc.Quality = 0;
21838 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21839 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21840 texture_desc.CPUAccessFlags = 0;
21841 texture_desc.MiscFlags = 0;
21842 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21843 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
21844 ID3D11UnorderedAccessView_Release(uav);
21845 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
21846 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
21848 ID3D11ComputeShader_Release(cs);
21849 hr = ID3D11Device_CreateComputeShader(device, cs_store_unorm_code, sizeof(cs_store_unorm_code), NULL, &cs);
21850 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
21851 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
21852 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21853 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21854 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21855 get_texture_readback(texture, 0, &rb);
21856 uint_data = get_readback_color(&rb, 0, 0, 0);
21857 ok(compare_color(uint_data, 0x80808080, 1), "Got unexpected color 0x%08x.\n", uint_data);
21858 release_resource_readback(&rb);
21860 ID3D11Texture2D_Release(texture);
21861 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_SNORM;
21862 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
21863 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
21864 ID3D11UnorderedAccessView_Release(uav);
21865 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
21866 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
21868 ID3D11ComputeShader_Release(cs);
21869 hr = ID3D11Device_CreateComputeShader(device, cs_store_snorm_code, sizeof(cs_store_snorm_code), NULL, &cs);
21870 ok(hr == S_OK, "Failed to create compute shader, hr %#x.\n", hr);
21871 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
21872 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
21873 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
21874 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
21875 get_texture_readback(texture, 0, &rb);
21876 uint_data = get_readback_color(&rb, 0, 0, 0);
21877 ok(compare_color(uint_data, 0xc0c0c0c0, 1), "Got unexpected color 0x%08x.\n", uint_data);
21878 release_resource_readback(&rb);
21880 ID3D11Buffer_Release(buffer);
21881 ID3D11Texture2D_Release(texture);
21882 ID3D11ComputeShader_Release(cs);
21883 ID3D11UnorderedAccessView_Release(uav);
21884 release_test_context(&test_context);
21887 static void test_ps_cs_uav_binding(void)
21889 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
21890 ID3D11UnorderedAccessView *cs_uav, *ps_uav;
21891 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
21892 ID3D11Texture2D *cs_texture, *ps_texture;
21893 struct d3d11_test_context test_context;
21894 static const float zero[4] = {0.0f};
21895 D3D11_TEXTURE2D_DESC texture_desc;
21896 ID3D11DeviceContext *context;
21897 ID3D11Buffer *cs_cb, *ps_cb;
21898 struct vec4 input = {1.0f};
21899 ID3D11ComputeShader *cs;
21900 ID3D11PixelShader *ps;
21901 ID3D11Device *device;
21902 HRESULT hr;
21904 static const DWORD cs_code[] =
21906 #if 0
21907 RWTexture2D<float> u;
21909 float value;
21911 [numthreads(1, 1, 1)]
21912 void main()
21914 uint x, y, width, height;
21915 u.GetDimensions(width, height);
21916 for (y = 0; y < height; ++y)
21918 for (x = 0; x < width; ++x)
21919 u[uint2(x, y)] = value;
21922 #endif
21923 0x43425844, 0x6503503a, 0x4cd524e6, 0x2473915d, 0x93cf1201, 0x00000001, 0x000001c8, 0x00000003,
21924 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21925 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000174, 0x00050050, 0x0000005d, 0x0100086a,
21926 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000000, 0x00005555,
21927 0x02000068, 0x00000003, 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x8900103d, 0x800000c2,
21928 0x00155543, 0x00100032, 0x00000000, 0x00004001, 0x00000000, 0x0011ee46, 0x00000000, 0x05000036,
21929 0x00100042, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100082, 0x00000000,
21930 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x03040003, 0x0010003a, 0x00000000, 0x05000036,
21931 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000, 0x05000036, 0x00100082, 0x00000000, 0x00004001,
21932 0x00000000, 0x01000030, 0x07000050, 0x00100012, 0x00000002, 0x0010003a, 0x00000000, 0x0010000a,
21933 0x00000000, 0x03040003, 0x0010000a, 0x00000002, 0x05000036, 0x00100012, 0x00000001, 0x0010003a,
21934 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000000, 0x00100e46, 0x00000001, 0x00208006, 0x00000000,
21935 0x00000000, 0x0700001e, 0x00100082, 0x00000000, 0x0010003a, 0x00000000, 0x00004001, 0x00000001,
21936 0x01000016, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000001,
21937 0x01000016, 0x0100003e,
21939 static const DWORD ps_code[] =
21941 #if 0
21942 RWTexture2D<float> u : register(u1);
21944 float value;
21946 void main()
21948 uint x, y, width, height;
21949 u.GetDimensions(width, height);
21950 for (y = 0; y < height; ++y)
21952 for (x = 0; x < width; ++x)
21953 u[uint2(x, y)] = value;
21956 #endif
21957 0x43425844, 0x2e14423b, 0x62c015c8, 0x5ea5ab9f, 0x514f1e22, 0x00000001, 0x000001b8, 0x00000003,
21958 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
21959 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000164, 0x00000050, 0x00000059, 0x0100086a,
21960 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400189c, 0x0011e000, 0x00000001, 0x00005555,
21961 0x02000068, 0x00000003, 0x8900103d, 0x800000c2, 0x00155543, 0x00100032, 0x00000000, 0x00004001,
21962 0x00000000, 0x0011ee46, 0x00000001, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
21963 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000,
21964 0x03040003, 0x0010003a, 0x00000000, 0x05000036, 0x001000e2, 0x00000001, 0x00100aa6, 0x00000000,
21965 0x05000036, 0x00100082, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100012,
21966 0x00000002, 0x0010003a, 0x00000000, 0x0010000a, 0x00000000, 0x03040003, 0x0010000a, 0x00000002,
21967 0x05000036, 0x00100012, 0x00000001, 0x0010003a, 0x00000000, 0x080000a4, 0x0011e0f2, 0x00000001,
21968 0x00100e46, 0x00000001, 0x00208006, 0x00000000, 0x00000000, 0x0700001e, 0x00100082, 0x00000000,
21969 0x0010003a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0700001e, 0x00100042, 0x00000000,
21970 0x0010002a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
21973 if (!init_test_context(&test_context, &feature_level))
21974 return;
21976 device = test_context.device;
21977 context = test_context.immediate_context;
21979 ps_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
21980 cs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(input), &input.x);
21982 texture_desc.Width = 64;
21983 texture_desc.Height = 64;
21984 texture_desc.MipLevels = 1;
21985 texture_desc.ArraySize = 1;
21986 texture_desc.Format = DXGI_FORMAT_R32_FLOAT;
21987 texture_desc.SampleDesc.Count = 1;
21988 texture_desc.SampleDesc.Quality = 0;
21989 texture_desc.Usage = D3D11_USAGE_DEFAULT;
21990 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
21991 texture_desc.CPUAccessFlags = 0;
21992 texture_desc.MiscFlags = 0;
21993 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &cs_texture);
21994 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21995 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ps_texture);
21996 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
21998 uav_desc.Format = texture_desc.Format;
21999 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_TEXTURE2D;
22000 U(uav_desc).Texture2D.MipSlice = 0;
22001 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)cs_texture, &uav_desc, &cs_uav);
22002 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22003 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)ps_texture, &uav_desc, &ps_uav);
22004 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22006 ID3D11Device_GetImmediateContext(device, &context);
22008 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cs_cb);
22009 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &cs_uav, NULL);
22010 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &ps_cb);
22011 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
22012 0, NULL, NULL, 1, 1, &ps_uav, NULL);
22014 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, cs_uav, zero);
22015 check_texture_float(cs_texture, 0.0f, 2);
22016 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, ps_uav, zero);
22017 check_texture_float(ps_texture, 0.0f, 2);
22019 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
22020 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22021 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22022 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22023 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22024 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22026 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22027 check_texture_float(cs_texture, 1.0f, 2);
22028 check_texture_float(ps_texture, 0.0f, 2);
22029 draw_quad(&test_context);
22030 check_texture_float(cs_texture, 1.0f, 2);
22031 check_texture_float(ps_texture, 1.0f, 2);
22033 input.x = 0.5f;
22034 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
22035 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22036 check_texture_float(cs_texture, 0.5f, 2);
22037 check_texture_float(ps_texture, 1.0f, 2);
22038 input.x = 2.0f;
22039 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
22040 draw_quad(&test_context);
22041 check_texture_float(cs_texture, 0.5f, 2);
22042 check_texture_float(ps_texture, 2.0f, 2);
22044 input.x = 8.0f;
22045 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cs_cb, 0, NULL, &input, 0, 0);
22046 input.x = 4.0f;
22047 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)ps_cb, 0, NULL, &input, 0, 0);
22048 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22049 check_texture_float(cs_texture, 8.0f, 2);
22050 check_texture_float(ps_texture, 2.0f, 2);
22051 draw_quad(&test_context);
22052 check_texture_float(cs_texture, 8.0f, 2);
22053 check_texture_float(ps_texture, 4.0f, 2);
22055 ID3D11ComputeShader_Release(cs);
22056 ID3D11PixelShader_Release(ps);
22057 ID3D11Buffer_Release(cs_cb);
22058 ID3D11Buffer_Release(ps_cb);
22059 ID3D11Texture2D_Release(cs_texture);
22060 ID3D11Texture2D_Release(ps_texture);
22061 ID3D11UnorderedAccessView_Release(cs_uav);
22062 ID3D11UnorderedAccessView_Release(ps_uav);
22063 ID3D11DeviceContext_Release(context);
22064 release_test_context(&test_context);
22067 static void test_atomic_instructions(void)
22069 ID3D11UnorderedAccessView *in_uav, *out_uav;
22070 ID3D11Buffer *cb, *in_buffer, *out_buffer;
22071 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22072 struct d3d11_test_context test_context;
22073 struct resource_readback rb, out_rb;
22074 D3D11_BUFFER_DESC buffer_desc;
22075 ID3D11DeviceContext *context;
22076 ID3D11ComputeShader *cs;
22077 ID3D11PixelShader *ps;
22078 ID3D11Device *device;
22079 unsigned int i, j;
22080 HRESULT hr;
22082 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22083 static const unsigned int zero[4] = {0, 0, 0, 0};
22084 static const DWORD ps_atomics_code[] =
22086 #if 0
22087 RWByteAddressBuffer u;
22089 uint4 v;
22090 int4 i;
22092 void main()
22094 u.InterlockedAnd(0 * 4, v.x);
22095 u.InterlockedCompareStore(1 * 4, v.y, v.x);
22096 u.InterlockedAdd(2 * 4, v.x);
22097 u.InterlockedOr(3 * 4, v.x);
22098 u.InterlockedMax(4 * 4, i.x);
22099 u.InterlockedMin(5 * 4, i.x);
22100 u.InterlockedMax(6 * 4, v.x);
22101 u.InterlockedMin(7 * 4, v.x);
22102 u.InterlockedXor(8 * 4, v.x);
22104 #endif
22105 0x43425844, 0x24c6a30c, 0x2ce4437d, 0xdee8a0df, 0xd18cb4bc, 0x00000001, 0x000001ac, 0x00000003,
22106 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22107 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000158, 0x00000050, 0x00000056, 0x0100086a,
22108 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x080000a9,
22109 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0b0000ac,
22110 0x0011e000, 0x00000000, 0x00004001, 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a,
22111 0x00000000, 0x00000000, 0x080000ad, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a,
22112 0x00000000, 0x00000000, 0x080000aa, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c, 0x0020800a,
22113 0x00000000, 0x00000000, 0x080000ae, 0x0011e000, 0x00000000, 0x00004001, 0x00000010, 0x0020800a,
22114 0x00000000, 0x00000001, 0x080000af, 0x0011e000, 0x00000000, 0x00004001, 0x00000014, 0x0020800a,
22115 0x00000000, 0x00000001, 0x080000b0, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a,
22116 0x00000000, 0x00000000, 0x080000b1, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
22117 0x00000000, 0x00000000, 0x080000ab, 0x0011e000, 0x00000000, 0x00004001, 0x00000020, 0x0020800a,
22118 0x00000000, 0x00000000, 0x0100003e,
22120 static const DWORD cs_atomics_code[] =
22122 #if 0
22123 RWByteAddressBuffer u;
22124 RWByteAddressBuffer u2;
22126 uint4 v;
22127 int4 i;
22129 [numthreads(1, 1, 1)]
22130 void main()
22132 uint r;
22133 u.InterlockedAnd(0 * 4, v.x, r);
22134 u2.Store(0 * 4, r);
22135 u.InterlockedCompareExchange(1 * 4, v.y, v.x, r);
22136 u2.Store(1 * 4, r);
22137 u.InterlockedAdd(2 * 4, v.x, r);
22138 u2.Store(2 * 4, r);
22139 u.InterlockedOr(3 * 4, v.x, r);
22140 u2.Store(3 * 4, r);
22141 u.InterlockedMax(4 * 4, i.x, r);
22142 u2.Store(4 * 4, r);
22143 u.InterlockedMin(5 * 4, i.x, r);
22144 u2.Store(5 * 4, r);
22145 u.InterlockedMax(6 * 4, v.x, r);
22146 u2.Store(6 * 4, r);
22147 u.InterlockedMin(7 * 4, v.x, r);
22148 u2.Store(7 * 4, r);
22149 u.InterlockedXor(8 * 4, v.x, r);
22150 u2.Store(8 * 4, r);
22152 #endif
22153 0x43425844, 0x859a96e3, 0x1a35e463, 0x1e89ce58, 0x5cfe430a, 0x00000001, 0x0000026c, 0x00000003,
22154 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22155 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000218, 0x00050050, 0x00000086, 0x0100086a,
22156 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d,
22157 0x0011e000, 0x00000001, 0x02000068, 0x00000001, 0x0400009b, 0x00000001, 0x00000001, 0x00000001,
22158 0x0a0000b5, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000000, 0x0020800a,
22159 0x00000000, 0x00000000, 0x0d0000b9, 0x00100022, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
22160 0x00000004, 0x0020801a, 0x00000000, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0a0000b4,
22161 0x00100042, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000008, 0x0020800a, 0x00000000,
22162 0x00000000, 0x0a0000b6, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000000c,
22163 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000000,
22164 0x00100e46, 0x00000000, 0x0a0000ba, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001,
22165 0x00000010, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bb, 0x00100022, 0x00000000, 0x0011e000,
22166 0x00000000, 0x00004001, 0x00000014, 0x0020800a, 0x00000000, 0x00000001, 0x0a0000bc, 0x00100042,
22167 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000018, 0x0020800a, 0x00000000, 0x00000000,
22168 0x0a0000bd, 0x00100082, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x0000001c, 0x0020800a,
22169 0x00000000, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001, 0x00000010, 0x00100e46,
22170 0x00000000, 0x0a0000b7, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x00004001, 0x00000020,
22171 0x0020800a, 0x00000000, 0x00000000, 0x070000a6, 0x0011e012, 0x00000001, 0x00004001, 0x00000020,
22172 0x0010000a, 0x00000000, 0x0100003e,
22175 static const char * const instructions[] =
22177 "atomic_and", "atomic_cmp_store", "atomic_iadd", "atomic_or",
22178 "atomic_imax", "atomic_imin", "atomic_umax", "atomic_umin", "atomic_xor",
22180 static const char * const imm_instructions[] =
22182 "imm_atomic_and", "imm_atomic_cmp_exch", "imm_atomic_iadd", "imm_atomic_or",
22183 "imm_atomic_imax", "imm_atomic_imin", "imm_atomic_umax", "imm_atomic_umin", "imm_atomic_xor",
22185 static const struct test
22187 struct uvec4 v;
22188 struct ivec4 i;
22189 unsigned int input[ARRAY_SIZE(instructions)];
22190 unsigned int expected_result[ARRAY_SIZE(instructions)];
22192 tests[] =
22194 {{1, 0}, {-1}, {0xffff, 0, 1, 0, 0, 0, 0, 0, 0xff}, { 1, 1, 2, 1, 0, ~0u, 1, 0, 0xfe}},
22195 {{~0u, ~0u}, { 0}, {0xffff, 0xf, 1, 0, 0, 0, 0, 9, ~0u}, {0xffff, 0xf, 0, ~0u, 0, 0, ~0u, 9, 0}},
22198 if (!init_test_context(&test_context, &feature_level))
22199 return;
22201 device = test_context.device;
22202 context = test_context.immediate_context;
22204 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, 2 * sizeof(struct uvec4), NULL);
22205 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22206 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
22208 buffer_desc.ByteWidth = sizeof(tests->input);
22209 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
22210 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
22211 buffer_desc.CPUAccessFlags = 0;
22212 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
22213 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &in_buffer);
22214 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22215 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &out_buffer);
22216 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
22218 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
22219 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
22220 U(uav_desc).Buffer.FirstElement = 0;
22221 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(*tests->input);
22222 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
22223 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)in_buffer, &uav_desc, &in_uav);
22224 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22225 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)out_buffer, &uav_desc, &out_uav);
22226 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
22228 set_viewport(context, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f);
22230 hr = ID3D11Device_CreatePixelShader(device, ps_atomics_code, sizeof(ps_atomics_code), NULL, &ps);
22231 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
22232 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22234 hr = ID3D11Device_CreateComputeShader(device, cs_atomics_code, sizeof(cs_atomics_code), NULL, &cs);
22235 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
22236 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
22238 for (i = 0; i < ARRAY_SIZE(tests); ++i)
22240 const struct test *test = &tests[i];
22242 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
22243 NULL, &test->v, 0, 0);
22245 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
22246 NULL, test->input, 0, 0);
22248 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 0, NULL, NULL,
22249 0, 1, &in_uav, NULL);
22251 draw_quad(&test_context);
22252 get_buffer_readback(in_buffer, &rb);
22253 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
22255 unsigned int value = get_readback_color(&rb, j, 0, 0);
22256 unsigned int expected = test->expected_result[j];
22258 todo_wine_if(expected != test->input[j]
22259 && (!strcmp(instructions[j], "atomic_imax")
22260 || !strcmp(instructions[j], "atomic_imin")))
22261 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
22262 "with inputs (%u, %u), (%d), %#x (%d).\n",
22263 i, value, value, expected, expected, instructions[j],
22264 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
22266 release_resource_readback(&rb);
22268 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)in_buffer, 0,
22269 NULL, test->input, 0, 0);
22270 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, out_uav, zero);
22272 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &in_uav, NULL);
22273 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &out_uav, NULL);
22275 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
22276 get_buffer_readback(in_buffer, &rb);
22277 get_buffer_readback(out_buffer, &out_rb);
22278 for (j = 0; j < ARRAY_SIZE(instructions); ++j)
22280 BOOL todo_instruction = !strcmp(imm_instructions[j], "imm_atomic_imax")
22281 || !strcmp(imm_instructions[j], "imm_atomic_imin");
22282 unsigned int out_value = get_readback_color(&out_rb, j, 0, 0);
22283 unsigned int value = get_readback_color(&rb, j, 0, 0);
22284 unsigned int expected = test->expected_result[j];
22286 todo_wine_if(expected != test->input[j] && todo_instruction)
22287 ok(value == expected, "Test %u: Got %#x (%d), expected %#x (%d) for '%s' "
22288 "with inputs (%u, %u), (%d), %#x (%d).\n",
22289 i, value, value, expected, expected, imm_instructions[j],
22290 test->v.x, test->v.y, test->i.x, test->input[j], test->input[j]);
22292 todo_wine_if(todo_instruction && out_value != test->input[j])
22293 ok(out_value == test->input[j], "Got original value %u, expected %u for '%s'.\n",
22294 out_value, test->input[j], imm_instructions[j]);
22296 release_resource_readback(&out_rb);
22297 release_resource_readback(&rb);
22300 ID3D11Buffer_Release(cb);
22301 ID3D11Buffer_Release(in_buffer);
22302 ID3D11Buffer_Release(out_buffer);
22303 ID3D11ComputeShader_Release(cs);
22304 ID3D11PixelShader_Release(ps);
22305 ID3D11UnorderedAccessView_Release(in_uav);
22306 ID3D11UnorderedAccessView_Release(out_uav);
22307 release_test_context(&test_context);
22310 static void test_sm4_ret_instruction(void)
22312 struct d3d11_test_context test_context;
22313 ID3D11DeviceContext *context;
22314 ID3D11PixelShader *ps;
22315 struct uvec4 constant;
22316 ID3D11Device *device;
22317 ID3D11Buffer *cb;
22318 HRESULT hr;
22320 static const DWORD ps_code[] =
22322 #if 0
22323 uint c;
22325 float4 main() : SV_TARGET
22327 if (c == 1)
22328 return float4(1, 0, 0, 1);
22329 if (c == 2)
22330 return float4(0, 1, 0, 1);
22331 if (c == 3)
22332 return float4(0, 0, 1, 1);
22333 return float4(1, 1, 1, 1);
22335 #endif
22336 0x43425844, 0x9ee6f808, 0xe74009f3, 0xbb1adaf2, 0x432e97b5, 0x00000001, 0x000001c4, 0x00000003,
22337 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22338 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22339 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x0000014c, 0x00000040, 0x00000053,
22340 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
22341 0x00000001, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001,
22342 0x00000001, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
22343 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012,
22344 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x00004001, 0x00000002, 0x0304001f, 0x0010000a,
22345 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
22346 0x3f800000, 0x0100003e, 0x01000015, 0x08000020, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
22347 0x00000000, 0x00004001, 0x00000003, 0x0304001f, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2,
22348 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000, 0x0100003e, 0x01000015,
22349 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
22350 0x0100003e,
22353 if (!init_test_context(&test_context, NULL))
22354 return;
22356 device = test_context.device;
22357 context = test_context.immediate_context;
22359 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22360 ok(SUCCEEDED(hr), "Failed to create shader, hr %#x.\n", hr);
22361 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22362 memset(&constant, 0, sizeof(constant));
22363 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
22364 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22366 draw_quad(&test_context);
22367 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22369 constant.x = 1;
22370 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22371 draw_quad(&test_context);
22372 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
22374 constant.x = 2;
22375 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22376 draw_quad(&test_context);
22377 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
22379 constant.x = 3;
22380 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22381 draw_quad(&test_context);
22382 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
22384 constant.x = 4;
22385 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22386 draw_quad(&test_context);
22387 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
22389 ID3D11Buffer_Release(cb);
22390 ID3D11PixelShader_Release(ps);
22391 release_test_context(&test_context);
22394 static void test_primitive_restart(void)
22396 struct d3d11_test_context test_context;
22397 ID3D11Buffer *ib32, *ib16, *vb;
22398 ID3D11DeviceContext *context;
22399 unsigned int stride, offset;
22400 ID3D11InputLayout *layout;
22401 ID3D11VertexShader *vs;
22402 ID3D11PixelShader *ps;
22403 ID3D11Device *device;
22404 unsigned int i;
22405 HRESULT hr;
22406 RECT rect;
22408 static const DWORD ps_code[] =
22410 #if 0
22411 struct vs_out
22413 float4 position : SV_Position;
22414 float4 color : color;
22417 float4 main(vs_out input) : SV_TARGET
22419 return input.color;
22421 #endif
22422 0x43425844, 0x119e48d1, 0x468aecb3, 0x0a405be5, 0x4e203b82, 0x00000001, 0x000000f4, 0x00000003,
22423 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
22424 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
22425 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072,
22426 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
22427 0x00000000, 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x00000038, 0x00000040,
22428 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
22429 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
22431 static const DWORD vs_code[] =
22433 #if 0
22434 struct vs_out
22436 float4 position : SV_Position;
22437 float4 color : color;
22440 void main(float4 position : POSITION, uint vertex_id : SV_VertexID, out vs_out output)
22442 output.position = position;
22443 output.color = vertex_id < 4 ? float4(0.0, 1.0, 1.0, 1.0) : float4(1.0, 0.0, 0.0, 1.0);
22445 #endif
22446 0x43425844, 0x2fa57573, 0xdb71c15f, 0x2641b028, 0xa8f87ccc, 0x00000001, 0x00000198, 0x00000003,
22447 0x0000002c, 0x00000084, 0x000000d8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
22448 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000006,
22449 0x00000001, 0x00000001, 0x00000101, 0x49534f50, 0x4e4f4954, 0x5f565300, 0x74726556, 0x44497865,
22450 0xababab00, 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001,
22451 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001,
22452 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69, 0x6f6c6f63, 0xabab0072, 0x52444853, 0x000000b8,
22453 0x00010040, 0x0000002e, 0x0300005f, 0x001010f2, 0x00000000, 0x04000060, 0x00101012, 0x00000001,
22454 0x00000006, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001,
22455 0x02000068, 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x0700004f,
22456 0x00100012, 0x00000000, 0x0010100a, 0x00000001, 0x00004001, 0x00000004, 0x0f000037, 0x001020f2,
22457 0x00000001, 0x00100006, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x3f800000, 0x3f800000,
22458 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000, 0x0100003e,
22460 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
22462 {"position", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
22464 static const struct vec2 vertices[] =
22466 {-1.00f, -1.0f},
22467 {-1.00f, 1.0f},
22468 {-0.25f, -1.0f},
22469 {-0.25f, 1.0f},
22470 { 0.25f, -1.0f},
22471 { 0.25f, 1.0f},
22472 { 1.00f, -1.0f},
22473 { 1.00f, 1.0f},
22475 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
22476 static const unsigned short indices16[] =
22478 0, 1, 2, 3, 0xffff, 4, 5, 6, 7
22480 static const unsigned int indices32[] =
22482 0, 1, 2, 3, 0xffffffff, 4, 5, 6, 7
22485 if (!init_test_context(&test_context, NULL))
22486 return;
22488 device = test_context.device;
22489 context = test_context.immediate_context;
22491 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
22492 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
22493 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
22494 ok(SUCCEEDED(hr), "Failed to create return pixel shader, hr %#x.\n", hr);
22496 ib16 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices16), indices16);
22497 ib32 = create_buffer(device, D3D11_BIND_INDEX_BUFFER, sizeof(indices32), indices32);
22499 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
22500 vs_code, sizeof(vs_code), &layout);
22501 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
22503 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
22505 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
22506 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22508 ID3D11DeviceContext_IASetInputLayout(context, layout);
22509 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
22510 stride = sizeof(*vertices);
22511 offset = 0;
22512 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
22514 for (i = 0; i < 2; ++i)
22516 if (!i)
22517 ID3D11DeviceContext_IASetIndexBuffer(context, ib32, DXGI_FORMAT_R32_UINT, 0);
22518 else
22519 ID3D11DeviceContext_IASetIndexBuffer(context, ib16, DXGI_FORMAT_R16_UINT, 0);
22521 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
22522 ID3D11DeviceContext_DrawIndexed(context, 9, 0, 0);
22523 SetRect(&rect, 0, 0, 240, 480);
22524 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xffffff00, 1);
22525 SetRect(&rect, 240, 0, 400, 480);
22526 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0x00000000, 1);
22527 SetRect(&rect, 400, 0, 640, 480);
22528 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff0000ff, 1);
22531 ID3D11Buffer_Release(ib16);
22532 ID3D11Buffer_Release(ib32);
22533 ID3D11Buffer_Release(vb);
22534 ID3D11InputLayout_Release(layout);
22535 ID3D11PixelShader_Release(ps);
22536 ID3D11VertexShader_Release(vs);
22537 release_test_context(&test_context);
22540 static void test_resinfo_instruction(void)
22542 struct shader
22544 const DWORD *code;
22545 size_t size;
22548 struct d3d11_test_context test_context;
22549 D3D11_TEXTURE3D_DESC texture3d_desc;
22550 D3D11_TEXTURE2D_DESC texture_desc;
22551 const struct shader *current_ps;
22552 D3D_FEATURE_LEVEL feature_level;
22553 ID3D11ShaderResourceView *srv;
22554 ID3D11DeviceContext *context;
22555 ID3D11Texture2D *rtv_texture;
22556 ID3D11RenderTargetView *rtv;
22557 ID3D11Resource *texture;
22558 struct uvec4 constant;
22559 ID3D11PixelShader *ps;
22560 ID3D11Device *device;
22561 unsigned int i, type;
22562 ID3D11Buffer *cb;
22563 HRESULT hr;
22565 static const DWORD ps_2d_code[] =
22567 #if 0
22568 Texture2D t;
22570 uint type;
22571 uint level;
22573 float4 main() : SV_TARGET
22575 if (!type)
22577 float width, height, miplevels;
22578 t.GetDimensions(level, width, height, miplevels);
22579 return float4(width, height, miplevels, 0);
22581 else
22583 uint width, height, miplevels;
22584 t.GetDimensions(level, width, height, miplevels);
22585 return float4(width, height, miplevels, 0);
22588 #endif
22589 0x43425844, 0x9c2db58d, 0x7218d757, 0x23255414, 0xaa86938e, 0x00000001, 0x00000168, 0x00000003,
22590 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22591 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22592 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
22593 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
22594 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22595 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22596 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
22597 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
22598 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
22599 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
22600 0x01000015, 0x0100003e,
22602 static const struct shader ps_2d = {ps_2d_code, sizeof(ps_2d_code)};
22603 static const DWORD ps_2d_array_code[] =
22605 #if 0
22606 Texture2DArray t;
22608 uint type;
22609 uint level;
22611 float4 main() : SV_TARGET
22613 if (!type)
22615 float width, height, elements, miplevels;
22616 t.GetDimensions(level, width, height, elements, miplevels);
22617 return float4(width, height, elements, miplevels);
22619 else
22621 uint width, height, elements, miplevels;
22622 t.GetDimensions(level, width, height, elements, miplevels);
22623 return float4(width, height, elements, miplevels);
22626 #endif
22627 0x43425844, 0x92cd8789, 0x38e359ac, 0xd65ab502, 0xa018a5ae, 0x00000001, 0x0000012c, 0x00000003,
22628 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22629 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22630 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
22631 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04004058, 0x00107000, 0x00000000, 0x00005555,
22632 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22633 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22634 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
22635 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
22636 0x0100003e, 0x01000015, 0x0100003e,
22638 static const struct shader ps_2d_array = {ps_2d_array_code, sizeof(ps_2d_array_code)};
22639 static const DWORD ps_3d_code[] =
22641 #if 0
22642 Texture3D t;
22644 uint type;
22645 uint level;
22647 float4 main() : SV_TARGET
22649 if (!type)
22651 float width, height, depth, miplevels;
22652 t.GetDimensions(level, width, height, depth, miplevels);
22653 return float4(width, height, depth, miplevels);
22655 else
22657 uint width, height, depth, miplevels;
22658 t.GetDimensions(level, width, height, depth, miplevels);
22659 return float4(width, height, depth, miplevels);
22662 #endif
22663 0x43425844, 0xac1f73b9, 0x2bce1322, 0x82c599e6, 0xbff0d681, 0x00000001, 0x0000012c, 0x00000003,
22664 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22665 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22666 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000b4, 0x00000040, 0x0000002d,
22667 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
22668 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22669 0x00000000, 0x0800003d, 0x001020f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22670 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000,
22671 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000,
22672 0x0100003e, 0x01000015, 0x0100003e,
22674 static const struct shader ps_3d = {ps_3d_code, sizeof(ps_3d_code)};
22675 static const DWORD ps_cube_code[] =
22677 #if 0
22678 TextureCube t;
22680 uint type;
22681 uint level;
22683 float4 main() : SV_TARGET
22685 if (!type)
22687 float width, height, miplevels;
22688 t.GetDimensions(level, width, height, miplevels);
22689 return float4(width, height, miplevels, 0);
22691 else
22693 uint width, height, miplevels;
22694 t.GetDimensions(level, width, height, miplevels);
22695 return float4(width, height, miplevels, 0);
22698 #endif
22699 0x43425844, 0x795eb161, 0xb8291400, 0xcc531086, 0x2a8143ce, 0x00000001, 0x00000168, 0x00000003,
22700 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22701 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22702 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f0, 0x00000040, 0x0000003c,
22703 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04003058, 0x00107000, 0x00000000, 0x00005555,
22704 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a, 0x00000000,
22705 0x00000000, 0x0800003d, 0x001000f2, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107e46,
22706 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100346, 0x00000000, 0x05000036, 0x00102082,
22707 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x001000f2, 0x00000000,
22708 0x0020801a, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x05000056, 0x00102072, 0x00000000,
22709 0x00100346, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e,
22710 0x01000015, 0x0100003e,
22712 static const struct shader ps_cube = {ps_cube_code, sizeof(ps_cube_code)};
22713 static const DWORD ps_cube_array_code[] =
22715 #if 0
22716 TextureCubeArray t;
22718 uint type;
22719 uint level;
22721 float4 main() : SV_TARGET
22723 if (!type)
22725 float width, height, elements, miplevels;
22726 t.GetDimensions(level, width, height, elements, miplevels);
22727 return float4(width, height, miplevels, 0);
22729 else
22731 uint width, height, elements, miplevels;
22732 t.GetDimensions(level, width, height, elements, miplevels);
22733 return float4(width, height, miplevels, 0);
22736 #endif
22737 0x43425844, 0x894d136f, 0xa1f5c746, 0xd771ac09, 0x6914e044, 0x00000001, 0x0000016c, 0x00000003,
22738 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22739 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
22740 0x0000000f, 0x545f5653, 0x45475241, 0xabab0054, 0x52444853, 0x000000f4, 0x00000041, 0x0000003d,
22741 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04005058, 0x00107000, 0x00000000,
22742 0x00005555, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0400001f, 0x0020800a,
22743 0x00000000, 0x00000000, 0x0800003d, 0x00100072, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
22744 0x00107b46, 0x00000000, 0x05000036, 0x00102072, 0x00000000, 0x00100246, 0x00000000, 0x05000036,
22745 0x00102082, 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000012, 0x0800103d, 0x00100072,
22746 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x00107b46, 0x00000000, 0x05000056, 0x00102072,
22747 0x00000000, 0x00100246, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x00000000,
22748 0x0100003e, 0x01000015, 0x0100003e,
22750 static const struct shader ps_cube_array = {ps_cube_array_code, sizeof(ps_cube_array_code)};
22751 static const struct ps_test
22753 const struct shader *ps;
22754 struct
22756 unsigned int width;
22757 unsigned int height;
22758 unsigned int depth;
22759 unsigned int miplevel_count;
22760 unsigned int array_size;
22761 unsigned int cube_count;
22762 } texture_desc;
22763 unsigned int miplevel;
22764 struct vec4 expected_result;
22766 ps_tests[] =
22768 {&ps_2d, {64, 64, 1, 1, 1, 0}, 0, {64.0f, 64.0f, 1.0f, 0.0f}},
22769 {&ps_2d, {32, 16, 1, 3, 1, 0}, 0, {32.0f, 16.0f, 3.0f, 0.0f}},
22770 {&ps_2d, {32, 16, 1, 3, 1, 0}, 1, {16.0f, 8.0f, 3.0f, 0.0f}},
22771 {&ps_2d, {32, 16, 1, 3, 1, 0}, 2, { 8.0f, 4.0f, 3.0f, 0.0f}},
22773 {&ps_2d_array, {64, 64, 1, 1, 6, 0}, 0, {64.0f, 64.0f, 6.0f, 1.0f}},
22774 {&ps_2d_array, {32, 16, 1, 3, 9, 0}, 0, {32.0f, 16.0f, 9.0f, 3.0f}},
22775 {&ps_2d_array, {32, 16, 1, 3, 7, 0}, 1, {16.0f, 8.0f, 7.0f, 3.0f}},
22776 {&ps_2d_array, {32, 16, 1, 3, 3, 0}, 2, { 8.0f, 4.0f, 3.0f, 3.0f}},
22778 {&ps_3d, {64, 64, 2, 1, 1, 0}, 0, {64.0f, 64.0f, 2.0f, 1.0f}},
22779 {&ps_3d, {64, 64, 2, 2, 1, 0}, 1, {32.0f, 32.0f, 1.0f, 2.0f}},
22780 {&ps_3d, {64, 64, 4, 1, 1, 0}, 0, {64.0f, 64.0f, 4.0f, 1.0f}},
22781 {&ps_3d, {64, 64, 4, 2, 1, 0}, 1, {32.0f, 32.0f, 2.0f, 2.0f}},
22782 {&ps_3d, { 8, 8, 8, 1, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 1.0f}},
22783 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 0, { 8.0f, 8.0f, 8.0f, 4.0f}},
22784 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 1, { 4.0f, 4.0f, 4.0f, 4.0f}},
22785 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 2, { 2.0f, 2.0f, 2.0f, 4.0f}},
22786 {&ps_3d, { 8, 8, 8, 4, 1, 0}, 3, { 1.0f, 1.0f, 1.0f, 4.0f}},
22788 {&ps_cube, { 4, 4, 1, 1, 6, 1}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
22789 {&ps_cube, {32, 32, 1, 1, 6, 1}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
22790 {&ps_cube, {32, 32, 1, 3, 6, 1}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
22791 {&ps_cube, {32, 32, 1, 3, 6, 1}, 1, {16.0f, 16.0f, 3.0f, 0.0f}},
22792 {&ps_cube, {32, 32, 1, 3, 6, 1}, 2, { 8.0f, 8.0f, 3.0f, 0.0f}},
22794 {&ps_cube_array, { 4, 4, 1, 1, 12, 2}, 0, { 4.0f, 4.0f, 1.0f, 0.0f}},
22795 {&ps_cube_array, {32, 32, 1, 1, 12, 2}, 0, {32.0f, 32.0f, 1.0f, 0.0f}},
22796 {&ps_cube_array, {32, 32, 1, 3, 12, 2}, 0, {32.0f, 32.0f, 3.0f, 0.0f}},
22799 if (!init_test_context(&test_context, NULL))
22800 return;
22802 device = test_context.device;
22803 context = test_context.immediate_context;
22804 feature_level = ID3D11Device_GetFeatureLevel(device);
22806 texture_desc.Width = 64;
22807 texture_desc.Height = 64;
22808 texture_desc.MipLevels = 1;
22809 texture_desc.ArraySize = 1;
22810 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
22811 texture_desc.SampleDesc.Count = 1;
22812 texture_desc.SampleDesc.Quality = 0;
22813 texture_desc.Usage = D3D11_USAGE_DEFAULT;
22814 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
22815 texture_desc.CPUAccessFlags = 0;
22816 texture_desc.MiscFlags = 0;
22817 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rtv_texture);
22818 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
22819 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rtv_texture, NULL, &rtv);
22820 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
22822 memset(&constant, 0, sizeof(constant));
22823 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
22825 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
22826 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
22828 ps = NULL;
22829 current_ps = NULL;
22830 for (i = 0; i < ARRAY_SIZE(ps_tests); ++i)
22832 const struct ps_test *test = &ps_tests[i];
22834 if (test->texture_desc.cube_count > 1 && feature_level < D3D_FEATURE_LEVEL_10_1)
22836 skip("Test %u: Cube map array textures require feature level 10_1.\n", i);
22837 continue;
22840 if (current_ps != test->ps)
22842 if (ps)
22843 ID3D11PixelShader_Release(ps);
22845 current_ps = test->ps;
22847 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
22848 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
22849 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
22852 if (test->texture_desc.depth != 1)
22854 texture3d_desc.Width = test->texture_desc.width;
22855 texture3d_desc.Height = test->texture_desc.height;
22856 texture3d_desc.Depth = test->texture_desc.depth;
22857 texture3d_desc.MipLevels = test->texture_desc.miplevel_count;
22858 texture3d_desc.Format = DXGI_FORMAT_R8_UNORM;
22859 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
22860 texture3d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22861 texture3d_desc.CPUAccessFlags = 0;
22862 texture3d_desc.MiscFlags = 0;
22863 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL, (ID3D11Texture3D **)&texture);
22864 ok(SUCCEEDED(hr), "Test %u: Failed to create 3d texture, hr %#x.\n", i, hr);
22866 else
22868 texture_desc.Width = test->texture_desc.width;
22869 texture_desc.Height = test->texture_desc.height;
22870 texture_desc.MipLevels = test->texture_desc.miplevel_count;
22871 texture_desc.ArraySize = test->texture_desc.array_size;
22872 texture_desc.Format = DXGI_FORMAT_R8_UNORM;
22873 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
22874 texture_desc.MiscFlags = 0;
22875 if (test->texture_desc.cube_count)
22876 texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_TEXTURECUBE;
22877 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, (ID3D11Texture2D **)&texture);
22878 ok(SUCCEEDED(hr), "Test %u: Failed to create 2d texture, hr %#x.\n", i, hr);
22881 hr = ID3D11Device_CreateShaderResourceView(device, texture, NULL, &srv);
22882 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
22883 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
22885 for (type = 0; type < 2; ++type)
22887 constant.x = type;
22888 constant.y = test->miplevel;
22889 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
22891 draw_quad(&test_context);
22892 check_texture_vec4(rtv_texture, &test->expected_result, 0);
22895 ID3D11Resource_Release(texture);
22896 ID3D11ShaderResourceView_Release(srv);
22898 ID3D11PixelShader_Release(ps);
22900 ID3D11Buffer_Release(cb);
22901 ID3D11RenderTargetView_Release(rtv);
22902 ID3D11Texture2D_Release(rtv_texture);
22903 release_test_context(&test_context);
22906 static void test_sm5_bufinfo_instruction(void)
22908 struct shader
22910 const DWORD *code;
22911 size_t size;
22914 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
22915 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
22916 struct d3d11_test_context test_context;
22917 D3D11_TEXTURE2D_DESC texture_desc;
22918 const struct shader *current_ps;
22919 ID3D11UnorderedAccessView *uav;
22920 ID3D11ShaderResourceView *srv;
22921 D3D11_BUFFER_DESC buffer_desc;
22922 ID3D11DeviceContext *context;
22923 ID3D11RenderTargetView *rtv;
22924 ID3D11Texture2D *texture;
22925 ID3D11PixelShader *ps;
22926 ID3D11Buffer *buffer;
22927 ID3D11Device *device;
22928 unsigned int i;
22929 HRESULT hr;
22931 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
22932 static const DWORD ps_uav_structured_code[] =
22934 #if 0
22935 struct s
22937 uint4 u;
22938 bool b;
22941 RWStructuredBuffer<s> b;
22943 uint4 main(void) : SV_Target
22945 uint count, stride;
22946 b.GetDimensions(count, stride);
22947 return uint4(count, stride, 0, 1);
22949 #endif
22950 0x43425844, 0xe1900f85, 0x13c1f338, 0xbb19865e, 0x366df28f, 0x00000001, 0x000000fc, 0x00000003,
22951 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22952 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
22953 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
22954 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000014, 0x03000065, 0x001020f2, 0x00000000,
22955 0x02000068, 0x00000001, 0x87000079, 0x8000a302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
22956 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
22957 0x00000000, 0x00004002, 0x00000000, 0x00000014, 0x00000000, 0x00000001, 0x0100003e,
22959 static const struct shader ps_uav_structured = {ps_uav_structured_code, sizeof(ps_uav_structured_code)};
22960 static const DWORD ps_uav_structured32_code[] =
22962 #if 0
22963 struct s
22965 uint4 u;
22966 bool4 b;
22969 RWStructuredBuffer<s> b;
22971 uint4 main(void) : SV_Target
22973 uint count, stride;
22974 b.GetDimensions(count, stride);
22975 return uint4(count, stride, 0, 1);
22977 #endif
22978 0x43425844, 0xdd87a805, 0x28090470, 0xe4fa7c4d, 0x57963f52, 0x00000001, 0x000000fc, 0x00000003,
22979 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
22980 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
22981 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
22982 0x0100086a, 0x0400009e, 0x0011e000, 0x00000001, 0x00000020, 0x03000065, 0x001020f2, 0x00000000,
22983 0x02000068, 0x00000001, 0x87000079, 0x80010302, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46,
22984 0x00000001, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
22985 0x00000000, 0x00004002, 0x00000000, 0x00000020, 0x00000000, 0x00000001, 0x0100003e,
22987 static const struct shader ps_uav_structured32 = {ps_uav_structured32_code, sizeof(ps_uav_structured32_code)};
22988 static const DWORD ps_srv_structured_code[] =
22990 #if 0
22991 StructuredBuffer<bool> b;
22993 uint4 main(void) : SV_Target
22995 uint count, stride;
22996 b.GetDimensions(count, stride);
22997 return uint4(count, stride, 0, 1);
22999 #endif
23000 0x43425844, 0x313f910c, 0x2f60c646, 0x2d87455c, 0xb9988c2c, 0x00000001, 0x000000fc, 0x00000003,
23001 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23002 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23003 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000084, 0x00000050, 0x00000021,
23004 0x0100086a, 0x040000a2, 0x00107000, 0x00000000, 0x00000004, 0x03000065, 0x001020f2, 0x00000000,
23005 0x02000068, 0x00000001, 0x87000079, 0x80002302, 0x00199983, 0x00100012, 0x00000000, 0x00107e46,
23006 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x08000036, 0x001020e2,
23007 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000, 0x00000001, 0x0100003e,
23009 static const struct shader ps_srv_structured = {ps_srv_structured_code, sizeof(ps_srv_structured_code)};
23010 static const DWORD ps_uav_raw_code[] =
23012 #if 0
23013 RWByteAddressBuffer b;
23015 uint4 main(void) : SV_Target
23017 uint width;
23018 b.GetDimensions(width);
23019 return width;
23021 #endif
23022 0x43425844, 0xb06e9715, 0x99733b00, 0xaa536550, 0x703a01c5, 0x00000001, 0x000000d8, 0x00000003,
23023 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23024 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23025 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
23026 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
23027 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x0011ee46, 0x00000001,
23028 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23030 static const struct shader ps_uav_raw = {ps_uav_raw_code, sizeof(ps_uav_raw_code)};
23031 static const DWORD ps_srv_raw_code[] =
23033 #if 0
23034 ByteAddressBuffer b;
23036 uint4 main(void) : SV_Target
23038 uint width;
23039 b.GetDimensions(width);
23040 return width;
23042 #endif
23043 0x43425844, 0x934bc27a, 0x3251cc9d, 0xa129bdd3, 0xf7cedcc4, 0x00000001, 0x000000d8, 0x00000003,
23044 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23045 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23046 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000060, 0x00000050, 0x00000018,
23047 0x0100086a, 0x030000a1, 0x00107000, 0x00000000, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
23048 0x00000001, 0x87000079, 0x800002c2, 0x00199983, 0x00100012, 0x00000000, 0x00107e46, 0x00000000,
23049 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23051 static const struct shader ps_srv_raw = {ps_srv_raw_code, sizeof(ps_srv_raw_code)};
23052 static const DWORD ps_uav_typed_code[] =
23054 #if 0
23055 RWBuffer<float> b;
23057 uint4 main(void) : SV_Target
23059 uint width;
23060 b.GetDimensions(width);
23061 return width;
23063 #endif
23064 0x43425844, 0x96b39f5f, 0x5fef24c7, 0xed404a41, 0x01c9d4fe, 0x00000001, 0x000000dc, 0x00000003,
23065 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23066 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23067 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
23068 0x0100086a, 0x0400089c, 0x0011e000, 0x00000001, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23069 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x0011ee46,
23070 0x00000001, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23072 static const struct shader ps_uav_typed = {ps_uav_typed_code, sizeof(ps_uav_typed_code)};
23073 static const DWORD ps_srv_typed_code[] =
23075 #if 0
23076 Buffer<float> b;
23078 uint4 main(void) : SV_Target
23080 uint width;
23081 b.GetDimensions(width);
23082 return width;
23084 #endif
23085 0x43425844, 0x6ae6dbb0, 0x6289d227, 0xaf4e708e, 0x111efed1, 0x00000001, 0x000000dc, 0x00000003,
23086 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23087 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001, 0x00000000,
23088 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064, 0x00000050, 0x00000019,
23089 0x0100086a, 0x04000858, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23090 0x02000068, 0x00000001, 0x87000079, 0x80000042, 0x00155543, 0x00100012, 0x00000000, 0x00107e46,
23091 0x00000000, 0x05000036, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x0100003e,
23093 static const struct shader ps_srv_typed = {ps_srv_typed_code, sizeof(ps_srv_typed_code)};
23094 static const struct test
23096 const struct shader *ps;
23097 BOOL uav;
23098 unsigned int buffer_size;
23099 unsigned int buffer_misc_flags;
23100 unsigned int buffer_structure_byte_stride;
23101 DXGI_FORMAT view_format;
23102 unsigned int view_element_idx;
23103 unsigned int view_element_count;
23104 struct uvec4 expected_result;
23106 tests[] =
23108 #define RAW D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS
23109 #define STRUCTURED D3D11_RESOURCE_MISC_BUFFER_STRUCTURED
23110 {&ps_uav_raw, TRUE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
23111 {&ps_uav_raw, TRUE, 512, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 64, {256, 256, 256, 256}},
23112 {&ps_srv_raw, FALSE, 100, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 0, 25, {100, 100, 100, 100}},
23113 {&ps_srv_raw, FALSE, 500, RAW, 0, DXGI_FORMAT_R32_TYPELESS, 64, 4, { 16, 16, 16, 16}},
23114 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 20, 0, 1}},
23115 {&ps_uav_structured, TRUE, 100, STRUCTURED, 20, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 20, 0, 1}},
23116 {&ps_uav_structured32, TRUE, 320, STRUCTURED, 32, DXGI_FORMAT_UNKNOWN, 8, 2, { 2, 32, 0, 1}},
23117 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 5, { 5, 4, 0, 1}},
23118 {&ps_srv_structured, FALSE, 100, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 0, 2, { 2, 4, 0, 1}},
23119 {&ps_srv_structured, FALSE, 400, STRUCTURED, 4, DXGI_FORMAT_UNKNOWN, 64, 2, { 2, 4, 0, 1}},
23120 {&ps_uav_typed, TRUE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
23121 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
23122 {&ps_uav_typed, TRUE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
23123 {&ps_uav_typed, TRUE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 1, { 1, 1, 1, 1}},
23124 {&ps_srv_typed, FALSE, 200, 0, 0, DXGI_FORMAT_R32_FLOAT, 0, 50, { 50, 50, 50, 50}},
23125 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R32_FLOAT, 64, 1, { 1, 1, 1, 1}},
23126 {&ps_srv_typed, FALSE, 100, 0, 0, DXGI_FORMAT_R16_FLOAT, 0, 50, { 50, 50, 50, 50}},
23127 {&ps_srv_typed, FALSE, 400, 0, 0, DXGI_FORMAT_R16_FLOAT, 128, 2, { 2, 2, 2, 2}},
23128 #undef RAW
23129 #undef STRUCTURED
23132 if (!init_test_context(&test_context, &feature_level))
23133 return;
23135 device = test_context.device;
23136 context = test_context.immediate_context;
23138 texture_desc.Width = 64;
23139 texture_desc.Height = 64;
23140 texture_desc.MipLevels = 1;
23141 texture_desc.ArraySize = 1;
23142 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
23143 texture_desc.SampleDesc.Count = 1;
23144 texture_desc.SampleDesc.Quality = 0;
23145 texture_desc.Usage = D3D11_USAGE_DEFAULT;
23146 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23147 texture_desc.CPUAccessFlags = 0;
23148 texture_desc.MiscFlags = 0;
23149 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23150 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
23151 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23152 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
23154 ps = NULL;
23155 current_ps = NULL;
23156 for (i = 0; i < ARRAY_SIZE(tests); ++i)
23158 const struct test *test = &tests[i];
23160 if (current_ps != test->ps)
23162 if (ps)
23163 ID3D11PixelShader_Release(ps);
23165 current_ps = test->ps;
23167 hr = ID3D11Device_CreatePixelShader(device, current_ps->code, current_ps->size, NULL, &ps);
23168 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
23169 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23172 buffer_desc.ByteWidth = test->buffer_size;
23173 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23174 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_UNORDERED_ACCESS;
23175 buffer_desc.CPUAccessFlags = 0;
23176 buffer_desc.MiscFlags = test->buffer_misc_flags;
23177 buffer_desc.StructureByteStride = test->buffer_structure_byte_stride;
23178 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
23179 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
23181 if (test->uav)
23183 uav_desc.Format = test->view_format;
23184 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
23185 U(uav_desc).Buffer.FirstElement = test->view_element_idx;
23186 U(uav_desc).Buffer.NumElements = test->view_element_count;
23187 U(uav_desc).Buffer.Flags = 0;
23188 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
23189 U(uav_desc).Buffer.Flags |= D3D11_BUFFER_UAV_FLAG_RAW;
23190 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
23191 ok(SUCCEEDED(hr), "Test %u: Failed to create unordered access view, hr %#x.\n", i, hr);
23192 srv = NULL;
23194 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context, 1, &rtv, NULL,
23195 1, 1, &uav, NULL);
23197 else
23199 srv_desc.Format = test->view_format;
23200 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
23201 U(srv_desc).BufferEx.FirstElement = test->view_element_idx;
23202 U(srv_desc).BufferEx.NumElements = test->view_element_count;
23203 U(srv_desc).BufferEx.Flags = 0;
23204 if (buffer_desc.MiscFlags & D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS)
23205 U(srv_desc).BufferEx.Flags |= D3D11_BUFFEREX_SRV_FLAG_RAW;
23206 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
23207 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
23208 uav = NULL;
23210 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23211 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23214 draw_quad(&test_context);
23215 check_texture_uvec4(texture, &test->expected_result);
23217 if (srv)
23218 ID3D11ShaderResourceView_Release(srv);
23219 if (uav)
23220 ID3D11UnorderedAccessView_Release(uav);
23221 ID3D11Buffer_Release(buffer);
23223 ID3D11PixelShader_Release(ps);
23225 ID3D11RenderTargetView_Release(rtv);
23226 ID3D11Texture2D_Release(texture);
23227 release_test_context(&test_context);
23230 static void test_sampleinfo_instruction(void)
23232 ID3D11Texture2D *float_rt_texture, *uint_rt_texture;
23233 ID3D11RenderTargetView *float_rtv, *uint_rtv, *rtv;
23234 ID3D11PixelShader *ps_float, *ps_uint, *ps_rt;
23235 ID3D11Texture2D *texture, *readback_texture;
23236 struct d3d11_test_context test_context;
23237 unsigned int sample_count, quality;
23238 D3D11_TEXTURE2D_DESC texture_desc;
23239 ID3D11RenderTargetView *rtvs[2];
23240 ID3D11ShaderResourceView *srv;
23241 ID3D11DeviceContext *context;
23242 struct uvec4 expected_uint;
23243 struct vec4 expected_float;
23244 ID3D11Device *device;
23245 HRESULT hr;
23247 static const DWORD ps_uint_code[] =
23249 #if 0
23250 Texture2DMS<float> t;
23252 uint4 main() : SV_Target1
23254 uint width, height, sample_count;
23255 t.GetDimensions(width, height, sample_count);
23256 return sample_count;
23258 #endif
23259 0x43425844, 0x4342ad12, 0x19addd8c, 0x5cb87c48, 0xe604a242, 0x00000001, 0x000000d4, 0x00000003,
23260 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23261 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000001, 0x00000000, 0x00000001, 0x00000001,
23262 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000005c, 0x00000050, 0x00000017,
23263 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000001,
23264 0x02000068, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a, 0x00000000, 0x05000036,
23265 0x001020f2, 0x00000001, 0x00100006, 0x00000000, 0x0100003e,
23267 static const DWORD ps_float_code[] =
23269 #if 0
23270 Texture2DMS<float> t;
23272 float4 main() : SV_Target
23274 uint width, height, sample_count;
23275 t.GetDimensions(width, height, sample_count);
23276 return sample_count;
23278 #endif
23279 0x43425844, 0x2b8aea46, 0x34ceda6f, 0xf98d222b, 0x235ebc0b, 0x00000001, 0x000000b8, 0x00000003,
23280 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23281 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23282 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000040, 0x00000050, 0x00000010,
23283 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x03000065, 0x001020f2, 0x00000000,
23284 0x0500006f, 0x001020f2, 0x00000000, 0x0010700a, 0x00000000, 0x0100003e,
23286 static const DWORD ps_rt_code[] =
23288 #if 0
23289 float4 main() : SV_Target
23291 return GetRenderTargetSampleCount();
23293 #endif
23294 0x43425844, 0x74404d37, 0xad6f88e4, 0xb006ea57, 0xf07d9e2a, 0x00000001, 0x000000a4, 0x00000003,
23295 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23296 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
23297 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000002c, 0x00000050, 0x0000000b,
23298 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x0400006f, 0x001020f2, 0x00000000, 0x0000e00a,
23299 0x0100003e,
23301 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
23303 if (!init_test_context(&test_context, &feature_level))
23304 return;
23306 device = test_context.device;
23307 context = test_context.immediate_context;
23309 texture_desc.Width = 64;
23310 texture_desc.Height = 64;
23311 texture_desc.MipLevels = 1;
23312 texture_desc.ArraySize = 1;
23313 texture_desc.SampleDesc.Count = 1;
23314 texture_desc.SampleDesc.Quality = 0;
23315 texture_desc.Usage = D3D11_USAGE_DEFAULT;
23316 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23317 texture_desc.CPUAccessFlags = 0;
23318 texture_desc.MiscFlags = 0;
23320 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
23321 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &float_rt_texture);
23322 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23323 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)float_rt_texture, NULL, &float_rtv);
23324 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
23325 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_UINT;
23326 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &uint_rt_texture);
23327 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23328 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)uint_rt_texture, NULL, &uint_rtv);
23329 ok(hr == S_OK, "Failed to create rendertarget view, hr %#x.\n", hr);
23331 rtvs[0] = float_rtv;
23332 rtvs[1] = uint_rtv;
23333 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
23335 hr = ID3D11Device_CreatePixelShader(device, ps_float_code, sizeof(ps_float_code), NULL, &ps_float);
23336 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23337 hr = ID3D11Device_CreatePixelShader(device, ps_uint_code, sizeof(ps_uint_code), NULL, &ps_uint);
23338 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23340 for (sample_count = 2; sample_count <= 8; sample_count *= 2)
23342 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
23343 texture_desc.SampleDesc.Count = sample_count;
23344 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
23346 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
23347 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
23348 if (!quality)
23350 skip("Sample count %u not supported.\n", sample_count);
23351 continue;
23354 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23355 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
23356 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
23357 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
23358 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23360 ID3D11DeviceContext_PSSetShader(context, ps_float, NULL, 0);
23361 draw_quad(&test_context);
23362 ID3D11DeviceContext_PSSetShader(context, ps_uint, NULL, 0);
23363 draw_quad(&test_context);
23365 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
23366 check_texture_vec4(float_rt_texture, &expected_float, 0);
23367 expected_uint.x = expected_uint.y = expected_uint.z = expected_uint.w = sample_count;
23368 check_texture_uvec4(uint_rt_texture, &expected_uint);
23370 ID3D11Texture2D_Release(texture);
23371 ID3D11ShaderResourceView_Release(srv);
23374 hr = ID3D11Device_CreatePixelShader(device, ps_rt_code, sizeof(ps_rt_code), NULL, &ps_rt);
23375 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
23376 for (sample_count = 1; sample_count <= 8; sample_count *= 2)
23378 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
23379 texture_desc.SampleDesc.Count = sample_count;
23380 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
23382 hr = ID3D11Device_CheckMultisampleQualityLevels(device, texture_desc.Format, sample_count, &quality);
23383 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
23384 if (!quality)
23386 skip("Sample count %u not supported.\n", sample_count);
23387 continue;
23390 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23391 ok(hr == S_OK, "Failed to create texture, hr %#x, sample count %u.\n", hr, sample_count);
23392 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23393 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
23394 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23396 /* Some drivers (AMD Radeon HD 6310) return stale sample counts if we
23397 * don't rebind the pixel shader between runs with different sample
23398 * counts. */
23399 ID3D11DeviceContext_PSSetShader(context, NULL, NULL, 0);
23400 ID3D11DeviceContext_PSSetShader(context, ps_rt, NULL, 0);
23401 draw_quad(&test_context);
23403 if (sample_count != 1)
23405 texture_desc.SampleDesc.Count = 1;
23406 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
23407 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
23408 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
23409 (ID3D11Resource *)texture, 0, texture_desc.Format);
23411 else
23413 readback_texture = texture;
23414 ID3D11Texture2D_AddRef(readback_texture);
23417 expected_float.x = expected_float.y = expected_float.z = expected_float.w = sample_count;
23418 check_texture_vec4(readback_texture, &expected_float, 0);
23420 ID3D11Texture2D_Release(readback_texture);
23421 ID3D11Texture2D_Release(texture);
23422 ID3D11RenderTargetView_Release(rtv);
23425 ID3D11RenderTargetView_Release(float_rtv);
23426 ID3D11RenderTargetView_Release(uint_rtv);
23427 ID3D11Texture2D_Release(float_rt_texture);
23428 ID3D11Texture2D_Release(uint_rt_texture);
23429 ID3D11PixelShader_Release(ps_float);
23430 ID3D11PixelShader_Release(ps_uint);
23431 ID3D11PixelShader_Release(ps_rt);
23432 release_test_context(&test_context);
23435 static void test_render_target_device_mismatch(void)
23437 struct d3d11_test_context test_context;
23438 struct device_desc device_desc = {0};
23439 ID3D11DeviceContext *context;
23440 ID3D11RenderTargetView *rtv;
23441 ID3D11Device *device;
23442 ULONG refcount;
23444 if (!init_test_context(&test_context, NULL))
23445 return;
23447 device = create_device(&device_desc);
23448 ok(!!device, "Failed to create device.\n");
23450 ID3D11Device_GetImmediateContext(device, &context);
23452 rtv = (ID3D11RenderTargetView *)0xdeadbeef;
23453 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
23454 ok(!rtv, "Got unexpected render target view %p.\n", rtv);
23455 if (!enable_debug_layer)
23457 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
23458 ID3D11DeviceContext_OMGetRenderTargets(context, 1, &rtv, NULL);
23459 ok(rtv == test_context.backbuffer_rtv, "Got unexpected render target view %p.\n", rtv);
23460 ID3D11RenderTargetView_Release(rtv);
23463 rtv = NULL;
23464 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23466 ID3D11DeviceContext_Release(context);
23467 refcount = ID3D11Device_Release(device);
23468 ok(!refcount, "Device has %u references left.\n", refcount);
23469 release_test_context(&test_context);
23472 static void test_buffer_srv(void)
23474 struct shader
23476 const DWORD *code;
23477 size_t size;
23478 BOOL requires_raw_and_structured_buffers;
23480 struct buffer
23482 unsigned int byte_count;
23483 unsigned int data_offset;
23484 const void *data;
23485 unsigned int structure_byte_stride;
23488 BOOL raw_and_structured_buffers_supported;
23489 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
23490 struct d3d11_test_context test_context;
23491 D3D11_SUBRESOURCE_DATA resource_data;
23492 const struct buffer *current_buffer;
23493 const struct shader *current_shader;
23494 ID3D11ShaderResourceView *srv;
23495 D3D11_BUFFER_DESC buffer_desc;
23496 ID3D11DeviceContext *context;
23497 DWORD color, expected_color;
23498 struct resource_readback rb;
23499 ID3D11Buffer *cb, *buffer;
23500 ID3D11PixelShader *ps;
23501 ID3D11Device *device;
23502 unsigned int i, x, y;
23503 struct vec4 cb_size;
23504 HRESULT hr;
23506 static const DWORD ps_float4_code[] =
23508 #if 0
23509 Buffer<float4> b;
23511 float2 size;
23513 float4 main(float4 position : SV_POSITION) : SV_Target
23515 float2 p;
23516 int2 coords;
23517 p.x = position.x / 640.0f;
23518 p.y = position.y / 480.0f;
23519 coords = int2(p.x * size.x, p.y * size.y);
23520 return b.Load(coords.y * size.x + coords.x);
23522 #endif
23523 0x43425844, 0xf10ea650, 0x311f5c38, 0x3a888b7f, 0x58230334, 0x00000001, 0x000001a0, 0x00000003,
23524 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
23525 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
23526 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
23527 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000104, 0x00000040,
23528 0x00000041, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04000858, 0x00107000, 0x00000000,
23529 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
23530 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516, 0x00000000, 0x00208516,
23531 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002,
23532 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032, 0x00000000, 0x00100046,
23533 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x0020800a, 0x00000000,
23534 0x00000000, 0x0010001a, 0x00000000, 0x0500001b, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
23535 0x0700002d, 0x001020f2, 0x00000000, 0x00100006, 0x00000000, 0x00107e46, 0x00000000, 0x0100003e,
23537 static const struct shader ps_float4 = {ps_float4_code, sizeof(ps_float4_code)};
23538 static const DWORD ps_structured_code[] =
23540 #if 0
23541 StructuredBuffer<float4> b;
23543 float2 size;
23545 float4 main(float4 position : SV_POSITION) : SV_Target
23547 float2 p;
23548 int2 coords;
23549 p.x = position.x / 640.0f;
23550 p.y = position.y / 480.0f;
23551 coords = int2(p.x * size.x, p.y * size.y);
23552 return b[coords.y * size.x + coords.x];
23554 #endif
23555 0x43425844, 0x246caabb, 0xf1e7d6b9, 0xcbe720dc, 0xcdc23036, 0x00000001, 0x000001c0, 0x00000004,
23556 0x00000030, 0x00000064, 0x00000098, 0x000001b0, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
23557 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f,
23558 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
23559 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000110,
23560 0x00000040, 0x00000044, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x040000a2,
23561 0x00107000, 0x00000000, 0x00000010, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
23562 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x08000038, 0x00100032, 0x00000000, 0x00101516,
23563 0x00000000, 0x00208516, 0x00000000, 0x00000000, 0x0a000038, 0x00100032, 0x00000000, 0x00100046,
23564 0x00000000, 0x00004002, 0x3b088889, 0x3acccccd, 0x00000000, 0x00000000, 0x05000043, 0x00100032,
23565 0x00000000, 0x00100046, 0x00000000, 0x0a000032, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
23566 0x0020800a, 0x00000000, 0x00000000, 0x0010001a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
23567 0x0010000a, 0x00000000, 0x090000a7, 0x001020f2, 0x00000000, 0x0010000a, 0x00000000, 0x00004001,
23568 0x00000000, 0x00107e46, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002, 0x00000000,
23570 static const struct shader ps_structured = {ps_structured_code, sizeof(ps_structured_code), TRUE};
23571 static const DWORD rgba16[] =
23573 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
23574 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
23575 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
23576 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
23578 static const DWORD rgba4[] =
23580 0xffffffff, 0xff0000ff,
23581 0xff000000, 0xff00ff00,
23583 static const BYTE r4[] =
23585 0xde, 0xad,
23586 0xba, 0xbe,
23588 static const struct vec4 rgba_float[] =
23590 {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 0.0f, 0.0f, 1.0f},
23591 {0.0f, 0.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f, 1.0f},
23593 static const struct buffer rgba16_buffer = {sizeof(rgba16), 0, &rgba16};
23594 static const struct buffer rgba16_offset_buffer = {256 + sizeof(rgba16), 256, &rgba16};
23595 static const struct buffer rgba4_buffer = {sizeof(rgba4), 0, &rgba4};
23596 static const struct buffer r4_buffer = {sizeof(r4), 0, &r4};
23597 static const struct buffer r4_offset_buffer = {256 + sizeof(r4), 256, &r4};
23598 static const struct buffer float_buffer = {sizeof(rgba_float), 0, &rgba_float, sizeof(*rgba_float)};
23599 static const struct buffer float_offset_buffer = {256 + sizeof(rgba_float), 256,
23600 &rgba_float, sizeof(*rgba_float)};
23601 static const DWORD rgba16_colors2x2[] =
23603 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
23604 0xff0000ff, 0xff0000ff, 0xff00ffff, 0xff00ffff,
23605 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
23606 0xff00ff00, 0xff00ff00, 0xffffff00, 0xffffff00,
23608 static const DWORD rgba16_colors1x1[] =
23610 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23611 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23612 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23613 0xff0000ff, 0xff0000ff, 0xff0000ff, 0xff0000ff,
23615 static const DWORD rgba4_colors[] =
23617 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
23618 0xffffffff, 0xffffffff, 0xff0000ff, 0xff0000ff,
23619 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
23620 0xff000000, 0xff000000, 0xff00ff00, 0xff00ff00,
23622 static const DWORD r4_colors[] =
23624 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
23625 0xff0000de, 0xff0000de, 0xff0000ad, 0xff0000ad,
23626 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
23627 0xff0000ba, 0xff0000ba, 0xff0000be, 0xff0000be,
23629 static const DWORD zero_colors[16] = {0};
23630 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
23632 static const struct test
23634 const struct shader *shader;
23635 const struct buffer *buffer;
23636 DXGI_FORMAT srv_format;
23637 unsigned int srv_first_element;
23638 unsigned int srv_element_count;
23639 struct vec2 size;
23640 const DWORD *expected_colors;
23642 tests[] =
23644 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, {4.0f, 4.0f}, rgba16},
23645 {&ps_float4, &rgba16_offset_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 64, 16, {4.0f, 4.0f}, rgba16},
23646 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba16_colors2x2},
23647 {&ps_float4, &rgba16_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 1, {1.0f, 1.0f}, rgba16_colors1x1},
23648 {&ps_float4, &rgba4_buffer, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 4, {2.0f, 2.0f}, rgba4_colors},
23649 {&ps_float4, &r4_buffer, DXGI_FORMAT_R8_UNORM, 0, 4, {2.0f, 2.0f}, r4_colors},
23650 {&ps_float4, &r4_offset_buffer, DXGI_FORMAT_R8_UNORM, 256, 4, {2.0f, 2.0f}, r4_colors},
23651 {&ps_structured, &float_buffer, DXGI_FORMAT_UNKNOWN, 0, 4, {2.0f, 2.0f}, rgba4_colors},
23652 {&ps_structured, &float_offset_buffer, DXGI_FORMAT_UNKNOWN, 16, 4, {2.0f, 2.0f}, rgba4_colors},
23653 {&ps_float4, NULL, 0, 0, 0, {2.0f, 2.0f}, zero_colors},
23654 {&ps_float4, NULL, 0, 0, 0, {1.0f, 1.0f}, zero_colors},
23657 if (!init_test_context(&test_context, NULL))
23658 return;
23660 device = test_context.device;
23661 context = test_context.immediate_context;
23662 raw_and_structured_buffers_supported = ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0
23663 || check_compute_shaders_via_sm4_support(device);
23665 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_size), NULL);
23666 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
23668 buffer_desc.ByteWidth = 256;
23669 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23670 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23671 buffer_desc.CPUAccessFlags = 0;
23672 buffer_desc.MiscFlags = 0;
23673 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
23674 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23675 srv_desc.Format = DXGI_FORMAT_R8_UNORM;
23676 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
23677 U(srv_desc).Buffer.FirstElement = 0;
23678 U(srv_desc).Buffer.NumElements = 0;
23679 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
23680 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
23681 ID3D11Buffer_Release(buffer);
23683 ps = NULL;
23684 srv = NULL;
23685 buffer = NULL;
23686 current_shader = NULL;
23687 current_buffer = NULL;
23688 for (i = 0; i < ARRAY_SIZE(tests); ++i)
23690 const struct test *test = &tests[i];
23692 if (test->shader->requires_raw_and_structured_buffers && !raw_and_structured_buffers_supported)
23694 skip("Test %u: Raw and structured buffers are not supported.\n", i);
23695 continue;
23697 /* Structured buffer views with an offset don't seem to work on WARP. */
23698 if (test->srv_format == DXGI_FORMAT_UNKNOWN && test->srv_first_element
23699 && is_warp_device(device))
23701 skip("Test %u: Broken WARP.\n", i);
23702 continue;
23705 if (current_shader != test->shader)
23707 if (ps)
23708 ID3D11PixelShader_Release(ps);
23710 current_shader = test->shader;
23712 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
23713 ok(SUCCEEDED(hr), "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
23714 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23717 if (current_buffer != test->buffer)
23719 if (buffer)
23720 ID3D11Buffer_Release(buffer);
23722 current_buffer = test->buffer;
23723 if (current_buffer)
23725 BYTE *data = NULL;
23727 buffer_desc.ByteWidth = current_buffer->byte_count;
23728 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23729 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23730 buffer_desc.CPUAccessFlags = 0;
23731 buffer_desc.MiscFlags = 0;
23732 if ((buffer_desc.StructureByteStride = current_buffer->structure_byte_stride))
23733 buffer_desc.MiscFlags |= D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
23734 resource_data.SysMemPitch = 0;
23735 resource_data.SysMemSlicePitch = 0;
23736 if (current_buffer->data_offset)
23738 data = heap_alloc_zero(current_buffer->byte_count);
23739 ok(!!data, "Failed to allocate memory.\n");
23740 memcpy(data + current_buffer->data_offset, current_buffer->data,
23741 current_buffer->byte_count - current_buffer->data_offset);
23742 resource_data.pSysMem = data;
23744 else
23746 resource_data.pSysMem = current_buffer->data;
23748 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
23749 ok(SUCCEEDED(hr), "Test %u: Failed to create buffer, hr %#x.\n", i, hr);
23750 heap_free(data);
23752 else
23754 buffer = NULL;
23758 if (srv)
23759 ID3D11ShaderResourceView_Release(srv);
23760 if (current_buffer)
23762 srv_desc.Format = test->srv_format;
23763 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFER;
23764 U(srv_desc).Buffer.FirstElement = test->srv_first_element;
23765 U(srv_desc).Buffer.NumElements = test->srv_element_count;
23766 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)buffer, &srv_desc, &srv);
23767 ok(SUCCEEDED(hr), "Test %u: Failed to create shader resource view, hr %#x.\n", i, hr);
23769 else
23771 srv = NULL;
23773 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23775 cb_size.x = test->size.x;
23776 cb_size.y = test->size.y;
23777 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_size, 0, 0);
23779 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
23780 draw_quad(&test_context);
23782 get_texture_readback(test_context.backbuffer, 0, &rb);
23783 for (y = 0; y < 4; ++y)
23785 for (x = 0; x < 4; ++x)
23787 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
23788 expected_color = test->expected_colors[y * 4 + x];
23789 ok(compare_color(color, expected_color, 1),
23790 "Test %u: Got 0x%08x, expected 0x%08x at (%u, %u).\n",
23791 i, color, expected_color, x, y);
23794 release_resource_readback(&rb);
23796 if (srv)
23797 ID3D11ShaderResourceView_Release(srv);
23798 if (buffer)
23799 ID3D11Buffer_Release(buffer);
23801 ID3D11Buffer_Release(cb);
23802 ID3D11PixelShader_Release(ps);
23803 release_test_context(&test_context);
23806 static void test_unaligned_raw_buffer_access(const D3D_FEATURE_LEVEL feature_level)
23808 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
23809 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
23810 struct d3d11_test_context test_context;
23811 D3D11_SUBRESOURCE_DATA resource_data;
23812 D3D11_TEXTURE2D_DESC texture_desc;
23813 ID3D11UnorderedAccessView *uav;
23814 ID3D11ShaderResourceView *srv;
23815 D3D11_BUFFER_DESC buffer_desc;
23816 ID3D11Buffer *cb, *raw_buffer;
23817 ID3D11DeviceContext *context;
23818 struct resource_readback rb;
23819 ID3D11RenderTargetView *rtv;
23820 ID3D11Texture2D *texture;
23821 ID3D11ComputeShader *cs;
23822 ID3D11PixelShader *ps;
23823 ID3D11Device *device;
23824 unsigned int i, data;
23825 struct uvec4 offset;
23826 HRESULT hr;
23828 static const unsigned int buffer_data[] =
23830 0xffffffff, 0x00000000,
23832 static const DWORD ps_code[] =
23834 #if 0
23835 ByteAddressBuffer buffer;
23837 uint offset;
23839 uint main() : SV_Target0
23841 return buffer.Load(offset);
23843 #endif
23844 0x43425844, 0xda171175, 0xb001721f, 0x60ef80eb, 0xe1fa7e75, 0x00000001, 0x000000e4, 0x00000004,
23845 0x00000030, 0x00000040, 0x00000074, 0x000000d4, 0x4e475349, 0x00000008, 0x00000000, 0x00000008,
23846 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000001,
23847 0x00000000, 0x00000e01, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000058, 0x00000040,
23848 0x00000016, 0x0100486a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x030000a1, 0x00107000,
23849 0x00000000, 0x03000065, 0x00102012, 0x00000000, 0x080000a5, 0x00102012, 0x00000000, 0x0020800a,
23850 0x00000000, 0x00000000, 0x00107006, 0x00000000, 0x0100003e, 0x30494653, 0x00000008, 0x00000002,
23851 0x00000000,
23853 static const DWORD cs_code[] =
23855 #if 0
23856 RWByteAddressBuffer buffer;
23858 uint2 input;
23860 [numthreads(1, 1, 1)]
23861 void main()
23863 buffer.Store(input.x, input.y);
23865 #endif
23866 0x43425844, 0x3c7103b0, 0xe6313979, 0xbcfb0c11, 0x3958af0c, 0x00000001, 0x000000b4, 0x00000003,
23867 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
23868 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000060, 0x00050050, 0x00000018, 0x0100086a,
23869 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300009d, 0x0011e000, 0x00000000, 0x0400009b,
23870 0x00000001, 0x00000001, 0x00000001, 0x090000a6, 0x0011e012, 0x00000000, 0x0020800a, 0x00000000,
23871 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e,
23873 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
23875 if (!init_test_context(&test_context, &feature_level))
23876 return;
23878 device = test_context.device;
23879 context = test_context.immediate_context;
23881 if (feature_level < D3D_FEATURE_LEVEL_11_0 && !check_compute_shaders_via_sm4_support(device))
23883 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
23884 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
23885 if (SUCCEEDED(hr))
23886 ID3D11PixelShader_Release(ps);
23887 skip("Raw buffers are not supported.\n");
23888 release_test_context(&test_context);
23889 return;
23892 if (is_intel_device(device))
23894 /* Offsets for raw buffer reads and writes should be 4 bytes aligned.
23895 * This test checks what happens when offsets are not properly aligned.
23896 * The behavior seems to be undefined on Intel hardware. */
23897 win_skip("Skipping the test on Intel hardware.\n");
23898 release_test_context(&test_context);
23899 return;
23902 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
23903 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
23905 memset(&offset, 0, sizeof(offset));
23906 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(offset), &offset.x);
23908 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
23909 texture_desc.Format = DXGI_FORMAT_R32_UINT;
23910 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
23911 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
23912 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
23913 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
23915 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
23917 buffer_desc.ByteWidth = sizeof(buffer_data);
23918 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
23919 buffer_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
23920 buffer_desc.CPUAccessFlags = 0;
23921 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
23922 resource_data.pSysMem = buffer_data;
23923 resource_data.SysMemPitch = 0;
23924 resource_data.SysMemSlicePitch = 0;
23925 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &raw_buffer);
23926 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23928 srv_desc.Format = DXGI_FORMAT_R32_TYPELESS;
23929 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_BUFFEREX;
23930 U(srv_desc).BufferEx.FirstElement = 0;
23931 U(srv_desc).BufferEx.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
23932 U(srv_desc).BufferEx.Flags = D3D11_BUFFEREX_SRV_FLAG_RAW;
23933 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)raw_buffer, &srv_desc, &srv);
23934 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
23936 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
23937 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
23938 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
23940 offset.x = 0;
23941 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23942 NULL, &offset, 0, 0);
23943 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23944 draw_quad(&test_context);
23945 check_texture_color(texture, buffer_data[0], 0);
23946 offset.x = 1;
23947 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23948 NULL, &offset, 0, 0);
23949 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23950 draw_quad(&test_context);
23951 check_texture_color(texture, buffer_data[0], 0);
23952 offset.x = 2;
23953 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23954 NULL, &offset, 0, 0);
23955 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23956 draw_quad(&test_context);
23957 check_texture_color(texture, buffer_data[0], 0);
23958 offset.x = 3;
23959 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23960 NULL, &offset, 0, 0);
23961 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23962 draw_quad(&test_context);
23963 check_texture_color(texture, buffer_data[0], 0);
23965 offset.x = 4;
23966 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23967 NULL, &offset, 0, 0);
23968 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23969 draw_quad(&test_context);
23970 check_texture_color(texture, buffer_data[1], 0);
23971 offset.x = 7;
23972 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
23973 NULL, &offset, 0, 0);
23974 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
23975 draw_quad(&test_context);
23976 check_texture_color(texture, buffer_data[1], 0);
23978 if (feature_level < D3D_FEATURE_LEVEL_11_0)
23980 skip("Feature level 11_0 required for unaligned UAV test.\n");
23981 goto done;
23984 ID3D11Buffer_Release(raw_buffer);
23985 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
23986 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &raw_buffer);
23987 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
23989 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
23990 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
23991 U(uav_desc).Buffer.FirstElement = 0;
23992 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
23993 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
23994 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)raw_buffer, &uav_desc, &uav);
23995 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
23997 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
23998 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24000 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24001 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
24002 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24004 offset.x = 0;
24005 offset.y = 0xffffffff;
24006 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24007 NULL, &offset, 0, 0);
24008 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24009 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24010 get_buffer_readback(raw_buffer, &rb);
24011 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24013 data = get_readback_color(&rb, i, 0, 0);
24014 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24016 release_resource_readback(&rb);
24018 offset.x = 1;
24019 offset.y = 0xffffffff;
24020 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24021 NULL, &offset, 0, 0);
24022 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24023 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24024 get_buffer_readback(raw_buffer, &rb);
24025 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24027 data = get_readback_color(&rb, i, 0, 0);
24028 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24030 release_resource_readback(&rb);
24032 offset.x = 2;
24033 offset.y = 0xffffffff;
24034 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24035 NULL, &offset, 0, 0);
24036 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24037 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24038 get_buffer_readback(raw_buffer, &rb);
24039 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24041 data = get_readback_color(&rb, i, 0, 0);
24042 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24044 release_resource_readback(&rb);
24046 offset.x = 3;
24047 offset.y = 0xffffffff;
24048 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24049 NULL, &offset, 0, 0);
24050 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24051 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24052 get_buffer_readback(raw_buffer, &rb);
24053 for (i = 0; i < ARRAY_SIZE(buffer_data); ++i)
24055 data = get_readback_color(&rb, i, 0, 0);
24056 ok(data == buffer_data[i], "Got unexpected result %#x at %u.\n", data, i);
24058 release_resource_readback(&rb);
24060 ID3D11DeviceContext_ClearUnorderedAccessViewFloat(context, uav, black);
24061 offset.x = 3;
24062 offset.y = 0xffff;
24063 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24064 NULL, &offset, 0, 0);
24065 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24066 offset.x = 4;
24067 offset.y = 0xa;
24068 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24069 NULL, &offset, 0, 0);
24070 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24071 get_buffer_readback(raw_buffer, &rb);
24072 data = get_readback_color(&rb, 0, 0, 0);
24073 ok(data == 0xffff, "Got unexpected result %#x.\n", data);
24074 data = get_readback_color(&rb, 1, 0, 0);
24075 ok(data == 0xa, "Got unexpected result %#x.\n", data);
24076 release_resource_readback(&rb);
24078 ID3D11ComputeShader_Release(cs);
24079 ID3D11UnorderedAccessView_Release(uav);
24081 done:
24082 ID3D11Buffer_Release(cb);
24083 ID3D11Buffer_Release(raw_buffer);
24084 ID3D11PixelShader_Release(ps);
24085 ID3D11RenderTargetView_Release(rtv);
24086 ID3D11ShaderResourceView_Release(srv);
24087 ID3D11Texture2D_Release(texture);
24088 release_test_context(&test_context);
24091 static unsigned int read_uav_counter(ID3D11DeviceContext *context,
24092 ID3D11Buffer *staging_buffer, ID3D11UnorderedAccessView *uav)
24094 D3D11_MAPPED_SUBRESOURCE map_desc;
24095 unsigned int counter;
24097 ID3D11DeviceContext_CopyStructureCount(context, staging_buffer, 0, uav);
24099 if (FAILED(ID3D11DeviceContext_Map(context, (ID3D11Resource *)staging_buffer, 0,
24100 D3D11_MAP_READ, 0, &map_desc)))
24101 return 0xdeadbeef;
24102 counter = *(unsigned int *)map_desc.pData;
24103 ID3D11DeviceContext_Unmap(context, (ID3D11Resource *)staging_buffer, 0);
24104 return counter;
24107 static int compare_id(const void *a, const void *b)
24109 return *(int *)a - *(int *)b;
24112 static void test_uav_counters(void)
24114 ID3D11Buffer *buffer, *buffer2, *staging_buffer;
24115 ID3D11ComputeShader *cs_producer, *cs_consumer;
24116 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24117 struct d3d11_test_context test_context;
24118 ID3D11UnorderedAccessView *uav, *uav2;
24119 unsigned int data, id[128], i;
24120 D3D11_BUFFER_DESC buffer_desc;
24121 ID3D11DeviceContext *context;
24122 struct resource_readback rb;
24123 ID3D11Device *device;
24124 D3D11_BOX box;
24125 HRESULT hr;
24127 static const DWORD cs_producer_code[] =
24129 #if 0
24130 RWStructuredBuffer<uint> u;
24132 [numthreads(4, 1, 1)]
24133 void main(uint3 dispatch_id : SV_DispatchThreadID)
24135 uint counter = u.IncrementCounter();
24136 u[counter] = dispatch_id.x;
24138 #endif
24139 0x43425844, 0x013163a8, 0xe7d371b8, 0x4f71e39a, 0xd479e584, 0x00000001, 0x000000c8, 0x00000003,
24140 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24141 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000074, 0x00050050, 0x0000001d, 0x0100086a,
24142 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0200005f, 0x00020012, 0x02000068, 0x00000001,
24143 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
24144 0x00000000, 0x080000a8, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
24145 0x0002000a, 0x0100003e,
24147 static const DWORD cs_consumer_code[] =
24149 #if 0
24150 RWStructuredBuffer<uint> u;
24151 RWStructuredBuffer<uint> u2;
24153 [numthreads(4, 1, 1)]
24154 void main()
24156 uint counter = u.DecrementCounter();
24157 u2[counter] = u[counter];
24159 #endif
24160 0x43425844, 0x957ef3dd, 0x9f317559, 0x09c8f12d, 0xdbfd98c8, 0x00000001, 0x00000100, 0x00000003,
24161 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24162 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000ac, 0x00050050, 0x0000002b, 0x0100086a,
24163 0x0480009e, 0x0011e000, 0x00000000, 0x00000004, 0x0400009e, 0x0011e000, 0x00000001, 0x00000004,
24164 0x02000068, 0x00000001, 0x0400009b, 0x00000004, 0x00000001, 0x00000001, 0x050000b3, 0x00100012,
24165 0x00000000, 0x0011e000, 0x00000000, 0x8b0000a7, 0x80002302, 0x00199983, 0x00100022, 0x00000000,
24166 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0011e006, 0x00000000, 0x090000a8, 0x0011e012,
24167 0x00000001, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x0010001a, 0x00000000, 0x0100003e,
24169 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24171 if (!init_test_context(&test_context, &feature_level))
24172 return;
24174 device = test_context.device;
24175 context = test_context.immediate_context;
24177 hr = ID3D11Device_CreateComputeShader(device, cs_producer_code, sizeof(cs_producer_code), NULL, &cs_producer);
24178 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24179 hr = ID3D11Device_CreateComputeShader(device, cs_consumer_code, sizeof(cs_consumer_code), NULL, &cs_consumer);
24180 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24182 memset(&buffer_desc, 0, sizeof(buffer_desc));
24183 buffer_desc.ByteWidth = sizeof(unsigned int);
24184 buffer_desc.Usage = D3D11_USAGE_STAGING;
24185 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
24186 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
24187 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24189 buffer_desc.ByteWidth = 1024;
24190 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24191 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24192 buffer_desc.CPUAccessFlags = 0;
24193 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24194 buffer_desc.StructureByteStride = sizeof(unsigned int);
24195 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24196 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24197 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
24198 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24199 U(uav_desc).Buffer.FirstElement = 0;
24200 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
24201 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_COUNTER;
24202 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24203 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24204 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
24205 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24206 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, NULL, &uav2);
24207 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24209 data = read_uav_counter(context, staging_buffer, uav);
24210 ok(!data, "Got unexpected initial value %u.\n", data);
24211 data = 8;
24212 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24213 data = read_uav_counter(context, staging_buffer, uav);
24214 ok(data == 8, "Got unexpected value %u.\n", data);
24215 data = ~0u;
24216 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24217 data = read_uav_counter(context, staging_buffer, uav);
24218 ok(data == 8, "Got unexpected value %u.\n", data);
24219 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24220 data = read_uav_counter(context, staging_buffer, uav);
24221 ok(data == 8, "Got unexpected value %u.\n", data);
24223 ID3D11DeviceContext_CSSetShader(context, cs_producer, NULL, 0);
24224 data = 0;
24225 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24226 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
24227 data = read_uav_counter(context, staging_buffer, uav);
24228 ok(!data, "Got unexpected value %u.\n", data);
24230 /* produce */
24231 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
24232 data = read_uav_counter(context, staging_buffer, uav);
24233 ok(data == 64, "Got unexpected value %u.\n", data);
24234 get_buffer_readback(buffer, &rb);
24235 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
24236 release_resource_readback(&rb);
24237 qsort(id, 64, sizeof(*id), compare_id);
24238 for (i = 0; i < 64; ++i)
24240 if (id[i] != i)
24241 break;
24243 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
24245 /* consume */
24246 ID3D11DeviceContext_CSSetShader(context, cs_consumer, NULL, 0);
24247 ID3D11DeviceContext_Dispatch(context, 16, 1, 1);
24248 data = read_uav_counter(context, staging_buffer, uav);
24249 ok(!data, "Got unexpected value %u.\n", data);
24250 get_buffer_readback(buffer2, &rb);
24251 memcpy(id, rb.map_desc.pData, 64 * sizeof(*id));
24252 release_resource_readback(&rb);
24253 qsort(id, 64, sizeof(*id), compare_id);
24254 for (i = 0; i < 64; ++i)
24256 if (id[i] != i)
24257 break;
24259 ok(i == 64, "Got unexpected id %u at %u.\n", id[i], i);
24261 /* produce on CPU */
24262 for (i = 0; i < 8; ++i)
24263 id[i] = 0xdeadbeef;
24264 set_box(&box, 0, 0, 0, 8 * sizeof(*id), 1, 1);
24265 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)buffer, 0, &box, id, 0, 0);
24266 data = 8;
24267 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24268 data = read_uav_counter(context, staging_buffer, uav);
24269 ok(data == 8, "Got unexpected value %u.\n", data);
24271 /* consume */
24272 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24273 data = read_uav_counter(context, staging_buffer, uav);
24274 ok(data == 4, "Got unexpected value %u.\n", data);
24275 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24276 data = read_uav_counter(context, staging_buffer, uav);
24277 ok(!data, "Got unexpected value %u.\n", data);
24278 get_buffer_readback(buffer2, &rb);
24279 for (i = 0; i < 8; ++i)
24281 data = get_readback_color(&rb, i, 0, 0);
24282 ok(data == 0xdeadbeef, "Got data %u at %u.\n", data, i);
24284 release_resource_readback(&rb);
24286 ID3D11Buffer_Release(buffer);
24287 ID3D11Buffer_Release(buffer2);
24288 ID3D11Buffer_Release(staging_buffer);
24289 ID3D11ComputeShader_Release(cs_producer);
24290 ID3D11ComputeShader_Release(cs_consumer);
24291 ID3D11UnorderedAccessView_Release(uav);
24292 ID3D11UnorderedAccessView_Release(uav2);
24293 release_test_context(&test_context);
24296 static void test_dispatch_indirect(void)
24298 struct stats
24300 unsigned int dispatch_count;
24301 unsigned int thread_count;
24302 unsigned int max_x;
24303 unsigned int max_y;
24304 unsigned int max_z;
24307 ID3D11Buffer *append_buffer, *stats_buffer, *args_buffer, *staging_buffer;
24308 ID3D11UnorderedAccessView *uav, *stats_uav;
24309 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24310 ID3D11ComputeShader *cs_append, *cs_stats;
24311 struct d3d11_test_context test_context;
24312 D3D11_BUFFER_DESC buffer_desc;
24313 ID3D11DeviceContext *context;
24314 struct resource_readback rb;
24315 ID3D11Device *device;
24316 unsigned int data, i;
24317 struct stats *stats;
24318 HRESULT hr;
24320 static const DWORD cs_append_code[] =
24322 #if 0
24323 struct dispatch_args
24325 uint x, y, z;
24328 AppendStructuredBuffer<dispatch_args> u;
24330 [numthreads(1, 1, 1)]
24331 void main()
24333 dispatch_args args = {4, 2, 1};
24334 u.Append(args);
24335 args.y = 1;
24336 u.Append(args);
24337 args.x = 3;
24338 u.Append(args);
24340 #endif
24341 0x43425844, 0x954de75a, 0x8bb1b78b, 0x84ded464, 0x9d9532b7, 0x00000001, 0x00000158, 0x00000003,
24342 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24343 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000104, 0x00050050, 0x00000041, 0x0100086a,
24344 0x0400009e, 0x0011e000, 0x00000000, 0x0000000c, 0x02000068, 0x00000001, 0x0400009b, 0x00000001,
24345 0x00000001, 0x00000001, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000, 0x0c0000a8,
24346 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002, 0x00000004,
24347 0x00000002, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000, 0x00000000,
24348 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000, 0x00004002,
24349 0x00000004, 0x00000001, 0x00000001, 0x00000000, 0x050000b2, 0x00100012, 0x00000000, 0x0011e000,
24350 0x00000000, 0x0c0000a8, 0x0011e072, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000000,
24351 0x00004002, 0x00000003, 0x00000001, 0x00000001, 0x00000000, 0x0100003e,
24353 static const DWORD cs_stats_code[] =
24355 #if 0
24356 struct stats
24358 uint dispatch_count;
24359 uint thread_count;
24360 uint max_x;
24361 uint max_y;
24362 uint max_z;
24365 RWStructuredBuffer<stats> u;
24367 [numthreads(1, 1, 1)]
24368 void main(uint3 id : SV_DispatchThreadID)
24370 if (all(!id))
24371 InterlockedAdd(u[0].dispatch_count, 1);
24372 InterlockedAdd(u[0].thread_count, 1);
24373 InterlockedMax(u[0].max_x, id.x);
24374 InterlockedMax(u[0].max_y, id.y);
24375 InterlockedMax(u[0].max_z, id.z);
24377 #endif
24378 0x43425844, 0xbd3f2e4e, 0xb0f61ff7, 0xa8e10584, 0x2f61aec9, 0x00000001, 0x000001bc, 0x00000003,
24379 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24380 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000168, 0x00050050, 0x0000005a, 0x0100086a,
24381 0x0400009e, 0x0011e000, 0x00000000, 0x00000014, 0x0200005f, 0x00020072, 0x02000068, 0x00000001,
24382 0x0400009b, 0x00000001, 0x00000001, 0x00000001, 0x09000020, 0x00100072, 0x00000000, 0x00020246,
24383 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x07000001, 0x00100012, 0x00000000,
24384 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00100012, 0x00000000, 0x0010002a,
24385 0x00000000, 0x0010000a, 0x00000000, 0x0304001f, 0x0010000a, 0x00000000, 0x0a0000ad, 0x0011e000,
24386 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00004001, 0x00000001,
24387 0x01000015, 0x0a0000ad, 0x0011e000, 0x00000000, 0x00004002, 0x00000000, 0x00000004, 0x00000000,
24388 0x00000000, 0x00004001, 0x00000001, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002, 0x00000000,
24389 0x00000008, 0x00000000, 0x00000000, 0x0002000a, 0x090000b0, 0x0011e000, 0x00000000, 0x00004002,
24390 0x00000000, 0x0000000c, 0x00000000, 0x00000000, 0x0002001a, 0x090000b0, 0x0011e000, 0x00000000,
24391 0x00004002, 0x00000000, 0x00000010, 0x00000000, 0x00000000, 0x0002002a, 0x0100003e,
24393 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24394 static const unsigned int zero[4] = {0, 0, 0, 0};
24396 if (!init_test_context(&test_context, &feature_level))
24397 return;
24399 device = test_context.device;
24400 context = test_context.immediate_context;
24402 hr = ID3D11Device_CreateComputeShader(device, cs_append_code, sizeof(cs_append_code), NULL, &cs_append);
24403 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24404 hr = ID3D11Device_CreateComputeShader(device, cs_stats_code, sizeof(cs_stats_code), NULL, &cs_stats);
24405 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24407 memset(&buffer_desc, 0, sizeof(buffer_desc));
24408 buffer_desc.ByteWidth = sizeof(unsigned int);
24409 buffer_desc.Usage = D3D11_USAGE_STAGING;
24410 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
24411 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &staging_buffer);
24412 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24414 buffer_desc.ByteWidth = 60;
24415 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24416 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24417 buffer_desc.CPUAccessFlags = 0;
24418 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24419 buffer_desc.StructureByteStride = 3 * sizeof(unsigned int);
24420 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &append_buffer);
24421 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24422 uav_desc.Format = DXGI_FORMAT_UNKNOWN;
24423 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24424 U(uav_desc).Buffer.FirstElement = 0;
24425 U(uav_desc).Buffer.NumElements = 5;
24426 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_APPEND;
24427 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)append_buffer, &uav_desc, &uav);
24428 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24430 /* We use a separate buffer because D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS
24431 * and D3D11_RESOURCE_MISC_BUFFER_STRUCTURED are mutually exclusive flags.
24433 buffer_desc.BindFlags = 0;
24434 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_DRAWINDIRECT_ARGS;
24435 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &args_buffer);
24436 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24438 buffer_desc.ByteWidth = sizeof(*stats);
24439 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24440 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24441 buffer_desc.StructureByteStride = sizeof(*stats);
24442 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &stats_buffer);
24443 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24444 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)stats_buffer, NULL, &stats_uav);
24445 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24447 data = read_uav_counter(context, staging_buffer, uav);
24448 ok(!data, "Got unexpected initial value %u.\n", data);
24449 data = 8;
24450 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24451 data = read_uav_counter(context, staging_buffer, uav);
24452 ok(data == 8, "Got unexpected value %u.\n", data);
24454 ID3D11DeviceContext_CSSetShader(context, cs_append, NULL, 0);
24455 data = 0;
24456 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, &data);
24457 ID3D11DeviceContext_Dispatch(context, 1, 1, 1);
24458 data = read_uav_counter(context, staging_buffer, uav);
24459 ok(data == 3, "Got unexpected value %u.\n", data);
24460 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)args_buffer, (ID3D11Resource *)append_buffer);
24462 ID3D11DeviceContext_CSSetShader(context, cs_stats, NULL, 0);
24463 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, stats_uav, zero);
24464 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &stats_uav, NULL);
24465 data = read_uav_counter(context, staging_buffer, uav);
24466 for (i = 0; i < data; ++i)
24467 ID3D11DeviceContext_DispatchIndirect(context, args_buffer, i * 3 * sizeof(unsigned int));
24468 get_buffer_readback(stats_buffer, &rb);
24469 stats = rb.map_desc.pData;
24470 ok(stats->dispatch_count == 3, "Got unexpected dispatch count %u.\n", stats->dispatch_count);
24471 ok(stats->thread_count == 15, "Got unexpected thread count %u.\n", stats->thread_count);
24472 ok(stats->max_x == 3, "Got unexpected max x %u.\n", stats->max_x);
24473 ok(stats->max_y == 1, "Got unexpected max y %u.\n", stats->max_y);
24474 ok(stats->max_z == 0, "Got unexpected max z %u.\n", stats->max_z);
24475 release_resource_readback(&rb);
24477 ID3D11Buffer_Release(append_buffer);
24478 ID3D11Buffer_Release(args_buffer);
24479 ID3D11Buffer_Release(staging_buffer);
24480 ID3D11Buffer_Release(stats_buffer);
24481 ID3D11ComputeShader_Release(cs_append);
24482 ID3D11ComputeShader_Release(cs_stats);
24483 ID3D11UnorderedAccessView_Release(uav);
24484 ID3D11UnorderedAccessView_Release(stats_uav);
24485 release_test_context(&test_context);
24488 static void test_compute_shader_registers(void)
24490 struct data
24492 unsigned int group_id[3];
24493 unsigned int group_index;
24494 unsigned int dispatch_id[3];
24495 unsigned int thread_id[3];
24498 struct d3d11_test_context test_context;
24499 unsigned int i, x, y, group_x, group_y;
24500 ID3D11UnorderedAccessView *uav;
24501 D3D11_BUFFER_DESC buffer_desc;
24502 ID3D11DeviceContext *context;
24503 struct resource_readback rb;
24504 ID3D11Buffer *cb, *buffer;
24505 struct uvec4 dimensions;
24506 ID3D11ComputeShader *cs;
24507 const struct data *data;
24508 ID3D11Device *device;
24509 HRESULT hr;
24511 static const DWORD cs_code[] =
24513 #if 0
24514 struct data
24516 uint3 group_id;
24517 uint group_index;
24518 uint3 dispatch_id;
24519 uint3 group_thread_id;
24522 RWStructuredBuffer<data> u;
24524 uint2 dim;
24526 [numthreads(3, 2, 1)]
24527 void main(uint3 group_id : SV_GroupID,
24528 uint group_index : SV_GroupIndex,
24529 uint3 dispatch_id : SV_DispatchThreadID,
24530 uint3 group_thread_id : SV_GroupThreadID)
24532 uint i = dispatch_id.x + dispatch_id.y * 3 * dim.x;
24533 u[i].group_id = group_id;
24534 u[i].group_index = group_index;
24535 u[i].dispatch_id = dispatch_id;
24536 u[i].group_thread_id = group_thread_id;
24538 #endif
24539 0x43425844, 0xf0bce218, 0xfc1e8267, 0xe6d57544, 0x342df592, 0x00000001, 0x000001a4, 0x00000003,
24540 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24541 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000150, 0x00050050, 0x00000054, 0x0100086a,
24542 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0400009e, 0x0011e000, 0x00000000, 0x00000028,
24543 0x0200005f, 0x00024000, 0x0200005f, 0x00021072, 0x0200005f, 0x00022072, 0x0200005f, 0x00020072,
24544 0x02000068, 0x00000002, 0x0400009b, 0x00000003, 0x00000002, 0x00000001, 0x04000036, 0x00100072,
24545 0x00000000, 0x00021246, 0x04000036, 0x00100082, 0x00000000, 0x0002400a, 0x08000026, 0x0000d000,
24546 0x00100012, 0x00000001, 0x0002001a, 0x0020800a, 0x00000000, 0x00000000, 0x08000023, 0x00100012,
24547 0x00000001, 0x0010000a, 0x00000001, 0x00004001, 0x00000003, 0x0002000a, 0x090000a8, 0x0011e0f2,
24548 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x04000036,
24549 0x00100072, 0x00000000, 0x00020246, 0x04000036, 0x00100082, 0x00000000, 0x0002200a, 0x090000a8,
24550 0x0011e0f2, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000010, 0x00100e46, 0x00000000,
24551 0x080000a8, 0x0011e032, 0x00000000, 0x0010000a, 0x00000001, 0x00004001, 0x00000020, 0x00022596,
24552 0x0100003e,
24554 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24556 if (!init_test_context(&test_context, &feature_level))
24557 return;
24559 device = test_context.device;
24560 context = test_context.immediate_context;
24562 buffer_desc.ByteWidth = 10240;
24563 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24564 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24565 buffer_desc.CPUAccessFlags = 0;
24566 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
24567 buffer_desc.StructureByteStride = 40;
24568 assert(sizeof(struct data) == buffer_desc.StructureByteStride);
24569 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24570 ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x.\n", hr);
24571 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, NULL, &uav);
24572 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24574 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(dimensions), NULL);
24576 hr = ID3D11Device_CreateComputeShader(device, cs_code, sizeof(cs_code), NULL, &cs);
24577 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24579 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24580 ID3D11DeviceContext_CSSetConstantBuffers(context, 0, 1, &cb);
24581 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24583 dimensions.x = 2;
24584 dimensions.y = 3;
24585 dimensions.z = 1;
24586 dimensions.w = 0;
24587 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0,
24588 NULL, &dimensions, 0, 0);
24589 ID3D11DeviceContext_Dispatch(context, dimensions.x, dimensions.y, dimensions.z);
24591 get_buffer_readback(buffer, &rb);
24592 i = 0;
24593 data = rb.map_desc.pData;
24594 for (y = 0; y < dimensions.y; ++y)
24596 for (group_y = 0; group_y < 2; ++group_y)
24598 for (x = 0; x < dimensions.x; ++x)
24600 for (group_x = 0; group_x < 3; ++group_x)
24602 const unsigned int dispatch_id[2] = {x * 3 + group_x, y * 2 + group_y};
24603 const unsigned int group_index = group_y * 3 + group_x;
24604 const struct data *d = &data[i];
24606 ok(d->group_id[0] == x && d->group_id[1] == y && !d->group_id[2],
24607 "Got group id (%u, %u, %u), expected (%u, %u, %u) at %u (%u, %u, %u, %u).\n",
24608 d->group_id[0], d->group_id[1], d->group_id[2], x, y, 0,
24609 i, x, y, group_x, group_y);
24610 ok(d->group_index == group_index,
24611 "Got group index %u, expected %u at %u (%u, %u, %u, %u).\n",
24612 d->group_index, group_index, i, x, y, group_x, group_y);
24613 ok(d->dispatch_id[0] == dispatch_id[0] && d->dispatch_id[1] == dispatch_id[1]
24614 && !d->dispatch_id[2],
24615 "Got dispatch id (%u, %u, %u), expected (%u, %u, %u) "
24616 "at %u (%u, %u, %u, %u).\n",
24617 d->dispatch_id[0], d->dispatch_id[1], d->dispatch_id[2],
24618 dispatch_id[0], dispatch_id[1], 0,
24619 i, x, y, group_x, group_y);
24620 ok(d->thread_id[0] == group_x && d->thread_id[1] == group_y && !d->thread_id[2],
24621 "Got group thread id (%u, %u, %u), expected (%u, %u, %u) "
24622 "at %u (%u, %u, %u, %u).\n",
24623 d->thread_id[0], d->thread_id[1], d->thread_id[2], group_x, group_y, 0,
24624 i, x, y, group_x, group_y);
24625 ++i;
24630 release_resource_readback(&rb);
24632 ID3D11Buffer_Release(cb);
24633 ID3D11Buffer_Release(buffer);
24634 ID3D11ComputeShader_Release(cs);
24635 ID3D11UnorderedAccessView_Release(uav);
24636 release_test_context(&test_context);
24639 static void test_tgsm(void)
24641 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
24642 struct d3d11_test_context test_context;
24643 ID3D11UnorderedAccessView *uav, *uav2;
24644 struct resource_readback rb, rb2;
24645 unsigned int i, data, expected;
24646 ID3D11Buffer *buffer, *buffer2;
24647 D3D11_BUFFER_DESC buffer_desc;
24648 ID3D11DeviceContext *context;
24649 ID3D11ComputeShader *cs;
24650 ID3D11Device *device;
24651 float float_data;
24652 HRESULT hr;
24654 static const DWORD raw_tgsm_code[] =
24656 #if 0
24657 RWByteAddressBuffer u;
24658 groupshared uint m;
24660 [numthreads(32, 1, 1)]
24661 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
24663 if (!local_idx)
24664 m = group_id.x;
24665 GroupMemoryBarrierWithGroupSync();
24666 InterlockedAdd(m, group_id.x);
24667 GroupMemoryBarrierWithGroupSync();
24668 if (!local_idx)
24669 u.Store(4 * group_id.x, m);
24671 #endif
24672 0x43425844, 0x467df6d9, 0x5f56edda, 0x5c96b787, 0x60c91fb8, 0x00000001, 0x00000148, 0x00000003,
24673 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24674 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x000000f4, 0x00050050, 0x0000003d, 0x0100086a,
24675 0x0300009d, 0x0011e000, 0x00000000, 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x02000068,
24676 0x00000001, 0x0400009f, 0x0011f000, 0x00000000, 0x00000004, 0x0400009b, 0x00000020, 0x00000001,
24677 0x00000001, 0x0200001f, 0x0002400a, 0x060000a6, 0x0011f012, 0x00000000, 0x00004001, 0x00000000,
24678 0x0002100a, 0x01000015, 0x010018be, 0x060000ad, 0x0011f000, 0x00000000, 0x00004001, 0x00000000,
24679 0x0002100a, 0x010018be, 0x0200001f, 0x0002400a, 0x06000029, 0x00100012, 0x00000000, 0x0002100a,
24680 0x00004001, 0x00000002, 0x070000a5, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x0011f006,
24681 0x00000000, 0x070000a6, 0x0011e012, 0x00000000, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000,
24682 0x01000015, 0x0100003e,
24684 static const DWORD structured_tgsm_code[] =
24686 #if 0
24687 #define GROUP_SIZE 32
24689 RWByteAddressBuffer u;
24690 RWByteAddressBuffer u2;
24691 groupshared uint m[GROUP_SIZE];
24693 [numthreads(GROUP_SIZE, 1, 1)]
24694 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID)
24696 uint sum, original, i;
24698 if (!local_idx)
24700 for (i = 0; i < GROUP_SIZE; ++i)
24701 m[i] = 2 * group_id.x;
24703 GroupMemoryBarrierWithGroupSync();
24704 InterlockedAdd(m[local_idx], 1);
24705 GroupMemoryBarrierWithGroupSync();
24706 for (i = 0, sum = 0; i < GROUP_SIZE; sum += m[i++]);
24707 u.InterlockedExchange(4 * group_id.x, sum, original);
24708 u2.Store(4 * group_id.x, original);
24710 #endif
24711 0x43425844, 0x9d906c94, 0x81f5ad92, 0x11e860b2, 0x3623c824, 0x00000001, 0x000002c0, 0x00000003,
24712 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24713 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x0000026c, 0x00050050, 0x0000009b, 0x0100086a,
24714 0x0300009d, 0x0011e000, 0x00000000, 0x0300009d, 0x0011e000, 0x00000001, 0x0200005f, 0x00024000,
24715 0x0200005f, 0x00021012, 0x02000068, 0x00000002, 0x050000a0, 0x0011f000, 0x00000000, 0x00000004,
24716 0x00000020, 0x0400009b, 0x00000020, 0x00000001, 0x00000001, 0x0200001f, 0x0002400a, 0x06000029,
24717 0x00100012, 0x00000000, 0x0002100a, 0x00004001, 0x00000001, 0x05000036, 0x00100022, 0x00000000,
24718 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
24719 0x00004001, 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x090000a8, 0x0011f012, 0x00000000,
24720 0x0010001a, 0x00000000, 0x00004001, 0x00000000, 0x0010000a, 0x00000000, 0x0700001e, 0x00100022,
24721 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be,
24722 0x04000036, 0x00100012, 0x00000000, 0x0002400a, 0x05000036, 0x00100022, 0x00000000, 0x00004001,
24723 0x00000000, 0x070000ad, 0x0011f000, 0x00000000, 0x00100046, 0x00000000, 0x00004001, 0x00000001,
24724 0x010018be, 0x08000036, 0x00100032, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000,
24725 0x00000000, 0x01000030, 0x07000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x00004001,
24726 0x00000020, 0x03040003, 0x0010002a, 0x00000000, 0x0700001e, 0x00100022, 0x00000001, 0x0010001a,
24727 0x00000000, 0x00004001, 0x00000001, 0x090000a7, 0x00100042, 0x00000000, 0x0010001a, 0x00000000,
24728 0x00004001, 0x00000000, 0x0011f006, 0x00000000, 0x0700001e, 0x00100012, 0x00000001, 0x0010000a,
24729 0x00000000, 0x0010002a, 0x00000000, 0x05000036, 0x00100032, 0x00000000, 0x00100046, 0x00000001,
24730 0x01000016, 0x06000029, 0x00100022, 0x00000000, 0x0002100a, 0x00004001, 0x00000002, 0x090000b8,
24731 0x00100012, 0x00000001, 0x0011e000, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000,
24732 0x070000a6, 0x0011e012, 0x00000001, 0x0010001a, 0x00000000, 0x0010000a, 0x00000001, 0x0100003e,
24734 static const DWORD structured_tgsm_float_code[] =
24736 #if 0
24737 #define GROUP_SIZE 32
24739 struct data
24741 float f;
24742 uint u;
24745 RWBuffer<float> u;
24746 RWBuffer<uint> u2;
24747 groupshared data m[GROUP_SIZE];
24749 [numthreads(GROUP_SIZE, 1, 1)]
24750 void main(uint local_idx : SV_GroupIndex, uint group_id : SV_GroupID,
24751 uint thread_id : SV_DispatchThreadID)
24753 uint i;
24754 if (!local_idx)
24756 for (i = 0; i < GROUP_SIZE; ++i)
24758 m[i].f = group_id.x;
24759 m[i].u = group_id.x;
24762 GroupMemoryBarrierWithGroupSync();
24763 for (i = 0; i < local_idx; ++i)
24765 m[local_idx].f += group_id.x;
24766 m[local_idx].u += group_id.x;
24768 u[thread_id.x] = m[local_idx].f;
24769 u2[thread_id.x] = m[local_idx].u;
24771 #endif
24772 0x43425844, 0xaadf1a71, 0x16f60224, 0x89b6ce76, 0xb66fb96f, 0x00000001, 0x000002ac, 0x00000003,
24773 0x0000002c, 0x0000003c, 0x0000004c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
24774 0x00000008, 0x00000000, 0x00000008, 0x58454853, 0x00000258, 0x00050050, 0x00000096, 0x0100086a,
24775 0x0400089c, 0x0011e000, 0x00000000, 0x00005555, 0x0400089c, 0x0011e000, 0x00000001, 0x00004444,
24776 0x0200005f, 0x00024000, 0x0200005f, 0x00021012, 0x0200005f, 0x00020012, 0x02000068, 0x00000002,
24777 0x050000a0, 0x0011f000, 0x00000000, 0x00000008, 0x00000020, 0x0400009b, 0x00000020, 0x00000001,
24778 0x00000001, 0x0200001f, 0x0002400a, 0x04000056, 0x00100012, 0x00000000, 0x0002100a, 0x04000036,
24779 0x00100022, 0x00000000, 0x0002100a, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x00000000,
24780 0x01000030, 0x07000050, 0x00100082, 0x00000000, 0x0010002a, 0x00000000, 0x00004001, 0x00000020,
24781 0x03040003, 0x0010003a, 0x00000000, 0x090000a8, 0x0011f032, 0x00000000, 0x0010002a, 0x00000000,
24782 0x00004001, 0x00000000, 0x00100046, 0x00000000, 0x0700001e, 0x00100042, 0x00000000, 0x0010002a,
24783 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000015, 0x010018be, 0x04000056, 0x00100012,
24784 0x00000000, 0x0002100a, 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030,
24785 0x06000050, 0x00100042, 0x00000000, 0x0010001a, 0x00000000, 0x0002400a, 0x03040003, 0x0010002a,
24786 0x00000000, 0x080000a7, 0x001000c2, 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f406,
24787 0x00000000, 0x07000000, 0x00100012, 0x00000001, 0x0010000a, 0x00000000, 0x0010002a, 0x00000000,
24788 0x0600001e, 0x00100022, 0x00000001, 0x0010003a, 0x00000000, 0x0002100a, 0x080000a8, 0x0011f032,
24789 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x00100046, 0x00000001, 0x0700001e, 0x00100022,
24790 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x080000a7, 0x00100032,
24791 0x00000000, 0x0002400a, 0x00004001, 0x00000000, 0x0011f046, 0x00000000, 0x060000a4, 0x0011e0f2,
24792 0x00000000, 0x00020006, 0x00100006, 0x00000000, 0x060000a4, 0x0011e0f2, 0x00000001, 0x00020006,
24793 0x00100556, 0x00000000, 0x0100003e,
24795 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
24796 static const unsigned int zero[4] = {0};
24798 if (!init_test_context(&test_context, &feature_level))
24799 return;
24801 device = test_context.device;
24802 context = test_context.immediate_context;
24804 buffer_desc.ByteWidth = 1024;
24805 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
24806 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
24807 buffer_desc.CPUAccessFlags = 0;
24808 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
24809 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24810 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24812 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
24813 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
24814 U(uav_desc).Buffer.FirstElement = 0;
24815 U(uav_desc).Buffer.NumElements = buffer_desc.ByteWidth / sizeof(unsigned int);
24816 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
24817 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24818 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24820 hr = ID3D11Device_CreateComputeShader(device, raw_tgsm_code, sizeof(raw_tgsm_code), NULL, &cs);
24821 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24823 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24824 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24826 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
24827 ID3D11DeviceContext_Dispatch(context, 64, 1, 1);
24828 get_buffer_readback(buffer, &rb);
24829 for (i = 0; i < 64; ++i)
24831 data = get_readback_color(&rb, i, 0, 0);
24832 expected = 33 * i;
24833 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
24835 release_resource_readback(&rb);
24837 ID3D11Buffer_Release(buffer);
24838 ID3D11ComputeShader_Release(cs);
24839 ID3D11UnorderedAccessView_Release(uav);
24841 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24842 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24843 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24844 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24845 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
24846 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24847 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
24848 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24849 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_code, sizeof(structured_tgsm_code), NULL, &cs);
24850 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24852 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24853 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24854 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
24856 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
24857 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
24858 ID3D11DeviceContext_Dispatch(context, 32, 1, 1);
24859 get_buffer_readback(buffer, &rb);
24860 get_buffer_readback(buffer2, &rb2);
24861 for (i = 0; i < 32; ++i)
24863 expected = 64 * i + 32;
24864 data = get_readback_color(&rb, i, 0, 0);
24865 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
24866 data = get_readback_color(&rb2, i, 0, 0);
24867 ok(data == expected || !data, "Got %u, expected %u (index %u).\n", data, expected, i);
24869 release_resource_readback(&rb);
24870 release_resource_readback(&rb2);
24872 ID3D11Buffer_Release(buffer);
24873 ID3D11Buffer_Release(buffer2);
24874 ID3D11ComputeShader_Release(cs);
24875 ID3D11UnorderedAccessView_Release(uav);
24876 ID3D11UnorderedAccessView_Release(uav2);
24878 buffer_desc.MiscFlags = 0;
24879 U(uav_desc).Buffer.Flags = 0;
24880 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
24881 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24882 uav_desc.Format = DXGI_FORMAT_R32_FLOAT;
24883 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
24884 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24885 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer2);
24886 ok(SUCCEEDED(hr), "Failed to create buffer, hr %#x.\n", hr);
24887 uav_desc.Format = DXGI_FORMAT_R32_UINT;
24888 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer2, &uav_desc, &uav2);
24889 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
24890 hr = ID3D11Device_CreateComputeShader(device, structured_tgsm_float_code,
24891 sizeof(structured_tgsm_float_code), NULL, &cs);
24892 ok(SUCCEEDED(hr), "Failed to create compute shader, hr %#x.\n", hr);
24894 ID3D11DeviceContext_CSSetShader(context, cs, NULL, 0);
24895 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 0, 1, &uav, NULL);
24896 ID3D11DeviceContext_CSSetUnorderedAccessViews(context, 1, 1, &uav2, NULL);
24898 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
24899 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav2, zero);
24900 ID3D11DeviceContext_Dispatch(context, 3, 1, 1);
24901 get_buffer_readback(buffer, &rb);
24902 get_buffer_readback(buffer2, &rb2);
24903 for (i = 0; i < 96; ++i)
24905 expected = (i % 32 + 1) * (i / 32);
24906 float_data = get_readback_float(&rb, i, 0);
24907 ok(float_data == expected, "Got %.8e, expected %u (index %u).\n", float_data, expected, i);
24908 data = get_readback_color(&rb2, i, 0, 0);
24909 ok(data == expected, "Got %u, expected %u (index %u).\n", data, expected, i);
24911 release_resource_readback(&rb);
24912 release_resource_readback(&rb2);
24914 ID3D11Buffer_Release(buffer);
24915 ID3D11Buffer_Release(buffer2);
24916 ID3D11ComputeShader_Release(cs);
24917 ID3D11UnorderedAccessView_Release(uav);
24918 ID3D11UnorderedAccessView_Release(uav2);
24919 release_test_context(&test_context);
24922 static void test_geometry_shader(void)
24924 static const struct
24926 struct vec4 position;
24927 unsigned int color;
24929 vertex[] =
24931 {{0.0f, 0.0f, 1.0f, 1.0f}, 0xffffff00},
24933 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
24935 {"SV_POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
24936 {"COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
24938 #if 0
24939 struct vs_data
24941 float4 pos : SV_POSITION;
24942 float4 color : COLOR;
24945 void main(in struct vs_data vs_input, out struct vs_data vs_output)
24947 vs_output.pos = vs_input.pos;
24948 vs_output.color = vs_input.color;
24950 #endif
24951 static const DWORD vs_code[] =
24953 0x43425844, 0xd5b32785, 0x35332906, 0x4d05e031, 0xf66a58af, 0x00000001, 0x00000144, 0x00000003,
24954 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
24955 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
24956 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
24957 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
24958 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
24959 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000068, 0x00010040,
24960 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2, 0x00000001, 0x04000067,
24961 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x05000036, 0x001020f2,
24962 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001,
24963 0x0100003e,
24965 #if 0
24966 struct gs_data
24968 float4 pos : SV_POSITION;
24969 float4 color : COLOR;
24972 [maxvertexcount(4)]
24973 void main(point struct gs_data vin[1], inout TriangleStream<gs_data> vout)
24975 float offset = 0.2 * vin[0].pos.w;
24976 gs_data v;
24978 v.color = vin[0].color;
24980 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
24981 vout.Append(v);
24982 v.pos = float4(vin[0].pos.x - offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
24983 vout.Append(v);
24984 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y - offset, vin[0].pos.z, 1.0);
24985 vout.Append(v);
24986 v.pos = float4(vin[0].pos.x + offset, vin[0].pos.y + offset, vin[0].pos.z, 1.0);
24987 vout.Append(v);
24989 #endif
24990 static const DWORD gs_code[] =
24992 0x43425844, 0x70616045, 0x96756e1f, 0x1caeecb8, 0x3749528c, 0x00000001, 0x0000034c, 0x00000003,
24993 0x0000002c, 0x00000080, 0x000000d4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
24994 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
24995 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
24996 0x4e47534f, 0x0000004c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
24997 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
24998 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x52444853, 0x00000270, 0x00020040,
24999 0x0000009c, 0x05000061, 0x002010f2, 0x00000001, 0x00000000, 0x00000001, 0x0400005f, 0x002010f2,
25000 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d, 0x0100285c, 0x04000067, 0x001020f2,
25001 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032,
25002 0x00100032, 0x00000000, 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd,
25003 0x3e4ccccd, 0x00000000, 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032,
25004 0x00000000, 0x00100046, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
25005 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
25006 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102012, 0x00000000,
25007 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
25008 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
25009 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
25010 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
25011 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x01000013, 0x05000036,
25012 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022, 0x00000000, 0x0010001a,
25013 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
25014 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25015 0x00000000, 0x00000001, 0x01000013, 0x05000036, 0x00102032, 0x00000000, 0x00100086, 0x00000000,
25016 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082,
25017 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000,
25018 0x00000001, 0x01000013, 0x0100003e,
25020 static const DWORD gs_5_0_code[] =
25022 0x43425844, 0x57251c23, 0x4971d115, 0x8fee0b13, 0xba149ea1, 0x00000001, 0x00000384, 0x00000003,
25023 0x0000002c, 0x00000080, 0x000000dc, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25024 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x00000044, 0x00000000, 0x00000000,
25025 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25026 0x3547534f, 0x00000054, 0x00000002, 0x00000008, 0x00000000, 0x00000040, 0x00000000, 0x00000001,
25027 0x00000003, 0x00000000, 0x0000000f, 0x00000000, 0x0000004c, 0x00000000, 0x00000000, 0x00000003,
25028 0x00000001, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052, 0x58454853,
25029 0x000002a0, 0x00020050, 0x000000a8, 0x0100086a, 0x05000061, 0x002010f2, 0x00000001, 0x00000000,
25030 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x02000068, 0x00000001, 0x0100085d,
25031 0x0300008f, 0x00110000, 0x00000000, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25032 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000004, 0x0f000032, 0x00100032, 0x00000000,
25033 0x80201ff6, 0x00000041, 0x00000000, 0x00000000, 0x00004002, 0x3e4ccccd, 0x3e4ccccd, 0x00000000,
25034 0x00000000, 0x00201046, 0x00000000, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00100046,
25035 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000, 0x00000000, 0x05000036,
25036 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25037 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036, 0x00102012, 0x00000000,
25038 0x0010000a, 0x00000000, 0x0e000032, 0x00100052, 0x00000000, 0x00201ff6, 0x00000000, 0x00000000,
25039 0x00004002, 0x3e4ccccd, 0x00000000, 0x3e4ccccd, 0x00000000, 0x00201106, 0x00000000, 0x00000000,
25040 0x05000036, 0x00102022, 0x00000000, 0x0010002a, 0x00000000, 0x06000036, 0x00102042, 0x00000000,
25041 0x0020102a, 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000,
25042 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000,
25043 0x00000000, 0x05000036, 0x00102012, 0x00000000, 0x0010000a, 0x00000000, 0x05000036, 0x00102022,
25044 0x00000000, 0x0010001a, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a, 0x00000000,
25045 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036, 0x001020f2,
25046 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000, 0x05000036,
25047 0x00102032, 0x00000000, 0x00100086, 0x00000000, 0x06000036, 0x00102042, 0x00000000, 0x0020102a,
25048 0x00000000, 0x00000000, 0x05000036, 0x00102082, 0x00000000, 0x00004001, 0x3f800000, 0x06000036,
25049 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001, 0x03000075, 0x00110000, 0x00000000,
25050 0x0100003e,
25052 #if 0
25053 struct ps_data
25055 float4 pos : SV_POSITION;
25056 float4 color : COLOR;
25059 float4 main(struct ps_data ps_input) : SV_Target
25061 return ps_input.color;
25063 #endif
25064 static const DWORD ps_code[] =
25066 0x43425844, 0x89803e59, 0x3f798934, 0xf99181df, 0xf5556512, 0x00000001, 0x000000f4, 0x00000003,
25067 0x0000002c, 0x00000080, 0x000000b4, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
25068 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000,
25069 0x00000003, 0x00000001, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x4f4c4f43, 0xabab0052,
25070 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
25071 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040,
25072 0x0000000e, 0x03001062, 0x001010f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036,
25073 0x001020f2, 0x00000000, 0x00101e46, 0x00000001, 0x0100003e,
25075 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
25076 struct d3d11_test_context test_context;
25077 ID3D11InputLayout *input_layout;
25078 ID3D11DeviceContext *context;
25079 unsigned int stride, offset;
25080 struct resource_readback rb;
25081 ID3D11GeometryShader *gs;
25082 ID3D11VertexShader *vs;
25083 ID3D11PixelShader *ps;
25084 ID3D11Device *device;
25085 ID3D11Buffer *vb;
25086 DWORD color;
25087 HRESULT hr;
25089 if (!init_test_context(&test_context, NULL))
25090 return;
25092 device = test_context.device;
25093 context = test_context.immediate_context;
25095 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
25096 vs_code, sizeof(vs_code), &input_layout);
25097 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
25099 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertex), vertex);
25101 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
25102 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
25103 if (ID3D11Device_GetFeatureLevel(device) >= D3D_FEATURE_LEVEL_11_0)
25104 hr = ID3D11Device_CreateGeometryShader(device, gs_5_0_code, sizeof(gs_5_0_code), NULL, &gs);
25105 else
25106 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
25107 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
25108 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
25109 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
25111 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
25112 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
25113 stride = sizeof(*vertex);
25114 offset = 0;
25115 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
25116 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
25117 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
25118 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
25120 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
25121 ID3D11DeviceContext_Draw(context, 1, 0);
25123 get_texture_readback(test_context.backbuffer, 0, &rb);
25124 color = get_readback_color(&rb, 320, 190, 0);
25125 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25126 color = get_readback_color(&rb, 255, 240, 0);
25127 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25128 color = get_readback_color(&rb, 320, 240, 0);
25129 ok(compare_color(color, 0xffffff00, 1), "Got unexpected color 0x%08x.\n", color);
25130 color = get_readback_color(&rb, 385, 240, 0);
25131 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25132 color = get_readback_color(&rb, 320, 290, 0);
25133 ok(compare_color(color, 0xff0000ff, 1), "Got unexpected color 0x%08x.\n", color);
25134 release_resource_readback(&rb);
25136 ID3D11PixelShader_Release(ps);
25137 ID3D11GeometryShader_Release(gs);
25138 ID3D11VertexShader_Release(vs);
25139 ID3D11Buffer_Release(vb);
25140 ID3D11InputLayout_Release(input_layout);
25141 release_test_context(&test_context);
25144 struct triangle
25146 struct vec4 v[3];
25149 #define check_triangles(buffer, triangles, count) check_triangles_(__LINE__, buffer, triangles, count)
25150 static void check_triangles_(unsigned int line, ID3D11Buffer *buffer,
25151 const struct triangle *triangles, unsigned int triangle_count)
25153 const struct triangle *current, *expected;
25154 struct resource_readback rb;
25155 unsigned int i, j, offset;
25156 BOOL all_match = TRUE;
25158 get_buffer_readback(buffer, &rb);
25160 for (i = 0; i < triangle_count; ++i)
25162 current = get_readback_data(&rb, i, 0, 0, sizeof(*current));
25163 expected = &triangles[i];
25165 offset = ~0u;
25166 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
25168 if (compare_vec4(&current->v[0], &expected->v[j], 0))
25170 offset = j;
25171 break;
25175 if (offset == ~0u)
25177 all_match = FALSE;
25178 break;
25181 for (j = 0; j < ARRAY_SIZE(expected->v); ++j)
25183 if (!compare_vec4(&current->v[j], &expected->v[(j + offset) % 3], 0))
25185 all_match = FALSE;
25186 break;
25189 if (!all_match)
25190 break;
25193 ok_(__FILE__, line)(all_match, "Triangle %u vertices {%.8e, %.8e, %.8e, %.8e}, "
25194 "{%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e} "
25195 "do not match {%.8e, %.8e, %.8e, %.8e}, {%.8e, %.8e, %.8e, %.8e}, "
25196 "{%.8e, %.8e, %.8e, %.8e}.\n", i,
25197 current->v[0].x, current->v[0].y, current->v[0].z, current->v[0].w,
25198 current->v[1].x, current->v[1].y, current->v[1].z, current->v[1].w,
25199 current->v[2].x, current->v[2].y, current->v[2].z, current->v[2].w,
25200 expected->v[0].x, expected->v[0].y, expected->v[0].z, expected->v[0].w,
25201 expected->v[1].x, expected->v[1].y, expected->v[1].z, expected->v[1].w,
25202 expected->v[2].x, expected->v[2].y, expected->v[2].z, expected->v[2].w);
25204 release_resource_readback(&rb);
25207 static void test_quad_tessellation(void)
25209 #if 0
25210 struct point_data
25212 float4 position : SV_POSITION;
25215 struct patch_constant_data
25217 float edges[4] : SV_TessFactor;
25218 float inside[2] : SV_InsideTessFactor;
25221 float4 tess_factors;
25222 float2 inside_tess_factors;
25224 patch_constant_data patch_constant(InputPatch<point_data, 4> input)
25226 patch_constant_data output;
25228 output.edges[0] = tess_factors.x;
25229 output.edges[1] = tess_factors.y;
25230 output.edges[2] = tess_factors.z;
25231 output.edges[3] = tess_factors.w;
25232 output.inside[0] = inside_tess_factors.x;
25233 output.inside[1] = inside_tess_factors.y;
25235 return output;
25238 [domain("quad")]
25239 [outputcontrolpoints(4)]
25240 [outputtopology("triangle_ccw")]
25241 [partitioning("integer")]
25242 [patchconstantfunc("patch_constant")]
25243 point_data hs_main(InputPatch<point_data, 4> input,
25244 uint i : SV_OutputControlPointID)
25246 return input[i];
25249 [domain("quad")]
25250 point_data ds_main(patch_constant_data input,
25251 float2 tess_coord : SV_DomainLocation,
25252 const OutputPatch<point_data, 4> patch)
25254 point_data output;
25256 float4 a = lerp(patch[0].position, patch[1].position, tess_coord.x);
25257 float4 b = lerp(patch[2].position, patch[3].position, tess_coord.x);
25258 output.position = lerp(a, b, tess_coord.y);
25260 return output;
25262 #endif
25263 static const DWORD hs_quad_ccw_code[] =
25265 0x43425844, 0xdf8df700, 0x58b08fb1, 0xbd23d2c3, 0xcf884094, 0x00000001, 0x000002b8, 0x00000004,
25266 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25267 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25268 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
25269 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
25270 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
25271 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
25272 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
25273 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
25274 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
25275 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
25276 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
25277 0x01002097, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
25278 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
25279 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
25280 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25281 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
25282 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
25283 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25284 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
25285 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
25286 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
25288 static const DWORD ds_quad_code[] =
25290 0x43425844, 0xeb6b7631, 0x07f5469e, 0xed0cbf4a, 0x7158b3a6, 0x00000001, 0x00000284, 0x00000004,
25291 0x00000030, 0x00000064, 0x00000128, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25292 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25293 0x004e4f49, 0x47534350, 0x000000bc, 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b,
25294 0x00000003, 0x00000000, 0x00000001, 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001,
25295 0x00000001, 0x00000098, 0x00000002, 0x0000000b, 0x00000003, 0x00000002, 0x00000001, 0x00000098,
25296 0x00000003, 0x0000000b, 0x00000003, 0x00000003, 0x00000001, 0x000000a6, 0x00000000, 0x0000000c,
25297 0x00000003, 0x00000004, 0x00000001, 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005,
25298 0x00000001, 0x545f5653, 0x46737365, 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365,
25299 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000,
25300 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x58454853,
25301 0x00000120, 0x00040050, 0x00000048, 0x01002093, 0x01001895, 0x0100086a, 0x0200005f, 0x0001c032,
25302 0x0400005f, 0x002190f2, 0x00000004, 0x00000000, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25303 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000, 0x80219e46, 0x00000041, 0x00000002,
25304 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032, 0x001000f2, 0x00000000, 0x0001c006,
25305 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000, 0x0a000000, 0x001000f2, 0x00000001,
25306 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46, 0x00000001, 0x00000000, 0x09000032,
25307 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001, 0x00219e46, 0x00000000, 0x00000000,
25308 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x80100e46, 0x00000041, 0x00000001,
25309 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46, 0x00000000, 0x00100e46, 0x00000001,
25310 0x0100003e,
25312 #if 0
25314 [outputtopology("triangle_cw")]
25316 #endif
25317 static const DWORD hs_quad_cw_code[] =
25319 0x43425844, 0x1ab30cc8, 0x94174771, 0x61f4cdd0, 0xa287f62c, 0x00000001, 0x000002b8, 0x00000004,
25320 0x00000030, 0x00000064, 0x00000098, 0x0000015c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008,
25321 0x00000020, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f,
25322 0x004e4f49, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
25323 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x47534350, 0x000000bc,
25324 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
25325 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
25326 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
25327 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
25328 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
25329 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
25330 0x00000154, 0x00030050, 0x00000055, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01000896,
25331 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x01000073, 0x04000067,
25332 0x00102012, 0x00000000, 0x0000000b, 0x06000036, 0x00102012, 0x00000000, 0x0020800a, 0x00000000,
25333 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000001, 0x0000000c, 0x06000036,
25334 0x00102012, 0x00000001, 0x0020801a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25335 0x00102012, 0x00000002, 0x0000000d, 0x06000036, 0x00102012, 0x00000002, 0x0020802a, 0x00000000,
25336 0x00000000, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000003, 0x0000000e, 0x06000036,
25337 0x00102012, 0x00000003, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x04000067,
25338 0x00102012, 0x00000004, 0x0000000f, 0x06000036, 0x00102012, 0x00000004, 0x0020800a, 0x00000000,
25339 0x00000001, 0x0100003e, 0x01000073, 0x04000067, 0x00102012, 0x00000005, 0x00000010, 0x06000036,
25340 0x00102012, 0x00000005, 0x0020801a, 0x00000000, 0x00000001, 0x0100003e,
25342 #if 0
25343 struct point_data
25345 float4 pos : SV_POSITION;
25348 [maxvertexcount(3)]
25349 void main(triangle point_data vin[3], inout TriangleStream<point_data> vout)
25351 for (uint i = 0; i < 3; ++i)
25352 vout.Append(vin[i]);
25354 #endif
25355 static const DWORD gs_code[] =
25357 0x43425844, 0x8e49d18d, 0x6d08d6e5, 0xb7015628, 0xf9351fdd, 0x00000001, 0x00000164, 0x00000003,
25358 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
25359 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
25360 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000001, 0x00000003,
25361 0x00000000, 0x0000000f, 0x505f5653, 0x5449534f, 0x004e4f49, 0x52444853, 0x000000c8, 0x00020040,
25362 0x00000032, 0x05000061, 0x002010f2, 0x00000003, 0x00000000, 0x00000001, 0x02000068, 0x00000001,
25363 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x0200005e, 0x00000003,
25364 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
25365 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010001a, 0x00000000,
25366 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x01000013,
25367 0x0700001e, 0x00100012, 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016,
25368 0x0100003e,
25370 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
25372 {0, "SV_POSITION", 0, 0, 4, 0},
25374 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25375 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
25376 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
25377 static const BYTE zero_data[1024];
25378 static const struct triangle expected_quad_ccw[] =
25380 {{{-1.0f, -1.0f, 0.0f, 1.0f},
25381 { 1.0f, -1.0f, 0.0f, 1.0f},
25382 {-1.0f, 1.0f, 0.0f, 1.0f}}},
25383 {{{-1.0f, 1.0f, 0.0f, 1.0f},
25384 { 1.0f, -1.0f, 0.0f, 1.0f},
25385 { 1.0f, 1.0f, 0.0f, 1.0f}}},
25386 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
25387 { 0.0f, 0.0f, 0.0f, 0.0f},
25388 { 0.0f, 0.0f, 0.0f, 0.0f}}},
25390 static const struct triangle expected_quad_cw[] =
25392 {{{-1.0f, -1.0f, 0.0f, 1.0f},
25393 {-1.0f, 1.0f, 0.0f, 1.0f},
25394 { 1.0f, -1.0f, 0.0f, 1.0f}}},
25395 {{{-1.0f, 1.0f, 0.0f, 1.0f},
25396 { 1.0f, 1.0f, 0.0f, 1.0f},
25397 { 1.0f, -1.0f, 0.0f, 1.0f}}},
25398 {{{ 0.0f, 0.0f, 0.0f, 0.0f},
25399 { 0.0f, 0.0f, 0.0f, 0.0f},
25400 { 0.0f, 0.0f, 0.0f, 0.0f}}},
25402 struct
25404 float tess_factors[4];
25405 float inside_tess_factors[2];
25406 DWORD padding[2];
25407 } constant;
25409 D3D11_QUERY_DATA_SO_STATISTICS so_statistics;
25410 struct d3d11_test_context test_context;
25411 ID3D11DeviceContext *context;
25412 ID3D11Buffer *cb, *so_buffer;
25413 D3D11_QUERY_DESC query_desc;
25414 ID3D11Asynchronous *query;
25415 ID3D11GeometryShader *gs;
25416 ID3D11DomainShader *ds;
25417 const UINT offset = 0;
25418 ID3D11HullShader *hs;
25419 ID3D11Device *device;
25420 unsigned int i;
25421 HRESULT hr;
25423 if (!init_test_context(&test_context, &feature_level))
25424 return;
25426 device = test_context.device;
25427 context = test_context.immediate_context;
25429 draw_color_quad(&test_context, &white);
25430 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25432 set_quad_color(&test_context, &green);
25433 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
25435 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, sizeof(zero_data), zero_data);
25436 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
25437 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0, NULL, &gs);
25438 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
25439 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
25441 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
25442 constant.tess_factors[i] = 1.0f;
25443 for (i = 0; i < ARRAY_SIZE(constant.inside_tess_factors); ++i)
25444 constant.inside_tess_factors[i] = 1.0f;
25445 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
25446 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &cb);
25447 hr = ID3D11Device_CreateHullShader(device, hs_quad_ccw_code, sizeof(hs_quad_ccw_code), NULL, &hs);
25448 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
25449 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
25450 hr = ID3D11Device_CreateDomainShader(device, ds_quad_code, sizeof(ds_quad_code), NULL, &ds);
25451 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
25452 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
25454 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25455 ID3D11DeviceContext_Draw(context, 4, 0);
25456 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25457 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
25458 check_triangles(so_buffer, expected_quad_ccw, ARRAY_SIZE(expected_quad_ccw));
25460 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
25462 ID3D11HullShader_Release(hs);
25463 hr = ID3D11Device_CreateHullShader(device, hs_quad_cw_code, sizeof(hs_quad_cw_code), NULL, &hs);
25464 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
25465 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
25467 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25468 ID3D11DeviceContext_Draw(context, 4, 0);
25469 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
25470 ID3D11DeviceContext_SOSetTargets(context, 0, NULL, NULL);
25471 check_triangles(so_buffer, expected_quad_cw, ARRAY_SIZE(expected_quad_cw));
25473 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)so_buffer, 0, NULL, zero_data, 0, 0);
25475 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
25476 query_desc.Query = D3D11_QUERY_SO_STATISTICS_STREAM0;
25477 query_desc.MiscFlags = 0;
25478 hr = ID3D11Device_CreateQuery(device, &query_desc, (ID3D11Query **)&query);
25479 ok(hr == S_OK, "Failed to create query, hr %#x.\n", hr);
25480 ID3D11DeviceContext_Begin(context, query);
25482 set_quad_color(&test_context, &white);
25483 for (i = 0; i < ARRAY_SIZE(constant.tess_factors); ++i)
25484 constant.tess_factors[i] = 2.0f;
25485 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25486 ID3D11DeviceContext_Draw(context, 4, 0);
25487 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25489 set_quad_color(&test_context, &green);
25490 constant.tess_factors[0] = 0.0f; /* A patch is discarded. */
25491 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25492 ID3D11DeviceContext_Draw(context, 4, 0);
25493 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
25495 ID3D11DeviceContext_End(context, query);
25496 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
25497 ok(so_statistics.NumPrimitivesWritten == 8, "Got unexpected primitives written %u.\n",
25498 (unsigned int)so_statistics.NumPrimitivesWritten);
25499 ok(so_statistics.PrimitivesStorageNeeded == 8, "Got unexpected primitives storage needed %u.\n",
25500 (unsigned int)so_statistics.PrimitivesStorageNeeded);
25501 ID3D11DeviceContext_Begin(context, query);
25503 constant.tess_factors[0] = 5.0f;
25504 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
25505 ID3D11DeviceContext_Draw(context, 4, 0);
25506 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
25508 ID3D11DeviceContext_End(context, query);
25509 get_query_data(context, query, &so_statistics, sizeof(so_statistics));
25510 ok(so_statistics.NumPrimitivesWritten == 11, "Got unexpected primitives written %u.\n",
25511 (unsigned int)so_statistics.NumPrimitivesWritten);
25512 ok(so_statistics.PrimitivesStorageNeeded == 11, "Got unexpected primitives storage needed %u.\n",
25513 (unsigned int)so_statistics.PrimitivesStorageNeeded);
25514 ID3D11Asynchronous_Release(query);
25516 ID3D11Buffer_Release(so_buffer);
25517 ID3D11GeometryShader_Release(gs);
25518 ID3D11DomainShader_Release(ds);
25519 ID3D11HullShader_Release(hs);
25520 ID3D11Buffer_Release(cb);
25521 release_test_context(&test_context);
25524 #define check_so_desc(a, b, c, d, e, f, g, h) check_so_desc_(__LINE__, a, b, c, d, e, f, g, h)
25525 static void check_so_desc_(unsigned int line, ID3D11Device *device,
25526 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
25527 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
25528 unsigned int rasterizer_stream)
25530 ID3D11GeometryShader *gs;
25531 HRESULT hr;
25533 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
25534 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
25535 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#x.\n", hr);
25536 if (SUCCEEDED(hr))
25537 ID3D11GeometryShader_Release(gs);
25540 #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)
25541 static void check_invalid_so_desc_(unsigned int line, ID3D11Device *device,
25542 const DWORD *code, size_t code_size, const D3D11_SO_DECLARATION_ENTRY *entry,
25543 unsigned int entry_count, unsigned int *strides, unsigned int stride_count,
25544 unsigned int rasterizer_stream)
25546 ID3D11GeometryShader *gs = (ID3D11GeometryShader *)0xdeadbeef;
25547 HRESULT hr;
25549 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, code, code_size,
25550 entry, entry_count, strides, stride_count, rasterizer_stream, NULL, &gs);
25551 ok_(__FILE__, line)(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
25552 ok_(__FILE__, line)(!gs, "Got unexpected geometry shader %p.\n", gs);
25553 if (SUCCEEDED(hr))
25554 ID3D11GeometryShader_Release(gs);
25557 static void test_stream_output(void)
25559 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
25560 struct d3d11_test_context test_context;
25561 unsigned int i, count;
25562 ID3D11Device *device;
25564 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
25565 static const DWORD vs_code[] =
25567 #if 0
25568 struct data
25570 float4 position : SV_Position;
25571 float4 attrib1 : ATTRIB1;
25572 float3 attrib2 : attrib2;
25573 float2 attrib3 : ATTriB3;
25574 float attrib4 : ATTRIB4;
25577 void main(in data i, out data o)
25579 o = i;
25581 #endif
25582 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
25583 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
25584 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
25585 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
25586 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
25587 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
25588 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
25589 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
25590 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
25591 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
25592 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
25593 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
25594 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
25595 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
25596 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25597 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
25598 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
25599 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
25600 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
25601 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
25603 static const DWORD gs_code[] =
25605 #if 0
25606 struct data
25608 float4 position : SV_Position;
25609 float4 attrib1 : ATTRIB1;
25610 float3 attrib2 : attrib2;
25611 float2 attrib3 : ATTriB3;
25612 float attrib4 : ATTRIB4;
25615 [maxvertexcount(1)]
25616 void main(point data i[1], inout PointStream<data> o)
25618 o.Append(i[0]);
25620 #endif
25621 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
25622 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
25623 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
25624 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
25625 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
25626 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
25627 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
25628 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
25629 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
25630 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
25631 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
25632 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
25633 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
25634 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
25635 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
25636 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
25637 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
25638 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
25639 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
25640 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
25641 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
25643 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
25645 {0, "SV_Position", 0, 0, 4, 0},
25647 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
25649 {0, "SV_Position", 0, 0, 4, 0},
25650 {0, NULL, 0, 0, 0, 0},
25652 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
25654 /* SemanticName and SemanticIndex */
25656 {0, "sv_position", 0, 0, 4, 0},
25657 {0, "attrib", 1, 0, 4, 0},
25660 {0, "sv_position", 0, 0, 4, 0},
25661 {0, "ATTRIB", 1, 0, 4, 0},
25663 /* Gaps */
25665 {0, "SV_POSITION", 0, 0, 4, 0},
25666 {0, NULL, 0, 0, 8, 0},
25667 {0, "ATTRIB", 1, 0, 4, 0},
25670 {0, "SV_POSITION", 0, 0, 4, 0},
25671 {0, NULL, 0, 0, 4, 0},
25672 {0, NULL, 0, 0, 4, 0},
25673 {0, "ATTRIB", 1, 0, 4, 0},
25675 /* ComponentCount */
25677 {0, "ATTRIB", 1, 0, 4, 0},
25680 {0, "ATTRIB", 2, 0, 3, 0},
25683 {0, "ATTRIB", 3, 0, 2, 0},
25686 {0, "ATTRIB", 4, 0, 1, 0},
25688 /* ComponentIndex */
25690 {0, "ATTRIB", 1, 1, 3, 0},
25693 {0, "ATTRIB", 1, 2, 2, 0},
25696 {0, "ATTRIB", 1, 3, 1, 0},
25699 {0, "ATTRIB", 3, 1, 1, 0},
25701 /* OutputSlot */
25703 {0, "attrib", 1, 0, 4, 0},
25706 {0, "attrib", 1, 0, 4, 1},
25709 {0, "attrib", 1, 0, 4, 2},
25712 {0, "attrib", 1, 0, 4, 3},
25715 {0, "attrib", 1, 0, 4, 0},
25716 {0, "attrib", 2, 0, 3, 1},
25717 {0, NULL, 0, 0, 1, 1},
25718 {0, "attrib", 3, 0, 2, 2},
25719 {0, NULL, 0, 0, 2, 2},
25720 {0, "attrib", 4, 0, 1, 3},
25721 {0, NULL, 0, 0, 7, 3},
25724 {0, "attrib", 1, 0, 4, 0},
25725 {0, "attrib", 2, 0, 3, 1},
25726 {0, NULL, 0, 0, 1, 1},
25727 {0, "attrib", 3, 0, 2, 2},
25728 {0, NULL, 0, 0, 1, 2},
25729 {0, NULL, 0, 0, 1, 2},
25730 {0, "attrib", 4, 0, 1, 3},
25731 {0, NULL, 0, 0, 3, 3},
25732 {0, NULL, 0, 0, 1, 3},
25733 {0, NULL, 0, 0, 1, 3},
25734 {0, NULL, 0, 0, 1, 3},
25735 {0, NULL, 0, 0, 1, 3},
25738 {0, "attrib", 1, 0, 4, 0},
25739 {0, "attrib", 2, 0, 3, 0},
25740 {0, "attrib", 3, 0, 2, 0},
25741 {0, NULL, 0, 0, 1, 0},
25742 {0, "attrib", 4, 0, 1, 0},
25745 {0, "attrib", 1, 0, 4, 0},
25746 {0, "attrib", 2, 0, 3, 0},
25747 {0, "attrib", 3, 0, 2, 3},
25748 {0, NULL, 0, 0, 1, 3},
25749 {0, "attrib", 4, 0, 1, 3},
25751 /* Multiple occurrences of the same output */
25753 {0, "ATTRIB", 1, 0, 2, 0},
25754 {0, "ATTRIB", 1, 2, 2, 1},
25757 {0, "ATTRIB", 1, 0, 1, 0},
25758 {0, "ATTRIB", 1, 1, 3, 0},
25761 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
25763 /* SemanticName and SemanticIndex */
25765 {0, "SV_Position", 0, 0, 4, 0},
25766 {0, "ATTRIB", 0, 0, 4, 0},
25769 {0, "sv_position", 0, 0, 4, 0},
25770 {0, "ATTRIB_", 1, 0, 4, 0},
25772 /* Gaps */
25774 {0, "SV_POSITION", 0, 0, 4, 0},
25775 {0, NULL, 0, 1, 8, 0},
25776 {0, "ATTRIB", 1, 0, 4, 0},
25779 {0, "SV_POSITION", 0, 0, 4, 0},
25780 {0, NULL, 1, 0, 8, 0},
25781 {0, "ATTRIB", 1, 0, 4, 0},
25783 /* Buffer stride */
25785 {0, "SV_POSITION", 0, 0, 4, 0},
25786 {0, NULL, 0, 0, 8, 0},
25787 {0, NULL, 0, 0, 8, 0},
25788 {0, "ATTRIB", 1, 0, 4, 0},
25790 /* ComponentCount */
25792 {0, "ATTRIB", 2, 0, 5, 0},
25795 {0, "ATTRIB", 2, 0, 4, 0},
25798 {0, "ATTRIB", 3, 0, 3, 0},
25801 {0, "ATTRIB", 4, 0, 2, 0},
25803 /* ComponentIndex */
25805 {0, "ATTRIB", 1, 1, 4, 0},
25808 {0, "ATTRIB", 1, 2, 3, 0},
25811 {0, "ATTRIB", 1, 3, 2, 0},
25814 {0, "ATTRIB", 1, 4, 0, 0},
25817 {0, "ATTRIB", 1, 4, 1, 0},
25820 {0, "ATTRIB", 3, 2, 1, 0},
25823 {0, "ATTRIB", 3, 2, 0, 0},
25825 /* OutputSlot */
25827 {0, "attrib", 1, 0, 4, 4},
25830 {0, "attrib", 1, 0, 4, 4},
25833 {0, "attrib", 1, 0, 4, 4},
25836 {0, "attrib", 1, 0, 4, 4},
25839 {0, "attrib", 1, 0, 4, 0},
25840 {0, "attrib", 2, 0, 3, 1},
25841 {0, NULL, 0, 0, 1, 1},
25842 {0, "attrib", 3, 0, 2, 2},
25843 {0, NULL, 0, 0, 2, 2},
25844 {0, "attrib", 4, 0, 1, 3},
25845 {0, NULL, 0, 0, 3, 4},
25848 {0, "attrib", 1, 0, 4, 0},
25849 {0, "attrib", 2, 0, 3, 0},
25850 {0, "attrib", 3, 0, 2, 0},
25851 {0, NULL, 0, 0, 1, 0},
25852 {0, "attrib", 4, 0, 1, 0},
25853 {0, NULL, 0, 0, 3, 3},
25854 {0, NULL, 0, 0, 1, 3},
25855 {0, NULL, 0, 0, 1, 3},
25856 {0, NULL, 0, 0, 1, 3},
25857 {0, NULL, 0, 0, 1, 3},
25860 {0, "attrib", 1, 0, 4, 0},
25861 {0, NULL, 0, 0, 3, 1},
25862 {0, NULL, 0, 0, 1, 1},
25863 {0, NULL, 0, 0, 1, 2},
25864 {0, "attrib", 2, 0, 3, 3},
25865 {0, NULL, 0, 0, 1, 3},
25868 {0, "attrib", 2, 0, 3, 3},
25869 {0, NULL, 0, 0, 3, 1},
25870 {0, NULL, 0, 0, 1, 3},
25871 {0, "attrib", 1, 0, 4, 0},
25872 {0, NULL, 0, 0, 1, 2},
25873 {0, NULL, 0, 0, 1, 1},
25875 /* Stream */
25877 {1, "attrib", 1, 0, 4, 0},
25880 {4, "attrib", 1, 0, 4, 0},
25882 /* Multiple occurrences of the same output */
25884 {0, "ATTRIB", 1, 0, 4, 0},
25885 {0, "ATTRIB", 1, 0, 4, 1},
25888 {0, "ATTRIB", 1, 0, 4, 0},
25889 {0, "ATTRIB", 1, 0, 3, 0},
25893 if (!init_test_context(&test_context, &feature_level))
25894 return;
25896 device = test_context.device;
25898 for (i = 0; i < ARRAY_SIZE(stride); ++i)
25899 stride[i] = 64;
25901 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25902 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25903 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25904 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25905 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25906 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25908 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
25909 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25910 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration),
25911 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25913 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0,
25914 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25915 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
25916 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration),
25917 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25919 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0,
25920 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25921 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0,
25922 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25924 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
25926 unsigned int max_output_slot = 0;
25927 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
25929 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
25930 max_output_slot = max(max_output_slot, e->OutputSlot);
25931 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
25932 break;
25935 /* Buffer strides are required for all buffers. */
25936 if (!max_output_slot)
25938 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25939 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25940 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25941 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25942 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25943 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
25944 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25945 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
25946 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25947 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
25949 else
25951 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25952 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
25953 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count,
25954 stride, max_output_slot + 1, D3D11_SO_NO_RASTERIZED_STREAM);
25958 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
25960 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
25962 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
25963 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
25964 break;
25967 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
25968 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25969 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
25970 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
25971 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
25972 stride, 3, D3D11_SO_NO_RASTERIZED_STREAM);
25973 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
25974 stride, 4, D3D11_SO_NO_RASTERIZED_STREAM);
25977 /* Buffer strides */
25978 stride[1] = 63;
25979 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25980 &stride[1], 1, D3D11_SO_NO_RASTERIZED_STREAM);
25981 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25982 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
25983 stride[1] = 1;
25984 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25985 stride, 2, D3D11_SO_NO_RASTERIZED_STREAM);
25986 stride[0] = 0;
25987 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25988 stride, 1, D3D11_SO_NO_RASTERIZED_STREAM);
25990 /* Rasterizer stream */
25991 for (i = 0; i < D3D11_SO_STREAM_COUNT; ++i)
25992 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, i);
25993 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
25994 NULL, 0, D3D11_SO_STREAM_COUNT);
25996 release_test_context(&test_context);
25999 static void test_fl10_stream_output_desc(void)
26001 UINT stride[D3D11_SO_BUFFER_SLOT_COUNT];
26002 struct d3d11_test_context test_context;
26003 unsigned int i, count;
26004 ID3D11Device *device;
26006 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0;
26007 static const DWORD vs_code[] =
26009 #if 0
26010 struct data
26012 float4 position : SV_Position;
26013 float4 attrib1 : ATTRIB1;
26014 float3 attrib2 : attrib2;
26015 float2 attrib3 : ATTriB3;
26016 float attrib4 : ATTRIB4;
26019 void main(in data i, out data o)
26021 o = i;
26023 #endif
26024 0x43425844, 0x3f5b621f, 0x8f390786, 0x7235c8d6, 0xc1181ad3, 0x00000001, 0x00000278, 0x00000003,
26025 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
26026 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
26027 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26028 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
26029 0x00000004, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69,
26030 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
26031 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26032 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
26033 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
26034 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
26035 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
26036 0xababab00, 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x0300005f, 0x001010f2, 0x00000000,
26037 0x0300005f, 0x001010f2, 0x00000001, 0x0300005f, 0x00101072, 0x00000002, 0x0300005f, 0x00101032,
26038 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
26039 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
26040 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
26041 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036, 0x00102072,
26042 0x00000002, 0x00101246, 0x00000002, 0x05000036, 0x00102032, 0x00000003, 0x00101046, 0x00000003,
26043 0x05000036, 0x00102042, 0x00000003, 0x0010100a, 0x00000004, 0x0100003e,
26045 static const DWORD gs_code[] =
26047 #if 0
26048 struct data
26050 float4 position : SV_Position;
26051 float4 attrib1 : ATTRIB1;
26052 float3 attrib2 : attrib2;
26053 float2 attrib3 : ATTriB3;
26054 float attrib4 : ATTRIB4;
26057 [maxvertexcount(1)]
26058 void main(point data i[1], inout PointStream<data> o)
26060 o.Append(i[0]);
26062 #endif
26063 0x43425844, 0x59c61884, 0x3eef167b, 0x82618c33, 0x243cb630, 0x00000001, 0x000002a0, 0x00000003,
26064 0x0000002c, 0x000000d8, 0x00000184, 0x4e475349, 0x000000a4, 0x00000005, 0x00000008, 0x00000080,
26065 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000008c, 0x00000001, 0x00000000,
26066 0x00000003, 0x00000001, 0x00000f0f, 0x00000093, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26067 0x00000707, 0x0000009a, 0x00000003, 0x00000000, 0x00000003, 0x00000003, 0x00000303, 0x0000008c,
26068 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000404, 0x505f5653, 0x7469736f, 0x006e6f69,
26069 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254, 0xababab00, 0x4e47534f, 0x000000a4,
26070 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
26071 0x0000008c, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000093, 0x00000002,
26072 0x00000000, 0x00000003, 0x00000002, 0x00000807, 0x0000009a, 0x00000003, 0x00000000, 0x00000003,
26073 0x00000003, 0x00000c03, 0x0000008c, 0x00000004, 0x00000000, 0x00000003, 0x00000003, 0x00000b04,
26074 0x505f5653, 0x7469736f, 0x006e6f69, 0x52545441, 0x61004249, 0x69727474, 0x54410062, 0x42697254,
26075 0xababab00, 0x52444853, 0x00000114, 0x00020040, 0x00000045, 0x05000061, 0x002010f2, 0x00000001,
26076 0x00000000, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x00201072,
26077 0x00000001, 0x00000002, 0x0400005f, 0x00201032, 0x00000001, 0x00000003, 0x0400005f, 0x00201042,
26078 0x00000001, 0x00000003, 0x0100085d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000, 0x00000001,
26079 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x00102072, 0x00000002, 0x03000065, 0x00102032,
26080 0x00000003, 0x03000065, 0x00102042, 0x00000003, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2,
26081 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46,
26082 0x00000000, 0x00000001, 0x06000036, 0x00102072, 0x00000002, 0x00201246, 0x00000000, 0x00000002,
26083 0x06000036, 0x00102072, 0x00000003, 0x00201246, 0x00000000, 0x00000003, 0x01000013, 0x0100003e,
26085 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26087 {0, "SV_Position", 0, 0, 4, 0},
26089 static const D3D11_SO_DECLARATION_ENTRY invalid_gap_declaration[] =
26091 {0, "SV_Position", 0, 0, 4, 0},
26092 {0, NULL, 0, 0, 0, 0},
26094 static const D3D11_SO_DECLARATION_ENTRY valid_so_declarations[][12] =
26096 /* Gaps */
26098 {0, "SV_POSITION", 0, 0, 4, 0},
26099 {0, NULL, 0, 0, 8, 0},
26100 {0, "ATTRIB", 1, 0, 4, 0},
26103 {0, "SV_POSITION", 0, 0, 4, 0},
26104 {0, NULL, 0, 0, 4, 0},
26105 {0, NULL, 0, 0, 4, 0},
26106 {0, "ATTRIB", 1, 0, 4, 0},
26108 /* OutputSlot */
26110 {0, "attrib", 1, 0, 4, 0},
26111 {0, "attrib", 2, 0, 3, 0},
26112 {0, "attrib", 3, 0, 2, 0},
26113 {0, "attrib", 4, 0, 1, 0},
26116 {0, "attrib", 1, 0, 4, 0},
26117 {0, "attrib", 2, 0, 3, 1},
26118 {0, "attrib", 3, 0, 2, 2},
26119 {0, "attrib", 4, 0, 1, 3},
26122 {0, "attrib", 1, 0, 4, 0},
26123 {0, "attrib", 2, 0, 3, 3},
26126 {0, "attrib", 1, 0, 4, 0},
26127 {0, "attrib", 2, 0, 3, 0},
26128 {0, "attrib", 3, 0, 2, 0},
26129 {0, NULL, 0, 0, 1, 0},
26130 {0, "attrib", 4, 0, 1, 0},
26132 /* Multiple occurrences of the same output */
26134 {0, "ATTRIB", 1, 0, 2, 0},
26135 {0, "ATTRIB", 1, 2, 2, 1},
26138 {0, "ATTRIB", 1, 0, 1, 0},
26139 {0, "ATTRIB", 1, 1, 3, 0},
26142 static const D3D11_SO_DECLARATION_ENTRY invalid_so_declarations[][12] =
26144 /* OutputSlot */
26146 {0, "attrib", 1, 0, 4, 0},
26147 {0, NULL, 0, 0, 4, 0},
26148 {0, "attrib", 4, 0, 1, 3},
26151 {0, "attrib", 1, 0, 4, 0},
26152 {0, NULL, 0, 0, 4, 0},
26153 {0, NULL, 0, 0, 4, 0},
26154 {0, "attrib", 4, 0, 1, 3},
26157 {0, "attrib", 1, 0, 4, 0},
26158 {0, "attrib", 2, 0, 3, 0},
26159 {0, "attrib", 3, 0, 2, 0},
26160 {0, "attrib", 4, 0, 1, 1},
26163 {0, "attrib", 1, 0, 4, 0},
26164 {0, "attrib", 2, 0, 3, 0},
26165 {0, "attrib", 3, 0, 2, 3},
26166 {0, NULL, 0, 0, 1, 3},
26167 {0, "attrib", 4, 0, 1, 3},
26170 {0, "attrib", 1, 0, 4, 0},
26171 {0, "attrib", 1, 0, 3, 1},
26172 {0, "attrib", 1, 0, 2, 2},
26173 {0, "attrib", 1, 0, 1, 3},
26174 {0, NULL, 0, 0, 3, 3},
26178 if (!init_test_context(&test_context, &feature_level))
26179 return;
26181 device = test_context.device;
26183 for (i = 0; i < ARRAY_SIZE(stride); ++i)
26184 stride[i] = 64;
26186 check_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, NULL, 0, 0);
26187 todo_wine check_invalid_so_desc(device, gs_code, sizeof(gs_code), NULL, 0, stride, 1, 0);
26188 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26189 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
26191 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26192 check_so_desc(device, vs_code, sizeof(vs_code), so_declaration, ARRAY_SIZE(so_declaration), stride, 1, 0);
26194 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, 0, stride, 1, 0);
26195 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
26196 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), stride, 1, 0);
26197 check_invalid_so_desc(device, gs_code, sizeof(gs_code),
26198 invalid_gap_declaration, ARRAY_SIZE(invalid_gap_declaration), NULL, 0, 0);
26200 check_invalid_so_desc(device, vs_code, sizeof(vs_code), so_declaration, 0, NULL, 0, 0);
26201 check_invalid_so_desc(device, vs_code, sizeof(vs_code), NULL, 0, NULL, 0, 0);
26203 for (i = 0; i < ARRAY_SIZE(valid_so_declarations); ++i)
26205 for (count = 0; count < ARRAY_SIZE(valid_so_declarations[i]); ++count)
26207 const D3D11_SO_DECLARATION_ENTRY *e = &valid_so_declarations[i][count];
26208 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26209 break;
26212 check_so_desc(device, gs_code, sizeof(gs_code), valid_so_declarations[i], count, NULL, 0, 0);
26215 for (i = 0; i < ARRAY_SIZE(invalid_so_declarations); ++i)
26217 for (count = 0; count < ARRAY_SIZE(invalid_so_declarations[i]); ++count)
26219 const D3D11_SO_DECLARATION_ENTRY *e = &invalid_so_declarations[i][count];
26220 if (!e->Stream && !e->SemanticName && !e->SemanticIndex && !e->ComponentCount)
26221 break;
26224 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26225 stride, 1, 0);
26226 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26227 stride, 2, 0);
26228 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26229 stride, 3, 0);
26230 check_invalid_so_desc(device, gs_code, sizeof(gs_code), invalid_so_declarations[i], count,
26231 stride, 4, 0);
26234 /* Buffer strides */
26235 stride[1] = 63;
26236 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26237 &stride[1], 1, 0);
26238 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26239 stride, 2, 0);
26240 stride[0] = 0;
26241 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26242 stride, 1, 0);
26244 /* Rasterizer stream */
26245 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26246 NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM);
26247 for (i = 1; i < D3D11_SO_STREAM_COUNT; ++i)
26248 check_invalid_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration),
26249 NULL, 0, i);
26250 check_so_desc(device, gs_code, sizeof(gs_code), so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, 0);
26252 release_test_context(&test_context);
26255 static void test_stream_output_resume(void)
26257 struct d3d11_test_context test_context;
26258 ID3D11Buffer *cb, *so_buffer, *buffer;
26259 unsigned int i, j, idx, offset;
26260 ID3D11DeviceContext *context;
26261 struct resource_readback rb;
26262 ID3D11GeometryShader *gs;
26263 const struct vec4 *data;
26264 ID3D11Device *device;
26265 HRESULT hr;
26267 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26268 static const DWORD gs_code[] =
26270 #if 0
26271 float4 constant;
26273 struct vertex
26275 float4 position : SV_POSITION;
26278 struct element
26280 float4 position : SV_POSITION;
26281 float4 so_output : so_output;
26284 [maxvertexcount(3)]
26285 void main(triangle vertex input[3], inout PointStream<element> output)
26287 element o;
26288 o.so_output = constant;
26289 o.position = input[0].position;
26290 output.Append(o);
26291 o.position = input[1].position;
26292 output.Append(o);
26293 o.position = input[2].position;
26294 output.Append(o);
26296 #endif
26297 0x43425844, 0x4c16e500, 0xa0dc6126, 0x261156f3, 0xf01eedc8, 0x00000001, 0x000001b8, 0x00000003,
26298 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26299 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x5449534f, 0x004e4f49,
26300 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
26301 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
26302 0x505f5653, 0x5449534f, 0x004e4f49, 0x6f5f6f73, 0x75707475, 0xabab0074, 0x52444853, 0x000000f8,
26303 0x00020040, 0x0000003e, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2,
26304 0x00000003, 0x00000000, 0x00000001, 0x0100185d, 0x0100085c, 0x04000067, 0x001020f2, 0x00000000,
26305 0x00000001, 0x03000065, 0x001020f2, 0x00000001, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2,
26306 0x00000000, 0x00201e46, 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46,
26307 0x00000000, 0x00000000, 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001,
26308 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013,
26309 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x001020f2,
26310 0x00000001, 0x00208e46, 0x00000000, 0x00000000, 0x01000013, 0x0100003e,
26312 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26314 {0, "so_output", 0, 0, 4, 0},
26316 static const struct vec4 constants[] =
26318 {0.5f, 0.250f, 0.0f, 0.0f},
26319 {0.0f, 0.125f, 0.0f, 1.0f},
26320 {1.0f, 1.000f, 1.0f, 0.0f}
26322 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
26323 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
26324 static const struct vec4 red = {1.0f, 0.0f, 0.0f, 1.0f};
26326 if (!init_test_context(&test_context, &feature_level))
26327 return;
26329 device = test_context.device;
26330 context = test_context.immediate_context;
26332 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
26333 so_declaration, ARRAY_SIZE(so_declaration), NULL, 0, D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
26334 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
26336 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constants[0]), &constants[0]);
26337 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26339 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26340 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &cb);
26342 offset = 0;
26343 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
26345 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
26346 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26348 draw_color_quad(&test_context, &red);
26349 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26351 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26352 draw_color_quad(&test_context, &green);
26353 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26355 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[1], 0, 0);
26356 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26357 draw_color_quad(&test_context, &red);
26358 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26360 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26361 draw_color_quad(&test_context, &red);
26362 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
26364 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constants[2], 0, 0);
26365 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26366 draw_color_quad(&test_context, &white);
26367 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
26369 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26370 draw_color_quad(&test_context, &green);
26371 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
26373 buffer = NULL;
26374 ID3D11DeviceContext_SOSetTargets(context, 1, &buffer, &offset);
26375 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
26376 draw_color_quad(&test_context, &white);
26377 check_texture_color(test_context.backbuffer, 0xffffffff, 0);
26379 idx = 0;
26380 get_buffer_readback(so_buffer, &rb);
26381 for (i = 0; i < ARRAY_SIZE(constants); ++i)
26383 for (j = 0; j < 6; ++j) /* 2 triangles */
26385 data = get_readback_vec4(&rb, idx++, 0);
26386 ok(compare_vec4(data, &constants[i], 0),
26387 "Got unexpected result {%.8e, %.8e, %.8e, %.8e} at %u (%u, %u).\n",
26388 data->x, data->y, data->z, data->w, idx, i, j);
26391 release_resource_readback(&rb);
26393 ID3D11Buffer_Release(cb);
26394 ID3D11Buffer_Release(so_buffer);
26395 ID3D11GeometryShader_Release(gs);
26396 release_test_context(&test_context);
26399 static void test_stream_output_components(void)
26401 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
26402 struct d3d11_test_context test_context;
26403 ID3D11InputLayout *input_layout[2];
26404 ID3D11Buffer *vb[2], *so_buffer;
26405 ID3D11DeviceContext *context;
26406 struct resource_readback rb;
26407 unsigned int stride, offset;
26408 ID3D11GeometryShader *gs;
26409 ID3D11VertexShader *vs;
26410 ID3D11PixelShader *ps;
26411 ID3D11Device *device;
26412 const float *result;
26413 unsigned int i, j;
26414 HRESULT hr;
26416 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26417 static const DWORD vs_code[] =
26419 #if 0
26420 struct vertex
26422 float4 position : POSITION;
26423 float4 color : COLOR;
26424 float4 color2 : COLOR2;
26427 void main(in vertex i, out vertex o)
26429 o = i;
26431 #endif
26432 0x43425844, 0x95991b76, 0x4898640b, 0xe36ad9d6, 0xfbfe78b4, 0x00000001, 0x00000194, 0x00000003,
26433 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26434 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26435 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26436 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26437 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26438 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
26439 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26440 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
26441 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
26442 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
26443 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
26444 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
26446 static const DWORD gs_code[] =
26448 #if 0
26449 struct vertex
26451 float4 position : POSITION;
26452 float4 color : COLOR;
26453 float4 color2 : COLOR2;
26456 [maxvertexcount(1)]
26457 void main(point vertex input[1], inout PointStream<vertex> output)
26459 output.Append(input[0]);
26461 #endif
26462 0x43425844, 0x218f7d27, 0x555fa7f1, 0x282c545f, 0x3989c843, 0x00000001, 0x000001c0, 0x00000003,
26463 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26464 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26465 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000002, 0x00000000, 0x00000003, 0x00000002,
26466 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26467 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26468 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000002, 0x00000000,
26469 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26470 0x000000bc, 0x00020040, 0x0000002f, 0x0400005f, 0x002010f2, 0x00000001, 0x00000000, 0x0400005f,
26471 0x002010f2, 0x00000001, 0x00000001, 0x0400005f, 0x002010f2, 0x00000001, 0x00000002, 0x0100085d,
26472 0x0100085c, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x03000065,
26473 0x001020f2, 0x00000002, 0x0200005e, 0x00000001, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46,
26474 0x00000000, 0x00000000, 0x06000036, 0x001020f2, 0x00000001, 0x00201e46, 0x00000000, 0x00000001,
26475 0x06000036, 0x001020f2, 0x00000002, 0x00201e46, 0x00000000, 0x00000002, 0x01000013, 0x0100003e,
26477 static const DWORD ps_code[] =
26479 #if 0
26480 float4 main(float4 position : SV_Position,
26481 float2 texcoord : TEXCOORD) : SV_Target
26483 return float4(position.xy, texcoord);
26485 #endif
26486 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
26487 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
26488 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
26489 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
26490 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
26491 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
26492 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
26493 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
26494 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
26496 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
26498 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26499 {"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26500 {"COLOR", 2, DXGI_FORMAT_R32G32_FLOAT, 0, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
26502 static const D3D11_INPUT_ELEMENT_DESC layout_desc2[] =
26504 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26505 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26506 {"COLOR", 2, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
26508 static const D3D11_SO_DECLARATION_ENTRY so_declaration[] =
26510 {0, "POSITION", 0, 0, 4, 0},
26511 {0, "COLOR", 0, 0, 3, 0},
26512 {0, "COLOR", 2, 0, 2, 0},
26514 static const D3D11_SO_DECLARATION_ENTRY so_declaration2[] =
26516 {0, "POSITION", 0, 0, 1, 0},
26517 {0, "POSITION", 0, 1, 1, 0},
26518 {0, "POSITION", 0, 2, 1, 0},
26519 {0, "POSITION", 0, 3, 1, 0},
26520 {0, "COLOR", 0, 0, 1, 0},
26521 {0, "COLOR", 0, 1, 1, 0},
26522 {0, "COLOR", 0, 2, 1, 0},
26523 {0, "COLOR", 2, 0, 1, 0},
26524 {0, "COLOR", 2, 1, 1, 0},
26526 static const D3D11_SO_DECLARATION_ENTRY so_declaration3[] =
26528 {0, "COLOR", 0, 2, 2, 0},
26529 {0, "COLOR", 2, 3, 1, 0},
26531 static const struct
26533 struct vec4 position;
26534 struct vec3 color;
26535 struct vec2 color2;
26537 vb_data[] =
26539 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 0.0f}, {0.5f, 1.0f}},
26540 {{-1.0f, 1.0f, 0.0f, 1.0f}, {0.0f, 1.0f, 0.0f}, {0.0f, 0.0f}},
26541 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 0.0f, 1.0f}, {0.5f, 0.4f}},
26542 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 0.0f}, {0.1f, 0.6f}},
26544 static const struct
26546 struct vec4 position;
26547 struct vec4 color;
26548 struct vec4 color2;
26550 vb_data2[] =
26552 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
26553 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
26554 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
26555 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
26557 static const unsigned int vb_stride[] = {sizeof(*vb_data), sizeof(*vb_data2)};
26558 static const float expected_data[] =
26560 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.5f, 1.0f,
26561 -1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
26562 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.5f, 0.4f,
26563 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.1f, 0.6f,
26565 static const float expected_data2[] =
26567 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
26568 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
26569 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
26570 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
26572 static const float expected_data3[] =
26574 3.0f, 4.0f, 8.0f, 1.2f, 1.3f, 1.7f, 2.0f, 2.1f, 2.5f, 2.7f, 2.8f, 3.2f,
26576 static const struct
26578 BOOL with_ps;
26579 unsigned int vb_idx;
26580 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
26581 unsigned int so_entry_count;
26582 const float *expected_data;
26583 unsigned int expected_data_size;
26585 tests[] =
26587 {TRUE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
26588 {TRUE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
26589 {TRUE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
26590 {TRUE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
26591 {TRUE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
26593 {FALSE, 0, so_declaration, ARRAY_SIZE(so_declaration), expected_data, ARRAY_SIZE(expected_data)},
26594 {FALSE, 1, so_declaration, ARRAY_SIZE(so_declaration), expected_data2, ARRAY_SIZE(expected_data2)},
26595 {FALSE, 0, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data, ARRAY_SIZE(expected_data)},
26596 {FALSE, 1, so_declaration2, ARRAY_SIZE(so_declaration2), expected_data2, ARRAY_SIZE(expected_data2)},
26597 {FALSE, 1, so_declaration3, ARRAY_SIZE(so_declaration3), expected_data3, ARRAY_SIZE(expected_data3)},
26600 if (!init_test_context(&test_context, &feature_level))
26601 return;
26603 device = test_context.device;
26604 context = test_context.immediate_context;
26606 vb[0] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
26607 vb[1] = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data2), vb_data2);
26609 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
26610 vs_code, sizeof(vs_code), &input_layout[0]);
26611 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26612 hr = ID3D11Device_CreateInputLayout(device, layout_desc2, ARRAY_SIZE(layout_desc2),
26613 vs_code, sizeof(vs_code), &input_layout[1]);
26614 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26616 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
26617 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
26618 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
26619 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
26621 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
26622 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
26624 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26626 gs = NULL;
26627 current_so_declaration = NULL;
26628 for (i = 0; i < ARRAY_SIZE(tests); ++i)
26630 ID3D11DeviceContext_PSSetShader(context, tests[i].with_ps ? ps : NULL, NULL, 0);
26632 if (current_so_declaration != tests[i].so_declaration)
26634 if (gs)
26635 ID3D11GeometryShader_Release(gs);
26637 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, gs_code, sizeof(gs_code),
26638 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
26639 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
26640 ok(SUCCEEDED(hr), "Failed to create geometry shader with stream output, hr %#x.\n", hr);
26641 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26642 current_so_declaration = tests[i].so_declaration;
26645 ID3D11DeviceContext_IASetInputLayout(context, input_layout[tests[i].vb_idx]);
26646 stride = vb_stride[tests[i].vb_idx];
26647 offset = 0;
26648 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb[tests[i].vb_idx], &stride, &offset);
26650 offset = 0;
26651 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
26653 ID3D11DeviceContext_Draw(context, 4, 0);
26655 get_buffer_readback(so_buffer, &rb);
26656 result = rb.map_desc.pData;
26657 for (j = 0; j < tests[i].expected_data_size; ++j)
26659 float expected_value = tests[i].expected_data[j];
26660 ok(compare_float(result[j], expected_value, 2),
26661 "Test %u: Got %.8e, expected %.8e at %u.\n",
26662 i, result[j], expected_value, j);
26664 release_resource_readback(&rb);
26667 for (i = 0; i < ARRAY_SIZE(vb); ++i)
26668 ID3D11Buffer_Release(vb[i]);
26669 ID3D11Buffer_Release(so_buffer);
26670 ID3D11VertexShader_Release(vs);
26671 ID3D11GeometryShader_Release(gs);
26672 ID3D11PixelShader_Release(ps);
26673 for (i = 0; i < ARRAY_SIZE(input_layout); ++i)
26674 ID3D11InputLayout_Release(input_layout[i]);
26675 release_test_context(&test_context);
26678 static void test_stream_output_vs(void)
26680 const D3D11_SO_DECLARATION_ENTRY *current_so_declaration;
26681 struct d3d11_test_context test_context;
26682 ID3D11InputLayout *input_layout;
26683 ID3D11Buffer *vb, *so_buffer;
26684 ID3D11DeviceContext *context;
26685 struct resource_readback rb;
26686 ID3D11GeometryShader *gs;
26687 ID3D11VertexShader *vs;
26688 ID3D11Device *device;
26689 const float *result;
26690 unsigned int offset;
26691 unsigned int i, j;
26692 HRESULT hr;
26694 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
26695 static const DWORD vs_code[] =
26697 #if 0
26698 struct vertex
26700 float4 position : POSITION;
26701 float4 color0 : COLOR0;
26702 float4 color1 : COLOR1;
26705 vertex main(in vertex i)
26707 return i;
26709 #endif
26710 0x43425844, 0xa67e993e, 0x1632c139, 0x02a7725f, 0xfb0221cd, 0x00000001, 0x00000194, 0x00000003,
26711 0x0000002c, 0x00000094, 0x000000fc, 0x4e475349, 0x00000060, 0x00000003, 0x00000008, 0x00000050,
26712 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
26713 0x00000003, 0x00000001, 0x00000f0f, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
26714 0x00000f0f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x4e47534f, 0x00000060, 0x00000003,
26715 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x00000059,
26716 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x0000000f, 0x00000059, 0x00000001, 0x00000000,
26717 0x00000003, 0x00000002, 0x0000000f, 0x49534f50, 0x4e4f4954, 0x4c4f4300, 0xab00524f, 0x52444853,
26718 0x00000090, 0x00010040, 0x00000024, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x001010f2,
26719 0x00000001, 0x0300005f, 0x001010f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000000, 0x03000065,
26720 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x05000036, 0x001020f2, 0x00000000,
26721 0x00101e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00101e46, 0x00000001, 0x05000036,
26722 0x001020f2, 0x00000002, 0x00101e46, 0x00000002, 0x0100003e,
26724 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
26726 {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
26727 {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
26728 {"COLOR", 1, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0},
26730 static const D3D11_SO_DECLARATION_ENTRY all_so_decl[] =
26732 {0, "POSITION", 0, 0, 4, 0},
26733 {0, "COLOR", 0, 0, 3, 0},
26734 {0, "COLOR", 1, 0, 2, 0},
26736 static const D3D11_SO_DECLARATION_ENTRY position_so_decl[] =
26738 {0, "POSITION", 0, 0, 4, 0},
26740 static const D3D11_SO_DECLARATION_ENTRY position2_so_decl[] =
26742 {0, "POSITION", 0, 0, 2, 0},
26744 static const struct
26746 struct vec4 position;
26747 struct vec4 color0;
26748 struct vec4 color1;
26750 vb_data[] =
26752 {{-1.0f, -1.0f, 0.0f, 1.0f}, {1.0f, 2.0f, 3.0f, 4.0f}, {5.0f, 6.0f, 7.0f, 8.0f}},
26753 {{-1.0f, 1.0f, 0.0f, 1.0f}, {9.0f, 1.1f, 1.2f, 1.3f}, {1.4f, 1.5f, 1.6f, 1.7f}},
26754 {{ 1.0f, -1.0f, 0.0f, 1.0f}, {1.8f, 1.9f, 2.0f, 2.1f}, {2.2f, 2.3f, 2.4f, 2.5f}},
26755 {{ 1.0f, 1.0f, 0.0f, 1.0f}, {2.5f, 2.6f, 2.7f, 2.8f}, {2.9f, 3.0f, 3.1f, 3.2f}},
26757 static const unsigned int vb_stride[] = {sizeof(*vb_data)};
26758 static const float expected_data[] =
26760 -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 2.0f, 3.0f, 5.0f, 6.0f,
26761 -1.0f, 1.0f, 0.0f, 1.0f, 9.0f, 1.1f, 1.2f, 1.4f, 1.5f,
26762 1.0f, -1.0f, 0.0f, 1.0f, 1.8f, 1.9f, 2.0f, 2.2f, 2.3f,
26763 1.0f, 1.0f, 0.0f, 1.0f, 2.5f, 2.6f, 2.7f, 2.9f, 3.0f,
26765 static const float expected_data2[] =
26767 -1.0f, -1.0f, 0.0f, 1.0f,
26768 -1.0f, 1.0f, 0.0f, 1.0f,
26769 1.0f, -1.0f, 0.0f, 1.0f,
26770 1.0f, 1.0f, 0.0f, 1.0f,
26772 static const float expected_data3[] =
26774 -1.0f, -1.0f,
26775 -1.0f, 1.0f,
26776 1.0f, -1.0f,
26777 1.0f, 1.0f,
26779 static const struct
26781 const D3D11_SO_DECLARATION_ENTRY *so_declaration;
26782 unsigned int so_entry_count;
26783 const float *expected_data;
26784 unsigned int expected_data_size;
26786 tests[] =
26788 {all_so_decl, ARRAY_SIZE(all_so_decl), expected_data, ARRAY_SIZE(expected_data)},
26789 {position_so_decl, ARRAY_SIZE(position_so_decl), expected_data2, ARRAY_SIZE(expected_data2)},
26790 {position2_so_decl, ARRAY_SIZE(position2_so_decl), expected_data3, ARRAY_SIZE(expected_data3)},
26793 if (!init_test_context(&test_context, &feature_level))
26794 return;
26796 device = test_context.device;
26797 context = test_context.immediate_context;
26799 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vb_data), vb_data);
26801 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
26802 vs_code, sizeof(vs_code), &input_layout);
26803 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
26805 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
26806 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
26808 so_buffer = create_buffer(device, D3D11_BIND_STREAM_OUTPUT, 1024, NULL);
26810 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
26811 offset = 0;
26812 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, vb_stride, &offset);
26813 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
26815 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);
26817 gs = NULL;
26818 current_so_declaration = NULL;
26819 for (i = 0; i < ARRAY_SIZE(tests); ++i)
26821 if (current_so_declaration != tests[i].so_declaration)
26823 if (gs)
26824 ID3D11GeometryShader_Release(gs);
26826 hr = ID3D11Device_CreateGeometryShaderWithStreamOutput(device, vs_code, sizeof(vs_code),
26827 tests[i].so_declaration, tests[i].so_entry_count, NULL, 0,
26828 D3D11_SO_NO_RASTERIZED_STREAM, NULL, &gs);
26829 ok(hr == S_OK, "Failed to create geometry shader with stream output, hr %#x.\n", hr);
26830 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
26831 current_so_declaration = tests[i].so_declaration;
26834 offset = 0;
26835 ID3D11DeviceContext_SOSetTargets(context, 1, &so_buffer, &offset);
26837 ID3D11DeviceContext_Draw(context, 4, 0);
26839 get_buffer_readback(so_buffer, &rb);
26840 result = rb.map_desc.pData;
26841 for (j = 0; j < tests[i].expected_data_size; ++j)
26843 float expected_value = tests[i].expected_data[j];
26844 ok(compare_float(result[j], expected_value, 2),
26845 "Test %u: Got %.8e, expected %.8e at %u.\n",
26846 i, result[j], expected_value, j);
26848 release_resource_readback(&rb);
26851 ID3D11Buffer_Release(vb);
26852 ID3D11Buffer_Release(so_buffer);
26853 ID3D11VertexShader_Release(vs);
26854 ID3D11GeometryShader_Release(gs);
26855 ID3D11InputLayout_Release(input_layout);
26856 release_test_context(&test_context);
26859 static void test_gather(void)
26861 struct
26863 int width, height;
26864 int offset_x, offset_y;
26865 } constant;
26866 struct d3d11_test_context test_context;
26867 D3D11_TEXTURE2D_DESC texture_desc;
26868 ID3D11ShaderResourceView *srv;
26869 ID3D11Texture2D *texture, *rt;
26870 ID3D11DeviceContext *context;
26871 ID3D11RenderTargetView *rtv;
26872 struct resource_readback rb;
26873 ID3D11PixelShader *ps;
26874 ID3D11Device *device;
26875 unsigned int x, y;
26876 ID3D11Buffer *cb;
26877 HRESULT hr;
26879 static const DWORD gather4_code[] =
26881 #if 0
26882 SamplerState s;
26883 Texture2D<float4> t;
26885 int2 size;
26887 float4 main(float4 position : SV_Position) : SV_Target
26889 return t.Gather(s, position.xy / size);
26891 #endif
26892 0x43425844, 0xca1ee692, 0xb122f477, 0x8c467d38, 0x0f5a233a, 0x00000001, 0x00000154, 0x00000003,
26893 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26894 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26895 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26896 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000b8, 0x00000041,
26897 0x0000002e, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
26898 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
26899 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
26900 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
26901 0x00000000, 0x00100046, 0x00000000, 0x0900006d, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
26902 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
26904 static const DWORD gather4_offset_code[] =
26906 #if 0
26907 SamplerState s;
26908 Texture2D<float4> t;
26910 int2 size;
26912 float4 main(float4 position : SV_Position) : SV_Target
26914 return t.Gather(s, position.xy / size, int2(1, 1));
26916 #endif
26917 0x43425844, 0xe5ab2216, 0x90748ece, 0x7ccf2123, 0x4edbba7c, 0x00000001, 0x00000158, 0x00000003,
26918 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26919 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26920 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26921 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000bc, 0x00000041,
26922 0x0000002f, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
26923 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
26924 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
26925 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
26926 0x00000000, 0x00100046, 0x00000000, 0x8a00006d, 0x00002201, 0x001020f2, 0x00000000, 0x00100046,
26927 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0100003e,
26929 static const DWORD gather4_green_code[] =
26931 #if 0
26932 SamplerState s;
26933 Texture2D<float4> t;
26935 int2 size;
26937 float4 main(float4 position : SV_Position) : SV_Target
26939 return t.GatherGreen(s, position.xy / size);
26941 #endif
26942 0x43425844, 0x2b0ad2d9, 0x8ad30b52, 0xc418477f, 0xe5211693, 0x00000001, 0x0000015c, 0x00000003,
26943 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26944 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26945 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26946 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000c0, 0x00000050,
26947 0x00000030, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
26948 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
26949 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
26950 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
26951 0x00000000, 0x00100046, 0x00000000, 0x8b00006d, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
26952 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010601a, 0x00000000, 0x0100003e,
26954 static const DWORD gather4_po_code[] =
26956 #if 0
26957 SamplerState s;
26958 Texture2D<float4> t;
26960 int2 size;
26961 int2 offset;
26963 float4 main(float4 position : SV_Position) : SV_Target
26965 return t.Gather(s, position.xy / size, offset);
26967 #endif
26968 0x43425844, 0xe19bdd35, 0x44514fb3, 0xfaa8727f, 0xc1092da0, 0x00000001, 0x00000168, 0x00000003,
26969 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
26970 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
26971 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
26972 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
26973 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x0300005a, 0x00106000,
26974 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
26975 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
26976 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
26977 0x00000000, 0x00100046, 0x00000000, 0x8e00007f, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
26978 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
26979 0x00000000, 0x0100003e,
26981 static const struct vec4 texture_data[] =
26983 {0.0f, 0.0f}, {1.0f, 1.0f}, {2.0f, 2.0f}, {3.0f, 3.0f},
26984 {4.0f, 0.1f}, {5.0f, 1.1f}, {6.0f, 2.1f}, {7.0f, 3.1f},
26985 {8.0f, 0.2f}, {9.0f, 1.2f}, {0.5f, 2.2f}, {1.5f, 3.2f},
26986 {2.5f, 0.3f}, {3.5f, 1.3f}, {4.5f, 2.3f}, {5.5f, 3.3f},
26988 static const struct vec4 expected_gather4[] =
26990 {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},
26991 {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},
26992 {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},
26993 {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},
26995 static const struct vec4 expected_gather4_offset[] =
26997 {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},
26998 {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},
26999 {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},
27000 {3.5f, 4.5f, 4.5f, 3.5f}, {4.5f, 5.5f, 5.5f, 4.5f}, {5.5f, 5.5f, 5.5f, 5.5f}, {5.5f, 5.5f, 5.5f, 5.5f},
27002 static const struct vec4 expected_gather4_green[] =
27004 {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},
27005 {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},
27006 {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},
27007 {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},
27009 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
27010 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
27012 if (!init_test_context(&test_context, NULL))
27013 return;
27015 device = test_context.device;
27016 context = test_context.immediate_context;
27018 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_10_1)
27020 skip("Shader model 4.1 required for gather4 instruction.\n");
27021 release_test_context(&test_context);
27022 return;
27025 texture_desc.Width = 4;
27026 texture_desc.Height = 4;
27027 texture_desc.MipLevels = 1;
27028 texture_desc.ArraySize = 1;
27029 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27030 texture_desc.SampleDesc.Count = 1;
27031 texture_desc.SampleDesc.Quality = 0;
27032 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27033 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27034 texture_desc.CPUAccessFlags = 0;
27035 texture_desc.MiscFlags = 0;
27036 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27037 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27038 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27039 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27040 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27042 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
27043 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
27044 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27045 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
27046 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
27047 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
27049 constant.width = texture_desc.Width;
27050 constant.height = texture_desc.Height;
27051 constant.offset_x = 1;
27052 constant.offset_y = 1;
27053 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
27054 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
27056 hr = ID3D11Device_CreatePixelShader(device, gather4_code, sizeof(gather4_code), NULL, &ps);
27057 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27058 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27060 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27061 draw_quad(&test_context);
27062 get_texture_readback(rt, 0, &rb);
27063 for (y = 0; y < texture_desc.Height; ++y)
27065 for (x = 0; x < texture_desc.Width; ++x)
27067 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
27068 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27069 ok(compare_vec4(got, expected, 0),
27070 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27071 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27074 release_resource_readback(&rb);
27076 ID3D11PixelShader_Release(ps);
27077 hr = ID3D11Device_CreatePixelShader(device, gather4_offset_code, sizeof(gather4_offset_code), NULL, &ps);
27078 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27079 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27081 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27082 draw_quad(&test_context);
27083 get_texture_readback(rt, 0, &rb);
27084 for (y = 0; y < texture_desc.Height; ++y)
27086 for (x = 0; x < texture_desc.Width; ++x)
27088 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
27089 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27090 ok(compare_vec4(got, expected, 0),
27091 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27092 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27095 release_resource_readback(&rb);
27097 ID3D11PixelShader_Release(ps);
27099 if (ID3D11Device_GetFeatureLevel(device) < D3D_FEATURE_LEVEL_11_0)
27101 skip("Shader model 5 required for GatherGreen()/gather4_po.\n");
27102 goto done;
27105 hr = ID3D11Device_CreatePixelShader(device, gather4_green_code, sizeof(gather4_green_code), NULL, &ps);
27106 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27107 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27109 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27110 draw_quad(&test_context);
27111 get_texture_readback(rt, 0, &rb);
27112 for (y = 0; y < texture_desc.Height; ++y)
27114 for (x = 0; x < texture_desc.Width; ++x)
27116 const struct vec4 *expected = &expected_gather4_green[y * texture_desc.Width + x];
27117 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27118 ok(compare_vec4(got, expected, 0),
27119 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27120 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27123 release_resource_readback(&rb);
27125 ID3D11PixelShader_Release(ps);
27126 hr = ID3D11Device_CreatePixelShader(device, gather4_po_code, sizeof(gather4_po_code), NULL, &ps);
27127 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27128 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27130 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27131 draw_quad(&test_context);
27132 get_texture_readback(rt, 0, &rb);
27133 for (y = 0; y < texture_desc.Height; ++y)
27135 for (x = 0; x < texture_desc.Width; ++x)
27137 const struct vec4 *expected = &expected_gather4_offset[y * texture_desc.Width + x];
27138 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27139 ok(compare_vec4(got, expected, 0),
27140 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27141 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27144 release_resource_readback(&rb);
27146 constant.offset_x = 0;
27147 constant.offset_y = 0;
27148 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
27149 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27150 draw_quad(&test_context);
27151 get_texture_readback(rt, 0, &rb);
27152 for (y = 0; y < texture_desc.Height; ++y)
27154 for (x = 0; x < texture_desc.Width; ++x)
27156 const struct vec4 *expected = &expected_gather4[y * texture_desc.Width + x];
27157 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27158 ok(compare_vec4(got, expected, 0),
27159 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27160 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27163 release_resource_readback(&rb);
27165 ID3D11PixelShader_Release(ps);
27167 done:
27168 ID3D11Buffer_Release(cb);
27169 ID3D11Texture2D_Release(rt);
27170 ID3D11Texture2D_Release(texture);
27171 ID3D11RenderTargetView_Release(rtv);
27172 ID3D11ShaderResourceView_Release(srv);
27173 release_test_context(&test_context);
27176 static void test_gather_c(void)
27178 struct
27180 int width, height;
27181 int offset_x, offset_y;
27182 float compare_value;
27183 int padding[3];
27184 } constant;
27185 struct d3d11_test_context test_context;
27186 D3D11_TEXTURE2D_DESC texture_desc;
27187 D3D11_SAMPLER_DESC sampler_desc;
27188 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
27189 ID3D11ShaderResourceView *srv;
27190 ID3D11Texture2D *texture, *rt;
27191 ID3D11DeviceContext *context;
27192 ID3D11SamplerState *sampler;
27193 ID3D11RenderTargetView *rtv;
27194 struct resource_readback rb;
27195 ID3D11PixelShader *ps;
27196 ID3D11Device *device;
27197 unsigned int x, y;
27198 ID3D11Buffer *cb;
27199 HRESULT hr;
27201 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27202 static const DWORD gather4_c_code[] =
27204 #if 0
27205 SamplerComparisonState s;
27206 Texture2D<float4> t;
27208 int2 size;
27209 int2 offset;
27210 float compare;
27212 float4 main(float4 position : SV_Position) : SV_Target
27214 return t.GatherCmp(s, position.xy / size, compare);
27216 #endif
27217 0x43425844, 0xd3d04479, 0x901e9208, 0x7074fd0c, 0xbcadb2da, 0x00000001, 0x00000168, 0x00000003,
27218 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27219 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27220 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27221 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000cc, 0x00000050,
27222 0x00000033, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
27223 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27224 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27225 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27226 0x00000000, 0x00100046, 0x00000000, 0x8e00007e, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27227 0x00100046, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a, 0x00000000, 0x0020800a, 0x00000000,
27228 0x00000001, 0x0100003e,
27230 static const DWORD gather4_po_c_code[] =
27232 #if 0
27233 SamplerComparisonState s;
27234 Texture2D<float4> t;
27236 int2 size;
27237 int2 offset;
27238 float compare;
27240 float4 main(float4 position : SV_Position) : SV_Target
27242 return t.GatherCmp(s, position.xy / size, compare, offset);
27244 #endif
27245 0x43425844, 0x501de13e, 0x472d2d20, 0x6df0fee4, 0xef27d9e6, 0x00000001, 0x00000174, 0x00000003,
27246 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
27247 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
27248 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
27249 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d8, 0x00000050,
27250 0x00000036, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000002, 0x0300085a, 0x00106000,
27251 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000,
27252 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0600002b, 0x00100032,
27253 0x00000000, 0x00208046, 0x00000000, 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046,
27254 0x00000000, 0x00100046, 0x00000000, 0x91000080, 0x800000c2, 0x00155543, 0x001020f2, 0x00000000,
27255 0x00100046, 0x00000000, 0x00208ae6, 0x00000000, 0x00000000, 0x00107e46, 0x00000000, 0x0010600a,
27256 0x00000000, 0x0020800a, 0x00000000, 0x00000001, 0x0100003e,
27258 static const float texture_data[] =
27260 0.00f, 0.10f, 0.20f, 0.30f,
27261 0.40f, 0.50f, 0.60f, 0.70f,
27262 0.80f, 0.90f, 0.05f, 0.15f,
27263 0.25f, 0.35f, 0.45f, 0.55f,
27265 static const struct vec4 expected_gather4_c[] =
27267 {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},
27268 {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},
27269 {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},
27270 {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},
27272 static const struct vec4 expected_gather4_po_c[] =
27274 {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},
27275 {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},
27276 {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},
27277 {0.0f, 0.0f, 0.0f, 0.0f}, {0.0f, 1.0f, 1.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f},
27279 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
27280 static const D3D11_SUBRESOURCE_DATA resource_data = {&texture_data, sizeof(texture_data) / 4};
27282 if (!init_test_context(&test_context, &feature_level))
27283 return;
27285 device = test_context.device;
27286 context = test_context.immediate_context;
27288 sampler_desc.Filter = D3D11_FILTER_COMPARISON_MIN_MAG_MIP_POINT;
27289 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
27290 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
27291 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
27292 sampler_desc.MipLODBias = 0.0f;
27293 sampler_desc.MaxAnisotropy = 0;
27294 sampler_desc.ComparisonFunc = D3D11_COMPARISON_LESS_EQUAL;
27295 sampler_desc.BorderColor[0] = 0.0f;
27296 sampler_desc.BorderColor[1] = 0.0f;
27297 sampler_desc.BorderColor[2] = 0.0f;
27298 sampler_desc.BorderColor[3] = 0.0f;
27299 sampler_desc.MinLOD = 0.0f;
27300 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
27302 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
27303 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
27304 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
27306 texture_desc.Width = 4;
27307 texture_desc.Height = 4;
27308 texture_desc.MipLevels = 1;
27309 texture_desc.ArraySize = 1;
27310 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27311 texture_desc.SampleDesc.Count = 1;
27312 texture_desc.SampleDesc.Quality = 0;
27313 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27314 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27315 texture_desc.CPUAccessFlags = 0;
27316 texture_desc.MiscFlags = 0;
27317 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27318 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27319 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27320 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27321 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27323 constant.width = texture_desc.Width;
27324 constant.height = texture_desc.Height;
27325 constant.offset_x = 1;
27326 constant.offset_y = 1;
27327 constant.compare_value = 0.5f;
27328 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
27329 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
27331 texture_desc.Format = DXGI_FORMAT_R32_TYPELESS;
27332 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
27333 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &texture);
27334 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27336 srv_desc.Format = DXGI_FORMAT_R32_FLOAT;
27337 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
27338 U(srv_desc).Texture2D.MostDetailedMip = 0;
27339 U(srv_desc).Texture2D.MipLevels = 1;
27340 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
27341 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
27342 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
27344 hr = ID3D11Device_CreatePixelShader(device, gather4_c_code, sizeof(gather4_c_code), NULL, &ps);
27345 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27346 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27348 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27349 draw_quad(&test_context);
27350 get_texture_readback(rt, 0, &rb);
27351 for (y = 0; y < texture_desc.Height; ++y)
27353 for (x = 0; x < texture_desc.Width; ++x)
27355 const struct vec4 *expected = &expected_gather4_c[y * texture_desc.Width + x];
27356 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27357 ok(compare_vec4(got, expected, 0),
27358 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27359 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27362 release_resource_readback(&rb);
27363 ID3D11PixelShader_Release(ps);
27365 hr = ID3D11Device_CreatePixelShader(device, gather4_po_c_code, sizeof(gather4_po_c_code), NULL, &ps);
27366 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27367 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27369 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, &white.x);
27370 draw_quad(&test_context);
27371 get_texture_readback(rt, 0, &rb);
27372 for (y = 0; y < texture_desc.Height; ++y)
27374 for (x = 0; x < texture_desc.Width; ++x)
27376 const struct vec4 *expected = &expected_gather4_po_c[y * texture_desc.Width + x];
27377 const struct vec4 *got = get_readback_vec4(&rb, x, y);
27378 ok(compare_vec4(got, expected, 0),
27379 "Got {%.8e, %.8e, %.8e, %.8e}, expected {%.8e, %.8e, %.8e, %.8e}.\n",
27380 got->x, got->y, got->z, got->w, expected->x, expected->y, expected->z, expected->w);
27383 release_resource_readback(&rb);
27384 ID3D11PixelShader_Release(ps);
27386 ID3D11ShaderResourceView_Release(srv);
27387 ID3D11Texture2D_Release(texture);
27389 ID3D11Buffer_Release(cb);
27390 ID3D11Texture2D_Release(rt);
27391 ID3D11RenderTargetView_Release(rtv);
27392 ID3D11SamplerState_Release(sampler);
27393 release_test_context(&test_context);
27396 static float clamp_depth_bias(float bias, float clamp)
27398 if (clamp > 0.0f)
27399 return min(bias, clamp);
27400 if (clamp < 0.0f)
27401 return max(bias, clamp);
27402 return bias;
27405 static void test_depth_bias(void)
27407 struct vec3 vertices[] =
27409 {-1.0f, -1.0f, 0.5f},
27410 {-1.0f, 1.0f, 0.5f},
27411 { 1.0f, -1.0f, 0.5f},
27412 { 1.0f, 1.0f, 0.5f},
27414 struct d3d11_test_context test_context;
27415 D3D11_RASTERIZER_DESC rasterizer_desc;
27416 struct swapchain_desc swapchain_desc;
27417 D3D11_TEXTURE2D_DESC texture_desc;
27418 ID3D11DeviceContext *context;
27419 double m, bias, depth, data;
27420 struct resource_readback rb;
27421 ID3D11DepthStencilView *dsv;
27422 unsigned int expected_value;
27423 ID3D11RasterizerState *rs;
27424 ID3D11Texture2D *texture;
27425 unsigned int format_idx;
27426 unsigned int y, i, j, k;
27427 unsigned int shift = 0;
27428 ID3D11Device *device;
27429 float *depth_values;
27430 DXGI_FORMAT format;
27431 const UINT32 *u32;
27432 const UINT16 *u16;
27433 UINT32 u32_value;
27434 HRESULT hr;
27436 static const struct
27438 float z;
27439 float exponent;
27441 quads[] =
27443 {0.125f, -3.0f},
27444 {0.250f, -2.0f},
27445 {0.500f, -1.0f},
27446 {1.000f, 0.0f},
27448 static const int bias_tests[] =
27450 -10000, -1000, -100, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1,
27451 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50, 100, 200, 500, 1000, 10000,
27453 static const float bias_clamp_tests[] =
27455 0.0f, -1e-5f, 1e-5f,
27457 static const float quad_slopes[] =
27459 0.0f, 0.5f, 1.0f
27461 static const float slope_scaled_bias_tests[] =
27463 0.0f, 0.5f, 1.0f, 2.0f, 128.0f, 1000.0f, 10000.0f,
27465 static const DXGI_FORMAT formats[] =
27467 DXGI_FORMAT_D32_FLOAT,
27468 DXGI_FORMAT_D24_UNORM_S8_UINT,
27469 DXGI_FORMAT_D16_UNORM,
27472 swapchain_desc.windowed = TRUE;
27473 swapchain_desc.buffer_count = 1;
27474 swapchain_desc.width = 200;
27475 swapchain_desc.height = 200;
27476 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
27477 swapchain_desc.flags = 0;
27478 if (!init_test_context_ext(&test_context, NULL, &swapchain_desc))
27479 return;
27481 device = test_context.device;
27482 context = test_context.immediate_context;
27484 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
27485 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
27486 rasterizer_desc.CullMode = D3D11_CULL_NONE;
27487 rasterizer_desc.FrontCounterClockwise = FALSE;
27488 rasterizer_desc.DepthBias = 0;
27489 rasterizer_desc.DepthBiasClamp = 0.0f;
27490 rasterizer_desc.SlopeScaledDepthBias = 0.0f;
27491 rasterizer_desc.DepthClipEnable = TRUE;
27493 depth_values = heap_calloc(swapchain_desc.height, sizeof(*depth_values));
27494 ok(!!depth_values, "Failed to allocate memory.\n");
27496 for (format_idx = 0; format_idx < ARRAY_SIZE(formats); ++format_idx)
27498 format = formats[format_idx];
27500 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
27501 texture_desc.Format = format;
27502 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
27503 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
27504 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27505 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
27506 ok(SUCCEEDED(hr), "Failed to create render depth stencil view, hr %#x.\n", hr);
27507 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
27508 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
27509 draw_quad_z(&test_context, 1.0f);
27510 switch (format)
27512 case DXGI_FORMAT_D32_FLOAT:
27513 check_texture_float(texture, 1.0f, 0);
27514 break;
27515 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27516 /* FIXME: Depth/stencil byte order is reversed in wined3d. */
27517 shift = get_texture_color(texture, 0, 0) == 0xffffff ? 0 : 8;
27518 todo_wine
27519 check_texture_color(texture, 0xffffff, 1);
27520 break;
27521 case DXGI_FORMAT_D16_UNORM:
27522 get_texture_readback(texture, 0, &rb);
27523 check_readback_data_u16(&rb, NULL, 0xffffu, 0);
27524 release_resource_readback(&rb);
27525 break;
27526 default:
27527 trace("Unhandled format %#x.\n", format);
27528 break;
27530 draw_quad(&test_context);
27532 /* DepthBias */
27533 for (i = 0; i < ARRAY_SIZE(quads); ++i)
27535 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
27536 vertices[j].z = quads[i].z;
27537 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
27538 0, NULL, vertices, 0, 0);
27540 for (j = 0; j < ARRAY_SIZE(bias_tests); ++j)
27542 rasterizer_desc.DepthBias = bias_tests[j];
27544 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
27546 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
27547 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
27548 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
27549 ID3D11DeviceContext_RSSetState(context, rs);
27550 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27551 draw_quad(&test_context);
27552 switch (format)
27554 case DXGI_FORMAT_D32_FLOAT:
27555 bias = rasterizer_desc.DepthBias * pow(2.0f, quads[i].exponent - 23.0f);
27556 bias = clamp_depth_bias(bias, rasterizer_desc.DepthBiasClamp);
27557 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27559 check_texture_float(texture, depth, 2);
27560 break;
27561 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27562 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 16777215.0f,
27563 rasterizer_desc.DepthBiasClamp);
27564 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27566 get_texture_readback(texture, 0, &rb);
27567 check_readback_data_u24(&rb, NULL, shift, depth * 16777215.0f + 0.5f, 1);
27568 release_resource_readback(&rb);
27569 break;
27570 case DXGI_FORMAT_D16_UNORM:
27571 bias = clamp_depth_bias(rasterizer_desc.DepthBias / 65535.0f,
27572 rasterizer_desc.DepthBiasClamp);
27573 depth = min(max(0.0f, quads[i].z + bias), 1.0f);
27575 get_texture_readback(texture, 0, &rb);
27576 check_readback_data_u16(&rb, NULL, depth * 65535.0f + 0.5f, 1);
27577 release_resource_readback(&rb);
27578 break;
27579 default:
27580 break;
27582 ID3D11RasterizerState_Release(rs);
27587 /* SlopeScaledDepthBias */
27588 rasterizer_desc.DepthBias = 0;
27589 for (i = 0; i < ARRAY_SIZE(quad_slopes); ++i)
27591 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
27592 vertices[j].z = j == 1 || j == 3 ? 0.0f : quad_slopes[i];
27593 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)test_context.vb,
27594 0, NULL, vertices, 0, 0);
27596 ID3D11DeviceContext_RSSetState(context, NULL);
27597 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27598 draw_quad(&test_context);
27599 get_texture_readback(texture, 0, &rb);
27600 for (y = 0; y < texture_desc.Height; ++y)
27602 switch (format)
27604 case DXGI_FORMAT_D32_FLOAT:
27605 depth_values[y] = get_readback_float(&rb, 0, y);
27606 break;
27607 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27608 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
27609 u32_value = *u32 >> shift;
27610 depth_values[y] = u32_value / 16777215.0f;
27611 break;
27612 case DXGI_FORMAT_D16_UNORM:
27613 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
27614 depth_values[y] = *u16 / 65535.0f;
27615 break;
27616 default:
27617 break;
27620 release_resource_readback(&rb);
27622 for (j = 0; j < ARRAY_SIZE(slope_scaled_bias_tests); ++j)
27624 rasterizer_desc.SlopeScaledDepthBias = slope_scaled_bias_tests[j];
27626 for (k = 0; k < ARRAY_SIZE(bias_clamp_tests); ++k)
27628 BOOL all_match = TRUE;
27629 rasterizer_desc.DepthBiasClamp = bias_clamp_tests[k];
27630 ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rs);
27631 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
27632 ID3D11DeviceContext_RSSetState(context, rs);
27633 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
27634 draw_quad(&test_context);
27636 m = quad_slopes[i] / texture_desc.Height;
27637 bias = clamp_depth_bias(rasterizer_desc.SlopeScaledDepthBias * m, rasterizer_desc.DepthBiasClamp);
27638 get_texture_readback(texture, 0, &rb);
27639 for (y = 0; y < texture_desc.Height && all_match; ++y)
27641 depth = min(max(0.0f, depth_values[y] + bias), 1.0f);
27642 switch (format)
27644 case DXGI_FORMAT_D32_FLOAT:
27645 data = get_readback_float(&rb, 0, y);
27646 all_match = compare_float(data, depth, 64);
27647 ok(all_match,
27648 "Got depth %.8e, expected %.8e.\n", data, depth);
27649 break;
27650 case DXGI_FORMAT_D24_UNORM_S8_UINT:
27651 u32 = get_readback_data(&rb, 0, y, 0, sizeof(*u32));
27652 u32_value = *u32 >> shift;
27653 expected_value = depth * 16777215.0f + 0.5f;
27654 all_match = compare_uint(u32_value, expected_value, 3);
27655 ok(all_match,
27656 "Got value %#x (%.8e), expected %#x (%.8e).\n",
27657 u32_value, u32_value / 16777215.0f,
27658 expected_value, expected_value / 16777215.0f);
27659 break;
27660 case DXGI_FORMAT_D16_UNORM:
27661 u16 = get_readback_data(&rb, 0, y, 0, sizeof(*u16));
27662 expected_value = depth * 65535.0f + 0.5f;
27663 all_match = compare_uint(*u16, expected_value, 1);
27664 ok(all_match,
27665 "Got value %#x (%.8e), expected %#x (%.8e).\n",
27666 *u16, *u16 / 65535.0f, expected_value, expected_value / 65535.0f);
27667 break;
27668 default:
27669 break;
27672 release_resource_readback(&rb);
27673 ID3D11RasterizerState_Release(rs);
27678 ID3D11Texture2D_Release(texture);
27679 ID3D11DepthStencilView_Release(dsv);
27682 heap_free(depth_values);
27683 release_test_context(&test_context);
27686 static void test_fractional_viewports(void)
27688 struct d3d11_test_context test_context;
27689 D3D11_TEXTURE2D_DESC texture_desc;
27690 ID3D11InputLayout *input_layout;
27691 ID3D11DeviceContext *context;
27692 struct resource_readback rb;
27693 ID3D11RenderTargetView *rtv;
27694 ID3D11VertexShader *vs;
27695 ID3D11PixelShader *ps;
27696 unsigned int i, x, y;
27697 ID3D11Device *device;
27698 ID3D11Texture2D *rt;
27699 UINT offset, stride;
27700 ID3D11Buffer *vb;
27701 HRESULT hr;
27703 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27704 static const DWORD vs_code[] =
27706 #if 0
27707 void main(in float4 in_position : POSITION,
27708 in float2 in_texcoord : TEXCOORD,
27709 out float4 position : SV_Position,
27710 out float2 texcoord : TEXCOORD)
27712 position = in_position;
27713 texcoord = in_texcoord;
27715 #endif
27716 0x43425844, 0x4df282ca, 0x85c8bbfc, 0xd44ad19f, 0x1158be97, 0x00000001, 0x00000148, 0x00000003,
27717 0x0000002c, 0x00000080, 0x000000d8, 0x4e475349, 0x0000004c, 0x00000002, 0x00000008, 0x00000038,
27718 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000041, 0x00000000, 0x00000000,
27719 0x00000003, 0x00000001, 0x00000303, 0x49534f50, 0x4e4f4954, 0x58455400, 0x524f4f43, 0xabab0044,
27720 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
27721 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000c03,
27722 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f, 0xababab00, 0x52444853, 0x00000068,
27723 0x00010040, 0x0000001a, 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101032, 0x00000001,
27724 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102032, 0x00000001, 0x05000036,
27725 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102032, 0x00000001, 0x00101046,
27726 0x00000001, 0x0100003e,
27728 static const DWORD ps_code[] =
27730 #if 0
27731 float4 main(float4 position : SV_Position,
27732 float2 texcoord : TEXCOORD) : SV_Target
27734 return float4(position.xy, texcoord);
27736 #endif
27737 0x43425844, 0xa15616bc, 0x6862ab1c, 0x28b915c0, 0xdb0df67c, 0x00000001, 0x0000011c, 0x00000003,
27738 0x0000002c, 0x00000084, 0x000000b8, 0x4e475349, 0x00000050, 0x00000002, 0x00000008, 0x00000038,
27739 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x00000044, 0x00000000, 0x00000000,
27740 0x00000003, 0x00000001, 0x00000303, 0x505f5653, 0x7469736f, 0x006e6f69, 0x43584554, 0x44524f4f,
27741 0xababab00, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
27742 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000005c,
27743 0x00000040, 0x00000017, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03001062, 0x00101032,
27744 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x05000036, 0x00102032, 0x00000000, 0x00101046,
27745 0x00000000, 0x05000036, 0x001020c2, 0x00000000, 0x00101406, 0x00000001, 0x0100003e,
27747 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
27749 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
27750 {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
27752 static const struct
27754 struct vec2 position;
27755 struct vec2 texcoord;
27757 quad[] =
27759 {{-1.0f, -1.0f}, {0.0f, 0.0f}},
27760 {{-1.0f, 1.0f}, {0.0f, 1.0f}},
27761 {{ 1.0f, -1.0f}, {1.0f, 0.0f}},
27762 {{ 1.0f, 1.0f}, {1.0f, 1.0f}},
27764 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
27765 static const float viewport_offsets[] =
27767 0.0f, 1.0f / 2.0f, 1.0f / 4.0f, 1.0f / 8.0f, 1.0f / 16.0f, 1.0f / 32.0f,
27768 1.0f / 64.0f, 1.0f / 128.0f, 1.0f / 256.0f, 63.0f / 128.0f,
27771 if (!init_test_context(&test_context, &feature_level))
27772 return;
27773 device = test_context.device;
27774 context = test_context.immediate_context;
27776 texture_desc.Width = 4;
27777 texture_desc.Height = 4;
27778 texture_desc.MipLevels = 1;
27779 texture_desc.ArraySize = 1;
27780 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
27781 texture_desc.SampleDesc.Count = 1;
27782 texture_desc.SampleDesc.Quality = 0;
27783 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27784 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
27785 texture_desc.CPUAccessFlags = 0;
27786 texture_desc.MiscFlags = 0;
27787 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rt);
27788 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27789 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rt, NULL, &rtv);
27790 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
27791 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
27793 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
27794 vs_code, sizeof(vs_code), &input_layout);
27795 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
27796 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(quad), quad);
27798 ID3D11DeviceContext_IASetInputLayout(context, input_layout);
27799 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
27800 stride = sizeof(*quad);
27801 offset = 0;
27802 ID3D11DeviceContext_IASetVertexBuffers(context, 0, 1, &vb, &stride, &offset);
27804 hr = ID3D11Device_CreateVertexShader(device, vs_code, sizeof(vs_code), NULL, &vs);
27805 ok(SUCCEEDED(hr), "Failed to create vertex shader, hr %#x.\n", hr);
27806 ID3D11DeviceContext_VSSetShader(context, vs, NULL, 0);
27808 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
27809 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27810 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27812 for (i = 0; i < ARRAY_SIZE(viewport_offsets); ++i)
27814 set_viewport(context, viewport_offsets[i], viewport_offsets[i],
27815 texture_desc.Width, texture_desc.Height, 0.0f, 1.0f);
27816 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
27817 ID3D11DeviceContext_Draw(context, 4, 0);
27818 get_texture_readback(rt, 0, &rb);
27819 for (y = 0; y < texture_desc.Height; ++y)
27821 for (x = 0; x < texture_desc.Width; ++x)
27823 const struct vec4 *v = get_readback_vec4(&rb, x, y);
27824 struct vec4 expected = {x + 0.5f, y + 0.5f,
27825 (x + 0.5f - viewport_offsets[i]) / texture_desc.Width,
27826 1.0f - (y + 0.5f - viewport_offsets[i]) / texture_desc.Height};
27827 ok(compare_float(v->x, expected.x, 0) && compare_float(v->y, expected.y, 0),
27828 "Got fragcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
27829 v->x, v->y, expected.x, expected.y, x, y, viewport_offsets[i]);
27830 todo_wine
27831 ok(compare_float(v->z, expected.z, 2) && compare_float(v->w, expected.w, 2),
27832 "Got texcoord {%.8e, %.8e}, expected {%.8e, %.8e} at (%u, %u), offset %.8e.\n",
27833 v->z, v->w, expected.z, expected.w, x, y, viewport_offsets[i]);
27836 release_resource_readback(&rb);
27839 ID3D11InputLayout_Release(input_layout);
27840 ID3D11Buffer_Release(vb);
27841 ID3D11VertexShader_Release(vs);
27842 ID3D11PixelShader_Release(ps);
27843 ID3D11RenderTargetView_Release(rtv);
27844 ID3D11Texture2D_Release(rt);
27845 release_test_context(&test_context);
27848 static void test_negative_viewports(const D3D_FEATURE_LEVEL feature_level)
27850 struct d3d11_test_context test_context;
27851 ID3D11DeviceContext *context;
27852 BOOL quirk;
27853 RECT rect;
27855 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
27856 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
27858 if (!init_test_context(&test_context, &feature_level))
27859 return;
27860 context = test_context.immediate_context;
27862 set_viewport(context, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
27863 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27864 draw_color_quad(&test_context, &green);
27865 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
27867 set_viewport(context, -0.0f, -0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
27868 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27869 draw_color_quad(&test_context, &green);
27870 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
27872 /* For feature levels greater than or equal to 11_0, a negative top left
27873 * corner shifts the bottom right corner by a whole integer. It seems that
27874 * floor() is used to round viewport corners to integers.
27876 quirk = feature_level >= D3D_FEATURE_LEVEL_11_0;
27878 set_viewport(context, -0.4f, -0.4f, 640.0f, 480.0f, 0.0f, 1.0f);
27879 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27880 draw_color_quad(&test_context, &green);
27881 SetRect(&rect, 0, 0, 639, 479);
27882 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
27883 SetRect(&rect, 639, 479, 640, 480);
27884 todo_wine_if(quirk)
27885 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
27887 set_viewport(context, -1.0f / 128.0f, -1.0 / 128.0f, 640.0f, 480.0f, 0.0f, 1.0f);
27888 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
27889 draw_color_quad(&test_context, &green);
27890 SetRect(&rect, 0, 0, 639, 479);
27891 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, 0xff00ff00, 1);
27892 SetRect(&rect, 639, 479, 640, 480);
27893 todo_wine_if(quirk)
27894 check_texture_sub_resource_color(test_context.backbuffer, 0, &rect, quirk ? 0xffffffff : 0xff00ff00, 1);
27896 release_test_context(&test_context);
27899 static void test_early_depth_stencil(void)
27901 ID3D11DepthStencilState *depth_stencil_state;
27902 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
27903 ID3D11Texture2D *texture, *depth_texture;
27904 struct d3d11_test_context test_context;
27905 D3D11_TEXTURE2D_DESC texture_desc;
27906 ID3D11UnorderedAccessView *uav;
27907 ID3D11DeviceContext *context;
27908 ID3D11DepthStencilView *dsv;
27909 ID3D11PixelShader *ps;
27910 ID3D11Device *device;
27911 HRESULT hr;
27913 static const DWORD ps_code[] =
27915 #if 0
27916 RWTexture2D<int> u;
27918 [earlydepthstencil]
27919 float4 main() : SV_Target
27921 InterlockedAdd(u[uint2(0, 0)], 1);
27922 return float4(1.0f, 1.0f, 1.0f, 1.0f);
27924 #endif
27925 0x43425844, 0xda4325ad, 0xc01d3815, 0xfd610cc9, 0x8ed1e351, 0x00000001, 0x000000ec, 0x00000003,
27926 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
27927 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
27928 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000074, 0x00000050, 0x0000001d,
27929 0x0100286a, 0x0400189c, 0x0011e000, 0x00000001, 0x00003333, 0x03000065, 0x001020f2, 0x00000000,
27930 0x0a0000ad, 0x0011e000, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
27931 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000,
27932 0x3f800000, 0x3f800000, 0x0100003e,
27934 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
27935 static const UINT values[4] = {0};
27937 if (!init_test_context(&test_context, &feature_level))
27938 return;
27940 device = test_context.device;
27941 context = test_context.immediate_context;
27943 depth_stencil_desc.DepthEnable = TRUE;
27944 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO;
27945 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_LESS_EQUAL;
27946 depth_stencil_desc.StencilEnable = FALSE;
27947 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
27948 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
27950 texture_desc.Width = 1;
27951 texture_desc.Height = 1;
27952 texture_desc.MipLevels = 1;
27953 texture_desc.ArraySize = 1;
27954 texture_desc.Format = DXGI_FORMAT_R32_SINT;
27955 texture_desc.SampleDesc.Count = 1;
27956 texture_desc.SampleDesc.Quality = 0;
27957 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27958 texture_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
27959 texture_desc.CPUAccessFlags = 0;
27960 texture_desc.MiscFlags = 0;
27961 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
27962 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27963 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)texture, NULL, &uav);
27964 ok(SUCCEEDED(hr), "Failed to create unordered access view, hr %#x.\n", hr);
27966 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
27967 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
27968 texture_desc.Usage = D3D11_USAGE_DEFAULT;
27969 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
27970 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &depth_texture);
27971 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
27972 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)depth_texture, NULL, &dsv);
27973 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
27975 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
27976 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
27977 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
27979 set_viewport(context, 0.0f, 0.0f, 1.0f, 100.0f, 0.5f, 0.5f);
27980 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
27981 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
27982 1, &test_context.backbuffer_rtv, dsv, 1, 1, &uav, NULL);
27984 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, values);
27986 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.6f, 0);
27987 draw_quad(&test_context);
27988 check_texture_color(texture, 100, 1);
27989 draw_quad(&test_context);
27990 check_texture_color(texture, 200, 1);
27991 check_texture_float(depth_texture, 0.6f, 1);
27993 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.3f, 0);
27994 draw_quad(&test_context);
27995 draw_quad(&test_context);
27996 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.55f, 0);
27997 draw_quad(&test_context);
27998 check_texture_color(texture, 300, 1);
28000 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
28001 draw_quad(&test_context);
28002 check_texture_color(texture, 400, 1);
28003 check_texture_float(depth_texture, 0.5f, 1);
28005 ID3D11Texture2D_Release(depth_texture);
28006 ID3D11DepthStencilView_Release(dsv);
28007 ID3D11DepthStencilState_Release(depth_stencil_state);
28008 ID3D11PixelShader_Release(ps);
28009 ID3D11Texture2D_Release(texture);
28010 ID3D11UnorderedAccessView_Release(uav);
28011 release_test_context(&test_context);
28014 static void test_conservative_depth_output(void)
28016 struct shader
28018 const DWORD *code;
28019 size_t size;
28022 ID3D11DepthStencilState *depth_stencil_state;
28023 D3D11_DEPTH_STENCIL_DESC depth_stencil_desc;
28024 struct d3d11_test_context test_context;
28025 const struct shader *current_shader;
28026 D3D11_TEXTURE2D_DESC texture_desc;
28027 ID3D11DeviceContext *context;
28028 ID3D11DepthStencilView *dsv;
28029 ID3D11Texture2D *texture;
28030 ID3D11PixelShader *ps;
28031 DWORD expected_color;
28032 float expected_depth;
28033 ID3D11Device *device;
28034 struct vec4 ps_depth;
28035 ID3D11Buffer *cb;
28036 unsigned int i;
28037 HRESULT hr;
28039 static const DWORD ps_depth_le_code[] =
28041 #if 0
28042 float depth;
28044 float4 main(out float out_depth : SV_DepthLessEqual) : SV_Target0
28046 out_depth = depth;
28047 return float4(0.0f, 1.0f, 0.f, 1.0f);
28049 #endif
28050 0x43425844, 0x045c8d00, 0xc49e2ebe, 0x76f6022a, 0xf6996ecc, 0x00000001, 0x00000108, 0x00000003,
28051 0x0000002c, 0x0000003c, 0x00000098, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28052 0x00000054, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28053 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
28054 0x65677261, 0x56530074, 0x7065445f, 0x654c6874, 0x71457373, 0x006c6175, 0x58454853, 0x00000068,
28055 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x03000065,
28056 0x001020f2, 0x00000000, 0x02000065, 0x00027001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
28057 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00027001, 0x0020800a, 0x00000000,
28058 0x00000000, 0x0100003e,
28060 static const struct shader ps_depth_le = {ps_depth_le_code, sizeof(ps_depth_le_code)};
28061 static const DWORD ps_depth_ge_code[] =
28063 #if 0
28064 float depth;
28066 float4 main(out float out_depth : SV_DepthGreaterEqual) : SV_Target0
28068 out_depth = depth;
28069 return float4(0.0f, 1.0f, 0.f, 1.0f);
28071 #endif
28072 0x43425844, 0xd17af83e, 0xa32c01cc, 0x0d8e9665, 0xe6dc17c2, 0x00000001, 0x0000010c, 0x00000003,
28073 0x0000002c, 0x0000003c, 0x0000009c, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
28074 0x00000058, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
28075 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000003, 0xffffffff, 0x00000e01, 0x545f5653,
28076 0x65677261, 0x56530074, 0x7065445f, 0x72476874, 0x65746165, 0x75714572, 0xab006c61, 0x58454853,
28077 0x00000068, 0x00000050, 0x0000001a, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
28078 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x00026001, 0x08000036, 0x001020f2, 0x00000000,
28079 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x05000036, 0x00026001, 0x0020800a,
28080 0x00000000, 0x00000000, 0x0100003e,
28082 static const struct shader ps_depth_ge = {ps_depth_ge_code, sizeof(ps_depth_ge_code)};
28083 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
28084 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28085 static const struct
28087 const struct shader *ps;
28088 float vs_depth;
28089 float ps_depth;
28090 BOOL passes_depth_test;
28092 tests[] =
28094 {&ps_depth_le, 0.7f, 0.7f, TRUE},
28095 {&ps_depth_le, 0.7f, 0.4f, FALSE},
28096 {&ps_depth_le, 0.4f, 0.4f, FALSE},
28097 /* {&ps_depth_le, 0.4f, 0.6f, FALSE}, undefined result */
28098 {&ps_depth_ge, 0.7f, 0.7f, TRUE},
28099 /* {&ps_depth_ge, 0.7f, 0.4f, TRUE}, undefined result */
28100 {&ps_depth_ge, 0.4f, 0.4f, FALSE},
28101 {&ps_depth_ge, 0.4f, 0.6f, TRUE},
28104 if (!init_test_context(&test_context, &feature_level))
28105 return;
28107 device = test_context.device;
28108 context = test_context.immediate_context;
28110 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_depth), NULL);
28112 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
28113 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
28114 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28115 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
28116 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
28117 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
28118 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
28119 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
28121 depth_stencil_desc.DepthEnable = TRUE;
28122 depth_stencil_desc.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL;
28123 depth_stencil_desc.DepthFunc = D3D11_COMPARISON_GREATER_EQUAL;
28124 depth_stencil_desc.StencilEnable = FALSE;
28125 hr = ID3D11Device_CreateDepthStencilState(device, &depth_stencil_desc, &depth_stencil_state);
28126 ok(SUCCEEDED(hr), "Failed to create depth stencil state, hr %#x.\n", hr);
28128 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
28129 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
28130 ID3D11DeviceContext_OMSetDepthStencilState(context, depth_stencil_state, 0);
28132 ps = NULL;
28133 current_shader = NULL;
28134 for (i = 0; i < ARRAY_SIZE(tests); ++i)
28136 if (current_shader != tests[i].ps)
28138 if (ps)
28139 ID3D11PixelShader_Release(ps);
28141 current_shader = tests[i].ps;
28142 hr = ID3D11Device_CreatePixelShader(device, current_shader->code, current_shader->size, NULL, &ps);
28143 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
28144 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
28147 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
28148 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 0.5f, 0);
28149 ps_depth.x = tests[i].ps_depth;
28150 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_depth, 0, 0);
28151 draw_quad_z(&test_context, tests[i].vs_depth);
28153 expected_color = tests[i].passes_depth_test ? 0xff00ff00 : 0xffffffff;
28154 expected_depth = tests[i].passes_depth_test ? max(tests[i].vs_depth, tests[i].ps_depth) : 0.5f;
28155 check_texture_color(test_context.backbuffer, expected_color, 0);
28156 check_texture_float(texture, expected_depth, 1);
28159 ID3D11Buffer_Release(cb);
28160 ID3D11PixelShader_Release(ps);
28161 ID3D11DepthStencilView_Release(dsv);
28162 ID3D11DepthStencilState_Release(depth_stencil_state);
28163 ID3D11Texture2D_Release(texture);
28164 release_test_context(&test_context);
28167 static void test_format_compatibility(void)
28169 ID3D11Texture2D *dst_texture, *src_texture;
28170 D3D11_SUBRESOURCE_DATA resource_data;
28171 D3D11_TEXTURE2D_DESC texture_desc;
28172 ID3D11DeviceContext *context;
28173 struct resource_readback rb;
28174 DWORD colour, expected;
28175 ID3D11Device *device;
28176 unsigned int i, j;
28177 ULONG refcount;
28178 HRESULT hr;
28180 static const struct
28182 DXGI_FORMAT src_format;
28183 DXGI_FORMAT dst_format;
28184 size_t texel_size;
28185 BOOL success;
28186 BOOL src_ds;
28187 BOOL dst_ds;
28189 test_data[] =
28191 {DXGI_FORMAT_R8G8B8A8_TYPELESS, DXGI_FORMAT_R8G8B8A8_UNORM, 4, TRUE},
28192 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, 4, TRUE},
28193 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, DXGI_FORMAT_R8G8B8A8_UINT, 4, TRUE},
28194 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R8G8B8A8_SNORM, 4, TRUE},
28195 {DXGI_FORMAT_R8G8B8A8_SNORM, DXGI_FORMAT_R8G8B8A8_SINT, 4, TRUE},
28196 {DXGI_FORMAT_R8G8B8A8_SINT, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, TRUE},
28197 {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, 4, FALSE},
28198 {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R16G16_UINT, 4, FALSE},
28199 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R16G16_FLOAT, 4, TRUE},
28200 {DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R16G16_UNORM, 4, TRUE},
28201 {DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_UINT, 4, TRUE},
28202 {DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R16G16_SNORM, 4, TRUE},
28203 {DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_SINT, 4, TRUE},
28204 {DXGI_FORMAT_R16G16_SINT, DXGI_FORMAT_R16G16_TYPELESS, 4, TRUE},
28205 {DXGI_FORMAT_R16G16_TYPELESS, DXGI_FORMAT_R32_TYPELESS, 4, FALSE},
28206 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_TYPELESS, 4, TRUE},
28207 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_FLOAT, 4, TRUE},
28208 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_UINT, 4, TRUE},
28209 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R32_SINT, 4, TRUE},
28210 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, FALSE},
28211 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_B8G8R8A8_TYPELESS, 4, FALSE},
28212 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, DXGI_FORMAT_R16G16_TYPELESS, 4, FALSE},
28213 {DXGI_FORMAT_R32G32_TYPELESS, DXGI_FORMAT_R32G32_FLOAT, 8, TRUE},
28214 {DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32_UINT, 8, TRUE},
28215 {DXGI_FORMAT_R32G32_UINT, DXGI_FORMAT_R32G32_SINT, 8, TRUE},
28216 {DXGI_FORMAT_R32G32_SINT, DXGI_FORMAT_R32G32_TYPELESS, 8, TRUE},
28217 {DXGI_FORMAT_D16_UNORM, DXGI_FORMAT_R16_UNORM, 2, TRUE, TRUE},
28218 {DXGI_FORMAT_R16_UNORM, DXGI_FORMAT_D16_UNORM, 2, TRUE, FALSE, TRUE},
28219 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_TYPELESS, 2, TRUE, TRUE},
28220 {DXGI_FORMAT_R16_TYPELESS, DXGI_FORMAT_R16_TYPELESS, 2, TRUE, FALSE, TRUE},
28222 static const DWORD initial_data[16] = {0};
28223 static const DWORD bitmap_data[] =
28225 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28226 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28227 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28228 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28231 if (!(device = create_device(NULL)))
28233 skip("Failed to create device.\n");
28234 return;
28236 ID3D11Device_GetImmediateContext(device, &context);
28238 texture_desc.Height = 4;
28239 texture_desc.MipLevels = 1;
28240 texture_desc.ArraySize = 1;
28241 texture_desc.SampleDesc.Count = 1;
28242 texture_desc.SampleDesc.Quality = 0;
28243 texture_desc.CPUAccessFlags = 0;
28244 texture_desc.MiscFlags = 0;
28246 for (i = 0; i < ARRAY_SIZE(test_data); ++i)
28248 unsigned int x, y, texel_dwords;
28249 BOOL broken = FALSE;
28250 D3D11_BOX box;
28252 texture_desc.Width = sizeof(bitmap_data) / (texture_desc.Height * test_data[i].texel_size);
28253 texture_desc.Format = test_data[i].src_format;
28254 texture_desc.Usage = test_data[i].src_ds ? D3D11_USAGE_DEFAULT : D3D11_USAGE_IMMUTABLE;
28255 texture_desc.BindFlags = test_data[i].src_ds ? D3D11_BIND_DEPTH_STENCIL : D3D11_BIND_SHADER_RESOURCE;
28257 resource_data.pSysMem = bitmap_data;
28258 resource_data.SysMemPitch = texture_desc.Width * test_data[i].texel_size;
28259 resource_data.SysMemSlicePitch = 0;
28261 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
28262 ok(SUCCEEDED(hr), "Failed to create source texture, hr %#x.\n", hr);
28264 texture_desc.Format = test_data[i].dst_format;
28265 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28266 texture_desc.BindFlags = test_data[i].dst_ds ? D3D11_BIND_DEPTH_STENCIL : D3D11_BIND_SHADER_RESOURCE;
28268 resource_data.pSysMem = initial_data;
28270 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
28271 ok(SUCCEEDED(hr), "Failed to create destination texture, hr %#x.\n", hr);
28273 set_box(&box, 0, 0, 0, texture_desc.Width - 1, texture_desc.Height - 1, 1);
28274 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0, 1, 1, 0,
28275 (ID3D11Resource *)src_texture, 0, &box);
28277 texel_dwords = test_data[i].texel_size / sizeof(DWORD);
28278 get_texture_readback(dst_texture, 0, &rb);
28279 colour = get_readback_color(&rb, 0, 0, 0);
28280 if (test_data[i].src_format == DXGI_FORMAT_R9G9B9E5_SHAREDEXP && colour == bitmap_data[0])
28282 win_skip("Broken destination offset for %#x -> %#x copy.\n",
28283 test_data[i].src_format, test_data[i].dst_format);
28284 broken = TRUE;
28286 for (j = 0; j < ARRAY_SIZE(bitmap_data) && !broken; ++j)
28288 x = j % 4;
28289 y = j / 4;
28290 colour = get_readback_color(&rb, x, y, 0);
28291 expected = test_data[i].success && !test_data[i].src_ds && !test_data[i].dst_ds
28292 && x >= texel_dwords && y ? bitmap_data[j - (4 + texel_dwords)] : initial_data[j];
28293 todo_wine_if((test_data[i].src_ds || test_data[i].dst_ds) && colour)
28294 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
28295 i, colour, x, y, expected);
28297 release_resource_readback(&rb);
28299 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
28301 get_texture_readback(dst_texture, 0, &rb);
28302 for (j = 0; j < ARRAY_SIZE(bitmap_data); ++j)
28304 x = j % 4;
28305 y = j / 4;
28306 colour = get_readback_color(&rb, x, y, 0);
28307 expected = test_data[i].success ? bitmap_data[j] : initial_data[j];
28308 ok(colour == expected, "Test %u: Got unexpected colour 0x%08x at (%u, %u), expected 0x%08x.\n",
28309 i, colour, x, y, expected);
28311 release_resource_readback(&rb);
28313 ID3D11Texture2D_Release(dst_texture);
28314 ID3D11Texture2D_Release(src_texture);
28317 ID3D11DeviceContext_Release(context);
28318 refcount = ID3D11Device_Release(device);
28319 ok(!refcount, "Device has %u references left.\n", refcount);
28322 static void test_compressed_format_compatibility(const D3D_FEATURE_LEVEL feature_level)
28324 const struct format_info *src_format, *dst_format;
28325 unsigned int row_block_count, row_count, i, j, k;
28326 ID3D11Texture2D *src_texture, *dst_texture;
28327 BOOL supported, broken_dst_offset = FALSE;
28328 D3D11_SUBRESOURCE_DATA resource_data;
28329 D3D11_TEXTURE2D_DESC texture_desc;
28330 ID3D11DeviceContext *context;
28331 unsigned int block_idx, x, y;
28332 struct resource_readback rb;
28333 DWORD colour, expected;
28334 ID3D11Device *device;
28335 UINT format_support;
28336 const BYTE *row;
28337 ULONG refcount;
28338 D3D11_BOX box;
28339 HRESULT hr;
28340 const struct device_desc device_desc =
28342 .feature_level = &feature_level,
28345 static const struct format_info
28347 DXGI_FORMAT id;
28348 size_t block_size;
28349 size_t block_edge;
28350 BOOL supported;
28351 BOOL skip_if_broken;
28353 formats[] =
28355 {DXGI_FORMAT_R32G32B32A32_TYPELESS, 16, 1, TRUE},
28356 {DXGI_FORMAT_R32G32B32A32_FLOAT, 16, 1, TRUE},
28357 {DXGI_FORMAT_R32G32B32A32_UINT, 16, 1, TRUE},
28358 {DXGI_FORMAT_R32G32B32A32_SINT, 16, 1, TRUE},
28360 {DXGI_FORMAT_R16G16B16A16_TYPELESS, 8, 1, TRUE},
28361 {DXGI_FORMAT_R16G16B16A16_FLOAT, 8, 1, TRUE},
28362 {DXGI_FORMAT_R16G16B16A16_UNORM, 8, 1, TRUE},
28363 {DXGI_FORMAT_R16G16B16A16_UINT, 8, 1, TRUE},
28364 {DXGI_FORMAT_R16G16B16A16_SNORM, 8, 1, TRUE},
28365 {DXGI_FORMAT_R16G16B16A16_SINT, 8, 1, TRUE},
28367 {DXGI_FORMAT_R32G32_TYPELESS, 8, 1, TRUE},
28368 {DXGI_FORMAT_R32G32_FLOAT, 8, 1, TRUE},
28369 {DXGI_FORMAT_R32G32_UINT, 8, 1, TRUE},
28370 {DXGI_FORMAT_R32G32_SINT, 8, 1, TRUE},
28372 {DXGI_FORMAT_R32_TYPELESS, 4, 1, TRUE},
28373 {DXGI_FORMAT_R32_FLOAT, 4, 1, TRUE},
28374 {DXGI_FORMAT_R32_UINT, 4, 1, TRUE},
28375 {DXGI_FORMAT_R32_SINT, 4, 1, TRUE},
28377 {DXGI_FORMAT_R32G8X24_TYPELESS, 8, 1},
28378 {DXGI_FORMAT_R10G10B10A2_TYPELESS, 4, 1},
28379 {DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, 1},
28380 {DXGI_FORMAT_R16G16_TYPELESS, 4, 1},
28381 {DXGI_FORMAT_R24G8_TYPELESS, 4, 1},
28382 {DXGI_FORMAT_R9G9B9E5_SHAREDEXP, 4, 1},
28383 {DXGI_FORMAT_B8G8R8A8_TYPELESS, 4, 1},
28384 {DXGI_FORMAT_R8G8_TYPELESS, 2, 1},
28385 {DXGI_FORMAT_R16_TYPELESS, 2, 1},
28386 {DXGI_FORMAT_R8_TYPELESS, 1, 1},
28388 {DXGI_FORMAT_BC1_TYPELESS, 8, 4},
28389 {DXGI_FORMAT_BC1_UNORM, 8, 4},
28390 {DXGI_FORMAT_BC1_UNORM_SRGB, 8, 4},
28392 {DXGI_FORMAT_BC2_TYPELESS, 16, 4},
28393 {DXGI_FORMAT_BC2_UNORM, 16, 4},
28394 {DXGI_FORMAT_BC2_UNORM_SRGB, 16, 4},
28396 {DXGI_FORMAT_BC3_TYPELESS, 16, 4},
28397 {DXGI_FORMAT_BC3_UNORM, 16, 4},
28398 {DXGI_FORMAT_BC3_UNORM_SRGB, 16, 4},
28400 {DXGI_FORMAT_BC4_TYPELESS, 8, 4},
28401 {DXGI_FORMAT_BC4_UNORM, 8, 4},
28402 {DXGI_FORMAT_BC4_SNORM, 8, 4},
28404 {DXGI_FORMAT_BC5_TYPELESS, 16, 4},
28405 {DXGI_FORMAT_BC5_UNORM, 16, 4},
28406 {DXGI_FORMAT_BC5_SNORM, 16, 4},
28408 {DXGI_FORMAT_BC6H_TYPELESS, 16, 4, FALSE, TRUE},
28409 {DXGI_FORMAT_BC6H_UF16, 16, 4, FALSE, TRUE},
28410 {DXGI_FORMAT_BC6H_SF16, 16, 4, FALSE, TRUE},
28412 {DXGI_FORMAT_BC7_TYPELESS, 16, 4, FALSE, TRUE},
28413 {DXGI_FORMAT_BC7_UNORM, 16, 4, FALSE, TRUE},
28414 {DXGI_FORMAT_BC7_UNORM_SRGB, 16, 4, FALSE, TRUE},
28417 static const DWORD initial_data[64] = {0};
28418 static const DWORD texture_data[] =
28420 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28421 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28422 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28423 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28425 0xffffffff, 0xff000000, 0xff000000, 0xff000000,
28426 0xffffffff, 0xffffffff, 0xffffffff, 0xff000000,
28427 0xffff0000, 0xffff00ff, 0xff000000, 0xff7f7f7f,
28428 0xff0000ff, 0xff00ffff, 0xff00ff00, 0xffffff00,
28430 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
28431 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
28432 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
28433 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
28435 0xff000000, 0xff000000, 0xffffffff, 0xff000000,
28436 0xffffffff, 0xff000000, 0xffffffff, 0xffffffff,
28437 0xff000000, 0xff7f7f7f, 0xffff0000, 0xffff00ff,
28438 0xff00ff00, 0xffffff00, 0xff0000ff, 0xff00ffff,
28441 if (!(device = create_device(&device_desc)))
28443 skip("Failed to create device for feature level %#x.\n", feature_level);
28444 return;
28446 ID3D11Device_GetImmediateContext(device, &context);
28448 row_block_count = 4;
28450 texture_desc.MipLevels = 1;
28451 texture_desc.ArraySize = 1;
28452 texture_desc.SampleDesc.Count = 1;
28453 texture_desc.SampleDesc.Quality = 0;
28454 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
28455 texture_desc.CPUAccessFlags = 0;
28456 texture_desc.MiscFlags = 0;
28458 resource_data.SysMemSlicePitch = 0;
28460 for (i = 0; i < ARRAY_SIZE(formats); ++i)
28462 src_format = &formats[i];
28463 row_count = sizeof(texture_data) / (row_block_count * src_format->block_size);
28464 texture_desc.Width = row_block_count * src_format->block_edge;
28465 texture_desc.Height = row_count * src_format->block_edge;
28466 texture_desc.Format = src_format->id;
28467 texture_desc.Usage = D3D11_USAGE_IMMUTABLE;
28469 resource_data.pSysMem = texture_data;
28470 resource_data.SysMemPitch = row_block_count * src_format->block_size;
28472 hr = ID3D11Device_CheckFormatSupport(device, src_format->id, &format_support);
28473 if (hr == E_FAIL || !(format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
28474 continue;
28476 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &src_texture);
28477 ok(hr == S_OK, "Source format %#x: Got unexpected hr %#x.\n", src_format->id, hr);
28479 for (j = 0; j < ARRAY_SIZE(formats); ++j)
28481 dst_format = &formats[j];
28483 if ((src_format->block_edge == 1 && dst_format->block_edge == 1)
28484 || (src_format->block_edge != 1 && dst_format->block_edge != 1))
28485 continue;
28487 hr = ID3D11Device_CheckFormatSupport(device, dst_format->id, &format_support);
28488 if (hr == E_FAIL || !(format_support & D3D11_FORMAT_SUPPORT_TEXTURE2D))
28489 continue;
28491 supported = ((src_format->block_edge != 1 && dst_format->supported)
28492 || (src_format->supported && dst_format->block_edge != 1))
28493 && src_format->block_size == dst_format->block_size
28494 && feature_level >= D3D_FEATURE_LEVEL_10_1;
28496 /* These cause the device to be removed on some versions of Windows. */
28497 if (supported && broken_dst_offset && (src_format->skip_if_broken || dst_format->skip_if_broken))
28499 win_skip("Skipping %#x -> %#x tests because of broken destination offset.\n",
28500 src_format->id, dst_format->id);
28501 continue;
28504 row_count = sizeof(initial_data) / (row_block_count * dst_format->block_size);
28505 texture_desc.Width = row_block_count * dst_format->block_edge;
28506 texture_desc.Height = row_count * dst_format->block_edge;
28507 texture_desc.Format = dst_format->id;
28508 texture_desc.Usage = D3D11_USAGE_DEFAULT;
28510 resource_data.pSysMem = initial_data;
28511 resource_data.SysMemPitch = row_block_count * dst_format->block_size;
28513 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, &resource_data, &dst_texture);
28514 ok(hr == S_OK, "%#x -> %#x: Got unexpected hr %#x.\n", src_format->id, dst_format->id, hr);
28516 if (supported && broken_dst_offset)
28518 win_skip("Skipping %#x -> %#x CopySubresourceRegion() test because of broken destination offset.\n",
28519 src_format->id, dst_format->id);
28521 else
28523 set_box(&box, 0, 0, 0, src_format->block_edge, src_format->block_edge, 1);
28524 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)dst_texture, 0,
28525 dst_format->block_edge, dst_format->block_edge, 0, (ID3D11Resource *)src_texture, 0, &box);
28526 get_texture_readback(dst_texture, 0, &rb);
28527 colour = get_readback_color(&rb, 0, 0, 0);
28528 if (supported && colour == texture_data[0])
28530 win_skip("Detected broken destination offset for %#x -> %#x copy.\n",
28531 src_format->id, dst_format->id);
28532 broken_dst_offset = TRUE;
28534 for (k = 0; k < ARRAY_SIZE(texture_data) && (!supported || !broken_dst_offset); ++k)
28536 block_idx = (k * sizeof(colour)) / dst_format->block_size;
28537 x = block_idx % row_block_count;
28538 y = block_idx / row_block_count;
28540 row = rb.map_desc.pData;
28541 row += y * rb.map_desc.RowPitch;
28542 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
28544 if (supported && x == 1 && y == 1)
28545 expected = texture_data[k - ((row_block_count + 1) * dst_format->block_size) / sizeof(colour)];
28546 else
28547 expected = initial_data[k];
28548 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
28549 src_format->id, dst_format->id, colour, k, expected);
28550 if (colour != expected)
28551 break;
28553 release_resource_readback(&rb);
28556 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_texture, (ID3D11Resource *)src_texture);
28557 get_texture_readback(dst_texture, 0, &rb);
28558 for (k = 0; k < ARRAY_SIZE(texture_data); ++k)
28560 block_idx = (k * sizeof(colour)) / dst_format->block_size;
28561 y = block_idx / row_block_count;
28563 row = rb.map_desc.pData;
28564 row += y * rb.map_desc.RowPitch;
28565 colour = ((DWORD *)row)[k % ((row_block_count * dst_format->block_size) / sizeof(colour))];
28567 if (supported)
28568 expected = texture_data[k];
28569 else
28570 expected = initial_data[k];
28571 ok(colour == expected, "%#x -> %#x: Got unexpected colour 0x%08x at %u, expected 0x%08x.\n",
28572 src_format->id, dst_format->id, colour, k, expected);
28573 if (colour != expected)
28574 break;
28576 release_resource_readback(&rb);
28578 ID3D11Texture2D_Release(dst_texture);
28581 ID3D11Texture2D_Release(src_texture);
28584 ID3D11DeviceContext_Release(context);
28585 refcount = ID3D11Device_Release(device);
28586 ok(!refcount, "Device has %u references left.\n", refcount);
28589 static void check_clip_distance(struct d3d11_test_context *test_context, ID3D11Buffer *vb)
28591 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
28592 struct vertex
28594 float clip_distance0;
28595 float clip_distance1;
28598 ID3D11DeviceContext *context = test_context->immediate_context;
28599 struct resource_readback rb;
28600 struct vertex vertices[4];
28601 unsigned int i;
28602 RECT rect;
28604 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28605 vertices[i].clip_distance0 = 1.0f;
28606 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28607 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28608 ID3D11DeviceContext_Draw(context, 4, 0);
28609 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
28611 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28612 vertices[i].clip_distance0 = 0.0f;
28613 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28614 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28615 ID3D11DeviceContext_Draw(context, 4, 0);
28616 check_texture_color(test_context->backbuffer, 0xff00ff00, 1);
28618 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28619 vertices[i].clip_distance0 = -1.0f;
28620 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28621 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28622 ID3D11DeviceContext_Draw(context, 4, 0);
28623 check_texture_color(test_context->backbuffer, 0xffffffff, 1);
28625 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28626 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
28627 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28628 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28629 ID3D11DeviceContext_Draw(context, 4, 0);
28630 get_texture_readback(test_context->backbuffer, 0, &rb);
28631 SetRect(&rect, 0, 0, 320, 480);
28632 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
28633 SetRect(&rect, 320, 0, 320, 480);
28634 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28635 release_resource_readback(&rb);
28637 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
28638 vertices[i].clip_distance0 = i % 2 ? 1.0f : -1.0f;
28639 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
28640 ID3D11DeviceContext_ClearRenderTargetView(context, test_context->backbuffer_rtv, white);
28641 ID3D11DeviceContext_Draw(context, 4, 0);
28642 get_texture_readback(test_context->backbuffer, 0, &rb);
28643 SetRect(&rect, 0, 0, 640, 240);
28644 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
28645 SetRect(&rect, 0, 240, 640, 240);
28646 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
28647 release_resource_readback(&rb);
28650 static void test_clip_distance(void)
28652 struct d3d11_test_context test_context;
28653 ID3D11Buffer *vs_cb, *tess_cb, *gs_cb;
28654 D3D_FEATURE_LEVEL feature_level;
28655 ID3D11DomainShader *ds = NULL;
28656 ID3D11DeviceContext *context;
28657 struct resource_readback rb;
28658 unsigned int offset, stride;
28659 ID3D11HullShader *hs = NULL;
28660 ID3D11GeometryShader *gs;
28661 ID3D11Device *device;
28662 ID3D11Buffer *vb;
28663 unsigned int i;
28664 HRESULT hr;
28665 RECT rect;
28667 static const DWORD vs_code[] =
28669 #if 0
28670 bool use_constant;
28671 float clip_distance;
28673 struct input
28675 float4 position : POSITION;
28676 float distance0 : CLIP_DISTANCE0;
28677 float distance1 : CLIP_DISTANCE1;
28680 struct vertex
28682 float4 position : SV_POSITION;
28683 float user_clip : CLIP_DISTANCE;
28684 float clip : SV_ClipDistance;
28687 void main(input vin, out vertex vertex)
28689 vertex.position = vin.position;
28690 vertex.user_clip = vin.distance0;
28691 vertex.clip = vin.distance0;
28692 if (use_constant)
28693 vertex.clip = clip_distance;
28695 #endif
28696 0x43425844, 0x09dfef58, 0x88570f2e, 0x1ebcf953, 0x9f97e22a, 0x00000001, 0x000001dc, 0x00000003,
28697 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
28698 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
28699 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
28700 0x00000001, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
28701 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
28702 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
28703 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49,
28704 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
28705 0x52444853, 0x000000b4, 0x00010040, 0x0000002d, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
28706 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x04000067, 0x001020f2,
28707 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
28708 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012,
28709 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012, 0x00000002, 0x0020800a, 0x00000000,
28710 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a, 0x00000001, 0x0100003e,
28712 static const DWORD vs_multiple_code[] =
28714 #if 0
28715 bool use_constant;
28716 float clip_distance0;
28717 float clip_distance1;
28719 struct input
28721 float4 position : POSITION;
28722 float distance0 : CLIP_DISTANCE0;
28723 float distance1 : CLIP_DISTANCE1;
28726 struct vertex
28728 float4 position : SV_POSITION;
28729 float user_clip : CLIP_DISTANCE;
28730 float2 clip : SV_ClipDistance;
28733 void main(input vin, out vertex vertex)
28735 vertex.position = vin.position;
28736 vertex.user_clip = vin.distance0;
28737 vertex.clip.x = vin.distance0;
28738 if (use_constant)
28739 vertex.clip.x = clip_distance0;
28740 vertex.clip.y = vin.distance1;
28741 if (use_constant)
28742 vertex.clip.y = clip_distance1;
28744 #endif
28745 0x43425844, 0xef5cc236, 0xe2fbfa69, 0x560b6591, 0x23037999, 0x00000001, 0x00000214, 0x00000003,
28746 0x0000002c, 0x0000009c, 0x00000120, 0x4e475349, 0x00000068, 0x00000003, 0x00000008, 0x00000050,
28747 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x00000059, 0x00000000, 0x00000000,
28748 0x00000003, 0x00000001, 0x00000101, 0x00000059, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
28749 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300, 0x49445f50, 0x4e415453, 0xab004543, 0x4e47534f,
28750 0x0000007c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
28751 0x0000000f, 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a,
28752 0x00000000, 0x00000002, 0x00000003, 0x00000002, 0x00000c03, 0x505f5653, 0x5449534f, 0x004e4f49,
28753 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065,
28754 0x52444853, 0x000000ec, 0x00010040, 0x0000003b, 0x04000059, 0x00208e46, 0x00000000, 0x00000001,
28755 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
28756 0x00000002, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001,
28757 0x04000067, 0x00102032, 0x00000002, 0x00000002, 0x05000036, 0x001020f2, 0x00000000, 0x00101e46,
28758 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a, 0x00000001, 0x0b000037, 0x00102012,
28759 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0010100a,
28760 0x00000001, 0x0b000037, 0x00102022, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020802a,
28761 0x00000000, 0x00000000, 0x0010100a, 0x00000002, 0x0100003e,
28763 #if 0
28764 bool use_constant;
28765 float clip_distance0;
28766 float clip_distance1;
28767 float tessellation_factor;
28769 struct vertex
28771 float4 position : SV_POSITION;
28772 float user_clip : CLIP_DISTANCE;
28773 float clip : SV_ClipDistance;
28776 struct patch_constant_data
28778 float edges[4] : SV_TessFactor;
28779 float inside[2] : SV_InsideTessFactor;
28782 patch_constant_data patch_constant()
28784 patch_constant_data output;
28786 output.edges[0] = tessellation_factor;
28787 output.edges[1] = tessellation_factor;
28788 output.edges[2] = tessellation_factor;
28789 output.edges[3] = tessellation_factor;
28790 output.inside[0] = tessellation_factor;
28791 output.inside[1] = tessellation_factor;
28793 return output;
28796 [domain("quad")]
28797 [outputcontrolpoints(4)]
28798 [outputtopology("triangle_cw")]
28799 [partitioning("pow2")]
28800 [patchconstantfunc("patch_constant")]
28801 vertex hs_main(InputPatch<vertex, 4> input,
28802 uint i : SV_OutputControlPointID)
28804 vertex o;
28805 o.position = input[i].position;
28806 o.user_clip = input[i].user_clip;
28807 o.clip = input[i].user_clip;
28808 return o;
28811 float4 interpolate_vec(float4 a, float4 b, float4 c, float4 d, float2 tess_coord)
28813 float4 e = lerp(a, b, tess_coord.x);
28814 float4 f = lerp(c, d, tess_coord.x);
28815 return lerp(e, f, tess_coord.y);
28818 float interpolate(float a, float b, float c, float d, float2 tess_coord)
28820 float e = lerp(a, b, tess_coord.x);
28821 float f = lerp(c, d, tess_coord.x);
28822 return lerp(e, f, tess_coord.y);
28825 [domain("quad")]
28826 vertex ds_main(patch_constant_data input,
28827 float2 tess_coord : SV_DomainLocation,
28828 const OutputPatch<vertex, 4> patch)
28830 vertex output;
28832 output.position = interpolate_vec(patch[0].position, patch[1].position,
28833 patch[2].position, patch[3].position, tess_coord);
28834 output.user_clip = interpolate(patch[0].user_clip, patch[1].user_clip,
28835 patch[2].user_clip, patch[3].user_clip, tess_coord);
28836 output.clip = interpolate(patch[0].clip, patch[1].clip,
28837 patch[2].clip, patch[3].clip, tess_coord);
28838 if (use_constant)
28839 output.clip = clip_distance0;
28841 return output;
28843 #endif
28844 static const DWORD hs_code[] =
28846 0x43425844, 0x5a6d7564, 0x5f30a6c9, 0x2cf3b848, 0x5b4c6dca, 0x00000001, 0x00000414, 0x00000004,
28847 0x00000030, 0x000000b4, 0x00000138, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
28848 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
28849 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
28850 0x00000002, 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
28851 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003,
28852 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c,
28853 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002,
28854 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f,
28855 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc,
28856 0x00000006, 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000e01,
28857 0x00000098, 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000e01, 0x00000098, 0x00000002,
28858 0x0000000b, 0x00000003, 0x00000002, 0x00000e01, 0x00000098, 0x00000003, 0x0000000b, 0x00000003,
28859 0x00000003, 0x00000e01, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000e01,
28860 0x000000a6, 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000e01, 0x545f5653, 0x46737365,
28861 0x6f746361, 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x58454853,
28862 0x00000210, 0x00030050, 0x00000084, 0x01000071, 0x01002093, 0x01002094, 0x01001895, 0x01001096,
28863 0x01001897, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x01000072, 0x0200005f,
28864 0x00016000, 0x0400005f, 0x002010f2, 0x00000004, 0x00000000, 0x0400005f, 0x00201012, 0x00000004,
28865 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x00102012, 0x00000001, 0x03000065,
28866 0x00102012, 0x00000002, 0x02000068, 0x00000001, 0x04000036, 0x00100012, 0x00000000, 0x00016001,
28867 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010000a, 0x00000000, 0x00000000, 0x07000036,
28868 0x00102012, 0x00000001, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x07000036, 0x00102012,
28869 0x00000002, 0x00a0100a, 0x0010000a, 0x00000000, 0x00000001, 0x0100003e, 0x01000073, 0x02000099,
28870 0x00000004, 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000000, 0x0000000b, 0x04000067,
28871 0x00102012, 0x00000001, 0x0000000c, 0x04000067, 0x00102012, 0x00000002, 0x0000000d, 0x04000067,
28872 0x00102012, 0x00000003, 0x0000000e, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000000,
28873 0x00000004, 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x07000036, 0x00902012, 0x0010000a,
28874 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e, 0x01000073, 0x02000099, 0x00000002,
28875 0x0200005f, 0x00017000, 0x04000067, 0x00102012, 0x00000004, 0x0000000f, 0x04000067, 0x00102012,
28876 0x00000005, 0x00000010, 0x02000068, 0x00000001, 0x0400005b, 0x00102012, 0x00000004, 0x00000002,
28877 0x04000036, 0x00100012, 0x00000000, 0x0001700a, 0x08000036, 0x00d02012, 0x00000004, 0x0010000a,
28878 0x00000000, 0x0020803a, 0x00000000, 0x00000000, 0x0100003e,
28880 static const DWORD ds_code[] =
28882 0x43425844, 0xc54dc020, 0x063a9622, 0x6f649eb9, 0xceb1dd36, 0x00000001, 0x0000054c, 0x00000004,
28883 0x00000030, 0x000000b4, 0x00000178, 0x000001fc, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008,
28884 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000,
28885 0x00000000, 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
28886 0x00000002, 0x00000101, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
28887 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x47534350, 0x000000bc, 0x00000006,
28888 0x00000008, 0x00000098, 0x00000000, 0x0000000b, 0x00000003, 0x00000000, 0x00000001, 0x00000098,
28889 0x00000001, 0x0000000b, 0x00000003, 0x00000001, 0x00000001, 0x00000098, 0x00000002, 0x0000000b,
28890 0x00000003, 0x00000002, 0x00000001, 0x00000098, 0x00000003, 0x0000000b, 0x00000003, 0x00000003,
28891 0x00000001, 0x000000a6, 0x00000000, 0x0000000c, 0x00000003, 0x00000004, 0x00000001, 0x000000a6,
28892 0x00000001, 0x0000000c, 0x00000003, 0x00000005, 0x00000001, 0x545f5653, 0x46737365, 0x6f746361,
28893 0x56530072, 0x736e495f, 0x54656469, 0x46737365, 0x6f746361, 0xabab0072, 0x4e47534f, 0x0000007c,
28894 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f,
28895 0x0000005c, 0x00000000, 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000,
28896 0x00000002, 0x00000003, 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43,
28897 0x5349445f, 0x434e4154, 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x58454853,
28898 0x00000348, 0x00040050, 0x000000d2, 0x01002093, 0x01001895, 0x0100086a, 0x04000059, 0x00208e46,
28899 0x00000000, 0x00000001, 0x0200005f, 0x0001c032, 0x0400005f, 0x002190f2, 0x00000004, 0x00000000,
28900 0x0400005f, 0x00219012, 0x00000004, 0x00000001, 0x0400005f, 0x00219012, 0x00000004, 0x00000002,
28901 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067,
28902 0x00102012, 0x00000002, 0x00000002, 0x02000068, 0x00000002, 0x0a000000, 0x001000f2, 0x00000000,
28903 0x80219e46, 0x00000041, 0x00000002, 0x00000000, 0x00219e46, 0x00000003, 0x00000000, 0x09000032,
28904 0x001000f2, 0x00000000, 0x0001c006, 0x00100e46, 0x00000000, 0x00219e46, 0x00000002, 0x00000000,
28905 0x0a000000, 0x001000f2, 0x00000001, 0x80219e46, 0x00000041, 0x00000000, 0x00000000, 0x00219e46,
28906 0x00000001, 0x00000000, 0x09000032, 0x001000f2, 0x00000001, 0x0001c006, 0x00100e46, 0x00000001,
28907 0x00219e46, 0x00000000, 0x00000000, 0x08000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
28908 0x80100e46, 0x00000041, 0x00000001, 0x08000032, 0x001020f2, 0x00000000, 0x0001c556, 0x00100e46,
28909 0x00000000, 0x00100e46, 0x00000001, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041,
28910 0x00000002, 0x00000001, 0x0021900a, 0x00000003, 0x00000001, 0x09000032, 0x00100012, 0x00000000,
28911 0x0001c00a, 0x0010000a, 0x00000000, 0x0021900a, 0x00000002, 0x00000001, 0x0a000000, 0x00100022,
28912 0x00000000, 0x8021900a, 0x00000041, 0x00000000, 0x00000001, 0x0021900a, 0x00000001, 0x00000001,
28913 0x09000032, 0x00100022, 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000,
28914 0x00000001, 0x08000000, 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a,
28915 0x00000000, 0x08000032, 0x00102012, 0x00000001, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a,
28916 0x00000000, 0x0a000000, 0x00100012, 0x00000000, 0x8021900a, 0x00000041, 0x00000002, 0x00000002,
28917 0x0021900a, 0x00000003, 0x00000002, 0x09000032, 0x00100012, 0x00000000, 0x0001c00a, 0x0010000a,
28918 0x00000000, 0x0021900a, 0x00000002, 0x00000002, 0x0a000000, 0x00100022, 0x00000000, 0x8021900a,
28919 0x00000041, 0x00000000, 0x00000002, 0x0021900a, 0x00000001, 0x00000002, 0x09000032, 0x00100022,
28920 0x00000000, 0x0001c00a, 0x0010001a, 0x00000000, 0x0021900a, 0x00000000, 0x00000002, 0x08000000,
28921 0x00100012, 0x00000000, 0x8010001a, 0x00000041, 0x00000000, 0x0010000a, 0x00000000, 0x08000032,
28922 0x00100012, 0x00000000, 0x0001c01a, 0x0010000a, 0x00000000, 0x0010001a, 0x00000000, 0x0b000037,
28923 0x00102012, 0x00000002, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
28924 0x0010000a, 0x00000000, 0x0100003e,
28926 static const DWORD gs_code[] =
28928 #if 0
28929 bool use_constant;
28930 float clip_distance;
28932 struct vertex
28934 float4 position : SV_POSITION;
28935 float user_clip : CLIP_DISTANCE;
28936 float clip : SV_ClipDistance;
28939 [maxvertexcount(3)]
28940 void main(triangle vertex input[3], inout TriangleStream<vertex> output)
28942 vertex o;
28943 o = input[0];
28944 o.clip = input[0].user_clip;
28945 if (use_constant)
28946 o.clip = clip_distance;
28947 output.Append(o);
28948 o = input[1];
28949 o.clip = input[1].user_clip;
28950 if (use_constant)
28951 o.clip = clip_distance;
28952 output.Append(o);
28953 o = input[2];
28954 o.clip = input[2].user_clip;
28955 if (use_constant)
28956 o.clip = clip_distance;
28957 output.Append(o);
28959 #endif
28960 0x43425844, 0x9b0823e9, 0xab3ed100, 0xba0ff618, 0x1bbd1cb8, 0x00000001, 0x00000338, 0x00000003,
28961 0x0000002c, 0x000000b0, 0x00000134, 0x4e475349, 0x0000007c, 0x00000003, 0x00000008, 0x00000050,
28962 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x0000005c, 0x00000000, 0x00000000,
28963 0x00000003, 0x00000001, 0x00000101, 0x0000006a, 0x00000000, 0x00000002, 0x00000003, 0x00000002,
28964 0x00000001, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154, 0x56530045,
28965 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x4e47534f, 0x0000007c, 0x00000003, 0x00000008,
28966 0x00000050, 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x0000005c, 0x00000000,
28967 0x00000000, 0x00000003, 0x00000001, 0x00000e01, 0x0000006a, 0x00000000, 0x00000002, 0x00000003,
28968 0x00000002, 0x00000e01, 0x505f5653, 0x5449534f, 0x004e4f49, 0x50494c43, 0x5349445f, 0x434e4154,
28969 0x56530045, 0x696c435f, 0x73694470, 0x636e6174, 0xabab0065, 0x52444853, 0x000001fc, 0x00020040,
28970 0x0000007f, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x05000061, 0x002010f2, 0x00000003,
28971 0x00000000, 0x00000001, 0x0400005f, 0x00201012, 0x00000003, 0x00000001, 0x0400005f, 0x00201012,
28972 0x00000003, 0x00000002, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
28973 0x00000000, 0x00000001, 0x03000065, 0x00102012, 0x00000001, 0x04000067, 0x00102012, 0x00000002,
28974 0x00000002, 0x0200005e, 0x00000003, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000000,
28975 0x00000000, 0x06000036, 0x00102012, 0x00000001, 0x0020100a, 0x00000000, 0x00000001, 0x0c000037,
28976 0x00100012, 0x00000000, 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000,
28977 0x0020100a, 0x00000000, 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000,
28978 0x01000013, 0x06000036, 0x001020f2, 0x00000000, 0x00201e46, 0x00000001, 0x00000000, 0x06000036,
28979 0x00102012, 0x00000001, 0x0020100a, 0x00000001, 0x00000001, 0x0c000037, 0x00100012, 0x00000000,
28980 0x0020800a, 0x00000000, 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000001,
28981 0x00000001, 0x05000036, 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x06000036,
28982 0x001020f2, 0x00000000, 0x00201e46, 0x00000002, 0x00000000, 0x06000036, 0x00102012, 0x00000001,
28983 0x0020100a, 0x00000002, 0x00000001, 0x0c000037, 0x00100012, 0x00000000, 0x0020800a, 0x00000000,
28984 0x00000000, 0x0020801a, 0x00000000, 0x00000000, 0x0020100a, 0x00000002, 0x00000001, 0x05000036,
28985 0x00102012, 0x00000002, 0x0010000a, 0x00000000, 0x01000013, 0x0100003e,
28987 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
28989 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
28990 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
28991 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
28993 struct
28995 float clip_distance0;
28996 float clip_distance1;
28998 vertices[] =
29000 {1.0f, 1.0f},
29001 {1.0f, 1.0f},
29002 {1.0f, 1.0f},
29003 {1.0f, 1.0f},
29005 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29006 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
29007 struct
29009 BOOL use_constant;
29010 float clip_distance0;
29011 float clip_distance1;
29012 float tessellation_factor;
29013 } cb_data;
29015 if (!init_test_context(&test_context, NULL))
29016 return;
29017 device = test_context.device;
29018 context = test_context.immediate_context;
29019 feature_level = ID3D11Device_GetFeatureLevel(device);
29021 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
29022 vs_code, sizeof(vs_code), &test_context.input_layout);
29023 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
29025 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
29026 stride = sizeof(*vertices);
29027 offset = 0;
29028 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
29030 memset(&cb_data, 0, sizeof(cb_data));
29031 cb_data.tessellation_factor = 1.0f;
29032 vs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29033 ID3D11DeviceContext_VSSetConstantBuffers(context, 0, 1, &vs_cb);
29034 tess_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29035 ID3D11DeviceContext_HSSetConstantBuffers(context, 0, 1, &tess_cb);
29036 ID3D11DeviceContext_DSSetConstantBuffers(context, 0, 1, &tess_cb);
29037 gs_cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29038 ID3D11DeviceContext_GSSetConstantBuffers(context, 0, 1, &gs_cb);
29040 /* vertex shader */
29041 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29042 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29043 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29045 check_clip_distance(&test_context, vb);
29047 cb_data.use_constant = TRUE;
29048 cb_data.clip_distance0 = -1.0f;
29049 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29051 /* tessellation shaders */
29052 if (feature_level >= D3D_FEATURE_LEVEL_11_0)
29054 ID3D11DeviceContext_IASetPrimitiveTopology(context, D3D11_PRIMITIVE_TOPOLOGY_4_CONTROL_POINT_PATCHLIST);
29056 hr = ID3D11Device_CreateHullShader(device, hs_code, sizeof(hs_code), NULL, &hs);
29057 ok(SUCCEEDED(hr), "Failed to create hull shader, hr %#x.\n", hr);
29058 ID3D11DeviceContext_HSSetShader(context, hs, NULL, 0);
29059 hr = ID3D11Device_CreateDomainShader(device, ds_code, sizeof(ds_code), NULL, &ds);
29060 ok(SUCCEEDED(hr), "Failed to create domain shader, hr %#x.\n", hr);
29061 ID3D11DeviceContext_DSSetShader(context, ds, NULL, 0);
29063 check_clip_distance(&test_context, vb);
29065 cb_data.use_constant = FALSE;
29066 cb_data.tessellation_factor = 2.0f;
29067 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
29069 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29070 vertices[i].clip_distance0 = 1.0f;
29071 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29072 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29073 ID3D11DeviceContext_Draw(context, 4, 0);
29074 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29076 cb_data.use_constant = TRUE;
29077 cb_data.clip_distance0 = -1.0f;
29078 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)tess_cb, 0, NULL, &cb_data, 0, 0);
29080 else
29082 skip("Tessellation shaders are not supported.\n");
29085 /* geometry shader */
29086 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
29087 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
29088 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
29090 check_clip_distance(&test_context, vb);
29092 cb_data.use_constant = TRUE;
29093 cb_data.clip_distance0 = 1.0f;
29094 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)gs_cb, 0, NULL, &cb_data, 0, 0);
29095 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29096 ID3D11DeviceContext_Draw(context, 4, 0);
29097 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29099 /* multiple clip distances */
29100 ID3D11DeviceContext_HSSetShader(context, NULL, NULL, 0);
29101 ID3D11DeviceContext_DSSetShader(context, NULL, NULL, 0);
29102 ID3D11DeviceContext_GSSetShader(context, NULL, NULL, 0);
29104 cb_data.use_constant = FALSE;
29105 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29107 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29108 vertices[i].clip_distance0 = 1.0f;
29109 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29110 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29111 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29112 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29114 for (i = 0; i < ARRAY_SIZE(vertices); ++i)
29116 vertices[i].clip_distance0 = i < 2 ? 1.0f : -1.0f;
29117 vertices[i].clip_distance1 = i % 2 ? 1.0f : -1.0f;
29119 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29120 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29121 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29122 get_texture_readback(test_context.backbuffer, 0, &rb);
29123 SetRect(&rect, 0, 0, 320, 240);
29124 check_readback_data_color(&rb, &rect, 0xff00ff00, 1);
29125 SetRect(&rect, 0, 240, 320, 480);
29126 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29127 SetRect(&rect, 320, 0, 640, 480);
29128 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29129 release_resource_readback(&rb);
29131 cb_data.use_constant = TRUE;
29132 cb_data.clip_distance0 = 0.0f;
29133 cb_data.clip_distance1 = 0.0f;
29134 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vs_cb, 0, NULL, &cb_data, 0, 0);
29135 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29136 draw_color_quad_vs(&test_context, &green, vs_multiple_code, sizeof(vs_multiple_code));
29137 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29139 if (hs)
29140 ID3D11HullShader_Release(hs);
29141 if (ds)
29142 ID3D11DomainShader_Release(ds);
29143 ID3D11GeometryShader_Release(gs);
29144 ID3D11Buffer_Release(vb);
29145 ID3D11Buffer_Release(vs_cb);
29146 ID3D11Buffer_Release(tess_cb);
29147 ID3D11Buffer_Release(gs_cb);
29148 release_test_context(&test_context);
29151 static void test_combined_clip_and_cull_distances(void)
29153 struct d3d11_test_context test_context;
29154 ID3D11DeviceContext *context;
29155 struct resource_readback rb;
29156 unsigned int offset, stride;
29157 ID3D11Device *device;
29158 unsigned int i, j, k;
29159 ID3D11Buffer *vb;
29160 HRESULT hr;
29162 static const DWORD vs_code[] =
29164 #if 0
29165 struct input
29167 float4 position : POSITION;
29168 float clip0 : CLIP_DISTANCE0;
29169 float clip1 : CLIP_DISTANCE1;
29170 float clip2 : CLIP_DISTANCE2;
29171 float clip3 : CLIP_DISTANCE3;
29172 float cull0 : CULL_DISTANCE0;
29173 float cull1 : CULL_DISTANCE1;
29174 float cull2 : CULL_DISTANCE2;
29175 float cull3 : CULL_DISTANCE3;
29178 struct vertex
29180 float4 position : SV_Position;
29181 float3 clip0 : SV_ClipDistance1;
29182 float3 cull0 : SV_CullDistance1;
29183 float clip1 : SV_ClipDistance2;
29184 float cull1 : SV_CullDistance2;
29187 void main(input vin, out vertex vertex)
29189 vertex.position = vin.position;
29190 vertex.clip0 = float3(vin.clip0, vin.clip1, vin.clip2);
29191 vertex.cull0 = float3(vin.cull0, vin.cull1, vin.cull2);
29192 vertex.clip1 = vin.clip3;
29193 vertex.cull1 = vin.cull3;
29195 #endif
29196 0x43425844, 0xa24fb3ea, 0x92e2c2b0, 0xb599b1b9, 0xd671f830, 0x00000001, 0x00000374, 0x00000003,
29197 0x0000002c, 0x0000013c, 0x000001f0, 0x4e475349, 0x00000108, 0x00000009, 0x00000008, 0x000000e0,
29198 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x00000f0f, 0x000000e9, 0x00000000, 0x00000000,
29199 0x00000003, 0x00000001, 0x00000101, 0x000000e9, 0x00000001, 0x00000000, 0x00000003, 0x00000002,
29200 0x00000101, 0x000000e9, 0x00000002, 0x00000000, 0x00000003, 0x00000003, 0x00000101, 0x000000e9,
29201 0x00000003, 0x00000000, 0x00000003, 0x00000004, 0x00000101, 0x000000f7, 0x00000000, 0x00000000,
29202 0x00000003, 0x00000005, 0x00000101, 0x000000f7, 0x00000001, 0x00000000, 0x00000003, 0x00000006,
29203 0x00000101, 0x000000f7, 0x00000002, 0x00000000, 0x00000003, 0x00000007, 0x00000101, 0x000000f7,
29204 0x00000003, 0x00000000, 0x00000003, 0x00000008, 0x00000101, 0x49534f50, 0x4e4f4954, 0x494c4300,
29205 0x49445f50, 0x4e415453, 0x43004543, 0x5f4c4c55, 0x54534944, 0x45434e41, 0xababab00, 0x4e47534f,
29206 0x000000ac, 0x00000005, 0x00000008, 0x00000080, 0x00000000, 0x00000001, 0x00000003, 0x00000000,
29207 0x0000000f, 0x0000008c, 0x00000000, 0x00000002, 0x00000003, 0x00000001, 0x00000807, 0x0000008c,
29208 0x00000001, 0x00000002, 0x00000003, 0x00000001, 0x00000708, 0x0000009c, 0x00000000, 0x00000003,
29209 0x00000003, 0x00000002, 0x00000807, 0x0000009c, 0x00000001, 0x00000003, 0x00000003, 0x00000002,
29210 0x00000708, 0x505f5653, 0x7469736f, 0x006e6f69, 0x435f5653, 0x4470696c, 0x61747369, 0x0065636e,
29211 0x435f5653, 0x446c6c75, 0x61747369, 0x0065636e, 0x52444853, 0x0000017c, 0x00010040, 0x0000005f,
29212 0x0300005f, 0x001010f2, 0x00000000, 0x0300005f, 0x00101012, 0x00000001, 0x0300005f, 0x00101012,
29213 0x00000002, 0x0300005f, 0x00101012, 0x00000003, 0x0300005f, 0x00101012, 0x00000004, 0x0300005f,
29214 0x00101012, 0x00000005, 0x0300005f, 0x00101012, 0x00000006, 0x0300005f, 0x00101012, 0x00000007,
29215 0x0300005f, 0x00101012, 0x00000008, 0x04000067, 0x001020f2, 0x00000000, 0x00000001, 0x04000067,
29216 0x00102072, 0x00000001, 0x00000002, 0x04000067, 0x00102082, 0x00000001, 0x00000002, 0x04000067,
29217 0x00102072, 0x00000002, 0x00000003, 0x04000067, 0x00102082, 0x00000002, 0x00000003, 0x05000036,
29218 0x001020f2, 0x00000000, 0x00101e46, 0x00000000, 0x05000036, 0x00102012, 0x00000001, 0x0010100a,
29219 0x00000001, 0x05000036, 0x00102022, 0x00000001, 0x0010100a, 0x00000002, 0x05000036, 0x00102042,
29220 0x00000001, 0x0010100a, 0x00000003, 0x05000036, 0x00102082, 0x00000001, 0x0010100a, 0x00000004,
29221 0x05000036, 0x00102012, 0x00000002, 0x0010100a, 0x00000005, 0x05000036, 0x00102022, 0x00000002,
29222 0x0010100a, 0x00000006, 0x05000036, 0x00102042, 0x00000002, 0x0010100a, 0x00000007, 0x05000036,
29223 0x00102082, 0x00000002, 0x0010100a, 0x00000008, 0x0100003e,
29225 static const D3D11_INPUT_ELEMENT_DESC layout_desc[] =
29227 {"POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29228 {"CLIP_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
29229 {"CLIP_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 4, D3D11_INPUT_PER_VERTEX_DATA, 0},
29230 {"CLIP_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 8, D3D11_INPUT_PER_VERTEX_DATA, 0},
29231 {"CLIP_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
29232 {"CULL_DISTANCE", 0, DXGI_FORMAT_R32_FLOAT, 1, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},
29233 {"CULL_DISTANCE", 1, DXGI_FORMAT_R32_FLOAT, 1, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
29234 {"CULL_DISTANCE", 2, DXGI_FORMAT_R32_FLOAT, 1, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},
29235 {"CULL_DISTANCE", 3, DXGI_FORMAT_R32_FLOAT, 1, 28, D3D11_INPUT_PER_VERTEX_DATA, 0},
29237 struct
29239 float clip_distance[4];
29240 float cull_distance[4];
29242 vertices[4] =
29244 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29245 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29246 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29247 {{1.0f, 1.0f, 1.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}},
29249 static const struct test
29251 float vertices[4];
29252 BOOL triangle_visible[2];
29254 cull_distance_tests[] =
29256 {{-1.0f, 1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29257 {{ 1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29258 {{ 1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29259 {{-1.0f, -1.0f, 1.0f, 1.0f}, {TRUE, TRUE}},
29260 {{-1.0f, 1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
29261 {{-1.0f, 1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29262 {{ 1.0f, -1.0f, -1.0f, 1.0f}, {TRUE, TRUE}},
29263 {{ 1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29264 {{ 1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
29266 {{-1.0f, -1.0f, -1.0f, 1.0f}, {FALSE, TRUE}},
29267 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29268 {{-1.0f, -1.0f, 1.0f, -1.0f}, {TRUE, TRUE}},
29269 {{-1.0f, 1.0f, -1.0f, -1.0f}, {TRUE, TRUE}},
29270 {{ 1.0f, -1.0f, -1.0f, -1.0f}, {TRUE, FALSE}},
29272 {{-1.0f, -1.0f, -1.0f, -1.0f}, {FALSE, FALSE}},
29274 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29275 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
29277 if (!init_test_context(&test_context, NULL))
29278 return;
29279 device = test_context.device;
29280 context = test_context.immediate_context;
29282 hr = ID3D11Device_CreateInputLayout(device, layout_desc, ARRAY_SIZE(layout_desc),
29283 vs_code, sizeof(vs_code), &test_context.input_layout);
29284 ok(SUCCEEDED(hr), "Failed to create input layout, hr %#x.\n", hr);
29286 vb = create_buffer(device, D3D11_BIND_VERTEX_BUFFER, sizeof(vertices), vertices);
29287 stride = sizeof(*vertices);
29288 offset = 0;
29289 ID3D11DeviceContext_IASetVertexBuffers(context, 1, 1, &vb, &stride, &offset);
29291 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29292 draw_color_quad(&test_context, &green);
29293 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29295 for (i = 0; i < ARRAY_SIZE(vertices->cull_distance); ++i)
29297 for (j = 0; j < ARRAY_SIZE(cull_distance_tests); ++j)
29299 const struct test *test = &cull_distance_tests[j];
29300 unsigned int expected_color[ARRAY_SIZE(test->triangle_visible)];
29301 unsigned int color;
29303 for (k = 0; k < ARRAY_SIZE(vertices); ++k)
29304 vertices[k].cull_distance[i] = test->vertices[k];
29305 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29307 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29308 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29310 for (k = 0; k < ARRAY_SIZE(expected_color); ++k)
29311 expected_color[k] = test->triangle_visible[k] ? 0xff00ff00 : 0xffffffff;
29313 if (expected_color[0] == expected_color[1])
29315 check_texture_color(test_context.backbuffer, *expected_color, 1);
29317 else
29319 get_texture_readback(test_context.backbuffer, 0, &rb);
29320 color = get_readback_color(&rb, 160, 240, 0);
29321 ok(color == expected_color[0], "Got unexpected color 0x%08x.\n", color);
29322 color = get_readback_color(&rb, 480, 240, 0);
29323 ok(color == expected_color[1], "Got unexpected color 0x%08x.\n", color);
29324 release_resource_readback(&rb);
29328 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29329 vertices[j].cull_distance[i] = 1.0f;
29332 for (i = 0; i < ARRAY_SIZE(vertices->clip_distance); ++i)
29334 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29335 vertices[j].clip_distance[i] = -1.0f;
29336 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29338 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29339 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29340 check_texture_color(test_context.backbuffer, 0xffffffff, 1);
29342 for (j = 0; j < ARRAY_SIZE(vertices); ++j)
29343 vertices[j].clip_distance[i] = 1.0f;
29346 memset(vertices, 0, sizeof(vertices));
29347 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)vb, 0, NULL, vertices, 0, 0);
29348 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
29349 draw_color_quad_vs(&test_context, &green, vs_code, sizeof(vs_code));
29350 check_texture_color(test_context.backbuffer, 0xff00ff00, 1);
29352 ID3D11Buffer_Release(vb);
29353 release_test_context(&test_context);
29356 static void test_generate_mips(void)
29358 static const DWORD ps_code[] =
29360 #if 0
29361 Texture2D t;
29362 SamplerState s;
29364 float4 main(float4 position : SV_POSITION) : SV_Target
29366 float2 p;
29368 p.x = position.x / 640.0f;
29369 p.y = position.y / 480.0f;
29370 return t.Sample(s, p);
29372 #endif
29373 0x43425844, 0x1ce9b612, 0xc8176faa, 0xd37844af, 0xdb515605, 0x00000001, 0x00000134, 0x00000003,
29374 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29375 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
29376 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
29377 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000098, 0x00000040,
29378 0x00000026, 0x0300005a, 0x00106000, 0x00000000, 0x04001858, 0x00107000, 0x00000000, 0x00005555,
29379 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
29380 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
29381 0x3b088889, 0x00000000, 0x00000000, 0x09000045, 0x001020f2, 0x00000000, 0x00100046, 0x00000000,
29382 0x00107e46, 0x00000000, 0x00106000, 0x00000000, 0x0100003e,
29384 static const DWORD ps_code_3d[] =
29386 #if 0
29387 Texture3D t;
29388 SamplerState s;
29390 float4 main(float4 position : SV_POSITION) : SV_Target
29392 float3 p;
29394 p.x = position.x / 640.0f;
29395 p.y = position.y / 480.0f;
29396 p.z = 0.5f;
29397 return t.Sample(s, p);
29399 #endif
29400 0x43425844, 0xa1e26083, 0xeb45763e, 0x1e5a5089, 0xdfbbe0df, 0x00000001, 0x00000148, 0x00000003,
29401 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29402 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
29403 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
29404 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x000000ac, 0x00000040,
29405 0x0000002b, 0x0300005a, 0x00106000, 0x00000000, 0x04002858, 0x00107000, 0x00000000, 0x00005555,
29406 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
29407 0x00000001, 0x0a000038, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00004002, 0x3acccccd,
29408 0x3b088889, 0x00000000, 0x00000000, 0x05000036, 0x00100042, 0x00000000, 0x00004001, 0x3f000000,
29409 0x09000045, 0x001020f2, 0x00000000, 0x00100246, 0x00000000, 0x00107e46, 0x00000000, 0x00106000,
29410 0x00000000, 0x0100003e,
29412 static const struct
29414 D3D11_RESOURCE_DIMENSION dim;
29415 D3D11_SRV_DIMENSION srv_dim;
29416 unsigned int array_size;
29418 resource_types[] =
29420 {D3D11_RESOURCE_DIMENSION_BUFFER, D3D11_SRV_DIMENSION_BUFFER, 1},
29421 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2D, 1},
29422 {D3D11_RESOURCE_DIMENSION_TEXTURE2D, D3D11_SRV_DIMENSION_TEXTURE2DARRAY, 4},
29423 {D3D11_RESOURCE_DIMENSION_TEXTURE3D, D3D11_SRV_DIMENSION_TEXTURE3D, 1},
29425 static const struct
29427 DXGI_FORMAT texture_format;
29428 UINT bind_flags;
29429 UINT misc_flags;
29430 BOOL null_srv;
29431 UINT base_level;
29432 BOOL expected_creation;
29433 BOOL expected_mips;
29435 tests[] =
29437 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
29438 0, TRUE, FALSE},
29439 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, TRUE,
29440 0, TRUE, FALSE},
29441 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
29442 0, TRUE, FALSE},
29443 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, 0, FALSE,
29444 0, TRUE, FALSE},
29445 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29446 0, FALSE, FALSE},
29447 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29448 0, FALSE, FALSE},
29449 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29450 0, TRUE, TRUE},
29451 {DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29452 1, TRUE, TRUE},
29453 {DXGI_FORMAT_R8G8B8A8_TYPELESS, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, FALSE,
29454 1, TRUE, TRUE},
29455 {DXGI_FORMAT_R8G8B8A8_UINT, D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, D3D11_RESOURCE_MISC_GENERATE_MIPS, TRUE,
29456 1, TRUE, FALSE},
29458 static const struct
29460 POINT pos;
29461 DWORD color;
29463 expected[] =
29465 {{200, 200}, 0xffff0000},
29466 {{280, 200}, 0xffff0000},
29467 {{360, 200}, 0xff00ff00},
29468 {{440, 200}, 0xff00ff00},
29469 {{200, 270}, 0xff0000ff},
29470 {{280, 270}, 0xff0000ff},
29471 {{360, 270}, 0xff000000},
29472 {{440, 270}, 0xff000000},
29474 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
29475 static const RECT r1 = {8, 8, 16, 16};
29476 static const RECT r2 = {16, 8, 24, 16};
29477 static const RECT r3 = {8, 16, 16, 24};
29478 static const RECT r4 = {16, 16, 24, 24};
29479 DWORD *data, *zero_data, color, expected_color;
29480 ID3D11ShaderResourceView *srv, *srv_sampling;
29481 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc;
29482 struct d3d11_test_context test_context;
29483 D3D11_TEXTURE2D_DESC texture2d_desc;
29484 D3D11_TEXTURE3D_DESC texture3d_desc;
29485 ID3D11SamplerState *sampler_state;
29486 D3D11_SAMPLER_DESC sampler_desc;
29487 D3D11_BUFFER_DESC buffer_desc;
29488 unsigned int i, j, k, x, y, z;
29489 ID3D11PixelShader *ps, *ps_3d;
29490 ID3D11DeviceContext *context;
29491 struct resource_readback rb;
29492 ID3D11Resource *resource;
29493 ID3D11Device *device;
29494 HRESULT hr;
29496 if (!init_test_context(&test_context, NULL))
29497 return;
29499 device = test_context.device;
29500 context = test_context.immediate_context;
29502 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
29503 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29505 hr = ID3D11Device_CreatePixelShader(device, ps_code_3d, sizeof(ps_code_3d), NULL, &ps_3d);
29506 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29508 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
29509 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
29510 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
29511 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
29512 sampler_desc.MipLODBias = 0.0f;
29513 sampler_desc.MaxAnisotropy = 0;
29514 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
29515 sampler_desc.BorderColor[0] = 0.0f;
29516 sampler_desc.BorderColor[1] = 0.0f;
29517 sampler_desc.BorderColor[2] = 0.0f;
29518 sampler_desc.BorderColor[3] = 0.0f;
29519 sampler_desc.MinLOD = 0.0f;
29520 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
29522 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler_state);
29523 ok(SUCCEEDED(hr), "Failed to create sampler state, hr %#x.\n", hr);
29524 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler_state);
29526 data = heap_alloc(sizeof(*data) * 32 * 32 * 32);
29528 for (z = 0; z < 32; ++z)
29530 for (y = 0; y < 32; ++y)
29532 for (x = 0; x < 32; ++x)
29534 DWORD *dst = &data[z * 32 * 32 + y * 32 + x];
29535 POINT pt;
29537 pt.x = x;
29538 pt.y = y;
29539 if (PtInRect(&r1, pt))
29540 *dst = 0xffff0000;
29541 else if (PtInRect(&r2, pt))
29542 *dst = 0xff00ff00;
29543 else if (PtInRect(&r3, pt))
29544 *dst = 0xff0000ff;
29545 else if (PtInRect(&r4, pt))
29546 *dst = 0xff000000;
29547 else
29548 *dst = 0xffffffff;
29553 zero_data = heap_alloc_zero(sizeof(*zero_data) * 16 * 16 * 16);
29555 for (i = 0; i < ARRAY_SIZE(resource_types); ++i)
29557 for (j = 0; j < ARRAY_SIZE(tests); ++j)
29559 unsigned int base_multiplier = 1u << tests[j].base_level;
29561 if (is_warp_device(device) && tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT)
29563 /* Testing this format seems to break the WARP device. */
29564 skip("Skipping test with DXGI_FORMAT_R8G8B8A8_UINT on WARP.\n");
29565 continue;
29568 switch (resource_types[i].dim)
29570 case D3D11_RESOURCE_DIMENSION_BUFFER:
29571 buffer_desc.ByteWidth = 32 * base_multiplier;
29572 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
29573 buffer_desc.BindFlags = tests[j].bind_flags;
29574 buffer_desc.CPUAccessFlags = 0;
29575 buffer_desc.MiscFlags = tests[j].misc_flags;
29576 buffer_desc.StructureByteStride = 0;
29578 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL,
29579 (ID3D11Buffer **)&resource);
29580 break;
29581 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
29582 texture2d_desc.Width = 32 * base_multiplier;
29583 texture2d_desc.Height = 32 * base_multiplier;
29584 texture2d_desc.MipLevels = 0;
29585 texture2d_desc.ArraySize = resource_types[i].array_size;
29586 texture2d_desc.Format = tests[j].texture_format;
29587 texture2d_desc.SampleDesc.Count = 1;
29588 texture2d_desc.SampleDesc.Quality = 0;
29589 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
29590 texture2d_desc.BindFlags = tests[j].bind_flags;
29591 texture2d_desc.CPUAccessFlags = 0;
29592 texture2d_desc.MiscFlags = tests[j].misc_flags;
29594 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL,
29595 (ID3D11Texture2D **)&resource);
29596 break;
29597 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
29598 texture3d_desc.Width = 32 * base_multiplier;
29599 texture3d_desc.Height = 32 * base_multiplier;
29600 texture3d_desc.Depth = 32 * base_multiplier;
29601 texture3d_desc.MipLevels = 0;
29602 texture3d_desc.Format = tests[j].texture_format;
29603 texture3d_desc.Usage = D3D11_USAGE_DEFAULT;
29604 texture3d_desc.BindFlags = tests[j].bind_flags;
29605 texture3d_desc.CPUAccessFlags = 0;
29606 texture3d_desc.MiscFlags = tests[j].misc_flags;
29608 hr = ID3D11Device_CreateTexture3D(device, &texture3d_desc, NULL,
29609 (ID3D11Texture3D **)&resource);
29610 break;
29611 default:
29612 break;
29614 if (tests[j].expected_creation && (resource_types[i].dim != D3D11_RESOURCE_DIMENSION_BUFFER
29615 || !(tests[j].misc_flags & D3D11_RESOURCE_MISC_GENERATE_MIPS)))
29617 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create resource, hr %#x.\n", i, j, hr);
29619 else
29621 ok(hr == E_INVALIDARG, "Resource type %u, test %u: unexpectedly succeeded "
29622 "to create resource, hr %#x.\n", i, j, hr);
29623 continue;
29626 if (tests[j].null_srv)
29628 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
29630 else
29632 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29633 srv_desc.ViewDimension = resource_types[i].srv_dim;
29634 switch (resource_types[i].srv_dim)
29636 case D3D11_SRV_DIMENSION_BUFFER:
29637 srv_desc.Buffer.ElementOffset = 0;
29638 srv_desc.Buffer.ElementWidth = 0;
29639 break;
29640 case D3D11_SRV_DIMENSION_TEXTURE2D:
29641 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level;
29642 srv_desc.Texture2D.MipLevels = ~0u;
29643 break;
29644 case D3D11_SRV_DIMENSION_TEXTURE2DARRAY:
29645 srv_desc.Texture2DArray.MostDetailedMip = tests[j].base_level;
29646 srv_desc.Texture2DArray.MipLevels = ~0u;
29647 srv_desc.Texture2DArray.FirstArraySlice = 0;
29648 srv_desc.Texture2DArray.ArraySize = resource_types[i].array_size;
29649 break;
29650 case D3D11_SRV_DIMENSION_TEXTURE3D:
29651 srv_desc.Texture3D.MostDetailedMip = tests[j].base_level;
29652 srv_desc.Texture3D.MipLevels = ~0u;
29653 break;
29654 default:
29655 break;
29657 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
29659 if (resource_types[i].dim == D3D11_RESOURCE_DIMENSION_BUFFER)
29661 ok(FAILED(hr), "Test %u: unexpectedly succeeded to create shader resource view, "
29662 "hr %#x.\n", j, hr);
29663 ID3D11Resource_Release(resource);
29664 continue;
29666 else
29668 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create "
29669 "shader resource view, hr %#x.\n", i, j, hr);
29672 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level,
29673 NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
29674 ID3D11DeviceContext_UpdateSubresource(context, resource, tests[j].base_level + 1,
29675 NULL, zero_data, sizeof(*zero_data) * 16, sizeof(*zero_data) * 16 * 16);
29677 ID3D11DeviceContext_GenerateMips(context, srv);
29679 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.x);
29681 srv_desc.Format = tests[j].texture_format == DXGI_FORMAT_R8G8B8A8_UINT
29682 ? DXGI_FORMAT_R8G8B8A8_UINT : DXGI_FORMAT_R8G8B8A8_UNORM;
29683 srv_desc.ViewDimension = resource_types[i].dim == D3D11_RESOURCE_DIMENSION_TEXTURE3D
29684 ? D3D11_SRV_DIMENSION_TEXTURE3D : D3D11_SRV_DIMENSION_TEXTURE2D;
29685 srv_desc.Texture2D.MostDetailedMip = tests[j].base_level + 1;
29686 srv_desc.Texture2D.MipLevels = ~0u;
29687 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
29688 ok(SUCCEEDED(hr), "Resource type %u, test %u: failed to create shader resource view, "
29689 "hr %#x.\n", i, j, hr);
29690 ID3D11DeviceContext_PSSetShader(context, resource_types[i].dim
29691 == D3D11_RESOURCE_DIMENSION_TEXTURE3D ? ps_3d : ps, NULL, 0);
29692 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
29694 draw_quad(&test_context);
29696 get_texture_readback(test_context.backbuffer, 0, &rb);
29697 for (k = 0; k < ARRAY_SIZE(expected); ++k)
29699 color = get_readback_color(&rb, expected[k].pos.x, expected[k].pos.y, 0);
29700 expected_color = tests[j].expected_mips ? expected[k].color : 0;
29701 ok(color == expected_color, "Resource type %u, test %u: pixel (%u, %u) "
29702 "has color %08x, expected %08x.\n",
29703 i, j, expected[k].pos.x, expected[k].pos.y, color, expected_color);
29705 release_resource_readback(&rb);
29707 ID3D11ShaderResourceView_Release(srv_sampling);
29708 ID3D11ShaderResourceView_Release(srv);
29709 ID3D11Resource_Release(resource);
29713 /* Test the effect of sRGB views. */
29714 for (y = 0; y < 32; ++y)
29716 for (x = 0; x < 32; ++x)
29718 DWORD *dst = &data[y * 32 + x];
29720 *dst = (x + y) % 2 * 0xffffffff;
29723 texture2d_desc.Width = 32;
29724 texture2d_desc.Height = 32;
29725 texture2d_desc.MipLevels = 0;
29726 texture2d_desc.ArraySize = 1;
29727 texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_TYPELESS;
29728 texture2d_desc.SampleDesc.Count = 1;
29729 texture2d_desc.SampleDesc.Quality = 0;
29730 texture2d_desc.Usage = D3D11_USAGE_DEFAULT;
29731 texture2d_desc.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE;
29732 texture2d_desc.CPUAccessFlags = 0;
29733 texture2d_desc.MiscFlags = D3D11_RESOURCE_MISC_GENERATE_MIPS;
29735 hr = ID3D11Device_CreateTexture2D(device, &texture2d_desc, NULL, (ID3D11Texture2D **)&resource);
29736 ok(SUCCEEDED(hr), "Failed to create resource, hr %#x.\n", hr);
29737 hr = ID3D11Device_CreateShaderResourceView(device, resource, NULL, &srv);
29738 ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr);
29739 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
29740 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29741 srv_desc.Texture2D.MostDetailedMip = 0;
29742 srv_desc.Texture2D.MipLevels = ~0u;
29743 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
29744 ID3D11DeviceContext_UpdateSubresource(context, resource,
29745 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
29747 ID3D11DeviceContext_GenerateMips(context, srv);
29749 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
29751 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29752 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29753 srv_desc.Texture2D.MostDetailedMip = 1;
29754 srv_desc.Texture2D.MipLevels = ~0u;
29755 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
29756 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
29757 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29758 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
29760 draw_quad(&test_context);
29762 get_texture_readback(test_context.backbuffer, 0, &rb);
29763 color = get_readback_color(&rb, 320, 240, 0);
29764 ok(compare_color(color, 0x7fbcbcbc, 1) || broken(compare_color(color, 0x7f7f7f7f, 1)), /* AMD */
29765 "Unexpected color %08x.\n", color);
29766 release_resource_readback(&rb);
29768 ID3D11ShaderResourceView_Release(srv_sampling);
29769 ID3D11ShaderResourceView_Release(srv);
29771 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29772 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29773 srv_desc.Texture2D.MostDetailedMip = 0;
29774 srv_desc.Texture2D.MipLevels = ~0u;
29775 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv);
29776 ID3D11DeviceContext_UpdateSubresource(context, resource,
29777 0, NULL, data, sizeof(*data) * 32, sizeof(*data) * 32 * 32);
29779 ID3D11DeviceContext_GenerateMips(context, srv);
29781 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, &white.w);
29783 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
29784 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
29785 srv_desc.Texture2D.MostDetailedMip = 1;
29786 srv_desc.Texture2D.MipLevels = ~0u;
29787 hr = ID3D11Device_CreateShaderResourceView(device, resource, &srv_desc, &srv_sampling);
29788 ok(SUCCEEDED(hr), "Failed to create shader resource view, hr %#x.\n", hr);
29789 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29790 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_sampling);
29792 draw_quad(&test_context);
29794 get_texture_readback(test_context.backbuffer, 0, &rb);
29795 check_readback_data_color(&rb, NULL, 0x7f7f7f7f, 1);
29796 release_resource_readback(&rb);
29798 ID3D11ShaderResourceView_Release(srv_sampling);
29799 ID3D11ShaderResourceView_Release(srv);
29801 ID3D11Resource_Release(resource);
29803 heap_free(zero_data);
29804 heap_free(data);
29806 ID3D11SamplerState_Release(sampler_state);
29807 ID3D11PixelShader_Release(ps_3d);
29808 ID3D11PixelShader_Release(ps);
29809 release_test_context(&test_context);
29812 static void test_alpha_to_coverage(void)
29814 struct ps_cb
29816 struct vec2 top;
29817 struct vec2 bottom;
29818 float alpha[2];
29819 float padding[2];
29822 struct d3d11_test_context test_context;
29823 ID3D11Texture2D *render_targets[3];
29824 D3D11_TEXTURE2D_DESC texture_desc;
29825 ID3D11Texture2D *readback_texture;
29826 ID3D11RenderTargetView *rtvs[3];
29827 ID3D11BlendState *blend_state;
29828 ID3D11DeviceContext *context;
29829 D3D11_BLEND_DESC blend_desc;
29830 struct resource_readback rb;
29831 UINT quality_level_count;
29832 ID3D11PixelShader *ps;
29833 struct ps_cb cb_data;
29834 ID3D11Device *device;
29835 ID3D11Buffer *cb;
29836 unsigned int i;
29837 HRESULT hr;
29838 RECT rect;
29840 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
29841 static const DWORD ps_code[] =
29843 #if 0
29844 float2 top;
29845 float2 bottom;
29846 float alpha1;
29847 float alpha2;
29849 void main(float4 position : SV_Position,
29850 out float4 target0 : SV_Target0,
29851 out float4 target1 : SV_Target1,
29852 out float4 target2 : SV_Target2)
29854 float alpha = all(top <= position.xy) && all(position.xy <= bottom) ? 1.0f : 0.0f;
29855 target0 = float4(0.0f, 1.0f, 0.0f, alpha);
29856 target1 = float4(0.0f, 0.0f, 1.0f, alpha1);
29857 target2 = float4(0.0f, 1.0f, 0.0f, alpha2);
29859 #endif
29860 0x43425844, 0x771ff802, 0xca927279, 0x5bdd75ae, 0xf53cb31b, 0x00000001, 0x00000264, 0x00000003,
29861 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
29862 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
29863 0x4e47534f, 0x0000005c, 0x00000003, 0x00000008, 0x00000050, 0x00000000, 0x00000000, 0x00000003,
29864 0x00000000, 0x0000000f, 0x00000050, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
29865 0x00000050, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x545f5653, 0x65677261,
29866 0xabab0074, 0x52444853, 0x00000198, 0x00000040, 0x00000066, 0x04000059, 0x00208e46, 0x00000000,
29867 0x00000002, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
29868 0x03000065, 0x001020f2, 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x02000068, 0x00000001,
29869 0x0800001d, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00208046, 0x00000000, 0x00000000,
29870 0x07000001, 0x00100012, 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0800001d,
29871 0x00100062, 0x00000000, 0x00208ba6, 0x00000000, 0x00000000, 0x00101106, 0x00000000, 0x07000001,
29872 0x00100022, 0x00000000, 0x0010002a, 0x00000000, 0x0010001a, 0x00000000, 0x07000001, 0x00100012,
29873 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x07000001, 0x00102082, 0x00000000,
29874 0x0010000a, 0x00000000, 0x00004001, 0x3f800000, 0x08000036, 0x00102072, 0x00000000, 0x00004002,
29875 0x00000000, 0x3f800000, 0x00000000, 0x00000000, 0x08000036, 0x00102072, 0x00000001, 0x00004002,
29876 0x00000000, 0x00000000, 0x3f800000, 0x00000000, 0x06000036, 0x00102082, 0x00000001, 0x0020800a,
29877 0x00000000, 0x00000001, 0x08000036, 0x00102072, 0x00000002, 0x00004002, 0x00000000, 0x3f800000,
29878 0x00000000, 0x00000000, 0x06000036, 0x00102082, 0x00000002, 0x0020801a, 0x00000000, 0x00000001,
29879 0x0100003e,
29881 static const DWORD colors[] = {0xff00ff00, 0xbfff0000, 0x8000ff00};
29883 if (!init_test_context(&test_context, NULL))
29884 return;
29885 device = test_context.device;
29886 context = test_context.immediate_context;
29888 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
29889 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
29890 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
29892 memset(&blend_desc, 0, sizeof(blend_desc));
29893 blend_desc.AlphaToCoverageEnable = TRUE;
29894 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
29895 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
29896 ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr);
29897 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
29899 render_targets[0] = test_context.backbuffer;
29900 rtvs[0] = test_context.backbuffer_rtv;
29901 for (i = 1; i < ARRAY_SIZE(render_targets); ++i)
29903 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29904 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
29905 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29906 hr = ID3D11Device_CreateRenderTargetView(device,
29907 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
29908 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
29910 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
29912 cb_data.top.x = cb_data.top.y = 0.0f;
29913 cb_data.bottom.x = cb_data.bottom.y = 200.0f;
29914 cb_data.alpha[0] = 0.75;
29915 cb_data.alpha[1] = 0.5f;
29916 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
29917 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
29919 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
29920 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
29921 draw_quad(&test_context);
29922 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
29924 DWORD expected_color;
29926 assert(i < ARRAY_SIZE(colors));
29927 expected_color = colors[i];
29928 get_texture_readback(render_targets[i], 0, &rb);
29929 SetRect(&rect, 0, 0, 200, 200);
29930 check_readback_data_color(&rb, &rect, expected_color, 1);
29931 SetRect(&rect, 200, 0, 640, 200);
29932 todo_wine
29933 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29934 SetRect(&rect, 0, 200, 640, 480);
29935 todo_wine
29936 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29937 release_resource_readback(&rb);
29939 if (i > 0)
29940 ID3D11Texture2D_Release(render_targets[i]);
29941 render_targets[i] = NULL;
29944 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29945 texture_desc.Format = DXGI_FORMAT_R16G16_UNORM;
29946 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[0]);
29947 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29948 hr = ID3D11Device_CreateRenderTargetView(device,
29949 (ID3D11Resource *)render_targets[0], NULL, &rtvs[0]);
29950 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
29951 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
29953 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[0], white);
29954 draw_quad(&test_context);
29955 get_texture_readback(render_targets[0], 0, &rb);
29956 SetRect(&rect, 0, 0, 200, 200);
29957 check_readback_data_color(&rb, &rect, 0xffff0000, 1);
29958 SetRect(&rect, 200, 0, 640, 200);
29959 todo_wine
29960 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29961 SetRect(&rect, 0, 200, 640, 480);
29962 todo_wine
29963 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
29964 release_resource_readback(&rb);
29966 ID3D11Texture2D_Release(render_targets[0]);
29967 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
29968 ID3D11RenderTargetView_Release(rtvs[i]);
29970 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
29971 hr = ID3D11Device_CheckMultisampleQualityLevels(device,
29972 texture_desc.Format, 4, &quality_level_count);
29973 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
29974 if (!quality_level_count)
29976 skip("4xMSAA not supported.\n");
29977 goto done;
29979 texture_desc.SampleDesc.Count = 4;
29980 texture_desc.SampleDesc.Quality = 0;
29982 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
29984 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &render_targets[i]);
29985 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29986 hr = ID3D11Device_CreateRenderTargetView(device,
29987 (ID3D11Resource *)render_targets[i], NULL, &rtvs[i]);
29988 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
29990 ID3D11DeviceContext_OMSetRenderTargets(context, ARRAY_SIZE(rtvs), rtvs, NULL);
29992 for (i = 0; i < ARRAY_SIZE(rtvs); ++i)
29993 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], white);
29994 draw_quad(&test_context);
29995 texture_desc.SampleDesc.Count = 1;
29996 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &readback_texture);
29997 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
29998 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
30000 DWORD expected_color;
30002 assert(i < ARRAY_SIZE(colors));
30003 expected_color = colors[i];
30005 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)readback_texture, 0,
30006 (ID3D11Resource *)render_targets[i], 0, texture_desc.Format);
30008 get_texture_readback(readback_texture, 0, &rb);
30009 SetRect(&rect, 0, 0, 200, 200);
30010 check_readback_data_color(&rb, &rect, expected_color, 1);
30011 SetRect(&rect, 200, 0, 640, 200);
30012 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30013 SetRect(&rect, 0, 200, 640, 480);
30014 check_readback_data_color(&rb, &rect, 0xffffffff, 1);
30015 release_resource_readback(&rb);
30017 ID3D11Texture2D_Release(readback_texture);
30019 for (i = 0; i < ARRAY_SIZE(render_targets); ++i)
30021 ID3D11Texture2D_Release(render_targets[i]);
30022 ID3D11RenderTargetView_Release(rtvs[i]);
30025 done:
30026 ID3D11Buffer_Release(cb);
30027 ID3D11PixelShader_Release(ps);
30028 ID3D11BlendState_Release(blend_state);
30029 release_test_context(&test_context);
30032 static void test_unbound_multisample_texture(void)
30034 struct d3d11_test_context test_context;
30035 ID3D11DeviceContext *context;
30036 ID3D11PixelShader *ps;
30037 struct uvec4 cb_data;
30038 ID3D11Device *device;
30039 ID3D11Buffer *cb;
30040 unsigned int i;
30041 HRESULT hr;
30043 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30044 static const DWORD ps_code[] =
30046 #if 0
30047 Texture2DMS<float4, 4> t;
30049 uint sample_index;
30051 float4 main(float4 position : SV_Position) : SV_Target
30053 float3 p;
30054 t.GetDimensions(p.x, p.y, p.z);
30055 p *= float3(position.x / 640.0f, position.y / 480.0f, 0.0f);
30056 /* sample index must be a literal */
30057 switch (sample_index)
30059 case 1: return t.Load(int2(p.xy), 1);
30060 case 2: return t.Load(int2(p.xy), 2);
30061 case 3: return t.Load(int2(p.xy), 3);
30062 default: return t.Load(int2(p.xy), 0);
30065 #endif
30066 0x43425844, 0x03d62416, 0x1914ee8b, 0xccd08d68, 0x27f42136, 0x00000001, 0x000002f8, 0x00000003,
30067 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30068 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
30069 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
30070 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000025c, 0x00000040,
30071 0x00000097, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04042058, 0x00107000, 0x00000000,
30072 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000,
30073 0x02000068, 0x00000002, 0x0700003d, 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46,
30074 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000,
30075 0x0a000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889,
30076 0x00000000, 0x00000000, 0x0400004c, 0x0020800a, 0x00000000, 0x00000000, 0x03000006, 0x00004001,
30077 0x00000001, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000, 0x08000036, 0x001000c2,
30078 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0900002e, 0x001020f2,
30079 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001, 0x00000001, 0x0100003e,
30080 0x03000006, 0x00004001, 0x00000002, 0x0500001b, 0x00100032, 0x00000001, 0x00100046, 0x00000000,
30081 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
30082 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46, 0x00000000, 0x00004001,
30083 0x00000002, 0x0100003e, 0x03000006, 0x00004001, 0x00000003, 0x0500001b, 0x00100032, 0x00000001,
30084 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000001, 0x00004002, 0x00000000, 0x00000000,
30085 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000001, 0x00107e46,
30086 0x00000000, 0x00004001, 0x00000003, 0x0100003e, 0x0100000a, 0x0500001b, 0x00100032, 0x00000000,
30087 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
30088 0x00000000, 0x00000000, 0x0900002e, 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46,
30089 0x00000000, 0x00004001, 0x00000000, 0x0100003e, 0x01000017, 0x0100003e,
30092 if (!init_test_context(&test_context, NULL))
30093 return;
30094 device = test_context.device;
30095 context = test_context.immediate_context;
30097 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30098 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30099 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30101 memset(&cb_data, 0, sizeof(cb_data));
30102 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(cb_data), &cb_data);
30103 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30105 for (i = 0; i < 4; ++i)
30107 cb_data.x = i;
30108 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &cb_data, 0, 0);
30109 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
30110 draw_quad(&test_context);
30111 check_texture_color(test_context.backbuffer, 0x00000000, 1);
30114 ID3D11Buffer_Release(cb);
30115 ID3D11PixelShader_Release(ps);
30116 release_test_context(&test_context);
30119 static void test_multiple_viewports(void)
30121 struct
30123 unsigned int draw_id;
30124 unsigned int padding[3];
30125 } constant;
30126 D3D11_VIEWPORT vp[D3D11_VIEWPORT_AND_SCISSORRECT_OBJECT_COUNT_PER_PIPELINE + 1];
30127 struct d3d11_test_context test_context;
30128 D3D11_TEXTURE2D_DESC texture_desc;
30129 ID3D11DeviceContext *context;
30130 ID3D11RenderTargetView *rtv;
30131 ID3D11Texture2D *texture;
30132 ID3D11GeometryShader *gs;
30133 ID3D11PixelShader *ps;
30134 ID3D11Device *device;
30135 ID3D11Buffer *cb;
30136 HRESULT hr;
30138 static const DWORD gs_code[] =
30140 #if 0
30141 struct gs_in
30143 float4 pos : SV_Position;
30146 struct gs_out
30148 float4 pos : SV_Position;
30149 uint viewport : SV_ViewportArrayIndex;
30152 [maxvertexcount(6)]
30153 void main(triangle gs_in vin[3], inout TriangleStream<gs_out> vout)
30155 gs_out o;
30156 for (uint instance_id = 0; instance_id < 2; ++instance_id)
30158 o.viewport = instance_id;
30159 for (uint i = 0; i < 3; ++i)
30161 o.pos = vin[i].pos;
30162 vout.Append(o);
30164 vout.RestartStrip();
30167 #endif
30168 0x43425844, 0xabbb660f, 0x0729bf23, 0x14a9a104, 0x1b454917, 0x00000001, 0x0000021c, 0x00000003,
30169 0x0000002c, 0x00000060, 0x000000c4, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30170 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x00000f0f, 0x505f5653, 0x7469736f, 0x006e6f69,
30171 0x4e47534f, 0x0000005c, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000001, 0x00000003,
30172 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005, 0x00000001, 0x00000001, 0x00000e01,
30173 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569, 0x4174726f, 0x79617272, 0x65646e49,
30174 0xabab0078, 0x52444853, 0x00000150, 0x00020040, 0x00000054, 0x05000061, 0x002010f2, 0x00000003,
30175 0x00000000, 0x00000001, 0x02000068, 0x00000001, 0x0100185d, 0x0100285c, 0x04000067, 0x001020f2,
30176 0x00000000, 0x00000001, 0x04000067, 0x00102012, 0x00000001, 0x00000005, 0x0200005e, 0x00000006,
30177 0x05000036, 0x00100012, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100022,
30178 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000002, 0x03040003, 0x0010001a, 0x00000000,
30179 0x05000036, 0x00100022, 0x00000000, 0x00004001, 0x00000000, 0x01000030, 0x07000050, 0x00100042,
30180 0x00000000, 0x0010001a, 0x00000000, 0x00004001, 0x00000003, 0x03040003, 0x0010002a, 0x00000000,
30181 0x07000036, 0x001020f2, 0x00000000, 0x00a01e46, 0x0010001a, 0x00000000, 0x00000000, 0x05000036,
30182 0x00102012, 0x00000001, 0x0010000a, 0x00000000, 0x01000013, 0x0700001e, 0x00100022, 0x00000000,
30183 0x0010001a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x01000009, 0x0700001e, 0x00100012,
30184 0x00000000, 0x0010000a, 0x00000000, 0x00004001, 0x00000001, 0x01000016, 0x0100003e,
30186 static const DWORD ps_code[] =
30188 #if 0
30189 uint draw_id;
30191 float4 main(in float4 pos : SV_Position,
30192 in uint viewport : SV_ViewportArrayIndex) : SV_Target
30194 return float4(viewport, draw_id, 0, 0);
30196 #endif
30197 0x43425844, 0x77334c0f, 0x5df3ca7a, 0xc53c00db, 0x3e6e5750, 0x00000001, 0x00000150, 0x00000003,
30198 0x0000002c, 0x00000090, 0x000000c4, 0x4e475349, 0x0000005c, 0x00000002, 0x00000008, 0x00000038,
30199 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x00000044, 0x00000000, 0x00000005,
30200 0x00000001, 0x00000001, 0x00000101, 0x505f5653, 0x7469736f, 0x006e6f69, 0x565f5653, 0x70776569,
30201 0x4174726f, 0x79617272, 0x65646e49, 0xabab0078, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008,
30202 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261,
30203 0xabab0074, 0x52444853, 0x00000084, 0x00000040, 0x00000021, 0x04000059, 0x00208e46, 0x00000000,
30204 0x00000001, 0x04000864, 0x00101012, 0x00000001, 0x00000005, 0x03000065, 0x001020f2, 0x00000000,
30205 0x05000056, 0x00102012, 0x00000000, 0x0010100a, 0x00000001, 0x06000056, 0x00102022, 0x00000000,
30206 0x0020800a, 0x00000000, 0x00000000, 0x08000036, 0x001020c2, 0x00000000, 0x00004002, 0x00000000,
30207 0x00000000, 0x00000000, 0x00000000, 0x0100003e,
30209 static const struct vec4 expected_values[] =
30211 {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},
30212 {0.0f, 5.0f}, {0.5f, 0.5f}, {1.0f, 5.0f}, {0.5f, 0.5f},
30214 static const float clear_color[] = {0.5f, 0.5f, 0.0f, 0.0f};
30215 ID3D11RasterizerState *rasterizer_state;
30216 D3D11_RASTERIZER_DESC rasterizer_desc;
30217 unsigned int count, i;
30218 D3D11_RECT rects[2];
30219 RECT rect;
30220 int width;
30222 if (!init_test_context(&test_context, NULL))
30223 return;
30225 device = test_context.device;
30226 context = test_context.immediate_context;
30228 memset(&constant, 0, sizeof(constant));
30229 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(constant), &constant);
30230 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30232 hr = ID3D11Device_CreateGeometryShader(device, gs_code, sizeof(gs_code), NULL, &gs);
30233 ok(SUCCEEDED(hr), "Failed to create geometry shader, hr %#x.\n", hr);
30234 ID3D11DeviceContext_GSSetShader(context, gs, NULL, 0);
30236 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
30237 ok(SUCCEEDED(hr), "Failed to create pixel shader, hr %#x.\n", hr);
30238 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30240 texture_desc.Width = 32;
30241 texture_desc.Height = 32;
30242 texture_desc.MipLevels = 1;
30243 texture_desc.ArraySize = 1;
30244 texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
30245 texture_desc.SampleDesc.Count = 1;
30246 texture_desc.SampleDesc.Quality = 0;
30247 texture_desc.Usage = D3D11_USAGE_DEFAULT;
30248 texture_desc.BindFlags = D3D11_BIND_RENDER_TARGET;
30249 texture_desc.CPUAccessFlags = 0;
30250 texture_desc.MiscFlags = 0;
30251 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30252 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
30254 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
30255 ok(SUCCEEDED(hr), "Failed to create render target view, hr %#x.\n", hr);
30256 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30258 width = texture_desc.Width / 2;
30260 vp[0].TopLeftX = 0.0f;
30261 vp[0].TopLeftY = 0.0f;
30262 vp[0].Width = width;
30263 vp[0].Height = texture_desc.Height;
30264 vp[0].MinDepth = 0.0f;
30265 vp[0].MaxDepth = 1.0f;
30267 vp[1] = vp[0];
30268 vp[1].TopLeftX = width;
30269 vp[1].Width = width;
30270 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
30272 count = enable_debug_layer ? ARRAY_SIZE(vp) - 1 : ARRAY_SIZE(vp);
30273 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
30274 ok(count == 2, "Unexpected viewport count %d.\n", count);
30276 constant.draw_id = 0;
30277 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30278 draw_quad(&test_context);
30279 constant.draw_id = 1;
30280 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30281 draw_quad(&test_context);
30283 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
30284 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[0], 1);
30285 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30286 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[1], 1);
30288 /* One viewport. */
30289 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30290 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
30291 constant.draw_id = 2;
30292 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30293 draw_quad(&test_context);
30294 SetRect(&rect, 0, 0, width - 1, texture_desc.Height - 1);
30295 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[2], 1);
30296 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30297 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[3], 1);
30299 /* Reset viewports. */
30300 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30301 ID3D11DeviceContext_RSSetViewports(context, 0, NULL);
30302 constant.draw_id = 3;
30303 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30304 draw_quad(&test_context);
30305 check_texture_sub_resource_vec4(texture, 0, NULL, &expected_values[4], 1);
30307 /* Two viewports, only first scissor rectangle set. */
30308 memset(&rasterizer_desc, 0, sizeof(rasterizer_desc));
30309 rasterizer_desc.FillMode = D3D11_FILL_SOLID;
30310 rasterizer_desc.CullMode = D3D11_CULL_BACK;
30311 rasterizer_desc.DepthClipEnable = TRUE;
30312 rasterizer_desc.ScissorEnable = TRUE;
30313 hr = ID3D11Device_CreateRasterizerState(device, &rasterizer_desc, &rasterizer_state);
30314 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
30316 ID3D11DeviceContext_RSSetState(context, rasterizer_state);
30317 ID3D11RasterizerState_Release(rasterizer_state);
30319 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30320 ID3D11DeviceContext_RSSetViewports(context, 2, vp);
30322 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
30323 memset(&rects[1], 0, sizeof(*rects));
30324 ID3D11DeviceContext_RSSetScissorRects(context, 1, rects);
30325 constant.draw_id = 4;
30326 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30327 draw_quad(&test_context);
30329 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
30330 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[5], 1);
30331 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
30332 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[6], 1);
30333 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height - 1);
30334 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[7], 1);
30336 /* Set both rectangles. */
30337 SetRect(&rects[0], 0, 0, width, texture_desc.Height / 2);
30338 SetRect(&rects[1], width, 0, 2 * width, texture_desc.Height / 2);
30339 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, clear_color);
30340 ID3D11DeviceContext_RSSetScissorRects(context, 2, rects);
30341 constant.draw_id = 5;
30342 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &constant, 0, 0);
30343 draw_quad(&test_context);
30345 SetRect(&rect, 0, 0, width - 1, texture_desc.Height / 2 - 1);
30346 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[8], 1);
30347 SetRect(&rect, 0, texture_desc.Height / 2, width - 1, texture_desc.Height - 1);
30348 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[9], 1);
30350 SetRect(&rect, width, 0, 2 * width - 1, texture_desc.Height / 2 - 1);
30351 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[10], 1);
30352 SetRect(&rect, width, texture_desc.Height / 2, 2 * width - 1, texture_desc.Height - 1);
30353 check_texture_sub_resource_vec4(texture, 0, &rect, &expected_values[11], 1);
30355 if (enable_debug_layer)
30356 goto done;
30358 /* Viewport count exceeding maximum value. */
30359 ID3D11DeviceContext_RSSetViewports(context, 1, vp);
30361 vp[0].TopLeftX = 1.0f;
30362 vp[0].TopLeftY = 0.0f;
30363 vp[0].Width = width;
30364 vp[0].Height = texture_desc.Height;
30365 vp[0].MinDepth = 0.0f;
30366 vp[0].MaxDepth = 1.0f;
30367 for (i = 1; i < ARRAY_SIZE(vp); ++i)
30369 vp[i] = vp[0];
30371 ID3D11DeviceContext_RSSetViewports(context, ARRAY_SIZE(vp), vp);
30373 count = ARRAY_SIZE(vp);
30374 memset(vp, 0, sizeof(vp));
30375 ID3D11DeviceContext_RSGetViewports(context, &count, vp);
30376 ok(count == 1, "Unexpected viewport count %d.\n", count);
30377 ok(vp[0].TopLeftX == 0.0f && vp[0].Width == width, "Unexpected viewport.\n");
30379 done:
30380 ID3D11RenderTargetView_Release(rtv);
30381 ID3D11Texture2D_Release(texture);
30383 ID3D11Buffer_Release(cb);
30384 ID3D11GeometryShader_Release(gs);
30385 ID3D11PixelShader_Release(ps);
30386 release_test_context(&test_context);
30389 static void test_multisample_resolve(void)
30391 struct d3d11_test_context test_context;
30392 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
30393 ID3D11Texture2D *texture, *ms_texture;
30394 D3D11_TEXTURE2D_DESC texture_desc;
30395 ID3D11DeviceContext *context;
30396 ID3D11RenderTargetView *rtv;
30397 ID3D11Device *device;
30398 unsigned int i;
30399 HRESULT hr;
30401 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30402 static const struct vec4 green = {0.0f, 1.0f, 0.0f, 1.0f};
30403 static const struct vec4 color = {0.25f, 0.5f, 0.75f, 1.0f};
30404 static const struct
30406 DXGI_FORMAT src_format;
30407 DXGI_FORMAT dst_format;
30408 DXGI_FORMAT format;
30410 DXGI_FORMAT rtv_format;
30412 const struct vec4 *color;
30413 DWORD expected_color;
30415 BOOL todo;
30417 tests[] =
30419 {DXGI_FORMAT_R8G8B8A8_UNORM,
30420 DXGI_FORMAT_R8G8B8A8_UNORM,
30421 DXGI_FORMAT_R8G8B8A8_UNORM,
30422 DXGI_FORMAT_R8G8B8A8_UNORM,
30423 &green, 0xff80ff80},
30424 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30425 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30426 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30427 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30428 &green, 0xffbcffbc},
30429 {DXGI_FORMAT_R8G8B8A8_UNORM,
30430 DXGI_FORMAT_R8G8B8A8_UNORM,
30431 DXGI_FORMAT_R8G8B8A8_UNORM,
30432 DXGI_FORMAT_R8G8B8A8_UNORM,
30433 &color, 0xffdfc0a0},
30434 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30435 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30436 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30437 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30438 &color, 0xfff1e1cf},
30440 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30441 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30442 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30443 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30444 &green, 0xffbcffbc},
30445 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30446 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30447 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30448 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30449 &green, 0xffbcffbc},
30450 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30451 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30452 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30453 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30454 &color, 0xfff1e1cf},
30455 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30456 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30457 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30458 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30459 &color, 0xfff1e1cf},
30461 {DXGI_FORMAT_R8G8B8A8_UNORM,
30462 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30463 DXGI_FORMAT_R8G8B8A8_UNORM,
30464 DXGI_FORMAT_R8G8B8A8_UNORM,
30465 &green, 0xff80ff80},
30466 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30467 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30468 DXGI_FORMAT_R8G8B8A8_UNORM,
30469 DXGI_FORMAT_R8G8B8A8_UNORM,
30470 &green, 0xff80ff80},
30471 {DXGI_FORMAT_R8G8B8A8_UNORM,
30472 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30473 DXGI_FORMAT_R8G8B8A8_UNORM,
30474 DXGI_FORMAT_R8G8B8A8_UNORM,
30475 &color, 0xffdfc0a0},
30476 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30477 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30478 DXGI_FORMAT_R8G8B8A8_UNORM,
30479 DXGI_FORMAT_R8G8B8A8_UNORM,
30480 &color, 0xffdfc0a0},
30482 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30483 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30484 DXGI_FORMAT_R8G8B8A8_UNORM,
30485 DXGI_FORMAT_R8G8B8A8_UNORM,
30486 &green, 0xff80ff80},
30487 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30488 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30489 DXGI_FORMAT_R8G8B8A8_UNORM,
30490 DXGI_FORMAT_R8G8B8A8_UNORM,
30491 &color, 0xffdfc0a0},
30492 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30493 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30494 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30495 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30496 &green, 0xffbcffbc},
30497 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30498 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30499 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30500 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30501 &color, 0xfff1e1cf},
30502 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30503 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30504 DXGI_FORMAT_R8G8B8A8_UNORM,
30505 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30506 &green, 0xff80ff80},
30507 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30508 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30509 DXGI_FORMAT_R8G8B8A8_UNORM,
30510 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30511 &color, 0xfff0dec4},
30512 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30513 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30514 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30515 DXGI_FORMAT_R8G8B8A8_UNORM,
30516 &green, 0xffbcffbc, TRUE},
30517 {DXGI_FORMAT_R8G8B8A8_TYPELESS,
30518 DXGI_FORMAT_R8G8B8A8_TYPELESS,
30519 DXGI_FORMAT_R8G8B8A8_UNORM_SRGB,
30520 DXGI_FORMAT_R8G8B8A8_UNORM,
30521 &color, 0xffe2cdc0, TRUE},
30524 if (!init_test_context(&test_context, NULL))
30525 return;
30526 device = test_context.device;
30527 context = test_context.immediate_context;
30529 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &i);
30530 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
30531 if (!i)
30533 skip("4xMSAA not supported.\n");
30534 release_test_context(&test_context);
30535 return;
30538 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, 3);
30540 for (i = 0; i < ARRAY_SIZE(tests); ++i)
30542 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30543 texture_desc.Format = tests[i].dst_format;
30544 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30545 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30547 texture_desc.Format = tests[i].src_format;
30548 texture_desc.SampleDesc.Count = 4;
30549 texture_desc.SampleDesc.Quality = 0;
30550 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &ms_texture);
30551 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30552 rtv_desc.Format = tests[i].rtv_format;
30553 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
30554 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)ms_texture, &rtv_desc, &rtv);
30555 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
30557 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30558 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
30559 draw_color_quad(&test_context, tests[i].color);
30560 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)texture, 0,
30561 (ID3D11Resource *)ms_texture, 0, tests[i].format);
30563 /* Found broken on AMD Radeon HD 6310 */
30564 if (!broken(is_amd_device(device) && tests[i].format == DXGI_FORMAT_R8G8B8A8_UNORM_SRGB))
30565 todo_wine_if(tests[i].todo) check_texture_color(texture, tests[i].expected_color, 2);
30567 ID3D11RenderTargetView_Release(rtv);
30568 ID3D11Texture2D_Release(ms_texture);
30569 ID3D11Texture2D_Release(texture);
30572 release_test_context(&test_context);
30575 static void test_sample_shading(void)
30577 struct shader
30579 const DWORD *code;
30580 size_t size;
30583 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
30584 struct d3d11_test_context test_context;
30585 struct swapchain_desc swapchain_desc;
30586 D3D11_TEXTURE2D_DESC texture_desc;
30587 ID3D11UnorderedAccessView *uav;
30588 D3D11_BUFFER_DESC buffer_desc;
30589 ID3D11ShaderResourceView *srv;
30590 ID3D11DeviceContext *context;
30591 ID3D11RenderTargetView *rtv;
30592 struct resource_readback rb;
30593 ID3D11Buffer *buffer, *cb;
30594 ID3D11Texture2D *texture;
30595 struct uvec4 ps_constant;
30596 ID3D11PixelShader *ps;
30597 ID3D11Device *device;
30598 unsigned int data;
30599 unsigned int i;
30600 HRESULT hr;
30602 static const DWORD ps_unused_sample_index_code[] =
30604 #if 0
30605 RWByteAddressBuffer u;
30607 float4 main(uint id : SV_SampleIndex) : SV_Target
30609 u.InterlockedAdd(0, 1);
30610 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30612 #endif
30613 0x43425844, 0x41e4574b, 0x1e6441d6, 0x5e756375, 0xacd5dc27, 0x00000001, 0x00000104, 0x00000003,
30614 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30615 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000001, 0x535f5653, 0x6c706d61, 0x646e4965,
30616 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30617 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000064,
30618 0x00000050, 0x00000019, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2,
30619 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
30620 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
30621 0x0100003e,
30623 static const struct shader ps_unused_sample_index
30624 = {ps_unused_sample_index_code, sizeof(ps_unused_sample_index_code)};
30625 static const DWORD ps_sample_index_code[] =
30627 #if 0
30628 RWByteAddressBuffer u;
30630 float4 main(uint id : SV_SampleIndex) : SV_Target
30632 u.InterlockedAdd(0, 1);
30633 u.InterlockedAdd(4, id);
30634 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30636 #endif
30637 0x43425844, 0x943ab9ed, 0x91520b4a, 0xb75df9d0, 0x692cd3e6, 0x00000001, 0x00000130, 0x00000003,
30638 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30639 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
30640 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30641 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000090,
30642 0x00000050, 0x00000024, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
30643 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001,
30644 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
30645 0x00000004, 0x0010100a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
30646 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30648 static const struct shader ps_sample_index = {ps_sample_index_code, sizeof(ps_sample_index_code)};
30649 static const DWORD ps_samplepos_code[] =
30651 #if 0
30652 Texture2DMS<float> t;
30653 RWByteAddressBuffer u;
30655 float4 main() : SV_Target
30657 float2 sample_position = t.GetSamplePosition(0);
30658 u.InterlockedAdd(0, 1);
30659 u.InterlockedAdd(4, sample_position.x + sample_position.y);
30660 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30662 #endif
30663 0x43425844, 0x9ec7f344, 0x588f5863, 0x436c0531, 0x69dc54bb, 0x00000001, 0x00000160, 0x00000003,
30664 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
30665 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
30666 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e8, 0x00000050, 0x0000003a,
30667 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
30668 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
30669 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
30670 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
30671 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
30672 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
30673 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30675 static const struct shader ps_samplepos = {ps_samplepos_code, sizeof(ps_samplepos_code)};
30676 static const DWORD ps_samplepos_rasterizer_code[] =
30678 #if 0
30679 RWByteAddressBuffer u;
30681 float4 main() : SV_Target
30683 float2 sample_position = GetRenderTargetSamplePosition(0);
30684 u.InterlockedAdd(0, 1);
30685 u.InterlockedAdd(4, sample_position.x + sample_position.y);
30686 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30688 #endif
30689 0x43425844, 0xe31795d9, 0x4e9951da, 0xc1713913, 0xfb12da31, 0x00000001, 0x00000148, 0x00000003,
30690 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
30691 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
30692 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000d0, 0x00000050, 0x00000034,
30693 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
30694 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
30695 0x0600006e, 0x00100032, 0x00000000, 0x0000e046, 0x00004001, 0x00000000, 0x07000000, 0x00100012,
30696 0x00000000, 0x0010001a, 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000,
30697 0x0010000a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
30698 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
30699 0x3f800000, 0x0100003e,
30701 static const struct shader ps_samplepos_rasterizer
30702 = {ps_samplepos_rasterizer_code, sizeof(ps_samplepos_rasterizer_code)};
30703 static const DWORD ps_samplepos_indexed_code[] =
30705 #if 0
30706 RWByteAddressBuffer u;
30708 float4 main(uint id : SV_SampleIndex) : SV_Target
30710 float2 sample_position = GetRenderTargetSamplePosition(id);
30711 u.InterlockedAdd(0, 1);
30712 u.InterlockedAdd(4, sample_position.x + sample_position.y);
30713 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30715 #endif
30716 0x43425844, 0x4b501464, 0x0cd4f636, 0x36428677, 0x6db6b4fb, 0x00000001, 0x00000180, 0x00000003,
30717 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30718 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
30719 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30720 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000e0,
30721 0x00000050, 0x00000038, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04000863, 0x00101012,
30722 0x00000000, 0x0000000a, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad,
30723 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0600006e, 0x00100032,
30724 0x00000000, 0x0000e046, 0x0010100a, 0x00000000, 0x07000000, 0x00100012, 0x00000000, 0x0010001a,
30725 0x00000000, 0x0010000a, 0x00000000, 0x0500001c, 0x00100012, 0x00000000, 0x0010000a, 0x00000000,
30726 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000, 0x08000036,
30727 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30729 static const struct shader ps_samplepos_indexed
30730 = {ps_samplepos_indexed_code, sizeof(ps_samplepos_indexed_code)};
30731 static const DWORD ps_sampleinfo_code[] =
30733 #if 0
30734 Texture2DMS<float> t;
30735 RWByteAddressBuffer u;
30737 float4 main() : SV_Target
30739 uint width, height, sample_count;
30740 t.GetDimensions(width, height, sample_count);
30741 u.InterlockedAdd(0, 1);
30742 u.InterlockedAdd(4, sample_count);
30743 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30745 #endif
30746 0x43425844, 0x4e4f4065, 0x20d88902, 0xd4750e8c, 0x652b8c04, 0x00000001, 0x00000124, 0x00000003,
30747 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
30748 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
30749 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050, 0x0000002b,
30750 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
30751 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000, 0x00000001,
30752 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500086f, 0x00100012, 0x00000000, 0x0010700a,
30753 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a, 0x00000000,
30754 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000, 0x3f800000,
30755 0x0100003e,
30757 static const struct shader ps_sampleinfo = {ps_sampleinfo_code, sizeof(ps_sampleinfo_code)};
30758 static const DWORD ps_sampleinfo_rasterizer_code[] =
30760 #if 0
30761 RWByteAddressBuffer u;
30763 float4 main() : SV_Target
30765 uint sample_count = GetRenderTargetSampleCount();
30766 u.InterlockedAdd(0, 1);
30767 u.InterlockedAdd(4, sample_count);
30768 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30770 #endif
30771 0x43425844, 0xfbbd8619, 0x9c2654c8, 0xb385363a, 0x4aacd10f, 0x00000001, 0x00000110, 0x00000003,
30772 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
30773 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
30774 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000098, 0x00000050, 0x00000026,
30775 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068,
30776 0x00000001, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001,
30777 0x0400086f, 0x00100012, 0x00000000, 0x0000e00a, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001,
30778 0x00000004, 0x0010000a, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
30779 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e,
30781 static const struct shader ps_sampleinfo_rasterizer
30782 = {ps_sampleinfo_rasterizer_code, sizeof(ps_sampleinfo_rasterizer_code)};
30783 static const DWORD ps_sample_code[] =
30785 #if 0
30786 RWByteAddressBuffer u;
30788 float4 main(sample float4 position : SV_Position) : SV_Target
30790 u.InterlockedAdd(0, 1);
30791 u.InterlockedAdd(4, position.x);
30792 return float4(0.0f, 1.0f, 0.0f, 1.0f);
30794 #endif
30795 0x43425844, 0x46ecbadb, 0xedccbea6, 0x236d7923, 0x0c356c8c, 0x00000001, 0x00000148, 0x00000003,
30796 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30797 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000010f, 0x505f5653, 0x7469736f, 0x006e6f69,
30798 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
30799 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000ac, 0x00000050,
30800 0x0000002b, 0x0100086a, 0x0300009d, 0x0011e000, 0x00000001, 0x04003864, 0x00101012, 0x00000000,
30801 0x00000001, 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x070000ad, 0x0011e000,
30802 0x00000001, 0x00004001, 0x00000000, 0x00004001, 0x00000001, 0x0500001c, 0x00100012, 0x00000000,
30803 0x0010100a, 0x00000000, 0x070000ad, 0x0011e000, 0x00000001, 0x00004001, 0x00000004, 0x0010000a,
30804 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x3f800000, 0x00000000,
30805 0x3f800000, 0x0100003e,
30807 static const struct shader ps_sample = {ps_sample_code, sizeof(ps_sample_code)};
30808 static const DWORD ps_color_code[] =
30810 #if 0
30811 float4 main(uint id : SV_SampleIndex) : SV_Target
30813 switch (id)
30815 case 0: return float4(1.0f, 0.0f, 0.0f, 1.0f);
30816 case 1: return float4(0.0f, 1.0f, 0.0f, 1.0f);
30817 case 2: return float4(0.0f, 0.0f, 1.0f, 1.0f);
30818 default: return float4(0.0f, 0.0f, 0.0f, 1.0f);
30821 #endif
30822 0x43425844, 0x94c35f48, 0x04c6b0f7, 0x407d8214, 0xc24f01e5, 0x00000001, 0x00000194, 0x00000003,
30823 0x0000002c, 0x00000064, 0x00000098, 0x4e475349, 0x00000030, 0x00000001, 0x00000008, 0x00000020,
30824 0x00000000, 0x0000000a, 0x00000001, 0x00000000, 0x00000101, 0x535f5653, 0x6c706d61, 0x646e4965,
30825 0xab007865, 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000,
30826 0x00000003, 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x000000f4,
30827 0x00000050, 0x0000003d, 0x0100086a, 0x04000863, 0x00101012, 0x00000000, 0x0000000a, 0x03000065,
30828 0x001020f2, 0x00000000, 0x0300004c, 0x0010100a, 0x00000000, 0x03000006, 0x00004001, 0x00000000,
30829 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x00000000, 0x00000000, 0x3f800000,
30830 0x0100003e, 0x03000006, 0x00004001, 0x00000001, 0x08000036, 0x001020f2, 0x00000000, 0x00004002,
30831 0x00000000, 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e, 0x03000006, 0x00004001, 0x00000002,
30832 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x3f800000, 0x3f800000,
30833 0x0100003e, 0x0100000a, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000, 0x00000000,
30834 0x00000000, 0x3f800000, 0x0100003e, 0x01000017, 0x0100003e,
30836 static const DWORD ps_resolve_code[] =
30838 #if 0
30839 Texture2DMS<float4> t;
30841 uint sample;
30842 uint rt_size;
30844 float4 main(float4 position : SV_Position) : SV_Target
30846 float3 p;
30847 t.GetDimensions(p.x, p.y, p.z);
30848 p *= float3(position.x / rt_size, position.y / rt_size, 0);
30849 return t.Load((int2)p.xy, sample);
30851 #endif
30852 0x43425844, 0x68a4590b, 0xc1ec3070, 0x1b957c43, 0x0c080741, 0x00000001, 0x000001c8, 0x00000003,
30853 0x0000002c, 0x00000060, 0x00000094, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
30854 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x7469736f, 0x006e6f69,
30855 0x4e47534f, 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003,
30856 0x00000000, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x0000012c, 0x00000050,
30857 0x0000004b, 0x0100086a, 0x04000059, 0x00208e46, 0x00000000, 0x00000001, 0x04002058, 0x00107000,
30858 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065, 0x001020f2,
30859 0x00000000, 0x02000068, 0x00000001, 0x06000056, 0x00100012, 0x00000000, 0x0020801a, 0x00000000,
30860 0x00000000, 0x0700000e, 0x00100032, 0x00000000, 0x00101046, 0x00000000, 0x00100006, 0x00000000,
30861 0x8900003d, 0x80000102, 0x00155543, 0x001000c2, 0x00000000, 0x00004001, 0x00000000, 0x001074e6,
30862 0x00000000, 0x07000038, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x00100ae6, 0x00000000,
30863 0x0500001b, 0x00100032, 0x00000000, 0x00100046, 0x00000000, 0x08000036, 0x001000c2, 0x00000000,
30864 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x8c00002e, 0x80000102, 0x00155543,
30865 0x001020f2, 0x00000000, 0x00100e46, 0x00000000, 0x00107e46, 0x00000000, 0x0020800a, 0x00000000,
30866 0x00000000, 0x0100003e,
30868 static const struct
30870 const struct shader *ps;
30871 BOOL sample_shading;
30872 BOOL todo;
30873 BOOL broken;
30875 tests[] =
30877 {&ps_unused_sample_index, FALSE, FALSE, TRUE /* broken on Nvidia */},
30878 {&ps_sample_index, TRUE},
30879 {&ps_samplepos, FALSE},
30880 {&ps_samplepos_rasterizer, FALSE},
30881 {&ps_samplepos_indexed, TRUE, TRUE},
30882 {&ps_sampleinfo, FALSE},
30883 {&ps_sampleinfo_rasterizer, FALSE},
30884 {&ps_sample, TRUE, TRUE, TRUE /* broken on Intel */},
30886 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
30887 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
30888 static const unsigned int zero[4] = {0};
30890 swapchain_desc.windowed = TRUE;
30891 swapchain_desc.buffer_count = 1;
30892 swapchain_desc.width = 32;
30893 swapchain_desc.height = 32;
30894 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
30895 swapchain_desc.flags = 0;
30896 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
30897 return;
30898 device = test_context.device;
30899 context = test_context.immediate_context;
30901 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
30902 texture_desc.SampleDesc.Count = 4;
30903 texture_desc.SampleDesc.Quality = 0;
30904 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
30905 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
30906 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
30907 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
30908 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
30909 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
30910 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
30912 buffer_desc.ByteWidth = 1024;
30913 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
30914 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
30915 buffer_desc.CPUAccessFlags = 0;
30916 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
30917 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
30918 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
30919 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
30920 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
30921 U(uav_desc).Buffer.FirstElement = 0;
30922 U(uav_desc).Buffer.NumElements = 256;
30923 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
30924 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
30925 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
30927 for (i = 0; i < ARRAY_SIZE(tests); ++i)
30929 hr = ID3D11Device_CreatePixelShader(device, tests[i].ps->code, tests[i].ps->size, NULL, &ps);
30930 ok(hr == S_OK, "Test %u: Failed to create pixel shader, hr %#x.\n", i, hr);
30931 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30933 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
30934 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
30935 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
30936 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
30937 draw_quad(&test_context);
30938 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
30939 get_buffer_readback(buffer, &rb);
30940 data = get_readback_color(&rb, 0, 0, 0);
30941 ok(1024 <= data && data <= 1056, "Test %u: Got unexpected value %u.\n", i, data);
30942 release_resource_readback(&rb);
30944 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
30945 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
30946 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
30947 1, &rtv, NULL, 1, 1, &uav, NULL);
30948 draw_quad(&test_context);
30949 get_buffer_readback(buffer, &rb);
30950 data = get_readback_color(&rb, 0, 0, 0);
30951 todo_wine_if(tests[i].todo)
30953 if (tests[i].sample_shading)
30955 ok(4096 <= data || broken(tests[i].broken && data >= 1024),
30956 "Test %u: Got unexpected value %u.\n", i, data);
30958 else
30960 ok((1024 <= data && data <= 1056) || broken(tests[i].broken && data >= 4096),
30961 "Test %u: Got unexpected value %u.\n", i, data);
30964 release_resource_readback(&rb);
30966 ID3D11PixelShader_Release(ps);
30969 if (is_warp_device(device))
30971 skip("Sample shading tests fail on WARP.\n");
30972 goto done;
30975 hr = ID3D11Device_CreatePixelShader(device, ps_color_code, sizeof(ps_color_code), NULL, &ps);
30976 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30977 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30978 ID3D11PixelShader_Release(ps);
30980 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, white);
30981 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
30982 draw_quad(&test_context);
30983 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
30984 (ID3D11Resource *)texture, 0, texture_desc.Format);
30985 check_texture_color(test_context.backbuffer, 0xff404040, 2);
30987 hr = ID3D11Device_CreatePixelShader(device, ps_resolve_code, sizeof(ps_resolve_code), NULL, &ps);
30988 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
30989 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
30990 ID3D11PixelShader_Release(ps);
30991 ps_constant.x = 0;
30992 ps_constant.y = texture_desc.Width;
30993 cb = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(ps_constant), &ps_constant);
30994 ID3D11DeviceContext_PSSetConstantBuffers(context, 0, 1, &cb);
30996 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
30997 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
30998 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
30999 draw_quad(&test_context);
31000 check_texture_color(test_context.backbuffer, 0xff0000ff, 0);
31001 ps_constant.x = 1;
31002 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
31003 draw_quad(&test_context);
31004 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
31005 ps_constant.x = 2;
31006 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
31007 draw_quad(&test_context);
31008 check_texture_color(test_context.backbuffer, 0xffff0000, 0);
31009 ps_constant.x = 3;
31010 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)cb, 0, NULL, &ps_constant, 0, 0);
31011 draw_quad(&test_context);
31012 check_texture_color(test_context.backbuffer, 0xff000000, 0);
31014 ID3D11Buffer_Release(cb);
31015 done:
31016 ID3D11Buffer_Release(buffer);
31017 ID3D11UnorderedAccessView_Release(uav);
31018 ID3D11RenderTargetView_Release(rtv);
31019 ID3D11ShaderResourceView_Release(srv);
31020 ID3D11Texture2D_Release(texture);
31021 release_test_context(&test_context);
31024 static void test_sample_mask(void)
31026 static const DWORD ps_code[] =
31028 #if 0
31029 float4 main(in float4 pos : SV_Position, out uint sample_mask : SV_Coverage) : SV_Target
31031 sample_mask = 0x5;
31032 return float4(1.0, 1.0, 1.0, 1.0);
31034 #endif
31035 0x43425844, 0x196779a9, 0xda85988a, 0xb7f0a0b6, 0xb30dd6ba, 0x00000001, 0x00000114, 0x00000003,
31036 0x0000002c, 0x00000060, 0x000000b8, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31037 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
31038 0x4e47534f, 0x00000050, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
31039 0x00000000, 0x0000000f, 0x00000042, 0x00000000, 0x00000000, 0x00000001, 0xffffffff, 0x00000e01,
31040 0x545f5653, 0x65677261, 0x56530074, 0x766f435f, 0x67617265, 0xabab0065, 0x58454853, 0x00000054,
31041 0x00000050, 0x00000015, 0x0100086a, 0x03000065, 0x001020f2, 0x00000000, 0x02000065, 0x0000f000,
31042 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f800000, 0x3f800000, 0x3f800000, 0x3f800000,
31043 0x04000036, 0x0000f001, 0x00004001, 0x00000005, 0x0100003e,
31045 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
31046 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
31047 struct d3d11_test_context test_context;
31048 D3D11_TEXTURE2D_DESC texture_desc;
31049 ID3D11DeviceContext *context;
31050 ID3D11RenderTargetView *rtv;
31051 ID3D11Texture2D *texture;
31052 ID3D11PixelShader *ps;
31053 ID3D11Device *device;
31054 UINT quality_levels;
31055 HRESULT hr;
31057 if (!init_test_context(&test_context, &feature_level))
31058 return;
31059 device = test_context.device;
31060 context = test_context.immediate_context;
31062 hr = ID3D11Device_CheckMultisampleQualityLevels(device, DXGI_FORMAT_R8G8B8A8_TYPELESS, 4, &quality_levels);
31063 ok(hr == S_OK, "Failed to check multisample quality levels, hr %#x.\n", hr);
31064 if (!quality_levels)
31066 skip("4xMSAA not supported.\n");
31067 release_test_context(&test_context);
31068 return;
31071 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31072 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31073 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31075 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31076 texture_desc.SampleDesc.Count = 4;
31077 texture_desc.SampleDesc.Quality = 0;
31078 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31079 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31080 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
31081 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
31083 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
31084 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31085 draw_quad(&test_context);
31086 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
31087 (ID3D11Resource *)texture, 0, texture_desc.Format);
31088 check_texture_color(test_context.backbuffer, 0x7f7f7f7f, 1);
31090 ID3D11DeviceContext_OMSetBlendState(context, NULL, NULL, 0xb);
31091 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31092 draw_quad(&test_context);
31093 ID3D11DeviceContext_ResolveSubresource(context, (ID3D11Resource *)test_context.backbuffer, 0,
31094 (ID3D11Resource *)texture, 0, texture_desc.Format);
31095 check_texture_color(test_context.backbuffer, 0x3f3f3f3f, 1);
31097 ID3D11RenderTargetView_Release(rtv);
31098 ID3D11Texture2D_Release(texture);
31099 ID3D11PixelShader_Release(ps);
31100 release_test_context(&test_context);
31103 static void test_depth_clip(void)
31105 struct d3d11_test_context test_context;
31106 D3D11_TEXTURE2D_DESC texture_desc;
31107 D3D11_RASTERIZER_DESC rs_desc;
31108 ID3D11DeviceContext *context;
31109 ID3D11DepthStencilView *dsv;
31110 ID3D11RasterizerState *rs;
31111 ID3D11Texture2D *texture;
31112 ID3D11Device *device;
31113 unsigned int count;
31114 D3D11_VIEWPORT vp;
31115 HRESULT hr;
31117 if (!init_test_context(&test_context, NULL))
31118 return;
31119 device = test_context.device;
31120 context = test_context.immediate_context;
31122 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31123 texture_desc.Format = DXGI_FORMAT_D32_FLOAT;
31124 texture_desc.BindFlags = D3D11_BIND_DEPTH_STENCIL;
31126 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31127 ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr);
31128 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)texture, NULL, &dsv);
31129 ok(SUCCEEDED(hr), "Failed to create depth stencil view, hr %#x.\n", hr);
31130 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, dsv);
31132 count = 1;
31133 ID3D11DeviceContext_RSGetViewports(context, &count, &vp);
31135 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
31136 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
31137 draw_quad_z(&test_context, 2.0f);
31138 check_texture_float(texture, 1.0f, 1);
31139 draw_quad_z(&test_context, 0.5f);
31140 check_texture_float(texture, 0.5f, 1);
31141 draw_quad_z(&test_context, -1.0f);
31142 check_texture_float(texture, 0.5f, 1);
31144 rs_desc.FillMode = D3D11_FILL_SOLID;
31145 rs_desc.CullMode = D3D11_CULL_BACK;
31146 rs_desc.FrontCounterClockwise = FALSE;
31147 rs_desc.DepthBias = 0;
31148 rs_desc.DepthBiasClamp = 0.0f;
31149 rs_desc.SlopeScaledDepthBias = 0.0f;
31150 rs_desc.DepthClipEnable = FALSE;
31151 rs_desc.ScissorEnable = FALSE;
31152 rs_desc.MultisampleEnable = FALSE;
31153 rs_desc.AntialiasedLineEnable = FALSE;
31154 hr = ID3D11Device_CreateRasterizerState(device, &rs_desc, &rs);
31155 ok(SUCCEEDED(hr), "Failed to create rasterizer state, hr %#x.\n", hr);
31157 ID3D11DeviceContext_RSSetState(context, rs);
31159 ID3D11DeviceContext_ClearDepthStencilView(context, dsv, D3D11_CLEAR_DEPTH, 1.0f, 0);
31160 set_viewport(context, vp.TopLeftX, vp.TopLeftY, vp.Width, vp.Height, 0.4f, 0.6f);
31161 draw_quad_z(&test_context, 2.0f);
31162 check_texture_float(texture, 0.6f, 1);
31163 draw_quad_z(&test_context, 0.5f);
31164 check_texture_float(texture, 0.5f, 1);
31165 draw_quad_z(&test_context, -1.0f);
31166 check_texture_float(texture, 0.4f, 1);
31168 ID3D11DepthStencilView_Release(dsv);
31169 ID3D11Texture2D_Release(texture);
31170 ID3D11RasterizerState_Release(rs);
31171 release_test_context(&test_context);
31174 static void test_staging_buffers(void)
31176 struct d3d11_test_context test_context;
31177 ID3D11Buffer *dst_buffer, *src_buffer;
31178 D3D11_SUBRESOURCE_DATA resource_data;
31179 D3D11_BUFFER_DESC buffer_desc;
31180 ID3D11DeviceContext *context;
31181 struct resource_readback rb;
31182 float data[16], value;
31183 ID3D11Device *device;
31184 unsigned int i;
31185 HRESULT hr;
31187 if (!init_test_context(&test_context, NULL))
31188 return;
31189 device = test_context.device;
31190 context = test_context.immediate_context;
31192 buffer_desc.ByteWidth = sizeof(data);
31193 buffer_desc.Usage = D3D11_USAGE_STAGING;
31194 buffer_desc.BindFlags = 0;
31195 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
31196 buffer_desc.MiscFlags = 0;
31197 buffer_desc.StructureByteStride = 0;
31199 for (i = 0; i < ARRAY_SIZE(data); ++i)
31200 data[i] = i;
31201 resource_data.pSysMem = data;
31202 resource_data.SysMemPitch = 0;
31203 resource_data.SysMemSlicePitch = 0;
31205 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &src_buffer);
31206 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31208 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
31209 buffer_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
31210 buffer_desc.CPUAccessFlags = 0;
31211 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &dst_buffer);
31212 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31214 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
31215 get_buffer_readback(dst_buffer, &rb);
31216 for (i = 0; i < ARRAY_SIZE(data); ++i)
31218 value = get_readback_float(&rb, i, 0);
31219 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
31221 release_resource_readback(&rb);
31223 for (i = 0; i < ARRAY_SIZE(data); ++i)
31224 data[i] = 2 * i;
31225 ID3D11DeviceContext_UpdateSubresource(context, (ID3D11Resource *)src_buffer, 0, NULL, data, 0, 0);
31226 ID3D11DeviceContext_CopyResource(context, (ID3D11Resource *)dst_buffer, (ID3D11Resource *)src_buffer);
31227 get_buffer_readback(dst_buffer, &rb);
31228 for (i = 0; i < ARRAY_SIZE(data); ++i)
31230 value = get_readback_float(&rb, i, 0);
31231 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
31233 release_resource_readback(&rb);
31235 ID3D11Buffer_Release(dst_buffer);
31236 ID3D11Buffer_Release(src_buffer);
31237 release_test_context(&test_context);
31240 static void test_render_a8(void)
31242 static const float black[] = {0.0f, 0.0f, 0.0f, 0.0f};
31243 struct d3d11_test_context test_context;
31244 D3D11_TEXTURE2D_DESC texture_desc;
31245 ID3D11DeviceContext *context;
31246 ID3D11RenderTargetView *rtv;
31247 struct resource_readback rb;
31248 ID3D11Texture2D *texture;
31249 ID3D11PixelShader *ps;
31250 ID3D11Device *device;
31251 unsigned int i;
31252 HRESULT hr;
31254 static const DWORD ps_code[] =
31256 #if 0
31257 void main(out float4 target : SV_Target)
31259 target = float4(0.0f, 0.25f, 0.5f, 1.0f);
31261 #endif
31262 0x43425844, 0x8a06129f, 0x3041bde2, 0x09389749, 0xb339ba8b, 0x00000001, 0x000000b0, 0x00000003,
31263 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31264 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31265 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000038, 0x00000040, 0x0000000e,
31266 0x03000065, 0x001020f2, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31267 0x3e800000, 0x3f000000, 0x3f800000, 0x0100003e,
31270 if (!init_test_context(&test_context, NULL))
31271 return;
31272 device = test_context.device;
31273 context = test_context.immediate_context;
31275 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31276 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31277 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31279 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31280 texture_desc.Format = DXGI_FORMAT_A8_UNORM;
31281 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31282 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31283 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
31284 ok(hr == S_OK, "Failed to create render target view, hr %#x.\n", hr);
31286 for (i = 0; i < 2; ++i)
31288 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, black);
31289 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &rtv, NULL);
31290 draw_quad(&test_context);
31291 get_texture_readback(texture, 0, &rb);
31292 check_readback_data_u8(&rb, NULL, 0xff, 0);
31293 release_resource_readback(&rb);
31295 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, black);
31296 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
31297 draw_quad(&test_context);
31298 check_texture_sub_resource_color(test_context.backbuffer, 0, NULL, 0xff7f4000, 1);
31301 ID3D11PixelShader_Release(ps);
31302 ID3D11Texture2D_Release(texture);
31303 ID3D11RenderTargetView_Release(rtv);
31304 release_test_context(&test_context);
31307 static void test_standard_pattern(void)
31309 D3D11_UNORDERED_ACCESS_VIEW_DESC uav_desc;
31310 struct d3d11_test_context test_context;
31311 struct swapchain_desc swapchain_desc;
31312 D3D11_TEXTURE2D_DESC texture_desc;
31313 ID3D11UnorderedAccessView *uav;
31314 D3D11_BUFFER_DESC buffer_desc;
31315 ID3D11ShaderResourceView *srv;
31316 ID3D11DeviceContext *context;
31317 struct resource_readback rb;
31318 ID3D11Texture2D *texture;
31319 ID3D11PixelShader *ps;
31320 ID3D11Buffer *buffer;
31321 ID3D11Device *device;
31322 unsigned int i;
31323 HRESULT hr;
31325 static const DWORD ps_samplepos[] =
31327 #if 0
31328 Texture2DMS<float> t;
31329 RWByteAddressBuffer u;
31331 float4 main() : SV_Target
31333 u.Store2(0, asuint(t.GetSamplePosition(0)));
31334 u.Store2(8, asuint(t.GetSamplePosition(1)));
31335 u.Store2(16, asuint(t.GetSamplePosition(2)));
31336 u.Store2(24, asuint(t.GetSamplePosition(3)));
31337 return float4(0.0f, 1.0f, 0.0f, 1.0f);
31339 #endif
31340 0x43425844, 0xa1db77e8, 0x804d8862, 0x0e3c213d, 0x2703dec6, 0x00000001, 0x00000190, 0x00000003,
31341 0x0000002c, 0x0000003c, 0x00000070, 0x4e475349, 0x00000008, 0x00000000, 0x00000008, 0x4e47534f,
31342 0x0000002c, 0x00000001, 0x00000008, 0x00000020, 0x00000000, 0x00000000, 0x00000003, 0x00000000,
31343 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x58454853, 0x00000118, 0x00000050, 0x00000046,
31344 0x0100086a, 0x04002058, 0x00107000, 0x00000000, 0x00005555, 0x0300009d, 0x0011e000, 0x00000001,
31345 0x03000065, 0x001020f2, 0x00000000, 0x02000068, 0x00000001, 0x0800006e, 0x00100032, 0x00000000,
31346 0x00107046, 0x00000000, 0x00004001, 0x00000000, 0x00000000, 0x0800006e, 0x001000c2, 0x00000000,
31347 0x00107406, 0x00000000, 0x00004001, 0x00000001, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001,
31348 0x00004001, 0x00000000, 0x00100e46, 0x00000000, 0x0800006e, 0x00100032, 0x00000000, 0x00107046,
31349 0x00000000, 0x00004001, 0x00000002, 0x00000000, 0x0800006e, 0x001000c2, 0x00000000, 0x00107406,
31350 0x00000000, 0x00004001, 0x00000003, 0x00000000, 0x070000a6, 0x0011e0f2, 0x00000001, 0x00004001,
31351 0x00000010, 0x00100e46, 0x00000000, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x00000000,
31352 0x3f800000, 0x00000000, 0x3f800000, 0x0100003e
31354 static const D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_11_0;
31355 static const float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
31356 static const unsigned int zero[4] = {0};
31357 static const float standard_pos4[] =
31359 -2 / 16.0f, -6 / 16.0f,
31360 6 / 16.0f, -2 / 16.0f,
31361 -6 / 16.0f, 2 / 16.0f,
31362 2 / 16.0f, 6 / 16.0f,
31365 swapchain_desc.windowed = TRUE;
31366 swapchain_desc.buffer_count = 1;
31367 swapchain_desc.width = 32;
31368 swapchain_desc.height = 32;
31369 swapchain_desc.swap_effect = DXGI_SWAP_EFFECT_DISCARD;
31370 swapchain_desc.flags = 0;
31371 if (!init_test_context_ext(&test_context, &feature_level, &swapchain_desc))
31372 return;
31373 device = test_context.device;
31374 context = test_context.immediate_context;
31376 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31377 texture_desc.SampleDesc.Count = 4;
31378 texture_desc.SampleDesc.Quality = D3D11_STANDARD_MULTISAMPLE_PATTERN;
31379 texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
31380 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31381 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
31382 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
31383 ok(hr == S_OK, "Failed to create shader resource view, hr %#x.\n", hr);
31385 buffer_desc.ByteWidth = 1024;
31386 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
31387 buffer_desc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
31388 buffer_desc.CPUAccessFlags = 0;
31389 buffer_desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_ALLOW_RAW_VIEWS;
31390 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, NULL, &buffer);
31391 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
31392 uav_desc.Format = DXGI_FORMAT_R32_TYPELESS;
31393 uav_desc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
31394 U(uav_desc).Buffer.FirstElement = 0;
31395 U(uav_desc).Buffer.NumElements = 256;
31396 U(uav_desc).Buffer.Flags = D3D11_BUFFER_UAV_FLAG_RAW;
31397 hr = ID3D11Device_CreateUnorderedAccessView(device, (ID3D11Resource *)buffer, &uav_desc, &uav);
31398 ok(hr == S_OK, "Failed to create unordered access view, hr %#x.\n", hr);
31400 hr = ID3D11Device_CreatePixelShader(device, ps_samplepos, sizeof(ps_samplepos), NULL, &ps);
31401 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31402 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31404 ID3D11DeviceContext_ClearUnorderedAccessViewUint(context, uav, zero);
31405 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, white);
31406 ID3D11DeviceContext_OMSetRenderTargetsAndUnorderedAccessViews(context,
31407 1, &test_context.backbuffer_rtv, NULL, 1, 1, &uav, NULL);
31408 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31409 draw_quad(&test_context);
31410 check_texture_color(test_context.backbuffer, 0xff00ff00, 0);
31411 get_buffer_readback(buffer, &rb);
31412 for (i = 0; i < ARRAY_SIZE(standard_pos4); ++i)
31414 float data = get_readback_float(&rb, i, 0);
31415 /* Wine does not support GetSamplePosition. */
31416 todo_wine ok(data == standard_pos4[i], "Got sample position %.8e, expected %.8e.\n", data, standard_pos4[i]);
31418 release_resource_readback(&rb);
31420 ID3D11PixelShader_Release(ps);
31421 ID3D11Buffer_Release(buffer);
31422 ID3D11UnorderedAccessView_Release(uav);
31423 ID3D11ShaderResourceView_Release(srv);
31424 ID3D11Texture2D_Release(texture);
31425 release_test_context(&test_context);
31428 static void test_desktop_window(void)
31430 ID3D11RenderTargetView *backbuffer_rtv;
31431 DXGI_SWAP_CHAIN_DESC swapchain_desc;
31432 ID3D11DeviceContext *context;
31433 ID3D11Texture2D *backbuffer;
31434 IDXGISwapChain *swapchain;
31435 IDXGIDevice *dxgi_device;
31436 IDXGIAdapter *adapter;
31437 IDXGIFactory *factory;
31438 ID3D11Device *device;
31439 ULONG refcount;
31440 HRESULT hr;
31442 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
31444 if (!(device = create_device(NULL)))
31446 skip("Failed to create device.\n");
31447 return;
31450 hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
31451 ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr);
31452 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
31453 ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr);
31454 IDXGIDevice_Release(dxgi_device);
31455 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
31456 ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr);
31457 IDXGIAdapter_Release(adapter);
31459 swapchain_desc.BufferDesc.Width = 640;
31460 swapchain_desc.BufferDesc.Height = 480;
31461 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
31462 swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
31463 swapchain_desc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31464 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
31465 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
31466 swapchain_desc.SampleDesc.Count = 1;
31467 swapchain_desc.SampleDesc.Quality = 0;
31468 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
31469 swapchain_desc.BufferCount = 1;
31470 swapchain_desc.OutputWindow = GetDesktopWindow();
31471 swapchain_desc.Windowed = TRUE;
31472 swapchain_desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
31473 swapchain_desc.Flags = 0;
31475 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &swapchain_desc, &swapchain);
31476 ok(hr == S_OK || broken(hr == DXGI_ERROR_INVALID_CALL) /* Not available on all Windows versions. */,
31477 "Failed to create swapchain, hr %#x.\n", hr);
31478 IDXGIFactory_Release(factory);
31479 if (FAILED(hr))
31481 ID3D11Device_Release(device);
31482 return;
31485 hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_ID3D11Texture2D, (void **)&backbuffer);
31486 ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
31488 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)backbuffer, NULL, &backbuffer_rtv);
31489 ok(SUCCEEDED(hr), "Failed to create rendertarget view, hr %#x.\n", hr);
31491 ID3D11Device_GetImmediateContext(device, &context);
31493 ID3D11DeviceContext_ClearRenderTargetView(context, backbuffer_rtv, red);
31494 check_texture_color(backbuffer, 0xff0000ff, 1);
31496 hr = IDXGISwapChain_Present(swapchain, 0, 0);
31497 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31499 ID3D11RenderTargetView_Release(backbuffer_rtv);
31500 ID3D11Texture2D_Release(backbuffer);
31501 IDXGISwapChain_Release(swapchain);
31502 ID3D11DeviceContext_Release(context);
31503 refcount = ID3D11Device_Release(device);
31504 ok(!refcount, "Device has %u references left.\n", refcount);
31507 static void test_sample_attached_rtv(void)
31509 ID3D11ShaderResourceView *srv, *srv2, *srv_test, *srv_ds;
31510 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc, srvds_desc;
31511 ID3D11Texture2D *texture, *texture2, *dstexture;
31512 ID3D11RenderTargetView *rtv, *rtv2, *rtvs[2];
31513 D3D11_DEPTH_STENCIL_VIEW_DESC dsview_desc;
31514 struct d3d11_test_context test_context;
31515 D3D11_RENDER_TARGET_VIEW_DESC rtv_desc;
31516 D3D11_TEXTURE2D_DESC texture_desc;
31517 D3D_FEATURE_LEVEL feature_level;
31518 D3D11_SAMPLER_DESC sampler_desc;
31519 ID3D11DepthStencilView *dsview;
31520 ID3D11BlendState *blend_state;
31521 ID3D11DeviceContext *context;
31522 D3D11_BLEND_DESC blend_desc;
31523 ID3D11SamplerState *sampler;
31524 struct resource_readback rb;
31525 ID3D11PixelShader *ps;
31526 ID3D11Device *device;
31527 unsigned int x, y;
31528 unsigned int i;
31529 D3D11_BOX box;
31530 DWORD color;
31531 HRESULT hr;
31533 static const DWORD ps_ld_code[] =
31535 #if 0
31536 Texture2D t;
31538 struct PS_OUTPUT
31540 float4 color0: SV_Target0;
31541 float4 color1: SV_Target1;
31544 PS_OUTPUT main(float4 position : SV_POSITION)
31546 PS_OUTPUT output;
31547 float3 p;
31549 t.GetDimensions(0, p.x, p.y, p.z);
31550 p.z = 0;
31551 p *= float3(position.x / 640.0f, position.y / 480.0f, 1.0f);
31552 output.color0 = output.color1 = t.Load(int3(p)) + float4(0.25, 0.25, 0.25, 0.25);
31553 return output;
31555 #endif
31556 0x43425844, 0x08dd0517, 0x07d7e538, 0x4cad261f, 0xa2ae5942, 0x00000001, 0x00000200, 0x00000003,
31557 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31558 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000030f, 0x505f5653, 0x5449534f, 0x004e4f49,
31559 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
31560 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
31561 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x0000014c, 0x00000040, 0x00000053, 0x04001858,
31562 0x00107000, 0x00000000, 0x00005555, 0x04002064, 0x00101032, 0x00000000, 0x00000001, 0x03000065,
31563 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x02000068, 0x00000001, 0x0700003d,
31564 0x001000f2, 0x00000000, 0x00004001, 0x00000000, 0x00107e46, 0x00000000, 0x07000038, 0x00100032,
31565 0x00000000, 0x00100046, 0x00000000, 0x00101046, 0x00000000, 0x0a000038, 0x00100032, 0x00000000,
31566 0x00100046, 0x00000000, 0x00004002, 0x3acccccd, 0x3b088889, 0x00000000, 0x00000000, 0x08000036,
31567 0x001000c2, 0x00000000, 0x00004002, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x0500001b,
31568 0x001000f2, 0x00000000, 0x00100e46, 0x00000000, 0x0700002d, 0x001000f2, 0x00000000, 0x00100e46,
31569 0x00000000, 0x00107e46, 0x00000000, 0x0a000000, 0x001000f2, 0x00000000, 0x00100e46, 0x00000000,
31570 0x00004002, 0x3e800000, 0x3e800000, 0x3e800000, 0x3e800000, 0x05000036, 0x001020f2, 0x00000000,
31571 0x00100e46, 0x00000000, 0x05000036, 0x001020f2, 0x00000001, 0x00100e46, 0x00000000, 0x0100003e,
31573 static const float red[] = {1.0f, 0.0f, 0.0f, 0.5f};
31574 static const struct
31576 DXGI_FORMAT texture_format, dsv_format, srv_format;
31577 UINT dsv_flags;
31578 BOOL srv_bind_allowed;
31580 ds_tests[] =
31582 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
31583 0, FALSE},
31584 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_R24_UNORM_X8_TYPELESS,
31585 D3D11_DSV_READ_ONLY_DEPTH, TRUE},
31586 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_X24_TYPELESS_G8_UINT,
31587 D3D11_DSV_READ_ONLY_DEPTH, FALSE},
31588 {DXGI_FORMAT_R24G8_TYPELESS, DXGI_FORMAT_D24_UNORM_S8_UINT, DXGI_FORMAT_X24_TYPELESS_G8_UINT,
31589 D3D11_DSV_READ_ONLY_STENCIL, TRUE},
31590 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT,
31591 0, FALSE},
31592 {DXGI_FORMAT_R32_TYPELESS, DXGI_FORMAT_D32_FLOAT, DXGI_FORMAT_R32_FLOAT,
31593 D3D11_DSV_READ_ONLY_DEPTH, TRUE},
31596 if (!init_test_context(&test_context, NULL))
31597 return;
31599 device = test_context.device;
31600 context = test_context.immediate_context;
31602 feature_level = ID3D11Device_GetFeatureLevel(device);
31604 texture_desc.SampleDesc.Count = 1;
31605 texture_desc.SampleDesc.Quality = 0;
31606 texture_desc.Usage = D3D11_USAGE_DEFAULT;
31607 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
31608 texture_desc.CPUAccessFlags = 0;
31609 texture_desc.MiscFlags = 0;
31611 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
31612 sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
31613 sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
31614 sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
31615 sampler_desc.MipLODBias = 0.0f;
31616 sampler_desc.MaxAnisotropy = 0;
31617 sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER;
31618 sampler_desc.BorderColor[0] = 0.0f;
31619 sampler_desc.BorderColor[1] = 0.0f;
31620 sampler_desc.BorderColor[2] = 0.0f;
31621 sampler_desc.BorderColor[3] = 0.0f;
31622 sampler_desc.MinLOD = 0.0f;
31623 sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
31625 hr = ID3D11Device_CreatePixelShader(device, ps_ld_code, sizeof(ps_ld_code), NULL, &ps);
31626 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31628 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31630 texture_desc.Width = 64;
31631 texture_desc.Height = 64;
31632 texture_desc.MipLevels = 2;
31633 texture_desc.ArraySize = 1;
31634 texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31636 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
31637 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31639 texture_desc.Width = 640;
31640 texture_desc.Height = 480;
31641 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture2);
31642 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31644 sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
31645 sampler_desc.MipLODBias = 0.0f;
31646 sampler_desc.MinLOD = 0.0f;
31647 sampler_desc.MaxLOD = 0.0f;
31649 hr = ID3D11Device_CreateSamplerState(device, &sampler_desc, &sampler);
31650 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31652 ID3D11DeviceContext_PSSetSamplers(context, 0, 1, &sampler);
31654 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
31656 memset(&rtv_desc, 0, sizeof(rtv_desc));
31657 rtv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31658 rtv_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
31659 U(rtv_desc).Texture2D.MipSlice = 0;
31661 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv);
31662 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31663 U(rtv_desc).Texture2D.MipSlice = 1;
31664 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture2, &rtv_desc, &rtv2);
31665 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31667 rtvs[0] = test_context.backbuffer_rtv;
31668 rtvs[1] = rtv;
31670 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31672 memset(&srv_desc, 0, sizeof(srv_desc));
31673 srv_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
31674 srv_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
31675 U(srv_desc).Texture2D.MipLevels = 1;
31677 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, &srv_desc, &srv);
31678 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31679 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31681 draw_quad(&test_context);
31683 set_box(&box, 0, 0, 0, 320, 240, 1);
31684 ID3D11DeviceContext_CopySubresourceRegion(context, (ID3D11Resource *)texture2, 1, 0, 0, 0, (ID3D11Resource *)texture2, 0, &box);
31686 get_texture_readback(texture2, 0, &rb);
31687 for (y = 0; y < 4; ++y)
31689 for (x = 0; x < 4; ++x)
31691 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31692 ok(compare_color(color, 0x40404040, 2),
31693 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31696 release_resource_readback(&rb);
31697 get_texture_readback(texture2, 1, &rb);
31698 for (y = 0; y < 4; ++y)
31700 for (x = 0; x < 4; ++x)
31702 color = get_readback_color(&rb, 40 + x * 80, 30 + y * 60, 0);
31703 ok(compare_color(color, 0x40404040, 2),
31704 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31707 release_resource_readback(&rb);
31709 ID3D11ShaderResourceView_Release(srv);
31710 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31712 ID3D11DeviceContext_ClearRenderTargetView(context, rtv, red);
31714 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv);
31715 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31717 U(srv_desc).Texture2D.MostDetailedMip = 1;
31718 U(srv_desc).Texture2D.MipLevels = 1;
31719 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture2, &srv_desc, &srv2);
31720 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31722 memset(&blend_desc, 0, sizeof(blend_desc));
31723 blend_desc.IndependentBlendEnable = TRUE;
31724 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
31725 blend_desc.RenderTarget[1].RenderTargetWriteMask = 0;
31726 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
31727 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31728 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
31729 ID3D11BlendState_Release(blend_state);
31731 /* SRV does not get bound if resource is attached as render target, even if write mask is 0. */
31732 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31733 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31734 ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
31736 blend_desc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
31737 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
31738 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31739 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
31740 ID3D11BlendState_Release(blend_state);
31742 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, red);
31744 draw_quad(&test_context);
31745 draw_quad(&test_context);
31747 get_texture_readback(test_context.backbuffer, 0, &rb);
31748 for (y = 0; y < 4; ++y)
31750 for (x = 0; x < 4; ++x)
31752 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31753 ok(compare_color(color, 0x40404040, 2),
31754 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31757 release_resource_readback(&rb);
31759 get_texture_readback(texture2, 0, &rb);
31760 for (y = 0; y < 4; ++y)
31762 for (x = 0; x < 4; ++x)
31764 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31765 ok(compare_color(color, 0x40404040, 2),
31766 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31769 release_resource_readback(&rb);
31771 ID3D11DeviceContext_OMSetRenderTargets(context, 1, &test_context.backbuffer_rtv, NULL);
31772 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv);
31773 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31774 ok(!!srv_test, "Unexpected SRV %p.\n", srv_test);
31775 ID3D11ShaderResourceView_Release(srv_test);
31777 draw_quad(&test_context);
31778 get_texture_readback(test_context.backbuffer, 0, &rb);
31779 for (y = 0; y < 4; ++y)
31781 for (x = 0; x < 4; ++x)
31783 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31784 ok(compare_color(color, 0x80808080, 2),
31785 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31788 release_resource_readback(&rb);
31790 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31792 /* SRV is reset when the same resource is set as render target. */
31793 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31794 ok(!srv_test, "Unexpected SRV %p.\n", srv_test);
31796 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv2);
31797 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31798 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31799 ok(!!srv_test, "Unexpected SRV %p.\n", srv_test);
31800 ID3D11ShaderResourceView_Release(srv_test);
31802 draw_quad(&test_context);
31803 get_texture_readback(test_context.backbuffer, 0, &rb);
31804 for (y = 0; y < 4; ++y)
31806 for (x = 0; x < 4; ++x)
31808 color = get_readback_color(&rb, 80 + x * 160, 60 + y * 120, 0);
31809 ok(compare_color(color, 0x80808080, 2),
31810 "Got unexpected color 0x%08x at (%u, %u).\n", color, x, y);
31813 release_resource_readback(&rb);
31815 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_DEPTH_STENCIL;
31816 memset(&dsview_desc, 0, sizeof(dsview_desc));
31817 dsview_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
31819 memset(&srvds_desc, 0, sizeof(srvds_desc));
31820 srvds_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
31821 U(srvds_desc).Texture2D.MipLevels = 1;
31823 for (i = 0; i < ARRAY_SIZE(ds_tests); ++i)
31825 if (ds_tests[i].dsv_flags && feature_level < D3D_FEATURE_LEVEL_11_0)
31827 static unsigned int skip_once;
31829 if (!skip_once++)
31830 skip("Read only depths or stencils are not supported.\n");
31832 continue;
31835 texture_desc.Format = ds_tests[i].texture_format;
31836 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &dstexture);
31837 ok(hr == S_OK, "Test %u, got unexpected hr %#x.\n", i, hr);
31838 dsview_desc.Format = ds_tests[i].dsv_format;
31839 dsview_desc.Flags = ds_tests[i].dsv_flags;
31840 hr = ID3D11Device_CreateDepthStencilView(device, (ID3D11Resource *)dstexture, &dsview_desc, &dsview);
31841 ok(hr == S_OK, "Test %u, got unexpected hr %#x.\n", i, hr);
31843 srvds_desc.Format = ds_tests[i].srv_format;
31844 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)dstexture, &srvds_desc, &srv_ds);
31845 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
31847 ID3D11DeviceContext_OMSetRenderTargets(context, 1, rtvs, NULL);
31848 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_ds);
31849 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31850 ok(!!srv_test, "Test %u, unexpected SRV %p.\n", i, srv_test);
31851 ID3D11ShaderResourceView_Release(srv_test);
31853 ID3D11DeviceContext_OMSetRenderTargets(context, 1, rtvs, dsview);
31854 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31855 ok(!!srv_test == ds_tests[i].srv_bind_allowed, "Test %u, unexpected SRV %p.\n", i, srv_test);
31856 if (srv_test)
31857 ID3D11ShaderResourceView_Release(srv_test);
31859 ID3D11DeviceContext_PSSetShaderResources(context, 0, 1, &srv_ds);
31860 ID3D11DeviceContext_PSGetShaderResources(context, 0, 1, &srv_test);
31861 ok(!!srv_test == ds_tests[i].srv_bind_allowed, "Test %u, unexpected SRV %p.\n", i, srv_test);
31862 if (srv_test)
31863 ID3D11ShaderResourceView_Release(srv_test);
31865 ID3D11Texture2D_Release(dstexture);
31866 ID3D11DepthStencilView_Release(dsview);
31867 ID3D11ShaderResourceView_Release(srv_ds);
31870 ID3D11DeviceContext_OMSetRenderTargets(context, 2, rtvs, NULL);
31872 ID3D11RenderTargetView_Release(rtv2);
31873 ID3D11RenderTargetView_Release(rtv);
31874 ID3D11ShaderResourceView_Release(srv2);
31875 ID3D11ShaderResourceView_Release(srv);
31876 ID3D11SamplerState_Release(sampler);
31877 ID3D11PixelShader_Release(ps);
31878 ID3D11Texture2D_Release(texture2);
31879 ID3D11Texture2D_Release(texture);
31880 ID3D11SamplerState_Release(sampler);
31882 release_test_context(&test_context);
31885 static void test_color_mask(void)
31887 struct d3d11_test_context test_context;
31888 D3D11_TEXTURE2D_DESC texture_desc;
31889 ID3D11RenderTargetView *rtvs[8];
31890 ID3D11BlendState *blend_state;
31891 ID3D11DeviceContext *context;
31892 struct resource_readback rb;
31893 D3D11_BLEND_DESC blend_desc;
31894 ID3D11Texture2D *rts[8];
31895 ID3D11PixelShader *ps;
31896 ID3D11Device *device;
31897 unsigned int i;
31898 DWORD color;
31899 HRESULT hr;
31901 static const DWORD expected_colors[] =
31902 {0xff000080, 0xff0080ff, 0xff8000ff, 0x80808080, 0x800000ff, 0xff008080, 0x800080ff, 0xff0000ff};
31904 static const DWORD ps_code[] =
31906 #if 0
31907 void main(float4 position : SV_Position,
31908 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
31909 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
31910 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
31911 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
31913 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.5f, 0.5f, 0.5f, 0.5f);
31915 #endif
31916 0x43425844, 0x7b1ab233, 0xdbe32d3b, 0x77084cc5, 0xe874d2b5, 0x00000001, 0x000002b0, 0x00000003,
31917 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
31918 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
31919 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
31920 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
31921 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
31922 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
31923 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
31924 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
31925 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
31926 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
31927 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
31928 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
31929 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3f000000,
31930 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3f000000,
31931 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3f000000,
31932 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3f000000,
31933 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3f000000,
31934 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3f000000,
31935 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3f000000,
31936 0x3f000000, 0x3f000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3f000000,
31937 0x3f000000, 0x3f000000, 0x3f000000, 0x0100003e,
31940 static const float red[] = {1.0f, 0.0f, 0.0f, 1.0f};
31942 if (!init_test_context(&test_context, NULL))
31943 return;
31945 device = test_context.device;
31946 context = test_context.immediate_context;
31948 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
31949 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
31950 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
31952 memset(&blend_desc, 0, sizeof(blend_desc));
31953 blend_desc.IndependentBlendEnable = TRUE;
31954 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED;
31955 blend_desc.RenderTarget[1].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN;
31956 blend_desc.RenderTarget[2].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_BLUE;
31957 blend_desc.RenderTarget[3].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
31958 blend_desc.RenderTarget[4].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALPHA;
31959 blend_desc.RenderTarget[5].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED | D3D11_COLOR_WRITE_ENABLE_GREEN;
31960 blend_desc.RenderTarget[6].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN | D3D11_COLOR_WRITE_ENABLE_ALPHA;
31961 blend_desc.RenderTarget[7].RenderTargetWriteMask = 0;
31963 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
31964 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
31965 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
31966 ID3D11BlendState_Release(blend_state);
31968 for (i = 0; i < 8; ++i)
31970 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
31971 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
31972 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
31974 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
31975 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
31978 ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
31980 for (i = 0; i < 8; ++i)
31981 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], red);
31982 draw_quad(&test_context);
31984 for (i = 0; i < 8; ++i)
31986 get_texture_readback(rts[i], 0, &rb);
31987 color = get_readback_color(&rb, 320, 240, 0);
31988 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
31989 release_resource_readback(&rb);
31992 blend_desc.IndependentBlendEnable = FALSE;
31993 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
31994 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
31995 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
31996 ID3D11BlendState_Release(blend_state);
31998 for (i = 0; i < 8; ++i)
31999 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], red);
32000 draw_quad(&test_context);
32002 for (i = 0; i < 8; ++i)
32004 get_texture_readback(rts[i], 0, &rb);
32005 color = get_readback_color(&rb, 320, 240, 0);
32006 ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32007 release_resource_readback(&rb);
32009 ID3D11Texture2D_Release(rts[i]);
32010 ID3D11RenderTargetView_Release(rtvs[i]);
32013 ID3D11PixelShader_Release(ps);
32014 release_test_context(&test_context);
32017 static void test_independent_blend(void)
32019 struct d3d11_test_context test_context;
32020 D3D11_TEXTURE2D_DESC texture_desc;
32021 ID3D11RenderTargetView *rtvs[8];
32022 ID3D11BlendState *blend_state;
32023 ID3D11DeviceContext *context;
32024 struct resource_readback rb;
32025 ID3D11Texture2D *rts[8];
32026 ID3D11PixelShader *ps;
32027 ID3D11Device *device;
32028 unsigned int i;
32029 DWORD color;
32030 HRESULT hr;
32032 static const DWORD ps_code[] =
32034 #if 0
32035 void main(float4 position : SV_Position,
32036 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1,
32037 out float4 t2 : SV_Target2, out float4 t3 : SV_Target3,
32038 out float4 t4 : SV_Target4, out float4 t5 : SV_Target5,
32039 out float4 t6 : SV_Target6, out float4 t7 : SV_Target7)
32041 t0 = t1 = t2 = t3 = t4 = t5 = t6 = t7 = float4(0.1f, 0.2f, 0.3f, 0.4f);
32043 #endif
32044 0x43425844, 0xb3dca7dc, 0x4a31f0f1, 0x747569cb, 0xae7af5ce, 0x00000001, 0x000002b0, 0x00000003,
32045 0x0000002c, 0x00000060, 0x0000013c, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
32046 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
32047 0x4e47534f, 0x000000d4, 0x00000008, 0x00000008, 0x000000c8, 0x00000000, 0x00000000, 0x00000003,
32048 0x00000000, 0x0000000f, 0x000000c8, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
32049 0x000000c8, 0x00000002, 0x00000000, 0x00000003, 0x00000002, 0x0000000f, 0x000000c8, 0x00000003,
32050 0x00000000, 0x00000003, 0x00000003, 0x0000000f, 0x000000c8, 0x00000004, 0x00000000, 0x00000003,
32051 0x00000004, 0x0000000f, 0x000000c8, 0x00000005, 0x00000000, 0x00000003, 0x00000005, 0x0000000f,
32052 0x000000c8, 0x00000006, 0x00000000, 0x00000003, 0x00000006, 0x0000000f, 0x000000c8, 0x00000007,
32053 0x00000000, 0x00000003, 0x00000007, 0x0000000f, 0x545f5653, 0x65677261, 0xabab0074, 0x52444853,
32054 0x0000016c, 0x00000040, 0x0000005b, 0x03000065, 0x001020f2, 0x00000000, 0x03000065, 0x001020f2,
32055 0x00000001, 0x03000065, 0x001020f2, 0x00000002, 0x03000065, 0x001020f2, 0x00000003, 0x03000065,
32056 0x001020f2, 0x00000004, 0x03000065, 0x001020f2, 0x00000005, 0x03000065, 0x001020f2, 0x00000006,
32057 0x03000065, 0x001020f2, 0x00000007, 0x08000036, 0x001020f2, 0x00000000, 0x00004002, 0x3dcccccd,
32058 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000001, 0x00004002, 0x3dcccccd,
32059 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000002, 0x00004002, 0x3dcccccd,
32060 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000003, 0x00004002, 0x3dcccccd,
32061 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000004, 0x00004002, 0x3dcccccd,
32062 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000005, 0x00004002, 0x3dcccccd,
32063 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000006, 0x00004002, 0x3dcccccd,
32064 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x08000036, 0x001020f2, 0x00000007, 0x00004002, 0x3dcccccd,
32065 0x3e4ccccd, 0x3e99999a, 0x3ecccccd, 0x0100003e,
32068 D3D11_BLEND_DESC blend_desc =
32070 .IndependentBlendEnable = TRUE,
32071 .RenderTarget =
32073 {TRUE, D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD,
32074 D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32075 {TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ZERO, D3D11_BLEND_OP_ADD,
32076 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32077 {TRUE, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_OP_ADD,
32078 D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_DEST_ALPHA, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32079 {TRUE, D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN,
32080 D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_MIN, D3D11_COLOR_WRITE_ENABLE_ALL},
32081 {TRUE, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_BLEND_FACTOR, D3D11_BLEND_OP_ADD,
32082 D3D11_BLEND_ZERO, D3D11_BLEND_ONE, D3D11_BLEND_OP_ADD, D3D11_COLOR_WRITE_ENABLE_ALL},
32083 {TRUE, D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_BLEND_FACTOR, D3D11_BLEND_OP_SUBTRACT,
32084 D3D11_BLEND_ONE, D3D11_BLEND_ONE, D3D11_BLEND_OP_REV_SUBTRACT, D3D11_COLOR_WRITE_ENABLE_ALL},
32085 {FALSE, 0, 0, 0, 0, 0, 0, D3D11_COLOR_WRITE_ENABLE_ALL},
32086 {TRUE, D3D11_BLEND_DEST_COLOR, D3D11_BLEND_SRC_COLOR, D3D11_BLEND_OP_ADD,
32087 D3D11_BLEND_INV_SRC_ALPHA, D3D11_BLEND_INV_DEST_ALPHA, D3D11_BLEND_OP_SUBTRACT,
32088 D3D11_COLOR_WRITE_ENABLE_ALL},
32092 static const DWORD expected_colors[] =
32093 {0x66426e1c, 0xb34c3319, 0xa6214a05, 0x66333319, 0xb34c4829, 0x4d19000a, 0x664c3319, 0x081f3305};
32095 static const float clear_color[] = {0.1f, 0.5f, 0.2f, 0.7f};
32096 static const float blend_factor[] = {0.8f, 0.4f, 0.6f, 0.2f};
32098 if (!init_test_context(&test_context, NULL))
32099 return;
32101 device = test_context.device;
32102 context = test_context.immediate_context;
32104 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
32105 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
32106 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32108 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32109 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32110 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
32111 ID3D11BlendState_Release(blend_state);
32113 for (i = 0; i < 8; ++i)
32115 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32116 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &rts[i]);
32117 ok(hr == S_OK, "Failed to create texture %u, hr %#x.\n", i, hr);
32119 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)rts[i], NULL, &rtvs[i]);
32120 ok(hr == S_OK, "Failed to create rendertarget view %u, hr %#x.\n", i, hr);
32123 ID3D11DeviceContext_OMSetRenderTargets(context, 8, rtvs, NULL);
32125 for (i = 0; i < 8; ++i)
32126 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
32127 draw_quad(&test_context);
32129 for (i = 0; i < 8; ++i)
32131 get_texture_readback(rts[i], 0, &rb);
32132 color = get_readback_color(&rb, 320, 240, 0);
32133 ok(compare_color(color, expected_colors[i], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32134 release_resource_readback(&rb);
32137 blend_desc.IndependentBlendEnable = FALSE;
32138 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32139 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32140 ID3D11DeviceContext_OMSetBlendState(context, blend_state, blend_factor, D3D11_DEFAULT_SAMPLE_MASK);
32141 ID3D11BlendState_Release(blend_state);
32143 for (i = 0; i < 8; ++i)
32144 ID3D11DeviceContext_ClearRenderTargetView(context, rtvs[i], clear_color);
32145 draw_quad(&test_context);
32147 for (i = 0; i < 8; ++i)
32149 get_texture_readback(rts[i], 0, &rb);
32150 color = get_readback_color(&rb, 320, 240, 0);
32151 ok(compare_color(color, expected_colors[0], 1), "%u: Got unexpected color 0x%08x.\n", i, color);
32152 release_resource_readback(&rb);
32154 ID3D11Texture2D_Release(rts[i]);
32155 ID3D11RenderTargetView_Release(rtvs[i]);
32158 ID3D11PixelShader_Release(ps);
32159 release_test_context(&test_context);
32162 static void test_dual_source_blend(void)
32164 struct d3d11_test_context test_context;
32165 ID3D11BlendState *blend_state;
32166 ID3D11DeviceContext *context;
32167 ID3D11PixelShader *ps;
32168 ID3D11Device *device;
32169 DWORD color;
32170 HRESULT hr;
32172 static const DWORD ps_code[] =
32174 #if 0
32175 void main(float4 position : SV_Position,
32176 out float4 t0 : SV_Target0, out float4 t1 : SV_Target1)
32178 t0 = float4(0.5, 0.5, 0.0, 1.0);
32179 t1 = float4(0.0, 0.5, 0.5, 0.0);
32181 #endif
32182 0x43425844, 0x87120d01, 0xa0014738, 0x3a32d86c, 0x9d757441, 0x00000001, 0x00000118, 0x00000003,
32183 0x0000002c, 0x00000060, 0x000000ac, 0x4e475349, 0x0000002c, 0x00000001, 0x00000008, 0x00000020,
32184 0x00000000, 0x00000001, 0x00000003, 0x00000000, 0x0000000f, 0x505f5653, 0x7469736f, 0x006e6f69,
32185 0x4e47534f, 0x00000044, 0x00000002, 0x00000008, 0x00000038, 0x00000000, 0x00000000, 0x00000003,
32186 0x00000000, 0x0000000f, 0x00000038, 0x00000001, 0x00000000, 0x00000003, 0x00000001, 0x0000000f,
32187 0x545f5653, 0x65677261, 0xabab0074, 0x52444853, 0x00000064, 0x00000040, 0x00000019, 0x03000065,
32188 0x001020f2, 0x00000000, 0x03000065, 0x001020f2, 0x00000001, 0x08000036, 0x001020f2, 0x00000000,
32189 0x00004002, 0x3f000000, 0x3f000000, 0x00000000, 0x3f000000, 0x08000036, 0x001020f2, 0x00000001,
32190 0x00004002, 0x00000000, 0x3f000000, 0x3f000000, 0x00000000, 0x0100003e
32193 static const D3D11_BLEND_DESC blend_desc =
32195 .RenderTarget[0].BlendEnable = TRUE,
32196 .RenderTarget[0].SrcBlend = D3D11_BLEND_SRC1_COLOR,
32197 .RenderTarget[0].DestBlend = D3D11_BLEND_SRC1_COLOR,
32198 .RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD,
32199 .RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE,
32200 .RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO,
32201 .RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD,
32202 .RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL,
32205 static const float clear_color[] = {0.7f, 0.0f, 1.0f, 1.0f};
32207 if (!init_test_context(&test_context, NULL))
32208 return;
32210 device = test_context.device;
32211 context = test_context.immediate_context;
32213 hr = ID3D11Device_CreatePixelShader(device, ps_code, sizeof(ps_code), NULL, &ps);
32214 ok(hr == S_OK, "Failed to create pixel shader, hr %#x.\n", hr);
32215 ID3D11DeviceContext_PSSetShader(context, ps, NULL, 0);
32217 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blend_state);
32218 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32219 ID3D11DeviceContext_OMSetBlendState(context, blend_state, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32220 ID3D11BlendState_Release(blend_state);
32222 ID3D11DeviceContext_ClearRenderTargetView(context, test_context.backbuffer_rtv, clear_color);
32223 draw_quad(&test_context);
32225 color = get_texture_color(test_context.backbuffer, 320, 240);
32226 ok(compare_color(color, 0x80804000, 1), "Got unexpected color 0x%08x.\n", color);
32228 ID3D11PixelShader_Release(ps);
32229 release_test_context(&test_context);
32232 static void test_deferred_context_state(void)
32234 ID3D11Buffer *green_buffer, *blue_buffer, *ret_buffer;
32235 ID3D11DeviceContext *immediate, *deferred, *deferred2;
32236 ID3D11ShaderResourceView *srv, *ret_srv;
32237 struct d3d11_test_context test_context;
32238 ID3D11RenderTargetView *rtv, *ret_rtv;
32239 D3D11_TEXTURE2D_DESC texture_desc;
32240 ID3D11CommandList *list1, *list2;
32241 ID3D11Texture2D *texture;
32242 ID3D11Device *device;
32243 HRESULT hr;
32245 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32246 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
32248 if (!init_test_context(&test_context, NULL))
32249 return;
32251 device = test_context.device;
32252 immediate = test_context.immediate_context;
32254 green_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(green), &green);
32255 blue_buffer = create_buffer(device, D3D11_BIND_CONSTANT_BUFFER, sizeof(blue), &blue);
32256 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32258 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32259 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32261 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32262 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32264 ID3D11DeviceContext_PSSetConstantBuffers(deferred, 0, 1, &blue_buffer);
32266 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32267 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32268 ID3D11Buffer_Release(ret_buffer);
32270 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32271 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32273 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32274 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32275 ID3D11Buffer_Release(ret_buffer);
32277 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list2);
32278 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32280 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32281 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32283 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32284 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32285 ID3D11DeviceContext_PSGetConstantBuffers(immediate, 0, 1, &ret_buffer);
32286 ok(ret_buffer == green_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32287 ID3D11Buffer_Release(ret_buffer);
32289 ID3D11DeviceContext_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32290 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
32291 ID3D11DeviceContext_PSGetConstantBuffers(immediate, 0, 1, &ret_buffer);
32292 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32294 ID3D11CommandList_Release(list2);
32295 ID3D11CommandList_Release(list1);
32297 /* Test recording a command list into another deferred context. */
32299 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred2);
32300 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32302 ID3D11DeviceContext_PSSetConstantBuffers(deferred2, 0, 1, &green_buffer);
32304 hr = ID3D11DeviceContext_FinishCommandList(deferred2, FALSE, &list1);
32305 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32307 ID3D11DeviceContext_PSSetConstantBuffers(deferred, 0, 1, &blue_buffer);
32308 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, TRUE);
32309 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32310 ok(ret_buffer == blue_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32311 ID3D11Buffer_Release(ret_buffer);
32313 ID3D11DeviceContext_PSSetConstantBuffers(deferred, 0, 1, &blue_buffer);
32314 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, FALSE);
32315 ID3D11DeviceContext_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32316 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32318 ID3D11CommandList_Release(list1);
32319 ID3D11DeviceContext_Release(deferred2);
32321 /* Test unbinding an SRV when using the same resource as RTV. */
32323 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32324 texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET;
32325 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
32326 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
32327 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
32328 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32329 hr = ID3D11Device_CreateShaderResourceView(device, (ID3D11Resource *)texture, NULL, &srv);
32330 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32332 ID3D11DeviceContext_PSSetShaderResources(deferred, 0, 1, &srv);
32333 ID3D11DeviceContext_PSGetShaderResources(deferred, 0, 1, &ret_srv);
32334 ok(ret_srv == srv, "Got unexpected SRV %p.\n", ret_srv);
32335 ID3D11ShaderResourceView_Release(ret_srv);
32337 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &rtv, NULL);
32338 ID3D11DeviceContext_OMGetRenderTargets(deferred, 1, &ret_rtv, NULL);
32339 ok(ret_rtv == rtv, "Got unexpected RTV %p.\n", ret_rtv);
32340 ID3D11RenderTargetView_Release(ret_rtv);
32341 ID3D11DeviceContext_PSGetShaderResources(deferred, 0, 1, &ret_srv);
32342 ok(!ret_srv, "Got unexpected SRV %p.\n", ret_srv);
32344 ID3D11DeviceContext_PSSetShaderResources(deferred, 0, 1, &srv);
32345 ID3D11DeviceContext_PSGetShaderResources(deferred, 0, 1, &ret_srv);
32346 ok(!ret_srv, "Got unexpected SRV %p.\n", ret_srv);
32348 ID3D11DeviceContext_PSSetShaderResources(immediate, 0, 1, &srv);
32349 ID3D11DeviceContext_PSGetShaderResources(immediate, 0, 1, &ret_srv);
32350 ok(ret_srv == srv, "Got unexpected SRV %p.\n", ret_srv);
32351 ID3D11ShaderResourceView_Release(ret_srv);
32353 ID3D11ShaderResourceView_Release(srv);
32354 ID3D11RenderTargetView_Release(rtv);
32355 ID3D11Texture2D_Release(texture);
32356 ID3D11DeviceContext_Release(deferred);
32357 ID3D11Buffer_Release(blue_buffer);
32358 ID3D11Buffer_Release(green_buffer);
32359 release_test_context(&test_context);
32362 static void test_deferred_context_swap_state(void)
32364 ID3D11DeviceContext1 *immediate, *deferred;
32365 ID3DDeviceContextState *state, *prev_state;
32366 ID3D11Buffer *green_buffer, *ret_buffer;
32367 struct d3d11_test_context test_context;
32368 D3D_FEATURE_LEVEL feature_level;
32369 ID3D11Device1 *device;
32370 HRESULT hr;
32372 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32374 if (!init_test_context(&test_context, NULL))
32375 return;
32377 if (FAILED(ID3D11Device_QueryInterface(test_context.device, &IID_ID3D11Device1, (void **)&device)))
32379 skip("ID3D11Device1 is not available.\n");
32380 release_test_context(&test_context);
32381 return;
32384 ID3D11Device1_GetImmediateContext1(device, &immediate);
32386 green_buffer = create_buffer(test_context.device, D3D11_BIND_CONSTANT_BUFFER, sizeof(green), &green);
32387 ID3D11DeviceContext1_PSSetConstantBuffers(immediate, 0, 1, &green_buffer);
32389 hr = ID3D11Device1_CreateDeferredContext1(device, 0, &deferred);
32390 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32392 feature_level = ID3D11Device1_GetFeatureLevel(device);
32393 hr = ID3D11Device1_CreateDeviceContextState(device, 0, &feature_level, 1, D3D11_SDK_VERSION,
32394 &IID_ID3D11Device1, NULL, &state);
32395 ok(hr == S_OK, "Failed to create device context state, hr %#x.\n", hr);
32397 prev_state = (void *)0xdeadbeef;
32398 ID3D11DeviceContext1_SwapDeviceContextState(deferred, NULL, &prev_state);
32399 ok(!prev_state, "Got state %p.\n", prev_state);
32401 prev_state = (void *)0xdeadbeef;
32402 ID3D11DeviceContext1_SwapDeviceContextState(deferred, state, &prev_state);
32403 ok(!prev_state, "Got state %p.\n", prev_state);
32405 ID3D11DeviceContext1_PSGetConstantBuffers(deferred, 0, 1, &ret_buffer);
32406 ok(!ret_buffer, "Got unexpected buffer %p.\n", ret_buffer);
32408 ID3DDeviceContextState_Release(state);
32409 ID3D11DeviceContext1_Release(deferred);
32411 ID3D11Buffer_Release(green_buffer);
32412 ID3D11DeviceContext1_Release(immediate);
32413 ID3D11Device1_Release(device);
32414 release_test_context(&test_context);
32417 static void test_deferred_context_rendering(void)
32419 ID3D11BlendState *red_blend, *green_blend, *blue_blend, *ret_blend;
32420 ID3D11DeviceContext *immediate, *deferred, *deferred2;
32421 struct d3d11_test_context test_context;
32422 D3D11_TEXTURE2D_DESC texture_desc;
32423 ID3D11CommandList *list1, *list2;
32424 ID3D11RenderTargetView *rtv;
32425 D3D11_BLEND_DESC blend_desc;
32426 ID3D11Texture2D *texture;
32427 float blend_factor[4];
32428 ID3D11Device *device;
32429 UINT sample_mask;
32430 DWORD color;
32431 HRESULT hr;
32433 static const struct vec4 white = {1.0f, 1.0f, 1.0f, 1.0f};
32434 static const float green[] = {0.0f, 1.0f, 0.0f, 1.0f};
32435 static const float blue[] = {0.0f, 0.0f, 1.0f, 1.0f};
32436 static const float black[] = {0.0f, 0.0f, 0.0f, 1.0f};
32438 if (!init_test_context(&test_context, NULL))
32439 return;
32441 device = test_context.device;
32442 immediate = test_context.immediate_context;
32444 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32445 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32447 memset(&blend_desc, 0, sizeof(blend_desc));
32449 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_RED;
32450 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &red_blend);
32451 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32452 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_GREEN;
32453 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &green_blend);
32454 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32455 blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_BLUE;
32456 hr = ID3D11Device_CreateBlendState(device, &blend_desc, &blue_blend);
32457 ok(hr == S_OK, "Failed to create blend state, hr %#x.\n", hr);
32459 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32461 ID3D11DeviceContext_ClearRenderTargetView(deferred, test_context.backbuffer_rtv, green);
32463 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32464 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32466 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32467 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32469 color = get_texture_color(test_context.backbuffer, 320, 240);
32470 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32472 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32473 color = get_texture_color(test_context.backbuffer, 320, 240);
32474 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32476 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32477 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32478 color = get_texture_color(test_context.backbuffer, 320, 240);
32479 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32481 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32482 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, TRUE);
32483 color = get_texture_color(test_context.backbuffer, 320, 240);
32484 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32486 ID3D11CommandList_Release(list2);
32488 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, TRUE);
32489 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32490 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32492 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32493 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, TRUE);
32494 color = get_texture_color(test_context.backbuffer, 320, 240);
32495 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32497 ID3D11CommandList_Release(list2);
32498 ID3D11CommandList_Release(list1);
32499 ID3D11DeviceContext_Release(deferred);
32501 ID3D11Texture2D_GetDesc(test_context.backbuffer, &texture_desc);
32502 hr = ID3D11Device_CreateTexture2D(device, &texture_desc, NULL, &texture);
32503 ok(hr == S_OK, "Failed to create texture, hr %#x.\n", hr);
32504 hr = ID3D11Device_CreateRenderTargetView(device, (ID3D11Resource *)texture, NULL, &rtv);
32505 ok(hr == S_OK, "Failed to create view, hr %#x.\n", hr);
32507 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, &white.x);
32508 ID3D11DeviceContext_ClearRenderTargetView(immediate, rtv, green);
32510 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32511 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32513 ID3D11DeviceContext_CopyResource(deferred, (ID3D11Resource *)test_context.backbuffer, (ID3D11Resource *)texture);
32515 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32516 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32518 ID3D11DeviceContext_ClearRenderTargetView(immediate, rtv, blue);
32519 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32520 color = get_texture_color(test_context.backbuffer, 320, 240);
32521 ok(color == 0xffff0000, "Got unexpected color %#08x.\n", color);
32523 ID3D11CommandList_Release(list1);
32524 ID3D11DeviceContext_Release(deferred);
32526 /* As Get* calls imply, state changes recorded into a command list do not
32527 * affect subsequent draws after the state is restored or cleared. */
32529 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32530 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32532 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32534 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32535 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32537 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32538 ID3D11DeviceContext_OMSetBlendState(immediate, blue_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32539 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, TRUE);
32540 draw_color_quad(&test_context, &white);
32541 color = get_texture_color(test_context.backbuffer, 320, 240);
32542 ok(color == 0xffff0000, "Got unexpected color %#08x.\n", color);
32544 ID3D11DeviceContext_OMGetBlendState(immediate, &ret_blend, blend_factor, &sample_mask);
32545 ok(ret_blend == blue_blend, "Got unexpected blend state %p.\n", ret_blend);
32546 ID3D11BlendState_Release(ret_blend);
32548 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32549 ID3D11DeviceContext_OMSetBlendState(immediate, blue_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32550 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
32551 ID3D11DeviceContext_OMSetRenderTargets(immediate, 1, &test_context.backbuffer_rtv, NULL);
32552 set_viewport(immediate, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
32553 draw_color_quad(&test_context, &white);
32554 color = get_texture_color(test_context.backbuffer, 320, 240);
32555 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32557 ID3D11DeviceContext_OMGetBlendState(immediate, &ret_blend, blend_factor, &sample_mask);
32558 ok(!ret_blend, "Got unexpected blend state %p.\n", ret_blend);
32560 ID3D11CommandList_Release(list1);
32561 ID3D11DeviceContext_Release(deferred);
32563 /* The clearing of state done by FinishCommandList is captured by a
32564 * subsequent call to FinishCommandList... */
32566 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32567 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32569 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32570 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list1);
32571 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32572 ID3D11CommandList_Release(list1);
32574 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
32575 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
32576 test_context.immediate_context = deferred;
32577 draw_color_quad(&test_context, &white);
32578 test_context.immediate_context = immediate;
32579 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32580 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32582 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32583 ID3D11DeviceContext_OMSetBlendState(immediate, red_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32584 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
32585 color = get_texture_color(test_context.backbuffer, 320, 240);
32586 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32588 ID3D11CommandList_Release(list1);
32590 /* ...and so is the save/restore. */
32592 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32593 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32594 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32595 ID3D11CommandList_Release(list1);
32597 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
32598 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
32599 test_context.immediate_context = deferred;
32600 draw_color_quad(&test_context, &white);
32601 test_context.immediate_context = immediate;
32602 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list1);
32603 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32605 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32606 ID3D11DeviceContext_OMSetBlendState(immediate, red_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32607 ID3D11DeviceContext_ExecuteCommandList(immediate, list1, FALSE);
32608 color = get_texture_color(test_context.backbuffer, 320, 240);
32609 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32611 ID3D11CommandList_Release(list1);
32613 ID3D11DeviceContext_Release(deferred);
32615 /* Similarly, clearing of state done by ExecuteCommandList is captured by a
32616 * subsequent call to FinishCommandList. */
32618 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32619 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32620 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred2);
32621 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32623 ID3D11DeviceContext_OMSetBlendState(deferred2, blue_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32625 hr = ID3D11DeviceContext_FinishCommandList(deferred2, FALSE, &list1);
32626 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32628 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32629 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, FALSE);
32630 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
32631 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
32632 test_context.immediate_context = deferred;
32633 draw_color_quad(&test_context, &white);
32634 test_context.immediate_context = immediate;
32635 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32636 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32638 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32639 ID3D11DeviceContext_OMSetBlendState(immediate, red_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32640 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, FALSE);
32641 color = get_texture_color(test_context.backbuffer, 320, 240);
32642 ok(color == 0xffffffff, "Got unexpected color %#08x.\n", color);
32644 ID3D11CommandList_Release(list2);
32646 /* Make sure that save/restore is handled correctly as well. */
32648 ID3D11DeviceContext_OMSetBlendState(deferred, green_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32649 ID3D11DeviceContext_ExecuteCommandList(deferred, list1, TRUE);
32650 ID3D11DeviceContext_OMSetRenderTargets(deferred, 1, &test_context.backbuffer_rtv, NULL);
32651 set_viewport(deferred, 0.0f, 0.0f, 640.0f, 480.0f, 0.0f, 1.0f);
32652 test_context.immediate_context = deferred;
32653 draw_color_quad(&test_context, &white);
32654 test_context.immediate_context = immediate;
32655 hr = ID3D11DeviceContext_FinishCommandList(deferred, TRUE, &list2);
32656 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32658 ID3D11DeviceContext_ClearRenderTargetView(immediate, test_context.backbuffer_rtv, black);
32659 ID3D11DeviceContext_OMSetBlendState(immediate, red_blend, NULL, D3D11_DEFAULT_SAMPLE_MASK);
32660 ID3D11DeviceContext_ExecuteCommandList(immediate, list2, FALSE);
32661 color = get_texture_color(test_context.backbuffer, 320, 240);
32662 ok(color == 0xff00ff00, "Got unexpected color %#08x.\n", color);
32664 ID3D11CommandList_Release(list2);
32666 ID3D11CommandList_Release(list1);
32667 ID3D11DeviceContext_Release(deferred2);
32668 ID3D11DeviceContext_Release(deferred);
32670 ID3D11BlendState_Release(red_blend);
32671 ID3D11BlendState_Release(green_blend);
32672 ID3D11BlendState_Release(blue_blend);
32673 ID3D11RenderTargetView_Release(rtv);
32674 ID3D11Texture2D_Release(texture);
32675 release_test_context(&test_context);
32678 static void test_deferred_context_map(void)
32680 ID3D11DeviceContext *immediate, *deferred;
32681 struct d3d11_test_context test_context;
32682 D3D11_SUBRESOURCE_DATA resource_data;
32683 D3D11_BUFFER_DESC buffer_desc = {0};
32684 D3D11_MAPPED_SUBRESOURCE map_desc;
32685 ID3D11Buffer *buffer, *buffer2;
32686 struct resource_readback rb;
32687 ID3D11CommandList *list;
32688 float data[16], value;
32689 ID3D11Device *device;
32690 float *map_data;
32691 unsigned int i;
32692 HRESULT hr;
32694 if (!init_test_context(&test_context, NULL))
32695 return;
32697 device = test_context.device;
32698 immediate = test_context.immediate_context;
32700 hr = ID3D11Device_CreateDeferredContext(device, 0, &deferred);
32701 ok(hr == S_OK, "Failed to create deferred context, hr %#x.\n", hr);
32703 for (i = 0; i < ARRAY_SIZE(data); ++i)
32704 data[i] = i;
32705 resource_data.pSysMem = data;
32706 resource_data.SysMemPitch = 0;
32707 resource_data.SysMemSlicePitch = 0;
32709 buffer_desc.ByteWidth = sizeof(data);
32710 buffer_desc.Usage = D3D11_USAGE_DYNAMIC;
32711 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
32712 buffer_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
32713 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
32714 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
32715 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer2);
32716 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
32718 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &map_desc);
32719 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
32721 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
32722 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
32724 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &map_desc);
32725 todo_wine ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
32727 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
32728 todo_wine ok(hr == D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, "Got unexpected hr %#x.\n", hr);
32730 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
32731 todo_wine ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32732 if (hr != S_OK)
32734 ID3D11Buffer_Release(buffer2);
32735 ID3D11Buffer_Release(buffer);
32736 ID3D11DeviceContext_Release(deferred);
32737 release_test_context(&test_context);
32738 return;
32740 map_data = map_desc.pData;
32741 /* The previous contents of map_data are undefined and may in practice be
32742 * uninitialized garbage. */
32743 for (i = 0; i < ARRAY_SIZE(data); ++i)
32744 map_data[i] = 2 * i;
32746 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
32748 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
32749 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32750 map_data = map_desc.pData;
32751 for (i = 0; i < ARRAY_SIZE(data); ++i)
32752 map_data[i] = 3 * i;
32753 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
32755 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
32756 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32758 get_buffer_readback(buffer, &rb);
32759 for (i = 0; i < ARRAY_SIZE(data); ++i)
32761 value = get_readback_float(&rb, i, 0);
32762 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
32764 release_resource_readback(&rb);
32766 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
32768 get_buffer_readback(buffer, &rb);
32769 for (i = 0; i < ARRAY_SIZE(data); ++i)
32771 value = get_readback_float(&rb, i, 0);
32772 ok(value == 3 * i, "Got unexpected value %.8e at %u.\n", value, i);
32774 release_resource_readback(&rb);
32776 ID3D11CommandList_Release(list);
32778 /* Test WRITE_NO_OVERWRITE. */
32780 hr = ID3D11DeviceContext_Map(immediate, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
32781 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32782 map_data = map_desc.pData;
32783 for (i = 0; i < ARRAY_SIZE(data); ++i)
32784 map_data[i] = i;
32785 ID3D11DeviceContext_Unmap(immediate, (ID3D11Resource *)buffer, 0);
32787 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
32788 ok(hr == D3D11_ERROR_DEFERRED_CONTEXT_MAP_WITHOUT_INITIAL_DISCARD, "Got unexpected hr %#x.\n", hr);
32790 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
32791 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32792 map_data = map_desc.pData;
32793 for (i = 0; i < ARRAY_SIZE(data); ++i)
32794 map_data[i] = 2 * i;
32795 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
32797 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ, 0, &map_desc);
32798 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
32800 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_READ_WRITE, 0, &map_desc);
32801 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
32803 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE, 0, &map_desc);
32804 ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr);
32806 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
32807 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32809 map_data = map_desc.pData;
32810 for (i = 0; i < ARRAY_SIZE(data); ++i)
32812 ok(map_data[i] == 2 * i, "Got unexpected value %.8e at %u.\n", map_data[i], i);
32813 if (i % 2)
32814 map_data[i] = 3 * i;
32816 memcpy(data, map_data, sizeof(data));
32818 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
32820 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &map_desc);
32821 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32823 map_data = map_desc.pData;
32824 for (i = 0; i < ARRAY_SIZE(data); ++i)
32826 ok(map_data[i] == data[i], "Got unexpected value %.8e at %u.\n", map_data[i], i);
32827 if (i % 3)
32828 map_data[i] = 4 * i;
32830 memcpy(data, map_data, sizeof(data));
32832 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
32834 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
32835 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32837 get_buffer_readback(buffer, &rb);
32838 for (i = 0; i < ARRAY_SIZE(data); ++i)
32840 value = get_readback_float(&rb, i, 0);
32841 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
32843 release_resource_readback(&rb);
32845 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
32847 get_buffer_readback(buffer, &rb);
32848 for (i = 0; i < ARRAY_SIZE(data); ++i)
32850 value = get_readback_float(&rb, i, 0);
32851 ok(value == data[i], "Got unexpected value %.8e at %u.\n", value, i);
32853 release_resource_readback(&rb);
32855 ID3D11CommandList_Release(list);
32857 /* Do something with the mapped data from within the deferred context. */
32859 hr = ID3D11DeviceContext_Map(immediate, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
32860 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32861 map_data = map_desc.pData;
32862 for (i = 0; i < ARRAY_SIZE(data); ++i)
32863 map_data[i] = i;
32864 ID3D11DeviceContext_Unmap(immediate, (ID3D11Resource *)buffer, 0);
32866 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
32867 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32868 map_data = map_desc.pData;
32869 for (i = 0; i < ARRAY_SIZE(data); ++i)
32870 map_data[i] = 2 * i;
32871 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
32873 ID3D11DeviceContext_CopyResource(deferred, (ID3D11Resource *)buffer2, (ID3D11Resource *)buffer);
32875 hr = ID3D11DeviceContext_Map(deferred, (ID3D11Resource *)buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map_desc);
32876 ok(hr == S_OK, "Got unexpected hr %#x.\n", hr);
32877 map_data = map_desc.pData;
32878 for (i = 0; i < ARRAY_SIZE(data); ++i)
32879 map_data[i] = 3 * i;
32880 ID3D11DeviceContext_Unmap(deferred, (ID3D11Resource *)buffer, 0);
32882 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
32883 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32885 get_buffer_readback(buffer, &rb);
32886 for (i = 0; i < ARRAY_SIZE(data); ++i)
32888 value = get_readback_float(&rb, i, 0);
32889 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
32891 release_resource_readback(&rb);
32893 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
32895 get_buffer_readback(buffer2, &rb);
32896 for (i = 0; i < ARRAY_SIZE(data); ++i)
32898 value = get_readback_float(&rb, i, 0);
32899 ok(value == 2 * i, "Got unexpected value %.8e at %u.\n", value, i);
32901 release_resource_readback(&rb);
32903 get_buffer_readback(buffer, &rb);
32904 for (i = 0; i < ARRAY_SIZE(data); ++i)
32906 value = get_readback_float(&rb, i, 0);
32907 ok(value == 3 * i, "Got unexpected value %.8e at %u.\n", value, i);
32909 release_resource_readback(&rb);
32911 ID3D11CommandList_Release(list);
32913 ID3D11Buffer_Release(buffer2);
32914 ID3D11Buffer_Release(buffer);
32916 /* Test UpdateSubresource. */
32918 for (i = 0; i < ARRAY_SIZE(data); ++i)
32919 data[i] = i;
32921 buffer_desc.ByteWidth = sizeof(data);
32922 buffer_desc.Usage = D3D11_USAGE_DEFAULT;
32923 buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
32924 buffer_desc.CPUAccessFlags = 0;
32925 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer);
32926 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
32927 hr = ID3D11Device_CreateBuffer(device, &buffer_desc, &resource_data, &buffer2);
32928 ok(hr == S_OK, "Failed to create buffer, hr %#x.\n", hr);
32930 for (i = 0; i < ARRAY_SIZE(data); ++i)
32931 data[i] = 2 * i;
32932 ID3D11DeviceContext_UpdateSubresource(deferred, (ID3D11Resource *)buffer, 0, NULL, data, 0, 0);
32934 hr = ID3D11DeviceContext_FinishCommandList(deferred, FALSE, &list);
32935 ok(hr == S_OK, "Failed to create command list, hr %#x.\n", hr);
32937 get_buffer_readback(buffer, &rb);
32938 for (i = 0; i < ARRAY_SIZE(data); ++i)
32940 value = get_readback_float(&rb, i, 0);
32941 ok(value == i, "Got unexpected value %.8e at %u.\n", value, i);
32943 release_resource_readback(&rb);
32945 ID3D11DeviceContext_ExecuteCommandList(immediate, list, TRUE);
32947 get_buffer_readback(buffer, &rb);
32948 for (i = 0; i < ARRAY_SIZE(data); ++i)
32950 value = get_readback_float(&rb, i, 0);
32951 ok(value == 2 * i, "Got unexpected value %.8e at %u.\n", value, i);
32953 release_resource_readback(&rb);
32955 ID3D11CommandList_Release(list);
32957 ID3D11Buffer_Release(buffer2);
32958 ID3D11Buffer_Release(buffer);
32960 ID3D11DeviceContext_Release(deferred);
32961 release_test_context(&test_context);
32964 START_TEST(d3d11)
32966 unsigned int argc, i;
32967 char **argv;
32969 use_mt = !getenv("WINETEST_NO_MT_D3D");
32971 argc = winetest_get_mainargs(&argv);
32972 for (i = 2; i < argc; ++i)
32974 if (!strcmp(argv[i], "--validate"))
32975 enable_debug_layer = TRUE;
32976 else if (!strcmp(argv[i], "--warp"))
32977 use_warp_adapter = TRUE;
32978 else if (!strcmp(argv[i], "--adapter") && i + 1 < argc)
32979 use_adapter_idx = atoi(argv[++i]);
32980 else if (!strcmp(argv[i], "--single"))
32981 use_mt = FALSE;
32984 print_adapter_info();
32986 queue_test(test_create_device);
32987 queue_for_each_feature_level(test_device_interfaces);
32988 queue_test(test_immediate_context);
32989 queue_test(test_create_deferred_context);
32990 queue_test(test_create_texture1d);
32991 queue_test(test_texture1d_interfaces);
32992 queue_test(test_create_texture2d);
32993 queue_test(test_texture2d_interfaces);
32994 queue_test(test_create_texture3d);
32995 queue_test(test_texture3d_interfaces);
32996 queue_test(test_create_buffer);
32997 queue_test(test_create_depthstencil_view);
32998 queue_test(test_depthstencil_view_interfaces);
32999 queue_test(test_create_rendertarget_view);
33000 queue_test(test_create_shader_resource_view);
33001 queue_for_each_feature_level(test_create_shader);
33002 queue_test(test_create_sampler_state);
33003 queue_test(test_create_blend_state);
33004 queue_test(test_create_depthstencil_state);
33005 queue_test(test_create_rasterizer_state);
33006 queue_test(test_create_query);
33007 queue_test(test_occlusion_query);
33008 queue_test(test_pipeline_statistics_query);
33009 queue_test(test_timestamp_query);
33010 queue_test(test_so_statistics_query);
33011 queue_test(test_device_removed_reason);
33012 queue_test(test_private_data);
33013 queue_for_each_feature_level(test_state_refcounting);
33014 queue_test(test_device_context_state);
33015 queue_test(test_blend);
33016 queue_test(test_texture1d);
33017 queue_test(test_texture);
33018 queue_test(test_cube_maps);
33019 queue_test(test_depth_stencil_sampling);
33020 queue_test(test_sample_c_lz);
33021 queue_test(test_multiple_render_targets);
33022 queue_test(test_render_target_views);
33023 queue_test(test_layered_rendering);
33024 queue_test(test_scissor);
33025 queue_test(test_clear_state);
33026 queue_test(test_il_append_aligned);
33027 queue_test(test_instanced_draw);
33028 queue_test(test_vertex_id);
33029 queue_test(test_fragment_coords);
33030 queue_test(test_initial_texture_data);
33031 queue_test(test_update_subresource);
33032 queue_test(test_copy_subresource_region);
33033 queue_test(test_copy_subresource_region_1d);
33034 queue_test(test_copy_subresource_region_3d);
33035 queue_test(test_resource_map);
33036 queue_for_each_feature_level(test_resource_access);
33037 queue_test(test_check_multisample_quality_levels);
33038 queue_for_each_feature_level(test_swapchain_formats);
33039 queue_test(test_swapchain_views);
33040 queue_test(test_swapchain_flip);
33041 queue_test(test_clear_render_target_view_1d);
33042 queue_test(test_clear_render_target_view_2d);
33043 queue_test(test_clear_render_target_view_3d);
33044 queue_test(test_clear_depth_stencil_view);
33045 queue_test(test_clear_buffer_unordered_access_view);
33046 queue_test(test_initial_depth_stencil_state);
33047 queue_test(test_draw_depth_only);
33048 queue_test(test_draw_uav_only);
33049 queue_test(test_cb_relative_addressing);
33050 queue_test(test_vs_input_relative_addressing);
33051 queue_test(test_getdc);
33052 queue_test(test_shader_stage_input_output_matching);
33053 queue_test(test_shader_interstage_interface);
33054 queue_test(test_sm4_if_instruction);
33055 queue_test(test_sm4_breakc_instruction);
33056 queue_test(test_sm4_continuec_instruction);
33057 queue_test(test_sm4_discard_instruction);
33058 queue_test(test_sm5_swapc_instruction);
33059 queue_test(test_create_input_layout);
33060 queue_test(test_input_layout_alignment);
33061 queue_test(test_input_assembler);
33062 queue_test(test_null_sampler);
33063 queue_test(test_check_feature_support);
33064 queue_test(test_create_unordered_access_view);
33065 queue_test(test_immediate_constant_buffer);
33066 queue_test(test_fp_specials);
33067 queue_test(test_uint_shader_instructions);
33068 queue_test(test_index_buffer_offset);
33069 queue_test(test_face_culling);
33070 queue_test(test_line_antialiasing_blending);
33071 queue_for_each_feature_level(test_format_support);
33072 queue_for_each_9_x_feature_level(test_fl9_draw);
33073 queue_test(test_ddy);
33074 queue_test(test_shader_input_registers_limits);
33075 queue_test(test_unbind_shader_resource_view);
33076 queue_test(test_stencil_separate);
33077 queue_test(test_uav_load);
33078 queue_test(test_cs_uav_store);
33079 queue_test(test_uav_store_immediate_constant);
33080 queue_test(test_ps_cs_uav_binding);
33081 queue_test(test_atomic_instructions);
33082 queue_test(test_sm4_ret_instruction);
33083 queue_test(test_primitive_restart);
33084 queue_test(test_resinfo_instruction);
33085 queue_test(test_sm5_bufinfo_instruction);
33086 queue_test(test_sampleinfo_instruction);
33087 queue_test(test_render_target_device_mismatch);
33088 queue_test(test_buffer_srv);
33089 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
33090 test_unaligned_raw_buffer_access);
33091 queue_test(test_uav_counters);
33092 queue_test(test_dispatch_indirect);
33093 queue_test(test_compute_shader_registers);
33094 queue_test(test_tgsm);
33095 queue_test(test_geometry_shader);
33096 queue_test(test_quad_tessellation);
33097 queue_test(test_stream_output);
33098 queue_test(test_fl10_stream_output_desc);
33099 queue_test(test_stream_output_resume);
33100 queue_test(test_stream_output_components);
33101 queue_test(test_stream_output_vs);
33102 queue_test(test_gather);
33103 queue_test(test_gather_c);
33104 queue_test(test_depth_bias);
33105 queue_test(test_fractional_viewports);
33106 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0, test_negative_viewports);
33107 queue_test(test_early_depth_stencil);
33108 queue_test(test_conservative_depth_output);
33109 queue_test(test_format_compatibility);
33110 queue_for_each_feature_level_in_range(D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_11_0,
33111 test_compressed_format_compatibility);
33112 queue_test(test_clip_distance);
33113 queue_test(test_combined_clip_and_cull_distances);
33114 queue_test(test_generate_mips);
33115 queue_test(test_alpha_to_coverage);
33116 queue_test(test_unbound_multisample_texture);
33117 queue_test(test_multiple_viewports);
33118 queue_test(test_multisample_resolve);
33119 queue_test(test_sample_shading);
33120 queue_test(test_sample_mask);
33121 queue_test(test_depth_clip);
33122 queue_test(test_staging_buffers);
33123 queue_test(test_render_a8);
33124 queue_test(test_standard_pattern);
33125 queue_test(test_desktop_window);
33126 queue_test(test_sample_attached_rtv);
33127 queue_test(test_color_mask);
33128 queue_test(test_independent_blend);
33129 queue_test(test_dual_source_blend);
33130 queue_test(test_deferred_context_state);
33131 queue_test(test_deferred_context_swap_state);
33132 queue_test(test_deferred_context_rendering);
33133 queue_test(test_deferred_context_map);
33134 queue_test(test_unbound_streams);
33136 run_queued_tests();